From aea7918433b2797bd311c30dd548f59f34820eef Mon Sep 17 00:00:00 2001 From: Etaash Mathamsetty Date: Sun, 10 Dec 2023 15:29:32 -0500 Subject: [PATCH] xinput: Implement XInputGetCapabilitiesEx. --- dlls/xinput1_3/main.c | 30 ++++++++++++++++++++++++++++++ dlls/xinput1_4/xinput1_4.spec | 1 + include/xinput.h | 11 +++++++++++ 3 files changed, 42 insertions(+) diff --git a/dlls/xinput1_3/main.c b/dlls/xinput1_3/main.c index e69553fba16..3f0cedab5cb 100644 --- a/dlls/xinput1_3/main.c +++ b/dlls/xinput1_3/main.c @@ -1129,3 +1129,33 @@ DWORD WINAPI DECLSPEC_HOTPATCH XInputGetBatteryInformation(DWORD index, BYTE typ return ERROR_NOT_SUPPORTED; } + +DWORD WINAPI DECLSPEC_HOTPATCH XInputGetCapabilitiesEx(DWORD unk, DWORD index, DWORD flags, XINPUT_CAPABILITIES_EX *caps) +{ + HIDD_ATTRIBUTES attr; + DWORD ret = ERROR_SUCCESS; + + TRACE("unk %lu, index %lu, flags %#lx, capabilities %p.\n", unk, index, flags, caps); + + start_update_thread(); + + if (index >= XUSER_MAX_COUNT) return ERROR_BAD_ARGUMENTS; + + if (!controller_lock(&controllers[index])) return ERROR_DEVICE_NOT_CONNECTED; + + if (flags & XINPUT_FLAG_GAMEPAD && controllers[index].caps.SubType != XINPUT_DEVSUBTYPE_GAMEPAD) + ret = ERROR_DEVICE_NOT_CONNECTED; + else if (!HidD_GetAttributes(controllers[index].device, &attr)) + ret = ERROR_DEVICE_NOT_CONNECTED; + else + { + caps->Capabilities = controllers[index].caps; + caps->VendorId = attr.VendorID; + caps->ProductId = attr.ProductID; + caps->VersionNumber = attr.VersionNumber; + } + + controller_unlock(&controllers[index]); + + return ret; +} diff --git a/dlls/xinput1_4/xinput1_4.spec b/dlls/xinput1_4/xinput1_4.spec index 8c3f4c0cd73..22c511237dd 100644 --- a/dlls/xinput1_4/xinput1_4.spec +++ b/dlls/xinput1_4/xinput1_4.spec @@ -7,3 +7,4 @@ 8 stdcall XInputGetKeystroke(long long ptr) 10 stub XInputGetAudioDeviceIds(long ptr ptr ptr ptr) 100 stdcall XInputGetStateEx(long ptr) +108 stdcall XInputGetCapabilitiesEx(long long long ptr) diff --git a/include/xinput.h b/include/xinput.h index f7c291630cb..c1e1ab3d39c 100644 --- a/include/xinput.h +++ b/include/xinput.h @@ -210,6 +210,16 @@ typedef struct _XINPUT_CAPABILITIES { XINPUT_VIBRATION Vibration; } XINPUT_CAPABILITIES, *PXINPUT_CAPABILITIES; +typedef struct _XINPUT_CAPABILITIES_EX +{ + XINPUT_CAPABILITIES Capabilities; + WORD VendorId; + WORD ProductId; + WORD VersionNumber; + WORD unk1; + DWORD unk2; +} XINPUT_CAPABILITIES_EX, *PXINPUT_CAPABILITIES_EX; + /* * Defines the structure for a joystick input event which is * retrieved using the function XInputGetKeystroke @@ -237,6 +247,7 @@ DWORD WINAPI XInputSetState(DWORD, XINPUT_VIBRATION*); DWORD WINAPI XInputGetState(DWORD, XINPUT_STATE*); DWORD WINAPI XInputGetKeystroke(DWORD, DWORD, PXINPUT_KEYSTROKE); DWORD WINAPI XInputGetCapabilities(DWORD, DWORD, XINPUT_CAPABILITIES*); +DWORD WINAPI XInputGetCapabilitiesEx(DWORD, DWORD, DWORD, XINPUT_CAPABILITIES_EX*); DWORD WINAPI XInputGetDSoundAudioDeviceGuids(DWORD, GUID*, GUID*); DWORD WINAPI XInputGetBatteryInformation(DWORD, BYTE, XINPUT_BATTERY_INFORMATION*);