public DBCReader(string fileName)
{
FileName = fileName;
using (var reader = Extensions.FromFile(fileName))
{
if (reader.BaseStream.Length < HeaderSize)
{
throw new InvalidDataException(string.Format("File {0} is corrupted!", fileName));
}
if (reader.ReadUInt32() != DBCFmtSig)
{
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();
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 Dictionary<int, string>();
while (reader.BaseStream.Position != reader.BaseStream.Length)
{
int index = (int)reader.BaseStream.Position - stringTableStart;
StringTable[index] = reader.ReadStringNull();
}
reader.BaseStream.Position = stringTableStart;
Strings = reader.ReadBytes(StringTableSize);
}
}