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,46 +109,37 @@ 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 AddInput(new Trigger(i, (&m_state_in.Gamepad.bLeftTrigger)[i], 255));
if ((&caps.Gamepad.bLeftTrigger)[i])
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 const SHORT& ax = (&m_state_in.Gamepad.sThumbLX)[i];
if ((&caps.Gamepad.sThumbLX)[i])
{
const SHORT& ax = (&m_state_in.Gamepad.sThumbLX)[i];
// each axis gets a negative and a positive input instance associated with it // each axis gets a negative and a positive input instance associated with it
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 AddOutput(new Motor(i, this, (&m_state_out.wLeftMotorSpeed)[i], 65535));
if ((&caps.Vibration.wLeftMotorSpeed)[i])
AddOutput(new Motor(i, this, (&m_state_out.wLeftMotorSpeed)[i], 65535));
} }
ZeroMemory(&m_state_in, sizeof(m_state_in)); ZeroMemory(&m_state_in, sizeof(m_state_in));