XInput: Do not use XINPUT_CAPS_FFB_SUPPORTED

There are several reasons for this:
1. XINPUT_CAPS_FFB_SUPPORTED flag was introduced in Windows 8,
   and therefore only supported by XInput 1.4
2. Despite the name, this flag does NOT indicate whether normal rumble
   is supported. This flag is reserved for more complex force feedback,
   and according to MSDN it may have went unused on Windows.

This fixes a future (the method is not used yet) bug where
XInputControllerInterface::GetControllerRumbleMotorCount would
erroreously report no rumble support.
This commit is contained in:
Silent 2020-08-22 22:46:12 +02:00
parent 136a9d60e9
commit 1c4bbc8cde
No known key found for this signature in database
GPG key ID: AE53149BB0C45AF1
2 changed files with 2 additions and 19 deletions

View file

@ -39,11 +39,9 @@ bool XInputControllerInterface::Initialize(CommonHostInterface* host_interface)
reinterpret_cast<decltype(m_xinput_get_state)>(GetProcAddress(m_xinput_module, reinterpret_cast<LPCSTR>(100)));
if (!m_xinput_get_state)
reinterpret_cast<decltype(m_xinput_get_state)>(GetProcAddress(m_xinput_module, "XInputGetState"));
m_xinput_get_capabilities =
reinterpret_cast<decltype(m_xinput_get_capabilities)>(GetProcAddress(m_xinput_module, "XInputGetCapabilities"));
m_xinput_set_state =
reinterpret_cast<decltype(m_xinput_set_state)>(GetProcAddress(m_xinput_module, "XInputSetState"));
if (!m_xinput_get_state || !m_xinput_get_capabilities || !m_xinput_set_state)
if (!m_xinput_get_state || !m_xinput_set_state)
{
Log_ErrorPrintf("Failed to get XInput function pointers.");
return false;
@ -72,7 +70,6 @@ void XInputControllerInterface::PollEvents()
if (!cd.connected)
{
cd.connected = true;
UpdateCapabilities(i);
OnControllerConnected(static_cast<int>(i));
}
@ -155,17 +152,6 @@ void XInputControllerInterface::CheckForStateChanges(u32 index, const XINPUT_STA
}
}
void XInputControllerInterface::UpdateCapabilities(u32 index)
{
ControllerData& cd = m_controllers[index];
XINPUT_CAPABILITIES caps = {};
m_xinput_get_capabilities(index, 0, &caps);
cd.supports_rumble = (caps.Flags & 0x0001 /* XINPUT_CAPS_FFB_SUPPORTED */);
Log_InfoPrintf("Controller %u: Rumble is %s", index, cd.supports_rumble ? "supported" : "not supported");
}
void XInputControllerInterface::ClearBindings()
{
for (auto& it : m_controllers)
@ -277,7 +263,7 @@ u32 XInputControllerInterface::GetControllerRumbleMotorCount(int controller_inde
if (static_cast<u32>(controller_index) >= XUSER_MAX_COUNT || !m_controllers[controller_index].connected)
return 0;
return m_controllers[controller_index].supports_rumble ? NUM_RUMBLE_MOTORS : 0;
return NUM_RUMBLE_MOTORS;
}
void XInputControllerInterface::SetControllerRumbleStrength(int controller_index, const float* strengths,

View file

@ -60,7 +60,6 @@ private:
{
XINPUT_STATE last_state = {};
bool connected = false;
bool supports_rumble = false;
// Scaling value of 1.30f to 1.40f recommended when using recent controllers
float axis_scale = 1.00f;
@ -74,7 +73,6 @@ private:
using ControllerDataArray = std::array<ControllerData, XUSER_MAX_COUNT>;
void CheckForStateChanges(u32 index, const XINPUT_STATE& new_state);
void UpdateCapabilities(u32 index);
bool HandleAxisEvent(u32 index, Axis axis, s32 value);
bool HandleButtonEvent(u32 index, u32 button, bool pressed);
@ -82,7 +80,6 @@ private:
HMODULE m_xinput_module{};
DWORD(WINAPI* m_xinput_get_state)(DWORD, XINPUT_STATE*);
DWORD(WINAPI* m_xinput_get_capabilities)(DWORD, DWORD, XINPUT_CAPABILITIES*);
DWORD(WINAPI* m_xinput_set_state)(DWORD, XINPUT_VIBRATION*);
std::mutex m_event_intercept_mutex;
Hook::Callback m_event_intercept_callback;