www.pudn.com > boogiebot.zip > ADTFile.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace BoogieBot.Common
{
/// ADT File. Parses and stores a maptile, and its 256 map chunks.
public class ADTFile
{
// Data read in from ADT file
private MVER mver; // ADT File Version
private MHDR mhdr; // ADT File Header
private MCIN[] mcin_array; // Array of indices to MapChunks
private List wmoFiles; // List of WMO Files located on this MapTile
private MDDF[] doodadLocations; // List of Doodad Locations on this MapTile
private MODF[] wmoLocations; // List of WMO Locations on this MapTile
protected MCNK[][] mapChunkTable; // 16x16 MapChunk Table
// ** Removed because this constructor isn't neccessary.
public ADTFile(String filename)
{
}
public ADTFile(String mapname, int x, int z)
{
}
/*private void parseFile(MPQFile mpqfile)
{
MemoryStream ms = mpqfile.GetStream();
BinaryReader bin = new BinaryReader(ms);
BoogieCore.Log(LogType.SystemDebug, "ATDFile: Parsing {0}... ", mpqfile.Filename);
BlizChunkHeader tempHeader;
long pos = 0;
// Read bytes from the stream until we run out
while (pos < ms.Length)
{
// Advance to the next Chunk
ms.Position = pos;
// Read in Chunk Header Name
tempHeader = new BlizChunkHeader(bin.ReadChars(4), bin.ReadUInt32());
tempHeader.Flip();
// Set pos to the location of the next Chunk
pos = ms.Position + tempHeader.Size;
if(tempHeader.Is("MVER")) // ADT File Version
{
mver = new MVER();
mver.version = bin.ReadUInt32();
continue;
}
if (tempHeader.Is("MHDR")) // ADT File Header
{
mhdr = new MHDR();
mhdr.pad = bin.ReadUInt32();
mhdr.offsInfo = bin.ReadUInt32();
mhdr.offsTex = bin.ReadUInt32();
mhdr.offsModels = bin.ReadUInt32();
mhdr.offsModelsIds = bin.ReadUInt32();
mhdr.offsMapObejcts = bin.ReadUInt32();
mhdr.offsMapObejctsIds = bin.ReadUInt32();
mhdr.offsDoodsDef = bin.ReadUInt32();
mhdr.offsObjectsDef = bin.ReadUInt32();
mhdr.pad1 = bin.ReadUInt32();
mhdr.pad2 = bin.ReadUInt32();
mhdr.pad3 = bin.ReadUInt32();
mhdr.pad4 = bin.ReadUInt32();
mhdr.pad5 = bin.ReadUInt32();
mhdr.pad6 = bin.ReadUInt32();
mhdr.pad7 = bin.ReadUInt32();
continue;
}
if (tempHeader.Is("MCIN")) // Index for MCNK chunks.
{
if (tempHeader.Size != 256 * 16)
throw new Exception("MCIN Chunk is short??");
mcin_array = new MCIN[256];
// Read in the 256 records
for (int i = 0; i < 256; i++)
{
mcin_array[i].MCNK_offset = bin.ReadUInt32();
mcin_array[i].MCNK_size = bin.ReadUInt32();
mcin_array[i].flags = bin.ReadUInt32();
mcin_array[i].asyncID = bin.ReadUInt32();
}
continue;
}
if (tempHeader.Is("MTEX")) // List of texture filenames used by the terrain in this map tile.
{
// Not needed.
continue;
}
if (tempHeader.Is("MMDX")) // List of filenames for M2 models that appear in this map tile.
{
// Not needed.
continue;
}
if (tempHeader.Is("MMID")) // Lists the relative offsets of string beginnings in the above MMDX chunk.
{
// Not needed.
continue;
}
if (tempHeader.Is("MWMO")) // List of filenames for WMOs (world map objects) that appear in this map tile.
{
byte[] wmoFilesChunk = bin.ReadBytes((int)tempHeader.Size);
wmoFiles = new List();
StringBuilder str = new StringBuilder();
// Convert szString's to a List.
for (int i = 0; i < wmoFilesChunk.Length; i++)
{
if (wmoFilesChunk[i] == '\0')
{
if (str.Length > 1)
wmoFiles.Add(str.ToString());
str = new StringBuilder();
}
else
str.Append((char)wmoFilesChunk[i]);
}
continue;
}
if (tempHeader.Is("MWID")) // Lists the relative offsets of string beginnings in the above MWWO chunk.
{
// Not needed.
continue;
}
if (tempHeader.Is("MDDF")) // Placement information for doodads (M2 models).
{
uint num = tempHeader.Size / 32;
doodadLocations = new MDDF[num];
for(int i = 0 ; i