From dbb08050d42ea10d57dc22f9b92e870d703bbc7b Mon Sep 17 00:00:00 2001 From: Robyn Dressler Date: Tue, 8 Oct 2024 20:07:03 -0500 Subject: [PATCH] Allowing Config class to resolve isFullscreen flag from CLI arguments --- src/common/config.cpp | 24 ++++++++++++++++++++++++ src/common/config.h | 3 +++ src/emulator.cpp | 8 ++++++++ src/emulator.h | 1 + src/main.cpp | 11 +---------- src/qt_gui/main.cpp | 10 +--------- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 8ac3c694b..a6ce41bdc 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -41,6 +41,7 @@ static std::string logFilter; static std::string logType = "async"; static std::string userName = "shadPS4"; static std::string updateChannel; +static std::string patchFile = ""; static bool useSpecialPad = false; static int specialPadClass = 1; static bool isDebugDump = false; @@ -123,6 +124,10 @@ std::string getUpdateChannel() { return updateChannel; } +std::string getPatchFile() { + return patchFile; +} + bool getUseSpecialPad() { return useSpecialPad; } @@ -275,6 +280,10 @@ void setUpdateChannel(const std::string& type) { updateChannel = type; } +void setPatchFile(const std::string& fileName) { + patchFile = fileName; +} + void setUseSpecialPad(bool use) { useSpecialPad = use; } @@ -435,6 +444,7 @@ void load(const std::filesystem::path& path) { } isShowSplash = toml::find_or(general, "showSplash", true); isAutoUpdate = toml::find_or(general, "autoUpdate", false); + patchFile = toml::find_or(general, "patchFile", ""); } if (data.contains("Input")) { @@ -502,6 +512,18 @@ void load(const std::filesystem::path& path) { m_language = toml::find_or(settings, "consoleLanguage", 1); } } + +void loadArgs(int& argc, char* argv[]) { + for (int i = 0; i < argc; i++) { + const std::string arg = argv[i]; + if (arg == "-p") { + patchFile = argv[i + 1]; + } else if (arg == "-f") { + isFullscreen = true; + } + } +} + void save(const std::filesystem::path& path) { toml::value data; @@ -533,6 +555,7 @@ void save(const std::filesystem::path& path) { data["General"]["updateChannel"] = updateChannel; data["General"]["showSplash"] = isShowSplash; data["General"]["autoUpdate"] = isAutoUpdate; + data["General"]["patchFile"] = patchFile; data["Input"]["useSpecialPad"] = useSpecialPad; data["Input"]["specialPadClass"] = specialPadClass; data["GPU"]["screenWidth"] = screenWidth; @@ -591,6 +614,7 @@ void setDefaultValues() { } else { updateChannel = "Nightly"; } + patchFile = ""; useSpecialPad = false; specialPadClass = 1; isDebugDump = false; diff --git a/src/common/config.h b/src/common/config.h index daee9e078..96dd7d5f3 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -10,6 +10,7 @@ namespace Config { void load(const std::filesystem::path& path); void save(const std::filesystem::path& path); +void loadArgs(int& argc, char* argv[]); bool isNeoMode(); bool isFullscreenMode(); @@ -20,6 +21,7 @@ std::string getLogFilter(); std::string getLogType(); std::string getUserName(); std::string getUpdateChannel(); +std::string getPatchFile(); bool getUseSpecialPad(); int getSpecialPadClass(); @@ -54,6 +56,7 @@ void setLanguage(u32 language); void setNeoMode(bool enable); void setUserName(const std::string& type); void setUpdateChannel(const std::string& type); +void setPatchFile(const std::string& fileName); void setUseSpecialPad(bool use); void setSpecialPadClass(int type); diff --git a/src/emulator.cpp b/src/emulator.cpp index 721151ccc..cc5cf4c99 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -220,6 +220,14 @@ void Emulator::Run(const std::filesystem::path& file) { std::exit(0); } +void Emulator::Run(int& argc, char* argv[]) { + //Load config options from arguments + Config::loadArgs(argc, argv); + MemoryPatcher::patchFile = Config::getPatchFile(); + + this->Run(argv[1]); +} + void Emulator::LoadSystemModules(const std::filesystem::path& file) { constexpr std::array ModulesToLoad{ {{"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2}, diff --git a/src/emulator.h b/src/emulator.h index 01bce7e7c..9d40abcd3 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -26,6 +26,7 @@ public: ~Emulator(); void Run(const std::filesystem::path& file); + void Run(int& argc, char* argv[]); private: void LoadSystemModules(const std::filesystem::path& file); diff --git a/src/main.cpp b/src/main.cpp index de1d92326..70d2b432e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include "common/memory_patcher.h" #include "emulator.h" #ifdef _WIN32 @@ -24,16 +23,8 @@ int main(int argc, char* argv[]) { return -1; } - for (int i = 0; i < argc; i++) { - std::string curArg = argv[i]; - if (curArg == "-p") { - std::string patchFile = argv[i + 1]; - MemoryPatcher::patchFile = patchFile; - } - } - Core::Emulator emulator; - emulator.Run(argv[1]); + emulator.Run(argc, argv); return 0; } diff --git a/src/qt_gui/main.cpp b/src/qt_gui/main.cpp index 8c565a19b..32b2102aa 100644 --- a/src/qt_gui/main.cpp +++ b/src/qt_gui/main.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/config.h" -#include "common/memory_patcher.h" #include "core/file_sys/fs.h" #include "emulator.h" #include "game_install_dialog.h" @@ -45,14 +44,7 @@ int main(int argc, char* argv[]) { // Check for command line arguments if (has_command_line_argument) { Core::Emulator emulator; - for (int i = 0; i < argc; i++) { - std::string curArg = argv[i]; - if (curArg == "-p") { - std::string patchFile = argv[i + 1]; - MemoryPatcher::patchFile = patchFile; - } - } - emulator.Run(argv[1]); + emulator.Run(argc, argv); } // Run the Qt application