From 564dbc7b94b02c70febd901f613ccb567923cb5e Mon Sep 17 00:00:00 2001 From: Ian Carpenter Date: Sat, 25 Jan 2025 04:00:52 -0500 Subject: [PATCH] system_service: Add simple event queue and push an EntitlementUpdate event to it when app content is initialized (#2238) --- .../libraries/app_content/app_content.cpp | 10 ++++++++ src/core/libraries/system/systemservice.cpp | 23 ++++++++++++++++--- src/core/libraries/system/systemservice.h | 4 ++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/core/libraries/app_content/app_content.cpp b/src/core/libraries/app_content/app_content.cpp index 1d23e7f44..1223022c5 100644 --- a/src/core/libraries/app_content/app_content.cpp +++ b/src/core/libraries/app_content/app_content.cpp @@ -12,6 +12,7 @@ #include "core/file_sys/fs.h" #include "core/libraries/app_content/app_content_error.h" #include "core/libraries/libs.h" +#include "core/libraries/system/systemservice.h" namespace Libraries::AppContent { @@ -262,6 +263,15 @@ int PS4_SYSV_ABI sceAppContentInitialize(const OrbisAppContentInitParam* initPar entitlement_label.copy(info.entitlement_label, sizeof(info.entitlement_label)); } } + + if (addcont_count > 0) { + SystemService::OrbisSystemServiceEvent event{}; + event.event_type = SystemService::OrbisSystemServiceEventType::EntitlementUpdate; + event.service_entitlement_update.user_id = 0; + event.service_entitlement_update.np_service_label = 0; + SystemService::PushSystemServiceEvent(event); + } + return ORBIS_OK; } diff --git a/src/core/libraries/system/systemservice.cpp b/src/core/libraries/system/systemservice.cpp index ebb9f4392..a67b9a2fc 100644 --- a/src/core/libraries/system/systemservice.cpp +++ b/src/core/libraries/system/systemservice.cpp @@ -10,6 +10,8 @@ namespace Libraries::SystemService { bool g_splash_status{true}; +std::queue g_event_queue; +std::mutex g_event_queue_mutex; bool IsSplashVisible() { return Config::showSplash() && g_splash_status; @@ -1772,7 +1774,9 @@ s32 PS4_SYSV_ABI sceSystemServiceGetStatus(OrbisSystemServiceStatus* status) { LOG_ERROR(Lib_SystemService, "OrbisSystemServiceStatus is null"); return ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER; } - status->event_num = 0; + + std::lock_guard lock(g_event_queue_mutex); + status->event_num = static_cast(g_event_queue.size()); status->is_system_ui_overlaid = false; status->is_in_background_execution = false; status->is_cpu_mode7_cpu_normal = true; @@ -1940,11 +1944,19 @@ int PS4_SYSV_ABI sceSystemServiceRaiseExceptionLocalProcess() { } s32 PS4_SYSV_ABI sceSystemServiceReceiveEvent(OrbisSystemServiceEvent* event) { - LOG_ERROR(Lib_SystemService, "(STUBBED) called"); + LOG_TRACE(Lib_SystemService, "called"); if (event == nullptr) { return ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER; } - return ORBIS_SYSTEM_SERVICE_ERROR_NO_EVENT; + + std::lock_guard lock(g_event_queue_mutex); + if (g_event_queue.empty()) { + return ORBIS_SYSTEM_SERVICE_ERROR_NO_EVENT; + } + + *event = g_event_queue.front(); + g_event_queue.pop(); + return ORBIS_OK; } int PS4_SYSV_ABI sceSystemServiceReenableMusicPlayer() { @@ -2412,6 +2424,11 @@ int PS4_SYSV_ABI Func_CB5E885E225F69F0() { return ORBIS_OK; } +void PushSystemServiceEvent(const OrbisSystemServiceEvent& event) { + std::lock_guard lock(g_event_queue_mutex); + g_event_queue.push(event); +} + void RegisterlibSceSystemService(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("alZfRdr2RP8", "libSceAppMessaging", 1, "libSceSystemService", 1, 1, sceAppMessagingClearEventFlag); diff --git a/src/core/libraries/system/systemservice.h b/src/core/libraries/system/systemservice.h index cdd3c15e8..c22ccc88f 100644 --- a/src/core/libraries/system/systemservice.h +++ b/src/core/libraries/system/systemservice.h @@ -4,6 +4,8 @@ // https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/blob/master/include/orbis/_types/sys_service.h #pragma once +#include +#include #include "common/types.h" namespace Core::Loader { @@ -603,5 +605,7 @@ int PS4_SYSV_ABI sceSystemServiceReenableVoiceRecognition(); int PS4_SYSV_ABI Func_6B1CDB955F0EBD65(); int PS4_SYSV_ABI Func_CB5E885E225F69F0(); +void PushSystemServiceEvent(const OrbisSystemServiceEvent& event); + void RegisterlibSceSystemService(Core::Loader::SymbolsResolver* sym); } // namespace Libraries::SystemService