public/sample_ext/sdk/smsdk_ext.h
author David Anderson <dvander@alliedmods.net>
Fri Jul 27 18:24:09 2007 +0000 (2007-07-27)
changeset 1192 94ee3f012044
parent 1090 5c54e353c019
child 1226 478550a4d5ec
permissions -rw-r--r--
added a new function to ILibrarySys
added define in SDK for LIBRARYSYS
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>
dvander@859
    33
#if defined SMEXT_ENABLE_FORWARDSYS
ds@757
    34
#include <IForwardSys.h>
dvander@859
    35
#endif //SMEXT_ENABLE_FORWARDSYS
dvander@859
    36
#if defined SMEXT_ENABLE_PLAYERHELPERS
dvander@859
    37
#include <IPlayerHelpers.h>
dvander@859
    38
#endif //SMEXT_ENABLE_PlAYERHELPERS
dvander@859
    39
#if defined SMEXT_ENABLE_DBMANAGER
dvander@859
    40
#include <IDBDriver.h>
dvander@859
    41
#endif //SMEXT_ENABLE_DBMANAGER
dvander@934
    42
#if defined SMEXT_ENABLE_GAMECONF
dvander@934
    43
#include <IGameConfigs.h>
dvander@934
    44
#endif
dvander@963
    45
#if defined SMEXT_ENABLE_MEMUTILS
dvander@963
    46
#include <IMemoryUtils.h>
dvander@963
    47
#endif
dvander@1016
    48
#if defined SMEXT_ENABLE_GAMEHELPERS
dvander@1016
    49
#include <IGameHelpers.h>
dvander@1016
    50
#endif
dvander@1016
    51
#if defined SMEXT_ENABLE_TIMERSYS
dvander@1016
    52
#include <ITimerSystem.h>
dvander@1016
    53
#endif
dvander@1028
    54
#if defined SMEXT_ENABLE_ADTFACTORY
dvander@1028
    55
#include <IADTFactory.h>
dvander@1028
    56
#endif
dvander@1090
    57
#if defined SMEXT_ENABLE_THREADER
dvander@1090
    58
#include <IThreader.h>
dvander@1090
    59
#endif
dvander@1192
    60
#if defined SMEXT_ENABLE_LIBSYS
dvander@1192
    61
#include <ILibrarySys.h>
dvander@1192
    62
#endif
ds@757
    63
ds@757
    64
#if defined SMEXT_CONF_METAMOD
ds@757
    65
#include <ISmmPlugin.h>
ds@757
    66
#include <eiface.h>
ds@757
    67
#endif
ds@757
    68
ds@757
    69
using namespace SourceMod;
ds@757
    70
using namespace SourcePawn;
ds@757
    71
ds@757
    72
class SDKExtension : 
ds@757
    73
#if defined SMEXT_CONF_METAMOD
ds@757
    74
	public ISmmPlugin,
ds@757
    75
#endif
ds@757
    76
	public IExtensionInterface
ds@757
    77
{
ds@757
    78
public:
ds@757
    79
	/** Constructor */
ds@757
    80
	SDKExtension();
ds@757
    81
public:
ds@757
    82
	/**
ds@757
    83
	 * @brief This is called after the initial loading sequence has been processed.
ds@757
    84
	 *
ds@757
    85
	 * @param error		Error message buffer.
ds@757
    86
	 * @param maxlength	Size of error message buffer.
ds@757
    87
	 * @param late		Whether or not the module was loaded after map load.
ds@757
    88
	 * @return			True to succeed loading, false to fail.
ds@757
    89
	 */
ds@757
    90
	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
ds@757
    91
	
ds@757
    92
	/**
ds@757
    93
	 * @brief This is called right before the extension is unloaded.
ds@757
    94
	 */
ds@757
    95
	virtual void SDK_OnUnload();
ds@757
    96
ds@757
    97
	/**
ds@757
    98
	 * @brief This is called once all known extensions have been loaded.
ds@757
    99
	 */
ds@757
   100
	virtual void SDK_OnAllLoaded();
ds@757
   101
ds@757
   102
	/**
ds@757
   103
	 * @brief Called when the pause state is changed.
ds@757
   104
	 */
ds@757
   105
	virtual void SDK_OnPauseChange(bool paused);
ds@757
   106
ds@757
   107
#if defined SMEXT_CONF_METAMOD
ds@757
   108
	/**
ds@757
   109
	 * @brief Called when Metamod is attached, before the extension version is called.
ds@757
   110
	 *
ds@757
   111
	 * @param error			Error buffer.
ds@757
   112
	 * @param maxlength		Maximum size of error buffer.
ds@757
   113
	 * @param late			Whether or not Metamod considers this a late load.
ds@757
   114
	 * @return				True to succeed, false to fail.
ds@757
   115
	 */
ds@757
   116
	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
ds@757
   117
ds@757
   118
	/**
ds@757
   119
	 * @brief Called when Metamod is detaching, after the extension version is called.
ds@757
   120
	 * NOTE: By default this is blocked unless sent from SourceMod.
ds@757
   121
	 *
ds@757
   122
	 * @param error			Error buffer.
ds@757
   123
	 * @param maxlength		Maximum size of error buffer.
ds@757
   124
	 * @return				True to succeed, false to fail.
ds@757
   125
	 */
ds@757
   126
	virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
ds@757
   127
ds@757
   128
	/**
ds@757
   129
	 * @brief Called when Metamod's pause state is changing.
ds@757
   130
	 * NOTE: By default this is blocked unless sent from SourceMod.
ds@757
   131
	 *
ds@757
   132
	 * @param paused		Pause state being set.
ds@757
   133
	 * @param error			Error buffer.
ds@757
   134
	 * @param maxlength		Maximum size of error buffer.
ds@757
   135
	 * @return				True to succeed, false to fail.
ds@757
   136
	 */
ds@757
   137
	virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
ds@757
   138
#endif
ds@757
   139
ds@757
   140
public: //IExtensionInterface
ds@757
   141
	virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
ds@757
   142
	virtual void OnExtensionUnload();
ds@757
   143
	virtual void OnExtensionsAllLoaded();
ds@757
   144
ds@757
   145
	/** Returns whether or not this is a Metamod-based extension */
ds@757
   146
	virtual bool IsMetamodExtension();
ds@757
   147
ds@757
   148
	/**
ds@757
   149
	 * @brief Called when the pause state changes.
ds@757
   150
	 * 
ds@757
   151
	 * @param state			True if being paused, false if being unpaused.
ds@757
   152
	 */
ds@757
   153
	virtual void OnExtensionPauseChange(bool state);
ds@757
   154
ds@757
   155
	/** Returns name */
ds@757
   156
	virtual const char *GetExtensionName();
ds@757
   157
	/** Returns URL */
ds@757
   158
	virtual const char *GetExtensionURL();
ds@757
   159
	/** Returns log tag */
ds@757
   160
	virtual const char *GetExtensionTag();
ds@757
   161
	/** Returns author */
ds@757
   162
	virtual const char *GetExtensionAuthor();
ds@757
   163
	/** Returns version string */
ds@757
   164
	virtual const char *GetExtensionVerString();
ds@757
   165
	/** Returns description string */
ds@757
   166
	virtual const char *GetExtensionDescription();
ds@757
   167
	/** Returns date string */
ds@757
   168
	virtual const char *GetExtensionDateString();
ds@757
   169
#if defined SMEXT_CONF_METAMOD
ds@757
   170
public: //ISmmPlugin
ds@757
   171
	/** Called when the extension is attached to Metamod. */
ds@757
   172
	virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
ds@757
   173
	/** Returns the author to MM */
ds@757
   174
	virtual const char *GetAuthor();
ds@757
   175
	/** Returns the name to MM */
ds@757
   176
	virtual const char *GetName();
ds@757
   177
	/** Returns the description to MM */
ds@757
   178
	virtual const char *GetDescription();
ds@757
   179
	/** Returns the URL to MM */
ds@757
   180
	virtual const char *GetURL();
ds@757
   181
	/** Returns the license to MM */
ds@757
   182
	virtual const char *GetLicense();
ds@757
   183
	/** Returns the version string to MM */
ds@757
   184
	virtual const char *GetVersion();
ds@757
   185
	/** Returns the date string to MM */
ds@757
   186
	virtual const char *GetDate();
ds@757
   187
	/** Returns the logtag to MM */
ds@757
   188
	virtual const char *GetLogTag();
ds@757
   189
	/** Called on unload */
ds@757
   190
	virtual bool Unload(char *error, size_t maxlength);
ds@757
   191
	/** Called on pause */
ds@757
   192
	virtual bool Pause(char *error, size_t maxlength);
ds@757
   193
	/** Called on unpause */
ds@757
   194
	virtual bool Unpause(char *error, size_t maxlength);
ds@757
   195
private:
ds@757
   196
	bool m_SourceMMLoaded;
ds@757
   197
	bool m_WeAreUnloaded;
ds@757
   198
	bool m_WeGotPauseChange;
ds@757
   199
#endif
ds@757
   200
};
ds@757
   201
ds@757
   202
extern SDKExtension *g_pExtensionIface;
dvander@859
   203
extern IExtension *myself;
ds@757
   204
ds@757
   205
extern IShareSys *g_pShareSys;
dvander@859
   206
extern IShareSys *sharesys;				/* Note: Newer name */
dvander@859
   207
extern ISourceMod *g_pSM;
dvander@859
   208
extern ISourceMod *smutils;				/* Note: Newer name */
dvander@859
   209
dvander@859
   210
/* Optional interfaces are below */
dvander@859
   211
#if defined SMEXT_ENABLE_FORWARDSYS
dvander@859
   212
extern IForwardManager *g_pForwards;
dvander@859
   213
extern IForwardManager *forwards;		/* Note: Newer name */
dvander@859
   214
#endif //SMEXT_ENABLE_FORWARDSYS
dvander@859
   215
#if defined SMEXT_ENABLE_HANDLESYS
ds@757
   216
extern IHandleSys *g_pHandleSys;
dvander@859
   217
extern IHandleSys *handlesys;			/* Note: Newer name */
dvander@859
   218
#endif //SMEXT_ENABLE_HANDLESYS
dvander@859
   219
#if defined SMEXT_ENABLE_PLAYERHELPERS
dvander@934
   220
extern IPlayerManager *playerhelpers;
dvander@859
   221
#endif //SMEXT_ENABLE_PLAYERHELPERS
dvander@859
   222
#if defined SMEXT_ENABLE_DBMANAGER
dvander@859
   223
extern IDBManager *dbi;
dvander@859
   224
#endif //SMEXT_ENABLE_DBMANAGER
dvander@934
   225
#if defined SMEXT_ENABLE_GAMECONF
dvander@934
   226
extern IGameConfigManager *gameconfs;
dvander@934
   227
#endif //SMEXT_ENABLE_DBMANAGER
dvander@963
   228
#if defined SMEXT_ENABLE_MEMUTILS
dvander@963
   229
extern IMemoryUtils *memutils;
dvander@963
   230
#endif
dvander@1016
   231
#if defined SMEXT_ENABLE_GAMEHELPERS
dvander@1016
   232
extern IGameHelpers *gamehelpers;
dvander@1016
   233
#endif
dvander@1016
   234
#if defined SMEXT_ENABLE_TIMERSYS
dvander@1016
   235
extern ITimerSystem *timersys;
dvander@1016
   236
#endif
dvander@1028
   237
#if defined SMEXT_ENABLE_ADTFACTORY
dvander@1028
   238
extern IADTFactory *adtfactory;
dvander@1028
   239
#endif
dvander@1090
   240
#if defined SMEXT_ENABLE_THREADER
dvander@1090
   241
extern IThreader *threader;
dvander@1090
   242
#endif
dvander@1192
   243
#if defined SMEXT_ENABLE_LIBSYS
dvander@1192
   244
extern ILibrarySys *libsys;
dvander@1192
   245
#endif
ds@757
   246
ds@757
   247
#if defined SMEXT_CONF_METAMOD
ds@757
   248
PLUGIN_GLOBALVARS();
ds@757
   249
extern IVEngineServer *engine;
ds@757
   250
extern IServerGameDLL *gamedll;
ds@757
   251
#endif
ds@757
   252
ds@757
   253
/** Creates a SourceMod interface macro pair */
ds@757
   254
#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
ds@757
   255
/** Automates retrieving SourceMod interfaces */
ds@757
   256
#define SM_GET_IFACE(prefix, addr) \
ds@757
   257
	if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
ds@757
   258
	{ \
ds@757
   259
		if (error) \
ds@757
   260
		{ \
dvander@859
   261
			snprintf(error, maxlength, "Could not find interface: %s (version: %d)", SMINTERFACE_##prefix##_NAME, SMINTERFACE_##prefix##_VERSION); \
ds@757
   262
			return false; \
ds@757
   263
		} \
ds@757
   264
	}
ds@757
   265
/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
ds@757
   266
#define SM_GET_LATE_IFACE(prefix, addr) \
ds@757
   267
	g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
ds@757
   268
/** Validates a SourceMod interface pointer */
ds@757
   269
#define SM_CHECK_IFACE(prefix, addr) \
ds@757
   270
	if (!addr) \
ds@757
   271
	{ \
ds@757
   272
		if (error) \
ds@757
   273
		{ \
ds@757
   274
			snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
ds@757
   275
			return false; \
ds@757
   276
		} \
ds@757
   277
	}
ds@757
   278
ds@757
   279
#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_