Ejemplo n.º 1
0
        }                                 // Just junk data?

        public RT04CategoryMeta(EndianBinReader reader)
        {
            TitleOffset = reader.ReadUInt32();
            EntryCount  = reader.ReadUInt32();
            EntryOffset = reader.ReadUInt32();
            Padding     = reader.ReadUInt32();
        }
Ejemplo n.º 2
0
        public override void Read(EndianBinReader reader)
        {
            var pageNameOffset = reader.ReadUInt32();
            var pairUnitCount  = reader.ReadUInt32();
            var pairUnitOffset = reader.ReadUInt32();

            reader.BaseStream.Position = pageNameOffset;
            Name = reader.ReadNullTerminatedString();

            reader.BaseStream.Position += reader.BaseStream.Position % 0x10; // Padding with 0x5E

            for (int i = 0; i < pairUnitCount; i++)
            {
                reader.BaseStream.Position = pairUnitOffset + (i * EntrySize);
                int  id          = reader.ReadInt32();
                uint labelOffset = reader.ReadUInt32();
                uint valueOffset = reader.ReadUInt32();

                reader.BaseStream.Position = labelOffset;
                string label = reader.ReadNullTerminatedString();

                reader.BaseStream.Position = valueOffset;
                string value = reader.ReadNullTerminatedString();

                var pair = new RTextPairUnit(id, label, value);
                PairUnits.Add(label, pair);
            }
        }
Ejemplo n.º 3
0
 public _50TRCategoryMeta(EndianBinReader reader)
 {
     TitleOffset = reader.ReadUInt32();
     Padding1    = reader.ReadUInt32();
     EntryCount  = reader.ReadUInt32();
     Padding2    = reader.ReadUInt32();
     EntryOffset = reader.ReadUInt32();
 }
Ejemplo n.º 4
0
        public _50TRHeader(EndianBinReader reader)
        {
            reader.BaseStream.Position = 0;
            if ((Magic = reader.ReadUInt32(EndianType.BIG_ENDIAN)) != Constants._50TR_MAGIC)
            {
                throw new Exception("Invalid magic, doesn't match 50TR.");
            }

            EntryCount = reader.ReadUInt32();
            Obfuscated = reader.ReadByte();
        }
Ejemplo n.º 5
0
        public RT05Header(EndianBinReader reader)
        {
            reader.BaseStream.Position = 0;
            if ((Magic = reader.ReadUInt32()) != Constants.RT05_MAGIC)
            {
                throw new Exception("Invalid magic, doesn't match RT05.");
            }

            EntryCount = reader.ReadUInt32();
            Obfuscated = reader.ReadByte();
        }
Ejemplo n.º 6
0
        public RT04Header(EndianBinReader reader)
        {
            reader.BaseStream.Position = 0;
            if ((Magic = reader.ReadUInt32(EndianType.BIG_ENDIAN)) != Constants.RT04_MAGIC)
            {
                throw new Exception("Invalid magic, doesn't match RT04.");
            }

            Padding    = reader.ReadUInt64();
            EntryCount = reader.ReadUInt32();
        }
Ejemplo n.º 7
0
        public Header(EndianBinReader reader)
        {
            reader.BaseStream.Position = 0;
            if ((Magic = reader.ReadUInt32()) != Constants.NDB0_MAGIC)
            {
                throw new Exception("Invalid magic, doesn't match NDB0.");
            }

            Padding            = reader.ReadUInt32();
            SpeedUpTableOffset = reader.ReadUInt32();
            EntryCount         = reader.ReadUInt32();
        }
Ejemplo n.º 8
0
        public void Load(EndianBinReader reader, uint dataSize, uint segmentSize)
        {
            if (reader.ReadUInt32() != kMAGIC)
            {
                return;
            }

            SegmentSize = segmentSize;

            _nameTableOffset      = reader.ReadUInt32();
            _extensionTableOffset = reader.ReadUInt32();
            _fileInfoTableOffset  = reader.ReadUInt32();
            _numFileIdTrees       = reader.ReadUInt32();

            Load(reader);
        }
Ejemplo n.º 9
0
        public EntryMetaData(EndianBinReader reader)
        {
            CarID              = reader.ReadUInt32();
            OrderID            = reader.ReadUInt32();
            DataOffset         = reader.ReadUInt32();
            LookupTableOffsets = reader.ReadBytes(4);
            Lookup1            = LookupTableOffsets[0];
            Lookup2            = LookupTableOffsets[1];
            Lookup3            = LookupTableOffsets[2];
            Lookup4            = LookupTableOffsets[3];

            var saveOffset = reader.BaseStream.Position;

            reader.BaseStream.Position = DataOffset;
            Data = reader.ReadNullTerminatedString();
            reader.BaseStream.Position = saveOffset;
        }
Ejemplo n.º 10
0
        public bool Read(EndianBinReader reader, uint size, uint realSize)
        {
            Size     = size;
            RealSize = realSize;

            if ((Magic = reader.ReadUInt32()) != 0xC5EEF7FFu)
            {
                return(false);
            }

            DataSize = reader.ReadUInt32();
            DataSize = (uint)-DataSize;

            Size -= Consts.kVOLUME_SEGMENT_HEADER_SIZE;

            Data = reader.ReadBytes((int)Size);
            Data = DeflateStream.UncompressBuffer(Data);
            System.Diagnostics.Debug.Assert(Data.Length == RealSize);

            return(true);
        }
Ejemplo n.º 11
0
        public override void Read(EndianBinReader reader)
        {
            var pageNameOffset = _gt7 ? reader.ReadInt64() : reader.ReadUInt32();
            var pairUnitCount  = reader.ReadUInt32();

            reader.ReadUInt32(); // Unk
            var pairUnitOffset = _gt7 ? reader.ReadInt64() : reader.ReadUInt32();

            reader.BaseStream.Position = (int)pageNameOffset;
            Name = reader.ReadNullTerminatedString();

            for (int i = 0; i < pairUnitCount; i++)
            {
                reader.BaseStream.Position = pairUnitOffset + (i * (_gt7 ? EntrySizeGT7 : EntrySize));
                int id = reader.ReadInt32();

                ushort labelLen = reader.ReadUInt16();
                ushort valueLen = reader.ReadUInt16();

                long labelOffset = _gt7 ? reader.ReadInt64() : reader.ReadUInt32();
                long valueOffset = _gt7 ? reader.ReadInt64() : reader.ReadUInt32();

                reader.BaseStream.Position = labelOffset;
                string label = ReadString(reader, labelLen);

                reader.BaseStream.Position = valueOffset;
                string value = ReadString(reader, valueLen);

                var pair = new RTextPairUnit(id, label, value);
                PairUnits.Add(label, pair);
            }
        }
Ejemplo n.º 12
0
        public bool Read(EndianBinReader reader)
        {
            if ((Magic = reader.ReadUInt32()) != Consts.kVOLUME_HEADER_MAGIC)
            {
                return(false);
            }

            Seed = reader.ReadUInt32();
            if (Seed <= 0)
            {
                return(false);
            }

            Size          = reader.ReadUInt32();
            RealSize      = reader.ReadUInt32();
            PatchSequence = reader.ReadUInt64();
            FileSize      = reader.ReadUInt64();
            var buffer = reader.ReadBytes(128);

            TitleID = Encoding.UTF8.GetString(buffer);

            return(true);
        }
Ejemplo n.º 13
0
        public bool Load(EndianBinReader reader, bool readHeader = false)
        {
            if (readHeader)
            {
                if (reader.ReadUInt32() != kMAGIC)
                {
                    return(false);
                }

                _nameTableOffset      = reader.ReadUInt32();
                _extensionTableOffset = reader.ReadUInt32();
                _fileInfoTableOffset  = reader.ReadUInt32();
                _numFileIdTrees       = reader.ReadUInt32();
            }

            _fileIdOffsets = new uint[_numFileIdTrees];
            for (int i = 0; i < _numFileIdTrees; i++)
            {
                _fileIdOffsets[i] = reader.ReadUInt32();
            }

            // Read Names
            Names = LoadStringBTree(reader, _nameTableOffset);
            // Read Extensions
            Extensions = LoadStringBTree(reader, _extensionTableOffset);
            // Read FileInfo
            FileInfos = LoadFileInfoBTree(reader, _fileInfoTableOffset);

            // Read FileID:s
            int index = 0;

            FileIDs = new FileIDBTree[_fileIdOffsets.Length][];

            foreach (uint offset in _fileIdOffsets)
            {
                FileIDBTree[] temp = new FileIDBTree[0];
                LoadFileIDBTree(reader, ref temp, offset);

                FileIDs[index] = temp;
                index++;
            }

            // Get the file count
            for (int i = 0; i < FileIDs.Length; i++)
            {
                for (int j = 0; j < FileIDs[i].Length; j++)
                {
                    if (FileIDs[i][j].Flag == FileIDBTree.kFILE_FLAG ||
                        FileIDs[i][j].Flag == FileIDBTree.kFILE_WITHOUT_EXTENSION_FLAG)
                    {
                        FileCount++;
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 14
0
        public void Read(byte[] data)
        {
            using (var ms = new MemoryStream(data))
                using (var reader = new EndianBinReader(ms))
                {
                    switch (reader.ReadUInt32())
                    {
                    case Constants.RT03_MAGIC:
                        RText = new RT03(_logWriter);
                        break;

                    case Constants.RT04_MAGIC:
                        RText = new RT04(_logWriter);
                        break;

                    case Constants.RT05_MAGIC:
                        RText = new RT05(_logWriter);
                        break;

                    case Constants._50TR_MAGIC:
                        try
                        {
                            RText = new _50TR(_logWriter);
                            RText.Read(data);
                            return;
                        }
                        catch { }

                        // Failed, try GT7
                        RText = new _50TR(_logWriter, gt7: true);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("Unknown header magic.");
                    }

                    RText.Read(data);
                }
        }
Ejemplo n.º 15
0
        public override void Read(byte[] data)
        {
            using (var ms = new MemoryStream(data))
                using (var reader = new EndianBinReader(ms, EndianType.LITTLE_ENDIAN))
                {
                    reader.BaseStream.Position = 0;
                    if (reader.ReadString(4) != Magic)
                    {
                        throw new Exception("Invalid magic, doesn't match RT03.");
                    }

                    reader.ReadInt32();  // Relocation Ptr
                    reader.ReadUInt32(); // Empty - skipped by GT4
                    int entryCount = reader.ReadInt32();

                    for (int i = 0; i < entryCount; i++)
                    {
                        ms.Position = HeaderSize + (i * 0x10);
                        var page = new RT03Page(_logWriter);
                        page.Read(reader);
                        _pages.Add(page.Name, page);
                    }
                }
        }
Ejemplo n.º 16
0
        private void Read()
        {
            using (var ms = new MemoryStream(_data))
                using (var reader = new EndianBinReader(ms))
                {
                    _header = new Header(reader);

                    _entryTables = new List <EntryTable>();
                    for (int i = 0; i < _header.EntryCount; i++)
                    {
                        reader.BaseStream.Position = Constants.NDB0_HEADER_SIZE + (i * 0x04);
                        reader.BaseStream.Position = reader.ReadUInt32();
                        _entryTables.Add(new EntryTable(reader, _logWriter));
                    }

#if DEBUG
                    for (int i = 0; i < _entryTables.Count; i++)
                    {
                        var entryTable = _entryTables[i];
                        _logWriter?.WriteLine($"---- Entry Table {i} ({entryTable.Entries.Count}) ----");
                        for (int j = 0; j < entryTable.Entries.Count; j++)
                        {
                            var entryTableEntry = entryTable.Entries[j];

                            _logWriter?.WriteLine($"{j:X8} | {entryTableEntry.CarID:X8} - {entryTableEntry.OrderID:X8} - {entryTableEntry.DataOffset:X8} - {entryTableEntry.Lookup1:X2} - {entryTableEntry.Lookup2:X2} - {entryTableEntry.Lookup3:X2} - {entryTableEntry.Lookup4:X2} - {entryTableEntry.Data}");
                        }
                    }
#endif

                    _speedUpTable = new List <string>();
                    reader.BaseStream.Position = _header.SpeedUpTableOffset;
                    var count = reader.ReadUInt32();
                    for (int i = 0; i < count; i++)
                    {
                        reader.BaseStream.Position = _header.SpeedUpTableOffset + 0x04 + (i * 0x04);
                        reader.BaseStream.Position = reader.ReadUInt32();
                        _speedUpTable.Add(reader.ReadNullTerminatedString());
                    }

#if DEBUG
                    _logWriter?.WriteLine($"---- Speed Up Table ({_speedUpTable.Count}) ----");
                    for (int i = 0; i < _speedUpTable.Count; i++)
                    {
                        _logWriter?.WriteLine($"{i:X8} | {_speedUpTable[i]}");
                    }


                    var usageCount = new int[0xFF];
                    for (int i = 0; i < _entryTables.Count; i++)
                    {
                        var entryTable = _entryTables[i];
                        foreach (var entryTableEntry in entryTable.Entries.OrderBy(x => x.OrderID))
                        {
                            for (int k = 0; k < 4; k++)
                            {
                                if (entryTableEntry.LookupTableOffsets[k] < 0xFF)
                                {
                                    usageCount[entryTableEntry.LookupTableOffsets[k]]++;
                                }
                            }
                        }
                    }
#endif


                    for (int i = 0; i < _entryTables.Count; i++)
                    {
                        using (var sw = new StreamWriter($"NDB0_Table_{i}.txt"))
                        {
                            var entryTable = _entryTables[i];
                            foreach (var entryTableEntry in entryTable.Entries.OrderBy(x => x.OrderID))
                            {
                                var sb = new StringBuilder();

                                for (int k = 0; k < 4; k++)
                                {
                                    if (entryTableEntry.LookupTableOffsets[k] < 0xFF)
                                    {
                                        sb.Append($"{_speedUpTable[entryTableEntry.LookupTableOffsets[k]]} ");
                                    }
                                }

                                sb.Append(entryTableEntry.Data);
                                sw.WriteLine($"{entryTableEntry.CarID:X8} - {entryTableEntry.OrderID:X8} - {sb}");
                            }
                        }
                    }
                }
        }
Ejemplo n.º 17
0
 public CategoryMetaData(EndianBinReader reader)
 {
     Version    = reader.ReadUInt32();
     EntryCount = reader.ReadUInt32();
 }