From 913fdda337b94d9ae76d6bc64cfbd74d7f3271cd Mon Sep 17 00:00:00 2001 From: Lozatto Date: Fri, 9 Aug 2024 00:11:33 -0300 Subject: [PATCH 1/2] Implement CBreakable:: hooks --- regamedll/dlls/API/CAPI_Impl.cpp | 8 ++++ regamedll/dlls/API/CAPI_Impl.h | 44 ++++++++++++++++++++++ regamedll/dlls/func_break.cpp | 26 +++++++++---- regamedll/dlls/func_break.h | 9 +++++ regamedll/public/regamedll/regamedll_api.h | 36 ++++++++++++++++++ 5 files changed, 116 insertions(+), 7 deletions(-) diff --git a/regamedll/dlls/API/CAPI_Impl.cpp b/regamedll/dlls/API/CAPI_Impl.cpp index 41175c838..1a3f9fad4 100644 --- a/regamedll/dlls/API/CAPI_Impl.cpp +++ b/regamedll/dlls/API/CAPI_Impl.cpp @@ -337,6 +337,14 @@ GAMEHOOK_REGISTRY(CBasePlayer_PlayerDeathThink); GAMEHOOK_REGISTRY(CBasePlayer_Observer_Think); GAMEHOOK_REGISTRY(CBasePlayer_RemoveAllItems); +GAMEHOOK_REGISTRY(CBreakable_Spawn); +GAMEHOOK_REGISTRY(CBreakable_Restart); +GAMEHOOK_REGISTRY(CBreakable_TraceAttack); +GAMEHOOK_REGISTRY(CBreakable_TakeDamage); +GAMEHOOK_REGISTRY(CBreakable_Use); +GAMEHOOK_REGISTRY(CBreakable_Die); +GAMEHOOK_REGISTRY(CBreakable_BreakTouch); + 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..e0874eb66 100644 --- a/regamedll/dlls/API/CAPI_Impl.h +++ b/regamedll/dlls/API/CAPI_Impl.h @@ -749,6 +749,34 @@ typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBase typedef IHookChainClassImpl CReGameHook_CBasePlayer_RemoveAllItems; typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayer_RemoveAllItems; +// CBreakable::Spawn hook +typedef IHookChainClassImpl CReGameHook_CBreakable_Spawn; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_Spawn; + +// CBreakable::Spawn hook +typedef IHookChainClassImpl CReGameHook_CBreakable_Restart; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_Restart; + +// CBreakable::TakeDamage hook +typedef IHookChainClassImpl CReGameHook_CBreakable_TakeDamage; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_TakeDamage; + +// CBasePlayer::TraceAttack hook +typedef IHookChainClassImpl CReGameHook_CBreakable_TraceAttack; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_TraceAttack; + +// CBreakable::Use hook +typedef IHookChainClassImpl CReGameHook_CBreakable_Use; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_Use; + +// CBreakable::Die hook +typedef IHookChainClassImpl CReGameHook_CBreakable_Die; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_Die; + +// CBreakable::BreakTouch hook +typedef IHookChainClassImpl CReGameHook_CBreakable_BreakTouch; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_BreakTouch; + class CReGameHookchains: public IReGameHookchains { public: // CBasePlayer virtual @@ -911,6 +939,14 @@ class CReGameHookchains: public IReGameHookchains { CReGameHookRegistry_CBasePlayer_Observer_Think m_CBasePlayer_Observer_Think; CReGameHookRegistry_CBasePlayer_RemoveAllItems m_CBasePlayer_RemoveAllItems; + CReGameHookRegistry_CBreakable_Spawn m_CBreakable_Spawn; + CReGameHookRegistry_CBreakable_Restart m_CBreakable_Restart; + CReGameHookRegistry_CBreakable_TraceAttack m_CBreakable_TraceAttack; + CReGameHookRegistry_CBreakable_TakeDamage m_CBreakable_TakeDamage; + CReGameHookRegistry_CBreakable_Use m_CBreakable_Use; + CReGameHookRegistry_CBreakable_Die m_CBreakable_Die; + CReGameHookRegistry_CBreakable_BreakTouch m_CBreakable_BreakTouch; + public: virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn(); virtual IReGameHookRegistry_CBasePlayer_Precache *CBasePlayer_Precache(); @@ -1070,6 +1106,14 @@ 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_CBreakable_Spawn* CBreakable_Spawn(); + virtual IReGameHookRegistry_CBreakable_Restart* CBreakable_Restart(); + virtual IReGameHookRegistry_CBreakable_TraceAttack* CBreakable_TraceAttack(); + virtual IReGameHookRegistry_CBreakable_TakeDamage* CBreakable_TakeDamage(); + virtual IReGameHookRegistry_CBreakable_Use* CBreakable_Use(); + virtual IReGameHookRegistry_CBreakable_Die* CBreakable_Die(); + virtual IReGameHookRegistry_CBreakable_BreakTouch* CBreakable_BreakTouch(); }; extern CReGameHookchains g_ReGameHookchains; diff --git a/regamedll/dlls/func_break.cpp b/regamedll/dlls/func_break.cpp index fa819f83e..340469d22 100644 --- a/regamedll/dlls/func_break.cpp +++ b/regamedll/dlls/func_break.cpp @@ -89,7 +89,9 @@ TYPEDESCRIPTION CBreakable::m_SaveData[] = LINK_ENTITY_TO_CLASS(func_breakable, CBreakable, CCSBreakable) IMPLEMENT_SAVERESTORE(CBreakable, CBaseEntity) -void CBreakable::Spawn() +LINK_HOOK_CLASS_VOID_CHAIN2(CBreakable, Spawn) + +void EXT_FUNC CBreakable::__API_HOOK(Spawn)() { Precache(); @@ -129,7 +131,9 @@ void CBreakable::Spawn() } } -void CBreakable::Restart() +LINK_HOOK_CLASS_VOID_CHAIN2(CBreakable, Restart) + +void EXT_FUNC CBreakable::__API_HOOK(Restart)() { pev->solid = SOLID_BSP; pev->movetype = MOVETYPE_PUSH; @@ -471,7 +475,9 @@ void CBreakable::DamageSound() } } -void CBreakable::BreakTouch(CBaseEntity *pOther) +LINK_HOOK_CLASS_VOID_CHAIN(CBreakable, BreakTouch, (CBaseEntity *pOther), pOther) + +void EXT_FUNC CBreakable::__API_HOOK(BreakTouch)(CBaseEntity *pOther) { float flDamage; entvars_t *pevToucher = pOther->pev; @@ -530,9 +536,10 @@ void CBreakable::BreakTouch(CBaseEntity *pOther) } } +LINK_HOOK_CLASS_VOID_CHAIN(CBreakable, Use, (CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value), pActivator, pCaller, useType, value) // Smash the our breakable object // Break when triggered -void CBreakable::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) +void EXT_FUNC CBreakable::__API_HOOK(Use)(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, FloatRef value) { if (IsBreakable()) { @@ -550,7 +557,9 @@ void CBreakable::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE use } } -void CBreakable::TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) +LINK_HOOK_CLASS_VOID_CHAIN(CBreakable, TraceAttack, (entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType), pevAttacker, flDamage, vecDir, ptr, bitsDamageType) + +void EXT_FUNC CBreakable::__API_HOOK(TraceAttack)(entvars_t *pevAttacker, float flDamage, VectorRef vecDir, TraceResult *ptr, int bitsDamageType) { // random spark if this is a 'computer' object if (RANDOM_LONG(0, 1)) @@ -582,10 +591,11 @@ void CBreakable::TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecD CBaseDelay::TraceAttack(pevAttacker, flDamage, vecDir, ptr, bitsDamageType); } +LINK_HOOK_CLASS_CHAIN(BOOL, CBreakable, TakeDamage, (entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType), pevInflictor, pevAttacker, flDamage, bitsDamageType) // Special takedamage for func_breakable. Allows us to make // exceptions that are breakable-specific // bitsDamageType indicates the type of damage sustained ie: DMG_CRUSH -BOOL CBreakable::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) +BOOL EXT_FUNC CBreakable::__API_HOOK(TakeDamage)(entvars_t *pevInflictor, entvars_t *pevAttacker, FloatRef flDamage, int bitsDamageType) { Vector vecTemp; @@ -652,7 +662,9 @@ BOOL CBreakable::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, flo return TRUE; } -void CBreakable::Die() +LINK_HOOK_CLASS_VOID_CHAIN2(CBreakable, Die) + +void EXT_FUNC CBreakable::__API_HOOK(Die)() { Vector vecSpot; // shard origin Vector vecVelocity; // shard velocity diff --git a/regamedll/dlls/func_break.h b/regamedll/dlls/func_break.h index 6b3756ce9..9783559db 100644 --- a/regamedll/dlls/func_break.h +++ b/regamedll/dlls/func_break.h @@ -78,6 +78,15 @@ class CBreakable: public CBaseDelay virtual int DamageDecal(int bitsDamageType); virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); +#ifdef REGAMEDLL_API + void Spawn_OrigFunc(); + void Restart_OrigFunc(); + void TraceAttack_OrigFunc(entvars_t *pevAttacker, float flDamage, VectorRef vecDir, TraceResult* ptr, int bitsDamageType); + BOOL TakeDamage_OrigFunc(entvars_t *pevInflictor, entvars_t *pevAttacker, FloatRef flDamage, int bitsDamageType); + void Use_OrigFunc(CBaseEntity *pActivator, CBaseEntity* pCaller, USE_TYPE useType, FloatRef value); + void Die_OrigFunc(); + void BreakTouch_OrigFunc(CBaseEntity *pOther); +#endif // REGAMEDLL_API public: void EXPORT BreakTouch(CBaseEntity *pOther); diff --git a/regamedll/public/regamedll/regamedll_api.h b/regamedll/public/regamedll/regamedll_api.h index d655ee656..9f0dcf0cf 100644 --- a/regamedll/public/regamedll/regamedll_api.h +++ b/regamedll/public/regamedll/regamedll_api.h @@ -628,6 +628,34 @@ typedef IHookChainRegistryClass IReGameHookRegistry_CBa typedef IHookChainClass IReGameHook_CBasePlayer_RemoveAllItems; typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_RemoveAllItems; +// CBreakable::Spawn hook +typedef IHookChainClassImpl IReGameHook_CBreakable_Spawn; +typedef IHookChainRegistryClassImpl IReGameHookRegistry_CBreakable_Spawn; + +// CBreakable::Restart hook +typedef IHookChainClassImpl IReGameHook_CBreakable_Restart; +typedef IHookChainRegistryClassImpl IReGameHookRegistry_CBreakable_Restart; + +// CBreakable::TakeDamage hook +typedef IHookChainClassImpl IReGameHook_CBreakable_TakeDamage; +typedef IHookChainRegistryClassImpl IReGameHookRegistry_CBreakable_TakeDamage; + +// CBreakable::TraceAttack hook +typedef IHookChainClass IReGameHook_CBreakable_TraceAttack; +typedef IHookChainRegistryClass IReGameHookRegistry_CBreakable_TraceAttack; + +// CBreakable::Use hook +typedef IHookChainClass IReGameHook_CBreakable_Use; +typedef IHookChainRegistryClass IReGameHookRegistry_CBreakable_Use; + +// CBreakable::Die hook +typedef IHookChainClassImpl IReGameHook_CBreakable_Die; +typedef IHookChainRegistryClassImpl IReGameHookRegistry_CBreakable_Die; + +// CBreakable::BreakTouch hook +typedef IHookChainClassImpl IReGameHook_CBreakabl_BreakTouch; +typedef IHookChainRegistryClassImpl IReGameHookRegistry_CBreakable_BreakTouch; + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -790,6 +818,14 @@ 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_CBreakable_Spawn* CBreakable_Spawn() = 0; + virtual IReGameHookRegistry_CBreakable_Restart* CBreakable_Restart() = 0; + virtual IReGameHookRegistry_CBreakable_TraceAttack* CBreakable_TraceAttack() = 0; + virtual IReGameHookRegistry_CBreakable_TakeDamage* CBreakable_TakeDamage() = 0; + virtual IReGameHookRegistry_CBreakable_Use* CBreakable_Use() = 0; + virtual IReGameHookRegistry_CBreakable_Die* CBreakable_Die() = 0; + virtual IReGameHookRegistry_CBreakable_BreakTouch* CBreakable_BreakTouch() = 0; }; struct ReGameFuncs_t { From 6a18daf7362f933353bac39ac287b99d8f76885f Mon Sep 17 00:00:00 2001 From: Lozatto Date: Fri, 9 Aug 2024 09:04:24 -0300 Subject: [PATCH 2/2] CBreakable:: hooks adjust * and comments --- regamedll/dlls/API/CAPI_Impl.h | 16 ++++++++-------- regamedll/public/regamedll/regamedll_api.h | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/regamedll/dlls/API/CAPI_Impl.h b/regamedll/dlls/API/CAPI_Impl.h index e0874eb66..52fea8b46 100644 --- a/regamedll/dlls/API/CAPI_Impl.h +++ b/regamedll/dlls/API/CAPI_Impl.h @@ -753,7 +753,7 @@ typedef IHookChainRegistryClassImpl CReGameHookRegistry typedef IHookChainClassImpl CReGameHook_CBreakable_Spawn; typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_Spawn; -// CBreakable::Spawn hook +// CBreakable::Restart hook typedef IHookChainClassImpl CReGameHook_CBreakable_Restart; typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBreakable_Restart; @@ -1107,13 +1107,13 @@ class CReGameHookchains: public IReGameHookchains { virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think(); virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems(); - virtual IReGameHookRegistry_CBreakable_Spawn* CBreakable_Spawn(); - virtual IReGameHookRegistry_CBreakable_Restart* CBreakable_Restart(); - virtual IReGameHookRegistry_CBreakable_TraceAttack* CBreakable_TraceAttack(); - virtual IReGameHookRegistry_CBreakable_TakeDamage* CBreakable_TakeDamage(); - virtual IReGameHookRegistry_CBreakable_Use* CBreakable_Use(); - virtual IReGameHookRegistry_CBreakable_Die* CBreakable_Die(); - virtual IReGameHookRegistry_CBreakable_BreakTouch* CBreakable_BreakTouch(); + virtual IReGameHookRegistry_CBreakable_Spawn *CBreakable_Spawn(); + virtual IReGameHookRegistry_CBreakable_Restart *CBreakable_Restart(); + virtual IReGameHookRegistry_CBreakable_TraceAttack *CBreakable_TraceAttack(); + virtual IReGameHookRegistry_CBreakable_TakeDamage *CBreakable_TakeDamage(); + virtual IReGameHookRegistry_CBreakable_Use *CBreakable_Use(); + virtual IReGameHookRegistry_CBreakable_Die *CBreakable_Die(); + virtual IReGameHookRegistry_CBreakable_BreakTouch *CBreakable_BreakTouch(); }; extern CReGameHookchains g_ReGameHookchains; diff --git a/regamedll/public/regamedll/regamedll_api.h b/regamedll/public/regamedll/regamedll_api.h index 9f0dcf0cf..0203fd6e9 100644 --- a/regamedll/public/regamedll/regamedll_api.h +++ b/regamedll/public/regamedll/regamedll_api.h @@ -819,13 +819,13 @@ class IReGameHookchains { virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think() = 0; virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems() = 0; - virtual IReGameHookRegistry_CBreakable_Spawn* CBreakable_Spawn() = 0; - virtual IReGameHookRegistry_CBreakable_Restart* CBreakable_Restart() = 0; - virtual IReGameHookRegistry_CBreakable_TraceAttack* CBreakable_TraceAttack() = 0; - virtual IReGameHookRegistry_CBreakable_TakeDamage* CBreakable_TakeDamage() = 0; - virtual IReGameHookRegistry_CBreakable_Use* CBreakable_Use() = 0; - virtual IReGameHookRegistry_CBreakable_Die* CBreakable_Die() = 0; - virtual IReGameHookRegistry_CBreakable_BreakTouch* CBreakable_BreakTouch() = 0; + virtual IReGameHookRegistry_CBreakable_Spawn *CBreakable_Spawn() = 0; + virtual IReGameHookRegistry_CBreakable_Restart *CBreakable_Restart() = 0; + virtual IReGameHookRegistry_CBreakable_TraceAttack *CBreakable_TraceAttack() = 0; + virtual IReGameHookRegistry_CBreakable_TakeDamage *CBreakable_TakeDamage() = 0; + virtual IReGameHookRegistry_CBreakable_Use *CBreakable_Use() = 0; + virtual IReGameHookRegistry_CBreakable_Die *CBreakable_Die() = 0; + virtual IReGameHookRegistry_CBreakable_BreakTouch *CBreakable_BreakTouch() = 0; }; struct ReGameFuncs_t {