From cdc5223f026696076ed75750b065f2c7fc1f372f Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 27 Sep 2024 07:21:59 +0300 Subject: [PATCH] loading libSceNgs2 from sceSysmoduleLoadModule instead of startup. This will prevent loading modules at startup that games not using . Still some work left but main idea is this for other modules as well --- src/core/libraries/kernel/libkernel.h | 2 ++ src/core/libraries/system/sysmodule.cpp | 8 ++++++++ src/emulator.cpp | 12 +++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/libraries/kernel/libkernel.h b/src/core/libraries/kernel/libkernel.h index 73705cdc2..4ed575951 100644 --- a/src/core/libraries/kernel/libkernel.h +++ b/src/core/libraries/kernel/libkernel.h @@ -36,6 +36,8 @@ int* PS4_SYSV_ABI __Error(); int PS4_SYSV_ABI sceKernelConvertUtcToLocaltime(time_t time, time_t* local_time, struct OrbisTimesec* st, unsigned long* dst_sec); int PS4_SYSV_ABI sceKernelGetCompiledSdkVersion(int* ver); +s32 PS4_SYSV_ABI sceKernelLoadStartModule(const char* moduleFileName, size_t args, const void* argp, + u32 flags, const void* pOpt, int* pRes); void LibKernel_Register(Core::Loader::SymbolsResolver* sym); diff --git a/src/core/libraries/system/sysmodule.cpp b/src/core/libraries/system/sysmodule.cpp index 596efc0af..4e72e8716 100644 --- a/src/core/libraries/system/sysmodule.cpp +++ b/src/core/libraries/system/sysmodule.cpp @@ -9,6 +9,7 @@ #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" #include "core/libraries/system/sysmodule.h" +#include "core/libraries//kernel/libkernel.h" namespace Libraries::SysModule { @@ -45,6 +46,13 @@ int PS4_SYSV_ABI sceSysmoduleIsLoadedInternal() { int PS4_SYSV_ABI sceSysmoduleLoadModule(OrbisSysModule id) { auto color_name = magic_enum::enum_name(id); LOG_ERROR(Lib_SysModule, "(DUMMY) called module = {}", magic_enum::enum_name(id)); + //const auto& sys_module_path = Common::FS::GetUserPath(Common::FS::PathType::SysModuleDir); + switch (id) { + case OrbisSysModule::ORBIS_SYSMODULE_NGS2: + Libraries::Kernel::sceKernelLoadStartModule("/system/common/lib/libSceNgs2.sprx", 0, NULL, 0, + NULL, NULL); + break; + } return ORBIS_OK; } diff --git a/src/emulator.cpp b/src/emulator.cpp index fe10a9b17..0e4b78ed9 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -191,6 +191,9 @@ void Emulator::Run(const std::filesystem::path& file) { } VideoCore::SetOutputDir(mount_captures_dir, id); + const auto& sys_module_path = Common::FS::GetUserPath(Common::FS::PathType::SysModuleDir); + mnt->Mount(sys_module_path, "/system/common/lib"); + // Initialize kernel and library facilities. Libraries::Kernel::init_pthreads(); Libraries::InitHLELibs(&linker->GetHLESymbols()); @@ -222,8 +225,8 @@ void Emulator::Run(const std::filesystem::path& file) { } void Emulator::LoadSystemModules(const std::filesystem::path& file) { - constexpr std::array ModulesToLoad{ - {{"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2}, + constexpr std::array ModulesToLoad{ + {/* {"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2},*/ {"libSceFiber.sprx", nullptr}, {"libSceUlt.sprx", nullptr}, {"libSceJson.sprx", nullptr}, @@ -247,7 +250,10 @@ void Emulator::LoadSystemModules(const std::filesystem::path& file) { found_modules, [&](const auto& path) { return path.filename() == module_name; }); if (it != found_modules.end()) { LOG_INFO(Loader, "Loading {}", it->string()); - linker->LoadModule(*it); + if (!(it->string() == "libSceNgs2.sprx")) { + linker->LoadModule(*it); + } + continue; } if (init_func) {