/// <summary> /// Gets a DBPFEntry's data from this DBPF instance. /// </summary> /// <param name="entry">Entry to retrieve data for.</param> /// <returns>Data for entry.</returns> public byte[] GetEntry(DBPFEntry entry) { m_Reader.Seek(SeekOrigin.Begin, entry.FileOffset); return m_Reader.ReadBytes((int)entry.FileSize); }
/// <summary> /// Reads a DBPF archive from a stream. /// </summary> /// <param name="stream">The stream to read from.</param> 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); } }
/// <summary> /// Reads a DBPF archive from a stream. /// </summary> /// <param name="stream">The stream to read from.</param> 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); } }
/// <summary> /// Gets a DBPFEntry's data from this DBPF instance. /// </summary> /// <param name="entry">Entry to retrieve data for.</param> /// <returns>Data for entry.</returns> public byte[] GetEntry(DBPFEntry entry) { m_Reader.Seek(SeekOrigin.Begin, entry.FileOffset); return(m_Reader.ReadBytes((int)entry.FileSize)); }