From 003046c91c0c52518b36ecbaf5432a9f7f9596af Mon Sep 17 00:00:00 2001 From: KrossX Date: Sun, 28 Jul 2019 22:24:39 -0300 Subject: [PATCH] GSDumpGUI: Minor improvements. Loop changes, icon and info shows up, can take screenshot. --- tools/GSDumpGUI/Core/Program.cs | 28 +---- tools/GSDumpGUI/Library/GSDXWrapper.cs | 166 +++++++++++++------------ 2 files changed, 89 insertions(+), 105 deletions(-) diff --git a/tools/GSDumpGUI/Core/Program.cs b/tools/GSDumpGUI/Core/Program.cs index 0b90f7ab62..40329a321b 100644 --- a/tools/GSDumpGUI/Core/Program.cs +++ b/tools/GSDumpGUI/Core/Program.cs @@ -43,17 +43,19 @@ namespace GSDumpGUI static public List Clients; static public TCPLibrary.MessageBased.Core.BaseMessageClient Client; - static private Boolean ChangeIcon; static private GSDump dump; static private GSDXWrapper wrap; static private TreeNode CurrentNode; + static public IntPtr hMainIcon; [STAThread] static void Main(String[] args) { if (args.Length == 5) { + hMainIcon = Resources.AppIcon.Handle; + // do this first, else racy mess ;) wrap = new GSDXWrapper(); var port = Convert.ToInt32(args[4]); @@ -69,29 +71,6 @@ namespace GSDumpGUI Client = null; } - Thread thd = new Thread(new ThreadStart(delegate - { - while (true) - { - IntPtr pt = Process.GetCurrentProcess().MainWindowHandle; - if (ChangeIcon) - { - if (pt.ToInt64() != 0) - { - NativeMethods.SetClassLong(pt, -14, Resources.AppIcon.Handle.ToInt64()); - ChangeIcon = false; - } - } - - Int32 tmp = NativeMethods.GetAsyncKeyState(0x1b) & 0xf; - if (tmp != 0) - Process.GetCurrentProcess().Kill(); - Thread.Sleep(16); - } - })); - thd.IsBackground = true; - thd.Start(); - // Retrieve parameters String DLLPath = args[0]; String DumpPath = args[1]; @@ -111,7 +90,6 @@ namespace GSDumpGUI } wrap.Run(dump, Renderer); - ChangeIcon = true; } else wrap.GSConfig(); diff --git a/tools/GSDumpGUI/Library/GSDXWrapper.cs b/tools/GSDumpGUI/Library/GSDXWrapper.cs index 069a66cfc0..382fe9546a 100644 --- a/tools/GSDumpGUI/Library/GSDXWrapper.cs +++ b/tools/GSDumpGUI/Library/GSDXWrapper.cs @@ -39,14 +39,15 @@ namespace GSDumpGUI public delegate void GSreset(); public delegate void GSreadFIFO2(IntPtr data, int size); public delegate void GSsetGameCRC(int crc, int options); - public delegate int GSfreeze(int mode, IntPtr data); - public delegate void GSopen(IntPtr hwnd, String Title, int renderer); + public delegate int GSfreeze(int mode, IntPtr data); + public delegate int GSopen(IntPtr hwnd, String Title, int renderer); public delegate void GSclose(); public delegate void GSshutdown(); public delegate void GSConfigure(); public delegate void GSsetBaseMem(IntPtr data); public delegate IntPtr PSEgetLibName(); public delegate void GSinit(); + public delegate UInt32 GSmakeSnapshot(string path); public class InvalidGSPlugin : Exception { @@ -73,7 +74,7 @@ namespace GSDumpGUI private GSsetBaseMem GSsetBaseMem; private GSinit GSinit; private GSreset GSreset; - + private GSmakeSnapshot GSmakeSnapshot; private Boolean Loaded; private String DLL; @@ -128,6 +129,7 @@ namespace GSDumpGUI IntPtr funcaddrFreeze = NativeMethods.GetProcAddress(hmod, "GSfreeze"); IntPtr funcaddrGSreadFIFO2 = NativeMethods.GetProcAddress(hmod, "GSreadFIFO2"); IntPtr funcaddrinit = NativeMethods.GetProcAddress(hmod, "GSinit"); + IntPtr funcmakeSnapshot = NativeMethods.GetProcAddress(hmod, "GSmakeSnapshot"); if (!((funcaddrConfig.ToInt64() > 0) && (funcaddrLibName.ToInt64() > 0) && (funcaddrGIF.ToInt64() > 0))) { @@ -151,6 +153,7 @@ namespace GSDumpGUI this.GSreset = (GSreset) Marshal.GetDelegateForFunctionPointer(funcaddrGSReset, typeof(GSreset)); this.GSreadFIFO2 = (GSreadFIFO2) Marshal.GetDelegateForFunctionPointer(funcaddrGSreadFIFO2, typeof(GSreadFIFO2)); this.GSinit = (GSinit) Marshal.GetDelegateForFunctionPointer(funcaddrinit, typeof(GSinit)); + this.GSmakeSnapshot = (GSmakeSnapshot)Marshal.GetDelegateForFunctionPointer(funcmakeSnapshot, typeof(GSmakeSnapshot)); Loaded = true; } @@ -205,10 +208,15 @@ namespace GSDumpGUI fixed (byte* pointer = tempregisters) { GSsetBaseMem(new IntPtr(pointer)); - Int32 HWND = 0; - GSopen(new IntPtr(&HWND), "", rendererOverride); + IntPtr hWnd = IntPtr.Zero; + + if (GSopen(new IntPtr(&hWnd), "", rendererOverride) != 0) + return; + GSsetGameCRC(dump.CRC, 0); + NativeMethods.SetClassLong(hWnd,/*GCL_HICON*/ -14, Program.hMainIcon.ToInt32()); + fixed (byte* freeze = dump.StateData) { byte[] GSFreez = new byte[8]; @@ -225,95 +233,93 @@ namespace GSDumpGUI } GSVSync(1); + GSreset(); + Marshal.Copy(dump.Registers, 0, new IntPtr(pointer), 8192); + GSsetBaseMem(new IntPtr(pointer)); + GSfreeze(0, new IntPtr(fr)); + + int gs_idx = 0; + int debug_idx = 0; + NativeMessage msg; + while (Running) { - if (!NativeMethods.IsWindowVisible(new IntPtr(HWND))) + while (NativeMethods.PeekMessage(out msg, hWnd, 0, 0, 1)) // PM_REMOVE { - Running = false; - break; + NativeMethods.TranslateMessage(ref msg); + NativeMethods.DispatchMessage(ref msg); + + if(msg.msg == 0x0100) // WM_KEYDOWN + { + switch(msg.wParam.ToInt32() & 0xFF) + { + case 0x1B: Running = false; break; // VK_ESCAPE; + case 0x77: GSmakeSnapshot(""); break; // VK_F8; + } + } } - GSreset(); - Marshal.Copy(dump.Registers, 0, new IntPtr(pointer), 8192); - GSsetBaseMem(new IntPtr(pointer)); - GSfreeze(0, new IntPtr(fr)); + if (!Running) + break; - for (int i = 0; i < dump.Data.Count; i++) + if (DebugMode) { - GSData itm = dump.Data[i]; - CurrentGIFPacket = itm; - - if (DebugMode) + if (QueueMessage.Count > 0) { - if (RunTo != -1) + TCPMessage Mess = QueueMessage.Dequeue(); + switch (Mess.MessageType) { - if (i == RunTo) - { - RunTo = -1; - int idxnextReg = dump.Data.FindIndex(i, a => a.id == GSType.Registers); - if (idxnextReg != -1) - { - Step(dump.Data[idxnextReg], pointer); - } - - GSData g = new GSData(); - g.id = GSType.VSync; - Step(g, pointer); - - TCPMessage Msg = new TCPMessage(); - Msg.MessageType = MessageType.RunToCursor; - Msg.Parameters.Add(i); - Program.Client.Send(Msg); - - ExternalEvent.Set(); - } - else - { - Step(itm, pointer); - } - } - else - { - while (!ThereIsWork && Running) - { - NativeMessage message; - while (NativeMethods.PeekMessage(out message, IntPtr.Zero, 0, 0, 1)) - { - if (!NativeMethods.IsWindowVisible(new IntPtr(HWND))) - { - Running = false; - } - NativeMethods.TranslateMessage(ref message); - NativeMethods.DispatchMessage(ref message); - } - } - - ThereIsWork = false; - if (QueueMessage.Count > 0) - { - TCPMessage Mess = QueueMessage.Dequeue(); - switch (Mess.MessageType) - { - case MessageType.Step: - RunTo = i; - break; - case MessageType.RunToCursor: - RunTo = (int)Mess.Parameters[0]; - break; - case MessageType.RunToNextVSync: - RunTo = dump.Data.FindIndex(i, a => a.id == GSType.VSync); - break; - default: - break; - } + case MessageType.Step: + if (debug_idx >= dump.Data.Count) debug_idx = 0; + RunTo = debug_idx; + break; + case MessageType.RunToCursor: + RunTo = (int)Mess.Parameters[0]; + if(debug_idx > RunTo) debug_idx = 0; + break; + case MessageType.RunToNextVSync: + if (debug_idx >= dump.Data.Count) debug_idx = 1; + RunTo = dump.Data.FindIndex(debug_idx, a => a.id == GSType.VSync); + break; + default: break; - } } } - else + + if (debug_idx <= RunTo) { - Step(itm, pointer); + while (debug_idx <= RunTo) + { + GSData itm = dump.Data[debug_idx]; + CurrentGIFPacket = itm; + Step(itm, pointer); + debug_idx++; + } + + int idxnextReg = dump.Data.FindIndex(debug_idx, a => a.id == GSType.Registers); + if (idxnextReg != -1) + Step(dump.Data[idxnextReg], pointer); + + TCPMessage Msg = new TCPMessage(); + Msg.MessageType = MessageType.RunToCursor; + Msg.Parameters.Add(debug_idx - 1); + Program.Client.Send(Msg); + + ExternalEvent.Set(); } + + GSData g = new GSData(); + g.id = GSType.VSync; + Step(g, pointer); + + } + else + { + GSData itm = dump.Data[gs_idx++]; + CurrentGIFPacket = itm; + Step(itm, pointer); + + if (gs_idx >= dump.Data.Count) gs_idx = 0; } }