Implement RG_CBasePlayer_DropIdlePlayer hook (#444)

This commit is contained in:
Dmitry 2019-11-02 15:48:23 +07:00 committed by Dmitry Novikov
parent dbf08416fd
commit fd06d655ec
5 changed files with 43 additions and 19 deletions

View File

@ -166,6 +166,7 @@ GAMEHOOK_REGISTRY(CBasePlayerWeapon_CanDeploy);
GAMEHOOK_REGISTRY(CBasePlayerWeapon_DefaultDeploy);
GAMEHOOK_REGISTRY(CBasePlayerWeapon_DefaultReload);
GAMEHOOK_REGISTRY(CBasePlayerWeapon_DefaultShotgunReload);
GAMEHOOK_REGISTRY(CBasePlayer_DropIdlePlayer);
int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;

View File

@ -563,6 +563,10 @@ typedef IHookChainRegistryClassImpl<int, CBasePlayerWeapon, int, int, float> CRe
typedef IHookChainClassImpl<bool, CBasePlayerWeapon, int, int, float, float, const char *, const char *> CReGameHook_CBasePlayerWeapon_DefaultShotgunReload;
typedef IHookChainRegistryClassImpl<bool, CBasePlayerWeapon, int, int, float, float, const char *, const char *> CReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload;
// CBasePlayer::DropIdlePlayer hook
typedef IHookChainClassImpl<void, CBasePlayer, const char *> CReGameHook_CBasePlayer_DropIdlePlayer;
typedef IHookChainRegistryClassImpl<void, CBasePlayer, const char *> CReGameHookRegistry_CBasePlayer_DropIdlePlayer;
class CReGameHookchains: public IReGameHookchains {
public:
// CBasePlayer virtual
@ -676,6 +680,7 @@ public:
CReGameHookRegistry_CBasePlayerWeapon_DefaultDeploy m_CBasePlayerWeapon_DefaultDeploy;
CReGameHookRegistry_CBasePlayerWeapon_DefaultReload m_CBasePlayerWeapon_DefaultReload;
CReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload m_CBasePlayerWeapon_DefaultShotgunReload;
CReGameHookRegistry_CBasePlayer_DropIdlePlayer m_CBasePlayer_DropIdlePlayer;
public:
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
@ -788,6 +793,7 @@ public:
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultDeploy *CBasePlayerWeapon_DefaultDeploy();
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultReload *CBasePlayerWeapon_DefaultReload();
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload();
virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer();
};
extern CReGameHookchains g_ReGameHookchains;

View File

@ -4316,26 +4316,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)()
real_t flLastMove = gpGlobals->time - m_fLastMovement;
//check if this player has been inactive for 2 rounds straight
if (flLastMove > CSGameRules()->m_fMaxIdlePeriod)
if (!IsBot() && flLastMove > CSGameRules()->m_fMaxIdlePeriod)
{
if (!IsBot() && autokick.value)
{
// Log the kick
UTIL_LogPrintf("\"%s<%i><%s><%s>\" triggered \"Game_idle_kick\" (auto)\n", STRING(pev->netname), GETPLAYERUSERID(edict()), GETPLAYERAUTHID(edict()), GetTeam(m_iTeam));
UTIL_ClientPrintAll(HUD_PRINTCONSOLE, "#Game_idle_kick", STRING(pev->netname));
#ifdef REGAMEDLL_FIXES
int iUserID = GETPLAYERUSERID(edict());
if (iUserID != -1)
{
SERVER_COMMAND(UTIL_VarArgs("kick #%d \"Player idle\"\n", iUserID));
}
#else
SERVER_COMMAND(UTIL_VarArgs("kick \"%s\"\n", STRING(pev->netname)));
#endif // #ifdef REGAMEDLL_FIXES
m_fLastMovement = gpGlobals->time;
}
DropIdlePlayer("Player idle");
m_fLastMovement = gpGlobals->time;
}
#ifdef REGAMEDLL_ADD
if (afk_bomb_drop_time.value > 0.0 && IsBombGuy())
@ -9921,3 +9906,28 @@ void CBasePlayer::__API_HOOK(RemoveSpawnProtection)()
CSPlayer()->m_flSpawnProtectionEndTime = 0.0f;
}
LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayer, DropIdlePlayer, (const char *reason), reason)
void EXT_FUNC CBasePlayer::__API_HOOK(DropIdlePlayer)(const char *reason)
{
if (!autokick.value)
return;
edict_t *pEntity = edict();
int iUserID = GETPLAYERUSERID(pEntity);
// Log the kick
UTIL_LogPrintf("\"%s<%i><%s><%s>\" triggered \"Game_idle_kick\" (auto)\n", STRING(pev->netname), iUserID , GETPLAYERAUTHID(pEntity), GetTeam(m_iTeam));
UTIL_ClientPrintAll(HUD_PRINTCONSOLE, "#Game_idle_kick", STRING(pev->netname));
#ifdef REGAMEDLL_FIXES
if (iUserID != -1)
{
SERVER_COMMAND(UTIL_VarArgs("kick #%d \"%s\"\n", iUserID, reason));
}
#else
SERVER_COMMAND(UTIL_VarArgs("kick \"%s\"\n", STRING(pev->netname)));
#endif // #ifdef REGAMEDLL_FIXES
}

View File

@ -429,6 +429,7 @@ public:
void RemoveSpawnProtection_OrigFunc();
bool HintMessageEx_OrigFunc(const char *pMessage, float duration = 6.0f, bool bDisplayIfPlayerDead = false, bool bOverride = false);
void UseEmpty_OrigFunc();
void DropIdlePlayer_OrigFunc(const char *reason);
CCSPlayer *CSPlayer() const;
#endif // REGAMEDLL_API
@ -625,6 +626,7 @@ public:
void SetSpawnProtection(float flProtectionTime);
void RemoveSpawnProtection();
void UseEmpty();
void DropIdlePlayer(const char *reason);
// templates
template<typename T = CBasePlayerItem, typename Functor>

View File

@ -460,6 +460,10 @@ typedef IHookChainRegistryClass<int, class CBasePlayerWeapon, int, int, float> I
typedef IHookChainClass<bool, class CBasePlayerWeapon, int, int, float, float, const char *, const char *> IReGameHook_CBasePlayerWeapon_DefaultShotgunReload;
typedef IHookChainRegistryClass<bool, class CBasePlayerWeapon, int, int, float, float, const char *, const char *> IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload;
// CBasePlayer::DropIdlePlayer hook
typedef IHookChainClass<void, CBasePlayer, const char *> IReGameHook_CBasePlayer_DropIdlePlayer;
typedef IHookChainRegistryClass<void, CBasePlayer, const char *> IReGameHookRegistry_CBasePlayer_DropIdlePlayer;
class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
@ -574,6 +578,7 @@ public:
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultDeploy *CBasePlayerWeapon_DefaultDeploy() = 0;
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultReload *CBasePlayerWeapon_DefaultReload() = 0;
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload() = 0;
virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer() = 0;
};
struct ReGameFuncs_t {