2007-01-25 23:36:38 +01:00
|
|
|
/**
|
|
|
|
* ===============================================================
|
|
|
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
|
|
|
* ===============================================================
|
|
|
|
*
|
|
|
|
* This file is not open source and may not be copied without explicit
|
|
|
|
* written permission of AlliedModders LLC. This file may not be redistributed
|
|
|
|
* in whole or significant part.
|
|
|
|
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2006-11-12 02:06:17 +01:00
|
|
|
#ifndef _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|
|
|
|
#define _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|
|
|
|
|
|
|
|
#include <IForwardSys.h>
|
|
|
|
#include <IPluginSys.h>
|
|
|
|
#include "sm_globals.h"
|
|
|
|
#include <sh_list.h>
|
|
|
|
#include <sh_stack.h>
|
2006-12-15 14:38:04 +01:00
|
|
|
#include "sourcemod.h"
|
2006-11-12 02:06:17 +01:00
|
|
|
|
|
|
|
using namespace SourceHook;
|
|
|
|
|
|
|
|
typedef List<IPluginFunction *>::iterator FuncIter;
|
|
|
|
|
|
|
|
//:TODO: a global name max define for sourcepawn, should mirror compiler's sNAMEMAX
|
|
|
|
#define FORWARDS_NAME_MAX 64
|
|
|
|
|
2006-11-12 10:51:39 +01:00
|
|
|
struct ByrefInfo
|
2006-11-12 02:06:17 +01:00
|
|
|
{
|
2006-11-12 10:51:39 +01:00
|
|
|
unsigned int cells;
|
|
|
|
cell_t *orig_addr;
|
|
|
|
int flags;
|
2006-12-06 15:52:11 +01:00
|
|
|
int sz_flags;
|
2006-11-12 02:06:17 +01:00
|
|
|
};
|
|
|
|
|
2006-11-12 10:51:39 +01:00
|
|
|
struct FwdParamInfo
|
|
|
|
{
|
|
|
|
cell_t val;
|
|
|
|
ByrefInfo byref;
|
|
|
|
ParamType pushedas;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CForward : public IChangeableForward
|
2006-11-12 02:06:17 +01:00
|
|
|
{
|
|
|
|
public: //ICallable
|
|
|
|
virtual int PushCell(cell_t cell);
|
2007-03-07 19:37:41 +01:00
|
|
|
virtual int PushCellByRef(cell_t *cell, int flags);
|
2006-11-12 02:06:17 +01:00
|
|
|
virtual int PushFloat(float number);
|
2007-03-07 19:37:41 +01:00
|
|
|
virtual int PushFloatByRef(float *number, int flags);
|
2007-03-10 22:02:40 +01:00
|
|
|
virtual int PushArray(cell_t *inarray, unsigned int cells, int flags);
|
2006-11-12 02:06:17 +01:00
|
|
|
virtual int PushString(const char *string);
|
2006-12-06 15:52:11 +01:00
|
|
|
virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
|
2006-11-12 02:06:17 +01:00
|
|
|
virtual void Cancel();
|
|
|
|
public: //IForward
|
2007-03-15 05:34:42 +01:00
|
|
|
virtual const char *GetForwardName();
|
|
|
|
virtual unsigned int GetFunctionCount();
|
|
|
|
virtual ExecType GetExecType();
|
2006-11-12 02:06:17 +01:00
|
|
|
virtual int Execute(cell_t *result, IForwardFilter *filter);
|
|
|
|
public: //IChangeableForward
|
|
|
|
virtual bool RemoveFunction(IPluginFunction *func);
|
|
|
|
virtual unsigned int RemoveFunctionsOfPlugin(IPlugin *plugin);
|
|
|
|
virtual bool AddFunction(IPluginFunction *func);
|
2007-01-19 09:22:44 +01:00
|
|
|
virtual bool AddFunction(IPluginContext *ctx, funcid_t index);
|
2006-11-12 02:06:17 +01:00
|
|
|
public:
|
|
|
|
static CForward *CreateForward(const char *name,
|
|
|
|
ExecType et,
|
|
|
|
unsigned int num_params,
|
2007-03-02 10:15:54 +01:00
|
|
|
const ParamType *types,
|
2006-11-12 02:06:17 +01:00
|
|
|
va_list ap);
|
|
|
|
private:
|
|
|
|
void _Int_PushArray(cell_t *inarray, unsigned int cells, int flags);
|
2006-12-06 15:52:11 +01:00
|
|
|
void _Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags);
|
2006-11-12 02:06:17 +01:00
|
|
|
inline int SetError(int err)
|
|
|
|
{
|
|
|
|
m_errstate = err;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
/* :TODO: I want a caching list type here.
|
|
|
|
* Destroying these things and using new/delete for their members feels bad.
|
|
|
|
*/
|
2007-02-11 01:17:54 +01:00
|
|
|
mutable List<IPluginFunction *> m_functions;
|
2007-02-22 03:20:15 +01:00
|
|
|
mutable List<IPluginFunction *> m_paused;
|
2006-11-12 02:06:17 +01:00
|
|
|
|
|
|
|
/* Type and name information */
|
2006-11-12 10:51:39 +01:00
|
|
|
FwdParamInfo m_params[SP_MAX_EXEC_PARAMS];
|
2006-11-12 02:06:17 +01:00
|
|
|
ParamType m_types[SP_MAX_EXEC_PARAMS];
|
|
|
|
char m_name[FORWARDS_NAME_MAX+1];
|
|
|
|
unsigned int m_numparams;
|
2006-11-12 10:51:39 +01:00
|
|
|
unsigned int m_varargs;
|
2006-11-12 02:06:17 +01:00
|
|
|
ExecType m_ExecType;
|
|
|
|
|
|
|
|
/* State information */
|
|
|
|
unsigned int m_curparam;
|
|
|
|
int m_errstate;
|
|
|
|
};
|
|
|
|
|
2006-12-15 14:38:04 +01:00
|
|
|
class CForwardManager :
|
|
|
|
public IForwardManager,
|
|
|
|
public IPluginsListener,
|
|
|
|
public SMGlobalClass
|
2006-11-14 09:45:21 +01:00
|
|
|
{
|
|
|
|
friend class CForward;
|
2006-12-15 14:38:04 +01:00
|
|
|
public: //IForwardManager
|
2007-02-04 23:41:44 +01:00
|
|
|
IForward *CreateForward(const char *name,
|
2006-11-14 09:45:21 +01:00
|
|
|
ExecType et,
|
|
|
|
unsigned int num_params,
|
2007-03-02 10:15:54 +01:00
|
|
|
const ParamType *types,
|
2006-11-14 09:45:21 +01:00
|
|
|
...);
|
2007-02-04 23:41:44 +01:00
|
|
|
IChangeableForward *CreateForwardEx(const char *name,
|
2006-11-14 09:45:21 +01:00
|
|
|
ExecType et,
|
|
|
|
int num_params,
|
2007-03-02 10:15:54 +01:00
|
|
|
const ParamType *types,
|
2006-11-14 09:45:21 +01:00
|
|
|
...);
|
2007-02-04 23:41:44 +01:00
|
|
|
IForward *FindForward(const char *name, IChangeableForward **ifchng);
|
|
|
|
void ReleaseForward(IForward *forward);
|
2006-12-15 14:38:04 +01:00
|
|
|
public: //IPluginsListener
|
2007-02-04 23:41:44 +01:00
|
|
|
void OnPluginLoaded(IPlugin *plugin);
|
|
|
|
void OnPluginUnloaded(IPlugin *plugin);
|
|
|
|
void OnPluginPauseChange(IPlugin *plugin, bool paused);
|
2006-12-15 14:38:04 +01:00
|
|
|
public: //SMGlobalClass
|
2007-02-04 23:41:44 +01:00
|
|
|
void OnSourceModAllInitialized();
|
|
|
|
void OnSourceModShutdown();
|
2006-11-14 09:45:21 +01:00
|
|
|
protected:
|
|
|
|
CForward *ForwardMake();
|
|
|
|
void ForwardFree(CForward *fwd);
|
|
|
|
private:
|
|
|
|
CStack<CForward *> m_FreeForwards;
|
|
|
|
List<CForward *> m_managed;
|
|
|
|
List<CForward *> m_unmanaged;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern CForwardManager g_Forwards;
|
|
|
|
|
2006-11-12 02:06:17 +01:00
|
|
|
#endif //_INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|