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); } } } } } }
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(); } } }
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(); } } }