From e0320352f15f9902783fb8373ad2376c99ef1503 Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Sat, 26 Apr 2025 09:38:23 +0200 Subject: [PATCH] Good enough --- src/core/libraries/system/userservice.cpp | 12 +++++++++--- src/input/controller.cpp | 12 ++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/core/libraries/system/userservice.cpp b/src/core/libraries/system/userservice.cpp index 3f737e0a4..df6eeee14 100644 --- a/src/core/libraries/system/userservice.cpp +++ b/src/core/libraries/system/userservice.cpp @@ -580,15 +580,21 @@ int PS4_SYSV_ABI sceUserServiceGetLoginFlag() { } s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(OrbisUserServiceLoginUserIdList* userIdList) { - LOG_DEBUG(Lib_UserService, "called"); + // LOG_DEBUG(Lib_UserService, "called"); if (userIdList == nullptr) { LOG_ERROR(Lib_UserService, "user_id is null"); return ORBIS_USER_SERVICE_ERROR_INVALID_ARGUMENT; } // TODO only first user, do the others as well auto controllers = *Common::Singleton::Instance(); - for (int i = 0; i < 4; i++) { - userIdList->user_id[i] = controllers[i]->user_id; + int li = 0; + for (int ci = 0; ci < 4; ci++) { + if (controllers[ci]->user_id != -1) { + userIdList->user_id[li++] = controllers[ci]->user_id; + } + } + for (; li < 4; li++) { + userIdList->user_id[li] = -1; } return ORBIS_OK; } diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 63631653c..911805b13 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -269,6 +269,9 @@ void GameControllers::TryOpenSDLControllers(GameControllers& controllers) { SDL_CloseGamepad(pad); controllers[i]->m_sdl_gamepad = nullptr; controllers[i]->user_id = -1; + slot_taken[i] = false; + } else { + controllers[i]->player_index = i; } } } @@ -285,7 +288,8 @@ void GameControllers::TryOpenSDLControllers(GameControllers& controllers) { for (int i = 0; i < 4; i++) { if (!slot_taken[i]) { controllers[i]->m_sdl_gamepad = pad; - LOG_INFO(Input, "Gamepad registered for slot {}! Handle: {}", i, (void*)pad); + LOG_INFO(Input, "Gamepad registered for slot {}! Handle: {}", i, + SDL_GetGamepadID(pad)); controllers[i]->user_id = i + 1; slot_taken[i] = true; controllers[i]->player_index = i; @@ -346,16 +350,12 @@ u32 GameController::Poll() { u8 GameControllers::GetGamepadIndexFromJoystickId(SDL_JoystickID id) { auto& controllers = *Common::Singleton::Instance(); - auto gamepad = SDL_GetGamepadFromID(id); - if (!gamepad) { - UNREACHABLE_MSG("Gamepad is null!"); - } for (int i = 0; i < 4; i++) { if (SDL_GetGamepadID(controllers[i]->m_sdl_gamepad) == id) { return controllers[i]->player_index; } } - UNREACHABLE_MSG("Gamepad not registered! Handle: {}", (void*)gamepad); + UNREACHABLE_MSG("Handle {} is not registered!", id); } } // namespace Input