Ejemplo n.º 1
0
        public void Read(byte[] inData)
        {
            using (var stream = new MemoryStream(inData))
                using (var reader = new BinaryReader(stream))
                {
                    var modiSize = inData.Length / 4;
                    DoodadFileIds = new uint[modiSize];

                    for (var i = 0; i < modiSize; ++i)
                    {
                        var filedataId = reader.ReadUInt32();
                        var filename   = Listfile.LookupFilename(filedataId, ".wmo", "m2").Replace("m2", "mdx").Replace("/", "\\") + "\0";

                        if (!DoodadNames.ContainsKey(filedataId))
                        {
                            DoodadNames.Add(filedataId, filename);
                        }

                        DoodadFileIds[i] = filedataId;
                    }
                }

            if (WMOFile.DisableDoodads)
            {
                WMOFile.Chunks.Add(new MODN());
            }
            else
            {
                WMOFile.Chunks.Add(new MODN {
                    DoodadFilenames = DoodadNames.Values.ToList()
                });
            }
        }
        private void ReadSFID(BinaryReader reader, uint size)
        {
            for (var i = 0u; i < size / 4u; ++i)
            {
                var skinFileId = reader.ReadUInt32();
                var filename   = Listfile.LookupFilename(skinFileId, ".m2").Replace('/', '\\');

                filename = System.IO.Path.GetFileName(filename);

                SkinFiles.Add(filename);
            }
        }
Ejemplo n.º 3
0
        private void RetrieveTextures()
        {
            using (var stream = new MemoryStream(tex.Data))
                using (var reader = new BinaryReader(stream))
                {
                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        var chunk = new string(reader.ReadChars(4));
                        var size  = reader.ReadUInt32();

                        switch (chunk)
                        {
                        case "PMAM":
                            texPos += (int)size + 8;
                            reader.BaseStream.Position += size;
                            break;

                        case "DIDM":    //< Texures
                            for (var i = 0; i < size / 4; ++i)
                            {
                                var filedataid = reader.ReadUInt32();
                                if (filedataid != 0)
                                {
                                    var filename = Listfile.LookupFilename(filedataid, ".adt", modelname) + "\0";
                                    MapTextures.Add(filedataid, filename);
                                }
                            }

                            texPos += (int)size + 8;
                            break;

                        case "DIHM":    //< Textures as well
                            for (var i = 0; i < size / 4; ++i)
                            {
                                var filedataid = reader.ReadUInt32();
                                if (filedataid != 0)
                                {
                                    var filename = Listfile.LookupFilename(filedataid, ".adt", modelname) + "\0";
                                    MapTextures.Add(filedataid, filename);
                                }
                            }

                            texPos += (int)size + 8;
                            break;

                        default:
                            reader.BaseStream.Position += size;
                            break;
                        }
                    }
                }
        }
Ejemplo n.º 4
0
        private string AddFilename(uint fdid)
        {
            if (fdid != 0)
            {
                var textureFilename = Listfile.LookupFilename(fdid, ".wmo").Replace('/', '\\') + "\0";

                if (!Filenames.ContainsKey(textureFilename))
                {
                    Filenames.Add(textureFilename, textureOffset);
                    textureOffset += (uint)textureFilename.Length;
                }

                return(textureFilename);
            }

            return(string.Empty);
        }
Ejemplo n.º 5
0
        private void ReadTXID(uint size)
        {
            for (var i = 0; i < size / 4; ++i)
            {
                var textureId = Read <uint>();

                var filename = Listfile.LookupFilename(textureId, ".m2", ModelName);
                if (filename != string.Empty)
                {
                    TexturePaths.Add(filename + "\0\0", filename.Length);
                }
                else
                {
                    Console.WriteLine("DBC Defined Texture!");
                }
            }
        }
Ejemplo n.º 6
0
        private string AddFilename(uint fdid)
        {
            if (fdid != 0)
            {
                var textureFilename = Listfile.LookupFilename(fdid, ".wmo", wmoName).Replace('/', '\\');
                var texFilename     = textureFilename + "\0";

                if (!filenamePosition.ContainsKey(texFilename))
                {
                    filenamePosition.Add(texFilename, textureOffset);
                    textureOffset += (uint)texFilename.Length;
                }

                return(texFilename);
            }

            return(string.Empty);
        }
        private void ReadTXID(BinaryReader reader, uint size)
        {
            for (var i = 0u; i < size / 4u; i++)
            {
                var textureId = reader.ReadUInt32();

                var filename = Listfile.LookupFilename(textureId, ".m2").Replace('/', '\\');
                var texture  = new Texture
                {
                    Filename       = filename + "\0\0",
                    FilenameLength = filename.Length
                };

                if (Textures.ContainsKey(texture))
                {
                    Textures[texture]++;
                }
                else
                {
                    Textures.Add(texture, 1);
                }
            }
        }
Ejemplo n.º 8
0
        public bool Fix()
        {
            if (!Valid || Size() < 0x5C)
            {
                return(false);
            }

            int pos = 0;// 0x54 + ReadInt(0x58) + 0x8;

            pos = SkipChunk(pos, "MVER");
            pos = SkipChunk(pos, "MOHD");
            // pos += 28 + 44;          // Skip shit
            // WriteUInt(pos, 0);  // Set Doodads to 0
            // pos += 44;

            var motx = MagicToInt("MOTX");
            var ofs  = ChunksOfs(pos, motx);

            if (ofs.ContainsKey(motx))
            {
                pos = SkipChunk(pos, "MOTX");
                ReadMOMT(pos);
                pos = WriteMOMT(pos);
            }
            else
            {
                ReadMOMT(pos);
                var motxSize = CalculateTextureSize(filenamePosition.Keys.ToList());
                AddEmptyBytes(pos, (int)motxSize + 8);
                WriteHeaderMagic(pos, "MOTX");
                WriteUInt(pos + 4, motxSize);

                pos += 8;
                foreach (var texture in filenamePosition)
                {
                    var newFilename = texture.Key.ToUpper();
                    for (var j = 0; j < newFilename.Length; ++j)
                    {
                        WriteChar(pos + j, newFilename[j]);
                    }
                    pos += newFilename.Length;
                }

                pos = WriteMOMT(pos);
            }

            pos = SkipChunk(pos, "MOGN");
            pos = FixMOGI(pos);// MOGI

            int mosb = MagicToInt("MOSB");

            ofs = ChunksOfs(pos, mosb);
            if (!ofs.ContainsKey(mosb))
            {
                AddEmptyBytes(pos, 0xC);
                WriteInt(pos, mosb);
                WriteInt(pos + 0x4, 4);
                pos += 0xC;
            }
            else
            {
                pos = SkipChunk(pos, "MOSB");
            }

            pos = SkipChunk(pos, "MOPV");
            pos = SkipChunk(pos, "MOPT");
            pos = SkipChunk(pos, "MOPR");

            int pos_molt = pos;

            pos = SkipChunk(pos, "MOLT");
            // fix nLights
            WriteInt(0x20, ReadInt(pos_molt + 0x4) / 0x30);

            pos = SkipChunk(pos, "MODS");

            int modi = MagicToInt("MODI");

            ofs = ChunksOfs(pos, modi);
            if (ofs.ContainsKey(modi))
            {
                pos += 4;
                var size = ReadUInt(pos);

                for (var i = 0; i < size / 4; ++i)
                {
                    pos += 4;
                    var filedataid = ReadUInt(pos);
                    var filename   = Listfile.LookupFilename(filedataid, ".wmo", wmoName, "m2").Replace('/', '\\').Replace("m2", "mdx");

                    var remainderCount = 4u - (uint)filename.Length % 4u;
                    if (!doodadsPosition.ContainsValue(filename))
                    {
                        doodadsPosition.Add(doodadsOffset, filename);
                        doodadsOffset += (uint)filename.Length;

                        filenamePadding.Add(filename, remainderCount);
                    }
                }

                pos += 4;

                var modiSize = CalculateDoodadSize();
                AddEmptyBytes(pos, (int)modiSize + 8);
                WriteHeaderMagic(pos, "MODN");
                WriteUInt(pos + 0x4, modiSize);

                pos += 0x8;
                foreach (var filename in doodadsPosition)
                {
                    var paddingCount  = filenamePadding[filename.Value];
                    var upperFilename = filename.Value.ToUpper();

                    for (var i = 0; i < upperFilename.Length; ++i)
                    {
                        WriteChar(pos + i, upperFilename[i]);
                    }
                    pos += upperFilename.Length;

                    for (var i = 0; i < paddingCount; ++i)
                    {
                        WriteChar(pos + i, '\0');
                    }
                    pos += (int)paddingCount;
                }
            }

            pos = FixMODD(pos);  // MODD
            pos = SkipChunk(pos, "MFOG");
            pos = SkipMCVP(pos); // Optional chunk

            return(true);
        }