extensions/clientprefs/sdk/smsdk_ext.h
author David Anderson <dvander@alliedmods.net>
Mon Aug 10 22:16:58 2009 -0400 (2009-08-10)
changeset 2767 c1f37afdcbb9
parent 2048 2454ff4d6afb
child 4029 cf8bdfcf6503
permissions -rw-r--r--
Fixed incorrect escaping in clientprefs SQLite queries (bug 3904, r+a12=pred).
pred@2009
     1
/**
pred@2009
     2
 * vim: set ts=4 :
pred@2009
     3
 * =============================================================================
pred@2009
     4
 * SourceMod Base Extension Code
pred@2009
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
pred@2009
     6
 * =============================================================================
pred@2009
     7
 *
pred@2009
     8
 * This program is free software; you can redistribute it and/or modify it under
pred@2009
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@2009
    10
 * Free Software Foundation.
pred@2009
    11
 * 
pred@2009
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@2009
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@2009
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@2009
    15
 * details.
pred@2009
    16
 *
pred@2009
    17
 * You should have received a copy of the GNU General Public License along with
pred@2009
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@2009
    19
 *
pred@2009
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@2009
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@2009
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@2009
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@2009
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@2009
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@2009
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@2009
    27
 * or <http://www.sourcemod.net/license.php>.
pred@2009
    28
 *
pred@2009
    29
 * Version: $Id$
pred@2009
    30
 */
pred@2009
    31
pred@2009
    32
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
pred@2009
    33
#define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
pred@2009
    34
pred@2009
    35
/**
pred@2009
    36
 * @file smsdk_ext.h
pred@2009
    37
 * @brief Contains wrappers for making Extensions easier to write.
pred@2009
    38
 */
pred@2009
    39
pred@2009
    40
#include "smsdk_config.h"
pred@2009
    41
#include <IExtensionSys.h>
pred@2009
    42
#include <IHandleSys.h>
pred@2009
    43
#include <sp_vm_api.h>
pred@2009
    44
#include <sm_platform.h>
pred@2009
    45
#include <ISourceMod.h>
pred@2009
    46
#if defined SMEXT_ENABLE_FORWARDSYS
pred@2009
    47
#include <IForwardSys.h>
pred@2009
    48
#endif //SMEXT_ENABLE_FORWARDSYS
pred@2009
    49
#if defined SMEXT_ENABLE_PLAYERHELPERS
pred@2009
    50
#include <IPlayerHelpers.h>
pred@2009
    51
#endif //SMEXT_ENABLE_PlAYERHELPERS
pred@2009
    52
#if defined SMEXT_ENABLE_DBMANAGER
pred@2009
    53
#include <IDBDriver.h>
pred@2009
    54
#endif //SMEXT_ENABLE_DBMANAGER
pred@2009
    55
#if defined SMEXT_ENABLE_GAMECONF
pred@2009
    56
#include <IGameConfigs.h>
pred@2009
    57
#endif
pred@2009
    58
#if defined SMEXT_ENABLE_MEMUTILS
pred@2009
    59
#include <IMemoryUtils.h>
pred@2009
    60
#endif
pred@2009
    61
#if defined SMEXT_ENABLE_GAMEHELPERS
pred@2009
    62
#include <IGameHelpers.h>
pred@2009
    63
#endif
pred@2009
    64
#if defined SMEXT_ENABLE_TIMERSYS
pred@2009
    65
#include <ITimerSystem.h>
pred@2009
    66
#endif
pred@2009
    67
#if defined SMEXT_ENABLE_ADTFACTORY
pred@2009
    68
#include <IADTFactory.h>
pred@2009
    69
#endif
pred@2009
    70
#if defined SMEXT_ENABLE_THREADER
pred@2009
    71
#include <IThreader.h>
pred@2009
    72
#endif
pred@2009
    73
#if defined SMEXT_ENABLE_LIBSYS
pred@2009
    74
#include <ILibrarySys.h>
pred@2009
    75
#endif
pred@2009
    76
#if defined SMEXT_ENABLE_PLUGINSYS
pred@2009
    77
#include <IPluginSys.h>
pred@2009
    78
#endif
pred@2009
    79
#if defined SMEXT_ENABLE_MENUS
pred@2009
    80
#include <IMenuManager.h>
pred@2009
    81
#endif
pred@2009
    82
#if defined SMEXT_ENABLE_ADMINSYS
pred@2009
    83
#include <IAdminSystem.h>
pred@2009
    84
#endif
pred@2009
    85
#if defined SMEXT_ENABLE_TEXTPARSERS
pred@2009
    86
#include <ITextParsers.h>
pred@2009
    87
#endif
pred@2009
    88
#if defined SMEXT_ENABLE_USERMSGS
pred@2009
    89
#include <IUserMessages.h>
pred@2009
    90
#endif
pred@2048
    91
#if defined SMEXT_ENABLE_TRANSLATOR
pred@2048
    92
#include <ITranslator.h>
pred@2048
    93
#endif
pred@2009
    94
pred@2009
    95
#if defined SMEXT_CONF_METAMOD
pred@2009
    96
#include <ISmmPlugin.h>
pred@2009
    97
#include <eiface.h>
pred@2009
    98
#endif
pred@2009
    99
pred@2009
   100
using namespace SourceMod;
pred@2009
   101
using namespace SourcePawn;
pred@2009
   102
pred@2009
   103
class SDKExtension : 
pred@2009
   104
#if defined SMEXT_CONF_METAMOD
pred@2009
   105
	public ISmmPlugin,
pred@2009
   106
#endif
pred@2009
   107
	public IExtensionInterface
pred@2009
   108
{
pred@2009
   109
public:
pred@2009
   110
	/** Constructor */
pred@2009
   111
	SDKExtension();
pred@2009
   112
public:
pred@2009
   113
	/**
pred@2009
   114
	 * @brief This is called after the initial loading sequence has been processed.
pred@2009
   115
	 *
pred@2009
   116
	 * @param error		Error message buffer.
pred@2009
   117
	 * @param maxlength	Size of error message buffer.
pred@2009
   118
	 * @param late		Whether or not the module was loaded after map load.
pred@2009
   119
	 * @return			True to succeed loading, false to fail.
pred@2009
   120
	 */
pred@2009
   121
	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
pred@2009
   122
	
pred@2009
   123
	/**
pred@2009
   124
	 * @brief This is called right before the extension is unloaded.
pred@2009
   125
	 */
pred@2009
   126
	virtual void SDK_OnUnload();
pred@2009
   127
pred@2009
   128
	/**
pred@2009
   129
	 * @brief This is called once all known extensions have been loaded.
pred@2009
   130
	 */
pred@2009
   131
	virtual void SDK_OnAllLoaded();
pred@2009
   132
pred@2009
   133
	/**
pred@2009
   134
	 * @brief Called when the pause state is changed.
pred@2009
   135
	 */
pred@2009
   136
	virtual void SDK_OnPauseChange(bool paused);
pred@2009
   137
pred@2009
   138
#if defined SMEXT_CONF_METAMOD
pred@2009
   139
	/**
pred@2009
   140
	 * @brief Called when Metamod is attached, before the extension version is called.
pred@2009
   141
	 *
pred@2009
   142
	 * @param error			Error buffer.
pred@2009
   143
	 * @param maxlength		Maximum size of error buffer.
pred@2009
   144
	 * @param late			Whether or not Metamod considers this a late load.
pred@2009
   145
	 * @return				True to succeed, false to fail.
pred@2009
   146
	 */
pred@2009
   147
	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
pred@2009
   148
pred@2009
   149
	/**
pred@2009
   150
	 * @brief Called when Metamod is detaching, after the extension version is called.
pred@2009
   151
	 * NOTE: By default this is blocked unless sent from SourceMod.
pred@2009
   152
	 *
pred@2009
   153
	 * @param error			Error buffer.
pred@2009
   154
	 * @param maxlength		Maximum size of error buffer.
pred@2009
   155
	 * @return				True to succeed, false to fail.
pred@2009
   156
	 */
pred@2009
   157
	virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
pred@2009
   158
pred@2009
   159
	/**
pred@2009
   160
	 * @brief Called when Metamod's pause state is changing.
pred@2009
   161
	 * NOTE: By default this is blocked unless sent from SourceMod.
pred@2009
   162
	 *
pred@2009
   163
	 * @param paused		Pause state being set.
pred@2009
   164
	 * @param error			Error buffer.
pred@2009
   165
	 * @param maxlength		Maximum size of error buffer.
pred@2009
   166
	 * @return				True to succeed, false to fail.
pred@2009
   167
	 */
pred@2009
   168
	virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
pred@2009
   169
#endif
pred@2009
   170
pred@2009
   171
public: //IExtensionInterface
pred@2009
   172
	virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late);
pred@2009
   173
	virtual void OnExtensionUnload();
pred@2009
   174
	virtual void OnExtensionsAllLoaded();
pred@2009
   175
pred@2009
   176
	/** Returns whether or not this is a Metamod-based extension */
pred@2009
   177
	virtual bool IsMetamodExtension();
pred@2009
   178
pred@2009
   179
	/**
pred@2009
   180
	 * @brief Called when the pause state changes.
pred@2009
   181
	 * 
pred@2009
   182
	 * @param state			True if being paused, false if being unpaused.
pred@2009
   183
	 */
pred@2009
   184
	virtual void OnExtensionPauseChange(bool state);
pred@2009
   185
pred@2009
   186
	/** Returns name */
pred@2009
   187
	virtual const char *GetExtensionName();
pred@2009
   188
	/** Returns URL */
pred@2009
   189
	virtual const char *GetExtensionURL();
pred@2009
   190
	/** Returns log tag */
pred@2009
   191
	virtual const char *GetExtensionTag();
pred@2009
   192
	/** Returns author */
pred@2009
   193
	virtual const char *GetExtensionAuthor();
pred@2009
   194
	/** Returns version string */
pred@2009
   195
	virtual const char *GetExtensionVerString();
pred@2009
   196
	/** Returns description string */
pred@2009
   197
	virtual const char *GetExtensionDescription();
pred@2009
   198
	/** Returns date string */
pred@2009
   199
	virtual const char *GetExtensionDateString();
pred@2009
   200
#if defined SMEXT_CONF_METAMOD
pred@2009
   201
public: //ISmmPlugin
pred@2009
   202
	/** Called when the extension is attached to Metamod. */
pred@2009
   203
	virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late);
pred@2009
   204
	/** Returns the author to MM */
pred@2009
   205
	virtual const char *GetAuthor();
pred@2009
   206
	/** Returns the name to MM */
pred@2009
   207
	virtual const char *GetName();
pred@2009
   208
	/** Returns the description to MM */
pred@2009
   209
	virtual const char *GetDescription();
pred@2009
   210
	/** Returns the URL to MM */
pred@2009
   211
	virtual const char *GetURL();
pred@2009
   212
	/** Returns the license to MM */
pred@2009
   213
	virtual const char *GetLicense();
pred@2009
   214
	/** Returns the version string to MM */
pred@2009
   215
	virtual const char *GetVersion();
pred@2009
   216
	/** Returns the date string to MM */
pred@2009
   217
	virtual const char *GetDate();
pred@2009
   218
	/** Returns the logtag to MM */
pred@2009
   219
	virtual const char *GetLogTag();
pred@2009
   220
	/** Called on unload */
pred@2009
   221
	virtual bool Unload(char *error, size_t maxlength);
pred@2009
   222
	/** Called on pause */
pred@2009
   223
	virtual bool Pause(char *error, size_t maxlength);
pred@2009
   224
	/** Called on unpause */
pred@2009
   225
	virtual bool Unpause(char *error, size_t maxlength);
pred@2009
   226
private:
pred@2009
   227
	bool m_SourceMMLoaded;
pred@2009
   228
	bool m_WeAreUnloaded;
pred@2009
   229
	bool m_WeGotPauseChange;
pred@2009
   230
#endif
pred@2009
   231
};
pred@2009
   232
pred@2009
   233
extern SDKExtension *g_pExtensionIface;
pred@2009
   234
extern IExtension *myself;
pred@2009
   235
pred@2009
   236
extern IShareSys *g_pShareSys;
pred@2009
   237
extern IShareSys *sharesys;				/* Note: Newer name */
pred@2009
   238
extern ISourceMod *g_pSM;
pred@2009
   239
extern ISourceMod *smutils;				/* Note: Newer name */
pred@2009
   240
pred@2009
   241
/* Optional interfaces are below */
pred@2009
   242
#if defined SMEXT_ENABLE_FORWARDSYS
pred@2009
   243
extern IForwardManager *g_pForwards;
pred@2009
   244
extern IForwardManager *forwards;		/* Note: Newer name */
pred@2009
   245
#endif //SMEXT_ENABLE_FORWARDSYS
pred@2009
   246
#if defined SMEXT_ENABLE_HANDLESYS
pred@2009
   247
extern IHandleSys *g_pHandleSys;
pred@2009
   248
extern IHandleSys *handlesys;			/* Note: Newer name */
pred@2009
   249
#endif //SMEXT_ENABLE_HANDLESYS
pred@2009
   250
#if defined SMEXT_ENABLE_PLAYERHELPERS
pred@2009
   251
extern IPlayerManager *playerhelpers;
pred@2009
   252
#endif //SMEXT_ENABLE_PLAYERHELPERS
pred@2009
   253
#if defined SMEXT_ENABLE_DBMANAGER
pred@2009
   254
extern IDBManager *dbi;
pred@2009
   255
#endif //SMEXT_ENABLE_DBMANAGER
pred@2009
   256
#if defined SMEXT_ENABLE_GAMECONF
pred@2009
   257
extern IGameConfigManager *gameconfs;
pred@2009
   258
#endif //SMEXT_ENABLE_DBMANAGER
pred@2009
   259
#if defined SMEXT_ENABLE_MEMUTILS
pred@2009
   260
extern IMemoryUtils *memutils;
pred@2009
   261
#endif
pred@2009
   262
#if defined SMEXT_ENABLE_GAMEHELPERS
pred@2009
   263
extern IGameHelpers *gamehelpers;
pred@2009
   264
#endif
pred@2009
   265
#if defined SMEXT_ENABLE_TIMERSYS
pred@2009
   266
extern ITimerSystem *timersys;
pred@2009
   267
#endif
pred@2009
   268
#if defined SMEXT_ENABLE_ADTFACTORY
pred@2009
   269
extern IADTFactory *adtfactory;
pred@2009
   270
#endif
pred@2009
   271
#if defined SMEXT_ENABLE_THREADER
pred@2009
   272
extern IThreader *threader;
pred@2009
   273
#endif
pred@2009
   274
#if defined SMEXT_ENABLE_LIBSYS
pred@2009
   275
extern ILibrarySys *libsys;
pred@2009
   276
#endif
pred@2009
   277
#if defined SMEXT_ENABLE_PLUGINSYS
pred@2009
   278
extern SourceMod::IPluginManager *plsys;
pred@2009
   279
#endif
pred@2009
   280
#if defined SMEXT_ENABLE_MENUS
pred@2009
   281
extern IMenuManager *menus;
pred@2009
   282
#endif
pred@2009
   283
#if defined SMEXT_ENABLE_ADMINSYS
pred@2009
   284
extern IAdminSystem *adminsys;
pred@2009
   285
#endif
pred@2009
   286
#if defined SMEXT_ENABLE_USERMSGS
pred@2009
   287
extern IUserMessages *usermsgs;
pred@2009
   288
#endif
pred@2048
   289
#if defined SMEXT_ENABLE_TRANSLATOR
pred@2048
   290
extern ITranslator *translator;
pred@2048
   291
#endif
pred@2009
   292
pred@2009
   293
#if defined SMEXT_CONF_METAMOD
pred@2009
   294
PLUGIN_GLOBALVARS();
pred@2009
   295
extern IVEngineServer *engine;
pred@2009
   296
extern IServerGameDLL *gamedll;
pred@2009
   297
#endif
pred@2009
   298
pred@2009
   299
/** Creates a SourceMod interface macro pair */
pred@2009
   300
#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
pred@2009
   301
/** Automates retrieving SourceMod interfaces */
pred@2009
   302
#define SM_GET_IFACE(prefix, addr) \
pred@2009
   303
	if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
pred@2009
   304
	{ \
pred@2009
   305
		if (error != NULL && maxlength) \
pred@2009
   306
		{ \
pred@2009
   307
			size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
pred@2009
   308
			if (len >= maxlength) \
pred@2009
   309
			{ \
pred@2009
   310
				error[maxlength - 1] = '\0'; \
pred@2009
   311
			} \
pred@2009
   312
		} \
pred@2009
   313
		return false; \
pred@2009
   314
	}
pred@2009
   315
/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
pred@2009
   316
#define SM_GET_LATE_IFACE(prefix, addr) \
pred@2009
   317
	g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)
pred@2009
   318
/** Validates a SourceMod interface pointer */
pred@2009
   319
#define SM_CHECK_IFACE(prefix, addr) \
pred@2009
   320
	if (!addr) \
pred@2009
   321
	{ \
pred@2009
   322
		if (error != NULL && maxlength) \
pred@2009
   323
		{ \
pred@2009
   324
			size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
pred@2009
   325
			if (len >= maxlength) \
pred@2009
   326
			{ \
pred@2009
   327
				error[maxlength - 1] = '\0'; \
pred@2009
   328
			} \
pred@2009
   329
		} \
pred@2009
   330
		return false; \
pred@2009
   331
	}
pred@2009
   332
pred@2009
   333
#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_