Beispiel #1
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);
        }
Beispiel #2
0
        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);
        }