public DarkSoulsProcess() { this.state = HookingStates.Start; this.darksoulsHandle = IntPtr.Zero; this.progress = new GameProgress(new List <Requirement>() { { new Requirement("Treasure Locations", 0.2, UpdatePickedUpItems) }, { new Requirement("Bosses", 0.25, UpdateDefetedBosses) }, { new Requirement("Non-respawning Enemies", 0.15, UpdateKilledNonRespawningEnemies) }, { new Requirement("NPC Questlines", 0.2, UpdateCompletedQuestlines) }, { new Requirement("Shortcuts / Locked Doors", 0.1, UpdateUnlockedShortcutsAndLockedDoors) }, { new Requirement("Illusory Walls", 0.025, ReleavedIllusoryWalls) }, { new Requirement("Foggates", 0.025, UpdateDissolvedFoggates) }, { new Requirement("Kindled Bonfires", 0.05, UpdateFullyKindledBonfires) }, }); }
public void Next() { switch (state) { // At the start, we force and progress update to start the UI / whatever is // hooked to progress.OnGameProgressUpdated case HookingStates.Start: progress.OnGameProgressUpdated += Progress_OnGameProgressUpdated; progress.Reset(); state = HookingStates.Unhooked; break; // Will loop here untils it finds a valid DARKSOULS.exe (Release or Debug) case HookingStates.Unhooked: if (Hook()) { // Game hooked! We can move on state = HookingStates.CheckingProcess; } break; // Before updating the progress, we verify that the game is running up and running // Deallocates the asm memory if it's not the case and switch back to Unhooked // If the game is still present, this will bounce back and forth with Hooked case HookingStates.CheckingProcess: if (!IsGameRunning()) { // Process is gone Reset(); state = HookingStates.Unhooked; } else { // Everything's fine, we can update state = HookingStates.Hooked; } break; // If we're here, then we can finally update all the requirements... case HookingStates.Hooked: try { Update(); state = HookingStates.CheckingProcess; } // Unless we get an Exception wil reading the memory, which means the game // got closed / while we were reading. Switch back to CheckingProcess catch (Exception e) when(e is Win32Exception || e is ArgumentNullException || e is ArgumentException) { state = HookingStates.CheckingProcess; return; } break; // Cause you always need a default in a switch amarite default: state = HookingStates.Unhooked; break; } }
private void Reset() { darksouls = null; darksoulsHandle = IntPtr.Zero; state = HookingStates.Start; }