From 6a0062a3cc61ced4d3fdae4ea77387c7981165ec Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Sat, 25 Jan 2025 18:35:18 +0000 Subject: [PATCH] input_patches: fix touchpad flag magnetism --- UnleashedRecomp/patches/input_patches.cpp | 40 ++++++++++++++--------- UnleashedRecompLib/config/SWA.toml | 5 +-- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/UnleashedRecomp/patches/input_patches.cpp b/UnleashedRecomp/patches/input_patches.cpp index 2b384983..b8b7abc7 100644 --- a/UnleashedRecomp/patches/input_patches.cpp +++ b/UnleashedRecomp/patches/input_patches.cpp @@ -165,10 +165,15 @@ static bool IsLeftStickThreshold(const SWA::SPadState* pPadState, double deadzon (pPadState->LeftStickVertical * pPadState->LeftStickVertical)) > deadzone; } -static bool IsTouchThreshold(double deadzone = 0) +static bool IsTouchThreshold(double deadzone = 0, bool isBelowThreshold = false) { - return sqrtl((g_worldMapTouchVelocityX * g_worldMapTouchVelocityX) + - (g_worldMapTouchVelocityY * g_worldMapTouchVelocityY)) > deadzone; + auto sqrt = sqrtl((g_worldMapTouchVelocityX * g_worldMapTouchVelocityX) + + (g_worldMapTouchVelocityY * g_worldMapTouchVelocityY)); + + if (isBelowThreshold) + return sqrt < deadzone; + + return sqrt >= deadzone; } static void SetDPadAnalogDirectionX(PPCRegister& pPadState, PPCRegister& x, bool invert, float max = 1.0f) @@ -254,13 +259,10 @@ bool WorldMapDeadzoneMidAsmHook(PPCRegister& pPadState) { SDLEventListenerForInputPatches::Update(App::s_deltaTime); - auto vxAbs = fabs(g_worldMapTouchVelocityX); - auto vyAbs = fabs(g_worldMapTouchVelocityY); - /* Reduce touch noise if the player has their finger resting on the touchpad, but allow much precise values without touch for proper interpolation to zero. */ - if (IsTouchThreshold(0.05)) + if (IsTouchThreshold(0.05, true)) return !g_isTouchActive; return IsTouchThreshold(); @@ -269,9 +271,17 @@ bool WorldMapDeadzoneMidAsmHook(PPCRegister& pPadState) return IsDPadThreshold(pGuestPadState) || IsLeftStickThreshold(pGuestPadState, WORLD_MAP_ROTATE_DEADZONE); } -bool WorldMapTouchMagnetismSupportMidAsmHook(PPCRegister& f0) +bool WorldMapMagnetismMidAsmHook(PPCRegister& f0) { - return fabs(g_worldMapTouchVelocityX) > f0.f64 || fabs(g_worldMapTouchVelocityY) > f0.f64; + if (IsTouchThreshold(f0.f64, true)) + { + g_worldMapTouchVelocityX = 0; + g_worldMapTouchVelocityY = 0; + + return true; + } + + return false; } void TouchAndDPadSupportWorldMapXMidAsmHook(PPCRegister& pPadState, PPCRegister& x) @@ -282,10 +292,9 @@ void TouchAndDPadSupportWorldMapXMidAsmHook(PPCRegister& pPadState, PPCRegister& { SetDPadAnalogDirectionX(pPadState, x, false); } - else + else if (fabs(g_worldMapTouchVelocityX) > 0) { - if (fabs(g_worldMapTouchVelocityX) > 0) - x.f64 = -g_worldMapTouchVelocityX; + x.f64 = -g_worldMapTouchVelocityX; } } @@ -297,10 +306,9 @@ void TouchAndDPadSupportWorldMapYMidAsmHook(PPCRegister& pPadState, PPCRegister& { SetDPadAnalogDirectionY(pPadState, y, false); } - else + else if (fabs(g_worldMapTouchVelocityY) > 0) { - if (fabs(g_worldMapTouchVelocityY) > 0) - y.f64 = g_worldMapTouchVelocityY; + y.f64 = g_worldMapTouchVelocityY; } } @@ -348,7 +356,7 @@ PPC_FUNC(sub_8256C938) if (rPadState.IsDown(SWA::eKeyState_DpadRight)) pWorldMapCursor->m_LeftStickHorizontal = 1.0f; - if (sqrtf((pWorldMapCursor->m_LeftStickHorizontal * pWorldMapCursor->m_LeftStickHorizontal) + + if (sqrtl((pWorldMapCursor->m_LeftStickHorizontal * pWorldMapCursor->m_LeftStickHorizontal) + (pWorldMapCursor->m_LeftStickVertical * pWorldMapCursor->m_LeftStickVertical)) > WORLD_MAP_ROTATE_DEADZONE) { pWorldMapCursor->m_IsCursorMoving = true; diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index a907ea3a..0d86e64d 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -654,10 +654,11 @@ jump_address_on_true = 0x824862F0 # SWA::CWorldMapCamera - disable flag magnetism for touch [[midasm_hook]] -name = "WorldMapTouchMagnetismSupportMidAsmHook" +name = "WorldMapMagnetismMidAsmHook" address = 0x824866D4 registers = ["f0"] -jump_address_on_true = 0x82486838 +jump_address_on_true = 0x824866D8 +jump_address_on_false = 0x82486838 # SWA::CWorldMapCamera - touch and D-Pad support for camera adjustment threshold on the X axis [[midasm_hook]]