Load custom modules stored in custom_modules/<gameid> (#4440)

* Load custom modules stored in custom_modules/<gameid>

* Fix formatting
This commit is contained in:
Connor Harrison
2026-05-17 19:11:21 +01:00
committed by GitHub
parent e9cbc02c01
commit 482d17c6e1
3 changed files with 39 additions and 17 deletions
+1
View File
@@ -131,6 +131,7 @@ static auto UserPaths = [] {
create_path(PathType::CacheDir, user_dir / CACHE_DIR);
create_path(PathType::FontsDir, user_dir / FONTS_DIR);
create_path(PathType::HomeDir, user_dir / HOME_DIR);
create_path(PathType::CustomModulesDir, user_dir / CUSTOM_MODULES_DIR);
std::ofstream notice_file(user_dir / CUSTOM_TROPHY / "Notice.txt");
if (notice_file.is_open()) {
+19 -17
View File
@@ -10,23 +10,24 @@
namespace Common::FS {
enum class PathType {
UserDir, // Where shadPS4 stores its data.
LogDir, // Where log files are stored.
ScreenshotsDir, // Where screenshots are stored.
ShaderDir, // Where shaders are stored.
TempDataDir, // Where game temp data is stored.
GameDataDir, // Where game data is stored.
SysModuleDir, // Where system modules are stored.
DownloadDir, // Where downloads/temp files are stored.
CapturesDir, // Where rdoc captures are stored.
CheatsDir, // Where cheats are stored.
PatchesDir, // Where patches are stored.
MetaDataDir, // Where game metadata (e.g. trophies and menu backgrounds) is stored.
CustomTrophy, // Where custom files for trophies are stored.
CustomConfigs, // Where custom files for different games are stored.
CacheDir, // Where pipeline and shader cache is stored.
FontsDir, // Where dumped system fonts are stored.
HomeDir, // PS4 home directory
UserDir, // Where shadPS4 stores its data.
LogDir, // Where log files are stored.
ScreenshotsDir, // Where screenshots are stored.
ShaderDir, // Where shaders are stored.
TempDataDir, // Where game temp data is stored.
GameDataDir, // Where game data is stored.
SysModuleDir, // Where system modules are stored.
DownloadDir, // Where downloads/temp files are stored.
CapturesDir, // Where rdoc captures are stored.
CheatsDir, // Where cheats are stored.
PatchesDir, // Where patches are stored.
MetaDataDir, // Where game metadata (e.g. trophies and menu backgrounds) is stored.
CustomTrophy, // Where custom files for trophies are stored.
CustomConfigs, // Where custom files for different games are stored.
CacheDir, // Where pipeline and shader cache is stored.
FontsDir, // Where dumped system fonts are stored.
HomeDir, // PS4 home directory
CustomModulesDir // Where custom modules are stored.
};
constexpr auto PORTABLE_DIR = "user";
@@ -48,6 +49,7 @@ constexpr auto CUSTOM_CONFIGS = "custom_configs";
constexpr auto CACHE_DIR = "cache";
constexpr auto FONTS_DIR = "fonts";
constexpr auto HOME_DIR = "home";
constexpr auto CUSTOM_MODULES_DIR = "custom_modules";
// Filenames
constexpr auto LOG_FILE = "shad_log.txt";
+19
View File
@@ -5,6 +5,7 @@
#include "common/arch.h"
#include "common/assert.h"
#include "common/elf_info.h"
#include "common/logging/formatter.h"
#include "common/logging/log.h"
#include "common/path_util.h"
#include "common/string_util.h"
@@ -125,6 +126,24 @@ void Linker::Execute(const std::vector<std::string>& args) {
// Have libSceSysmodule preload our libraries.
Libraries::SysModule::sceSysmodulePreloadModuleForLibkernel();
// Load and start custom modules from the user directory.
std::string_view id = Common::ElfInfo::Instance().GameSerial();
const auto& custom_mod_directory =
Common::FS::GetUserPath(Common::FS::PathType::CustomModulesDir) / id;
if (!std::filesystem::exists(custom_mod_directory)) {
std::filesystem::create_directory(custom_mod_directory);
}
for (const auto& entry : std::filesystem::directory_iterator(custom_mod_directory)) {
if (entry.is_regular_file()) {
LOG_INFO(Core_Linker, "Loading custom module: {}",
fmt::UTF(entry.path().u8string()));
if (LoadAndStartModule(entry.path(), 0, nullptr, nullptr) == -1) {
LOG_ERROR(Core_Linker, "Failed to load custom module: {}",
fmt::UTF(entry.path().u8string()));
}
}
}
// Simulate libSceGnmDriver initialization, which maps a chunk of direct memory.
// Some games fail without accurately emulating this behavior.
s64 phys_addr{};