From 1112eba7fa2a25007a97cbda6757cf634fb24179 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sun, 7 Nov 2021 11:09:00 +0000 Subject: [PATCH 1/5] Add customizable speed scale for stance --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/Dvar.cpp | 3 +++ src/Game/Structs.hpp | 31 +++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 7b76cb02..fea7625e 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -104,6 +104,7 @@ namespace Components Loader::Register(new Gamepad()); Loader::Register(new Chat()); Loader::Register(new TextRenderer()); + Loader::Register(new Movement()); Loader::Register(new Client()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 2265b729..dd948b09 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -132,6 +132,7 @@ namespace Components #include "Modules/SoundMutexFix.hpp" #include "Modules/Chat.hpp" #include "Modules/TextRenderer.hpp" +#include "Modules/Movement.hpp" #include "Modules/Gamepad.hpp" #include "Modules/Client.hpp" diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index d0892d2e..24149280 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -299,6 +299,9 @@ namespace Components // Uncheat ui_debugMode Utils::Hook::Xor(0x6312DE, Game::dvar_flag::DVAR_FLAG_CHEAT); + // Remove unknown flag (to prevent unknown behaviour) + Utils::Hook::Xor(0x448B42, Game::dvar_flag::DVAR_FLAG_UNKNOWN80); + // Hook dvar 'name' registration Utils::Hook(0x40531C, Dvar::RegisterName, HOOK_CALL).install()->quick(); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 7be1e8d7..1a9c019c 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -6876,6 +6876,37 @@ namespace Game const char* args[9]; }; + struct pmove_s + { + playerState_s* ps; + usercmd_s cmd; + usercmd_s oldcmd; + int tracemask; + int numtouch; + int touchents[32]; + char __pad0[24]; + float xyspeed; + int proneChange; + float maxSprintTimeMultiplier; + bool mantleStarted; + float mantleEndPos[3]; + int mantleDuration; + int viewChangeTime; + float viewChange; + float fTorsoPitch; + float fWaistPitch; + unsigned char handler; + }; + + enum EffectiveStance + { + PM_EFF_STANCE_DEFAULT = 0, + PM_EFF_STANCE_PRONE = 1, + PM_EFF_STANCE_DUCKED = 2, + PM_EFF_STANCE_LASTSTANDCRAWL = 3, + PM_EFF_STANCE_COUNT = 4 + }; + #pragma endregion #ifndef IDA From 1b1a53cef623dfcfc99870a46261bfe2b0bea5e3 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sun, 7 Nov 2021 11:16:56 +0000 Subject: [PATCH 2/5] Add Module --- src/Components/Modules/Dvar.cpp | 2 +- src/Components/Modules/Movement.cpp | 151 ++++++++++++++++++++++++++++ src/Components/Modules/Movement.hpp | 20 ++++ 3 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 src/Components/Modules/Movement.cpp create mode 100644 src/Components/Modules/Movement.hpp diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 24149280..5b7122d2 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -299,7 +299,7 @@ namespace Components // Uncheat ui_debugMode Utils::Hook::Xor(0x6312DE, Game::dvar_flag::DVAR_FLAG_CHEAT); - // Remove unknown flag (to prevent unknown behaviour) + // Remove unknown flag (prevent unknown behaviour) Utils::Hook::Xor(0x448B42, Game::dvar_flag::DVAR_FLAG_UNKNOWN80); // Hook dvar 'name' registration diff --git a/src/Components/Modules/Movement.cpp b/src/Components/Modules/Movement.cpp new file mode 100644 index 00000000..10a1377a --- /dev/null +++ b/src/Components/Modules/Movement.cpp @@ -0,0 +1,151 @@ +#include "STDInclude.hpp" + +namespace Components +{ + Dvar::Var Movement::PlayerDuckedSpeedScale; + Dvar::Var Movement::PlayerLastStandCrawlSpeedScale; + Dvar::Var Movement::PlayerProneSpeedScale; + + int Movement::PMGetEffectiveStance(Game::playerState_s* ps) + { + auto heightTarget = ps->viewHeightTarget; + + if (heightTarget == 0x16) + return Game::PM_EFF_STANCE_LASTSTANDCRAWL; + + if (heightTarget == 0x28) + return Game::PM_EFF_STANCE_DUCKED; + + if (heightTarget == 0xB) + return Game::PM_EFF_STANCE_PRONE; + + return Game::PM_EFF_STANCE_DEFAULT; + } + + float Movement::PMCmdScaleForStance(Game::pmove_s* move) + { + auto* playerState = move->ps; + float scale; + + if (playerState->viewHeightLerpTime != 0 && playerState->viewHeightLerpTarget == 0xB) + { + scale = move->cmd.serverTime - playerState->viewHeightLerpTime / 400.0f; + + if (0.0f <= scale) + { + auto flags = 0; + + if (scale < 1.0f) + { + flags |= 1 << 8; + } + + if (scale == 1.0f) + { + flags |= 1 << 14; + } + + if (flags == 0) + { + 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 / move->cmd.serverTime - playerState->viewHeightLerpTime; + + if (0.0f <= scale) + { + auto flags = 0; + + if (scale < 1.0f) + { + flags |= 1 << 8; + } + + if (scale == 1.0f) + { + flags |= 1 << 14; + } + + if (flags == 0) + { + scale = 1.0f; + } + else if (scale != 0.0f) + { + return scale * 0.65f + (1.0f - scale) * 0.15f; + } + } + } + + scale = 1.0f; + auto stance = Movement::PMGetEffectiveStance(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::PMCmdScaleForStanceStub() + { + __asm + { + pushad + + push edx + call Movement::PMCmdScaleForStance + add esp, 4 + + popad + ret + } + } + + Movement::Movement() + { + Dvar::OnInit([] + { + 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"); + + Movement::PlayerLastStandCrawlSpeedScale = Dvar::Register("player_lastStandCrawlSpeedScale", + 0.2f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, + "The scale applied to the player speed when crawling in last stand"); + + Movement::PlayerProneSpeedScale = Dvar::Register("player_proneSpeedScale", + 0.15f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, + "The scale applied to the player speed when crawling"); + }); + + Utils::Hook(0x572F34, Movement::PMCmdScaleForStanceStub, HOOK_CALL).install()->quick(); + Utils::Hook(0x57395F, Movement::PMCmdScaleForStanceStub, HOOK_CALL).install()->quick(); + } + + Movement::~Movement() + { + } +} diff --git a/src/Components/Modules/Movement.hpp b/src/Components/Modules/Movement.hpp new file mode 100644 index 00000000..4c8104a2 --- /dev/null +++ b/src/Components/Modules/Movement.hpp @@ -0,0 +1,20 @@ +#pragma once + +namespace Components +{ + class Movement : public Component + { + public: + Movement(); + ~Movement(); + + private: + static Dvar::Var PlayerDuckedSpeedScale; + static Dvar::Var PlayerLastStandCrawlSpeedScale; + static Dvar::Var PlayerProneSpeedScale; + + static int PMGetEffectiveStance(Game::playerState_s* ps); + static float PMCmdScaleForStance(Game::pmove_s* move); + static void PMCmdScaleForStanceStub(); + }; +} From 7664a773e729d47f4b1876dfe64c1d832e04df0b Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sun, 7 Nov 2021 17:58:33 +0000 Subject: [PATCH 3/5] Have comment explain what dvar flag is being modified --- src/Components/Modules/Dvar.cpp | 2 +- src/Game/Structs.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 5b7122d2..0d7f8f9f 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -299,7 +299,7 @@ namespace Components // Uncheat ui_debugMode Utils::Hook::Xor(0x6312DE, Game::dvar_flag::DVAR_FLAG_CHEAT); - // Remove unknown flag (prevent unknown behaviour) + // Remove unknown flag from player_lastStandCrawlSpeedScale (prevent unknown behaviour) Utils::Hook::Xor(0x448B42, Game::dvar_flag::DVAR_FLAG_UNKNOWN80); // Hook dvar 'name' registration diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 1a9c019c..2d8b443c 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -109,7 +109,7 @@ namespace Game IMG_CATEGORY_WATER = 0x5, IMG_CATEGORY_RENDERTARGET = 0x6, IMG_CATEGORY_TEMP = 0x7, - } ; + }; enum buttons_t { From 37e79f7c3acce22bc4f8e5caca4ef4a9f1f36dd0 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 11 Nov 2021 13:38:51 +0000 Subject: [PATCH 4/5] Hook dvar register func --- src/Components/Modules/Dvar.cpp | 3 --- src/Components/Modules/Movement.cpp | 18 ++++++++++++++---- src/Components/Modules/Movement.hpp | 2 ++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 0d7f8f9f..d0892d2e 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -299,9 +299,6 @@ namespace Components // Uncheat ui_debugMode Utils::Hook::Xor(0x6312DE, Game::dvar_flag::DVAR_FLAG_CHEAT); - // Remove unknown flag from player_lastStandCrawlSpeedScale (prevent unknown behaviour) - Utils::Hook::Xor(0x448B42, Game::dvar_flag::DVAR_FLAG_UNKNOWN80); - // Hook dvar 'name' registration Utils::Hook(0x40531C, Dvar::RegisterName, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Movement.cpp b/src/Components/Modules/Movement.cpp index 10a1377a..3c04b232 100644 --- a/src/Components/Modules/Movement.cpp +++ b/src/Components/Modules/Movement.cpp @@ -124,6 +124,14 @@ namespace Components } } + Game::dvar_t* Movement::Dvar_RegisterLastStandSpeedScale(const char* name, float defaultVal, float min, float max, int, const char*) + { + Movement::PlayerLastStandCrawlSpeedScale = Dvar::Register(name, defaultVal, + min, max, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, "TEST DESC"); + + return Movement::PlayerLastStandCrawlSpeedScale.get(); + } + Movement::Movement() { Dvar::OnInit([] @@ -132,17 +140,19 @@ namespace Components 0.65f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, "The scale applied to the player speed when ducking"); - Movement::PlayerLastStandCrawlSpeedScale = Dvar::Register("player_lastStandCrawlSpeedScale", - 0.2f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, - "The scale applied to the player speed when crawling in last stand"); - Movement::PlayerProneSpeedScale = Dvar::Register("player_proneSpeedScale", 0.15f, 0.0f, 5.0f, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, "The scale applied to the player speed when crawling"); }); + // Hook PM_CmdScaleForStance in PM_CmdScale_Walk Utils::Hook(0x572F34, Movement::PMCmdScaleForStanceStub, HOOK_CALL).install()->quick(); + + //Hook PM_CmdScaleForStance in PM_GetMaxSpeed Utils::Hook(0x57395F, Movement::PMCmdScaleForStanceStub, 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(); } Movement::~Movement() diff --git a/src/Components/Modules/Movement.hpp b/src/Components/Modules/Movement.hpp index 4c8104a2..07ad6894 100644 --- a/src/Components/Modules/Movement.hpp +++ b/src/Components/Modules/Movement.hpp @@ -16,5 +16,7 @@ namespace Components static int PMGetEffectiveStance(Game::playerState_s* ps); static float PMCmdScaleForStance(Game::pmove_s* move); static void PMCmdScaleForStanceStub(); + + static Game::dvar_t* Dvar_RegisterLastStandSpeedScale(const char* name, float defaultVal, float min, float max, int flags, const char* desc); }; } From b02d7f41aee85ef2a063f077469737d4376f88b2 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 11 Nov 2021 13:40:52 +0000 Subject: [PATCH 5/5] Overlooked this detail --- 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 3c04b232..f71c9699 100644 --- a/src/Components/Modules/Movement.cpp +++ b/src/Components/Modules/Movement.cpp @@ -124,10 +124,10 @@ namespace Components } } - Game::dvar_t* Movement::Dvar_RegisterLastStandSpeedScale(const char* name, float defaultVal, float min, float max, int, const char*) + Game::dvar_t* Movement::Dvar_RegisterLastStandSpeedScale(const char* name, float defaultVal, float min, float max, int, const char* desc) { Movement::PlayerLastStandCrawlSpeedScale = Dvar::Register(name, defaultVal, - min, max, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, "TEST DESC"); + min, max, Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_REPLICATED, desc); return Movement::PlayerLastStandCrawlSpeedScale.get(); }