2016-11-05 16:51:55 +01:00
|
|
|
#include <Windows.h>
|
|
|
|
|
#include <Xinput.h>
|
|
|
|
|
|
2017-05-12 20:40:08 +02:00
|
|
|
bool GetOculusBasePath(PWCHAR path, DWORD length)
|
|
|
|
|
{
|
|
|
|
|
LONG error = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
HKEY oculusKey;
|
|
|
|
|
error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Oculus VR, LLC\\Oculus", 0, KEY_READ | KEY_WOW64_32KEY, &oculusKey);
|
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
|
return false;
|
|
|
|
|
error = RegQueryValueEx(oculusKey, L"Base", NULL, NULL, (PBYTE)path, &length);
|
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
|
return false;
|
|
|
|
|
RegCloseKey(oculusKey);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-05 16:51:55 +01:00
|
|
|
HMODULE GetXInputModule()
|
|
|
|
|
{
|
|
|
|
|
static HMODULE module = NULL;
|
|
|
|
|
if (module)
|
|
|
|
|
return module;
|
|
|
|
|
|
|
|
|
|
wchar_t XInputPath[MAX_PATH];
|
2017-05-21 14:00:39 +02:00
|
|
|
if (GetOculusBasePath(XInputPath, MAX_PATH))
|
|
|
|
|
{
|
|
|
|
|
wcsncat(XInputPath, L"Support\\oculus-runtime\\xinput1_3.dll", MAX_PATH);
|
|
|
|
|
module = LoadLibraryW(XInputPath);
|
|
|
|
|
if (module)
|
|
|
|
|
return module;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 04:26:54 +02:00
|
|
|
if (GetWindowsDirectory(XInputPath, MAX_PATH))
|
|
|
|
|
{
|
|
|
|
|
wcsncat(XInputPath, L"\\System32\\xinput1_3.dll", MAX_PATH);
|
|
|
|
|
module = LoadLibraryW(XInputPath);
|
|
|
|
|
}
|
2016-11-05 16:51:55 +01:00
|
|
|
return module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef DWORD(__stdcall* _XInputGetState)(DWORD dwUserIndex, XINPUT_STATE* pState);
|
|
|
|
|
DWORD WINAPI XInputGetState(DWORD dwUserIndex, XINPUT_STATE* pState)
|
|
|
|
|
{
|
2017-03-20 21:20:18 +01:00
|
|
|
static _XInputGetState func = NULL;
|
2016-11-05 16:51:55 +01:00
|
|
|
if (!func)
|
|
|
|
|
func = (_XInputGetState)GetProcAddress(GetXInputModule(), "XInputGetState");
|
|
|
|
|
return func(dwUserIndex, pState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef DWORD(__stdcall* _XInputSetState)(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration);
|
|
|
|
|
DWORD WINAPI XInputSetState(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration)
|
|
|
|
|
{
|
2017-03-20 21:20:18 +01:00
|
|
|
static _XInputSetState func = NULL;
|
2016-11-05 16:51:55 +01:00
|
|
|
if (!func)
|
|
|
|
|
func = (_XInputSetState)GetProcAddress(GetXInputModule(), "XInputSetState");
|
|
|
|
|
return func(dwUserIndex, pVibration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef DWORD(__stdcall* _XInputGetCapabilities)(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities);
|
|
|
|
|
DWORD WINAPI XInputGetCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities)
|
|
|
|
|
{
|
2017-03-20 21:20:18 +01:00
|
|
|
static _XInputGetCapabilities func = NULL;
|
2016-11-05 16:51:55 +01:00
|
|
|
if (!func)
|
|
|
|
|
func = (_XInputGetCapabilities)GetProcAddress(GetXInputModule(), "XInputGetCapabilities");
|
|
|
|
|
return func(dwUserIndex, dwFlags, pCapabilities);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 22:21:50 +02:00
|
|
|
#pragma warning(push)
|
|
|
|
|
#pragma warning(disable:4995)
|
2016-11-05 16:51:55 +01:00
|
|
|
typedef void(__stdcall* _XInputEnable)(BOOL enable);
|
|
|
|
|
void WINAPI XInputEnable(BOOL enable)
|
|
|
|
|
{
|
2017-03-20 21:20:18 +01:00
|
|
|
static _XInputEnable func = NULL;
|
2016-11-05 16:51:55 +01:00
|
|
|
if (!func)
|
|
|
|
|
func = (_XInputEnable)GetProcAddress(GetXInputModule(), "XInputEnable");
|
|
|
|
|
return func(enable);
|
|
|
|
|
}
|
2017-08-20 22:21:50 +02:00
|
|
|
#pragma warning(pop)
|
2016-11-05 16:51:55 +01:00
|
|
|
|
|
|
|
|
typedef DWORD(__stdcall* _XInputGetDSoundAudioDeviceGuids)(DWORD dwUserIndex, GUID* pDSoundRenderGuid, GUID* pDSoundCaptureGuid);
|
|
|
|
|
DWORD WINAPI XInputGetDSoundAudioDeviceGuids(DWORD dwUserIndex, GUID* pDSoundRenderGuid, GUID* pDSoundCaptureGuid)
|
|
|
|
|
{
|
2017-03-20 21:20:18 +01:00
|
|
|
static _XInputGetDSoundAudioDeviceGuids func = NULL;
|
2016-11-05 16:51:55 +01:00
|
|
|
if (!func)
|
|
|
|
|
func = (_XInputGetDSoundAudioDeviceGuids)GetProcAddress(GetXInputModule(), "XInputGetDSoundAudioDeviceGuids");
|
|
|
|
|
return func(dwUserIndex, pDSoundRenderGuid, pDSoundCaptureGuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef DWORD(__stdcall* _XInputGetBatteryInformation)(DWORD dwUserIndex, BYTE devType, XINPUT_BATTERY_INFORMATION* pBatteryInformation);
|
|
|
|
|
DWORD WINAPI XInputGetBatteryInformation(DWORD dwUserIndex, BYTE devType, XINPUT_BATTERY_INFORMATION* pBatteryInformation)
|
|
|
|
|
{
|
2017-03-20 21:20:18 +01:00
|
|
|
static _XInputGetBatteryInformation func = NULL;
|
2016-11-05 16:51:55 +01:00
|
|
|
if (!func)
|
|
|
|
|
func = (_XInputGetBatteryInformation)GetProcAddress(GetXInputModule(), "XInputGetBatteryInformation");
|
|
|
|
|
return func(dwUserIndex, devType, pBatteryInformation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef DWORD(__stdcall* _XInputGetKeystroke)(DWORD dwUserIndex, DWORD dwReserved, PXINPUT_KEYSTROKE pKeystroke);
|
|
|
|
|
DWORD WINAPI XInputGetKeystroke(DWORD dwUserIndex, DWORD dwReserved, PXINPUT_KEYSTROKE pKeystroke)
|
|
|
|
|
{
|
2017-03-20 21:20:18 +01:00
|
|
|
static _XInputGetKeystroke func = NULL;
|
2016-11-05 16:51:55 +01:00
|
|
|
if (!func)
|
|
|
|
|
func = (_XInputGetKeystroke)GetProcAddress(GetXInputModule(), "XInputGetKeystroke");
|
|
|
|
|
return func(dwUserIndex, dwReserved, pKeystroke);
|
|
|
|
|
}
|