3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
33 #define _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
35 #include <IForwardSys.h>
36 #include <IPluginSys.h>
37 #include "sm_globals.h"
40 #include "sourcemod.h"
42 using namespace SourceHook;
44 typedef List<IPluginFunction *>::iterator FuncIter;
46 /* :TODO: a global name max define for sourcepawn, should mirror compiler's sNAMEMAX */
47 #define FORWARDS_NAME_MAX 64
64 class CForward : public IChangeableForward
67 virtual int PushCell(cell_t cell);
68 virtual int PushCellByRef(cell_t *cell, int flags);
69 virtual int PushFloat(float number);
70 virtual int PushFloatByRef(float *number, int flags);
71 virtual int PushArray(cell_t *inarray, unsigned int cells, int flags);
72 virtual int PushString(const char *string);
73 virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
74 virtual void Cancel();
76 virtual const char *GetForwardName();
77 virtual unsigned int GetFunctionCount();
78 virtual ExecType GetExecType();
79 virtual int Execute(cell_t *result, IForwardFilter *filter);
80 public: //IChangeableForward
81 virtual bool RemoveFunction(IPluginFunction *func);
82 virtual unsigned int RemoveFunctionsOfPlugin(IPlugin *plugin);
83 virtual bool AddFunction(IPluginFunction *func);
84 virtual bool AddFunction(IPluginContext *ctx, funcid_t index);
85 virtual bool RemoveFunction(IPluginContext *ctx, funcid_t index);
87 static CForward *CreateForward(const char *name,
89 unsigned int num_params,
90 const ParamType *types,
93 void _Int_PushArray(cell_t *inarray, unsigned int cells, int flags);
94 void _Int_PushString(cell_t *inarray, unsigned int cells, int sz_flags, int cp_flags);
95 inline int SetError(int err)
101 /* :TODO: I want a caching list type here.
102 * Destroying these things and using new/delete for their members feels bad.
104 mutable List<IPluginFunction *> m_functions;
105 mutable List<IPluginFunction *> m_paused;
107 /* Type and name information */
108 FwdParamInfo m_params[SP_MAX_EXEC_PARAMS];
109 ParamType m_types[SP_MAX_EXEC_PARAMS];
110 char m_name[FORWARDS_NAME_MAX+1];
111 unsigned int m_numparams;
112 unsigned int m_varargs;
115 /* State information */
116 unsigned int m_curparam;
120 class CForwardManager :
121 public IForwardManager,
122 public IPluginsListener,
125 friend class CForward;
128 public: //IForwardManager
129 IForward *CreateForward(const char *name,
131 unsigned int num_params,
132 const ParamType *types,
134 IChangeableForward *CreateForwardEx(const char *name,
137 const ParamType *types,
139 IForward *FindForward(const char *name, IChangeableForward **ifchng);
140 void ReleaseForward(IForward *forward);
141 public: //IPluginsListener
142 void OnPluginLoaded(IPlugin *plugin);
143 void OnPluginUnloaded(IPlugin *plugin);
144 void OnPluginPauseChange(IPlugin *plugin, bool paused);
145 public: //SMGlobalClass
146 void OnSourceModAllInitialized();
148 CForward *ForwardMake();
149 void ForwardFree(CForward *fwd);
151 CStack<CForward *> m_FreeForwards;
152 List<CForward *> m_managed;
153 List<CForward *> m_unmanaged;
156 extern CForwardManager g_Forwards;
158 #endif //_INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_