Skip to content

Commit

Permalink
Implement player hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0werD committed Aug 24, 2021
1 parent d85b030 commit d6761ba
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
4 changes: 4 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ GAMEHOOK_REGISTRY(CBaseEntity_FireBullets);
GAMEHOOK_REGISTRY(CBaseEntity_FireBuckshots);
GAMEHOOK_REGISTRY(CBaseEntity_FireBullets3);

GAMEHOOK_REGISTRY(CBasePlayer_Pain);
GAMEHOOK_REGISTRY(CBasePlayer_DeathSound);
GAMEHOOK_REGISTRY(CBasePlayer_JoiningThink);

int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;
}
Expand Down
20 changes: 20 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,18 @@ typedef IHookChainRegistryClassImpl<void, class CBaseEntity, ULONG, Vector &, Ve
typedef IHookChainClassImpl<Vector &, class CBaseEntity, Vector &, Vector &, float, float, int, int, int, float, entvars_t *, bool, int> CReGameHook_CBaseEntity_FireBullets3;
typedef IHookChainRegistryClassImpl<Vector &, class CBaseEntity, Vector &, Vector &, float, float, int, int, int, float, entvars_t *, bool, int> CReGameHookRegistry_CBaseEntity_FireBullets3;

// CBasePlayer::Pain hook
typedef IHookChainClassImpl<void, CBasePlayer, int, bool> CReGameHook_CBasePlayer_Pain;
typedef IHookChainRegistryClassImpl<void, CBasePlayer, int, bool> CReGameHookRegistry_CBasePlayer_Pain;

// CBasePlayer::DeathSound hook
typedef IHookChainClassImpl<void, CBasePlayer> CReGameHook_CBasePlayer_DeathSound;
typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBasePlayer_DeathSound;

// CBasePlayer::JoiningThink hook
typedef IHookChainClassImpl<void, CBasePlayer> CReGameHook_CBasePlayer_JoiningThink;
typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBasePlayer_JoiningThink;

class CReGameHookchains: public IReGameHookchains {
public:
// CBasePlayer virtual
Expand Down Expand Up @@ -746,6 +758,10 @@ class CReGameHookchains: public IReGameHookchains {
CReGameHookRegistry_CBaseEntity_FireBullets m_CBaseEntity_FireBullets;
CReGameHookRegistry_CBaseEntity_FireBuckshots m_CBaseEntity_FireBuckshots;
CReGameHookRegistry_CBaseEntity_FireBullets3 m_CBaseEntity_FireBullets3;

CReGameHookRegistry_CBasePlayer_Pain m_CBasePlayer_Pain;
CReGameHookRegistry_CBasePlayer_DeathSound m_CBasePlayer_DeathSound;
CReGameHookRegistry_CBasePlayer_JoiningThink m_CBasePlayer_JoiningThink;

public:
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
Expand Down Expand Up @@ -870,6 +886,10 @@ class CReGameHookchains: public IReGameHookchains {
virtual IReGameHookRegistry_CBaseEntity_FireBullets *CBaseEntity_FireBullets();
virtual IReGameHookRegistry_CBaseEntity_FireBuckshots *CBaseEntity_FireBuckshots();
virtual IReGameHookRegistry_CBaseEntity_FireBullets3 *CBaseEntity_FireBullets3();

virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain();
virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound();
virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink();
};

extern CReGameHookchains g_ReGameHookchains;
Expand Down
12 changes: 9 additions & 3 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ void CBasePlayer::SmartRadio()
;
}

void CBasePlayer::Pain(int iLastHitGroup, bool bHasArmour)
LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayer, Pain, (int iLastHitGroup, bool bHasArmour), iLastHitGroup, bHasArmour)

void EXT_FUNC CBasePlayer::__API_HOOK(Pain)(int iLastHitGroup, bool bHasArmour)
{
int temp = RANDOM_LONG(0, 2);

Expand Down Expand Up @@ -537,7 +539,9 @@ int TrainSpeed(int iSpeed, int iMax)
return iRet;
}

void CBasePlayer::DeathSound()
LINK_HOOK_CLASS_VOID_CHAIN2(CBasePlayer, DeathSound)

void EXT_FUNC CBasePlayer::__API_HOOK(DeathSound)()
{
// temporarily using pain sounds for death sounds
switch (RANDOM_LONG(1, 4))
Expand Down Expand Up @@ -3538,7 +3542,9 @@ void EXT_FUNC CBasePlayer::__API_HOOK(MakeVIP)()
CSGameRules()->m_iConsecutiveVIP = 1;
}

void CBasePlayer::JoiningThink()
LINK_HOOK_CLASS_VOID_CHAIN2(CBasePlayer, JoiningThink)

void EXT_FUNC CBasePlayer::__API_HOOK(JoiningThink)()
{
switch (m_iJoiningState)
{
Expand Down
3 changes: 3 additions & 0 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ class CBasePlayer: public CBaseMonster {
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);
void Pain_OrigFunc(int iLastHitGroup, bool bHasArmour);
void DeathSound_OrigFunc();
void JoiningThink_OrigFunc();

CCSPlayer *CSPlayer() const;
#endif // REGAMEDLL_API
Expand Down
17 changes: 16 additions & 1 deletion regamedll/public/regamedll/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <API/CSInterfaces.h>

#define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 20
#define REGAMEDLL_API_VERSION_MINOR 21

// CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
Expand Down Expand Up @@ -500,6 +500,17 @@ typedef IHookChainRegistryClass<void, class CBaseEntity, ULONG, Vector &, Vector
typedef IHookChainClass<Vector &, class CBaseEntity, Vector &, Vector &, float, float, int, int, int, float, entvars_t *, bool, int> IReGameHook_CBaseEntity_FireBullets3;
typedef IHookChainRegistryClass<Vector &, class CBaseEntity, Vector &, Vector &, float, float, int, int, int, float, entvars_t *, bool, int> IReGameHookRegistry_CBaseEntity_FireBullets3;

// CBasePlayer::Pain hook
typedef IHookChainClass<void, class CBasePlayer, int, bool> IReGameHook_CBasePlayer_Pain;
typedef IHookChainRegistryClass<void, class CBasePlayer, int, bool> IReGameHookRegistry_CBasePlayer_Pain;

// CBasePlayer::DeathSound hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_DeathSound;
typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBasePlayer_DeathSound;

// CBasePlayer::JoiningThink hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_JoiningThink;
typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBasePlayer_JoiningThink;

class IReGameHookchains {
public:
Expand Down Expand Up @@ -627,6 +638,10 @@ class IReGameHookchains {
virtual IReGameHookRegistry_CBaseEntity_FireBullets *CBaseEntity_FireBullets() = 0;
virtual IReGameHookRegistry_CBaseEntity_FireBuckshots *CBaseEntity_FireBuckshots() = 0;
virtual IReGameHookRegistry_CBaseEntity_FireBullets3 *CBaseEntity_FireBullets3() = 0;

virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain() = 0;
virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound() = 0;
virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink() = 0;
};

struct ReGameFuncs_t {
Expand Down

0 comments on commit d6761ba

Please sign in to comment.