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