1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2007 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): David "BAILOPAN" Anderson
8 * ============================
11 #ifndef _INCLUDE_ISMM_API_H
12 #define _INCLUDE_ISMM_API_H
15 * @brief External API interface
19 #include <interface.h>
21 #include <sourcehook/sourcehook.h>
22 #include "IPluginManager.h"
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
30 class IMetamodListener;
31 class ISmmPluginManager;
34 #define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
35 #define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
36 #define IFACE_MAXNUM 999 /**< Maximum interface version */
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) */
46 * @brief Logs a message through the HL2 log system.
47 * Note: Newlines are appended automatically.
49 * @param pl Plugin API pointer (used for tagging message)
50 * @param msg Formatted string.
52 virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
55 * @brief Returns an interface factory for the HL2 engine.
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.
61 virtual CreateInterfaceFn engineFactory(bool syn=true) =0;
64 * @brief Returns an interface factory for the HL2 physics engine.
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.
70 virtual CreateInterfaceFn physicsFactory(bool syn=true) =0;
73 * @brief Returns an interface factory for the HL2 file system.
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.
79 virtual CreateInterfaceFn fileSystemFactory(bool syn=true) =0;
82 * @brief Returns an interface factory for the GameDLL.
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.
88 virtual CreateInterfaceFn serverFactory(bool syn=true) =0;
91 * @brief Returns a CGlobalVars pointer from the HL2 Engine.
93 * @return CGlobalVars pointer.
95 virtual CGlobalVars *pGlobals() =0;
98 * @brief Used with SourceHook, sets teh last meta return value.
99 * Note: Do not call this directly, use the Metamod macros.
101 * @param res META_RETURN value to set.
103 virtual void SetLastMetaReturn(META_RES res) =0;
106 * @brief Used with SourceHook, returns the last meta return value.
107 * Note: This is only valid inside a hook function.
109 * @return Last META_RETURN value set by a plugin.
111 virtual META_RES GetLastMetaReturn() =0;
113 public: // Added in 1.00-RC2 (0:0)
115 * @brief Allows access to Metamod's ConCommandBaseAccessor.
117 * @return Returns IConCommandBaseAccessor pointer.
119 virtual IConCommandBaseAccessor *GetCvarBaseAccessor() =0;
122 * @brief Registers a ConCommandBase.
124 * @param plugin Parent plugin API pointer.
125 * @param pCommand ConCommandBase to register.
126 * @return True if successful, false otherwise.
128 virtual bool RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
131 * @brief Unregisters a ConCommandBase.
133 * @param plugin Parent plugin API pointer.
134 * @param pCommand ConCommandBase to unlink.
136 virtual void UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
139 * @brief Prints an unformatted string to the remote server console.
141 * Note: Newlines are not added automatically.
143 * @param str Message string.
145 virtual void ConPrint(const char *str) =0;
148 * @brief Prints a formatted message to the remote server console.
150 * Note: Newlines are not added automatically.
152 * @param fmt Formatted message.
154 virtual void ConPrintf(const char *fmt, ...) =0;
156 public: // Added in 1.1.0 (1:0)
158 * @brief Checks if ConPrint/ConPrintf will mirror to rcon.
160 * @return True if remote printing available, false otherwise.
162 virtual bool RemotePrintingAvailable() =0;
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.
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.
174 virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
177 * @brief Returns sourcehook API version and implementation version.
179 * @param shvers Filled with the SourceHook API version number.
180 * @param shimpl Filled with the SourceHook implementation number.
182 virtual void GetShVersions(int &shvers, int &shimpl) =0;
185 * @brief Adds a Metamod listener.
187 * @param plugin Plugin interface pointer.
188 * @param pListener Listener interface pointer to add.
190 virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
193 * @brief Queries the metamod factory
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
200 virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
202 public: // Added in 1.1.2 (1:1)
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().
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.
212 virtual int FormatIface(char iface[], unsigned int maxlength) =0;
214 public: // Added in 1.2 (1:2)
216 * @brief Searches for an interface, eliminating the need to loop through FormatIface().
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.
224 virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
227 * @brief Returns the base directory of the game/server, equivalent to
228 * IVEngineServer::GetGameDir(), except the path is absolute.
230 * @return Static pointer to game's absolute basedir.
232 virtual const char *GetBaseDir() =0;
235 * @brief Formats a file path to the local OS.
237 * Does not include any base directories. Note that all slashes and black
238 * slashes are reverted to the local OS's expectancy.
240 * @param buffer Destination buffer to store path.
241 * @param len Maximum length of buffer, including null terminator.
242 * @param fmt Formatted string.
244 virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
246 public: // Added in 1.2.2 (1:3)
248 * @brief Prints text in the specified client's console. Same as
249 * IVEngineServer::ClientPrintf except that it allows for string formatting.
251 * @param client Client edict pointer.
252 * @param fmt Formatted string to print to the client.
254 virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
256 public: // Added in 1.3 (1:4)
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.
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.
273 virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1) =0;
275 public: // Added in 1.4 (1:5)
277 * @brief Tells SourceMM to add VSP hooking capability to plugins.
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
287 virtual void EnableVSPListener() =0;
290 * @brief Returns the interface version of the GameDLL's IServerGameDLL
293 * @return Interface version of the loaded IServerGameDLL.
295 virtual int GetGameDLLVersion() =0;
298 * @brief Returns the number of user messages in the GameDLL.
300 * @return Number of user messages, or -1 if SourceMM has
301 * failed to get user message list.
303 virtual int GetUserMessageCount() =0;
306 * @brief Returns the index of the specified user message.
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.
312 virtual int FindUserMessage(const char *name, int *size=NULL) =0;
315 * @brief Returns the name of the specified user message.
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.
321 virtual const char *GetUserMessage(int index, int *size=NULL) =0;
323 public: // Added in 1.5.0 (1:6)
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.
329 * @return Highest interface version of IServerPluginCallbacks.
330 * Returns 0 if SourceMM's VSP listener isn't currently
333 virtual int GetVSPVersion() =0;
335 public: // Added in 1.6.0 (1:7)
337 * @brief Returns the engine interface that MM:S is using as a backend.
339 * The values will be one of the SOURCE_ENGINE_* constants from the top
342 * @return A SOURCE_ENGINE_* constant value.
344 virtual int GetSourceEngineBuild() =0;
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.
361 #endif //_INCLUDE_ISMM_API_H