From 834652922a0953a17cbd8fa5063539cf0321dc1b Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sat, 27 Feb 2016 11:50:55 +0000 Subject: [PATCH 1/4] lilypad:windows:xinput: Only support 1.3 and 1.4 1.3 is used on Vista and 7, so we don't need earlier versions. --- plugins/LilyPad/XInputEnum.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/LilyPad/XInputEnum.cpp b/plugins/LilyPad/XInputEnum.cpp index 5e039b46e2..3f72441f0a 100644 --- a/plugins/LilyPad/XInputEnum.cpp +++ b/plugins/LilyPad/XInputEnum.cpp @@ -16,6 +16,7 @@ */ #include "Global.h" +#include #include #include "VKey.h" #include "InputManager.h" @@ -248,18 +249,21 @@ public: }; void EnumXInputDevices() { - int i; wchar_t temp[30]; if (!pXInputSetState) { // Also used as flag to indicute XInput not installed, so // don't repeatedly try to load it. if (pXInputEnable) return; - HMODULE hMod = 0; - for (i=3; i>= 0; i--) { - wsprintfW(temp, L"xinput1_%i.dll", i); - if (hMod = LoadLibraryW(temp)) break; + const DWORD flags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32; + + // Prefer XInput 1.3 since SCP only has an XInput 1.3 wrapper right now. + // FIXME: Missing FreeLibrary call. + HMODULE hMod = LoadLibraryEx(L"xinput1_3.dll", nullptr, flags); + if (hMod == nullptr && IsWindows8OrGreater()) { + hMod = LoadLibraryEx(L"XInput1_4.dll", nullptr, flags); } + if (hMod) { if ((pXInputEnable = (_XInputEnable) GetProcAddress(hMod, "XInputEnable")) && ((pXInputGetStateEx = (_XInputGetStateEx) GetProcAddress(hMod, (LPCSTR)100)) || // Try Ex version first @@ -274,7 +278,7 @@ void EnumXInputDevices() { } } pXInputEnable(1); - for (i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { wsprintfW(temp, L"XInput Pad %i", i); dm->AddDevice(new XInputDevice(i, temp)); } From 02ea7d390c14e089060a6877763d291602c3519c Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sat, 27 Feb 2016 12:04:50 +0000 Subject: [PATCH 2/4] lilypad:windows: Switch to includes from Windows SDK --- plugins/LilyPad/LilyPad.vcxproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/LilyPad/LilyPad.vcxproj b/plugins/LilyPad/LilyPad.vcxproj index 7b664eae67..d7a396423a 100644 --- a/plugins/LilyPad/LilyPad.vcxproj +++ b/plugins/LilyPad/LilyPad.vcxproj @@ -99,9 +99,6 @@ AllRules.ruleset - $(DXSDK_DIR)Lib\x86;$(LibraryPath) - $(DXSDK_DIR)Lib\x64;$(LibraryPath) - $(DXSDK_DIR)include;$(IncludePath) From 13bb7cf30aacd7cabcc0147d66d70f92721a2fbd Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Mon, 29 Feb 2016 00:46:48 +0000 Subject: [PATCH 3/4] xpad: Support both XInput 1.3 and 1.4 --- plugins/xpad/xpad.cpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/plugins/xpad/xpad.cpp b/plugins/xpad/xpad.cpp index f75dd5389a..eb390bf8af 100644 --- a/plugins/xpad/xpad.cpp +++ b/plugins/xpad/xpad.cpp @@ -21,8 +21,13 @@ #include "stdafx.h" #include "xpad.h" +#include static HMODULE s_hModule; +static HMODULE s_xInputDll; +static decltype(&XInputEnable) pXInputEnable; +static decltype(&XInputGetState) pXInputGetState; +static decltype(&XInputSetState) pXInputSetState; BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { @@ -133,7 +138,7 @@ public: { memset(&m_state, 0, sizeof(m_state)); - m_connected = XInputGetState(m_pad, &m_state) == S_OK; // ERROR_DEVICE_NOT_CONNECTED is not an error, SUCCEEDED(...) won't work here + m_connected = pXInputGetState(m_pad, &m_state) == S_OK; // ERROR_DEVICE_NOT_CONNECTED is not an error, SUCCEEDED(...) won't work here m_lastpoll = now; } @@ -147,7 +152,7 @@ public: { if(m_vibration.wLeftMotorSpeed != vibration.wLeftMotorSpeed || m_vibration.wRightMotorSpeed != vibration.wRightMotorSpeed) { - XInputSetState(m_pad, &vibration); + pXInputSetState(m_pad, &vibration); m_vibration = vibration; } @@ -634,16 +639,41 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) EXPORT_C_(UINT32) PADinit(UINT32 flags) { + DWORD loadFlags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32; + + s_xInputDll = LoadLibraryEx(L"xinput1_3.dll", nullptr, loadFlags); + if (s_xInputDll == nullptr && IsWindows8OrGreater()) + { + s_xInputDll = LoadLibraryEx(L"XInput1_4.dll", nullptr, loadFlags); + } + if (s_xInputDll == nullptr) + { + return 1; + } + + if (!(pXInputEnable = reinterpret_cast(GetProcAddress(s_xInputDll, "XInputEnable"))) + || !(pXInputSetState = reinterpret_cast(GetProcAddress(s_xInputDll, "XInputSetState"))) + || !(pXInputGetState = reinterpret_cast(GetProcAddress(s_xInputDll, "XInputGetState")))) + { + FreeLibrary(s_xInputDll); + s_xInputDll = nullptr; + return 1; + } return 0; } EXPORT_C PADshutdown() { + if (s_xInputDll) + { + FreeLibrary(s_xInputDll); + s_xInputDll = nullptr; + } } EXPORT_C_(UINT32) PADopen(void* pDsp) { - XInputEnable(TRUE); + pXInputEnable(TRUE); if(s_nRefs == 0) { @@ -671,7 +701,7 @@ EXPORT_C PADclose() } } - XInputEnable(FALSE); + pXInputEnable(FALSE); } EXPORT_C_(UINT32) CALLBACK PADquery() From a80a7175f35e1b70082dc27117bfe814f1c7b549 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Mon, 29 Feb 2016 00:57:21 +0000 Subject: [PATCH 4/4] xpad: Use the Windows SDK and remove unneeded dependencies --- plugins/xpad/stdafx.h | 1 - plugins/xpad/vsprops/common.props | 4 ---- plugins/xpad/xpad.cpp | 4 ++++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/xpad/stdafx.h b/plugins/xpad/stdafx.h index 79ef23aede..ca7195e206 100644 --- a/plugins/xpad/stdafx.h +++ b/plugins/xpad/stdafx.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include diff --git a/plugins/xpad/vsprops/common.props b/plugins/xpad/vsprops/common.props index 2698a1f853..613c944fc5 100644 --- a/plugins/xpad/vsprops/common.props +++ b/plugins/xpad/vsprops/common.props @@ -12,16 +12,12 @@ Level4 ProgramDatabase 4995;4324;%(DisableSpecificWarnings) - $(DXSDK_DIR)include;%(AdditionalIncludeDirectories) - d3d10.lib;d3dx10.lib;d3d9.lib;d3dx9.lib;dxguid.lib;winmm.lib;strmiids.lib;xinput.lib;%(AdditionalDependencies) ..\..\bin\plugins\$(ProjectName).dll - d3d9.dll;d3dx9_43.dll;d3d10.dll;d3dx10_43.dll;%(DelayLoadDLLs) true Windows false - $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories) \ No newline at end of file diff --git a/plugins/xpad/xpad.cpp b/plugins/xpad/xpad.cpp index eb390bf8af..4da8b77816 100644 --- a/plugins/xpad/xpad.cpp +++ b/plugins/xpad/xpad.cpp @@ -23,6 +23,10 @@ #include "xpad.h" #include +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0602 // Required for XInputEnable definition +#include + static HMODULE s_hModule; static HMODULE s_xInputDll; static decltype(&XInputEnable) pXInputEnable;