Пример #1
0
        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);
        }
Пример #2
0
        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;
        }
Пример #3
0
        public static 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.Registers = br.ReadBytes(8192);

            while (br.PeekChar() != -1)
            {
                GSType id = (GSType)br.ReadByte();
                switch (id)
                {
                    case GSType.Transfer:
                        GSTransfer data = new GSTransfer();

                        byte index = br.ReadByte();

                        data.id = id;
                        data.Path = (GSTransferPath)index;

                        Int32 size = br.ReadInt32();

                        List<byte> Data = new List<byte>();
                        Data.AddRange(br.ReadBytes(size));
                        data.data = Data.ToArray();
                        dmp.Data.Add(data);
                        break;
                    case GSType.VSync:
                        GSData dataV = new GSData();
                        dataV.id = id;
                        dataV.data = br.ReadBytes(1);
                        dmp.Data.Add(dataV);
                        break;
                    case GSType.ReadFIFO2:
                        GSData dataR = new GSData();
                        dataR.id = id;
                        Int32 sF = br.ReadInt32();
                        dataR.data = BitConverter.GetBytes(sF);
                        dmp.Data.Add(dataR);
                        break;
                    case GSType.Registers:
                        GSData dataRR = new GSData();
                        dataRR.id = id;
                        dataRR.data = br.ReadBytes(8192);
                        dmp.Data.Add(dataRR);
                        break;
                    default:
                        break;
                }
            }
            br.Close();

            return dmp;
        }
Пример #4
0
        private unsafe void Step(GSData itm, byte *registers)
        {
            /*"C:\Users\Alessio\Desktop\Plugins\Dll\GSdx-SSE4.dll" "C:\Users\Alessio\Desktop\Plugins\Dumps\gsdx_20101222215004.gs" "GSReplay" 0*/
            switch (itm.id)
            {
            case GSType.Transfer:
                switch (((GSTransfer)itm).Path)
                {
                case GSTransferPath.Path1Old:
                    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)
                    {
                        GSgifTransfer1(new IntPtr(gifdata), addr);
                    }

                    break;

                case GSTransferPath.Path2:
                    fixed(byte *gifdata = itm.data)
                    {
                        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);
                    }

                    break;

                case GSTransferPath.Path1New:
                    fixed(byte *gifdata = itm.data)
                    {
                        GSgifTransfer(new IntPtr(gifdata), (itm.data.Length) / 16);
                    }

                    break;
                }
                break;

            case GSType.VSync:
                GSVSync((*((int *)(registers + 4096)) & 0x2000) > 0 ? (byte)1 : (byte)0);
                break;

            case GSType.ReadFIFO2:
                fixed(byte *FIFO = itm.data)
                {
                    byte[] arrnew = new byte[*((int *)FIFO)];
                    fixed(byte *arrn = arrnew)
                    {
                        GSreadFIFO2(new IntPtr(arrn), *((int *)FIFO));
                    }
                }

                break;

            case GSType.Registers:
                Marshal.Copy(itm.data, 0, new IntPtr(registers), 8192);
                break;

            default:
                break;
            }
        }
Пример #5
0
        public unsafe void Run(GSDump dump, int rendererOverride)
        {
            QueueMessage  = new Queue <TCPMessage>();
            Running       = true;
            ExternalEvent = new AutoResetEvent(true);

            GSinit();
            byte[] tempregisters = new byte[8192];
            Array.Copy(dump.Registers, tempregisters, 8192);
            fixed(byte *pointer = tempregisters)
            {
                GSsetBaseMem(new IntPtr(pointer));
                IntPtr hWnd = IntPtr.Zero;

                if (GSopen(new IntPtr(&hWnd), "", rendererOverride) != 0)
                {
                    return;
                }

                GSsetGameCRC(dump.CRC, 0);

                NativeMethods.SetClassLong(hWnd, /*GCL_HICON*/ -14, Program.hMainIcon);

                fixed(byte *freeze = dump.StateData)
                {
                    byte[] GSFreez;

                    if (Environment.Is64BitProcess)
                    {
                        GSFreez = new byte[16];
                        Array.Copy(BitConverter.GetBytes((Int64)dump.StateData.Length), 0, GSFreez, 0, 8);
                        Array.Copy(BitConverter.GetBytes(new IntPtr(freeze).ToInt64()), 0, GSFreez, 8, 8);
                    }
                    else
                    {
                        GSFreez = new byte[8];
                        Array.Copy(BitConverter.GetBytes((Int32)dump.StateData.Length), 0, GSFreez, 0, 4);
                        Array.Copy(BitConverter.GetBytes(new IntPtr(freeze).ToInt32()), 0, GSFreez, 4, 4);
                    }

                    fixed(byte *fr = GSFreez)
                    {
                        int ris = GSfreeze(0, new IntPtr(fr));

                        if (ris == -1)
                        {
                            DumpTooOld = true;
                            Running    = false;
                        }
                        GSVSync(1);

                        GSreset();
                        Marshal.Copy(dump.Registers, 0, new IntPtr(pointer), 8192);
                        GSsetBaseMem(new IntPtr(pointer));
                        GSfreeze(0, new IntPtr(fr));

                        GSData gsd_vsync = new GSData();

                        gsd_vsync.id = GSType.VSync;

                        int           gs_idx    = 0;
                        int           debug_idx = 0;
                        NativeMessage msg;

                        while (Running)
                        {
                            while (NativeMethods.PeekMessage(out msg, hWnd, 0, 0, 1)) // PM_REMOVE
                            {
                                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;
                                    }
                                }
                            }

                            if (!Running || !NativeMethods.IsWindowVisible(hWnd))
                            {
                                break;
                            }

                            if (DebugMode)
                            {
                                if (QueueMessage.Count > 0)
                                {
                                    TCPMessage Mess = QueueMessage.Dequeue();
                                    switch (Mess.MessageType)
                                    {
                                    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;
                                    }
                                }

                                if (debug_idx <= RunTo)
                                {
                                    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();
                                }

                                Step(gsd_vsync, pointer);
                            }
                            else
                            {
                                while (gs_idx < dump.Data.Count)
                                {
                                    GSData itm = dump.Data[gs_idx++];
                                    CurrentGIFPacket = itm;
                                    Step(itm, pointer);

                                    if (gs_idx < dump.Data.Count && dump.Data[gs_idx].id == GSType.VSync)
                                    {
                                        break;
                                    }
                                }

                                if (gs_idx >= dump.Data.Count)
                                {
                                    gs_idx = 0;
                                }
                            }
                        }

                        GSclose();
                        GSshutdown();
                    }
                }
            }
        }
Пример #6
0
 private unsafe void Step(GSData itm, byte* registers)
 {
     /*"C:\Users\Alessio\Desktop\Plugins\Dll\GSdx-SSE4.dll" "C:\Users\Alessio\Desktop\Plugins\Dumps\gsdx_20101222215004.gs" "GSReplay" 0*/
     switch (itm.id)
     {
         case GSType.Transfer:
             switch (((GSTransfer)itm).Path)
             {
                 case GSTransferPath.Path1Old:
                     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)
                     {
                         GSgifTransfer1(new IntPtr(gifdata), addr);
                     }
                     break;
                 case GSTransferPath.Path2:
                     fixed (byte* gifdata = itm.data)
                     {
                         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);
                     }
                     break;
                 case GSTransferPath.Path1New:
                     fixed (byte* gifdata = itm.data)
                     {
                         GSgifTransfer(new IntPtr(gifdata), (itm.data.Length) / 16);
                     }
                     break;
             }
             break;
         case GSType.VSync:
             GSVSync((*((int*)(registers + 4096)) & 0x2000) > 0 ? (byte)1 : (byte)0);
             break;
         case GSType.ReadFIFO2:
             fixed (byte* FIFO = itm.data)
             {
                 byte[] arrnew = new byte[*((int*)FIFO)];
                 fixed (byte* arrn = arrnew)
                 {
                     GSreadFIFO2(new IntPtr(arrn), *((int*)FIFO));
                 }
             }
             break;
         case GSType.Registers:
             Marshal.Copy(itm.data, 0, new IntPtr(registers), 8192);
             break;
         default:
             break;
     }            
 }
Пример #7
0
        public unsafe void Run(GSDump dump, int rendererOverride)
        {
            QueueMessage = new Queue<TCPMessage>();
            Running = true;
            ExternalEvent = new AutoResetEvent(true);

            GSinit();
            byte[] tempregisters = new byte[8192];
            Array.Copy(dump.Registers, tempregisters, 8192);
            fixed (byte* pointer = tempregisters)
            {
                GSsetBaseMem(new IntPtr(pointer));
                Int32 HWND = 0;
                GSopen(new IntPtr(&HWND), "", rendererOverride);
                GSsetGameCRC(dump.CRC, 0);

                fixed (byte* freeze = dump.StateData)
                {
                    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);

                    fixed (byte* fr = GSFreez)
                    {
                        int ris = GSfreeze(0, new IntPtr(fr));
                        if (ris == -1)
                        {
                            DumpTooOld = true;
                            return;
                        }
                        GSVSync(1);

                        while (Running)
                        {
                            if (!NativeMethods.IsWindowVisible(new IntPtr(HWND)))
                            {
                                Running = false;
                                break;
                            }

                            GSreset();
                            Marshal.Copy(dump.Registers, 0, new IntPtr(pointer), 8192);
                            GSsetBaseMem(new IntPtr(pointer));
                            GSfreeze(0, new IntPtr(fr));

                            for (int i = 0; i < dump.Data.Count; i++)
                            {
                                GSData itm = dump.Data[i];
                                CurrentGIFPacket = itm;

                                if (DebugMode)
                                {
                                    if (RunTo != -1)
                                    {
                                        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;
                                            }
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    Step(itm, pointer);
                                }
                            }
                        }

                        GSclose();
                        GSshutdown();
                    }
                }
            }
        }
Пример #8
0
        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.Registers = br.ReadBytes(8192);

            while (br.PeekChar() != -1)
            {
                GSType id = (GSType)br.ReadByte();
                switch (id)
                {
                case GSType.Transfer:
                    GSTransfer data = new GSTransfer();

                    byte index = br.ReadByte();

                    data.id   = id;
                    data.Path = (GSTransferPath)index;

                    Int32 size = br.ReadInt32();

                    List <byte> Data = new List <byte>();
                    Data.AddRange(br.ReadBytes(size));
                    data.data = Data.ToArray();
                    dmp.Data.Add(data);
                    break;

                case GSType.VSync:
                    GSData dataV = new GSData();
                    dataV.id   = id;
                    dataV.data = br.ReadBytes(1);
                    dmp.Data.Add(dataV);
                    break;

                case GSType.ReadFIFO2:
                    GSData dataR = new GSData();
                    dataR.id = id;
                    Int32 sF = br.ReadInt32();
                    dataR.data = BitConverter.GetBytes(sF);
                    dmp.Data.Add(dataR);
                    break;

                case GSType.Registers:
                    GSData dataRR = new GSData();
                    dataRR.id   = id;
                    dataRR.data = br.ReadBytes(8192);
                    dmp.Data.Add(dataRR);
                    break;

                default:
                    break;
                }
            }
            br.Close();

            return(dmp);
        }
Пример #9
0
        public unsafe void Run(GSDump dump, int rendererOverride)
        {
            QueueMessage  = new Queue <TCPMessage>();
            Running       = true;
            ExternalEvent = new AutoResetEvent(true);

            GSinit();
            byte[] tempregisters = new byte[8192];
            Array.Copy(dump.Registers, tempregisters, 8192);
            fixed(byte *pointer = tempregisters)
            {
                GSsetBaseMem(new IntPtr(pointer));
                Int32 HWND = 0;

                GSopen(new IntPtr(&HWND), "", rendererOverride);
                GSsetGameCRC(dump.CRC, 0);

                fixed(byte *freeze = dump.StateData)
                {
                    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);

                    fixed(byte *fr = GSFreez)
                    {
                        int ris = GSfreeze(0, new IntPtr(fr));

                        if (ris == -1)
                        {
                            DumpTooOld = true;
                            return;
                        }
                        GSVSync(1);

                        while (Running)
                        {
                            if (!NativeMethods.IsWindowVisible(new IntPtr(HWND)))
                            {
                                Running = false;
                                break;
                            }

                            GSreset();
                            Marshal.Copy(dump.Registers, 0, new IntPtr(pointer), 8192);
                            GSsetBaseMem(new IntPtr(pointer));
                            GSfreeze(0, new IntPtr(fr));

                            for (int i = 0; i < dump.Data.Count; i++)
                            {
                                GSData itm = dump.Data[i];
                                CurrentGIFPacket = itm;

                                if (DebugMode)
                                {
                                    if (RunTo != -1)
                                    {
                                        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;
                                            }
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    Step(itm, pointer);
                                }
                            }
                        }

                        GSclose();
                        GSshutdown();
                    }
                }
            }
        }