sourcemm/ISmmAPI.h
author Scott Ehlert <ds@alliedmods.net>
Sun Aug 27 05:39:59 2006 +0000 (2006-08-27)
changeset 256 3ebdfd08c624
parent 251 3bd7e7008ac3
child 280 946485e00593
permissions -rw-r--r--
Fixed makefiles for the HL2 SDK move
     1 /* ======== SourceMM ========
     2 * Copyright (C) 2004-2006 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 <convar.h>
    22 #include <sourcehook/sourcehook.h>
    23 #include "IPluginManager.h"
    24 
    25 #if defined __GNUC__
    26 #if ((__GNUC__ == 3) && (__GNUC_MINOR__ < 4)) || (__GNUC__ < 3)
    27 #error "You must compile with at least GCC 3.4! If you know what you are doing, you can remove this message."
    28 #endif //version check
    29 #endif //__GNUC__
    30 
    31 class IMetamodListener;
    32 class ISmmPluginManager;
    33 class ISmmPlugin;
    34 
    35 #define	MMIFACE_SOURCEHOOK		"ISourceHook"
    36 #define	MMIFACE_PLMANAGER		"IPluginManager"
    37 #define IFACE_MAXNUM			999
    38 
    39 class ISmmAPI
    40 {
    41 public:
    42 	/**
    43 	 * @brief Logs a message through the HL2 log system.
    44 	 * Note: Newlines are appended automatically.
    45 	 *
    46 	 * @param pl			Plugin API pointer (used for tagging message)
    47 	 * @param msg			Formatted string.
    48 	 */
    49 	virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
    50 public:
    51 	/**
    52 	 * @brief Returns an interface factory for the HL2 engine.
    53 	 *
    54 	 * @param syn			If syn is true, the synthetic wrapper is returned.  
    55 	 *						If syn is false, the true function is returned.
    56 	 * @return				CreateInterfaceFn function pointer.
    57 	 */
    58 	virtual CreateInterfaceFn engineFactory(bool syn=true) =0;
    59 
    60 	/**
    61 	 * @brief Returns an interface factory for the HL2 physics engine.
    62 	 *
    63 	 * @param syn			If syn is true, the synthetic wrapper is returned.  
    64 	 *						If syn is false, the true function is returned.
    65 	 * @return				CreateInterfaceFn function pointer.
    66 	 */
    67 	virtual CreateInterfaceFn physicsFactory(bool syn=true) =0;
    68 
    69 	/**
    70 	 * @brief Returns an interface factory for the HL2 file system.
    71 	 *
    72 	 * @param syn			If syn is true, the synthetic wrapper is returned.  
    73 	 *						If syn is false, the true function is returned.
    74 	 * @return				CreateInterfaceFn function pointer.
    75 	 */
    76 	virtual CreateInterfaceFn fileSystemFactory(bool syn=true) =0;
    77 
    78 	/**
    79 	 * @brief Returns an interface factory for the GameDLL.
    80 	 *
    81 	 * @param syn			If syn is true, the synthetic wrapper is returned.  
    82 	 *						If syn is false, the true function is returned.
    83 	 * @return				CreateInterfaceFn function pointer.
    84 	 */
    85 	virtual CreateInterfaceFn serverFactory(bool syn=true) =0;
    86 
    87 	/**
    88 	 * @brief Returns a CGlobalVars pointer from the HL2 Engine.
    89 	 *
    90 	 * @return				CGlobalVars pointer.
    91 	 */
    92 	virtual CGlobalVars *pGlobals() =0;
    93 
    94 	/**
    95 	 * @brief Used with SourceHook, sets teh last meta return value.
    96 	 * Note: Do not call this directly, use the Metamod macros.
    97 	 *
    98 	 * @param res			META_RETURN value to set.
    99 	 */
   100 	virtual void SetLastMetaReturn(META_RES res) =0;
   101 
   102 	/**
   103 	 * @brief Used with SourceHook, returns the last meta return value.
   104 	 * Note: This is only valid inside a hook function.
   105 	 *
   106 	 * @return				Last META_RETURN value set by a plugin.
   107 	 */
   108 	virtual META_RES GetLastMetaReturn() =0;
   109 
   110 public:		//Added in 1.00-RC2 (0:0)
   111 	/**
   112 	 * @brief Allows access to Metamod's ConCommandBaseAccessor.
   113 	 *
   114 	 * @return				Returns IConCommandBaseAccessor pointer.
   115 	 */
   116 	virtual IConCommandBaseAccessor *GetCvarBaseAccessor() =0;
   117 
   118 	/**
   119 	 * @brief Registers a ConCommandBase.
   120 	 *
   121 	 * @param plugin		Parent plugin API pointer.
   122 	 * @param pCommand		ConCommandBase to register.
   123 	 * @return				True if successful, false otherwise.  Does not return false yet.
   124 	 */
   125 	virtual bool RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
   126 
   127 	/**
   128 	 * @brief Unregisters a ConCommandBase.
   129 	 *
   130 	 * @param plugin		Parent plugin API pointer.
   131 	 * @param pCommand		ConCommandBase to unlink.
   132 	 */
   133 	virtual void UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
   134 	
   135 	/**
   136 	 * @brief Prints an unformatted string to the remote server console.
   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 	 * Note: Newlines are not added automatically.
   146 	 *
   147 	 * @param fmt			Formatted message.
   148 	 */
   149 	virtual void ConPrintf(const char *fmt, ...) =0;
   150 
   151 public:		//Added in 1.1.0 (1:0)
   152 	/**
   153 	 * @brief Checks if ConPrint/ConPrintf will mirror to rcon.
   154 	 *
   155 	 * @return				True if remote printing available, false otherwise.
   156 	 */
   157 	virtual bool RemotePrintingAvailable() =0;
   158 
   159 	/**
   160 	 * @brief Returns the Metamod Version numbers as major version and minor (API) version.
   161 	 * Changes to minor version are guaranteed to be backwards compatible.
   162 	 * Changes to major version are not.
   163 	 * 
   164 	 * @param major			Filled with the major API version number.
   165 	 * @param minor			Filled with the minor API version number.
   166 	 * @param plvers		Filled with the current plugin API version number.
   167 	 * @param plmin			Filled with the minimum plugin API version number supported.
   168 	 */
   169 	virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
   170 	
   171 	/** 
   172 	 * @brief Returns sourcehook API version and implementation version.
   173 	 *
   174 	 * @param shvers		Filled with the SourceHook API version number.
   175 	 * @param shimpl		Filled with the SourceHook implementation number.
   176 	 */
   177 	virtual void GetShVersions(int &shvers, int &shimpl) =0;
   178 	
   179 	/**
   180 	 * @brief Adds a Metamod listener.
   181 	 *
   182 	 * @param plugin		Plugin interface pointer.
   183 	 * @param pListener		Listener interface pointer to add.
   184 	 */
   185 	virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
   186 
   187 	/**
   188 	  * @brief Queries the metamod factory
   189 	  *
   190 	  * @param iface		String containing interface name
   191 	  * @param ret			Optional pointer to store return status
   192 	  * @param id			Optional pointer to store id of plugin that overrode interface, 0 if none
   193 	  * @return				Returned pointer
   194 	  */
   195 	virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
   196 
   197 public:		//Added in 1.1.2 (1:1)
   198 	/**
   199 	 * @brief Given a base interface name, such as ServerGameDLL or ServerGameDLL003, 
   200 	 * reformats the string to increase the number, then returns the new number.
   201 	 * This is the base function to InterfaceSearch() and VInterfaceMatch().
   202 	 * 
   203 	 * @param iface			Input/output interface name.  Must be writable.
   204 	 * @param maxlength		Maximum length of iface buffer.  Must be at least strlen(iface)+4 chars.
   205 	 * @return				The newly incremented iface version number.
   206 	 */
   207 	virtual int FormatIface(char iface[], unsigned int maxlength) =0;
   208 
   209 public:		//Added in 1.2 (1:2)
   210 	/**
   211 	 * @brief Searches for an interface for you.
   212 	 * 
   213 	 * @param fn			InterfaceFactory function.
   214 	 * @param iface			Interface string name.
   215 	 * @param max			Maximum version to look up.
   216 	 * @param ret			Last return code from interface factory function.
   217 	 * @return				Interface pointer, or NULL if not found.
   218 	 */
   219 	virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
   220 
   221 	/**
   222 	 * @brief Returns the base directory of the game/server, equivalent to 
   223 	 *  IVEngineServer::GetGameDir().
   224 	 *
   225 	 * @return				Static pointer to game's basedir.
   226 	 */
   227 	virtual const char *GetBaseDir() =0;
   228 
   229 	/**
   230 	 * @brief Formats a file path to the local OS.  Does not include any base directories.
   231 	 * Note that all slashes and black slashes are reverted to the local OS's expectancy.
   232 	 *
   233 	 * @param buffer		Destination buffer to store path.
   234 	 * @param len			Maximum length of buffer, including null terminator.
   235 	 * @param fmt			Formatted string.
   236 	 */
   237 	virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
   238 
   239 public:		// Added in 1.2.2 (1:3)
   240 	/**
   241 	 * @brief Prints text in the specified client's console. Same as IVEngineServer::ClientPrintf 
   242 	 *  except that it allows for string formatting.
   243 	 *
   244 	 * @param client		Client edict pointer.
   245 	 * @param fmt			Formatted string to print to the client.
   246 	 */
   247 	virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
   248 
   249 public:		// Added in 1.3 (1:4)
   250 	/**
   251 	 * @brief Wrapper around InterfaceSearch().  Assumes no maximum.
   252 	 * This is designed to replace the fact that searches only went upwards.
   253 	 * The "V" is intended to convey that this is for Valve formatted interface strings.
   254 	 *
   255 	 * @param fn			Interface factory function.
   256 	 * @param iface			Interface string.
   257 	 * @param min			Minimum value to search from.  If zero, searching begins from the
   258 	 *                       first available version regardless of the interface.  
   259 	 *                      Note that this can return interfaces EARLIER than the version specified.
   260 	 *                      A value of -1 (default) specifies the string version as the minimum.
   261 	 *                      Any other value specifices the minimum value to search from.
   262 	 * @return				Interface pointer, or NULL if not found.
   263 	 */
   264 	virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1) =0;
   265 };
   266 
   267 
   268 /** Version history
   269  * 1.1.0 bumped API to 1:0.  The breaking changes occured in sourcehook and the plugin API.
   270  * 1.1.2 added API call for generating iface names.
   271  * 1.2   added API more helper functions and new SourceHook version.
   272  * 1.2.2 added API for printing to client console (with string formatting)
   273  * 1.3   added new interface search API
   274  */
   275 
   276 #endif //_INCLUDE_ISMM_API_H