From bffb373539ba534e2e6c417172db1627d7550fc9 Mon Sep 17 00:00:00 2001 From: fl0werD Date: Wed, 27 May 2020 06:56:24 +0400 Subject: [PATCH] implement CGib (#536) * implement CGib Move code part from basemonster.cpp to gib.cpp 3-rd party: Link entity to class (can hookable by HamSandwich amxx module) Add hooks for ReAPI --- gradle.properties | 2 +- regamedll/dlls/API/CAPI_Impl.cpp | 6 +++ regamedll/dlls/API/CAPI_Impl.h | 48 ++++++++++++++++++++- regamedll/dlls/basemonster.cpp | 26 ------------ regamedll/dlls/gib.cpp | 49 ++++++++++++++++++++-- regamedll/dlls/gib.h | 9 +++- regamedll/public/regamedll/regamedll_api.h | 32 ++++++++++++-- 7 files changed, 135 insertions(+), 37 deletions(-) diff --git a/gradle.properties b/gradle.properties index 66a24d06..107964b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ majorVersion=5 -minorVersion=16 +minorVersion=17 maintenanceVersion=0 diff --git a/regamedll/dlls/API/CAPI_Impl.cpp b/regamedll/dlls/API/CAPI_Impl.cpp index 388ae83e..6175dcc0 100644 --- a/regamedll/dlls/API/CAPI_Impl.cpp +++ b/regamedll/dlls/API/CAPI_Impl.cpp @@ -170,6 +170,12 @@ GAMEHOOK_REGISTRY(CBasePlayer_DropIdlePlayer); GAMEHOOK_REGISTRY(CreateWeaponBox); +GAMEHOOK_REGISTRY(SpawnHeadGib); +GAMEHOOK_REGISTRY(SpawnRandomGibs); +GAMEHOOK_REGISTRY(CGib_Spawn); +GAMEHOOK_REGISTRY(CGib_BounceGibTouch); +GAMEHOOK_REGISTRY(CGib_WaitTillLand); + 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 af487627..e33b4e69 100644 --- a/regamedll/dlls/API/CAPI_Impl.h +++ b/regamedll/dlls/API/CAPI_Impl.h @@ -105,6 +105,16 @@ return g_ReGameHookchains.m_##functionName.callChain(functionName##_OrigFunc, __VA_ARGS__);\ } +#define LINK_HOOK_GLOB_CLASS_VOID_CHAIN(className, functionName, args, ...)\ + void className::functionName args {\ + g_ReGameHookchains.m_##functionName.callChain(className::functionName##_OrigFunc, __VA_ARGS__);\ + } + +#define LINK_HOOK_GLOB_CLASS_CHAIN(ret, className, functionName, args, ...)\ + ret className::functionName args {\ + return g_ReGameHookchains.m_##functionName.callChain(className::functionName##_OrigFunc, __VA_ARGS__);\ + } + #define LINK_HOOK_CUSTOM2_CHAIN(ret, customFuncName, functionName, args, ...)\ ret functionName args {\ return g_ReGameHookchains.m_##customFuncName.callChain(functionName##_OrigFunc, __VA_ARGS__);\ @@ -137,6 +147,8 @@ #define LINK_HOOK_VOID_CHAIN2(...) #define LINK_HOOK_CHAIN(...) #define LINK_HOOK_CHAIN2(...) +#define LINK_HOOK_GLOB_CLASS_VOID_CHAIN(...) +#define LINK_HOOK_GLOB_CLASS_CHAIN(...) #endif // REGAMEDLL_API @@ -564,13 +576,33 @@ typedef IHookChainClassImpl CReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload; // CBasePlayer::DropIdlePlayer hook -typedef IHookChainClassImpl CReGameHook_CBasePlayer_DropIdlePlayer; -typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayer_DropIdlePlayer; +typedef IHookChainClassImpl CReGameHook_CBasePlayer_DropIdlePlayer; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayer_DropIdlePlayer; // CreateWeaponBox hook typedef IHookChainImpl CReGameHook_CreateWeaponBox; typedef IHookChainRegistryImpl CReGameHookRegistry_CreateWeaponBox; +// SpawnHeadGib hook +typedef IHookChainImpl CReGameHook_SpawnHeadGib; +typedef IHookChainRegistryImpl CReGameHookRegistry_SpawnHeadGib; + +// SpawnRandomGibs hook +typedef IHookChainImpl CReGameHook_SpawnRandomGibs; +typedef IHookChainRegistryImpl CReGameHookRegistry_SpawnRandomGibs; + +// CGib::Spawn hook +typedef IHookChainClassImpl CReGameHook_CGib_Spawn; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CGib_Spawn; + +// CGib::BounceGibTouch hook +typedef IHookChainClassImpl CReGameHook_CGib_BounceGibTouch; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CGib_BounceGibTouch; + +// CGib::WaitTillLand hook +typedef IHookChainClassImpl CReGameHook_CGib_WaitTillLand; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CGib_WaitTillLand; + class CReGameHookchains: public IReGameHookchains { public: // CBasePlayer virtual @@ -687,6 +719,12 @@ public: CReGameHookRegistry_CBasePlayer_DropIdlePlayer m_CBasePlayer_DropIdlePlayer; CReGameHookRegistry_CreateWeaponBox m_CreateWeaponBox; + CReGameHookRegistry_SpawnHeadGib m_SpawnHeadGib; + CReGameHookRegistry_SpawnRandomGibs m_SpawnRandomGibs; + CReGameHookRegistry_CGib_Spawn m_CGib_Spawn; + CReGameHookRegistry_CGib_BounceGibTouch m_CGib_BounceGibTouch; + CReGameHookRegistry_CGib_WaitTillLand m_CGib_WaitTillLand; + public: virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn(); virtual IReGameHookRegistry_CBasePlayer_Precache *CBasePlayer_Precache(); @@ -800,6 +838,12 @@ public: virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload(); virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer(); virtual IReGameHookRegistry_CreateWeaponBox *CreateWeaponBox(); + + virtual IReGameHookRegistry_SpawnHeadGib *SpawnHeadGib(); + virtual IReGameHookRegistry_SpawnRandomGibs *SpawnRandomGibs(); + virtual IReGameHookRegistry_CGib_Spawn *CGib_Spawn(); + virtual IReGameHookRegistry_CGib_BounceGibTouch *CGib_BounceGibTouch(); + virtual IReGameHookRegistry_CGib_WaitTillLand *CGib_WaitTillLand(); }; extern CReGameHookchains g_ReGameHookchains; diff --git a/regamedll/dlls/basemonster.cpp b/regamedll/dlls/basemonster.cpp index 82ca7bfd..a134d99c 100644 --- a/regamedll/dlls/basemonster.cpp +++ b/regamedll/dlls/basemonster.cpp @@ -368,32 +368,6 @@ void CBaseMonster::Killed(entvars_t *pevAttacker, int iGib) m_IdealMonsterState = MONSTERSTATE_DEAD; } -void CGib::WaitTillLand() -{ - if (!IsInWorld()) - { - UTIL_Remove(this); - return; - } - - if (pev->velocity == g_vecZero) - { - SetThink(&CBaseEntity::SUB_StartFadeOut); - pev->nextthink = gpGlobals->time + m_lifeTime; - -#ifndef REGAMEDLL_FIXES - if (m_bloodColor != DONT_BLEED) - { - CSoundEnt::InsertSound(bits_SOUND_MEAT, pev->origin, 384, 25); - } -#endif - } - else - { - pev->nextthink = gpGlobals->time + 0.5f; - } -} - BOOL CBaseMonster::TakeHealth(float flHealth, int bitsDamageType) { if (pev->takedamage == DAMAGE_NO) diff --git a/regamedll/dlls/gib.cpp b/regamedll/dlls/gib.cpp index 448923e0..5b9122d0 100644 --- a/regamedll/dlls/gib.cpp +++ b/regamedll/dlls/gib.cpp @@ -1,5 +1,7 @@ #include "precompiled.h" +LINK_ENTITY_TO_CLASS(gib, CGib, CCSGib) + void CGib::LimitVelocity() { float length = pev->velocity.Length(); @@ -74,7 +76,9 @@ NOXREF void CGib::SpawnStickyGibs(entvars_t *pevVictim, Vector vecOrigin, int cG } } -void CGib::SpawnHeadGib(entvars_t *pevVictim) +LINK_HOOK_GLOB_CLASS_CHAIN(CGib *, CGib, SpawnHeadGib, (entvars_t *pevVictim), pevVictim) + +CGib *CGib::__API_HOOK(SpawnHeadGib)(entvars_t *pevVictim) { CGib *pGib = GetClassPtr((CGib *)nullptr); @@ -132,9 +136,13 @@ void CGib::SpawnHeadGib(entvars_t *pevVictim) } pGib->LimitVelocity(); + + return pGib; } -void CGib::SpawnRandomGibs(entvars_t *pevVictim, int cGibs, int human) +LINK_HOOK_GLOB_CLASS_VOID_CHAIN(CGib, SpawnRandomGibs, (entvars_t *pevVictim, int cGibs, int human), pevVictim, cGibs, human) + +void CGib::__API_HOOK(SpawnRandomGibs)(entvars_t *pevVictim, int cGibs, int human) { for (int cSplat = 0; cSplat < cGibs; cSplat++) { @@ -198,11 +206,14 @@ void CGib::SpawnRandomGibs(entvars_t *pevVictim, int cGibs, int human) pGib->pev->solid = SOLID_BBOX; UTIL_SetSize(pGib->pev, Vector(0, 0, 0), Vector(0, 0, 0)); } + pGib->LimitVelocity(); } } -void CGib::BounceGibTouch(CBaseEntity *pOther) +LINK_HOOK_CLASS_VOID_CHAIN(CGib, BounceGibTouch, (CBaseEntity *pOther), pOther) + +void CGib::__API_HOOK(BounceGibTouch)(CBaseEntity *pOther) { if (pev->flags & FL_ONGROUND) { @@ -260,7 +271,9 @@ void CGib::StickyGibTouch(CBaseEntity *pOther) pev->movetype = MOVETYPE_NONE; } -void CGib::Spawn(const char *szGibModel) +LINK_HOOK_CLASS_VOID_CHAIN(CGib, Spawn, (const char *szGibModel), szGibModel) + +void CGib::__API_HOOK(Spawn)(const char *szGibModel) { pev->movetype = MOVETYPE_BOUNCE; @@ -292,3 +305,31 @@ void CGib::Spawn(const char *szGibModel) // how many blood decals this gib can place (1 per bounce until none remain). m_cBloodDecals = 5; } + +LINK_HOOK_CLASS_VOID_CHAIN2(CGib, WaitTillLand) + +void CGib::__API_HOOK(WaitTillLand)() +{ + if (!IsInWorld()) + { + UTIL_Remove(this); + return; + } + + if (pev->velocity == g_vecZero) + { + SetThink(&CBaseEntity::SUB_StartFadeOut); + pev->nextthink = gpGlobals->time + m_lifeTime; + +#ifndef REGAMEDLL_FIXES + if (m_bloodColor != DONT_BLEED) + { + CSoundEnt::InsertSound(bits_SOUND_MEAT, pev->origin, 384, 25); + } +#endif + } + else + { + pev->nextthink = gpGlobals->time + 0.5f; + } +} diff --git a/regamedll/dlls/gib.h b/regamedll/dlls/gib.h index 686fad8d..8566bd0b 100644 --- a/regamedll/dlls/gib.h +++ b/regamedll/dlls/gib.h @@ -34,6 +34,10 @@ public: virtual int ObjectCaps() { return (CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_DONT_SAVE; } public: + void Spawn_OrigFunc(const char *szGibModel); + void BounceGibTouch_OrigFunc(CBaseEntity *pOther); + void WaitTillLand_OrigFunc(); + void Spawn(const char *szGibModel); void EXPORT BounceGibTouch(CBaseEntity *pOther); void EXPORT StickyGibTouch(CBaseEntity *pOther); @@ -41,7 +45,10 @@ public: void LimitVelocity(); public: - static void SpawnHeadGib(entvars_t *pevVictim); + static CGib *SpawnHeadGib_OrigFunc(entvars_t *pevVictim); + static void SpawnRandomGibs_OrigFunc(entvars_t *pevVictim, int cGibs, int human); + + static CGib *SpawnHeadGib(entvars_t *pevVictim); static void SpawnRandomGibs(entvars_t *pevVictim, int cGibs, int human); static void SpawnStickyGibs(entvars_t *pevVictim, Vector vecOrigin, int cGibs); diff --git a/regamedll/public/regamedll/regamedll_api.h b/regamedll/public/regamedll/regamedll_api.h index d0c6e8d5..e8c7b9dc 100644 --- a/regamedll/public/regamedll/regamedll_api.h +++ b/regamedll/public/regamedll/regamedll_api.h @@ -38,7 +38,7 @@ #include #define REGAMEDLL_API_VERSION_MAJOR 5 -#define REGAMEDLL_API_VERSION_MINOR 16 +#define REGAMEDLL_API_VERSION_MINOR 17 // CBasePlayer::Spawn hook typedef IHookChainClass IReGameHook_CBasePlayer_Spawn; @@ -461,13 +461,33 @@ typedef IHookChainClass IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload; // CBasePlayer::DropIdlePlayer hook -typedef IHookChainClass IReGameHook_CBasePlayer_DropIdlePlayer; -typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_DropIdlePlayer; +typedef IHookChainClass IReGameHook_CBasePlayer_DropIdlePlayer; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_DropIdlePlayer; // CreateWeaponBox hook typedef IHookChain IReGameHook_CreateWeaponBox; typedef IHookChainRegistry IReGameHookRegistry_CreateWeaponBox; +// SpawnHeadGib hook +typedef IHookChain IReGameHook_SpawnHeadGib; +typedef IHookChainRegistry IReGameHookRegistry_SpawnHeadGib; + +// SpawnRandomGibs hook +typedef IHookChain IReGameHook_SpawnRandomGibs; +typedef IHookChainRegistry IReGameHookRegistry_SpawnRandomGibs; + +// CGib::Spawn hook +typedef IHookChainClass IReGameHook_CGib_Spawn; +typedef IHookChainRegistryClass IReGameHookRegistry_CGib_Spawn; + +// CGib::BounceGibTouch hook +typedef IHookChainClass IReGameHook_CGib_BounceGibTouch; +typedef IHookChainRegistryClass IReGameHookRegistry_CGib_BounceGibTouch; + +// CGib::WaitTillLand hook +typedef IHookChainClass IReGameHook_CGib_WaitTillLand; +typedef IHookChainRegistryClass IReGameHookRegistry_CGib_WaitTillLand; + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -584,6 +604,12 @@ public: virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload() = 0; virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer() = 0; virtual IReGameHookRegistry_CreateWeaponBox *CreateWeaponBox() = 0; + + virtual IReGameHookRegistry_SpawnHeadGib *SpawnHeadGib() = 0; + virtual IReGameHookRegistry_SpawnRandomGibs *SpawnRandomGibs() = 0; + virtual IReGameHookRegistry_CGib_Spawn *CGib_Spawn() = 0; + virtual IReGameHookRegistry_CGib_BounceGibTouch *CGib_BounceGibTouch() = 0; + virtual IReGameHookRegistry_CGib_WaitTillLand *CGib_WaitTillLand() = 0; }; struct ReGameFuncs_t {