sourcemm/ISmmAPI.h
author David Anderson <dvander@alliedmods.net>
Thu Oct 04 19:18:19 2007 +0000 (2007-10-04)
branchsourcemm-1.6.0
changeset 369 2b8c2ea08b6d
parent 367 fc76472b980f
permissions -rw-r--r--
fixed usermessages not printing
removed old ConMsg extraction code
     1 /**
     2  * vim: set ts=4 :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2007 AlliedModders LLC and authors.
     6  * All rights reserved.
     7  * ======================================================
     8  *
     9  * This software is provided 'as-is', without any express or implied warranty.
    10  * In no event will the authors be held liable for any damages arising from 
    11  * the use of this software.
    12  * 
    13  * Permission is granted to anyone to use this software for any purpose, 
    14  * including commercial applications, and to alter it and redistribute it 
    15  * freely, subject to the following restrictions:
    16  *
    17  * 1. The origin of this software must not be misrepresented; you must not 
    18  * claim that you wrote the original software. If you use this software in a 
    19  * product, an acknowledgment in the product documentation would be 
    20  * appreciated but is not required.
    21  * 2. Altered source versions must be plainly marked as such, and must not be
    22  * misrepresented as being the original software.
    23  * 3. This notice may not be removed or altered from any source distribution.
    24  *
    25  * Version: $Id$
    26  */
    27 
    28 #ifndef _INCLUDE_ISMM_API_H
    29 #define _INCLUDE_ISMM_API_H
    30 
    31 /**
    32  * @brief External API interface
    33  * @file ISmmAPI.h
    34  */
    35 
    36 #include <interface.h>
    37 #include <eiface.h>
    38 #include <sourcehook.h>
    39 #include "IPluginManager.h"
    40 
    41 #if defined __GNUC__
    42 #if ((__GNUC__ == 3) && (__GNUC_MINOR__ < 4)) || (__GNUC__ < 3)
    43 #error "You must compile with at least GCC 3.4! If you know what you are doing, you can remove this message."
    44 #endif //version check
    45 #endif //__GNUC__
    46 
    47 class IMetamodListener;
    48 class ISmmPluginManager;
    49 class ISmmPlugin;
    50 
    51 #define	MMIFACE_SOURCEHOOK		"ISourceHook"			/**< ISourceHook Pointer */
    52 #define	MMIFACE_PLMANAGER		"IPluginManager"		/**< SourceMM Plugin Functions */
    53 #define IFACE_MAXNUM			999						/**< Maximum interface version */
    54 
    55 #define SOURCE_ENGINE_UNKNOWN			0				/**< Could not determine the engine version */
    56 #define SOURCE_ENGINE_ORIGINAL			1				/**< Original Source Engine (used by The Ship) */
    57 #define SOURCE_ENGINE_EPISODEONE		2				/**< Episode 1 Source Engine (second major SDK) */
    58 #define SOURCE_ENGINE_ORANGEBOX			3				/**< Orange Box Source Engine (third major SDK) */
    59 
    60 class ISmmAPI
    61 {
    62 public:
    63 	/**
    64 	 * @brief Logs a message through the HL2 log system.
    65 	 * Note: Newlines are appended automatically.
    66 	 *
    67 	 * @param pl			Plugin API pointer (used for tagging message)
    68 	 * @param msg			Formatted string.
    69 	 */
    70 	virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
    71 public:
    72 	/**
    73 	 * @brief Returns an interface factory for the HL2 engine.
    74 	 *
    75 	 * @param syn			If syn is true, the synthetic wrapper is returned.  
    76 	 *						If syn is false, the true function is returned.
    77 	 * @return				CreateInterfaceFn function pointer.
    78 	 */
    79 	virtual CreateInterfaceFn engineFactory(bool syn=true) =0;
    80 
    81 	/**
    82 	 * @brief Returns an interface factory for the HL2 physics engine.
    83 	 *
    84 	 * @param syn			If syn is true, the synthetic wrapper is returned.  
    85 	 *						If syn is false, the true function is returned.
    86 	 * @return				CreateInterfaceFn function pointer.
    87 	 */
    88 	virtual CreateInterfaceFn physicsFactory(bool syn=true) =0;
    89 
    90 	/**
    91 	 * @brief Returns an interface factory for the HL2 file system.
    92 	 *
    93 	 * @param syn			If syn is true, the synthetic wrapper is returned.  
    94 	 *						If syn is false, the true function is returned.
    95 	 * @return				CreateInterfaceFn function pointer.
    96 	 */
    97 	virtual CreateInterfaceFn fileSystemFactory(bool syn=true) =0;
    98 
    99 	/**
   100 	 * @brief Returns an interface factory for the GameDLL.
   101 	 *
   102 	 * @param syn			If syn is true, the synthetic wrapper is returned.  
   103 	 *						If syn is false, the true function is returned.
   104 	 * @return				CreateInterfaceFn function pointer.
   105 	 */
   106 	virtual CreateInterfaceFn serverFactory(bool syn=true) =0;
   107 
   108 	/**
   109 	 * @brief Returns a CGlobalVars pointer from the HL2 Engine.
   110 	 *
   111 	 * @return				CGlobalVars pointer.
   112 	 */
   113 	virtual CGlobalVars *pGlobals() =0;
   114 
   115 	/**
   116 	 * @brief Used with SourceHook, sets teh last meta return value.
   117 	 * Note: Do not call this directly, use the Metamod macros.
   118 	 *
   119 	 * @param res			META_RETURN value to set.
   120 	 */
   121 	virtual void SetLastMetaReturn(META_RES res) =0;
   122 
   123 	/**
   124 	 * @brief Used with SourceHook, returns the last meta return value.
   125 	 * Note: This is only valid inside a hook function.
   126 	 *
   127 	 * @return				Last META_RETURN value set by a plugin.
   128 	 */
   129 	virtual META_RES GetLastMetaReturn() =0;
   130 
   131 public:		// Added in 1.00-RC2 (0:0)
   132 	/**
   133 	 * @brief Allows access to Metamod's ConCommandBaseAccessor.
   134 	 *
   135 	 * @return				Returns IConCommandBaseAccessor pointer.
   136 	 */
   137 	virtual IConCommandBaseAccessor *GetCvarBaseAccessor() =0;
   138 
   139 	/**
   140 	 * @brief Registers a ConCommandBase.
   141 	 *
   142 	 * @param plugin		Parent plugin API pointer.
   143 	 * @param pCommand		ConCommandBase to register.
   144 	 * @return				True if successful, false otherwise.
   145 	 */
   146 	virtual bool RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
   147 
   148 	/**
   149 	 * @brief Unregisters a ConCommandBase.
   150 	 *
   151 	 * @param plugin		Parent plugin API pointer.
   152 	 * @param pCommand		ConCommandBase to unlink.
   153 	 */
   154 	virtual void UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
   155 	
   156 	/**
   157 	 * @brief Prints an unformatted string to the remote server console.
   158 	 * 
   159 	 * Note: Newlines are not added automatically.
   160 	 *
   161 	 * @param str			Message string.
   162 	 */
   163 	virtual void ConPrint(const char *str) =0;
   164 
   165 	/**
   166 	 * @brief Prints a formatted message to the remote server console.  
   167 	 * 
   168 	 * Note: Newlines are not added automatically.
   169 	 *
   170 	 * @param fmt			Formatted message.
   171 	 */
   172 	virtual void ConPrintf(const char *fmt, ...) =0;
   173 
   174 public:		// Added in 1.1.0 (1:0)
   175 	/**
   176 	 * @brief Checks if ConPrint/ConPrintf will mirror to rcon.
   177 	 *
   178 	 * @return				True if remote printing available, false otherwise.
   179 	 */
   180 	virtual bool RemotePrintingAvailable() =0;
   181 
   182 	/**
   183 	 * @brief Returns the Metamod Version numbers as major version and minor (API) version.
   184 	 * Changes to minor version are guaranteed to be backwards compatible.
   185 	 * Changes to major version are not.
   186 	 * 
   187 	 * @param major			Filled with the major API version number.
   188 	 * @param minor			Filled with the minor API version number.
   189 	 * @param plvers		Filled with the current plugin API version number.
   190 	 * @param plmin			Filled with the minimum plugin API version number supported.
   191 	 */
   192 	virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
   193 	
   194 	/** 
   195 	 * @brief Returns sourcehook API version and implementation version.
   196 	 *
   197 	 * @param shvers		Filled with the SourceHook API version number.
   198 	 * @param shimpl		Filled with the SourceHook implementation number.
   199 	 */
   200 	virtual void GetShVersions(int &shvers, int &shimpl) =0;
   201 	
   202 	/**
   203 	 * @brief Adds a Metamod listener.
   204 	 *
   205 	 * @param plugin		Plugin interface pointer.
   206 	 * @param pListener		Listener interface pointer to add.
   207 	 */
   208 	virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
   209 
   210 	/**
   211 	  * @brief Queries the metamod factory
   212 	  *
   213 	  * @param iface		String containing interface name
   214 	  * @param ret			Optional pointer to store return status
   215 	  * @param id			Optional pointer to store id of plugin that overrode interface, 0 if none
   216 	  * @return				Returned pointer
   217 	  */
   218 	virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
   219 
   220 public:		// Added in 1.1.2 (1:1)
   221 	/**
   222 	 * @brief Given a base interface name, such as ServerGameDLL or ServerGameDLL003, 
   223 	 * reformats the string to increase the number, then returns the new number.
   224 	 * This is the base function to InterfaceSearch() and VInterfaceMatch().
   225 	 * 
   226 	 * @param iface			Input/output interface name.  Must be writable.
   227 	 * @param maxlength		Maximum length of iface buffer.  Must be at least strlen(iface)+4 chars.
   228 	 * @return				The newly incremented iface version number.
   229 	 */
   230 	virtual int FormatIface(char iface[], unsigned int maxlength) =0;
   231 
   232 public:		// Added in 1.2 (1:2)
   233 	/**
   234 	 * @brief Searches for an interface, eliminating the need to loop through FormatIface().
   235 	 * 
   236 	 * @param fn			InterfaceFactory function.
   237 	 * @param iface			Interface string name.
   238 	 * @param max			Maximum version to look up.
   239 	 * @param ret			Last return code from interface factory function.
   240 	 * @return				Interface pointer, or NULL if not found.
   241 	 */
   242 	virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
   243 
   244 	/**
   245 	 * @brief Returns the base directory of the game/server, equivalent to 
   246 	 * IVEngineServer::GetGameDir(), except the path is absolute.
   247 	 *
   248 	 * @return				Static pointer to game's absolute basedir.
   249 	 */
   250 	virtual const char *GetBaseDir() =0;
   251 
   252 	/**
   253 	 * @brief Formats a file path to the local OS.  
   254 	 *
   255 	 * Does not include any base directories.  Note that all slashes and black 
   256 	 * slashes are reverted to the local OS's expectancy.
   257 	 *
   258 	 * @param buffer		Destination buffer to store path.
   259 	 * @param len			Maximum length of buffer, including null terminator.
   260 	 * @param fmt			Formatted string.
   261 	 */
   262 	virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
   263 
   264 public:		// Added in 1.2.2 (1:3)
   265 	/**
   266 	 * @brief Prints text in the specified client's console. Same as 
   267 	 * IVEngineServer::ClientPrintf except that it allows for string formatting.
   268 	 *
   269 	 * @param client		Client edict pointer.
   270 	 * @param fmt			Formatted string to print to the client.
   271 	 */
   272 	virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
   273 
   274 public:		// Added in 1.3 (1:4)
   275 	/**
   276 	 * @brief Wrapper around InterfaceSearch().  Assumes no maximum.
   277 	 * This is designed to replace the fact that searches only went upwards.
   278 	 * The "V" is intended to convey that this is for Valve formatted interface strings.
   279 	 *
   280 	 * @param fn			Interface factory function.
   281 	 * @param iface			Interface string.
   282 	 * @param min			Minimum value to search from.  If zero, searching 
   283 	 *						begins from the first available version regardless 
   284 	 *						of the interface.  Note that this can return 
   285 	 *						interfaces EARLIER than the version specified.  A 
   286 	 *						value of -1 (default) specifies the string version 
   287 	 *						as the minimum.  Any other value specifices the 
   288 	 *						minimum value to search from.
   289 	 * @return				Interface pointer, or NULL if not found.
   290 	 */
   291 	virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1) =0;
   292 
   293 public:		// Added in 1.4 (1:5)
   294 	/**
   295 	 * @brief Tells SourceMM to add VSP hooking capability to plugins.  
   296 	 *
   297 	 * Since this  potentially uses more resources than it would otherwise, 
   298 	 * plugins have to explicitly enable the feature.  Whether requested or 
   299 	 * not, if it is enabled, all plugins will get a pointer to the VSP 
   300 	 * listener through IMetamodListener.  This will not be called more than 
   301 	 * once for a given plugin; if it is requested more than once, each 
   302 	 * successive call will only give the pointer to plugins which have not 
   303 	 * yet received it.
   304 	 */
   305 	virtual void EnableVSPListener() =0;
   306 
   307 	/**
   308 	 * @brief Returns the interface version of the GameDLL's IServerGameDLL 
   309 	 * implementation.
   310 	 *
   311 	 * @return				Interface version of the loaded IServerGameDLL.
   312 	 */
   313 	virtual int GetGameDLLVersion() =0;
   314 
   315 	/**
   316 	 * @brief Returns the number of user messages in the GameDLL.
   317 	 *
   318 	 * @return				Number of user messages, or -1 if SourceMM has 
   319 	 *						failed to get user message list.
   320 	 */
   321 	virtual int GetUserMessageCount() =0;
   322 
   323 	/**
   324 	 * @brief Returns the index of the specified user message.
   325 	 *
   326 	 * @param name			User message name.
   327 	 * @param size			Optional pointer to store size of user message.
   328 	 * @return				Message index, or -1 on failure.
   329 	 */
   330 	virtual int FindUserMessage(const char *name, int *size=NULL) =0;
   331 
   332 	/**
   333 	 * @brief Returns the name of the specified user message.
   334 	 *
   335 	 * @param index			User message index.
   336 	 * @param size			Optional pointer to store size of user message.
   337 	 * @return				Message name, or NULL on failure.
   338 	 */
   339 	virtual const char *GetUserMessage(int index, int *size=NULL) =0;
   340 
   341 public:		// Added in 1.5.0 (1:6)
   342 	/**
   343 	 * @brief Returns the highest interface version of IServerPluginCallbacks 
   344 	 * that the engine supports.  This is useful for games that run on older 
   345 	 * versions of the Source engine, such as The Ship.
   346 	 *
   347 	 * @return				Highest interface version of IServerPluginCallbacks.
   348 	 *						Returns 0 if SourceMM's VSP listener isn't currently 
   349 	 *						enabled.
   350 	 */
   351 	virtual int GetVSPVersion() =0;
   352 
   353 public:		// Added in 1.6.0 (1:7)
   354 	/**
   355 	 * @brief Returns the engine interface that MM:S is using as a backend.
   356 	 *
   357 	 * The values will be one of the SOURCE_ENGINE_* constants from the top
   358 	 * of this file.
   359 	 *
   360 	 * @return				A SOURCE_ENGINE_* constant value.
   361 	 */
   362 	virtual int GetSourceEngineBuild() =0;
   363 
   364 	/**
   365 	 * @brief Returns the VSP listener loaded.  
   366 	 *
   367 	 * This is useful for late-loading plugins which need to decide whether 
   368 	 * to add a listener or not (or need to get the pointer at all).
   369 	 *
   370 	 * @param				Optional pointer to store the VSP version.
   371 	 * @return				IServerPluginCallbacks pointer, or NULL if an
   372 	 * 						IMetamodListener event has yet to occur for 
   373 	 * 						EnableVSPListener().
   374 	 */
   375 	virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0;
   376 };
   377 
   378 
   379 /** 
   380  * Version History
   381  *
   382  * 1.1.0 Bumped API to 1:0. The breaking changes occurred in SourceHook and the plugin API.
   383  * 1.1.2 Added API call for generating iface names.
   384  * 1.2   Added API more helper functions and new SourceHook version.
   385  * 1.2.2 Added API for printing to client console (with string formatting).
   386  * 1.3   Added new interface search API.
   387  * 1.4	 Added VSP listener and user message API.
   388  * 1.5.0 Added API for getting highest supported version of IServerPluginCallbacks.
   389  * 1.6.0 Added API for Orange Box.
   390  */
   391 
   392 #endif //_INCLUDE_ISMM_API_H
   393