Skip to content

Commit bffb373

Browse files
authored
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
1 parent 27c15c3 commit bffb373

File tree

7 files changed

+135
-37
lines changed

7 files changed

+135
-37
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
majorVersion=5
2-
minorVersion=16
2+
minorVersion=17
33
maintenanceVersion=0

regamedll/dlls/API/CAPI_Impl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ GAMEHOOK_REGISTRY(CBasePlayer_DropIdlePlayer);
170170

171171
GAMEHOOK_REGISTRY(CreateWeaponBox);
172172

173+
GAMEHOOK_REGISTRY(SpawnHeadGib);
174+
GAMEHOOK_REGISTRY(SpawnRandomGibs);
175+
GAMEHOOK_REGISTRY(CGib_Spawn);
176+
GAMEHOOK_REGISTRY(CGib_BounceGibTouch);
177+
GAMEHOOK_REGISTRY(CGib_WaitTillLand);
178+
173179
int CReGameApi::GetMajorVersion() {
174180
return REGAMEDLL_API_VERSION_MAJOR;
175181
}

regamedll/dlls/API/CAPI_Impl.h

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@
105105
return g_ReGameHookchains.m_##functionName.callChain(functionName##_OrigFunc, __VA_ARGS__);\
106106
}
107107

108+
#define LINK_HOOK_GLOB_CLASS_VOID_CHAIN(className, functionName, args, ...)\
109+
void className::functionName args {\
110+
g_ReGameHookchains.m_##functionName.callChain(className::functionName##_OrigFunc, __VA_ARGS__);\
111+
}
112+
113+
#define LINK_HOOK_GLOB_CLASS_CHAIN(ret, className, functionName, args, ...)\
114+
ret className::functionName args {\
115+
return g_ReGameHookchains.m_##functionName.callChain(className::functionName##_OrigFunc, __VA_ARGS__);\
116+
}
117+
108118
#define LINK_HOOK_CUSTOM2_CHAIN(ret, customFuncName, functionName, args, ...)\
109119
ret functionName args {\
110120
return g_ReGameHookchains.m_##customFuncName.callChain(functionName##_OrigFunc, __VA_ARGS__);\
@@ -137,6 +147,8 @@
137147
#define LINK_HOOK_VOID_CHAIN2(...)
138148
#define LINK_HOOK_CHAIN(...)
139149
#define LINK_HOOK_CHAIN2(...)
150+
#define LINK_HOOK_GLOB_CLASS_VOID_CHAIN(...)
151+
#define LINK_HOOK_GLOB_CLASS_CHAIN(...)
140152

141153
#endif // REGAMEDLL_API
142154

@@ -564,13 +576,33 @@ typedef IHookChainClassImpl<bool, CBasePlayerWeapon, int, int, float, float, con
564576
typedef IHookChainRegistryClassImpl<bool, CBasePlayerWeapon, int, int, float, float, const char *, const char *> CReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload;
565577

566578
// CBasePlayer::DropIdlePlayer hook
567-
typedef IHookChainClassImpl<void, CBasePlayer, const char *> CReGameHook_CBasePlayer_DropIdlePlayer;
568-
typedef IHookChainRegistryClassImpl<void, CBasePlayer, const char *> CReGameHookRegistry_CBasePlayer_DropIdlePlayer;
579+
typedef IHookChainClassImpl<void, class CBasePlayer, const char *> CReGameHook_CBasePlayer_DropIdlePlayer;
580+
typedef IHookChainRegistryClassImpl<void, class CBasePlayer, const char *> CReGameHookRegistry_CBasePlayer_DropIdlePlayer;
569581

570582
// CreateWeaponBox hook
571583
typedef IHookChainImpl<CWeaponBox *, CBasePlayerItem *, CBasePlayer *, const char *, Vector &, Vector &, Vector &, float, bool> CReGameHook_CreateWeaponBox;
572584
typedef IHookChainRegistryImpl<CWeaponBox *, CBasePlayerItem *, CBasePlayer *, const char *, Vector &, Vector &, Vector &, float, bool> CReGameHookRegistry_CreateWeaponBox;
573585

586+
// SpawnHeadGib hook
587+
typedef IHookChainImpl<class CGib *, entvars_t *> CReGameHook_SpawnHeadGib;
588+
typedef IHookChainRegistryImpl<class CGib *, entvars_t *> CReGameHookRegistry_SpawnHeadGib;
589+
590+
// SpawnRandomGibs hook
591+
typedef IHookChainImpl<void, entvars_t *, int, int> CReGameHook_SpawnRandomGibs;
592+
typedef IHookChainRegistryImpl<void, entvars_t *, int, int> CReGameHookRegistry_SpawnRandomGibs;
593+
594+
// CGib::Spawn hook
595+
typedef IHookChainClassImpl<void, class CGib, const char *> CReGameHook_CGib_Spawn;
596+
typedef IHookChainRegistryClassImpl<void, class CGib, const char *> CReGameHookRegistry_CGib_Spawn;
597+
598+
// CGib::BounceGibTouch hook
599+
typedef IHookChainClassImpl<void, class CGib, CBaseEntity *> CReGameHook_CGib_BounceGibTouch;
600+
typedef IHookChainRegistryClassImpl<void, class CGib, CBaseEntity *> CReGameHookRegistry_CGib_BounceGibTouch;
601+
602+
// CGib::WaitTillLand hook
603+
typedef IHookChainClassImpl<void, class CGib> CReGameHook_CGib_WaitTillLand;
604+
typedef IHookChainRegistryClassImpl<void, class CGib> CReGameHookRegistry_CGib_WaitTillLand;
605+
574606
class CReGameHookchains: public IReGameHookchains {
575607
public:
576608
// CBasePlayer virtual
@@ -687,6 +719,12 @@ class CReGameHookchains: public IReGameHookchains {
687719
CReGameHookRegistry_CBasePlayer_DropIdlePlayer m_CBasePlayer_DropIdlePlayer;
688720
CReGameHookRegistry_CreateWeaponBox m_CreateWeaponBox;
689721

722+
CReGameHookRegistry_SpawnHeadGib m_SpawnHeadGib;
723+
CReGameHookRegistry_SpawnRandomGibs m_SpawnRandomGibs;
724+
CReGameHookRegistry_CGib_Spawn m_CGib_Spawn;
725+
CReGameHookRegistry_CGib_BounceGibTouch m_CGib_BounceGibTouch;
726+
CReGameHookRegistry_CGib_WaitTillLand m_CGib_WaitTillLand;
727+
690728
public:
691729
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
692730
virtual IReGameHookRegistry_CBasePlayer_Precache *CBasePlayer_Precache();
@@ -800,6 +838,12 @@ class CReGameHookchains: public IReGameHookchains {
800838
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload();
801839
virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer();
802840
virtual IReGameHookRegistry_CreateWeaponBox *CreateWeaponBox();
841+
842+
virtual IReGameHookRegistry_SpawnHeadGib *SpawnHeadGib();
843+
virtual IReGameHookRegistry_SpawnRandomGibs *SpawnRandomGibs();
844+
virtual IReGameHookRegistry_CGib_Spawn *CGib_Spawn();
845+
virtual IReGameHookRegistry_CGib_BounceGibTouch *CGib_BounceGibTouch();
846+
virtual IReGameHookRegistry_CGib_WaitTillLand *CGib_WaitTillLand();
803847
};
804848

805849
extern CReGameHookchains g_ReGameHookchains;

regamedll/dlls/basemonster.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -368,32 +368,6 @@ void CBaseMonster::Killed(entvars_t *pevAttacker, int iGib)
368368
m_IdealMonsterState = MONSTERSTATE_DEAD;
369369
}
370370

371-
void CGib::WaitTillLand()
372-
{
373-
if (!IsInWorld())
374-
{
375-
UTIL_Remove(this);
376-
return;
377-
}
378-
379-
if (pev->velocity == g_vecZero)
380-
{
381-
SetThink(&CBaseEntity::SUB_StartFadeOut);
382-
pev->nextthink = gpGlobals->time + m_lifeTime;
383-
384-
#ifndef REGAMEDLL_FIXES
385-
if (m_bloodColor != DONT_BLEED)
386-
{
387-
CSoundEnt::InsertSound(bits_SOUND_MEAT, pev->origin, 384, 25);
388-
}
389-
#endif
390-
}
391-
else
392-
{
393-
pev->nextthink = gpGlobals->time + 0.5f;
394-
}
395-
}
396-
397371
BOOL CBaseMonster::TakeHealth(float flHealth, int bitsDamageType)
398372
{
399373
if (pev->takedamage == DAMAGE_NO)

regamedll/dlls/gib.cpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "precompiled.h"
22

3+
LINK_ENTITY_TO_CLASS(gib, CGib, CCSGib)
4+
35
void CGib::LimitVelocity()
46
{
57
float length = pev->velocity.Length();
@@ -74,7 +76,9 @@ NOXREF void CGib::SpawnStickyGibs(entvars_t *pevVictim, Vector vecOrigin, int cG
7476
}
7577
}
7678

77-
void CGib::SpawnHeadGib(entvars_t *pevVictim)
79+
LINK_HOOK_GLOB_CLASS_CHAIN(CGib *, CGib, SpawnHeadGib, (entvars_t *pevVictim), pevVictim)
80+
81+
CGib *CGib::__API_HOOK(SpawnHeadGib)(entvars_t *pevVictim)
7882
{
7983
CGib *pGib = GetClassPtr<CCSGib>((CGib *)nullptr);
8084

@@ -132,9 +136,13 @@ void CGib::SpawnHeadGib(entvars_t *pevVictim)
132136
}
133137

134138
pGib->LimitVelocity();
139+
140+
return pGib;
135141
}
136142

137-
void CGib::SpawnRandomGibs(entvars_t *pevVictim, int cGibs, int human)
143+
LINK_HOOK_GLOB_CLASS_VOID_CHAIN(CGib, SpawnRandomGibs, (entvars_t *pevVictim, int cGibs, int human), pevVictim, cGibs, human)
144+
145+
void CGib::__API_HOOK(SpawnRandomGibs)(entvars_t *pevVictim, int cGibs, int human)
138146
{
139147
for (int cSplat = 0; cSplat < cGibs; cSplat++)
140148
{
@@ -198,11 +206,14 @@ void CGib::SpawnRandomGibs(entvars_t *pevVictim, int cGibs, int human)
198206
pGib->pev->solid = SOLID_BBOX;
199207
UTIL_SetSize(pGib->pev, Vector(0, 0, 0), Vector(0, 0, 0));
200208
}
209+
201210
pGib->LimitVelocity();
202211
}
203212
}
204213

205-
void CGib::BounceGibTouch(CBaseEntity *pOther)
214+
LINK_HOOK_CLASS_VOID_CHAIN(CGib, BounceGibTouch, (CBaseEntity *pOther), pOther)
215+
216+
void CGib::__API_HOOK(BounceGibTouch)(CBaseEntity *pOther)
206217
{
207218
if (pev->flags & FL_ONGROUND)
208219
{
@@ -260,7 +271,9 @@ void CGib::StickyGibTouch(CBaseEntity *pOther)
260271
pev->movetype = MOVETYPE_NONE;
261272
}
262273

263-
void CGib::Spawn(const char *szGibModel)
274+
LINK_HOOK_CLASS_VOID_CHAIN(CGib, Spawn, (const char *szGibModel), szGibModel)
275+
276+
void CGib::__API_HOOK(Spawn)(const char *szGibModel)
264277
{
265278
pev->movetype = MOVETYPE_BOUNCE;
266279

@@ -292,3 +305,31 @@ void CGib::Spawn(const char *szGibModel)
292305
// how many blood decals this gib can place (1 per bounce until none remain).
293306
m_cBloodDecals = 5;
294307
}
308+
309+
LINK_HOOK_CLASS_VOID_CHAIN2(CGib, WaitTillLand)
310+
311+
void CGib::__API_HOOK(WaitTillLand)()
312+
{
313+
if (!IsInWorld())
314+
{
315+
UTIL_Remove(this);
316+
return;
317+
}
318+
319+
if (pev->velocity == g_vecZero)
320+
{
321+
SetThink(&CBaseEntity::SUB_StartFadeOut);
322+
pev->nextthink = gpGlobals->time + m_lifeTime;
323+
324+
#ifndef REGAMEDLL_FIXES
325+
if (m_bloodColor != DONT_BLEED)
326+
{
327+
CSoundEnt::InsertSound(bits_SOUND_MEAT, pev->origin, 384, 25);
328+
}
329+
#endif
330+
}
331+
else
332+
{
333+
pev->nextthink = gpGlobals->time + 0.5f;
334+
}
335+
}

regamedll/dlls/gib.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@ class CGib: public CBaseEntity
3434
virtual int ObjectCaps() { return (CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_DONT_SAVE; }
3535

3636
public:
37+
void Spawn_OrigFunc(const char *szGibModel);
38+
void BounceGibTouch_OrigFunc(CBaseEntity *pOther);
39+
void WaitTillLand_OrigFunc();
40+
3741
void Spawn(const char *szGibModel);
3842
void EXPORT BounceGibTouch(CBaseEntity *pOther);
3943
void EXPORT StickyGibTouch(CBaseEntity *pOther);
4044
void EXPORT WaitTillLand();
4145
void LimitVelocity();
4246

4347
public:
44-
static void SpawnHeadGib(entvars_t *pevVictim);
48+
static CGib *SpawnHeadGib_OrigFunc(entvars_t *pevVictim);
49+
static void SpawnRandomGibs_OrigFunc(entvars_t *pevVictim, int cGibs, int human);
50+
51+
static CGib *SpawnHeadGib(entvars_t *pevVictim);
4552
static void SpawnRandomGibs(entvars_t *pevVictim, int cGibs, int human);
4653
static void SpawnStickyGibs(entvars_t *pevVictim, Vector vecOrigin, int cGibs);
4754

regamedll/public/regamedll/regamedll_api.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <API/CSInterfaces.h>
3939

4040
#define REGAMEDLL_API_VERSION_MAJOR 5
41-
#define REGAMEDLL_API_VERSION_MINOR 16
41+
#define REGAMEDLL_API_VERSION_MINOR 17
4242

4343
// CBasePlayer::Spawn hook
4444
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
@@ -461,13 +461,33 @@ typedef IHookChainClass<bool, class CBasePlayerWeapon, int, int, float, float, c
461461
typedef IHookChainRegistryClass<bool, class CBasePlayerWeapon, int, int, float, float, const char *, const char *> IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload;
462462

463463
// CBasePlayer::DropIdlePlayer hook
464-
typedef IHookChainClass<void, CBasePlayer, const char *> IReGameHook_CBasePlayer_DropIdlePlayer;
465-
typedef IHookChainRegistryClass<void, CBasePlayer, const char *> IReGameHookRegistry_CBasePlayer_DropIdlePlayer;
464+
typedef IHookChainClass<void, class CBasePlayer, const char *> IReGameHook_CBasePlayer_DropIdlePlayer;
465+
typedef IHookChainRegistryClass<void, class CBasePlayer, const char *> IReGameHookRegistry_CBasePlayer_DropIdlePlayer;
466466

467467
// CreateWeaponBox hook
468468
typedef IHookChain<class CWeaponBox *, class CBasePlayerItem *, class CBasePlayer *, const char *, Vector &, Vector &, Vector &, float, bool> IReGameHook_CreateWeaponBox;
469469
typedef IHookChainRegistry<class CWeaponBox *, class CBasePlayerItem *, class CBasePlayer *, const char *, Vector &, Vector &, Vector &, float, bool> IReGameHookRegistry_CreateWeaponBox;
470470

471+
// SpawnHeadGib hook
472+
typedef IHookChain<class CGib *, entvars_t *> IReGameHook_SpawnHeadGib;
473+
typedef IHookChainRegistry<class CGib *, entvars_t *> IReGameHookRegistry_SpawnHeadGib;
474+
475+
// SpawnRandomGibs hook
476+
typedef IHookChain<void, entvars_t *, int, int> IReGameHook_SpawnRandomGibs;
477+
typedef IHookChainRegistry<void, entvars_t *, int, int> IReGameHookRegistry_SpawnRandomGibs;
478+
479+
// CGib::Spawn hook
480+
typedef IHookChainClass<void, class CGib, const char *> IReGameHook_CGib_Spawn;
481+
typedef IHookChainRegistryClass<void, class CGib, const char *> IReGameHookRegistry_CGib_Spawn;
482+
483+
// CGib::BounceGibTouch hook
484+
typedef IHookChainClass<void, class CGib, CBaseEntity *> IReGameHook_CGib_BounceGibTouch;
485+
typedef IHookChainRegistryClass<void, class CGib, CBaseEntity *> IReGameHookRegistry_CGib_BounceGibTouch;
486+
487+
// CGib::WaitTillLand hook
488+
typedef IHookChainClass<void, class CGib> IReGameHook_CGib_WaitTillLand;
489+
typedef IHookChainRegistryClass<void, class CGib> IReGameHookRegistry_CGib_WaitTillLand;
490+
471491
class IReGameHookchains {
472492
public:
473493
virtual ~IReGameHookchains() {}
@@ -584,6 +604,12 @@ class IReGameHookchains {
584604
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload() = 0;
585605
virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer() = 0;
586606
virtual IReGameHookRegistry_CreateWeaponBox *CreateWeaponBox() = 0;
607+
608+
virtual IReGameHookRegistry_SpawnHeadGib *SpawnHeadGib() = 0;
609+
virtual IReGameHookRegistry_SpawnRandomGibs *SpawnRandomGibs() = 0;
610+
virtual IReGameHookRegistry_CGib_Spawn *CGib_Spawn() = 0;
611+
virtual IReGameHookRegistry_CGib_BounceGibTouch *CGib_BounceGibTouch() = 0;
612+
virtual IReGameHookRegistry_CGib_WaitTillLand *CGib_WaitTillLand() = 0;
587613
};
588614

589615
struct ReGameFuncs_t {

0 commit comments

Comments
 (0)