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
This commit is contained in:
kalaposfos13 2026-05-26 17:54:16 +02:00 committed by GitHub
parent 0f094cb6c8
commit 2b5aa0b1c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 25 deletions

View File

@ -42,20 +42,6 @@ static u64 pad_handle_counter = 1;
static std::unordered_map<HandleKey, s32, HandleKeyHash> pad_handle_map{};
static std::unordered_map<s32, GameController*> handle_to_controller_map{};
static std::optional<HandleKey> 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<HandleKey>& 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<u8>(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;
}

View File

@ -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) {