From f7d23f3bb3c33bdda7595a560e99a0bddb5e81dc Mon Sep 17 00:00:00 2001 From: mark wallace Date: Sun, 30 Mar 2025 18:35:13 +0000 Subject: [PATCH 1/2] Modified `CPad::DuckJustDown` to use a frame counter for a 1-second delay. --- src/miami/core/Pad.cpp | 59 ++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/miami/core/Pad.cpp b/src/miami/core/Pad.cpp index 35f8a8f2..90d4dea8 100644 --- a/src/miami/core/Pad.cpp +++ b/src/miami/core/Pad.cpp @@ -3881,36 +3881,49 @@ bool CPad::CollectPickupJustDown(void) return false; } -bool CPad::DuckJustDown(void) +bool CPad::DuckJustDown(void) { - if (ArePlayerControlsDisabled()) + if (ArePlayerControlsDisabled()) { + duckFrameCounter = 0; return false; + } + #ifdef RW_DC - switch (CPad::GetPad(0)->Mode) - { - case 0: //Xbox Mode - if (CPad::GetPad(0)->IsDualAnalog) - { - return !!(NewState.X&& !OldState.X); - } - else - { - return !!(NewState.X&& !OldState.X); - } - case 1: //PS2 Mode - if (CPad::GetPad(0)->IsDualAnalog) - { - return !!(NewState.X&& !OldState.X); - } - else - { - return !!(NewState.X&& !OldState.X); - } + bool buttonPressed = false; + switch (CPad::GetPad(0)->Mode) { + case 0: // Xbox Mode + buttonPressed = NewState.X; + break; + case 1: // PS2 Mode + buttonPressed = NewState.X; + break; + } + + if (buttonPressed) { + duckFrameCounter++; + if (duckFrameCounter >= DUCK_DELAY_FRAMES && !isDucking) { + isDucking = true; + return true; // Trigger ducking after delay + } + } else { + duckFrameCounter = 0; + isDucking = false; } return false; #else - return !!(NewState.LeftShock && !OldState.LeftShock); + bool buttonPressed = NewState.Square; + if (buttonPressed) { + duckFrameCounter++; + if (duckFrameCounter >= DUCK_DELAY_FRAMES && !isDucking) { + isDucking = true; + return true; + } + } else { + duckFrameCounter = 0; + isDucking = false; + } + return false; #endif } From d0ea5f41bed9073eac71ba173cbe677f3e8cee1d Mon Sep 17 00:00:00 2001 From: mark wallace Date: Sun, 30 Mar 2025 18:37:55 +0000 Subject: [PATCH 2/2] - Added `static const int DUCK_DELAY_FRAMES = 30` to define the delay (1 second at 30 FPS). - Added `int duckFrameCounter` to track frames the duck button is held. - Added `bool isDucking` to track crouch state and prevent re-triggering. - Updated `CPad` constructor to initialize `duckFrameCounter` and `isDucking`. --- src/miami/core/Pad.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/miami/core/Pad.h b/src/miami/core/Pad.h index aa76eb1f..1702cb82 100644 --- a/src/miami/core/Pad.h +++ b/src/miami/core/Pad.h @@ -173,11 +173,26 @@ public: uint32 CameraJustUpTime; uint32 CameraLastPressed; bool CameraIsDoublePressed; + static const int DUCK_DELAY_FRAMES = 30; // 1 second at 30 FPS + int duckFrameCounter; // Frames the duck button has been held + bool isDucking; // Tracks if duck action is active #ifdef DETECT_PAD_INPUT_SWITCH - static bool IsAffectedByController; + static bool IsAffectedByController; #endif - CPad() { } + + CPad() : duckFrameCounter(0), isDucking(false), // New variables initialized + SteeringLeftRightBuffer{0}, DrunkDrivingBufferUsed(0), Phase(0), Mode(0), + ShakeDur(0), DisablePlayerControls(0), ShakeFreq(0), iCurrHornHistory(0), + JustOutOfFrontend(0), bApplyBrakes(0), LastTimeTouched(0), AverageWeapon(0), + AverageEntries(0), IsKeyboardMouse(false), IsDualAnalog(false), + CameraJustDown(false), CameraJustUp(false), CameraJustUpTime(0), + CameraLastPressed(0), CameraIsDoublePressed(false) { + Clear(false); + memset(bHornHistory, 0, sizeof(bHornHistory)); + memset(CheatString, 0, sizeof(CheatString)); + } + ~CPad() { } static bool bDisplayNoControllerMessage;