예제 #1
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;
        }
예제 #2
0
파일: ADTParser.cs 프로젝트: pallmall/WCell
		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;
			}
		}
예제 #3
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;
        }
예제 #4
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;
        }
예제 #5
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;
        }
예제 #6
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;
        }
예제 #7
0
파일: ZoneGrid.cs 프로젝트: pallmall/WCell
        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;

        }