From ba8aa3865488afceee36acaeceb54541feb0bd97 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 2 May 2020 19:00:47 +0300 Subject: Switching pad modes and cheats when player is switching between controller and kb&m --- src/core/Pad.cpp | 141 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 112 insertions(+), 29 deletions(-) (limited to 'src/core/Pad.cpp') diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index f4b81cb4..ef074a0c 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -55,6 +55,10 @@ CMouseControllerState CPad::OldMouseControllerState; CMouseControllerState CPad::NewMouseControllerState; CMouseControllerState CPad::PCTempMouseControllerState; +#ifdef DETECT_PAD_INPUT_SWITCH +bool CPad::IsAffectedByController = false; +#endif + _TODO("gbFastTime"); extern bool gbFastTime; @@ -325,6 +329,16 @@ void AltDodoCheat(void) } #endif +#ifdef DETECT_PAD_INPUT_SWITCH +bool +CControllerState::IsAnyButtonPressed(void) +{ + return !!LeftStickX || !!LeftStickY || !!RightStickX || !!RightStickY || !!LeftShoulder1 || !!LeftShoulder2 || !!RightShoulder1 || !!RightShoulder2 || + !!DPadUp || !!DPadDown || !!DPadLeft || !!DPadRight || !!Start || !!Select || !!Square || !!Triangle || !!Cross || !!Circle || !!LeftShock || + !!RightShock || !!NetworkTalk; +} +#endif + void CControllerState::Clear(void) { @@ -1037,11 +1051,20 @@ void CPad::UpdatePads(void) #else CapturePad(0); #endif - +#ifdef DETECT_PAD_INPUT_SWITCH + if (GetPad(0)->PCTempJoyState.IsAnyButtonPressed()) + IsAffectedByController = true; + else { +#endif + ControlsManager.ClearSimButtonPressCheckers(); + ControlsManager.AffectPadFromKeyBoard(); + ControlsManager.AffectPadFromMouse(); - ControlsManager.ClearSimButtonPressCheckers(); - ControlsManager.AffectPadFromKeyBoard(); - ControlsManager.AffectPadFromMouse(); +#ifdef DETECT_PAD_INPUT_SWITCH + } + if (IsAffectedByController && (GetPad(0)->PCTempKeyState.IsAnyButtonPressed() || GetPad(0)->PCTempMouseState.IsAnyButtonPressed())) + IsAffectedByController = false; +#endif if ( CReplay::IsPlayingBackFromFile() ) bUpdate = false; @@ -1096,7 +1119,10 @@ void CPad::Update(int16 unk) void CPad::DoCheats(void) { - GetPad(0)->DoCheats(0); +#ifdef DETECT_PAD_INPUT_SWITCH + if (IsAffectedByController) +#endif + GetPad(0)->DoCheats(0); } void CPad::DoCheats(int16 unk) @@ -1159,7 +1185,9 @@ int16 CPad::GetSteeringLeftRight(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1192,7 +1220,9 @@ int16 CPad::GetSteeringUpDown(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1225,7 +1255,9 @@ int16 CPad::GetCarGunUpDown(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1252,7 +1284,9 @@ int16 CPad::GetCarGunLeftRight(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1279,7 +1313,9 @@ int16 CPad::GetPedWalkLeftRight(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1313,7 +1349,9 @@ int16 CPad::GetPedWalkUpDown(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1344,6 +1382,9 @@ int16 CPad::GetPedWalkUpDown(void) int16 CPad::GetAnalogueUpDown(void) { +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1409,7 +1450,9 @@ bool CPad::GetHorn(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1448,7 +1491,9 @@ bool CPad::HornJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1488,7 +1533,9 @@ bool CPad::GetCarGunFired(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1515,7 +1562,9 @@ bool CPad::CarGunJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1542,7 +1591,9 @@ int16 CPad::GetHandBrake(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1575,7 +1626,9 @@ int16 CPad::GetBrake(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1613,7 +1666,9 @@ bool CPad::GetExitVehicle(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1640,7 +1695,9 @@ bool CPad::ExitVehicleJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1667,7 +1724,9 @@ int32 CPad::GetWeapon(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1700,7 +1759,9 @@ bool CPad::WeaponJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1733,7 +1794,9 @@ int16 CPad::GetAccelerate(void) { if ( ArePlayerControlsDisabled() ) return 0; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1769,6 +1832,9 @@ int16 CPad::GetAccelerate(void) bool CPad::CycleCameraModeUpJustDown(void) { +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1793,6 +1859,9 @@ bool CPad::CycleCameraModeUpJustDown(void) bool CPad::CycleCameraModeDownJustDown(void) { +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1819,7 +1888,9 @@ bool CPad::ChangeStationJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1875,7 +1946,9 @@ bool CPad::GetTarget(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1902,7 +1975,9 @@ bool CPad::TargetJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -1937,7 +2012,9 @@ bool CPad::GetSprint(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -2092,7 +2169,9 @@ bool CPad::ForceCameraBehindPlayer(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -2125,7 +2204,9 @@ bool CPad::SniperZoomIn(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: @@ -2152,7 +2233,9 @@ bool CPad::SniperZoomOut(void) { if ( ArePlayerControlsDisabled() ) return false; - +#ifdef DETECT_PAD_INPUT_SWITCH + int16 Mode = IsAffectedByController ? this->Mode : 0; +#endif switch ( Mode ) { case 0: -- cgit v1.2.3 From d2712afc788e59973b5331eb8d10870239d803e4 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 3 May 2020 00:11:02 +0300 Subject: Add CURMODE macro --- src/core/Pad.cpp | 166 +++++++++++++++++++------------------------------------ 1 file changed, 58 insertions(+), 108 deletions(-) (limited to 'src/core/Pad.cpp') diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index ef074a0c..e6e43632 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -1180,15 +1180,19 @@ CPad *CPad::GetPad(int32 pad) { return &Pads[pad]; } +#ifdef DETECT_PAD_INPUT_SWITCH +#define CURMODE (IsAffectedByController ? Mode : 0) +#else +#define CURMODE (Mode) +#endif + int16 CPad::GetSteeringLeftRight(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 2: @@ -1220,10 +1224,8 @@ int16 CPad::GetSteeringUpDown(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 2: @@ -1255,10 +1257,8 @@ int16 CPad::GetCarGunUpDown(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1284,10 +1284,8 @@ int16 CPad::GetCarGunLeftRight(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1313,10 +1311,8 @@ int16 CPad::GetPedWalkLeftRight(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 2: @@ -1349,10 +1345,8 @@ int16 CPad::GetPedWalkUpDown(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 2: @@ -1382,10 +1376,7 @@ int16 CPad::GetPedWalkUpDown(void) int16 CPad::GetAnalogueUpDown(void) { -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + switch (CURMODE) { case 0: case 2: @@ -1450,10 +1441,8 @@ bool CPad::GetHorn(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: { @@ -1491,10 +1480,8 @@ bool CPad::HornJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: { @@ -1533,10 +1520,8 @@ bool CPad::GetCarGunFired(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1562,10 +1547,8 @@ bool CPad::CarGunJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1591,10 +1574,8 @@ int16 CPad::GetHandBrake(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1626,10 +1607,8 @@ int16 CPad::GetBrake(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 2: @@ -1666,10 +1645,8 @@ bool CPad::GetExitVehicle(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1695,10 +1672,8 @@ bool CPad::ExitVehicleJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1724,10 +1699,8 @@ int32 CPad::GetWeapon(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1759,10 +1732,8 @@ bool CPad::WeaponJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1794,10 +1765,8 @@ int16 CPad::GetAccelerate(void) { if ( ArePlayerControlsDisabled() ) return 0; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 2: @@ -1832,10 +1801,7 @@ int16 CPad::GetAccelerate(void) bool CPad::CycleCameraModeUpJustDown(void) { -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + switch (CURMODE) { case 0: case 2: @@ -1859,10 +1825,7 @@ bool CPad::CycleCameraModeUpJustDown(void) bool CPad::CycleCameraModeDownJustDown(void) { -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + switch (CURMODE) { case 0: case 2: @@ -1888,10 +1851,8 @@ bool CPad::ChangeStationJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: { @@ -1946,10 +1907,8 @@ bool CPad::GetTarget(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -1975,10 +1934,8 @@ bool CPad::TargetJustDown(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -2012,10 +1969,8 @@ bool CPad::GetSprint(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -2169,10 +2124,8 @@ bool CPad::ForceCameraBehindPlayer(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -2204,10 +2157,8 @@ bool CPad::SniperZoomIn(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -2233,10 +2184,8 @@ bool CPad::SniperZoomOut(void) { if ( ArePlayerControlsDisabled() ) return false; -#ifdef DETECT_PAD_INPUT_SWITCH - int16 Mode = IsAffectedByController ? this->Mode : 0; -#endif - switch ( Mode ) + + switch (CURMODE) { case 0: case 1: @@ -2258,6 +2207,7 @@ bool CPad::SniperZoomOut(void) return false; } +#undef CURMODE int16 CPad::SniperModeLookLeftRight(void) { -- cgit v1.2.3 From ff4af35292e82e03c7160a3c85e2296655057deb Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 3 May 2020 01:42:05 +0300 Subject: Fix pad Y axis --- src/core/Pad.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/core/Pad.cpp') diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index e6e43632..c4c4a69e 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -1016,7 +1016,7 @@ void CPad::AffectFromXinput(uint32 pad) if (Abs(rx) > 0.3f || Abs(ry) > 0.3f) { PCTempJoyState.RightStickX = (int32)(rx * 128.0f); - PCTempJoyState.RightStickY = (int32)(ry * 128.0f); + PCTempJoyState.RightStickY = (int32)(-ry * 128.0f); } XINPUT_VIBRATION VibrationState; @@ -2223,6 +2223,9 @@ int16 CPad::SniperModeLookLeftRight(void) int16 CPad::SniperModeLookUpDown(void) { int16 axis = NewState.LeftStickY; +#ifdef FIX_BUGS + axis = -axis; +#endif int16 dpad = (NewState.DPadUp - NewState.DPadDown) / 2; if ( Abs(axis) > Abs(dpad) ) @@ -2249,7 +2252,11 @@ int16 CPad::LookAroundLeftRight(void) int16 CPad::LookAroundUpDown(void) { int16 axis = GetPad(0)->NewState.RightStickY; - + +#ifdef FIX_BUGS + axis = -axis; +#endif + if ( Abs(axis) > 85 && !GetLookBehindForPed() ) return (int16) ( (axis + ( ( axis > 0 ) ? -85 : 85) ) * (127.0f / 32.0f) ); // 3.96875f -- cgit v1.2.3