Пример #1
0
        public DB2Reader(string fileName)
        {
            using (var reader = BinaryReaderExtensions.FromFile(fileName))
            {
                if (reader.BaseStream.Length < HeaderSize)
                {
                    throw new InvalidDataException(String.Format("File {0} is corrupted!", fileName));
                }

                if (reader.ReadUInt32() != DB2FmtSig)
                {
                    throw new InvalidDataException(String.Format("File {0} isn't valid DBC file!", fileName));
                }

                RecordsCount    = reader.ReadInt32();
                FieldsCount     = reader.ReadInt32();
                RecordSize      = reader.ReadInt32();
                StringTableSize = reader.ReadInt32();

                // WDB2 specific fields
                uint tableHash = reader.ReadUInt32(); // new field in WDB2
                uint build     = reader.ReadUInt32(); // new field in WDB2
                uint unk1      = reader.ReadUInt32(); // new field in WDB2

                if (build > 12880)                    // new extended header
                {
                    int MinId  = reader.ReadInt32();  // new field in WDB2
                    int MaxId  = reader.ReadInt32();  // new field in WDB2
                    int locale = reader.ReadInt32();  // new field in WDB2
                    int unk5   = reader.ReadInt32();  // new field in WDB2

                    if (MaxId != 0)
                    {
                        var diff = MaxId - MinId + 1;   // blizzard is weird people...
                        reader.ReadBytes(diff * 4);     // an index for rows
                        reader.ReadBytes(diff * 2);     // a memory allocation bank
                    }
                }

                m_rows = new byte[RecordsCount][];

                for (int i = 0; i < RecordsCount; i++)
                {
                    m_rows[i] = reader.ReadBytes(RecordSize);
                }

                int stringTableStart = (int)reader.BaseStream.Position;

                StringTable = new StringTable();

                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    int index = (int)reader.BaseStream.Position - stringTableStart;
                    StringTable[index] = reader.ReadStringNull();
                }
            }
        }
Пример #2
0
        public DB2Reader(string fileName)
        {
            using (var reader = BinaryReaderExtensions.FromFile(fileName))
            {
                if (reader.BaseStream.Length < HeaderSize)
                {
                    Console.WriteLine("File {0} is corrupted!", fileName);
                    return;
                }

                var signature = reader.ReadUInt32();

                if (signature != DB2FmtSig && signature != ADBFmtSig)
                {
                    Console.WriteLine("File {0} isn't valid DBC file!", fileName);
                    return;
                }

                RecordsCount    = reader.ReadInt32();
                FieldsCount     = reader.ReadInt32(); // not fields count in WCH2
                RecordSize      = reader.ReadInt32();
                StringTableSize = reader.ReadInt32();

                // WDB2/WCH2 specific fields
                uint tableHash = reader.ReadUInt32(); // new field in WDB2
                uint build     = reader.ReadUInt32(); // new field in WDB2

                int unk1   = reader.ReadInt32();      // new field in WDB2 (Unix time in WCH2)
                int unk2   = reader.ReadInt32();      // new field in WDB2
                int unk3   = reader.ReadInt32();      // new field in WDB2 (index table?)
                int locale = reader.ReadInt32();      // new field in WDB2
                int unk5   = reader.ReadInt32();      // new field in WDB2

                if (unk3 != 0)
                {
                    reader.ReadBytes(unk3 * 4 - HeaderSize);     // an index for rows
                    reader.ReadBytes(unk3 * 2 - HeaderSize * 2); // a memory allocation bank
                }

                m_rows = new byte[RecordsCount][];

                for (int i = 0; i < RecordsCount; i++)
                {
                    m_rows[i] = reader.ReadBytes(RecordSize);
                }

                int stringTableStart = (int)reader.BaseStream.Position;

                StringTable = new StringTable();

                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    int index = (int)reader.BaseStream.Position - stringTableStart;
                    StringTable[index] = reader.ReadStringNull();
                }
            }
        }
Пример #3
0
        public DB2Reader(string fileName)
        {
            using (var reader = BinaryReaderExtensions.FromFile(fileName))
            {
                if (reader.BaseStream.Length < HeaderSize)
                {
                    throw new InvalidDataException(String.Format("File {0} is corrupted!", fileName));
                }

                if (reader.ReadUInt32() != DB2FmtSig)
                {
                    throw new InvalidDataException(String.Format("File {0} isn't valid DBC file!", fileName));
                }

                RecordsCount    = reader.ReadInt32();
                FieldsCount     = reader.ReadInt32();
                RecordSize      = reader.ReadInt32();
                StringTableSize = reader.ReadInt32();

                // WDB2 specific fields
                uint tableHash = reader.ReadUInt32(); // new field in WDB2
                uint build     = reader.ReadUInt32(); // new field in WDB2

                int unk1   = reader.ReadInt32();      // new field in WDB2
                int unk2   = reader.ReadInt32();      // new field in WDB2
                int unk3   = reader.ReadInt32();      // new field in WDB2 (index table?)
                int locale = reader.ReadInt32();      // new field in WDB2
                int unk5   = reader.ReadInt32();      // new field in WDB2

                if (unk3 != 0)
                {
                    reader.ReadBytes(unk3 * 4 - HeaderSize);     // an index for rows
                    reader.ReadBytes(unk3 * 2 - HeaderSize * 2); // a memory allocation bank
                }

                m_rows = new byte[RecordsCount][];

                for (int i = 0; i < RecordsCount; i++)
                {
                    m_rows[i] = reader.ReadBytes(RecordSize);
                }

                int stringTableStart = (int)reader.BaseStream.Position;

                StringTable = new StringTable();

                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    int index = (int)reader.BaseStream.Position - stringTableStart;
                    StringTable[index] = reader.ReadStringNull();
                }
            }
        }
Пример #4
0
        public WDBReader(string fileName)
        {
            using (var reader = BinaryReaderExtensions.FromFile(fileName))
            {
                if (reader.BaseStream.Length < HeaderSize)
                {
                    throw new InvalidDataException(String.Format("File {0} is corrupted!", fileName));
                }

                var signature = reader.ReadUInt32();

                if (!WDBSigs.Contains(signature))
                {
                    throw new InvalidDataException(String.Format("File {0} isn't valid WDB file!", fileName));
                }

                uint build   = reader.ReadUInt32();
                uint locale  = reader.ReadUInt32();
                var  unk1    = reader.ReadInt32();
                var  unk2    = reader.ReadInt32();
                var  version = reader.ReadInt32();

                m_rows = new Dictionary <int, byte[]>();

                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    var entry = reader.ReadInt32();
                    var size  = reader.ReadInt32();
                    if (entry == 0 && size == 0 && reader.BaseStream.Position == reader.BaseStream.Length)
                    {
                        break;
                    }
                    var row = new byte[0]
                              .Concat(BitConverter.GetBytes(entry))
                              .Concat(reader.ReadBytes(size))
                              .ToArray();
                    m_rows.Add(entry, row);
                }

                RecordsCount = m_rows.Count;
            }
        }
Пример #5
0
        public DBCReader(string fileName)
        {
            using (var reader = BinaryReaderExtensions.FromFile(fileName))
            {
                if (reader.BaseStream.Length < HeaderSize)
                {
                    Console.WriteLine("File {0} is corrupted!", fileName);
                    return;
                }

                if (reader.ReadUInt32() != DBCFmtSig)
                {
                    Console.WriteLine("File {0} isn't valid DBC file!", fileName);
                    return;
                }

                RecordsCount    = reader.ReadInt32();
                FieldsCount     = reader.ReadInt32();
                RecordSize      = reader.ReadInt32();
                StringTableSize = reader.ReadInt32();

                m_rows = new byte[RecordsCount][];

                for (int i = 0; i < RecordsCount; i++)
                {
                    m_rows[i] = reader.ReadBytes(RecordSize);
                }

                int stringTableStart = (int)reader.BaseStream.Position;

                StringTable = new StringTable();

                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    int index = (int)reader.BaseStream.Position - stringTableStart;
                    StringTable[index] = reader.ReadStringNull();
                }
            }
        }