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 used
9 * or modified under the Terms and Conditions of its License Agreement, which is found
10 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
11 * may change at any time. To view the latest information, see:
12 * http://www.sourcemod.net/license.php
17 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
18 #define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
22 * @brief Contains wrappers for making Extensions easier to write.
25 #include "smsdk_config.h"
26 #include <IExtensionSys.h>
27 #include <IHandleSys.h>
28 #include <sp_vm_api.h>
29 #include <sm_platform.h>
30 #include <ISourceMod.h>
31 #include <IForwardSys.h>
33 #if defined SMEXT_CONF_METAMOD
34 #include <ISmmPlugin.h>
38 using namespace SourceMod;
39 using namespace SourcePawn;
42 #if defined SMEXT_CONF_METAMOD
45 public IExtensionInterface
52 * @brief This is called after the initial loading sequence has been processed.
54 * @param error Error message buffer.
55 * @param err_max Size of error message buffer.
56 * @param late Whether or not the module was loaded after map load.
57 * @return True to succeed loading, false to fail.
59 virtual bool SDK_OnLoad(char *error, size_t err_max, bool late);
62 * @brief This is called right before the extension is unloaded.
64 virtual void SDK_OnUnload();
67 * @brief This is called once all known extensions have been loaded.
69 virtual void SDK_OnAllLoaded();
72 * @brief Called when the pause state is changed.
74 virtual void SDK_OnPauseChange(bool paused);
76 #if defined SMEXT_CONF_METAMOD
78 * @brief Called when Metamod is attached, before the extension version is called.
80 * @param error Error buffer.
81 * @param err_max Maximum size of error buffer.
82 * @param late Whether or not Metamod considers this a late load.
83 * @return True to succeed, false to fail.
85 virtual bool SDK_OnMetamodLoad(char *error, size_t err_max, bool late);
88 * @brief Called when Metamod is detaching, after the extension version is called.
89 * NOTE: By default this is blocked unless sent from SourceMod.
91 * @param error Error buffer.
92 * @param err_max Maximum size of error buffer.
93 * @return True to succeed, false to fail.
95 virtual bool SDK_OnMetamodUnload(char *error, size_t err_max);
98 * @brief Called when Metamod's pause state is changing.
99 * NOTE: By default this is blocked unless sent from SourceMod.
101 * @param paused Pause state being set.
102 * @param error Error buffer.
103 * @param err_max Maximum size of error buffer.
104 * @return True to succeed, false to fail.
106 virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t err_max);
109 public: //IExtensionInterface
110 virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t err_max, bool late);
111 virtual void OnExtensionUnload();
112 virtual void OnExtensionsAllLoaded();
114 /** Returns whether or not this is a Metamod-based extension */
115 virtual bool IsMetamodExtension();
118 * @brief Called when the pause state changes.
120 * @param state True if being paused, false if being unpaused.
122 virtual void OnExtensionPauseChange(bool state);
125 virtual const char *GetExtensionName();
127 virtual const char *GetExtensionURL();
128 /** Returns log tag */
129 virtual const char *GetExtensionTag();
130 /** Returns author */
131 virtual const char *GetExtensionAuthor();
132 /** Returns version string */
133 virtual const char *GetExtensionVerString();
134 /** Returns description string */
135 virtual const char *GetExtensionDescription();
136 /** Returns date string */
137 virtual const char *GetExtensionDateString();
138 #if defined SMEXT_CONF_METAMOD
140 /** Called when the extension is attached to Metamod. */
141 virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
142 /** Returns the author to MM */
143 virtual const char *GetAuthor();
144 /** Returns the name to MM */
145 virtual const char *GetName();
146 /** Returns the description to MM */
147 virtual const char *GetDescription();
148 /** Returns the URL to MM */
149 virtual const char *GetURL();
150 /** Returns the license to MM */
151 virtual const char *GetLicense();
152 /** Returns the version string to MM */
153 virtual const char *GetVersion();
154 /** Returns the date string to MM */
155 virtual const char *GetDate();
156 /** Returns the logtag to MM */
157 virtual const char *GetLogTag();
158 /** Called on unload */
159 virtual bool Unload(char *error, size_t maxlen);
160 /** Called on pause */
161 virtual bool Pause(char *error, size_t maxlen);
162 /** Called on unpause */
163 virtual bool Unpause(char *error, size_t maxlen);
165 bool m_SourceMMLoaded;
166 bool m_WeAreUnloaded;
167 bool m_WeGotPauseChange;
171 extern SDKExtension *g_pExtensionIface;
173 extern IShareSys *g_pShareSys;
174 extern IExtension *myself;
175 extern IHandleSys *g_pHandleSys;
176 extern ISourceMod *g_pSM;
177 extern IForwardManager *g_pForwards;
179 #if defined SMEXT_CONF_METAMOD
181 extern IVEngineServer *engine;
182 extern IServerGameDLL *gamedll;
185 /** Creates a SourceMod interface macro pair */
186 #define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
187 /** Automates retrieving SourceMod interfaces */
188 #define SM_GET_IFACE(prefix,addr) \
189 if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) { \
191 snprintf(error, err_max, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
196 #endif //_INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_