3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
8 * used or modified under the Terms and Conditions of its License Agreement,
9 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
10 * works must be licensed under the GNU General Public License (version 2 or
11 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
13 * To view the latest information, see: http://www.sourcemod.net/license.php
18 #ifndef _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
19 #define _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
23 * @brief Defines miscellaneous helper functions useful to extensions.
26 #include <IHandleSys.h>
27 #include <sp_vm_api.h>
28 #include <IDataPack.h>
30 #define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
31 #define SMINTERFACE_SOURCEMOD_VERSION 3
34 * @brief Forward declaration of the KeyValues class.
41 * @brief Describes various ways of formatting a base path.
45 Path_None = 0, /**< No base path */
46 Path_Game, /**< Base path is absolute mod folder */
47 Path_SM, /**< Base path is absolute to SourceMod */
48 Path_SM_Rel, /**< Base path is relative to SourceMod */
52 * @brief Contains miscellaneous helper functions.
54 class ISourceMod : public SMInterface
57 virtual const char *GetInterfaceName()
59 return SMINTERFACE_SOURCEMOD_NAME;
61 virtual unsigned int GetInterfaceVersion()
63 return SMINTERFACE_SOURCEMOD_VERSION;
67 * @brief Returns the full path to the game directory.
69 * @return A string containing the full game path.
71 virtual const char *GetGamePath() const =0;
74 * @brief Returns the full path to the SourceMod directory.
76 * @return A string containing the full SourceMod path.
78 virtual const char *GetSourceModPath() const =0;
81 * @brief Builds a platform path for a specific target base path.
83 * @param type Type of path to use as a base.
84 * @param buffer Buffer to write to.
85 * @param maxlength Size of buffer.
86 * @param format Format string.
87 * @param ... Format arguments.
88 * @return Number of bytes written.
90 virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...) =0;
93 * @brief Logs a message to the SourceMod logs.
95 * @param pExt Extension calling this function.
96 * @param format Message format.
97 * @param ... Message format parameters.
99 virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
102 * @brief Logs a message to the SourceMod error logs.
104 * @param pExt Extension calling this function.
105 * @param format Message format.
106 * @param ... Message format parameters.
108 virtual void LogError(IExtension *pExt, const char *format, ...) =0;
111 * @brief Formats a string from a native.
113 * @param buffer Buffer to store message.
114 * @param maxlength Maximum length of buffer (including null terminator).
115 * @param pContext Pointer to the plugin's context.
116 * @param params Parameter array that was passed to the native.
117 * @param param Parameter index where format string and variable arguments begin.
118 * Note: parameter indexes start at 1.
119 * @return Number of bytes written, not including the null terminator.
121 virtual size_t FormatString(char *buffer,
123 SourcePawn::IPluginContext *pContext,
124 const cell_t *params,
125 unsigned int param) =0;
128 * @brief Creates a data pack object.
130 * @return A new IDataPack object.
132 virtual IDataPack *CreateDataPack() =0;
135 * @brief Releases a data pack's resources so it can be re-used.
137 * @param pack An IDataPack object to release.
139 virtual void FreeDataPack(IDataPack *pack) =0;
142 * @brief Returns the automated data pack handle type.
144 * The read-only data type is the parent of the writable type.
145 * Note that calling CloseHandle() on either type will release the data pack.
146 * The read-only type is inheritable, but due to limitations of the Handle System,
147 * the writable type is not.
149 * @param readonly If true, the read-only type will be returned.
150 * @return The Handle type for storing generic data packs.
152 virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
155 * @brief Retrieves a KeyValues pointer from a handle.
157 * @param hndl Handle_t from which to retrieve contents.
158 * @param err Optional address to store a possible handle error.
159 * @param root If true it will return the root KeyValues pointer for the whole structure.
161 * @return The KeyValues pointer, or NULL for any error encountered.
163 virtual KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false) =0;
166 * @brief Returns the name of the game directory.
168 * @return A string containing the name of the game directory.
170 virtual const char *GetGameFolderName() const =0;
173 * @brief Returns the scripting engine interface.
175 * @return A pointer to the scripting engine interface.
177 virtual SourcePawn::ISourcePawnEngine *GetScriptingEngine() =0;
180 * @brief Returns the JIT interface.
182 * @return A pointer to the JIT interface.
184 virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
188 #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_