1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2006 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>
22 #include <sourcehook/sourcehook.h>
23 #include "IPluginManager.h"
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
31 class IMetamodListener;
32 class ISmmPluginManager;
35 #define MMIFACE_SOURCEHOOK "ISourceHook"
36 #define MMIFACE_PLMANAGER "IPluginManager"
37 #define IFACE_MAXNUM 999
43 * @brief Logs a message through the HL2 log system.
44 * Note: Newlines are appended automatically.
46 * @param pl Plugin API pointer (used for tagging message)
47 * @param msg Formatted string.
49 virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
52 * @brief Returns an interface factory for the HL2 engine.
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.
58 virtual CreateInterfaceFn engineFactory(bool syn=true) =0;
61 * @brief Returns an interface factory for the HL2 physics engine.
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.
67 virtual CreateInterfaceFn physicsFactory(bool syn=true) =0;
70 * @brief Returns an interface factory for the HL2 file system.
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.
76 virtual CreateInterfaceFn fileSystemFactory(bool syn=true) =0;
79 * @brief Returns an interface factory for the GameDLL.
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.
85 virtual CreateInterfaceFn serverFactory(bool syn=true) =0;
88 * @brief Returns a CGlobalVars pointer from the HL2 Engine.
90 * @return CGlobalVars pointer.
92 virtual CGlobalVars *pGlobals() =0;
95 * @brief Used with SourceHook, sets teh last meta return value.
96 * Note: Do not call this directly, use the Metamod macros.
98 * @param res META_RETURN value to set.
100 virtual void SetLastMetaReturn(META_RES res) =0;
103 * @brief Used with SourceHook, returns the last meta return value.
104 * Note: This is only valid inside a hook function.
106 * @return Last META_RETURN value set by a plugin.
108 virtual META_RES GetLastMetaReturn() =0;
110 public: //Added in 1.00-RC2 (0:0)
112 * @brief Allows access to Metamod's ConCommandBaseAccessor.
114 * @return Returns IConCommandBaseAccessor pointer.
116 virtual IConCommandBaseAccessor *GetCvarBaseAccessor() =0;
119 * @brief Registers a ConCommandBase.
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.
125 virtual bool RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
128 * @brief Unregisters a ConCommandBase.
130 * @param plugin Parent plugin API pointer.
131 * @param pCommand ConCommandBase to unlink.
133 virtual void UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
136 * @brief Prints an unformatted string to the remote server console.
137 * Note: Newlines are not added automatically.
139 * @param str Message string.
141 virtual void ConPrint(const char *str) =0;
144 * @brief Prints a formatted message to the remote server console.
145 * Note: Newlines are not added automatically.
147 * @param fmt Formatted message.
149 virtual void ConPrintf(const char *fmt, ...) =0;
151 public: //Added in 1.1.0 (1:0)
153 * @brief Checks if ConPrint/ConPrintf will mirror to rcon.
155 * @return True if remote printing available, false otherwise.
157 virtual bool RemotePrintingAvailable() =0;
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.
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.
169 virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
172 * @brief Returns sourcehook API version and implementation version.
174 * @param shvers Filled with the SourceHook API version number.
175 * @param shimpl Filled with the SourceHook implementation number.
177 virtual void GetShVersions(int &shvers, int &shimpl) =0;
180 * @brief Adds a Metamod listener.
182 * @param plugin Plugin interface pointer.
183 * @param pListener Listener interface pointer to add.
185 virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
188 * @brief Queries the metamod factory
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
195 virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
197 public: //Added in 1.1.2 (1:1)
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().
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.
207 virtual int FormatIface(char iface[], unsigned int maxlength) =0;
209 public: //Added in 1.2 (1:2)
211 * @brief Searches for an interface for you.
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.
219 virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
222 * @brief Returns the base directory of the game/server, equivalent to
223 * IVEngineServer::GetGameDir().
225 * @return Static pointer to game's basedir.
227 virtual const char *GetBaseDir() =0;
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.
233 * @param buffer Destination buffer to store path.
234 * @param len Maximum length of buffer, including null terminator.
235 * @param fmt Formatted string.
237 virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
239 public: // Added in 1.2.2 (1:3)
241 * @brief Prints text in the specified client's console. Same as IVEngineServer::ClientPrintf
242 * except that it allows for string formatting.
244 * @param client Client edict pointer.
245 * @param fmt Formatted string to print to the client.
247 virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
249 public: // Added in 1.3 (1:4)
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.
255 * @param fn Interface factory function.
256 * @param iface Interface string.
257 * @param chop If true, chops an interface version number off and searches
258 * from the beginning.
259 * @return Interface pointer, or NULL if not found.
261 virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, bool chop=true) =0;
266 * 1.1.0 bumped API to 1:0. The breaking changes occured in sourcehook and the plugin API.
267 * 1.1.2 added API call for generating iface names.
268 * 1.2 added API more helper functions and new SourceHook version.
269 * 1.2.2 added API for printing to client console (with string formatting)
270 * 1.3 added new interface search API
273 #endif //_INCLUDE_ISMM_API_H