From fa799f94ecdac42c6c731f88fd77a47129403a22 Mon Sep 17 00:00:00 2001 From: 1987kostya Date: Wed, 9 Dec 2020 22:34:47 +0600 Subject: [PATCH] Dumper refactor, GUI fix --- NetMFAPatcher/DotNetCTFDumper.csproj | 15 +- NetMFAPatcher/GUI/FrameViewer.cs | 103 +++++++++++ NetMFAPatcher/GUI/MainForm.Designer.cs | 24 ++- NetMFAPatcher/GUI/MainForm.cs | 164 +++++++----------- NetMFAPatcher/GUI/ObjectBox.cs | 15 ++ NetMFAPatcher/MMFParser/Data/MFA.cs | 2 +- NetMFAPatcher/Utils/Backend.cs | 58 +++++++ NetMFAPatcher/mmfparser/chunkloaders/Frame.cs | 12 +- .../mmfparser/chunkloaders/ObjectInfo.cs | 32 +++- .../mmfparser/chunkloaders/banks/ImageBank.cs | 79 ++++++--- NetMFAPatcher/packages.config | 3 +- 11 files changed, 362 insertions(+), 145 deletions(-) create mode 100644 NetMFAPatcher/GUI/FrameViewer.cs create mode 100644 NetMFAPatcher/GUI/ObjectBox.cs create mode 100644 NetMFAPatcher/Utils/Backend.cs diff --git a/NetMFAPatcher/DotNetCTFDumper.csproj b/NetMFAPatcher/DotNetCTFDumper.csproj index 9761aae..dd98f5a 100644 --- a/NetMFAPatcher/DotNetCTFDumper.csproj +++ b/NetMFAPatcher/DotNetCTFDumper.csproj @@ -80,8 +80,8 @@ ..\packages\Be.Windows.Forms.HexBox.1.6.1\lib\net40\Be.Windows.Forms.HexBox.dll True - - ..\packages\Ionic.Zlib.1.9.1.5\lib\Ionic.Zlib.dll + + ..\packages\DotNetZip.1.15.0\lib\net40\DotNetZip.dll True @@ -106,6 +106,12 @@ CryptoKeyForm.cs + + Form + + + FrameViewer.cs + Form @@ -118,6 +124,7 @@ MainForm.cs + Form @@ -180,6 +187,7 @@ + @@ -216,6 +224,9 @@ CryptoKeyForm.cs + + FrameViewer.cs + HexViewForm.cs diff --git a/NetMFAPatcher/GUI/FrameViewer.cs b/NetMFAPatcher/GUI/FrameViewer.cs new file mode 100644 index 0000000..7681488 --- /dev/null +++ b/NetMFAPatcher/GUI/FrameViewer.cs @@ -0,0 +1,103 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using DotNetCTFDumper.MMFParser.ChunkLoaders; +using DotNetCTFDumper.MMFParser.ChunkLoaders.Banks; +using DotNetCTFDumper.MMFParser.ChunkLoaders.Objects; +using DotNetCTFDumper.MMFParser.Data; +using DotNetCTFDumper.MMFParser.MFALoaders; +using Frame = DotNetCTFDumper.MMFParser.ChunkLoaders.Frame; + +namespace DotNetCTFDumper.GUI +{ + public partial class FrameViewer : Form + { + private ImageBank images; + private ObjectBox _lastSelectedObject; + + public FrameViewer() + { + InitializeComponent(); + } + + public FrameViewer(Frame frame, ImageBank imgs) + { + InitializeComponent(); + this.Width = frame.Width; + this.Height = frame.Height; + this.BackColor = frame.Background; + this.Text = "Frame Viewer: "+frame.Name; + images = imgs; + contextMenuStrip1.ItemClicked+= new ToolStripItemClickedEventHandler(MenuItemSelected); + LoadObjects(frame); + } + + public void CreateImage(ObjectInstance obj) + { + var pictureBox1 = new ObjectBox(obj); + var img = obj.FrameItem.GetPreview(); + if (img != null) + { + pictureBox1.Anchor = AnchorStyles.None; + pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; + pictureBox1.Location = new Point(obj.X-obj.FrameItem.GetPreview().XHotspot, obj.Y-obj.FrameItem.GetPreview().YHotspot); + pictureBox1.ClientSize = new Size(img.Bitmap.Width, img.Bitmap.Height); + pictureBox1.Image = img.Bitmap; + pictureBox1.MouseClick += new MouseEventHandler(OnObjectSelected); + scrollableControl1.Controls.Add(pictureBox1); + } + } + + private void OnObjectSelected(object sender, MouseEventArgs e) + { + if ((e.Button & MouseButtons.Right) != 0) + { + + + _lastSelectedObject = (ObjectBox) sender; + nameMenuItem.Text = "Name: " + _lastSelectedObject.Obj.Name; + positionMenuItem.Text = $"Position: {_lastSelectedObject.Obj.X}x{_lastSelectedObject.Obj.Y}"; + contextMenuStrip1.Show(Cursor.Position); + } + else + { + + } + } + + private void LoadObjects(Frame frame) + { + var size = new Size(Exe.Instance.GameData.Header.WindowWidth,Exe.Instance.GameData.Header.WindowHeight); + scrollableControl1.Size = new Size(frame.Width,frame.Height);; + ClientSize = size; + var list = frame.Objects.Items.OrderBy(x=>x.Handle); + foreach (var obj in list) + { + //TODO:Layers + CreateImage(obj); + } + } + + + + + private void MenuItemSelected(object sender, ToolStripItemClickedEventArgs e) + { + if (e.ClickedItem.Name == "deleteObjBtn") + { + Controls.Remove(_lastSelectedObject); + _lastSelectedObject.Dispose(); + + } + + } + + private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) + { + + } + } + +} diff --git a/NetMFAPatcher/GUI/MainForm.Designer.cs b/NetMFAPatcher/GUI/MainForm.Designer.cs index 1738641..4151ac4 100644 --- a/NetMFAPatcher/GUI/MainForm.Designer.cs +++ b/NetMFAPatcher/GUI/MainForm.Designer.cs @@ -51,6 +51,7 @@ this.ChunkCombo = new System.Windows.Forms.ContextMenuStrip(this.components); this.saveChunkBtn = new System.Windows.Forms.ToolStripMenuItem(); this.viewHexBtn = new System.Windows.Forms.ToolStripMenuItem(); + this.previewFrameBtn = new System.Windows.Forms.ToolStripMenuItem(); this.packDataBtn = new System.Windows.Forms.Button(); this.musicsButton = new System.Windows.Forms.Button(); this.musicBar = new System.Windows.Forms.ProgressBar(); @@ -114,7 +115,7 @@ this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(180, 281); this.listBox1.TabIndex = 5; - this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); + // // GameInfo // @@ -271,7 +272,6 @@ this.loadingLabel.Size = new System.Drawing.Size(335, 91); this.loadingLabel.TabIndex = 16; this.loadingLabel.Text = "Loading..."; - this.loadingLabel.Click += new System.EventHandler(this.loadingLabel_Click); // // cryptKeyBtn // @@ -302,7 +302,7 @@ this.showHexBtn.Text = "Show hex"; this.showHexBtn.UseVisualStyleBackColor = false; this.showHexBtn.Visible = false; - this.showHexBtn.Click += new System.EventHandler(this.ShowHex_Click); + // // dumpSortedBtn // @@ -322,24 +322,30 @@ // // ChunkCombo // - this.ChunkCombo.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.saveChunkBtn, this.viewHexBtn}); + this.ChunkCombo.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.saveChunkBtn, this.viewHexBtn, this.previewFrameBtn}); this.ChunkCombo.Name = "Save"; - this.ChunkCombo.Size = new System.Drawing.Size(124, 48); - this.ChunkCombo.Opening += new System.ComponentModel.CancelEventHandler(this.ChunkCombo_Opening); + this.ChunkCombo.Size = new System.Drawing.Size(152, 70); + this.ChunkCombo.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ChunkCombo_ItemSelected); // // saveChunkBtn // this.saveChunkBtn.Name = "saveChunkBtn"; - this.saveChunkBtn.Size = new System.Drawing.Size(123, 22); + this.saveChunkBtn.Size = new System.Drawing.Size(151, 22); this.saveChunkBtn.Text = "Save"; // // viewHexBtn // this.viewHexBtn.Name = "viewHexBtn"; - this.viewHexBtn.Size = new System.Drawing.Size(123, 22); + this.viewHexBtn.Size = new System.Drawing.Size(151, 22); this.viewHexBtn.Text = "View Hex"; // + // previewFrameBtn + // + this.previewFrameBtn.Name = "previewFrameBtn"; + this.previewFrameBtn.Size = new System.Drawing.Size(151, 22); + this.previewFrameBtn.Text = "Preview Frame"; + // // packDataBtn // this.packDataBtn.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -437,6 +443,8 @@ this.PerformLayout(); } + private System.Windows.Forms.ToolStripMenuItem previewFrameBtn; + private System.Windows.Forms.Button musicsButton; private System.Windows.Forms.ProgressBar imageBar; diff --git a/NetMFAPatcher/GUI/MainForm.cs b/NetMFAPatcher/GUI/MainForm.cs index 89554a3..7427ffa 100644 --- a/NetMFAPatcher/GUI/MainForm.cs +++ b/NetMFAPatcher/GUI/MainForm.cs @@ -42,6 +42,8 @@ namespace DotNetCTFDumper.GUI saveChunkBtn.BackColor=Color.Black; viewHexBtn.ForeColor = ColorTheme; viewHexBtn.BackColor=Color.Black; + previewFrameBtn.ForeColor = ColorTheme; + previewFrameBtn.BackColor=Color.Black; //Labels label1.ForeColor = ColorTheme; label1.Text = Settings.DumperVersion; @@ -141,6 +143,15 @@ namespace DotNetCTFDumper.GUI break; case "viewHexBtn": ShowHex(); + break; + case "previewFrameBtn": + var selected = ((ChunkNode) treeView1.SelectedNode).loader; + if (selected is Frame frm) + { + var viewer = new FrameViewer(frm,Exe.Instance.GameData.GameChunks.GetChunk()); + viewer.Show(); + } + break; } } @@ -289,69 +300,57 @@ namespace DotNetCTFDumper.GUI { if (!IsDumpingSounds) { - soundBar.Visible = true; - soundLabel.Visible = true; - soundsButton.Text = "Cancel"; - soundBar.Value = 0; - IsDumpingSounds = true; - BreakSounds = false; - var worker = new BackgroundWorker(); - worker.DoWork += (senderA, eA) => - { - Exe.Instance.GameData.GameChunks.GetChunk().Read(true); - }; - worker.RunWorkerCompleted += (senderA, eA) => - { - soundBar.Visible = false; - soundLabel.Visible = false; - Logger.Log("Sounds done"); - soundsButton.Text = "Dump Sounds"; - }; - worker.RunWorkerAsync(); + SetSoundElements(true); + Backend.DumpSounds(this,true,true); + } else { BreakSounds = true; - soundBar.Visible = false; - soundLabel.Visible = false; - soundsButton.Text = "Dump Sounds"; IsDumpingSounds = false; + SetSoundElements(false); } } - private void imagesButton_Click(object sender, EventArgs e) { if (!IsDumpingImages) { - imageBar.Visible = true; - imageLabel.Visible = true; - imagesButton.Text = "Cancel"; - imageBar.Value = 0; - IsDumpingImages = true; - BreakImages = false; - var worker = new BackgroundWorker(); - worker.DoWork += (senderA, eA) => - { - Exe.Instance.GameData.GameChunks.GetChunk().Read(true,true); - }; - worker.RunWorkerCompleted += (senderA, eA) => - { - imageBar.Visible = false; - imageLabel.Visible = false; - Logger.Log("Images done",true,ConsoleColor.Yellow); - imagesButton.Text = "Dump Images"; - }; - worker.RunWorkerAsync(); + SetImageElements(true); + Backend.DumpImages(this,true,true); + } else { BreakImages = true; - imageBar.Visible = false; - imageLabel.Visible = false; - imagesButton.Text = "Dump Images"; IsDumpingImages = false; + SetImageElements(false); } } + + + public void SetSoundElements(bool state) + { + soundBar.Visible = state; + soundLabel.Visible = state; + soundsButton.Text = state ? "Cancel":"Dump Sounds"; + soundBar.Value = 0; + } + public void SetImageElements(bool state) + { + imageBar.Visible = state; + imageLabel.Visible = state; + imagesButton.Text = state ? "Cancel":"Dump Images"; + imageBar.Value = 0; + } + public void SetMusicElements(bool state) + { + musicBar.Visible = state; + musicLabel.Visible = state; + musicsButton.Text = state ? "Cancel":"Dump Musics"; + musicBar.Value = 0; + } + + @@ -377,31 +376,25 @@ namespace DotNetCTFDumper.GUI KeyForm.Show(); } - private void ShowHex_Click(object sender, EventArgs e) - { - ShowHex(); - - } + private void ShowHex() { - if ((ChunkNode) treeView1.SelectedNode != null) - { - var node = ((ChunkNode) treeView1.SelectedNode); - HexViewForm hexform = null; - - hexform = new HexViewForm(node.chunk.ChunkData,node.chunk.RawData,ColorTheme,$"Hew View: {node.chunk.Name}"); - - hexform.Show(); - } - - } + if ((ChunkNode) treeView1.SelectedNode != null) + { + var node = ((ChunkNode) treeView1.SelectedNode); + HexViewForm hexform = null; + + hexform = new HexViewForm(node.chunk.ChunkData, node.chunk.RawData, ColorTheme, + $"Hew View: {node.chunk.Name}"); + + hexform.Show(); + } - private void loadingLabel_Click(object sender, EventArgs e) - { - throw new NotImplementedException(); } + + private void dumpSortedBtn_Click(object sender, EventArgs e) { imageBar.Visible = true; @@ -409,7 +402,6 @@ namespace DotNetCTFDumper.GUI var worker = new BackgroundWorker(); worker.DoWork += (senderA, eA) => { - Settings.DumpImages = true; var bank = Exe.Instance.GameData.GameChunks.GetChunk(); bank.SaveImages=false; @@ -420,24 +412,12 @@ namespace DotNetCTFDumper.GUI { imageBar.Visible = false; imageLabel.Visible = false; - - ImageDumper.DumpImages(); }; worker.RunWorkerAsync(); } - private void listBox1_SelectedIndexChanged(object sender, EventArgs e) - { - //throw new System.NotImplementedException(); - } - - - - private void ChunkCombo_Opening(object sender, CancelEventArgs e) - { - - } + private void tabPage1_Click(object sender, EventArgs e) { @@ -452,39 +432,19 @@ namespace DotNetCTFDumper.GUI private void musicsButton_Click(object sender, EventArgs e) { - var bank = Exe.Instance.GameData.GameChunks.GetChunk(); - if (bank == null) return; + if (!IsDumpingMusics) { - musicBar.Visible = true; - musicLabel.Visible = true; - musicsButton.Text = "Cancel"; - musicBar.Value = 0; - IsDumpingMusics = true; - BreakMusics = false; - var worker = new BackgroundWorker(); - worker.DoWork += (senderA, eA) => - { - Exe.Instance.GameData.GameChunks.GetChunk().Read(true); - }; - worker.RunWorkerCompleted += (senderA, eA) => - { - musicBar.Visible = false; - musicLabel.Visible = false; - Logger.Log("Musics done",true,ConsoleColor.Yellow); - musicsButton.Text = "Dump Musics"; - }; - worker.RunWorkerAsync(); + Backend.DumpMusics(this,true,true); } else { BreakMusics = true; - musicBar.Visible = false; - musicLabel.Visible = false; - musicsButton.Text = "Dump Musics"; IsDumpingMusics = false; + SetMusicElements(false); } } + } } \ No newline at end of file diff --git a/NetMFAPatcher/GUI/ObjectBox.cs b/NetMFAPatcher/GUI/ObjectBox.cs new file mode 100644 index 0000000..9cd1603 --- /dev/null +++ b/NetMFAPatcher/GUI/ObjectBox.cs @@ -0,0 +1,15 @@ +using System.Windows.Forms; +using DotNetCTFDumper.MMFParser.ChunkLoaders; + +namespace DotNetCTFDumper.GUI +{ + public class ObjectBox:PictureBox + { + public ObjectInstance Obj; + + public ObjectBox(ObjectInstance obj) + { + this.Obj = obj; + } + } +} \ No newline at end of file diff --git a/NetMFAPatcher/MMFParser/Data/MFA.cs b/NetMFAPatcher/MMFParser/Data/MFA.cs index 3eddb44..c8259ff 100644 --- a/NetMFAPatcher/MMFParser/Data/MFA.cs +++ b/NetMFAPatcher/MMFParser/Data/MFA.cs @@ -139,7 +139,7 @@ namespace DotNetCTFDumper.MMFParser.Data //I am not an asshole lol writer.WriteAscii(ImageBankId); Icons.Write(writer); - return; + writer.WriteAscii(ImageBankId); Images.Write(writer); diff --git a/NetMFAPatcher/Utils/Backend.cs b/NetMFAPatcher/Utils/Backend.cs new file mode 100644 index 0000000..66bdbc4 --- /dev/null +++ b/NetMFAPatcher/Utils/Backend.cs @@ -0,0 +1,58 @@ +using System.ComponentModel; +using DotNetCTFDumper.GUI; +using DotNetCTFDumper.MMFParser.ChunkLoaders.Banks; +using static DotNetCTFDumper.MMFParser.Data.Exe; + +namespace DotNetCTFDumper.Utils +{ + public static class Backend + { + public static void DumpSounds(MainForm form,bool load,bool save) + { + using (var worker = new BackgroundWorker()) + { + if (Instance.GameData.GameChunks.GetChunk() == null) return; + form.SetSoundElements(true); + worker.DoWork += (senderA, eA) => { Instance.GameData.GameChunks.GetChunk().Read(save); }; + worker.RunWorkerCompleted += (senderA, eA) => + { + form.SetSoundElements(false); + MainForm.IsDumpingSounds = false; + }; + worker.RunWorkerAsync(); + } + } + public static void DumpImages(MainForm form,bool load,bool save) + { + using (var worker = new BackgroundWorker()) + { + if (Instance.GameData.GameChunks.GetChunk() == null) return; + form.SetImageElements(true); + worker.DoWork += (senderA, eA) => { Instance.GameData.GameChunks.GetChunk().Read(load,save); }; + worker.RunWorkerCompleted += (senderA, eA) => + { + form.SetImageElements(false); + MainForm.IsDumpingImages = false; + }; + worker.RunWorkerAsync(); + } + } + public static void DumpMusics(MainForm form,bool load,bool save) + { + using (var worker = new BackgroundWorker()) + { + if (Instance.GameData.GameChunks.GetChunk() == null) return; + form.SetMusicElements(true); + worker.DoWork += (senderA, eA) => { Instance.GameData.GameChunks.GetChunk().Read(save); }; + worker.RunWorkerCompleted += (senderA, eA) => + { + form.SetMusicElements(false); + MainForm.IsDumpingMusics = false; + }; + worker.RunWorkerAsync(); + } + } + + + } +} \ No newline at end of file diff --git a/NetMFAPatcher/mmfparser/chunkloaders/Frame.cs b/NetMFAPatcher/mmfparser/chunkloaders/Frame.cs index 1ce0172..7dc7032 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/Frame.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/Frame.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using DotNetCTFDumper.MMFParser.Data; using DotNetCTFDumper.Utils; using ChunkList = DotNetCTFDumper.MMFParser.Data.ChunkList; @@ -34,7 +35,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders public string Password; public int Width; public int Height; - public byte[] Background; + public Color Background; public int Flags; public int CountOfObjs; int _top; @@ -146,7 +147,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders "ToShow" }); - public byte[] Background; + public Color Background; public FrameHeader(ByteReader reader) : base(reader) { } @@ -174,7 +175,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders { Width = Reader.ReadInt32(); Height = Reader.ReadInt32(); - Background = Reader.ReadBytes(4); + Background = Reader.ReadColor(); Flags.flag = Reader.ReadUInt32(); @@ -244,9 +245,8 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders public override void Read() { - ObjectInfo = (ushort) Reader.ReadInt16(); Handle = (ushort) Reader.ReadInt16(); - + ObjectInfo = (ushort) Reader.ReadInt16(); X = Reader.ReadInt32(); Y = Reader.ReadInt32(); ParentType = Reader.ReadInt16(); @@ -264,7 +264,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders { get { - return Exe.Instance.GameData.GameChunks.GetChunk().FromHandle(Handle); + return Exe.Instance.GameData.GameChunks.GetChunk().FromHandle(ObjectInfo); } } diff --git a/NetMFAPatcher/mmfparser/chunkloaders/ObjectInfo.cs b/NetMFAPatcher/mmfparser/chunkloaders/ObjectInfo.cs index 03bff6d..b0483ee 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/ObjectInfo.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/ObjectInfo.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; +using DotNetCTFDumper.MMFParser.ChunkLoaders.Banks; using DotNetCTFDumper.MMFParser.ChunkLoaders.Objects; using DotNetCTFDumper.MMFParser.Data; using DotNetCTFDumper.Utils; @@ -83,9 +86,36 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders if (Properties != null) { - //Properties.ReadNew(ObjectType,this); + Properties.ReadNew(ObjectType,this); } } + + public ImageItem GetPreview() + { + ImageItem bmp=null; + var images = Exe.Instance.GameData.GameChunks.GetChunk(); + if (ObjectType == 2) + { + + var anims = ((ObjectCommon) (Properties.Loader)).Animations; + if (anims != null) + { + anims.AnimationDict.TryGetValue(0, + out Animation anim); + anim.DirectionDict.TryGetValue(0, out AnimationDirection direction); + var firstFrameHandle = direction.Frames[0]; + + bmp = images.Images[firstFrameHandle]; + } + } + else if (ObjectType == 1) + { + images.Images.TryGetValue(((Backdrop) Properties.Loader).Image, out var img); + bmp = img; + } + + return bmp; + } } public class ObjectName : StringChunk diff --git a/NetMFAPatcher/mmfparser/chunkloaders/banks/ImageBank.cs b/NetMFAPatcher/mmfparser/chunkloaders/banks/ImageBank.cs index 5c9e906..613cf15 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/banks/ImageBank.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/banks/ImageBank.cs @@ -90,10 +90,10 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks int _width; int _height; int _graphicMode; - int _xHotspot; - int _yHotspot; - int _actionX; - int _actionY; + public int XHotspot; + public int YHotspot; + public int ActionX; + public int ActionY; BitDict Flags = new BitDict(new string[] { @@ -119,6 +119,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks public bool Debug = false; public int Debug2 = 1; + private Bitmap _bitmap; public override void Read() { @@ -138,6 +139,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks public void Load() { + _bitmap = null; Reader.Seek(Position); ByteReader imageReader; @@ -157,16 +159,15 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks _width = imageReader.ReadInt16(); _height = imageReader.ReadInt16(); _graphicMode = imageReader.ReadByte(); //Graphic mode is always 4 for SL - Console.WriteLine("COLORMODE: "+_graphicMode); Flags.flag = imageReader.ReadByte(); imageReader.Skip(2); - _xHotspot = imageReader.ReadInt16(); - _yHotspot = imageReader.ReadInt16(); - _actionX = imageReader.ReadInt16(); - _actionY = imageReader.ReadInt16(); + XHotspot = imageReader.ReadInt16(); + YHotspot = imageReader.ReadInt16(); + ActionX = imageReader.ReadInt16(); + ActionY = imageReader.ReadInt16(); _transparent = imageReader.ReadBytes(4); - Logger.Log($"Loading image {Handle.ToString(),4} Size: {_width,4}x{_height,4}"); + //Logger.Log($"Loading image {Handle.ToString(),4} Size: {_width,4}x{_height,4}"); byte[] imageData; if (Flags["LZX"]) { @@ -227,22 +228,52 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks public void Save(string filename) { - using (var bmp = new Bitmap(_width, _height, PixelFormat.Format32bppArgb)) + + 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); + + bmp.UnlockBits(bmpData); + bmp.Save(filename); + } + + + } + + public Bitmap Bitmap + { + get { - BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, - bmp.Width, - bmp.Height), - ImageLockMode.WriteOnly, - bmp.PixelFormat); + if (_bitmap == null) + { + _bitmap = new Bitmap(_width, _height, PixelFormat.Format32bppArgb); + + BitmapData bmpData = _bitmap.LockBits(new Rectangle(0, 0, + _bitmap.Width, + _bitmap.Height), + ImageLockMode.WriteOnly, + _bitmap.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); + _bitmap.UnlockBits(bmpData); - bmp.Save(filename); + } + + return _bitmap; } + + } + public void Write(ByteWriter writer) { @@ -263,10 +294,10 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks } chunk.Skip(2); - chunk.WriteInt16((short) _xHotspot); - chunk.WriteInt16((short) _yHotspot); - chunk.WriteInt16((short) _actionX); - chunk.WriteInt16((short) _actionY); + chunk.WriteInt16((short) XHotspot); + chunk.WriteInt16((short) YHotspot); + chunk.WriteInt16((short) ActionX); + chunk.WriteInt16((short) ActionY); chunk.WriteBytes(_transparent); chunk.WriteBytes(rawImg); diff --git a/NetMFAPatcher/packages.config b/NetMFAPatcher/packages.config index b0f93ba..385f809 100644 --- a/NetMFAPatcher/packages.config +++ b/NetMFAPatcher/packages.config @@ -1,6 +1,7 @@  + - + \ No newline at end of file