示例#1
0
        public bool Init(uint mapId)
        {
            FilenameChunk mwmo = GetChunk("MWMO")?.As <FilenameChunk>();

            if (mwmo != null && mwmo.Filenames.Count > 0)
            {
                foreach (var filename in mwmo.Filenames)
                {
                    wmoInstanceNames.Add(filename);
                    VmapFile.ExtractSingleWmo(filename);
                }
            }

            MODF wmoChunk = GetChunk("MODF")?.As <MODF>();

            if (wmoChunk != null && wmoChunk.MapObjDefs.Length > 0)
            {
                foreach (var wmo in wmoChunk.MapObjDefs)
                {
                    if (wmo.Flags.HasAnyFlag(MODFFlags.EntryIsFileID))
                    {
                        string fileName = $"FILE{wmo.Id:X8}.xxx";
                        VmapFile.ExtractSingleWmo(fileName);
                        WMORoot.Extract(wmo, fileName, false, mapId, mapId, Program.DirBinWriter, null);

                        if (VmapFile.WmoDoodads.ContainsKey(fileName))
                        {
                            Model.ExtractSet(VmapFile.WmoDoodads[fileName], wmo, false, mapId, mapId, Program.DirBinWriter, null);
                        }
                    }
                    else
                    {
                        WMORoot.Extract(wmo, wmoInstanceNames[(int)wmo.Id], false, mapId, mapId, Program.DirBinWriter, null);
                        if (VmapFile.WmoDoodads.ContainsKey(wmoInstanceNames[(int)wmo.Id]))
                        {
                            Model.ExtractSet(VmapFile.WmoDoodads[wmoInstanceNames[(int)wmo.Id]], wmo, false, mapId, mapId, Program.DirBinWriter, null);
                        }
                    }
                }

                wmoInstanceNames.Clear();
            }

            return(true);
        }
示例#2
0
文件: Wmo.cs 项目: ywscr/Tools
        public bool Read(Stream stream)
        {
            if (stream == null)
            {
                Console.WriteLine("No such file.");
                return(false);
            }

            using (BinaryReader reader = new BinaryReader(stream))
            {
                long fileLength = reader.BaseStream.Length;
                while (reader.BaseStream.Position < fileLength)
                {
                    string fourcc = reader.ReadStringFromChars(4, true);
                    uint   size   = reader.ReadUInt32();

                    int nextpos = (int)(reader.BaseStream.Position + size);
                    if (fourcc == "MOHD") // header
                    {
                        nTextures    = reader.ReadUInt32();
                        nGroups      = reader.ReadUInt32();
                        nPortals     = reader.ReadUInt32();
                        nLights      = reader.ReadUInt32();
                        nDoodadNames = reader.ReadUInt32();
                        nDoodadDefs  = reader.ReadUInt32();
                        nDoodadSets  = reader.ReadUInt32();
                        color        = reader.ReadUInt32();
                        RootWMOID    = reader.ReadUInt32();

                        for (var i = 0; i < 3; ++i)
                        {
                            bbcorn1[i] = reader.ReadSingle();
                        }

                        for (var i = 0; i < 3; ++i)
                        {
                            bbcorn2[i] = reader.ReadSingle();
                        }

                        flags  = reader.ReadUInt16();
                        numLod = reader.ReadUInt16();
                    }
                    else if (fourcc == "MODS")
                    {
                        for (var i = 0; i < size / 32; ++i)
                        {
                            DoodadData.Sets.Add(reader.ReadStruct <MODS>());
                        }
                    }
                    else if (fourcc == "MODN")
                    {
                        DoodadData.Paths = reader.ReadBytes((int)size);

                        using (BinaryReader doodadReader = new BinaryReader(new MemoryStream(DoodadData.Paths)))
                        {
                            int  index    = 0;
                            long endIndex = doodadReader.BaseStream.Length;
                            while (doodadReader.BaseStream.Position < endIndex)
                            {
                                string path = doodadReader.ReadCString();
                                if (VmapFile.ExtractSingleModel(path))
                                {
                                    ValidDoodadNames.Add((uint)index);
                                }

                                index += path.Length + 1;
                            }
                        }
                    }
                    else if (fourcc == "MODI")
                    {
                        uint fileDataIdCount = size / 4;
                        DoodadData.FileDataIds = new uint[size / 4];

                        Buffer.BlockCopy(reader.ReadBytes((int)size), 0, DoodadData.FileDataIds, 0, DoodadData.FileDataIds.Length);
                        for (uint i = 0; i < fileDataIdCount; ++i)
                        {
                            if (DoodadData.FileDataIds[i] == 0)
                            {
                                continue;
                            }

                            string path = $"File{DoodadData.FileDataIds[i]:X8}.xxx";
                            if (VmapFile.ExtractSingleModel(path))
                            {
                                ValidDoodadNames.Add(i);
                            }
                        }
                    }
                    else if (fourcc == "MODD")
                    {
                        for (var i = 0; i < size / 40; ++i)
                        {
                            DoodadData.Spawns.Add(reader.Read <MODD>());
                        }
                    }
                    else if (fourcc == "GFID")
                    {
                        for (uint gp = 0; gp < nGroups; ++gp)
                        {
                            uint fileDataId = reader.ReadUInt32();
                            if (fileDataId != 0)
                            {
                                groupFileDataIDs.Add(fileDataId);
                            }
                        }
                    }

                    reader.BaseStream.Seek(nextpos, SeekOrigin.Begin);
                }
            }
            return(true);
        }
示例#3
0
文件: Wmo.cs 项目: ywscr/Tools
        public static void Extract(MODF mapObjDef, string WmoInstName, bool isGlobalWmo, uint mapID, uint originalMapId, BinaryWriter writer, List <ADTOutputCache> dirfileCache)
        {
            // destructible wmo, do not dump. we can handle the vmap for these
            // in dynamic tree (gameobject vmaps)
            if ((mapObjDef.Flags & 0x01) != 0)
            {
                return;
            }

            if (!File.Exists(Program.WmoDirectory + WmoInstName))
            {
                Console.WriteLine($"WMOInstance.WMOInstance: couldn't open {WmoInstName}");
                return;
            }

            //-----------add_in _dir_file----------------
            using (BinaryReader binaryReader = new BinaryReader(File.Open(Program.WmoDirectory + WmoInstName, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                binaryReader.BaseStream.Seek(8, SeekOrigin.Begin); // get the correct no of vertices
                int nVertices = binaryReader.ReadInt32();
                if (nVertices == 0)
                {
                    return;
                }

                Vector3        position = fixCoords(mapObjDef.Position);
                AxisAlignedBox bounds   = new AxisAlignedBox(fixCoords(mapObjDef.Bounds.Lo), fixCoords(mapObjDef.Bounds.Hi));

                if (isGlobalWmo)
                {
                    position += new Vector3(533.33333f * 32, 533.33333f * 32, 0.0f);
                    bounds   += new Vector3(533.33333f * 32, 533.33333f * 32, 0.0f);
                }

                float scale = 1.0f;
                if (Convert.ToBoolean(mapObjDef.Flags & 0x4))
                {
                    scale = mapObjDef.Scale / 1024.0f;
                }
                uint uniqueId = VmapFile.GenerateUniqueObjectId(mapObjDef.UniqueId, 0);
                uint flags    = ModelFlags.HasBound;
                if (mapID != originalMapId)
                {
                    flags |= ModelFlags.ParentSpawn;
                }

                if (uniqueId == 198660)
                {
                }

                //write mapID, Flags, ID, Pos, Rot, Scale, Bound_lo, Bound_hi, name
                writer.Write(mapID);
                writer.Write(flags);
                writer.Write(mapObjDef.NameSet);
                writer.Write(uniqueId);
                writer.WriteVector3(position);
                writer.WriteVector3(mapObjDef.Rotation);
                writer.Write(scale);
                writer.WriteVector3(bounds.Lo);
                writer.WriteVector3(bounds.Hi);
                writer.Write(WmoInstName.GetByteCount());
                writer.WriteString(WmoInstName);

                if (dirfileCache != null)
                {
                    ADTOutputCache cacheModelData = new ADTOutputCache();
                    cacheModelData.Flags = flags & ~ModelFlags.ParentSpawn;

                    MemoryStream stream    = new MemoryStream();
                    BinaryWriter cacheData = new BinaryWriter(stream);
                    cacheData.Write(mapObjDef.NameSet);
                    cacheData.Write(uniqueId);
                    cacheData.WriteVector3(position);
                    cacheData.WriteVector3(mapObjDef.Rotation);
                    cacheData.Write(scale);
                    cacheData.WriteVector3(bounds.Lo);
                    cacheData.WriteVector3(bounds.Hi);
                    cacheData.Write(WmoInstName.GetByteCount());
                    cacheData.WriteString(WmoInstName);

                    cacheModelData.Data = stream.ToArray();
                    dirfileCache.Add(cacheModelData);
                }
            }
        }
示例#4
0
文件: Model.cs 项目: ywscr/Tools
        public static void ExtractSet(WMODoodadData doodadData, MODF wmo, bool isGlobalWmo, uint mapID, uint originalMapId, BinaryWriter writer, List <ADTOutputCache> dirfileCache)
        {
            if (wmo.DoodadSet >= doodadData.Sets.Count)
            {
                return;
            }

            Vector3 wmoPosition = new Vector3(wmo.Position.Z, wmo.Position.X, wmo.Position.Y);
            Matrix3 wmoRotation = Matrix3.fromEulerAnglesZYX(MathFunctions.toRadians(wmo.Rotation.Y), MathFunctions.toRadians(wmo.Rotation.X), MathFunctions.toRadians(wmo.Rotation.Z));

            if (isGlobalWmo)
            {
                wmoPosition += new Vector3(533.33333f * 32, 533.33333f * 32, 0.0f);
            }

            ushort doodadId      = 0;
            MODS   doodadSetData = doodadData.Sets[wmo.DoodadSet];

            using (BinaryReader reader = new BinaryReader(new MemoryStream(doodadData.Paths)))
            {
                foreach (ushort doodadIndex in doodadData.References)
                {
                    if (doodadIndex < doodadSetData.StartIndex ||
                        doodadIndex >= doodadSetData.StartIndex + doodadSetData.Count)
                    {
                        continue;
                    }

                    MODD doodad = doodadData.Spawns[doodadIndex];

                    reader.BaseStream.Position = doodad.NameIndex;
                    string ModelInstName = reader.ReadCString().GetPlainName();

                    if (ModelInstName.Length > 3)
                    {
                        string extension = ModelInstName.Substring(ModelInstName.Length - 4);
                        if (extension == ".mdx" || extension == ".mdl")
                        {
                            ModelInstName  = ModelInstName.Remove(ModelInstName.Length - 2, 2);
                            ModelInstName += "2";
                        }
                    }

                    if (!File.Exists(Program.WmoDirectory + ModelInstName))
                    {
                        continue;
                    }

                    using (BinaryReader binaryReader = new BinaryReader(File.Open(Program.WmoDirectory + ModelInstName, FileMode.Open, FileAccess.Read, FileShare.Read)))
                    {
                        binaryReader.BaseStream.Seek(8, SeekOrigin.Begin); // get the correct no of vertices
                        int nVertices = binaryReader.ReadInt32();
                        if (nVertices == 0)
                        {
                            continue;
                        }
                    }
                    ++doodadId;

                    Vector3 position = wmoPosition + (wmoRotation * new Vector3(doodad.Position.X, doodad.Position.Y, doodad.Position.Z));

                    Vector3 rotation;
                    (new Quaternion(doodad.Rotation.X, doodad.Rotation.Y, doodad.Rotation.Z, doodad.Rotation.W).toRotationMatrix() * wmoRotation).toEulerAnglesXYZ(out rotation.Z, out rotation.X, out rotation.Y);

                    rotation.Z = MathFunctions.toDegrees(rotation.Z);
                    rotation.X = MathFunctions.toDegrees(rotation.X);
                    rotation.Y = MathFunctions.toDegrees(rotation.Y);

                    ushort nameSet  = 0;    // not used for models
                    uint   uniqueId = VmapFile.GenerateUniqueObjectId(wmo.UniqueId, doodadId);
                    uint   flags    = ModelFlags.M2;
                    if (mapID != originalMapId)
                    {
                        flags |= ModelFlags.ParentSpawn;
                    }

                    //write mapID, Flags, NameSet, UniqueId, Pos, Rot, Scale, name
                    writer.Write(mapID);
                    writer.Write(flags);
                    writer.Write(nameSet);
                    writer.Write(uniqueId);
                    writer.WriteVector3(position);
                    writer.WriteVector3(rotation);
                    writer.Write(doodad.Scale);
                    writer.Write(ModelInstName.GetByteCount());
                    writer.WriteString(ModelInstName);

                    if (dirfileCache != null)
                    {
                        ADTOutputCache cacheModelData = new ADTOutputCache();
                        cacheModelData.Flags = flags & ~ModelFlags.ParentSpawn;

                        MemoryStream stream    = new MemoryStream();
                        BinaryWriter cacheData = new BinaryWriter(stream);
                        cacheData.Write(nameSet);
                        cacheData.Write(uniqueId);
                        cacheData.WriteVector3(position);
                        cacheData.WriteVector3(rotation);
                        cacheData.Write(doodad.Scale);
                        cacheData.Write(ModelInstName.GetByteCount());
                        cacheData.WriteString(ModelInstName);

                        cacheModelData.Data = stream.ToArray();
                        dirfileCache.Add(cacheModelData);
                    }
                }
            }
        }
示例#5
0
文件: Model.cs 项目: ywscr/Tools
        public static void Extract(MDDF doodadDef, string ModelInstName, uint mapID, uint originalMapId, BinaryWriter writer, List <ADTOutputCache> dirfileCache)
        {
            if (!File.Exists(Program.WmoDirectory + ModelInstName))
            {
                return;
            }

            using (BinaryReader binaryReader = new BinaryReader(File.Open(Program.WmoDirectory + ModelInstName, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                binaryReader.BaseStream.Seek(8, SeekOrigin.Begin); // get the correct no of vertices
                int nVertices = binaryReader.ReadInt32();
                if (nVertices == 0)
                {
                    return;
                }
            }

            // scale factor - divide by 1024. blizzard devs must be on crack, why not just use a float?
            float sc = doodadDef.Scale / 1024.0f;

            Vector3 position = fixCoords(doodadDef.Position);

            ushort nameSet  = 0;// not used for models
            uint   uniqueId = VmapFile.GenerateUniqueObjectId(doodadDef.UniqueId, 0);
            uint   flags    = ModelFlags.M2;

            if (mapID != originalMapId)
            {
                flags |= ModelFlags.ParentSpawn;
            }


            //write mapID, Flags, NameSet, UniqueId, Pos, Rot, Scale, name
            writer.Write(mapID);
            writer.Write(flags);
            writer.Write(nameSet);
            writer.Write(uniqueId);
            writer.WriteVector3(position);
            writer.WriteVector3(doodadDef.Rotation);
            writer.Write(sc);
            writer.Write(ModelInstName.GetByteCount());
            writer.WriteString(ModelInstName);

            if (dirfileCache != null)
            {
                ADTOutputCache cacheModelData = new ADTOutputCache();
                cacheModelData.Flags = flags & ~ModelFlags.ParentSpawn;

                MemoryStream stream    = new MemoryStream();
                BinaryWriter cacheData = new BinaryWriter(stream);
                cacheData.Write(nameSet);
                cacheData.Write(uniqueId);
                cacheData.WriteVector3(position);
                cacheData.WriteVector3(doodadDef.Rotation);
                cacheData.Write(sc);
                cacheData.Write(ModelInstName.GetByteCount());
                cacheData.WriteString(ModelInstName);

                cacheModelData.Data = stream.ToArray();
                dirfileCache.Add(cacheModelData);
            }
        }
示例#6
0
文件: Adt.cs 项目: yurlik-karu/Tools
        public bool init(uint map_num, uint originalMapId)
        {
            if (dirfileCache != null)
            {
                return(initFromCache(map_num, originalMapId));
            }

            MemoryStream stream = Program.cascHandler.ReadFile(Adtfilename);

            if (stream == null)
            {
                return(false);
            }

            if (cacheable)
            {
                dirfileCache = new List <ADTOutputCache>();
            }

            string dirname = Program.wmoDirectory + "dir_bin";

            using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(dirname, FileMode.Append, FileAccess.Write)))
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    long fileLength = binaryReader.BaseStream.Length;
                    while (binaryReader.BaseStream.Position < fileLength)
                    {
                        string fourcc = binaryReader.ReadStringFromChars(4, true);
                        uint   size   = binaryReader.ReadUInt32();

                        long nextpos = binaryReader.BaseStream.Position + size;

                        if (fourcc == "MCIN")
                        {
                        }
                        else if (fourcc == "MTEX")
                        {
                        }
                        else if (fourcc == "MMDX")
                        {
                            if (size != 0)
                            {
                                while (size > 0)
                                {
                                    string path = binaryReader.ReadCString();

                                    ModelInstanceNames.Add(path.GetPlainName());
                                    VmapFile.ExtractSingleModel(path);

                                    size -= (uint)(path.Length + 1);
                                }
                            }
                        }
                        else if (fourcc == "MWMO")
                        {
                            if (size != 0)
                            {
                                while (size > 0)
                                {
                                    string path = binaryReader.ReadCString();

                                    WmoInstanceNames.Add(path.GetPlainName());
                                    VmapFile.ExtractSingleWmo(path);

                                    size -= (uint)(path.Length + 1);
                                }
                            }
                        }
                        //======================
                        else if (fourcc == "MDDF")
                        {
                            if (size != 0)
                            {
                                uint doodadCount = size / 36; //sizeof(MDDF)
                                for (int i = 0; i < doodadCount; ++i)
                                {
                                    MDDF doodadDef = binaryReader.Read <MDDF>();
                                    if (!Convert.ToBoolean(doodadDef.Flags & 0x40))
                                    {
                                        Model.Extract(doodadDef, ModelInstanceNames[(int)doodadDef.Id], map_num, originalMapId, binaryWriter, dirfileCache);
                                    }
                                    else
                                    {
                                        string fileName = $"FILE{doodadDef.Id}:X8.xxx";
                                        VmapFile.ExtractSingleModel(fileName);
                                        Model.Extract(doodadDef, fileName, map_num, originalMapId, binaryWriter, dirfileCache);
                                    }
                                }

                                ModelInstanceNames.Clear();
                            }
                        }
                        else if (fourcc == "MODF")
                        {
                            if (size != 0)
                            {
                                uint mapObjectCount = size / 64; // sizeof(ADT::MODF);
                                for (int i = 0; i < mapObjectCount; ++i)
                                {
                                    MODF mapObjDef = binaryReader.Read <MODF>();
                                    if (!Convert.ToBoolean(mapObjDef.Flags & 0x8))
                                    {
                                        WMORoot.Extract(mapObjDef, WmoInstanceNames[(int)mapObjDef.Id], false, map_num, originalMapId, binaryWriter, dirfileCache);
                                        Model.ExtractSet(VmapFile.WmoDoodads[WmoInstanceNames[(int)mapObjDef.Id]], mapObjDef, false, map_num, originalMapId, binaryWriter, dirfileCache);
                                    }
                                    else
                                    {
                                        string fileName = $"FILE{mapObjDef.Id}:8X.xxx";
                                        VmapFile.ExtractSingleWmo(fileName);
                                        WMORoot.Extract(mapObjDef, fileName, false, map_num, originalMapId, binaryWriter, dirfileCache);
                                        Model.ExtractSet(VmapFile.WmoDoodads[fileName], mapObjDef, false, map_num, originalMapId, binaryWriter, dirfileCache);
                                    }
                                }

                                WmoInstanceNames.Clear();
                            }
                        }

                        //======================
                        binaryReader.BaseStream.Seek(nextpos, SeekOrigin.Begin);
                    }
                }
            }

            return(true);
        }
示例#7
0
        public bool init(string fileName, uint map_num, uint tileX, uint tileY)
        {
            MemoryStream stream = Program.cascHandler.ReadFile(fileName);

            if (stream == null)
            {
                return(false);
            }

            string dirname = Program.wmoDirectory + "dir_bin";

            using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(dirname, FileMode.Append, FileAccess.Write)))
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
                    {
                        string fourcc = binaryReader.ReadStringFromChars(4, true);
                        uint   size   = binaryReader.ReadUInt32();

                        long nextpos = binaryReader.BaseStream.Position + size;

                        if (fourcc == "MCIN")
                        {
                        }
                        else if (fourcc == "MTEX")
                        {
                        }
                        else if (fourcc == "MMDX")
                        {
                            if (size != 0)
                            {
                                while (size > 0)
                                {
                                    string path = binaryReader.ReadCString();

                                    ModelInstanceNames.Add(path.GetPlainName());
                                    if (path.GetPlainName() == "Skullcandle02.m2")
                                    {
                                    }
                                    VmapFile.ExtractSingleModel(path);

                                    size -= (uint)(path.Length + 1);
                                }
                            }
                        }
                        else if (fourcc == "MWMO")
                        {
                            if (size != 0)
                            {
                                while (size > 0)
                                {
                                    string path = binaryReader.ReadCString();

                                    WmoInstanceNames.Add(path.GetPlainName());
                                    VmapFile.ExtractSingleWmo(path);

                                    size -= (uint)(path.Length + 1);
                                }
                            }
                        }
                        //======================
                        else if (fourcc == "MDDF")
                        {
                            if (size != 0)
                            {
                                nMDX = (int)size / 36;
                                for (int i = 0; i < nMDX; ++i)
                                {
                                    int           id   = binaryReader.ReadInt32();
                                    ModelInstance inst = new ModelInstance(binaryReader, ModelInstanceNames[id], map_num, tileX, tileY, binaryWriter);
                                }

                                ModelInstanceNames.Clear();
                            }
                        }
                        else if (fourcc == "MODF")
                        {
                            if (size != 0)
                            {
                                nWMO = (int)size / 64;
                                for (int i = 0; i < nWMO; ++i)
                                {
                                    int         id   = binaryReader.ReadInt32();
                                    WMOInstance inst = new WMOInstance(binaryReader, WmoInstanceNames[id], map_num, tileX, tileY, binaryWriter);
                                }

                                WmoInstanceNames.Clear();
                            }
                        }

                        //======================
                        binaryReader.BaseStream.Seek(nextpos, SeekOrigin.Begin);
                    }
                }
            }

            return(true);
        }
示例#8
0
        public bool init(uint mapId)
        {
            Stream stream = Program.CascHandler.OpenFile(_mapName + ".wdt");

            if (stream == null)
            {
                return(false);
            }

            string dirname = Program.WmoDirectory + "dir_bin";

            using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(dirname, FileMode.Append, FileAccess.Write)))
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    long fileLength = binaryReader.BaseStream.Length;
                    while (binaryReader.BaseStream.Position < fileLength)
                    {
                        string fourcc = binaryReader.ReadStringFromChars(4, true);
                        uint   size   = binaryReader.ReadUInt32();

                        long nextpos = binaryReader.BaseStream.Position + size;

                        if (fourcc == "MAIN")
                        {
                        }
                        if (fourcc == "MWMO")
                        {
                            // global map objects
                            if (size != 0)
                            {
                                while (size > 0)
                                {
                                    string path = binaryReader.ReadCString();

                                    _wmoNames.Add(path.GetPlainName());
                                    VmapFile.ExtractSingleWmo(path);

                                    size -= (uint)(path.Length + 1);
                                }
                            }
                        }
                        else if (fourcc == "MODF")
                        {
                            // global wmo instance data
                            if (size != 0)
                            {
                                uint mapObjectCount = size / 64; //sizeof(ADT::MODF);
                                for (int i = 0; i < mapObjectCount; ++i)
                                {
                                    MODF mapObjDef = binaryReader.Read <MODF>();
                                    if (!Convert.ToBoolean(mapObjDef.Flags & 0x8))
                                    {
                                        WMORoot.Extract(mapObjDef, _wmoNames[(int)mapObjDef.Id], true, mapId, mapId, binaryWriter, null);
                                        Model.ExtractSet(VmapFile.WmoDoodads[_wmoNames[(int)mapObjDef.Id]], mapObjDef, true, mapId, mapId, binaryWriter, null);
                                    }
                                    else
                                    {
                                        string fileName = $"FILE{mapObjDef.Id}:8X.xxx";
                                        VmapFile.ExtractSingleWmo(fileName);
                                        WMORoot.Extract(mapObjDef, fileName, true, mapId, mapId, binaryWriter, null);
                                        Model.ExtractSet(VmapFile.WmoDoodads[fileName], mapObjDef, true, mapId, mapId, binaryWriter, null);
                                    }
                                }
                            }
                        }

                        binaryReader.BaseStream.Seek(nextpos, SeekOrigin.Begin);
                    }
                }
            }

            return(true);
        }
示例#9
0
文件: Wdt.cs 项目: Luzifix/Tools
        public bool init(string fileName, uint mapID)
        {
            MemoryStream stream = Program.cascHandler.ReadFile(fileName);

            if (stream == null)
            {
                return(false);
            }

            string dirname = Program.wmoDirectory + "dir_bin";

            using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(dirname, FileMode.Append, FileAccess.Write)))
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
                    {
                        string fourcc = binaryReader.ReadStringFromChars(4, true);
                        uint   size   = binaryReader.ReadUInt32();

                        long nextpos = binaryReader.BaseStream.Position + size;

                        if (fourcc == "MAIN")
                        {
                        }
                        if (fourcc == "MWMO")
                        {
                            // global map objects
                            if (size != 0)
                            {
                                while (size > 0)
                                {
                                    string path = binaryReader.ReadCString();

                                    gWmoInstansName.Add(path.GetPlainName());
                                    VmapFile.ExtractSingleWmo(path);

                                    size -= (uint)(path.Length + 1);
                                }
                            }
                        }
                        else if (fourcc == "MODF")
                        {
                            // global wmo instance data
                            if (size != 0)
                            {
                                gnWMO = (int)size / 64;

                                for (int i = 0; i < gnWMO; ++i)
                                {
                                    int         id   = binaryReader.ReadInt32();
                                    WMOInstance inst = new WMOInstance(binaryReader, gWmoInstansName[id], mapID, 65, 65, binaryWriter);
                                }
                            }
                        }

                        binaryReader.BaseStream.Seek(nextpos, SeekOrigin.Begin);
                    }
                }
            }

            return(true);
        }
示例#10
0
        public bool Init(uint mapNum, uint originalMapId)
        {
            if (dirFileCache != null)
            {
                return(InitFromCache(mapNum, originalMapId));
            }

            if (cacheable)
            {
                dirFileCache = new List <ADTOutputCache>();
            }

            FilenameChunk mmdx = GetChunk("MMDX")?.As <FilenameChunk>();

            if (mmdx != null && mmdx.Filenames.Count > 0)
            {
                foreach (var filename in mmdx.Filenames)
                {
                    modelInstanceNames.Add(filename);
                    VmapFile.ExtractSingleModel(filename);
                }
            }

            FilenameChunk mwmo = GetChunk("MWMO")?.As <FilenameChunk>();

            if (mwmo != null && mwmo.Filenames.Count > 0)
            {
                foreach (var filename in mwmo.Filenames)
                {
                    wmoInstanceNames.Add(filename);
                    VmapFile.ExtractSingleWmo(filename);
                }
            }

            MDDF doodadChunk = GetChunk("MDDF")?.As <MDDF>();

            if (doodadChunk != null && doodadChunk.DoodadDefs.Length > 0)
            {
                foreach (var doodad in doodadChunk.DoodadDefs)
                {
                    if (doodad.Flags.HasAnyFlag(MDDFFlags.EntryIsFileID))
                    {
                        string fileName = $"FILE{doodad.Id:X8}.xxx";
                        VmapFile.ExtractSingleModel(fileName);
                        Model.Extract(doodad, fileName, mapNum, originalMapId, Program.DirBinWriter, dirFileCache);
                    }
                    else
                    {
                        Model.Extract(doodad, modelInstanceNames[(int)doodad.Id], mapNum, originalMapId, Program.DirBinWriter, dirFileCache);
                    }
                }

                modelInstanceNames.Clear();
            }

            MODF wmoChunk = GetChunk("MODF")?.As <MODF>();

            if (wmoChunk != null && wmoChunk.MapObjDefs.Length > 0)
            {
                foreach (var wmo in wmoChunk.MapObjDefs)
                {
                    if (wmo.Flags.HasAnyFlag(MODFFlags.EntryIsFileID))
                    {
                        string fileName = $"FILE{wmo.Id:X8}.xxx";
                        VmapFile.ExtractSingleWmo(wmo.Id);
                        WMORoot.Extract(wmo, fileName, false, mapNum, originalMapId, Program.DirBinWriter, dirFileCache);

                        if (VmapFile.WmoDoodads.ContainsKey(fileName))
                        {
                            Model.ExtractSet(VmapFile.WmoDoodads[fileName], wmo, false, mapNum, originalMapId, Program.DirBinWriter, dirFileCache);
                        }
                    }
                    else
                    {
                        WMORoot.Extract(wmo, wmoInstanceNames[(int)wmo.Id], false, mapNum, originalMapId, Program.DirBinWriter, dirFileCache);
                        if (VmapFile.WmoDoodads.ContainsKey(wmoInstanceNames[(int)wmo.Id]))
                        {
                            Model.ExtractSet(VmapFile.WmoDoodads[wmoInstanceNames[(int)wmo.Id]], wmo, false, mapNum, originalMapId, Program.DirBinWriter, dirFileCache);
                        }
                    }
                }

                wmoInstanceNames.Clear();
            }

            return(true);
        }