Skip to content

Commit

Permalink
#Implement CBasePlayerItem:: hook
Browse files Browse the repository at this point in the history
  • Loading branch information
lozatto committed Aug 13, 2024
1 parent f9969ac commit 1f69e15
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
regamedll/version/appversion.h
regamedll/msvc/PublishPath*.txt
publish
/.vs/VSWorkspaceState.json
/.vs/slnx.sqlite
/regamedll/msvc/cpp.hint
3 changes: 3 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ GAMEHOOK_REGISTRY(CBasePlayer_PlayerDeathThink);
GAMEHOOK_REGISTRY(CBasePlayer_Observer_Think);
GAMEHOOK_REGISTRY(CBasePlayer_RemoveAllItems);

GAMEHOOK_REGISTRY(CBasePlayerItem_Materialize);
GAMEHOOK_REGISTRY(CBasePlayerItem_CheckRespawn);

int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;
}
Expand Down
18 changes: 18 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,15 @@ typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBase
typedef IHookChainClassImpl<void, CBasePlayer, BOOL> CReGameHook_CBasePlayer_RemoveAllItems;
typedef IHookChainRegistryClassImpl<void, CBasePlayer, BOOL> CReGameHookRegistry_CBasePlayer_RemoveAllItems;

// CBasePlayerItem::Materialize hook
typedef IHookChainClassImpl<void, CBasePlayerItem> CReGameHook_CBasePlayerItem_Materialize;
typedef IHookChainRegistryClassImpl<void, CBasePlayerItem> CReGameHookRegistry_CBasePlayerItem_Materialize;

// CBasePlayerItem::CheckRespawn hook
typedef IHookChainClassImpl<void, CBasePlayerItem> CReGameHook_CBasePlayerItem_CheckRespawn;
typedef IHookChainRegistryClassImpl<void, CBasePlayerItem> CReGameHookRegistry_CBasePlayerItem_CheckRespawn;


class CReGameHookchains: public IReGameHookchains {
public:
// CBasePlayer virtual
Expand Down Expand Up @@ -911,6 +920,10 @@ class CReGameHookchains: public IReGameHookchains {
CReGameHookRegistry_CBasePlayer_Observer_Think m_CBasePlayer_Observer_Think;
CReGameHookRegistry_CBasePlayer_RemoveAllItems m_CBasePlayer_RemoveAllItems;

CReGameHookRegistry_CBasePlayerItem_Materialize m_CBasePlayerItem_Materialize;
CReGameHookRegistry_CBasePlayerItem_CheckRespawn m_CBasePlayerItem_CheckRespawn;


public:
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
virtual IReGameHookRegistry_CBasePlayer_Precache *CBasePlayer_Precache();
Expand Down Expand Up @@ -1070,6 +1083,11 @@ class CReGameHookchains: public IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink();
virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think();
virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems();


virtual IReGameHookRegistry_CBasePlayerItem_Materialize *CBasePlayerItem_Materialize();
virtual IReGameHookRegistry_CBasePlayerItem_CheckRespawn *CBasePlayerItem_CheckRespawn();

};

extern CReGameHookchains g_ReGameHookchains;
Expand Down
6 changes: 4 additions & 2 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ void CBasePlayerItem::FallThink()
}
}

LINK_HOOK_CLASS_VOID_CHAIN2(CBasePlayerItem, Materialize)
// Materialize - make a CBasePlayerItem visible and tangible
void CBasePlayerItem::Materialize()
void EXT_FUNC CBasePlayerItem::__API_HOOK(Materialize)()
{
if (pev->effects & EF_NODRAW)
{
Expand Down Expand Up @@ -553,9 +554,10 @@ void CBasePlayerItem::AttemptToMaterialize()
pev->nextthink = gpGlobals->time + time;
}

LINK_HOOK_CLASS_VOID_CHAIN2(CBasePlayerItem, CheckRespawn)
// CheckRespawn - a player is taking this weapon, should
// it respawn?
void CBasePlayerItem::CheckRespawn()
void EXT_FUNC CBasePlayerItem::__API_HOOK(CheckRespawn)()
{
switch (g_pGameRules->WeaponShouldRespawn(this))
{
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ class CBasePlayerItem: public CBaseAnimating

public:
#ifdef REGAMEDLL_API
void Materialize_OrigFunc();
void CheckRespawn_OrigFunc();
CCSPlayerItem *CSPlayerItem() const;
#endif

Expand Down
12 changes: 12 additions & 0 deletions regamedll/public/regamedll/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,14 @@ typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBa
typedef IHookChainClass<void, class CBasePlayer, BOOL> IReGameHook_CBasePlayer_RemoveAllItems;
typedef IHookChainRegistryClass<void, class CBasePlayer, BOOL> IReGameHookRegistry_CBasePlayer_RemoveAllItems;

// CBasePlayerItem::Materialize hook
typedef IHookChainClassImpl<void, CBasePlayerItem> IReGameHook_CBasePlayerItem_Materialize;
typedef IHookChainRegistryClassImpl<void, CBasePlayerItem> IReGameHookRegistry_CBasePlayerItem_Materialize;

// CBasePlayerItem::CheckRespawn hook
typedef IHookChainClassImpl<void, CBasePlayerItem> IReGameHook_CBasePlayerItem_CheckRespawn;
typedef IHookChainRegistryClassImpl<void, CBasePlayerItem> IReGameHookRegistry_CBasePlayerItem_CheckRespawn;

class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
Expand Down Expand Up @@ -790,6 +798,10 @@ class IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink() = 0;
virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think() = 0;
virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems() = 0;

virtual IReGameHookRegistry_CBasePlayerItem_Materialize* CBasePlayerItem_Materialize() = 0;
virtual IReGameHookRegistry_CBasePlayerItem_CheckRespawn* CBasePlayerItem_CheckRespawn() = 0;

};

struct ReGameFuncs_t {
Expand Down

0 comments on commit 1f69e15

Please sign in to comment.