From 84a39e2fb0de762035ccc7881c90977505fa1796 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 26 Jun 2024 14:43:01 +0300 Subject: [PATCH] load existing lle modules from sys_module folder --- src/core/libraries/libs.cpp | 3 --- src/emulator.cpp | 37 +++++++++++++++++++++++++++++++++---- src/emulator.h | 7 +++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/core/libraries/libs.cpp b/src/core/libraries/libs.cpp index f163a9d8..46ada931 100644 --- a/src/core/libraries/libs.cpp +++ b/src/core/libraries/libs.cpp @@ -63,10 +63,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) { Libraries::NpScore::RegisterlibSceNpScore(sym); Libraries::NpTrophy::RegisterlibSceNpTrophy(sym); Libraries::ScreenShot::RegisterlibSceScreenShot(sym); - Libraries::LibcInternal::RegisterlibSceLibcInternal(sym); Libraries::AppContent::RegisterlibSceAppContent(sym); - Libraries::Rtc::RegisterlibSceRtc(sym); - Libraries::DiscMap::RegisterlibSceDiscMap(sym); Libraries::PngDec::RegisterlibScePngDec(sym); Libraries::PlayGo::RegisterlibScePlayGo(sym); Libraries::Usbd::RegisterlibSceUsbd(sym); diff --git a/src/emulator.cpp b/src/emulator.cpp index 2da7513b..77ba91f0 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -4,7 +4,10 @@ #include #include #include +#include #include +#include +#include #include #include #include "common/config.h" @@ -136,12 +139,38 @@ void Emulator::Run(const std::filesystem::path& file) { } void Emulator::LoadSystemModules(const std::filesystem::path& file) { + + constexpr std::array ModulesToLoad{ + {{"libSceNgs2.sprx", nullptr}, + {"libSceLibcInternal.sprx", &Libraries::LibcInternal::RegisterlibSceLibcInternal}, + {"libSceDiscMap.sprx", &Libraries::DiscMap::RegisterlibSceDiscMap}, + {"libSceRtc.sprx", &Libraries::Rtc::RegisterlibSceRtc}}}; + + std::vector found_modules; const auto& sys_module_path = Common::FS::GetUserPath(Common::FS::PathType::SysModuleDir); for (const auto& entry : std::filesystem::directory_iterator(sys_module_path)) { - if (entry.path().filename() == "libSceNgs2.sprx" || - entry.path().filename() == "libSceLibcInternal.sprx") { - LOG_INFO(Loader, "Loading {}", entry.path().string().c_str()); - linker->LoadModule(entry.path()); + found_modules.push_back(entry.path()); + } + for (auto it : ModulesToLoad) { + bool found = false; + std::filesystem::path foundpath; + for (auto f : found_modules) { + if (f.filename().string() == it.module_name) { + found = true; + foundpath = f; + break; + } + } + if (found) { + LOG_INFO(Loader, "Loading {}", foundpath.string().c_str()); + linker->LoadModule(foundpath); + } else { + if (it.callback != nullptr) { + LOG_INFO(Loader, "Can't Load {} switching to HLE", it.module_name); + it.callback(&linker->GetHLESymbols()); + } else { + LOG_INFO(Loader, "No HLE available for {} module", it.module_name); + } } } } diff --git a/src/emulator.h b/src/emulator.h index 36faaad3..3267b8fd 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -13,6 +13,13 @@ namespace Core { +using HLEInitDef = void (*)(Core::Loader::SymbolsResolver* sym); + +struct SysModules { + std::string_view module_name; + HLEInitDef callback; +}; + class Emulator { public: Emulator();