From d2ebca38a1c8d95730ff801396bb3845d3db82d0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 22 Oct 2006 03:49:23 +0000 Subject: [PATCH] Experimental addition to CreateMultiForward() for bcompat --- amxmodx/CForward.cpp | 21 ++++++++++++++++----- amxmodx/CForward.h | 10 +++++++--- amxmodx/amxmodx.cpp | 16 ++++++++++++++++ plugins/include/amxconst.inc | 4 ++++ plugins/include/amxmodx.inc | 11 ++++++++++- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/amxmodx/CForward.cpp b/amxmodx/CForward.cpp index 8e2448fa..6387f2ef 100755 --- a/amxmodx/CForward.cpp +++ b/amxmodx/CForward.cpp @@ -33,7 +33,7 @@ #include "debugger.h" #include "binlog.h" -CForward::CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam *paramTypes) +CForward::CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam *paramTypes, int fwd_type) { m_FuncName = name; m_ExecType = et; @@ -47,6 +47,13 @@ CForward::CForward(const char *name, ForwardExecType et, int numParams, const Fo for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter) { + if ((fwd_type != FORWARD_ALL) && + ((fwd_type == FORWARD_ONLY_NEW && ((*iter).getAMX()->flags & AMX_FLAG_OLDFILE)) + || (fwd_type == FORWARD_ONLY_OLD && !((*iter).getAMX()->flags & AMX_FLAG_OLDFILE)) + )) + { + continue; + } if ((*iter).isValid() && amx_FindPublic((*iter).getAMX(), name, &func) == AMX_ERR_NONE) { AMXForward tmp; @@ -352,13 +359,15 @@ cell CSPForward::execute(cell *params, ForwardPreparedArray *preparedArrays) return retVal; } -int CForwardMngr::registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam * paramTypes) +int CForwardMngr::registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam * paramTypes, int fwd_type) { int retVal = m_Forwards.size() << 1; - CForward *tmp = new CForward(funcName, et, numParams, paramTypes); + CForward *tmp = new CForward(funcName, et, numParams, paramTypes, fwd_type); if (!tmp) + { return -1; // should be invalid + } m_Forwards.push_back(tmp); @@ -519,14 +528,16 @@ void CForwardMngr::unregisterSPForward(int id) m_FreeSPForwards.push(id); } -int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_t num) +int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_t num, int fwd_type) { ForwardParam params[FORWARD_MAX_PARAMS]; for (size_t i=0; i(list[i]); + } - return g_forwards.registerForward(funcName, et, num, params); + return g_forwards.registerForward(funcName, et, num, params, fwd_type); } int registerForward(const char *funcName, ForwardExecType et, ...) diff --git a/amxmodx/CForward.h b/amxmodx/CForward.h index 57b527a0..68554bd0 100755 --- a/amxmodx/CForward.h +++ b/amxmodx/CForward.h @@ -51,6 +51,10 @@ const int FORWARD_MAX_PARAMS = 32; +#define FORWARD_ONLY_OLD 1 +#define FORWARD_ONLY_NEW 2 +#define FORWARD_ALL 3 + enum ForwardExecType { ET_IGNORE = 0, // Ignore return vaue @@ -107,7 +111,7 @@ class CForward ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS]; public: - CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes); + CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes, int fwd_type=FORWARD_ALL); CForward() {} // leaves everything unitialized' cell execute(cell *params, ForwardPreparedArray *preparedArrays); @@ -203,7 +207,7 @@ public: // Interface // Register normal forward - int registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam *paramTypes); + int registerForward(const char *funcName, ForwardExecType et, int numParams, const ForwardParam *paramTypes, int fwd_type=FORWARD_ALL); // Register single plugin forward int registerSPForward(const char *funcName, AMX *amx, int numParams, const ForwardParam * paramTypes); int registerSPForward(int func, AMX *amx, int numParams, const ForwardParam * paramTypes); @@ -227,7 +231,7 @@ public: // (un)register forward int registerForward(const char *funcName, ForwardExecType et, ...); -int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_t num); +int registerForwardC(const char *funcName, ForwardExecType et, cell *list, size_t num, int fwd_type=FORWARD_ALL); int registerSPForwardByName(AMX *amx, const char *funcName, ...); int registerSPForwardByNameC(AMX *amx, const char *funcName, cell *list, size_t num); int registerSPForward(AMX *amx, int func, ...); diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index d6861dd3..d5401606 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -3967,6 +3967,21 @@ static cell AMX_NATIVE_CALL CreateMultiForward(AMX *amx, cell *params) return registerForwardC(funcname, static_cast(params[2]), ps, count-2); } +static cell AMX_NATIVE_CALL CreateMultiForwardEx(AMX *amx, cell *params) +{ + int len; + char *funcname = get_amxstring(amx, params[1], 0, len); + + cell ps[FORWARD_MAX_PARAMS]; + cell count = params[0] / sizeof(cell); + for (cell i=4; i<=count; i++) + { + ps[i-4] = *get_amxaddr(amx, params[i]); + } + + return registerForwardC(funcname, static_cast(params[2]), ps, count-3, params[3]); +} + static cell AMX_NATIVE_CALL CreateOneForward(AMX *amx, cell *params) { CPluginMngr::CPlugin *p = g_plugins.findPlugin(params[1]); @@ -4501,6 +4516,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"CreateHudSyncObj", CreateHudSyncObj}, {"CreateLangKey", CreateLangKey}, {"CreateMultiForward", CreateMultiForward}, + {"CreateMultiForwardEx", CreateMultiForwardEx}, {"CreateOneForward", CreateOneForward}, {"DestroyForward", DestroyForward}, {"ExecuteForward", ExecuteForward}, diff --git a/plugins/include/amxconst.inc b/plugins/include/amxconst.inc index e05ec372..da589f57 100755 --- a/plugins/include/amxconst.inc +++ b/plugins/include/amxconst.inc @@ -277,6 +277,10 @@ enum { #define FP_STRING 2 #define FP_ARRAY 4 +#define FORWARD_ONLY_OLD 1 +#define FORWARD_ONLY_NEW 2 +#define FORWARD_ALL 3 + #define MEXIT_ALL 1 #define MEXIT_NORMAL 0 #define MEXIT_NEVER -1 diff --git a/plugins/include/amxmodx.inc b/plugins/include/amxmodx.inc index 8ed7cdff..5322955f 100755 --- a/plugins/include/amxmodx.inc +++ b/plugins/include/amxmodx.inc @@ -1016,11 +1016,20 @@ native set_addr_val(addr, val); /** - * creates a multi-plugin forward. + * Creates a multi-plugin forward. + * Stop type must be one of the ET_ values in amxconst.inc * results will be > 0 for success */ native CreateMultiForward(const name[], stop_type, ...); +/** + * Creates a multi-forward plugin that can filter between old/new plugins. + * Old plugins are used by the AMX Mod backwards compatibility layer. + * Stop type must be one of the ET_ values in amxconst.inc + * Forward type must be one of the FORWARD_ values in amxconst.inc. + */ +native CreateMultiForwardEx(const name[], stop_type, forward_type, ...); + /** * Creates a forward for one plugin. * Results will be > 0 for success.