From 43b092033cb7be208640b328bc42cdab7c5102ef Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Fri, 27 Mar 2020 20:54:35 +0200 Subject: XInput --- src/core/Pad.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'src/core/Pad.cpp') diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index 51102c7b..9a911aa4 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -5,6 +5,10 @@ #pragma warning( pop ) #include "common.h" +#ifdef XINPUT +#include +#pragma comment( lib, "Xinput.lib" ) +#endif #include "patcher.h" #include "Pad.h" #include "ControllerConfig.h" @@ -547,12 +551,60 @@ void CPad::AddToPCCheatString(char c) #undef _CHEATCMP } +#ifdef XINPUT +void CPad::AffectFromXinput(uint32 pad) +{ + XINPUT_STATE xstate; + memset(&xstate, 0, sizeof(XINPUT_STATE)); + if (XInputGetState(pad, &xstate) == ERROR_SUCCESS) + { + PCTempJoyState.Circle = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_B) ? 255 : 0; + PCTempJoyState.Cross = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_A) ? 255 : 0; + PCTempJoyState.Square = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_X) ? 255 : 0; + PCTempJoyState.Triangle = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_Y) ? 255 : 0; + PCTempJoyState.DPadDown = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) ? 255 : 0; + PCTempJoyState.DPadLeft = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) ? 255 : 0; + PCTempJoyState.DPadRight = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) ? 255 : 0; + PCTempJoyState.DPadUp = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) ? 255 : 0; + PCTempJoyState.LeftShock = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? 255 : 0; + PCTempJoyState.LeftShoulder1 = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? 255 : 0; + PCTempJoyState.LeftShoulder2 = xstate.Gamepad.bLeftTrigger; + PCTempJoyState.RightShock = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? 255 : 0; + PCTempJoyState.RightShoulder1 = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? 255 : 0; + PCTempJoyState.RightShoulder2 = xstate.Gamepad.bRightTrigger; + + PCTempJoyState.Select = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) ? 255 : 0; + PCTempJoyState.Start = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_START) ? 255 : 0; + + float lx = (float)xstate.Gamepad.sThumbLX / (float)0x7FFF; + float ly = (float)xstate.Gamepad.sThumbLY / (float)0x7FFF; + float rx = (float)xstate.Gamepad.sThumbRX / (float)0x7FFF; + float ry = (float)xstate.Gamepad.sThumbRY / (float)0x7FFF; + + if (Abs(lx) > 0.3f || Abs(ly) > 0.3f) { + PCTempJoyState.LeftStickX = (int32)(lx * 128.0f); + PCTempJoyState.LeftStickY = (int32)(-ly * 128.0f); + } + + if (Abs(rx) > 0.3f || Abs(ry) > 0.3f) { + PCTempJoyState.RightStickX = (int32)(rx * 128.0f); + PCTempJoyState.RightStickY = (int32)(ry * 128.0f); + } + } +} +#endif + void CPad::UpdatePads(void) { bool bUpdate = true; GetPad(0)->UpdateMouse(); +#ifdef XINPUT + GetPad(0)->AffectFromXinput(0); + GetPad(1)->AffectFromXinput(1); +#else CapturePad(0); +#endif ControlsManager.ClearSimButtonPressCheckers(); @@ -566,9 +618,11 @@ void CPad::UpdatePads(void) { GetPad(0)->Update(0); } - + +#if defined(MASTER) && !defined(XINPUT) GetPad(1)->NewState.Clear(); GetPad(1)->OldState.Clear(); +#endif OldKeyState = NewKeyState; NewKeyState = TempKeyState; -- cgit v1.2.3 From c953230237d3ac09b9e3fbfaf19b204f0cc568f1 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 28 Mar 2020 04:53:42 +0200 Subject: Set Xinput version to 9.1.0 + vibration set --- src/core/Pad.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/core/Pad.cpp') diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index 9a911aa4..87f45b9f 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -7,7 +7,7 @@ #include "common.h" #ifdef XINPUT #include -#pragma comment( lib, "Xinput.lib" ) +#pragma comment( lib, "Xinput9_1_0.lib" ) #endif #include "patcher.h" #include "Pad.h" @@ -590,6 +590,24 @@ void CPad::AffectFromXinput(uint32 pad) PCTempJoyState.RightStickX = (int32)(rx * 128.0f); PCTempJoyState.RightStickY = (int32)(ry * 128.0f); } + + XINPUT_VIBRATION VibrationState; + + memset(&VibrationState, 0, sizeof(XINPUT_VIBRATION)); + + uint16 iLeftMotor = (uint16)((float)ShakeFreq / 255.0f * (float)0xffff); + uint16 iRightMotor = (uint16)((float)ShakeFreq / 255.0f * (float)0xffff); + + if (ShakeDur < CTimer::GetTimeStepInMilliseconds()) + ShakeDur = 0; + else + ShakeDur -= CTimer::GetTimeStepInMilliseconds(); + if (ShakeDur == 0) ShakeFreq = 0; + + VibrationState.wLeftMotorSpeed = iLeftMotor; + VibrationState.wRightMotorSpeed = iRightMotor; + + XInputSetState(pad, &VibrationState); } } #endif @@ -617,6 +635,7 @@ void CPad::UpdatePads(void) if ( bUpdate ) { GetPad(0)->Update(0); + GetPad(1)->Update(0); } #if defined(MASTER) && !defined(XINPUT) -- cgit v1.2.3 From 112685ebac0a4f5da50fdc60ff71c35a5cddbdfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sat, 28 Mar 2020 17:47:52 +0300 Subject: CCopPed done and #include cleanup --- src/core/Pad.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/Pad.cpp') diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index 87f45b9f..6bbe00f2 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -574,8 +574,9 @@ void CPad::AffectFromXinput(uint32 pad) PCTempJoyState.RightShoulder2 = xstate.Gamepad.bRightTrigger; PCTempJoyState.Select = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) ? 255 : 0; +#ifdef REGISTER_START_BUTTON PCTempJoyState.Start = (xstate.Gamepad.wButtons & XINPUT_GAMEPAD_START) ? 255 : 0; - +#endif float lx = (float)xstate.Gamepad.sThumbLX / (float)0x7FFF; float ly = (float)xstate.Gamepad.sThumbLY / (float)0x7FFF; float rx = (float)xstate.Gamepad.sThumbRX / (float)0x7FFF; -- cgit v1.2.3