• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

public/sample_ext/sdk/smsdk_ext.h

Go to the documentation of this file.
00001 /**
00002  * vim: set ts=4 :
00003  * =============================================================================
00004  * SourceMod Base Extension Code
00005  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
00006  * =============================================================================
00007  *
00008  * This program is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License, version 3.0, as published by the
00010  * Free Software Foundation.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * As a special exception, AlliedModders LLC gives you permission to link the
00021  * code of this program (as well as its derivative works) to "Half-Life 2," the
00022  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
00023  * by the Valve Corporation.  You must obey the GNU General Public License in
00024  * all respects for all other code used.  Additionally, AlliedModders LLC grants
00025  * this exception to all derivative works.  AlliedModders LLC defines further
00026  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
00027  * or <http://www.sourcemod.net/license.php>.
00028  *
00029  * Version: $Id$
00030  */
00031 
00032 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
00033 #define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
00034 
00035 /**
00036  * @file smsdk_ext.h
00037  * @brief Contains wrappers for making Extensions easier to write.
00038  */
00039 
00040 #include "smsdk_config.h"
00041 #include <IExtensionSys.h>
00042 #include <IHandleSys.h>
00043 #include <sp_vm_api.h>
00044 #include <sm_platform.h>
00045 #include <ISourceMod.h>
00046 #if defined SMEXT_ENABLE_FORWARDSYS
00047 #include <IForwardSys.h>
00048 #endif //SMEXT_ENABLE_FORWARDSYS
00049 #if defined SMEXT_ENABLE_PLAYERHELPERS
00050 #include <IPlayerHelpers.h>
00051 #endif //SMEXT_ENABLE_PlAYERHELPERS
00052 #if defined SMEXT_ENABLE_DBMANAGER
00053 #include <IDBDriver.h>
00054 #endif //SMEXT_ENABLE_DBMANAGER
00055 #if defined SMEXT_ENABLE_GAMECONF
00056 #include <IGameConfigs.h>
00057 #endif
00058 #if defined SMEXT_ENABLE_MEMUTILS
00059 #include <IMemoryUtils.h>
00060 #endif
00061 #if defined SMEXT_ENABLE_GAMEHELPERS
00062 #include <IGameHelpers.h>
00063 #endif
00064 #if defined SMEXT_ENABLE_TIMERSYS
00065 #include <ITimerSystem.h>
00066 #endif
00067 #if defined SMEXT_ENABLE_ADTFACTORY
00068 #include <IADTFactory.h>
00069 #endif
00070 #if defined SMEXT_ENABLE_THREADER
00071 #include <IThreader.h>
00072 #endif
00073 #if defined SMEXT_ENABLE_LIBSYS
00074 #include <ILibrarySys.h>
00075 #endif
00076 #if defined SMEXT_ENABLE_PLUGINSYS
00077 #include <IPluginSys.h>
00078 #endif
00079 #if defined SMEXT_ENABLE_MENUS
00080 #include <IMenuManager.h>
00081 #endif
00082 #if defined SMEXT_ENABLE_ADMINSYS
00083 #include <IAdminSystem.h>
00084 #endif
00085 #if defined SMEXT_ENABLE_TEXTPARSERS
00086 #include <ITextParsers.h>
00087 #endif
00088 #if defined SMEXT_ENABLE_USERMSGS
00089 #include <IUserMessages.h>
00090 #endif
00091 #if defined SMEXT_ENABLE_TRANSLATOR
00092 #include <ITranslator.h>
00093 #endif
00094 #if defined SMEXT_ENABLE_NINVOKE
00095 #include <INativeInvoker.h>
00096 #endif
00097 #if defined SMEXT_ENABLE_ROOTCONSOLEMENU
00098 #include <IRootConsoleMenu.h>
00099 #endif
00100 
00101 #if defined SMEXT_CONF_METAMOD
00102 #include <ISmmPlugin.h>
00103 #include <eiface.h>
00104 #endif
00105 
00106 using namespace SourceMod;
00107 using namespace SourcePawn;
00108 
00109 class SDKExtension : 
00110 #if defined SMEXT_CONF_METAMOD
00111           public ISmmPlugin,
00112 #endif
00113           public IExtensionInterface
00114 {
00115 public:
00116           /** Constructor */
00117           SDKExtension();
00118 public:
00119           /**
00120            * @brief This is called after the initial loading sequence has been processed.
00121            *
00122            * @param error               Error message buffer.
00123            * @param maxlength Size of error message buffer.
00124            * @param late                Whether or not the module was loaded after map load.
00125            * @return                              True to succeed loading, false to fail.
00126            */
00127           virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
00128           
00129           /**
00130            * @brief This is called right before the extension is unloaded.
00131            */
00132           virtual void SDK_OnUnload();
00133 
00134           /**
00135            * @brief This is called once all known extensions have been loaded.
00136            */
00137           virtual void SDK_OnAllLoaded();
00138 
00139           /**
00140            * @brief Called when the pause state is changed.
00141            */
00142           virtual void SDK_OnPauseChange(bool paused);
00143 
00144 #if defined SMEXT_CONF_METAMOD
00145           /**
00146            * @brief Called when Metamod is attached, before the extension version is called.
00147            *
00148            * @param error                         Error buffer.
00149            * @param maxlength           Maximum size of error buffer.
00150            * @param late                          Whether or not Metamod considers this a late load.
00151            * @return                                        True to succeed, false to fail.
00152            */
00153           virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
00154 
00155           /**
00156            * @brief Called when Metamod is detaching, after the extension version is called.
00157            * NOTE: By default this is blocked unless sent from SourceMod.
00158            *
00159            * @param error                         Error buffer.
00160            * @param maxlength           Maximum size of error buffer.
00161            * @return                                        True to succeed, false to fail.
00162            */
00163           virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
00164 
00165           /**
00166            * @brief Called when Metamod's pause state is changing.
00167            * NOTE: By default this is blocked unless sent from SourceMod.
00168            *
00169            * @param paused              Pause state being set.
00170            * @param error                         Error buffer.
00171            * @param maxlength           Maximum size of error buffer.
00172            * @return                                        True to succeed, false to fail.
00173            */
00174           virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
00175 #endif
00176 
00177 public: //IExtensionInterface
00178           virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
00179           virtual void OnExtensionUnload();
00180           virtual void OnExtensionsAllLoaded();
00181 
00182           /** Returns whether or not this is a Metamod-based extension */
00183           virtual bool IsMetamodExtension();
00184 
00185           /**
00186            * @brief Called when the pause state changes.
00187            * 
00188            * @param state                         True if being paused, false if being unpaused.
00189            */
00190           virtual void OnExtensionPauseChange(bool state);
00191 
00192           /** Returns name */
00193           virtual const char *GetExtensionName();
00194           /** Returns URL */
00195           virtual const char *GetExtensionURL();
00196           /** Returns log tag */
00197           virtual const char *GetExtensionTag();
00198           /** Returns author */
00199           virtual const char *GetExtensionAuthor();
00200           /** Returns version string */
00201           virtual const char *GetExtensionVerString();
00202           /** Returns description string */
00203           virtual const char *GetExtensionDescription();
00204           /** Returns date string */
00205           virtual const char *GetExtensionDateString();
00206 #if defined SMEXT_CONF_METAMOD
00207 public: //ISmmPlugin
00208           /** Called when the extension is attached to Metamod. */
00209           virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
00210           /** Returns the author to MM */
00211           virtual const char *GetAuthor();
00212           /** Returns the name to MM */
00213           virtual const char *GetName();
00214           /** Returns the description to MM */
00215           virtual const char *GetDescription();
00216           /** Returns the URL to MM */
00217           virtual const char *GetURL();
00218           /** Returns the license to MM */
00219           virtual const char *GetLicense();
00220           /** Returns the version string to MM */
00221           virtual const char *GetVersion();
00222           /** Returns the date string to MM */
00223           virtual const char *GetDate();
00224           /** Returns the logtag to MM */
00225           virtual const char *GetLogTag();
00226           /** Called on unload */
00227           virtual bool Unload(char *error, size_t maxlength);
00228           /** Called on pause */
00229           virtual bool Pause(char *error, size_t maxlength);
00230           /** Called on unpause */
00231           virtual bool Unpause(char *error, size_t maxlength);
00232 private:
00233           bool m_SourceMMLoaded;
00234           bool m_WeAreUnloaded;
00235           bool m_WeGotPauseChange;
00236 #endif
00237 };
00238 
00239 extern SDKExtension *g_pExtensionIface;
00240 extern IExtension *myself;
00241 
00242 extern IShareSys *g_pShareSys;
00243 extern IShareSys *sharesys;                                 /* Note: Newer name */
00244 extern ISourceMod *g_pSM;
00245 extern ISourceMod *smutils;                                 /* Note: Newer name */
00246 
00247 /* Optional interfaces are below */
00248 #if defined SMEXT_ENABLE_FORWARDSYS
00249 extern IForwardManager *g_pForwards;
00250 extern IForwardManager *forwards;                 /* Note: Newer name */
00251 #endif //SMEXT_ENABLE_FORWARDSYS
00252 #if defined SMEXT_ENABLE_HANDLESYS
00253 extern IHandleSys *g_pHandleSys;
00254 extern IHandleSys *handlesys;                     /* Note: Newer name */
00255 #endif //SMEXT_ENABLE_HANDLESYS
00256 #if defined SMEXT_ENABLE_PLAYERHELPERS
00257 extern IPlayerManager *playerhelpers;
00258 #endif //SMEXT_ENABLE_PLAYERHELPERS
00259 #if defined SMEXT_ENABLE_DBMANAGER
00260 extern IDBManager *dbi;
00261 #endif //SMEXT_ENABLE_DBMANAGER
00262 #if defined SMEXT_ENABLE_GAMECONF
00263 extern IGameConfigManager *gameconfs;
00264 #endif //SMEXT_ENABLE_DBMANAGER
00265 #if defined SMEXT_ENABLE_MEMUTILS
00266 extern IMemoryUtils *memutils;
00267 #endif
00268 #if defined SMEXT_ENABLE_GAMEHELPERS
00269 extern IGameHelpers *gamehelpers;
00270 #endif
00271 #if defined SMEXT_ENABLE_TIMERSYS
00272 extern ITimerSystem *timersys;
00273 #endif
00274 #if defined SMEXT_ENABLE_ADTFACTORY
00275 extern IADTFactory *adtfactory;
00276 #endif
00277 #if defined SMEXT_ENABLE_THREADER
00278 extern IThreader *threader;
00279 #endif
00280 #if defined SMEXT_ENABLE_LIBSYS
00281 extern ILibrarySys *libsys;
00282 #endif
00283 #if defined SMEXT_ENABLE_PLUGINSYS
00284 extern SourceMod::IPluginManager *plsys;
00285 #endif
00286 #if defined SMEXT_ENABLE_MENUS
00287 extern IMenuManager *menus;
00288 #endif
00289 #if defined SMEXT_ENABLE_ADMINSYS
00290 extern IAdminSystem *adminsys;
00291 #endif
00292 #if defined SMEXT_ENABLE_USERMSGS
00293 extern IUserMessages *usermsgs;
00294 #endif
00295 #if defined SMEXT_ENABLE_TRANSLATOR
00296 extern ITranslator *translator;
00297 #endif
00298 #if defined SMEXT_ENABLE_NINVOKE
00299 extern INativeInterface *ninvoke;
00300 #endif
00301 
00302 #if defined SMEXT_CONF_METAMOD
00303 PLUGIN_GLOBALVARS();
00304 extern IVEngineServer *engine;
00305 extern IServerGameDLL *gamedll;
00306 #endif
00307 
00308 /** Creates a SourceMod interface macro pair */
00309 #define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
00310 /** Automates retrieving SourceMod interfaces */
00311 #define SM_GET_IFACE(prefix, addr) \
00312           if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
00313           { \
00314                     if (error != NULL && maxlength) \
00315                     { \
00316                               size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
00317                               if (len >= maxlength) \
00318                               { \
00319                                         error[maxlength - 1] = '\0'; \
00320                               } \
00321                     } \
00322                     return false; \
00323           }
00324 /** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
00325 #define SM_GET_LATE_IFACE(prefix, addr) \
00326           g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
00327 /** Validates a SourceMod interface pointer */
00328 #define SM_CHECK_IFACE(prefix, addr) \
00329           if (!addr) \
00330           { \
00331                     if (error != NULL && maxlength) \
00332                     { \
00333                               size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
00334                               if (len >= maxlength) \
00335                               { \
00336                                         error[maxlength - 1] = '\0'; \
00337                               } \
00338                     } \
00339                     return false; \
00340           }
00341 
00342 #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_

Generated on Wed Dec 7 2011 18:50:03 for SourceMod SDK by  doxygen 1.7.1