core: Persist plg:ldr state across resets without static state. (#7327)

This commit is contained in:
Steveice10 2024-01-08 09:20:14 -08:00 committed by GitHub
parent c8c2beaeff
commit 57696b2c11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 22 deletions

View file

@ -40,10 +40,6 @@ namespace Service::PLGLDR {
static const Kernel::CoreVersion plgldr_version = Kernel::CoreVersion(1, 0, 0);
PLG_LDR::PluginLoaderContext PLG_LDR::plgldr_context;
bool PLG_LDR::allow_game_change = true;
PAddr PLG_LDR::plugin_fb_addr = 0;
PLG_LDR::PLG_LDR(Core::System& system_) : ServiceFramework{"plg:ldr", 1}, system(system_) {
static const FunctionInfo functions[] = {
// clang-format off
@ -70,6 +66,7 @@ PLG_LDR::PLG_LDR(Core::System& system_) : ServiceFramework{"plg:ldr", 1}, system
template <class Archive>
void PLG_LDR::PluginLoaderContext::serialize(Archive& ar, const unsigned int) {
ar& is_enabled;
ar& allow_game_change;
ar& plugin_loaded;
ar& is_default_path;
ar& plugin_path;
@ -82,6 +79,7 @@ void PLG_LDR::PluginLoaderContext::serialize(Archive& ar, const unsigned int) {
ar& exe_load_checksum;
ar& load_exe_func;
ar& load_exe_args;
ar& plugin_fb_addr;
}
SERIALIZE_IMPL(PLG_LDR::PluginLoaderContext)
@ -89,8 +87,6 @@ template <class Archive>
void PLG_LDR::serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
ar& plgldr_context;
ar& plugin_fb_addr;
ar& allow_game_change;
}
SERIALIZE_IMPL(PLG_LDR)
@ -195,7 +191,7 @@ void PLG_LDR::SetEnabled(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
bool enabled = rp.Pop<u32>() == 1;
bool can_change = enabled == plgldr_context.is_enabled || allow_game_change;
bool can_change = enabled == plgldr_context.is_enabled || plgldr_context.allow_game_change;
if (can_change) {
plgldr_context.is_enabled = enabled;
Settings::values.plugin_loader_enabled.SetValue(enabled);

View file

@ -52,6 +52,7 @@ public:
friend class boost::serialization::access;
};
bool is_enabled = true;
bool allow_game_change = true;
bool plugin_loaded = false;
bool is_default_path = false;
std::string plugin_path = "";
@ -69,6 +70,8 @@ public:
std::vector<u32> load_exe_func;
u32_le load_exe_args[4] = {0};
PAddr plugin_fb_addr = 0;
template <class Archive>
void serialize(Archive& ar, const unsigned int);
friend class boost::serialization::access;
@ -82,6 +85,12 @@ public:
ResultVal<Kernel::Handle> GetMemoryChangedHandle(Kernel::KernelSystem& kernel);
void OnMemoryChanged(Kernel::Process& process, Kernel::KernelSystem& kernel);
PluginLoaderContext& GetPluginLoaderContext() {
return plgldr_context;
}
void SetPluginLoaderContext(PluginLoaderContext& context) {
plgldr_context = context;
}
void SetEnabled(bool enabled) {
plgldr_context.is_enabled = enabled;
}
@ -89,24 +98,22 @@ public:
return plgldr_context.is_enabled;
}
void SetAllowGameChangeState(bool allow) {
allow_game_change = allow;
plgldr_context.allow_game_change = allow;
}
bool GetAllowGameChangeState() {
return allow_game_change;
return plgldr_context.allow_game_change;
}
void SetPluginFBAddr(PAddr addr) {
plugin_fb_addr = addr;
plgldr_context.plugin_fb_addr = addr;
}
PAddr GetPluginFBAddr() {
return plugin_fb_addr;
return plgldr_context.plugin_fb_addr;
}
private:
Core::System& system;
static PluginLoaderContext plgldr_context;
static PAddr plugin_fb_addr;
static bool allow_game_change;
PluginLoaderContext plgldr_context;
void IsEnabled(Kernel::HLERequestContext& ctx);
void SetEnabled(Kernel::HLERequestContext& ctx);