public WorldTable(byte[] data) { using (MemoryStream ms = new MemoryStream(data)) { using (BinaryReader br = new BinaryReader(ms)) { this.Version = br.ReadIFFChunk <TerrainVersion>(); this.Header = br.ReadIFFChunk <WorldTableHeader>(); this.AreaInfo = br.ReadIFFChunk <WorldTableAreaInfo>(); this.WorldModelObjects = br.ReadIFFChunk <TerrainWorldModelObjects>(); if (this.WorldModelObjects.Filenames.Count > 0) { this.WorldModelObjectPlacementInfo = br.ReadIFFChunk <TerrainWorldModelObjectPlacementInfo>(); } } } }
// TODO: Change to stream-based loading /// <summary> /// Creates a new ADT object from a file on disk /// </summary> /// <param name="data">Byte array containing ADT data.</param> /// <returns>A parsed ADT file with objects for all chunks</returns> public TerrainTile(byte[] data) { using (MemoryStream ms = new MemoryStream(data)) { using (BinaryReader br = new BinaryReader(ms)) { // In all ADT files, the version chunk and header chunk are at the beginning of the file, // with the header following the version. From them, the rest of the chunks can be // seeked to and read. // Read Version Chunk this.Version = br.ReadIFFChunk <TerrainVersion>(); // Read the header chunk this.Header = br.ReadIFFChunk <TerrainHeader>(); if (this.Header.MapChunkOffsetsOffset > 0) { br.BaseStream.Position = this.Header.MapChunkOffsetsOffset; this.MapChunkOffsets = br.ReadIFFChunk <TerrainMapChunkOffsets>(); } if (this.Header.TexturesOffset > 0) { br.BaseStream.Position = this.Header.TexturesOffset; this.Textures = br.ReadIFFChunk <TerrainTextures>(); } if (this.Header.ModelsOffset > 0) { br.BaseStream.Position = this.Header.ModelsOffset; this.Models = br.ReadIFFChunk <TerrainModels>(); } if (this.Header.ModelIndicesOffset > 0) { br.BaseStream.Position = this.Header.ModelIndicesOffset; this.ModelIndices = br.ReadIFFChunk <TerrainModelIndices>(); } if (this.Header.WorldModelObjectsOffset > 0) { br.BaseStream.Position = this.Header.WorldModelObjectsOffset; this.WorldModelObjects = br.ReadIFFChunk <TerrainWorldModelObjects>(); } if (this.Header.WorldModelObjectIndicesOffset > 0) { br.BaseStream.Position = this.Header.WorldModelObjectIndicesOffset; this.WorldModelObjectIndices = br.ReadIFFChunk <TerrainWorldObjectModelIndices>(); } if (this.Header.LiquidOffset > 0) { br.BaseStream.Position = this.Header.LiquidOffset; this.Liquids = br.ReadIFFChunk <TerrainLiquid>(); // TODO: [#9] Pass in DBC liquid type to load the vertex data } // Read and fill the map chunks foreach (MapChunkOffsetEntry entry in this.MapChunkOffsets.Entries) { br.BaseStream.Position = entry.MapChunkOffset; this.MapChunks.Add(br.ReadIFFChunk <TerrainMapChunk>()); } } } }
public WorldLOD(byte[] inData) { using (MemoryStream ms = new MemoryStream(inData)) { using (BinaryReader br = new BinaryReader(ms)) { // Set up the two area lists with default values for (int i = 0; i < 4096; ++i) { MapAreas.Add(null); MapAreaHoles.Add(null); } Version = br.ReadIFFChunk <TerrainVersion>(); if (br.PeekChunkSignature() == TerrainWorldModelObjects.Signature) { WorldModelObjects = br.ReadIFFChunk <TerrainWorldModelObjects>(); } if (br.PeekChunkSignature() == TerrainWorldModelObjectIndices.Signature) { WorldModelObjectIndices = br.ReadIFFChunk <TerrainWorldModelObjectIndices>(); } if (br.PeekChunkSignature() == TerrainWorldModelObjectPlacementInfo.Signature) { WorldModelObjectPlacementInfo = br.ReadIFFChunk <TerrainWorldModelObjectPlacementInfo>(); } MapAreaOffsets = br.ReadIFFChunk <WorldLODMapAreaOffsets>(); // Read the map areas and their holes for (int y = 0; y < 64; ++y) { for (int x = 0; x < 64; ++x) { int mapAreaOffsetIndex = (y * 64) + x; uint mapAreaOffset = MapAreaOffsets.MapAreaOffsets[mapAreaOffsetIndex]; if (mapAreaOffset > 0) { br.BaseStream.Position = mapAreaOffset; MapAreas[mapAreaOffsetIndex] = br.ReadIFFChunk <WorldLODMapArea>(); if (br.PeekChunkSignature() == WorldLODMapAreaHoles.Signature) { MapAreaHoles[mapAreaOffsetIndex] = br.ReadIFFChunk <WorldLODMapAreaHoles>(); } else { MapAreaHoles[mapAreaOffsetIndex] = WorldLODMapAreaHoles.CreateEmpty(); } } else { MapAreas[mapAreaOffsetIndex] = null; MapAreaHoles[mapAreaOffsetIndex] = null; } } } } } }