Skip to content

Commit

Permalink
feat: implement slope boost ensurance cheat
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzyhau committed Oct 23, 2024
1 parent 69a9448 commit 92924ce
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

}
1 change: 1 addition & 0 deletions src/Cheats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/Modules/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -223,6 +224,15 @@ DETOUR_T(int, Server::CheckStuck) {
return result;
}

// CGameMovement::SetGroundEntity
DETOUR(Server::SetGroundEntity, CGameTrace* tr) {
auto player = *reinterpret_cast<void **>((uintptr_t)thisptr + Offsets::player);
auto mv = *reinterpret_cast<const CHLMoveData **>((uintptr_t)thisptr + Offsets::mv);

Cheats::EnsureSlopeBoost(mv, player, &tr);
return Server::SetGroundEntity(thisptr, tr);
}

// CGameMovement::PlayerMove
DETOUR(Server::PlayerMove) {
auto player = *reinterpret_cast<void **>((uintptr_t)thisptr + Offsets::player);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Modules/Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/Offsets/Portal 2 8491.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 92924ce

Please sign in to comment.