SourceMod SDK  1.7
smsdk_ext.h
Go to the documentation of this file.
1 
32 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
33 #define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
34 
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>
57 #endif
58 #if defined SMEXT_ENABLE_MEMUTILS
59 #include <IMemoryUtils.h>
60 #endif
61 #if defined SMEXT_ENABLE_GAMEHELPERS
62 #include <IGameHelpers.h>
63 #endif
64 #if defined SMEXT_ENABLE_TIMERSYS
65 #include <ITimerSystem.h>
66 #endif
67 #if defined SMEXT_ENABLE_ADTFACTORY
68 #include <IADTFactory.h>
69 #endif
70 #if defined SMEXT_ENABLE_THREADER
71 #include <IThreader.h>
72 #endif
73 #if defined SMEXT_ENABLE_LIBSYS
74 #include <ILibrarySys.h>
75 #endif
76 #if defined SMEXT_ENABLE_PLUGINSYS
77 #include <IPluginSys.h>
78 #endif
79 #if defined SMEXT_ENABLE_MENUS
80 #include <IMenuManager.h>
81 #endif
82 #if defined SMEXT_ENABLE_ADMINSYS
83 #include <IAdminSystem.h>
84 #endif
85 #if defined SMEXT_ENABLE_TEXTPARSERS
86 #include <ITextParsers.h>
87 #endif
88 #if defined SMEXT_ENABLE_USERMSGS
89 #include <IUserMessages.h>
90 #endif
91 #if defined SMEXT_ENABLE_TRANSLATOR
92 #include <ITranslator.h>
93 #endif
94 #if defined SMEXT_ENABLE_NINVOKE
95 #include <INativeInvoker.h>
96 #endif
97 #if defined SMEXT_ENABLE_ROOTCONSOLEMENU
98 #include <IRootConsoleMenu.h>
99 #endif
100 
101 #if defined SMEXT_CONF_METAMOD
102 #include <ISmmPlugin.h>
103 #include <eiface.h>
104 #endif
105 
106 #if !defined METAMOD_PLAPI_VERSION
107 #include <metamod_wrappers.h>
108 #endif
109 
110 using namespace SourceMod;
111 using namespace SourcePawn;
112 
113 class SDKExtension :
114 #if defined SMEXT_CONF_METAMOD
115  public ISmmPlugin,
116 #endif
117  public IExtensionInterface
118 {
119 public:
121  SDKExtension();
122 public:
131  virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
132 
136  virtual void SDK_OnUnload();
137 
141  virtual void SDK_OnAllLoaded();
142 
146  virtual void SDK_OnPauseChange(bool paused);
147 
152  virtual void SDK_OnDependenciesDropped();
153 
154 #if defined SMEXT_CONF_METAMOD
155 
163  virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
164 
173  virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
174 
184  virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
185 #endif
186 
187 public: //IExtensionInterface
188  virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
189  virtual void OnExtensionUnload();
190  virtual void OnExtensionsAllLoaded();
191 
193  virtual bool IsMetamodExtension();
194 
200  virtual void OnExtensionPauseChange(bool state);
201 
203  virtual const char *GetExtensionName();
205  virtual const char *GetExtensionURL();
207  virtual const char *GetExtensionTag();
209  virtual const char *GetExtensionAuthor();
211  virtual const char *GetExtensionVerString();
213  virtual const char *GetExtensionDescription();
215  virtual const char *GetExtensionDateString();
216 
218  virtual void OnDependenciesDropped();
219 #if defined SMEXT_CONF_METAMOD
220 public: //ISmmPlugin
222  virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
224  virtual const char *GetAuthor();
226  virtual const char *GetName();
228  virtual const char *GetDescription();
230  virtual const char *GetURL();
232  virtual const char *GetLicense();
234  virtual const char *GetVersion();
236  virtual const char *GetDate();
238  virtual const char *GetLogTag();
240  virtual bool Unload(char *error, size_t maxlength);
242  virtual bool Pause(char *error, size_t maxlength);
244  virtual bool Unpause(char *error, size_t maxlength);
245 private:
246  bool m_SourceMMLoaded;
247  bool m_WeAreUnloaded;
248  bool m_WeGotPauseChange;
249 #endif
250 };
251 
252 extern SDKExtension *g_pExtensionIface;
253 extern IExtension *myself;
254 
255 extern IShareSys *g_pShareSys;
256 extern IShareSys *sharesys; /* Note: Newer name */
257 extern ISourceMod *g_pSM;
258 extern ISourceMod *smutils; /* Note: Newer name */
259 
260 /* Optional interfaces are below */
261 #if defined SMEXT_ENABLE_FORWARDSYS
262 extern IForwardManager *g_pForwards;
263 extern IForwardManager *forwards; /* Note: Newer name */
264 #endif //SMEXT_ENABLE_FORWARDSYS
265 #if defined SMEXT_ENABLE_HANDLESYS
266 extern IHandleSys *g_pHandleSys;
267 extern IHandleSys *handlesys; /* Note: Newer name */
268 #endif //SMEXT_ENABLE_HANDLESYS
269 #if defined SMEXT_ENABLE_PLAYERHELPERS
270 extern IPlayerManager *playerhelpers;
271 #endif //SMEXT_ENABLE_PLAYERHELPERS
272 #if defined SMEXT_ENABLE_DBMANAGER
273 extern IDBManager *dbi;
274 #endif //SMEXT_ENABLE_DBMANAGER
275 #if defined SMEXT_ENABLE_GAMECONF
276 extern IGameConfigManager *gameconfs;
277 #endif //SMEXT_ENABLE_DBMANAGER
278 #if defined SMEXT_ENABLE_MEMUTILS
279 extern IMemoryUtils *memutils;
280 #endif
281 #if defined SMEXT_ENABLE_GAMEHELPERS
282 extern IGameHelpers *gamehelpers;
283 #endif
284 #if defined SMEXT_ENABLE_TIMERSYS
285 extern ITimerSystem *timersys;
286 #endif
287 #if defined SMEXT_ENABLE_ADTFACTORY
288 extern IADTFactory *adtfactory;
289 #endif
290 #if defined SMEXT_ENABLE_THREADER
291 extern IThreader *threader;
292 #endif
293 #if defined SMEXT_ENABLE_LIBSYS
294 extern ILibrarySys *libsys;
295 #endif
296 #if defined SMEXT_ENABLE_PLUGINSYS
297 extern SourceMod::IPluginManager *plsys;
298 #endif
299 #if defined SMEXT_ENABLE_MENUS
300 extern IMenuManager *menus;
301 #endif
302 #if defined SMEXT_ENABLE_ADMINSYS
303 extern IAdminSystem *adminsys;
304 #endif
305 #if defined SMEXT_ENABLE_USERMSGS
306 extern IUserMessages *usermsgs;
307 #endif
308 #if defined SMEXT_ENABLE_TRANSLATOR
309 extern ITranslator *translator;
310 #endif
311 #if defined SMEXT_ENABLE_NINVOKE
312 extern INativeInterface *ninvoke;
313 #endif
314 #if defined SMEXT_ENABLE_ROOTCONSOLEMENU
315 extern IRootConsole *rootconsole;
316 #endif
317 
318 #if defined SMEXT_CONF_METAMOD
319 PLUGIN_GLOBALVARS();
320 extern IVEngineServer *engine;
321 extern IServerGameDLL *gamedll;
322 #endif
323 
325 #define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
326 
327 #define SM_GET_IFACE(prefix, addr) \
328  if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
329  { \
330  if (error != NULL && maxlength) \
331  { \
332  size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
333  if (len >= maxlength) \
334  { \
335  error[maxlength - 1] = '\0'; \
336  } \
337  } \
338  return false; \
339  }
340 
341 #define SM_GET_LATE_IFACE(prefix, addr) \
342  g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
343 
344 #define SM_CHECK_IFACE(prefix, addr) \
345  if (!addr) \
346  { \
347  if (error != NULL && maxlength) \
348  { \
349  size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
350  if (len >= maxlength) \
351  { \
352  error[maxlength - 1] = '\0'; \
353  } \
354  } \
355  return false; \
356  }
357 
358 #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
Defines the interface for adding options to the "sm" console command.
Provides Source helper functions.
IShareSys * g_pShareSys
Definition: smsdk_ext.cpp:42
Manages menu creation and displaying.
Definition: IMenuManager.h:823
Defines the interface for managing collections ("forwards") of plugin calls.
The interface an extension must expose.
Definition: IExtensionSys.h:145
IVEngineServer * engine
Definition: smsdk_ext.cpp:310
Defines the interface for creating, reading, and removing Handles.
Contains functions for advanced usermessage hooking.
Manages the root console menu - the "sm" command for servers.
Definition: IRootConsoleMenu.h:97
Interface for invoking natives.
Factory for dealing with native invocations.
Definition: INativeInvoker.h:84
IShareSys * sharesys
Definition: smsdk_ext.cpp:43
Defines basic helper functions for Half-Life 2 clients.
Provides functions for managing Handles.
Definition: IHandleSys.h:222
Tracks dependencies and fires dependency listeners.
Definition: IShareSys.h:126
Defines the interface for the Plugin System, which manages loaded plugins.
Abstracts game private data configuration.
Definition: IPlayerHelpers.h:489
Interface for finding patterns in memory.
Definition: IMemoryUtils.h:45
Provides functions for manipulating the admin options cache.
Definition: IAdminSystem.h:220
Contains functions for hooking user messages.
Definition: IUserMessages.h:178
Contains miscellaneous helper functions.
Definition: ISourceMod.h:83
Definition: ITimerSystem.h:111
ISourceMod * g_pSM
Definition: smsdk_ext.cpp:44
Definition: smsdk_ext.h:113
ISourceMod * smutils
Definition: smsdk_ext.cpp:45
Provides functions for translation.
Definition: ITranslator.h:229
Contains platform-specific macros for abstraction.
Manages the runtime loading and unloading of plugins.
Definition: IPluginSys.h:299
Describes a threading system.
Definition: IThreader.h:414
Definition: IADTFactory.h:101
IServerGameDLL * gamedll
Definition: smsdk_ext.cpp:311
Abstracts on-screen menus for clients.
Contains various operating system specific code.
Definition: ILibrarySys.h:123
Manages game config files.
Definition: IGameConfigs.h:106
Defines interfaces for interacting with relational databases.
Provides functions for creating/destroying managed and unmanaged forwards.
Definition: IForwardSys.h:247
Describes the DBI manager.
Definition: IDBDriver.h:797
Defines various text/file parsing functions, as well as UTF-8 support code.
Defines the interface for loading/unloading/managing extensions.
Contains functions for creating and managing timers.
Definition: IAdminSystem.h:63
Defines the interface to manage the Admin Users/Groups and Override caches.
Creates abstract data types.
Encapsulates an IExtensionInterface and its dependencies.
Definition: IExtensionSys.h:53
Defines interfaces related to translation files.
Defines miscellaneous helper functions useful to extensions.
Contains platform independent routines for threading. These tools should be considered deprecated...
Definition: IGameHelpers.h:76
Defines platform-dependent operations, such as opening libraries and files.
IExtension * myself
Definition: smsdk_ext.cpp:41