Skip to content

Commit

Permalink
Add hookchain and getter/setter for spawn protection
Browse files Browse the repository at this point in the history
Add hookchain for IsPenetrableEntity
  • Loading branch information
fl0werD authored and theAsmodai committed Apr 11, 2018
1 parent b0026f3 commit 8996519
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 4 deletions.
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=5
minorVersion=6
maintenanceVersion=0
31 changes: 30 additions & 1 deletion reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,14 @@ enum GamedllFunc
* Return type: CGrenade * (Entity index of bomb)
* Params: (const index, Float:vecStart[3], Float:vecVelocity[3])
*/
RG_PlantBomb
RG_PlantBomb,

/*
* Description: Called when a player hit to entity.
* Return type: bool
* Params: (Float:vecSrc[3], Float:vecEnd[3], index, entity)
*/
RG_IsPenetrableEntity,
};

/**
Expand Down Expand Up @@ -724,6 +731,20 @@ enum GamedllFunc_CBasePlayer
* Params: (const this, const grenade, Float:vecSrc[3], Float:vecThrow[3], Float:time, const usEvent)
*/
RG_CBasePlayer_ThrowGrenade,

/*
* Description: Called when a player's set protection.
* Return type: void
* Params: (const this, Float:time)
*/
RG_CBasePlayer_SetSpawnProtection,

/*
* Description: Called when a player's remove protection.
* Return type: void
* Params: (const this)
*/
RG_CBasePlayer_RemoveSpawnProtection,
};

/**
Expand Down Expand Up @@ -4371,6 +4392,14 @@ enum CCSPlayer_Members
* Set params: set_member(index, member, Float:value);
*/
m_flRespawnPending,

/*
* Description: -
* Member type: float
* Get params: Float:get_member(index, member);
* Set params: set_member(index, member, Float:value);
*/
m_flSpawnProtectionEndTime,
};

/**
Expand Down
5 changes: 4 additions & 1 deletion reapi/include/cssdk/dlls/API/CSPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class CCSPlayer: public CCSMonster {
public:
CCSPlayer() : m_bForceShowMenu(false), m_flRespawnPending(0)
CCSPlayer() : m_bForceShowMenu(false), m_flRespawnPending(0), m_flSpawnProtectionEndTime(0)
{
m_szModel[0] = '\0';
}
Expand Down Expand Up @@ -80,13 +80,16 @@ class CCSPlayer: public CCSMonster {
virtual void ResetSequenceInfo();
virtual void StartDeathCam();
virtual bool RemovePlayerItemEx(const char* pszItemName, bool bRemoveAmmo);
virtual void SetSpawnProtection(float flProtectionTime);
virtual void RemoveSpawnProtection();

CBasePlayer *BasePlayer() const;

public:
char m_szModel[32];
bool m_bForceShowMenu;
float m_flRespawnPending;
float m_flSpawnProtectionEndTime;
};

// Inlines
Expand Down
32 changes: 32 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,26 @@ CGrenade *CBasePlayer_ThrowGrenade(IReGameHook_CBasePlayer_ThrowGrenade *chain,
return getPrivate<CGrenade>(callForward<size_t>(RG_CBasePlayer_ThrowGrenade, original, indexOfEdict(pthis->pev), indexOfEdict(pWeapon->pev), getAmxVector(vecSrcCopy), getAmxVector(vecThrowCopy), time, usEvent));
}

void CBasePlayer_SetSpawnProtection(IReGameHook_CBasePlayer_SetSpawnProtection *chain, CBasePlayer *pthis, float flProtectionTime)
{
auto original = [chain](int _pthis, float _flProtectionTime)
{
return chain->callNext(getPrivate<CBasePlayer>(_pthis), _flProtectionTime);
};

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

void CBasePlayer_RemoveSpawnProtection(IReGameHook_CBasePlayer_RemoveSpawnProtection *chain, CBasePlayer *pthis)
{
auto original = [chain](int _pthis)
{
return chain->callNext(getPrivate<CBasePlayer>(_pthis));
};

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

void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis)
{
auto original = [chain](int _pthis)
Expand Down Expand Up @@ -1004,6 +1024,18 @@ CGrenade *PlantBomb(IReGameHook_PlantBomb *chain, entvars_t *pevOwner, Vector &v
return getPrivate<CGrenade>(callForward<size_t>(RG_PlantBomb, original, indexOfEdict(pevOwner), getAmxVector(vecStartCopy), getAmxVector(vecVelocityCopy)));
}

bool IsPenetrableEntity(IReGameHook_IsPenetrableEntity *chain, Vector &vecSrc, Vector &vecEnd, entvars_t *pevAttacker, edict_t *pHit)
{
Vector vecSrcCopy(vecSrc), vecEndCopy(vecEnd);

auto original = [chain, &vecSrcCopy, &vecEndCopy](cell _vecSrc, cell _vecEnd, int _pevAttacker, int _pHit)
{
return chain->callNext(vecSrcCopy, vecEndCopy, PEV(_pevAttacker), edictByIndexAmx(_pHit));
};

return callForward<bool>(RG_IsPenetrableEntity, original, getAmxVector(vecSrcCopy), getAmxVector(vecEndCopy), indexOfEdict(pevAttacker), indexOfEdict(pHit));
}

int g_iClientStartSpeak, g_iClientStopSpeak;

void OnClientStartSpeak(size_t clientIndex)
Expand Down
3 changes: 3 additions & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ CGrenade *ThrowHeGrenade(IReGameHook_ThrowHeGrenade *chain, entvars_t *pevOwner,
CGrenade *ThrowFlashbang(IReGameHook_ThrowFlashbang *chain, entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity, float time);
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);

// regamedll functions - player
void CBasePlayer_Spawn(IReGameHook_CBasePlayer_Spawn *chain, CBasePlayer *pthis);
Expand Down Expand Up @@ -377,6 +378,8 @@ void CBasePlayer_StartDeathCam(IReGameHook_CBasePlayer_StartDeathCam *chain, CBa
void CBasePlayer_SwitchTeam(IReGameHook_CBasePlayer_SwitchTeam *chain, CBasePlayer *pthis);
bool CBasePlayer_CanSwitchTeam(IReGameHook_CBasePlayer_CanSwitchTeam *chain, CBasePlayer *pthis, TeamName teamToSwap);
CGrenade *CBasePlayer_ThrowGrenade(IReGameHook_CBasePlayer_ThrowGrenade *chain, CBasePlayer *pthis, CBasePlayerWeapon *pWeapon, Vector &vecSrc, Vector &vecThrow, float time, unsigned short usEvent);
void CBasePlayer_SetSpawnProtection(IReGameHook_CBasePlayer_SetSpawnProtection *chain, CBasePlayer *pthis, float flProtectionTime);
void CBasePlayer_RemoveSpawnProtection(IReGameHook_CBasePlayer_RemoveSpawnProtection *chain, CBasePlayer *pthis);

void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis);

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

hook_t hooklist_animating[] = {
Expand Down Expand Up @@ -150,6 +151,8 @@ hook_t hooklist_player[] = {
DLL(CBasePlayer_SwitchTeam),
DLL(CBasePlayer_CanSwitchTeam),
DLL(CBasePlayer_ThrowGrenade),
DLL(CBasePlayer_SetSpawnProtection),
DLL(CBasePlayer_RemoveSpawnProtection),
};

hook_t hooklist_gamerules[] = {
Expand Down
5 changes: 4 additions & 1 deletion reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ enum GamedllFunc
RG_ThrowHeGrenade,
RG_ThrowFlashbang,
RG_ThrowSmokeGrenade,
RG_PlantBomb
RG_PlantBomb,
RG_IsPenetrableEntity,

// [...]
};
Expand Down Expand Up @@ -172,6 +173,8 @@ enum GamedllFunc_CBasePlayer
RG_CBasePlayer_SwitchTeam,
RG_CBasePlayer_CanSwitchTeam,
RG_CBasePlayer_ThrowGrenade,
RG_CBasePlayer_SetSpawnProtection,
RG_CBasePlayer_RemoveSpawnProtection,

// [...]
};
Expand Down
1 change: 1 addition & 0 deletions reapi/src/member_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ member_t memberlist_csplayer[] = {
CSPL_MEMBERS(m_szModel),
CSPL_MEMBERS(m_bForceShowMenu),
CSPL_MEMBERS(m_flRespawnPending),
CSPL_MEMBERS(m_flSpawnProtectionEndTime),
};

member_t memberlist_baseitem[] = {
Expand Down
1 change: 1 addition & 0 deletions reapi/src/member_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ enum CSPlayer_Members
m_szModel = BEGIN_MEMBER_REGION(csplayer),
m_bForceShowMenu,
m_flRespawnPending,
m_flSpawnProtectionEndTime,
};

enum CBasePlayerItem_Members
Expand Down

0 comments on commit 8996519

Please sign in to comment.