From 0e28124a8e0dc228194c24324f868aa79b36548d Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 31 Jul 2024 05:01:49 +0000 Subject: [PATCH] Scale player hitbox size on death to fix potential crashes --- qcsrc/common/constants.qh | 2 ++ qcsrc/lib/csqcmodel/cl_player.qc | 7 +++++-- qcsrc/server/client.qc | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 708f4c845..132504a9f 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -57,6 +57,8 @@ const vector PL_MIN_CONST = '-16 -16 -24'; const vector PL_CROUCH_MAX_CONST = '16 16 25'; const vector PL_CROUCH_MIN_CONST = '-16 -16 -24'; +const float PL_CORPSE_SCALE = 0.235; // average hitbox height is scaled by this when the player dies + // gametype vote flags const int GTV_FORBIDDEN = 0; // Cannot be voted const int GTV_AVAILABLE = 1; // Can be voted diff --git a/qcsrc/lib/csqcmodel/cl_player.qc b/qcsrc/lib/csqcmodel/cl_player.qc index a92fcc5c5..13c7c556e 100644 --- a/qcsrc/lib/csqcmodel/cl_player.qc +++ b/qcsrc/lib/csqcmodel/cl_player.qc @@ -108,8 +108,11 @@ void CSQCPlayer_SetMinsMaxs(entity this) { this.mins = PHYS_PL_MIN(this); this.maxs = PHYS_PL_MAX(this); - if (IS_DEAD(this)) - this.maxs.z = 5; + if(IS_DEAD(this)) + { + float h = ceil((this.mins.z + this.maxs.z) * PL_CORPSE_SCALE * 10) / 10; + this.maxs.z = max(h, this.mins.z + 1); + } this.view_ofs = PHYS_PL_VIEWOFS(this); } } diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index bc5c57600..575d6d971 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -2659,7 +2659,8 @@ void PlayerPostThink (entity this) { // player's bbox gets resized now, instead of in the damage event that killed the player, // once all the damage events of this frame have been processed with normal size - this.maxs.z = 5; + float h = ceil((this.mins.z + this.maxs.z) * PL_CORPSE_SCALE * 10) / 10; + this.maxs.z = max(h, this.mins.z + 1); setsize(this, this.mins, this.maxs); } DrownPlayer(this); -- 2.39.2