Esempio n. 1
0
        static void Main(string[] args)
        {
            /*if (File.Exists("states.json")) // Check if states.json exists and if so, read from it and parse JSON data for savestates
             * {
             *  using (StreamReader reader = File.OpenText("states.json"))
             *  using (JsonTextReader treader = new JsonTextReader(reader))
             *  {
             *      JObject jsonObj = (JObject)JToken.ReadFrom(treader);
             *      //jsonObj.Value<string>("Version"); //SaveState file version, useful for later when there's gonna be updates to the savestates themselves
             *
             *      saveStates = jsonObj["SaveStates"]?.ToObject<SaveState[]>();
             *  }
             * }*/

            if (File.Exists("save.states"))
            {
                saveStates = SaveStateSerialization.DeserializeStates();
            }

            if (File.Exists("DInput.txt")) // If DInput is configured (DInput file exists) then use the DInput code
            {
                string json = File.ReadAllText("DInput.txt");
                DCONTROLLER = JsonConvert.DeserializeObject <DController>(json);
                isDInput    = true;

                DCONTROLLER.InitializeController();
            }
            else
            {
                ConnectController();
            }

            Hook();
            Run();
        }
Esempio n. 2
0
        private static void Run()
        {
            bool hasSaved = false, hasLoaded = false, hasSwitched = false;

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

            while (true)
            {
                while (gameHooked)
                {
                    #region getButtons

                    bool dLeft, dRight, dUp, dDown, lb;
                    if (!isDInput)
                    {
                        if (CONTROLLER == null)
                        {
                            ConnectController();
                        }
                        else if (!CONTROLLER.GetConnected())
                        {
                            CONTROLLER = null;
                            Console.WriteLine("Controller disconnected");
                            continue;
                        }

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

                        dUp    = (buttonsPressed & 1) != 0;
                        dDown  = (buttonsPressed & 2) != 0;
                        dLeft  = (buttonsPressed & 4) != 0;
                        dRight = (buttonsPressed & 8) != 0;
                        lb     = (buttonsPressed & 256) != 0;
                    }
                    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];
                    }
                    #endregion

                    byte gameState = gameProc.ReadByte(0x3B22DE4);

                    if (!lb && UserSettings.Default.extraInput)
                    {
                        continue;
                    }

                    if (dLeft && !hasSaved)
                    {
                        if (gameState != 16 && gameState != 21)
                        {
                            saveStates[curSaveState] = new SaveState(ref gameProc, ref baseAddress);

                            Console.WriteLine("Saved to {0}", curSaveState);

                            SaveStateSerialization.SerialiseStates(saveStates);
                        }
                        hasSaved = true;
                    }
                    else if (!dLeft && hasSaved)
                    {
                        hasSaved = false;
                    }

                    if (dRight && !hasLoaded)
                    {
                        if (saveStates[curSaveState] != null)
                        {
                            if (gameState != 16 && gameState != 21)
                            {
                                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 (gameState != 16)
                        {
                            //Console.WriteLine(Convert.ToInt32(UserSettings.Default.invertCycle));

                            curSaveState += Convert.ToInt32(dUp) * invertCycle;
                            curSaveState -= Convert.ToInt32(dDown) * invertCycle;

                            switch (curSaveState)
                            {
                            case -1:
                                curSaveState = 9;
                                break;

                            case 10:
                                curSaveState = 0;
                                break;
                            }

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

                    Thread.Sleep(10);
                }

                Hook();
            }
        }