Skip to content

Commit

Permalink
Implement RG_CBasePlayer_DropIdlePlayer hook (rehlds#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m37r4 authored and s1lentq committed Nov 2, 2019
1 parent dbf0841 commit fd06d65
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
1 change: 1 addition & 0 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -676,6 +680,7 @@ class CReGameHookchains: public IReGameHookchains {
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();
Expand Down Expand Up @@ -788,6 +793,7 @@ class CReGameHookchains: public IReGameHookchains {
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;
Expand Down
48 changes: 29 additions & 19 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ class CBasePlayer: public CBaseMonster {
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
Expand Down Expand Up @@ -625,6 +626,7 @@ class CBasePlayer: public CBaseMonster {
void SetSpawnProtection(float flProtectionTime);
void RemoveSpawnProtection();
void UseEmpty();
void DropIdlePlayer(const char *reason);

// templates
template<typename T = CBasePlayerItem, typename Functor>
Expand Down
5 changes: 5 additions & 0 deletions regamedll/public/regamedll/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -574,6 +578,7 @@ class IReGameHookchains {
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 {
Expand Down

0 comments on commit fd06d65

Please sign in to comment.