diff --git a/src/common/config.cpp b/src/common/config.cpp index 9da9b4ae6..abc65e38d 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -133,10 +133,8 @@ static ConfigEntry volumeSlider(100); static ConfigEntry logFilter(""); static ConfigEntry logType("sync"); static ConfigEntry userName("shadPS4"); -static ConfigEntry isShowSplash(false); static ConfigEntry isConnectedToNetwork(false); static bool enableDiscordRPC = false; -static std::filesystem::path sys_modules_path = {}; // Input static ConfigEntry cursorState(HideCursorState::Idle); @@ -194,7 +192,6 @@ static ConfigEntry logEnabled(true); // GUI static std::vector settings_install_dirs = {}; std::vector install_dirs_enabled = {}; -std::filesystem::path settings_addon_install_dir = {}; std::filesystem::path save_data_path = {}; // Settings @@ -223,17 +220,6 @@ void setGameRunning(bool running) { isGameRunning = running; } -std::filesystem::path getSysModulesPath() { - if (sys_modules_path.empty()) { - return Common::FS::GetUserPath(Common::FS::PathType::SysModuleDir); - } - return sys_modules_path; -} - -void setSysModulesPath(const std::filesystem::path& path) { - sys_modules_path = path; -} - int getVolumeSlider() { return volumeSlider.get(); } @@ -378,10 +364,6 @@ bool collectShadersForDebug() { return isShaderDebug.get(); } -bool showSplash() { - return isShowSplash.get(); -} - bool nullGpu() { return isNullGpu.get(); } @@ -509,10 +491,6 @@ void setCollectShaderForDebug(bool enable, bool is_game_specific) { isShaderDebug.set(enable, is_game_specific); } -void setShowSplash(bool enable, bool is_game_specific) { - isShowSplash.set(enable, is_game_specific); -} - void setNullGpu(bool enable, bool is_game_specific) { isNullGpu.set(enable, is_game_specific); } @@ -577,7 +555,6 @@ void setPresentMode(std::string mode, bool is_game_specific) { presentMode.set(mode, is_game_specific); } - void setEnableDiscordRPC(bool enable) { enableDiscordRPC = enable; } @@ -630,79 +607,10 @@ void setIsMotionControlsEnabled(bool use, bool is_game_specific) { isMotionControlsEnabled.set(use, is_game_specific); } -bool addGameInstallDir(const std::filesystem::path& dir, bool enabled) { - for (const auto& install_dir : settings_install_dirs) { - if (install_dir.path == dir) { - return false; - } - } - settings_install_dirs.push_back({dir, enabled}); - return true; -} - -void removeGameInstallDir(const std::filesystem::path& dir) { - auto iterator = - std::find_if(settings_install_dirs.begin(), settings_install_dirs.end(), - [&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; }); - if (iterator != settings_install_dirs.end()) { - settings_install_dirs.erase(iterator); - } -} - -void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled) { - auto iterator = - std::find_if(settings_install_dirs.begin(), settings_install_dirs.end(), - [&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; }); - if (iterator != settings_install_dirs.end()) { - iterator->enabled = enabled; - } -} - -void setAddonInstallDir(const std::filesystem::path& dir) { - settings_addon_install_dir = dir; -} - -void setGameInstallDirs(const std::vector& dirs_config) { - settings_install_dirs.clear(); - for (const auto& dir : dirs_config) { - settings_install_dirs.push_back({dir, true}); - } -} - -void setAllGameInstallDirs(const std::vector& dirs_config) { - settings_install_dirs = dirs_config; -} - void setSaveDataPath(const std::filesystem::path& path) { save_data_path = path; } -const std::vector getGameInstallDirs() { - std::vector enabled_dirs; - for (const auto& dir : settings_install_dirs) { - if (dir.enabled) { - enabled_dirs.push_back(dir.path); - } - } - return enabled_dirs; -} - -const std::vector getGameInstallDirsEnabled() { - std::vector enabled_dirs; - for (const auto& dir : settings_install_dirs) { - enabled_dirs.push_back(dir.enabled); - } - return enabled_dirs; -} - -std::filesystem::path getAddonInstallDir() { - if (settings_addon_install_dir.empty()) { - // Default for users without a config file or a config file from before this option existed - return Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "addcont"; - } - return settings_addon_install_dir; -} - u32 GetLanguage() { return m_language.get(); } @@ -792,12 +700,8 @@ void load(const std::filesystem::path& path, bool is_game_specific) { logFilter.setFromToml(general, "logFilter", is_game_specific); logType.setFromToml(general, "logType", is_game_specific); userName.setFromToml(general, "userName", is_game_specific); - isShowSplash.setFromToml(general, "showSplash", is_game_specific); - - isConnectedToNetwork.setFromToml(general, "isConnectedToNetwork", is_game_specific); defaultControllerID.setFromToml(general, "defaultControllerID", is_game_specific); - sys_modules_path = toml::find_fs_path_or(general, "sysModulesPath", sys_modules_path); } if (data.contains("Input")) { @@ -894,9 +798,6 @@ void load(const std::filesystem::path& path, bool is_game_specific) { } save_data_path = toml::find_fs_path_or(gui, "saveDataPath", save_data_path); - - settings_addon_install_dir = - toml::find_fs_path_or(gui, "addonInstallDir", settings_addon_install_dir); } if (data.contains("Settings")) { @@ -972,7 +873,6 @@ void save(const std::filesystem::path& path, bool is_game_specific) { logFilter.setTomlValue(data, "General", "logFilter", is_game_specific); logType.setTomlValue(data, "General", "logType", is_game_specific); userName.setTomlValue(data, "General", "userName", is_game_specific); - isShowSplash.setTomlValue(data, "General", "showSplash", is_game_specific); isConnectedToNetwork.setTomlValue(data, "General", "isConnectedToNetwork", is_game_specific); cursorState.setTomlValue(data, "Input", "cursorState", is_game_specific); @@ -1052,12 +952,9 @@ void save(const std::filesystem::path& path, bool is_game_specific) { // Non game-specific entries data["General"]["enableDiscordRPC"] = enableDiscordRPC; - data["General"]["sysModulesPath"] = string{fmt::UTF(sys_modules_path.u8string()).data}; data["GUI"]["installDirs"] = install_dirs; data["GUI"]["installDirsEnabled"] = install_dirs_enabled; data["GUI"]["saveDataPath"] = string{fmt::UTF(save_data_path.u8string()).data}; - data["GUI"]["addonInstallDir"] = - string{fmt::UTF(settings_addon_install_dir.u8string()).data}; data["Debug"]["ConfigVersion"] = config_version; data["Keys"]["TrophyKey"] = trophyKey; @@ -1097,8 +994,6 @@ void setDefaultValues(bool is_game_specific) { logFilter.set("", is_game_specific); logType.set("sync", is_game_specific); userName.set("shadPS4", is_game_specific); - isShowSplash.set(false, is_game_specific); - // GS - Input cursorState.set(HideCursorState::Idle, is_game_specific); diff --git a/src/common/config.h b/src/common/config.h index 6ce56056a..f25a7831f 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -55,8 +55,6 @@ bool allowHDR(); void setAllowHDR(bool enable, bool is_game_specific = false); bool collectShadersForDebug(); void setCollectShaderForDebug(bool enable, bool is_game_specific = false); -bool showSplash(); -void setShowSplash(bool enable, bool is_game_specific = false); bool nullGpu(); void setNullGpu(bool enable, bool is_game_specific = false); bool copyGPUCmdBuffers(); @@ -128,8 +126,6 @@ void setRcasAttenuation(int value, bool is_game_specific = false); bool getIsConnectedToNetwork(); void setConnectedToNetwork(bool enable, bool is_game_specific = false); void setUserName(const std::string& name, bool is_game_specific = false); -std::filesystem::path getSysModulesPath(); -void setSysModulesPath(const std::filesystem::path& path); bool getLoadAutoPatches(); void setLoadAutoPatches(bool enable); @@ -146,18 +142,7 @@ bool GetOverrideControllerColor(); void SetOverrideControllerColor(bool enable); int* GetControllerCustomColor(); void SetControllerCustomColor(int r, int b, int g); -void setGameInstallDirs(const std::vector& dirs_config); -void setAllGameInstallDirs(const std::vector& dirs_config); void setSaveDataPath(const std::filesystem::path& path); -// Gui -bool addGameInstallDir(const std::filesystem::path& dir, bool enabled = true); -void removeGameInstallDir(const std::filesystem::path& dir); -void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled); -void setAddonInstallDir(const std::filesystem::path& dir); - -const std::vector getGameInstallDirs(); -const std::vector getGameInstallDirsEnabled(); -std::filesystem::path getAddonInstallDir(); void setDefaultValues(bool is_game_specific = false); diff --git a/src/core/address_space.cpp b/src/core/address_space.cpp index 177764c2e..d3a0d132a 100644 --- a/src/core/address_space.cpp +++ b/src/core/address_space.cpp @@ -506,7 +506,7 @@ enum PosixPageProtection { struct AddressSpace::Impl { Impl() { - BackingSize += Config::getExtraDmemInMbytes() * 1_MB; + BackingSize += EmulatorSettings::GetInstance()->GetExtraDmemInMBytes() * 1_MB; // Allocate virtual address placeholder for our address space. system_managed_size = SystemManagedSize; system_reserved_size = SystemReservedSize; diff --git a/src/core/devtools/widget/module_list.h b/src/core/devtools/widget/module_list.h index 0702ac4db..911618a48 100644 --- a/src/core/devtools/widget/module_list.h +++ b/src/core/devtools/widget/module_list.h @@ -11,6 +11,7 @@ #include "common/config.h" #include "common/elf_info.h" #include "common/path_util.h" +#include "core/emulator_settings.h" namespace Core::Devtools::Widget { @@ -23,7 +24,7 @@ public: bool open = false; static bool IsSystemModule(const std::filesystem::path& path) { - const auto sys_modules_path = Config::getSysModulesPath(); + const auto sys_modules_path = EmulatorSettings::GetInstance()->GetSysModulesDir(); const auto abs_path = std::filesystem::absolute(path).lexically_normal(); const auto abs_sys_path = std::filesystem::absolute(sys_modules_path).lexically_normal(); diff --git a/src/core/emulator_settings.cpp b/src/core/emulator_settings.cpp index 3734eeff6..55009140b 100644 --- a/src/core/emulator_settings.cpp +++ b/src/core/emulator_settings.cpp @@ -82,6 +82,39 @@ void EmulatorSettings::SetAllGameInstallDirs(const std::vector& m_general.install_dirs.value = dirs; } +void EmulatorSettings::RemoveGameInstallDir(const std::filesystem::path& dir) { + auto iterator = + std::find_if(m_general.install_dirs.value.begin(), m_general.install_dirs.value.end(), + [&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; }); + if (iterator != m_general.install_dirs.value.end()) { + m_general.install_dirs.value.erase(iterator); + } +} + +void EmulatorSettings::SetGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled) { + auto iterator = + std::find_if(m_general.install_dirs.value.begin(), m_general.install_dirs.value.end(), + [&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; }); + if (iterator != m_general.install_dirs.value.end()) { + iterator->enabled = enabled; + } +} + +void EmulatorSettings::SetGameInstallDirs(const std::vector& dirs_config) { + m_general.install_dirs.value.clear(); + for (const auto& dir : dirs_config) { + m_general.install_dirs.value.push_back({dir, true}); + } +} + +const std::vector EmulatorSettings::GetGameInstallDirsEnabled() { + std::vector enabled_dirs; + for (const auto& dir : m_general.install_dirs.value) { + enabled_dirs.push_back(dir.enabled); + } + return enabled_dirs; +} + std::filesystem::path EmulatorSettings::GetHomeDir() { if (m_general.home_dir.value.empty()) { return Common::FS::GetUserPath(Common::FS::PathType::HomeDir); diff --git a/src/core/emulator_settings.h b/src/core/emulator_settings.h index 2092909df..f950b5e82 100644 --- a/src/core/emulator_settings.h +++ b/src/core/emulator_settings.h @@ -264,6 +264,11 @@ public: bool AddGameInstallDir(const std::filesystem::path& dir, bool enabled = true); std::vector GetGameInstallDirs() const; void SetAllGameInstallDirs(const std::vector& dirs); + void RemoveGameInstallDir(const std::filesystem::path& dir); + void SetGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled); + void SetGameInstallDirs(const std::vector& dirs_config); + const std::vector GetGameInstallDirsEnabled(); + std::filesystem::path GetHomeDir(); void SetHomeDir(const std::filesystem::path& dir); std::filesystem::path GetSysModulesDir(); @@ -325,7 +330,8 @@ public: SETTING_FORWARD_BOOL(m_general, PSNSignedIn, psn_signed_in) SETTING_FORWARD_BOOL(m_general, TrophyPopupDisabled, trophy_popup_disabled) SETTING_FORWARD(m_general, TrophyNotificationDuration, trophy_notification_duration) - SETTING_FORWARD(m_general, GetTrophyNotificationSide, trophy_notification_side) + SETTING_FORWARD(m_general, TrophyNotificationSide, trophy_notification_side) + SETTING_FORWARD_BOOL(m_general, ShowSplash, show_splash) SETTING_FORWARD(m_general, AddonInstallDir, addon_install_dir) // Debug settings diff --git a/src/core/libraries/app_content/app_content.cpp b/src/core/libraries/app_content/app_content.cpp index 1523c2703..0d7ee2d92 100644 --- a/src/core/libraries/app_content/app_content.cpp +++ b/src/core/libraries/app_content/app_content.cpp @@ -13,6 +13,7 @@ #include "core/libraries/app_content/app_content_error.h" #include "core/libraries/libs.h" #include "core/libraries/system/systemservice.h" +#include "core/emulator_settings.h" namespace Libraries::AppContent { @@ -57,7 +58,7 @@ int PS4_SYSV_ABI sceAppContentAddcontMount(u32 service_label, OrbisAppContentMountPoint* mount_point) { LOG_INFO(Lib_AppContent, "called"); - const auto& addon_path = Config::getAddonInstallDir() / title_id; + const auto& addon_path = EmulatorSettings::GetInstance()->GetAddonInstallDir() / title_id; auto* mnt = Common::Singleton::Instance(); // Determine which loaded additional content this entitlement label is for. @@ -282,7 +283,7 @@ int PS4_SYSV_ABI sceAppContentInitialize(const OrbisAppContentInitParam* initPar LOG_ERROR(Lib_AppContent, "(DUMMY) called"); auto* param_sfo = Common::Singleton::Instance(); - const auto addons_dir = Config::getAddonInstallDir(); + const auto addons_dir = EmulatorSettings::GetInstance()->GetAddonInstallDir(); if (const auto value = param_sfo->GetString("TITLE_ID"); value.has_value()) { title_id = *value; } else { diff --git a/src/core/libraries/system/systemservice.cpp b/src/core/libraries/system/systemservice.cpp index c02c4b3c3..f02269ff4 100644 --- a/src/core/libraries/system/systemservice.cpp +++ b/src/core/libraries/system/systemservice.cpp @@ -4,6 +4,7 @@ #include "common/config.h" #include "common/logging/log.h" #include "common/singleton.h" +#include "core/emulator_settings.h" #include "core/file_sys/fs.h" #include "core/libraries/libs.h" #include "core/libraries/system/systemservice.h" @@ -17,7 +18,7 @@ std::queue g_event_queue; std::mutex g_event_queue_mutex; bool IsSplashVisible() { - return Config::showSplash() && g_splash_status; + return EmulatorSettings::GetInstance()->IsShowSplash() && g_splash_status; } int PS4_SYSV_ABI sceAppMessagingClearEventFlag() { diff --git a/src/emulator.cpp b/src/emulator.cpp index c81f23303..81284a1db 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -508,7 +508,7 @@ void Emulator::LoadSystemModules(const std::string& game_serial) { {"libSceFreeTypeOt.sprx", nullptr}}); std::vector found_modules; - const auto& sys_module_path = Config::getSysModulesPath(); + const auto& sys_module_path = EmulatorSettings::GetInstance()->GetSysModulesDir(); for (const auto& entry : std::filesystem::directory_iterator(sys_module_path)) { found_modules.push_back(entry.path()); } diff --git a/src/main.cpp b/src/main.cpp index be4e9fee8..cdc2687d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) { exit(1); } - Config::addGameInstallDir(config_path); + EmulatorSettings::GetInstance()->AddGameInstallDir(config_path); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); std::cout << "Game folder successfully saved.\n"; exit(0); @@ -153,8 +153,8 @@ int main(int argc, char* argv[]) { exit(1); } - Config::setAddonInstallDir(config_path); - Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); + EmulatorSettings::GetInstance()->SetAddonInstallDir(config_path); + EmulatorSettings::GetInstance()->Save(); std::cout << "Addon folder successfully saved.\n"; exit(0); }}, @@ -220,7 +220,7 @@ int main(int argc, char* argv[]) { } // If no game directory is set and no command line argument, prompt for it - if (Config::getGameInstallDirs().empty()) { + if (EmulatorSettings::GetInstance()->GetGameInstallDirs().empty()) { std::cerr << "Warning: No game folder set, please set it by calling shadps4" " with the --add-game-folder argument\n"; } @@ -238,7 +238,7 @@ int main(int argc, char* argv[]) { // If not a file, treat it as a game ID and search in install directories recursively bool game_found = false; const int max_depth = 5; - for (const auto& install_dir : Config::getGameInstallDirs()) { + for (const auto& install_dir : EmulatorSettings::GetInstance()->GetGameInstallDirs()) { if (auto found_path = Common::FS::FindGameByID(install_dir, game_path, max_depth)) { eboot_path = *found_path; game_found = true;