2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-03-13 14:00:19 +03:00

Implemented hook CBasePlayer::HintMessageEx. Closes #133

Add native rg_hint_message
Add news CBasePlayer members
Bump minor version API
This commit is contained in:
s1lent 2019-06-06 02:59:53 +07:00
parent 4834b7a117
commit 0eed4cd833
No known key found for this signature in database
GPG Key ID: 0FE401DC73916B5C
14 changed files with 143 additions and 7 deletions

View File

@ -1,3 +1,3 @@
majorVersion=5 majorVersion=5
minorVersion=8 minorVersion=9
maintenanceVersion=0 maintenanceVersion=0

View File

@ -823,3 +823,16 @@ native rg_set_iteminfo(const entity, ItemInfo:type, any:...);
* *
*/ */
native rg_get_iteminfo(const ent, 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);

View File

@ -747,6 +747,13 @@ enum GamedllFunc_CBasePlayer
* Params: (const this) * Params: (const this)
*/ */
RG_CBasePlayer_RemoveSpawnProtection, 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,
}; };
/** /**
@ -3499,7 +3506,31 @@ enum CBasePlayer_Members
* Get params: Float:get_member(index, member, element); * Get params: Float:get_member(index, member, element);
* Set params: set_member(index, member, Float:value, 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,
}; };
/** /**

View File

@ -226,4 +226,8 @@ class CCSTriggerCamera: public CCSDelay {};
class CCSWeather: public CCSTrigger {}; class CCSWeather: public CCSTrigger {};
class CCSClientFog: public CCSEntity {}; class CCSClientFog: public CCSEntity {};
class CCSTriggerSetOrigin: public CCSDelay {}; class CCSTriggerSetOrigin: public CCSDelay {};
class CCSTriggerRandom: public CCSDelay {};
class CCSItemAirBox: public CCSArmoury {}; class CCSItemAirBox: public CCSArmoury {};
class CCSPointBaseCommand: public CCSPointEntity {};
class CCSPointClientCommand: public CCSPointBaseCommand {};
class CCSPointServerCommand: public CCSPointBaseCommand {};

View File

@ -82,9 +82,20 @@ public:
virtual bool RemovePlayerItemEx(const char* pszItemName, bool bRemoveAmmo); virtual bool RemovePlayerItemEx(const char* pszItemName, bool bRemoveAmmo);
virtual void SetSpawnProtection(float flProtectionTime); virtual void SetSpawnProtection(float flProtectionTime);
virtual void RemoveSpawnProtection(); virtual void RemoveSpawnProtection();
virtual bool HintMessageEx(const char *pMessage, float duration = 6.0f, bool bDisplayIfPlayerDead = false, bool bOverride = false);
CBasePlayer *BasePlayer() const; CBasePlayer *BasePlayer() const;
public:
enum EProtectionState
{
ProtectionSt_NoSet,
ProtectionSt_Active,
ProtectionSt_Expired,
};
EProtectionState GetProtectionState() const;
public: public:
char m_szModel[32]; char m_szModel[32];
bool m_bForceShowMenu; bool m_bForceShowMenu;
@ -97,3 +108,17 @@ inline CBasePlayer *CCSPlayer::BasePlayer() const
{ {
return reinterpret_cast<CBasePlayer *>(this->m_pContainingEntity); 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;
}

View File

@ -584,6 +584,9 @@ public:
float m_silentTimestamp; float m_silentTimestamp;
MusicState m_musicState; MusicState m_musicState;
float m_flLastCommandTime[COMMANDS_TO_TRACK]; float m_flLastCommandTime[COMMANDS_TO_TRACK];
int m_iLastAccount;
int m_iLastClientHealth;
float m_tmNextAccountHealthUpdate;
}; };
class CWShield: public CBaseEntity { class CWShield: public CBaseEntity {

View File

@ -38,7 +38,7 @@
#include <API/CSInterfaces.h> #include <API/CSInterfaces.h>
#define REGAMEDLL_API_VERSION_MAJOR 5 #define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 8 #define REGAMEDLL_API_VERSION_MINOR 9
// CBasePlayer::Spawn hook // CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn; typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
@ -436,6 +436,10 @@ typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBa
typedef IHookChain<bool, Vector &, Vector &, entvars_t *, edict_t *> IReGameHook_IsPenetrableEntity; typedef IHookChain<bool, Vector &, Vector &, entvars_t *, edict_t *> IReGameHook_IsPenetrableEntity;
typedef IHookChainRegistry<bool, Vector &, Vector &, entvars_t *, edict_t *> IReGameHookRegistry_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 { class IReGameHookchains {
public: public:
virtual ~IReGameHookchains() {} virtual ~IReGameHookchains() {}
@ -544,6 +548,7 @@ public:
virtual IReGameHookRegistry_CBasePlayer_RemoveSpawnProtection *CBasePlayer_RemoveSpawnProtection() = 0; virtual IReGameHookRegistry_CBasePlayer_RemoveSpawnProtection *CBasePlayer_RemoveSpawnProtection() = 0;
virtual IReGameHookRegistry_CBasePlayer_SetSpawnProtection *CBasePlayer_SetSpawnProtection() = 0; virtual IReGameHookRegistry_CBasePlayer_SetSpawnProtection *CBasePlayer_SetSpawnProtection() = 0;
virtual IReGameHookRegistry_IsPenetrableEntity *IsPenetrableEntity() = 0; virtual IReGameHookRegistry_IsPenetrableEntity *IsPenetrableEntity() = 0;
virtual IReGameHookRegistry_CBasePlayer_HintMessageEx *CBasePlayer_HintMessageEx() = 0;
}; };
struct ReGameFuncs_t { struct ReGameFuncs_t {

View File

@ -532,6 +532,16 @@ void CBasePlayer_RemoveSpawnProtection(IReGameHook_CBasePlayer_RemoveSpawnProtec
callVoidForward(RG_CBasePlayer_RemoveSpawnProtection, original, indexOfEdict(pthis->pev)); 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) void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis)
{ {
auto original = [chain](int _pthis) auto original = [chain](int _pthis)

View File

@ -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); 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_SetSpawnProtection(IReGameHook_CBasePlayer_SetSpawnProtection *chain, CBasePlayer *pthis, float flProtectionTime);
void CBasePlayer_RemoveSpawnProtection(IReGameHook_CBasePlayer_RemoveSpawnProtection *chain, CBasePlayer *pthis); 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); void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis);

View File

@ -153,6 +153,7 @@ hook_t hooklist_player[] = {
DLL(CBasePlayer_ThrowGrenade), DLL(CBasePlayer_ThrowGrenade),
DLL(CBasePlayer_SetSpawnProtection), DLL(CBasePlayer_SetSpawnProtection),
DLL(CBasePlayer_RemoveSpawnProtection), DLL(CBasePlayer_RemoveSpawnProtection),
DLL(CBasePlayer_HintMessageEx),
}; };
hook_t hooklist_gamerules[] = { hook_t hooklist_gamerules[] = {

View File

@ -175,6 +175,7 @@ enum GamedllFunc_CBasePlayer
RG_CBasePlayer_ThrowGrenade, RG_CBasePlayer_ThrowGrenade,
RG_CBasePlayer_SetSpawnProtection, RG_CBasePlayer_SetSpawnProtection,
RG_CBasePlayer_RemoveSpawnProtection, RG_CBasePlayer_RemoveSpawnProtection,
RG_CBasePlayer_HintMessageEx,
// [...] // [...]
}; };

View File

@ -476,6 +476,9 @@ member_t memberlist_player[] = {
PL_MEMBERS(m_silentTimestamp), PL_MEMBERS(m_silentTimestamp),
PL_MEMBERS(m_musicState), PL_MEMBERS(m_musicState),
PL_MEMBERS(m_flLastCommandTime), PL_MEMBERS(m_flLastCommandTime),
PL_MEMBERS(m_iLastAccount),
PL_MEMBERS(m_iLastClientHealth),
PL_MEMBERS(m_tmNextAccountHealthUpdate),
}; };
member_t memberlist_entvars[] = { member_t memberlist_entvars[] = {

View File

@ -466,7 +466,10 @@ enum CBasePlayer_Members
m_intenseTimestamp, m_intenseTimestamp,
m_silentTimestamp, m_silentTimestamp,
m_musicState, m_musicState,
m_flLastCommandTime m_flLastCommandTime,
m_iLastAccount,
m_iLastClientHealth,
m_tmNextAccountHealthUpdate,
}; };
// entvars // entvars

View File

@ -2112,6 +2112,40 @@ cell AMX_NATIVE_CALL rg_get_iteminfo(AMX *amx, cell *params)
return TRUE; 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[] = AMX_NATIVE_INFO Misc_Natives_RG[] =
{ {
{ "rg_set_animation", rg_set_animation }, { "rg_set_animation", rg_set_animation },
@ -2190,6 +2224,8 @@ AMX_NATIVE_INFO Misc_Natives_RG[] =
{ "rg_set_iteminfo", rg_set_iteminfo }, { "rg_set_iteminfo", rg_set_iteminfo },
{ "rg_get_iteminfo", rg_get_iteminfo }, { "rg_get_iteminfo", rg_get_iteminfo },
{ "rg_hint_message", rg_hint_message },
{ nullptr, nullptr } { nullptr, nullptr }
}; };