コード例 #1
0
            public void AddTexture(string fileName)
            {
                BNTX bntx = BNTX.CreateBNTXFromTexture(fileName);
                var  mem  = new MemoryStream();

                bntx.Save(mem);

                string filePath = fileName;

                ArchiveFile.AddFile(new ArchiveFileInfo()
                {
                    FileData   = mem.ToArray(),
                    FileFormat = bntx,
                    FileName   = filePath,
                });
            }
コード例 #2
0
            private void ReplaceAllAction(object sender, EventArgs args)
            {
                LoadTextures();

                List <BNTX> bntxFiles = new List <BNTX>();

                foreach (TextureData node in Textures)
                {
                    bntxFiles.Add(node.ParentBNTX);
                }

                if (bntxFiles.Count > 0)
                {
                    BNTX.ReplaceAll(bntxFiles.ToArray());
                }
            }
コード例 #3
0
ファイル: NUTEXB.cs プロジェクト: vgisuruex/Switch-Toolbox
        public string ArcOffset; //Temp for exporting in batch

        private void Replace(object sender, EventArgs args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            /*  ofd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
             *             "Microsoft DDS |*.dds|" +
             *             "Portable Network Graphics |*.png|" +
             *             "Joint Photographic Experts Group |*.jpg|" +
             *             "Bitmap Image |*.bmp|" +
             *             "Tagged Image File Format |*.tiff|" +
             *             "All files(*.*)|*.*";*/
            ofd.Filter = "Supported Formats|*.dds;" +
                         "Microsoft DDS |*.dds" +
                         "All files(*.*)|*.*";

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var bntxFile = new BNTX();
                var tex      = new TextureData();
                tex.Replace(ofd.FileName);

                if (Surfaces[0].mipmaps[0].Length != Surfaces[0].mipmaps[0].Length)
                {
                    throw new Exception("Image must be the same size!");
                }

                if (Surfaces[0].mipmaps.Count != tex.Surfaces[0].mipmaps.Count)
                {
                    throw new Exception("Map map count must be the same!");
                }

                if (Width != tex.Texture.Width || Height != tex.Texture.Height)
                {
                    throw new Exception("Image size must be the same!");
                }

                ImageData = tex.Texture.TextureData[0][0];
                Surfaces  = tex.Surfaces;

                Width  = tex.Texture.Width;
                Height = tex.Texture.Height;

                UpdateEditor();
            }
        }
コード例 #4
0
            public void Read(FileReader reader, BNTX bntx)
            {
                uint Position = (uint)reader.Position; //Offsets are relative to this

                TextureID = reader.ReadUInt64();
                uint NextDesriptorOffset = reader.ReadUInt32();
                uint StringLength        = reader.ReadUInt32();

                TexName = reader.ReadString(BinaryStringFormat.ZeroTerminated);

                Text = TexName + " " + TextureID.ToString("x");

                if (NextDesriptorOffset != 0)
                {
                    reader.Seek(NextDesriptorOffset + Position, SeekOrigin.Begin);
                }
            }
コード例 #5
0
ファイル: BFRES.cs プロジェクト: vgisuruex/Switch-Toolbox
        private void NewTextureFile(object sender, EventArgs args)
        {
            string Name = "textures";

            for (int i = 0; i < resFile.ExternalFiles.Count; i++)
            {
                if (resFile.ExternalFileDict.GetKey(i) == Name)
                {
                    Name = Name + i;
                }
            }
            if (!Nodes.ContainsKey("EXT"))
            {
                Nodes.Add(new EmbeddedFilesFolder());
            }
            BNTX bntx = new BNTX();

            bntx.Data     = new byte[0];
            bntx.FileName = "textures";
            Nodes["EXT"].Nodes.Add(bntx);
        }
コード例 #6
0
        public override void Replace(string FileName)
        {
            var bntxFile = new BNTX();
            var tex      = new TextureData();

            tex.Replace(FileName, MipCount, 0, Format);

            //If it's null, the operation is cancelled
            if (tex.Texture == null)
            {
                return;
            }

            List <byte[]> data = new List <byte[]>();

            foreach (var array in tex.Texture.TextureData)
            {
                data.Add(array[0]);
            }

            var output = Utils.CombineByteArray(data.ToArray());

            Width    = tex.Texture.Width;
            Height   = tex.Texture.Height;
            MipCount = tex.Texture.MipCount;
            // ArrayCount = tex.Texture.ArrayLength;
            // Depth = tex.Texture.Depth;

            Format    = tex.Format;
            NutFormat = ConvertGenericToNutFormat(tex.Format);

            mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);

            ImageData = SetImageData(output);

            data.Clear();
            UpdateEditor();
        }
コード例 #7
0
        private void AddTexture(BNTX bntx)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Supported Formats|*.bftex;*.dds; *.png;*.tga;*.jpg;*.tiff|" +
                         "Binary Texture |*.bftex|" +
                         "Microsoft DDS |*.dds|" +
                         "Portable Network Graphics |*.png|" +
                         "Joint Photographic Experts Group |*.jpg|" +
                         "Bitmap Image |*.bmp|" +
                         "Tagged Image File Format |*.tiff|" +
                         "All files(*.*)|*.*";
            ofd.DefaultExt  = "bftex";
            ofd.Multiselect = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                foreach (string name in ofd.FileNames)
                {
                    bntx.AddTexture(name);
                    listView1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(name));
                }
            }
        }
コード例 #8
0
        public override void Replace(string FileName)
        {
            var bntxFile = new BNTX();
            var tex      = new TextureData();

            tex.Replace(FileName, MipCount, 0, Format);

            //If it's null, the operation is cancelled
            if (tex.Texture == null)
            {
                return;
            }

            var surfacesNew = tex.GetSurfaces();
            var surfaces    = GetSurfaces();

            if (LimitFileSize)
            {
                if (surfaces[0].mipmaps[0].Length < surfacesNew[0].mipmaps[0].Length)
                {
                    if (surfaces[0].mipmaps[0].Length != surfacesNew[0].mipmaps[0].Length)
                    {
                        throw new Exception($"Image must be the same size! {surfaces[0].mipmaps[0].Length}");
                    }

                    if (mipSizes[0].Length != surfacesNew[0].mipmaps.Count)
                    {
                        throw new Exception($"Mip map count must be the same! {mipSizes[0].Length}");
                    }

                    if (Width != tex.Texture.Width || Height != tex.Texture.Height)
                    {
                        throw new Exception("Image size must be the same!");
                    }
                }

                Width    = tex.Texture.Width;
                Height   = tex.Texture.Height;
                MipCount = tex.Texture.MipCount;
            }
            else
            {
                Width      = tex.Texture.Width;
                Height     = tex.Texture.Height;
                MipCount   = tex.Texture.MipCount;
                ArrayCount = tex.Texture.ArrayLength;
                Depth      = tex.Texture.Depth;

                Format    = tex.Format;
                NutFormat = ConvertGenericToNutFormat(tex.Format);

                mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);
            }

            List <byte[]> data = new List <byte[]>();

            foreach (var array in tex.Texture.TextureData)
            {
                data.Add(array[0]);
            }

            var output = Utils.CombineByteArray(data.ToArray());

            ImageData = SetImageData(output);

            data.Clear();
            surfacesNew.Clear();
            surfaces.Clear();

            UpdateEditor();
        }
コード例 #9
0
            public void LoadTextures()
            {
                if (HasExpanded)
                {
                    return;
                }

                Dictionary <string, TreeNode> folders = new Dictionary <string, TreeNode>();

                //Create a folder lookup
                foreach (TreeNode node in Nodes)
                {
                    var file = (FileEntry)node.Tag;

                    string folder = file.FolderHash.Parent.hash.ToString();
                    if (!folders.ContainsKey(folder))
                    {
                        folders.Add(folder, new TreeNode($"{folders.Count}"));
                    }
                }

                List <TreeNode> subNodes = new List <TreeNode>();

                if (folders.Count > 1)
                {
                    foreach (var node in folders.Values)
                    {
                        subNodes.Add(node);
                    }
                }

                foreach (TreeNode node in Nodes)
                {
                    var file = (FileEntry)node.Tag;
                    if (file.FileFormat == null)
                    {
                        file.FileFormat = file.OpenFile();
                    }

                    string folder = file.FolderHash.Parent.hash.ToString();

                    BNTX bntx = file.FileFormat as BNTX;
                    foreach (var tex in bntx.Textures)
                    {
                        tex.Value.OnTextureDeleted += OnTextureDeleted;
                        //Set tree key for deletion
                        tex.Value.Name = tex.Key;
                        tex.Value.Tag  = file;

                        if (folders.Count > 1)
                        {
                            folders[folder].Nodes.Add(tex.Value);
                        }
                        else
                        {
                            subNodes.Add(tex.Value);
                        }
                        Textures.Add(tex.Value);
                    }
                }

                Nodes.Clear();
                Nodes.AddRange(subNodes.ToArray());

                HasExpanded = true;
            }
コード例 #10
0
        private void Replace(object sender, EventArgs args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = FileFilters.NUTEXB;

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var bntxFile = new BNTX();
                var tex      = new TextureData();
                tex.Replace(ofd.FileName, MipCount, Format);

                //If it's null, the operation is cancelled
                if (tex.Texture == null)
                {
                    return;
                }

                var surfacesNew = tex.GetSurfaces();
                var surfaces    = GetSurfaces();

                if (LimitFileSize)
                {
                    if (surfaces[0].mipmaps[0].Length != surfacesNew[0].mipmaps[0].Length)
                    {
                        throw new Exception($"Image must be the same size! {surfaces[0].mipmaps[0].Length}");
                    }

                    if (mipSizes[0].Length != surfacesNew[0].mipmaps.Count)
                    {
                        throw new Exception($"Mip map count must be the same! {mipSizes[0].Length}");
                    }

                    if (Width != tex.Texture.Width || Height != tex.Texture.Height)
                    {
                        throw new Exception("Image size must be the same!");
                    }

                    ImageData = tex.Texture.TextureData[0][0];

                    Width    = tex.Texture.Width;
                    Height   = tex.Texture.Height;
                    MipCount = tex.Texture.MipCount;
                }
                else
                {
                    ImageData = tex.Texture.TextureData[0][0];

                    Width    = tex.Texture.Width;
                    Height   = tex.Texture.Height;
                    MipCount = tex.Texture.MipCount;

                    Format    = tex.Format;
                    NutFormat = ConvertGenericToNutFormat(tex.Format);

                    mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);
                }

                surfacesNew.Clear();
                surfaces.Clear();

                UpdateEditor();
            }
        }
コード例 #11
0
ファイル: NUTEXB.cs プロジェクト: cano159/Switch-Toolbox
        public string ArcOffset; //Temp for exporting in batch

        private void Replace(object sender, EventArgs args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
                         "Microsoft DDS |*.dds|" +
                         "Portable Network Graphics |*.png|" +
                         "Joint Photographic Experts Group |*.jpg|" +
                         "Bitmap Image |*.bmp|" +
                         "Tagged Image File Format |*.tiff|" +
                         "All files(*.*)|*.*";

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var bntxFile = new BNTX();
                var tex      = new TextureData();
                tex.Replace(ofd.FileName, MipCount, Format);

                //If it's null, the operation is cancelled
                if (tex.Texture == null)
                {
                    return;
                }

                var surfacesNew = tex.GetSurfaces();
                var surfaces    = GetSurfaces();

                if (LimitFileSize)
                {
                    if (surfaces[0].mipmaps[0].Length != surfacesNew[0].mipmaps[0].Length)
                    {
                        throw new Exception($"Image must be the same size! {surfaces[0].mipmaps[0].Length}");
                    }

                    if (mipSizes[0].Length != surfacesNew[0].mipmaps.Count)
                    {
                        throw new Exception($"Mip map count must be the same! {mipSizes[0].Length}");
                    }

                    if (Width != tex.Texture.Width || Height != tex.Texture.Height)
                    {
                        throw new Exception("Image size must be the same!");
                    }

                    ImageData = tex.Texture.TextureData[0][0];

                    Width    = tex.Texture.Width;
                    Height   = tex.Texture.Height;
                    MipCount = tex.Texture.MipCount;
                }
                else
                {
                    ImageData = tex.Texture.TextureData[0][0];

                    Width    = tex.Texture.Width;
                    Height   = tex.Texture.Height;
                    MipCount = tex.Texture.MipCount;

                    Format    = tex.Format;
                    NutFormat = ConvertGenericToNutFormat(tex.Format);

                    mipSizes = GenerateMipSizes();
                }

                surfacesNew.Clear();
                surfaces.Clear();

                UpdateEditor();
            }
        }
コード例 #12
0
            private void ReadSectionData(SectionBase section, Header ptclHeader, FileReader reader)
            {
                if (section.BinaryDataOffset != NullOffset)
                {
                    using (reader.TemporarySeek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin))
                    {
                        BinaryDataBytes = reader.ReadBytes((int)section.SectionSize);
                    }
                }

                switch (section.Signature)
                {
                case "TEXR":
                    section.Text = "Texture Info";
                    BinaryData   = new TEXR();

                    if (SubSectionCount > 0)
                    {
                        //Set the data block first!
                        reader.Seek(SubSectionOffset + section.Position, SeekOrigin.Begin);
                        var dataBlockSection = new SectionBase();
                        dataBlockSection.Read(reader, ptclHeader, "GX2B");

                        if (dataBlockSection.BinaryDataOffset != NullOffset)
                        {
                            reader.Seek(dataBlockSection.BinaryDataOffset + dataBlockSection.Position, SeekOrigin.Begin);
                            ((TEXR)BinaryData).data = reader.ReadBytes((int)dataBlockSection.SectionSize);
                        }
                    }

                    reader.Seek(BinaryDataOffset + section.Position, SeekOrigin.Begin);
                    ((TEXR)BinaryData).Read(reader, ptclHeader);

                    break;

                case "SHDB":
                    reader.Seek(BinaryDataOffset + section.Position, SeekOrigin.Begin);
                    section.Text = "GTX Shader";
                    reader.ReadBytes((int)section.SectionSize);
                    break;

                case "EMTR":
                    reader.Seek(BinaryDataOffset + 16 + section.Position, SeekOrigin.Begin);
                    Text = reader.ReadString(BinaryStringFormat.ZeroTerminated);

                    reader.Seek(BinaryDataOffset + 16 + 64 + section.Position, SeekOrigin.Begin);
                    BinaryData = new Emitter();
                    ((Emitter)BinaryData).Read(reader, ptclHeader);
                    break;

                case "ESTA":
                    section.Text = "Emitter Sets";
                    break;

                case "ESET":
                    byte[] Padding = reader.ReadBytes(16);
                    section.Text = reader.ReadString(BinaryStringFormat.ZeroTerminated);
                    break;

                case "GRTF":
                    if (section.BinaryDataOffset != NullOffset)
                    {
                        reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                        BinaryData = new BNTX();
                        ((BNTX)BinaryData).FileName = "textures.bntx";
                        ((BNTX)BinaryData).Load(new MemoryStream(reader.ReadBytes((int)section.SectionSize)));
                        ((BNTX)BinaryData).IFileInfo.InArchive = true;
                        Nodes.Add(((BNTX)BinaryData));
                    }
                    break;

                case "PRMA":
                    break;

                case "ESFT":
                    reader.Seek(28, SeekOrigin.Current);
                    int StringSize = reader.ReadInt32();
                    section.Text = reader.ReadString(StringSize, Encoding.ASCII);
                    break;

                case "GRSN":
                    section.Text = "Shaders";

                    if (section.BinaryDataOffset != NullOffset)
                    {
                        reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                        BinaryData = reader.ReadBytes((int)section.SectionSize);
                    }
                    break;

                case "GRSC":
                    section.Text = "Shaders 2";
                    if (section.BinaryDataOffset != NullOffset)
                    {
                        reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                        BinaryData = reader.ReadBytes((int)section.SectionSize);
                    }
                    break;

                case "G3PR":
                    if (section.BinaryDataOffset != NullOffset)
                    {
                        reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                        BinaryData = new BFRES();
                        ((BFRES)BinaryData).FileName = "model.bfres";
                        ((BFRES)BinaryData).Load(new MemoryStream(reader.ReadBytes((int)section.SectionSize)));
                        ((BFRES)BinaryData).IFileInfo           = new IFileInfo();
                        ((BFRES)BinaryData).IFileInfo.InArchive = true;
                        Nodes.Add(((BFRES)BinaryData));
                    }
                    break;

                case "GTNT":
                    if (section.BinaryDataOffset != NullOffset)
                    {
                        foreach (var node in Parent.Nodes)
                        {
                            if (node is BNTX)
                            {
                                BNTX bntx = (BNTX)node;

                                reader.Seek(section.BinaryDataOffset + section.Position, SeekOrigin.Begin);
                                for (int i = 0; i < bntx.Textures.Count; i++)
                                {
                                    var texDescriptor = new TextureDescriptor();
                                    Nodes.Add(texDescriptor);
                                    texDescriptor.Read(reader, bntx);
                                }
                            }
                        }
                    }
                    break;
                }
            }
コード例 #13
0
            private void MapTextureIDs(PTCL ptcl)
            {
                List <TextureDescriptor> texDescp = new List <TextureDescriptor>();
                List <Emitter>           emitters = new List <Emitter>();
                BNTX        bntx    = null;
                List <TEXR> botwTex = new List <TEXR>(); //Used for BOTW

                foreach (var node in TreeViewExtensions.Collect(ptcl.Nodes))
                {
                    if (node is TextureDescriptor)
                    {
                        texDescp.Add((TextureDescriptor)node);
                    }
                    if (node is SectionBase && ((SectionBase)node).BinaryData is Emitter)
                    {
                        emitters.Add((Emitter)((SectionBase)node).BinaryData);
                    }
                    if (node is BNTX)
                    {
                        bntx = (BNTX)node;
                    }
                    if (node is SectionBase && ((SectionBase)node).BinaryData is TEXR)
                    {
                        botwTex.Add((TEXR)((SectionBase)node).BinaryData);
                    }
                }

                int index = 0;

                if (botwTex.Count > 0)
                {
                    TreeNode textureFolder = new TreeNode("Textures");
                    ptcl.Nodes.Add(textureFolder);

                    List <TEXR> TextureList = new List <TEXR>();

                    foreach (var emitter in emitters)
                    {
                        foreach (TEXR tex in botwTex)
                        {
                            bool HasImage = TextureList.Any(item => item.data == tex.data);
                            if (!HasImage)
                            {
                                tex.Text = "Texture " + index++;
                                textureFolder.Nodes.Add(tex);
                            }
                            TextureList.Add(tex);

                            foreach (var sampler in emitter.Samplers)
                            {
                                if (sampler.TextureID == tex.TextureID)
                                {
                                    emitter.DrawableTex.Add(tex);
                                }
                            }
                        }
                    }
                    TextureList.Clear();
                }


                if (bntx == null)
                {
                    return;
                }

                foreach (var emitter in emitters)
                {
                    foreach (var tex in texDescp)
                    {
                        foreach (var sampler in emitter.Samplers)
                        {
                            if (sampler.TextureID == tex.TextureID)
                            {
                                if (bntx.Textures.ContainsKey(tex.TexName))
                                {
                                    emitter.DrawableTex.Add(bntx.Textures[tex.TexName]);
                                }
                            }
                        }
                    }
                }
            }