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