From d7d8949d2aee4fee65edee133cb43e9bed7ed288 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Fri, 14 Jan 2022 19:42:03 +0000 Subject: [PATCH 1/4] Use newly added flag --- src/Components/Modules/Gamepad.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Modules/Gamepad.cpp b/src/Components/Modules/Gamepad.cpp index c3555fc7..9ce1123a 100644 --- a/src/Components/Modules/Gamepad.cpp +++ b/src/Components/Modules/Gamepad.cpp @@ -868,7 +868,7 @@ namespace Components } // Check for frozen controls. Flag name should start with PMF_ - if (CG_ShouldUpdateViewAngles(gamePadIndex) && (clientActive.snap.ps.pm_flags & 0x800) == 0) + if (CG_ShouldUpdateViewAngles(gamePadIndex) && (clientActive.snap.ps.pm_flags & Game::PMF_FROZEN) == 0) { Game::AimInput aimInput{}; Game::AimOutput aimOutput{}; From 4ee39b510f550601f93ec6cf5352e62d6a6d4c44 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 19 Jan 2022 00:49:50 +0000 Subject: [PATCH 2/4] Refactor bounces --- src/Components/Modules/Movement.cpp | 86 +++++++++++++++++++++++++++ src/Components/Modules/Movement.hpp | 10 ++++ src/Components/Modules/QuickPatch.cpp | 32 ---------- src/Components/Modules/QuickPatch.hpp | 3 - 4 files changed, 96 insertions(+), 35 deletions(-) diff --git a/src/Components/Modules/Movement.cpp b/src/Components/Modules/Movement.cpp index e3d42e72..70fdb608 100644 --- a/src/Components/Modules/Movement.cpp +++ b/src/Components/Modules/Movement.cpp @@ -8,6 +8,8 @@ namespace Components Dvar::Var Movement::PlayerSpectateSpeedScale; Dvar::Var Movement::CGUfoScaler; Dvar::Var Movement::CGNoclipScaler; + Dvar::Var Movement::BGBouncesAllAngles; + Game::dvar_t* Movement::BGBounces; float Movement::PM_CmdScaleForStance(const Game::pmove_s* pm) { @@ -153,6 +155,71 @@ namespace Components } } + __declspec(naked) void Movement::PM_StepSlideMoveStub() + { + __asm + { + // Check the value of BGEnableBounces + push ecx + push eax + + mov eax, Movement::BGBounces + mov ecx, dword ptr [eax + 0x10] + test ecx, ecx + + pop eax + pop ecx + + // Do not bounce if BGEnableBounces is 0 + jle noBounce + + // Bounce + push 0x4B1B34 + retn + + noBounce: + // Original code + cmp dword ptr [esp + 0x24], 0 + push 0x4B1B48 + retn + } + } + + void Movement::PM_ProjectVelocityStub(const float* velIn, const float* normal, float* velOut) + { + auto lengthSquared2D = velIn[0] * velIn[0] + velIn[1] * velIn[1]; + + if (std::fabsf(normal[2]) < 0.001f || lengthSquared2D == 0.0) + { + velOut[0] = velIn[0]; + velOut[1] = velIn[1]; + velOut[2] = velIn[2]; + return; + } + + auto newZ = velIn[0] * normal[0] + velIn[1] * normal[1]; + newZ = -newZ / normal[2]; + auto lengthScale = std::sqrtf((velIn[2] * velIn[2] + lengthSquared2D) + / (newZ * newZ + lengthSquared2D)); + + if (Movement::BGBouncesAllAngles.get() + || (lengthScale < 1.f || newZ < 0.f || velIn[2] > 0.f)) + { + velOut[0] = velIn[0] * lengthScale; + velOut[1] = velIn[1] * lengthScale; + velOut[2] = newZ * lengthScale; + } + } + + // Double bounces + void Movement::Jump_ClearStateHk(Game::playerState_s* ps) + { + if (Movement::BGBounces->current.integer == Movement::DOUBLE) + return; + + Game::Jump_ClearState(ps); + } + Game::dvar_t* Movement::Dvar_RegisterLastStandSpeedScale(const char* name, float value, float min, float max, int, const char* desc) { @@ -175,6 +242,14 @@ namespace Components { Dvar::OnInit([] { + static const char* bg_enableBouncesValues[] = + { + "disabled", + "enabled", + "double", + nullptr + }; + Movement::PlayerDuckedSpeedScale = Dvar::Register("player_duckedSpeedScale", 0.65f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, "The scale applied to the player speed when ducking"); @@ -191,6 +266,12 @@ namespace Components Movement::CGNoclipScaler = Dvar::Register("cg_noclip_scaler", 3.0f, 0.001f, 1000.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, "The speed at which noclip camera moves"); + + Movement::BGBounces = Game::Dvar_RegisterEnum("bg_bounces", + bg_enableBouncesValues, Movement::DISABLED, Game::DVAR_FLAG_REPLICATED, "Bounce glitch settings"); + + Movement::BGBouncesAllAngles = Dvar::Register("bg_bouncesAllAngles", + false, Game::DVAR_FLAG_REPLICATED, "Force bounce from all angles"); }); // Hook PM_CmdScaleForStance in PM_CmdScale_Walk @@ -208,6 +289,11 @@ namespace Components // Hook PM_MoveScale so we can add custom speed scale for Ufo and Noclip Utils::Hook(0x56F845, Movement::PM_MoveScaleStub, HOOK_CALL).install()->quick(); Utils::Hook(0x56FABD, Movement::PM_MoveScaleStub, HOOK_CALL).install()->quick(); + + Utils::Hook(0x4B1B2D, Movement::PM_StepSlideMoveStub, HOOK_JUMP).install()->quick(); + Utils::Hook(0x57383E, Movement::Jump_ClearStateHk, HOOK_CALL).install()->quick(); + + Utils::Hook(0x4B1B97, Movement::PM_ProjectVelocityStub, HOOK_CALL).install()->quick(); } Movement::~Movement() diff --git a/src/Components/Modules/Movement.hpp b/src/Components/Modules/Movement.hpp index 09678e37..791dfedc 100644 --- a/src/Components/Modules/Movement.hpp +++ b/src/Components/Modules/Movement.hpp @@ -9,12 +9,17 @@ namespace Components ~Movement(); private: + enum BouncesSettings { DISABLED, ENABLED, DOUBLE }; + static Dvar::Var PlayerDuckedSpeedScale; static Dvar::Var PlayerLastStandCrawlSpeedScale; static Dvar::Var PlayerProneSpeedScale; static Dvar::Var PlayerSpectateSpeedScale; static Dvar::Var CGUfoScaler; static Dvar::Var CGNoclipScaler; + static Dvar::Var BGBouncesAllAngles; + // Can't use Var class inside assembly stubs + static Game::dvar_t* BGBounces; static float PM_CmdScaleForStance(const Game::pmove_s* move); static void PM_CmdScaleForStanceStub(); @@ -22,6 +27,11 @@ namespace Components static float PM_MoveScale(Game::playerState_s* ps, float forwardmove, float rightmove, float upmove); static void PM_MoveScaleStub(); + // Bounce logic + static void PM_StepSlideMoveStub(); + static void PM_ProjectVelocityStub(const float* velIn, const float* normal, float* velOut); + static void Jump_ClearStateHk(Game::playerState_s* ps); + static Game::dvar_t* Dvar_RegisterLastStandSpeedScale(const char* name, float value, float min, float max, int flags, const char* desc); static Game::dvar_t* Dvar_RegisterSpectateSpeedScale(const char* name, float value, float min, float max, int flags, const char* desc); }; diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index edaafa42..c327a79b 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -239,34 +239,6 @@ namespace Components } } - Game::dvar_t* QuickPatch::sv_enableBounces; - __declspec(naked) void QuickPatch::BounceStub() - { - __asm - { - // check the value of sv_enableBounces - push eax; - mov eax, sv_enableBounces; - cmp byte ptr[eax + 16], 1; - pop eax; - - // always bounce if sv_enableBounces is set to 1 - je bounce; - - // original code - cmp dword ptr[esp + 24h], 0; - jnz dontBounce; - - bounce: - push 0x004B1B34; - retn; - - dontBounce: - push 0x004B1B48; - retn; - } - } - Game::dvar_t* QuickPatch::Dvar_RegisterAspectRatioDvar(const char* name, char**, int defaultVal, int flags, const char* description) { static const char* r_aspectRatioEnum[] = @@ -457,10 +429,6 @@ namespace Components // Hook escape handling on open console to change behaviour to close the console instead of only canceling autocomplete Utils::Hook(0x4F66A3, CL_KeyEvent_ConsoleEscape_Stub, HOOK_JUMP).install()->quick(); - // bounce dvar - sv_enableBounces = Game::Dvar_RegisterBool("sv_enableBounces", false, Game::DVAR_FLAG_REPLICATED, "Enables bouncing on the server"); - Utils::Hook(0x4B1B2D, QuickPatch::BounceStub, HOOK_JUMP).install()->quick(); - // Intermission time dvar Game::Dvar_RegisterFloat("scr_intermissionTime", 10, 0, 120, Game::DVAR_FLAG_REPLICATED | Game::DVAR_FLAG_DEDISAVED, "Time in seconds before match server loads the next map"); diff --git a/src/Components/Modules/QuickPatch.hpp b/src/Components/Modules/QuickPatch.hpp index 6b13a5a1..197f9bc8 100644 --- a/src/Components/Modules/QuickPatch.hpp +++ b/src/Components/Modules/QuickPatch.hpp @@ -31,9 +31,6 @@ namespace Components static bool InvalidNameCheck(char* dest, const char* source, int size); static void InvalidNameStub(); - static Game::dvar_t* sv_enableBounces; - static void BounceStub(); - static Dvar::Var r_customAspectRatio; static Game::dvar_t* Dvar_RegisterAspectRatioDvar(const char* name, char** enumValues, int defaultVal, int flags, const char* description); static void SetAspectRatioStub(); From 9af4a9b8e04ce934729f7da8c80943231c12b0ba Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 19 Jan 2022 00:53:06 +0000 Subject: [PATCH 3/4] Comments, I'm tired :alien: --- src/Components/Modules/Movement.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Movement.cpp b/src/Components/Modules/Movement.cpp index 70fdb608..2fb7552e 100644 --- a/src/Components/Modules/Movement.cpp +++ b/src/Components/Modules/Movement.cpp @@ -159,7 +159,7 @@ namespace Components { __asm { - // Check the value of BGEnableBounces + // Check the value of BGBounces push ecx push eax @@ -170,7 +170,7 @@ namespace Components pop eax pop ecx - // Do not bounce if BGEnableBounces is 0 + // Do not bounce if BGBounces is 0 jle noBounce // Bounce From 65eb2e34e01f3cefb4de4dc6bd11538c73bbf930 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Wed, 19 Jan 2022 10:48:33 +0000 Subject: [PATCH 4/4] Change style a bit --- src/Components/Modules/Movement.cpp | 14 +++++++------- src/Components/Modules/Movement.hpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Components/Modules/Movement.cpp b/src/Components/Modules/Movement.cpp index 2fb7552e..c631b623 100644 --- a/src/Components/Modules/Movement.cpp +++ b/src/Components/Modules/Movement.cpp @@ -187,7 +187,7 @@ namespace Components void Movement::PM_ProjectVelocityStub(const float* velIn, const float* normal, float* velOut) { - auto lengthSquared2D = velIn[0] * velIn[0] + velIn[1] * velIn[1]; + const auto lengthSquared2D = velIn[0] * velIn[0] + velIn[1] * velIn[1]; if (std::fabsf(normal[2]) < 0.001f || lengthSquared2D == 0.0) { @@ -199,7 +199,7 @@ namespace Components auto newZ = velIn[0] * normal[0] + velIn[1] * normal[1]; newZ = -newZ / normal[2]; - auto lengthScale = std::sqrtf((velIn[2] * velIn[2] + lengthSquared2D) + const auto lengthScale = std::sqrtf((velIn[2] * velIn[2] + lengthSquared2D) / (newZ * newZ + lengthSquared2D)); if (Movement::BGBouncesAllAngles.get() @@ -212,7 +212,7 @@ namespace Components } // Double bounces - void Movement::Jump_ClearStateHk(Game::playerState_s* ps) + void Movement::Jump_ClearStateHook(Game::playerState_s* ps) { if (Movement::BGBounces->current.integer == Movement::DOUBLE) return; @@ -242,7 +242,7 @@ namespace Components { Dvar::OnInit([] { - static const char* bg_enableBouncesValues[] = + static const char* bg_bouncesValues[] = { "disabled", "enabled", @@ -268,7 +268,7 @@ namespace Components "The speed at which noclip camera moves"); Movement::BGBounces = Game::Dvar_RegisterEnum("bg_bounces", - bg_enableBouncesValues, Movement::DISABLED, Game::DVAR_FLAG_REPLICATED, "Bounce glitch settings"); + bg_bouncesValues, Movement::DISABLED, Game::DVAR_FLAG_REPLICATED, "Bounce glitch settings"); Movement::BGBouncesAllAngles = Dvar::Register("bg_bouncesAllAngles", false, Game::DVAR_FLAG_REPLICATED, "Force bounce from all angles"); @@ -290,9 +290,9 @@ namespace Components Utils::Hook(0x56F845, Movement::PM_MoveScaleStub, HOOK_CALL).install()->quick(); Utils::Hook(0x56FABD, Movement::PM_MoveScaleStub, HOOK_CALL).install()->quick(); + // Bounce logic Utils::Hook(0x4B1B2D, Movement::PM_StepSlideMoveStub, HOOK_JUMP).install()->quick(); - Utils::Hook(0x57383E, Movement::Jump_ClearStateHk, HOOK_CALL).install()->quick(); - + Utils::Hook(0x57383E, Movement::Jump_ClearStateHook, HOOK_CALL).install()->quick(); Utils::Hook(0x4B1B97, Movement::PM_ProjectVelocityStub, HOOK_CALL).install()->quick(); } diff --git a/src/Components/Modules/Movement.hpp b/src/Components/Modules/Movement.hpp index 791dfedc..fd91293a 100644 --- a/src/Components/Modules/Movement.hpp +++ b/src/Components/Modules/Movement.hpp @@ -30,7 +30,7 @@ namespace Components // Bounce logic static void PM_StepSlideMoveStub(); static void PM_ProjectVelocityStub(const float* velIn, const float* normal, float* velOut); - static void Jump_ClearStateHk(Game::playerState_s* ps); + static void Jump_ClearStateHook(Game::playerState_s* ps); static Game::dvar_t* Dvar_RegisterLastStandSpeedScale(const char* name, float value, float min, float max, int flags, const char* desc); static Game::dvar_t* Dvar_RegisterSpectateSpeedScale(const char* name, float value, float min, float max, int flags, const char* desc);