core-legacy/ISmmAPI.h
author David Anderson <dvander@alliedmods.net>
Mon Nov 18 12:42:17 2013 -0800 (2013-11-18)
changeset 885 a4c8a8c571a0
parent 667 938f7325d919
permissions -rw-r--r--
Fix dependency graph.
     1 /* ======== SourceMM ========
     2 * Copyright (C) 2004-2008 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
    37 
    38 #define SOURCE_ENGINE_UNKNOWN			0				/**< Could not determine the engine version */
    39 #define SOURCE_ENGINE_ORIGINAL			1				/**< Original Source Engine (used by The Ship) */
    40 #define SOURCE_ENGINE_EPISODEONE		2				/**< Episode 1 Source Engine (second 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.  Does not return false yet.
   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 	 * Note: Newlines are not added automatically.
   141 	 *
   142 	 * @param str			Message string.
   143 	 */
   144 	virtual void ConPrint(const char *str) =0;
   145 
   146 	/**
   147 	 * @brief Prints a formatted message to the remote server console.  
   148 	 * Note: Newlines are not added automatically.
   149 	 *
   150 	 * @param fmt			Formatted message.
   151 	 */
   152 	virtual void ConPrintf(const char *fmt, ...) =0;
   153 
   154 public:		// Added in 1.1.0 (1:0)
   155 	/**
   156 	 * @brief Checks if ConPrint/ConPrintf will mirror to rcon.
   157 	 *
   158 	 * @return				True if remote printing available, false otherwise.
   159 	 */
   160 	virtual bool RemotePrintingAvailable() =0;
   161 
   162 	/**
   163 	 * @brief Returns the Metamod Version numbers as major version and minor (API) version.
   164 	 * Changes to minor version are guaranteed to be backwards compatible.
   165 	 * Changes to major version are not.
   166 	 * 
   167 	 * @param major			Filled with the major API version number.
   168 	 * @param minor			Filled with the minor API version number.
   169 	 * @param plvers		Filled with the current plugin API version number.
   170 	 * @param plmin			Filled with the minimum plugin API version number supported.
   171 	 */
   172 	virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
   173 	
   174 	/** 
   175 	 * @brief Returns sourcehook API version and implementation version.
   176 	 *
   177 	 * @param shvers		Filled with the SourceHook API version number.
   178 	 * @param shimpl		Filled with the SourceHook implementation number.
   179 	 */
   180 	virtual void GetShVersions(int &shvers, int &shimpl) =0;
   181 	
   182 	/**
   183 	 * @brief Adds a Metamod listener.
   184 	 *
   185 	 * @param plugin		Plugin interface pointer.
   186 	 * @param pListener		Listener interface pointer to add.
   187 	 */
   188 	virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
   189 
   190 	/**
   191 	  * @brief Queries the metamod factory
   192 	  *
   193 	  * @param iface		String containing interface name
   194 	  * @param ret			Optional pointer to store return status
   195 	  * @param id			Optional pointer to store id of plugin that overrode interface, 0 if none
   196 	  * @return				Returned pointer
   197 	  */
   198 	virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
   199 
   200 public:		// Added in 1.1.2 (1:1)
   201 	/**
   202 	 * @brief Given a base interface name, such as ServerGameDLL or ServerGameDLL003, 
   203 	 * reformats the string to increase the number, then returns the new number.
   204 	 * This is the base function to InterfaceSearch() and VInterfaceMatch().
   205 	 * 
   206 	 * @param iface			Input/output interface name.  Must be writable.
   207 	 * @param maxlength		Maximum length of iface buffer.  Must be at least strlen(iface)+4 chars.
   208 	 * @return				The newly incremented iface version number.
   209 	 */
   210 	virtual int FormatIface(char iface[], unsigned int maxlength) =0;
   211 
   212 public:		// Added in 1.2 (1:2)
   213 	/**
   214 	 * @brief Searches for an interface for you.
   215 	 * 
   216 	 * @param fn			InterfaceFactory function.
   217 	 * @param iface			Interface string name.
   218 	 * @param max			Maximum version to look up.
   219 	 * @param ret			Last return code from interface factory function.
   220 	 * @return				Interface pointer, or NULL if not found.
   221 	 */
   222 	virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
   223 
   224 	/**
   225 	 * @brief Returns the base directory of the game/server, equivalent to 
   226 	 *  IVEngineServer::GetGameDir(), except the path is absolute.
   227 	 *
   228 	 * @return				Static pointer to game's absolute basedir.
   229 	 */
   230 	virtual const char *GetBaseDir() =0;
   231 
   232 	/**
   233 	 * @brief Formats a file path to the local OS.  Does not include any base directories.
   234 	 * Note that all slashes and black slashes are reverted to the local OS's expectancy.
   235 	 *
   236 	 * @param buffer		Destination buffer to store path.
   237 	 * @param len			Maximum length of buffer, including null terminator.
   238 	 * @param fmt			Formatted string.
   239 	 */
   240 	virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
   241 
   242 public:		// Added in 1.2.2 (1:3)
   243 	/**
   244 	 * @brief Prints text in the specified client's console. Same as IVEngineServer::ClientPrintf 
   245 	 *  except that it allows for string formatting.
   246 	 *
   247 	 * @param client		Client edict pointer.
   248 	 * @param fmt			Formatted string to print to the client.
   249 	 */
   250 	virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
   251 
   252 public:		// Added in 1.3 (1:4)
   253 	/**
   254 	 * @brief Wrapper around InterfaceSearch().  Assumes no maximum.
   255 	 * This is designed to replace the fact that searches only went upwards.
   256 	 * The "V" is intended to convey that this is for Valve formatted interface strings.
   257 	 *
   258 	 * @param fn			Interface factory function.
   259 	 * @param iface			Interface string.
   260 	 * @param min			Minimum value to search from.  If zero, searching begins from the
   261 	 *                       first available version regardless of the interface.  
   262 	 *                      Note that this can return interfaces EARLIER than the version specified.
   263 	 *                      A value of -1 (default) specifies the string version as the minimum.
   264 	 *                      Any other value specifices the minimum value to search from.
   265 	 * @return				Interface pointer, or NULL if not found.
   266 	 */
   267 	virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1) =0;
   268 
   269 public:		// Added in 1.4 (1:5)
   270 	/**
   271 	 * @brief Tells SourceMM to add VSP hooking capability to plugins.  
   272 	 *
   273 	 * Since this  potentially uses more resources than it would otherwise, plugins have to 
   274 	 * explicitly enable the feature.  Whether requested or not, if it is enabled, all plugins 
   275 	 * will get a pointer to the VSP listener through IMetamodListener.
   276 	 */
   277 	virtual void EnableVSPListener() =0;
   278 
   279 	/**
   280 	 * @brief Returns the interface version of the GameDLL's IServerGameDLL implementation.
   281 	 *
   282 	 * @return				Interface version of the loaded IServerGameDLL.
   283 	 */
   284 	virtual int GetGameDLLVersion() =0;
   285 
   286 	/**
   287 	 * @brief Returns the number of user messages in the GameDLL.
   288 	 *
   289 	 * @return				Number of user messages, or -1 if SourceMM has failed to get user message list.
   290 	 */
   291 	virtual int GetUserMessageCount() =0;
   292 
   293 	/**
   294 	 * @brief Returns the index of the specified user message.
   295 	 *
   296 	 * @param name			User message name.
   297 	 * @param size			Optional pointer to store size of user message.
   298 	 * @return				Message index, or -1 on failure.
   299 	 */
   300 	virtual int FindUserMessage(const char *name, int *size=NULL) =0;
   301 
   302 	/**
   303 	 * @brief Returns the name of the specified user message.
   304 	 *
   305 	 * @param index			User message index.
   306 	 * @param size			Optional pointer to store size of user message.
   307 	 * @return				Message name, or NULL on failure.
   308 	 */
   309 	virtual const char *GetUserMessage(int index, int *size=NULL) =0;
   310 
   311 	/**
   312 	 * @brief Returns the VSP listener loaded.
   313 	 *
   314 	 * This is useful for late-loading plugins which need to decide whether 
   315 	 * to add a listener or not (or need to get the pointer at all).
   316 	 *
   317 	 * @param pVersion		Optional pointer to store the VSP version.
   318 	 * @return				IServerPluginCallbacks pointer, or NULL if an
   319 	 * 						IMetamodListener event has yet to occur for 
   320 	 * 						EnableVSPListener().
   321 	 */
   322 	virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0;
   323 
   324 	/**
   325 	 * @brief Returns the engine interface that MM:S is using as a backend.
   326 	 *
   327 	 * The values will be one of the SOURCE_ENGINE_* constants from the top
   328 	 * of this file.
   329 	 *
   330 	 * @return				A SOURCE_ENGINE_* constant value.
   331 	 */
   332 	virtual int GetSourceEngineBuild() =0;
   333 
   334 };
   335 
   336 
   337 /** 
   338  * Version History
   339  *
   340  * 1.1.0 Bumped API to 1:0. The breaking changes occurred in SourceHook and the plugin API.
   341  * 1.1.2 Added API call for generating iface names.
   342  * 1.2   Added API more helper functions and new SourceHook version.
   343  * 1.2.2 Added API for printing to client console (with string formatting).
   344  * 1.3   Added new interface search API.
   345  * 1.4	 Added VSP listener and user message API.
   346  * 1.8   Backported SH VP hooks and various "new API" calls.
   347  */
   348 
   349 #endif //_INCLUDE_ISMM_API_H