From 6559321a4c66dd1875bcbf56d35acd462453d78d Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Sat, 17 Oct 2020 23:20:24 +0200 Subject: [PATCH] Add first two changes of #1131 --- data/menu/nullified-ui.xml | 1 + data/menu/nullifiedcat/movement.xml | 32 +---------------- data/menu/nullifiedcat/warp.xml | 40 +++++++++++++++++++++ src/hacks/Warp.cpp | 54 +++++++++++++++++++++++++++-- 4 files changed, 93 insertions(+), 34 deletions(-) create mode 100644 data/menu/nullifiedcat/warp.xml diff --git a/data/menu/nullified-ui.xml b/data/menu/nullified-ui.xml index 3e96b99d..80b11c00 100755 --- a/data/menu/nullified-ui.xml +++ b/data/menu/nullified-ui.xml @@ -9,6 +9,7 @@ + diff --git a/data/menu/nullifiedcat/movement.xml b/data/menu/nullifiedcat/movement.xml index d1cb4055..b179a0b9 100755 --- a/data/menu/nullifiedcat/movement.xml +++ b/data/menu/nullifiedcat/movement.xml @@ -1,4 +1,4 @@ - + @@ -56,34 +56,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/data/menu/nullifiedcat/warp.xml b/data/menu/nullifiedcat/warp.xml new file mode 100644 index 00000000..5826f02d --- /dev/null +++ b/data/menu/nullifiedcat/warp.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/hacks/Warp.cpp b/src/hacks/Warp.cpp index a4b3db85..ae3a21fd 100644 --- a/src/hacks/Warp.cpp +++ b/src/hacks/Warp.cpp @@ -22,6 +22,7 @@ static settings::Boolean no_movement{ "warp.rapidfire.no-movement", "true" }; static settings::Boolean rapidfire{ "warp.rapidfire", "false" }; static settings::Boolean wait_full{ "warp.rapidfire.wait-full", "true" }; static settings::Button rapidfire_key{ "warp.rapidfire.key", "" }; +static settings::Int rapidfire_key_mode{ "warp.rapidfire.key-mode", "1" }; static settings::Float speed{ "warp.speed", "23" }; static settings::Boolean draw{ "warp.draw", "false" }; static settings::Button warp_key{ "warp.key", "" }; @@ -69,6 +70,45 @@ static bool charged = false; static bool should_warp = true; static bool was_hurt = false; +// Rapidfire key mode +static bool key_valid = false; + +// A function that determins whether our key state allows us to rapidfire or not +bool UpdateRFKey() +{ + static bool key_flip = false; + static bool pressed_last_tick = false; + bool allow_key = true; + + // Check if the key is even used + if (rapidfire_key && rapidfire_key_mode) + { + bool key_down = rapidfire_key.isKeyDown(); + switch ((int) rapidfire_key_mode) + { + case 1: // Only while key is pressed + if (!key_down) + allow_key = false; + break; + case 2: // Only while key is not pressed + if (key_down) + allow_key = false; + break; + case 3: // Key acts like a toggle switch + if (!pressed_last_tick && key_down) + key_flip = !key_flip; + if (!key_flip) + allow_key = false; + break; + default: + break; + } + pressed_last_tick = key_down; + } + // Return whether the key allows it + return allow_key; +} + bool shouldRapidfire() { if (!rapidfire) @@ -78,8 +118,8 @@ bool shouldRapidfire() if (in_rapidfire) return false; - // No key set? Always run. Else check if key is held - if (rapidfire_key && !rapidfire_key.isKeyDown()) + // Only run if key state allows it + if (!key_valid) return false; // Dead player @@ -104,7 +144,13 @@ bool shouldRapidfire() return false; // Mouse 1 is held, do it. - return current_user_cmd && current_user_cmd->buttons & IN_ATTACK; + bool buttons_pressed = current_user_cmd && current_user_cmd->buttons & IN_ATTACK; + + // Unless we are on a flamethrower, where we only want m2. + if (LOCAL_W->m_iClassID() == CL_CLASS(CTFFlameThrower)) + buttons_pressed = current_user_cmd && current_user_cmd->buttons & IN_ATTACK2; + + return buttons_pressed; } // Should we warp? @@ -391,6 +437,8 @@ void CL_Move_hook(float accumulated_extra_samples, bool bFinalTick) // and the global variable so our time based functions are synced properly. void CreateMoveEarly() { + // Update key state + key_valid = UpdateRFKey(); if (hacks::tf2::warp::in_rapidfire && current_user_cmd) { if (current_user_cmd)