From 9d53136f20f48db9577a0e9c532429ed587b09c0 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Thu, 11 Oct 2018 11:12:07 +0200 Subject: [PATCH 1/3] remove GetCurrentModule() functions in HLE Services --- .../configuration/configure_system.cpp | 8 ++++- src/core/frontend/applets/swkbd.cpp | 9 ++++- src/core/hle/service/apt/applet_manager.cpp | 29 ++++++++++----- src/core/hle/service/apt/apt.cpp | 10 +++++- src/core/hle/service/cam/cam.cpp | 12 +++---- src/core/hle/service/cam/cam.h | 5 ++- src/core/hle/service/cfg/cfg.cpp | 13 +++---- src/core/hle/service/cfg/cfg.h | 5 ++- src/core/hle/service/hid/hid.cpp | 12 +++---- src/core/hle/service/hid/hid.h | 5 ++- src/core/hle/service/ir/ir.cpp | 13 ------- src/core/hle/service/ir/ir.h | 3 -- src/core/loader/ncch.cpp | 8 ++++- src/core/settings.cpp | 36 +++++++++++++++---- 14 files changed, 99 insertions(+), 69 deletions(-) diff --git a/src/citra_qt/configuration/configure_system.cpp b/src/citra_qt/configuration/configure_system.cpp index 5597e0a6b..aa2fac4d8 100644 --- a/src/citra_qt/configuration/configure_system.cpp +++ b/src/citra_qt/configuration/configure_system.cpp @@ -246,7 +246,13 @@ void ConfigureSystem::setConfiguration() { ui->edit_init_time->setDateTime(date_time); if (!enabled) { - cfg = Service::CFG::GetCurrentModule(); + + auto cfg_interface = Core::System::GetInstance() + .ServiceManager() + .GetService("cfg:u"); + ASSERT_MSG(cfg_interface, "cfg:u not started!"); + cfg = cfg_interface->GetModule(); + ASSERT_MSG(cfg, "CFG Module missing!"); ReadSystemSettings(); ui->group_system_settings->setEnabled(false); } else { diff --git a/src/core/frontend/applets/swkbd.cpp b/src/core/frontend/applets/swkbd.cpp index 5c64defe8..f61693ebb 100644 --- a/src/core/frontend/applets/swkbd.cpp +++ b/src/core/frontend/applets/swkbd.cpp @@ -135,7 +135,14 @@ ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) { void DefaultKeyboard::Setup(const Frontend::KeyboardConfig* config) { SoftwareKeyboard::Setup(config); - std::string username = Common::UTF16ToUTF8(Service::CFG::GetCurrentModule()->GetUsername()); + + auto cfg = + Core::System::GetInstance().ServiceManager().GetService( + "cfg:u"); + ASSERT_MSG(cfg, "cfg:u not started!"); + auto cfg_module = cfg->GetModule(); + ASSERT_MSG(cfg_module, "CFG Module missing!"); + std::string username = Common::UTF16ToUTF8(cfg_module->GetUsername()); switch (this->config.button_config) { case ButtonConfig::None: case ButtonConfig::Single: diff --git a/src/core/hle/service/apt/applet_manager.cpp b/src/core/hle/service/apt/applet_manager.cpp index c4f622669..4bb93f9a7 100644 --- a/src/core/hle/service/apt/applet_manager.cpp +++ b/src/core/hle/service/apt/applet_manager.cpp @@ -69,7 +69,7 @@ static constexpr std::array applet_titleids = {{ // TODO(Subv): Fill in the rest of the titleids }}; -static u64 GetTitleIdForApplet(AppletId id) { +static u64 GetTitleIdForApplet(AppletId id, u32 region_value) { ASSERT_MSG(id != AppletId::None, "Invalid applet id"); auto itr = std::find_if(applet_titleids.begin(), applet_titleids.end(), @@ -79,7 +79,7 @@ static u64 GetTitleIdForApplet(AppletId id) { ASSERT_MSG(itr != applet_titleids.end(), "Unknown applet id 0x{:#05X}", static_cast(id)); - return itr->title_ids[CFG::GetCurrentModule()->GetRegionValue()]; + return itr->title_ids[region_value]; } AppletManager::AppletSlotData* AppletManager::GetAppletSlotData(AppletId id) { @@ -327,8 +327,8 @@ ResultCode AppletManager::PrepareToStartLibraryApplet(AppletId applet_id) { // There are some problems with LLE applets. The rasterizer cache gets out of sync // when the applet is closed. To avoid breaking applications because of the issue, // we are going to disable loading LLE applets before further fixes are done. - // auto process = NS::LaunchTitle(FS::MediaType::NAND, GetTitleIdForApplet(applet_id)); - // if (process) { + // auto process = NS::LaunchTitle(FS::MediaType::NAND, GetTitleIdForApplet(applet_id, + // region_value)); if (process) { // return RESULT_SUCCESS; // } @@ -354,8 +354,8 @@ ResultCode AppletManager::PreloadLibraryApplet(AppletId applet_id) { // There are some problems with LLE applets. The rasterizer cache gets out of sync // when the applet is closed. To avoid breaking applications because of the issue, // we are going to disable loading LLE applets before further fixes are done. - // auto process = NS::LaunchTitle(FS::MediaType::NAND, GetTitleIdForApplet(applet_id)); - // if (process) { + // auto process = NS::LaunchTitle(FS::MediaType::NAND, GetTitleIdForApplet(applet_id, + // region_value)); if (process) { // return RESULT_SUCCESS; // } @@ -465,8 +465,14 @@ ResultVal AppletManager::GetAppletInfo(AppletId app_i ErrorLevel::Status); } - return MakeResult({GetTitleIdForApplet(app_id), Service::FS::MediaType::NAND, - slot->registered, slot->loaded, slot->attributes.raw}); + auto cfg = system.ServiceManager().GetService("cfg:u"); + ASSERT_MSG(cfg, "cfg:u not started!"); + auto cfg_module = cfg->GetModule(); + ASSERT_MSG(cfg_module, "CFG Module missing!"); + u32 region_value = cfg_module->GetRegionValue(); + return MakeResult({GetTitleIdForApplet(app_id, region_value), + Service::FS::MediaType::NAND, slot->registered, slot->loaded, + slot->attributes.raw}); } ResultCode AppletManager::PrepareToDoApplicationJump(u64 title_id, FS::MediaType media_type, @@ -548,7 +554,12 @@ void AppletManager::EnsureHomeMenuLoaded() { return; } - u64 menu_title_id = GetTitleIdForApplet(AppletId::HomeMenu); + auto cfg = system.ServiceManager().GetService("cfg:u"); + ASSERT_MSG(cfg, "cfg:u not started!"); + auto cfg_module = cfg->GetModule(); + ASSERT_MSG(cfg_module, "CFG Module missing!"); + u32 region_value = cfg_module->GetRegionValue(); + u64 menu_title_id = GetTitleIdForApplet(AppletId::HomeMenu, region_value); auto process = NS::LaunchTitle(FS::MediaType::NAND, menu_title_id); if (!process) { LOG_WARNING(Service_APT, diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index bd0621fc4..03d6c5e4e 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -5,6 +5,7 @@ #include "common/common_paths.h" #include "common/file_util.h" #include "common/logging/log.h" +#include "common/string_util.h" #include "core/core.h" #include "core/file_sys/archive_ncch.h" #include "core/file_sys/file_backend.h" @@ -103,7 +104,14 @@ static u32 DecompressLZ11(const u8* in, u8* out) { bool Module::LoadSharedFont() { u8 font_region_code; - switch (CFG::GetCurrentModule()->GetRegionValue()) { + auto cfg = + Core::System::GetInstance().ServiceManager().GetService( + "cfg:u"); + ASSERT_MSG(cfg, "cfg:u not started!"); + auto cfg_module = cfg->GetModule(); + ASSERT_MSG(cfg_module, "CFG Module missing!"); + std::string username = Common::UTF16ToUTF8(cfg_module->GetUsername()); + switch (cfg_module->GetRegionValue()) { case 4: // CHN font_region_code = 2; break; diff --git a/src/core/hle/service/cam/cam.cpp b/src/core/hle/service/cam/cam.cpp index af027bd85..d6399194a 100644 --- a/src/core/hle/service/cam/cam.cpp +++ b/src/core/hle/service/cam/cam.cpp @@ -22,8 +22,6 @@ namespace Service::CAM { -static std::weak_ptr current_cam; - // built-in resolution parameters constexpr std::array PRESET_RESOLUTION{{ {640, 480, 0, 0, 639, 479}, // VGA @@ -200,6 +198,10 @@ Module::Interface::Interface(std::shared_ptr cam, const char* name, u32 Module::Interface::~Interface() = default; +std::shared_ptr Module::Interface::GetModule() const { + return cam; +} + void Module::Interface::StartCapture(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x01, 1, 0); const PortSet port_select(rp.Pop()); @@ -1050,15 +1052,9 @@ void Module::LoadCameraImplementation(CameraConfig& camera, int camera_id) { camera.impl->SetResolution(camera.contexts[0].resolution); } -void ReloadCameraDevices() { - if (auto cam = current_cam.lock()) - cam->ReloadCameraDevices(); -} - void InstallInterfaces(Core::System& system) { auto& service_manager = system.ServiceManager(); auto cam = std::make_shared(); - current_cam = cam; std::make_shared(cam)->InstallAsService(service_manager); std::make_shared(cam)->InstallAsService(service_manager); diff --git a/src/core/hle/service/cam/cam.h b/src/core/hle/service/cam/cam.h index 319debfdb..b8375999c 100644 --- a/src/core/hle/service/cam/cam.h +++ b/src/core/hle/service/cam/cam.h @@ -250,6 +250,8 @@ public: Interface(std::shared_ptr cam, const char* name, u32 max_session); ~Interface(); + std::shared_ptr GetModule() const; + protected: /** * Starts capturing at the selected port. @@ -783,9 +785,6 @@ private: std::atomic is_camera_reload_pending{false}; }; -/// Reload camera devices. Used when input configuration changed -void ReloadCameraDevices(); - void InstallInterfaces(Core::System& system); } // namespace Service::CAM diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index c07fb6bd4..ab73bb048 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -114,14 +114,6 @@ static const std::vector cfg_system_savedata_id = { 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x01, 0x00, }; -static std::weak_ptr current_cfg; - -std::shared_ptr GetCurrentModule() { - auto cfg = current_cfg.lock(); - ASSERT_MSG(cfg, "No CFG module running!"); - return cfg; -} - Module::Interface::Interface(std::shared_ptr cfg, const char* name, u32 max_session) : ServiceFramework(name, max_session), cfg(std::move(cfg)) {} @@ -145,6 +137,10 @@ void Module::Interface::GetCountryCodeString(Kernel::HLERequestContext& ctx) { rb.Push(country_codes[country_code_id]); } +std::shared_ptr Module::Interface::GetModule() const { + return cfg; +} + void Module::Interface::GetCountryCodeID(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x0A, 1, 0); u16 country_code = rp.Pop(); @@ -729,7 +725,6 @@ void InstallInterfaces(Core::System& system) { std::make_shared(cfg)->InstallAsService(service_manager); std::make_shared(cfg)->InstallAsService(service_manager); std::make_shared()->InstallAsService(service_manager); - current_cfg = cfg; } } // namespace Service::CFG diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index 02342711f..ed2f65fc8 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h @@ -97,6 +97,8 @@ public: Interface(std::shared_ptr cfg, const char* name, u32 max_session); ~Interface(); + std::shared_ptr GetModule() const; + /** * CFG::GetCountryCodeString service function * Inputs: @@ -117,8 +119,6 @@ public: */ void GetCountryCodeID(Kernel::HLERequestContext& ctx); - u32 GetRegionValue(); - /** * CFG::SecureInfoGetRegion service function * Inputs: @@ -412,6 +412,5 @@ private: }; void InstallInterfaces(Core::System& system); -std::shared_ptr GetCurrentModule(); } // namespace Service::CFG diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 4d183c014..aa8ddb5f9 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -21,8 +21,6 @@ namespace Service::HID { -static std::weak_ptr current_module; - // Updating period for each HID device. These empirical values are measured from a 11.2 3DS. constexpr u64 pad_update_ticks = BASE_CLOCK_RATE_ARM11 / 234; constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE_ARM11 / 104; @@ -354,6 +352,10 @@ void Module::Interface::GetSoundVolume(Kernel::HLERequestContext& ctx) { Module::Interface::Interface(std::shared_ptr hid, const char* name, u32 max_session) : ServiceFramework(name, max_session), hid(std::move(hid)) {} +std::shared_ptr Module::Interface::GetModule() const { + return hid; +} + Module::Module(Core::System& system) : system(system) { using namespace Kernel; @@ -388,17 +390,11 @@ void Module::ReloadInputDevices() { is_device_reload_pending.store(true); } -void ReloadInputDevices() { - if (auto hid = current_module.lock()) - hid->ReloadInputDevices(); -} - void InstallInterfaces(Core::System& system) { auto& service_manager = system.ServiceManager(); auto hid = std::make_shared(system); std::make_shared(hid)->InstallAsService(service_manager); std::make_shared(hid)->InstallAsService(service_manager); - current_module = hid; } } // namespace Service::HID diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index ecdb02f21..75b206dcd 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -208,6 +208,8 @@ public: public: Interface(std::shared_ptr hid, const char* name, u32 max_session); + std::shared_ptr GetModule() const; + protected: /** * HID::GetIPCHandles service function @@ -336,7 +338,4 @@ private: }; void InstallInterfaces(Core::System& system); - -/// Reload input devices. Used when input configuration changed -void ReloadInputDevices(); } // namespace Service::HID diff --git a/src/core/hle/service/ir/ir.cpp b/src/core/hle/service/ir/ir.cpp index 481ef123c..0869941f2 100644 --- a/src/core/hle/service/ir/ir.cpp +++ b/src/core/hle/service/ir/ir.cpp @@ -12,28 +12,15 @@ namespace Service::IR { -static std::weak_ptr current_ir_rst; -static std::weak_ptr current_ir_user; - -void ReloadInputDevices() { - if (auto ir_user = current_ir_user.lock()) - ir_user->ReloadInputDevices(); - - if (auto ir_rst = current_ir_rst.lock()) - ir_rst->ReloadInputDevices(); -} - void InstallInterfaces(Core::System& system) { auto& service_manager = system.ServiceManager(); std::make_shared()->InstallAsService(service_manager); auto ir_user = std::make_shared(); ir_user->InstallAsService(service_manager); - current_ir_user = ir_user; auto ir_rst = std::make_shared(); ir_rst->InstallAsService(service_manager); - current_ir_rst = ir_rst; } } // namespace Service::IR diff --git a/src/core/hle/service/ir/ir.h b/src/core/hle/service/ir/ir.h index 0666ed0b6..3887e0f6e 100644 --- a/src/core/hle/service/ir/ir.h +++ b/src/core/hle/service/ir/ir.h @@ -14,9 +14,6 @@ class ServiceManager; namespace Service::IR { -/// Reload input devices. Used when input configuration changed -void ReloadInputDevices(); - void InstallInterfaces(Core::System& system); } // namespace Service::IR diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 12301cb94..96bf44fcb 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -144,7 +144,13 @@ void AppLoader_NCCH::ParseRegionLockoutInfo() { } region_lockout >>= 1; } - Service::CFG::GetCurrentModule()->SetPreferredRegionCodes(regions); + auto cfg = Core::System::GetInstance() + .ServiceManager() + .GetService("cfg:u"); + ASSERT_MSG(cfg, "cfg:u not started!"); + auto cfg_module = cfg->GetModule(); + ASSERT_MSG(cfg_module, "CFG Module missing!"); + cfg_module->SetPreferredRegionCodes(regions); } } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index c648714fb..22f70aac2 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -6,7 +6,8 @@ #include "core/core.h" #include "core/gdbstub/gdbstub.h" #include "core/hle/service/hid/hid.h" -#include "core/hle/service/ir/ir.h" +#include "core/hle/service/ir/ir_rst.h" +#include "core/hle/service/ir/ir_user.h" #include "core/settings.h" #include "video_core/renderer_base.h" #include "video_core/video_core.h" @@ -32,14 +33,37 @@ void Apply() { VideoCore::g_renderer_bg_color_update_requested = true; - if (Core::System::GetInstance().IsPoweredOn()) { + auto& system = Core::System::GetInstance(); + if (system.IsPoweredOn()) { Core::DSP().SetSink(values.sink_id, values.audio_device_id); Core::DSP().EnableStretching(values.enable_audio_stretching); - } - Service::HID::ReloadInputDevices(); - Service::IR::ReloadInputDevices(); - Service::CAM::ReloadCameraDevices(); + auto& sm = system.ServiceManager(); + + auto hid = sm.GetService("hid:USER"); + if (hid) { + auto hid_module = hid->GetModule(); + if (hid_module) { + hid_module->ReloadInputDevices(); + } + } + + auto ir_user = sm.GetService("ir:USER"); + if (ir_user) + ir_user->ReloadInputDevices(); + + auto ir_rst = sm.GetService("ir:rst"); + if (ir_rst) + ir_rst->ReloadInputDevices(); + + auto cam = sm.GetService("cam:u"); + if (cam) { + auto cam_module = cam->GetModule(); + if (cam_module) { + cam_module->ReloadCameraDevices(); + } + } + } } template From 1b1de23a98dcb1bb620a5d56813e174242dbcfc4 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Thu, 11 Oct 2018 20:05:45 +0200 Subject: [PATCH 2/3] Fixup: Remove unneeded GetUsername --- src/core/hle/service/apt/apt.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 03d6c5e4e..eb5b7d537 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -5,7 +5,6 @@ #include "common/common_paths.h" #include "common/file_util.h" #include "common/logging/log.h" -#include "common/string_util.h" #include "core/core.h" #include "core/file_sys/archive_ncch.h" #include "core/file_sys/file_backend.h" @@ -110,7 +109,6 @@ bool Module::LoadSharedFont() { ASSERT_MSG(cfg, "cfg:u not started!"); auto cfg_module = cfg->GetModule(); ASSERT_MSG(cfg_module, "CFG Module missing!"); - std::string username = Common::UTF16ToUTF8(cfg_module->GetUsername()); switch (cfg_module->GetRegionValue()) { case 4: // CHN font_region_code = 2; From eb3af0f16aeaae9ce190cb57a2973c7e28d5a751 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Fri, 12 Oct 2018 11:50:50 +0200 Subject: [PATCH 3/3] Add GetModule() helper functions, for HID, CAM, and CFG --- .../configuration/configure_system.cpp | 7 +------ src/core/frontend/applets/swkbd.cpp | 10 +++------- src/core/hle/service/apt/applet_manager.cpp | 16 ++++++---------- src/core/hle/service/apt/apt.cpp | 10 +++------- src/core/hle/service/cam/cam.cpp | 7 +++++++ src/core/hle/service/cam/cam.h | 2 ++ src/core/hle/service/cfg/cfg.cpp | 9 ++++++++- src/core/hle/service/cfg/cfg.h | 2 ++ src/core/hle/service/hid/hid.cpp | 7 +++++++ src/core/hle/service/hid/hid.h | 2 ++ src/core/loader/ncch.cpp | 10 +++------- src/core/settings.cpp | 18 +++++------------- 12 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/citra_qt/configuration/configure_system.cpp b/src/citra_qt/configuration/configure_system.cpp index aa2fac4d8..475699b86 100644 --- a/src/citra_qt/configuration/configure_system.cpp +++ b/src/citra_qt/configuration/configure_system.cpp @@ -246,12 +246,7 @@ void ConfigureSystem::setConfiguration() { ui->edit_init_time->setDateTime(date_time); if (!enabled) { - - auto cfg_interface = Core::System::GetInstance() - .ServiceManager() - .GetService("cfg:u"); - ASSERT_MSG(cfg_interface, "cfg:u not started!"); - cfg = cfg_interface->GetModule(); + cfg = Service::CFG::GetModule(Core::System::GetInstance()); ASSERT_MSG(cfg, "CFG Module missing!"); ReadSystemSettings(); ui->group_system_settings->setEnabled(false); diff --git a/src/core/frontend/applets/swkbd.cpp b/src/core/frontend/applets/swkbd.cpp index f61693ebb..8d10a0742 100644 --- a/src/core/frontend/applets/swkbd.cpp +++ b/src/core/frontend/applets/swkbd.cpp @@ -136,13 +136,9 @@ ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) { void DefaultKeyboard::Setup(const Frontend::KeyboardConfig* config) { SoftwareKeyboard::Setup(config); - auto cfg = - Core::System::GetInstance().ServiceManager().GetService( - "cfg:u"); - ASSERT_MSG(cfg, "cfg:u not started!"); - auto cfg_module = cfg->GetModule(); - ASSERT_MSG(cfg_module, "CFG Module missing!"); - std::string username = Common::UTF16ToUTF8(cfg_module->GetUsername()); + auto cfg = Service::CFG::GetModule(Core::System::GetInstance()); + ASSERT_MSG(cfg, "CFG Module missing!"); + std::string username = Common::UTF16ToUTF8(cfg->GetUsername()); switch (this->config.button_config) { case ButtonConfig::None: case ButtonConfig::Single: diff --git a/src/core/hle/service/apt/applet_manager.cpp b/src/core/hle/service/apt/applet_manager.cpp index 4bb93f9a7..e950542aa 100644 --- a/src/core/hle/service/apt/applet_manager.cpp +++ b/src/core/hle/service/apt/applet_manager.cpp @@ -465,11 +465,9 @@ ResultVal AppletManager::GetAppletInfo(AppletId app_i ErrorLevel::Status); } - auto cfg = system.ServiceManager().GetService("cfg:u"); - ASSERT_MSG(cfg, "cfg:u not started!"); - auto cfg_module = cfg->GetModule(); - ASSERT_MSG(cfg_module, "CFG Module missing!"); - u32 region_value = cfg_module->GetRegionValue(); + auto cfg = Service::CFG::GetModule(system); + ASSERT_MSG(cfg, "CFG Module missing!"); + u32 region_value = cfg->GetRegionValue(); return MakeResult({GetTitleIdForApplet(app_id, region_value), Service::FS::MediaType::NAND, slot->registered, slot->loaded, slot->attributes.raw}); @@ -554,11 +552,9 @@ void AppletManager::EnsureHomeMenuLoaded() { return; } - auto cfg = system.ServiceManager().GetService("cfg:u"); - ASSERT_MSG(cfg, "cfg:u not started!"); - auto cfg_module = cfg->GetModule(); - ASSERT_MSG(cfg_module, "CFG Module missing!"); - u32 region_value = cfg_module->GetRegionValue(); + auto cfg = Service::CFG::GetModule(system); + ASSERT_MSG(cfg, "CFG Module missing!"); + u32 region_value = cfg->GetRegionValue(); u64 menu_title_id = GetTitleIdForApplet(AppletId::HomeMenu, region_value); auto process = NS::LaunchTitle(FS::MediaType::NAND, menu_title_id); if (!process) { diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index eb5b7d537..7c302bdee 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -103,13 +103,9 @@ static u32 DecompressLZ11(const u8* in, u8* out) { bool Module::LoadSharedFont() { u8 font_region_code; - auto cfg = - Core::System::GetInstance().ServiceManager().GetService( - "cfg:u"); - ASSERT_MSG(cfg, "cfg:u not started!"); - auto cfg_module = cfg->GetModule(); - ASSERT_MSG(cfg_module, "CFG Module missing!"); - switch (cfg_module->GetRegionValue()) { + auto cfg = Service::CFG::GetModule(Core::System::GetInstance()); + ASSERT_MSG(cfg, "CFG Module missing!"); + switch (cfg->GetRegionValue()) { case 4: // CHN font_region_code = 2; break; diff --git a/src/core/hle/service/cam/cam.cpp b/src/core/hle/service/cam/cam.cpp index d6399194a..99dad6980 100644 --- a/src/core/hle/service/cam/cam.cpp +++ b/src/core/hle/service/cam/cam.cpp @@ -1052,6 +1052,13 @@ void Module::LoadCameraImplementation(CameraConfig& camera, int camera_id) { camera.impl->SetResolution(camera.contexts[0].resolution); } +std::shared_ptr GetModule(Core::System& system) { + auto cam = system.ServiceManager().GetService("cam:u"); + if (!cam) + return nullptr; + return cam->GetModule(); +} + void InstallInterfaces(Core::System& system) { auto& service_manager = system.ServiceManager(); auto cam = std::make_shared(); diff --git a/src/core/hle/service/cam/cam.h b/src/core/hle/service/cam/cam.h index b8375999c..401a2a203 100644 --- a/src/core/hle/service/cam/cam.h +++ b/src/core/hle/service/cam/cam.h @@ -785,6 +785,8 @@ private: std::atomic is_camera_reload_pending{false}; }; +std::shared_ptr GetModule(Core::System& system); + void InstallInterfaces(Core::System& system); } // namespace Service::CAM diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index ab73bb048..d5c08a5a7 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -137,7 +137,7 @@ void Module::Interface::GetCountryCodeString(Kernel::HLERequestContext& ctx) { rb.Push(country_codes[country_code_id]); } -std::shared_ptr Module::Interface::GetModule() const { +std::shared_ptr Module::Interface::Interface::GetModule() const { return cfg; } @@ -718,6 +718,13 @@ u64 Module::GetConsoleUniqueId() { return console_id_le; } +std::shared_ptr GetModule(Core::System& system) { + auto cfg = system.ServiceManager().GetService("cfg:u"); + if (!cfg) + return nullptr; + return cfg->GetModule(); +} + void InstallInterfaces(Core::System& system) { auto& service_manager = system.ServiceManager(); auto cfg = std::make_shared(); diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index ed2f65fc8..b069ad728 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h @@ -411,6 +411,8 @@ private: u32 preferred_region_code = 0; }; +std::shared_ptr GetModule(Core::System& system); + void InstallInterfaces(Core::System& system); } // namespace Service::CFG diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index aa8ddb5f9..b9876012e 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -390,6 +390,13 @@ void Module::ReloadInputDevices() { is_device_reload_pending.store(true); } +std::shared_ptr GetModule(Core::System& system) { + auto hid = system.ServiceManager().GetService("hid:USER"); + if (!hid) + return nullptr; + return hid->GetModule(); +} + void InstallInterfaces(Core::System& system) { auto& service_manager = system.ServiceManager(); auto hid = std::make_shared(system); diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 75b206dcd..45f94bb30 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -337,5 +337,7 @@ private: std::unique_ptr touch_device; }; +std::shared_ptr GetModule(Core::System& system); + void InstallInterfaces(Core::System& system); } // namespace Service::HID diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 96bf44fcb..2a087366a 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -144,13 +144,9 @@ void AppLoader_NCCH::ParseRegionLockoutInfo() { } region_lockout >>= 1; } - auto cfg = Core::System::GetInstance() - .ServiceManager() - .GetService("cfg:u"); - ASSERT_MSG(cfg, "cfg:u not started!"); - auto cfg_module = cfg->GetModule(); - ASSERT_MSG(cfg_module, "CFG Module missing!"); - cfg_module->SetPreferredRegionCodes(regions); + auto cfg = Service::CFG::GetModule(Core::System::GetInstance()); + ASSERT_MSG(cfg, "CFG Module missing!"); + cfg->SetPreferredRegionCodes(regions); } } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 22f70aac2..8bdf5689b 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -38,30 +38,22 @@ void Apply() { Core::DSP().SetSink(values.sink_id, values.audio_device_id); Core::DSP().EnableStretching(values.enable_audio_stretching); - auto& sm = system.ServiceManager(); - - auto hid = sm.GetService("hid:USER"); + auto hid = Service::HID::GetModule(system); if (hid) { - auto hid_module = hid->GetModule(); - if (hid_module) { - hid_module->ReloadInputDevices(); - } + hid->ReloadInputDevices(); } + auto sm = system.ServiceManager(); auto ir_user = sm.GetService("ir:USER"); if (ir_user) ir_user->ReloadInputDevices(); - auto ir_rst = sm.GetService("ir:rst"); if (ir_rst) ir_rst->ReloadInputDevices(); - auto cam = sm.GetService("cam:u"); + auto cam = Service::CAM::GetModule(system); if (cam) { - auto cam_module = cam->GetModule(); - if (cam_module) { - cam_module->ReloadCameraDevices(); - } + cam->ReloadCameraDevices(); } } }