diff --git a/amxmodx/amx.cpp b/amxmodx/amx.cpp index 4e431212..a3021c80 100755 --- a/amxmodx/amx.cpp +++ b/amxmodx/amx.cpp @@ -1481,6 +1481,36 @@ int AMXAPI amx_RegisterToAny(AMX *amx, AMX_NATIVE f) return err; } +int AMXAPI amx_Reregister(AMX *amx, const AMX_NATIVE_INFO *list, int number) +{ + AMX_FUNCSTUB *func; + AMX_HEADER *hdr; + int i,numnatives,count=0; + AMX_NATIVE funcptr; + + hdr=(AMX_HEADER *)amx->base; + assert(hdr!=NULL); + assert(hdr->magic==AMX_MAGIC); + assert(hdr->natives<=hdr->libraries); + numnatives=NUMENTRIES(hdr,natives,libraries); + + count=0; + func=GETENTRY(hdr,natives,0); + for (i=0; iaddress!=0) { + /* this function is located */ + funcptr=(list!=NULL) ? findfunction(GETENTRYNAME(hdr,func),list,number) : NULL; + if (funcptr!=NULL) + { + func->address=(ucell)funcptr; + count++; + } + } /* if */ + func=(AMX_FUNCSTUB*)((unsigned char*)func+hdr->defsize); + } /* for */ + return count; +} + int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *list, int number) { AMX_FUNCSTUB *func; @@ -1501,12 +1531,12 @@ int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *list, int number) /* this function is not yet located */ funcptr=(list!=NULL) ? findfunction(GETENTRYNAME(hdr,func),list,number) : NULL; if (funcptr!=NULL) - { + { func->address=(ucell)funcptr; } else { no_function = GETENTRYNAME(hdr,func); err=AMX_ERR_NOTFOUND; - } + } } /* if */ func=(AMX_FUNCSTUB*)((unsigned char*)func+hdr->defsize); } /* for */ diff --git a/amxmodx/amx.h b/amxmodx/amx.h index 1c2d76fa..f1d3ecce 100755 --- a/amxmodx/amx.h +++ b/amxmodx/amx.h @@ -410,6 +410,7 @@ int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar); int AMXAPI amx_RaiseError(AMX *amx, int error); int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number); +int AMXAPI amx_Reregister(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number); int AMXAPI amx_RegisterToAny(AMX *amx, AMX_NATIVE f); int AMXAPI amx_Release(AMX *amx, cell amx_addr); int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback); diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 27d86d6d..500e82d9 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -1647,6 +1647,25 @@ void MNF_RegisterFunction(void *pfn, const char *description) REGISTER_FUNC(description, pfn); } +void *MNF_RegisterFunctionEx(void *pfn, const char *description) +{ + func_s *pFunc; + CList::iterator iter; + + for (iter = g_functions.begin(); iter; ++iter) + { + pFunc = &(*iter); + if (strcmp(description, pFunc->desc) == 0) + { + void *pOld = pFunc->pfn; + pFunc->pfn = pfn; + return pOld; + } + } + + return NULL; +} + void Module_UncacheFunctions() { g_functions.clear(); @@ -1746,6 +1765,7 @@ void Module_CacheFunctions() REGISTER_FUNC("MergeDefinitionFile", MNF_MergeDefinitionFile) REGISTER_FUNC("Format", MNF_Format) REGISTER_FUNC("RegisterFunction", MNF_RegisterFunction); + REGISTER_FUNC("RegisterFunctionEx", MNF_RegisterFunctionEx); // Amx scripts loading / unloading / managing REGISTER_FUNC("GetAmxScript", MNF_GetAmxScript) @@ -1762,6 +1782,7 @@ void Module_CacheFunctions() REGISTER_FUNC("FormatAmxString", MNF_FormatAmxString) REGISTER_FUNC("CopyAmxMemory", MNF_CopyAmxMemory) REGISTER_FUNC("GetAmxAddr", get_amxaddr) + REGISTER_FUNC("AmxReregister", amx_Reregister); // other amx stuff REGISTER_FUNC("amx_Exec", amx_Exec) diff --git a/amxmodx/sdk/amxxmodule.cpp b/amxmodx/sdk/amxxmodule.cpp index 30ef9c79..fb488735 100755 --- a/amxmodx/sdk/amxxmodule.cpp +++ b/amxmodx/sdk/amxxmodule.cpp @@ -2513,6 +2513,8 @@ PFN_ADDLIBRARIES g_fn_AddLibraries; PFN_REMOVELIBRARIES g_fn_RemoveLibraries; PFN_OVERRIDENATIVES g_fn_OverrideNatives; PFN_GETLOCALINFO g_fn_GetLocalInfo; +PFN_AMXREREGISTER g_fn_AmxReRegister; +PFN_REGISTERFUNCTIONEX g_fn_RegisterFunctionEx; // *** Exports *** C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo) @@ -2563,6 +2565,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("MergeDefinitionFile", g_fn_MergeDefinition_File, PFN_MERGEDEFINITION_FILE); REQFUNC("Format", g_fn_Format, PFN_FORMAT); REQFUNC("RegisterFunction", g_fn_RegisterFunction, PFN_REGISTERFUNCTION); + REQFUNC("RegisterFunctionEx", g_fn_RegisterFunctionEx, PFN_REGISTERFUNCTIONEX); // Amx scripts REQFUNC("GetAmxScript", g_fn_GetAmxScript, PFN_GET_AMXSCRIPT); @@ -2627,11 +2630,13 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("RegAuthFunc", g_fn_RegAuthFunc, PFN_REG_AUTH_FUNC); REQFUNC("UnregAuthFunc", g_fn_UnregAuthFunc, PFN_UNREG_AUTH_FUNC); + //Added in 1.75 REQFUNC("FindLibrary", g_fn_FindLibrary, PFN_FINDLIBRARY); REQFUNC("AddLibraries", g_fn_AddLibraries, PFN_ADDLIBRARIES); REQFUNC("RemoveLibraries", g_fn_RemoveLibraries, PFN_REMOVELIBRARIES); REQFUNC("OverrideNatives", g_fn_OverrideNatives, PFN_OVERRIDENATIVES); REQFUNC("GetLocalInfo", g_fn_GetLocalInfo, PFN_GETLOCALINFO); + REQFUNC("AmxReregister", g_fn_AmxReRegister, PFN_AMX_REREGISTER); #ifdef MEMORY_TEST // Memory @@ -2766,6 +2771,7 @@ void ValidateMacros_DontCallThis_Smiley() MF_GetPlayerEdict(0); MF_Format("", 4, "str"); MF_RegisterFunction(NULL, ""); + MF_RegisterFunctionEx(NULL, ""); MF_SetPlayerTeamInfo(0, 0, ""); MF_PlayerPropAddr(0, 0); MF_RegAuthFunc(NULL); diff --git a/amxmodx/sdk/amxxmodule.h b/amxmodx/sdk/amxxmodule.h index 986e0eb4..e74febf4 100755 --- a/amxmodx/sdk/amxxmodule.h +++ b/amxmodx/sdk/amxxmodule.h @@ -2181,6 +2181,8 @@ typedef size_t (*PFN_ADDLIBRARIES) (const char * /*name*/, LibType /*type*/ typedef size_t (*PFN_REMOVELIBRARIES) (void * /*parent*/); typedef void (*PFN_OVERRIDENATIVES) (AMX_NATIVE_INFO * /*natives*/); typedef const char * (*PFN_GETLOCALINFO) (const char * /*name*/, const char * /*def*/); +typedef int (*PFN_AMX_REREGISTER) (AMX * /*amx*/, AMX_NATIVE_INFO * /*list*/, int /*list*/); +typedef void * (*PFN_REGISTERFUNCTIONEX) (void * /*pfn*/, const char * /*desc*/); extern PFN_ADD_NATIVES g_fn_AddNatives; extern PFN_BUILD_PATHNAME g_fn_BuildPathname; @@ -2253,6 +2255,8 @@ extern PFN_ADDLIBRARIES g_fn_AddLibraries; extern PFN_REMOVELIBRARIES g_fn_RemoveLibraries; extern PFN_OVERRIDENATIVES g_fn_OverrideNatives; extern PFN_GETLOCALINFO g_fn_GetLocalInfo; +extern PFN_AMX_REREGISTER g_fn_AmxReRegister; +extern PFN_REGISTERFUNCTIONEX g_fn_RegisterFunctionEx; #ifdef MAY_NEVER_BE_DEFINED // Function prototypes for intellisense and similar systems @@ -2322,6 +2326,8 @@ size_t MF_AddLibraries (const char *name, LibType type, void *parent) { } size_t MF_RemoveLibraries (void *parent) { } void MF_OverrideNatives (AMX_NATIVE_INFO *natives) { } const char * MF_GetLocalInfo (const char *name, const char *def) { } +int MF_AmxReRegister (AMX *amx, AMX_NATIVE_INFO *list, int number) { return 0; } +void * MF_RegisterFunctionEx (void *pfn, const char *description) { } #endif // MAY_NEVER_BE_DEFINED #define MF_AddNatives g_fn_AddNatives @@ -2396,6 +2402,8 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...); #define MF_RemoveLibraries g_fn_RemoveLibraries #define MF_OverrideNatives g_fn_OverrideNatives #define MF_GetLocalInfo g_fn_GetLocalInfo +#define MF_AmxReRegister g_fn_AmxReRegister +#define MF_RegisterFunctionEx g_fn_RegisterFunctionEx #ifdef MEMORY_TEST /*** Memory ***/