From 1ba339a98bfee8220785e5ecdeff36f5f8c9edbd Mon Sep 17 00:00:00 2001 From: asmodai Date: Fri, 8 Jul 2016 00:27:35 +0300 Subject: [PATCH] Fixed pmtrace natives Added error if native requires one of the unexisting addons --- .../amxmodx/scripting/include/reapi_gamedll.inc | 4 ++-- reapi/src/natives/natives_addons.cpp | 11 +++++++---- reapi/src/natives/natives_helper.h | 6 ++++++ reapi/src/natives/natives_hookchains.cpp | 6 ++++-- reapi/src/natives/natives_members.cpp | 7 ++++--- reapi/src/natives/natives_misc.cpp | 12 +++++++----- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 88141fb..34c3327 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -88,7 +88,7 @@ native any:get_movevar(const MoveVars:var, any:...); * * @return 1 on success. */ -native set_pmtrace(const PMTrace:var, any:...); +native set_pmtrace(const tracehandle, const PMTrace:var, any:...); /* * Returns a pmtrace vars @@ -97,7 +97,7 @@ native set_pmtrace(const PMTrace:var, any:...); * * @return If an integer or boolean or one byte, array or everything else is passed via 3rd argument and more, look at argument list for specified mvar */ -native any:get_pmtrace(const PMTrace:var, any:...); +native any:get_pmtrace(const tracehandle, const PMTrace:var, any:...); /* * Assign the number of the player animations. diff --git a/reapi/src/natives/natives_addons.cpp b/reapi/src/natives/natives_addons.cpp index da5fba4..3fce2ff 100644 --- a/reapi/src/natives/natives_addons.cpp +++ b/reapi/src/natives/natives_addons.cpp @@ -108,9 +108,12 @@ AMX_NATIVE_INFO Reunion_Natives[] = void RegisterNatives_Addons() { - if (api_cfg.hasVTC()) - g_amxxapi.AddNatives(Vtc_Natives); + if (!api_cfg.hasVTC()) + fillNatives(Vtc_Natives, [](AMX *amx, cell *params) -> cell { MF_LogError(amx, AMX_ERR_NATIVE, "%s: isn't available", "VTC"); return FALSE; }); - if (api_cfg.hasReunion()) - g_amxxapi.AddNatives(Reunion_Natives); + if (!api_cfg.hasReunion()) + fillNatives(Reunion_Natives, [](AMX *amx, cell *params) -> cell { MF_LogError(amx, AMX_ERR_NATIVE, "%s: isn't available", "Reunion"); return FALSE; }); + + g_amxxapi.AddNatives(Vtc_Natives); + g_amxxapi.AddNatives(Reunion_Natives); } diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index 96207db..84b2177 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -93,3 +93,9 @@ private: AMX* m_amx; cell* m_params; }; + +inline void fillNatives(AMX_NATIVE_INFO* table, cell (AMX_NATIVE_CALL with)(AMX *, cell *)) +{ + for (size_t i = 0; table[i].name; i++) + table[i].func = with; +} diff --git a/reapi/src/natives/natives_hookchains.cpp b/reapi/src/natives/natives_hookchains.cpp index 234b93a..9afac6d 100644 --- a/reapi/src/natives/natives_hookchains.cpp +++ b/reapi/src/natives/natives_hookchains.cpp @@ -295,6 +295,8 @@ AMX_NATIVE_INFO HookChain_Natives[] = void RegisterNatives_HookChains() { - if (api_cfg.hasReHLDS() || api_cfg.hasReGameDLL()) - g_amxxapi.AddNatives(HookChain_Natives); + if (!api_cfg.hasReHLDS() && !api_cfg.hasReGameDLL()) + fillNatives(HookChain_Natives, [](AMX *amx, cell *params) -> cell { MF_LogError(amx, AMX_ERR_NATIVE, "You need ReHlds or ReGameDll for use hookchains"); return FALSE; }); + + g_amxxapi.AddNatives(HookChain_Natives); } diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index 9eb2a29..47d4075 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -433,9 +433,10 @@ AMX_NATIVE_INFO ReGameVars_Natives[] = void RegisterNatives_Members() { - if (api_cfg.hasReGameDLL()) - g_amxxapi.AddNatives(ReGameVars_Natives); - + if (!api_cfg.hasReGameDLL()) + fillNatives(ReGameVars_Natives, [](AMX *amx, cell *params) -> cell { MF_LogError(amx, AMX_ERR_NATIVE, "%s: isn't available", "ReGameDll"); return FALSE; }); + + g_amxxapi.AddNatives(ReGameVars_Natives); g_amxxapi.AddNatives(EngineVars_Natives); } diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index c4b8a0b..790fb11 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -1760,11 +1760,13 @@ AMX_NATIVE_INFO Misc_Natives_Checks[] = void RegisterNatives_Misc() { - if (api_cfg.hasReGameDLL()) - g_amxxapi.AddNatives(Misc_Natives_RG); - - if (api_cfg.hasReHLDS()) - g_amxxapi.AddNatives(Misc_Natives_RH); + if (!api_cfg.hasReGameDLL()) + fillNatives(Misc_Natives_RG, [](AMX *amx, cell *params) -> cell { MF_LogError(amx, AMX_ERR_NATIVE, "%s: isn't available", "ReGameDll"); return FALSE; }); + + if (!api_cfg.hasReHLDS()) + fillNatives(Misc_Natives_RH, [](AMX *amx, cell *params) -> cell { MF_LogError(amx, AMX_ERR_NATIVE, "%s: isn't available", "ReHlds"); return FALSE; }); + g_amxxapi.AddNatives(Misc_Natives_RG); + g_amxxapi.AddNatives(Misc_Natives_RH); g_amxxapi.AddNatives(Misc_Natives_Checks); }