Last active
December 6, 2023 10:28
-
-
Save DJm00n/0f0563702f6cf01e8812ebc760a78cf1 to your computer and use it in GitHub Desktop.
We can use a hidden func XInputGetCapabilitiesEx from XInput 1.4 (comes with Windows 8) to fetch gamepad VID/PID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct _XINPUT_CAPABILITIES_EX | |
{ | |
XINPUT_CAPABILITIES Capabilities; | |
WORD VendorId; | |
WORD ProductId; | |
WORD VersionNumber; | |
WORD unk1; | |
DWORD unk2; | |
} XINPUT_CAPABILITIES_EX, *PXINPUT_CAPABILITIES_EX; | |
// XInputGetCapabilitiesEx hidden function is available since Windows 8 version of XInput1_4.dll | |
DWORD XInputGetCapabilitiesEx(DWORD dwUserIndex, PXINPUT_CAPABILITIES_EX pCapabilitiesEx) | |
{ | |
DWORD(WINAPI* XInputGetCapabilitiesExFunc)(DWORD unk1, DWORD dwUserIndex, DWORD dwFlags, PXINPUT_CAPABILITIES_EX pCapabilities); | |
XInputGetCapabilitiesExFunc = reinterpret_cast<decltype(XInputGetCapabilitiesExFunc)>(::GetProcAddress(::GetModuleHandleW(L"XInput1_4.dll"), (LPCSTR)108)); | |
if (!XInputGetCapabilitiesExFunc) | |
return ERROR_INVALID_FUNCTION; | |
return XInputGetCapabilitiesExFunc(1, dwUserIndex, 0, pCapabilitiesEx); | |
} | |
.... | |
XINPUT_CAPABILITIES_EX caps {}; | |
XInputGetCapabilitiesEx(m_UserIndex, &caps); | |
// Fixup for Wireless Xbox 360 Controller | |
if (caps.ProductId == 0 && caps.Capabilities.Flags & /*XINPUT_CAPS_WIRELESS*/0x0002) | |
{ | |
caps.VendorId = 0x045E; | |
caps.ProductId = 0x02A1; | |
} | |
m_VendorId = caps.VendorId; | |
m_ProductId = caps.ProductId; | |
// Known controller VID/PID list: https://github.com/libsdl-org/SDL/blob/main/src/joystick/controller_type.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment