/// <summary> /// Get byte array from lump /// </summary> public byte[] GetRottWadLumpDataByLump(Rott2DWadDirectoryEntry lump) { byte[] data = null; if (lump.Size > 0) { this._WADFile.Seek(lump.Offset, SeekOrigin.Begin); data = this._WADReader.ReadBytes(lump.Size); } return(data); }
/// <summary> /// Get byte array from lump name /// </summary> public byte[] GetWadLumpDataByName(string strSearchName) { Rott2DWadDirectoryEntry lump = this.GetWadEntryByName(strSearchName); byte[] data = null; if (lump.Size > 0) { this._WADFile.Seek(lump.Offset, SeekOrigin.Begin); data = this._WADReader.ReadBytes(lump.Size); } return(data); }
/// <summary> /// Get WAD entry by file size /// </summary> public Rott2DWadDirectoryEntry GetRottWadEntryBySize(int intSearchSize) { Rott2DWadDirectoryEntry rweFound = new Rott2DWadDirectoryEntry(); rweFound.Name = "EMPTY"; rweFound.Offset = 0; rweFound.Size = 0; foreach (Rott2DWadDirectoryEntry rwe in this._WADEntries) { if (rwe.Size == intSearchSize) { rweFound = rwe; } } return(rweFound); }
/// <summary> /// Get WAD entry by Name /// </summary> public Rott2DWadDirectoryEntry GetWadEntryByName(string strSearchName) { Rott2DWadDirectoryEntry rweReturn = new Rott2DWadDirectoryEntry(); rweReturn.Name = "EMPTY"; rweReturn.Offset = 0; rweReturn.Size = 0; foreach (Rott2DWadDirectoryEntry rwe in this._WADEntries) { if (rwe.Name == strSearchName) { rweReturn = rwe; /*rweReturn.Name = rwe.Name; * rweReturn.Offset = rwe.Offset; * rweReturn.Size = rwe.Size;*/ } } return(rweReturn); }
/// <summary> /// Read Wad file LUMP's /// </summary> private bool ReadRottWadEntries() { //Entries can only be read when the file is allocated if (this.WADAllocated) { try { //Create header for WAD this._WADHeader = new Rott2DWadHeader(); this._WADHeader.IsWADFile = false; //initialize //Go to beginning of WAD file this._WADFile.Seek(0, SeekOrigin.Begin); //read first 4 bytes for the IWAD_ID if (this._WADFile.Length != 0) { this._WADHeader.WadFileId = System.Text.Encoding.ASCII.GetString(this._WADReader.ReadBytes(4)); } //read WAD header data if (this._WADHeader.WadFileId.CompareTo(IWAD_ID) == 0) { this._WADHeader.IsWADFile = true; this._WADHeader.NumEntries = BitConverter.ToInt32(this._WADReader.ReadBytes(4), 0); this._WADHeader.DirOffset = BitConverter.ToInt32(this._WADReader.ReadBytes(4), 0); } if (this._WADHeader.IsWADFile) { //start reading WAD entries this._WADEntries = new Rott2DWadDirectoryEntry[this._WADHeader.NumEntries]; this._WADFile.Seek(this._WADHeader.DirOffset, SeekOrigin.Begin); for (int i = 0; i < this._WADHeader.NumEntries; i++) { this._WADEntries[i] = new Rott2DWadDirectoryEntry(); this._WADEntries[i].ID = i; //Set our own ID this._WADEntries[i].Offset = BitConverter.ToInt32(this._WADReader.ReadBytes(4), 0); this._WADEntries[i].Size = BitConverter.ToInt32(this._WADReader.ReadBytes(4), 0); //this._WADEntries[i].Name = System.Text.Encoding.ASCII.GetString(this._WADReader.ReadBytes(8)).ToUpper(); this._WADEntries[i].Name = System.Text.Encoding.ASCII.GetString(this._WADReader.ReadBytes(8)).Trim('\0').ToUpper(); } //flag ready if this is a rott wad file //the lump in a ROTT WAD file, always reads "WALLSTRT" by name and is a lump marker! if (this._WADEntries.Length > 0) { Rott2DWadDirectoryEntry wde = this.GetRottWadEntryByIndex(0); if (wde.Name == "WALLSTRT") { this._bWADFileHeaderRead = true; this.WADValid = true; } } else { this.CloseRottWad(); //not a ROTT WAD file! } } else { this.CloseRottWad(); //close on fail? } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error in ReadRottWadEntries"); System.Diagnostics.Debug.Write(ex.ToString()); throw new Exception("Error in ReadRottWadEntries"); } } //if end return(WADHeader.IsWADFile); }