예제 #1
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);
        }
예제 #2
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);
            }
        }
예제 #3
0
파일: ADTFile.cs 프로젝트: DeKaDeNcE/Tools
        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);
        }