From 8480102bd19db7eef3015a9322ae9d564787a927 Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Fri, 22 May 2020 14:50:58 +0200 Subject: [PATCH] Address issued mentioned in PR --- src/hacks/Warp.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hacks/Warp.cpp b/src/hacks/Warp.cpp index aecb9f2b..730c8d83 100644 --- a/src/hacks/Warp.cpp +++ b/src/hacks/Warp.cpp @@ -45,6 +45,15 @@ static int warp_amount_override = 0; static bool should_melee = false; static bool charged = false; +static bool should_warp = true; +static bool was_hurt = false; + +// Should we warp? +bool shouldWarp(bool check_amount) +{ + return ((warp_key && warp_key.isKeyDown()) || was_hurt) && (!check_amount || warp_amount); +} + // How many ticks of excess we have (for decimal speeds) float excess_ticks = 0.0f; int GetWarpAmount(bool finalTick) @@ -70,9 +79,6 @@ int GetWarpAmount(bool finalTick) return std::min(warp_amount_processed, max_extra_ticks); } -static bool should_warp = true; -static bool was_hurt = false; - DetourHook cl_move_detour; typedef void (*CL_Move_t)(float accumulated_extra_samples, bool bFinalTick); @@ -228,7 +234,7 @@ void CreateMove() return; if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer()) return; - if (!warp_key.isKeyDown() && !was_hurt) + if (!shouldWarp(false)) { warp_last_tick = false; current_state = ATTACK; @@ -601,7 +607,7 @@ void CL_Move_hook(float accumulated_extra_samples, bool bFinalTick) cl_move_detour.RestorePatch(); // Should we warp? - if ((warp_key.isKeyDown() || was_hurt) && warp_amount) + if (shouldWarp(true)) { Warp(accumulated_extra_samples, bFinalTick); if (warp_amount < GetMaxWarpTicks()) @@ -623,6 +629,7 @@ static InitRoutine init([]() { []() { g_IEventManager2->RemoveListener(&listener); cl_sendmove_detour.Shutdown(); + cl_move_detour.Shutdown(); }, "warp_shutdown"); warp_forward.installChangeCallback(rvarCallback);