API: CSPlayer new members (physics related) (#851)

* CSPlayer new members
* 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
This commit is contained in:
Francisco Muñoz 2023-09-05 00:52:14 -03:00 committed by GitHub
parent 696f465977
commit f441279294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 16 deletions

View File

@ -12,6 +12,10 @@ char pm_grgchTextureType[MAX_TEXTURES];
playermove_t *pmove = nullptr; playermove_t *pmove = nullptr;
BOOL g_onladder = FALSE; BOOL g_onladder = FALSE;
#ifdef REGAMEDLL_API
static CCSPlayer *pmoveplayer = nullptr;
#endif
#ifdef CLIENT_DLL #ifdef CLIENT_DLL
int iJumpSpectator; int iJumpSpectator;
float vJumpOrigin[3]; float vJumpOrigin[3];
@ -1907,9 +1911,16 @@ void EXT_FUNC __API_HOOK(PM_Duck)()
return; return;
} }
pmove->cmd.forwardmove *= PLAYER_DUCKING_MULTIPLIER; real_t mult = PLAYER_DUCKING_MULTIPLIER;
pmove->cmd.sidemove *= PLAYER_DUCKING_MULTIPLIER;
pmove->cmd.upmove *= PLAYER_DUCKING_MULTIPLIER; #ifdef REGAMEDLL_API
if (pmoveplayer->m_flDuckSpeedMultiplier > 0.0)
mult = pmoveplayer->m_flDuckSpeedMultiplier;
#endif
pmove->cmd.forwardmove *= mult;
pmove->cmd.sidemove *= mult;
pmove->cmd.upmove *= mult;
if (pmove->cmd.buttons & IN_DUCK) if (pmove->cmd.buttons & IN_DUCK)
{ {
@ -2023,8 +2034,17 @@ void EXT_FUNC __API_HOOK(PM_LadderMove)(physent_t *pLadder)
if (pmove->flags & FL_DUCKING) if (pmove->flags & FL_DUCKING)
{ {
#ifdef REGAMEDLL_API
if (pmoveplayer->m_flDuckSpeedMultiplier > 0.0)
{
flSpeed *= pmoveplayer->m_flDuckSpeedMultiplier;
}
else
#endif
{
flSpeed *= PLAYER_DUCKING_MULTIPLIER; flSpeed *= PLAYER_DUCKING_MULTIPLIER;
} }
}
if (pmove->cmd.buttons & IN_BACK) if (pmove->cmd.buttons & IN_BACK)
{ {
@ -2354,6 +2374,20 @@ void PM_PreventMegaBunnyJumping()
VectorScale(pmove->velocity, fraction, pmove->velocity); 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));
}
LINK_HOOK_VOID_CHAIN2(PM_Jump) LINK_HOOK_VOID_CHAIN2(PM_Jump)
void EXT_FUNC __API_HOOK(PM_Jump)() void EXT_FUNC __API_HOOK(PM_Jump)()
@ -2432,16 +2466,12 @@ void EXT_FUNC __API_HOOK(PM_Jump)()
return; return;
} }
#ifdef REGAMEDLL_API
const CCSPlayer* player = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer();
#endif
// don't pogo stick // don't pogo stick
if (pmove->oldbuttons & IN_JUMP if (pmove->oldbuttons & IN_JUMP
#ifdef REGAMEDLL_ADD #ifdef REGAMEDLL_ADD
&& sv_autobunnyhopping.value <= 0.0 && sv_autobunnyhopping.value <= 0.0
#ifdef REGAMEDLL_API #ifdef REGAMEDLL_API
&& !player->m_bAutoBunnyHopping && !pmoveplayer->m_bAutoBunnyHopping
#endif #endif
#endif #endif
) )
@ -2462,7 +2492,7 @@ void EXT_FUNC __API_HOOK(PM_Jump)()
#ifdef REGAMEDLL_ADD #ifdef REGAMEDLL_ADD
if (sv_enablebunnyhopping.value <= 0.0 if (sv_enablebunnyhopping.value <= 0.0
#ifdef REGAMEDLL_API #ifdef REGAMEDLL_API
&& !player->m_bMegaBunnyJumping && !pmoveplayer->m_bMegaBunnyJumping
#endif #endif
) )
#endif #endif
@ -2492,23 +2522,34 @@ void EXT_FUNC __API_HOOK(PM_Jump)()
{ {
pmove->punchangle[0] = -5.0f; pmove->punchangle[0] = -5.0f;
for (int i = 0; i < 2; i++) #ifdef REGAMEDLL_API
if (pmoveplayer->m_flLongJumpForce > 0.0)
{ {
pmove->velocity[i] = pmove->forward[i] * PLAYER_LONGJUMP_SPEED * 1.6f; fvel = pmoveplayer->m_flLongJumpForce;
}
else
#endif
{
fvel = PLAYER_LONGJUMP_SPEED * 1.6f;
} }
pmove->velocity[2] = Q_sqrt(2 * 800 * 56.0f); for (int i = 0; i < 2; i++)
{
pmove->velocity[i] = pmove->forward[i] * fvel;
}
pmove->velocity[2] = PM_JumpHeight(true);
} }
else else
{ {
pmove->velocity[2] = Q_sqrt(2 * 800 * 45.0f); pmove->velocity[2] = PM_JumpHeight(false);
} }
} }
else else
#endif #endif
{ {
// NOTE: don't do it in .f (float) // 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) if (pmove->fuser2 > 0.0f)
@ -3235,6 +3276,10 @@ void EXT_FUNC __API_HOOK(PM_Move)(struct playermove_s *ppmove, int server)
pmove = ppmove; pmove = ppmove;
#ifdef REGAMEDLL_API
pmoveplayer = UTIL_PlayerByIndex(pmove->player_index + 1)->CSPlayer();
#endif
PM_PlayerMove((server != 0) ? TRUE : FALSE); PM_PlayerMove((server != 0) ? TRUE : FALSE);
if (pmove->onground != -1) if (pmove->onground != -1)

View File

@ -50,7 +50,11 @@ public:
m_bAutoBunnyHopping(false), m_bAutoBunnyHopping(false),
m_bMegaBunnyJumping(false), m_bMegaBunnyJumping(false),
m_bPlantC4Anywhere(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'; m_szModel[0] = '\0';
} }
@ -136,6 +140,10 @@ public:
bool m_bMegaBunnyJumping; bool m_bMegaBunnyJumping;
bool m_bPlantC4Anywhere; bool m_bPlantC4Anywhere;
bool m_bSpawnProtectionEffects; bool m_bSpawnProtectionEffects;
double m_flJumpHeight;
double m_flLongJumpHeight;
double m_flLongJumpForce;
double m_flDuckSpeedMultiplier;
}; };
// Inlines // Inlines