extensions/batsupport/sdk/smsdk_ext.h
author Scott Ehlert <ds@alliedmods.net>
Wed May 09 05:20:03 2007 +0000 (2007-05-09)
changeset 757 b799caa9a190
child 1330 ab94316bb52b
permissions -rw-r--r--
Whew, massive-ish reorgranization for extensions and such. I will inevitably be shot for this.
(Yes, bail, it all compiles on both platforms)
ds@757
     1
/**
ds@757
     2
 * vim: set ts=4 :
ds@757
     3
 * ===============================================================
ds@757
     4
 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
ds@757
     5
 * All rights reserved.
ds@757
     6
 * ===============================================================
ds@757
     7
 *
ds@757
     8
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
ds@757
     9
 * used or modified under the Terms and Conditions of its License Agreement, 
ds@757
    10
 * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
ds@757
    11
 * works must be licensed under the GNU General Public License (version 2 or 
ds@757
    12
 * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
ds@757
    13
 * 
ds@757
    14
 * To view the latest information, see: http://www.sourcemod.net/license.php
ds@757
    15
 *
ds@757
    16
 * Version: $Id$
ds@757
    17
 */
ds@757
    18
ds@757
    19
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
ds@757
    20
#define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
ds@757
    21
ds@757
    22
/**
ds@757
    23
 * @file smsdk_ext.h
ds@757
    24
 * @brief Contains wrappers for making Extensions easier to write.
ds@757
    25
 */
ds@757
    26
ds@757
    27
#include "smsdk_config.h"
ds@757
    28
#include <IExtensionSys.h>
ds@757
    29
#include <IHandleSys.h>
ds@757
    30
#include <sp_vm_api.h>
ds@757
    31
#include <sm_platform.h>
ds@757
    32
#include <ISourceMod.h>
ds@757
    33
#include <IForwardSys.h>
ds@757
    34
ds@757
    35
#if defined SMEXT_CONF_METAMOD
ds@757
    36
#include <ISmmPlugin.h>
ds@757
    37
#include <eiface.h>
ds@757
    38
#endif
ds@757
    39
ds@757
    40
using namespace SourceMod;
ds@757
    41
using namespace SourcePawn;
ds@757
    42
ds@757
    43
class SDKExtension : 
ds@757
    44
#if defined SMEXT_CONF_METAMOD
ds@757
    45
	public ISmmPlugin,
ds@757
    46
#endif
ds@757
    47
	public IExtensionInterface
ds@757
    48
{
ds@757
    49
public:
ds@757
    50
	/** Constructor */
ds@757
    51
	SDKExtension();
ds@757
    52
public:
ds@757
    53
	/**
ds@757
    54
	 * @brief This is called after the initial loading sequence has been processed.
ds@757
    55
	 *
ds@757
    56
	 * @param error		Error message buffer.
ds@757
    57
	 * @param maxlength	Size of error message buffer.
ds@757
    58
	 * @param late		Whether or not the module was loaded after map load.
ds@757
    59
	 * @return			True to succeed loading, false to fail.
ds@757
    60
	 */
ds@757
    61
	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
ds@757
    62
	
ds@757
    63
	/**
ds@757
    64
	 * @brief This is called right before the extension is unloaded.
ds@757
    65
	 */
ds@757
    66
	virtual void SDK_OnUnload();
ds@757
    67
ds@757
    68
	/**
ds@757
    69
	 * @brief This is called once all known extensions have been loaded.
ds@757
    70
	 */
ds@757
    71
	virtual void SDK_OnAllLoaded();
ds@757
    72
ds@757
    73
	/**
ds@757
    74
	 * @brief Called when the pause state is changed.
ds@757
    75
	 */
ds@757
    76
	virtual void SDK_OnPauseChange(bool paused);
ds@757
    77
ds@757
    78
#if defined SMEXT_CONF_METAMOD
ds@757
    79
	/**
ds@757
    80
	 * @brief Called when Metamod is attached, before the extension version is called.
ds@757
    81
	 *
ds@757
    82
	 * @param error			Error buffer.
ds@757
    83
	 * @param maxlength		Maximum size of error buffer.
ds@757
    84
	 * @param late			Whether or not Metamod considers this a late load.
ds@757
    85
	 * @return				True to succeed, false to fail.
ds@757
    86
	 */
ds@757
    87
	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
ds@757
    88
ds@757
    89
	/**
ds@757
    90
	 * @brief Called when Metamod is detaching, after the extension version is called.
ds@757
    91
	 * NOTE: By default this is blocked unless sent from SourceMod.
ds@757
    92
	 *
ds@757
    93
	 * @param error			Error buffer.
ds@757
    94
	 * @param maxlength		Maximum size of error buffer.
ds@757
    95
	 * @return				True to succeed, false to fail.
ds@757
    96
	 */
ds@757
    97
	virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
ds@757
    98
ds@757
    99
	/**
ds@757
   100
	 * @brief Called when Metamod's pause state is changing.
ds@757
   101
	 * NOTE: By default this is blocked unless sent from SourceMod.
ds@757
   102
	 *
ds@757
   103
	 * @param paused		Pause state being set.
ds@757
   104
	 * @param error			Error buffer.
ds@757
   105
	 * @param maxlength		Maximum size of error buffer.
ds@757
   106
	 * @return				True to succeed, false to fail.
ds@757
   107
	 */
ds@757
   108
	virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
ds@757
   109
#endif
ds@757
   110
ds@757
   111
public: // IExtensionInterface
ds@757
   112
	virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
ds@757
   113
	virtual void OnExtensionUnload();
ds@757
   114
	virtual void OnExtensionsAllLoaded();
ds@757
   115
ds@757
   116
	/** Returns whether or not this is a Metamod-based extension */
ds@757
   117
	virtual bool IsMetamodExtension();
ds@757
   118
ds@757
   119
	/**
ds@757
   120
	 * @brief Called when the pause state changes.
ds@757
   121
	 * 
ds@757
   122
	 * @param state			True if being paused, false if being unpaused.
ds@757
   123
	 */
ds@757
   124
	virtual void OnExtensionPauseChange(bool state);
ds@757
   125
ds@757
   126
	/** Returns name */
ds@757
   127
	virtual const char *GetExtensionName();
ds@757
   128
	/** Returns URL */
ds@757
   129
	virtual const char *GetExtensionURL();
ds@757
   130
	/** Returns log tag */
ds@757
   131
	virtual const char *GetExtensionTag();
ds@757
   132
	/** Returns author */
ds@757
   133
	virtual const char *GetExtensionAuthor();
ds@757
   134
	/** Returns version string */
ds@757
   135
	virtual const char *GetExtensionVerString();
ds@757
   136
	/** Returns description string */
ds@757
   137
	virtual const char *GetExtensionDescription();
ds@757
   138
	/** Returns date string */
ds@757
   139
	virtual const char *GetExtensionDateString();
ds@757
   140
#if defined SMEXT_CONF_METAMOD
ds@757
   141
public: // ISmmPlugin
ds@757
   142
	/** Called when the extension is attached to Metamod. */
ds@757
   143
	virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late);
ds@757
   144
	/** Returns the author to MM */
ds@757
   145
	virtual const char *GetAuthor();
ds@757
   146
	/** Returns the name to MM */
ds@757
   147
	virtual const char *GetName();
ds@757
   148
	/** Returns the description to MM */
ds@757
   149
	virtual const char *GetDescription();
ds@757
   150
	/** Returns the URL to MM */
ds@757
   151
	virtual const char *GetURL();
ds@757
   152
	/** Returns the license to MM */
ds@757
   153
	virtual const char *GetLicense();
ds@757
   154
	/** Returns the version string to MM */
ds@757
   155
	virtual const char *GetVersion();
ds@757
   156
	/** Returns the date string to MM */
ds@757
   157
	virtual const char *GetDate();
ds@757
   158
	/** Returns the logtag to MM */
ds@757
   159
	virtual const char *GetLogTag();
ds@757
   160
	/** Called on unload */
ds@757
   161
	virtual bool Unload(char *error, size_t maxlen);
ds@757
   162
	/** Called on pause */
ds@757
   163
	virtual bool Pause(char *error, size_t maxlen);
ds@757
   164
	/** Called on unpause */
ds@757
   165
	virtual bool Unpause(char *error, size_t maxlen);
ds@757
   166
private:
ds@757
   167
	bool m_SourceMMLoaded;
ds@757
   168
	bool m_WeAreUnloaded;
ds@757
   169
	bool m_WeGotPauseChange;
ds@757
   170
#endif
ds@757
   171
};
ds@757
   172
ds@757
   173
extern SDKExtension *g_pExtensionIface;
ds@757
   174
ds@757
   175
extern IShareSys *g_pShareSys;
ds@757
   176
extern IExtension *myself;
ds@757
   177
extern IHandleSys *g_pHandleSys;
ds@757
   178
extern ISourceMod *g_pSM;
ds@757
   179
extern IForwardManager *g_pForwards;
ds@757
   180
ds@757
   181
#if defined SMEXT_CONF_METAMOD
ds@757
   182
PLUGIN_GLOBALVARS();
ds@757
   183
extern IVEngineServer *engine;
ds@757
   184
extern IServerGameDLL *gamedll;
ds@757
   185
#endif
ds@757
   186
ds@757
   187
/** Creates a SourceMod interface macro pair */
ds@757
   188
#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
ds@757
   189
/** Automates retrieving SourceMod interfaces */
ds@757
   190
#define SM_GET_IFACE(prefix, addr) \
ds@757
   191
	if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
ds@757
   192
	{ \
ds@757
   193
		if (error) \
ds@757
   194
		{ \
ds@757
   195
			snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
ds@757
   196
			return false; \
ds@757
   197
		} \
ds@757
   198
	}
ds@757
   199
/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
ds@757
   200
#define SM_GET_LATE_IFACE(prefix, addr) \
ds@757
   201
	g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
ds@757
   202
/** Validates a SourceMod interface pointer */
ds@757
   203
#define SM_CHECK_IFACE(prefix, addr) \
ds@757
   204
	if (!addr) \
ds@757
   205
	{ \
ds@757
   206
		if (error) \
ds@757
   207
		{ \
ds@757
   208
			snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
ds@757
   209
			return false; \
ds@757
   210
		} \
ds@757
   211
	}
ds@757
   212
ds@757
   213
#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_