Skip to content

Commit

Permalink
SV_CheckUserInfo: Refer to 'userinfo' argument as a pointer instead o…
Browse files Browse the repository at this point in the history
…f an AMX string buffer

Added natives:
- set_netadr/get_netaddr
- set_key_value_buffer(buffer, "\\name\\ololo") overwrite a entire buffer
- get_key_value_buffer(buffer, userinfo, charsmax(userinfo)) get userinfo as AMX string presentation
Minor cleanup
Bump minor
  • Loading branch information
s1lentq committed Oct 7, 2023
1 parent 08210be commit ed57d7b
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 41 deletions.
3 changes: 2 additions & 1 deletion reapi/extra/amxmodx/scripting/include/reapi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ enum members_tables_e
mt_rebuystruct,
mt_mapinfo,
mt_csplayerweapon,
mt_gib
mt_gib,
mt_netadr
};

#define ReAPIFunc {EngineFunc, GamedllFunc, GamedllFunc_CBaseAnimating, GamedllFunc_CBasePlayer, GamedllFunc_CSGameRules, GamedllFunc_CGrenade, GamedllFunc_CWeaponBox, ReCheckerFunc, GamedllFunc_CBasePlayerWeapon, GamedllFunc_CGib, GamedllFunc_CBaseEntity, GamedllFunc_CBotManager}
Expand Down
42 changes: 41 additions & 1 deletion reapi/extra/amxmodx/scripting/include/reapi_engine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ native set_ucmd(const ucmd, const UCmd:var, any:...);
*/
native any:get_ucmd(const ucmd, const UCmd:var, any:...);

/*
* Sets a NetAdr var.
*
* @param var The specified mvar, look at the enum NetAdrVars
*
* @return 1 on success.
*/
native set_netadr(const adr, const NetAdrVars:var, any:...);

/*
* Returns a NetAdr var
*
* @param var The specified mvar, look at the enum NetAdrVars
*
* @return If an integer or boolean or one byte, array or everything else is passed via the 3rd argument and more, look at the argument list for the specified mvar
*/
native any:get_netadr(const adr, const NetAdrVars:var, any:...);

/*
* Gets value for key in buffer
*
Expand All @@ -55,6 +73,28 @@ native get_key_value(const pbuffer, const key[], const value[], const maxlen);
*/
native set_key_value(const pbuffer, const key[], const value[]);

/*
* Gets an AMXX string buffer from a infobuffer pointer
*
* @param buffer Info string pointer
* @param value String to copy value to
* @param maxlen Maximum size of the output buffer
*
* @return Returns a string buffer on infobuffer pointer
*/
native get_key_value_buffer(const pbuffer, const output[], const maxlen);

/*
* Sets value string to entire buffer
*
* @param buffer Pointer to buffer
* @param value Value to set
* @param maxlen Maximum size of the value buffer to set, -1 means copy all characters
*
* @return 1 on success, 0 otherwise
*/
native set_key_value_buffer(const pbuffer, const value[], const maxlen = -1);

/*
* Gets the position of the bone
*
Expand Down Expand Up @@ -156,7 +196,7 @@ native rh_drop_client(const index, const message[] = "");
* @param len Maximum buffer size
*
* @noreturn
*
*
*/
native rh_get_net_from(output[], len);

Expand Down
53 changes: 45 additions & 8 deletions reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,53 +115,53 @@ enum EngineFunc

/*
* Description: Called when a player's userinfo is being checked.
* Params: (adr, userinfo[], bool:reconnect, reconnectSlot, name[])
* Params: (adr, buffer, bool:reconnect, reconnectSlot, name[])
*
* @note Param adr is unused, guaranteed to return nothing also, don't send anything through it.
* @note In order for param name work, hook needs to be registered as Post.
*/
RH_SV_CheckUserInfo,

/*
* Description: Called when a generic resource is being added to generic precache list.
* Return type: int
* Params: (const string[])
*/
RH_PF_precache_generic_I,

/*
* Description: Called when a model is being added to model precache list.
* Return type: int
* Params: (const string[])
*/
RH_PF_precache_model_I,

/*
* Description: Called when a sound is being added to sound precache list.
* Return type: int
* Params: (const string[])
*/
RH_PF_precache_sound_I,

/*
* Description: Called when an event is being added to event precache list.
* Return type: int
* Params: (const string[])
*/
RH_EV_Precache,

/*
* Description: Called when a resource is being added to resource list.
* Params: (ResourceType_t:type, const filename[], size, flags, index)
*/
RH_SV_AddResource,

/*
* Description: Called when message is being printed to client console.
* Params: (const string[])
*/
RH_SV_ClientPrintf,

/*
* Description: Called when a command is being sent to server.
* Params: (const cmd[], source, id)
Expand Down Expand Up @@ -1268,3 +1268,40 @@ enum UCmd
*/
ucmd_impact_position
};

enum NetAdrType
{
NA_NULL = 0,
NA_LOOPBACK,
NA_BROADCAST,
NA_IP,
NA_IPX, // Deprecated: GoldSrc
NA_BROADCAST_IPX, // Deprecated: GoldSrc
};

enum NetAdrVars
{
/*
* Description: -
* Member type: NetAdrType
* Get params: get_netadr(const NetAdr:adr, const NetAdrVars:var);
* Set params: set_netadr(const NetAdr:adr, const NetAdrVars:var, const value);
*/
netadr_type = BEGIN_MEMBER_REGION(netadr),

/*
* Description: -
* Member type: unsigned char [4]
* Get params: get_netadr(const NetAdr:adr, const NetAdrVars:var, dest[], const lenght); // Also returns a iplong value
* Set params: set_netadr(const NetAdr:adr, const NetAdrVars:var, const iplong_value); // Only iplong can to set
*/
netadr_ip,

/*
* Description: -
* Member type: unsigned short
* Get params: get_netadr(const NetAdr:adr, const NetAdrVars:var);
* Set params: set_netadr(const NetAdr:adr, const NetAdrVars:var, const value);
*/
netadr_port
};
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ enum GamedllFunc
RG_ApplyMultiDamage,

/*
* Description: Called when player buys an item from buy menu (Nightvision, Kevlar, etc.)
* Description: Called when player buys an item from buy menu (Nightvision, Kevlar, etc.)
* Params: (const pPlayer, iSlot)
*/
RG_BuyItem,
Expand Down
15 changes: 10 additions & 5 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,19 @@ bool SV_AllowPhysent(IRehldsHook_SV_AllowPhysent* chain, edict_t* check, edict_t
return callForward<bool>(RH_SV_AllowPhysent, original, indexOfEdict(check), indexOfEdict(sv_player));
}

int SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name)
BOOL SV_CheckUserInfo_AMXX(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, size_t userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name)
{
auto original = [chain](netadr_t *_adr, char *_userinfo, qboolean _bIsReconnecting, int _iReconnectSlot, char *_name)
auto original = [chain](netadr_t *_adr, cell _userinfo, qboolean _bIsReconnecting, int _iReconnectSlot, char *_name)
{
return chain->callNext(_adr, _userinfo, _bIsReconnecting, _iReconnectSlot, _name);
return chain->callNext(_adr, (char *)_userinfo, _bIsReconnecting, _iReconnectSlot, _name);
};

return callForward<int>(RH_SV_CheckUserInfo, original, adr, userinfo, bIsReconnecting, iReconnectSlot, name);
return callForward<BOOL>(RH_SV_CheckUserInfo, original, adr, userinfo, bIsReconnecting, iReconnectSlot, name);
}

BOOL SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name)
{
return SV_CheckUserInfo_AMXX(chain, adr, (size_t)userinfo, bIsReconnecting, iReconnectSlot, name);
}

int PF_precache_generic_I(IRehldsHook_PF_precache_generic_I *chain, const char *s)
Expand Down Expand Up @@ -1614,7 +1619,7 @@ void CSGameRules_Think(IReGameHook_CSGameRules_Think *chain)

callVoidForward(RG_CSGameRules_Think, original);
}

BOOL CSGameRules_TeamFull(IReGameHook_CSGameRules_TeamFull *chain, int team_id)
{
auto original = [chain](int _team_id)
Expand Down
7 changes: 4 additions & 3 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics);
void Cvar_DirectSet(IRehldsHook_Cvar_DirectSet *chain, cvar_t *var, const char *value);
void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl);
void SV_ConnectClient(IRehldsHook_SV_ConnectClient* chain);
int SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo* chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name);
BOOL SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name);
BOOL SV_CheckUserInfo_AMXX(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, size_t userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name);

struct SV_WriteFullClientUpdate_args_t
{
Expand Down Expand Up @@ -547,14 +548,14 @@ void ClearMultiDamage(IReGameHook_ClearMultiDamage *chain);
void AddMultiDamage(IReGameHook_AddMultiDamage *chain, entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType);
void ApplyMultiDamage(IReGameHook_ApplyMultiDamage *chain, entvars_t *pevInflictor, entvars_t *pevAttacker);
void BuyItem(IReGameHook_BuyItem *chain, CBasePlayer *pPlayer, int iSlot);
void CSGameRules_Think(IReGameHook_CSGameRules_Think *chain);
void CSGameRules_Think(IReGameHook_CSGameRules_Think *chain);
BOOL CSGameRules_TeamFull(IReGameHook_CSGameRules_TeamFull *chain, int team_id);
BOOL CSGameRules_TeamStacked(IReGameHook_CSGameRules_TeamStacked *chain, int newTeam_id, int curTeam_id);
void CSGameRules_PlayerGotWeapon(IReGameHook_CSGameRules_PlayerGotWeapon *chain, CBasePlayer *pPlayer, CBasePlayerItem *pWeapon);
void CBotManager_OnEvent(IReGameHook_CBotManager_OnEvent *chain, GameEventType event, CBaseEntity* pEntity, CBaseEntity* pOther);
void CBasePlayer_CheckTimeBasedDamage(IReGameHook_CBasePlayer_CheckTimeBasedDamage *chain, CBasePlayer *pthis);
edict_t *CBasePlayer_EntSelectSpawnPoint(IReGameHook_CBasePlayer_EntSelectSpawnPoint *chain, CBasePlayer *pthis);
void CBasePlayerWeapon_ItemPostFrame(IReGameHook_CBasePlayerWeapon_ItemPostFrame *chain, CBasePlayerWeapon *pthis);
void CBasePlayerWeapon_ItemPostFrame(IReGameHook_CBasePlayerWeapon_ItemPostFrame *chain, CBasePlayerWeapon *pthis);
void CBasePlayerWeapon_KickBack(IReGameHook_CBasePlayerWeapon_KickBack *chain, CBasePlayerWeapon *pthis, float up_base, float lateral_base, float up_modifier, float lateral_modifier, float up_max, float lateral_max, int direction_change);
void CBasePlayerWeapon_SendWeaponAnim(IReGameHook_CBasePlayerWeapon_SendWeaponAnim *chain, CBasePlayerWeapon *pthis, int iAnim, int skiplocal);

Expand Down
2 changes: 1 addition & 1 deletion reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ hook_t hooklist_engine[] = {
ENG(ED_Alloc),
ENG(ED_Free),
ENG(Con_Printf),
ENG(SV_CheckUserInfo),
ENG(SV_CheckUserInfo, _AMXX),
ENG(PF_precache_generic_I),
ENG(PF_precache_model_I),
ENG(PF_precache_sound_I),
Expand Down
9 changes: 9 additions & 0 deletions reapi/src/member_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define MOVEVAR_MEMBERS(mx) STRUCT_MEMBERS(movevars_t, mx, mv_##mx)
#define UCMD_MEMBERS(mx) STRUCT_MEMBERS(usercmd_s, mx, ucmd_##mx)
#define PMTRACE_MEMBERS(mx) STRUCT_MEMBERS(pmtrace_s, mx, pmt_##mx)
#define NETADR_MEMBERS(mx) STRUCT_MEMBERS(netadr_t, mx, netadr_##mx)
#define CSPL_MEMBERS(mx) CLASS_MEMBERS(CCSPlayer, mx, mx)
#define BASEITEM_MEMBERS(mx) CLASS_MEMBERS(CBasePlayerItem, mx, mx)
#define BASEWPN_MEMBERS(mx) CLASS_MEMBERS_PREF(CBasePlayerWeapon, mx, m_Weapon_##mx, m_)
Expand Down Expand Up @@ -111,6 +112,7 @@ inline MType getMemberType(MONSTERSTATE) { return MEMBER_INTEGER; }
inline MType getMemberType(ArmorType) { return MEMBER_INTEGER; }
inline MType getMemberType(ArmouryItemPack) { return MEMBER_INTEGER; }
inline MType getMemberType(InfoMapBuyParam) { return MEMBER_INTEGER; }
inline MType getMemberType(netadrtype_t) { return MEMBER_INTEGER; }

inline MType getMemberType(TraceResult) { return MEMBER_TRACERESULT; }

Expand Down Expand Up @@ -1048,6 +1050,12 @@ member_t memberlist_gib[] = {
GIB_MEMBERS(lifeTime),
};

member_t memberlist_netadr[] = {
NETADR_MEMBERS(type),
NETADR_MEMBERS(ip),
NETADR_MEMBERS(port)
};

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // #ifdef __GNUC__
Expand Down Expand Up @@ -1111,6 +1119,7 @@ member_t *memberlist_t::operator[](size_t members) const
CASE(mapinfo)
CASE(csplayerweapon)
CASE(gib)
CASE(netadr)
}

#undef CASE
Expand Down
8 changes: 8 additions & 0 deletions reapi/src/member_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct memberlist_t
mt_mapinfo,
mt_csplayerweapon,
mt_gib,
mt_netadr
};
};

Expand Down Expand Up @@ -735,6 +736,13 @@ enum PMTrace
pmt_hitgroup
};

enum NetAdr
{
netadr_type = BEGIN_MEMBER_REGION(netadr),
netadr_ip,
netadr_port
};

// CCSPlayer
enum CSPlayer_Members
{
Expand Down
Loading

0 comments on commit ed57d7b

Please sign in to comment.