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
42 * @brief Logs a message through the HL2 log system.
43 * Note: Newlines are appended automatically.
45 * @param pl Plugin API pointer (used for tagging message)
46 * @param msg Formatted string.
48 virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
51 * @brief Returns an interface factory for the HL2 engine.
53 * @param syn If syn is true, the synthetic wrapper is returned.
54 * If syn is false, the true function is returned.
55 * @return CreateInterfaceFn function pointer.
57 virtual CreateInterfaceFn engineFactory(bool syn=true) =0;
60 * @brief Returns an interface factory for the HL2 physics engine.
62 * @param syn If syn is true, the synthetic wrapper is returned.
63 * If syn is false, the true function is returned.
64 * @return CreateInterfaceFn function pointer.
66 virtual CreateInterfaceFn physicsFactory(bool syn=true) =0;
69 * @brief Returns an interface factory for the HL2 file system.
71 * @param syn If syn is true, the synthetic wrapper is returned.
72 * If syn is false, the true function is returned.
73 * @return CreateInterfaceFn function pointer.
75 virtual CreateInterfaceFn fileSystemFactory(bool syn=true) =0;
78 * @brief Returns an interface factory for the GameDLL.
80 * @param syn If syn is true, the synthetic wrapper is returned.
81 * If syn is false, the true function is returned.
82 * @return CreateInterfaceFn function pointer.
84 virtual CreateInterfaceFn serverFactory(bool syn=true) =0;
87 * @brief Returns a CGlobalVars pointer from the HL2 Engine.
89 * @return CGlobalVars pointer.
91 virtual CGlobalVars *pGlobals() =0;
94 * @brief Used with SourceHook, sets teh last meta return value.
95 * Note: Do not call this directly, use the Metamod macros.
97 * @param res META_RETURN value to set.
99 virtual void SetLastMetaReturn(META_RES res) =0;
102 * @brief Used with SourceHook, returns the last meta return value.
103 * Note: This is only valid inside a hook function.
105 * @return Last META_RETURN value set by a plugin.
107 virtual META_RES GetLastMetaReturn() =0;
109 public: // Added in 1.00-RC2 (0:0)
111 * @brief Allows access to Metamod's ConCommandBaseAccessor.
113 * @return Returns IConCommandBaseAccessor pointer.
115 virtual IConCommandBaseAccessor *GetCvarBaseAccessor() =0;
118 * @brief Registers a ConCommandBase.
120 * @param plugin Parent plugin API pointer.
121 * @param pCommand ConCommandBase to register.
122 * @return True if successful, false otherwise. Does not return false yet.
124 virtual bool RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
127 * @brief Unregisters a ConCommandBase.
129 * @param plugin Parent plugin API pointer.
130 * @param pCommand ConCommandBase to unlink.
132 virtual void UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
135 * @brief Prints an unformatted string to the remote server console.
136 * Note: Newlines are not added automatically.
138 * @param str Message string.
140 virtual void ConPrint(const char *str) =0;
143 * @brief Prints a formatted message to the remote server console.
144 * Note: Newlines are not added automatically.
146 * @param fmt Formatted message.
148 virtual void ConPrintf(const char *fmt, ...) =0;
150 public: // Added in 1.1.0 (1:0)
152 * @brief Checks if ConPrint/ConPrintf will mirror to rcon.
154 * @return True if remote printing available, false otherwise.
156 virtual bool RemotePrintingAvailable() =0;
159 * @brief Returns the Metamod Version numbers as major version and minor (API) version.
160 * Changes to minor version are guaranteed to be backwards compatible.
161 * Changes to major version are not.
163 * @param major Filled with the major API version number.
164 * @param minor Filled with the minor API version number.
165 * @param plvers Filled with the current plugin API version number.
166 * @param plmin Filled with the minimum plugin API version number supported.
168 virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
171 * @brief Returns sourcehook API version and implementation version.
173 * @param shvers Filled with the SourceHook API version number.
174 * @param shimpl Filled with the SourceHook implementation number.
176 virtual void GetShVersions(int &shvers, int &shimpl) =0;
179 * @brief Adds a Metamod listener.
181 * @param plugin Plugin interface pointer.
182 * @param pListener Listener interface pointer to add.
184 virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
187 * @brief Queries the metamod factory
189 * @param iface String containing interface name
190 * @param ret Optional pointer to store return status
191 * @param id Optional pointer to store id of plugin that overrode interface, 0 if none
192 * @return Returned pointer
194 virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
196 public: // Added in 1.1.2 (1:1)
198 * @brief Given a base interface name, such as ServerGameDLL or ServerGameDLL003,
199 * reformats the string to increase the number, then returns the new number.
200 * This is the base function to InterfaceSearch() and VInterfaceMatch().
202 * @param iface Input/output interface name. Must be writable.
203 * @param maxlength Maximum length of iface buffer. Must be at least strlen(iface)+4 chars.
204 * @return The newly incremented iface version number.
206 virtual int FormatIface(char iface[], unsigned int maxlength) =0;
208 public: // Added in 1.2.0 (1:2)
210 * @brief Searches for an interface for you.
212 * @param fn InterfaceFactory function.
213 * @param iface Interface string name.
214 * @param max Maximum version to look up.
215 * @param ret Last return code from interface factory function.
216 * @return Interface pointer, or NULL if not found.
218 virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
221 * @brief Returns the base directory of the game/server, equivalent to
222 * IVEngineServer::GetGameDir(), except the path is absolute.
224 * @return Static pointer to game's absolute basedir.
226 virtual const char *GetBaseDir() =0;
229 * @brief Formats a file path to the local OS. Does not include any base directories.
230 * Note that all slashes and black slashes are reverted to the local OS's expectancy.
232 * @param buffer Destination buffer to store path.
233 * @param len Maximum length of buffer, including null terminator.
234 * @param fmt Formatted string.
236 virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
238 public: // Added in 1.2.2 (1:3)
240 * @brief Prints text in the specified client's console. Same as IVEngineServer::ClientPrintf
241 * except that it allows for string formatting.
243 * @param client Client edict pointer.
244 * @param fmt Formatted string to print to the client.
246 virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
248 public: // Added in 1.3.0 (1:4)
250 * @brief Wrapper around InterfaceSearch(). Assumes no maximum.
251 * This is designed to replace the fact that searches only went upwards.
252 * The "V" is intended to convey that this is for Valve formatted interface strings.
254 * @param fn Interface factory function.
255 * @param iface Interface string.
256 * @param min Minimum value to search from. If zero, searching begins from the
257 * first available version regardless of the interface.
258 * Note that this can return interfaces EARLIER than the version specified.
259 * A value of -1 (default) specifies the string version as the minimum.
260 * Any other value specifices the minimum value to search from.
261 * @return Interface pointer, or NULL if not found.
263 virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1) =0;
265 public: // Added in 1.4.0 (1:5)
267 * @brief Tells SourceMM to add VSP hooking capability to plugins.
269 * Since this potentially uses more resources than it would otherwise, plugins have to
270 * explicitly enable the feature. Whether requested or not, if it is enabled, all plugins
271 * will get a pointer to the VSP listener through IMetamodListener.
273 virtual void EnableVSPListener() =0;
276 * @brief Returns the interface version of the GameDLL's IServerGameDLL implementation.
278 * @return Interface version of the loaded IServerGameDLL.
280 virtual int GetGameDLLVersion() =0;
283 * @brief Returns the number of user messages in the GameDLL.
285 * @return Number of user messages, or -1 if SourceMM has failed to get user message list.
287 virtual int GetUserMessageCount() =0;
290 * @brief Returns the index of the specified user message.
292 * @param name User message name.
293 * @param size Optional pointer to store size of user message.
294 * @return Message index, or -1 on failure.
296 virtual int FindUserMessage(const char *name, int *size=NULL) =0;
299 * @brief Returns the name of the specified user message.
301 * @param index User message index.
302 * @param size Optional pointer to store size of user message.
303 * @return Message name, or NULL on failure.
305 virtual const char *GetUserMessage(int index, int *size=NULL) =0;
306 public: // Added in 1.5.0 (1:6)
308 * @brief Returns the highest interface version of IServerPluginCallbacks that the engine supports.
309 * This is useful for games that run on older versions of the Source engine, such as The Ship.
311 * @return Highest interface version of IServerPluginCallbacks.
312 * Returns 0 if SourceMM's VSP listener isn't currently enabled.
314 virtual int GetVSPVersion() =0;
321 * 1.1.0 Bumped API to 1:0. The breaking changes occurred in SourceHook and the plugin API.
322 * 1.1.2 Added API call for generating iface names.
323 * 1.2.0 Added API more helper functions and new SourceHook version.
324 * 1.2.2 Added API for printing to client console (with string formatting).
325 * 1.3.0 Added new interface search API.
326 * 1.4.0 Added VSP listener and user message API.
327 * 1.5.0 Added API for getting highest supported version of IServerPluginCallbacks.
330 #endif //_INCLUDE_ISMM_API_H