public void Read(Stream stream)
{
m_EntryByID = new Dictionary<ulong,DBPFEntry>();
m_EntriesList = new List<DBPFEntry>();
var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN);
m_Reader = io;
this.Io = io;
var magic = io.ReadCString(4);
if (magic != "DBPF")
{
throw new Exception("Not a DBPF file");
}
var majorVersion = io.ReadUInt32();
var minorVersion = io.ReadUInt32();
var version = majorVersion + (((double)minorVersion)/10.0);
/** Unknown, set to 0 **/
io.Skip(12);
if (version == 1.0)
{
this.DateCreated = io.ReadInt32();
this.DateModified = io.ReadInt32();
}
if (version < 2.0)
{
IndexMajorVersion = io.ReadUInt32();
}
NumEntries = io.ReadUInt32();
uint indexOffset = 0;
if (version < 2.0)
{
indexOffset = io.ReadUInt32();
}
var indexSize = io.ReadUInt32();
if (version < 2.0)
{
var trashEntryCount = io.ReadUInt32();
var trashIndexOffset = io.ReadUInt32();
var trashIndexSize = io.ReadUInt32();
var indexMinor = io.ReadUInt32();
}
else if (version == 2.0)
{
var indexMinor = io.ReadUInt32();
indexOffset = io.ReadUInt32();
io.Skip(4);
}
/** Padding **/
io.Skip(32);
io.Seek(SeekOrigin.Begin, indexOffset);
for (int i = 0; i < NumEntries; i++)
{
var entry = new DBPFEntry();
entry.TypeID = (DBPFTypeID)io.ReadUInt32();
entry.GroupID = (DBPFGroupID)io.ReadUInt32();
entry.InstanceID = io.ReadUInt32();
entry.FileOffset = io.ReadUInt32();
entry.FileSize = io.ReadUInt32();
m_EntriesList.Add(entry);
ulong id = (((ulong)entry.InstanceID) << 32) + (ulong)entry.TypeID;
if (!m_EntryByID.ContainsKey(id))
m_EntryByID.Add(id, entry);
if (!m_EntriesByType.ContainsKey(entry.TypeID))
m_EntriesByType.Add(entry.TypeID, new List<DBPFEntry>());
m_EntriesByType[entry.TypeID].Add(entry);
}
}