core-legacy/ISmmAPI.h
author David Anderson <dvander@alliedmods.net>
Wed Oct 28 23:14:32 2009 -0700 (2009-10-28)
changeset 659 b35a5fdbc654
parent 545 07e5df11f9fc
child 664 a62858ce7114
permissions -rw-r--r--
Merged PM's unreleased SourceHook-legacy, getting us VP hooks (bug 4019, r=ds).
dvander@541
     1
/* ======== SourceMM ========
dvander@541
     2
* Copyright (C) 2004-2008 Metamod:Source Development Team
dvander@541
     3
* No warranties of any kind
dvander@541
     4
*
dvander@541
     5
* License: zlib/libpng
dvander@541
     6
*
dvander@541
     7
* Author(s): David "BAILOPAN" Anderson
dvander@541
     8
* ============================
dvander@541
     9
*/
dvander@541
    10
dvander@541
    11
#ifndef _INCLUDE_ISMM_API_H
dvander@541
    12
#define _INCLUDE_ISMM_API_H
dvander@541
    13
dvander@541
    14
/**
dvander@541
    15
 * @brief External API interface
dvander@541
    16
 * @file ISmmAPI.h
dvander@541
    17
 */
dvander@541
    18
dvander@541
    19
#include <interface.h>
dvander@541
    20
#include <eiface.h>
dvander@541
    21
#include <sourcehook/sourcehook.h>
dvander@541
    22
#include "IPluginManager.h"
dvander@541
    23
dvander@541
    24
#if defined __GNUC__
dvander@541
    25
#if ((__GNUC__ == 3) && (__GNUC_MINOR__ < 4)) || (__GNUC__ < 3)
dvander@541
    26
#error "You must compile with at least GCC 3.4! If you know what you are doing, you can remove this message."
dvander@541
    27
#endif //version check
dvander@541
    28
#endif //__GNUC__
dvander@541
    29
dvander@541
    30
class IMetamodListener;
dvander@541
    31
class ISmmPluginManager;
dvander@541
    32
class ISmmPlugin;
dvander@541
    33
dvander@541
    34
#define	MMIFACE_SOURCEHOOK		"ISourceHook"			/**< ISourceHook Pointer */
dvander@541
    35
#define	MMIFACE_PLMANAGER		"IPluginManager"		/**< SourceMM Plugin Functions */
dvander@541
    36
#define IFACE_MAXNUM			999
dvander@541
    37
dvander@541
    38
class ISmmAPI
dvander@541
    39
{
dvander@541
    40
public:
dvander@541
    41
	/**
dvander@541
    42
	 * @brief Logs a message through the HL2 log system.
dvander@541
    43
	 * Note: Newlines are appended automatically.
dvander@541
    44
	 *
dvander@541
    45
	 * @param pl			Plugin API pointer (used for tagging message)
dvander@541
    46
	 * @param msg			Formatted string.
dvander@541
    47
	 */
dvander@541
    48
	virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
dvander@541
    49
public:
dvander@541
    50
	/**
dvander@541
    51
	 * @brief Returns an interface factory for the HL2 engine.
dvander@541
    52
	 *
dvander@541
    53
	 * @param syn			If syn is true, the synthetic wrapper is returned.  
dvander@541
    54
	 *						If syn is false, the true function is returned.
dvander@541
    55
	 * @return				CreateInterfaceFn function pointer.
dvander@541
    56
	 */
dvander@541
    57
	virtual CreateInterfaceFn engineFactory(bool syn=true) =0;
dvander@541
    58
dvander@541
    59
	/**
dvander@541
    60
	 * @brief Returns an interface factory for the HL2 physics engine.
dvander@541
    61
	 *
dvander@541
    62
	 * @param syn			If syn is true, the synthetic wrapper is returned.  
dvander@541
    63
	 *						If syn is false, the true function is returned.
dvander@541
    64
	 * @return				CreateInterfaceFn function pointer.
dvander@541
    65
	 */
dvander@541
    66
	virtual CreateInterfaceFn physicsFactory(bool syn=true) =0;
dvander@541
    67
dvander@541
    68
	/**
dvander@541
    69
	 * @brief Returns an interface factory for the HL2 file system.
dvander@541
    70
	 *
dvander@541
    71
	 * @param syn			If syn is true, the synthetic wrapper is returned.  
dvander@541
    72
	 *						If syn is false, the true function is returned.
dvander@541
    73
	 * @return				CreateInterfaceFn function pointer.
dvander@541
    74
	 */
dvander@541
    75
	virtual CreateInterfaceFn fileSystemFactory(bool syn=true) =0;
dvander@541
    76
dvander@541
    77
	/**
dvander@541
    78
	 * @brief Returns an interface factory for the GameDLL.
dvander@541
    79
	 *
dvander@541
    80
	 * @param syn			If syn is true, the synthetic wrapper is returned.  
dvander@541
    81
	 *						If syn is false, the true function is returned.
dvander@541
    82
	 * @return				CreateInterfaceFn function pointer.
dvander@541
    83
	 */
dvander@541
    84
	virtual CreateInterfaceFn serverFactory(bool syn=true) =0;
dvander@541
    85
dvander@541
    86
	/**
dvander@541
    87
	 * @brief Returns a CGlobalVars pointer from the HL2 Engine.
dvander@541
    88
	 *
dvander@541
    89
	 * @return				CGlobalVars pointer.
dvander@541
    90
	 */
dvander@541
    91
	virtual CGlobalVars *pGlobals() =0;
dvander@541
    92
dvander@541
    93
	/**
dvander@541
    94
	 * @brief Used with SourceHook, sets teh last meta return value.
dvander@541
    95
	 * Note: Do not call this directly, use the Metamod macros.
dvander@541
    96
	 *
dvander@541
    97
	 * @param res			META_RETURN value to set.
dvander@541
    98
	 */
dvander@541
    99
	virtual void SetLastMetaReturn(META_RES res) =0;
dvander@541
   100
dvander@541
   101
	/**
dvander@541
   102
	 * @brief Used with SourceHook, returns the last meta return value.
dvander@541
   103
	 * Note: This is only valid inside a hook function.
dvander@541
   104
	 *
dvander@541
   105
	 * @return				Last META_RETURN value set by a plugin.
dvander@541
   106
	 */
dvander@541
   107
	virtual META_RES GetLastMetaReturn() =0;
dvander@541
   108
dvander@541
   109
public:		// Added in 1.00-RC2 (0:0)
dvander@541
   110
	/**
dvander@541
   111
	 * @brief Allows access to Metamod's ConCommandBaseAccessor.
dvander@541
   112
	 *
dvander@541
   113
	 * @return				Returns IConCommandBaseAccessor pointer.
dvander@541
   114
	 */
dvander@541
   115
	virtual IConCommandBaseAccessor *GetCvarBaseAccessor() =0;
dvander@541
   116
dvander@541
   117
	/**
dvander@541
   118
	 * @brief Registers a ConCommandBase.
dvander@541
   119
	 *
dvander@541
   120
	 * @param plugin		Parent plugin API pointer.
dvander@541
   121
	 * @param pCommand		ConCommandBase to register.
dvander@541
   122
	 * @return				True if successful, false otherwise.  Does not return false yet.
dvander@541
   123
	 */
dvander@541
   124
	virtual bool RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
dvander@541
   125
dvander@541
   126
	/**
dvander@541
   127
	 * @brief Unregisters a ConCommandBase.
dvander@541
   128
	 *
dvander@541
   129
	 * @param plugin		Parent plugin API pointer.
dvander@541
   130
	 * @param pCommand		ConCommandBase to unlink.
dvander@541
   131
	 */
dvander@541
   132
	virtual void UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
dvander@541
   133
	
dvander@541
   134
	/**
dvander@541
   135
	 * @brief Prints an unformatted string to the remote server console.
dvander@541
   136
	 * Note: Newlines are not added automatically.
dvander@541
   137
	 *
dvander@541
   138
	 * @param str			Message string.
dvander@541
   139
	 */
dvander@541
   140
	virtual void ConPrint(const char *str) =0;
dvander@541
   141
dvander@541
   142
	/**
dvander@541
   143
	 * @brief Prints a formatted message to the remote server console.  
dvander@541
   144
	 * Note: Newlines are not added automatically.
dvander@541
   145
	 *
dvander@541
   146
	 * @param fmt			Formatted message.
dvander@541
   147
	 */
dvander@541
   148
	virtual void ConPrintf(const char *fmt, ...) =0;
dvander@541
   149
dvander@541
   150
public:		// Added in 1.1.0 (1:0)
dvander@541
   151
	/**
dvander@541
   152
	 * @brief Checks if ConPrint/ConPrintf will mirror to rcon.
dvander@541
   153
	 *
dvander@541
   154
	 * @return				True if remote printing available, false otherwise.
dvander@541
   155
	 */
dvander@541
   156
	virtual bool RemotePrintingAvailable() =0;
dvander@541
   157
dvander@541
   158
	/**
dvander@541
   159
	 * @brief Returns the Metamod Version numbers as major version and minor (API) version.
dvander@541
   160
	 * Changes to minor version are guaranteed to be backwards compatible.
dvander@541
   161
	 * Changes to major version are not.
dvander@541
   162
	 * 
dvander@541
   163
	 * @param major			Filled with the major API version number.
dvander@541
   164
	 * @param minor			Filled with the minor API version number.
dvander@541
   165
	 * @param plvers		Filled with the current plugin API version number.
dvander@541
   166
	 * @param plmin			Filled with the minimum plugin API version number supported.
dvander@541
   167
	 */
dvander@541
   168
	virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
dvander@541
   169
	
dvander@541
   170
	/** 
dvander@541
   171
	 * @brief Returns sourcehook API version and implementation version.
dvander@541
   172
	 *
dvander@541
   173
	 * @param shvers		Filled with the SourceHook API version number.
dvander@541
   174
	 * @param shimpl		Filled with the SourceHook implementation number.
dvander@541
   175
	 */
dvander@541
   176
	virtual void GetShVersions(int &shvers, int &shimpl) =0;
dvander@541
   177
	
dvander@541
   178
	/**
dvander@541
   179
	 * @brief Adds a Metamod listener.
dvander@541
   180
	 *
dvander@541
   181
	 * @param plugin		Plugin interface pointer.
dvander@541
   182
	 * @param pListener		Listener interface pointer to add.
dvander@541
   183
	 */
dvander@541
   184
	virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
dvander@541
   185
dvander@541
   186
	/**
dvander@541
   187
	  * @brief Queries the metamod factory
dvander@541
   188
	  *
dvander@541
   189
	  * @param iface		String containing interface name
dvander@541
   190
	  * @param ret			Optional pointer to store return status
dvander@541
   191
	  * @param id			Optional pointer to store id of plugin that overrode interface, 0 if none
dvander@541
   192
	  * @return				Returned pointer
dvander@541
   193
	  */
dvander@541
   194
	virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
dvander@541
   195
dvander@541
   196
public:		// Added in 1.1.2 (1:1)
dvander@541
   197
	/**
dvander@541
   198
	 * @brief Given a base interface name, such as ServerGameDLL or ServerGameDLL003, 
dvander@541
   199
	 * reformats the string to increase the number, then returns the new number.
dvander@541
   200
	 * This is the base function to InterfaceSearch() and VInterfaceMatch().
dvander@541
   201
	 * 
dvander@541
   202
	 * @param iface			Input/output interface name.  Must be writable.
dvander@541
   203
	 * @param maxlength		Maximum length of iface buffer.  Must be at least strlen(iface)+4 chars.
dvander@541
   204
	 * @return				The newly incremented iface version number.
dvander@541
   205
	 */
dvander@541
   206
	virtual int FormatIface(char iface[], unsigned int maxlength) =0;
dvander@541
   207
dvander@541
   208
public:		// Added in 1.2 (1:2)
dvander@541
   209
	/**
dvander@541
   210
	 * @brief Searches for an interface for you.
dvander@541
   211
	 * 
dvander@541
   212
	 * @param fn			InterfaceFactory function.
dvander@541
   213
	 * @param iface			Interface string name.
dvander@541
   214
	 * @param max			Maximum version to look up.
dvander@541
   215
	 * @param ret			Last return code from interface factory function.
dvander@541
   216
	 * @return				Interface pointer, or NULL if not found.
dvander@541
   217
	 */
dvander@541
   218
	virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
dvander@541
   219
dvander@541
   220
	/**
dvander@541
   221
	 * @brief Returns the base directory of the game/server, equivalent to 
dvander@541
   222
	 *  IVEngineServer::GetGameDir(), except the path is absolute.
dvander@541
   223
	 *
dvander@541
   224
	 * @return				Static pointer to game's absolute basedir.
dvander@541
   225
	 */
dvander@541
   226
	virtual const char *GetBaseDir() =0;
dvander@541
   227
dvander@541
   228
	/**
dvander@541
   229
	 * @brief Formats a file path to the local OS.  Does not include any base directories.
dvander@541
   230
	 * Note that all slashes and black slashes are reverted to the local OS's expectancy.
dvander@541
   231
	 *
dvander@541
   232
	 * @param buffer		Destination buffer to store path.
dvander@541
   233
	 * @param len			Maximum length of buffer, including null terminator.
dvander@541
   234
	 * @param fmt			Formatted string.
dvander@541
   235
	 */
dvander@541
   236
	virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
dvander@541
   237
dvander@541
   238
public:		// Added in 1.2.2 (1:3)
dvander@541
   239
	/**
dvander@541
   240
	 * @brief Prints text in the specified client's console. Same as IVEngineServer::ClientPrintf 
dvander@541
   241
	 *  except that it allows for string formatting.
dvander@541
   242
	 *
dvander@541
   243
	 * @param client		Client edict pointer.
dvander@541
   244
	 * @param fmt			Formatted string to print to the client.
dvander@541
   245
	 */
dvander@541
   246
	virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
dvander@541
   247
dvander@541
   248
public:		// Added in 1.3 (1:4)
dvander@541
   249
	/**
dvander@541
   250
	 * @brief Wrapper around InterfaceSearch().  Assumes no maximum.
dvander@541
   251
	 * This is designed to replace the fact that searches only went upwards.
dvander@541
   252
	 * The "V" is intended to convey that this is for Valve formatted interface strings.
dvander@541
   253
	 *
dvander@541
   254
	 * @param fn			Interface factory function.
dvander@541
   255
	 * @param iface			Interface string.
dvander@541
   256
	 * @param min			Minimum value to search from.  If zero, searching begins from the
dvander@541
   257
	 *                       first available version regardless of the interface.  
dvander@541
   258
	 *                      Note that this can return interfaces EARLIER than the version specified.
dvander@541
   259
	 *                      A value of -1 (default) specifies the string version as the minimum.
dvander@541
   260
	 *                      Any other value specifices the minimum value to search from.
dvander@541
   261
	 * @return				Interface pointer, or NULL if not found.
dvander@541
   262
	 */
dvander@541
   263
	virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1) =0;
dvander@541
   264
dvander@541
   265
public:		// Added in 1.4 (1:5)
dvander@541
   266
	/**
dvander@541
   267
	 * @brief Tells SourceMM to add VSP hooking capability to plugins.  
dvander@541
   268
	 *
dvander@541
   269
	 * Since this  potentially uses more resources than it would otherwise, plugins have to 
dvander@541
   270
	 * explicitly enable the feature.  Whether requested or not, if it is enabled, all plugins 
dvander@541
   271
	 * will get a pointer to the VSP listener through IMetamodListener.
dvander@541
   272
	 */
dvander@541
   273
	virtual void EnableVSPListener() =0;
dvander@541
   274
dvander@541
   275
	/**
dvander@541
   276
	 * @brief Returns the interface version of the GameDLL's IServerGameDLL implementation.
dvander@541
   277
	 *
dvander@541
   278
	 * @return				Interface version of the loaded IServerGameDLL.
dvander@541
   279
	 */
dvander@541
   280
	virtual int GetGameDLLVersion() =0;
dvander@541
   281
dvander@541
   282
	/**
dvander@541
   283
	 * @brief Returns the number of user messages in the GameDLL.
dvander@541
   284
	 *
dvander@541
   285
	 * @return				Number of user messages, or -1 if SourceMM has failed to get user message list.
dvander@541
   286
	 */
dvander@541
   287
	virtual int GetUserMessageCount() =0;
dvander@541
   288
dvander@541
   289
	/**
dvander@541
   290
	 * @brief Returns the index of the specified user message.
dvander@541
   291
	 *
dvander@541
   292
	 * @param name			User message name.
dvander@541
   293
	 * @param size			Optional pointer to store size of user message.
dvander@541
   294
	 * @return				Message index, or -1 on failure.
dvander@541
   295
	 */
dvander@541
   296
	virtual int FindUserMessage(const char *name, int *size=NULL) =0;
dvander@541
   297
dvander@541
   298
	/**
dvander@541
   299
	 * @brief Returns the name of the specified user message.
dvander@541
   300
	 *
dvander@541
   301
	 * @param index			User message index.
dvander@541
   302
	 * @param size			Optional pointer to store size of user message.
dvander@541
   303
	 * @return				Message name, or NULL on failure.
dvander@541
   304
	 */
dvander@541
   305
	virtual const char *GetUserMessage(int index, int *size=NULL) =0;
dvander@541
   306
};
dvander@541
   307
dvander@541
   308
dvander@541
   309
/** 
dvander@541
   310
 * Version History
dvander@541
   311
 *
dvander@541
   312
 * 1.1.0 Bumped API to 1:0. The breaking changes occurred in SourceHook and the plugin API.
dvander@541
   313
 * 1.1.2 Added API call for generating iface names.
dvander@541
   314
 * 1.2   Added API more helper functions and new SourceHook version.
dvander@541
   315
 * 1.2.2 Added API for printing to client console (with string formatting).
dvander@541
   316
 * 1.3   Added new interface search API.
dvander@541
   317
 * 1.4	 Added VSP listener and user message API.
dvander@659
   318
 * 1.8   Added VP hooks to SH-legacy.
dvander@541
   319
 */
dvander@541
   320
dvander@541
   321
#endif //_INCLUDE_ISMM_API_H