From 74c0ea8432e8fd8028e321315c299b5daea524dc Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Wed, 1 Oct 2025 21:28:34 +0200 Subject: [PATCH] Add CLI argument to launch the emulator with global config or with default settings (#3688) * --config-clean, --config-global * copyright 2025 * fine you win * copyright 2024 --- src/common/config.cpp | 21 +++++++++++++++++++-- src/common/config.h | 7 +++++++ src/main.cpp | 7 ++++++- src/qt_gui/main.cpp | 8 +++++++- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 7d88c29bb..339990c55 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -8,6 +8,7 @@ #include // for wstring support #include +#include "common/assert.h" #include "common/config.h" #include "common/logging/formatter.h" #include "common/path_util.h" @@ -74,18 +75,34 @@ std::optional get_optional(const toml::value& v, const std::string& key) { namespace Config { +ConfigMode config_mode = ConfigMode::Default; + +void setConfigMode(ConfigMode mode) { + config_mode = mode; +} + template class ConfigEntry { public: + const T default_value; T base_value; optional game_specific_value; - ConfigEntry(const T& t = T()) : base_value(t), game_specific_value(nullopt) {} + ConfigEntry(const T& t = T()) : default_value(t), base_value(t), game_specific_value(nullopt) {} ConfigEntry operator=(const T& t) { base_value = t; return *this; } const T get() const { - return game_specific_value.has_value() ? *game_specific_value : base_value; + switch (config_mode) { + case ConfigMode::Default: + return game_specific_value.value_or(base_value); + case ConfigMode::Global: + return base_value; + case ConfigMode::Clean: + return default_value; + default: + UNREACHABLE(); + } } void setFromToml(const toml::value& v, const std::string& key, bool is_game_specific = false) { if (is_game_specific) { diff --git a/src/common/config.h b/src/common/config.h index 0d41d2c99..aacf4c96a 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -9,6 +9,13 @@ namespace Config { +enum class ConfigMode { + Default, + Global, + Clean, +}; +void setConfigMode(ConfigMode mode); + struct GameInstallDir { std::filesystem::path path; bool enabled; diff --git a/src/main.cpp b/src/main.cpp index 90c694cc8..1b49f41f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,6 +62,10 @@ int main(int argc, char* argv[]) { "parent of game path\n" " --wait-for-debugger Wait for debugger to attach\n" " --wait-for-pid Wait for process with specified PID to stop\n" + " --config-clean Run the emulator with the default config " + "values, ignores the config file(s) entirely.\n" + " --config-global Run the emulator with the base config file " + "only, ignores game specific configs.\n" " -h, --help Display this help message\n"; exit(0); }}, @@ -151,6 +155,8 @@ int main(int argc, char* argv[]) { exit(0); }}, {"--log-append", [&](int& i) { Common::Log::SetAppend(); }}, + {"--config-clean", [&](int& i) { Config::setConfigMode(Config::ConfigMode::Clean); }}, + {"--config-global", [&](int& i) { Config::setConfigMode(Config::ConfigMode::Global); }}, {"--override-root", [&](int& i) { if (++i >= argc) { @@ -249,7 +255,6 @@ int main(int argc, char* argv[]) { // Run the emulator with the resolved eboot path Core::Emulator* emulator = Common::Singleton::Instance(); emulator->executableName = argv[0]; - emulator->waitForDebuggerBeforeRun = waitForDebugger; emulator->Run(eboot_path, game_args, game_folder); return 0; diff --git a/src/qt_gui/main.cpp b/src/qt_gui/main.cpp index c4d1b5129..5412dfb69 100644 --- a/src/qt_gui/main.cpp +++ b/src/qt_gui/main.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "iostream" @@ -68,6 +68,10 @@ int main(int argc, char* argv[]) { "parent of game path\n" " --wait-for-debugger Wait for debugger to attach\n" " --wait-for-pid Wait for process with specified PID to stop\n" + " --config-clean Run the emulator with the default config " + "values, ignores the config file(s) entirely.\n" + " --config-global Run the emulator with the base config file " + "only, ignores game specific configs.\n" " -h, --help Display this help message\n"; exit(0); }}, @@ -142,6 +146,8 @@ int main(int argc, char* argv[]) { exit(0); }}, {"--log-append", [&](int& i) { Common::Log::SetAppend(); }}, + {"--config-clean", [&](int& i) { Config::setConfigMode(Config::ConfigMode::Clean); }}, + {"--config-global", [&](int& i) { Config::setConfigMode(Config::ConfigMode::Global); }}, {"--override-root", [&](int& i) { if (++i >= argc) {