From 415fa3c6a5f25353e3e8348ee95f99399d3d0701 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Tue, 10 Sep 2024 08:18:38 -0400 Subject: [PATCH 1/3] 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; From 72f682ab13edc49e40cd5e52f24a16feb60f5de8 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Wed, 24 Jul 2024 22:15:06 -0400 Subject: [PATCH 2/3] Add Confirm Popups for Achievements Logout and Hardcore Off --- .../AchievementSettingsWidget.cpp | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp b/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp index 261130d105..b90ad58604 100644 --- a/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp +++ b/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp @@ -21,6 +21,7 @@ #include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h" #include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h" +#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/NonDefaultQPushButton.h" #include "DolphinQt/QtUtils/SignalBlocking.h" #include "DolphinQt/Settings.h" @@ -36,7 +37,7 @@ AchievementSettingsWidget::AchievementSettingsWidget(QWidget* parent) : QWidget( // If hardcore is enabled when the emulator starts, make sure it turns off what it needs to if (Config::Get(Config::RA_HARDCORE_ENABLED)) - ToggleHardcore(); + UpdateHardcoreMode(); } void AchievementSettingsWidget::UpdateData() @@ -260,12 +261,29 @@ void AchievementSettingsWidget::Login() void AchievementSettingsWidget::Logout() { - AchievementManager::GetInstance().Logout(); - SaveSettings(); + auto confirm = ModalMessageBox::question( + this, tr("Confirm Logout"), tr("Are you sure you want to log out of RetroAchievements?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton, Qt::ApplicationModal); + if (confirm == QMessageBox::Yes) + { + AchievementManager::GetInstance().Logout(); + SaveSettings(); + } } void AchievementSettingsWidget::ToggleHardcore() { + if (Config::Get(Config::RA_HARDCORE_ENABLED)) + { + auto confirm = ModalMessageBox::question( + this, tr("Confirm Hardcore Off"), tr("Are you sure you want to turn hardcore mode off?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton, Qt::ApplicationModal); + if (confirm != QMessageBox::Yes) + { + SignalBlocking(m_common_hardcore_enabled_input)->setChecked(true); + return; + } + } SaveSettings(); UpdateHardcoreMode(); } From a36746a79a603a5b1ae96aadd52fa2492a760d58 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Thu, 3 Oct 2024 09:01:00 -0400 Subject: [PATCH 3/3] Turn off debug mode if hardcore is active on emulator start Found this bug while testing; if I manually edit the config files while Dolphin is closed I was able to get debug and hardcore on at the same time, this resolves that. --- Source/Core/DolphinQt/MainWindow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 5c3ca31d5a..1268d215d3 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -269,6 +269,8 @@ MainWindow::MainWindow(std::unique_ptr boot_parameters, #ifdef USE_RETRO_ACHIEVEMENTS AchievementManager::GetInstance().Init(); + if (AchievementManager::GetInstance().IsHardcoreModeActive()) + Settings::Instance().SetDebugModeEnabled(false); #endif // USE_RETRO_ACHIEVEMENTS #if defined(__unix__) || defined(__unix) || defined(__APPLE__)