static void ReadMH2O(BinaryReader fileReader, ADT adt) { var sig = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); long ofsMH2O = fileReader.BaseStream.Position; MH20Header[] mh20Header = new MH20Header[256]; for (int i = 0; i < 256; i++) { mh20Header[i].ofsData1 = fileReader.ReadUInt32(); mh20Header[i].LayerCount = fileReader.ReadUInt32(); mh20Header[i].ofsData2 = fileReader.ReadUInt32(); } // Rows for (int x = 0; x < 16; x++) { // Columns for (int y = 0; y < 16; y++) { // Indexing is [col, row] adt.LiquidInfo[y, x] = ProcessMH2O(fileReader, mh20Header[x * 16 + y], ofsMH2O); } } }
static void ReadMVER(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); adt.Version = fileReader.ReadInt32(); }
static void ReadMDDF(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); var endPos = fileReader.BaseStream.Position + size; while (fileReader.BaseStream.Position < endPos) { var doodadDefinition = new MapDoodadDefinition(); var nameIndex = fileReader.ReadInt32(); doodadDefinition.FilePath = adt.ModelFiles[nameIndex]; // 4 bytes doodadDefinition.UniqueId = fileReader.ReadUInt32(); // 4 bytes var Y = fileReader.ReadSingle(); var Z = fileReader.ReadSingle(); var X = fileReader.ReadSingle(); doodadDefinition.Position = new Vector3(X, Y, Z); // 12 bytes doodadDefinition.OrientationA = fileReader.ReadSingle(); // 4 Bytes doodadDefinition.OrientationB = fileReader.ReadSingle(); // 4 Bytes doodadDefinition.OrientationC = fileReader.ReadSingle(); // 4 Bytes doodadDefinition.Scale = fileReader.ReadUInt16() / 1024f; // 2 bytes doodadDefinition.Flags = fileReader.ReadUInt16(); // 2 bytes adt.DoodadDefinitions.Add(doodadDefinition); } }
static void ReadMHDR(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); adt.Header.Base = (uint)fileReader.BaseStream.Position; var pad = fileReader.ReadUInt32(); adt.Header.offsInfo = fileReader.ReadUInt32(); adt.Header.offsTex = fileReader.ReadUInt32(); adt.Header.offsModels = fileReader.ReadUInt32(); adt.Header.offsModelIds = fileReader.ReadUInt32(); adt.Header.offsMapObjects = fileReader.ReadUInt32(); adt.Header.offsMapObjectIds = fileReader.ReadUInt32(); adt.Header.offsDoodadDefinitions = fileReader.ReadUInt32(); adt.Header.offsObjectDefinitions = fileReader.ReadUInt32(); adt.Header.offsFlightBoundary = fileReader.ReadUInt32(); adt.Header.offsMH2O = fileReader.ReadUInt32(); var pad3 = fileReader.ReadUInt32(); var pad4 = fileReader.ReadUInt32(); var pad5 = fileReader.ReadUInt32(); var pad6 = fileReader.ReadUInt32(); var pad7 = fileReader.ReadUInt32(); }
static void ReadMCNK(BinaryReader br, ADT adt) { for (var i = 0; i < 256; i++) { var chunk = ADTChunkParser.Process(br, adt.MapChunkInfo[i].Offset, adt); adt.MapChunks[chunk.Header.IndexY, chunk.Header.IndexX] = chunk; } }
static void ReadMWID(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); uint count = size / 4; for (int i = 0; i < count; i++) { adt.ObjectFileOffsets.Add(fileReader.ReadInt32()); } }
public static ADTChunk Process(BinaryReader fileReader, uint mcnkOffset, ADT parent) { var chunk = new ADTChunk(); fileReader.BaseStream.Position = mcnkOffset; // Read the header ReadMCNK(fileReader, chunk); if (chunk.Header.offsColorValues != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.offsColorValues; ReadMCCV(fileReader, chunk); } if (chunk.Header.ofsHeight != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsHeight; ReadMCVT(fileReader, chunk); } if (chunk.Header.ofsNormal != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsNormal; ReadMCNR(fileReader, chunk); } if (chunk.Header.ofsLayer != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsLayer; ReadMCLY(fileReader, chunk); } if (chunk.Header.ofsRefs != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsRefs; ReadMCRF(fileReader, chunk); } if (chunk.Header.ofsShadow != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsShadow; ReadMCSH(fileReader, chunk); } if (chunk.Header.ofsAlpha != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsAlpha; ReadMCAL(fileReader, chunk); } if (chunk.Header.ofsSndEmitters != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsSndEmitters; ReadMCSE(fileReader, chunk); } return(chunk); }
static void ReadMWMO(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); long endPos = fileReader.BaseStream.Position + size; while (fileReader.BaseStream.Position < endPos) { if (fileReader.PeekByte() == 0) { fileReader.BaseStream.Position++; } else { adt.ObjectFiles.Add(fileReader.ReadCString()); } } }
static void ReadMCIN(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); adt.MapChunkInfo = new MapChunkInfo[256]; for (var i = 0; i < 256; i++) { var mcin = new MapChunkInfo { Offset = fileReader.ReadUInt32(), Size = fileReader.ReadUInt32(), Flags = fileReader.ReadUInt32(), AsyncId = fileReader.ReadUInt32() }; adt.MapChunkInfo[i] = mcin; } }
static void ReadMODF(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); long endPos = fileReader.BaseStream.Position + size; while (fileReader.BaseStream.Position < endPos) { var objectDef = new MapObjectDefinition(); int nameIndex = fileReader.ReadInt32(); // 4 bytes objectDef.FilePath = adt.ObjectFiles[nameIndex]; objectDef.UniqueId = fileReader.ReadUInt32(); // 4 bytes // This Position appears to be in the wrong order. // To get WoW coords, read it as: {Y, Z, X} var Y = fileReader.ReadSingle(); var Z = fileReader.ReadSingle(); var X = fileReader.ReadSingle(); objectDef.Position = new Vector3(X, Y, Z); // 12 bytes objectDef.OrientationA = fileReader.ReadSingle(); // 4 Bytes objectDef.OrientationB = fileReader.ReadSingle(); // 4 Bytes objectDef.OrientationC = fileReader.ReadSingle(); // 4 Bytes var min = new Vector3(); min.Y = fileReader.ReadSingle(); min.Z = fileReader.ReadSingle(); min.X = fileReader.ReadSingle(); var max = new Vector3(); max.Y = fileReader.ReadSingle(); max.Z = fileReader.ReadSingle(); max.X = fileReader.ReadSingle(); objectDef.Extents = new BoundingBox(min, max); // 12*2 bytes objectDef.Flags = fileReader.ReadUInt16(); // 2 bytes objectDef.DoodadSetId = fileReader.ReadUInt16(); // 2 bytes objectDef.NameSet = fileReader.ReadUInt16(); // 2 bytes fileReader.ReadUInt16(); // padding adt.ObjectDefinitions.Add(objectDef); } }
static void ReadMFBO(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); }
public static ADT Process(MpqManager mpqManager, TileIdentifier tileId) { var fileName = string.Format("{0}\\{0}_{1}_{2}{3}", tileId.MapName, tileId.TileY, tileId.TileX, Extension); var filePath = Path.Combine(baseDir, fileName); var adt = new ADT(tileId); if (!mpqManager.FileExists(filePath)) { log.Error("ADT file does not exist: ", filePath); } using (var stream = mpqManager.OpenFile(filePath)) using (var fileReader = new BinaryReader(stream)) { ReadMVER(fileReader, adt); ReadMHDR(fileReader, adt); if (adt.Header.offsInfo != 0) { fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsInfo; ReadMCIN(fileReader, adt); } //if (adt.Header.offsTex != 0) //{ // fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsTex; // ReadMTEX(fileReader, adt); //} if (adt.Header.offsModels != 0) { fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsModels; ReadMMDX(fileReader, adt); } if (adt.Header.offsModelIds != 0) { fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsModelIds; ReadMMID(fileReader, adt); } if (adt.Header.offsMapObjects != 0) { fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsMapObjects; ReadMWMO(fileReader, adt); } if (adt.Header.offsMapObjectIds != 0) { fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsMapObjectIds; ReadMWID(fileReader, adt); } if (adt.Header.offsDoodadDefinitions != 0) { fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsDoodadDefinitions; ReadMDDF(fileReader, adt); } if (adt.Header.offsObjectDefinitions != 0) { fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsObjectDefinitions; ReadMODF(fileReader, adt); } //if (adt.Header.offsFlightBoundary != 0) //{ // fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsFlightBoundary; // ReadMFBO(fileReader, adt); //} if (adt.Header.offsMH2O != 0) { fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsMH2O; ReadMH2O(fileReader, adt); } ReadMCNK(fileReader, adt); } return(adt); }
static void ReadMTEX(BinaryReader br, ADT adt) { }