static void Main(string[] args) { if (File.Exists("file.txt")) { using (StreamReader reader = File.OpenText("file.txt")) 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("DInput.txt")) { string json = File.ReadAllText("DInput.txt"); DCONTROLLER = JsonConvert.DeserializeObject <DController>(json); isDInput = true; DCONTROLLER.InitializeController(); } else { ConnectController(); } Hook(); Run(); }
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(); }
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(); } }