Exemplo n.º 1
0
 public static MpqLibrarian GetDefaultFinder(string wowPath)
 {
     if (DefaultLibrarian == null)
     {
         DefaultLibrarian = new MpqLibrarian(DBCTool.FindWowDirOrThrow(wowPath));
     }
     return DefaultLibrarian;
 }
Exemplo n.º 2
0
 public static MpqLibrarian GetDefaultFinder(string wowPath)
 {
     if (DefaultLibrarian == null)
     {
         DefaultLibrarian = new MpqLibrarian(DBCTool.FindWowDirOrThrow(wowPath));
     }
     return(DefaultLibrarian);
 }
Exemplo n.º 3
0
        public static M2Model ReadM2(MpqLibrarian librarian, string filePath)
        {
            if (!librarian.FileExists(filePath))
            {
                var altFilePath = Path.ChangeExtension(filePath, ".m2");
                if (!librarian.FileExists(altFilePath))
                {
                    throw new Exception("File does not exist: " + filePath);
                }

                filePath = altFilePath;
            }

            var model = new M2Model();

            using (var stream = librarian.OpenFile(filePath))
            using (var br = new BinaryReader(stream))
            {
                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;
        }
Exemplo n.º 4
0
        public static M2 ReadM2(MpqLibrarian librarian, MapDoodadDefinition doodadDefinition)
        {
            var model = M2Reader.ReadM2(librarian, doodadDefinition.FilePath, false);

            var tempIndices = new List<int>();
            foreach (var tri in model.BoundingTriangles)
            {
                tempIndices.Add(tri.Index0);
                tempIndices.Add(tri.Index1);
                tempIndices.Add(tri.Index2);
            }

            var currentM2 = TransformM2(model, tempIndices, doodadDefinition);
            currentM2.Bounds = new BoundingBox(currentM2.Vertices.ToArray());

            return currentM2;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets a WMOGroup from the WMO Group file
        /// </summary>
        /// <param name="librarian"></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(MpqLibrarian librarian, string filePath, WMORoot root, int groupIndex)
        {
            if (!librarian.FileExists(filePath))
            {
                log.Error("WMOGroup file does not exist: ", filePath);
            }

            var currentWMOGroup = new WMOGroup(root, groupIndex);

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

            return currentWMOGroup;
        }
Exemplo n.º 6
0
		public static M2 ReadM2(MpqLibrarian librarian, MapDoodadDefinition doodadDefinition)
		{
			var filePath = doodadDefinition.FilePath;
			var ext = Path.GetExtension(filePath);

			if (ext.Equals(".mdx") ||
				ext.Equals(".mdl"))
			{
				filePath = Path.ChangeExtension(filePath, ".m2");
			}

			var model = M2Reader.ReadM2(librarian, doodadDefinition.FilePath);

			var tempIndices = new List<int>();
			foreach (var tri in model.BoundingTriangles)
			{
				tempIndices.Add(tri.Index2);
				tempIndices.Add(tri.Index1);
				tempIndices.Add(tri.Index0);
			}

			var currentM2 = TransformM2(model, tempIndices, doodadDefinition);
			var tempVertices = currentM2.Vertices;
			var bounds = new BoundingBox(tempVertices.ToArray());
			currentM2.Bounds = bounds;

			return currentM2;
		}
Exemplo n.º 7
0
 public static bool TryGetADTPath(MapId mapId, int x, int y, out string filePath, MpqLibrarian mpqFinder)
 {
     filePath = GetFilename(mapId, x, y);
     if (!mpqFinder.FileExists(filePath))
     {
         return false;
     }
     return true;
 }
Exemplo n.º 8
0
 public static bool TryGetADTPath(MapId mapId, int x, int y, out string filePath, out MpqLibrarian mpqFinder)
 {
     mpqFinder = WCellTerrainSettings.GetDefaultMPQFinder();
     filePath = GetFilename(mapId, x, y);
     if (!mpqFinder.FileExists(filePath))
     {
         return false;
     }
     return true;
 }
Exemplo n.º 9
0
		/// <summary>
		/// Adds a WMO to the manager
		/// </summary>
		public static WMORoot ReadWMO(MpqLibrarian librarian, MapObjectDefinition currentMODF)
		{
			// Parse the WMORoot
			var wmoRoot = WMOReader.ReadWMO(librarian, currentMODF.FilePath);

			// Parse the WMOGroups
			for (var wmoGroup = 0; wmoGroup < wmoRoot.Header.GroupCount; wmoGroup++)
			{
				var newFile = wmoRoot.FilePath.Substring(0, wmoRoot.FilePath.LastIndexOf('.'));
				var currentFilePath = String.Format("{0}_{1:000}.wmo", newFile, wmoGroup);

				var group = WMOGroupReader.Process(librarian, currentFilePath, wmoRoot, wmoGroup);

				wmoRoot.Groups[wmoGroup] = group;
			}

			//wmoRoot.DumpLiqChunks();

			// Parse in the WMO's M2s
			var curDoodadSet = currentMODF.DoodadSetId;

			var setIndices = new List<int> { 0 };
			if (curDoodadSet > 0) setIndices.Add(curDoodadSet);

			foreach (var index in setIndices)
			{
				var doodadSetOffset = wmoRoot.DoodadSets[index].FirstInstanceIndex;
				var doodadSetCount = wmoRoot.DoodadSets[index].InstanceCount;
				wmoRoot.WMOM2s = new M2[(int)doodadSetCount];
				for (var i = doodadSetOffset; i < (doodadSetOffset + doodadSetCount); i++)
				{
					var curDoodadDef = wmoRoot.DoodadDefinitions[i];
					var curM2 = M2Reader.ReadM2(librarian, curDoodadDef.FilePath);

					var tempIndices = new List<int>();
					for (var j = 0; j < curM2.BoundingTriangles.Length; j++)
					{
						var tri = curM2.BoundingTriangles[j];

						tempIndices.Add(tri.Index2);
						tempIndices.Add(tri.Index1);
						tempIndices.Add(tri.Index0);
					}

					var rotatedM2 = TransformWMOM2(curM2, tempIndices, curDoodadDef);
					wmoRoot.WMOM2s[i - doodadSetOffset] = rotatedM2;
				}
			}

			TransformWMO(currentMODF, wmoRoot);

			var bounds = new BoundingBox(wmoRoot.WmoVertices);
			wmoRoot.Bounds = bounds;
			return wmoRoot;
		}
Exemplo n.º 10
0
        public static WMORoot ReadWMO(MpqLibrarian mpqLibrarian, string filePath)
        {
            var root = new WMORoot(filePath);

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

            using (var stream = mpqLibrarian.OpenFile(filePath))
            using (var fileReader = new BinaryReader(stream))
            {
                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;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Adds a WMO to the manager
        /// </summary>
        public static WMORoot ReadWMO(MpqLibrarian librarian, MapObjectDefinition currentMODF)
        {
            // Parse the WMORoot
            var wmoRoot = WMOReader.ReadWMO(librarian, currentMODF.FilePath);

            if (wmoRoot == null) return null;

            // Parse the WMOGroups
            for (var wmoGroup = 0; wmoGroup < wmoRoot.Header.GroupCount; wmoGroup++)
            {
                var newFile = wmoRoot.FilePath.Substring(0, wmoRoot.FilePath.LastIndexOf('.'));
                var currentFilePath = String.Format("{0}_{1:000}.wmo", newFile, wmoGroup);

                var group = WMOGroupReader.Process(librarian, currentFilePath, wmoRoot, wmoGroup);

                wmoRoot.Groups[wmoGroup] = group;
            }

            //wmoRoot.DumpLiqChunks();

            // Parse in the WMO's M2s
            var curDoodadSet = currentMODF.DoodadSetId;

            var setIndices = new List<int> { 0 };
            if (curDoodadSet > 0) setIndices.Add(curDoodadSet);
            var setDefs = new List<DoodadSet>(setIndices.Count);
            foreach (var index in setIndices)
            {
                if (index >= wmoRoot.DoodadSets.Length)
                {
                    log.Error("Invalid index {0} into wmoRoot.DoodadSet array with id", index, curDoodadSet);
                    continue;
                }
                setDefs.Add(wmoRoot.DoodadSets[index]);
            }

            var m2List = new List<M2>();
            foreach (var def in setDefs)
            {
                var doodadSetOffset = def.FirstInstanceIndex;
                var doodadSetCount = def.InstanceCount;
                for (var i = doodadSetOffset; i < (doodadSetOffset + doodadSetCount); i++)
                {
                    var curDoodadDef = wmoRoot.DoodadDefinitions[i];
                    if (string.IsNullOrEmpty(curDoodadDef.FilePath))
                    {
                        log.Error("Encountered Doodad with empty file path");
                        continue;
                    }
                    var curM2 = M2Reader.ReadM2(librarian, curDoodadDef.FilePath, true);

                    var tempIndices = new List<int>();
                    for (var j = 0; j < curM2.BoundingTriangles.Length; j++)
                    {
                        var tri = curM2.BoundingTriangles[j];

                        tempIndices.Add(tri.Index2);
                        tempIndices.Add(tri.Index1);
                        tempIndices.Add(tri.Index0);
                    }

                    var rotatedM2 = TransformWMOM2(curM2, tempIndices, curDoodadDef);
                    m2List.Add(rotatedM2);
                }
            }

            wmoRoot.WMOM2s = m2List.ToArray();
            TransformWMO(currentMODF, wmoRoot);

            var bounds = new BoundingBox(wmoRoot.WmoVertices);
            wmoRoot.Bounds = bounds;
            return wmoRoot;
        }