|
ds@757
|
1 |
/** |
|
ds@757
|
2 |
* vim: set ts=4 : |
|
ds@1330
|
3 |
* ============================================================================= |
|
ds@1330
|
4 |
* SourceMod Base Extension Code |
|
ds@1947
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1330
|
6 |
* ============================================================================= |
|
ds@757
|
7 |
* |
|
ds@1330
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1330
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1330
|
10 |
* Free Software Foundation. |
|
ds@757
|
11 |
* |
|
ds@1330
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1330
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1330
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1330
|
15 |
* details. |
|
dvander@1226
|
16 |
* |
|
ds@1330
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1330
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
dvander@1226
|
19 |
* |
|
ds@1330
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1330
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1330
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1330
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1330
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1330
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1330
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1330
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@757
|
28 |
* |
|
ds@757
|
29 |
* Version: $Id$ |
|
ds@757
|
30 |
*/ |
|
ds@757
|
31 |
|
|
ds@757
|
32 |
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ |
|
ds@757
|
33 |
#define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ |
|
ds@757
|
34 |
|
|
ds@757
|
35 |
/** |
|
ds@757
|
36 |
* @file smsdk_ext.h |
|
ds@757
|
37 |
* @brief Contains wrappers for making Extensions easier to write. |
|
ds@757
|
38 |
*/ |
|
ds@757
|
39 |
|
|
ds@757
|
40 |
#include "smsdk_config.h" |
|
ds@757
|
41 |
#include <IExtensionSys.h> |
|
ds@757
|
42 |
#include <IHandleSys.h> |
|
ds@757
|
43 |
#include <sp_vm_api.h> |
|
ds@757
|
44 |
#include <sm_platform.h> |
|
ds@757
|
45 |
#include <ISourceMod.h> |
|
dvander@943
|
46 |
#if defined SMEXT_ENABLE_FORWARDSYS |
|
ds@757
|
47 |
#include <IForwardSys.h> |
|
dvander@943
|
48 |
#endif //SMEXT_ENABLE_FORWARDSYS |
|
dvander@943
|
49 |
#if defined SMEXT_ENABLE_PLAYERHELPERS |
|
dvander@943
|
50 |
#include <IPlayerHelpers.h> |
|
dvander@943
|
51 |
#endif //SMEXT_ENABLE_PlAYERHELPERS |
|
dvander@943
|
52 |
#if defined SMEXT_ENABLE_DBMANAGER |
|
dvander@943
|
53 |
#include <IDBDriver.h> |
|
dvander@943
|
54 |
#endif //SMEXT_ENABLE_DBMANAGER |
|
dvander@943
|
55 |
#if defined SMEXT_ENABLE_GAMECONF |
|
dvander@943
|
56 |
#include <IGameConfigs.h> |
|
dvander@943
|
57 |
#endif |
|
dvander@1226
|
58 |
#if defined SMEXT_ENABLE_MEMUTILS |
|
dvander@1226
|
59 |
#include <IMemoryUtils.h> |
|
dvander@1226
|
60 |
#endif |
|
dvander@1226
|
61 |
#if defined SMEXT_ENABLE_GAMEHELPERS |
|
dvander@1226
|
62 |
#include <IGameHelpers.h> |
|
dvander@1226
|
63 |
#endif |
|
dvander@1226
|
64 |
#if defined SMEXT_ENABLE_TIMERSYS |
|
dvander@1226
|
65 |
#include <ITimerSystem.h> |
|
dvander@1226
|
66 |
#endif |
|
dvander@1226
|
67 |
#if defined SMEXT_ENABLE_ADTFACTORY |
|
dvander@1226
|
68 |
#include <IADTFactory.h> |
|
dvander@1226
|
69 |
#endif |
|
dvander@1226
|
70 |
#if defined SMEXT_ENABLE_THREADER |
|
dvander@1226
|
71 |
#include <IThreader.h> |
|
dvander@1226
|
72 |
#endif |
|
dvander@1226
|
73 |
#if defined SMEXT_ENABLE_LIBSYS |
|
dvander@1226
|
74 |
#include <ILibrarySys.h> |
|
dvander@1226
|
75 |
#endif |
|
pred@2504
|
76 |
#if defined SMEXT_ENABLE_PLUGINSYS |
|
pred@2504
|
77 |
#include <IPluginSys.h> |
|
pred@2504
|
78 |
#endif |
|
pred@2504
|
79 |
#if defined SMEXT_ENABLE_MENUS |
|
pred@2504
|
80 |
#include <IMenuManager.h> |
|
pred@2504
|
81 |
#endif |
|
pred@2504
|
82 |
#if defined SMEXT_ENABLE_ADMINSYS |
|
pred@2504
|
83 |
#include <IAdminSystem.h> |
|
pred@2504
|
84 |
#endif |
|
pred@2504
|
85 |
#if defined SMEXT_ENABLE_TEXTPARSERS |
|
pred@2504
|
86 |
#include <ITextParsers.h> |
|
pred@2504
|
87 |
#endif |
|
pred@2504
|
88 |
#if defined SMEXT_ENABLE_USERMSGS |
|
pred@2504
|
89 |
#include <IUserMessages.h> |
|
pred@2504
|
90 |
#endif |
|
pred@2504
|
91 |
#if defined SMEXT_ENABLE_TRANSLATOR |
|
pred@2504
|
92 |
#include <ITranslator.h> |
|
pred@2504
|
93 |
#endif |
|
ds@757
|
94 |
|
|
ds@757
|
95 |
#if defined SMEXT_CONF_METAMOD |
|
ds@757
|
96 |
#include <ISmmPlugin.h> |
|
ds@757
|
97 |
#include <eiface.h> |
|
ds@757
|
98 |
#endif |
|
ds@757
|
99 |
|
|
ds@757
|
100 |
using namespace SourceMod; |
|
ds@757
|
101 |
using namespace SourcePawn; |
|
ds@757
|
102 |
|
|
ds@757
|
103 |
class SDKExtension : |
|
ds@757
|
104 |
#if defined SMEXT_CONF_METAMOD |
|
ds@757
|
105 |
public ISmmPlugin, |
|
ds@757
|
106 |
#endif |
|
ds@757
|
107 |
public IExtensionInterface |
|
ds@757
|
108 |
{ |
|
ds@757
|
109 |
public: |
|
ds@757
|
110 |
/** Constructor */ |
|
ds@757
|
111 |
SDKExtension(); |
|
ds@757
|
112 |
public: |
|
ds@757
|
113 |
/** |
|
ds@757
|
114 |
* @brief This is called after the initial loading sequence has been processed. |
|
ds@757
|
115 |
* |
|
ds@757
|
116 |
* @param error Error message buffer. |
|
ds@757
|
117 |
* @param maxlength Size of error message buffer. |
|
ds@757
|
118 |
* @param late Whether or not the module was loaded after map load. |
|
ds@757
|
119 |
* @return True to succeed loading, false to fail. |
|
ds@757
|
120 |
*/ |
|
ds@757
|
121 |
virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); |
|
ds@757
|
122 |
|
|
ds@757
|
123 |
/** |
|
ds@757
|
124 |
* @brief This is called right before the extension is unloaded. |
|
ds@757
|
125 |
*/ |
|
ds@757
|
126 |
virtual void SDK_OnUnload(); |
|
ds@757
|
127 |
|
|
ds@757
|
128 |
/** |
|
ds@757
|
129 |
* @brief This is called once all known extensions have been loaded. |
|
ds@757
|
130 |
*/ |
|
ds@757
|
131 |
virtual void SDK_OnAllLoaded(); |
|
ds@757
|
132 |
|
|
ds@757
|
133 |
/** |
|
ds@757
|
134 |
* @brief Called when the pause state is changed. |
|
ds@757
|
135 |
*/ |
|
ds@757
|
136 |
virtual void SDK_OnPauseChange(bool paused); |
|
ds@757
|
137 |
|
|
ds@757
|
138 |
#if defined SMEXT_CONF_METAMOD |
|
ds@757
|
139 |
/** |
|
ds@757
|
140 |
* @brief Called when Metamod is attached, before the extension version is called. |
|
ds@757
|
141 |
* |
|
ds@757
|
142 |
* @param error Error buffer. |
|
ds@757
|
143 |
* @param maxlength Maximum size of error buffer. |
|
ds@757
|
144 |
* @param late Whether or not Metamod considers this a late load. |
|
ds@757
|
145 |
* @return True to succeed, false to fail. |
|
ds@757
|
146 |
*/ |
|
ds@757
|
147 |
virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); |
|
ds@757
|
148 |
|
|
ds@757
|
149 |
/** |
|
ds@757
|
150 |
* @brief Called when Metamod is detaching, after the extension version is called. |
|
ds@757
|
151 |
* NOTE: By default this is blocked unless sent from SourceMod. |
|
ds@757
|
152 |
* |
|
ds@757
|
153 |
* @param error Error buffer. |
|
ds@757
|
154 |
* @param maxlength Maximum size of error buffer. |
|
ds@757
|
155 |
* @return True to succeed, false to fail. |
|
ds@757
|
156 |
*/ |
|
ds@757
|
157 |
virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); |
|
ds@757
|
158 |
|
|
ds@757
|
159 |
/** |
|
ds@757
|
160 |
* @brief Called when Metamod's pause state is changing. |
|
ds@757
|
161 |
* NOTE: By default this is blocked unless sent from SourceMod. |
|
ds@757
|
162 |
* |
|
ds@757
|
163 |
* @param paused Pause state being set. |
|
ds@757
|
164 |
* @param error Error buffer. |
|
ds@757
|
165 |
* @param maxlength Maximum size of error buffer. |
|
ds@757
|
166 |
* @return True to succeed, false to fail. |
|
ds@757
|
167 |
*/ |
|
ds@757
|
168 |
virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); |
|
ds@757
|
169 |
#endif |
|
ds@757
|
170 |
|
|
dvander@943
|
171 |
public: //IExtensionInterface |
|
ds@757
|
172 |
virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late); |
|
ds@757
|
173 |
virtual void OnExtensionUnload(); |
|
ds@757
|
174 |
virtual void OnExtensionsAllLoaded(); |
|
ds@757
|
175 |
|
|
ds@757
|
176 |
/** Returns whether or not this is a Metamod-based extension */ |
|
ds@757
|
177 |
virtual bool IsMetamodExtension(); |
|
ds@757
|
178 |
|
|
ds@757
|
179 |
/** |
|
ds@757
|
180 |
* @brief Called when the pause state changes. |
|
ds@757
|
181 |
* |
|
ds@757
|
182 |
* @param state True if being paused, false if being unpaused. |
|
ds@757
|
183 |
*/ |
|
ds@757
|
184 |
virtual void OnExtensionPauseChange(bool state); |
|
ds@757
|
185 |
|
|
ds@757
|
186 |
/** Returns name */ |
|
ds@757
|
187 |
virtual const char *GetExtensionName(); |
|
ds@757
|
188 |
/** Returns URL */ |
|
ds@757
|
189 |
virtual const char *GetExtensionURL(); |
|
ds@757
|
190 |
/** Returns log tag */ |
|
ds@757
|
191 |
virtual const char *GetExtensionTag(); |
|
ds@757
|
192 |
/** Returns author */ |
|
ds@757
|
193 |
virtual const char *GetExtensionAuthor(); |
|
ds@757
|
194 |
/** Returns version string */ |
|
ds@757
|
195 |
virtual const char *GetExtensionVerString(); |
|
ds@757
|
196 |
/** Returns description string */ |
|
ds@757
|
197 |
virtual const char *GetExtensionDescription(); |
|
ds@757
|
198 |
/** Returns date string */ |
|
ds@757
|
199 |
virtual const char *GetExtensionDateString(); |
|
ds@757
|
200 |
#if defined SMEXT_CONF_METAMOD |
|
dvander@943
|
201 |
public: //ISmmPlugin |
|
ds@757
|
202 |
/** Called when the extension is attached to Metamod. */ |
|
dvander@943
|
203 |
virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late); |
|
ds@757
|
204 |
/** Returns the author to MM */ |
|
ds@757
|
205 |
virtual const char *GetAuthor(); |
|
ds@757
|
206 |
/** Returns the name to MM */ |
|
ds@757
|
207 |
virtual const char *GetName(); |
|
ds@757
|
208 |
/** Returns the description to MM */ |
|
ds@757
|
209 |
virtual const char *GetDescription(); |
|
ds@757
|
210 |
/** Returns the URL to MM */ |
|
ds@757
|
211 |
virtual const char *GetURL(); |
|
ds@757
|
212 |
/** Returns the license to MM */ |
|
ds@757
|
213 |
virtual const char *GetLicense(); |
|
ds@757
|
214 |
/** Returns the version string to MM */ |
|
ds@757
|
215 |
virtual const char *GetVersion(); |
|
ds@757
|
216 |
/** Returns the date string to MM */ |
|
ds@757
|
217 |
virtual const char *GetDate(); |
|
ds@757
|
218 |
/** Returns the logtag to MM */ |
|
ds@757
|
219 |
virtual const char *GetLogTag(); |
|
ds@757
|
220 |
/** Called on unload */ |
|
dvander@943
|
221 |
virtual bool Unload(char *error, size_t maxlength); |
|
ds@757
|
222 |
/** Called on pause */ |
|
dvander@943
|
223 |
virtual bool Pause(char *error, size_t maxlength); |
|
ds@757
|
224 |
/** Called on unpause */ |
|
dvander@943
|
225 |
virtual bool Unpause(char *error, size_t maxlength); |
|
ds@757
|
226 |
private: |
|
ds@757
|
227 |
bool m_SourceMMLoaded; |
|
ds@757
|
228 |
bool m_WeAreUnloaded; |
|
ds@757
|
229 |
bool m_WeGotPauseChange; |
|
ds@757
|
230 |
#endif |
|
ds@757
|
231 |
}; |
|
ds@757
|
232 |
|
|
ds@757
|
233 |
extern SDKExtension *g_pExtensionIface; |
|
dvander@943
|
234 |
extern IExtension *myself; |
|
ds@757
|
235 |
|
|
ds@757
|
236 |
extern IShareSys *g_pShareSys; |
|
dvander@943
|
237 |
extern IShareSys *sharesys; /* Note: Newer name */ |
|
dvander@943
|
238 |
extern ISourceMod *g_pSM; |
|
dvander@943
|
239 |
extern ISourceMod *smutils; /* Note: Newer name */ |
|
dvander@943
|
240 |
|
|
dvander@943
|
241 |
/* Optional interfaces are below */ |
|
dvander@943
|
242 |
#if defined SMEXT_ENABLE_FORWARDSYS |
|
dvander@943
|
243 |
extern IForwardManager *g_pForwards; |
|
dvander@943
|
244 |
extern IForwardManager *forwards; /* Note: Newer name */ |
|
dvander@943
|
245 |
#endif //SMEXT_ENABLE_FORWARDSYS |
|
dvander@943
|
246 |
#if defined SMEXT_ENABLE_HANDLESYS |
|
ds@757
|
247 |
extern IHandleSys *g_pHandleSys; |
|
dvander@943
|
248 |
extern IHandleSys *handlesys; /* Note: Newer name */ |
|
dvander@943
|
249 |
#endif //SMEXT_ENABLE_HANDLESYS |
|
dvander@943
|
250 |
#if defined SMEXT_ENABLE_PLAYERHELPERS |
|
dvander@943
|
251 |
extern IPlayerManager *playerhelpers; |
|
dvander@943
|
252 |
#endif //SMEXT_ENABLE_PLAYERHELPERS |
|
dvander@943
|
253 |
#if defined SMEXT_ENABLE_DBMANAGER |
|
dvander@943
|
254 |
extern IDBManager *dbi; |
|
dvander@943
|
255 |
#endif //SMEXT_ENABLE_DBMANAGER |
|
dvander@943
|
256 |
#if defined SMEXT_ENABLE_GAMECONF |
|
dvander@943
|
257 |
extern IGameConfigManager *gameconfs; |
|
dvander@943
|
258 |
#endif //SMEXT_ENABLE_DBMANAGER |
|
dvander@1226
|
259 |
#if defined SMEXT_ENABLE_MEMUTILS |
|
dvander@1226
|
260 |
extern IMemoryUtils *memutils; |
|
dvander@1226
|
261 |
#endif |
|
dvander@1226
|
262 |
#if defined SMEXT_ENABLE_GAMEHELPERS |
|
dvander@1226
|
263 |
extern IGameHelpers *gamehelpers; |
|
dvander@1226
|
264 |
#endif |
|
dvander@1226
|
265 |
#if defined SMEXT_ENABLE_TIMERSYS |
|
dvander@1226
|
266 |
extern ITimerSystem *timersys; |
|
dvander@1226
|
267 |
#endif |
|
dvander@1226
|
268 |
#if defined SMEXT_ENABLE_ADTFACTORY |
|
dvander@1226
|
269 |
extern IADTFactory *adtfactory; |
|
dvander@1226
|
270 |
#endif |
|
dvander@1226
|
271 |
#if defined SMEXT_ENABLE_THREADER |
|
dvander@1226
|
272 |
extern IThreader *threader; |
|
dvander@1226
|
273 |
#endif |
|
dvander@1226
|
274 |
#if defined SMEXT_ENABLE_LIBSYS |
|
dvander@1226
|
275 |
extern ILibrarySys *libsys; |
|
dvander@1226
|
276 |
#endif |
|
pred@2504
|
277 |
#if defined SMEXT_ENABLE_PLUGINSYS |
|
pred@2504
|
278 |
extern SourceMod::IPluginManager *plsys; |
|
pred@2504
|
279 |
#endif |
|
pred@2504
|
280 |
#if defined SMEXT_ENABLE_MENUS |
|
pred@2504
|
281 |
extern IMenuManager *menus; |
|
pred@2504
|
282 |
#endif |
|
pred@2504
|
283 |
#if defined SMEXT_ENABLE_ADMINSYS |
|
pred@2504
|
284 |
extern IAdminSystem *adminsys; |
|
pred@2504
|
285 |
#endif |
|
pred@2504
|
286 |
#if defined SMEXT_ENABLE_USERMSGS |
|
pred@2504
|
287 |
extern IUserMessages *usermsgs; |
|
pred@2504
|
288 |
#endif |
|
pred@2504
|
289 |
#if defined SMEXT_ENABLE_TRANSLATOR |
|
pred@2504
|
290 |
extern ITranslator *translator; |
|
pred@2504
|
291 |
#endif |
|
ds@757
|
292 |
|
|
ds@757
|
293 |
#if defined SMEXT_CONF_METAMOD |
|
ds@757
|
294 |
PLUGIN_GLOBALVARS(); |
|
ds@757
|
295 |
extern IVEngineServer *engine; |
|
ds@757
|
296 |
extern IServerGameDLL *gamedll; |
|
ds@757
|
297 |
#endif |
|
ds@757
|
298 |
|
|
ds@757
|
299 |
/** Creates a SourceMod interface macro pair */ |
|
ds@757
|
300 |
#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION |
|
ds@757
|
301 |
/** Automates retrieving SourceMod interfaces */ |
|
ds@757
|
302 |
#define SM_GET_IFACE(prefix, addr) \ |
|
ds@757
|
303 |
if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \ |
|
ds@757
|
304 |
{ \ |
|
dvander@1650
|
305 |
if (error != NULL && maxlength) \ |
|
ds@757
|
306 |
{ \ |
|
dvander@1650
|
307 |
size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ |
|
dvander@1650
|
308 |
if (len >= maxlength) \ |
|
dvander@1650
|
309 |
{ \ |
|
dvander@1650
|
310 |
error[maxlength - 1] = '\0'; \ |
|
dvander@1650
|
311 |
} \ |
|
ds@757
|
312 |
} \ |
|
dvander@1650
|
313 |
return false; \ |
|
ds@757
|
314 |
} |
|
ds@757
|
315 |
/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */ |
|
ds@757
|
316 |
#define SM_GET_LATE_IFACE(prefix, addr) \ |
|
ds@757
|
317 |
g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr) |
|
ds@757
|
318 |
/** Validates a SourceMod interface pointer */ |
|
ds@757
|
319 |
#define SM_CHECK_IFACE(prefix, addr) \ |
|
ds@757
|
320 |
if (!addr) \ |
|
ds@757
|
321 |
{ \ |
|
dvander@1650
|
322 |
if (error != NULL && maxlength) \ |
|
ds@757
|
323 |
{ \ |
|
dvander@1650
|
324 |
size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ |
|
dvander@1650
|
325 |
if (len >= maxlength) \ |
|
dvander@1650
|
326 |
{ \ |
|
dvander@1650
|
327 |
error[maxlength - 1] = '\0'; \ |
|
dvander@1650
|
328 |
} \ |
|
ds@757
|
329 |
} \ |
|
dvander@1650
|
330 |
return false; \ |
|
ds@757
|
331 |
} |
|
ds@757
|
332 |
|
|
ds@757
|
333 |
#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ |