VERY experimental Nintendo Switch 2 emulator
C++
applets: Pass current process title ID to applets
Zach Hilman2f49b0e0b10c
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cppindex 4a7bf4acb3..33cebb48b8 100644--- a/src/core/hle/service/am/am.cpp+++ b/src/core/hle/service/am/am.cpp@@ -887,7 +887,9 @@ void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) {rb.Push(RESULT_SUCCESS);}-ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") {+ILibraryAppletCreator::ILibraryAppletCreator(u64 current_process_title_id)+ : ServiceFramework("ILibraryAppletCreator"),+ current_process_title_id(current_process_title_id) {static const FunctionInfo functions[] = {{0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"},{1, nullptr, "TerminateAllLibraryApplets"},@@ -910,7 +912,7 @@ void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx)static_cast<u32>(applet_id), applet_mode);const auto& applet_manager{Core::System::GetInstance().GetAppletManager()};- const auto applet = applet_manager.GetApplet(applet_id);+ const auto applet = applet_manager.GetApplet(applet_id, current_process_title_id);if (applet == nullptr) {LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", static_cast<u32>(applet_id));@@ -1234,13 +1236,13 @@ void IApplicationFunctions::GetSaveDataSize(Kernel::HLERequestContext& ctx) {}void InstallInterfaces(SM::ServiceManager& service_manager,- std::shared_ptr<NVFlinger::NVFlinger> nvflinger) {+ std::shared_ptr<NVFlinger::NVFlinger> nvflinger, Core::System& system) {auto message_queue = std::make_shared<AppletMessageQueue>();message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); // Needed on// game boot- std::make_shared<AppletAE>(nvflinger, message_queue)->InstallAsService(service_manager);- std::make_shared<AppletOE>(nvflinger, message_queue)->InstallAsService(service_manager);+ std::make_shared<AppletAE>(nvflinger, message_queue, system)->InstallAsService(service_manager);+ std::make_shared<AppletOE>(nvflinger, message_queue, system)->InstallAsService(service_manager);std::make_shared<IdleSys>()->InstallAsService(service_manager);std::make_shared<OMM>()->InstallAsService(service_manager);std::make_shared<SPSM>()->InstallAsService(service_manager);diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.hindex 1fa069e560..4ea609d23b 100644--- a/src/core/hle/service/am/am.h+++ b/src/core/hle/service/am/am.h@@ -201,13 +201,15 @@ private:class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> {public:- ILibraryAppletCreator();+ ILibraryAppletCreator(u64 current_process_title_id);~ILibraryAppletCreator() override;private:void CreateLibraryApplet(Kernel::HLERequestContext& ctx);void CreateStorage(Kernel::HLERequestContext& ctx);void CreateTransferMemoryStorage(Kernel::HLERequestContext& ctx);++ u64 current_process_title_id;};class IApplicationFunctions final : public ServiceFramework<IApplicationFunctions> {@@ -264,7 +266,7 @@ public:/// Registers all AM services with the specified service manager.void InstallInterfaces(SM::ServiceManager& service_manager,- std::shared_ptr<NVFlinger::NVFlinger> nvflinger);+ std::shared_ptr<NVFlinger::NVFlinger> nvflinger, Core::System& system);} // namespace AM} // namespace Servicediff --git a/src/core/hle/service/am/applet_ae.cpp b/src/core/hle/service/am/applet_ae.cppindex 488add8e75..fe5beb8f9a 100644--- a/src/core/hle/service/am/applet_ae.cpp+++ b/src/core/hle/service/am/applet_ae.cpp@@ -4,6 +4,7 @@#include "common/logging/log.h"#include "core/hle/ipc_helpers.h"+#include "core/hle/kernel/process.h"#include "core/hle/service/am/am.h"#include "core/hle/service/am/applet_ae.h"#include "core/hle/service/nvflinger/nvflinger.h"@@ -13,9 +14,10 @@ namespace Service::AM {class ILibraryAppletProxy final : public ServiceFramework<ILibraryAppletProxy> {public:explicit ILibraryAppletProxy(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,- std::shared_ptr<AppletMessageQueue> msg_queue)+ std::shared_ptr<AppletMessageQueue> msg_queue,+ Core::System& system): ServiceFramework("ILibraryAppletProxy"), nvflinger(std::move(nvflinger)),- msg_queue(std::move(msg_queue)) {+ msg_queue(std::move(msg_queue)), system(system) {// clang-format offstatic const FunctionInfo functions[] = {{0, &ILibraryAppletProxy::GetCommonStateGetter, "GetCommonStateGetter"},@@ -96,7 +98,7 @@ private:IPC::ResponseBuilder rb{ctx, 2, 0, 1};rb.Push(RESULT_SUCCESS);- rb.PushIpcInterface<ILibraryAppletCreator>();+ rb.PushIpcInterface<ILibraryAppletCreator>(system.CurrentProcess()->GetTitleID());}void GetApplicationFunctions(Kernel::HLERequestContext& ctx) {@@ -109,14 +111,15 @@ private:std::shared_ptr<NVFlinger::NVFlinger> nvflinger;std::shared_ptr<AppletMessageQueue> msg_queue;+ Core::System& system;};class ISystemAppletProxy final : public ServiceFramework<ISystemAppletProxy> {public:explicit ISystemAppletProxy(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,- std::shared_ptr<AppletMessageQueue> msg_queue)+ std::shared_ptr<AppletMessageQueue> msg_queue, Core::System& system): ServiceFramework("ISystemAppletProxy"), nvflinger(std::move(nvflinger)),- msg_queue(std::move(msg_queue)) {+ msg_queue(std::move(msg_queue)), system(system) {// clang-format offstatic const FunctionInfo functions[] = {{0, &ISystemAppletProxy::GetCommonStateGetter, "GetCommonStateGetter"},@@ -191,7 +194,7 @@ private:IPC::ResponseBuilder rb{ctx, 2, 0, 1};rb.Push(RESULT_SUCCESS);- rb.PushIpcInterface<ILibraryAppletCreator>();+ rb.PushIpcInterface<ILibraryAppletCreator>(system.CurrentProcess()->GetTitleID());}void GetHomeMenuFunctions(Kernel::HLERequestContext& ctx) {@@ -219,6 +222,7 @@ private:}std::shared_ptr<NVFlinger::NVFlinger> nvflinger;std::shared_ptr<AppletMessageQueue> msg_queue;+ Core::System& system;};void AppletAE::OpenSystemAppletProxy(Kernel::HLERequestContext& ctx) {@@ -226,7 +230,7 @@ void AppletAE::OpenSystemAppletProxy(Kernel::HLERequestContext& ctx) {IPC::ResponseBuilder rb{ctx, 2, 0, 1};rb.Push(RESULT_SUCCESS);- rb.PushIpcInterface<ISystemAppletProxy>(nvflinger, msg_queue);+ rb.PushIpcInterface<ISystemAppletProxy>(nvflinger, msg_queue, system);}void AppletAE::OpenLibraryAppletProxy(Kernel::HLERequestContext& ctx) {@@ -234,7 +238,7 @@ void AppletAE::OpenLibraryAppletProxy(Kernel::HLERequestContext& ctx) {IPC::ResponseBuilder rb{ctx, 2, 0, 1};rb.Push(RESULT_SUCCESS);- rb.PushIpcInterface<ILibraryAppletProxy>(nvflinger, msg_queue);+ rb.PushIpcInterface<ILibraryAppletProxy>(nvflinger, msg_queue, system);}void AppletAE::OpenLibraryAppletProxyOld(Kernel::HLERequestContext& ctx) {@@ -242,13 +246,13 @@ void AppletAE::OpenLibraryAppletProxyOld(Kernel::HLERequestContext& ctx) {IPC::ResponseBuilder rb{ctx, 2, 0, 1};rb.Push(RESULT_SUCCESS);- rb.PushIpcInterface<ILibraryAppletProxy>(nvflinger, msg_queue);+ rb.PushIpcInterface<ILibraryAppletProxy>(nvflinger, msg_queue, system);}AppletAE::AppletAE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,- std::shared_ptr<AppletMessageQueue> msg_queue)+ std::shared_ptr<AppletMessageQueue> msg_queue, Core::System& system): ServiceFramework("appletAE"), nvflinger(std::move(nvflinger)),- msg_queue(std::move(msg_queue)) {+ msg_queue(std::move(msg_queue)), system(system) {// clang-format offstatic const FunctionInfo functions[] = {{100, &AppletAE::OpenSystemAppletProxy, "OpenSystemAppletProxy"},diff --git a/src/core/hle/service/am/applet_ae.h b/src/core/hle/service/am/applet_ae.hindex 902db26658..9e006cd9d8 100644--- a/src/core/hle/service/am/applet_ae.h+++ b/src/core/hle/service/am/applet_ae.h@@ -18,7 +18,7 @@ namespace AM {class AppletAE final : public ServiceFramework<AppletAE> {public:explicit AppletAE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,- std::shared_ptr<AppletMessageQueue> msg_queue);+ std::shared_ptr<AppletMessageQueue> msg_queue, Core::System& system);~AppletAE() override;const std::shared_ptr<AppletMessageQueue>& GetMessageQueue() const;@@ -30,6 +30,7 @@ private:std::shared_ptr<NVFlinger::NVFlinger> nvflinger;std::shared_ptr<AppletMessageQueue> msg_queue;+ Core::System& system;};} // namespace AMdiff --git a/src/core/hle/service/am/applet_oe.cpp b/src/core/hle/service/am/applet_oe.cppindex d3a0a15689..6e255fe95b 100644--- a/src/core/hle/service/am/applet_oe.cpp+++ b/src/core/hle/service/am/applet_oe.cpp@@ -4,6 +4,7 @@#include "common/logging/log.h"#include "core/hle/ipc_helpers.h"+#include "core/hle/kernel/process.h"#include "core/hle/service/am/am.h"#include "core/hle/service/am/applet_oe.h"#include "core/hle/service/nvflinger/nvflinger.h"@@ -13,9 +14,9 @@ namespace Service::AM {class IApplicationProxy final : public ServiceFramework<IApplicationProxy> {public:explicit IApplicationProxy(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,- std::shared_ptr<AppletMessageQueue> msg_queue)+ std::shared_ptr<AppletMessageQueue> msg_queue, Core::System& system): ServiceFramework("IApplicationProxy"), nvflinger(std::move(nvflinger)),- msg_queue(std::move(msg_queue)) {+ msg_queue(std::move(msg_queue)), system(system) {// clang-format offstatic const FunctionInfo functions[] = {{0, &IApplicationProxy::GetCommonStateGetter, "GetCommonStateGetter"},@@ -87,7 +88,7 @@ private:IPC::ResponseBuilder rb{ctx, 2, 0, 1};rb.Push(RESULT_SUCCESS);- rb.PushIpcInterface<ILibraryAppletCreator>();+ rb.PushIpcInterface<ILibraryAppletCreator>(system.CurrentProcess()->GetTitleID());}void GetApplicationFunctions(Kernel::HLERequestContext& ctx) {@@ -100,6 +101,7 @@ private:std::shared_ptr<NVFlinger::NVFlinger> nvflinger;std::shared_ptr<AppletMessageQueue> msg_queue;+ Core::System& system;};void AppletOE::OpenApplicationProxy(Kernel::HLERequestContext& ctx) {@@ -107,13 +109,13 @@ void AppletOE::OpenApplicationProxy(Kernel::HLERequestContext& ctx) {IPC::ResponseBuilder rb{ctx, 2, 0, 1};rb.Push(RESULT_SUCCESS);- rb.PushIpcInterface<IApplicationProxy>(nvflinger, msg_queue);+ rb.PushIpcInterface<IApplicationProxy>(nvflinger, msg_queue, system);}AppletOE::AppletOE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,- std::shared_ptr<AppletMessageQueue> msg_queue)+ std::shared_ptr<AppletMessageQueue> msg_queue, Core::System& system): ServiceFramework("appletOE"), nvflinger(std::move(nvflinger)),- msg_queue(std::move(msg_queue)) {+ msg_queue(std::move(msg_queue)), system(system) {static const FunctionInfo functions[] = {{0, &AppletOE::OpenApplicationProxy, "OpenApplicationProxy"},};diff --git a/src/core/hle/service/am/applet_oe.h b/src/core/hle/service/am/applet_oe.hindex bbd0108eff..22c05419d7 100644--- a/src/core/hle/service/am/applet_oe.h+++ b/src/core/hle/service/am/applet_oe.h@@ -18,7 +18,7 @@ namespace AM {class AppletOE final : public ServiceFramework<AppletOE> {public:explicit AppletOE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,- std::shared_ptr<AppletMessageQueue> msg_queue);+ std::shared_ptr<AppletMessageQueue> msg_queue, Core::System& system);~AppletOE() override;const std::shared_ptr<AppletMessageQueue>& GetMessageQueue() const;@@ -28,6 +28,7 @@ private:std::shared_ptr<NVFlinger::NVFlinger> nvflinger;std::shared_ptr<AppletMessageQueue> msg_queue;+ Core::System& system;};} // namespace AMdiff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cppindex 5532061779..6bdba2468b 100644--- a/src/core/hle/service/am/applets/applets.cpp+++ b/src/core/hle/service/am/applets/applets.cpp@@ -139,12 +139,14 @@ void Applet::Initialize() {AppletFrontendSet::AppletFrontendSet() = default;-AppletFrontendSet::AppletFrontendSet(ErrorApplet error, PhotoViewer photo_viewer,- ProfileSelect profile_select,- SoftwareKeyboard software_keyboard, WebBrowser web_browser)- : error{std::move(error)}, photo_viewer{std::move(photo_viewer)}, profile_select{std::move(- profile_select)},- software_keyboard{std::move(software_keyboard)}, web_browser{std::move(web_browser)} {}+AppletFrontendSet::AppletFrontendSet(ParentalControlsApplet parental_controls, ErrorApplet error,+ PhotoViewer photo_viewer, ProfileSelect profile_select,+ SoftwareKeyboard software_keyboard, WebBrowser web_browser,+ ECommerceApplet e_commerce)+ : parental_controls{std::move(parental_controls)}, error{std::move(error)},+ photo_viewer{std::move(photo_viewer)}, profile_select{std::move(profile_select)},+ software_keyboard{std::move(software_keyboard)}, web_browser{std::move(web_browser)},+ e_commerce{std::move(e_commerce)} {}AppletFrontendSet::~AppletFrontendSet() = default;@@ -214,7 +216,7 @@ void AppletManager::ClearAll() {frontend = {};}-std::shared_ptr<Applet> AppletManager::GetApplet(AppletId id) const {+std::shared_ptr<Applet> AppletManager::GetApplet(AppletId id, u64 current_process_title_id) const {switch (id) {case AppletId::Auth:return std::make_shared<Auth>(*frontend.parental_controls);@@ -227,9 +229,10 @@ std::shared_ptr<Applet> AppletManager::GetApplet(AppletId id) const {case AppletId::PhotoViewer:return std::make_shared<PhotoViewer>(*frontend.photo_viewer);case AppletId::LibAppletShop:- return std::make_shared<WebBrowser>(*frontend.web_browser, frontend.e_commerce.get());+ return std::make_shared<WebBrowser>(*frontend.web_browser, current_process_title_id,+ frontend.e_commerce.get());case AppletId::LibAppletOff:- return std::make_shared<WebBrowser>(*frontend.web_browser);+ return std::make_shared<WebBrowser>(*frontend.web_browser, current_process_title_id);default:UNIMPLEMENTED_MSG("No backend implementation exists for applet_id={:02X}! Falling back to stub applet.",diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.hindex ef37918654..adc973dad0 100644--- a/src/core/hle/service/am/applets/applets.h+++ b/src/core/hle/service/am/applets/applets.h@@ -187,7 +187,7 @@ public:void SetDefaultAppletsIfMissing();void ClearAll();- std::shared_ptr<Applet> GetApplet(AppletId id) const;+ std::shared_ptr<Applet> GetApplet(AppletId id, u64 current_process_title_id) const;private:AppletFrontendSet frontend;diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cppindex 3aa8f24688..2762e0653b 100644--- a/src/core/hle/service/am/applets/web_browser.cpp+++ b/src/core/hle/service/am/applets/web_browser.cpp@@ -207,9 +207,10 @@ FileSys::VirtualFile GetApplicationRomFS(u64 title_id, FileSys::ContentRecordTyp} // Anonymous namespace-WebBrowser::WebBrowser(Core::Frontend::WebBrowserApplet& frontend,+WebBrowser::WebBrowser(Core::Frontend::WebBrowserApplet& frontend, u64 current_process_title_id,Core::Frontend::ECommerceApplet* frontend_e_commerce)- : frontend(frontend), frontend_e_commerce(frontend_e_commerce) {}+ : frontend(frontend), frontend_e_commerce(frontend_e_commerce),+ current_process_title_id(current_process_title_id) {}WebBrowser::~WebBrowser() = default;@@ -469,7 +470,7 @@ void WebBrowser::InitializeOffline() {}if (title_id == 0) {- title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();+ title_id = current_process_title_id;}offline_romfs = GetApplicationRomFS(title_id, type);diff --git a/src/core/hle/service/am/applets/web_browser.h b/src/core/hle/service/am/applets/web_browser.hindex 9667dcf6f1..870f57b645 100644--- a/src/core/hle/service/am/applets/web_browser.h+++ b/src/core/hle/service/am/applets/web_browser.h@@ -17,7 +17,7 @@ enum class WebArgTLVType : u16;class WebBrowser final : public Applet {public:- WebBrowser(Core::Frontend::WebBrowserApplet& frontend,+ WebBrowser(Core::Frontend::WebBrowserApplet& frontend, u64 current_process_title_id,Core::Frontend::ECommerceApplet* frontend_e_commerce = nullptr);~WebBrowser() override;@@ -59,6 +59,8 @@ private:bool unpacked = false;ResultCode status = RESULT_SUCCESS;+ u64 current_process_title_id;+ShimKind kind;std::map<WebArgTLVType, std::vector<u8>> args;diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cppindex b2954eb343..dfffcb5109 100644--- a/src/core/hle/service/service.cpp+++ b/src/core/hle/service/service.cpp@@ -204,7 +204,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system,SM::ServiceManager::InstallInterfaces(sm);Account::InstallInterfaces(system);- AM::InstallInterfaces(*sm, nv_flinger);+ AM::InstallInterfaces(*sm, nv_flinger, system);AOC::InstallInterfaces(*sm);APM::InstallInterfaces(*sm);ARP::InstallInterfaces(*sm);