From e903287f4cc4a3c81215080fce25597e0ca12dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 9 Apr 2024 11:58:35 +0200 Subject: [PATCH] Game info screen: Show list of any plugins that will be loaded on start of the game --- Common/Data/Format/IniFile.h | 7 +++-- Core/HLE/Plugins.cpp | 52 ++++++++++++++++-------------------- Core/HLE/Plugins.h | 16 +++++++++++ UI/GameScreen.cpp | 11 ++++++++ assets/lang/pt_BR.ini | 1 + 5 files changed, 54 insertions(+), 33 deletions(-) diff --git a/Common/Data/Format/IniFile.h b/Common/Data/Format/IniFile.h index 1103721ca9..8fa1e5c750 100644 --- a/Common/Data/Format/IniFile.h +++ b/Common/Data/Format/IniFile.h @@ -180,13 +180,12 @@ public: std::vector> &Sections() { return sections; } - bool HasSection(const char *section) { return GetSection(section) != 0; } + bool HasSection(const char *section) { return GetSection(section) != nullptr; } + const Section* GetSection(const char* section) const; + Section* GetSection(const char* section); Section* GetOrCreateSection(const char* section); private: std::vector> sections; - - const Section* GetSection(const char* section) const; - Section* GetSection(const char* section); }; diff --git a/Core/HLE/Plugins.cpp b/Core/HLE/Plugins.cpp index 91e29fba04..44b1249a74 100644 --- a/Core/HLE/Plugins.cpp +++ b/Core/HLE/Plugins.cpp @@ -41,18 +41,6 @@ std::map PluginDataKeys; static bool anyEnabled = false; static std::vector prxPlugins; -enum class PluginType { - INVALID = 0, - PRX, -}; - -struct PluginInfo { - PluginType type; - std::string filename; - int version; - uint32_t memory; -}; - static PluginInfo ReadPluginIni(const std::string &subdir, IniFile &ini) { PluginInfo info; @@ -66,11 +54,16 @@ static PluginInfo ReadPluginIni(const std::string &subdir, IniFile &ini) { } if (options->Get("filename", &value, "")) { + info.name = value; info.filename = "ms0:/PSP/PLUGINS/" + subdir + "/" + value; } else { info.type = PluginType::INVALID; } + if (options->Get("name", &value, "")) { + info.name = value; + } + options->Get("version", &info.version, 0); options->Get("memory", &info.memory, 0); if (info.memory > 93) { @@ -89,7 +82,7 @@ static PluginInfo ReadPluginIni(const std::string &subdir, IniFile &ini) { return info; } -static std::vector FindPlugins(const std::string &gameID, const std::string &lang) { +std::vector FindPlugins(const std::string &gameID, const std::string &lang) { std::vector pluginDirs; GetFilesInDir(GetSysDirectory(DIRECTORY_PLUGINS), &pluginDirs); @@ -110,23 +103,24 @@ static std::vector FindPlugins(const std::string &gameID, const std: std::string gameIni; // TODO: Should just use getsection and fail the ini if not found, I guess. - Section *games = ini.GetOrCreateSection("games"); - - if (games->Get(gameID.c_str(), &gameIni, "")) { - if (!strcasecmp(gameIni.c_str(), "true")) { - matches.insert("plugin.ini"); - } else if (!strcasecmp(gameIni.c_str(), "false")){ - continue; - } else if (!gameIni.empty()) { - matches.insert(gameIni); + const Section *games = ini.GetSection("games"); + if (games) { + if (games->Get(gameID.c_str(), &gameIni, "")) { + if (!strcasecmp(gameIni.c_str(), "true")) { + matches.insert("plugin.ini"); + } else if (!strcasecmp(gameIni.c_str(), "false")) { + continue; + } else if (!gameIni.empty()) { + matches.insert(gameIni); + } } - } - if (games->Get("ALL", &gameIni, "")) { - if (!strcasecmp(gameIni.c_str(), "true")) { - matches.insert("plugin.ini"); - } else if (!gameIni.empty()) { - matches.insert(gameIni); + if (games->Get("ALL", &gameIni, "")) { + if (!strcasecmp(gameIni.c_str(), "true")) { + matches.insert("plugin.ini"); + } else if (!gameIni.empty()) { + matches.insert(gameIni); + } } } @@ -196,7 +190,7 @@ bool Load() { ERROR_LOG(SYSTEM, "Unable to start plugin %s: %08x", filename.c_str(), ret); } else { std::string shortName = Path(filename).GetFilename(); - g_OSD.Show(OSDType::MESSAGE_SUCCESS, ApplySafeSubstitutions(sy->T("Loaded plugin: %1"), shortName)); + g_OSD.Show(OSDType::MESSAGE_SUCCESS, ApplySafeSubstitutions(sy->T("Loaded plugin: %1"), shortName), 6.0f); started = true; } diff --git a/Core/HLE/Plugins.h b/Core/HLE/Plugins.h index 3b5a2bd029..4c179fcf56 100644 --- a/Core/HLE/Plugins.h +++ b/Core/HLE/Plugins.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include "Input/KeyCodes.h" class PointerWrap; @@ -34,6 +35,21 @@ void DoState(PointerWrap &p); bool HasEnabled(); +enum class PluginType { + INVALID = 0, + PRX, +}; + +struct PluginInfo { + PluginType type; + std::string name; + std::string filename; // PSP-space path. So we can't use a Path object. + int version; + uint32_t memory; +}; + +std::vector FindPlugins(const std::string &gameID, const std::string &lang); + void SetKey(int key, uint8_t value); uint8_t GetKey(int key); diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index dacd879545..88b4667f02 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -37,6 +37,7 @@ #include "Core/System.h" #include "Core/Loaders.h" #include "Core/Util/GameDB.h" +#include "Core/HLE/Plugins.h" #include "UI/OnScreenDisplay.h" #include "UI/CwCheatScreen.h" #include "UI/EmuScreen.h" @@ -150,6 +151,16 @@ void GameScreen::CreateViews() { tvVerified_ = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("Click \"Calculate CRC\" to verify ISO"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); tvVerified_->SetVisibility(UI::V_GONE); tvVerified_->SetSquishy(true); + + // Show plugin info, if any. Later might add checkboxes. + auto plugins = HLEPlugins::FindPlugins(info->id, g_Config.sLanguageIni); + if (!plugins.empty()) { + auto sy = GetI18NCategory(I18NCat::SYSTEM); + infoLayout->Add(new TextView(sy->T("Plugins"), ALIGN_LEFT, true)); + for (const auto &plugin : plugins) { + infoLayout->Add(new TextView(ApplySafeSubstitutions("* %1", plugin.name), ALIGN_LEFT, true)); + } + } } else { tvTitle_ = nullptr; tvID_ = nullptr; diff --git a/assets/lang/pt_BR.ini b/assets/lang/pt_BR.ini index a5e2328105..e6936e4e68 100644 --- a/assets/lang/pt_BR.ini +++ b/assets/lang/pt_BR.ini @@ -1274,6 +1274,7 @@ Change CPU Clock = Mudar o clock da CPU do PSP emulado (instável) CPU Core = Núcleo da CPU Dynarec/JIT (recommended) = Dynarec/JIT (recomendado) JIT using IR = JIT using IR +Plugins = Plugins Loaded plugin: %1 = Plugin carregado: %1 Memory Stick folder = Pasta do cartão de memória Memory Stick size = Tamanho do cartão de memória