From d3804de24300e1ded41a65ce7d7fe15aa14fcabb Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 18 Apr 2026 16:09:01 +0200 Subject: [PATCH] Loader: try to retrieve database config if not booted through the UI --- rpcs3/Emu/System.cpp | 17 ++++++++++++----- rpcs3/Emu/System.h | 8 +++++--- rpcs3/main_application.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index e92dc9f8a0..aa1180131a 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -933,7 +933,7 @@ game_boot_result Emulator::GetElfPathFromDir(std::string& elf_path, const std::s return game_boot_result::invalid_file_or_folder; } -game_boot_result Emulator::BootGame(const std::string& path, const std::string& title_id, bool direct, cfg_mode config_mode, const std::string& config_path, const std::string& db_config) +game_boot_result Emulator::BootGame(const std::string& path, const std::string& title_id, bool direct, cfg_mode config_mode, const std::string& config_path, const std::optional& db_config) { if (m_restrict_emu_state_change) { @@ -1565,8 +1565,15 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch, sys_log.notice("Version: APP_VER=%s VERSION=%s", version_app, version_disc); { + if (!m_db_config && (m_config_mode == cfg_mode::database_config || m_config_mode == cfg_mode::custom)) + { + // Get database config if possible. This only happens if the database config hasn't been set by the UI (e.g. if booted with no-gui). + // We only know the title_id for sure at this point, so it doesn't make sense to retrieve it earlier. + m_db_config = Emu.GetCallbacks().get_database_config(m_title_id); + } + // We add the database configuration if it is set, unless we are using a mode that specifically selects a different configuration. - bool add_database_config = !m_db_config.empty() && (m_config_mode == cfg_mode::database_config || m_config_mode == cfg_mode::custom || m_config_mode == cfg_mode::continuous); + bool add_database_config = m_db_config && !m_db_config->empty() && (m_config_mode == cfg_mode::database_config || m_config_mode == cfg_mode::custom || m_config_mode == cfg_mode::continuous); if (m_config_mode == cfg_mode::custom_selection || (m_config_mode == cfg_mode::continuous && !m_config_path.empty())) { @@ -1619,12 +1626,12 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch, } } - if (add_database_config) + if (add_database_config && m_db_config && !m_db_config->empty()) { // Add database config sys_log.notice("Applying database config"); - if (g_cfg.from_string(m_db_config)) + if (g_cfg.from_string(*m_db_config)) { g_cfg.name = "database_config"; } @@ -3373,7 +3380,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_s klic.clear(); hdd1.clear(); init_mem_containers = nullptr; - m_db_config.clear(); + m_db_config = std::nullopt; m_config_path.clear(); m_config_mode = cfg_mode::custom; read_used_savestate_versions(); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 08db927452..f613bb94d6 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -115,6 +115,7 @@ struct EmuCallbacks std::function check_microphone_permissions; std::function()> make_video_source; std::function enable_gamemode; + std::function get_database_config; }; namespace utils @@ -146,7 +147,7 @@ class Emulator final cfg_mode m_config_mode = cfg_mode::custom; std::string m_config_path; - std::string m_db_config; + std::optional m_db_config; // std::nullopt means it has not been retrieved yet std::string m_path; std::string m_path_old; std::string m_path_original; @@ -370,7 +371,8 @@ public: const std::string& GetUsedDatabaseConfig() const { - return m_db_config; + static std::string empty_db_config; + return m_db_config ? *m_db_config : empty_db_config; } bool IsChildProcess() const @@ -422,7 +424,7 @@ public: return emulation_state_guard_t{this}; } - game_boot_result BootGame(const std::string& path, const std::string& title_id = "", bool direct = false, cfg_mode config_mode = cfg_mode::custom, const std::string& config_path = "", const std::string& db_config = ""); + game_boot_result BootGame(const std::string& path, const std::string& title_id = "", bool direct = false, cfg_mode config_mode = cfg_mode::custom, const std::string& config_path = "", const std::optional& db_config = std::nullopt); bool BootRsxCapture(const std::string& path); void SetForceBoot(bool force_boot); diff --git a/rpcs3/main_application.cpp b/rpcs3/main_application.cpp index b5d4401b7e..8c067f3975 100644 --- a/rpcs3/main_application.cpp +++ b/rpcs3/main_application.cpp @@ -2,6 +2,8 @@ #include "main_application.h" #include "display_sleep_control.h" #include "gamemode_control.h" +#include "rpcs3qt/gui_settings.h" +#include "rpcs3qt/config_database.h" #include "util/types.hpp" #include "util/logs.hpp" @@ -409,5 +411,28 @@ EmuCallbacks main_application::CreateCallbacks() return path + suffix; }; + callbacks.get_database_config = [](const std::string& title_id) + { + if (title_id.empty()) + return std::string(); + + sys_log.notice("Trying to retrieve database config for: '%s'", title_id); + + const auto settings = std::make_shared(); + config_database config_db(settings, nullptr); + config_db.request_config_database(false); + + if (!config_db.has_config(title_id)) + return std::string(); + + if (const auto config = config_db.get_config(title_id)) + { + sys_log.notice("Found database config for: '%s'", title_id); + return config.value(); + } + + return std::string(); + }; + return callbacks; }