1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sdk/smsdk_ext.h Sun Jun 24 21:58:09 2007 +0000
1.3 @@ -0,0 +1,261 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * ===============================================================
1.7 + * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
1.8 + * All rights reserved.
1.9 + * ===============================================================
1.10 + *
1.11 + * This file is part of the SourceMod/SourcePawn SDK. This file may only be
1.12 + * used or modified under the Terms and Conditions of its License Agreement,
1.13 + * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
1.14 + * works must be licensed under the GNU General Public License (version 2 or
1.15 + * greater). A copy of the GPL is included under public/licenses/GPL.txt.
1.16 + *
1.17 + * To view the latest information, see: http://www.sourcemod.net/license.php
1.18 + *
1.19 + * Version: $Id$
1.20 + */
1.21 +
1.22 +#ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
1.23 +#define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
1.24 +
1.25 +/**
1.26 + * @file smsdk_ext.h
1.27 + * @brief Contains wrappers for making Extensions easier to write.
1.28 + */
1.29 +
1.30 +#include "smsdk_config.h"
1.31 +#include <IExtensionSys.h>
1.32 +#include <IHandleSys.h>
1.33 +#include <sp_vm_api.h>
1.34 +#include <sm_platform.h>
1.35 +#include <ISourceMod.h>
1.36 +#if defined SMEXT_ENABLE_FORWARDSYS
1.37 +#include <IForwardSys.h>
1.38 +#endif //SMEXT_ENABLE_FORWARDSYS
1.39 +#if defined SMEXT_ENABLE_PLAYERHELPERS
1.40 +#include <IPlayerHelpers.h>
1.41 +#endif //SMEXT_ENABLE_PlAYERHELPERS
1.42 +#if defined SMEXT_ENABLE_DBMANAGER
1.43 +#include <IDBDriver.h>
1.44 +#endif //SMEXT_ENABLE_DBMANAGER
1.45 +#if defined SMEXT_ENABLE_GAMECONF
1.46 +#include <IGameConfigs.h>
1.47 +#endif
1.48 +#if defined SMEXT_ENABLE_MEMUTILS
1.49 +#include <IMemoryUtils.h>
1.50 +#endif
1.51 +#if defined SMEXT_ENABLE_GAMEHELPERS
1.52 +#include <IGameHelpers.h>
1.53 +#endif
1.54 +#if defined SMEXT_ENABLE_TIMERSYS
1.55 +#include <ITimerSystem.h>
1.56 +#endif
1.57 +
1.58 +#if defined SMEXT_CONF_METAMOD
1.59 +#include <ISmmPlugin.h>
1.60 +#include <eiface.h>
1.61 +#endif
1.62 +
1.63 +using namespace SourceMod;
1.64 +using namespace SourcePawn;
1.65 +
1.66 +class SDKExtension :
1.67 +#if defined SMEXT_CONF_METAMOD
1.68 + public ISmmPlugin,
1.69 +#endif
1.70 + public IExtensionInterface
1.71 +{
1.72 +public:
1.73 + /** Constructor */
1.74 + SDKExtension();
1.75 +public:
1.76 + /**
1.77 + * @brief This is called after the initial loading sequence has been processed.
1.78 + *
1.79 + * @param error Error message buffer.
1.80 + * @param maxlength Size of error message buffer.
1.81 + * @param late Whether or not the module was loaded after map load.
1.82 + * @return True to succeed loading, false to fail.
1.83 + */
1.84 + virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
1.85 +
1.86 + /**
1.87 + * @brief This is called right before the extension is unloaded.
1.88 + */
1.89 + virtual void SDK_OnUnload();
1.90 +
1.91 + /**
1.92 + * @brief This is called once all known extensions have been loaded.
1.93 + */
1.94 + virtual void SDK_OnAllLoaded();
1.95 +
1.96 + /**
1.97 + * @brief Called when the pause state is changed.
1.98 + */
1.99 + virtual void SDK_OnPauseChange(bool paused);
1.100 +
1.101 +#if defined SMEXT_CONF_METAMOD
1.102 + /**
1.103 + * @brief Called when Metamod is attached, before the extension version is called.
1.104 + *
1.105 + * @param error Error buffer.
1.106 + * @param maxlength Maximum size of error buffer.
1.107 + * @param late Whether or not Metamod considers this a late load.
1.108 + * @return True to succeed, false to fail.
1.109 + */
1.110 + virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
1.111 +
1.112 + /**
1.113 + * @brief Called when Metamod is detaching, after the extension version is called.
1.114 + * NOTE: By default this is blocked unless sent from SourceMod.
1.115 + *
1.116 + * @param error Error buffer.
1.117 + * @param maxlength Maximum size of error buffer.
1.118 + * @return True to succeed, false to fail.
1.119 + */
1.120 + virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
1.121 +
1.122 + /**
1.123 + * @brief Called when Metamod's pause state is changing.
1.124 + * NOTE: By default this is blocked unless sent from SourceMod.
1.125 + *
1.126 + * @param paused Pause state being set.
1.127 + * @param error Error buffer.
1.128 + * @param maxlength Maximum size of error buffer.
1.129 + * @return True to succeed, false to fail.
1.130 + */
1.131 + virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
1.132 +#endif
1.133 +
1.134 +public: //IExtensionInterface
1.135 + virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
1.136 + virtual void OnExtensionUnload();
1.137 + virtual void OnExtensionsAllLoaded();
1.138 +
1.139 + /** Returns whether or not this is a Metamod-based extension */
1.140 + virtual bool IsMetamodExtension();
1.141 +
1.142 + /**
1.143 + * @brief Called when the pause state changes.
1.144 + *
1.145 + * @param state True if being paused, false if being unpaused.
1.146 + */
1.147 + virtual void OnExtensionPauseChange(bool state);
1.148 +
1.149 + /** Returns name */
1.150 + virtual const char *GetExtensionName();
1.151 + /** Returns URL */
1.152 + virtual const char *GetExtensionURL();
1.153 + /** Returns log tag */
1.154 + virtual const char *GetExtensionTag();
1.155 + /** Returns author */
1.156 + virtual const char *GetExtensionAuthor();
1.157 + /** Returns version string */
1.158 + virtual const char *GetExtensionVerString();
1.159 + /** Returns description string */
1.160 + virtual const char *GetExtensionDescription();
1.161 + /** Returns date string */
1.162 + virtual const char *GetExtensionDateString();
1.163 +#if defined SMEXT_CONF_METAMOD
1.164 +public: //ISmmPlugin
1.165 + /** Called when the extension is attached to Metamod. */
1.166 + virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
1.167 + /** Returns the author to MM */
1.168 + virtual const char *GetAuthor();
1.169 + /** Returns the name to MM */
1.170 + virtual const char *GetName();
1.171 + /** Returns the description to MM */
1.172 + virtual const char *GetDescription();
1.173 + /** Returns the URL to MM */
1.174 + virtual const char *GetURL();
1.175 + /** Returns the license to MM */
1.176 + virtual const char *GetLicense();
1.177 + /** Returns the version string to MM */
1.178 + virtual const char *GetVersion();
1.179 + /** Returns the date string to MM */
1.180 + virtual const char *GetDate();
1.181 + /** Returns the logtag to MM */
1.182 + virtual const char *GetLogTag();
1.183 + /** Called on unload */
1.184 + virtual bool Unload(char *error, size_t maxlength);
1.185 + /** Called on pause */
1.186 + virtual bool Pause(char *error, size_t maxlength);
1.187 + /** Called on unpause */
1.188 + virtual bool Unpause(char *error, size_t maxlength);
1.189 +private:
1.190 + bool m_SourceMMLoaded;
1.191 + bool m_WeAreUnloaded;
1.192 + bool m_WeGotPauseChange;
1.193 +#endif
1.194 +};
1.195 +
1.196 +extern SDKExtension *g_pExtensionIface;
1.197 +extern IExtension *myself;
1.198 +
1.199 +extern IShareSys *g_pShareSys;
1.200 +extern IShareSys *sharesys; /* Note: Newer name */
1.201 +extern ISourceMod *g_pSM;
1.202 +extern ISourceMod *smutils; /* Note: Newer name */
1.203 +
1.204 +/* Optional interfaces are below */
1.205 +#if defined SMEXT_ENABLE_FORWARDSYS
1.206 +extern IForwardManager *g_pForwards;
1.207 +extern IForwardManager *forwards; /* Note: Newer name */
1.208 +#endif //SMEXT_ENABLE_FORWARDSYS
1.209 +#if defined SMEXT_ENABLE_HANDLESYS
1.210 +extern IHandleSys *g_pHandleSys;
1.211 +extern IHandleSys *handlesys; /* Note: Newer name */
1.212 +#endif //SMEXT_ENABLE_HANDLESYS
1.213 +#if defined SMEXT_ENABLE_PLAYERHELPERS
1.214 +extern IPlayerManager *playerhelpers;
1.215 +#endif //SMEXT_ENABLE_PLAYERHELPERS
1.216 +#if defined SMEXT_ENABLE_DBMANAGER
1.217 +extern IDBManager *dbi;
1.218 +#endif //SMEXT_ENABLE_DBMANAGER
1.219 +#if defined SMEXT_ENABLE_GAMECONF
1.220 +extern IGameConfigManager *gameconfs;
1.221 +#endif //SMEXT_ENABLE_DBMANAGER
1.222 +#if defined SMEXT_ENABLE_MEMUTILS
1.223 +extern IMemoryUtils *memutils;
1.224 +#endif //SMEXT_ENABLE_DBMANAGER
1.225 +#if defined SMEXT_ENABLE_GAMEHELPERS
1.226 +extern IGameHelpers *gamehelpers;
1.227 +#endif
1.228 +#if defined SMEXT_ENABLE_TIMERSYS
1.229 +extern ITimerSystem *timersys;
1.230 +#endif
1.231 +
1.232 +#if defined SMEXT_CONF_METAMOD
1.233 +PLUGIN_GLOBALVARS();
1.234 +extern IVEngineServer *engine;
1.235 +extern IServerGameDLL *gamedll;
1.236 +#endif
1.237 +
1.238 +/** Creates a SourceMod interface macro pair */
1.239 +#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
1.240 +/** Automates retrieving SourceMod interfaces */
1.241 +#define SM_GET_IFACE(prefix, addr) \
1.242 + if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
1.243 + { \
1.244 + if (error) \
1.245 + { \
1.246 + snprintf(error, maxlength, "Could not find interface: %s (version: %d)", SMINTERFACE_##prefix##_NAME, SMINTERFACE_##prefix##_VERSION); \
1.247 + return false; \
1.248 + } \
1.249 + }
1.250 +/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
1.251 +#define SM_GET_LATE_IFACE(prefix, addr) \
1.252 + g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
1.253 +/** Validates a SourceMod interface pointer */
1.254 +#define SM_CHECK_IFACE(prefix, addr) \
1.255 + if (!addr) \
1.256 + { \
1.257 + if (error) \
1.258 + { \
1.259 + snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
1.260 + return false; \
1.261 + } \
1.262 + }
1.263 +
1.264 +#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_