Пример #1
0
        private MTEX ReadMTEXChunk(uint size, BinaryReader bin)
        {
            var txchunk = new MTEX();

            //List of BLP filenames
            var blpFilesChunk = bin.ReadBytes((int)size);

            var str = new StringBuilder();

            for (var i = 0; i < blpFilesChunk.Length; i++)
            {
                if (blpFilesChunk[i] == '\0')
                {
                    blpFiles.Add(str.ToString());
                    str = new StringBuilder();
                }
                else
                {
                    str.Append((char)blpFilesChunk[i]);
                }
            }

            txchunk.filenames = blpFiles.ToArray();
            return(txchunk);
        }
Пример #2
0
        private MTEX ReadMTEXChunk(uint size, BinaryReader bin)
        {
            MTEX txchunk = new MTEX();

            //List of BLP filenames
            var blpFilesChunk = bin.ReadBytes((int)size);

            var str = new StringBuilder();

            for (var i = 0; i < blpFilesChunk.Length; i++)
            {
                if (blpFilesChunk[i] == '\0')
                {
                    blpFiles.Add(str.ToString());
                    if (!CASC.cascHandler.FileExists(str.ToString()))
                    {
                        Console.WriteLine("BLP file does not exist!!! {0}", str.ToString());
                    }
                    str = new StringBuilder();
                }
                else
                {
                    str.Append((char)blpFilesChunk[i]);
                }
            }

            txchunk.filenames = blpFiles.ToArray();
            return(txchunk);
        }
Пример #3
0
        public MTEX ReadMTEXChunk(BlizzHeader chunk, BinaryReader bin)
        {
            MTEX txchunk = new MTEX();

            //List of BLP filenames
            var blpFilesChunk = bin.ReadBytes((int)chunk.Size);

            var str = new StringBuilder();

            for (var i = 0; i < blpFilesChunk.Length; i++)
            {
                if (blpFilesChunk[i] == '\0')
                {
                    blpFiles.Add(str.ToString());
                    if (!CASC.FileExists(str.ToString()))
                    {
                        Console.WriteLine("BLP file does not exist!!! {0}", str.ToString());
                        new WoWFormatLib.Utils.MissingFile(str.ToString());
                    }
                    str = new StringBuilder();
                }
                else
                {
                    str.Append((char)blpFilesChunk[i]);
                }
            }

            txchunk.filenames = blpFiles.ToArray();
            return(txchunk);
        }
Пример #4
0
        public TEX0(Files.WOTLK.ADT wotlk)
        {
            ADTfileInfo = new FileInfo(wotlk.ADTfileInfo.Name.Split('.')[0] + "_tex0.adt");
            Logger.log(ADTfileInfo.Name, Logger.Type.CONVERT, "<- " + wotlk.ADTfileInfo.Name);

            MVER = new MVER(wotlk.MVER);
            MAMP = new MAMP();
            MTEX = new MTEX(wotlk.MTEX);

            foreach (Files.WOTLK.Chunks.MCNK x in wotlk.MCNKs)
            {
                MCNKs.Add(new MCNK_TEX0(x));
                //MCNKLength += MCNKs[MCNKs.Count - 1].GetBytes().Length;
            }
            Logger.log("MCNK[]", Logger.Type.LEVEL1);
        }
Пример #5
0
        public ADT(string filePath)
        {
            ADTfileInfo = new FileInfo(filePath);

            Logger.log(ADTfileInfo.Name, Logger.Type.READ, ADTfileInfo.DirectoryName);

            //Start reading the .ADT File
            using (BinaryReader reader = new BinaryReader(ADTfileInfo.Open(FileMode.Open)))
            {
                Length = (int)reader.BaseStream.Length;
                reader.BaseStream.Seek(0, SeekOrigin.Begin);
                int MCNK_counter = 0;
                int MCNK_size    = 0;

                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    byte[] ChunkMagic   = reader.ReadBytes(4);
                    byte[] ChunkSize    = reader.ReadBytes(4);
                    byte[] ChunkContent = reader.ReadBytes(BitConverter.ToInt32(ChunkSize, 0));

                    string ChunkMagicString = MagicBytesToString(ChunkMagic);
                    //read the chunks
                    switch (ChunkMagicString)
                    {
                    case "MVER":
                        MVER = new MVER(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MHDR":
                        MHDR = new MHDR(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MCIN":
                        MCIN = new MCIN(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MTEX":
                        MTEX = new MTEX(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MMDX":
                        MMDX = new MMDX(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MMID":
                        MMID = new MMID(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MWMO":
                        MWMO = new MWMO(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MWID":
                        MWID = new MWID(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MDDF":
                        MDDF = new MDDF(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MODF":
                        MODF = new MODF(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MH2O":
                        MH2O = new MH2O(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;

                    case "MCNK":
                        MCNKs.Add(new MCNK(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent));
                        break;

                    case "MFBO":
                        MFBO = new MFBO(MagicBytesToChars(ChunkMagic), ChunkSize, ChunkContent);
                        break;
                    }

                    if (ChunkMagicString == "MCNK")
                    {
                        MCNK_counter++; MCNK_size += BitConverter.ToInt32(ChunkSize, 0);
                    }
                    else if (ChunkMagicString == "\0\0\0\0") /*Logger.log("0 Byte Chunk", Logger.Direction.WARNING);*/ } {
            }

            if (MCNK_counter > 0)
            {
                Logger.log("MCNK[]", Logger.Type.LEVEL1, MCNK_size + " byte");
            }
        }
    }
Пример #6
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                Title = "Select an OBJ file."
            };

            FolderOpen(dialog);
            var dgrp = ActiveDGRP;

            try
            {
                Stream str;
                if ((str = dialog.OpenFile()) != null)
                {
                    var obj = new OBJ(str);
                    //identify and copy replacement textures
                    //only happens when this iff doesnt have a 3d model

                    foreach (var mtl in obj.FacesByObjgroup.Keys)
                    {
                        var split = mtl.Split('_');
                        if (split.Length < 3 || split[1] == "SPR" || split[0] == "DEPTH")
                        {
                            continue;
                        }

                        var baseDir  = Path.GetDirectoryName(dialog.FileName);
                        var copyname = "TEX_" + split[2] + ".png";
                        if (IffMode)
                        {
                            var texID = ushort.Parse(split[2]);
                            var tex   = ActiveObject.Resource.Get <MTEX>(texID);
                            if (tex == null)
                            {
                                tex = new MTEX
                                {
                                    ChunkLabel     = "OBJ Import Texture",
                                    ChunkID        = texID,
                                    ChunkProcessed = true,
                                    ChunkType      = "MTEX",
                                    AddedByPatch   = true
                                };
                                (ActiveObject.Resource.Sprites ?? ActiveObject.Resource.MainIff).AddChunk(tex);
                            }

                            GameContent.Get.Changes.BlockingResMod(new ResAction(() =>
                            {
                                tex.SetData(File.ReadAllBytes(Path.Combine(baseDir, copyname)));
                            }, tex));
                        }
                        else
                        {
                            var texname = ActiveDGRP.ChunkParent.Filename.Replace('.', '_').Replace("spf", "iff") + "_";
                            texname += copyname;

                            File.Copy(Path.Combine(baseDir, copyname), Path.Combine(FSOEnvironment.ContentDir, "MeshReplace/", texname), true);
                        }
                    }

                    GameThread.NextUpdate(x =>
                    {
                        var mesh = new DGRP3DMesh(ActiveDGRP, obj, Client.GameFacade.GraphicsDevice);
                        if (IffMode)
                        {
                            var fsom = ActiveObject.Resource.Get <FSOM>(ActiveDGRP.ChunkID);
                            if (fsom == null)
                            {
                                fsom = new FSOM
                                {
                                    ChunkLabel     = "OBJ Import Mesh",
                                    ChunkID        = ActiveDGRP.ChunkID,
                                    ChunkProcessed = true,
                                    ChunkType      = "FSOM",
                                    AddedByPatch   = true
                                };
                                (ActiveObject.Resource.Sprites ?? ActiveObject.Resource.MainIff).AddChunk(fsom);
                            }
                            GameContent.Get.Changes.QueueResMod(new ResAction(() =>
                            {
                                fsom.SetMesh(mesh);
                                GameContent.Get.RCMeshes.ClearCache(ActiveDGRP);
                                Debug3D.ForceUpdate();
                            }, fsom));
                        }
                        else
                        {
                            GameContent.Get.RCMeshes.Replace(ActiveDGRP, mesh);
                            Debug3D.ForceUpdate();
                        }
                    });

                    str.Close();
                }
            } catch (Exception)
            {
            }
        }
Пример #7
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.Title = "Select an OBJ file.";
            FolderOpen(dialog);
            var dgrp = ActiveDGRP;

            try
            {
                Stream str;
                if ((str = dialog.OpenFile()) != null)
                {
                    var obj = new OBJ(str);
                    //identify and copy replacement textures
                    //only happens when this iff doesnt have a 3d model

                    foreach (var mtl in obj.FacesByObjgroup.Keys)
                    {
                        var split = mtl.Split('_');
                        if (split.Length < 3 || split[1] == "SPR" || split[0] == "DEPTH")
                        {
                            continue;
                        }

                        var baseDir  = Path.GetDirectoryName(dialog.FileName);
                        var copyname = "TEX_" + split[2] + ".png";
                        if (IffMode)
                        {
                            var texID = ushort.Parse(split[2]);
                            var tex   = ActiveObject.Resource.Get <MTEX>(texID);
                            if (tex == null)
                            {
                                tex                = new MTEX();
                                tex.ChunkLabel     = "OBJ Import Texture";
                                tex.ChunkID        = texID;
                                tex.ChunkProcessed = true;
                                tex.ChunkType      = "MTEX";
                                tex.AddedByPatch   = true;
                                (ActiveObject.Resource.Sprites ?? ActiveObject.Resource.MainIff).AddChunk(tex);
                            }

                            Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
                            {
                                tex.SetData(File.ReadAllBytes(Path.Combine(baseDir, copyname)));
                            }, tex));
                        }
                        else
                        {
                            var texname = ActiveDGRP.ChunkParent.Filename.Replace('.', '_').Replace("spf", "iff") + "_";
                            texname += copyname;

                            File.Copy(Path.Combine(baseDir, copyname), Path.Combine(FSOEnvironment.ContentDir, "MeshReplace/", texname), true);
                        }
                    }

                    OBJToFSOM(obj);

                    str.Close();
                }
            } catch (Exception)
            {
            }
        }
Пример #8
0
        public void Write()
        {
            using (var writer = new BinaryWriter(File.OpenWrite("test.adt")))
            {
                // MVER
                writer.Write(MVER.GetChunkHeaderBytes());
                writer.Write(MVER.GetChunkBytes());

                // Write MHDR later when we got all offsets
                var positionBeforeMHDR = writer.BaseStream.Position;
                writer.BaseStream.Position += _HeaderSize + MHDR.ChunkSize;

                // MTEX
                MHDR.OffsetMTEX = (uint)writer.BaseStream.Position;
                writer.Write(MTEX.GetChunkHeaderBytes());
                writer.Write(MTEX.GetChunkBytes());

                // MMDX
                MHDR.OffsetMMDX = (uint)writer.BaseStream.Position;
                writer.Write(MMDX.GetChunkHeaderBytes());
                writer.Write(MMDX.GetChunkBytes());

                // MMID
                MHDR.OffsetMMID = (uint)writer.BaseStream.Position;
                writer.Write(MMID.GetChunkHeaderBytes());
                writer.Write(MMID.GetChunkBytes());

                // MWMO
                MHDR.OffsetMWMO = (uint)writer.BaseStream.Position;
                writer.Write(MWMO.GetChunkHeaderBytes());
                writer.Write(MWMO.GetChunkBytes());

                // MWID
                MHDR.OffsetMWID = (uint)writer.BaseStream.Position;
                writer.Write(MWID.GetChunkHeaderBytes());
                writer.Write(MWID.GetChunkBytes());

                // MDDF
                MHDR.OffsetMDDF = (uint)writer.BaseStream.Position;
                writer.Write(MDDF.GetChunkHeaderBytes());
                writer.Write(MDDF.GetChunkBytes());

                // MODF
                MHDR.OffsetMODF = (uint)writer.BaseStream.Position;
                writer.Write(MODF.GetChunkHeaderBytes());
                writer.Write(MODF.GetChunkBytes());

                // MH2O
                MHDR.OffsetMH2O = (uint)writer.BaseStream.Position;
                writer.Write(MH2O.GetChunkHeaderBytes());
                writer.Write(MH2O.GetChunkBytes());

                // MCNK
                for (int i = 0; i < MCIN.Entries.Length; i++)
                {
                    MCIN.Entries[i].OffsetMCNK = (uint)writer.BaseStream.Position;
                    MCIN.Entries[i].ChunkSize  = MCNK[i].ChunkSize;
                    writer.Write(MCNK[i].GetChunkHeaderBytes());
                    writer.Write(MCNK[i].GetChunkBytes());
                }

                // MCIN
                MHDR.OffsetMCIN = (uint)writer.BaseStream.Position;
                writer.Write(MCIN.GetChunkHeaderBytes());
                writer.Write(MCIN.GetChunkBytes());

                // MFBO
                if (MHDR.Flags.HasFlag(MHDRFlags.MFBO))
                {
                    MHDR.OffsetMFBO = (uint)writer.BaseStream.Position;
                    writer.Write(MFBO.GetChunkHeaderBytes());
                    writer.Write(MFBO.GetChunkBytes());
                }
                else
                {
                    MHDR.OffsetMFBO = 0;
                }

                // MTXF
                MHDR.OffsetMTXF = (uint)writer.BaseStream.Position;
                writer.Write(MTXF.GetChunkHeaderBytes());
                writer.Write(MTXF.GetChunkBytes());

                // MHDR
                writer.BaseStream.Position = positionBeforeMHDR;
                writer.Write(MHDR.GetChunkHeaderBytes());
                writer.Write(MHDR.GetChunkBytes());
            }
        }