Achievements: Rework challenge mode enabling

Fixes enabling hardcore mode per-game not having any effect.
This commit is contained in:
Connor McLaughlin 2022-10-17 19:41:46 +10:00 committed by lightningterror
parent 53bd98394b
commit ddf839beb0
3 changed files with 26 additions and 27 deletions

View File

@ -28,7 +28,7 @@ namespace Achievements
extern void GameChanged(u32 crc); extern void GameChanged(u32 crc);
/// Re-enables hardcode mode if it is enabled in the settings. /// Re-enables hardcode mode if it is enabled in the settings.
extern void ResetChallengeMode(); extern bool ResetChallengeMode();
/// Forces hardcore mode off until next reset. /// Forces hardcore mode off until next reset.
extern void DisableChallengeMode(); extern void DisableChallengeMode();
@ -62,7 +62,10 @@ namespace Achievements
return false; return false;
} }
static inline void ResetChallengeMode() {} static inline bool ResetChallengeMode()
{
return false;
}
static inline void DisableChallengeMode() {} static inline void DisableChallengeMode() {}

View File

@ -548,7 +548,8 @@ void Achievements::UpdateSettings(const Pcsx2Config::AchievementsOptions& old_co
} }
else if (!s_challenge_mode && EmuConfig.Achievements.ChallengeMode) else if (!s_challenge_mode && EmuConfig.Achievements.ChallengeMode)
{ {
ImGuiFullscreen::ShowToast(std::string(), "Hardcore mode will be enabled on system reset.", 10.0f); if (HasActiveGame())
ImGuiFullscreen::ShowToast(std::string(), "Hardcore mode will be enabled on system reset.", 10.0f);
} }
} }
@ -610,15 +611,18 @@ void Achievements::DisableChallengeMode()
SetChallengeMode(false); SetChallengeMode(false);
} }
void Achievements::ResetChallengeMode() bool Achievements::ResetChallengeMode()
{ {
if (!s_active) if (!s_active)
return; return false;
Host::RemoveKeyedOSDMessage("challenge_mode_reset"); Host::RemoveKeyedOSDMessage("challenge_mode_reset");
if (s_challenge_mode != EmuConfig.Achievements.ChallengeMode) if (s_challenge_mode == EmuConfig.Achievements.ChallengeMode)
SetChallengeMode(EmuConfig.Achievements.ChallengeMode); return false;
SetChallengeMode(EmuConfig.Achievements.ChallengeMode);
return true;
} }
void Achievements::SetChallengeMode(bool enabled) void Achievements::SetChallengeMode(bool enabled)
@ -701,19 +705,14 @@ bool Achievements::OnReset()
return true; return true;
std::unique_lock lock(s_achievements_mutex); std::unique_lock lock(s_achievements_mutex);
// Clear the game out, we'll re-query it once the ELF is loaded.
ClearGameInfo(true, true);
ClearGameHash();
// Reset runtime, there shouldn't be anything left in it though.
DevCon.WriteLn("Resetting rcheevos state..."); DevCon.WriteLn("Resetting rcheevos state...");
rc_runtime_reset(&s_rcheevos_runtime); rc_runtime_reset(&s_rcheevos_runtime);
// we can re-enable hardcore mode, since we're rebooting the system
if (EmuConfig.Achievements.ChallengeMode && !s_challenge_mode)
{
// but, clear the game first. otherwise, we re-query the current game in hardcore mode,
// reset to nothing (booting), then back to the game again and spam the user.
ClearGameInfo(true, true);
ClearGameHash();
ResetChallengeMode();
}
return true; return true;
} }

View File

@ -693,6 +693,12 @@ void VMManager::UpdateRunningGame(bool resetting, bool game_starting)
if (s_patches_crc != s_game_crc) if (s_patches_crc != s_game_crc)
ReloadPatches(game_starting, false); ReloadPatches(game_starting, false);
#ifdef ENABLE_ACHIEVEMENTS
// Per-game ini enabling of hardcore mode. We need to re-enforce the settings if so.
if (game_starting && Achievements::ResetChallengeMode())
ApplySettings();
#endif
GetMTGS().SendGameCRC(new_crc); GetMTGS().SendGameCRC(new_crc);
Host::OnGameChanged(s_disc_path, s_game_serial, s_game_name, s_game_crc); Host::OnGameChanged(s_disc_path, s_game_serial, s_game_name, s_game_crc);
@ -1095,17 +1101,8 @@ void VMManager::Shutdown(bool save_resume_state)
void VMManager::Reset() void VMManager::Reset()
{ {
#ifdef ENABLE_ACHIEVEMENTS #ifdef ENABLE_ACHIEVEMENTS
const bool previous_challenge_mode = Achievements::ChallengeModeActive();
if (!Achievements::OnReset()) if (!Achievements::OnReset())
return; return;
if (Achievements::ChallengeModeActive() && !previous_challenge_mode)
{
// Hardcore mode enabled, so reload settings. This only covers the BIOS
// portion of the boot, once the game loads we'll reset anyway, but better
// to change things like the speed now rather than later.
ApplySettings();
}
#endif #endif
const bool game_was_started = g_GameStarted; const bool game_was_started = g_GameStarted;