From a1cf2d38bbb2df8947183652568e6132152979b0 Mon Sep 17 00:00:00 2001 From: Sam V Date: Mon, 14 Aug 2023 13:03:37 +0200 Subject: [PATCH] Add cvar sv_allowbunnyhopping to control whether the bunny hopping limiter is enabled --- CHANGELOG.md | 4 ++++ dlls/client.cpp | 20 ++++++++++++++++++++ dlls/game.cpp | 4 ++++ dlls/game.h | 2 ++ dlls/player.cpp | 1 + pm_shared/pm_shared.cpp | 7 +++++++ 6 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79266906d..2734f9832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ * Fixed hand grenade animations not playing correctly [#209](https://github.com/SamVanheer/halflife-updated/pull/209) (Thanks Toodles2You) * Fixed out of bounds access in studiomodel renderer bone setup code (halflife issue [#3360](https://github.com/ValveSoftware/halflife/issues/3360)) +### Features + +* Added cvar `sv_allowbunnyhopping` to control whether the bunny hopping limiter is enabled (halflife issue [#11](https://github.com/ValveSoftware/halflife/issues/11)) + ## Changes in V1.0.0 Release Candidate 001 ### Bug fixes diff --git a/dlls/client.cpp b/dlls/client.cpp index dc3d795a4..145ff0fe2 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -773,6 +773,7 @@ void ParmsChangeLevel() pSaveData->connectionCount = BuildChangeList(pSaveData->levelList, MAX_LEVEL_CONNECTIONS); } +static bool g_LastAllowBunnyHoppingState = false; // // GLOBALS ASSUMED SET: g_ulFrameCount @@ -787,6 +788,25 @@ void StartFrame() gpGlobals->teamplay = teamplay.value; g_ulFrameCount++; + + const bool allowBunnyHopping = sv_allowbunnyhopping.value != 0; + + if (allowBunnyHopping != g_LastAllowBunnyHoppingState) + { + g_LastAllowBunnyHoppingState = allowBunnyHopping; + + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { + auto player = UTIL_PlayerByIndex(i); + + if (!player) + { + continue; + } + + g_engfuncs.pfnSetPhysicsKeyValue(player->edict(), "bj", UTIL_dtos1(allowBunnyHopping ? 1 : 0)); + } + } } diff --git a/dlls/game.cpp b/dlls/game.cpp index 6ac437630..d99c486da 100644 --- a/dlls/game.cpp +++ b/dlls/game.cpp @@ -44,6 +44,8 @@ cvar_t allow_spectators = {"allow_spectators", "0.0", FCVAR_SERVER}; // 0 preven cvar_t mp_chattime = {"mp_chattime", "10", FCVAR_SERVER}; +cvar_t sv_allowbunnyhopping = {"sv_allowbunnyhopping", "0", FCVAR_SERVER}; + //CVARS FOR SKILL LEVEL SETTINGS // Agrunt cvar_t sk_agrunt_health1 = {"sk_agrunt_health1", "0"}; @@ -493,6 +495,8 @@ void GameDLLInit() CVAR_REGISTER(&mp_chattime); + CVAR_REGISTER(&sv_allowbunnyhopping); + // REGISTER CVARS FOR SKILL LEVEL STUFF // Agrunt CVAR_REGISTER(&sk_agrunt_health1); // {"sk_agrunt_health1","0"}; diff --git a/dlls/game.h b/dlls/game.h index f2b8e6ba2..3e759521f 100644 --- a/dlls/game.h +++ b/dlls/game.h @@ -41,6 +41,8 @@ extern cvar_t allowmonsters; extern cvar_t allow_spectators; extern cvar_t mp_chattime; +extern cvar_t sv_allowbunnyhopping; + // Engine Cvars inline cvar_t* g_psv_gravity; inline cvar_t* g_psv_aim; diff --git a/dlls/player.cpp b/dlls/player.cpp index f0100ffa5..6b3161f94 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -2806,6 +2806,7 @@ void CBasePlayer::Spawn() g_engfuncs.pfnSetPhysicsKeyValue(edict(), "slj", "0"); g_engfuncs.pfnSetPhysicsKeyValue(edict(), "hl", "1"); + g_engfuncs.pfnSetPhysicsKeyValue(edict(), "bj", UTIL_dtos1(sv_allowbunnyhopping.value != 0 ? 1 : 0)); m_iFOV = 0; // init field of view. m_iClientFOV = -1; // make sure fov reset is sent diff --git a/pm_shared/pm_shared.cpp b/pm_shared/pm_shared.cpp index c54b73315..612e5ad2b 100644 --- a/pm_shared/pm_shared.cpp +++ b/pm_shared/pm_shared.cpp @@ -2525,6 +2525,13 @@ void PM_NoClip() //----------------------------------------------------------------------------- void PM_PreventMegaBunnyJumping() { + const bool allowBunnyHopping = atoi(pmove->PM_Info_ValueForKey(pmove->physinfo, "bj")) == 1; + + if (allowBunnyHopping) + { + return; + } + // Current player speed float spd; // If we have to crop, apply this cropping fraction to velocity