示例#1
0
		public static void WriteM2Files()
		{
			log.Info("Extracting partial M2 world objects - This might take a few minutes.....");
			var startTime = DateTime.Now;
			var wowRootDir = ToolConfig.Instance.GetWoWDir();
			var outputDir = ToolConfig.M2Dir;

			manager = new MpqManager(wowRootDir);

			var entryList = DBCMapReader.GetMapEntries();
			if (entryList == null)
			{
				log.Error("Could not retrieve MapEntries.");
				return;
			}

			foreach (var mapEntry in entryList)
			{
				//if (mapEntry.Id != (int)MapId.EasternKingdoms) continue;

				var dir = mapEntry.MapDirName;
				var wdtDir = Path.Combine(baseDir, dir);
				var wdtName = dir;

				var wdt = WDTParser.Process(manager, wdtDir, wdtName);
				if (wdt == null) continue;

				var regionM2s = ExtractRegionM2s(wdt);

				var count = 0;
				var max = regionM2s.HasTiles ? TerrainConstants.TilesPerMapSide : 1;
				for (var tileY = 0; tileY < max; tileY++)
				{
					for (var tileX = 0; tileX < max; tileX++)
					{
						//if (tileX != 36) continue;
						//if (tileY != 49) continue;

						if (regionM2s.ObjectsByTile[tileX, tileY] == null) continue;

						// Don't bother writing tiles with no models.
						var tileModels = regionM2s.ObjectsByTile[tileX, tileY];
						if (tileModels.Models.Count == 0) continue;

						var path = Path.Combine(outputDir, mapEntry.Id.ToString());
						if (!Directory.Exists(path))
							Directory.CreateDirectory(path);
						var file = File.Create(Path.Combine(path, TerrainConstants.GetM2File(tileX, tileY)));

						WriteTileM2s(file, tileModels);
						count++;
						file.Close();
					}
				}
				log.Info(count);
			}

			log.Info("Done ({0})", DateTime.Now - startTime);

		}
示例#2
0
        /// <summary>
        /// Starts processing all WDT and ADT files
        /// </summary>
        public static void ProcessAll()
        {
            if (Parsed == null)
            {
                throw new Exception("WDTExtractor.Parsed must be set before calling WDTExtractor.Process");
            }

            var wowRootDir = DBCTool.FindWowDir();
            MpqManager = new MpqManager(wowRootDir);
            var entryList = GetMapEntries();

            WDTParser.MpqManager = MpqManager;
            foreach (var mapEntry in entryList)
            {
                //if (mapEntry.Id != MapId.EasternKingdoms) continue;
                var wdt = WDTParser.Process(mapEntry);
                if (wdt == null) continue;

                var path = Path.Combine(TerrainDisplayConfig.MapDir, wdt.Entry.Id.ToString());
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                var filePath = Path.Combine(path, string.Format("{0}{1}", wdt.Entry.Id, Extension));
                using (var file = File.Create(filePath))
                {
                    WriteWdt(file, wdt);
                    file.Close();
                }
                Parsed(wdt);
            }
        }
示例#3
0
        public MpqTerrainManager(TileIdentifier tileId)
        {
            var wowRootDir = DBCTool.FindWowDir();
            MpqManager = new MpqManager(wowRootDir);
            TileId = tileId;

            var entries = GetMapEntries();
            MapInfo entry = null;
            foreach (var item in entries)
            {
                if (item.Id != tileId.MapId) continue;

                entry = item;
                break;
            }

            WDTParser.MpqManager = MpqManager;
            _wdt = WDTParser.Process(entry);

            _adtManager = new ADTManager(this);
            _wmoManager = new WMOManager();
            _m2Manager = new M2Manager();
            _meshManager = new NavMeshManager();
            _selectedTriangleManager = new SelectedTriangleManager(_adtManager);
        }
示例#4
0
        public static M2Model Process(MpqManager mpqManager, string filePath)
        {
            if (!mpqManager.FileExists(filePath))
            {
                var altFilePath = Path.ChangeExtension(filePath, ".m2");
                if (!mpqManager.FileExists(altFilePath))
                {
                    log.Error("M2 file does not exist: ", altFilePath);
                }

                filePath = altFilePath;
            }

            var model = new M2Model();

            using (var br = new BinaryReader(mpqManager.OpenFile(filePath)))
            {
                ReadHeader(br, model);
                ReadGlobalSequences(br, model);
                ReadAnimations(br, model);
                ReadAnimationLookup(br, model);
                ReadBones(br, model);
                ReadKeyBoneLookup(br, model);
                ReadVertices(br, model);
                ReadColors(br, model);
                ReadTextures(br, model);
                ReadTransparency(br, model);
                ReadUVAnimation(br, model);
                ReadTexReplace(br, model);
                ReadRenderFlags(br, model);
                ReadBoneLookupTable(br, model);
                ReadTexLookup(br, model);
                ReadTexUnits(br, model);
                ReadTransLookup(br, model);
                ReadUVAnimLookup(br, model);
                ReadBoundingTriangles(br, model);
                ReadBoundingVertices(br, model);
                ReadBoundingNormals(br, model);
                ReadAttachments(br, model);
                ReadAttachLookups(br, model);
                ReadEvents(br, model);
                ReadLights(br, model);
                ReadCameras(br, model);
                ReadCameraLookup(br, model);
                ReadRibbonEmitters(br, model);
                ReadParticleEmitters(br, model);

                if (model.Header.HasUnknownFinalPart)
                {
                    ReadOptionalSection(br, model);
                }
            }

            model.FilePath = filePath;
            return model;
        }
示例#5
0
文件: WDTParser.cs 项目: NVN/WCell
        /// <summary>
        /// Starts processing all WDT and ADT files
        /// </summary>
        public static void ProcessAll()
        {
            var wowRootDir = ToolConfig.Instance.GetWoWDir();
            MpqManager = new MpqManager(wowRootDir);
            var entryList = DBCMapReader.GetMapEntries();

            foreach (var mapEntry in entryList)
            {
                //if (mapEntry.Id != (int)MapId.EasternKingdoms) continue;
                Process(mapEntry);
            }
        }
示例#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;

			using (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);
				}
				if (adt.Header.offsModels != 0)
				{
					fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsModels;
					ReadMMDX(fileReader, adt);
				}
				if (adt.Header.offsMapObjects != 0)
				{
					fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsMapObjects;
					ReadMWMO(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.offsMH2O != 0)
				{
					fileReader.BaseStream.Position = adt.Header.Base + adt.Header.offsMH2O;
					ReadMH2O(fileReader, adt);
				}

				ReadMCNKs(fileReader, adt);

				return adt;
			}
		}
示例#7
0
        public static M2Model Process(MpqManager manager, string fileName)
        {
            if (!manager.FileExists(fileName))
            {
                throw new Exception("File does not exist: " + fileName);
            }

            var model = new M2Model();

            using (var fs = manager.OpenFile(fileName))
            using (var br = new BinaryReader(fs))
            {
                ReadHeader(br, model);
                ReadGlobalSequences(br, model);
                ReadAnimations(br, model);
                ReadAnimationLookup(br, model);
                ReadBones(br, model);
                ReadKeyBoneLookup(br, model);
                ReadVertices(br, model);
                ReadColors(br, model);
                ReadTextures(br, model);
                ReadTransparency(br, model);
                ReadUVAnimation(br, model);
                ReadTexReplace(br, model);
                ReadRenderFlags(br, model);
                ReadBoneLookupTable(br, model);
                ReadTexLookup(br, model);
                ReadTexUnits(br, model);
                ReadTransLookup(br, model);
                ReadUVAnimLookup(br, model);
                ReadBoundingTriangles(br, model);
                ReadBoundingVertices(br, model);
                ReadBoundingNormals(br, model);
                ReadAttachments(br, model);
                ReadAttachLookups(br, model);
                ReadEvents(br, model);
                ReadLights(br, model);
                ReadCameras(br, model);
                ReadCameraLookup(br, model);
                ReadRibbonEmitters(br, model);
                ReadParticleEmitters(br, model);

                if (model.Header.HasUnknownFinalPart)
                {
                    ReadOptionalSection(br, model);
                }
            }

            return model;
        }
示例#8
0
        /// <summary>
        /// Gets a WMOGroup from the WMO Group file
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="filePath">File path to the WMOGroup</param>
        /// <param name="root"></param>
        /// <param name="groupIndex">Current index in the WMO Group</param>
        /// <returns>A WMOGroup from the WMO Group file</returns>
        public static WMOGroup Process(MpqManager manager, string filePath, WMORoot root, int groupIndex)
        {
            if (!manager.FileExists(filePath))
            {
                log.Error("WMOGroup file does not exist: ", filePath);
            }

            var currentWMOGroup = new WMOGroup(root, groupIndex);

            using (var stream = manager.OpenFile(filePath))
            using (var br = new BinaryReader(stream))
            {
                ReadRequiredChunks(br, currentWMOGroup);
                ReadOptionalChunks(br, currentWMOGroup);
            }

            return currentWMOGroup;
        }
示例#9
0
        private static void LoadWMO(MpqManager manager, MapObjectDefinition def)
	    {
	        if (LoadedWmoIds.Contains(def.UniqueId)) return;
            LoadedWmoIds.Add(def.UniqueId);

	        if (!WorldObjectExtractor.LoadedWMORoots.ContainsKey(def.FilePath))
	        {
	            var root = WMORootParser.Process(manager, def.FilePath);
	            WorldObjectExtractor.LoadedWMORoots.Add(def.FilePath, root);
	        }

	        PrepareWMOInfo(def);
	    }
示例#10
0
	    private static void PrepareChunkInfo(MpqManager manager, ADT adt)
	    {
            for (var chunkX = 0; chunkX < TerrainConstants.ChunksPerTileSide; chunkX++)
            {
                for (var chunkY = 0; chunkY < TerrainConstants.ChunksPerTileSide; chunkY++)
                {
                    var chunk = adt.MapChunks[chunkY, chunkX];
                    foreach (var dRefId in chunk.DoodadRefs)
                    {
                        var dRef = adt.DoodadDefinitions[dRefId];
                        if (dRef == null) continue;
                        if (ModelsToIgnore.Contains(dRef.FilePath)) continue;
                        if (LoadedM2Ids.Contains(dRef.UniqueId)) continue;

                        M2Model model;
                        if (!WorldObjectExtractor.LoadedM2Models.TryGetValue(dRef.FilePath, out model))
                        {
                            model = M2ModelParser.Process(manager, dRef.FilePath);
                            WorldObjectExtractor.LoadedM2Models.Add(dRef.FilePath, model);
                        }

                        // This model may have no collision information. If so there is no point saving the data.
                        if (model.BoundingVertices.IsNullOrEmpty())
                        {
                            // This model has no collision information. We'll ignore it.
                            ModelsToIgnore.Add(dRef.FilePath);
                            WorldObjectExtractor.LoadedM2Models.Remove(dRef.FilePath);
                        }

                        // At this point, we're using the model for collision stuff
                        PrepareM2Info(dRef, model);
                        LoadedM2Ids.Add(dRef.UniqueId);
                    }

                    foreach (var oRefId in chunk.ObjectRefs)
                    {
                        var oRef = adt.ObjectDefinitions[oRefId];
                        if (oRef == null) continue;
                        LoadWMO(manager, oRef);
                    }

                    PrepareChunk(adt, chunkX, chunkY);
                }
            }
	    }
示例#11
0
文件: ADTParser.cs 项目: Jeroz/WCell
        public static ADT Process(MpqManager mpqManager, DBCMapEntry mapId, int tileX, int tileY)
        {
            var fileName = string.Format("{0}\\{0}_{1}_{2}{3}", mapId.MapDirName, tileY, tileX, Extension);
            var filePath = Path.Combine(baseDir, fileName);
            var adt = new ADT(fileName);

            if (!mpqManager.FileExists(filePath))
            {
                log.Error("ADT file does not exist: ", filePath);
            }
            var fileReader = new BinaryReader(mpqManager.OpenFile(filePath));

            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);

            fileReader.Close();

            return adt;
        }
示例#12
0
        public static WMORoot Process(MpqManager mpqManager, string filePath)
        {
            var root = new WMORoot(filePath);

            if (!mpqManager.FileExists(filePath))
            {
                log.Error("WMO file does not exist: ", filePath);
            }

            using (var file = mpqManager.OpenFile(filePath))
            using (var fileReader = new BinaryReader(file))
            {
                uint type = 0;
                uint size = 0;
                long curPos = AdvanceToNextChunk(fileReader, 0, ref type, ref size);

                if (type == Signatures.MVER)
                {
                    // Version
                    ReadMVER(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MVER");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOHD)
                {
                    // Root Header
                    ReadMOHD(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOHD");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOTX)
                {
                    // Texture Names
                    ReadMOTX(fileReader, root, size);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOTX");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOMT)
                {
                    // Materials
                    ReadMOMT(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOMT");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOGN)
                {
                    ReadMOGN(fileReader, root, size);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOGN");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOGI)
                {
                    // Group Information
                    ReadMOGI(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOGI");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOSB)
                {
                    // Skybox (always 0 now, its no longer handled in WMO)
                    ReadMOSB(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOSB");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOPV)
                {
                    // Portal Vertices
                    ReadMOPV(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOPV");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOPT)
                {
                    // Portal Information
                    ReadMOPT(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOPT");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOPR)
                {
                    // Portal Relations
                    ReadMOPR(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOPR");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOVV)
                {
                    // Visible Vertices
                    ReadMOVV(fileReader, root, size);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOVV");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOVB)
                {
                    // Visible Blocks
                    ReadMOVB(fileReader, root, size);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOVB");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MOLT)
                {
                    // Lights
                    ReadMOLT(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MOLT");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MODS)
                {
                    // Doodad Set
                    ReadMODS(fileReader, root);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MODS");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MODN)
                {
                    // Doodad Names
                    ReadMODN(fileReader, root, size);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MODN");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MODD)
                {
                    // Doodad Definitions
                    ReadMODD(fileReader, root, size);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MODD");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                if (type == Signatures.MFOG)
                {
                    // Fog info
                    ReadMFOG(fileReader, root, size);
                }
                else
                {
                    Console.WriteLine("WMO Root missing required chunk MFOG");
                }
                curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);

                // Theres only 1 optional chunk in a WMO root
                if (fileReader.BaseStream.Position < fileReader.BaseStream.Length)
                {
                    if (type == Signatures.MCVP)
                    {
                        ReadMCVP(fileReader, root, size);
                    }

                    //curPos = AdvanceToNextChunk(fileReader, curPos, ref type, ref size);
                }

            }


            return root;
        }
示例#13
0
        public static ZoneTileSet[] GetZoneTileSets()
        {
            var wowRootDir = DBCTool.FindWowDir(null);
            manager = new MpqManager(wowRootDir);

            var entryList = GetMapEntries();
            if (entryList == null)
            {
                Console.WriteLine("Error retrieving Map Entries.");
                return null;
            }

			var tiles = new ZoneTileSet[(int)MapId.End];
			var count = 0;

            foreach (var dbcMapEntry in entryList)
            {
                var dir = dbcMapEntry.MapDirName;
                var wdtDir = Path.Combine(baseDir, dir);
                var wdtName = dir;

                var wdt = RegionBoundaries.Process(manager, wdtDir, wdtName + ".wdt");
                if (wdt == null) continue;

                if ((wdt.Header.Header1 & WDTFlags.GlobalWMO) == 0)
                {
                    var tileSet = new ZoneTileSet();

                    // Read in the Tiles
                    for (var y = 0; y < 64; y++)
                    {
                        for (var x = 0; x < 64; x++)
                        {
                            if (!wdt.TileProfile[x, y]) continue;
                        	++count;
                            var adtName = string.Format("{0}_{1:00}_{2:00}", wdtName, x, y);
                            var adt = Process(manager, wdtDir, adtName);
                            if (adt == null) continue;

                            // Read in the TileChunks 
                            for (var j = 0; j < 16; j++)
                            {
                                for (var i = 0; i < 16; i++)
                                {
                                    var areaId = adt.MapChunks[i, j].AreaId;
									tileSet.ZoneGrids[x, y].ZoneIds[i, j] = (ZoneId)areaId;
                                }
                            }
                        }
                    }

                    tiles[dbcMapEntry.Id] = tileSet;
                }
				else
                {
                	log.Info("Could not read Zones from WMO: " + (MapId)dbcMapEntry.Id);
                }
            }

        	log.Info("Exported {0} ZoneTileSets.", count);

            return tiles;
        }
示例#14
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;

        }