/// <summary> /// Reads MapDItem data. /// </summary> /// <param name="Reader">A binary reader to data.</param> /// <param name="Region">Region index.</param> /// <param name="Location">Location index.</param> /// <param name="dfLocation">Destination DFLocation.</param> private void ReadMapDItem(ref BinaryReader Reader, int Region, int Location, ref DFLocation dfLocation) { // Exit if no data dfLocation.HasDungeon = false; if (Reader.BaseStream.Length == 0) { return; } // Find dungeon offset bool found = false; UInt32 locationId = dfLocation.Exterior.RecordElement.Header.LocationId; UInt32 dungeonCount = Reader.ReadUInt32(); DungeonOffset dungeonOffset = new DungeonOffset(); for (int i = 0; i < dungeonCount; i++) { // Search for dungeon offset matching location id dungeonOffset.Offset = Reader.ReadUInt32(); dungeonOffset.IsDungeon = Reader.ReadUInt16(); dungeonOffset.ExteriorLocationId = Reader.ReadUInt16(); if (dungeonOffset.ExteriorLocationId == locationId) { found = true; break; } } // Exit if correct offset not found if (!found) { return; } // Position reader at dungeon record by reading offset and adding to end of offset table Reader.BaseStream.Position = 4 + dungeonCount * 8 + dungeonOffset.Offset; // Read LocationRecordElement ReadLocationRecordElement(ref Reader, Region, ref dfLocation.Dungeon.RecordElement); // Read DungeonHeader dfLocation.Dungeon.Header.NullValue1 = Reader.ReadUInt16(); dfLocation.Dungeon.Header.Unknown1 = Reader.ReadUInt32(); dfLocation.Dungeon.Header.Unknown2 = Reader.ReadUInt32(); dfLocation.Dungeon.Header.BlockCount = Reader.ReadUInt16(); dfLocation.Dungeon.Header.Unknown3 = Reader.ReadBytes(5); // Read DungeonBlock elements dfLocation.Dungeon.Blocks = new DFLocation.DungeonBlock[dfLocation.Dungeon.Header.BlockCount]; for (int i = 0; i < dfLocation.Dungeon.Header.BlockCount; i++) { // Read data dfLocation.Dungeon.Blocks[i].X = Reader.ReadSByte(); dfLocation.Dungeon.Blocks[i].Z = Reader.ReadSByte(); dfLocation.Dungeon.Blocks[i].BlockNumberStartIndexBitfield = Reader.ReadUInt16(); // Decompose bitfield UInt16 bitfield = dfLocation.Dungeon.Blocks[i].BlockNumberStartIndexBitfield; dfLocation.Dungeon.Blocks[i].BlockNumber = (UInt16)(bitfield & 0x3ff); dfLocation.Dungeon.Blocks[i].IsStartingBlock = ((bitfield & 0x400) == 0x400) ? true : false; dfLocation.Dungeon.Blocks[i].BlockIndex = (Byte)(bitfield >> 11); // Compose block name dfLocation.Dungeon.Blocks[i].BlockName = String.Format("{0}{1:0000000}.RDB", RdbBlockLetters[dfLocation.Dungeon.Blocks[i].BlockIndex], dfLocation.Dungeon.Blocks[i].BlockNumber); } // Set dungeon flag dfLocation.HasDungeon = true; }
/// <summary> /// Reads MapDItem data. /// </summary> /// <param name="reader">A binary reader to data.</param> /// <param name="region">Region index.</param> /// <param name="location">Location index.</param> /// <param name="dfLocation">Destination DFLocation.</param> private void ReadMapDItem(ref BinaryReader reader, int region, int location, ref DFLocation dfLocation) { // Exit if no data dfLocation.HasDungeon = false; if (reader.BaseStream.Length == 0) return; // Find dungeon offset bool found = false; UInt32 locationId = dfLocation.Exterior.RecordElement.Header.LocationId; UInt32 dungeonCount = reader.ReadUInt32(); DungeonOffset dungeonOffset = new DungeonOffset(); for (int i = 0; i < dungeonCount; i++) { // Search for dungeon offset matching location id dungeonOffset.Offset = reader.ReadUInt32(); dungeonOffset.IsDungeon = reader.ReadUInt16(); dungeonOffset.ExteriorLocationId = reader.ReadUInt16(); if (dungeonOffset.ExteriorLocationId == locationId) { found = true; break; } } // Exit if correct offset not found if (!found) return; // Position reader at dungeon record by reading offset and adding to end of offset table reader.BaseStream.Position = 4 + dungeonCount * 8 + dungeonOffset.Offset; // Read LocationRecordElement ReadLocationRecordElement(ref reader, region, ref dfLocation.Dungeon.RecordElement); // Read DungeonHeader dfLocation.Dungeon.Header.NullValue1 = reader.ReadUInt16(); dfLocation.Dungeon.Header.Unknown1 = reader.ReadUInt32(); dfLocation.Dungeon.Header.Unknown2 = reader.ReadUInt32(); dfLocation.Dungeon.Header.BlockCount = reader.ReadUInt16(); dfLocation.Dungeon.Header.Unknown3 = reader.ReadBytes(5); // Read DungeonBlock elements dfLocation.Dungeon.Blocks = new DFLocation.DungeonBlock[dfLocation.Dungeon.Header.BlockCount]; for (int i = 0; i < dfLocation.Dungeon.Header.BlockCount; i++) { // Read data dfLocation.Dungeon.Blocks[i].X = reader.ReadSByte(); dfLocation.Dungeon.Blocks[i].Z = reader.ReadSByte(); dfLocation.Dungeon.Blocks[i].BlockNumberStartIndexBitfield = reader.ReadUInt16(); // Decompose bitfield UInt16 bitfield = dfLocation.Dungeon.Blocks[i].BlockNumberStartIndexBitfield; dfLocation.Dungeon.Blocks[i].BlockNumber = (UInt16)(bitfield & 0x3ff); dfLocation.Dungeon.Blocks[i].IsStartingBlock = ((bitfield & 0x400) == 0x400) ? true : false; dfLocation.Dungeon.Blocks[i].BlockIndex = (Byte)(bitfield >> 11); // Compose block name dfLocation.Dungeon.Blocks[i].BlockName = String.Format("{0}{1:0000000}.RDB", rdbBlockLetters[dfLocation.Dungeon.Blocks[i].BlockIndex], dfLocation.Dungeon.Blocks[i].BlockNumber); } // Set dungeon flag dfLocation.HasDungeon = true; }