Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/libs/prx/libSceNpManager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if(BUILD_TESTING)
endif()
add_test_executable(guest_np_manager_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpManager.cpp)
target_include_directories(guest_np_manager_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_np_manager_tests PRIVATE libSceNpManager libc)
target_link_libraries(guest_np_manager_tests PRIVATE libSceNpManager libSceUserService libc)
configure_windows_unwind(guest_np_manager_tests)
add_test(NAME guest_np_manager COMMAND guest_np_manager_tests)
if(WIN32)
Expand Down
3 changes: 3 additions & 0 deletions core/libs/prx/libSceUserService/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ int APS5_VABI sceUserServiceGetTraditionalChineseInputType(int user_id, int32_t*
}

int APS5_VABI sceUserServiceGetNpAccountId(int user_id, uint64_t* account_id) {
if (!initialized.load()) {
return USER_SERVICE_ERROR_NOT_INITIALIZED;
}
if (account_id == nullptr) {
return USER_SERVICE_ERROR_INVALID_ARGUMENT;
}
Expand Down
2 changes: 2 additions & 0 deletions core/libs/tests/GuestNpManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,8 @@ void CheckValueClasses() {
constexpr int AccountIdMissing = static_cast<int>(0x80559E2Bu);
constexpr int GuestUser = 0x20000000;

Require(sceUserServiceInitialize(nullptr) == 0, "the value classes need an initialized user service");

NpOnlineIdObject onlineId;
_ZN3sce2np10NpOnlineIdC1Ev(&onlineId);
Require(_ZNK3sce2np10NpOnlineId7IsEmptyEv(&onlineId), "a default online id must be empty");
Expand Down
7 changes: 7 additions & 0 deletions core/libs/tests/GuestUserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ void VerifyLoggedInUser(int userId) {
}

int main() {
std::uint64_t uninitialisedAccountId = 0xdeadbeefu;
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, &uninitialisedAccountId) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(uninitialisedAccountId == 0xdeadbeefu);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(sceUserServiceGetNpAccountId(123, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(sceUserServiceInitialize(nullptr) == USER_SERVICE_OK);

Require(sceUserServiceGetForegroundUser(nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
int foreground = -1;
Require(sceUserServiceGetForegroundUser(&foreground) == USER_SERVICE_OK);
Expand Down
14 changes: 7 additions & 7 deletions core/libs/tests/GuestUserServiceAccountNameLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void TestFourUserLoginLimitsAndTransitions() {
}

void TestNpAccountIdQueryBounds() {
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);

const int invalidIds[] = {
USER_SERVICE_INITIAL_USER_ID - 1,
Expand All @@ -175,14 +175,14 @@ void TestNpAccountIdQueryBounds() {
};
for (int id : invalidIds) {
uint64_t accountId = 0xCAFEBABE;
Require(sceUserServiceGetNpAccountId(id, &accountId) == USER_SERVICE_ERROR_UNKNOWN_USER);
Require(sceUserServiceGetNpAccountId(id, &accountId) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(accountId == 0xCAFEBABE);
Require(sceUserServiceGetNpAccountId(id, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(id, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);
}

uint64_t validAccountId = 0xCAFEBABE;
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, &validAccountId) == USER_SERVICE_OK);
Require(validAccountId == 0);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, &validAccountId) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(validAccountId == 0xCAFEBABE);
}

void TestNullPointerValidation() {
Expand All @@ -198,7 +198,7 @@ void TestNullPointerValidation() {
Require(sceUserServiceGetKeyboardType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetJapaneseInputType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetTraditionalChineseInputType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(sceUserServiceGetIsSpartacusEnabled(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);

for (int invalidId : {0, -1, USER_SERVICE_USER_ID_INVALID, 123}) {
Expand All @@ -208,7 +208,7 @@ void TestNullPointerValidation() {
Require(sceUserServiceGetKeyboardType(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetJapaneseInputType(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetTraditionalChineseInputType(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(invalidId, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(sceUserServiceGetIsSpartacusEnabled(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/libs/tests/GuestUserServiceAgeLevelGuestBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void TestUserQueryBoundsAndNulls() {
Require(sceUserServiceGetKeyboardType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetJapaneseInputType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetTraditionalChineseInputType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(sceUserServiceGetIsSpartacusEnabled(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);

char name[32]{};
Expand Down Expand Up @@ -192,7 +192,7 @@ void TestUserQueryBoundsAndNulls() {
int32_t zhType = -1;
Require(sceUserServiceGetTraditionalChineseInputType(invalidId, &zhType) == USER_SERVICE_ERROR_UNKNOWN_USER);
uint64_t accountId = 0xDEADBEEF;
Require(sceUserServiceGetNpAccountId(invalidId, &accountId) == USER_SERVICE_ERROR_UNKNOWN_USER);
Require(sceUserServiceGetNpAccountId(invalidId, &accountId) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(accountId == 0xDEADBEEF);
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/libs/tests/GuestUserServiceKratos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void TestInvalidUserIdRejection() {
Require(zhType == -1);

uint64_t accountId = 0xDEADBEEF;
Require(sceUserServiceGetNpAccountId(invalidId, &accountId) == USER_SERVICE_ERROR_UNKNOWN_USER);
Require(sceUserServiceGetNpAccountId(invalidId, &accountId) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(accountId == 0xDEADBEEF);
}
}
Expand All @@ -111,7 +111,7 @@ void TestNullOutputPointers() {
Require(sceUserServiceGetKeyboardType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetJapaneseInputType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetTraditionalChineseInputType(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);

for (int invalidId : {0, -1, USER_SERVICE_USER_ID_INVALID, 123}) {
Require(sceUserServiceGetUserNumber(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Expand All @@ -120,7 +120,7 @@ void TestNullOutputPointers() {
Require(sceUserServiceGetKeyboardType(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetJapaneseInputType(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetTraditionalChineseInputType(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(invalidId, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);
}
}

Expand Down
9 changes: 7 additions & 2 deletions core/libs/tests/GuestUserServiceProfilesBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ void TestInvalidUserIdRejection() {
Require(sceUserServiceGetPlatformPrivacyWs1(invalidId, nullptr) == USER_SERVICE_ERROR_NOT_LOGGED_IN);

uint64_t accountId = 0xDEADBEEF;
Require(sceUserServiceGetNpAccountId(invalidId, &accountId) == USER_SERVICE_ERROR_UNKNOWN_USER);
Require(sceUserServiceGetNpAccountId(invalidId, &accountId) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(accountId == 0xDEADBEEF);
Require(sceUserServiceGetNpAccountId(invalidId, nullptr) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Require(sceUserServiceGetNpAccountId(invalidId, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);

UserServiceGamePresets presets{};
presets.difficulty = 0x5A;
Expand Down Expand Up @@ -184,6 +184,11 @@ void TestLoginStateTransitions() {
UserServiceLoginUserIdList uninitList{};
Require(sceUserServiceGetLoginUserIdList(&uninitList) == USER_SERVICE_ERROR_NOT_INITIALIZED);

uint64_t uninitAccountId = 0xDEAD;
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, &uninitAccountId) == USER_SERVICE_ERROR_NOT_INITIALIZED);
Require(uninitAccountId == 0xDEAD);
Require(sceUserServiceGetNpAccountId(USER_SERVICE_INITIAL_USER_ID, nullptr) == USER_SERVICE_ERROR_NOT_INITIALIZED);

UserServiceInitParam badParam{};
badParam.priority = USER_SERVICE_THREAD_PRIORITY_MIN - 1;
Require(sceUserServiceInitialize(&badParam) == USER_SERVICE_ERROR_INVALID_ARGUMENT);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# libSceUserService

## change [sceUserServiceGetNpAccountId]

- [sceUserServiceGetNpAccountId](../../../core/libs/prx/libSceUserService/Export.cpp) (libSceUserService) - the account id for a logged-in user with no linked PSN account is assumed to be 0 with success; libSceNpManager's `sceNpGetAccountIdA` answers the same question with `SCE_NP_ERROR_SIGNED_OUT`. Console measurement on PS4 Pro firmware 10.71 confirms a user that is not logged in returns `0x80960105` (`USER_SERVICE_ERROR_UNKNOWN_USER`) and leaves the output untouched, differing from `sceUserServiceGetUserName`. Firmware 13.42's `libSceUserService.sprx` returns `0x80960002` while it is not initialized and `0x80960005` for a null output before it looks at the user, both modelled here ([disassembly and a native run with stubbed imports](https://github.com/boykopovar/AnyPS5/pull/12165#issuecomment-6512375278), not measured on a console).