Experimental addition to CreateMultiForward() for bcompat

This commit is contained in:
David Anderson 2006-10-22 03:49:23 +00:00
parent d542015214
commit d2ebca38a1
5 changed files with 53 additions and 9 deletions

View File

@ -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<num; i++)
{
params[i] = static_cast<ForwardParam>(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, ...)

View File

@ -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, ...);

View File

@ -3967,6 +3967,21 @@ static cell AMX_NATIVE_CALL CreateMultiForward(AMX *amx, cell *params)
return registerForwardC(funcname, static_cast<ForwardExecType>(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<ForwardExecType>(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},

View File

@ -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

View File

@ -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.