From 2b5aa0b1c3a40c6dfad059e5f53cd408ed25b7be Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Tue, 26 May 2026 17:54:16 +0200 Subject: [PATCH] Attempt to fix yet another input regression in some Unity games (#4480) * Set dummy GameController's m_connected to false * Remove this check and handle it differently * Save one reverse lookup on a map this is mostly irrelevant on performance * i have no clue so let's just log stuff * apparently this is the correct default * swap this to debug logging * the loathsome clang-formatter --- src/core/libraries/pad/pad.cpp | 32 ++++++++------------------------ src/input/controller.h | 5 ++++- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index 5fb65722d..537ffa1df 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -42,20 +42,6 @@ static u64 pad_handle_counter = 1; static std::unordered_map pad_handle_map{}; static std::unordered_map handle_to_controller_map{}; -static std::optional FindHandleKeyByHandle(s32 handle) { - for (const auto& [key, value] : pad_handle_map) { - if (value == handle) { - return key; - } - } - return std::nullopt; -} - -static bool IsUnavailableSpecialHandle(const std::optional& handle_key) { - return handle_key.has_value() && handle_key->device_class == ORBIS_PAD_PORT_TYPE_SPECIAL && - !EmulatorSettings.IsUsingSpecialPad(); -} - int PS4_SYSV_ABI scePadClose(s32 handle) { LOG_WARNING(Lib_Pad, "called, handle: {}", handle); if (handle_to_controller_map.erase(handle) == 0) { @@ -151,13 +137,10 @@ int PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadControllerIn if (it == handle_to_controller_map.end()) { return ORBIS_PAD_ERROR_INVALID_HANDLE; } - const auto handle_key = FindHandleKeyByHandle(handle); bool connected = false; int connected_count = 0; Input::State state{}; - if (!IsUnavailableSpecialHandle(handle_key)) { - it->second->ReadState(&state, &connected, &connected_count); - } + it->second->ReadState(&state, &connected, &connected_count); std::memset(pInfo, 0, sizeof(OrbisPadControllerInformation)); pInfo->touchPadInfo.pixelDensity = 1; @@ -167,14 +150,15 @@ int PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadControllerIn pInfo->stickInfo.deadZoneRight = 1; pInfo->connectionType = ORBIS_PAD_CONNECTION_TYPE_LOCAL; pInfo->connectedCount = static_cast(std::clamp(connected_count, 0, 0xff)); - pInfo->deviceClass = OrbisPadDeviceClass::Invalid; + pInfo->deviceClass = OrbisPadDeviceClass::Standard; pInfo->connected = connected; - if (handle_key.has_value() && handle_key->device_class == ORBIS_PAD_PORT_TYPE_STANDARD) { - pInfo->deviceClass = OrbisPadDeviceClass::Standard; - } else if (handle_key.has_value() && handle_key->device_class == ORBIS_PAD_PORT_TYPE_SPECIAL && - EmulatorSettings.IsUsingSpecialPad()) { - pInfo->deviceClass = (OrbisPadDeviceClass)EmulatorSettings.GetSpecialPadClass(); + if (connected) { + pInfo->deviceClass = EmulatorSettings.IsUsingSpecialPad() + ? (OrbisPadDeviceClass)EmulatorSettings.GetSpecialPadClass() + : OrbisPadDeviceClass::Standard; } + LOG_DEBUG(Lib_Pad, "c: {} cc: {}, ct: {}, dc: {}", pInfo->connected, pInfo->connectedCount, + pInfo->connectionType, std::to_underlying(pInfo->deviceClass)); return ORBIS_OK; } diff --git a/src/input/controller.h b/src/input/controller.h index a9ad7635c..ca414a062 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -178,7 +178,10 @@ class GameControllers { public: GameControllers() : controllers({new GameController(), new GameController(), new GameController(), - new GameController(), new GameController()}) {}; + new GameController(), new GameController()}) { + controllers[4]->m_connected = false; + controllers[4]->m_connected_count = 0; + }; virtual ~GameControllers() = default; GameController* operator[](const size_t& i) const { if (i > 4) {