From 415fa3c6a5f25353e3e8348ee95f99399d3d0701 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Tue, 10 Sep 2024 08:18:38 -0400 Subject: [PATCH] Migrate Hardcore Toggle Code to Achievement Manager AchievementManager::SetHardcoreMode now handles the (non-Qt) settings disabled by hardcore mode, instead of doing this on the Qt layer. Also ensured Init/Enable Achievements paths run this code, fixing the bug wherein the player can manipulate things when achievements are disabled that persist when turned back on. --- Source/Core/Core/AchievementManager.cpp | 11 ++++++- .../AchievementSettingsWidget.cpp | 29 +++++++++---------- .../Achievements/AchievementSettingsWidget.h | 2 ++ 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index a1288a2b70..4d3cb7a617 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -24,6 +24,8 @@ #include "Common/Version.h" #include "Common/WorkQueueThread.h" #include "Core/Config/AchievementSettings.h" +#include "Core/Config/FreeLookSettings.h" +#include "Core/Config/MainSettings.h" #include "Core/Core.h" #include "Core/HW/Memmap.h" #include "Core/HW/VideoInterface.h" @@ -62,7 +64,7 @@ void AchievementManager::Init() [](const char* message, const rc_client_t* client) { INFO_LOG_FMT(ACHIEVEMENTS, "{}", message); }); - rc_client_set_hardcore_enabled(m_client, Config::Get(Config::RA_HARDCORE_ENABLED)); + SetHardcoreMode(); m_queue.Reset("AchievementManagerQueue", [](const std::function& func) { func(); }); m_image_queue.Reset("AchievementManagerImageQueue", [](const std::function& func) { func(); }); @@ -345,6 +347,13 @@ std::recursive_mutex& AchievementManager::GetLock() void AchievementManager::SetHardcoreMode() { rc_client_set_hardcore_enabled(m_client, Config::Get(Config::RA_HARDCORE_ENABLED)); + if (Config::Get(Config::RA_HARDCORE_ENABLED)) + { + if (Config::Get(Config::MAIN_EMULATION_SPEED) < 1.0f) + Config::SetBaseOrCurrent(Config::MAIN_EMULATION_SPEED, 1.0f); + Config::SetBaseOrCurrent(Config::FREE_LOOK_ENABLED, false); + Config::SetBaseOrCurrent(Config::MAIN_ENABLE_CHEATS, false); + } } bool AchievementManager::IsHardcoreModeActive() const diff --git a/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp b/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp index 175d9b2f0e..261130d105 100644 --- a/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp +++ b/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp @@ -247,11 +247,7 @@ void AchievementSettingsWidget::ToggleRAIntegration() instance.Init(); else instance.Shutdown(); - if (Config::Get(Config::RA_HARDCORE_ENABLED)) - { - emit Settings::Instance().EmulationStateChanged(Core::GetState(Core::System::GetInstance())); - emit Settings::Instance().HardcoreStateChanged(); - } + UpdateHardcoreMode(); } void AchievementSettingsWidget::Login() @@ -271,17 +267,7 @@ void AchievementSettingsWidget::Logout() void AchievementSettingsWidget::ToggleHardcore() { SaveSettings(); - AchievementManager::GetInstance().SetHardcoreMode(); - if (Config::Get(Config::RA_HARDCORE_ENABLED)) - { - if (Config::Get(Config::MAIN_EMULATION_SPEED) < 1.0f) - Config::SetBaseOrCurrent(Config::MAIN_EMULATION_SPEED, 1.0f); - Config::SetBaseOrCurrent(Config::FREE_LOOK_ENABLED, false); - Config::SetBaseOrCurrent(Config::MAIN_ENABLE_CHEATS, false); - Settings::Instance().SetDebugModeEnabled(false); - } - emit Settings::Instance().EmulationStateChanged(Core::GetState(Core::System::GetInstance())); - emit Settings::Instance().HardcoreStateChanged(); + UpdateHardcoreMode(); } void AchievementSettingsWidget::ToggleUnofficial() @@ -311,4 +297,15 @@ void AchievementSettingsWidget::ToggleProgress() SaveSettings(); } +void AchievementSettingsWidget::UpdateHardcoreMode() +{ + AchievementManager::GetInstance().SetHardcoreMode(); + if (Config::Get(Config::RA_HARDCORE_ENABLED)) + { + Settings::Instance().SetDebugModeEnabled(false); + } + emit Settings::Instance().EmulationStateChanged(Core::GetState(Core::System::GetInstance())); + emit Settings::Instance().HardcoreStateChanged(); +} + #endif // USE_RETRO_ACHIEVEMENTS diff --git a/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.h b/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.h index 8d4aa03c2a..6a62a86191 100644 --- a/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.h +++ b/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.h @@ -39,6 +39,8 @@ private: void ToggleDiscordPresence(); void ToggleProgress(); + void UpdateHardcoreMode(); + QGroupBox* m_common_box; QVBoxLayout* m_common_layout; ToolTipCheckBox* m_common_integration_enabled_input;