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)
{
// XInputGetCaps seems to always claim all capabilities are supported
// but I will leave all this stuff in, incase m$ fixes xinput up a bit
// XInputGetCaps can be broken on some devices, so we'll just ignore it
// and assume all gamepad + vibration capabilities are supported
// get supported buttons
for (int i = 0; i != sizeof(named_buttons) / sizeof(*named_buttons); ++i)
{
// Guide button is never reported in caps
if ((named_buttons[i].bitmask & caps.Gamepad.wButtons) ||
((named_buttons[i].bitmask & XINPUT_GAMEPAD_GUIDE) && haveGuideButton))
// Only add guide button if we have the 100 ordinal XInputGetState
if (!(named_buttons[i].bitmask & XINPUT_GAMEPAD_GUIDE) || haveGuideButton)
AddInput(new Button(i, m_state_in.Gamepad.wButtons));
}
// get supported triggers
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
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];
// each axis gets a negative and a positive input instance associated with it
AddInput(new Axis(i, ax, -32768));
AddInput(new Axis(i, ax, 32767));
}
// each axis gets a negative and a positive input instance associated with it
AddInput(new Axis(i, ax, -32768));
AddInput(new Axis(i, ax, 32767));
}
// get supported motors
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));
}
ZeroMemory(&m_state_in, sizeof(m_state_in));