From 1550565855666dcf092bcf641ed4d7b279c20512 Mon Sep 17 00:00:00 2001 From: Nayla Hanegan Date: Mon, 10 Jun 2024 22:35:41 -0400 Subject: [PATCH] code handler update add switch dialog --- Source/Core/Common/Version.cpp | 2 +- Source/Core/Core/Config/MainSettings.h | 1 + Source/Core/Core/ConfigManager.cpp | 7 ++++ Source/Core/Core/ConfigManager.h | 7 ++++ Source/Core/Core/GeckoCode.cpp | 15 ++++++-- .../Core/DolphinQt/Settings/GeneralPane.cpp | 38 ++++++++++++++++--- Source/Core/DolphinQt/Settings/GeneralPane.h | 4 +- 7 files changed, 63 insertions(+), 11 deletions(-) diff --git a/Source/Core/Common/Version.cpp b/Source/Core/Common/Version.cpp index fa2e728f16..ab34332c12 100644 --- a/Source/Core/Common/Version.cpp +++ b/Source/Core/Common/Version.cpp @@ -31,7 +31,7 @@ const std::string& GetScmDescStr() } const std::string& GetScmRevStr() { - static const std::string scm_rev_str = std::string("Dolphin MPN [") + SCM_DESC_STR + "]"; + static const std::string scm_rev_str = std::string("Dolphin MPN (") + SCM_DESC_STR + ")"; return scm_rev_str; } diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index d7e78bf6e9..9e29dc9d49 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -67,6 +67,7 @@ extern const Info MAIN_CPU_THREAD; extern const Info MAIN_SYNC_ON_SKIP_IDLE; extern const Info MAIN_DEFAULT_ISO; extern const Info MAIN_ENABLE_CHEATS; +extern const Info MAIN_CODE_HANDLER; extern const Info MAIN_GC_LANGUAGE; extern const Info MAIN_OVERRIDE_REGION_SETTINGS; extern const Info MAIN_DPL2_DECODER; diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index c27f135e0e..e9a382d235 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -29,6 +29,7 @@ #include "Common/NandPaths.h" #include "Common/StringUtil.h" #include "Common/Version.h" +#include "Common/Config/Config.h" #include "Core/AchievementManager.h" #include "Core/Boot/Boot.h" @@ -86,6 +87,12 @@ SConfig::~SConfig() SaveSettings(); } +namespace Config +{ + // Initialize the configuration option + const Info MAIN_CODE_HANDLER{{System::Main, "CodeHandler", "UseMPN"}, false}; +} + void SConfig::SaveSettings() { NOTICE_LOG_FMT(BOOT, "Saving settings to {}", File::GetUserPath(F_DOLPHINCONFIG_IDX)); diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 999cc9f86c..f333ee8635 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -13,6 +13,7 @@ #include "Common/Common.h" #include "Common/CommonTypes.h" +#include "Common/Config/Config.h" namespace Common { @@ -34,6 +35,12 @@ struct Partition; class Volume; } // namespace DiscIO +namespace Config +{ + // Define the configuration option + extern const Info MAIN_CODE_HANDLER; +} + namespace IOS::ES { class TMDReader; diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index 046a69cfc3..454308c1ba 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -20,6 +20,8 @@ #include "Core/PowerPC/MMU.h" #include "Core/PowerPC/PowerPC.h" #include "Core/System.h" +#include "ConfigManager.h" +#include "Config/MainSettings.h" namespace Gecko { @@ -116,21 +118,26 @@ std::vector SetAndReturnActiveCodes(std::span gcodes return s_active_codes; } +const char* GetGeckoCodeHandlerPath() +{ + return Config::Get(Config::MAIN_CODE_HANDLER) ? + GECKO_CODE_HANDLER_MPN : GECKO_CODE_HANDLER; +} + // Requires s_active_codes_lock // NOTE: Refer to "codehandleronly.s" from Gecko OS. static Installation InstallCodeHandlerLocked(const Core::CPUThreadGuard& guard) { std::string data; - if (!File::ReadFileToString(File::GetSysDirectory() + GECKO_CODE_HANDLER, data)) + if (!File::ReadFileToString(File::GetSysDirectory() + GetGeckoCodeHandlerPath(), data)) { - ERROR_LOG_FMT(ACTIONREPLAY, - "Could not enable cheats because " GECKO_CODE_HANDLER " was missing."); + ERROR_LOG_FMT(ACTIONREPLAY, "Could not enable cheats because the selected codehandler was missing."); return Installation::Failed; } if (data.size() > INSTALLER_END_ADDRESS - INSTALLER_BASE_ADDRESS - CODE_SIZE) { - ERROR_LOG_FMT(ACTIONREPLAY, GECKO_CODE_HANDLER " is too big. The file may be corrupt."); + ERROR_LOG_FMT(ACTIONREPLAY, "The codehandler is too big. The file may be corrupt."); return Installation::Failed; } diff --git a/Source/Core/DolphinQt/Settings/GeneralPane.cpp b/Source/Core/DolphinQt/Settings/GeneralPane.cpp index e7ab58cc1d..6324bf89e1 100644 --- a/Source/Core/DolphinQt/Settings/GeneralPane.cpp +++ b/Source/Core/DolphinQt/Settings/GeneralPane.cpp @@ -67,15 +67,15 @@ void GeneralPane::CreateLayout() m_main_layout = new QVBoxLayout; // Create layout here CreateBasic(); - CreateFallbackRegion(); #if defined(USE_ANALYTICS) && USE_ANALYTICS CreateAnalytics(); #endif - + CreateCheats(); m_main_layout->addStretch(1); setLayout(m_main_layout); + } void GeneralPane::OnEmulationStateChanged(Core::State state) @@ -100,6 +100,7 @@ void GeneralPane::ConnectLayout() { connect(m_checkbox_dualcore, &QCheckBox::toggled, this, &GeneralPane::OnSaveConfig); connect(m_checkbox_cheats, &QCheckBox::toggled, this, &GeneralPane::OnSaveConfig); + connect(m_combobox_codehandler, QOverload::of(&QComboBox::currentIndexChanged), this, &GeneralPane::OnCodeHandlerChanged); connect(m_checkbox_override_region_settings, &QCheckBox::stateChanged, this, &GeneralPane::OnSaveConfig); connect(m_checkbox_auto_disc_change, &QCheckBox::toggled, this, &GeneralPane::OnSaveConfig); @@ -136,9 +137,6 @@ void GeneralPane::CreateBasic() m_checkbox_dualcore = new QCheckBox(tr("Enable Dual Core (speedup)")); basic_group_layout->addWidget(m_checkbox_dualcore); - m_checkbox_cheats = new QCheckBox(tr("Enable Cheats")); - basic_group_layout->addWidget(m_checkbox_cheats); - m_checkbox_override_region_settings = new QCheckBox(tr("Allow Mismatched Region Settings")); basic_group_layout->addWidget(m_checkbox_override_region_settings); @@ -213,6 +211,28 @@ void GeneralPane::CreateAnalytics() } #endif +void GeneralPane::CreateCheats() +{ + auto* cheats_group = new QGroupBox(tr("Cheats Settings")); + auto* cheats_group_layout = new QVBoxLayout; + cheats_group->setLayout(cheats_group_layout); + m_main_layout->addWidget(cheats_group); + + m_checkbox_cheats = new QCheckBox(tr("Enable Cheats")); + cheats_group_layout->addWidget(m_checkbox_cheats); + + // Add dropdown for code handler selection + auto* code_handler_layout = new QFormLayout(); + auto* code_handler_label = new QLabel(tr("Code Handler:")); + m_combobox_codehandler = new QComboBox(); + m_combobox_codehandler->addItem(tr("Dolphin (Stock)"), QVariant(false)); + m_combobox_codehandler->addItem(tr("MPN (Extended)"), QVariant(true)); + + code_handler_layout->addRow(code_handler_label, m_combobox_codehandler); + + cheats_group_layout->addLayout(code_handler_layout); +} + void GeneralPane::LoadConfig() { const QSignalBlocker blocker(this); @@ -225,6 +245,7 @@ void GeneralPane::LoadConfig() #endif SignalBlocking(m_checkbox_dualcore)->setChecked(Config::Get(Config::MAIN_CPU_THREAD)); SignalBlocking(m_checkbox_cheats)->setChecked(Settings::Instance().GetCheatsEnabled()); + SignalBlocking(m_combobox_codehandler)->setCurrentIndex(Config::Get(Config::MAIN_CODE_HANDLER) ? 1 : 0); SignalBlocking(m_checkbox_override_region_settings) ->setChecked(Config::Get(Config::MAIN_OVERRIDE_REGION_SETTINGS)); SignalBlocking(m_checkbox_auto_disc_change) @@ -340,3 +361,10 @@ void GeneralPane::GenerateNewIdentity() message_box.exec(); } #endif + +void GeneralPane::OnCodeHandlerChanged(int index) +{ + bool use_mpn = m_combobox_codehandler->itemData(index).toBool(); + Config::SetBaseOrCurrent(Config::MAIN_CODE_HANDLER, use_mpn); // Ensure correct usage + Config::Save(); +} diff --git a/Source/Core/DolphinQt/Settings/GeneralPane.h b/Source/Core/DolphinQt/Settings/GeneralPane.h index 0ee62ecf8c..9b527a38c8 100644 --- a/Source/Core/DolphinQt/Settings/GeneralPane.h +++ b/Source/Core/DolphinQt/Settings/GeneralPane.h @@ -30,10 +30,11 @@ private: void CreateBasic(); //void CreateAutoUpdate(); void CreateFallbackRegion(); - void LoadConfig(); void OnSaveConfig(); void OnEmulationStateChanged(Core::State state); + void CreateCheats(); + void OnCodeHandlerChanged(int index); // Widgets QVBoxLayout* m_main_layout; @@ -44,6 +45,7 @@ private: QCheckBox* m_checkbox_cheats; QCheckBox* m_checkbox_override_region_settings; QCheckBox* m_checkbox_auto_disc_change; + QComboBox* m_combobox_codehandler; #ifdef USE_DISCORD_PRESENCE QCheckBox* m_checkbox_discord_presence; #endif