From a84bb7eb88c2620f71113c046400caeed3f51cc5 Mon Sep 17 00:00:00 2001 From: pinumbernumber <1337rz@gmail.com> Date: Thu, 17 Apr 2014 12:03:44 +0100 Subject: [PATCH] Add support for the guide button to XInput --- .../ControllerInterface/XInput/XInput.cpp | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp index 860e12e46c..8b68fa80bc 100644 --- a/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp +++ b/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp @@ -1,6 +1,10 @@ #include "InputCommon/ControllerInterface/XInput/XInput.h" +#ifndef XINPUT_GAMEPAD_GUIDE +#define XINPUT_GAMEPAD_GUIDE 0x0400 +#endif + namespace ciface { namespace XInput @@ -24,6 +28,7 @@ static const struct { "Back", XINPUT_GAMEPAD_BACK }, { "Shoulder L", XINPUT_GAMEPAD_LEFT_SHOULDER }, { "Shoulder R", XINPUT_GAMEPAD_RIGHT_SHOULDER }, + { "Guide", XINPUT_GAMEPAD_GUIDE }, { "Thumb L", XINPUT_GAMEPAD_LEFT_THUMB }, { "Thumb R", XINPUT_GAMEPAD_RIGHT_THUMB } }; @@ -58,6 +63,8 @@ static XInputGetCapabilities_t PXInputGetCapabilities = nullptr; static XInputSetState_t PXInputSetState = nullptr; static XInputGetState_t PXInputGetState = nullptr; +static bool haveGuideButton = false; + void Init(std::vector& devices) { if (!hXInput) @@ -76,7 +83,15 @@ void Init(std::vector& devices) PXInputGetCapabilities = (XInputGetCapabilities_t)::GetProcAddress(hXInput, "XInputGetCapabilities"); PXInputSetState = (XInputSetState_t)::GetProcAddress(hXInput, "XInputSetState"); - PXInputGetState = (XInputGetState_t)::GetProcAddress(hXInput, "XInputGetState"); + + // Ordinal 100 is the same as XInputGetState, except it doesn't dummy out the guide + // button info. Try loading it and fall back if needed. + PXInputGetState = (XInputGetState_t)::GetProcAddress(hXInput, (LPCSTR)100); + if (PXInputGetState) + haveGuideButton = true; + else + PXInputGetState = (XInputGetState_t)::GetProcAddress(hXInput, "XInputGetState"); + if (!PXInputGetCapabilities || !PXInputSetState || !PXInputGetState) @@ -114,7 +129,9 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index) // get supported buttons for (int i = 0; i != sizeof(named_buttons)/sizeof(*named_buttons); ++i) { - if (named_buttons[i].bitmask & caps.Gamepad.wButtons) + // Guide button is never reported in caps + if ((named_buttons[i].bitmask & caps.Gamepad.wButtons) || + ((named_buttons[i].bitmask & XINPUT_GAMEPAD_GUIDE) && haveGuideButton)) AddInput(new Button(i, m_state_in.Gamepad.wButtons)); }