From 2b68f47d86879c8059234091e0d9b55f1380c6a9 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Mon, 2 May 2022 19:34:26 +0100 Subject: [PATCH 1/2] [Movement] Fix bug --- src/Components/Modules/Movement.cpp | 180 +++++++++------------------- src/Components/Modules/Movement.hpp | 12 +- 2 files changed, 62 insertions(+), 130 deletions(-) diff --git a/src/Components/Modules/Movement.cpp b/src/Components/Modules/Movement.cpp index 57bfc72f..9c322b9a 100644 --- a/src/Components/Modules/Movement.cpp +++ b/src/Components/Modules/Movement.cpp @@ -2,9 +2,6 @@ namespace Components { - Dvar::Var Movement::PlayerDuckedSpeedScale; - Dvar::Var Movement::PlayerLastStandCrawlSpeedScale; - Dvar::Var Movement::PlayerProneSpeedScale; Dvar::Var Movement::PlayerSpectateSpeedScale; Dvar::Var Movement::CGUfoScaler; Dvar::Var Movement::CGNoclipScaler; @@ -13,99 +10,50 @@ namespace Components Dvar::Var Movement::BGPlayerEjection; Dvar::Var Movement::BGPlayerCollision; Game::dvar_t* Movement::BGBounces; + Game::dvar_t* Movement::PlayerDuckedSpeedScale; + Game::dvar_t* Movement::PlayerProneSpeedScale; - float Movement::PM_CmdScaleForStance(const Game::pmove_s* pm) - { - assert(pm->ps != nullptr); - - const auto* playerState = pm->ps; - float scale; - - if (playerState->viewHeightLerpTime != 0 && playerState->viewHeightLerpTarget == 0xB) - { - scale = pm->cmd.serverTime - playerState->viewHeightLerpTime / 400.0f; - - if (0.0f <= scale) - { - if (scale > 1.0f) - { - scale = 1.0f; - return scale * 0.15f + (1.0f - scale) * 0.65f; - } - - if (scale != 0.0f) - { - return scale * 0.15f + (1.0f - scale) * 0.65f; - } - } - } - - if ((playerState->viewHeightLerpTime != 0 && playerState->viewHeightLerpTarget == 0x28) && - playerState->viewHeightLerpDown == 0) - { - scale = 400.0f / pm->cmd.serverTime - playerState->viewHeightLerpTime; - - if (0.0f <= scale) - { - if (scale > 1.0f) - { - scale = 1.0f; - } - else if (scale != 0.0f) - { - return scale * 0.65f + (1.0f - scale) * 0.15f; - } - } - } - - scale = 1.0f; - const auto stance = Game::PM_GetEffectiveStance(playerState); - - if (stance == Game::PM_EFF_STANCE_PRONE) - { - scale = Movement::PlayerProneSpeedScale.get(); - } - - else if (stance == Game::PM_EFF_STANCE_DUCKED) - { - scale = Movement::PlayerDuckedSpeedScale.get(); - } - - else if (stance == Game::PM_EFF_STANCE_LASTSTANDCRAWL) - { - scale = Movement::PlayerLastStandCrawlSpeedScale.get(); - } - - return scale; - } - - __declspec(naked) void Movement::PM_CmdScaleForStanceStub() + __declspec(naked) void Movement::PM_PlayerDuckedSpeedScaleStub() { __asm { - pushad + push eax + mov eax, Movement::PlayerDuckedSpeedScale + fld dword ptr [eax + 0x10] // dvar_t.current.value + pop eax - push edx - call Movement::PM_CmdScaleForStance // pm - add esp, 4 - - popad + // Game's code + pop ecx ret } } - float Movement::PM_MoveScale(Game::playerState_s* ps, float forwardmove, - float rightmove, float upmove) + __declspec(naked) void Movement::PM_PlayerProneSpeedScaleStub() + { + __asm + { + push eax + mov eax, Movement::PlayerProneSpeedScale + fld dword ptr [eax + 0x10] // dvar_t.current.value + pop eax + + // Game's code + pop ecx + ret + } + } + + float Movement::PM_MoveScale(Game::playerState_s* ps, float fmove, + float rmove, float umove) { assert(ps != nullptr); - auto max = (std::fabsf(forwardmove) < std::fabsf(rightmove)) - ? std::fabsf(rightmove) - : std::fabsf(forwardmove); + auto max = std::fabsf(fmove) < std::fabsf(rmove) + ? std::fabsf(rmove) : std::fabsf(fmove); - if (std::fabsf(upmove) > max) + if (std::fabsf(umove) > max) { - max = std::fabsf(upmove); + max = std::fabsf(umove); } if (max == 0.0f) @@ -113,28 +61,28 @@ namespace Components return 0.0f; } - auto total = std::sqrtf(forwardmove * forwardmove - + rightmove * rightmove + upmove * upmove); - auto scale = (ps->speed * max) / (127.0f * total); + auto total = std::sqrtf(fmove * fmove + + rmove * rmove + umove * umove); + auto scale = (static_cast(ps->speed) * max) / (127.0f * total); if (ps->pm_flags & Game::PMF_WALKING || ps->leanf != 0.0f) { scale *= 0.4f; } - if (ps->pm_type == Game::PM_NOCLIP) + switch (ps->pm_type) { - return scale * Movement::CGNoclipScaler.get(); - } - - if (ps->pm_type == Game::PM_UFO) - { - return scale * Movement::CGUfoScaler.get(); - } - - if (ps->pm_type == Game::PM_SPECTATOR) - { - return scale * Movement::PlayerSpectateSpeedScale.get(); + case Game::pmtype_t::PM_NOCLIP: + scale *= Movement::CGNoclipScaler.get(); + break; + case Game::pmtype_t::PM_UFO: + scale *= Movement::CGUfoScaler.get(); + break; + case Game::pmtype_t::PM_SPECTATOR: + scale *= Movement::PlayerSpectateSpeedScale.get(); + break; + default: + break; } return scale; @@ -146,9 +94,9 @@ namespace Components { pushad - push [esp + 0xC + 0x20] // upmove - push [esp + 0xC + 0x20] // rightmove - push [esp + 0xC + 0x20] // forwardmove + push [esp + 0xC + 0x20] // umove + push [esp + 0xC + 0x20] // rmove + push [esp + 0xC + 0x20] // fmove push esi // ps call Movement::PM_MoveScale add esp, 0x10 @@ -230,9 +178,9 @@ namespace Components if (ent->client != nullptr && BGRocketJump.get()) { - ent->client->ps.velocity[0] += (0 - wp->forward[0]) * 64.0f; - ent->client->ps.velocity[1] += (0 - wp->forward[1]) * 64.0f; - ent->client->ps.velocity[2] += (0 - wp->forward[2]) * 64.0f; + ent->client->ps.velocity[0] += (0.0f - wp->forward[0]) * 64.0f; + ent->client->ps.velocity[1] += (0.0f - wp->forward[1]) * 64.0f; + ent->client->ps.velocity[2] += (0.0f - wp->forward[2]) * 64.0f; } return result; @@ -260,15 +208,6 @@ namespace Components } } - Game::dvar_t* Movement::Dvar_RegisterLastStandSpeedScale(const char* dvarName, float value, - float min, float max, unsigned __int16 /*flags*/, const char* description) - { - Movement::PlayerLastStandCrawlSpeedScale = Dvar::Register(dvarName, value, - min, max, Game::DVAR_CHEAT | Game::DVAR_CODINFO, description); - - return Movement::PlayerLastStandCrawlSpeedScale.get(); - } - Game::dvar_t* Movement::Dvar_RegisterSpectateSpeedScale(const char* dvarName, float value, float min, float max, unsigned __int16 /*flags*/, const char* description) { @@ -290,11 +229,11 @@ namespace Components nullptr }; - Movement::PlayerDuckedSpeedScale = Dvar::Register("player_duckedSpeedScale", + Movement::PlayerDuckedSpeedScale = Game::Dvar_RegisterFloat("player_duckedSpeedScale", 0.65f, 0.0f, 5.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, "The scale applied to the player speed when ducking"); - Movement::PlayerProneSpeedScale = Dvar::Register("player_proneSpeedScale", + Movement::PlayerProneSpeedScale = Game::Dvar_RegisterFloat("player_proneSpeedScale", 0.15f, 0.0f, 5.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, "The scale applied to the player speed when crawling"); @@ -323,18 +262,13 @@ namespace Components true, Game::DVAR_CODINFO, "Push intersecting players away from each other"); }); - // Hook PM_CmdScaleForStance in PM_CmdScale_Walk - Utils::Hook(0x572F34, Movement::PM_CmdScaleForStanceStub, HOOK_CALL).install()->quick(); - - //Hook PM_CmdScaleForStance in PM_GetMaxSpeed - Utils::Hook(0x57395F, Movement::PM_CmdScaleForStanceStub, HOOK_CALL).install()->quick(); - - // Hook Dvar_RegisterFloat. Only thing that's changed is that the 0x80 flag is not used. - Utils::Hook(0x448B66, Movement::Dvar_RegisterLastStandSpeedScale, HOOK_CALL).install()->quick(); - // Hook Dvar_RegisterFloat. Only thing that's changed is that the 0x80 flag is not used. Utils::Hook(0x448990, Movement::Dvar_RegisterSpectateSpeedScale, HOOK_CALL).install()->quick(); + // PM_CmdScaleForStance + Utils::Hook(0x572D9B, Movement::PM_PlayerDuckedSpeedScaleStub, HOOK_JUMP).install()->quick(); + Utils::Hook(0x572DA5, Movement::PM_PlayerProneSpeedScaleStub, HOOK_JUMP).install()->quick(); + // 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(); diff --git a/src/Components/Modules/Movement.hpp b/src/Components/Modules/Movement.hpp index 2b718258..b1e06526 100644 --- a/src/Components/Modules/Movement.hpp +++ b/src/Components/Modules/Movement.hpp @@ -10,9 +10,6 @@ namespace Components 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; @@ -22,11 +19,13 @@ namespace Components static Dvar::Var BGPlayerCollision; // Can't use Var class inside assembly stubs static Game::dvar_t* BGBounces; + static Game::dvar_t* PlayerDuckedSpeedScale; + static Game::dvar_t* PlayerProneSpeedScale; - static float PM_CmdScaleForStance(const Game::pmove_s* move); - static void PM_CmdScaleForStanceStub(); + static void PM_PlayerDuckedSpeedScaleStub(); + static void PM_PlayerProneSpeedScaleStub(); - static float PM_MoveScale(Game::playerState_s* ps, float forwardmove, float rightmove, float upmove); + static float PM_MoveScale(Game::playerState_s* ps, float fmove, float rmove, float umove); static void PM_MoveScaleStub(); // Bounce logic @@ -40,7 +39,6 @@ namespace Components static int StuckInClient_Hk(Game::gentity_s* self); static void CM_TransformedCapsuleTrace_Hk(Game::trace_t* results, const float* start, const float* end, const Game::Bounds* bounds, const Game::Bounds* capsule, int contents, const float* origin, const float* angles); - static Game::dvar_t* Dvar_RegisterLastStandSpeedScale(const char* dvarName, float value, float min, float max, unsigned __int16 flags, const char* description); static Game::dvar_t* Dvar_RegisterSpectateSpeedScale(const char* dvarName, float value, float min, float max, unsigned __int16 flags, const char* description); }; } From 299eb11e1c31351dc616361776f2e08b38e61a56 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Mon, 2 May 2022 19:36:50 +0100 Subject: [PATCH 2/2] [Movement] Fix format --- src/Components/Modules/Movement.cpp | 470 ++++++++++++++-------------- src/Components/Modules/Movement.hpp | 62 ++-- 2 files changed, 266 insertions(+), 266 deletions(-) diff --git a/src/Components/Modules/Movement.cpp b/src/Components/Modules/Movement.cpp index 9c322b9a..806899c1 100644 --- a/src/Components/Modules/Movement.cpp +++ b/src/Components/Modules/Movement.cpp @@ -2,289 +2,289 @@ namespace Components { - Dvar::Var Movement::PlayerSpectateSpeedScale; - Dvar::Var Movement::CGUfoScaler; - Dvar::Var Movement::CGNoclipScaler; - Dvar::Var Movement::BGBouncesAllAngles; - Dvar::Var Movement::BGRocketJump; - Dvar::Var Movement::BGPlayerEjection; - Dvar::Var Movement::BGPlayerCollision; - Game::dvar_t* Movement::BGBounces; - Game::dvar_t* Movement::PlayerDuckedSpeedScale; - Game::dvar_t* Movement::PlayerProneSpeedScale; + Dvar::Var Movement::PlayerSpectateSpeedScale; + Dvar::Var Movement::CGUfoScaler; + Dvar::Var Movement::CGNoclipScaler; + Dvar::Var Movement::BGBouncesAllAngles; + Dvar::Var Movement::BGRocketJump; + Dvar::Var Movement::BGPlayerEjection; + Dvar::Var Movement::BGPlayerCollision; + Game::dvar_t* Movement::BGBounces; + Game::dvar_t* Movement::PlayerDuckedSpeedScale; + Game::dvar_t* Movement::PlayerProneSpeedScale; - __declspec(naked) void Movement::PM_PlayerDuckedSpeedScaleStub() - { - __asm - { - push eax - mov eax, Movement::PlayerDuckedSpeedScale - fld dword ptr [eax + 0x10] // dvar_t.current.value - pop eax + __declspec(naked) void Movement::PM_PlayerDuckedSpeedScaleStub() + { + __asm + { + push eax + mov eax, Movement::PlayerDuckedSpeedScale + fld dword ptr [eax + 0x10] // dvar_t.current.value + pop eax - // Game's code - pop ecx - ret - } - } + // Game's code + pop ecx + ret + } + } - __declspec(naked) void Movement::PM_PlayerProneSpeedScaleStub() - { - __asm - { - push eax - mov eax, Movement::PlayerProneSpeedScale - fld dword ptr [eax + 0x10] // dvar_t.current.value - pop eax + __declspec(naked) void Movement::PM_PlayerProneSpeedScaleStub() + { + __asm + { + push eax + mov eax, Movement::PlayerProneSpeedScale + fld dword ptr [eax + 0x10] // dvar_t.current.value + pop eax - // Game's code - pop ecx - ret - } - } + // Game's code + pop ecx + ret + } + } - float Movement::PM_MoveScale(Game::playerState_s* ps, float fmove, - float rmove, float umove) - { - assert(ps != nullptr); + float Movement::PM_MoveScale(Game::playerState_s* ps, float fmove, + float rmove, float umove) + { + assert(ps != nullptr); - auto max = std::fabsf(fmove) < std::fabsf(rmove) - ? std::fabsf(rmove) : std::fabsf(fmove); + auto max = std::fabsf(fmove) < std::fabsf(rmove) + ? std::fabsf(rmove) : std::fabsf(fmove); - if (std::fabsf(umove) > max) - { - max = std::fabsf(umove); - } + if (std::fabsf(umove) > max) + { + max = std::fabsf(umove); + } - if (max == 0.0f) - { - return 0.0f; - } + if (max == 0.0f) + { + return 0.0f; + } - auto total = std::sqrtf(fmove * fmove - + rmove * rmove + umove * umove); - auto scale = (static_cast(ps->speed) * max) / (127.0f * total); + auto total = std::sqrtf(fmove * fmove + + rmove * rmove + umove * umove); + auto scale = (static_cast(ps->speed) * max) / (127.0f * total); - if (ps->pm_flags & Game::PMF_WALKING || ps->leanf != 0.0f) - { - scale *= 0.4f; - } + if (ps->pm_flags & Game::PMF_WALKING || ps->leanf != 0.0f) + { + scale *= 0.4f; + } - switch (ps->pm_type) - { - case Game::pmtype_t::PM_NOCLIP: - scale *= Movement::CGNoclipScaler.get(); - break; - case Game::pmtype_t::PM_UFO: - scale *= Movement::CGUfoScaler.get(); - break; - case Game::pmtype_t::PM_SPECTATOR: - scale *= Movement::PlayerSpectateSpeedScale.get(); - break; - default: - break; - } + switch (ps->pm_type) + { + case Game::pmtype_t::PM_NOCLIP: + scale *= Movement::CGNoclipScaler.get(); + break; + case Game::pmtype_t::PM_UFO: + scale *= Movement::CGUfoScaler.get(); + break; + case Game::pmtype_t::PM_SPECTATOR: + scale *= Movement::PlayerSpectateSpeedScale.get(); + break; + default: + break; + } - return scale; - } + return scale; + } - __declspec(naked) void Movement::PM_MoveScaleStub() - { - __asm - { - pushad + __declspec(naked) void Movement::PM_MoveScaleStub() + { + __asm + { + pushad - push [esp + 0xC + 0x20] // umove - push [esp + 0xC + 0x20] // rmove - push [esp + 0xC + 0x20] // fmove - push esi // ps - call Movement::PM_MoveScale - add esp, 0x10 + push [esp + 0xC + 0x20] // umove + push [esp + 0xC + 0x20] // rmove + push [esp + 0xC + 0x20] // fmove + push esi // ps + call Movement::PM_MoveScale + add esp, 0x10 - popad - ret - } - } + popad + ret + } + } - __declspec(naked) void Movement::PM_StepSlideMoveStub() - { - __asm - { - // Check the value of BGBounces - push ecx - push eax + __declspec(naked) void Movement::PM_StepSlideMoveStub() + { + __asm + { + // Check the value of BGBounces + push ecx + push eax - mov eax, Movement::BGBounces - mov ecx, dword ptr [eax + 0x10] - test ecx, ecx + mov eax, Movement::BGBounces + mov ecx, dword ptr [eax + 0x10] + test ecx, ecx - pop eax - pop ecx + pop eax + pop ecx - // Do not bounce if BGBounces is 0 - jle noBounce + // Do not bounce if BGBounces is 0 + jle noBounce - // Bounce - push 0x4B1B34 - retn + // Bounce + push 0x4B1B34 + retn - noBounce: - // Original game code - cmp dword ptr [esp + 0x24], 0 - push 0x4B1B48 - retn - } - } + noBounce: + // Original game code + cmp dword ptr [esp + 0x24], 0 + push 0x4B1B48 + retn + } + } - void Movement::PM_ProjectVelocityStub(const float* velIn, const float* normal, float* velOut) - { - const auto lengthSquared2D = velIn[0] * velIn[0] + velIn[1] * velIn[1]; + void Movement::PM_ProjectVelocityStub(const float* velIn, const float* normal, float* velOut) + { + const 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; - } + 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]; - const auto lengthScale = std::sqrtf((velIn[2] * velIn[2] + lengthSquared2D) - / (newZ * newZ + lengthSquared2D)); + auto newZ = velIn[0] * normal[0] + velIn[1] * normal[1]; + newZ = -newZ / normal[2]; + const 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; - } - } + 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_ClearState_Hk(Game::playerState_s* ps) - { - if (Movement::BGBounces->current.integer != Movement::DOUBLE) - { - Game::Jump_ClearState(ps); - } - } + // Double bounces + void Movement::Jump_ClearState_Hk(Game::playerState_s* ps) + { + if (Movement::BGBounces->current.integer != Movement::DOUBLE) + { + Game::Jump_ClearState(ps); + } + } - Game::gentity_s* Movement::Weapon_RocketLauncher_Fire_Hk(Game::gentity_s* ent, unsigned int weaponIndex, - float spread, Game::weaponParms* wp, const float* gunVel, Game::lockonFireParms* lockParms, bool a7) - { - auto* result = Game::Weapon_RocketLauncher_Fire(ent, weaponIndex, spread, wp, gunVel, lockParms, a7); + Game::gentity_s* Movement::Weapon_RocketLauncher_Fire_Hk(Game::gentity_s* ent, unsigned int weaponIndex, + float spread, Game::weaponParms* wp, const float* gunVel, Game::lockonFireParms* lockParms, bool a7) + { + auto* result = Game::Weapon_RocketLauncher_Fire(ent, weaponIndex, spread, wp, gunVel, lockParms, a7); - if (ent->client != nullptr && BGRocketJump.get()) - { - ent->client->ps.velocity[0] += (0.0f - wp->forward[0]) * 64.0f; - ent->client->ps.velocity[1] += (0.0f - wp->forward[1]) * 64.0f; - ent->client->ps.velocity[2] += (0.0f - wp->forward[2]) * 64.0f; - } + if (ent->client != nullptr && BGRocketJump.get()) + { + ent->client->ps.velocity[0] += (0.0f - wp->forward[0]) * 64.0f; + ent->client->ps.velocity[1] += (0.0f - wp->forward[1]) * 64.0f; + ent->client->ps.velocity[2] += (0.0f - wp->forward[2]) * 64.0f; + } - return result; - } + return result; + } - int Movement::StuckInClient_Hk(Game::gentity_s* self) - { - if (Movement::BGPlayerEjection.get()) - { - return Utils::Hook::Call(0x402D30)(self); // StuckInClient - } + int Movement::StuckInClient_Hk(Game::gentity_s* self) + { + if (Movement::BGPlayerEjection.get()) + { + return Utils::Hook::Call(0x402D30)(self); // StuckInClient + } - return 0; - } + return 0; + } - void Movement::CM_TransformedCapsuleTrace_Hk(Game::trace_t* results, const float* start, const float* end, - const Game::Bounds* bounds, const Game::Bounds* capsule, int contents, const float* origin, const float* angles) - { - if (Movement::BGPlayerCollision.get()) - { - Utils::Hook::Call - (0x478300) - (results, start, end, bounds, capsule, contents, origin, angles); // CM_TransformedCapsuleTrace - } - } + void Movement::CM_TransformedCapsuleTrace_Hk(Game::trace_t* results, const float* start, const float* end, + const Game::Bounds* bounds, const Game::Bounds* capsule, int contents, const float* origin, const float* angles) + { + if (Movement::BGPlayerCollision.get()) + { + Utils::Hook::Call + (0x478300) + (results, start, end, bounds, capsule, contents, origin, angles); // CM_TransformedCapsuleTrace + } + } - Game::dvar_t* Movement::Dvar_RegisterSpectateSpeedScale(const char* dvarName, float value, - float min, float max, unsigned __int16 /*flags*/, const char* description) - { - Movement::PlayerSpectateSpeedScale = Dvar::Register(dvarName, value, - min, max, Game::DVAR_CHEAT | Game::DVAR_CODINFO, description); + Game::dvar_t* Movement::Dvar_RegisterSpectateSpeedScale(const char* dvarName, float value, + float min, float max, unsigned __int16 /*flags*/, const char* description) + { + Movement::PlayerSpectateSpeedScale = Dvar::Register(dvarName, value, + min, max, Game::DVAR_CHEAT | Game::DVAR_CODINFO, description); - return Movement::PlayerSpectateSpeedScale.get(); - } + return Movement::PlayerSpectateSpeedScale.get(); + } - Movement::Movement() - { - Dvar::OnInit([] - { - static const char* bg_bouncesValues[] = - { - "disabled", - "enabled", - "double", - nullptr - }; + Movement::Movement() + { + Dvar::OnInit([] + { + static const char* bg_bouncesValues[] = + { + "disabled", + "enabled", + "double", + nullptr + }; - Movement::PlayerDuckedSpeedScale = Game::Dvar_RegisterFloat("player_duckedSpeedScale", - 0.65f, 0.0f, 5.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, - "The scale applied to the player speed when ducking"); + Movement::PlayerDuckedSpeedScale = Game::Dvar_RegisterFloat("player_duckedSpeedScale", + 0.65f, 0.0f, 5.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, + "The scale applied to the player speed when ducking"); - Movement::PlayerProneSpeedScale = Game::Dvar_RegisterFloat("player_proneSpeedScale", - 0.15f, 0.0f, 5.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, - "The scale applied to the player speed when crawling"); + Movement::PlayerProneSpeedScale = Game::Dvar_RegisterFloat("player_proneSpeedScale", + 0.15f, 0.0f, 5.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, + "The scale applied to the player speed when crawling"); - // 3arc naming convention - Movement::CGUfoScaler = Dvar::Register("cg_ufo_scaler", - 6.0f, 0.001f, 1000.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, - "The speed at which ufo camera moves"); + // 3arc naming convention + Movement::CGUfoScaler = Dvar::Register("cg_ufo_scaler", + 6.0f, 0.001f, 1000.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, + "The speed at which ufo camera moves"); - Movement::CGNoclipScaler = Dvar::Register("cg_noclip_scaler", - 3.0f, 0.001f, 1000.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, - "The speed at which noclip camera moves"); + Movement::CGNoclipScaler = Dvar::Register("cg_noclip_scaler", + 3.0f, 0.001f, 1000.0f, Game::DVAR_CHEAT | Game::DVAR_CODINFO, + "The speed at which noclip camera moves"); - Movement::BGBounces = Game::Dvar_RegisterEnum("bg_bounces", - bg_bouncesValues, Movement::DISABLED, Game::DVAR_CODINFO, "Bounce glitch settings"); + Movement::BGBounces = Game::Dvar_RegisterEnum("bg_bounces", + bg_bouncesValues, Movement::DISABLED, Game::DVAR_CODINFO, "Bounce glitch settings"); - Movement::BGBouncesAllAngles = Dvar::Register("bg_bouncesAllAngles", - false, Game::DVAR_CODINFO, "Force bounce from all angles"); + Movement::BGBouncesAllAngles = Dvar::Register("bg_bouncesAllAngles", + false, Game::DVAR_CODINFO, "Force bounce from all angles"); - Movement::BGRocketJump = Dvar::Register("bg_rocketJump", - false, Game::DVAR_CODINFO, "Enable CoD4 rocket jumps"); + Movement::BGRocketJump = Dvar::Register("bg_rocketJump", + false, Game::DVAR_CODINFO, "Enable CoD4 rocket jumps"); - Movement::BGPlayerEjection = Dvar::Register("bg_playerEjection", - true, Game::DVAR_CODINFO, "Push intersecting players away from each other"); + Movement::BGPlayerEjection = Dvar::Register("bg_playerEjection", + true, Game::DVAR_CODINFO, "Push intersecting players away from each other"); - Movement::BGPlayerCollision = Dvar::Register("bg_playerCollision", - true, Game::DVAR_CODINFO, "Push intersecting players away from each other"); - }); + Movement::BGPlayerCollision = Dvar::Register("bg_playerCollision", + true, Game::DVAR_CODINFO, "Push intersecting players away from each other"); + }); - // Hook Dvar_RegisterFloat. Only thing that's changed is that the 0x80 flag is not used. - Utils::Hook(0x448990, Movement::Dvar_RegisterSpectateSpeedScale, HOOK_CALL).install()->quick(); + // Hook Dvar_RegisterFloat. Only thing that's changed is that the 0x80 flag is not used. + Utils::Hook(0x448990, Movement::Dvar_RegisterSpectateSpeedScale, HOOK_CALL).install()->quick(); - // PM_CmdScaleForStance - Utils::Hook(0x572D9B, Movement::PM_PlayerDuckedSpeedScaleStub, HOOK_JUMP).install()->quick(); - Utils::Hook(0x572DA5, Movement::PM_PlayerProneSpeedScaleStub, HOOK_JUMP).install()->quick(); + // PM_CmdScaleForStance + Utils::Hook(0x572D9B, Movement::PM_PlayerDuckedSpeedScaleStub, HOOK_JUMP).install()->quick(); + Utils::Hook(0x572DA5, Movement::PM_PlayerProneSpeedScaleStub, HOOK_JUMP).install()->quick(); - // 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(); + // 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(); - // Bounce logic - Utils::Hook(0x4B1B2D, Movement::PM_StepSlideMoveStub, HOOK_JUMP).install()->quick(); - Utils::Hook(0x57383E, Movement::Jump_ClearState_Hk, HOOK_CALL).install()->quick(); - Utils::Hook(0x4B1B97, Movement::PM_ProjectVelocityStub, HOOK_CALL).install()->quick(); + // Bounce logic + Utils::Hook(0x4B1B2D, Movement::PM_StepSlideMoveStub, HOOK_JUMP).install()->quick(); + Utils::Hook(0x57383E, Movement::Jump_ClearState_Hk, HOOK_CALL).install()->quick(); + Utils::Hook(0x4B1B97, Movement::PM_ProjectVelocityStub, HOOK_CALL).install()->quick(); - // Rocket jump - Utils::Hook(0x4A4F9B, Movement::Weapon_RocketLauncher_Fire_Hk, HOOK_CALL).install()->quick(); // FireWeapon + // Rocket jump + Utils::Hook(0x4A4F9B, Movement::Weapon_RocketLauncher_Fire_Hk, HOOK_CALL).install()->quick(); // FireWeapon - // Hook StuckInClient & CM_TransformedCapsuleTrace - // so we can prevent intersecting players from being pushed away from each other - Utils::Hook(0x5D8153, Movement::StuckInClient_Hk, HOOK_CALL).install()->quick(); - Utils::Hook(0x45A5BF, Movement::CM_TransformedCapsuleTrace_Hk, HOOK_CALL).install()->quick(); // SV_ClipMoveToEntity - Utils::Hook(0x5A0CAD, Movement::CM_TransformedCapsuleTrace_Hk, HOOK_CALL).install()->quick(); // CG_ClipMoveToEntity - } + // Hook StuckInClient & CM_TransformedCapsuleTrace + // so we can prevent intersecting players from being pushed away from each other + Utils::Hook(0x5D8153, Movement::StuckInClient_Hk, HOOK_CALL).install()->quick(); + Utils::Hook(0x45A5BF, Movement::CM_TransformedCapsuleTrace_Hk, HOOK_CALL).install()->quick(); // SV_ClipMoveToEntity + Utils::Hook(0x5A0CAD, Movement::CM_TransformedCapsuleTrace_Hk, HOOK_CALL).install()->quick(); // CG_ClipMoveToEntity + } } diff --git a/src/Components/Modules/Movement.hpp b/src/Components/Modules/Movement.hpp index b1e06526..72aa3347 100644 --- a/src/Components/Modules/Movement.hpp +++ b/src/Components/Modules/Movement.hpp @@ -2,43 +2,43 @@ namespace Components { - class Movement : public Component - { - public: - Movement(); + class Movement : public Component + { + public: + Movement(); - private: - enum BouncesSettings { DISABLED, ENABLED, DOUBLE }; + private: + enum BouncesSettings { DISABLED, ENABLED, DOUBLE }; - static Dvar::Var PlayerSpectateSpeedScale; - static Dvar::Var CGUfoScaler; - static Dvar::Var CGNoclipScaler; - static Dvar::Var BGBouncesAllAngles; - static Dvar::Var BGRocketJump; - static Dvar::Var BGPlayerEjection; - static Dvar::Var BGPlayerCollision; - // Can't use Var class inside assembly stubs - static Game::dvar_t* BGBounces; - static Game::dvar_t* PlayerDuckedSpeedScale; - static Game::dvar_t* PlayerProneSpeedScale; + static Dvar::Var PlayerSpectateSpeedScale; + static Dvar::Var CGUfoScaler; + static Dvar::Var CGNoclipScaler; + static Dvar::Var BGBouncesAllAngles; + static Dvar::Var BGRocketJump; + static Dvar::Var BGPlayerEjection; + static Dvar::Var BGPlayerCollision; + // Can't use Var class inside assembly stubs + static Game::dvar_t* BGBounces; + static Game::dvar_t* PlayerDuckedSpeedScale; + static Game::dvar_t* PlayerProneSpeedScale; - static void PM_PlayerDuckedSpeedScaleStub(); - static void PM_PlayerProneSpeedScaleStub(); + static void PM_PlayerDuckedSpeedScaleStub(); + static void PM_PlayerProneSpeedScaleStub(); - static float PM_MoveScale(Game::playerState_s* ps, float fmove, float rmove, float umove); - static void PM_MoveScaleStub(); + static float PM_MoveScale(Game::playerState_s* ps, float fmove, float rmove, float umove); + 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_ClearState_Hk(Game::playerState_s* ps); + // Bounce logic + static void PM_StepSlideMoveStub(); + static void PM_ProjectVelocityStub(const float* velIn, const float* normal, float* velOut); + static void Jump_ClearState_Hk(Game::playerState_s* ps); - static Game::gentity_s* Weapon_RocketLauncher_Fire_Hk(Game::gentity_s* ent, unsigned int weaponIndex, float spread, Game::weaponParms* wp, const float* gunVel, Game::lockonFireParms* lockParms, bool a7); + static Game::gentity_s* Weapon_RocketLauncher_Fire_Hk(Game::gentity_s* ent, unsigned int weaponIndex, float spread, Game::weaponParms* wp, const float* gunVel, Game::lockonFireParms* lockParms, bool a7); - // Player collison - static int StuckInClient_Hk(Game::gentity_s* self); - static void CM_TransformedCapsuleTrace_Hk(Game::trace_t* results, const float* start, const float* end, const Game::Bounds* bounds, const Game::Bounds* capsule, int contents, const float* origin, const float* angles); + // Player collison + static int StuckInClient_Hk(Game::gentity_s* self); + static void CM_TransformedCapsuleTrace_Hk(Game::trace_t* results, const float* start, const float* end, const Game::Bounds* bounds, const Game::Bounds* capsule, int contents, const float* origin, const float* angles); - static Game::dvar_t* Dvar_RegisterSpectateSpeedScale(const char* dvarName, float value, float min, float max, unsigned __int16 flags, const char* description); - }; + static Game::dvar_t* Dvar_RegisterSpectateSpeedScale(const char* dvarName, float value, float min, float max, unsigned __int16 flags, const char* description); + }; }