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: smsdk_ext.h 2132 2008-05-10 09:23:55Z dvander $
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 
00095 #if defined SMEXT_CONF_METAMOD
00096 #include <ISmmPlugin.h>
00097 #include <eiface.h>
00098 #endif
00099 
00100 using namespace SourceMod;
00101 using namespace SourcePawn;
00102 
00103 class SDKExtension : 
00104 #if defined SMEXT_CONF_METAMOD
00105           public ISmmPlugin,
00106 #endif
00107           public IExtensionInterface
00108 {
00109 public:
00110           /** Constructor */
00111           SDKExtension();
00112 public:
00113           /**
00114            * @brief This is called after the initial loading sequence has been processed.
00115            *
00116            * @param error               Error message buffer.
00117            * @param maxlength Size of error message buffer.
00118            * @param late                Whether or not the module was loaded after map load.
00119            * @return                              True to succeed loading, false to fail.
00120            */
00121           virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
00122           
00123           /**
00124            * @brief This is called right before the extension is unloaded.
00125            */
00126           virtual void SDK_OnUnload();
00127 
00128           /**
00129            * @brief This is called once all known extensions have been loaded.
00130            */
00131           virtual void SDK_OnAllLoaded();
00132 
00133           /**
00134            * @brief Called when the pause state is changed.
00135            */
00136           virtual void SDK_OnPauseChange(bool paused);
00137 
00138 #if defined SMEXT_CONF_METAMOD
00139           /**
00140            * @brief Called when Metamod is attached, before the extension version is called.
00141            *
00142            * @param error                         Error buffer.
00143            * @param maxlength           Maximum size of error buffer.
00144            * @param late                          Whether or not Metamod considers this a late load.
00145            * @return                                        True to succeed, false to fail.
00146            */
00147           virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
00148 
00149           /**
00150            * @brief Called when Metamod is detaching, after the extension version is called.
00151            * NOTE: By default this is blocked unless sent from SourceMod.
00152            *
00153            * @param error                         Error buffer.
00154            * @param maxlength           Maximum size of error buffer.
00155            * @return                                        True to succeed, false to fail.
00156            */
00157           virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
00158 
00159           /**
00160            * @brief Called when Metamod's pause state is changing.
00161            * NOTE: By default this is blocked unless sent from SourceMod.
00162            *
00163            * @param paused              Pause state being set.
00164            * @param error                         Error buffer.
00165            * @param maxlength           Maximum size of error buffer.
00166            * @return                                        True to succeed, false to fail.
00167            */
00168           virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
00169 #endif
00170 
00171 public: //IExtensionInterface
00172           virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
00173           virtual void OnExtensionUnload();
00174           virtual void OnExtensionsAllLoaded();
00175 
00176           /** Returns whether or not this is a Metamod-based extension */
00177           virtual bool IsMetamodExtension();
00178 
00179           /**
00180            * @brief Called when the pause state changes.
00181            * 
00182            * @param state                         True if being paused, false if being unpaused.
00183            */
00184           virtual void OnExtensionPauseChange(bool state);
00185 
00186           /** Returns name */
00187           virtual const char *GetExtensionName();
00188           /** Returns URL */
00189           virtual const char *GetExtensionURL();
00190           /** Returns log tag */
00191           virtual const char *GetExtensionTag();
00192           /** Returns author */
00193           virtual const char *GetExtensionAuthor();
00194           /** Returns version string */
00195           virtual const char *GetExtensionVerString();
00196           /** Returns description string */
00197           virtual const char *GetExtensionDescription();
00198           /** Returns date string */
00199           virtual const char *GetExtensionDateString();
00200 #if defined SMEXT_CONF_METAMOD
00201 public: //ISmmPlugin
00202           /** Called when the extension is attached to Metamod. */
00203           virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
00204           /** Returns the author to MM */
00205           virtual const char *GetAuthor();
00206           /** Returns the name to MM */
00207           virtual const char *GetName();
00208           /** Returns the description to MM */
00209           virtual const char *GetDescription();
00210           /** Returns the URL to MM */
00211           virtual const char *GetURL();
00212           /** Returns the license to MM */
00213           virtual const char *GetLicense();
00214           /** Returns the version string to MM */
00215           virtual const char *GetVersion();
00216           /** Returns the date string to MM */
00217           virtual const char *GetDate();
00218           /** Returns the logtag to MM */
00219           virtual const char *GetLogTag();
00220           /** Called on unload */
00221           virtual bool Unload(char *error, size_t maxlength);
00222           /** Called on pause */
00223           virtual bool Pause(char *error, size_t maxlength);
00224           /** Called on unpause */
00225           virtual bool Unpause(char *error, size_t maxlength);
00226 private:
00227           bool m_SourceMMLoaded;
00228           bool m_WeAreUnloaded;
00229           bool m_WeGotPauseChange;
00230 #endif
00231 };
00232 
00233 extern SDKExtension *g_pExtensionIface;
00234 extern IExtension *myself;
00235 
00236 extern IShareSys *g_pShareSys;
00237 extern IShareSys *sharesys;                                 /* Note: Newer name */
00238 extern ISourceMod *g_pSM;
00239 extern ISourceMod *smutils;                                 /* Note: Newer name */
00240 
00241 /* Optional interfaces are below */
00242 #if defined SMEXT_ENABLE_FORWARDSYS
00243 extern IForwardManager *g_pForwards;
00244 extern IForwardManager *forwards;                 /* Note: Newer name */
00245 #endif //SMEXT_ENABLE_FORWARDSYS
00246 #if defined SMEXT_ENABLE_HANDLESYS
00247 extern IHandleSys *g_pHandleSys;
00248 extern IHandleSys *handlesys;                     /* Note: Newer name */
00249 #endif //SMEXT_ENABLE_HANDLESYS
00250 #if defined SMEXT_ENABLE_PLAYERHELPERS
00251 extern IPlayerManager *playerhelpers;
00252 #endif //SMEXT_ENABLE_PLAYERHELPERS
00253 #if defined SMEXT_ENABLE_DBMANAGER
00254 extern IDBManager *dbi;
00255 #endif //SMEXT_ENABLE_DBMANAGER
00256 #if defined SMEXT_ENABLE_GAMECONF
00257 extern IGameConfigManager *gameconfs;
00258 #endif //SMEXT_ENABLE_DBMANAGER
00259 #if defined SMEXT_ENABLE_MEMUTILS
00260 extern IMemoryUtils *memutils;
00261 #endif
00262 #if defined SMEXT_ENABLE_GAMEHELPERS
00263 extern IGameHelpers *gamehelpers;
00264 #endif
00265 #if defined SMEXT_ENABLE_TIMERSYS
00266 extern ITimerSystem *timersys;
00267 #endif
00268 #if defined SMEXT_ENABLE_ADTFACTORY
00269 extern IADTFactory *adtfactory;
00270 #endif
00271 #if defined SMEXT_ENABLE_THREADER
00272 extern IThreader *threader;
00273 #endif
00274 #if defined SMEXT_ENABLE_LIBSYS
00275 extern ILibrarySys *libsys;
00276 #endif
00277 #if defined SMEXT_ENABLE_PLUGINSYS
00278 extern SourceMod::IPluginManager *plsys;
00279 #endif
00280 #if defined SMEXT_ENABLE_MENUS
00281 extern IMenuManager *menus;
00282 #endif
00283 #if defined SMEXT_ENABLE_ADMINSYS
00284 extern IAdminSystem *adminsys;
00285 #endif
00286 #if defined SMEXT_ENABLE_USERMSGS
00287 extern IUserMessages *usermsgs;
00288 #endif
00289 #if defined SMEXT_ENABLE_TRANSLATOR
00290 extern ITranslator *translator;
00291 #endif
00292 
00293 #if defined SMEXT_CONF_METAMOD
00294 PLUGIN_GLOBALVARS();
00295 extern IVEngineServer *engine;
00296 extern IServerGameDLL *gamedll;
00297 #endif
00298 
00299 /** Creates a SourceMod interface macro pair */
00300 #define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
00301 /** Automates retrieving SourceMod interfaces */
00302 #define SM_GET_IFACE(prefix, addr) \
00303           if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
00304           { \
00305                     if (error != NULL && maxlength) \
00306                     { \
00307                               size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
00308                               if (len >= maxlength) \
00309                               { \
00310                                         error[maxlength - 1] = '\0'; \
00311                               } \
00312                     } \
00313                     return false; \
00314           }
00315 /** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
00316 #define SM_GET_LATE_IFACE(prefix, addr) \
00317           g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
00318 /** Validates a SourceMod interface pointer */
00319 #define SM_CHECK_IFACE(prefix, addr) \
00320           if (!addr) \
00321           { \
00322                     if (error != NULL && maxlength) \
00323                     { \
00324                               size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
00325                               if (len >= maxlength) \
00326                               { \
00327                                         error[maxlength - 1] = '\0'; \
00328                               } \
00329                     } \
00330                     return false; \
00331           }
00332 
00333 #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_

Generated on Fri Nov 21 02:10:02 2008 for SourceMod SDK by  doxygen 1.5.1