sdk/smsdk_ext.h
author David Anderson <dvander@alliedmods.net>
Sun Jun 24 21:58:09 2007 +0000 (2007-06-24)
changeset 0 67dcd379a2d5
permissions -rw-r--r--
initial import of the amazing CS:S DM 2.0.0, so far only Windows is tested
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * All rights reserved.
     6  * ===============================================================
     7  *
     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.
    13  * 
    14  * To view the latest information, see: http://www.sourcemod.net/license.php
    15  *
    16  * Version: $Id$
    17  */
    18 
    19 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
    20 #define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
    21 
    22 /**
    23  * @file smsdk_ext.h
    24  * @brief Contains wrappers for making Extensions easier to write.
    25  */
    26 
    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>
    44 #endif
    45 #if defined SMEXT_ENABLE_MEMUTILS
    46 #include <IMemoryUtils.h>
    47 #endif
    48 #if defined SMEXT_ENABLE_GAMEHELPERS
    49 #include <IGameHelpers.h>
    50 #endif
    51 #if defined SMEXT_ENABLE_TIMERSYS
    52 #include <ITimerSystem.h>
    53 #endif
    54 
    55 #if defined SMEXT_CONF_METAMOD
    56 #include <ISmmPlugin.h>
    57 #include <eiface.h>
    58 #endif
    59 
    60 using namespace SourceMod;
    61 using namespace SourcePawn;
    62 
    63 class SDKExtension : 
    64 #if defined SMEXT_CONF_METAMOD
    65 	public ISmmPlugin,
    66 #endif
    67 	public IExtensionInterface
    68 {
    69 public:
    70 	/** Constructor */
    71 	SDKExtension();
    72 public:
    73 	/**
    74 	 * @brief This is called after the initial loading sequence has been processed.
    75 	 *
    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.
    80 	 */
    81 	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
    82 	
    83 	/**
    84 	 * @brief This is called right before the extension is unloaded.
    85 	 */
    86 	virtual void SDK_OnUnload();
    87 
    88 	/**
    89 	 * @brief This is called once all known extensions have been loaded.
    90 	 */
    91 	virtual void SDK_OnAllLoaded();
    92 
    93 	/**
    94 	 * @brief Called when the pause state is changed.
    95 	 */
    96 	virtual void SDK_OnPauseChange(bool paused);
    97 
    98 #if defined SMEXT_CONF_METAMOD
    99 	/**
   100 	 * @brief Called when Metamod is attached, before the extension version is called.
   101 	 *
   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.
   106 	 */
   107 	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
   108 
   109 	/**
   110 	 * @brief Called when Metamod is detaching, after the extension version is called.
   111 	 * NOTE: By default this is blocked unless sent from SourceMod.
   112 	 *
   113 	 * @param error			Error buffer.
   114 	 * @param maxlength		Maximum size of error buffer.
   115 	 * @return				True to succeed, false to fail.
   116 	 */
   117 	virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
   118 
   119 	/**
   120 	 * @brief Called when Metamod's pause state is changing.
   121 	 * NOTE: By default this is blocked unless sent from SourceMod.
   122 	 *
   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.
   127 	 */
   128 	virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
   129 #endif
   130 
   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();
   135 
   136 	/** Returns whether or not this is a Metamod-based extension */
   137 	virtual bool IsMetamodExtension();
   138 
   139 	/**
   140 	 * @brief Called when the pause state changes.
   141 	 * 
   142 	 * @param state			True if being paused, false if being unpaused.
   143 	 */
   144 	virtual void OnExtensionPauseChange(bool state);
   145 
   146 	/** Returns name */
   147 	virtual const char *GetExtensionName();
   148 	/** Returns URL */
   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
   161 public: //ISmmPlugin
   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);
   186 private:
   187 	bool m_SourceMMLoaded;
   188 	bool m_WeAreUnloaded;
   189 	bool m_WeGotPauseChange;
   190 #endif
   191 };
   192 
   193 extern SDKExtension *g_pExtensionIface;
   194 extern IExtension *myself;
   195 
   196 extern IShareSys *g_pShareSys;
   197 extern IShareSys *sharesys;				/* Note: Newer name */
   198 extern ISourceMod *g_pSM;
   199 extern ISourceMod *smutils;				/* Note: Newer name */
   200 
   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;
   224 #endif
   225 #if defined SMEXT_ENABLE_TIMERSYS
   226 extern ITimerSystem *timersys;
   227 #endif
   228 
   229 #if defined SMEXT_CONF_METAMOD
   230 PLUGIN_GLOBALVARS();
   231 extern IVEngineServer *engine;
   232 extern IServerGameDLL *gamedll;
   233 #endif
   234 
   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)) \
   240 	{ \
   241 		if (error) \
   242 		{ \
   243 			snprintf(error, maxlength, "Could not find interface: %s (version: %d)", SMINTERFACE_##prefix##_NAME, SMINTERFACE_##prefix##_VERSION); \
   244 			return false; \
   245 		} \
   246 	}
   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) \
   252 	if (!addr) \
   253 	{ \
   254 		if (error) \
   255 		{ \
   256 			snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
   257 			return false; \
   258 		} \
   259 	}
   260 
   261 #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_