From 50fbccbd84386c119a30f44da56bd8d2b965df3f Mon Sep 17 00:00:00 2001 From: 1987kostya Date: Sun, 20 Dec 2020 16:39:24 +0600 Subject: [PATCH] New sorted dumping system. Still not finished --- DotNetCTFDumper/GUI/MainForm.cs | 21 +++++- .../MMFParser/EXE/Loaders/Banks/ImageBank.cs | 32 ++++++--- DotNetCTFDumper/Utils/Helper.cs | 15 ++++ DotNetCTFDumper/Utils/ImageDumper.cs | 70 +++++++++++++++++++ 4 files changed, 126 insertions(+), 12 deletions(-) diff --git a/DotNetCTFDumper/GUI/MainForm.cs b/DotNetCTFDumper/GUI/MainForm.cs index 91ca13d..3dc4285 100644 --- a/DotNetCTFDumper/GUI/MainForm.cs +++ b/DotNetCTFDumper/GUI/MainForm.cs @@ -19,6 +19,7 @@ using DotNetCTFDumper.MMFParser.Translation; using DotNetCTFDumper.Utils; using Animation = DotNetCTFDumper.MMFParser.EXE.Loaders.Objects.Animation; using AnimationDirection = DotNetCTFDumper.MMFParser.EXE.Loaders.Objects.AnimationDirection; +using Keys = System.Windows.Forms.Keys; namespace DotNetCTFDumper.GUI { @@ -96,7 +97,9 @@ namespace DotNetCTFDumper.GUI ? $"[{date.Hour,2}:{date.Minute,2}:{date.Second,2}:{date.Millisecond,3}] {msg}\r\n" : "\r\n"); }; + KeyPreview = true; tabControl1.Selecting += tabControl1_Selecting; + } private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e) @@ -635,7 +638,7 @@ namespace DotNetCTFDumper.GUI { if (pair.Value.DirectionDict.Count > 1) { - var dirNode = new ChunkNode($"Direction {pair.Key}",pair.Value); + var dirNode = new ChunkNode($"Direction {pair.Value.DirectionDict.ToList().IndexOf(dir)}",dir.Value); animNode.Nodes.Add(dirNode); for (int a = 0; a < dir.Value.Frames.Count; a++) { @@ -846,6 +849,22 @@ namespace DotNetCTFDumper.GUI { } + + protected override void OnKeyDown(KeyEventArgs e) + { + if (tabControl1.SelectedTab == imgViewerTab) + { + if (e.Control) + { + var node = (ChunkNode)imagesTreeView.SelectedNode; + var path = $"{Settings.ImagePath}\\{Helper.GetTreePath(imagesTreeView,(ChunkNode) imagesTreeView.SelectedNode)}"; + Console.WriteLine(Helper.GetCurrentTime()+ "Saving "+path); + if (node == null) return; + ImageDumper.SaveFromNode(node); + + } + } + } } } diff --git a/DotNetCTFDumper/MMFParser/EXE/Loaders/Banks/ImageBank.cs b/DotNetCTFDumper/MMFParser/EXE/Loaders/Banks/ImageBank.cs index 978bcdc..cf276c4 100644 --- a/DotNetCTFDumper/MMFParser/EXE/Loaders/Banks/ImageBank.cs +++ b/DotNetCTFDumper/MMFParser/EXE/Loaders/Banks/ImageBank.cs @@ -277,20 +277,30 @@ namespace DotNetCTFDumper.MMFParser.EXE.Loaders.Banks public void Save(string filename) { - using (var bmp = new Bitmap(_width, _height, PixelFormat.Format32bppArgb)) + try + { + Bitmap.Save(filename); + } + catch { - BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, - bmp.Width, - bmp.Height), - ImageLockMode.WriteOnly, - bmp.PixelFormat); + using (var bmp = new Bitmap(_width, _height, PixelFormat.Format32bppArgb)) + { + BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, + bmp.Width, + bmp.Height), + ImageLockMode.WriteOnly, + bmp.PixelFormat); - IntPtr pNative = bmpData.Scan0; - Marshal.Copy(_colorArray, 0, pNative, _colorArray.Length); + IntPtr pNative = bmpData.Scan0; + Marshal.Copy(_colorArray, 0, pNative, _colorArray.Length); - bmp.UnlockBits(bmpData); - bmp.Save(filename); - } + bmp.UnlockBits(bmpData); + bmp.Save(filename); + } + } + + + } public Bitmap Bitmap diff --git a/DotNetCTFDumper/Utils/Helper.cs b/DotNetCTFDumper/Utils/Helper.cs index 6bef954..9a84d70 100644 --- a/DotNetCTFDumper/Utils/Helper.cs +++ b/DotNetCTFDumper/Utils/Helper.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text.RegularExpressions; +using System.Windows.Forms; using DotNetCTFDumper.GUI; using DotNetCTFDumper.MMFParser; using DotNetCTFDumper.MMFParser.EXE; @@ -30,6 +31,20 @@ namespace DotNetCTFDumper.Utils } } + public static string GetCurrentTime() + { + var date = DateTime.Now; + return $"[{date.Hour,2}:{date.Minute,2}:{date.Second,2}:{date.Millisecond,3}]"; + } + + public static string GetTreePath(TreeView tree, ChunkNode node) + { + string CombinedPath=node.FullPath; + + + return CombinedPath; + } + public static string Log(this byte[] bytes, bool log = true, string format = "") { string temp = String.Empty; diff --git a/DotNetCTFDumper/Utils/ImageDumper.cs b/DotNetCTFDumper/Utils/ImageDumper.cs index 7d64688..2afc62e 100644 --- a/DotNetCTFDumper/Utils/ImageDumper.cs +++ b/DotNetCTFDumper/Utils/ImageDumper.cs @@ -13,6 +13,76 @@ namespace DotNetCTFDumper.Utils { public static class ImageDumper { + public static void SaveFromNode(ChunkNode node) + { + var bank = Exe.Instance.GameData.GameChunks.GetChunk(); + var fullPath = $"{Settings.ImagePath}\\Sorted\\{node.FullPath}"; + Console.WriteLine("FULL PATH: "+fullPath); + if (fullPath == null) return; + + if (!(node.loader is ImageItem)) Directory.CreateDirectory(fullPath); + else Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); + + if(node.loader is ImageItem img) img.Save($"{fullPath}.png"); + else if (node.loader is AnimationDirection dir) + { + SaveDirection(dir,bank,fullPath); + } + + else if (node.loader is Animation anim) + { + SaveAnimation(anim,bank,fullPath); + } + + else if(node.loader is ObjectInstance) Console.WriteLine("Dumping Common"); + else if(node.loader is Backdrop) Console.WriteLine("Dumping Backdrop"); + else if(node.loader is Frame) Console.WriteLine("Dumping Frame"); + + + + + + + else Console.WriteLine("Unknown: "+node.loader.GetType().Name); + + } + + public static void SaveDirection(AnimationDirection dir, ImageBank bank,string fullPath) + { + for (int i = 0; i < dir.Frames.Count; i++) + { + var frame = dir.Frames[i]; + bank.Images[frame].Save($"{fullPath}\\{i}.png"); + } + } + + public static void SaveAnimation(Animation anim, ImageBank bank, string fullPath) + { + if (anim.DirectionDict.ToArray().Length > 1) + { + foreach (var dirpair in anim.DirectionDict.ToList()) + { + Directory.CreateDirectory($"{fullPath}\\Direction {anim.DirectionDict.ToList().IndexOf(dirpair)}"); + for (int i = 0; i < anim.DirectionDict[0].Frames.Count; i++) + { + var frame = dirpair.Value.Frames[i]; + Console.WriteLine("Trying to save: "+$"{fullPath}\\Direction {anim.DirectionDict.ToList().IndexOf(dirpair)}\\{i}.png"); + bank.Images[frame].Save($"{fullPath}\\Direction {anim.DirectionDict.ToList().IndexOf(dirpair)}\\{i}.png"); + } + } + } + else + { + for (int i = 0; i < anim.DirectionDict[0].Frames.Count; i++) + { + var frame = anim.DirectionDict[0].Frames[i]; + Console.WriteLine("Trying to save: "+$"{fullPath}\\{i}.png"); + bank.Images[frame].Save($"{fullPath}\\{i}.png"); + } + } + + } + public static void DumpImages() { using (var worker = new BackgroundWorker())