Merge pull request #5742 from ToadKing/fix-bad-controllers

Ignore capabilities reported by an XInput device
This commit is contained in:
Leo Lam 2017-08-17 03:42:02 +08:00 committed by GitHub
commit 918b0375e4

View File

@ -109,31 +109,25 @@ void DeInit()
Device::Device(const XINPUT_CAPABILITIES& caps, u8 index) : m_subtype(caps.SubType), m_index(index) Device::Device(const XINPUT_CAPABILITIES& caps, u8 index) : m_subtype(caps.SubType), m_index(index)
{ {
// XInputGetCaps seems to always claim all capabilities are supported // XInputGetCaps can be broken on some devices, so we'll just ignore it
// but I will leave all this stuff in, incase m$ fixes xinput up a bit // and assume all gamepad + vibration capabilities are supported
// get supported buttons // get supported buttons
for (int i = 0; i != sizeof(named_buttons) / sizeof(*named_buttons); ++i) for (int i = 0; i != sizeof(named_buttons) / sizeof(*named_buttons); ++i)
{ {
// Guide button is never reported in caps // Only add guide button if we have the 100 ordinal XInputGetState
if ((named_buttons[i].bitmask & caps.Gamepad.wButtons) || if (!(named_buttons[i].bitmask & XINPUT_GAMEPAD_GUIDE) || haveGuideButton)
((named_buttons[i].bitmask & XINPUT_GAMEPAD_GUIDE) && haveGuideButton))
AddInput(new Button(i, m_state_in.Gamepad.wButtons)); AddInput(new Button(i, m_state_in.Gamepad.wButtons));
} }
// get supported triggers // get supported triggers
for (int i = 0; i != sizeof(named_triggers) / sizeof(*named_triggers); ++i) for (int i = 0; i != sizeof(named_triggers) / sizeof(*named_triggers); ++i)
{ {
// BYTE val = (&caps.Gamepad.bLeftTrigger)[i]; // should be max value / MSDN lies
if ((&caps.Gamepad.bLeftTrigger)[i])
AddInput(new Trigger(i, (&m_state_in.Gamepad.bLeftTrigger)[i], 255)); AddInput(new Trigger(i, (&m_state_in.Gamepad.bLeftTrigger)[i], 255));
} }
// get supported axes // get supported axes
for (int i = 0; i != sizeof(named_axes) / sizeof(*named_axes); ++i) for (int i = 0; i != sizeof(named_axes) / sizeof(*named_axes); ++i)
{
// SHORT val = (&caps.Gamepad.sThumbLX)[i]; // xinput doesn't give the range / MSDN is a liar
if ((&caps.Gamepad.sThumbLX)[i])
{ {
const SHORT& ax = (&m_state_in.Gamepad.sThumbLX)[i]; const SHORT& ax = (&m_state_in.Gamepad.sThumbLX)[i];
@ -141,13 +135,10 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index) : m_subtype(caps.SubTy
AddInput(new Axis(i, ax, -32768)); AddInput(new Axis(i, ax, -32768));
AddInput(new Axis(i, ax, 32767)); AddInput(new Axis(i, ax, 32767));
} }
}
// get supported motors // get supported motors
for (int i = 0; i != sizeof(named_motors) / sizeof(*named_motors); ++i) for (int i = 0; i != sizeof(named_motors) / sizeof(*named_motors); ++i)
{ {
// WORD val = (&caps.Vibration.wLeftMotorSpeed)[i]; // should be max value / nope, more lies
if ((&caps.Vibration.wLeftMotorSpeed)[i])
AddOutput(new Motor(i, this, (&m_state_out.wLeftMotorSpeed)[i], 65535)); AddOutput(new Motor(i, this, (&m_state_out.wLeftMotorSpeed)[i], 65535));
} }