Beispiel #1
0
        public EVE(string file)
        {
            Console.WriteLine(file);
            using (var br = new BinaryReader(File.OpenRead(file)))
            {
                // Header ------------------------------------------------------------------------------------

                var header = new Header(br);
                FileId        = header.FileId;
                HeaderUnknown = header.Unknown;

                //Console.WriteLine("GroupItemCounts:");
                int[] groupItemCounts = new int[header.NumGroups];
                for (int i = 0; i < header.NumGroups; i++)
                {
                    groupItemCounts[i] = br.ReadInt32();
                    //Console.WriteLine($"  0x{groupItemCounts[i]:X}");
                }

                // Offset Tables -------------------------------------------------------------------------------

                //Console.WriteLine("OffsetTableA:");
                br.BaseStream.Position = OffsetTableStart;
                int[][] groupsA = new int[header.NumGroups][];
                for (int groupId = 0; groupId < header.NumGroups; groupId++)
                {
                    //Console.WriteLine($"  Group {groupId} (numItems:{groupItemCounts[groupId]}):");
                    groupsA[groupId] = new int[groupItemCounts[groupId]];
                    for (int idWithinGroup = 0; idWithinGroup < groupItemCounts[groupId]; idWithinGroup++)
                    {
                        groupsA[groupId][idWithinGroup] = br.ReadInt32();
                        //Console.WriteLine($"    0x{groupsA[groupId][idWithinGroup]:X} (id: {idWithinGroup})");
                    }
                }

                Debug.Assert(groupsA.Sum(i => i.Length) == header.NumOffsets);

                var shift = br.ReadUInt32();
                if (shift != header.TableBDataOffset)
                {
                    throw new InvalidDataException("Listed offset doesnt match earlier value");
                }


                //Console.WriteLine("OffsetTableB:");
                int[][] groupsB = new int[header.NumGroups][];
                for (int groupId = 0; groupId < header.NumGroups; groupId++)
                {
                    //Console.WriteLine($"  Group {groupId}:");
                    groupsB[groupId] = new int[groupItemCounts[groupId]];
                    for (int idWithinGroup = 0; idWithinGroup < groupItemCounts[groupId]; idWithinGroup++)
                    {
                        groupsB[groupId][idWithinGroup] = br.ReadInt32();
                        //Console.WriteLine($"    0x{groupsB[groupId][idWithinGroup]:X} (id: {idWithinGroup})");
                    }
                }

                Debug.Assert(groupsB.Sum(i => i.Length) == header.NumOffsets);

                var end = br.ReadInt32();
                //Console.WriteLine($"END OF OFFSETS VALUE = 0x{end:X}");

                // Data ---------------------------------------------------------------------------------------

                var startOffsetA = br.BaseStream.Position;
                for (int a = 0; a < groupsA.Length; a++)
                {
                    int[] group    = groupsA[a];
                    var   eveGroup = new List <(byte[], Event)>();
                    EventGroupsA.Add(eveGroup);
                    for (int i = 0; i < group.Length; i++)
                    {
                        var eventOffset = group[i];
                        br.BaseStream.Position = startOffsetA + eventOffset;
                        byte[] unknown = br.ReadBytes(0x40);
                        eveGroup.Add((unknown, new Event(br)));
                    }
                }

                var startOffsetB = br.BaseStream.Position;
                //Console.WriteLine("START OFFSET B: 0x{0:X}", startOffsetB);
                var expectedStartOffsetB = startOffsetA + header.TableBDataOffset;
                Debug.Assert(startOffsetB == expectedStartOffsetB, $"Start offset of B is unexpected: 0x{startOffsetB:X} (expected: 0x{expectedStartOffsetB:X})");

                for (int b = 0; b < groupsB.Length; b++)
                {
                    int[] group    = groupsB[b];
                    var   eveGroup = new List <Event>();
                    EventGroupsB.Add(eveGroup);
                    for (int i = 0; i < group.Length; i++)
                    {
                        var eventOffset = group[i];
                        br.BaseStream.Position = startOffsetB + eventOffset;
                        eveGroup.Add(new Event(br));
                    }
                }

                // ----------------------------------------------------------------------------
            }
        }