From 79aa2445b44e8542727c7f99b55d523864d46ce9 Mon Sep 17 00:00:00 2001 From: dystopm Date: Sun, 16 Jul 2023 23:49:03 -0400 Subject: [PATCH 1/6] CSPlayer new members --- regamedll/pm_shared/pm_shared.cpp | 65 +++++++++++++++++++---- regamedll/public/regamedll/API/CSPlayer.h | 10 +++- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index b3b57fa5d..f74a010bd 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -1899,9 +1899,18 @@ void PM_Duck() return; } - pmove->cmd.forwardmove *= PLAYER_DUCKING_MULTIPLIER; - pmove->cmd.sidemove *= PLAYER_DUCKING_MULTIPLIER; - pmove->cmd.upmove *= PLAYER_DUCKING_MULTIPLIER; + float mult = PLAYER_DUCKING_MULTIPLIER; + +#ifdef REGAMEDLL_API + const CCSPlayer* player = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer(); + + if (player->m_flDuckSpeedMultiplier > 0.0) + mult = player->m_flDuckSpeedMultiplier; +#endif + + pmove->cmd.forwardmove *= mult; + pmove->cmd.sidemove *= mult; + pmove->cmd.upmove *= mult; if (pmove->cmd.buttons & IN_DUCK) { @@ -2015,7 +2024,16 @@ void EXT_FUNC __API_HOOK(PM_LadderMove)(physent_t *pLadder) if (pmove->flags & FL_DUCKING) { - flSpeed *= PLAYER_DUCKING_MULTIPLIER; + float mult = PLAYER_DUCKING_MULTIPLIER; + +#ifdef REGAMEDLL_API + const CCSPlayer* player = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer(); + + if (player->m_flDuckSpeedMultiplier > 0.0) + mult = player->m_flDuckSpeedMultiplier; +#endif + + flSpeed *= mult; } if (pmove->cmd.buttons & IN_BACK) @@ -2465,6 +2483,24 @@ void PM_Jump() { PM_PlayStepSound(PM_MapTextureTypeStepType(pmove->chtexturetype), fvol); } + +#ifdef REGAMEDLL_API + auto PM_JumpHeight = [&player](bool longjump) +#else + auto PM_JumpHeight = [&](bool longjump) +#endif + { +#ifdef REGAMEDLL_API + if (longjump) + { + if(player->m_flLongJumpHeight > 0.0) + return player->m_flLongJumpHeight; + } + else if (player->m_flJumpHeight > 0.0) + return player->m_flJumpHeight; +#endif + return Q_sqrt(2.0 * 800.0f * (longjump ? 56.0f : 45.0f)); + }; #ifdef REGAMEDLL_ADD // See if user can super long jump? @@ -2480,23 +2516,34 @@ void PM_Jump() { pmove->punchangle[0] = -5.0f; - for (int i = 0; i < 2; i++) +#ifdef REGAMEDLL_API + if (player->m_flLongJumpForce > 0.0) + { + fvel = player->m_flLongJumpForce; + } + else +#endif + { + fvel = PLAYER_LONGJUMP_SPEED * 1.6f; + } + + for (int i = 0; i < 2; i++) { - pmove->velocity[i] = pmove->forward[i] * PLAYER_LONGJUMP_SPEED * 1.6f; + pmove->velocity[i] = pmove->forward[i] * fvel; } - pmove->velocity[2] = Q_sqrt(2 * 800 * 56.0f); + pmove->velocity[2] = PM_JumpHeight(true); } else { - pmove->velocity[2] = Q_sqrt(2 * 800 * 45.0f); + pmove->velocity[2] = PM_JumpHeight(false); } } else #endif { // NOTE: don't do it in .f (float) - pmove->velocity[2] = Q_sqrt(2.0 * 800.0f * 45.0f); + pmove->velocity[2] = PM_JumpHeight(false); } if (pmove->fuser2 > 0.0f) diff --git a/regamedll/public/regamedll/API/CSPlayer.h b/regamedll/public/regamedll/API/CSPlayer.h index 16150a56c..10c32cdb0 100644 --- a/regamedll/public/regamedll/API/CSPlayer.h +++ b/regamedll/public/regamedll/API/CSPlayer.h @@ -50,7 +50,11 @@ class CCSPlayer: public CCSMonster { m_bAutoBunnyHopping(false), m_bMegaBunnyJumping(false), m_bPlantC4Anywhere(false), - m_bSpawnProtectionEffects(false) + m_bSpawnProtectionEffects(false), + m_flJumpHeight(0), + m_flLongJumpHeight(0), + m_flLongJumpForce(0), + m_flDuckSpeedMultiplier(0) { m_szModel[0] = '\0'; } @@ -136,6 +140,10 @@ class CCSPlayer: public CCSMonster { bool m_bMegaBunnyJumping; bool m_bPlantC4Anywhere; bool m_bSpawnProtectionEffects; + double m_flJumpHeight; + double m_flLongJumpHeight; + double m_flLongJumpForce; + float m_flDuckSpeedMultiplier; }; // Inlines From 3d49516904d7f9659ba9ca389089453521429b62 Mon Sep 17 00:00:00 2001 From: dystopm Date: Mon, 17 Jul 2023 00:18:12 -0400 Subject: [PATCH 2/6] Force return value to be real --- regamedll/pm_shared/pm_shared.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index f74a010bd..06915d52e 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -2485,9 +2485,9 @@ void PM_Jump() } #ifdef REGAMEDLL_API - auto PM_JumpHeight = [&player](bool longjump) + real_t PM_JumpHeight = [&player](bool longjump) #else - auto PM_JumpHeight = [&](bool longjump) + real_t PM_JumpHeight = [&](bool longjump) #endif { #ifdef REGAMEDLL_API From 6c9f45188c1e57759791d3755c70a9a6ff31749b Mon Sep 17 00:00:00 2001 From: dystopm Date: Mon, 17 Jul 2023 00:26:06 -0400 Subject: [PATCH 3/6] Forgot syntax --- regamedll/pm_shared/pm_shared.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index 06915d52e..49ddcd616 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -2485,9 +2485,9 @@ void PM_Jump() } #ifdef REGAMEDLL_API - real_t PM_JumpHeight = [&player](bool longjump) + auto PM_JumpHeight = [&player](bool longjump) -> real_t #else - real_t PM_JumpHeight = [&](bool longjump) + auto PM_JumpHeight = [&](bool longjump) -> real_t #endif { #ifdef REGAMEDLL_API From 4fe644b4b9a5c357253e4610e8430f3b7e4ada69 Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Tue, 18 Jul 2023 11:48:49 +0700 Subject: [PATCH 4/6] Update pm_shared.cpp Use explicitly double precision to fix test demo --- regamedll/pm_shared/pm_shared.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index 49ddcd616..cad117a06 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -1899,7 +1899,7 @@ void PM_Duck() return; } - float mult = PLAYER_DUCKING_MULTIPLIER; + real_t mult = PLAYER_DUCKING_MULTIPLIER; #ifdef REGAMEDLL_API const CCSPlayer* player = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer(); @@ -2024,7 +2024,7 @@ void EXT_FUNC __API_HOOK(PM_LadderMove)(physent_t *pLadder) if (pmove->flags & FL_DUCKING) { - float mult = PLAYER_DUCKING_MULTIPLIER; + real_t mult = PLAYER_DUCKING_MULTIPLIER; #ifdef REGAMEDLL_API const CCSPlayer* player = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer(); From a81c8d887f84bd3bc70c3a3b0f7f55103366ddea Mon Sep 17 00:00:00 2001 From: dystopm Date: Tue, 18 Jul 2023 17:16:08 -0400 Subject: [PATCH 5/6] API refactory in pm_shared.cpp - Cached CSPlayer pointer in a global variable - Changed PM_JumpHeight from lambda function to an inline function - Changed m_flDuckSpeedMultiplier data type to double --- regamedll/pm_shared/pm_shared.cpp | 74 +++++++++++------------ regamedll/public/regamedll/API/CSPlayer.h | 2 +- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index cad117a06..91cfa782a 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -12,6 +12,10 @@ char pm_grgchTextureType[MAX_TEXTURES]; playermove_t *pmove = nullptr; BOOL g_onladder = FALSE; +#ifdef REGAMEDLL_API +static CCSPlayer *pmoveplayer = nullptr; +#endif + #ifdef CLIENT_DLL int iJumpSpectator; float vJumpOrigin[3]; @@ -1902,10 +1906,8 @@ void PM_Duck() real_t mult = PLAYER_DUCKING_MULTIPLIER; #ifdef REGAMEDLL_API - const CCSPlayer* player = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer(); - - if (player->m_flDuckSpeedMultiplier > 0.0) - mult = player->m_flDuckSpeedMultiplier; + if (pmoveplayer->m_flDuckSpeedMultiplier > 0.0) + mult = pmoveplayer->m_flDuckSpeedMultiplier; #endif pmove->cmd.forwardmove *= mult; @@ -2024,16 +2026,16 @@ void EXT_FUNC __API_HOOK(PM_LadderMove)(physent_t *pLadder) if (pmove->flags & FL_DUCKING) { - real_t mult = PLAYER_DUCKING_MULTIPLIER; - #ifdef REGAMEDLL_API - const CCSPlayer* player = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer(); - - if (player->m_flDuckSpeedMultiplier > 0.0) - mult = player->m_flDuckSpeedMultiplier; + if (pmoveplayer->m_flDuckSpeedMultiplier > 0.0) + { + flSpeed *= pmoveplayer->m_flDuckSpeedMultiplier; + } + else #endif - - flSpeed *= mult; + { + flSpeed *= PLAYER_DUCKING_MULTIPLIER; + } } if (pmove->cmd.buttons & IN_BACK) @@ -2362,6 +2364,20 @@ void PM_PreventMegaBunnyJumping() VectorScale(pmove->velocity, fraction, pmove->velocity); } +inline real_t PM_JumpHeight(bool longjump) +{ +#ifdef REGAMEDLL_API + if (longjump) + { + if(pmoveplayer->m_flLongJumpHeight > 0.0) + return pmoveplayer->m_flLongJumpHeight; + } + else if (pmoveplayer->m_flJumpHeight > 0.0) + return pmoveplayer->m_flJumpHeight; +#endif + return Q_sqrt(2.0 * 800.0f * (longjump ? 56.0f : 45.0f)); +} + void PM_Jump() { if (pmove->dead) @@ -2438,16 +2454,12 @@ void PM_Jump() return; } -#ifdef REGAMEDLL_API - const CCSPlayer* player = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer(); -#endif - // don't pogo stick if (pmove->oldbuttons & IN_JUMP #ifdef REGAMEDLL_ADD && sv_autobunnyhopping.value <= 0.0 #ifdef REGAMEDLL_API - && !player->m_bAutoBunnyHopping + && !pmoveplayer->m_bAutoBunnyHopping #endif #endif ) @@ -2468,7 +2480,7 @@ void PM_Jump() #ifdef REGAMEDLL_ADD if (sv_enablebunnyhopping.value <= 0.0 #ifdef REGAMEDLL_API - && !player->m_bMegaBunnyJumping + && !pmoveplayer->m_bMegaBunnyJumping #endif ) #endif @@ -2484,24 +2496,6 @@ void PM_Jump() PM_PlayStepSound(PM_MapTextureTypeStepType(pmove->chtexturetype), fvol); } -#ifdef REGAMEDLL_API - auto PM_JumpHeight = [&player](bool longjump) -> real_t -#else - auto PM_JumpHeight = [&](bool longjump) -> real_t -#endif - { -#ifdef REGAMEDLL_API - if (longjump) - { - if(player->m_flLongJumpHeight > 0.0) - return player->m_flLongJumpHeight; - } - else if (player->m_flJumpHeight > 0.0) - return player->m_flJumpHeight; -#endif - return Q_sqrt(2.0 * 800.0f * (longjump ? 56.0f : 45.0f)); - }; - #ifdef REGAMEDLL_ADD // See if user can super long jump? bool cansuperjump = (pmove->PM_Info_ValueForKey(pmove->physinfo, "slj")[0] == '1'); @@ -2517,9 +2511,9 @@ void PM_Jump() pmove->punchangle[0] = -5.0f; #ifdef REGAMEDLL_API - if (player->m_flLongJumpForce > 0.0) + if (pmoveplayer->m_flLongJumpForce > 0.0) { - fvel = player->m_flLongJumpForce; + fvel = pmoveplayer->m_flLongJumpForce; } else #endif @@ -3267,6 +3261,10 @@ void EXT_FUNC __API_HOOK(PM_Move)(struct playermove_s *ppmove, int server) assert(pm_shared_initialized); pmove = ppmove; + +#ifdef REGAMEDLL_API + pmoveplayer = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer(); +#endif PM_PlayerMove((server != 0) ? TRUE : FALSE); diff --git a/regamedll/public/regamedll/API/CSPlayer.h b/regamedll/public/regamedll/API/CSPlayer.h index 10c32cdb0..f56b1c513 100644 --- a/regamedll/public/regamedll/API/CSPlayer.h +++ b/regamedll/public/regamedll/API/CSPlayer.h @@ -143,7 +143,7 @@ class CCSPlayer: public CCSMonster { double m_flJumpHeight; double m_flLongJumpHeight; double m_flLongJumpForce; - float m_flDuckSpeedMultiplier; + double m_flDuckSpeedMultiplier; }; // Inlines From eba02ff214a4276ef65a4bb38ff2f56635454d2d Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Tue, 5 Sep 2023 10:44:42 +0700 Subject: [PATCH 6/6] Trim space --- regamedll/pm_shared/pm_shared.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index 91cfa782a..2ff6d7a12 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -2495,7 +2495,7 @@ void PM_Jump() { PM_PlayStepSound(PM_MapTextureTypeStepType(pmove->chtexturetype), fvol); } - + #ifdef REGAMEDLL_ADD // See if user can super long jump? bool cansuperjump = (pmove->PM_Info_ValueForKey(pmove->physinfo, "slj")[0] == '1');