Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CGib #164

Merged
merged 4 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
majorVersion=5
minorVersion=13
minorVersion=14
maintenanceVersion=0
8 changes: 5 additions & 3 deletions reapi/extra/amxmodx/scripting/include/reapi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ enum hooks_tables_e
ht_rechecker,
ht_grenade,
ht_weaponbox,
ht_weapon
ht_weapon,
ht_gib
};

enum members_tables_e
Expand Down Expand Up @@ -75,7 +76,8 @@ enum members_tables_e
mt_shield,
mt_rebuystruct,
mt_mapinfo,
mt_csplayerweapon
mt_csplayerweapon,
mt_gib
};

// Is like FNullEnt
Expand Down Expand Up @@ -137,7 +139,7 @@ enum HookChain
*
* @return Returns a hook handle. Use EnableHookChain/DisableHookChain to toggle the forward on or off
*/
native HookChain:RegisterHookChain({EngineFunc, GamedllFunc, GamedllFunc_CBaseAnimating, GamedllFunc_CBasePlayer, GamedllFunc_CSGameRules, GamedllFunc_CGrenade, GamedllFunc_CWeaponBox, ReCheckerFunc, GamedllFunc_CBasePlayerWeapon}:function_id, const callback[], post = 0);
native HookChain:RegisterHookChain({EngineFunc, GamedllFunc, GamedllFunc_CBaseAnimating, GamedllFunc_CBasePlayer, GamedllFunc_CSGameRules, GamedllFunc_CGrenade, GamedllFunc_CWeaponBox, ReCheckerFunc, GamedllFunc_CBasePlayerWeapon, GamedllFunc_CGib}:function_id, const callback[], post = 0);

/*
* Stops a hook from triggering.
Expand Down
75 changes: 75 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,19 @@ enum GamedllFunc
* Params: (Float:vecSrc[3], Float:vecEnd[3], index, entity)
*/
RG_IsPenetrableEntity,

/*
* Description: -
* Return type: CGib * (Entity index of gib)
* Params: (pevVictim)
*/
RG_SpawnHeadGib,

/*
* Description: -
* Params: (int cGibs, int human)
*/
RG_SpawnRandomGibs,
};

/**
Expand Down Expand Up @@ -804,6 +817,30 @@ enum GamedllFunc_CBasePlayerWeapon
RG_CBasePlayerWeapon_DefaultShotgunReload,
};

/**
* GamedllFunc CGib
*/
enum GamedllFunc_CGib
{
/*
* Description: -
* Params: (const this, const szGibModel[])
*/
RG_CGib_Spawn = BEGIN_FUNC_REGION(gib),

/*
* Description: -
* Params: (const this, pOther)
*/
RG_CGib_BounceGibTouch,

/*
* Description: -
* Params: (const this)
*/
RG_CGib_WaitTillLand,
};

/**
* GamedllFunc CSGameRules
*/
Expand Down Expand Up @@ -5903,3 +5940,41 @@ enum CCSPlayerWeapon_Members
*/
m_Weapon_flBaseDamage,
};

/**
* CGib Members
*/
enum CGib_Members
{
/*
* Description: -
* Member type: int
* Get params: get_member(index, member);
* Set params: set_member(index, member, value);
*/
m_Gib_bloodColor = BEGIN_MEMBER_REGION(gib),

/*
* Description: -
* Member type: int
* Get params: get_member(index, member);
* Set params: set_member(index, member, value);
*/
m_Gib_cBloodDecals,

/*
* Description: -
* Member type: int
* Get params: get_member(index, member);
* Set params: set_member(index, member, value);
*/
m_Gib_material,

/*
* Description: -
* Member type: float
* Get params: Float:get_member(index, member);
* Set params: set_member(index, member, Float:value);
*/
m_Gib_lifeTime,
};
41 changes: 41 additions & 0 deletions reapi/include/cssdk/dlls/gib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*
*/

#pragma once

class CGib : public CBaseEntity
{
public:
virtual int ObjectCaps() = 0;

public:
int m_bloodColor;
int m_cBloodDecals;
int m_material;
float m_lifeTime;
};
33 changes: 30 additions & 3 deletions reapi/include/cssdk/dlls/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
#include <cbase.h>
#include <gamerules.h>
#include <client.h>
#include <gib.h>
#include <API/CSInterfaces.h>

#define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 16
#define REGAMEDLL_API_VERSION_MINOR 17

// CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
Expand Down Expand Up @@ -461,13 +462,33 @@ typedef IHookChainClass<bool, class CBasePlayerWeapon, int, int, float, float, c
typedef IHookChainRegistryClass<bool, class CBasePlayerWeapon, int, int, float, float, const char *, const char *> IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload;

// CBasePlayer::DropIdlePlayer hook
typedef IHookChainClass<void, class CBasePlayer, const char *> IReGameHook_CBasePlayer_DropIdlePlayer;
typedef IHookChainRegistryClass<void, class CBasePlayer, const char *> IReGameHookRegistry_CBasePlayer_DropIdlePlayer;
typedef IHookChainClass<void, CBasePlayer, const char *> IReGameHook_CBasePlayer_DropIdlePlayer;
typedef IHookChainRegistryClass<void, CBasePlayer, const char *> IReGameHookRegistry_CBasePlayer_DropIdlePlayer;

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

// SpawnHeadGib hook
typedef IHookChain<class CGib *, entvars_t *> IReGameHook_SpawnHeadGib;
typedef IHookChainRegistry<class CGib *, entvars_t *> IReGameHookRegistry_SpawnHeadGib;

// SpawnRandomGibs hook
typedef IHookChain<void, entvars_t *, int, int> IReGameHook_SpawnRandomGibs;
typedef IHookChainRegistry<void, entvars_t *, int, int> IReGameHookRegistry_SpawnRandomGibs;

// CGib::Spawn hook
typedef IHookChainClass<void, class CGib, const char *> IReGameHook_CGib_Spawn;
typedef IHookChainRegistryClass<void, class CGib, const char *> IReGameHookRegistry_CGib_Spawn;

// CGib::BounceGibTouch hook
typedef IHookChainClass<void, class CGib, CBaseEntity *> IReGameHook_CGib_BounceGibTouch;
typedef IHookChainRegistryClass<void, class CGib, CBaseEntity *> IReGameHookRegistry_CGib_BounceGibTouch;

// CGib::WaitTillLand hook
typedef IHookChainClass<void, class CGib> IReGameHook_CGib_WaitTillLand;
typedef IHookChainRegistryClass<void, class CGib> IReGameHookRegistry_CGib_WaitTillLand;

class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
Expand Down Expand Up @@ -584,6 +605,12 @@ class IReGameHookchains {
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 {
Expand Down
1 change: 1 addition & 0 deletions reapi/msvc/reapi.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<ClInclude Include="..\include\cssdk\dlls\func_break.h" />
<ClInclude Include="..\include\cssdk\dlls\func_tank.h" />
<ClInclude Include="..\include\cssdk\dlls\gamerules.h" />
<ClInclude Include="..\include\cssdk\dlls\gib.h" />
<ClInclude Include="..\include\cssdk\dlls\healthkit.h" />
<ClInclude Include="..\include\cssdk\dlls\hintmessage.h" />
<ClInclude Include="..\include\cssdk\dlls\hookchains.h" />
Expand Down
3 changes: 3 additions & 0 deletions reapi/msvc/reapi.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@
<ClInclude Include="..\include\cssdk\dlls\API\CSPlayerWeapon.h">
<Filter>include\cssdk\dlls\API</Filter>
</ClInclude>
<ClInclude Include="..\include\cssdk\dlls\gib.h">
<Filter>include\cssdk\dlls</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\include\cssdk\common\parsemsg.cpp">
Expand Down
50 changes: 50 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,56 @@ bool IsPenetrableEntity(IReGameHook_IsPenetrableEntity *chain, Vector &vecSrc, V
return callForward<bool>(RG_IsPenetrableEntity, original, getAmxVector(vecSrcCopy), getAmxVector(vecEndCopy), indexOfEdict(pevAttacker), indexOfEdict(pHit));
}

CGib *SpawnHeadGib(IReGameHook_SpawnHeadGib *chain, entvars_t *pevVictim)
{
auto original = [chain](int _pevVictim)
{
return indexOfPDataAmx(chain->callNext(PEV(_pevVictim)));
};

return getPrivate<CGib>(callForward<size_t>(RG_SpawnHeadGib, original, indexOfEdict(pevVictim)));
}

void SpawnRandomGibs(IReGameHook_SpawnRandomGibs *chain, entvars_t *pevVictim, int cGibs, int human)
{
auto original = [chain](int _pevVictim, int _cGibs, int _human)
{
chain->callNext(PEV(_pevVictim), _cGibs, _human);
};

callVoidForward(RG_SpawnRandomGibs, original, indexOfEdict(pevVictim), cGibs, human);
}

void CGib_Spawn(IReGameHook_CGib_Spawn *chain, CGib *pthis, const char *szGibModel)
{
auto original = [chain](int _pthis, const char *_szGibModel)
{
chain->callNext(getPrivate<CGib>(_pthis), _szGibModel);
};

callVoidForward(RG_CGib_Spawn, original, indexOfEdict(pthis->pev), szGibModel);
}

void CGib_BounceGibTouch(IReGameHook_CGib_BounceGibTouch *chain, CGib *pthis, CBaseEntity *pOther)
{
auto original = [chain](int _pthis, int _pOther)
{
chain->callNext(getPrivate<CGib>(_pthis), getPrivate<CBaseEntity>(_pOther));
};

callVoidForward(RG_CGib_BounceGibTouch, original, indexOfEdict(pthis->pev), indexOfEdict(pOther->pev));
}

void CGib_WaitTillLand(IReGameHook_CGib_WaitTillLand *chain, CGib *pthis)
{
auto original = [chain](int _pthis)
{
chain->callNext(getPrivate<CGib>(_pthis));
};

callVoidForward(RG_CGib_WaitTillLand, original, indexOfEdict(pthis->pev));
}

int g_iClientStartSpeak, g_iClientStopSpeak;

void OnClientStartSpeak(size_t clientIndex)
Expand Down
7 changes: 7 additions & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ CGrenade *ThrowFlashbang(IReGameHook_ThrowFlashbang *chain, entvars_t *pevOwner,
CGrenade *ThrowSmokeGrenade(IReGameHook_ThrowSmokeGrenade *chain, entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity, float time, unsigned short usEvent);
CGrenade *PlantBomb(IReGameHook_PlantBomb *chain, entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity);
bool IsPenetrableEntity(IReGameHook_IsPenetrableEntity *chain, Vector &vecSrc, Vector &vecEnd, entvars_t *pevAttacker, edict_t *pHit);
CGib *SpawnHeadGib(IReGameHook_SpawnHeadGib *chain, entvars_t *pevVictim);
void SpawnRandomGibs(IReGameHook_SpawnRandomGibs *chain, entvars_t *pevVictim, int cGibs, int human);

// regamedll functions - player
void CBasePlayer_Spawn(IReGameHook_CBasePlayer_Spawn *chain, CBasePlayer *pthis);
Expand Down Expand Up @@ -432,6 +434,11 @@ void CGrenade_ExplodeFlashbang(IReGameHook_CGrenade_ExplodeFlashbang *chain, CGr
void CGrenade_ExplodeSmokeGrenade(IReGameHook_CGrenade_ExplodeSmokeGrenade *chain, CGrenade *pthis);
void CGrenade_ExplodeBomb(IReGameHook_CGrenade_ExplodeBomb *chain, CGrenade *pthis, TraceResult *ptr, int bitsDamageType);

// regamedll functions - gib
void CGib_Spawn(IReGameHook_CGib_Spawn *chain, CGib *pthis, const char *szGibModel);
void CGib_BounceGibTouch(IReGameHook_CGib_BounceGibTouch *chain, CGib *pthis, CBaseEntity *pOther);
void CGib_WaitTillLand(IReGameHook_CGib_WaitTillLand *chain, CGib *pthis);

extern int g_iClientStartSpeak;
extern int g_iClientStopSpeak;

Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ hook_t hooklist_gamedll[] = {
DLL(ThrowSmokeGrenade),
DLL(PlantBomb),
DLL(IsPenetrableEntity),
DLL(SpawnHeadGib),
DLL(SpawnRandomGibs),
};

hook_t hooklist_animating[] = {
Expand Down Expand Up @@ -205,6 +207,12 @@ hook_t hooklist_weapon[] = {
DLL(CBasePlayerWeapon_DefaultShotgunReload),
};

hook_t hooklist_gib[] = {
DLL(CGib_Spawn),
DLL(CGib_BounceGibTouch),
DLL(CGib_WaitTillLand),
};

#define RCHECK(h,...) { {}, {}, #h, "ReChecker", [](){ return api_cfg.hasRechecker(); }, ((!(RC_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RC_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_RecheckerHookchains->h()->registerHook(&h); }, [](){ g_RecheckerHookchains->h()->unregisterHook(&h); }}
hook_t hooklist_rechecker[] = {
RCHECK(FileConsistencyProcess, _AMXX),
Expand All @@ -229,6 +237,7 @@ hook_t* hooklist_t::getHookSafe(size_t hook)
CASE(grenade)
CASE(weaponbox)
CASE(weapon)
CASE(gib)
}

return nullptr;
Expand All @@ -247,6 +256,7 @@ void hooklist_t::clear()
FOREACH_CLEAR(grenade);
FOREACH_CLEAR(weaponbox);
FOREACH_CLEAR(weapon);
FOREACH_CLEAR(gib);
}

void hook_t::clear()
Expand Down
Loading