extensions/bintools/sdk/smsdk_ext.h
changeset 757 b799caa9a190
child 943 a4fa40b1a151
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/bintools/sdk/smsdk_ext.h	Wed May 09 05:20:03 2007 +0000
     1.3 @@ -0,0 +1,213 @@
     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 +#include <IForwardSys.h>
    1.37 +
    1.38 +#if defined SMEXT_CONF_METAMOD
    1.39 +#include <ISmmPlugin.h>
    1.40 +#include <eiface.h>
    1.41 +#endif
    1.42 +
    1.43 +using namespace SourceMod;
    1.44 +using namespace SourcePawn;
    1.45 +
    1.46 +class SDKExtension : 
    1.47 +#if defined SMEXT_CONF_METAMOD
    1.48 +	public ISmmPlugin,
    1.49 +#endif
    1.50 +	public IExtensionInterface
    1.51 +{
    1.52 +public:
    1.53 +	/** Constructor */
    1.54 +	SDKExtension();
    1.55 +public:
    1.56 +	/**
    1.57 +	 * @brief This is called after the initial loading sequence has been processed.
    1.58 +	 *
    1.59 +	 * @param error		Error message buffer.
    1.60 +	 * @param maxlength	Size of error message buffer.
    1.61 +	 * @param late		Whether or not the module was loaded after map load.
    1.62 +	 * @return			True to succeed loading, false to fail.
    1.63 +	 */
    1.64 +	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
    1.65 +	
    1.66 +	/**
    1.67 +	 * @brief This is called right before the extension is unloaded.
    1.68 +	 */
    1.69 +	virtual void SDK_OnUnload();
    1.70 +
    1.71 +	/**
    1.72 +	 * @brief This is called once all known extensions have been loaded.
    1.73 +	 */
    1.74 +	virtual void SDK_OnAllLoaded();
    1.75 +
    1.76 +	/**
    1.77 +	 * @brief Called when the pause state is changed.
    1.78 +	 */
    1.79 +	virtual void SDK_OnPauseChange(bool paused);
    1.80 +
    1.81 +#if defined SMEXT_CONF_METAMOD
    1.82 +	/**
    1.83 +	 * @brief Called when Metamod is attached, before the extension version is called.
    1.84 +	 *
    1.85 +	 * @param error			Error buffer.
    1.86 +	 * @param maxlength		Maximum size of error buffer.
    1.87 +	 * @param late			Whether or not Metamod considers this a late load.
    1.88 +	 * @return				True to succeed, false to fail.
    1.89 +	 */
    1.90 +	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
    1.91 +
    1.92 +	/**
    1.93 +	 * @brief Called when Metamod is detaching, after the extension version is called.
    1.94 +	 * NOTE: By default this is blocked unless sent from SourceMod.
    1.95 +	 *
    1.96 +	 * @param error			Error buffer.
    1.97 +	 * @param maxlength		Maximum size of error buffer.
    1.98 +	 * @return				True to succeed, false to fail.
    1.99 +	 */
   1.100 +	virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
   1.101 +
   1.102 +	/**
   1.103 +	 * @brief Called when Metamod's pause state is changing.
   1.104 +	 * NOTE: By default this is blocked unless sent from SourceMod.
   1.105 +	 *
   1.106 +	 * @param paused		Pause state being set.
   1.107 +	 * @param error			Error buffer.
   1.108 +	 * @param maxlength		Maximum size of error buffer.
   1.109 +	 * @return				True to succeed, false to fail.
   1.110 +	 */
   1.111 +	virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
   1.112 +#endif
   1.113 +
   1.114 +public: // IExtensionInterface
   1.115 +	virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
   1.116 +	virtual void OnExtensionUnload();
   1.117 +	virtual void OnExtensionsAllLoaded();
   1.118 +
   1.119 +	/** Returns whether or not this is a Metamod-based extension */
   1.120 +	virtual bool IsMetamodExtension();
   1.121 +
   1.122 +	/**
   1.123 +	 * @brief Called when the pause state changes.
   1.124 +	 * 
   1.125 +	 * @param state			True if being paused, false if being unpaused.
   1.126 +	 */
   1.127 +	virtual void OnExtensionPauseChange(bool state);
   1.128 +
   1.129 +	/** Returns name */
   1.130 +	virtual const char *GetExtensionName();
   1.131 +	/** Returns URL */
   1.132 +	virtual const char *GetExtensionURL();
   1.133 +	/** Returns log tag */
   1.134 +	virtual const char *GetExtensionTag();
   1.135 +	/** Returns author */
   1.136 +	virtual const char *GetExtensionAuthor();
   1.137 +	/** Returns version string */
   1.138 +	virtual const char *GetExtensionVerString();
   1.139 +	/** Returns description string */
   1.140 +	virtual const char *GetExtensionDescription();
   1.141 +	/** Returns date string */
   1.142 +	virtual const char *GetExtensionDateString();
   1.143 +#if defined SMEXT_CONF_METAMOD
   1.144 +public: // ISmmPlugin
   1.145 +	/** Called when the extension is attached to Metamod. */
   1.146 +	virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late);
   1.147 +	/** Returns the author to MM */
   1.148 +	virtual const char *GetAuthor();
   1.149 +	/** Returns the name to MM */
   1.150 +	virtual const char *GetName();
   1.151 +	/** Returns the description to MM */
   1.152 +	virtual const char *GetDescription();
   1.153 +	/** Returns the URL to MM */
   1.154 +	virtual const char *GetURL();
   1.155 +	/** Returns the license to MM */
   1.156 +	virtual const char *GetLicense();
   1.157 +	/** Returns the version string to MM */
   1.158 +	virtual const char *GetVersion();
   1.159 +	/** Returns the date string to MM */
   1.160 +	virtual const char *GetDate();
   1.161 +	/** Returns the logtag to MM */
   1.162 +	virtual const char *GetLogTag();
   1.163 +	/** Called on unload */
   1.164 +	virtual bool Unload(char *error, size_t maxlen);
   1.165 +	/** Called on pause */
   1.166 +	virtual bool Pause(char *error, size_t maxlen);
   1.167 +	/** Called on unpause */
   1.168 +	virtual bool Unpause(char *error, size_t maxlen);
   1.169 +private:
   1.170 +	bool m_SourceMMLoaded;
   1.171 +	bool m_WeAreUnloaded;
   1.172 +	bool m_WeGotPauseChange;
   1.173 +#endif
   1.174 +};
   1.175 +
   1.176 +extern SDKExtension *g_pExtensionIface;
   1.177 +
   1.178 +extern IShareSys *g_pShareSys;
   1.179 +extern IExtension *myself;
   1.180 +extern IHandleSys *g_pHandleSys;
   1.181 +extern ISourceMod *g_pSM;
   1.182 +extern IForwardManager *g_pForwards;
   1.183 +
   1.184 +#if defined SMEXT_CONF_METAMOD
   1.185 +PLUGIN_GLOBALVARS();
   1.186 +extern IVEngineServer *engine;
   1.187 +extern IServerGameDLL *gamedll;
   1.188 +#endif
   1.189 +
   1.190 +/** Creates a SourceMod interface macro pair */
   1.191 +#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
   1.192 +/** Automates retrieving SourceMod interfaces */
   1.193 +#define SM_GET_IFACE(prefix, addr) \
   1.194 +	if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
   1.195 +	{ \
   1.196 +		if (error) \
   1.197 +		{ \
   1.198 +			snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
   1.199 +			return false; \
   1.200 +		} \
   1.201 +	}
   1.202 +/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
   1.203 +#define SM_GET_LATE_IFACE(prefix, addr) \
   1.204 +	g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
   1.205 +/** Validates a SourceMod interface pointer */
   1.206 +#define SM_CHECK_IFACE(prefix, addr) \
   1.207 +	if (!addr) \
   1.208 +	{ \
   1.209 +		if (error) \
   1.210 +		{ \
   1.211 +			snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
   1.212 +			return false; \
   1.213 +		} \
   1.214 +	}
   1.215 +
   1.216 +#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_