3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
20 #define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
24 * @brief Contains wrappers for making Extensions easier to write.
27 #include "smsdk_config.h"
28 #include <IExtensionSys.h>
29 #include <IHandleSys.h>
30 #include <sp_vm_api.h>
31 #include <sm_platform.h>
32 #include <ISourceMod.h>
33 #if defined SMEXT_ENABLE_FORWARDSYS
34 #include <IForwardSys.h>
35 #endif //SMEXT_ENABLE_FORWARDSYS
36 #if defined SMEXT_ENABLE_PLAYERHELPERS
37 #include <IPlayerHelpers.h>
38 #endif //SMEXT_ENABLE_PlAYERHELPERS
39 #if defined SMEXT_ENABLE_DBMANAGER
40 #include <IDBDriver.h>
41 #endif //SMEXT_ENABLE_DBMANAGER
42 #if defined SMEXT_ENABLE_GAMECONF
43 #include <IGameConfigs.h>
45 #if defined SMEXT_ENABLE_MEMUTILS
46 #include <IMemoryUtils.h>
48 #if defined SMEXT_ENABLE_GAMEHELPERS
49 #include <IGameHelpers.h>
51 #if defined SMEXT_ENABLE_TIMERSYS
52 #include <ITimerSystem.h>
55 #if defined SMEXT_CONF_METAMOD
56 #include <ISmmPlugin.h>
60 using namespace SourceMod;
61 using namespace SourcePawn;
64 #if defined SMEXT_CONF_METAMOD
67 public IExtensionInterface
74 * @brief This is called after the initial loading sequence has been processed.
76 * @param error Error message buffer.
77 * @param maxlength Size of error message buffer.
78 * @param late Whether or not the module was loaded after map load.
79 * @return True to succeed loading, false to fail.
81 virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
84 * @brief This is called right before the extension is unloaded.
86 virtual void SDK_OnUnload();
89 * @brief This is called once all known extensions have been loaded.
91 virtual void SDK_OnAllLoaded();
94 * @brief Called when the pause state is changed.
96 virtual void SDK_OnPauseChange(bool paused);
98 #if defined SMEXT_CONF_METAMOD
100 * @brief Called when Metamod is attached, before the extension version is called.
102 * @param error Error buffer.
103 * @param maxlength Maximum size of error buffer.
104 * @param late Whether or not Metamod considers this a late load.
105 * @return True to succeed, false to fail.
107 virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
110 * @brief Called when Metamod is detaching, after the extension version is called.
111 * NOTE: By default this is blocked unless sent from SourceMod.
113 * @param error Error buffer.
114 * @param maxlength Maximum size of error buffer.
115 * @return True to succeed, false to fail.
117 virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
120 * @brief Called when Metamod's pause state is changing.
121 * NOTE: By default this is blocked unless sent from SourceMod.
123 * @param paused Pause state being set.
124 * @param error Error buffer.
125 * @param maxlength Maximum size of error buffer.
126 * @return True to succeed, false to fail.
128 virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
131 public: //IExtensionInterface
132 virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
133 virtual void OnExtensionUnload();
134 virtual void OnExtensionsAllLoaded();
136 /** Returns whether or not this is a Metamod-based extension */
137 virtual bool IsMetamodExtension();
140 * @brief Called when the pause state changes.
142 * @param state True if being paused, false if being unpaused.
144 virtual void OnExtensionPauseChange(bool state);
147 virtual const char *GetExtensionName();
149 virtual const char *GetExtensionURL();
150 /** Returns log tag */
151 virtual const char *GetExtensionTag();
152 /** Returns author */
153 virtual const char *GetExtensionAuthor();
154 /** Returns version string */
155 virtual const char *GetExtensionVerString();
156 /** Returns description string */
157 virtual const char *GetExtensionDescription();
158 /** Returns date string */
159 virtual const char *GetExtensionDateString();
160 #if defined SMEXT_CONF_METAMOD
162 /** Called when the extension is attached to Metamod. */
163 virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
164 /** Returns the author to MM */
165 virtual const char *GetAuthor();
166 /** Returns the name to MM */
167 virtual const char *GetName();
168 /** Returns the description to MM */
169 virtual const char *GetDescription();
170 /** Returns the URL to MM */
171 virtual const char *GetURL();
172 /** Returns the license to MM */
173 virtual const char *GetLicense();
174 /** Returns the version string to MM */
175 virtual const char *GetVersion();
176 /** Returns the date string to MM */
177 virtual const char *GetDate();
178 /** Returns the logtag to MM */
179 virtual const char *GetLogTag();
180 /** Called on unload */
181 virtual bool Unload(char *error, size_t maxlength);
182 /** Called on pause */
183 virtual bool Pause(char *error, size_t maxlength);
184 /** Called on unpause */
185 virtual bool Unpause(char *error, size_t maxlength);
187 bool m_SourceMMLoaded;
188 bool m_WeAreUnloaded;
189 bool m_WeGotPauseChange;
193 extern SDKExtension *g_pExtensionIface;
194 extern IExtension *myself;
196 extern IShareSys *g_pShareSys;
197 extern IShareSys *sharesys; /* Note: Newer name */
198 extern ISourceMod *g_pSM;
199 extern ISourceMod *smutils; /* Note: Newer name */
201 /* Optional interfaces are below */
202 #if defined SMEXT_ENABLE_FORWARDSYS
203 extern IForwardManager *g_pForwards;
204 extern IForwardManager *forwards; /* Note: Newer name */
205 #endif //SMEXT_ENABLE_FORWARDSYS
206 #if defined SMEXT_ENABLE_HANDLESYS
207 extern IHandleSys *g_pHandleSys;
208 extern IHandleSys *handlesys; /* Note: Newer name */
209 #endif //SMEXT_ENABLE_HANDLESYS
210 #if defined SMEXT_ENABLE_PLAYERHELPERS
211 extern IPlayerManager *playerhelpers;
212 #endif //SMEXT_ENABLE_PLAYERHELPERS
213 #if defined SMEXT_ENABLE_DBMANAGER
214 extern IDBManager *dbi;
215 #endif //SMEXT_ENABLE_DBMANAGER
216 #if defined SMEXT_ENABLE_GAMECONF
217 extern IGameConfigManager *gameconfs;
218 #endif //SMEXT_ENABLE_DBMANAGER
219 #if defined SMEXT_ENABLE_MEMUTILS
220 extern IMemoryUtils *memutils;
221 #endif //SMEXT_ENABLE_DBMANAGER
222 #if defined SMEXT_ENABLE_GAMEHELPERS
223 extern IGameHelpers *gamehelpers;
225 #if defined SMEXT_ENABLE_TIMERSYS
226 extern ITimerSystem *timersys;
229 #if defined SMEXT_CONF_METAMOD
231 extern IVEngineServer *engine;
232 extern IServerGameDLL *gamedll;
235 /** Creates a SourceMod interface macro pair */
236 #define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
237 /** Automates retrieving SourceMod interfaces */
238 #define SM_GET_IFACE(prefix, addr) \
239 if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
243 snprintf(error, maxlength, "Could not find interface: %s (version: %d)", SMINTERFACE_##prefix##_NAME, SMINTERFACE_##prefix##_VERSION); \
247 /** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
248 #define SM_GET_LATE_IFACE(prefix, addr) \
249 g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
250 /** Validates a SourceMod interface pointer */
251 #define SM_CHECK_IFACE(prefix, addr) \
256 snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
261 #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_