mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 14:25:38 +03:00
Modules can now intercommunicate through RegisterFunction() - UNTESTED
Registering a function will make it available through ReqFunc,
This commit is contained in:
parent
3f2c117039
commit
cc899d298d
@ -276,6 +276,7 @@ extern ModuleCallReason g_ModuleCallReason; // modules.cpp
|
||||
extern CModule *g_CurrentlyCalledModule; // modules.cpp
|
||||
extern const char *g_LastRequestedFunc; // modules.cpp
|
||||
extern CQueue<String> CurModuleList;
|
||||
void Module_CacheFunctions();
|
||||
|
||||
void *Module_ReqFnptr(const char *funcName); // modules.cpp
|
||||
|
||||
@ -295,5 +296,12 @@ extern int FF_InconsistentFile;
|
||||
extern int FF_ClientAuthorized;
|
||||
|
||||
extern CFakeMeta g_FakeMeta;
|
||||
|
||||
struct func_s
|
||||
{
|
||||
void *pfn;
|
||||
const char *desc;
|
||||
};
|
||||
|
||||
#endif // AMXMODX_H
|
||||
|
||||
|
@ -1077,6 +1077,9 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
|
||||
|
||||
memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS));
|
||||
gpGamedllFuncs=pGamedllFuncs;
|
||||
|
||||
Module_CacheFunctions();
|
||||
|
||||
CVAR_REGISTER(&init_amxmodx_version);
|
||||
CVAR_REGISTER(&init_amxmodx_modules);
|
||||
CVAR_REGISTER(&init_amxmodx_debug);
|
||||
|
@ -1316,20 +1316,36 @@ cell MNF_PrepareCharArray(char *ptr, unsigned int size)
|
||||
return prepareCharArray(ptr, size, false);
|
||||
}
|
||||
|
||||
inline bool operator ==(func_s &arg1, const char *desc)
|
||||
{
|
||||
if (strcmp(arg1.desc, desc) == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
CList<func_s, const char *> g_functions;
|
||||
|
||||
// Fnptr Request function for the new interface
|
||||
const char *g_LastRequestedFunc = NULL;
|
||||
#define REGISTER_FUNC(name, func) { name, (void*)func },
|
||||
void *Module_ReqFnptr(const char *funcName)
|
||||
#define REGISTER_FUNC(name, func) \
|
||||
{ \
|
||||
pFunc = new func_s; \
|
||||
pFunc->pfn = func; \
|
||||
pFunc->desc = name; \
|
||||
g_functions.put(pFunc); \
|
||||
}
|
||||
|
||||
void MNF_RegisterFunction(void *pfn, const char *description)
|
||||
{
|
||||
// func table
|
||||
struct Func_s
|
||||
func_s *pFunc;
|
||||
|
||||
REGISTER_FUNC(description, pfn);
|
||||
}
|
||||
|
||||
void Module_CacheFunctions()
|
||||
{
|
||||
const char *name;
|
||||
void *ptr;
|
||||
};
|
||||
static Func_s functions[] = {
|
||||
// Misc
|
||||
func_s *pFunc;
|
||||
|
||||
REGISTER_FUNC("BuildPathname", build_pathname)
|
||||
REGISTER_FUNC("PrintSrvConsole", print_srvconsole)
|
||||
REGISTER_FUNC("GetModname", MNF_GetModname)
|
||||
@ -1337,6 +1353,7 @@ void *Module_ReqFnptr(const char *funcName)
|
||||
REGISTER_FUNC("LogError", LogError)
|
||||
REGISTER_FUNC("MergeDefinitionFile", MNF_MergeDefinitionFile)
|
||||
REGISTER_FUNC("Format", MNF_Format)
|
||||
REGISTER_FUNC("RegisterFunction", MNF_RegisterFunction);
|
||||
|
||||
// Amx scripts loading / unloading / managing
|
||||
REGISTER_FUNC("GetAmxScript", MNF_GetAmxScript)
|
||||
@ -1411,19 +1428,25 @@ void *Module_ReqFnptr(const char *funcName)
|
||||
#endif // MEMORY_TEST
|
||||
|
||||
REGISTER_FUNC("Haha_HiddenStuff", MNF_HiddenStuff)
|
||||
};
|
||||
}
|
||||
|
||||
void *Module_ReqFnptr(const char *funcName)
|
||||
{
|
||||
// code
|
||||
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
|
||||
// ^---- really? wow!
|
||||
if (!g_CurrentlyCalledModule)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_LastRequestedFunc = funcName;
|
||||
for (unsigned int i = 0; i < (sizeof(functions) / sizeof(Func_s)); ++i)
|
||||
|
||||
CList<func_s, const char *>::iterator iter;
|
||||
for (iter = g_functions.begin(); iter; ++iter)
|
||||
{
|
||||
if (strcmp(funcName, functions[i].name) == 0)
|
||||
return functions[i].ptr;
|
||||
if (strcmp(funcName, iter->desc) == 0)
|
||||
return iter->pfn;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2501,6 +2501,7 @@ PFN_AMX_FINDNATIVE g_fn_AmxFindNative;
|
||||
PFN_GETPLAYERFLAGS g_fn_GetPlayerFlags;
|
||||
PFN_GET_PLAYER_EDICT g_fn_GetPlayerEdict;
|
||||
PFN_FORMAT g_fn_Format;
|
||||
PFN_REGISTERFUNCTION g_fn_RegisterFunction;
|
||||
|
||||
// *** Exports ***
|
||||
C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo)
|
||||
@ -2547,6 +2548,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc)
|
||||
REQFUNC("LogError", g_fn_LogErrorFunc, PFN_LOG_ERROR);
|
||||
REQFUNC("MergeDefinitionFile", g_fn_MergeDefinition_File, PFN_MERGEDEFINITION_FILE);
|
||||
REQFUNC("Format", g_fn_Format, PFN_FORMAT);
|
||||
REQFUNC("RegisterFunction", g_fn_RegisterFunction, PFN_REGISTERFUNCTION);
|
||||
|
||||
// Amx scripts
|
||||
REQFUNC("GetAmxScript", g_fn_GetAmxScript, PFN_GET_AMXSCRIPT);
|
||||
@ -2723,6 +2725,7 @@ void ValidateMacros_DontCallThis_Smiley()
|
||||
MF_GetPlayerFrags(0);
|
||||
MF_GetPlayerEdict(0);
|
||||
MF_Format("", 4, "str");
|
||||
MF_RegisterFunction(NULL, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1974,6 +1974,7 @@ typedef int (*PFN_REGISTER_SPFORWARD_BYNAME) (AMX * /*amx*/, const char * /*f
|
||||
typedef void (*PFN_UNREGISTER_SPFORWARD) (int /*id*/);
|
||||
typedef void (*PFN_MERGEDEFINITION_FILE) (const char * /*filename*/);
|
||||
typedef const char * (*PFN_FORMAT) (const char * /*fmt*/, ... /*params*/);
|
||||
typedef void (*PFN_REGISTERFUNCTION) (void * /*pfn*/, const char * /*desc*/);
|
||||
|
||||
extern PFN_ADD_NATIVES g_fn_AddNatives;
|
||||
extern PFN_BUILD_PATHNAME g_fn_BuildPathname;
|
||||
@ -2034,6 +2035,7 @@ extern PFN_GETPLAYERFLAGS g_fn_GetPlayerFlags;
|
||||
extern PFN_GET_PLAYER_EDICT g_fn_GetPlayerEdict;
|
||||
extern PFN_FORMAT g_fn_Format;
|
||||
extern PFN_GET_PLAYER_TEAM g_fn_GetPlayerTeam;
|
||||
extern PFN_REGISTERFUNCTION g_fn_RegisterFunction;
|
||||
|
||||
#ifdef MAY_NEVER_BE_DEFINED
|
||||
// Function prototypes for intellisense and similar systems
|
||||
@ -2089,6 +2091,7 @@ void MF_UnregisterSPForward (int id) { }
|
||||
int MF_GetPlayerFlags (int id) { }
|
||||
edict_t* MF_GetPlayerEdict (int id) { }
|
||||
const char * MF_Format (const char *fmt, ...) { }
|
||||
void MF_RegisterFunction (void *pfn, const char *description) { }
|
||||
#endif // MAY_NEVER_BE_DEFINED
|
||||
|
||||
#define MF_AddNatives g_fn_AddNatives
|
||||
@ -2150,6 +2153,7 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...);
|
||||
#define MF_GetPlayerFlags g_fn_GetPlayerFlags
|
||||
#define MF_GetPlayerEdict g_fn_GetPlayerEdict
|
||||
#define MF_Format g_fn_Format
|
||||
#define MF_RegisterFunction g_fn_RegisterFunction
|
||||
|
||||
/*** Memory ***/
|
||||
void *operator new(size_t reportedSize);
|
||||
|
Loading…
Reference in New Issue
Block a user