Skip to content

Commit

Permalink
Added configuration support
Browse files Browse the repository at this point in the history
Making a new branch due to weird behavior. Seems to break some games that worked before (e.g. Hitman 2). Please report any issues you find.
  • Loading branch information
araghon007 authored Mar 14, 2019
1 parent 06485f9 commit e0555d1
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions X1nput/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "stdafx.h"
#include <tchar.h>

#define XINPUT_GAMEPAD_DPAD_UP 0x0001
#define XINPUT_GAMEPAD_DPAD_DOWN 0x0002
Expand Down Expand Up @@ -53,13 +54,31 @@
#define ERROR_DEVICE_NOT_CONNECTED 1167
#define ERROR_SUCCESS 0

#define LEFT_TRIGGER_STRENGTH 0.25f
#define RIGHT_TRIGGER_STRENGTH 0.25f
#define CONFIG_PATH _T(".\\X1nput.ini")

std::unique_ptr<DirectX::GamePad> m_gamePad;

float RTriggerStrength = 0.25f;
float LTriggerStrength = 0.25f;
float RMotorStrength = 1.0f;
float LMotorStrength = 1.0f;

bool TriggerSwap = false;
bool MotorSwap = false;

bool initialized = false;

LPTSTR GetConfigString(LPCSTR AppName, LPCSTR KeyName, LPCSTR Default) {
TCHAR result[256];
GetPrivateProfileString(AppName, KeyName, Default, result, 256, CONFIG_PATH);
return result;
}

bool StringToBool(LPTSTR value) {
return value == "True" || value == "true";
}


//
// Structures used by XInput APIs
//
Expand Down Expand Up @@ -132,6 +151,15 @@ DLLEXPORT DWORD WINAPI XInputGetState(_In_ DWORD dwUserIndex, _Out_ XINPUT_STATE
{
if (!initialized) {
m_gamePad = std::make_unique<DirectX::GamePad>();

LTriggerStrength = atof(GetConfigString(_T("Triggers"), _T("LeftStrength"), _T("0.25")));
RTriggerStrength = atof(GetConfigString(_T("Triggers"), _T("RightStrength"), _T("0.25")));
TriggerSwap = StringToBool(GetConfigString(_T("Triggers"), _T("SwapSides"), _T("False")));

LMotorStrength = atof(GetConfigString(_T("Motors"), _T("LeftStrength"), _T("1.0")));
RMotorStrength = atof(GetConfigString(_T("Motors"), _T("RightStrength"), _T("1.0")));
MotorSwap = StringToBool(GetConfigString(_T("Motors"), _T("SwapSides"), _T("False")));

initialized = true;
}

Expand Down Expand Up @@ -192,7 +220,16 @@ DLLEXPORT DWORD WINAPI XInputSetState(_In_ DWORD dwUserIndex, _In_ XINPUT_VIBRAT

if (state.connected) {

m_gamePad->SetVibration(dwUserIndex, pVibration->wLeftMotorSpeed / 65535.0f, pVibration->wRightMotorSpeed / 65535.0f, pVibration->wLeftMotorSpeed / 65535.0f * LEFT_TRIGGER_STRENGTH, pVibration->wRightMotorSpeed / 65535.0f * RIGHT_TRIGGER_STRENGTH);
float LSpeed = pVibration->wLeftMotorSpeed / 65535.0f;
float RSpeed = pVibration->wRightMotorSpeed / 65535.0f;

float LMotorSpeed = MotorSwap ? RSpeed * LMotorStrength : LSpeed * LMotorStrength;
float RMotorSpeed = MotorSwap ? LSpeed * RMotorStrength : RSpeed * RMotorStrength;

float LTriggerSpeed = TriggerSwap ? RSpeed * LTriggerStrength : LSpeed * LTriggerStrength;
float RTriggerSpeed = TriggerSwap ? LSpeed * RTriggerStrength : RSpeed * RTriggerStrength;

m_gamePad->SetVibration(dwUserIndex, LMotorSpeed, RMotorSpeed, LTriggerSpeed, RTriggerSpeed);

return ERROR_SUCCESS;
}
Expand Down

0 comments on commit e0555d1

Please sign in to comment.