From 193c1ed52ad7af69a0e7f4e22e09f8cc16555635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Mu=C3=B1oz?= Date: Sun, 26 Nov 2023 01:24:48 -0300 Subject: [PATCH] Fixed grenades disappearing when speed exceeds 2000 fixed units ignoring sv_maxvelocity (#888) * Fixed grenades disappearing when speed exceeds 2000 fixed units ignoring sv_maxvelocity * Clamp nades velocity to sv_maxvelocity value when reached * Make IsInWorld behave like SV_CheckVelocity: less/greater without equal * Enclose IsInWorld changes with FIXES macro --- regamedll/dlls/cbase.cpp | 12 ++++++++++++ regamedll/dlls/game.cpp | 2 ++ regamedll/dlls/game.h | 3 ++- regamedll/dlls/ggrenade.cpp | 21 +++++++++++++++++++++ regamedll/dlls/gib.cpp | 5 ++--- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/regamedll/dlls/cbase.cpp b/regamedll/dlls/cbase.cpp index a779c69c5..77a499448 100644 --- a/regamedll/dlls/cbase.cpp +++ b/regamedll/dlls/cbase.cpp @@ -870,6 +870,17 @@ BOOL CBaseEntity::IsInWorld() } // speed +#ifdef REGAMEDLL_FIXES + float maxvel = g_psv_maxvelocity->value; + if (pev->velocity.x > maxvel || pev->velocity.y > maxvel || pev->velocity.z > maxvel) + { + return FALSE; + } + if (pev->velocity.x < -maxvel || pev->velocity.y < -maxvel || pev->velocity.z < -maxvel) + { + return FALSE; + } +#else if (pev->velocity.x >= 2000.0 || pev->velocity.y >= 2000.0 || pev->velocity.z >= 2000.0) { return FALSE; @@ -878,6 +889,7 @@ BOOL CBaseEntity::IsInWorld() { return FALSE; } +#endif return TRUE; } diff --git a/regamedll/dlls/game.cpp b/regamedll/dlls/game.cpp index 5d9238196..55c2600c1 100644 --- a/regamedll/dlls/game.cpp +++ b/regamedll/dlls/game.cpp @@ -9,6 +9,7 @@ cvar_t *g_psv_friction = nullptr; cvar_t *g_psv_stopspeed = nullptr; cvar_t *g_psv_stepsize = nullptr; cvar_t *g_psv_clienttrace = nullptr; +cvar_t *g_psv_maxvelocity = nullptr; cvar_t displaysoundlist = { "displaysoundlist", "0", 0, 0.0f, nullptr }; cvar_t timelimit = { "mp_timelimit", "0", FCVAR_SERVER, 0.0f, nullptr }; @@ -238,6 +239,7 @@ void EXT_FUNC GameDLLInit() g_psv_stopspeed = CVAR_GET_POINTER("sv_stopspeed"); g_psv_stepsize = CVAR_GET_POINTER("sv_stepsize"); g_psv_clienttrace = CVAR_GET_POINTER("sv_clienttrace"); + g_psv_maxvelocity = CVAR_GET_POINTER("sv_maxvelocity"); CVAR_REGISTER(&displaysoundlist); CVAR_REGISTER(&timelimit); diff --git a/regamedll/dlls/game.h b/regamedll/dlls/game.h index 3791a3c1f..cff031fbb 100644 --- a/regamedll/dlls/game.h +++ b/regamedll/dlls/game.h @@ -43,12 +43,13 @@ extern cvar_t *g_pskill; extern cvar_t *g_psv_gravity; extern cvar_t *g_psv_aim; +extern cvar_t *g_footsteps; extern cvar_t *g_psv_accelerate; extern cvar_t *g_psv_friction; extern cvar_t *g_psv_stopspeed; extern cvar_t *g_psv_stepsize; extern cvar_t *g_psv_clienttrace; -extern cvar_t *g_footsteps; +extern cvar_t *g_psv_maxvelocity; extern cvar_t displaysoundlist; extern cvar_t timelimit; diff --git a/regamedll/dlls/ggrenade.cpp b/regamedll/dlls/ggrenade.cpp index 678a78d58..41e92f27d 100644 --- a/regamedll/dlls/ggrenade.cpp +++ b/regamedll/dlls/ggrenade.cpp @@ -772,6 +772,13 @@ void CGrenade::BounceSound() void CGrenade::TumbleThink() { +#ifdef REGAMEDLL_FIXES + if (pev->velocity.IsLengthGreaterThan(g_psv_maxvelocity->value)) + { + pev->velocity = pev->velocity.Normalize() * g_psv_maxvelocity->value; + } +#endif + if (!IsInWorld()) { UTIL_Remove(this); @@ -809,6 +816,13 @@ void CGrenade::TumbleThink() void CGrenade::SG_TumbleThink() { +#ifdef REGAMEDLL_FIXES + if (pev->velocity.IsLengthGreaterThan(g_psv_maxvelocity->value)) + { + pev->velocity = pev->velocity.Normalize() * g_psv_maxvelocity->value; + } +#endif + if (!IsInWorld()) { UTIL_Remove(this); @@ -1322,6 +1336,13 @@ void AnnounceFlashInterval(float interval, float offset) void CGrenade::C4Think() { +#ifdef REGAMEDLL_FIXES + if (pev->velocity.IsLengthGreaterThan(g_psv_maxvelocity->value)) + { + pev->velocity = pev->velocity.Normalize() * g_psv_maxvelocity->value; + } +#endif + if (!IsInWorld()) { #ifdef REGAMEDLL_FIXES diff --git a/regamedll/dlls/gib.cpp b/regamedll/dlls/gib.cpp index 069b118d9..9301e283f 100644 --- a/regamedll/dlls/gib.cpp +++ b/regamedll/dlls/gib.cpp @@ -4,12 +4,11 @@ LINK_ENTITY_TO_CLASS(gib, CGib, CCSGib) void CGib::LimitVelocity() { - float length = pev->velocity.Length(); - float topspeed = CVAR_GET_FLOAT("sv_maxvelocity") * 0.75f; + float topspeed = g_psv_maxvelocity->value * 0.75f; // ceiling at topspeed. The gib velocity equation is not bounded properly. Rather than tune it // in 3 separate places again, I'll just limit it here. - if (length > topspeed) + if (pev->velocity.IsLengthGreaterThan(topspeed)) { // DONE: This should really be sv_maxvelocity * 0.75 or something pev->velocity = pev->velocity.Normalize() * topspeed;