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.
This commit is contained in:
LillyJadeKatrin 2023-11-15 12:03:21 -05:00
parent cb2fa9a1f2
commit 1a19a92943
12 changed files with 103 additions and 10 deletions

View File

@ -16,6 +16,7 @@
#include "Common/GekkoDisassembler.h" #include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/Config/MainSettings.h" #include "Core/Config/MainSettings.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/Debugger/OSThread.h" #include "Core/Debugger/OSThread.h"
@ -29,6 +30,10 @@
void ApplyMemoryPatch(const Core::CPUThreadGuard& guard, Common::Debug::MemoryPatch& patch, void ApplyMemoryPatch(const Core::CPUThreadGuard& guard, Common::Debug::MemoryPatch& patch,
bool store_existing_value) bool store_existing_value)
{ {
#ifdef USE_RETRO_ACHIEVEMENTS
if (Config::Get(Config::RA_HARDCORE_ENABLED))
return;
#endif // USE_RETRO_ACHIEVEMENTS
if (patch.value.empty()) if (patch.value.empty())
return; return;

View File

@ -26,6 +26,7 @@
#include "Core/ActionReplay.h" #include "Core/ActionReplay.h"
#include "Core/CheatCodes.h" #include "Core/CheatCodes.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/Config/SessionSettings.h" #include "Core/Config/SessionSettings.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
@ -232,6 +233,10 @@ void LoadPatches()
static void ApplyPatches(const Core::CPUThreadGuard& guard, const std::vector<Patch>& patches) static void ApplyPatches(const Core::CPUThreadGuard& guard, const std::vector<Patch>& patches)
{ {
#ifdef USE_RETRO_ACHIEVEMENTS
if (Config::Get(Config::RA_HARDCORE_ENABLED))
return;
#endif // USE_RETRO_ACHIEVEMENTS
for (const Patch& patch : patches) for (const Patch& patch : patches)
{ {
if (patch.enabled) if (patch.enabled)
@ -273,6 +278,10 @@ static void ApplyPatches(const Core::CPUThreadGuard& guard, const std::vector<Pa
static void ApplyMemoryPatches(const Core::CPUThreadGuard& guard, static void ApplyMemoryPatches(const Core::CPUThreadGuard& guard,
std::span<const std::size_t> memory_patch_indices) std::span<const std::size_t> 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); std::lock_guard lock(s_on_frame_memory_mutex);
for (std::size_t index : memory_patch_indices) for (std::size_t index : memory_patch_indices)
{ {

View File

@ -14,6 +14,7 @@
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/IOFile.h" #include "Common/IOFile.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/HLE/HLE.h" #include "Core/HLE/HLE.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/IOS/FS/FileSystem.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, static void ApplyMemoryPatch(const Core::CPUThreadGuard& guard, u32 offset,
const std::vector<u8>& value, const std::vector<u8>& original) const std::vector<u8>& value, const std::vector<u8>& original)
{ {
#ifdef USE_RETRO_ACHIEVEMENTS
if (::Config::Get(::Config::RA_HARDCORE_ENABLED))
return;
#endif // USE_RETRO_ACHIEVEMENTS
if (value.empty()) if (value.empty())
return; return;

View File

@ -14,6 +14,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/PatchEngine.h" #include "Core/PatchEngine.h"
#include "DolphinQt/Config/HardcoreWarningWidget.h"
#include "DolphinQt/Config/NewPatchDialog.h" #include "DolphinQt/Config/NewPatchDialog.h"
#include "DolphinQt/QtUtils/SetWindowDecorations.h" #include "DolphinQt/QtUtils/SetWindowDecorations.h"
@ -40,23 +41,38 @@ PatchesWidget::PatchesWidget(const UICommon::GameFile& game)
void PatchesWidget::CreateWidgets() void PatchesWidget::CreateWidgets()
{ {
#ifdef USE_RETRO_ACHIEVEMENTS
m_hc_warning = new HardcoreWarningWidget(this);
#endif // USE_RETRO_ACHIEVEMENTS
m_list = new QListWidget; m_list = new QListWidget;
m_add_button = new QPushButton(tr("&Add...")); m_add_button = new QPushButton(tr("&Add..."));
m_edit_button = new QPushButton(); m_edit_button = new QPushButton();
m_remove_button = new QPushButton(tr("&Remove")); m_remove_button = new QPushButton(tr("&Remove"));
auto* layout = new QGridLayout; auto* grid_layout = new QGridLayout;
layout->addWidget(m_list, 0, 0, 1, -1); grid_layout->addWidget(m_list, 0, 0, 1, -1);
layout->addWidget(m_add_button, 1, 0); grid_layout->addWidget(m_add_button, 1, 0);
layout->addWidget(m_edit_button, 1, 2); grid_layout->addWidget(m_edit_button, 1, 2);
layout->addWidget(m_remove_button, 1, 1); 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); setLayout(layout);
} }
void PatchesWidget::ConnectWidgets() 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::itemSelectionChanged, this, &PatchesWidget::UpdateActions);
connect(m_list, &QListWidget::itemChanged, this, &PatchesWidget::OnItemChanged); connect(m_list, &QListWidget::itemChanged, this, &PatchesWidget::OnItemChanged);
connect(m_remove_button, &QPushButton::clicked, this, &PatchesWidget::OnRemove); connect(m_remove_button, &QPushButton::clicked, this, &PatchesWidget::OnRemove);

View File

@ -9,12 +9,11 @@
#include <QWidget> #include <QWidget>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/PatchEngine.h"
namespace PatchEngine #ifdef USE_RETRO_ACHIEVEMENTS
{ class HardcoreWarningWidget;
struct Patch; #endif // USE_RETRO_ACHIEVEMENTS
}
class QListWidget; class QListWidget;
class QListWidgetItem; class QListWidgetItem;
class QPushButton; class QPushButton;
@ -26,9 +25,15 @@ class GameFile;
class PatchesWidget : public QWidget class PatchesWidget : public QWidget
{ {
Q_OBJECT
public: public:
explicit PatchesWidget(const UICommon::GameFile& game); explicit PatchesWidget(const UICommon::GameFile& game);
#ifdef USE_RETRO_ACHIEVEMENTS
signals:
void OpenAchievementSettings();
#endif // USE_RETRO_ACHIEVEMENTS
private: private:
void CreateWidgets(); void CreateWidgets();
void ConnectWidgets(); void ConnectWidgets();
@ -41,6 +46,9 @@ private:
void OnRemove(); void OnRemove();
void OnEdit(); void OnEdit();
#ifdef USE_RETRO_ACHIEVEMENTS
HardcoreWarningWidget* m_hc_warning;
#endif // USE_RETRO_ACHIEVEMENTS
QListWidget* m_list; QListWidget* m_list;
QPushButton* m_add_button; QPushButton* m_add_button;
QPushButton* m_edit_button; QPushButton* m_edit_button;

View File

@ -51,6 +51,10 @@ PropertiesDialog::PropertiesDialog(QWidget* parent, const UICommon::GameFile& ga
&PropertiesDialog::OpenGeneralSettings); &PropertiesDialog::OpenGeneralSettings);
connect(ar, &ARCodeWidget::OpenGeneralSettings, this, &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, connect(graphics_mod_list, &GraphicsModListWidget::OpenGraphicsSettings, this,
&PropertiesDialog::OpenGraphicsSettings); &PropertiesDialog::OpenGraphicsSettings);

View File

@ -19,4 +19,7 @@ public:
signals: signals:
void OpenGeneralSettings(); void OpenGeneralSettings();
void OpenGraphicsSettings(); void OpenGraphicsSettings();
#ifdef USE_RETRO_ACHIEVEMENTS
void OpenAchievementSettings();
#endif // USE_RETRO_ACHIEVEMENTS
}; };

View File

@ -552,6 +552,10 @@ void GameList::OpenProperties()
connect(properties, &PropertiesDialog::OpenGeneralSettings, this, &GameList::OpenGeneralSettings); connect(properties, &PropertiesDialog::OpenGeneralSettings, this, &GameList::OpenGeneralSettings);
connect(properties, &PropertiesDialog::OpenGraphicsSettings, this, connect(properties, &PropertiesDialog::OpenGraphicsSettings, this,
&GameList::OpenGraphicsSettings); &GameList::OpenGraphicsSettings);
#ifdef USE_RETRO_ACHIEVEMENTS
connect(properties, &PropertiesDialog::OpenAchievementSettings, this,
&GameList::OpenAchievementSettings);
#endif // USE_RETRO_ACHIEVEMENTS
SetQWidgetWindowDecorations(properties); SetQWidgetWindowDecorations(properties);
properties->show(); properties->show();

View File

@ -56,6 +56,9 @@ signals:
void SelectionChanged(std::shared_ptr<const UICommon::GameFile> game_file); void SelectionChanged(std::shared_ptr<const UICommon::GameFile> game_file);
void OpenGeneralSettings(); void OpenGeneralSettings();
void OpenGraphicsSettings(); void OpenGraphicsSettings();
#ifdef USE_RETRO_ACHIEVEMENTS
void OpenAchievementSettings();
#endif // USE_RETRO_ACHIEVEMENTS
private: private:
void ShowHeaderContextMenu(const QPoint& pos); void ShowHeaderContextMenu(const QPoint& pos);

View File

@ -246,6 +246,11 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters,
connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this, connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this,
&MainWindow::ShowGeneralWindow); &MainWindow::ShowGeneralWindow);
#ifdef USE_RETRO_ACHIEVEMENTS
connect(m_game_list, &GameList::OpenAchievementSettings, this,
&MainWindow::ShowAchievementSettings);
#endif // USE_RETRO_ACHIEVEMENTS
InitCoreCallbacks(); InitCoreCallbacks();
NetPlayInit(); NetPlayInit();

View File

@ -26,6 +26,7 @@
#include "DiscIO/GameModDescriptor.h" #include "DiscIO/GameModDescriptor.h"
#include "DiscIO/RiivolutionParser.h" #include "DiscIO/RiivolutionParser.h"
#include "DiscIO/RiivolutionPatcher.h" #include "DiscIO/RiivolutionPatcher.h"
#include "DolphinQt/Config/HardcoreWarningWidget.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
struct GuiRiivolutionPatchIndex struct GuiRiivolutionPatchIndex
@ -48,6 +49,7 @@ RiivolutionBootWidget::RiivolutionBootWidget(std::string game_id, std::optional<
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
CreateWidgets(); CreateWidgets();
ConnectWidgets();
LoadMatchingXMLs(); LoadMatchingXMLs();
resize(QSize(400, 600)); resize(QSize(400, 600));
@ -57,6 +59,9 @@ RiivolutionBootWidget::~RiivolutionBootWidget() = default;
void RiivolutionBootWidget::CreateWidgets() 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* open_xml_button = new QPushButton(tr("Open Riivolution XML..."));
auto* boot_game_button = new QPushButton(tr("Start")); auto* boot_game_button = new QPushButton(tr("Start"));
boot_game_button->setDefault(true); boot_game_button->setDefault(true);
@ -79,6 +84,9 @@ void RiivolutionBootWidget::CreateWidgets()
button_layout->addWidget(boot_game_button, 0, Qt::AlignRight); button_layout->addWidget(boot_game_button, 0, Qt::AlignRight);
auto* layout = new QVBoxLayout(); auto* layout = new QVBoxLayout();
#ifdef USE_RETRO_ACHIEVEMENTS
layout->addWidget(m_hc_warning);
#endif // USE_RETRO_ACHIEVEMENTS
layout->addWidget(scroll_area); layout->addWidget(scroll_area);
layout->addLayout(button_layout); layout->addLayout(button_layout);
setLayout(layout); setLayout(layout);
@ -88,6 +96,16 @@ void RiivolutionBootWidget::CreateWidgets()
connect(save_preset_button, &QPushButton::clicked, this, &RiivolutionBootWidget::SaveAsPreset); 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() void RiivolutionBootWidget::LoadMatchingXMLs()
{ {
const std::string& riivolution_dir = File::GetUserPath(D_RIIVOLUTION_IDX); const std::string& riivolution_dir = File::GetUserPath(D_RIIVOLUTION_IDX);

View File

@ -11,6 +11,9 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "DiscIO/RiivolutionParser.h" #include "DiscIO/RiivolutionParser.h"
#ifdef USE_RETRO_ACHIEVEMENTS
class HardcoreWarningWidget;
#endif // USE_RETRO_ACHIEVEMENTS
class QPushButton; class QPushButton;
class QVBoxLayout; class QVBoxLayout;
@ -26,8 +29,14 @@ public:
bool ShouldBoot() const { return m_should_boot; } bool ShouldBoot() const { return m_should_boot; }
std::vector<DiscIO::Riivolution::Patch>& GetPatches() { return m_patches; } std::vector<DiscIO::Riivolution::Patch>& GetPatches() { return m_patches; }
#ifdef USE_RETRO_ACHIEVEMENTS
signals:
void OpenAchievementSettings();
#endif // USE_RETRO_ACHIEVEMENTS
private: private:
void CreateWidgets(); void CreateWidgets();
void ConnectWidgets();
void LoadMatchingXMLs(); void LoadMatchingXMLs();
void OpenXML(); void OpenXML();
@ -38,6 +47,9 @@ private:
void BootGame(); void BootGame();
void SaveAsPreset(); void SaveAsPreset();
#ifdef USE_RETRO_ACHIEVEMENTS
HardcoreWarningWidget* m_hc_warning;
#endif // USE_RETRO_ACHIEVEMENTS
std::string m_game_id; std::string m_game_id;
std::optional<u16> m_revision; std::optional<u16> m_revision;
std::optional<u8> m_disc_number; std::optional<u8> m_disc_number;