Ejemplo n.º 1
0
        static void ReadMHDR(BinaryReader fileReader, ADTFile 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();
        }
Ejemplo n.º 2
0
        static void ReadMVER(BinaryReader fileReader, ADTFile adt)
        {
            var type = fileReader.ReadUInt32();
            var size = fileReader.ReadUInt32();

            adt.Version = fileReader.ReadInt32();
        }
Ejemplo n.º 3
0
        static void ReadMH2O(BinaryReader fileReader, ADTFile adt)
        {
            var sig  = fileReader.ReadUInt32();
            var size = fileReader.ReadUInt32();

            var ofsMH2O    = fileReader.BaseStream.Position;
            var mh2oHeader = new MH2OHeader[256];

            for (var i = 0; i < 256; i++)
            {
                mh2oHeader[i] = new MH2OHeader {
                    ofsData1   = fileReader.ReadUInt32(),
                    LayerCount = fileReader.ReadUInt32(),
                    ofsData2   = fileReader.ReadUInt32()
                };
            }

            for (var y = 0; y < 16; y++)
            {
                for (var x = 0; x < 16; x++)
                {
                    adt.LiquidMaps[x, y] = ProcessMH2O(fileReader, mh2oHeader[y * 16 + x], ofsMH2O);
                }
            }
        }
Ejemplo n.º 4
0
        static void ReadMCNKs(BinaryReader br, ADTFile adt)
        {
            for (var i = 0; i < 256; i++)
            {
                var chunk = ProcessChunk(br, adt.MapChunkInfo[i].Offset);
                adt.MapChunks[chunk.IndexX, chunk.IndexY] = chunk;

                if (chunk.ofsHeight != 0)
                {
                    adt.HeightMaps[chunk.IndexX, chunk.IndexY] = ProcessHeights(br, adt.MapChunkInfo[i].Offset + chunk.ofsHeight);
                }
            }
        }
Ejemplo n.º 5
0
        static void ReadMCIN(BinaryReader fileReader, ADTFile 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;
            }
        }
Ejemplo n.º 6
0
        public static ADTFile Process(MpqManager manager, string dataDirectory, string adtName)
        {
            var adtFilePath = Path.Combine(dataDirectory, adtName + ".adt");

            if (!manager.FileExists(adtFilePath))
            {
                return(null);
            }

            var fileReader = new BinaryReader(manager.OpenFile(adtFilePath));
            var adt        = new ADTFile()
            {
                Name = adtName,
                Path = dataDirectory
            };

            ReadMVER(fileReader, adt);
            ReadMHDR(fileReader, adt);

            if (adt.Header.offsInfo != 0)
            {
                fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsInfo;
                ReadMCIN(fileReader, adt);
            }

            ReadMCNKs(fileReader, adt);

            if (adt.Header.offsMH2O != 0)
            {
                fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsMH2O;
                ReadMH2O(fileReader, adt);
            }

            fileReader.Close();

            return(adt);
        }
Ejemplo n.º 7
0
        static void ReadMCNKs(BinaryReader br, ADTFile adt)
        {
            for (var i = 0; i < 256; i++)
            {
                var chunk = ProcessChunk(br, adt.MapChunkInfo[i].Offset);
                adt.MapChunks[chunk.IndexX, chunk.IndexY] = chunk;

                if (chunk.ofsHeight != 0)
                {
                    adt.HeightMaps[chunk.IndexX, chunk.IndexY] = ProcessHeights(br, adt.MapChunkInfo[i].Offset + chunk.ofsHeight);
                }
            }
        }
Ejemplo n.º 8
0
        static void ReadMCIN(BinaryReader fileReader, ADTFile 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;
            }
        }
Ejemplo n.º 9
0
        static void ReadMHDR(BinaryReader fileReader, ADTFile 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();
        }
Ejemplo n.º 10
0
        static void ReadMVER(BinaryReader fileReader, ADTFile adt)
        {
            var type = fileReader.ReadUInt32();
            var size = fileReader.ReadUInt32();

            adt.Version = fileReader.ReadInt32();
        }
Ejemplo n.º 11
0
        public static ADTFile Process(MpqManager manager, string dataDirectory, string adtName)
        {
            var adtFilePath = Path.Combine(dataDirectory, adtName + ".adt");
            if (!manager.FileExists(adtFilePath)) return null;

            var fileReader = new BinaryReader(manager.OpenFile(adtFilePath));
            var adt = new ADTFile() {
                Name = adtName,
                Path = dataDirectory
            };

            ReadMVER(fileReader, adt);
            ReadMHDR(fileReader, adt);
            
            if (adt.Header.offsInfo != 0)
            {
                fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsInfo;
                ReadMCIN(fileReader, adt);
            }
            
            ReadMCNKs(fileReader, adt);
            
            if (adt.Header.offsMH2O != 0)
            {
                fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsMH2O;
                ReadMH2O(fileReader, adt);
            }

            fileReader.Close();

            return adt;

        }
Ejemplo n.º 12
0
        private static TileModels ExtractTileM2s(int tileX, int tileY, ADTFile adt)
        {
            var LoadedWMOIds = new List<uint>();
            var list = adt.DoodadDefinitions;

            var tileModels = new TileModels
            {
                Models = new List<TileModel>(list.Count)
            };

            foreach (var definition in list)
            {
                if (LoadedM2Ids.Contains(definition.UniqueId)) continue;
                if (string.IsNullOrEmpty(definition.FilePath)) continue;

                var model = ExtractModel(definition);

                if (model.Vertices.Length < 1) continue;
                tileModels.Models.Add(model);

                LoadedM2Ids.AddUnique(definition.UniqueId);
            }

            var wmoList = adt.ObjectDefinitions;
            foreach (var wmo in wmoList)
            {
                if (LoadedWMOIds.Contains(wmo.UniqueId)) continue;

                var worldPos = new Vector3(TerrainConstants.CenterPoint - wmo.Position.X,
                                           wmo.Position.Y,
                                           TerrainConstants.CenterPoint - wmo.Position.Z);
                worldPos = CorrectWMOOrigin(worldPos);

                // If this WMO belongs to another tile, skip it.
                var wmoTileX = (int)((TerrainConstants.CenterPoint - worldPos.Y) / TerrainConstants.TileSize);
                var wmoTileY = (int)((TerrainConstants.CenterPoint - worldPos.X) / TerrainConstants.TileSize);
                if (wmoTileX != tileX || wmoTileY != tileY) continue;

                var filePath = wmo.FileName;
                var root = WMORootParser.Process(manager, filePath);

                ExtractWMOM2s(wmo, root, tileModels);
                LoadedWMOIds.AddUnique(wmo.UniqueId);
            }

            return tileModels;
        }
Ejemplo n.º 13
0
		public static FluidType[,] ExtractTileLiquidTypes(ADTFile adt)
		{
			var types = new FluidType[TerrainConstants.ChunksPerTileSide, TerrainConstants.ChunksPerTileSide];
			for (var y = 0; y < TerrainConstants.ChunksPerTileSide; y++)
			{
				for (var x = 0; x < TerrainConstants.ChunksPerTileSide; x++)
				{
					if (adt.LiquidMaps[x, y] == null)
					{
						types[x, y] = FluidType.None;
						continue;
					}
					types[x, y] = adt.LiquidMaps[x, y].Type;
				}
			}
			return types;
		}
Ejemplo n.º 14
0
		public static HeightMap[,] ExtractTileHeightMaps(ADTFile adt)
		{
			var maps = new HeightMap[TerrainConstants.ChunksPerTileSide, TerrainConstants.ChunksPerTileSide];

			for (var y = 0; y < TerrainConstants.ChunksPerTileSide; y++)
			{
				for (var x = 0; x < TerrainConstants.ChunksPerTileSide; x++)
				{
					var chunk = adt.MapChunks[x, y];
					var heights = adt.HeightMaps[x, y].Heights;
					var liq = adt.LiquidMaps[x, y];

					var heightMap = new HeightMap
					{
						MedianHeight = chunk.Y
					};

					// Read in Outer Heights
					for (var row = 0; row < 17; row += 2)
					{
						if (row % 2 != 0) continue;
						for (var col = 0; col < 9; col++)
						{
							var count = ((row / 2) * 9) + ((row / 2) * 8) + col;
							heightMap.OuterHeightDiff[row / 2, col] = heights[count];
						}
					}

					// Read in Inner Heights
					for (var row = 1; row < 16; row++)
					{
						if (row % 2 != 1) continue;
						for (var col = 0; col < 8; col++)
						{
							var count = (((row + 1) / 2) * 9) + ((row / 2) * 8) + col;
							heightMap.InnerHeightDiff[row / 2, col] = heights[count];
						}
					}

					// Read in Liquid Heights
					if (liq != null && (liq.Used && liq.Heights != null))
					{
						for (var row = 0; row < 9; row++)
						{
							for (var col = 0; col < 9; col++)
							{
								if (row < liq.YOffset || row > (liq.YOffset + liq.Height) ||
									col < liq.XOffset || col > (liq.XOffset + liq.Width))
								{
									heightMap.LiquidHeight[row, col] = float.MinValue;
									continue;
								}

								var oldRow = row - liq.YOffset;
								var oldCol = col - liq.XOffset;
								heightMap.LiquidHeight[row, col] = liq.Heights[oldRow, oldCol];
							}
						}
					}

					maps[x, y] = heightMap;
				}
			}

			return maps;
		}
Ejemplo n.º 15
0
        static void ReadMH2O(BinaryReader fileReader, ADTFile adt)
        {
            var sig = fileReader.ReadUInt32();
            var size = fileReader.ReadUInt32();

            var ofsMH2O = fileReader.BaseStream.Position;
            var mh2oHeader = new MH2OHeader[256];

            for (var i = 0; i < 256; i++)
            {
                mh2oHeader[i] = new MH2OHeader {
                    ofsData1 = fileReader.ReadUInt32(),
                    LayerCount = fileReader.ReadUInt32(),
                    ofsData2 = fileReader.ReadUInt32()
                };
            }

            for (var y = 0; y < 16; y++)
            {
                for (var x = 0; x < 16; x++)
                {
                    adt.LiquidMaps[x, y] = ProcessMH2O(fileReader, mh2oHeader[y * 16 + x], ofsMH2O);
                }
            }
        }
Ejemplo n.º 16
0
        private static TileModels ExtractTileM2s(int tileX, int tileY, ADTFile adt)
        {
            var LoadedWMOIds = new List <uint>();
            var list         = adt.DoodadDefinitions;

            var tileModels = new TileModels
            {
                Models = new List <TileModel>(list.Count)
            };

            foreach (var definition in list)
            {
                if (LoadedM2Ids.Contains(definition.UniqueId))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(definition.FilePath))
                {
                    continue;
                }

                var model = ExtractModel(definition);

                if (model.Vertices.Length < 1)
                {
                    continue;
                }
                tileModels.Models.Add(model);

                LoadedM2Ids.AddUnique(definition.UniqueId);
            }

            var wmoList = adt.ObjectDefinitions;

            foreach (var wmo in wmoList)
            {
                if (LoadedWMOIds.Contains(wmo.UniqueId))
                {
                    continue;
                }

                var worldPos = new Vector3(TerrainConstants.CenterPoint - wmo.Position.X,
                                           wmo.Position.Y,
                                           TerrainConstants.CenterPoint - wmo.Position.Z);
                worldPos = CorrectWMOOrigin(worldPos);

                // If this WMO belongs to another tile, skip it.
                var wmoTileX = (int)((TerrainConstants.CenterPoint - worldPos.Y) / TerrainConstants.TileSize);
                var wmoTileY = (int)((TerrainConstants.CenterPoint - worldPos.X) / TerrainConstants.TileSize);
                if (wmoTileX != tileX || wmoTileY != tileY)
                {
                    continue;
                }

                var filePath = wmo.FileName;
                var root     = WMORootParser.Process(manager, filePath);

                ExtractWMOM2s(wmo, root, tileModels);
                LoadedWMOIds.AddUnique(wmo.UniqueId);
            }

            return(tileModels);
        }
Ejemplo n.º 17
0
		public static bool[,] ExtractTileLiquidProfile(ADTFile adt)
		{
			var profile = new bool[TerrainConstants.ChunksPerTileSide, TerrainConstants.ChunksPerTileSide];
			for (var y = 0; y < TerrainConstants.ChunksPerTileSide; y++)
			{
				for (var x = 0; x < TerrainConstants.ChunksPerTileSide; x++)
				{
					if (adt.LiquidMaps[x, y] == null)
					{
						profile[x, y] = false;
						continue;
					}
					profile[x, y] = adt.LiquidMaps[x, y].Used;
				}
			}
			return profile;
		}