Example #1
0
        public Dictionary <string, STGenericTexture> GetTextures()
        {
            Dictionary <string, STGenericTexture> textures = new Dictionary <string, STGenericTexture>();

            if (IFileInfo.ArchiveParent != null)
            {
                foreach (var file in IFileInfo.ArchiveParent.Files)
                {
                    if (Utils.GetExtension(file.FileName) == ".tpl")
                    {
                        TPL tpl = (TPL)file.OpenFile();
                        file.FileFormat = tpl;
                        foreach (var tex in tpl.IconTextureList)
                        {
                            if (!textures.ContainsKey(tex.Text))
                            {
                                textures.Add(tex.Text, tex);
                            }
                        }
                    }
                }
            }

            return(textures);
        }
Example #2
0
        public override void Open(HSDReader Reader)
        {
            uint DataOffset = Reader.ReadUInt32();

            base.Open(Reader);
            Data = Reader.ReadBuffer(DataOffset, TPL.TextureByteSize((TPL_TextureFormat)Format, Width, Height));
        }
Example #3
0
        private void btnFromTplInputBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "TPL|*.tpl";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try { inputTpl = TPL.Load(ofd.FileName); }
                catch { MessageBox.Show("The selected file is not a valid TPL!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }

                tbFromTplInput.Text = ofd.FileName;

                if (inputTpl.NumOfTextures > 1)
                {
                    cmbFromTplTexture.Items.Clear();

                    for (int i = 0; i < inputTpl.NumOfTextures; i++)
                    {
                        cmbFromTplTexture.Items.Add(i + 1);
                    }

                    cmbFromTplTexture.SelectedIndex = 0;

                    cmbFromTplTexture.Visible = true;
                    lbFromTplTexture.Visible  = true;
                }
                else
                {
                    cmbFromTplTexture.Visible = false;
                    lbFromTplTexture.Visible  = false;
                }
            }
        }
Example #4
0
        public Dictionary <string, STGenericTexture> GetTextures()
        {
            Dictionary <string, STGenericTexture> textures = new Dictionary <string, STGenericTexture>();

            if (IFileInfo.ArchiveParent != null)
            {
                foreach (var file in IFileInfo.ArchiveParent.Files)
                {
                    try
                    {
                        if (Utils.GetExtension(file.FileName) == ".tpl")
                        {
                            TPL tpl = (TPL)file.OpenFile();
                            file.FileFormat = tpl;
                            foreach (var tex in tpl.TextureList)
                            {
                                //Only need the first texture
                                if (!textures.ContainsKey(tex.Text))
                                {
                                    textures.Add(file.FileName, tex);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        STErrorDialog.Show($"Failed to load texture {file.FileName}. ", "Layout Editor", ex.ToString());
                    }
                }
            }

            return(textures);
        }
Example #5
0
        public static void ReplaceTexture(Image newImage, TextureListObject textureListObject)
        {
            ImageHeader   imageHeader   = textureListObject.imageHeader;
            PaletteHeader paletteHeader = textureListObject.paletteHeader;

            byte[] newPaletteData;
            byte[] newTextureData = TPL.ConvertToTextureMelee(newImage, textureListObject, out newPaletteData);

            if (newTextureData.Length != textureListObject.imageSize)
            {
                MessageBox.Show("Error: Selected image is not the same file size!");
                return;
            }

            if (paletteHeader != null && newPaletteData.Length > paletteHeader.colorCount0xC * 2)
            {
                MessageBox.Show(
                    "The selected image contains more colors than the original image. Please use no more than " + paletteHeader.colorCount0xC + " colors.");
                return;
            }

            Array.ConstrainedCopy(newTextureData, 0, file, (int)(imageHeader.imageOffset0x0 + dataOffset), newTextureData.Length);
            if (paletteHeader != null)
            {
                Array.ConstrainedCopy(newPaletteData, 0, file, (int)(paletteHeader.paletteOffset0x0 + dataOffset), Math.Min((paletteHeader.colorCount0xC * 2), newPaletteData.Length));
            }
            OpenDatFile(file, fileName, ref textureList);
        }
Example #6
0
        private static void From(string[] args)
        {
            string input  = args[2];
            string output = args[3];

            //Check if file exists
            if (File.Exists(input) == false)
            {
                Console.WriteLine("ERROR: Unable to open file: {0}", input);
                Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                Console.WriteLine("Error: SHARPII_NET_CORE_TPL_FILE_ERR_01");
                Environment.Exit(0x00003E81);
                return;
            }

            //Run main part, and check for exceptions
            try
            {
                //Load tpl
                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Loading file...");
                }

                TPL tplfile = libWiiSharp.TPL.Load(input);

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                //save image
                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Extracting texture...");
                }

                tplfile.ExtractTexture(output);

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Operation completed succesfully!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error occured, please try again");
                Console.WriteLine("");
                Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                Console.WriteLine("Error: SHARPII_NET_CORE_TPL_UNKNOWN_01");
                Environment.Exit(0x00003E82);
                return;
            }
        }
Example #7
0
 public TextureListObject(UInt32 imageHeaderOffset, TextureNode node)
 {
     name          = "Texture " + (DatFile.textureList.Items.Count + 1) + " (" + imageHeaderOffset.ToString("x8") + ")";
     this.node     = node;
     imageHeader   = node.imageHeader;
     paletteHeader = node.paletteHeader;
     imageBitmap   = TPL.ConvertFromTextureMelee(imageHeader, paletteHeader, out imageSize);
 }
Example #8
0
        private void Read(FileReader reader, uint resourceType)
        {
            reader.SetByteOrder(true);

            ResourceType = resourceType;

            //Offsets are multiplied by 4
            positionsOffset      = reader.ReadUInt32() * 4;
            normalsoffset        = reader.ReadUInt32() * 4;
            colorsOffset         = reader.ReadUInt32() * 4;
            texCoordsOffset      = reader.ReadUInt32() * 4;
            materialColorsOffset = reader.ReadUInt32() * 4;
            uint textureContainerOffset = reader.ReadUInt32() * 4;
            uint drawElementCount       = reader.ReadUInt32();
            uint drawElementsOffset     = reader.ReadUInt32() * 4;
            uint shapeCount             = reader.ReadUInt32();
            uint shapesOffset           = reader.ReadUInt32() * 4;
            uint packetCount            = reader.ReadUInt32();
            uint packetsOffset          = reader.ReadUInt32() * 4;

            TextureContainer          = new TPL();
            TextureContainer.FileInfo = new File_Info();
            if (textureContainerOffset != 0)
            {
                TextureContainer.Load(new SubStream(
                                          reader.BaseStream, textureContainerOffset));
            }

            List <uint> readShapes = new List <uint>();

            for (int i = 0; i < drawElementCount; i++)
            {
                reader.SeekBegin(drawElementsOffset + (i * 8));
                uint numShapes   = reader.ReadUInt32();
                uint shapeOffset = reader.ReadUInt32() * 4;

                //Model lists often have dupes so skip those
                //Usually they are fixed to have 5 of them.
                //Then they get lower in detail.
                if (readShapes.Contains(shapeOffset))
                {
                    break;
                }

                ModelGroup model = new ModelGroup();
                Models.Add(model);

                readShapes.Add(shapeOffset);

                for (int j = 0; j < numShapes; j++)
                {
                    reader.SeekBegin(shapeOffset + (j * 8));
                    model.Meshes.Add(ReadShape(reader));
                }
            }
        }
Example #9
0
        public override void Open(HSDReader Reader)
        {
            uint DataOffset = Reader.ReadUInt32();

            Format     = (GXTlutFmt)Reader.ReadUInt32();
            GXTlut     = Reader.ReadUInt32();
            ColorCount = Reader.ReadUInt16();
            Reader.ReadUInt16();

            Data = Reader.ReadBuffer(DataOffset, TPL.PaletteByteSize((TPL_PaletteFormat)Format, ColorCount));
        }
        private void TextureViewer_Load(object sender, EventArgs e)
        {
            byte[] untrimmed = MainWindow.x;
            byte[] trimmed   = untrimmed.Skip(32).ToArray();
            var    bmp       = TPL.Load(trimmed);
            Bitmap newbmp    = new Bitmap(bmp.ExtractTexture());

            lblActualWidth.Text    = newbmp.Width.ToString();
            lblActuHeight.Text     = newbmp.Height.ToString();
            textureViewerBox.Image = newbmp;
        }
Example #11
0
        private static void From(string[] args)
        {
            string input  = args[2];
            string output = args[3];

            //Check if file exists
            if (File.Exists(input) == false)
            {
                Console.WriteLine("ERROR: Unable to open file: {0}", input);
                return;
            }

            //Run main part, and check for exceptions
            try
            {
                //Load tpl
                if (Quiet.quiet > 2)
                {
                    Console.Write("Loading file...");
                }

                TPL tplfile = libWiiSharp.TPL.Load(input);

                if (Quiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                //save image
                if (Quiet.quiet > 2)
                {
                    Console.Write("Extracting texture...");
                }

                tplfile.ExtractTexture(output);

                if (Quiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                if (Quiet.quiet > 1)
                {
                    Console.WriteLine("Operation completed succesfully!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error occured, please try again");
                Console.WriteLine("");
                Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                return;
            }
        }
Example #12
0
 static void Main(string[] args)
 {
     Cache.runPath = Directory.GetCurrentDirectory() + "\\";
     //EachLoad();
     //Unload();
     //Load();
     //Run();
     //RunFile();
     //RunCode();
     TPL.Init();
     View();
     Console.ReadLine();
 }
Example #13
0
        public override void Open(HSDReader Reader)
        {
            uint DataOffset = Reader.ReadUInt32();

            Width  = Reader.ReadUInt16();
            Height = Reader.ReadUInt16();
            Format = (GXTexFmt)Reader.ReadUInt32();
            Mipmap = Reader.ReadUInt32();
            MinLOD = Reader.ReadSingle();
            MaxLOD = Reader.ReadSingle();

            Data = Reader.ReadBuffer(DataOffset, TPL.TextureByteSize((TPL_TextureFormat)Format, Width, Height));
        }
Example #14
0
        /// <summary>
        /// Creates a <see cref="Bitmap"/> of this texture
        /// </summary>
        /// <returns></returns>
        public Bitmap ToBitmap()
        {
            if (ImageData != null && Tlut != null)
            {
                return(TPL.ConvertFromTextureMelee(ImageData.Data, ImageData.Width, ImageData.Height, (int)ImageData.Format, Tlut.Data, Tlut.ColorCount, (int)Tlut.Format));
            }

            if (ImageData != null)
            {
                return(TPL.ConvertFromTextureMelee(ImageData.Data, ImageData.Width, ImageData.Height, (int)ImageData.Format, null, 0, 0));
            }

            return(null);
        }
Example #15
0
 static void RunSection1_1()
 {
     //TPL.ParallelInvoke();
     //TPL.ParallelForEach();
     //TPL.ParallelFor();
     //TPL.ParallelLoopState();
     //TPL.AsParallel();
     //TPL.Tasks();
     //TPL.Tasks2();
     //TPL.WaitAll();
     //TPL.Continuation();
     //TPL.Threads();
     TPL.ThreadLocal();
 }
        public void makeTexturesSolidColor(Color colorChooser)
        {
            foreach (var layer in MAST.sectionSect2.layers)
            {
                if (layer.subLayer is SubLayer_PSL psl)
                {
                    foreach (var asset in psl.assets)
                    {
                        string convertedStr = BitConverter.ToString(asset.data).Replace("-", " ");
                        if (convertedStr.Contains("00 00 00 01 3F 80 00 00 00 02 00 00 78 C8 74 06 EE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 AF 30 00 00 00 02 00 00 00 0C 00 00 00 1C"))
                        {
                            int      Width    = 64;
                            int      Height   = 64;
                            Bitmap   newBmp   = new Bitmap(Width, Height);
                            Graphics graphics = Graphics.FromImage(newBmp);

                            Brush brush = new SolidBrush(colorChooser);

                            graphics.FillRectangle(brush, new System.Drawing.Rectangle(0, 0, newBmp.Width, newBmp.Height));
                            Bitmap newTextureFile  = new Bitmap(newBmp, 64, 64);
                            var    newTPLTEMP      = TPL.FromImage(newTextureFile, TPL_TextureFormat.RGB565);
                            byte[] finalNewTexture = newTPLTEMP.ToByteArray();

                            string extraHeaderData32Bytes = "00 00 00 01 3F 80 00 00 00 02 00 00 78 C8 74 06 EE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
                            byte[] extraHeaderData        = extraHeaderData32Bytes
                                                            .Split(' ')                               // Split into items
                                                            .Select(item => Convert.ToByte(item, 16)) // Convert each item into byte
                                                            .ToArray();
                            List <byte> list = new List <byte>();
                            list.AddRange(extraHeaderData);
                            list.AddRange(finalNewTexture);

                            byte[] ActualFinalTexture = list.ToArray();
                            customTextureData = ActualFinalTexture;

                            MainWindow form = Application.OpenForms.OfType <MainWindow>().FirstOrDefault();
                            if (form != null)
                            {
                                form.ReplaceInEditableArray(asset.absoluteDataOffset, customTextureData, asset.totalDataSize);

                                asset.actualSize = customTextureData.Length;
                                form.WriteNewSizeInEditableArray(asset.absoluteActualSizeOffset, customTextureData.Length);
                            }
                        }
                    }
                }
            }
        }
Example #17
0
 /// <summary>
 /// Sets the image data from a <see cref="Bitmap"/>
 /// </summary>
 /// <param name="b"></param>
 public void SetFromBitmap(Bitmap b, GXTexFmt imageFormat, GXTlutFmt paletteFormat)
 {
     byte[] palData;
     ImageData        = new HSD_Image();
     ImageData.Width  = (ushort)b.Width;
     ImageData.Height = (ushort)b.Height;
     ImageData.Format = imageFormat;
     ImageData.Data   = TPL.ConvertToTextureMelee(b, (int)imageFormat, (int)paletteFormat, out palData);
     if (palData != null && palData.Length > 0)
     {
         Tlut            = new HSD_Tlut();
         Tlut.Format     = paletteFormat;
         Tlut.ColorCount = (ushort)(palData.Length / 2);
         Tlut.Data       = palData;
     }
 }
        public void DumpTextures(string dumpFolder)
        {
            string directoryToUnpack = Path.Combine(dumpFolder, "Extracted Texture Files");

            foreach (var layer in MAST.sectionSect2.layers)
            {
                if (layer.subLayer is SubLayer_PSL psl)
                {
                    foreach (var asset in psl.assets)
                    {
                        string convertedStr = BitConverter.ToString(asset.data).Replace("-", " ");
                        if (convertedStr.Contains("00 00 00 01 3F 80 00 00 00 02 00 00 78 C8 74 06 EE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 AF 30 00 00 00 02 00 00 00 0C 00 00 00 1C"))
                        {
                            byte[] untrimmed = asset.data;
                            byte[] trimmed   = untrimmed.Skip(32).ToArray();
                            var    bmp       = TPL.Load(trimmed);
                            Bitmap newbmp    = new Bitmap(bmp.ExtractTexture());
                            string type;
                            if (Enum.IsDefined(typeof(AssetTypeHashed), asset.assetType))
                            {
                                type = ((AssetTypeHashed)asset.assetType).ToString();
                            }
                            else
                            {
                                type = asset.assetType.ToString("X8");
                            }

                            string name = $"[{type}] [{asset.assetID.ToString("X16")}]";
                            if (!Directory.Exists(directoryToUnpack))
                            {
                                Directory.CreateDirectory(directoryToUnpack);
                            }
                            newbmp.Save(Path.Combine(directoryToUnpack, name) + ".png", ImageFormat.Png);
                            if (File.Exists(dumpFolder))
                            {
                                getNextFileName(name);
                            }
                        }
                    }
                }
            }
        }
        private void btnReplaceWithSolidColor_Click(object sender, EventArgs e)
        {
            ColorDialog cld = new ColorDialog();

            if (cld.ShowDialog() == DialogResult.OK)
            {
                int Width  = 64;
                int Height = 64;
                textureViewerBox.Image = new Bitmap(Width, Height);
                Graphics graphics = Graphics.FromImage(textureViewerBox.Image);

                Brush brush = new SolidBrush(cld.Color);

                graphics.FillRectangle(brush, new System.Drawing.Rectangle(0, 0, textureViewerBox.Width, textureViewerBox.Height));
                Bitmap newTextureFile  = new Bitmap(textureViewerBox.Image, 64, 64);
                var    newTPLTEMP      = TPL.FromImage(newTextureFile, TPL_TextureFormat.RGB565);
                byte[] finalNewTexture = newTPLTEMP.ToByteArray();

                string extraHeaderData32Bytes = "00 00 00 01 3F 80 00 00 00 02 00 00 78 C8 74 06 EE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
                byte[] extraHeaderData        = extraHeaderData32Bytes
                                                .Split(' ')                               // Split into items
                                                .Select(item => Convert.ToByte(item, 16)) // Convert each item into byte
                                                .ToArray();
                List <byte> list = new List <byte>();
                list.AddRange(extraHeaderData);
                list.AddRange(finalNewTexture);

                byte[] ActualFinalTexture = list.ToArray();



                customTextureData = ActualFinalTexture;

                MainWindow form = Application.OpenForms.OfType <MainWindow>().FirstOrDefault();
                if (form != null)
                {
                    form.saveNewCustomTexture(sender, e);
                    form.refreshTextureViewerPreviewBox();
                }
            }
        }
Example #20
0
        private void btnToTpl_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbToTplInput.Text) && !string.IsNullOrEmpty(tbToTplOutput.Text))
            {
                try
                {
                    TPL_TextureFormat tplFormat = TPL_TextureFormat.RGBA8;

                    switch (cmbToTplFormat.SelectedIndex)
                    {
                    case 0:
                        tplFormat = TPL_TextureFormat.RGBA8; break;

                    case 1:
                        tplFormat = TPL_TextureFormat.RGB565; break;

                    case 2:
                        tplFormat = TPL_TextureFormat.RGB5A3; break;

                    case 3:
                        tplFormat = TPL_TextureFormat.IA8; break;

                    case 4:
                        tplFormat = TPL_TextureFormat.IA4; break;

                    case 5:
                        tplFormat = TPL_TextureFormat.I8; break;

                    case 6:
                        tplFormat = TPL_TextureFormat.I4; break;
                    }

                    TPL t = TPL.FromImage(inputImage, tplFormat);
                    t.Save(tbToTplOutput.Text);

                    MessageBox.Show("Successfully saved TPL to:\n" + tbToTplOutput.Text, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
        }
        private void btnImportTexture_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                byte[] saveToArray             = MainWindow.x;
                var    newTextureFileFromImage = textureViewerBox.Image = new Bitmap(ofd.FileName);
                textureViewerBox.Image = newTextureFileFromImage;


                Bitmap newTextureFile  = new Bitmap(textureViewerBox.Image, 64, 64);
                var    newTPLTEMP      = TPL.FromImage(newTextureFile, TPL_TextureFormat.RGB565);
                byte[] finalNewTexture = newTPLTEMP.ToByteArray();

                string extraHeaderData32Bytes = "00 00 00 01 3F 80 00 00 00 02 00 00 78 C8 74 06 EE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
                byte[] extraHeaderData        = extraHeaderData32Bytes
                                                .Split(' ')                               // Split into items
                                                .Select(item => Convert.ToByte(item, 16)) // Convert each item into byte
                                                .ToArray();
                List <byte> list = new List <byte>();
                list.AddRange(extraHeaderData);
                list.AddRange(finalNewTexture);

                byte[] ActualFinalTexture = list.ToArray();



                customTextureData = ActualFinalTexture;

                MainWindow form = Application.OpenForms.OfType <MainWindow>().FirstOrDefault();
                if (form != null)
                {
                    form.saveNewCustomTexture(sender, e);
                    form.refreshTextureViewerPreviewBox();
                }
            }
        }
Example #22
0
 public override void Import()
 {
     tpl = new TPL(GetStreamFromFile(filename));
     Export();
 }
Example #23
0
        private void TexturesList_DoubleClick(object sender, EventArgs e)
        {
            if (texturesList.Items.Count == 0)
            {
                return;
            }

            string ext = Path.GetExtension(texturesList.GetItemText(texturesList.SelectedItem));

            string[] exts        = { ".bti", ".tpl", ".bclim" };
            bool     isSupported = false;

            for (int i = 0; i < exts.Length; i++)
            {
                if (exts[i] == ext)
                {
                    isSupported = true;
                    break;
                }
            }

            if (!isSupported)
            {
                MessageBox.Show("This image format does not support viewing yet.");
                return;
            }

            string fullPath = mMainRoot + "timg/" + texturesList.GetItemText(texturesList.SelectedItem);

            byte[] data = null;

            if (mLayoutImages.ContainsKey(fullPath))
            {
                data = mLayoutImages[fullPath];
            }

            // this is because TEX1 has paths as upper but the filenames are lowercase
            if (data == null)
            {
                if (mLayoutImages.ContainsKey(fullPath.ToLower()))
                {
                    data = mLayoutImages[fullPath.ToLower()];
                }
            }

            if (data == null)
            {
                return;
            }

            EndianBinaryReader reader = new EndianBinaryReader(data);

            ImageContainerBase container = null;

            // no need for a default case since it will return if the format isnt supported
            switch (ext)
            {
            case ".tpl":
                container = new TPL(ref reader);
                break;

            case ".bti":
                container = new BTI(ref reader);
                break;

            case ".bclim":
                container = new BCLIM(ref reader);
                break;
            }

            if (container == null)
            {
                return;
            }

            ImageViewer viewer = new ImageViewer(texturesList.GetItemText(texturesList.SelectedItem));

            viewer.setImage(container.getImage(0));
            viewer.Show();
        }
        private void Preview_Load(object sender, EventArgs e)
        {
            this.CenterToParent();
            cbBanner.Items.Clear();
            cbIcon.Items.Clear();

            int startIndex = -1;

            List <TplImage> bannerImages = new List <TplImage>();
            List <TplImage> iconImages   = new List <TplImage>();

            for (int i = 0; i < bannerBin.NumOfNodes; i++)
            {
                if (bannerBin.StringTable[i].ToLower().EndsWith(".tpl"))
                {
                    TplImage tmpImage = new TplImage();
                    TPL      tmpTpl   = TPL.Load(bannerBin.Data[i]);

                    if (i == 10)
                    {
                    }

                    tmpImage.fileName     = bannerBin.StringTable[i];
                    tmpImage.tplFormat    = tmpTpl.GetTextureFormat(0).ToString();
                    tmpImage.tplImage     = tmpTpl.ExtractTexture();
                    tmpImage.checkerBoard = createCheckerBoard(tmpImage.tplImage.Width, tmpImage.tplImage.Height);

                    if (tmpImage.tplFormat.StartsWith("CI"))
                    {
                        tmpImage.tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                    }

                    bannerImages.Add(tmpImage);
                }
            }

            for (int i = 0; i < iconBin.NumOfNodes; i++)
            {
                if (iconBin.StringTable[i].ToLower().EndsWith(".tpl"))
                {
                    TplImage tmpImage = new TplImage();
                    TPL      tmpTpl   = TPL.Load(iconBin.Data[i]);

                    tmpImage.fileName     = iconBin.StringTable[i];
                    tmpImage.tplFormat    = tmpTpl.GetTextureFormat(0).ToString();
                    tmpImage.tplImage     = tmpTpl.ExtractTexture();
                    tmpImage.checkerBoard = createCheckerBoard(tmpImage.tplImage.Width, tmpImage.tplImage.Height);

                    if (tmpImage.tplFormat.StartsWith("CI"))
                    {
                        tmpImage.tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                    }

                    iconImages.Add(tmpImage);
                }
            }

            images[0] = bannerImages.ToArray();
            images[1] = iconImages.ToArray();

            for (int i = 0; i < images[0].Length; i++)
            {
                cbBanner.Items.Add(images[0][i].fileName);
                if (!startIcon)
                {
                    if (images[0][i].fileName.ToLower() == startTPL.ToLower())
                    {
                        startIndex = i;
                    }
                }
            }

            for (int i = 0; i < images[1].Length; i++)
            {
                cbIcon.Items.Add(images[1][i].fileName);
                if (startIcon)
                {
                    if (images[1][i].fileName.ToLower() == startTPL.ToLower())
                    {
                        startIndex = i;
                    }
                }
            }

            try
            {
                if (startIndex != -1)
                {
                    if (!startIcon)
                    {
                        cbBanner.SelectedIndex = startIndex;
                    }
                    else
                    {
                        cbIcon.SelectedIndex = startIndex;
                    }
                }
            }
            catch { }

            if (cbBanner.SelectedIndex != -1)
            {
                cbBanner.Select();
            }
            else if (cbIcon.SelectedIndex != -1)
            {
                cbIcon.Select();
            }

            tipTimer.Interval = 7000;
            tipTimer.Tag      = 0;
            tipTimer.Tick    += new EventHandler(tipTimer_Tick);
        }
        private void cmChangeFormat_Click(object sender, EventArgs e)
        {
            try
            {
                string tplName;
                TPL    tmpTpl = new TPL();
                Image  newImg;

                if (cbIcon.SelectedIndex == -1)
                {
                    tplName = cbBanner.SelectedItem.ToString().ToLower();
                    tmpTpl.LoadFile(bannerBin.Data[bannerBin.GetNodeIndex(tplName)]);
                }
                else
                {
                    tplName = cbIcon.SelectedItem.ToString().ToLower();
                    tmpTpl.LoadFile(iconBin.Data[iconBin.GetNodeIndex(tplName)]);
                }

                newImg = tmpTpl.ExtractTexture();
                TPL_TextureFormat tplFormat;
                TPL_PaletteFormat pFormat = TPL_PaletteFormat.RGB5A3;

                ToolStripMenuItem cmSender = sender as ToolStripMenuItem;
                switch (cmSender.Tag.ToString().ToLower())
                {
                case "i4":
                    tplFormat = TPL_TextureFormat.I4;
                    break;

                case "i8":
                    tplFormat = TPL_TextureFormat.I8;
                    break;

                case "ia4":
                    tplFormat = TPL_TextureFormat.IA4;
                    break;

                case "ia8":
                    tplFormat = TPL_TextureFormat.IA8;
                    break;

                case "rgb565":
                    tplFormat = TPL_TextureFormat.RGB565;
                    break;

                case "rgb5a3":
                    tplFormat = TPL_TextureFormat.RGB5A3;
                    break;

                case "ci8rgb5a3":
                    tplFormat = TPL_TextureFormat.CI8;
                    pFormat   = TPL_PaletteFormat.RGB5A3;
                    break;

                case "ci8rgb565":
                    tplFormat = TPL_TextureFormat.CI8;
                    pFormat   = TPL_PaletteFormat.RGB565;
                    break;

                case "ci8ia8":
                    tplFormat = TPL_TextureFormat.CI8;
                    pFormat   = TPL_PaletteFormat.IA8;
                    break;

                case "ci4rgb5a3":
                    tplFormat = TPL_TextureFormat.CI4;
                    pFormat   = TPL_PaletteFormat.RGB5A3;
                    break;

                case "ci4rgb565":
                    tplFormat = TPL_TextureFormat.CI4;
                    pFormat   = TPL_PaletteFormat.RGB565;
                    break;

                case "ci4ia8":
                    tplFormat = TPL_TextureFormat.CI4;
                    pFormat   = TPL_PaletteFormat.IA8;
                    break;

                default:
                    tplFormat = TPL_TextureFormat.RGBA8;
                    break;
                }

                if (tmpTpl.GetTextureFormat(0) == tplFormat)
                {
                    return;
                }

                tmpTpl.RemoveTexture(0);
                tmpTpl.AddTexture(newImg, tplFormat, pFormat);

                if (cbBanner.SelectedIndex != -1)
                {
                    bannerBin.ReplaceFile(bannerBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                    images[0][cbBanner.SelectedIndex].tplImage  = tmpTpl.ExtractTexture();
                    images[0][cbBanner.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                    if (images[0][cbBanner.SelectedIndex].tplFormat.StartsWith("CI"))
                    {
                        images[0][cbBanner.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                    }

                    pbPic.Image   = images[0][cbBanner.SelectedIndex].tplImage;
                    lbFormat.Text = images[0][cbBanner.SelectedIndex].tplFormat;
                    lbSize.Text   = string.Format("{0} x {1}", images[0][cbBanner.SelectedIndex].tplImage.Width, images[0][cbBanner.SelectedIndex].tplImage.Height);
                }
                else
                {
                    iconBin.ReplaceFile(iconBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                    images[1][cbIcon.SelectedIndex].tplImage  = tmpTpl.ExtractTexture();
                    images[1][cbIcon.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                    if (images[1][cbIcon.SelectedIndex].tplFormat.StartsWith("CI"))
                    {
                        images[1][cbIcon.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                    }

                    pbPic.Image   = images[1][cbIcon.SelectedIndex].tplImage;
                    lbFormat.Text = images[1][cbIcon.SelectedIndex].tplFormat;
                    lbSize.Text   = string.Format("{0} x {1}", images[1][cbIcon.SelectedIndex].tplImage.Width, images[1][cbIcon.SelectedIndex].tplImage.Height);
                }

                if (cbBanner.SelectedIndex != -1)
                {
                    cbBanner.Select();
                }
                else if (cbIcon.SelectedIndex != -1)
                {
                    cbIcon.Select();
                }

                if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8)
                {
                    lbTip.Visible = true;
                    tipTimer.Start();
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
        private void cmFormat_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "PNG|*.png|JPG|*.jpg|GIF|*.gif|BMP|*.bmp|TPL|*.tpl|All|*.png;*.jpg;*.gif;*.bmp;*.tpl";
            ofd.FilterIndex = 6;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string tplName;
                    TPL    tmpTpl = new TPL();
                    Image  newImg;

                    if (cbIcon.SelectedIndex == -1)
                    {
                        tplName = cbBanner.SelectedItem.ToString().ToLower();
                        tmpTpl.LoadFile(bannerBin.Data[bannerBin.GetNodeIndex(tplName)]);
                    }
                    else
                    {
                        tplName = cbIcon.SelectedItem.ToString().ToLower();
                        tmpTpl.LoadFile(iconBin.Data[iconBin.GetNodeIndex(tplName)]);
                    }

                    if (!ofd.FileName.ToLower().EndsWith(".tpl"))
                    {
                        newImg = Image.FromFile(ofd.FileName);
                    }
                    else
                    {
                        TPL newTpl = TPL.Load(ofd.FileName);
                        newImg = newTpl.ExtractTexture();
                    }

                    Size tplSize = tmpTpl.GetTextureSize(0);

                    if (newImg.Width != tplSize.Width ||
                        newImg.Height != tplSize.Height)
                    {
                        newImg = resizeImage(newImg, tplSize.Width, tplSize.Height);
                    }

                    ToolStripMenuItem cmSender = sender as ToolStripMenuItem;
                    TPL_TextureFormat tplFormat;
                    TPL_PaletteFormat pFormat = TPL_PaletteFormat.RGB5A3;

                    switch (cmSender.Tag.ToString().ToLower())
                    {
                    case "i4":
                        tplFormat = TPL_TextureFormat.I4;
                        break;

                    case "i8":
                        tplFormat = TPL_TextureFormat.I8;
                        break;

                    case "ia4":
                        tplFormat = TPL_TextureFormat.IA4;
                        break;

                    case "ia8":
                        tplFormat = TPL_TextureFormat.IA8;
                        break;

                    case "rgb565":
                        tplFormat = TPL_TextureFormat.RGB565;
                        break;

                    case "rgb5a3":
                        tplFormat = TPL_TextureFormat.RGB5A3;
                        break;

                    case "ci8rgb5a3":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat   = TPL_PaletteFormat.RGB5A3;
                        break;

                    case "ci8rgb565":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat   = TPL_PaletteFormat.RGB565;
                        break;

                    case "ci8ia8":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat   = TPL_PaletteFormat.IA8;
                        break;

                    case "ci4rgb5a3":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat   = TPL_PaletteFormat.RGB5A3;
                        break;

                    case "ci4rgb565":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat   = TPL_PaletteFormat.RGB565;
                        break;

                    case "ci4ia8":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat   = TPL_PaletteFormat.IA8;
                        break;

                    default:
                        tplFormat = TPL_TextureFormat.RGBA8;
                        break;
                    }

                    tmpTpl.RemoveTexture(0);
                    tmpTpl.AddTexture(newImg, tplFormat, pFormat);

                    if (cbBanner.SelectedIndex != -1)
                    {
                        bannerBin.ReplaceFile(bannerBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                        images[0][cbBanner.SelectedIndex].tplImage  = tmpTpl.ExtractTexture();
                        images[0][cbBanner.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                        if (images[0][cbBanner.SelectedIndex].tplFormat.StartsWith("CI"))
                        {
                            images[0][cbBanner.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                        }

                        pbPic.Image   = images[0][cbBanner.SelectedIndex].tplImage;
                        lbFormat.Text = images[0][cbBanner.SelectedIndex].tplFormat;
                        lbSize.Text   = string.Format("{0} x {1}", images[0][cbBanner.SelectedIndex].tplImage.Width, images[0][cbBanner.SelectedIndex].tplImage.Height);
                    }
                    else
                    {
                        iconBin.ReplaceFile(iconBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                        images[1][cbIcon.SelectedIndex].tplImage  = tmpTpl.ExtractTexture();
                        images[1][cbIcon.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                        if (images[1][cbIcon.SelectedIndex].tplFormat.StartsWith("CI"))
                        {
                            images[1][cbIcon.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                        }

                        pbPic.Image   = images[1][cbIcon.SelectedIndex].tplImage;
                        lbFormat.Text = images[1][cbIcon.SelectedIndex].tplFormat;
                        lbSize.Text   = string.Format("{0} x {1}", images[1][cbIcon.SelectedIndex].tplImage.Width, images[1][cbIcon.SelectedIndex].tplImage.Height);
                    }

                    if (cbBanner.SelectedIndex != -1)
                    {
                        cbBanner.Select();
                    }
                    else if (cbIcon.SelectedIndex != -1)
                    {
                        cbIcon.Select();
                    }

                    if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8)
                    {
                        lbTip.Visible = true;
                        tipTimer.Start();
                    }
                }
                catch (Exception ex)
                { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
        }
Example #27
0
        private void Read(FileReader reader, uint resourceType)
        {
            reader.SetByteOrder(true);
            ResourceType = resourceType;

            uint positionsOffset = reader.ReadUInt32() * 4;
            uint normalsOffset = reader.ReadUInt32() * 4;
            uint colorsOffset = reader.ReadUInt32() * 4;
            uint texCoordsOffset = reader.ReadUInt32() * 4;
            uint textureContainerOffset = reader.ReadUInt32() * 4;
            uint unkOffset = reader.ReadUInt32() * 4; //Material animations???
            uint unk2Offset = reader.ReadUInt32() * 4; //Material animation data???
            uint shapeCount = reader.ReadUInt32();
            uint shapesOffset = reader.ReadUInt32() * 4;
            uint packetCount = reader.ReadUInt32();
            uint packetsOffset = reader.ReadUInt32() * 4;

            TextureContainer = new TPL();
            TextureContainer.FileInfo = new File_Info();
            TextureContainer.Load(new SubStream(
                reader.BaseStream, textureContainerOffset));

            Dictionary<int, MeshGroup> meshGroups = new Dictionary<int, MeshGroup>();

            reader.SeekBegin(shapesOffset);
            for (int i = 0; i < shapeCount; i++)
            {
                uint unk = reader.ReadUInt16();
                uint numPackets = reader.ReadUInt16();
                uint packetOffset = reader.ReadUInt32() * 4;

                using (reader.TemporarySeek(packetOffset, SeekOrigin.Begin))
                {
                    for (int j = 0; j < numPackets; j++)
                    {
                        reader.SeekBegin(packetOffset + (j * 12));
                        Packet packet = new Packet()
                        {
                            Offset = reader.ReadUInt32() * 4,
                            Size = reader.ReadUInt32(),
                            Flags1 = reader.ReadByte(),
                            Flags2 = reader.ReadByte(),
                            MaterialColorIndex = reader.ReadSByte(),
                            TextureIndex = reader.ReadSByte(),
                        };

                        if (!meshGroups.ContainsKey(packet.TextureIndex))
                        {
                            meshGroups.Add(packet.TextureIndex, new MeshGroup() {
                                TextureIndex = packet.TextureIndex,
                            });
                        }

                        var meshGroup = meshGroups[packet.TextureIndex];

                        List<GXVertexLayout> layouts = new List<GXVertexLayout>();
                        layouts.Add(new GXVertexLayout(
                            GXAttributes.Position,
                            GXComponentType.F32, GXAttributeType.INDEX16, positionsOffset));
                        if (normalsOffset != 0)
                        {
                            layouts.Add(new GXVertexLayout(
                                GXAttributes.Normal,
                                GXComponentType.S16, GXAttributeType.INDEX16, normalsOffset));
                        }
                        if (colorsOffset != 0)
                        {
                            layouts.Add(new GXVertexLayout(
                                 GXAttributes.Color0,
                                 GXComponentType.RGBA4, GXAttributeType.INDEX16, colorsOffset));
                        }
                        if (texCoordsOffset != 0)
                        {
                            layouts.Add(new GXVertexLayout(
                                GXAttributes.TexCoord0,
                                GXComponentType.S16, GXAttributeType.INDEX16, texCoordsOffset) {
                                Divisor = 1024.0f,
                            });
                        }

                        var displayListData = new SubStream(reader.BaseStream, packet.Offset, packet.Size);
                        meshGroup.Vertices.AddRange(DisplayListHelper.ReadDisplayLists(
                            displayListData, reader.BaseStream, layouts.ToArray(), new DisplayListHelper.Config()
                            {
                                OpCodeShift = -1, //Op codes seem to be +1 higher than they should be. Unsure why.
                            }));
                    }
                }
            }

            //Maps have 100s of shapes. To make rendering more efficent, combine meshes by materials using the mesh groups.
            foreach (var group in meshGroups.Values) {
                Meshes.Add(new Mesh() {
                    Groups = new List<MeshGroup>() { group }
                });
            }
            meshGroups.Clear();
        }
Example #28
0
        private static void To(string[] args)
        {
            //Setting up variables
            string input     = args[2];
            string output    = args[3];
            string tplFormat = "RGB565";

            //Check if file exists
            if (File.Exists(input) == false)
            {
                Console.WriteLine("ERROR: Unable to open file: {0}", input);
                Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                Console.WriteLine("Error: SHARPII_NET_CORE_TPL_FILE_ERR_01");
                Environment.Exit(0x00003E81);
                return;
            }

            //Check for arguments
            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "-FORMAT":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No format set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_TPL_NO_FORMAT_01");
                        Environment.Exit(0x00003E91);
                        return;
                    }
                    tplFormat = args[i + 1];
                    break;

                case "-F":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No format set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_TPL_NO_FORMAT_01");
                        Environment.Exit(0x00003E91);
                        return;
                    }
                    tplFormat = args[i + 1];
                    break;
                }
            }

            //Check if valid format was entered
            if (tplFormat != "I4" & tplFormat != "I8" & tplFormat != "IA4" & tplFormat != "IA8" & tplFormat != "RGB565" & tplFormat != "RGB5A3" & tplFormat != "RGBA8")
            {
                Console.WriteLine("ERROR: Unknown format type: {0}", tplFormat);
                Console.WriteLine("Error: SHARPII_NET_CORE_TPL_UNKNOWN_FORMAT_01");
                Environment.Exit(0x00003E92);
                return;
            }


            //Run main part, and check for exceptions
            try
            {
                //Set format
                TPL_TextureFormat format = TPL_TextureFormat.RGB565;
                if (tplFormat == "I4")
                {
                    format = TPL_TextureFormat.I4;
                }
                if (tplFormat == "I8")
                {
                    format = TPL_TextureFormat.I8;
                }
                if (tplFormat == "IA4")
                {
                    format = TPL_TextureFormat.IA4;
                }
                if (tplFormat == "IA8")
                {
                    format = TPL_TextureFormat.IA8;
                }
                if (tplFormat == "RGB565")
                {
                    format = TPL_TextureFormat.RGB565;
                }
                if (tplFormat == "RGB5A3")
                {
                    format = TPL_TextureFormat.RGB5A3;
                }
                if (tplFormat == "RGBA8")
                {
                    format = TPL_TextureFormat.RGBA8;
                }

                if (BeQuiet.quiet > 2)
                {
                    Console.WriteLine("Format set to: {0}", tplFormat);
                }

                //Make tpl
                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Creating tpl file...");
                }

                TPL tplfile = libWiiSharp.TPL.FromImage(input, format);

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                //save
                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Saving tpl file...");
                }

                if (output.Substring(output.Length - 4, 4).ToUpper() != ".TPL")
                {
                    output = output + ".tpl";
                }

                tplfile.Save(output);

                if (BeQuiet.quiet > 2)
                {
                    Console.Write("Done!\n");
                }

                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Operation completed succesfully!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error occured, please try again");
                Console.WriteLine("");
                Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                Console.WriteLine("Error: SHARPII_NET_CORE_TPL_UNKNOWN_01");
                Environment.Exit(0x00003E82);
                return;
            }
        }
Example #29
0
        static void Main(string[] args)
        {
            Console.WriteLine("Change this World!");

            TPL.Example();
        }
 public TPLViewer(TPL Image)
 {
     this.Image = Image;
     InitializeComponent();
 }
Example #31
0
 public TPLViewer(TPL Image)
 {
     this.Image = Image;
     InitializeComponent();
 }