diff --git a/tools/GSDumpGUI/Core/Program.cs b/tools/GSDumpGUI/Core/Program.cs index 010502aafa..9d2063b366 100644 --- a/tools/GSDumpGUI/Core/Program.cs +++ b/tools/GSDumpGUI/Core/Program.cs @@ -79,6 +79,16 @@ namespace GSDumpGUI wrap.GSConfig(); wrap.Unload(); + if (GSDXWrapper.DumpTooOld) + { + if (Client != null) + { + TCPMessage msg = new TCPMessage(); + msg.MessageType = MessageType.StateOld; + Client.Send(msg); + } + } + if (Client != null) Client.Disconnect(); } @@ -134,6 +144,12 @@ namespace GSDumpGUI frmMain.txtRegisters.Text = ((int)Mess.Parameters[6]).ToString(); }), new object[] { null }); break; + case MessageType.StateOld: + frmMain.Invoke(new Action(delegate(object e) + { + MessageBox.Show("Savestate too old to be read. :(", "Warning"); + }), new object[] { null }); + break; default: break; } diff --git a/tools/GSDumpGUI/Library/GSDXWrapper.cs b/tools/GSDumpGUI/Library/GSDXWrapper.cs index 1778fb0e56..8976c9cc71 100644 --- a/tools/GSDumpGUI/Library/GSDXWrapper.cs +++ b/tools/GSDumpGUI/Library/GSDXWrapper.cs @@ -7,12 +7,13 @@ using System.IO; namespace GSDumpGUI { public delegate void GSgifTransfer(IntPtr data, int size); + public delegate void GSgifTransfer1(IntPtr data, int size); public delegate void GSgifTransfer2(IntPtr data, int size); public delegate void GSgifTransfer3(IntPtr data, int size); public delegate void GSVSync(byte field); public delegate void GSreadFIFO2(IntPtr data, int size); public delegate void GSsetGameCRC(int crc, int options); - public delegate void GSfreeze(int mode, IntPtr data); + public delegate int GSfreeze(int mode, IntPtr data); public delegate void GSopen(IntPtr hwnd, String Title, int renderer); public delegate void GSclose(); public delegate void GSshutdown(); @@ -23,9 +24,12 @@ namespace GSDumpGUI public class GSDXWrapper { + static public bool DumpTooOld = false; + private GSConfigure gsConfigure; private PSEgetLibName PsegetLibName; private GSgifTransfer GSgifTransfer; + private GSgifTransfer1 GSgifTransfer1; private GSgifTransfer2 GSgifTransfer2; private GSgifTransfer3 GSgifTransfer3; private GSVSync GSVSync; @@ -107,6 +111,7 @@ namespace GSDumpGUI IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure"); IntPtr funcaddrGIF = NativeMethods.GetProcAddress(hmod, "GSgifTransfer"); + IntPtr funcaddrGIF1 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer1"); IntPtr funcaddrGIF2 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer2"); IntPtr funcaddrGIF3 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer3"); IntPtr funcaddrVSync = NativeMethods.GetProcAddress(hmod, "GSvsync"); @@ -123,6 +128,7 @@ namespace GSDumpGUI PsegetLibName = (PSEgetLibName)Marshal.GetDelegateForFunctionPointer(funcaddrLibName, typeof(PSEgetLibName)); this.GSgifTransfer = (GSgifTransfer)Marshal.GetDelegateForFunctionPointer(funcaddrGIF, typeof(GSgifTransfer)); + this.GSgifTransfer1 = (GSgifTransfer1)Marshal.GetDelegateForFunctionPointer(funcaddrGIF1, typeof(GSgifTransfer1)); this.GSgifTransfer2 = (GSgifTransfer2)Marshal.GetDelegateForFunctionPointer(funcaddrGIF2, typeof(GSgifTransfer2)); this.GSgifTransfer3 = (GSgifTransfer3)Marshal.GetDelegateForFunctionPointer(funcaddrGIF3, typeof(GSgifTransfer3)); this.GSVSync = (GSVSync)Marshal.GetDelegateForFunctionPointer(funcaddrVSync, typeof(GSVSync)); @@ -172,24 +178,37 @@ namespace GSDumpGUI GSsetGameCRC(dump.CRC, 0); fixed (byte* freeze = dump.StateData) { - GSfreeze(0, new IntPtr(freeze)); - GSVSync(1); + byte[] GSFreez = new byte[8]; + Array.Copy(BitConverter.GetBytes(dump.StateData.Length), 0, GSFreez, 0, 4); + Array.Copy(BitConverter.GetBytes(new IntPtr(freeze).ToInt32()), 0, GSFreez, 4, 4); - while (Running) + fixed (byte* fr = GSFreez) { - if (!NativeMethods.IsWindowVisible(new IntPtr(HWND))) + int ris = GSfreeze(0, new IntPtr(fr)); + if (ris == -1) { - Running = false; - break; + DumpTooOld = true; + return; } - foreach (var itm in dump.Data) - { - Step(itm, pointer); - } - } + GSVSync(1); - GSclose(); - GSshutdown(); + while (Running) + { + if (!NativeMethods.IsWindowVisible(new IntPtr(HWND))) + { + Running = false; + break; + } + foreach (var itm in dump.Data) + { + Step(itm, pointer); + } + + } + + GSclose(); + GSshutdown(); + } } } } @@ -203,27 +222,30 @@ namespace GSDumpGUI switch (((GSTransfer)itm).Path) { case GSTransferPath.Path1Old: - fixed (byte* gifdata = itm.data) + byte[] data = new byte[16384]; + int addr = 16384 - itm.data.Length; + Array.Copy(itm.data, 0, data, addr, itm.data.Length); + fixed (byte* gifdata = data) { - GSgifTransfer(new IntPtr(gifdata), (itm.data.Length) / 16); + GSgifTransfer1(new IntPtr(gifdata), addr); } break; case GSTransferPath.Path2: fixed (byte* gifdata = itm.data) { - GSgifTransfer2(new IntPtr(gifdata), (itm.data.Length) /16); + GSgifTransfer2(new IntPtr(gifdata), (itm.data.Length) / 16); } break; case GSTransferPath.Path3: fixed (byte* gifdata = itm.data) { - GSgifTransfer3(new IntPtr(gifdata), (itm.data.Length) /16); + GSgifTransfer3(new IntPtr(gifdata), (itm.data.Length) / 16); } break; case GSTransferPath.Path1New: fixed (byte* gifdata = itm.data) { - GSgifTransfer(new IntPtr(gifdata), (itm.data.Length) /16); + GSgifTransfer(new IntPtr(gifdata), (itm.data.Length) / 16); } break; } diff --git a/tools/GSDumpGUI/Library/GSDump/GSDump.cs b/tools/GSDumpGUI/Library/GSDump/GSDump.cs index c5130e56c7..b1a4a064a6 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSDump.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSDump.cs @@ -8,6 +8,7 @@ namespace GSDumpGUI public class GSDump { public Int32 CRC; + public byte[] GSFreeze; public byte[] StateData; public byte[] Registers; // 8192 bytes @@ -34,14 +35,51 @@ namespace GSDumpGUI Data = new List(); } + public GSDump Clone() + { + GSDump newDump = new GSDump(); + newDump.CRC = this.CRC; + + byte[] state = new byte[StateData.Length]; + Array.Copy(StateData,state, StateData.Length); + newDump.StateData = state; + + newDump.Registers = new byte[8192]; + Array.Copy(this.Registers, newDump.Registers, 8192); + + foreach (var itm in this.Data) + { + if (itm.GetType().IsInstanceOfType(typeof(GSTransfer))) + { + GSTransfer gt = new GSTransfer(); + gt.id = itm.id; + gt.Path = ((GSTransfer)itm).Path; + gt.data = new byte[itm.data.Length]; + Array.Copy(itm.data, gt.data, itm.data.Length); + newDump.Data.Add(gt); + } + else + { + GSData gt = new GSData(); + gt.id = itm.id; + gt.data = new byte[itm.data.Length]; + Array.Copy(itm.data, gt.data, itm.data.Length); + newDump.Data.Add(gt); + } + } + return newDump; + } + static public GSDump LoadDump(String FileName) { GSDump dmp = new GSDump(); BinaryReader br = new BinaryReader(System.IO.File.Open(FileName, FileMode.Open)); dmp.CRC = br.ReadInt32(); + Int32 ss = br.ReadInt32(); - dmp.StateData = br.ReadBytes(ss); + dmp.StateData = br.ReadBytes(ss); + dmp.Registers = br.ReadBytes(8192); while (br.PeekChar() != -1) diff --git a/tools/GSDumpGUI/Library/TCPLibrary/Message/TCPMessage.cs b/tools/GSDumpGUI/Library/TCPLibrary/Message/TCPMessage.cs index ce4c762b11..dc0512e732 100644 --- a/tools/GSDumpGUI/Library/TCPLibrary/Message/TCPMessage.cs +++ b/tools/GSDumpGUI/Library/TCPLibrary/Message/TCPMessage.cs @@ -110,6 +110,7 @@ namespace TCPLibrary.MessageBased.Core Connect, MaxUsers, SizeDump, - Statistics + Statistics, + StateOld } }