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; } }
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; } }
private void btnFromTpl_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tbFromTplInput.Text) && !string.IsNullOrEmpty(tbFromTplOutput.Text)) { try { int texture = 0; if (inputTpl.NumOfTextures > 1) { texture = int.Parse(cmbFromTplTexture.SelectedItem.ToString()) - 1; } inputTpl.ExtractTexture(texture, tbFromTplOutput.Text); MessageBox.Show("Successfully extracted image to:\n" + tbFromTplOutput.Text, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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); } } }