From 1a19a9294342828630a6d0c02ba80a1010c87315 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Wed, 15 Nov 2023 12:03:21 -0500 Subject: [PATCH] Disable memory patches in hardcore mode Memory patches would be an easy way to manipulate the memory needed to calculate achievement logic, so they must be disabled. Riivolution patches that do not affect memory are allowed, as they will be hashed with the game file. --- .../Core/Core/Debugger/PPCDebugInterface.cpp | 5 ++++ Source/Core/Core/PatchEngine.cpp | 9 +++++++ Source/Core/DiscIO/RiivolutionPatcher.cpp | 6 +++++ .../Core/DolphinQt/Config/PatchesWidget.cpp | 26 +++++++++++++++---- Source/Core/DolphinQt/Config/PatchesWidget.h | 18 +++++++++---- .../DolphinQt/Config/PropertiesDialog.cpp | 4 +++ .../Core/DolphinQt/Config/PropertiesDialog.h | 3 +++ Source/Core/DolphinQt/GameList/GameList.cpp | 4 +++ Source/Core/DolphinQt/GameList/GameList.h | 3 +++ Source/Core/DolphinQt/MainWindow.cpp | 5 ++++ .../Core/DolphinQt/RiivolutionBootWidget.cpp | 18 +++++++++++++ Source/Core/DolphinQt/RiivolutionBootWidget.h | 12 +++++++++ 12 files changed, 103 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Debugger/PPCDebugInterface.cpp index 5f8d04d79a..7ab64c9310 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Debugger/PPCDebugInterface.cpp @@ -16,6 +16,7 @@ #include "Common/GekkoDisassembler.h" #include "Common/StringUtil.h" +#include "Core/Config/AchievementSettings.h" #include "Core/Config/MainSettings.h" #include "Core/Core.h" #include "Core/Debugger/OSThread.h" @@ -29,6 +30,10 @@ void ApplyMemoryPatch(const Core::CPUThreadGuard& guard, Common::Debug::MemoryPatch& patch, bool store_existing_value) { +#ifdef USE_RETRO_ACHIEVEMENTS + if (Config::Get(Config::RA_HARDCORE_ENABLED)) + return; +#endif // USE_RETRO_ACHIEVEMENTS if (patch.value.empty()) return; diff --git a/Source/Core/Core/PatchEngine.cpp b/Source/Core/Core/PatchEngine.cpp index 069d8565c0..456c2b008c 100644 --- a/Source/Core/Core/PatchEngine.cpp +++ b/Source/Core/Core/PatchEngine.cpp @@ -26,6 +26,7 @@ #include "Core/ActionReplay.h" #include "Core/CheatCodes.h" +#include "Core/Config/AchievementSettings.h" #include "Core/Config/SessionSettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -232,6 +233,10 @@ void LoadPatches() static void ApplyPatches(const Core::CPUThreadGuard& guard, const std::vector& patches) { +#ifdef USE_RETRO_ACHIEVEMENTS + if (Config::Get(Config::RA_HARDCORE_ENABLED)) + return; +#endif // USE_RETRO_ACHIEVEMENTS for (const Patch& patch : patches) { if (patch.enabled) @@ -273,6 +278,10 @@ static void ApplyPatches(const Core::CPUThreadGuard& guard, const std::vector memory_patch_indices) { +#ifdef USE_RETRO_ACHIEVEMENTS + if (Config::Get(Config::RA_HARDCORE_ENABLED)) + return; +#endif // USE_RETRO_ACHIEVEMENTS std::lock_guard lock(s_on_frame_memory_mutex); for (std::size_t index : memory_patch_indices) { diff --git a/Source/Core/DiscIO/RiivolutionPatcher.cpp b/Source/Core/DiscIO/RiivolutionPatcher.cpp index 9362a3930a..175ee18f17 100644 --- a/Source/Core/DiscIO/RiivolutionPatcher.cpp +++ b/Source/Core/DiscIO/RiivolutionPatcher.cpp @@ -14,6 +14,7 @@ #include "Common/FileUtil.h" #include "Common/IOFile.h" #include "Common/StringUtil.h" +#include "Core/Config/AchievementSettings.h" #include "Core/HLE/HLE.h" #include "Core/HW/Memmap.h" #include "Core/IOS/FS/FileSystem.h" @@ -522,6 +523,11 @@ static bool MemoryMatchesAt(const Core::CPUThreadGuard& guard, u32 offset, static void ApplyMemoryPatch(const Core::CPUThreadGuard& guard, u32 offset, const std::vector& value, const std::vector& original) { +#ifdef USE_RETRO_ACHIEVEMENTS + if (::Config::Get(::Config::RA_HARDCORE_ENABLED)) + return; +#endif // USE_RETRO_ACHIEVEMENTS + if (value.empty()) return; diff --git a/Source/Core/DolphinQt/Config/PatchesWidget.cpp b/Source/Core/DolphinQt/Config/PatchesWidget.cpp index e1fd12f913..0aa216ad82 100644 --- a/Source/Core/DolphinQt/Config/PatchesWidget.cpp +++ b/Source/Core/DolphinQt/Config/PatchesWidget.cpp @@ -14,6 +14,7 @@ #include "Core/ConfigManager.h" #include "Core/PatchEngine.h" +#include "DolphinQt/Config/HardcoreWarningWidget.h" #include "DolphinQt/Config/NewPatchDialog.h" #include "DolphinQt/QtUtils/SetWindowDecorations.h" @@ -40,23 +41,38 @@ PatchesWidget::PatchesWidget(const UICommon::GameFile& game) void PatchesWidget::CreateWidgets() { +#ifdef USE_RETRO_ACHIEVEMENTS + m_hc_warning = new HardcoreWarningWidget(this); +#endif // USE_RETRO_ACHIEVEMENTS m_list = new QListWidget; m_add_button = new QPushButton(tr("&Add...")); m_edit_button = new QPushButton(); m_remove_button = new QPushButton(tr("&Remove")); - auto* layout = new QGridLayout; + auto* grid_layout = new QGridLayout; - layout->addWidget(m_list, 0, 0, 1, -1); - layout->addWidget(m_add_button, 1, 0); - layout->addWidget(m_edit_button, 1, 2); - layout->addWidget(m_remove_button, 1, 1); + grid_layout->addWidget(m_list, 0, 0, 1, -1); + grid_layout->addWidget(m_add_button, 1, 0); + grid_layout->addWidget(m_edit_button, 1, 2); + grid_layout->addWidget(m_remove_button, 1, 1); + + auto* layout = new QVBoxLayout; + +#ifdef USE_RETRO_ACHIEVEMENTS + layout->addWidget(m_hc_warning); +#endif // USE_RETRO_ACHIEVEMENTS + layout->addLayout(grid_layout); setLayout(layout); } void PatchesWidget::ConnectWidgets() { +#ifdef USE_RETRO_ACHIEVEMENTS + connect(m_hc_warning, &HardcoreWarningWidget::OpenAchievementSettings, this, + &PatchesWidget::OpenAchievementSettings); +#endif // USE_RETRO_ACHIEVEMENTS + connect(m_list, &QListWidget::itemSelectionChanged, this, &PatchesWidget::UpdateActions); connect(m_list, &QListWidget::itemChanged, this, &PatchesWidget::OnItemChanged); connect(m_remove_button, &QPushButton::clicked, this, &PatchesWidget::OnRemove); diff --git a/Source/Core/DolphinQt/Config/PatchesWidget.h b/Source/Core/DolphinQt/Config/PatchesWidget.h index bb84519bbb..9c324ce49a 100644 --- a/Source/Core/DolphinQt/Config/PatchesWidget.h +++ b/Source/Core/DolphinQt/Config/PatchesWidget.h @@ -9,12 +9,11 @@ #include #include "Common/CommonTypes.h" +#include "Core/PatchEngine.h" -namespace PatchEngine -{ -struct Patch; -} - +#ifdef USE_RETRO_ACHIEVEMENTS +class HardcoreWarningWidget; +#endif // USE_RETRO_ACHIEVEMENTS class QListWidget; class QListWidgetItem; class QPushButton; @@ -26,9 +25,15 @@ class GameFile; class PatchesWidget : public QWidget { + Q_OBJECT public: explicit PatchesWidget(const UICommon::GameFile& game); +#ifdef USE_RETRO_ACHIEVEMENTS +signals: + void OpenAchievementSettings(); +#endif // USE_RETRO_ACHIEVEMENTS + private: void CreateWidgets(); void ConnectWidgets(); @@ -41,6 +46,9 @@ private: void OnRemove(); void OnEdit(); +#ifdef USE_RETRO_ACHIEVEMENTS + HardcoreWarningWidget* m_hc_warning; +#endif // USE_RETRO_ACHIEVEMENTS QListWidget* m_list; QPushButton* m_add_button; QPushButton* m_edit_button; diff --git a/Source/Core/DolphinQt/Config/PropertiesDialog.cpp b/Source/Core/DolphinQt/Config/PropertiesDialog.cpp index b72e950862..834c5d68cf 100644 --- a/Source/Core/DolphinQt/Config/PropertiesDialog.cpp +++ b/Source/Core/DolphinQt/Config/PropertiesDialog.cpp @@ -51,6 +51,10 @@ PropertiesDialog::PropertiesDialog(QWidget* parent, const UICommon::GameFile& ga &PropertiesDialog::OpenGeneralSettings); connect(ar, &ARCodeWidget::OpenGeneralSettings, this, &PropertiesDialog::OpenGeneralSettings); +#ifdef USE_RETRO_ACHIEVEMENTS + connect(patches, &PatchesWidget::OpenAchievementSettings, this, + &PropertiesDialog::OpenAchievementSettings); +#endif // USE_RETRO_ACHIEVEMENTS connect(graphics_mod_list, &GraphicsModListWidget::OpenGraphicsSettings, this, &PropertiesDialog::OpenGraphicsSettings); diff --git a/Source/Core/DolphinQt/Config/PropertiesDialog.h b/Source/Core/DolphinQt/Config/PropertiesDialog.h index 2135be8948..29d282a6e8 100644 --- a/Source/Core/DolphinQt/Config/PropertiesDialog.h +++ b/Source/Core/DolphinQt/Config/PropertiesDialog.h @@ -19,4 +19,7 @@ public: signals: void OpenGeneralSettings(); void OpenGraphicsSettings(); +#ifdef USE_RETRO_ACHIEVEMENTS + void OpenAchievementSettings(); +#endif // USE_RETRO_ACHIEVEMENTS }; diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index 242466af35..1b621222b2 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -552,6 +552,10 @@ void GameList::OpenProperties() connect(properties, &PropertiesDialog::OpenGeneralSettings, this, &GameList::OpenGeneralSettings); connect(properties, &PropertiesDialog::OpenGraphicsSettings, this, &GameList::OpenGraphicsSettings); +#ifdef USE_RETRO_ACHIEVEMENTS + connect(properties, &PropertiesDialog::OpenAchievementSettings, this, + &GameList::OpenAchievementSettings); +#endif // USE_RETRO_ACHIEVEMENTS SetQWidgetWindowDecorations(properties); properties->show(); diff --git a/Source/Core/DolphinQt/GameList/GameList.h b/Source/Core/DolphinQt/GameList/GameList.h index ebe2ec7152..54ca50ab15 100644 --- a/Source/Core/DolphinQt/GameList/GameList.h +++ b/Source/Core/DolphinQt/GameList/GameList.h @@ -56,6 +56,9 @@ signals: void SelectionChanged(std::shared_ptr game_file); void OpenGeneralSettings(); void OpenGraphicsSettings(); +#ifdef USE_RETRO_ACHIEVEMENTS + void OpenAchievementSettings(); +#endif // USE_RETRO_ACHIEVEMENTS private: void ShowHeaderContextMenu(const QPoint& pos); diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 6cf6ac57bd..e3b96c6390 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -246,6 +246,11 @@ MainWindow::MainWindow(std::unique_ptr boot_parameters, connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this, &MainWindow::ShowGeneralWindow); +#ifdef USE_RETRO_ACHIEVEMENTS + connect(m_game_list, &GameList::OpenAchievementSettings, this, + &MainWindow::ShowAchievementSettings); +#endif // USE_RETRO_ACHIEVEMENTS + InitCoreCallbacks(); NetPlayInit(); diff --git a/Source/Core/DolphinQt/RiivolutionBootWidget.cpp b/Source/Core/DolphinQt/RiivolutionBootWidget.cpp index 178fef2367..29b5af0a1f 100644 --- a/Source/Core/DolphinQt/RiivolutionBootWidget.cpp +++ b/Source/Core/DolphinQt/RiivolutionBootWidget.cpp @@ -26,6 +26,7 @@ #include "DiscIO/GameModDescriptor.h" #include "DiscIO/RiivolutionParser.h" #include "DiscIO/RiivolutionPatcher.h" +#include "DolphinQt/Config/HardcoreWarningWidget.h" #include "DolphinQt/QtUtils/ModalMessageBox.h" struct GuiRiivolutionPatchIndex @@ -48,6 +49,7 @@ RiivolutionBootWidget::RiivolutionBootWidget(std::string game_id, std::optional< setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); CreateWidgets(); + ConnectWidgets(); LoadMatchingXMLs(); resize(QSize(400, 600)); @@ -57,6 +59,9 @@ RiivolutionBootWidget::~RiivolutionBootWidget() = default; void RiivolutionBootWidget::CreateWidgets() { +#ifdef USE_RETRO_ACHIEVEMENTS + m_hc_warning = new HardcoreWarningWidget(this); +#endif // USE_RETRO_ACHIEVEMENTS auto* open_xml_button = new QPushButton(tr("Open Riivolution XML...")); auto* boot_game_button = new QPushButton(tr("Start")); boot_game_button->setDefault(true); @@ -79,6 +84,9 @@ void RiivolutionBootWidget::CreateWidgets() button_layout->addWidget(boot_game_button, 0, Qt::AlignRight); auto* layout = new QVBoxLayout(); +#ifdef USE_RETRO_ACHIEVEMENTS + layout->addWidget(m_hc_warning); +#endif // USE_RETRO_ACHIEVEMENTS layout->addWidget(scroll_area); layout->addLayout(button_layout); setLayout(layout); @@ -88,6 +96,16 @@ void RiivolutionBootWidget::CreateWidgets() connect(save_preset_button, &QPushButton::clicked, this, &RiivolutionBootWidget::SaveAsPreset); } +void RiivolutionBootWidget::ConnectWidgets() +{ +#ifdef USE_RETRO_ACHIEVEMENTS + connect(m_hc_warning, &HardcoreWarningWidget::OpenAchievementSettings, this, + &RiivolutionBootWidget::OpenAchievementSettings); + connect(m_hc_warning, &HardcoreWarningWidget::OpenAchievementSettings, this, + &RiivolutionBootWidget::reject); +#endif // USE_RETRO_ACHIEVEMENTS +} + void RiivolutionBootWidget::LoadMatchingXMLs() { const std::string& riivolution_dir = File::GetUserPath(D_RIIVOLUTION_IDX); diff --git a/Source/Core/DolphinQt/RiivolutionBootWidget.h b/Source/Core/DolphinQt/RiivolutionBootWidget.h index 1318241a11..2455001928 100644 --- a/Source/Core/DolphinQt/RiivolutionBootWidget.h +++ b/Source/Core/DolphinQt/RiivolutionBootWidget.h @@ -11,6 +11,9 @@ #include "Common/CommonTypes.h" #include "DiscIO/RiivolutionParser.h" +#ifdef USE_RETRO_ACHIEVEMENTS +class HardcoreWarningWidget; +#endif // USE_RETRO_ACHIEVEMENTS class QPushButton; class QVBoxLayout; @@ -26,8 +29,14 @@ public: bool ShouldBoot() const { return m_should_boot; } std::vector& GetPatches() { return m_patches; } +#ifdef USE_RETRO_ACHIEVEMENTS +signals: + void OpenAchievementSettings(); +#endif // USE_RETRO_ACHIEVEMENTS + private: void CreateWidgets(); + void ConnectWidgets(); void LoadMatchingXMLs(); void OpenXML(); @@ -38,6 +47,9 @@ private: void BootGame(); void SaveAsPreset(); +#ifdef USE_RETRO_ACHIEVEMENTS + HardcoreWarningWidget* m_hc_warning; +#endif // USE_RETRO_ACHIEVEMENTS std::string m_game_id; std::optional m_revision; std::optional m_disc_number;