From b8721e012397f2575c04361ffd5185c798bba3e0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 9 Sep 2004 06:04:50 +0000 Subject: [PATCH] Fixed module correction output --- amxmodx/amx.cpp | 37 ++++++++++++++++++++++++++++++++++++- amxmodx/amx.h | 2 +- amxmodx/amxmodx.cpp | 18 +++++++++--------- amxmodx/amxmodx.h | 2 ++ amxmodx/meta_api.cpp | 3 +++ amxmodx/modules.cpp | 7 ++++++- 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/amxmodx/amx.cpp b/amxmodx/amx.cpp index 15852489..b4ee26aa 100755 --- a/amxmodx/amx.cpp +++ b/amxmodx/amx.cpp @@ -1576,6 +1576,7 @@ static AMX_NATIVE findfunction(const char *name, AMX_NATIVE_INFO *list, int numb } const char *no_function; // PM: Nice hack ;) +int no_module_test; int AMXAPI amx_Register(AMX *amx, AMX_NATIVE_INFO *list, int number) { AMX_FUNCSTUB *func; @@ -1607,6 +1608,38 @@ int AMXAPI amx_Register(AMX *amx, AMX_NATIVE_INFO *list, int number) } /* for */ return err; } + +static cell AMX_NATIVE_CALL null_native(AMX *amx, cell *params) +{ + return 0; +} + +void amx_NullNativeTable(AMX *amx) +{ + AMX_FUNCSTUB *func; + AMX_HEADER *hdr; + int i, numnatives; + + hdr=(AMX_HEADER *)amx->base; + if (hdr == NULL) + return; + if (hdr->magic!=AMX_MAGIC) + return; + + numnatives = NUMENTRIES(hdr, natives, libraries); + + func=GETENTRY(hdr, natives, 0); + + for (i=0; iaddress == 0) + { + func->address = (ucell)null_native; + } + func=(AMX_FUNCSTUB*)((unsigned char*)func+hdr->defsize); + } +} + #endif /* AMX_REGISTER || AMX_EXEC || AMX_INIT */ #if defined AMX_NATIVEINFO @@ -2800,7 +2833,9 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index, int numparams, ...) if (amx->callback==NULL) return AMX_ERR_CALLBACK; i=amx_Register(amx,NULL,0); /* verify that all natives are registered */ - if (i!=AMX_ERR_NONE) + //HACKHACK - still execute if doing a module test! + // this WILL cause a crash if bad natives are used.... + if (i!=AMX_ERR_NONE && !no_module_test) return i; if ((amx->flags & AMX_FLAG_RELOC)==0) diff --git a/amxmodx/amx.h b/amxmodx/amx.h index 455120a1..b391ee0f 100755 --- a/amxmodx/amx.h +++ b/amxmodx/amx.h @@ -382,7 +382,7 @@ int AMXAPI amx_StrLen(cell *cstring, int *length); int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value); int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value); int AMXAPI amx_UTF8Check(const char *string); - +void amx_NullNativeTable(AMX *amx); #if !defined AMX_NO_ALIGN #if defined __linux__ diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 2e6e2625..f5cd0175 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2473,7 +2473,7 @@ static cell AMX_NATIVE_CALL callfunc_end(AMX *amx, cell *params) // native callfunc_push_int(value); // native callfunc_push_float(Float: value); -static cell callfunc_push_byval(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL callfunc_push_byval(AMX *amx, cell *params) { CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx); if (!g_CallFunc_Plugin) @@ -2499,7 +2499,7 @@ static cell callfunc_push_byval(AMX *amx, cell *params) // native callfunc_push_intref(&value); // native callfunc_push_floatref(Float: &value); -static cell callfunc_push_byref(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL callfunc_push_byref(AMX *amx, cell *params) { CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx); if (!g_CallFunc_Plugin) @@ -2557,7 +2557,7 @@ static cell callfunc_push_byref(AMX *amx, cell *params) } // native callfunc_push_str(value[]); -static cell callfunc_push_str(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL callfunc_push_str(AMX *amx, cell *params) { CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx); if (!g_CallFunc_Plugin) @@ -2618,20 +2618,20 @@ static cell callfunc_push_str(AMX *amx, cell *params) } // get_langsnum(); -static cell get_langsnum(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL get_langsnum(AMX *amx, cell *params) { return g_langMngr.GetLangsNum(); } // get_lang(id, name[(at least 3)]); -static cell get_lang(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL get_lang(AMX *amx, cell *params) { set_amxstring(amx, params[2], g_langMngr.GetLangName(params[1]), 2); return 0; } // register_dictionary(const filename[]); -static cell register_dictionary(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL register_dictionary(AMX *amx, cell *params) { int len; int result = g_langMngr.MergeDefinitionFile(build_pathname("%s/lang/%s", @@ -2639,7 +2639,7 @@ static cell register_dictionary(AMX *amx, cell *params) return result; } -static cell plugin_flags(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL plugin_flags(AMX *amx, cell *params) { AMX_HEADER *hdr; hdr = (AMX_HEADER *)amx->base; @@ -2647,13 +2647,13 @@ static cell plugin_flags(AMX *amx, cell *params) } // lang_exists(const name[]); -static cell lang_exists(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL lang_exists(AMX *amx, cell *params) { int len = 0; return g_langMngr.LangExists(get_amxstring(amx, params[1], 1, len)) ? 1 : 0; } -static cell register_module(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL register_module(AMX *amx, cell *params) { int len = 0; diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 37979a95..b222b2d3 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -254,6 +254,7 @@ void* alloc_amxmemory(void**, int size); void free_amxmemory(void **ptr); // get_localinfo const char* get_localinfo( const char* name , const char* def ); +static cell AMX_NATIVE_CALL null_native(AMX *amx, cell *params); enum ModuleCallReason { @@ -267,6 +268,7 @@ extern ModuleCallReason g_ModuleCallReason; // modules.cpp extern CModule *g_CurrentlyCalledModule; // modules.cpp extern const char *g_LastRequestedFunc; // modules.cpp extern CQueue CurModuleList; +extern int no_module_test; void *Module_ReqFnptr(const char *funcName); // modules.cpp diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 55b9a413..4f138e55 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -266,7 +266,9 @@ int C_Spawn( edict_t *pent ) { memset(g_players[0].flags,-1,sizeof(g_players[0].flags)); // ###### Load AMX scripts + no_module_test = 0; g_plugins.loadPluginsFromFile( get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini") ); + no_module_test = 0; // Register forwards FF_PluginInit = registerForward("plugin_init", ET_IGNORE, FP_DONE); @@ -446,6 +448,7 @@ void C_ServerDeactivate_Post() { // pft that's not really a hack g_FakeMeta.m_Plugins.begin()->GetDllFuncTable().pfnSpawn = C_Spawn; + no_module_test = 0; detachReloadModules(); g_auth.clear(); g_forwards.clear(); diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 52ec3297..a77989dc 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -222,6 +222,7 @@ int CheckModules(AMX *amx, char error[64]) { cell retVal = 0; int err = 0; + no_module_test = 1; if ( (err = amx_Exec(amx, &retVal, idx, 0)) == AMX_ERR_NONE ) { unsigned int i = 0; @@ -261,9 +262,11 @@ int CheckModules(AMX *amx, char error[64]) } } else { AMXXLOG_Log("[AMXX] Run time error %d on line %ld during module check.", err, amx->curline); + no_module_test = 0; //could not execute return -1; //bad! very bad! } + no_module_test = 0; } else { return -1; } @@ -292,7 +295,9 @@ int set_amxnatives(AMX* amx,char error[64]) { if (CheckModules(amx, error) == -1) { - //HACKHACK + //HACKHACK - if we get here, nullify the plugin's native table + // - BAILOPAN + amx_NullNativeTable(amx); sprintf(error,"Plugin uses an unknown function (name \"%s\") - check your modules.ini.",no_function); } return (amx->error = AMX_ERR_NATIVE);