private void exportFramesToolStripMenuItem_Click(object sender, EventArgs e) { if (TexAnim == null) { return; } var f = Tools.FileIO.SaveFile("PNG (*.png)|*.png"); if (f != null) { for (int i = 0; i < TexAnim.ImageCount; i++) { var v = TexAnim.ImageBuffers.Array[i]; HSD_TlutBuffer pal = null; if (TexAnim.TlutBuffers != null) { pal = TexAnim.TlutBuffers.Array[i]; } HSD_TOBJ tobj = new HSD_TOBJ(); tobj.ImageData = v.Data; if (pal != null) { tobj.TlutData = pal.Data; } var frame = TOBJConverter.RgbaToImage(tobj.GetDecodedImageData(), v.Data.Width, v.Data.Height); frame.Save(Path.GetDirectoryName(f) + "\\" + Path.GetFileNameWithoutExtension(f) + "_" + i.ToString() + Path.GetExtension(f)); frame.Dispose(); } } }
private void exportStripToolStripMenuItem1_Click(object sender, EventArgs e) { if (TEXG == null) { return; } var f = Tools.FileIO.SaveFile("PNG (*.png)|*.png"); if (f != null) { var bitmap = new Bitmap(TEXG.Width * TEXG.ImageCount, TEXG.Height); using (var g = Graphics.FromImage(bitmap)) { var imageData = TEXG.GetRGBAImageData(); for (int i = 0; i < TEXG.ImageCount; i++) { var frame = TOBJConverter.RgbaToImage(imageData[i], TEXG.Width, TEXG.Height); g.DrawImage(frame, TEXG.Width * i, 0); frame.Dispose(); } } bitmap.Save(f); bitmap.Dispose(); Node = Node; } }
private void importStripToolStripMenuItem1_Click(object sender, EventArgs e) { if (TEXG == null) { return; } var f = Tools.FileIO.OpenFile(ApplicationSettings.ImageFileFilter); if (f != null) { using (TextureImportDialog td = new TextureImportDialog()) { td.ShowCount = true; if (td.ShowDialog() == DialogResult.OK) { var bmp = new Bitmap(f); HSD_TOBJ[] images = new HSD_TOBJ[td.ImageCount]; for (int i = 0; i < td.ImageCount; i++) { images[i] = new HSD_TOBJ(); var image = bmp.Clone(new Rectangle(bmp.Width / td.ImageCount * i, 0, bmp.Width / td.ImageCount, bmp.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb); TOBJConverter.InjectBitmap(image, images[i], td.TextureFormat, td.PaletteFormat); image.Dispose(); } bmp.Dispose(); TEXG.SetFromTOBJs(images); Node = Node; } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonReplace_Click(object sender, EventArgs e) { if (listTexture.SelectedItems.Count > 0 && listTexture.SelectedItems[0] is TextureContainer con) { var tobj = TOBJConverter.ImportTOBJFromFile(); if (tobj != null) { // replace tobj con.TOBJ.ImageData = tobj.ImageData; con.TOBJ.TlutData = tobj.TlutData; //con.TOBJ._s.SetFromStruct(tobj._s); // replace image in list var image = TextureList.Images[con.ImageIndex]; image.Dispose(); var newImage = Tools.BitmapTools.RgbaToImage(tobj.GetDecodedImageData(), tobj.ImageData.Width, tobj.ImageData.Height); TextureList.Images[con.ImageIndex] = newImage; // update flags UpdateTextureFlags(); // refresh listTexture.Items[listTexture.SelectedIndices[0]] = listTexture.Items[listTexture.SelectedIndices[0]]; listTexture.Invalidate(); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonExportIcon_Click(object sender, EventArgs e) { var f = FileIO.SaveFile(ApplicationSettings.ImageFileFilter, "Icon.png"); if (f != null && sssEditor.SelectedObject is MEXStageIconEntry ico && ico.IconTOBJ != null) { using (var bmp = TOBJConverter.ToBitmap(ico.IconTOBJ)) bmp.Save(f); } }
/// <summary> /// /// </summary> public static void ImportTextures(HSD_JOBJ jobj) { var folder = Tools.FileIO.OpenFolder(); if (!string.IsNullOrEmpty(folder)) { // get all tobjs Dictionary <int, HSD_TOBJ> hashToImage = new Dictionary <int, HSD_TOBJ>(); // load all textures from file foreach (var tf in System.IO.Directory.GetFiles(folder)) { if (tf.ToLower().EndsWith(".png")) { var fn = System.IO.Path.GetFileNameWithoutExtension(tf); if (fn.Length >= 8 && int.TryParse(fn.Substring(0, 8), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int hash) && TOBJConverter.FormatFromString(fn, out HSDRaw.GX.GXTexFmt texFmt, out HSDRaw.GX.GXTlutFmt tlutFmt)) { hashToImage.Add(hash, TOBJConverter.ImportTOBJFromFile(tf, texFmt, tlutFmt)); } } } // get all tobjs foreach (var j in jobj.BreathFirstList) { if (j.Dobj != null) { foreach (var dobj in j.Dobj.List) { if (dobj.Mobj != null && dobj.Mobj.Textures != null) { foreach (var tobj in dobj.Mobj.Textures.List) { // generate hashes and export textures and formatting var hash = ComputeHash(tobj.GetDecodedImageData()); if (hashToImage.ContainsKey(hash)) { var imgClone = HSDAccessor.DeepClone <HSD_TOBJ>(hashToImage[hash]); tobj.ImageData = imgClone.ImageData; tobj.TlutData = imgClone.TlutData; } } } } } } } }
/// <summary> /// /// </summary> private void LoadTexture(byte[] data, int width, int height) { var id = TextureManager.TextureCount; TextureManager.Add(data, width, height); var image = TOBJConverter.RgbaToImage(data, width, height); BitmapList.Images.Add(image); textureList.Items.Add(new ListViewItem() { ImageIndex = id, Text = "Image_" + id }); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonSaveTexture_Click(object sender, EventArgs e) { if (listTexture.SelectedItems.Count > 0 && listTexture.SelectedItems[0] is TextureContainer con) { var f = Tools.FileIO.SaveFile(ApplicationSettings.ImageFileFilter); if (f != null) { var bmp = TOBJConverter.ToBitmap(con.TOBJ); bmp.Save(f); bmp.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void exportSelectedToolStripMenuItem_Click(object sender, EventArgs e) { if ((textureList.SelectedIndices == null || textureList.SelectedIndices.Count == 0) && TOBJ == null) { return; } var f = Tools.FileIO.SaveFile("PNG (.png)|*.png"); if (f != null) { var bmp = TOBJConverter.ToBitmap(GetTOBJs()[textureList.SelectedIndices[0]]); bmp.Save(f); bmp.Dispose(); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void exportAllToolStripMenuItem_Click(object sender, EventArgs e) { var f = Tools.FileIO.SaveFile("PNG (*.png)|*.png"); if (f != null) { var i = 0; foreach (var tobj in GetTOBJs()) { var frame = TOBJConverter.RgbaToImage(tobj.GetDecodedImageData(), tobj.ImageData.Width, tobj.ImageData.Height); frame.Save(Path.GetDirectoryName(f) + "\\" + Path.GetFileNameWithoutExtension(f) + "_" + i.ToString() + Path.GetExtension(f)); frame.Dispose(); i++; } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void exportSelectedToolStripMenuItem_Click(object sender, EventArgs e) { if ((textureList.SelectedIndices == null || textureList.SelectedIndices.Count == 0) && TOBJ == null) { return; } var f = Tools.FileIO.SaveFile(ApplicationSettings.ImageFileFilter); if (f != null) { var ind = textureList.SelectedIndices.Count > 0 ? textureList.SelectedIndices[0] : 0; var bmp = TOBJConverter.ToBitmap(GetTOBJs()[0]); bmp.Save(f); bmp.Dispose(); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonImportName_Click(object sender, EventArgs e) { var f = FileIO.OpenFile(ApplicationSettings.ImageFileFilter); if (f != null) { using (Bitmap bmp = new Bitmap(f)) { var tobj = TOBJConverter.BitmapToTOBJ(bmp, HSDRaw.GX.GXTexFmt.IA4, HSDRaw.GX.GXTlutFmt.IA8); if (sssEditor.SelectedObject is MEXStageIconEntry ico) { ico.NameTOBJ = tobj; StageNameJOBJManager.RefreshRendering = true; } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void importNewIconImageToolStripMenuItem_Click(object sender, EventArgs e) { var f = FileIO.OpenFile(ApplicationSettings.ImageFileFilter); if (f != null) { using (Bitmap bmp = new Bitmap(f)) { var tobj = TOBJConverter.BitmapToTOBJ(bmp, HSDRaw.GX.GXTexFmt.CI8, HSDRaw.GX.GXTlutFmt.RGB565); if (sssEditor.SelectedObject is MEXStageIconEntry ico) { ico.IconTOBJ = tobj; IconJOBJManager.RefreshRendering = true; } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void importTexture_Click(object sender, EventArgs e) { var tobj = TOBJConverter.ImportTOBJFromFile(); if (tobj != null) { var bmp = Tools.BitmapTools.RgbaToImage(tobj.GetDecodedImageData(), tobj.ImageData.Width, tobj.ImageData.Height); listTexture.Items.Add(new TextureContainer(tobj) { ImageIndex = TextureList.Images.Count, }); TextureList.Images.Add(bmp); // update flags UpdateTextureFlags(); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sssEditor_SelectedObjectChanged(object sender, EventArgs e) { if (StageMenuFile != null && sssEditor.SelectedObject is MEXStageIconEntry ico) { IconJOBJManager.SelectetedJOBJ = ico.Joint; ResourceCleanup(); if (ico.IconTOBJ != null) { iconPreviewBox.Image = TOBJConverter.ToBitmap(ico.IconTOBJ); } if (ico.NameTOBJ != null) { namePreviewBox.Image = TOBJConverter.ToBitmap(ico.NameTOBJ); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonReplace_Click(object sender, EventArgs e) { if ((textureList.SelectedIndices == null || textureList.SelectedIndices.Count == 0) && TOBJ == null) { return; } var index = 0; if (TOBJ == null) { index = textureList.SelectedIndices[0]; } var tobjs = GetTOBJs(); var f = Tools.FileIO.OpenFile(ApplicationSettings.ImageFileFilter); if (f != null) { if (tobjs.Length == 1) { TOBJConverter.InjectBitmap(f, tobjs[index]); } else { var beforeH = tobjs[index].ImageData.Height; var beforeW = tobjs[index].ImageData.Width; TOBJConverter.InjectBitmap(f, tobjs[index], tobjs[index].ImageData.Format, tobjs[index].TlutData != null ? tobjs[index].TlutData.Format : GXTlutFmt.IA8); } } else { return; } SetTOBJs(tobjs); ReloadTextures(); }
public void SetMOBJ(HSD_MOBJ mobj) { _mobj = mobj; // load textures if (mobj.Textures != null) { var tex = mobj.Textures.List; int index = 0; foreach (var t in tex) { var bmp = TOBJConverter.RgbaToImage(t.GetDecodedImageData(), t.ImageData.Width, t.ImageData.Height); TextureList.Images.Add(bmp); listTexture.Items.Add(new TextureContainer(t) { ImageIndex = index++, }); } listTexture.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.HeaderSize); } // load material color var mc = mobj.Material; buttonAmbient.BackColor = Color.FromArgb(mc.AMB_A, mc.AMB_R, mc.AMB_G, mc.AMB_B); buttonDiffuse.BackColor = Color.FromArgb(mc.DIF_A, mc.DIF_R, mc.DIF_G, mc.DIF_B); buttonSpecular.BackColor = Color.FromArgb(mc.SPC_A, mc.SPC_R, mc.SPC_G, mc.SPC_B); tbShine.Text = mc.Shininess.ToString(); tbAlpha.Text = mc.Alpha.ToString(); // load pixel processing if (mobj.PEDesc != null) { cbEnablePP.Checked = true; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void generateNameTagToolStripMenuItem_Click(object sender, EventArgs e) { if (sssEditor.SelectedObject is MEXStageIconEntry entry) { var settings = new NameTagSettings(); using (PropertyDialog d = new PropertyDialog("Name Tag Settings", settings)) { if (d.ShowDialog() == DialogResult.OK) { using (Bitmap bmp = MexMapGenerator.GenerateStageName(settings.StageName, settings.Location)) { if (bmp == null) { MessageBox.Show("Could not find fonts \"Palatino Linotype\" and/or \"A-OTF Folk Pro H\"", "Font not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } entry.NameTOBJ = TOBJConverter.BitmapToTOBJ(bmp, HSDRaw.GX.GXTexFmt.I4, HSDRaw.GX.GXTlutFmt.IA8); } } } } }
/// <summary> /// /// </summary> public static void ExportTextures(HSD_JOBJ jobj) { var folder = Tools.FileIO.OpenFolder(); if (!string.IsNullOrEmpty(folder)) { HashSet <int> textures = new HashSet <int>(); // get all tobjs foreach (var j in jobj.BreathFirstList) { if (j.Dobj != null) { foreach (var dobj in j.Dobj.List) { if (dobj.Mobj != null && dobj.Mobj.Textures != null) { foreach (var tobj in dobj.Mobj.Textures.List) { // generate hashes and export textures and formatting var hash = ComputeHash(tobj.GetDecodedImageData()); if (!textures.Contains(hash)) { using (var bmp = TOBJConverter.ToBitmap(tobj)) bmp.Save(System.IO.Path.Combine(folder, TOBJConverter.FormatName(hash.ToString("X8"), tobj) + ".png")); textures.Add(hash); } } } } } } } }
/// <summary> /// /// </summary> private void InstallUI(ZipFile pack, MEXFighterEntry fighter) { Console.WriteLine($"Installing UI data..."); // LOAD Stock Icons var icons = pack.Where(e => Regex.IsMatch(e.FileName, "Icon/ico..\\.png")).ToArray(); HSD_TOBJ[] iconTOBJs = new HSD_TOBJ[icons.Length]; foreach (var c in icons) { var index = int.Parse(Regex.Match(c.FileName, @"\d\d").Value); using (MemoryStream stream = new MemoryStream(GetBytes(c))) using (var bmp = new System.Drawing.Bitmap(stream)) iconTOBJs[index] = TOBJConverter.BitmapToTOBJ(bmp, HSDRaw.GX.GXTexFmt.CI4, HSDRaw.GX.GXTlutFmt.RGB5A3); } // Load Menu Icon // Load Emblem var emblemPack = pack["UI/emblem.obj"]; HSD_TOBJ emblemTexture = null; HSD_JOBJ emblemModel = null; if (emblemPack != null) { EmblemModel model; using (MemoryStream stream = new MemoryStream()) { emblemPack.Extract(stream); stream.Position = 0; model = Converters.EmblemConverter.GenerateEmblemModelFromOBJ(stream); } emblemModel = Converters.EmblemConverter.GenerateEmblemModel(model); emblemTexture = Converters.EmblemConverter.GenerateEmblemIconImage(model); } // Load Misc Name Tags and icons var largeName = pack["UI/result_victory_name.png"]; var smallName = pack["UI/result_name.png"]; HSD_TOBJ largeNameTexture = null; HSD_TOBJ smallNameTexture = null; if (largeName != null) { using (MemoryStream stream = new MemoryStream(GetBytes(largeName))) using (var bmp = new System.Drawing.Bitmap(stream)) largeNameTexture = TOBJConverter.BitmapToTOBJ(bmp, HSDRaw.GX.GXTexFmt.I4, HSDRaw.GX.GXTlutFmt.IA8); } if (smallName != null) { using (MemoryStream stream = new MemoryStream(GetBytes(smallName))) using (var bmp = new System.Drawing.Bitmap(stream)) smallNameTexture = TOBJConverter.BitmapToTOBJ(bmp, HSDRaw.GX.GXTexFmt.I4, HSDRaw.GX.GXTlutFmt.IA8); } // -------------------------------------------------------------------------- var root = Path.GetDirectoryName(MainForm.Instance.FilePath); int stride = editor.FighterControl.FighterEntries.Count - 3; int internalID = editor.FighterControl.FighterEntries.IndexOf(fighter); var externalId = MEXIdConverter.ToExternalID(internalID, editor.FighterControl.FighterEntries.Count); int GroupID = externalId - (externalId > 18 ? 1 : 0); // Inject CSPs and Stock Icons into Character Select //var chrSelPath = Path.Combine(root, "MnSlChr.usd"); //if (File.Exists(chrSelPath)) // InjectCharSelectImages(pack, chrSelPath, iconTOBJs, emblemTexture, fighter, stride, GroupID); // Inject Stock Icons into IfAll, GmRst var ifallPath = Path.Combine(root, "IfAll.usd"); if (File.Exists(ifallPath)) { var datFile = new HSDRawFile(ifallPath); var mark = datFile.Roots.Find(e => e.Name.Equals("Stc_scemdls")).Data as HSDNullPointerArrayAccessor <HSD_JOBJDesc>; for (int i = 0; i < 7; i++) // first 7 { InjectIntoMatTexAnim(mark[0].MaterialAnimations[0].Children[i].MaterialAnimation.TextureAnimation, iconTOBJs, GroupID, stride, MAX_COSTUME_COUNT); } var emblemGroup = datFile.Roots.Find(e => e.Name.Equals("DmgMrk_scene_models")).Data as HSDNullPointerArrayAccessor <HSD_JOBJDesc>; InjectIntoMatTexAnim(emblemGroup[0].MaterialAnimations[0].Child.MaterialAnimation.TextureAnimation, new HSDRaw.Common.HSD_TOBJ[] { emblemTexture }, GroupID, stride, 1, fighter.InsigniaID); editedFiles.Add(new Tuple <HSDRawFile, string, bool>(datFile, ifallPath, true)); } var gmRst = Path.Combine(root, "GmRst.usd"); if (File.Exists(gmRst)) { var datFile = new HSDRawFile(gmRst); var flmsce = datFile.Roots.Find(e => e.Name.Equals("flmsce")).Data as HSD_SOBJ; var pnlsce = datFile.Roots.Find(e => e.Name.Equals("pnlsce")).Data as HSD_SOBJ; // Stock Icons------------------------------------- for (int i = 5; i <= 8; i++) // at 5-8, 2nd mat anim { InjectIntoMatTexAnim( pnlsce.JOBJDescs[0].MaterialAnimations[0].Children[i].MaterialAnimation.Next.TextureAnimation, iconTOBJs, GroupID, stride, MAX_COSTUME_COUNT); } // Emblem Textures-------------------------------------- var matgroup = pnlsce.JOBJDescs[0].MaterialAnimations[0].Children[17]; for (int i = 0; i < 4; i++) { InjectIntoMatTexAnim(matgroup.Children[i].MaterialAnimation.TextureAnimation, new HSDRaw.Common.HSD_TOBJ[] { emblemTexture }, GroupID, stride, 1, fighter.InsigniaID); } // Emblem Model-------------------------------------- var emblemGroup = flmsce.JOBJDescs[0]; if (emblemModel != null) { var modelIndex = emblemGroup.RootJoint.Children[4].Children.Length; fighter.InsigniaID = (byte)modelIndex; var jointClone = HSDAccessor.DeepClone <HSDRaw.Common.Animation.HSD_AnimJoint>(emblemGroup.JointAnimations[0].Children[4].Child); jointClone.Next = null; var matjointClone = HSDAccessor.DeepClone <HSDRaw.Common.Animation.HSD_MatAnimJoint>(emblemGroup.MaterialAnimations[0].Children[4].Child); matjointClone.Next = null; emblemGroup.JointAnimations[0].Children[4].AddChild(jointClone); emblemGroup.MaterialAnimations[0].Children[4].AddChild(matjointClone); emblemGroup.RootJoint.Children[4].AddChild(emblemModel); } // name textures var largenameGroup = pnlsce.JOBJDescs[0].MaterialAnimations[0].Children[0].Children[2].MaterialAnimation.Next.TextureAnimation; InjectIntoMatTexAnim(largenameGroup, new HSD_TOBJ[] { largeNameTexture }, GroupID, stride, 1); var smallnameGroup = pnlsce.JOBJDescs[0].MaterialAnimations[0]; for (int i = 9; i < 13; i++) { InjectIntoMatTexAnim(smallnameGroup.Children[i].Children[1].MaterialAnimation.TextureAnimation, new HSD_TOBJ[] { smallNameTexture }, GroupID, stride, 1); } editedFiles.Add(new Tuple <HSDRawFile, string, bool>(datFile, gmRst, true)); } // Inject Emblem // Generate Emblem Models and Inject // Inject Misc Name Tags and icons }
private void importFramesToolStripMenuItem_Click(object sender, EventArgs e) { if (TexAnim == null) { return; } var files = Tools.FileIO.OpenFiles(ApplicationSettings.ImageFileFilter); if (files != null) { using (TextureImportDialog td = new TextureImportDialog()) { if (td.ShowDialog() == DialogResult.OK) { var matched = new HashSet <int>(); var tobjs = new List <HSD_TexBuffer>(); var pals = new List <HSD_TlutBuffer>(); foreach (var f in files) { int num = 0; int.TryParse(Regex.Match(Path.GetFileName(f).ToLower(), @"(?<=.*_)(\d+?)(?=\.)").Name, out num); Console.WriteLine(num + " " + Regex.Match(Path.GetFileName(f).ToLower(), @"(?<=.*_)(\d+?)(?=\.)").Groups[0].Value); if (!int.TryParse(Regex.Match(Path.GetFileName(f).ToLower(), @"(?<=.*_)(\d+?)(?=\.)").Groups[0].Value, out num) || matched.Contains(num)) { throw new InvalidDataException(num + " " + Path.GetFileName(f) + " is missing index tag or has duplicate index"); } else { HSD_TOBJ temp = new HSD_TOBJ(); TOBJConverter.InjectBitmap(f, temp, td.TextureFormat, td.PaletteFormat); HSD_TexBuffer buf = new HSD_TexBuffer(); buf.Data = temp.ImageData; tobjs.Add(buf); if (ImageDataFormat.IsPalettedFormat(td.TextureFormat)) { HSD_TlutBuffer palbuf = new HSD_TlutBuffer(); palbuf.Data = temp.TlutData; pals.Add(palbuf); } matched.Add(num); } } // convert tobjs into proper strip var ib = new HSDArrayAccessor <HSD_TexBuffer>(); ib.Array = tobjs.ToArray(); TexAnim.ImageBuffers = ib; if (ImageDataFormat.IsPalettedFormat(td.TextureFormat)) { var tb = new HSDRaw.HSDArrayAccessor <HSD_TlutBuffer>(); tb.Array = pals.ToArray(); TexAnim.TlutBuffers = tb; if (TexAnim?.AnimationObject?.FObjDesc?.List.Count < 2) { TexAnim.AnimationObject.FObjDesc.Next = new HSD_FOBJDesc(); TexAnim.AnimationObject.FObjDesc.Next.FromFOBJ(new HSD_FOBJ() { JointTrackType = JointTrackType.HSD_A_J_SCAX, Buffer = new byte[0] }); } } else { TexAnim.TlutBuffers = null; if (TexAnim?.AnimationObject?.FObjDesc?.List.Count > 1) { TexAnim.AnimationObject.FObjDesc.Next = null; } } Node = Node; } } } }
/// <summary> /// /// </summary> /// <param name="datPath"></param> /// <param name="pack"></param> private void InjectCharSelectImages(ZipFile pack, string datPath, HSD_TOBJ[] icons, HSD_TOBJ emblemTexture, MEXFighterEntry fighter, int stride, int groupID) { var cssFile = new HSDRawFile(datPath); if (cssFile.Roots[0].Data is SBM_SelectChrDataTable cssTable) { // get base width and height int width = 132; int height = 188; if (cssTable.PortraitMaterialAnimation.Children[2].Child.MaterialAnimation.TextureAnimation.ImageCount > 0) { width = cssTable.PortraitMaterialAnimation.Children[2].Child.MaterialAnimation.TextureAnimation.ImageBuffers[0].Data.Width; height = cssTable.PortraitMaterialAnimation.Children[2].Child.MaterialAnimation.TextureAnimation.ImageBuffers[0].Data.Height; } // LOAD CSPs var csps = pack.Where(e => Regex.IsMatch(e.FileName, "CSS/css..\\.png")).ToArray(); HSD_TOBJ[] cspTOBJs = new HSD_TOBJ[csps.Length]; foreach (var c in csps) { var index = int.Parse(Regex.Match(c.FileName, @"\d\d").Value); using (MemoryStream stream = new MemoryStream(GetBytes(c))) using (var bmp = new System.Drawing.Bitmap(stream)) { // shrink but don't grow if (bmp.Width > width || bmp.Height > height) { using (System.Drawing.Bitmap resized = new System.Drawing.Bitmap(width, height)) { using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(resized)) g.DrawImage(bmp, 0, 0, width, height); cspTOBJs[index] = TOBJConverter.BitmapToTOBJ(resized, HSDRaw.GX.GXTexFmt.CI8, HSDRaw.GX.GXTlutFmt.RGB5A3); } } else { cspTOBJs[index] = TOBJConverter.BitmapToTOBJ(bmp, HSDRaw.GX.GXTexFmt.CI8, HSDRaw.GX.GXTlutFmt.RGB5A3); } } } // Inject Icons foreach (var n in cssTable.SingleMenuMaterialAnimation.Children[9].Children) { InjectIntoMatTexAnim(n.MaterialAnimation.TextureAnimation, icons, groupID, stride, MAX_COSTUME_COUNT); } // Inject CSPs foreach (var n in cssTable.MenuMaterialAnimation.Children[6].Children) { InjectIntoMatTexAnim(n.MaterialAnimation.TextureAnimation, cspTOBJs, groupID, stride, MAX_COSTUME_COUNT); } foreach (var n in cssTable.SingleMenuMaterialAnimation.Children[6].Children) { InjectIntoMatTexAnim(n.MaterialAnimation.TextureAnimation, cspTOBJs, groupID, stride, MAX_COSTUME_COUNT); } foreach (var n in cssTable.PortraitMaterialAnimation.Children[2].Children) { InjectIntoMatTexAnim(n.MaterialAnimation.TextureAnimation, cspTOBJs, groupID, stride, MAX_COSTUME_COUNT); } // Emblem foreach (var n in cssTable.MenuMaterialAnimation.Children[5].Children) { InjectIntoMatTexAnim(n.MaterialAnimation.Next.TextureAnimation, new HSDRaw.Common.HSD_TOBJ[] { emblemTexture }, groupID, stride, 1, fighter.InsigniaID); } foreach (var n in cssTable.SingleMenuMaterialAnimation.Children[5].Children) { InjectIntoMatTexAnim(n.MaterialAnimation.Next.TextureAnimation, new HSDRaw.Common.HSD_TOBJ[] { emblemTexture }, groupID, stride, 1, fighter.InsigniaID); } foreach (var n in cssTable.PortraitMaterialAnimation.Children[1].Children) { InjectIntoMatTexAnim(n.MaterialAnimation.Next.TextureAnimation, new HSDRaw.Common.HSD_TOBJ[] { emblemTexture }, groupID, stride, 1, fighter.InsigniaID); } } editedFiles.Add(new Tuple <HSDRawFile, string, bool>(cssFile, datPath, true)); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonAdd_Click(object sender, EventArgs e) { //if (textureList.SelectedIndices == null || textureList.SelectedIndices.Count == 0) // return; //var index = textureList.SelectedIndices[0]; var tobjs = GetTOBJs(); HSD_TOBJ tobj; var f = Tools.FileIO.OpenFiles(ApplicationSettings.ImageFileFilter); if (f != null) { GXTexFmt texFormat = GXTexFmt.CMP; GXTlutFmt palFormat = GXTlutFmt.IA8; if (tobjs.Length == 0 || tobjs[0].ImageData == null) { using (TextureImportDialog settings = new TextureImportDialog()) { if (settings.ShowDialog() == DialogResult.OK) { texFormat = settings.TextureFormat; palFormat = settings.PaletteFormat; tobjs = new HSD_TOBJ[f.Length]; int ti = 0; foreach (var fi in f) { tobj = new HSD_TOBJ(); TOBJConverter.InjectBitmap(fi, tobj, texFormat, palFormat); tobjs[ti++] = tobj; } } else { return; } } } else { texFormat = tobjs[0].ImageData.Format; if (tobjs[0].TlutData != null) { palFormat = tobjs[0].TlutData.Format; } foreach (var fi in f) { tobj = new HSD_TOBJ(); TOBJConverter.InjectBitmap(fi, tobj, texFormat, palFormat); /*if (tobj.ImageData.Width != tobjs[0].ImageData.Width || tobj.ImageData.Height != tobjs[0].ImageData.Height) * { * MessageBox.Show($"Error the texture size does not match\n{tobj.ImageData.Width}x{tobj.ImageData.Height} -> {tobjs[0].ImageData.Width}x{tobjs[0].ImageData.Height}"); * return; * }*/ tobjs = InsertAt(tobjs, tobj, tobjs.Length); } } } else { return; } SetTOBJs(tobjs); ReloadTextures(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonReplace_Click(object sender, EventArgs e) { if ((textureList.SelectedIndices == null || textureList.SelectedIndices.Count == 0) && TOBJ == null) { return; } var index = 0; if (TOBJ == null) { index = textureList.SelectedIndices[0]; } var tobjs = GetTOBJs(); var f = Tools.FileIO.OpenFile("PNG (.png)|*.png"); if (f != null) { if (tobjs.Length == 1) { using (TextureImportDialog settings = new TextureImportDialog()) { if (settings.ShowDialog() == DialogResult.OK) { TOBJConverter.InjectBitmap(tobjs[index], f, settings.TextureFormat, settings.PaletteFormat); } else { return; } } } else { var beforeH = tobjs[index].ImageData.Height; var beforeW = tobjs[index].ImageData.Width; var bmp = new Bitmap(f); if (beforeW != bmp.Width || beforeH != bmp.Height) { MessageBox.Show($"Error the texture size does not match\n{beforeW}x{beforeH} -> {bmp.Width}x{bmp.Height}"); return; } bmp.Dispose(); TOBJConverter.InjectBitmap(tobjs[index], f, tobjs[index].ImageData.Format, tobjs[index].TlutData != null ? tobjs[index].TlutData.Format : GXTlutFmt.IA8); } } else { return; } SetTOBJs(tobjs); ReloadTextures(); }