From 92924cefeed80f0e0992175cd70dcd8cf3523988 Mon Sep 17 00:00:00 2001 From: Krzyhau Date: Wed, 23 Oct 2024 20:15:39 +0200 Subject: [PATCH] feat: implement slope boost ensurance cheat --- src/Cheats.cpp | 25 ++++++++++++++++++++++++- src/Cheats.hpp | 1 + src/Modules/Server.cpp | 11 +++++++++++ src/Modules/Server.hpp | 3 +++ src/Offsets/Portal 2 8491.hpp | 1 + 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Cheats.cpp b/src/Cheats.cpp index 1e7f2cc5..00fd55d2 100644 --- a/src/Cheats.cpp +++ b/src/Cheats.cpp @@ -29,7 +29,8 @@ Variable sar_autorecord("sar_autorecord", "0", -1, 1, "Enables or disables automatic demo recording.\n"); Variable sar_autojump("sar_autojump", "0", "Enables automatic jumping on the server.\n"); Variable sar_autostrafe("sar_autostrafe", "0", "Automatically strafes in your current wishdir.\n"); -Variable sar_jumpboost("sar_jumpboost", "0", 0, +Variable sar_ensure_slope_boost("sar_ensure_slope_boost", "0", "Ensures a successful slope boost."); + Variable sar_jumpboost("sar_jumpboost", "0", 0, "Enables special game movement on the server.\n" "0 = Default,\n" "1 = Orange Box Engine,\n" @@ -434,3 +435,25 @@ void Cheats::AutoStrafe(int slot, void *player, CUserCmd *cmd) { } tasPlayer->ApplyMoveAnalog(fb.moveAnalog, cmd); } + +void Cheats::EnsureSlopeBoost(const CHLMoveData *move, void *player, CGameTrace **tr) { + if ((*tr) == NULL) { + return; + } + + if (!server->AllowsMovementChanges() || !sar_ensure_slope_boost.GetBool()) { + return; + } + + bool goingDown = move->m_vecVelocity.z < 0; + bool isntAlreadyGrounded = !(SE(player)->ground_entity()); + bool landedOnSlope = (*tr)->plane.normal.z < 1.0f; + bool wantsToSnapToGround = (*tr)->fraction >= 0.000001f; + + if (goingDown && isntAlreadyGrounded && landedOnSlope && wantsToSnapToGround) { + // Nulling out pointer by reference, so that it's passed in CGameMovement::SetGroundEntity, + // preventing being grounded on this call, letting the player to boost off slope + *tr = NULL; + } + +} \ No newline at end of file diff --git a/src/Cheats.hpp b/src/Cheats.hpp index 039a7941..75d03e85 100644 --- a/src/Cheats.hpp +++ b/src/Cheats.hpp @@ -9,6 +9,7 @@ class Cheats { static void PatchBhop(int slot, void *player, CUserCmd *cmd); static void AutoStrafe(int slot, void *player, CUserCmd *cmd); + static void EnsureSlopeBoost(const CHLMoveData *move, void *player, CGameTrace **tr); }; extern Variable sar_autorecord; diff --git a/src/Modules/Server.cpp b/src/Modules/Server.cpp index 45c9b1b0..db0b8490 100644 --- a/src/Modules/Server.cpp +++ b/src/Modules/Server.cpp @@ -77,6 +77,7 @@ REDECL(Server::CheckJumpButtonBase); REDECL(Server::StepMove); REDECL(Server::TryPlayerMove); REDECL(Server::CheckStuck); +REDECL(Server::SetGroundEntity); REDECL(Server::PlayerMove); REDECL(Server::FinishGravity); REDECL(Server::AirMove); @@ -223,6 +224,15 @@ DETOUR_T(int, Server::CheckStuck) { return result; } +// CGameMovement::SetGroundEntity +DETOUR(Server::SetGroundEntity, CGameTrace* tr) { + auto player = *reinterpret_cast((uintptr_t)thisptr + Offsets::player); + auto mv = *reinterpret_cast((uintptr_t)thisptr + Offsets::mv); + + Cheats::EnsureSlopeBoost(mv, player, &tr); + return Server::SetGroundEntity(thisptr, tr); +} + // CGameMovement::PlayerMove DETOUR(Server::PlayerMove) { auto player = *reinterpret_cast((uintptr_t)thisptr + Offsets::player); @@ -817,6 +827,7 @@ bool Server::Init() { this->g_GameMovement->Hook(Server::StepMove_Hook, Server::StepMove, Offsets::StepMove); this->g_GameMovement->Hook(Server::TryPlayerMove_Hook, Server::TryPlayerMove, Offsets::TryPlayerMove); this->g_GameMovement->Hook(Server::CheckStuck_Hook, Server::CheckStuck, Offsets::CheckStuck); + this->g_GameMovement->Hook(Server::SetGroundEntity_Hook, Server::SetGroundEntity, Offsets::SetGroundEntity); this->g_GameMovement->Hook(Server::ProcessMovement_Hook, Server::ProcessMovement, Offsets::ProcessMovement); this->g_GameMovement->Hook(Server::GetPlayerViewOffset_Hook, Server::GetPlayerViewOffset, Offsets::GetPlayerViewOffset); this->g_GameMovement->Hook(Server::FinishGravity_Hook, Server::FinishGravity, Offsets::FinishGravity); diff --git a/src/Modules/Server.hpp b/src/Modules/Server.hpp index fcec4497..04f44d00 100644 --- a/src/Modules/Server.hpp +++ b/src/Modules/Server.hpp @@ -108,6 +108,9 @@ class Server : public Module { // CGameMovement::CheckStuck DECL_DETOUR_T(int, CheckStuck); + // CGameMovement::SetGroundEntity + DECL_DETOUR(SetGroundEntity, CGameTrace* tr); + // CGameMovement::TryPlayerMove DECL_DETOUR_T(int, TryPlayerMove, Vector *pFirstDest, CGameTrace *pFirstTrace); diff --git a/src/Offsets/Portal 2 8491.hpp b/src/Offsets/Portal 2 8491.hpp index d09c00bc..b1489b3f 100644 --- a/src/Offsets/Portal 2 8491.hpp +++ b/src/Offsets/Portal 2 8491.hpp @@ -114,6 +114,7 @@ OFFSET_DEFAULT(CheckJumpButton, 36, 37) OFFSET_DEFAULT(FullTossMove, -1, 38) OFFSET_DEFAULT(TryPlayerMove, 39, 40) OFFSET_DEFAULT(CheckStuck, 47, 48) +OFFSET_DEFAULT(SetGroundEntity, 69, 70) OFFSET_DEFAULT(StepMove, 70, 71) OFFSET_DEFAULT(mv, 8, 8) OFFSET_DEFAULT(player, 4, 4)