Ejemplo n.º 1
0
        public SaveState(ref Process gameProc, ref int baseAddress)
        {
            this.xPos = ProcessMemory.ReadSingle(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x20));
            this.yPos = ProcessMemory.ReadSingle(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x24));
            this.zPos = ProcessMemory.ReadSingle(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x28));
            this.xRot = ProcessMemory.ReadInt16(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x14));
            this.yRot = ProcessMemory.ReadInt16(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x18));
            this.zRot = ProcessMemory.ReadInt16(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x1C));

            this.hSpeed = ProcessMemory.ReadSingle(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0373CDF0, 0x38));
            this.vSpeed = ProcessMemory.ReadSingle(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0373CDF0, 0x3C));
            this.hover  = ProcessMemory.ReadInt16(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0373CDF0, 0x8));

            this.lives = ProcessMemory.ReadByte(gameProc, baseAddress + 0x0370EF34);
            this.rings = ProcessMemory.ReadInt16(gameProc, baseAddress + 0x0370F0E4);

            this.tFrames  = ProcessMemory.ReadByte(gameProc, baseAddress + 0x0370EF35);
            this.tSeconds = ProcessMemory.ReadByte(gameProc, baseAddress + 0x0370F128);
            this.tMins    = ProcessMemory.ReadByte(gameProc, baseAddress + 0x0370EF48);

            this.camX    = ProcessMemory.ReadSingle(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x20));
            this.camY    = ProcessMemory.ReadSingle(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x24));
            this.camZ    = ProcessMemory.ReadSingle(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x28));
            this.camXRot = ProcessMemory.ReadInt16(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x14));
            this.camYRot = ProcessMemory.ReadInt16(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x18));
            this.camZRot = ProcessMemory.ReadInt16(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x1C));
        }
Ejemplo n.º 2
0
        public static void LoadState(SaveState state)
        {
            // Write Position into memory
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x20), state.xPos);
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x24), state.yPos);
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x28), state.zPos);

            //ProcessMemory.Write("base+0372CAB0", "float", state.xPos.ToString());
            //ProcessMemory.Write("base+0372CAB4", "float", state.xPos.ToString());
            //ProcessMemory.Write("base+0372CAB8", "float", state.xPos.ToString());

            // Write Rotation into memory
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x14), state.xRot);
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x18), state.yRot);
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x03742E10, 0x1C), state.zRot);

            // Write Speed into memory
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0373CDF0, 0x38), state.hSpeed);
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0373CDF0, 0x3C), state.vSpeed);
            ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0373CDF0, 0x8), state.hover);

            // Write Lives and rings into memory
            ProcessMemory.Write(gameProc, baseAddress + 0x0370EF34, state.lives);
            ProcessMemory.Write(gameProc, baseAddress + 0x0370F0E4, state.rings);

            // Write time into memory
            ProcessMemory.Write(gameProc, baseAddress + 0x0370EF35, state.tFrames);
            ProcessMemory.Write(gameProc, baseAddress + 0x0370F128, state.tSeconds);
            ProcessMemory.Write(gameProc, baseAddress + 0x0370EF48, state.tMins);



            // Write camera info into memory
            if (ProcessMemory.ReadByte(gameProc, 0x372CBA8) != 7)
            {
                ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x20), state.camX);
                ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x24), state.camY);
                ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x28), state.camZ);

                ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x14), state.camXRot);
                ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x18), state.camYRot);
                ProcessMemory.Write(gameProc, ProcessMemory.GetFinalAddress(gameProc, baseAddress + 0x0372CBB0, 0x1C), state.camZRot);

                //ProcessMemory.Write("base+372CAE1", "byte", "0");
            }
        }
Ejemplo n.º 3
0
        public static void Run()
        {
            int buttonsPressed;

            bool hasSaved = false, hasLoaded = false, hasSwitched = false;
            bool DLeft, DRight, DUp, DDown, LB;

            int invertCycle = UserSettings.Default.invertCycle ? -1 : 1;

            while (true)
            {
                while (gameHooked)
                {
                    if (!isDInput)
                    {
                        if (CONTROLLER == null)
                        {
                            ConnectController();
                        }
                        else if (!CONTROLLER.GetConnected())
                        {
                            CONTROLLER = null;
                            Console.WriteLine("Controller disconnected");
                            continue;
                        }

                        buttonsPressed = (int)CONTROLLER.GetState().Gamepad.Buttons;

                        DUp    = (buttonsPressed & 1) != 0 ? true : false;
                        DDown  = (buttonsPressed & 2) != 0 ? true : false;
                        DLeft  = (buttonsPressed & 4) != 0 ? true : false;
                        DRight = (buttonsPressed & 8) != 0 ? true : false;
                        LB     = (buttonsPressed & 256) != 0 ? true : false;
                    }
                    else
                    {
                        bool[] Dinputs = DCONTROLLER.GetState();
                        if (!Dinputs[5])
                        {
                            DCONTROLLER.InitializeController();
                            continue;
                        }

                        DUp    = Dinputs[0];
                        DLeft  = Dinputs[1];
                        DRight = Dinputs[2];
                        DDown  = Dinputs[3];
                        LB     = Dinputs[4];
                    }

                    if (LB || !UserSettings.Default.extraInput)
                    {
                        if (DLeft && !hasSaved)
                        {
                            if (ProcessMemory.ReadByte(gameProc, baseAddress + 0x3722DE4) != 16)
                            {
                                saveStates[curSaveState] = new SaveState(ref gameProc, ref baseAddress);

                                Console.WriteLine("Saved to {0}", curSaveState);
                                SaveStateSerializer SaveObjectToSerialize = new SaveStateSerializer(saveStates);
                                string json = JsonConvert.SerializeObject(SaveObjectToSerialize, Formatting.Indented);

                                System.IO.File.WriteAllText("file.txt", json);
                            }
                            hasSaved = true;
                        }
                        else if (!DLeft && hasSaved)
                        {
                            hasSaved = false;
                        }


                        if (DRight && !hasLoaded)
                        {
                            if (saveStates[curSaveState] != null)
                            {
                                if (ProcessMemory.ReadByte(gameProc, baseAddress + 0x3722DE4) != 16)
                                {
                                    LoadState(saveStates[curSaveState]);

                                    Console.WriteLine("Loaded {0}", curSaveState);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Cannot find save state {0}", curSaveState);
                            }
                            hasLoaded = true;
                        }
                        else if (!DRight && hasLoaded)
                        {
                            hasLoaded = false;
                        }



                        if ((DUp || DDown) && !hasSwitched)
                        {
                            if (ProcessMemory.ReadByte(gameProc, baseAddress + 0x3722DE4) != 16)
                            {
                                //Console.WriteLine(Convert.ToInt32(UserSettings.Default.invertCycle));

                                curSaveState += Convert.ToInt32(DUp) * invertCycle;
                                curSaveState -= Convert.ToInt32(DDown) * invertCycle;

                                if (curSaveState == -1)
                                {
                                    curSaveState = 9;
                                }
                                else if (curSaveState == 10)
                                {
                                    curSaveState = 0;
                                }

                                Console.WriteLine("Switched to save slot {0}", curSaveState);
                            }
                            hasSwitched = true;
                        }
                        else if (!(DUp || DDown) && hasSwitched)
                        {
                            hasSwitched = false;
                        }

                        System.Threading.Thread.Sleep(10);
                    }
                }

                Hook();
            }
        }