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>
77 #if defined SMEXT_CONF_METAMOD
78 #include <ISmmPlugin.h>
82 using namespace SourceMod;
83 using namespace SourcePawn;
86 #if defined SMEXT_CONF_METAMOD
89 public IExtensionInterface
96 * @brief This is called after the initial loading sequence has been processed.
98 * @param error Error message buffer.
99 * @param maxlength Size of error message buffer.
100 * @param late Whether or not the module was loaded after map load.
101 * @return True to succeed loading, false to fail.
103 virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
106 * @brief This is called right before the extension is unloaded.
108 virtual void SDK_OnUnload();
111 * @brief This is called once all known extensions have been loaded.
113 virtual void SDK_OnAllLoaded();
116 * @brief Called when the pause state is changed.
118 virtual void SDK_OnPauseChange(bool paused);
120 #if defined SMEXT_CONF_METAMOD
122 * @brief Called when Metamod is attached, before the extension version is called.
124 * @param error Error buffer.
125 * @param maxlength Maximum size of error buffer.
126 * @param late Whether or not Metamod considers this a late load.
127 * @return True to succeed, false to fail.
129 virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
132 * @brief Called when Metamod is detaching, after the extension version is called.
133 * NOTE: By default this is blocked unless sent from SourceMod.
135 * @param error Error buffer.
136 * @param maxlength Maximum size of error buffer.
137 * @return True to succeed, false to fail.
139 virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
142 * @brief Called when Metamod's pause state is changing.
143 * NOTE: By default this is blocked unless sent from SourceMod.
145 * @param paused Pause state being set.
146 * @param error Error buffer.
147 * @param maxlength Maximum size of error buffer.
148 * @return True to succeed, false to fail.
150 virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
153 public: //IExtensionInterface
154 virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
155 virtual void OnExtensionUnload();
156 virtual void OnExtensionsAllLoaded();
158 /** Returns whether or not this is a Metamod-based extension */
159 virtual bool IsMetamodExtension();
162 * @brief Called when the pause state changes.
164 * @param state True if being paused, false if being unpaused.
166 virtual void OnExtensionPauseChange(bool state);
169 virtual const char *GetExtensionName();
171 virtual const char *GetExtensionURL();
172 /** Returns log tag */
173 virtual const char *GetExtensionTag();
174 /** Returns author */
175 virtual const char *GetExtensionAuthor();
176 /** Returns version string */
177 virtual const char *GetExtensionVerString();
178 /** Returns description string */
179 virtual const char *GetExtensionDescription();
180 /** Returns date string */
181 virtual const char *GetExtensionDateString();
182 #if defined SMEXT_CONF_METAMOD
184 /** Called when the extension is attached to Metamod. */
185 virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
186 /** Returns the author to MM */
187 virtual const char *GetAuthor();
188 /** Returns the name to MM */
189 virtual const char *GetName();
190 /** Returns the description to MM */
191 virtual const char *GetDescription();
192 /** Returns the URL to MM */
193 virtual const char *GetURL();
194 /** Returns the license to MM */
195 virtual const char *GetLicense();
196 /** Returns the version string to MM */
197 virtual const char *GetVersion();
198 /** Returns the date string to MM */
199 virtual const char *GetDate();
200 /** Returns the logtag to MM */
201 virtual const char *GetLogTag();
202 /** Called on unload */
203 virtual bool Unload(char *error, size_t maxlength);
204 /** Called on pause */
205 virtual bool Pause(char *error, size_t maxlength);
206 /** Called on unpause */
207 virtual bool Unpause(char *error, size_t maxlength);
209 bool m_SourceMMLoaded;
210 bool m_WeAreUnloaded;
211 bool m_WeGotPauseChange;
215 extern SDKExtension *g_pExtensionIface;
216 extern IExtension *myself;
218 extern IShareSys *g_pShareSys;
219 extern IShareSys *sharesys; /* Note: Newer name */
220 extern ISourceMod *g_pSM;
221 extern ISourceMod *smutils; /* Note: Newer name */
223 /* Optional interfaces are below */
224 #if defined SMEXT_ENABLE_FORWARDSYS
225 extern IForwardManager *g_pForwards;
226 extern IForwardManager *forwards; /* Note: Newer name */
227 #endif //SMEXT_ENABLE_FORWARDSYS
228 #if defined SMEXT_ENABLE_HANDLESYS
229 extern IHandleSys *g_pHandleSys;
230 extern IHandleSys *handlesys; /* Note: Newer name */
231 #endif //SMEXT_ENABLE_HANDLESYS
232 #if defined SMEXT_ENABLE_PLAYERHELPERS
233 extern IPlayerManager *playerhelpers;
234 #endif //SMEXT_ENABLE_PLAYERHELPERS
235 #if defined SMEXT_ENABLE_DBMANAGER
236 extern IDBManager *dbi;
237 #endif //SMEXT_ENABLE_DBMANAGER
238 #if defined SMEXT_ENABLE_GAMECONF
239 extern IGameConfigManager *gameconfs;
240 #endif //SMEXT_ENABLE_DBMANAGER
241 #if defined SMEXT_ENABLE_MEMUTILS
242 extern IMemoryUtils *memutils;
244 #if defined SMEXT_ENABLE_GAMEHELPERS
245 extern IGameHelpers *gamehelpers;
247 #if defined SMEXT_ENABLE_TIMERSYS
248 extern ITimerSystem *timersys;
250 #if defined SMEXT_ENABLE_ADTFACTORY
251 extern IADTFactory *adtfactory;
253 #if defined SMEXT_ENABLE_THREADER
254 extern IThreader *threader;
256 #if defined SMEXT_ENABLE_LIBSYS
257 extern ILibrarySys *libsys;
260 #if defined SMEXT_CONF_METAMOD
262 extern IVEngineServer *engine;
263 extern IServerGameDLL *gamedll;
266 /** Creates a SourceMod interface macro pair */
267 #define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
268 /** Automates retrieving SourceMod interfaces */
269 #define SM_GET_IFACE(prefix, addr) \
270 if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
272 if (error != NULL && maxlength) \
274 size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
275 if (len >= maxlength) \
277 error[maxlength - 1] = '\0'; \
282 /** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
283 #define SM_GET_LATE_IFACE(prefix, addr) \
284 g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
285 /** Validates a SourceMod interface pointer */
286 #define SM_CHECK_IFACE(prefix, addr) \
289 if (error != NULL && maxlength) \
291 size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
292 if (len >= maxlength) \
294 error[maxlength - 1] = '\0'; \
300 #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_