Skip to content

Commit

Permalink
Fix signatures for CS2 update, remove unnecessary jump height emulati…
Browse files Browse the repository at this point in the history
…on from ckz, remove some function hooks
  • Loading branch information
zer0k-z committed Oct 29, 2024
1 parent 978a8de commit d1c0d56
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 131 deletions.
36 changes: 11 additions & 25 deletions gamedata/cs2kz-core.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"PlayerMove"
{
"library" "server"
"windows" "\x48\x89\x5C\x24\x10\x48\x89\x6C\x24\x18\x48\x89\x74\x24\x20\x57\x48\x83\xEC\x30\x48\x8B\xF9"
"windows" "\x48\x89\x5C\x24\x10\x48\x89\x6C\x24\x18\x48\x89\x74\x24\x20\x57\x48\x83\xEC\x40\x48\x8B\xF9"
"linux" "\x55\x48\x89\xE5\x41\x55\x49\x89\xF5\x41\x54\x49\x89\xFC\x48\x8B\x7F\x30\x48\x8B\x07"
}
// Second thing called during PlayerMove
Expand All @@ -128,12 +128,12 @@
"windows" "\x40\x56\x57\x48\x83\xEC\x38\x48\x8B\xF2"
"linux" "\x55\x48\x89\xE5\x41\x56\x41\x55\x49\x89\xF5\x41\x54\x49\x89\xFC\x53\x48\x83\xEC\x20\x84\xD2"
}
// "[%s] Bogus pmove player movetype in ShouldApplyGravity %i\n" (check xref on linux, inlined on windows)
// sv_optimizedmovement ref
"MoveInit"
{
"library" "server"
"windows" "\x48\x89\x5C\x24\x10\x57\x48\x83\xEC\x60\x48\x8B\xFA\x48\x8B\xD9\xE8"
"linux" "\x55\x48\x89\xE5\x41\x56\x41\x55\x49\x89\xF5\x41\x54\x49\x89\xFC\x48\x89\xF7\x53\x48\x83\xEC\x10"
"windows" "\x48\x89\x5C\x24\x10\x57\x48\x83\xEC\x40\x48\x8B\xFA\x48\x8B\xD9\xE8\x2A\x2A\x2A\x2A\x48\x8B\xCB"
"linux" "\x55\x48\x89\xE5\x41\x55\x41\x54\x49\x89\xF4\x53\x48\x89\xFB\x48\x89\xF7\x48\x83\xEC\x18\x48\xC7\x86\xD4\x00\x00\x00\x00\x00\x00\x00"
}
// somewhere in MoveInit. GLHF!
"CheckWater"
Expand Down Expand Up @@ -188,22 +188,15 @@
"OnJump"
{
"library" "server"
"windows" "\x40\x53\x57\x48\x81\xEC\xB8\x00\x00\x00"
"linux" "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x49\x89\xF5\x41\x54\x49\x89\xFC\x53\x48\x83\xEC\x28\x48\x8B\x7F\x30"
"windows" "\x40\x53\x57\x48\x81\xEC\xC8\x00\x00\x00\x48\x8B\xD9\x48\x8B\xFA\x48\x8B\x49\x30"
"linux" "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x49\x89\xF5\x41\x54\x49\x89\xFC\x53\x48\x83\xEC\x18\x48\x8B\x7F\x30"
}
// sv_air_pushaway_dist
// "StartGravity", sv_air_max_wishspeed
"AirMove"
{
"library" "server"
"windows" "\x48\x8B\xC4\x55\x56\x41\x57\x48\x8D\xA8\x28\xFF\xFF\xFF"
"linux" "\x55\x48\x89\xE5\x41\x57\x41\x56\x4C\x8D\x75\x80"
}
// Look for sv_air_max_wishspeed
"AirAccelerate"
{
"library" "server"
"windows" "\x48\x89\x5C\x24\x18\xF3\x0F\x11\x5C\x24\x20"
"linux" "\x55\x66\x0F\xEF\xD2\x48\x89\xE5\x41\x55\x49"
"windows" "\x48\x8B\xC4\x48\x89\x58\x18\x48\x89\x70\x20\x55\x57\x41\x56\x48\x8D\x68\xA1\x48\x81\xEC\xC0\x00\x00\x00"
"linux" "\x55\x48\x89\xE5\x41\x57\x49\x89\xF7\x41\x56\x48\x8D\x4D\xAC"
}
// sub_7FFE47869020(a1, a2); <- this function
// sub_7FFE47863820(a1, a2, "FullWalkMovePreMove");
Expand Down Expand Up @@ -237,19 +230,12 @@
"windows" "\x40\x55\x56\x57\x41\x54\x48\x8D\xAC\x24\x28\xFE\xFF\xFF"
"linux" "\x48\xB8\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x55\x48\x89\xE5\x41\x57\x41\x89\xD7\x41\x56\x4C\x8D\xB5\x50\xFE\xFF\xFF"
}
// called before the "player_jump" string in OnJump
"FinishGravity"
{
"library" "server"
"windows" "\x48\x89\x74\x24\x10\x57\x48\x83\xEC\x40\x4C\x8B\x41\x30"
"linux" "\x55\x48\x89\xE5\x41\x56\x41\x55\x41\x54\x49\x89\xF4\x53\x48\x89\xFB\x48\x83\xEC\x2A\x48\x8B\x57"
}
// sv_staminalandcost only ref. not inlined in linux, check calling functions.
"CheckFalling"
{
"library" "server"
"windows" "\x48\x89\x5C\x24\x10\x57\x48\x81\xEC\x80\x00\x00\x00\xF3\x0F\x10\x81\x28\x02\x00\x00"
"linux" "\x55\x66\x0F\xEF\xDB\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x49\x89\xF4\x53\x48\x89\xFB\x48\x83\xEC\x38"
"windows" "\x48\x89\x5C\x24\x10\x57\x48\x81\xEC\x80\x00\x00\x00\x48\x8B\xD9"
"linux" "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x49\x89\xF4\x53\x48\x89\xFB\x48\x83\xEC\x38\x48\x8B\x7F\x30"
}
"PostPlayerMove"
{
Expand Down
42 changes: 40 additions & 2 deletions src/kz/jumpstats/kz_jumpstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ bool KZJumpstatsService::GroundSpeedCappedRecently()
return this->lastGroundSpeedCappedTime == this->lastMovementProcessedTime;
}

void KZJumpstatsService::OnAirAccelerate()
void KZJumpstatsService::OnAirMove()
{
if (g_pKZUtils->GetGlobals()->frametime == 0.0f)
{
Expand All @@ -727,12 +727,50 @@ void KZJumpstatsService::OnAirAccelerate()
strafe->aaCalls.AddToTail(call);
}

void KZJumpstatsService::OnAirAcceleratePost(Vector wishdir, f32 wishspeed, f32 accel)
void KZJumpstatsService::OnAirMovePost()
{
if (g_pKZUtils->GetGlobals()->frametime == 0.0f)
{
return;
}
int i;
Vector wishvel;
float fmove, smove;
Vector wishdir;
float wishspeed;
Vector forward, right, up;

AngleVectors(this->player->currentMoveData->m_vecViewAngles, &forward, &right, &up); // Determine movement angles

// Copy movement amounts
fmove = this->player->currentMoveData->m_flForwardMove;
smove = this->player->currentMoveData->m_flSideMove;

// Zero out z components of movement vectors
forward[2] = 0;
right[2] = 0;
VectorNormalize(forward); // Normalize remainder of vectors
VectorNormalize(right); //

for (i = 0; i < 2; i++) // Determine x and y parts of velocity
{
wishvel[i] = forward[i] * fmove + right[i] * smove;
}
wishvel[2] = 0; // Zero out z part of velocity

VectorCopy(wishvel, wishdir); // Determine maginitude of speed of move
wishspeed = VectorNormalize(wishdir);

//
// clamp to server defined max speed
//
if (wishspeed != 0 && (wishspeed > this->player->currentMoveData->m_flMaxSpeed))
{
VectorScale(wishvel, this->player->currentMoveData->m_flMaxSpeed / wishspeed, wishvel);
wishspeed = this->player->currentMoveData->m_flMaxSpeed;
}
auto accel = reinterpret_cast<CVValue_t *>(&(KZ::mode::modeCvars[3]->values))->m_flValue;

this->jumps.Tail().UpdateAACallPost(wishdir, wishspeed, accel);
}

Expand Down
4 changes: 2 additions & 2 deletions src/kz/jumpstats/kz_jumpstats.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ class KZJumpstatsService : public KZBaseService
void UpdateJump();
void EndJump();
void InvalidateJumpstats(const char *reason = NULL);
void OnAirAccelerate();
void OnAirAcceleratePost(Vector wishdir, f32 wishspeed, f32 accel);
void OnAirMove();
void OnAirMovePost();
void UpdateAACallPost();

void CheckValidMoveType();
Expand Down
2 changes: 0 additions & 2 deletions src/kz/kz.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ class KZPlayer : public MovementPlayer
virtual void OnJumpPost() override;
virtual void OnAirMove() override;
virtual void OnAirMovePost() override;
virtual void OnAirAccelerate(Vector &wishdir, f32 &wishspeed, f32 &accel) override;
virtual void OnAirAcceleratePost(Vector wishdir, f32 wishspeed, f32 accel) override;
virtual void OnFriction() override;
virtual void OnFrictionPost() override;
virtual void OnWalkMove() override;
Expand Down
22 changes: 2 additions & 20 deletions src/kz/kz_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ void KZPlayer::OnAirMove()
{
this->styleServices[i]->OnAirMove();
}
this->jumpstatsService->OnAirMove();
}

void KZPlayer::OnAirMovePost()
Expand All @@ -463,26 +464,7 @@ void KZPlayer::OnAirMovePost()
{
this->styleServices[i]->OnAirMovePost();
}
}

void KZPlayer::OnAirAccelerate(Vector &wishdir, f32 &wishspeed, f32 &accel)
{
this->modeService->OnAirAccelerate(wishdir, wishspeed, accel);
FOR_EACH_VEC(this->styleServices, i)
{
this->styleServices[i]->OnAirAccelerate(wishdir, wishspeed, accel);
}
this->jumpstatsService->OnAirAccelerate();
}

void KZPlayer::OnAirAcceleratePost(Vector wishdir, f32 wishspeed, f32 accel)
{
this->modeService->OnAirAcceleratePost(wishdir, wishspeed, accel);
FOR_EACH_VEC(this->styleServices, i)
{
this->styleServices[i]->OnAirAcceleratePost(wishdir, wishspeed, accel);
}
this->jumpstatsService->OnAirAcceleratePost(wishdir, wishspeed, accel);
this->jumpstatsService->OnAirMovePost();
}

void KZPlayer::OnFriction()
Expand Down
4 changes: 0 additions & 4 deletions src/kz/mode/kz_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ class KZModeService : public KZBaseService

virtual void OnAirMovePost() {}

virtual void OnAirAccelerate(Vector &wishdir, f32 &wishspeed, f32 &accel) {}

virtual void OnAirAcceleratePost(Vector wishdir, f32 wishspeed, f32 accel) {}

virtual void OnFriction() {}

virtual void OnFrictionPost() {}
Expand Down
36 changes: 0 additions & 36 deletions src/kz/mode/kz_mode_ckz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ CGameEntitySystem *GameEntitySystem()

void KZClassicModeService::Reset()
{
this->revertJumpTweak = {};
this->preJumpZSpeed = {};
this->tweakedJumpZSpeed = {};
this->hasValidDesiredViewAngle = {};
this->lastValidDesiredViewAngle = vec3_angle;
this->lastJumpReleaseTime = {};
Expand Down Expand Up @@ -215,45 +212,12 @@ const char **KZClassicModeService::GetModeConVarValues()
return modeCvarValues;
}

// Attempt to replicate 128t jump height.
void KZClassicModeService::OnJump()
{
Vector velocity;
this->player->GetVelocity(&velocity);
this->preJumpZSpeed = velocity.z;
// Emulate the 128t vertical velocity before jumping
if (this->player->GetPlayerPawn()->m_fFlags & FL_ONGROUND && this->player->GetPlayerPawn()->m_hGroundEntity().IsValid()
&& (this->preJumpZSpeed < 0.0f || !this->player->duckBugged))
{
velocity.z += 0.25 * this->player->GetPlayerPawn()->m_flGravityScale() * 800 * ENGINE_FIXED_TICK_INTERVAL;
this->player->SetVelocity(velocity);
this->tweakedJumpZSpeed = velocity.z;
this->revertJumpTweak = true;
}
}

void KZClassicModeService::OnJumpPost()
{
// If we didn't jump, we revert the jump height tweak.
Vector velocity;
this->player->GetVelocity(&velocity);
if (this->revertJumpTweak && velocity.z == this->tweakedJumpZSpeed)
{
velocity.z = this->preJumpZSpeed;
this->player->SetVelocity(velocity);
}
this->revertJumpTweak = false;
}

void KZClassicModeService::OnStopTouchGround()
{
Vector velocity;
this->player->GetVelocity(&velocity);
f32 speed = velocity.Length2D();

// If we are actually taking off, we don't need to revert the change anymore.
this->revertJumpTweak = false;

f32 timeOnGround = this->player->takeoffTime - this->player->landingTime;
// Perf
if (timeOnGround <= BH_PERF_WINDOW)
Expand Down
5 changes: 0 additions & 5 deletions src/kz/mode/kz_mode_ckz.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ class KZClassicModeService : public KZModeService
};
static_assert(Q_ARRAYSIZE(modeCvarValues) == MODECVAR_COUNT, "Array modeCvarValues length is not the same as MODECVAR_COUNT!");

bool revertJumpTweak {};
f32 preJumpZSpeed {};
f32 tweakedJumpZSpeed {};
bool hasValidDesiredViewAngle {};
QAngle lastValidDesiredViewAngle;
f32 lastJumpReleaseTime {};
Expand Down Expand Up @@ -155,8 +152,6 @@ class KZClassicModeService : public KZModeService
virtual void OnDuckPost() override;
virtual void OnAirMove() override;
virtual void OnAirMovePost() override;
virtual void OnJump() override;
virtual void OnJumpPost() override;
virtual void OnStartTouchGround() override;
virtual void OnStopTouchGround() override;
virtual void OnTryPlayerMove(Vector *pFirstDest, trace_t *pFirstTrace) override;
Expand Down
4 changes: 0 additions & 4 deletions src/kz/style/kz_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ class KZStyleService : public KZBaseService

virtual void OnAirMovePost() {}

virtual void OnAirAccelerate(Vector &wishdir, f32 &wishspeed, f32 &accel) {}

virtual void OnAirAcceleratePost(Vector wishdir, f32 wishspeed, f32 accel) {}

virtual void OnFriction() {}

virtual void OnFrictionPost() {}
Expand Down
6 changes: 0 additions & 6 deletions src/movement/movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ namespace movement
void FASTCALL Detour_CheckJumpButton(CCSPlayer_MovementServices *, CMoveData *);
void FASTCALL Detour_OnJump(CCSPlayer_MovementServices *, CMoveData *);
void FASTCALL Detour_AirMove(CCSPlayer_MovementServices *, CMoveData *);
void FASTCALL Detour_AirAccelerate(CCSPlayer_MovementServices *, CMoveData *, Vector &, f32, f32);
void FASTCALL Detour_Friction(CCSPlayer_MovementServices *, CMoveData *);
void FASTCALL Detour_WalkMove(CCSPlayer_MovementServices *, CMoveData *);
void FASTCALL Detour_TryPlayerMove(CCSPlayer_MovementServices *, CMoveData *, Vector *, trace_t *);
void FASTCALL Detour_CategorizePosition(CCSPlayer_MovementServices *, CMoveData *, bool);
void FASTCALL Detour_FinishGravity(CCSPlayer_MovementServices *, CMoveData *);
void FASTCALL Detour_CheckFalling(CCSPlayer_MovementServices *, CMoveData *);
void FASTCALL Detour_PostPlayerMove(CCSPlayer_MovementServices *, CMoveData *);
void FASTCALL Detour_PostThink(CCSPlayerPawnBase *);
Expand Down Expand Up @@ -154,10 +152,6 @@ class MovementPlayer : public Player

virtual void OnAirMovePost() {}

virtual void OnAirAccelerate(Vector &wishdir, f32 &wishspeed, f32 &accel) {}

virtual void OnAirAcceleratePost(Vector wishdir, f32 wishspeed, f32 accel) {}

virtual void OnFriction() {}

virtual void OnFrictionPost() {}
Expand Down
22 changes: 2 additions & 20 deletions src/movement/mv_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ void movement::InitDetours()
INIT_DETOUR(g_pGameConfig, CheckJumpButton);
INIT_DETOUR(g_pGameConfig, OnJump);
INIT_DETOUR(g_pGameConfig, AirMove);
INIT_DETOUR(g_pGameConfig, AirAccelerate);
INIT_DETOUR(g_pGameConfig, Friction);
INIT_DETOUR(g_pGameConfig, WalkMove);
INIT_DETOUR(g_pGameConfig, TryPlayerMove);
INIT_DETOUR(g_pGameConfig, CategorizePosition);
INIT_DETOUR(g_pGameConfig, FinishGravity);
INIT_DETOUR(g_pGameConfig, CheckFalling);
INIT_DETOUR(g_pGameConfig, PostPlayerMove);
INIT_DETOUR(g_pGameConfig, PostThink);
Expand Down Expand Up @@ -260,10 +258,10 @@ void FASTCALL movement::Detour_OnJump(CCSPlayer_MovementServices *ms, CMoveData
{
MovementPlayer *player = playerManager->ToPlayer(ms);
player->OnJump();
f32 oldJumpUntil = ms->m_flJumpUntil();
Vector oldOutWishVel = mv->m_outWishVel;
MoveType_t oldMoveType = player->GetPlayerPawn()->m_MoveType();
OnJump(ms, mv);
if (ms->m_flJumpUntil() != oldJumpUntil)
if (mv->m_outWishVel != oldOutWishVel)
{
player->inPerf = (oldMoveType != MOVETYPE_LADDER && !player->oldWalkMoved);
player->RegisterTakeoff(true);
Expand All @@ -280,14 +278,6 @@ void FASTCALL movement::Detour_AirMove(CCSPlayer_MovementServices *ms, CMoveData
player->OnAirMovePost();
}

void FASTCALL movement::Detour_AirAccelerate(CCSPlayer_MovementServices *ms, CMoveData *mv, Vector &wishdir, f32 wishspeed, f32 accel)
{
MovementPlayer *player = playerManager->ToPlayer(ms);
player->OnAirAccelerate(wishdir, wishspeed, accel);
AirAccelerate(ms, mv, wishdir, wishspeed, accel);
player->OnAirAcceleratePost(wishdir, wishspeed, accel);
}

void FASTCALL movement::Detour_Friction(CCSPlayer_MovementServices *ms, CMoveData *mv)
{
MovementPlayer *player = playerManager->ToPlayer(ms);
Expand Down Expand Up @@ -356,14 +346,6 @@ void FASTCALL movement::Detour_CategorizePosition(CCSPlayer_MovementServices *ms
player->OnCategorizePositionPost(bStayOnGround);
}

void FASTCALL movement::Detour_FinishGravity(CCSPlayer_MovementServices *ms, CMoveData *mv)
{
MovementPlayer *player = playerManager->ToPlayer(ms);
player->OnFinishGravity();
FinishGravity(ms, mv);
player->OnFinishGravityPost();
}

void FASTCALL movement::Detour_CheckFalling(CCSPlayer_MovementServices *ms, CMoveData *mv)
{
MovementPlayer *player = playerManager->ToPlayer(ms);
Expand Down
1 change: 0 additions & 1 deletion src/sdk/services.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class CCSPlayer_MovementServices : public CPlayer_MovementServices_Humanoid
{
public:
DECLARE_SCHEMA_CLASS(CCSPlayer_MovementServices);
SCHEMA_FIELD(float, m_flJumpUntil)
SCHEMA_FIELD(Vector, m_vecLadderNormal)
SCHEMA_FIELD(bool, m_bOldJumpPressed)
SCHEMA_FIELD(float, m_flJumpPressedTime)
Expand Down
2 changes: 0 additions & 2 deletions src/utils/detours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ DECLARE_MOVEMENT_DETOUR(LadderMove);
DECLARE_MOVEMENT_DETOUR(CheckJumpButton);
DECLARE_MOVEMENT_DETOUR(OnJump);
DECLARE_MOVEMENT_DETOUR(AirMove);
DECLARE_MOVEMENT_DETOUR(AirAccelerate);
DECLARE_MOVEMENT_DETOUR(Friction);
DECLARE_MOVEMENT_DETOUR(WalkMove);
DECLARE_MOVEMENT_DETOUR(TryPlayerMove);
DECLARE_MOVEMENT_DETOUR(CategorizePosition);
DECLARE_MOVEMENT_DETOUR(FinishGravity);
DECLARE_MOVEMENT_DETOUR(CheckFalling);
DECLARE_MOVEMENT_DETOUR(PostPlayerMove);
DECLARE_MOVEMENT_DETOUR(PostThink);
Expand Down
Loading

0 comments on commit d1c0d56

Please sign in to comment.