From ed24632ceb0e132f857f19478cbd27cac5682760 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 3 Oct 2024 14:03:26 +0300 Subject: [PATCH] Fix some network,npmanager issues (#1215) * improved np toolkit callbacks * added ExecuteGuest in callback * clang format --- src/core/libraries/np_manager/np_manager.cpp | 43 ++++++++++++-------- src/core/libraries/np_manager/np_manager.h | 4 +- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/core/libraries/np_manager/np_manager.cpp b/src/core/libraries/np_manager/np_manager.cpp index e4c24cad..28d28cc9 100644 --- a/src/core/libraries/np_manager/np_manager.cpp +++ b/src/core/libraries/np_manager/np_manager.cpp @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include +#include #include "common/config.h" #include "common/logging/log.h" #include "core/libraries/error_codes.h" @@ -874,19 +876,6 @@ int PS4_SYSV_ABI sceNpCheckCallback() { return ORBIS_OK; } -struct NpStateCallbackForNpToolkit { - OrbisNpStateCallbackForNpToolkit func; - void* userdata; -}; - -NpStateCallbackForNpToolkit NpStateCbForNp; - -int PS4_SYSV_ABI sceNpCheckCallbackForLib() { - // LOG_ERROR(Lib_NpManager, "(STUBBED) called"); - NpStateCbForNp.func(0, ORBIS_NP_STATE_SIGNED_OUT, NpStateCbForNp.userdata); - return ORBIS_OK; -} - int PS4_SYSV_ABI sceNpCheckNpAvailability() { LOG_ERROR(Lib_NpManager, "(STUBBED) called"); return ORBIS_OK; @@ -983,9 +972,10 @@ int PS4_SYSV_ABI sceNpGetGamePresenceStatusA() { } int PS4_SYSV_ABI sceNpGetNpId(OrbisUserServiceUserId userId, OrbisNpId* npId) { - LOG_ERROR(Lib_NpManager, "(DUMMY) called"); - + LOG_INFO(Lib_NpManager, "userId {}", userId); std::string name = Config::getUserName(); + // Fill the unused stuffs to 0 + memset(npId, 0, sizeof(*npId)); strcpy(npId->handle.data, name.c_str()); return ORBIS_OK; } @@ -1010,8 +1000,9 @@ int PS4_SYSV_ABI sceNpGetParentalControlInfoA() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNpGetState() { - LOG_ERROR(Lib_NpManager, "(STUBBED) called"); +int PS4_SYSV_ABI sceNpGetState(s32 userId, OrbisNpState* state) { + *state = ORBIS_NP_STATE_SIGNED_OUT; + LOG_DEBUG(Lib_NpManager, "Signed out"); return ORBIS_OK; } @@ -2515,12 +2506,28 @@ int PS4_SYSV_ABI Func_FF966E4351E564D6() { return ORBIS_OK; } +struct NpStateCallbackForNpToolkit { + OrbisNpStateCallbackForNpToolkit func; + void* userdata; +}; + +NpStateCallbackForNpToolkit NpStateCbForNp; + +int PS4_SYSV_ABI sceNpCheckCallbackForLib() { + // LOG_ERROR(Lib_NpManager, "(STUBBED) called"); + const auto* linker = Common::Singleton::Instance(); + linker->ExecuteGuest(NpStateCbForNp.func, 1, ORBIS_NP_STATE_SIGNED_OUT, + NpStateCbForNp.userdata); + return ORBIS_OK; +} + int PS4_SYSV_ABI sceNpRegisterStateCallbackForToolkit(OrbisNpStateCallbackForNpToolkit callback, void* userdata) { + static int id = 0; LOG_ERROR(Lib_NpManager, "(STUBBED) called"); NpStateCbForNp.func = callback; NpStateCbForNp.userdata = userdata; - return 1; + return id; } int PS4_SYSV_ABI sceNpUnregisterStateCallbackForToolkit() { diff --git a/src/core/libraries/np_manager/np_manager.h b/src/core/libraries/np_manager/np_manager.h index fa0ac82f..43ea49ce 100644 --- a/src/core/libraries/np_manager/np_manager.h +++ b/src/core/libraries/np_manager/np_manager.h @@ -11,6 +11,8 @@ class SymbolsResolver; namespace Libraries::NpManager { +constexpr int ORBIS_NP_ERROR_SIGNED_OUT = 0x80550006; + enum OrbisNpState { ORBIS_NP_STATE_UNKNOWN = 0, ORBIS_NP_STATE_SIGNED_OUT, @@ -234,7 +236,7 @@ int PS4_SYSV_ABI sceNpGetNpReachabilityState(); int PS4_SYSV_ABI sceNpGetOnlineId(); int PS4_SYSV_ABI sceNpGetParentalControlInfo(); int PS4_SYSV_ABI sceNpGetParentalControlInfoA(); -int PS4_SYSV_ABI sceNpGetState(); +int PS4_SYSV_ABI sceNpGetState(s32 userId, OrbisNpState* state); int PS4_SYSV_ABI sceNpGetUserIdByAccountId(); int PS4_SYSV_ABI sceNpGetUserIdByOnlineId(); int PS4_SYSV_ABI sceNpHasSignedUp();