3 * =============================================================================
4 * SourceMod Base Extension Code
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_EXTENSION_BASESDK_H_
33 #define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
37 * @brief Contains wrappers for making Extensions easier to write.
40 #include "smsdk_config.h"
41 #include <IExtensionSys.h>
42 #include <IHandleSys.h>
43 #include <sp_vm_api.h>
44 #include <sm_platform.h>
45 #include <ISourceMod.h>
46 #if defined SMEXT_ENABLE_FORWARDSYS
47 #include <IForwardSys.h>
48 #endif //SMEXT_ENABLE_FORWARDSYS
49 #if defined SMEXT_ENABLE_PLAYERHELPERS
50 #include <IPlayerHelpers.h>
51 #endif //SMEXT_ENABLE_PlAYERHELPERS
52 #if defined SMEXT_ENABLE_DBMANAGER
53 #include <IDBDriver.h>
54 #endif //SMEXT_ENABLE_DBMANAGER
55 #if defined SMEXT_ENABLE_GAMECONF
56 #include <IGameConfigs.h>
58 #if defined SMEXT_ENABLE_MEMUTILS
59 #include <IMemoryUtils.h>
61 #if defined SMEXT_ENABLE_GAMEHELPERS
62 #include <IGameHelpers.h>
64 #if defined SMEXT_ENABLE_TIMERSYS
65 #include <ITimerSystem.h>
67 #if defined SMEXT_ENABLE_ADTFACTORY
68 #include <IADTFactory.h>
70 #if defined SMEXT_ENABLE_THREADER
71 #include <IThreader.h>
73 #if defined SMEXT_ENABLE_LIBSYS
74 #include <ILibrarySys.h>
76 #if defined SMEXT_ENABLE_PLUGINSYS
77 #include <IPluginSys.h>
79 #if defined SMEXT_ENABLE_MENUS
80 #include <IMenuManager.h>
82 #if defined SMEXT_ENABLE_ADMINSYS
83 #include <IAdminSystem.h>
85 #if defined SMEXT_ENABLE_TEXTPARSERS
86 #include <ITextParsers.h>
88 #if defined SMEXT_ENABLE_USERMSGS
89 #include <IUserMessages.h>
91 #if defined SMEXT_ENABLE_TRANSLATOR
92 #include <ITranslator.h>
95 #if defined SMEXT_CONF_METAMOD
96 #include <ISmmPlugin.h>
100 using namespace SourceMod;
101 using namespace SourcePawn;
104 #if defined SMEXT_CONF_METAMOD
107 public IExtensionInterface
114 * @brief This is called after the initial loading sequence has been processed.
116 * @param error Error message buffer.
117 * @param maxlength Size of error message buffer.
118 * @param late Whether or not the module was loaded after map load.
119 * @return True to succeed loading, false to fail.
121 virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
124 * @brief This is called right before the extension is unloaded.
126 virtual void SDK_OnUnload();
129 * @brief This is called once all known extensions have been loaded.
131 virtual void SDK_OnAllLoaded();
134 * @brief Called when the pause state is changed.
136 virtual void SDK_OnPauseChange(bool paused);
138 #if defined SMEXT_CONF_METAMOD
140 * @brief Called when Metamod is attached, before the extension version is called.
142 * @param error Error buffer.
143 * @param maxlength Maximum size of error buffer.
144 * @param late Whether or not Metamod considers this a late load.
145 * @return True to succeed, false to fail.
147 virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
150 * @brief Called when Metamod is detaching, after the extension version is called.
151 * NOTE: By default this is blocked unless sent from SourceMod.
153 * @param error Error buffer.
154 * @param maxlength Maximum size of error buffer.
155 * @return True to succeed, false to fail.
157 virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
160 * @brief Called when Metamod's pause state is changing.
161 * NOTE: By default this is blocked unless sent from SourceMod.
163 * @param paused Pause state being set.
164 * @param error Error buffer.
165 * @param maxlength Maximum size of error buffer.
166 * @return True to succeed, false to fail.
168 virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
171 public: //IExtensionInterface
172 virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
173 virtual void OnExtensionUnload();
174 virtual void OnExtensionsAllLoaded();
176 /** Returns whether or not this is a Metamod-based extension */
177 virtual bool IsMetamodExtension();
180 * @brief Called when the pause state changes.
182 * @param state True if being paused, false if being unpaused.
184 virtual void OnExtensionPauseChange(bool state);
187 virtual const char *GetExtensionName();
189 virtual const char *GetExtensionURL();
190 /** Returns log tag */
191 virtual const char *GetExtensionTag();
192 /** Returns author */
193 virtual const char *GetExtensionAuthor();
194 /** Returns version string */
195 virtual const char *GetExtensionVerString();
196 /** Returns description string */
197 virtual const char *GetExtensionDescription();
198 /** Returns date string */
199 virtual const char *GetExtensionDateString();
200 #if defined SMEXT_CONF_METAMOD
202 /** Called when the extension is attached to Metamod. */
203 virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
204 /** Returns the author to MM */
205 virtual const char *GetAuthor();
206 /** Returns the name to MM */
207 virtual const char *GetName();
208 /** Returns the description to MM */
209 virtual const char *GetDescription();
210 /** Returns the URL to MM */
211 virtual const char *GetURL();
212 /** Returns the license to MM */
213 virtual const char *GetLicense();
214 /** Returns the version string to MM */
215 virtual const char *GetVersion();
216 /** Returns the date string to MM */
217 virtual const char *GetDate();
218 /** Returns the logtag to MM */
219 virtual const char *GetLogTag();
220 /** Called on unload */
221 virtual bool Unload(char *error, size_t maxlength);
222 /** Called on pause */
223 virtual bool Pause(char *error, size_t maxlength);
224 /** Called on unpause */
225 virtual bool Unpause(char *error, size_t maxlength);
227 bool m_SourceMMLoaded;
228 bool m_WeAreUnloaded;
229 bool m_WeGotPauseChange;
233 extern SDKExtension *g_pExtensionIface;
234 extern IExtension *myself;
236 extern IShareSys *g_pShareSys;
237 extern IShareSys *sharesys; /* Note: Newer name */
238 extern ISourceMod *g_pSM;
239 extern ISourceMod *smutils; /* Note: Newer name */
241 /* Optional interfaces are below */
242 #if defined SMEXT_ENABLE_FORWARDSYS
243 extern IForwardManager *g_pForwards;
244 extern IForwardManager *forwards; /* Note: Newer name */
245 #endif //SMEXT_ENABLE_FORWARDSYS
246 #if defined SMEXT_ENABLE_HANDLESYS
247 extern IHandleSys *g_pHandleSys;
248 extern IHandleSys *handlesys; /* Note: Newer name */
249 #endif //SMEXT_ENABLE_HANDLESYS
250 #if defined SMEXT_ENABLE_PLAYERHELPERS
251 extern IPlayerManager *playerhelpers;
252 #endif //SMEXT_ENABLE_PLAYERHELPERS
253 #if defined SMEXT_ENABLE_DBMANAGER
254 extern IDBManager *dbi;
255 #endif //SMEXT_ENABLE_DBMANAGER
256 #if defined SMEXT_ENABLE_GAMECONF
257 extern IGameConfigManager *gameconfs;
258 #endif //SMEXT_ENABLE_DBMANAGER
259 #if defined SMEXT_ENABLE_MEMUTILS
260 extern IMemoryUtils *memutils;
262 #if defined SMEXT_ENABLE_GAMEHELPERS
263 extern IGameHelpers *gamehelpers;
265 #if defined SMEXT_ENABLE_TIMERSYS
266 extern ITimerSystem *timersys;
268 #if defined SMEXT_ENABLE_ADTFACTORY
269 extern IADTFactory *adtfactory;
271 #if defined SMEXT_ENABLE_THREADER
272 extern IThreader *threader;
274 #if defined SMEXT_ENABLE_LIBSYS
275 extern ILibrarySys *libsys;
277 #if defined SMEXT_ENABLE_PLUGINSYS
278 extern SourceMod::IPluginManager *plsys;
280 #if defined SMEXT_ENABLE_MENUS
281 extern IMenuManager *menus;
283 #if defined SMEXT_ENABLE_ADMINSYS
284 extern IAdminSystem *adminsys;
286 #if defined SMEXT_ENABLE_USERMSGS
287 extern IUserMessages *usermsgs;
289 #if defined SMEXT_ENABLE_TRANSLATOR
290 extern ITranslator *translator;
293 #if defined SMEXT_CONF_METAMOD
295 extern IVEngineServer *engine;
296 extern IServerGameDLL *gamedll;
299 /** Creates a SourceMod interface macro pair */
300 #define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
301 /** Automates retrieving SourceMod interfaces */
302 #define SM_GET_IFACE(prefix, addr) \
303 if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
305 if (error != NULL && maxlength) \
307 size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
308 if (len >= maxlength) \
310 error[maxlength - 1] = '\0'; \
315 /** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
316 #define SM_GET_LATE_IFACE(prefix, addr) \
317 g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
318 /** Validates a SourceMod interface pointer */
319 #define SM_CHECK_IFACE(prefix, addr) \
322 if (error != NULL && maxlength) \
324 size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
325 if (len >= maxlength) \
327 error[maxlength - 1] = '\0'; \
333 #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_