Skip to content

Commit

Permalink
Implemented hook CBasePlayer::HintMessageEx. Closes #133
Browse files Browse the repository at this point in the history
Add native rg_hint_message
Add news CBasePlayer members
Bump minor version API
  • Loading branch information
s1lentq committed Jun 5, 2019
1 parent 4834b7a commit 0eed4cd
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 7 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=8
minorVersion=9
maintenanceVersion=0
13 changes: 13 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,16 @@ native rg_set_iteminfo(const entity, ItemInfo:type, any:...);
*
*/
native rg_get_iteminfo(const ent, ItemInfo:type, any:...);

/*
* Adds hint message to the queue.
*
* @param index Client index
* @param message The message hint
* @param duration The time duration in seconds stays on screen
* @param bDisplayIfPlayerDead Whether to print hint for dead players?
* @param bOverride Whether to override previous messages?
*
* @return true if prints, false otherwise
*/
native bool:rg_hint_message(const index, const message[], Float:duration = 6.0, bool:bDisplayIfPlayerDead = false, bool:bOverride = false);
39 changes: 35 additions & 4 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ enum GamedllFunc
* Params: (const index, Float:vecStart[3], Float:vecVelocity[3])
*/
RG_PlantBomb,

/*
* Description: Called when a player hit to entity.
* Return type: bool
Expand Down Expand Up @@ -733,20 +733,27 @@ 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,

/*
* Description: Called when the game prints hint message into DHUD.
* Return type: bool
* Params: (const this, const message[], Float:duration, bool:bDisplayIfPlayerDead, bool:bOverride)
*/
RG_CBasePlayer_HintMessageEx,
};

/**
Expand Down Expand Up @@ -3499,7 +3506,31 @@ enum CBasePlayer_Members
* Get params: Float:get_member(index, member, element);
* Set params: set_member(index, member, Float:value, element);
*/
m_flLastCommandTime
m_flLastCommandTime,

/*
* Description: The amount of money sent to the client last time.
* Member type: int
* Get params: get_member(index, member);
* Set params: set_member(index, member, value);
*/
m_iLastAccount,

/*
* Description: The amount of health sent to the client last time.
* Member type: int
* Get params: get_member(index, member);
* Set params: set_member(index, member, Float:value);
*/
m_iLastClientHealth,

/*
* Description: Waiting time for update fields into scoreboard.
* Member type: float
* Get params: Float:get_member(index, member);
* Set params: set_member(index, member, Float:value);
*/
m_tmNextAccountHealthUpdate,
};

/**
Expand Down
4 changes: 4 additions & 0 deletions reapi/include/cssdk/dlls/API/CSInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,8 @@ class CCSTriggerCamera: public CCSDelay {};
class CCSWeather: public CCSTrigger {};
class CCSClientFog: public CCSEntity {};
class CCSTriggerSetOrigin: public CCSDelay {};
class CCSTriggerRandom: public CCSDelay {};
class CCSItemAirBox: public CCSArmoury {};
class CCSPointBaseCommand: public CCSPointEntity {};
class CCSPointClientCommand: public CCSPointBaseCommand {};
class CCSPointServerCommand: public CCSPointBaseCommand {};
25 changes: 25 additions & 0 deletions reapi/include/cssdk/dlls/API/CSPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,20 @@ class CCSPlayer: public CCSMonster {
virtual bool RemovePlayerItemEx(const char* pszItemName, bool bRemoveAmmo);
virtual void SetSpawnProtection(float flProtectionTime);
virtual void RemoveSpawnProtection();
virtual bool HintMessageEx(const char *pMessage, float duration = 6.0f, bool bDisplayIfPlayerDead = false, bool bOverride = false);

CBasePlayer *BasePlayer() const;

public:
enum EProtectionState
{
ProtectionSt_NoSet,
ProtectionSt_Active,
ProtectionSt_Expired,
};

EProtectionState GetProtectionState() const;

public:
char m_szModel[32];
bool m_bForceShowMenu;
Expand All @@ -97,3 +108,17 @@ inline CBasePlayer *CCSPlayer::BasePlayer() const
{
return reinterpret_cast<CBasePlayer *>(this->m_pContainingEntity);
}

inline CCSPlayer::EProtectionState CCSPlayer::GetProtectionState() const
{
// no protection set
if (m_flSpawnProtectionEndTime <= 0.0f)
return ProtectionSt_NoSet;

// check if end time of protection isn't expired yet
if (m_flSpawnProtectionEndTime >= gpGlobals->time)
return ProtectionSt_Active;

// has expired
return ProtectionSt_Expired;
}
3 changes: 3 additions & 0 deletions reapi/include/cssdk/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ class CBasePlayer: public CBaseMonster {
float m_silentTimestamp;
MusicState m_musicState;
float m_flLastCommandTime[COMMANDS_TO_TRACK];
int m_iLastAccount;
int m_iLastClientHealth;
float m_tmNextAccountHealthUpdate;
};

class CWShield: public CBaseEntity {
Expand Down
7 changes: 6 additions & 1 deletion reapi/include/cssdk/dlls/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <API/CSInterfaces.h>

#define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 8
#define REGAMEDLL_API_VERSION_MINOR 9

// CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
Expand Down Expand Up @@ -436,6 +436,10 @@ typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBa
typedef IHookChain<bool, Vector &, Vector &, entvars_t *, edict_t *> IReGameHook_IsPenetrableEntity;
typedef IHookChainRegistry<bool, Vector &, Vector &, entvars_t *, edict_t *> IReGameHookRegistry_IsPenetrableEntity;

// CBasePlayer::HintMessageEx hook
typedef IHookChainClass<bool, class CBasePlayer, const char *, float, bool, bool> IReGameHook_CBasePlayer_HintMessageEx;
typedef IHookChainRegistryClass<bool, class CBasePlayer, const char *, float, bool, bool> IReGameHookRegistry_CBasePlayer_HintMessageEx;

class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
Expand Down Expand Up @@ -544,6 +548,7 @@ class IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_RemoveSpawnProtection *CBasePlayer_RemoveSpawnProtection() = 0;
virtual IReGameHookRegistry_CBasePlayer_SetSpawnProtection *CBasePlayer_SetSpawnProtection() = 0;
virtual IReGameHookRegistry_IsPenetrableEntity *IsPenetrableEntity() = 0;
virtual IReGameHookRegistry_CBasePlayer_HintMessageEx *CBasePlayer_HintMessageEx() = 0;
};

struct ReGameFuncs_t {
Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,16 @@ void CBasePlayer_RemoveSpawnProtection(IReGameHook_CBasePlayer_RemoveSpawnProtec
callVoidForward(RG_CBasePlayer_RemoveSpawnProtection, original, indexOfEdict(pthis->pev));
}

bool CBasePlayer_HintMessageEx(IReGameHook_CBasePlayer_HintMessageEx *chain, CBasePlayer *pthis, const char *pMessage, float duration, bool bDisplayIfPlayerDead, bool bOverride)
{
auto original = [chain](int _pthis, const char *_pMessage, float _duration, bool _bDisplayIfPlayerDead, bool _bOverride)
{
return chain->callNext(getPrivate<CBasePlayer>(_pthis), _pMessage, _duration, _bDisplayIfPlayerDead, _bOverride);
};

return callForward<bool>(RG_CBasePlayer_HintMessageEx, original, indexOfEdict(pthis->pev), pMessage, duration, bDisplayIfPlayerDead, bOverride);
}

void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis)
{
auto original = [chain](int _pthis)
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ bool CBasePlayer_CanSwitchTeam(IReGameHook_CBasePlayer_CanSwitchTeam *chain, CBa
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);
bool CBasePlayer_HintMessageEx(IReGameHook_CBasePlayer_HintMessageEx *chain, CBasePlayer *pthis, const char *pMessage, float duration, bool bDisplayIfPlayerDead, bool bOverride);

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

Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ hook_t hooklist_player[] = {
DLL(CBasePlayer_ThrowGrenade),
DLL(CBasePlayer_SetSpawnProtection),
DLL(CBasePlayer_RemoveSpawnProtection),
DLL(CBasePlayer_HintMessageEx),
};

hook_t hooklist_gamerules[] = {
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ enum GamedllFunc_CBasePlayer
RG_CBasePlayer_ThrowGrenade,
RG_CBasePlayer_SetSpawnProtection,
RG_CBasePlayer_RemoveSpawnProtection,
RG_CBasePlayer_HintMessageEx,

// [...]
};
Expand Down
3 changes: 3 additions & 0 deletions reapi/src/member_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ member_t memberlist_player[] = {
PL_MEMBERS(m_silentTimestamp),
PL_MEMBERS(m_musicState),
PL_MEMBERS(m_flLastCommandTime),
PL_MEMBERS(m_iLastAccount),
PL_MEMBERS(m_iLastClientHealth),
PL_MEMBERS(m_tmNextAccountHealthUpdate),
};

member_t memberlist_entvars[] = {
Expand Down
5 changes: 4 additions & 1 deletion reapi/src/member_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,10 @@ enum CBasePlayer_Members
m_intenseTimestamp,
m_silentTimestamp,
m_musicState,
m_flLastCommandTime
m_flLastCommandTime,
m_iLastAccount,
m_iLastClientHealth,
m_tmNextAccountHealthUpdate,
};

// entvars
Expand Down
36 changes: 36 additions & 0 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,40 @@ cell AMX_NATIVE_CALL rg_get_iteminfo(AMX *amx, cell *params)
return TRUE;
}

/*
* Adds hint message to the queue.
*
* @param index Client index
* @param message The message hint
* @param duration The time duration in seconds stays on screen
* @param bDisplayIfPlayerDead Whether to print hint for dead players?
* @param bOverride Whether to override previous messages?
*
* @return true if prints, false otherwise
*
* native bool:rg_hint_message(const index, const message[], Float:duration = 6.0, bool:bDisplayIfPlayerDead = false, bool:bOverride = false);
*/
cell AMX_NATIVE_CALL rg_hint_message(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_message, arg_duration, arg_displayIfPlayerDead, arg_override };

CHECK_ISPLAYER(arg_index);

CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

char messagebuf[190];
const char *message = getAmxString(amx, params[arg_message], messagebuf);

if (!message || message[0] == '\0') {
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: sending an empty hint message is meaningless. rework your code.", __FUNCTION__);
return FALSE;
}

CAmxArgs args(amx, params);
return pPlayer->CSPlayer()->HintMessageEx(message, args[arg_duration], args[arg_displayIfPlayerDead], args[arg_override]) ? TRUE : FALSE;
}

AMX_NATIVE_INFO Misc_Natives_RG[] =
{
{ "rg_set_animation", rg_set_animation },
Expand Down Expand Up @@ -2190,6 +2224,8 @@ AMX_NATIVE_INFO Misc_Natives_RG[] =
{ "rg_set_iteminfo", rg_set_iteminfo },
{ "rg_get_iteminfo", rg_get_iteminfo },

{ "rg_hint_message", rg_hint_message },

{ nullptr, nullptr }
};

Expand Down

0 comments on commit 0eed4cd

Please sign in to comment.