From ccc879027a6193d7c9612d7688a3f37e6cec570b Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Fri, 18 Apr 2025 17:56:20 +0200 Subject: [PATCH] Add the NpAuth library --- CMakeLists.txt | 2 + src/common/logging/filter.cpp | 1 + src/common/logging/types.h | 1 + src/core/aerolib/stubs.cpp | 3 + src/core/libraries/audio/sdl_audio.cpp | 15 ++-- src/core/libraries/libs.cpp | 2 + src/core/libraries/np_auth/np_auth.cpp | 100 +++++++++++++++++++++++++ src/core/libraries/np_auth/np_auth.h | 29 +++++++ 8 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 src/core/libraries/np_auth/np_auth.cpp create mode 100644 src/core/libraries/np_auth/np_auth.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 76e7cb0ee..beea8a1e0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -570,6 +570,8 @@ set(NP_LIBS src/core/libraries/np_common/np_common.cpp src/core/libraries/np_web_api/np_web_api.h src/core/libraries/np_party/np_party.cpp src/core/libraries/np_party/np_party.h + src/core/libraries/np_auth/np_auth.cpp + src/core/libraries/np_auth/np_auth.h ) set(ZLIB_LIB src/core/libraries/zlib/zlib.cpp diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index bed7802ed..867d62916 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp @@ -101,6 +101,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) { SUB(Lib, Ssl2) \ SUB(Lib, SysModule) \ SUB(Lib, Move) \ + SUB(Lib, NpAuth) \ SUB(Lib, NpCommon) \ SUB(Lib, NpManager) \ SUB(Lib, NpScore) \ diff --git a/src/common/logging/types.h b/src/common/logging/types.h index c07efbc0d..e5714a81a 100644 --- a/src/common/logging/types.h +++ b/src/common/logging/types.h @@ -69,6 +69,7 @@ enum class Class : u8 { Lib_Http2, ///< The LibSceHttp2 implementation. Lib_SysModule, ///< The LibSceSysModule implementation Lib_NpCommon, ///< The LibSceNpCommon implementation + Lib_NpAuth, ///< The LibSceNpAuth implementation Lib_NpManager, ///< The LibSceNpManager implementation Lib_NpScore, ///< The LibSceNpScore implementation Lib_NpTrophy, ///< The LibSceNpTrophy implementation diff --git a/src/core/aerolib/stubs.cpp b/src/core/aerolib/stubs.cpp index 2634fc46a..6e132a1b1 100644 --- a/src/core/aerolib/stubs.cpp +++ b/src/core/aerolib/stubs.cpp @@ -37,6 +37,9 @@ static std::string stub_nids_unknown[MAX_STUBS]; template static u64 CommonStub() { auto entry = stub_nids[stub_index]; + if (strcmp(entry->name, "sceNpAuthCreateRequest")) { + return 1; + } if (entry) { LOG_ERROR(Core, "Stub: {} (nid: {}) called, returning zero to {}", entry->name, entry->nid, __builtin_return_address(0)); diff --git a/src/core/libraries/audio/sdl_audio.cpp b/src/core/libraries/audio/sdl_audio.cpp index 9aee2b447..6536efd27 100644 --- a/src/core/libraries/audio/sdl_audio.cpp +++ b/src/core/libraries/audio/sdl_audio.cpp @@ -15,10 +15,11 @@ class SDLPortBackend : public PortBackend { public: explicit SDLPortBackend(const PortOut& port) : frame_size(port.format_info.FrameSize()), guest_buffer_size(port.BufferSize()) { - const SDL_AudioSpec fmt = { + SDL_AudioSpec fmt = { .format = port.format_info.is_float ? SDL_AUDIO_F32LE : SDL_AUDIO_S16LE, .channels = port.format_info.num_channels, .freq = static_cast(port.sample_rate), + // .samples = 8192, // Increased buffer size to reduce queue pressure }; stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &fmt, nullptr, nullptr); @@ -55,15 +56,12 @@ public: if (!stream) { return; } - // AudioOut library manages timing, but we still need to guard against the SDL - // audio queue stalling, which may happen during device changes, for example. - // Otherwise, latency may grow over time unbounded. - if (const auto queued = SDL_GetAudioStreamQueued(stream); queued >= queue_threshold) { + const auto queued = SDL_GetAudioStreamQueued(stream); + if (queued >= queue_threshold) { LOG_WARNING(Lib_AudioOut, "SDL audio queue backed up ({} queued, {} threshold), clearing.", queued, queue_threshold); SDL_ClearAudioStream(stream); - // Recalculate the threshold in case this happened because of a device change. CalculateQueueThreshold(); } if (!SDL_PutAudioStreamData(stream, ptr, static_cast(guest_buffer_size))) { @@ -75,7 +73,6 @@ public: if (!stream) { return; } - // SDL does not have per-channel volumes, for now just take the maximum of the channels. const auto vol = *std::ranges::max_element(ch_volumes); if (!SDL_SetAudioStreamGain(stream, static_cast(vol) / SCE_AUDIO_OUT_VOLUME_0DB)) { LOG_WARNING(Lib_AudioOut, "Failed to change SDL audio stream volume: {}", @@ -94,7 +91,7 @@ private: sdl_buffer_frames = 0; } const auto sdl_buffer_size = sdl_buffer_frames * frame_size; - const auto new_threshold = std::max(guest_buffer_size, sdl_buffer_size) * 4; + const auto new_threshold = std::max(guest_buffer_size, sdl_buffer_size) * 8; // Increased multiplier to 8 if (host_buffer_size != sdl_buffer_size || queue_threshold != new_threshold) { host_buffer_size = sdl_buffer_size; queue_threshold = new_threshold; @@ -115,4 +112,4 @@ std::unique_ptr SDLAudioOut::Open(PortOut& port) { return std::make_unique(port); } -} // namespace Libraries::AudioOut +} // namespace Libraries::AudioOut \ No newline at end of file diff --git a/src/core/libraries/libs.cpp b/src/core/libraries/libs.cpp index d0f82556e..035aef392 100644 --- a/src/core/libraries/libs.cpp +++ b/src/core/libraries/libs.cpp @@ -31,6 +31,7 @@ #include "core/libraries/np_manager/np_manager.h" #include "core/libraries/np_party/np_party.h" #include "core/libraries/np_score/np_score.h" +#include "core/libraries/np_auth/np_auth.h" #include "core/libraries/np_trophy/np_trophy.h" #include "core/libraries/np_web_api/np_web_api.h" #include "core/libraries/pad/pad.h" @@ -88,6 +89,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) { Libraries::NpScore::RegisterlibSceNpScore(sym); Libraries::NpTrophy::RegisterlibSceNpTrophy(sym); Libraries::NpWebApi::RegisterlibSceNpWebApi(sym); + Libraries::NpAuth::RegisterlibSceNpAuth(sym); Libraries::ScreenShot::RegisterlibSceScreenShot(sym); Libraries::AppContent::RegisterlibSceAppContent(sym); Libraries::PngDec::RegisterlibScePngDec(sym); diff --git a/src/core/libraries/np_auth/np_auth.cpp b/src/core/libraries/np_auth/np_auth.cpp new file mode 100644 index 000000000..ee029db63 --- /dev/null +++ b/src/core/libraries/np_auth/np_auth.cpp @@ -0,0 +1,100 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" +#include "core/libraries/libs.h" +#include "core/libraries/np_auth/np_auth.h" + +namespace Libraries::NpAuth { + +s32 PS4_SYSV_ABI sceNpAuthGetAuthorizationCode() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthGetIdToken() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthAbortRequest() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthCreateAsyncRequest() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthCreateRequest() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthDeleteRequest() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthGetAuthorizationCodeA() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthGetAuthorizationCodeV3() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthGetIdTokenA() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthGetIdTokenV3() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthPollAsync() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthSetTimeout() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNpAuthWaitAsync() { + LOG_ERROR(Lib_NpAuth, "(STUBBED) called"); + return ORBIS_OK; +} + +void RegisterlibSceNpAuth(Core::Loader::SymbolsResolver* sym) { + LIB_FUNCTION("KxGkOrQJTqY", "libSceNpAuthCompat", 1, "libSceNpAuth", 1, 1, + sceNpAuthGetAuthorizationCode); + LIB_FUNCTION("uaB-LoJqHis", "libSceNpAuthCompat", 1, "libSceNpAuth", 1, 1, + sceNpAuthGetIdToken); + LIB_FUNCTION("cE7wIsqXdZ8", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthAbortRequest); + LIB_FUNCTION("N+mr7GjTvr8", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, + sceNpAuthCreateAsyncRequest); + LIB_FUNCTION("6bwFkosYRQg", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthCreateRequest); + LIB_FUNCTION("H8wG9Bk-nPc", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthDeleteRequest); + LIB_FUNCTION("KxGkOrQJTqY", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, + sceNpAuthGetAuthorizationCode); + LIB_FUNCTION("qAUXQ9GdWp8", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, + sceNpAuthGetAuthorizationCodeA); + LIB_FUNCTION("KI4dHLlTNl0", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, + sceNpAuthGetAuthorizationCodeV3); + LIB_FUNCTION("uaB-LoJqHis", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthGetIdToken); + LIB_FUNCTION("CocbHVIKPE8", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthGetIdTokenA); + LIB_FUNCTION("RdsFVsgSpZY", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthGetIdTokenV3); + LIB_FUNCTION("gjSyfzSsDcE", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthPollAsync); + LIB_FUNCTION("PM3IZCw-7m0", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthSetTimeout); + LIB_FUNCTION("SK-S7daqJSE", "libSceNpAuth", 1, "libSceNpAuth", 1, 1, sceNpAuthWaitAsync); +}; + +} // namespace Libraries::NpAuth \ No newline at end of file diff --git a/src/core/libraries/np_auth/np_auth.h b/src/core/libraries/np_auth/np_auth.h new file mode 100644 index 000000000..262bb3a64 --- /dev/null +++ b/src/core/libraries/np_auth/np_auth.h @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/types.h" + +namespace Core::Loader { +class SymbolsResolver; +} + +namespace Libraries::NpAuth { + +s32 PS4_SYSV_ABI sceNpAuthGetAuthorizationCode(); +s32 PS4_SYSV_ABI sceNpAuthGetIdToken(); +s32 PS4_SYSV_ABI sceNpAuthAbortRequest(); +s32 PS4_SYSV_ABI sceNpAuthCreateAsyncRequest(); +s32 PS4_SYSV_ABI sceNpAuthCreateRequest(); +s32 PS4_SYSV_ABI sceNpAuthDeleteRequest(); +s32 PS4_SYSV_ABI sceNpAuthGetAuthorizationCodeA(); +s32 PS4_SYSV_ABI sceNpAuthGetAuthorizationCodeV3(); +s32 PS4_SYSV_ABI sceNpAuthGetIdTokenA(); +s32 PS4_SYSV_ABI sceNpAuthGetIdTokenV3(); +s32 PS4_SYSV_ABI sceNpAuthPollAsync(); +s32 PS4_SYSV_ABI sceNpAuthSetTimeout(); +s32 PS4_SYSV_ABI sceNpAuthWaitAsync(); + +void RegisterlibSceNpAuth(Core::Loader::SymbolsResolver* sym); +} // namespace Libraries::NpAuth \ No newline at end of file