From 7414e479edfaee22a5ef8c957a28dae366924383 Mon Sep 17 00:00:00 2001 From: asmodai Date: Mon, 2 May 2016 18:21:28 +0300 Subject: [PATCH] Added arg name for native params checks Added NULLENT Fixed some checks --- .../extra/amxmodx/scripting/include/reapi.inc | 2 ++ reapi/msvc/reapi.vcxproj | 1 - reapi/msvc/reapi.vcxproj.filters | 3 -- reapi/src/natives/natives_addons.cpp | 4 +-- reapi/src/natives/natives_helper.h | 13 +++---- reapi/src/natives/natives_misc.cpp | 36 +++++++++---------- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 8adefb3..70d895e 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -17,6 +17,8 @@ #define REAPI_VERISON_MAJOR 1 #define REAPI_VERISON_MINOR 0 +#define NULLENT -1 + #include #include // NOTE: only for ReHLDS #include // NOTE: only for gamedll Counter-Strike (ReGameDLL_CS) diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index 641825d..713f35f 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -262,7 +262,6 @@ - diff --git a/reapi/msvc/reapi.vcxproj.filters b/reapi/msvc/reapi.vcxproj.filters index 4cc46c6..3c4e06b 100644 --- a/reapi/msvc/reapi.vcxproj.filters +++ b/reapi/msvc/reapi.vcxproj.filters @@ -743,9 +743,6 @@ src - - amxmodx\scripting\include - amxmodx\scripting\include diff --git a/reapi/src/natives/natives_addons.cpp b/reapi/src/natives/natives_addons.cpp index 0b513f5..5c050aa 100644 --- a/reapi/src/natives/natives_addons.cpp +++ b/reapi/src/natives/natives_addons.cpp @@ -66,7 +66,7 @@ cell AMX_NATIVE_CALL REU_GetProtocol(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); return g_ReunionApi->GetClientProtocol(params[arg_index] - 1); } @@ -82,7 +82,7 @@ cell AMX_NATIVE_CALL REU_GetAuthtype(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); return g_ReunionApi->GetClientAuthtype(params[arg_index] - 1); } diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index 82ce7d4..6a64097 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -1,13 +1,13 @@ #pragma once -#define CHECK_ISPLAYER(x) if (x <= 0 || x > gpGlobals->maxClients) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid player index %i", x); return FALSE; } -#define CHECK_ISENTITY(x) if (x > gpGlobals->maxEntities) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid entity index %i", x); return FALSE; } +#define CHECK_ISPLAYER(x) if (params[x] <= 0 || params[x] > gpGlobals->maxClients) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid player index %i [%s]", params[x], #x); return FALSE; } +#define CHECK_ISENTITY(x) if (params[x] > gpGlobals->maxEntities) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid entity index %i [%s]", params[x], #x); return FALSE; } class CAmxArg { public: CAmxArg(AMX* amx, cell value) : m_amx(amx), m_value(value) {} - operator float&() const + operator float() const { return *(float *)m_value; } @@ -17,7 +17,7 @@ public: } operator entvars_s*() const { - auto pev = PEV(m_value); + auto pev = PEV(m_value); // faster return m_value < 0 ? nullptr : pev; } operator int() const @@ -34,8 +34,9 @@ public: } operator CBaseEntity*() const { - auto player = g_ReGameFuncs->UTIL_PlayerByIndex(m_value); - return m_value < 0 ? nullptr : player; + if (m_value < 0) + return nullptr; + return g_ReGameFuncs->UTIL_PlayerByIndex(m_value); } operator PLAYER_ANIM() const { diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 418735e..7075013 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -14,7 +14,7 @@ cell AMX_NATIVE_CALL rg_set_animation(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_anim }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -41,7 +41,7 @@ cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_amount, arg_track_change }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -67,7 +67,7 @@ cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_item }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -93,7 +93,7 @@ cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -119,7 +119,7 @@ cell AMX_NATIVE_CALL rg_give_shield(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_deploy }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -150,8 +150,8 @@ cell AMX_NATIVE_CALL rg_dmg_radius(AMX *amx, cell *params) { enum args_e { arg_count, arg_vec, arg_inflictor, arg_attacker, arg_damage, arg_radius, arg_ignore_class, arg_dmg_type }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_attacker]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_attacker); CAmxArgs args(amx, params); g_ReGameFuncs->RadiusDamage(args[arg_vec], args[arg_inflictor], args[arg_attacker], args[arg_damage], args[arg_radius], args[arg_ignore_class], args[arg_dmg_type]); @@ -186,8 +186,8 @@ cell AMX_NATIVE_CALL rg_multidmg_apply(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_attacker]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_attacker); CAmxArgs args(amx, params); g_ReGameFuncs->ApplyMultiDamage(args[arg_inflictor], args[arg_attacker]); @@ -211,8 +211,8 @@ cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_victim, arg_damage, arg_dmg_type }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_victim]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_victim); if (params[arg_victim] < 0) { // null MF_LogError(amx, AMX_ERR_NATIVE, "rg_multidmg_add: victim == null"); @@ -247,8 +247,8 @@ cell AMX_NATIVE_CALL rg_fire_bullets(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker, arg_shots, arg_vecSrc, arg_dir, arg_spread, arg_dist, arg_bullet_type, arg_tracefrq, arg_dmg }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_attacker]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_attacker); CAmxArgs args(amx, params); ICSEntity *pInflictor = args[arg_inflictor]; @@ -293,8 +293,8 @@ cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker, arg_vecSrc, arg_dir, arg_spread, arg_dist, arg_penetration, arg_bullet_type, arg_dmg, arg_range_mod, arg_pistol, arg_rand, arg_out }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_attacker]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_attacker); CAmxArgs args(amx, params); ICSEntity *pInflictor = args[arg_inflictor]; @@ -476,7 +476,7 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) { enum args_e { arg_count, arg_start_index, arg_classname, arg_onwer }; - CHECK_ISENTITY(params[arg_onwer]); + CHECK_ISENTITY(arg_onwer); const char* value = getAmxString(amx, params[arg_classname]); edict_t *pOwner = edictByIndex(params[arg_onwer]); @@ -564,7 +564,7 @@ cell AMX_NATIVE_CALL rg_remove_all_items(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_suit }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -590,7 +590,7 @@ cell AMX_NATIVE_CALL rg_remove_item(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_item_name }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); CBasePlayer *pPlayer = (CBasePlayer *)g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_index]); if (pPlayer == nullptr || pPlayer->has_disconnected) {