Skip to content

Commit

Permalink
Implement RG_CBasePlayer_DropIdlePlayer hook (#148)
Browse files Browse the repository at this point in the history
* Implement RG_CBasePlayer_DropIdlePlayer hook
  • Loading branch information
d3m37r4 authored and s1lentq committed Nov 4, 2019
1 parent 9874820 commit d954d04
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,13 @@ enum GamedllFunc_CBasePlayer
* Params: (const this)
*/
RG_CBasePlayer_UseEmpty,

/*
* Description: Called when a idle player is removed from server.
* Return type: void
* Params: (const this, const reason[])
*/
RG_CBasePlayer_DropIdlePlayer,
};

/**
Expand Down
5 changes: 5 additions & 0 deletions reapi/include/cssdk/dlls/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, class CBasePlayer, const char *> IReGameHook_CBasePlayer_DropIdlePlayer;
typedef IHookChainRegistryClass<void, class 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
10 changes: 10 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,16 @@ void CBasePlayer_UseEmpty(IReGameHook_CBasePlayer_UseEmpty *chain, CBasePlayer *
callVoidForward(RG_CBasePlayer_UseEmpty, original, indexOfEdict(pthis->pev));
}

void CBasePlayer_DropIdlePlayer(IReGameHook_CBasePlayer_DropIdlePlayer *chain, CBasePlayer *pthis, const char *reason)
{
auto original = [chain](int _pthis, const char *_reason)
{
return chain->callNext(getPrivate<CBasePlayer>(_pthis), _reason);
};

callVoidForward(RG_CBasePlayer_DropIdlePlayer, original, indexOfEdict(pthis->pev), reason);
}

void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis)
{
auto original = [chain](int _pthis)
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ void CBasePlayer_SetSpawnProtection(IReGameHook_CBasePlayer_SetSpawnProtection *
void CBasePlayer_RemoveSpawnProtection(IReGameHook_CBasePlayer_RemoveSpawnProtection *chain, CBasePlayer *pthis);
bool CBasePlayer_HintMessageEx(IReGameHook_CBasePlayer_HintMessageEx *chain, CBasePlayer *pthis, const char *pMessage, float duration, bool bDisplayIfPlayerDead, bool bOverride);
void CBasePlayer_UseEmpty(IReGameHook_CBasePlayer_UseEmpty *chain, CBasePlayer *pthis);
void CBasePlayer_DropIdlePlayer(IReGameHook_CBasePlayer_DropIdlePlayer *chain, CBasePlayer *pthis, const char *reason);

void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis);

Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ hook_t hooklist_player[] = {
DLL(CBasePlayer_RemoveSpawnProtection),
DLL(CBasePlayer_HintMessageEx),
DLL(CBasePlayer_UseEmpty),
DLL(CBasePlayer_DropIdlePlayer),
};

hook_t hooklist_gamerules[] = {
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ enum GamedllFunc_CBasePlayer
RG_CBasePlayer_RemoveSpawnProtection,
RG_CBasePlayer_HintMessageEx,
RG_CBasePlayer_UseEmpty,
RG_CBasePlayer_DropIdlePlayer,

// [...]
};
Expand Down

0 comments on commit d954d04

Please sign in to comment.