示例#1
0
        public static M2Model ReadM2(MpqLibrarian librarian, string filePath, bool isWMOM2)
        {
            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, isWMOM2);
                    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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
            }
            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);
        }
示例#5
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);
        }
示例#6
0
 public static MpqLibrarian GetDefaultMPQFinder()
 {
     return(MpqLibrarian.GetDefaultFinder(WoWPath));
 }
示例#7
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);
 }
示例#8
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);
 }