From 607a5cc96405e65d78ea0bffc658c4a46f796c5a Mon Sep 17 00:00:00 2001 From: Celio Lozatto Date: Tue, 13 Aug 2024 13:01:18 -0300 Subject: [PATCH] Implement CBasePlayerItem:: hook --- regamedll/dlls/API/CAPI_Impl.cpp | 3 +++ regamedll/dlls/API/CAPI_Impl.h | 14 ++++++++++++++ regamedll/dlls/weapons.cpp | 6 ++++-- regamedll/dlls/weapons.h | 2 ++ regamedll/public/regamedll/regamedll_api.h | 11 +++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/regamedll/dlls/API/CAPI_Impl.cpp b/regamedll/dlls/API/CAPI_Impl.cpp index 41175c838..8877ddf9a 100644 --- a/regamedll/dlls/API/CAPI_Impl.cpp +++ b/regamedll/dlls/API/CAPI_Impl.cpp @@ -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; } diff --git a/regamedll/dlls/API/CAPI_Impl.h b/regamedll/dlls/API/CAPI_Impl.h index 2635be5b9..caecf5f15 100644 --- a/regamedll/dlls/API/CAPI_Impl.h +++ b/regamedll/dlls/API/CAPI_Impl.h @@ -749,6 +749,14 @@ typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBase typedef IHookChainClassImpl CReGameHook_CBasePlayer_RemoveAllItems; typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayer_RemoveAllItems; +// CBasePlayerItem::Materialize hook +typedef IHookChainClassImpl CReGameHook_CBasePlayerItem_Materialize; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayerItem_Materialize; + +// CBasePlayerItem::CheckRespawn hook +typedef IHookChainClassImpl CReGameHook_CBasePlayerItem_CheckRespawn; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayerItem_CheckRespawn; + class CReGameHookchains: public IReGameHookchains { public: // CBasePlayer virtual @@ -911,6 +919,9 @@ 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(); @@ -1070,6 +1081,9 @@ 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; diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 9a3d8e0c0..1b5f447ff 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -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) { @@ -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)) { diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index 9266d8434..801a14eb3 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -311,6 +311,8 @@ class CBasePlayerItem: public CBaseAnimating public: #ifdef REGAMEDLL_API + void Materialize_OrigFunc(); + void CheckRespawn_OrigFunc(); CCSPlayerItem *CSPlayerItem() const; #endif diff --git a/regamedll/public/regamedll/regamedll_api.h b/regamedll/public/regamedll/regamedll_api.h index d655ee656..9a04ed587 100644 --- a/regamedll/public/regamedll/regamedll_api.h +++ b/regamedll/public/regamedll/regamedll_api.h @@ -628,6 +628,14 @@ typedef IHookChainRegistryClass IReGameHookRegistry_CBa typedef IHookChainClass IReGameHook_CBasePlayer_RemoveAllItems; typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_RemoveAllItems; +// CBasePlayerItem::Materialize hook +typedef IHookChainClass IReGameHook_CBasePlayerItem_Materialize; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerItem_Materialize; + +// CBasePlayerItem::CheckRespawn hook +typedef IHookChainClass IReGameHook_CBasePlayerItem_CheckRespawn; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerItem_CheckRespawn; + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -790,6 +798,9 @@ 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 {