3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
33 #define _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
37 * @brief Defines miscellaneous helper functions useful to extensions.
40 #include <IHandleSys.h>
41 #include <sp_vm_api.h>
42 #include <IDataPack.h>
45 #define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
46 #define SMINTERFACE_SOURCEMOD_VERSION 4
49 * @brief Forward declaration of the KeyValues class.
56 * @brief Describes various ways of formatting a base path.
60 Path_None = 0, /**< No base path */
61 Path_Game, /**< Base path is absolute mod folder */
62 Path_SM, /**< Base path is absolute to SourceMod */
63 Path_SM_Rel, /**< Base path is relative to SourceMod */
67 * @brief Contains miscellaneous helper functions.
69 class ISourceMod : public SMInterface
72 virtual const char *GetInterfaceName()
74 return SMINTERFACE_SOURCEMOD_NAME;
76 virtual unsigned int GetInterfaceVersion()
78 return SMINTERFACE_SOURCEMOD_VERSION;
82 * @brief Returns the full path to the game directory.
84 * @return A string containing the full game path.
86 virtual const char *GetGamePath() const =0;
89 * @brief Returns the full path to the SourceMod directory.
91 * @return A string containing the full SourceMod path.
93 virtual const char *GetSourceModPath() const =0;
96 * @brief Builds a platform path for a specific target base path.
98 * If the path starts with the string "file://" and the PathType is
99 * not relative, then the "file://" portion is stripped off, and the
100 * rest of the path is used without any modification (except for
101 * correcting slashes). This can be used to override the path
102 * builder to supply alternate absolute paths. Examples:
104 * file://C:/Temp/file.txt
105 * file:///tmp/file.txt
107 * @param type Type of path to use as a base.
108 * @param buffer Buffer to write to.
109 * @param maxlength Size of buffer.
110 * @param format Format string.
111 * @param ... Format arguments.
112 * @return Number of bytes written.
114 virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...) =0;
117 * @brief Logs a message to the SourceMod logs.
119 * @param pExt Extension calling this function.
120 * @param format Message format.
121 * @param ... Message format parameters.
123 virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
126 * @brief Logs a message to the SourceMod error logs.
128 * @param pExt Extension calling this function.
129 * @param format Message format.
130 * @param ... Message format parameters.
132 virtual void LogError(IExtension *pExt, const char *format, ...) =0;
135 * @brief Formats a string from a native.
137 * @param buffer Buffer to store message.
138 * @param maxlength Maximum length of buffer (including null terminator).
139 * @param pContext Pointer to the plugin's context.
140 * @param params Parameter array that was passed to the native.
141 * @param param Parameter index where format string and variable arguments begin.
142 * Note: parameter indexes start at 1.
143 * @return Number of bytes written, not including the null terminator.
145 virtual size_t FormatString(char *buffer,
147 SourcePawn::IPluginContext *pContext,
148 const cell_t *params,
149 unsigned int param) =0;
152 * @brief Creates a data pack object.
154 * @return A new IDataPack object.
156 virtual IDataPack *CreateDataPack() =0;
159 * @brief Releases a data pack's resources so it can be re-used.
161 * @param pack An IDataPack object to release.
163 virtual void FreeDataPack(IDataPack *pack) =0;
166 * @brief Not implemented, do not use.
168 * @param readonly Ignored
171 virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
174 * @brief Retrieves a KeyValues pointer from a handle.
176 * @param hndl Handle_t from which to retrieve contents.
177 * @param err Optional address to store a possible handle error.
178 * @param root If true it will return the root KeyValues pointer for the whole structure.
180 * @return The KeyValues pointer, or NULL for any error encountered.
182 virtual KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false) =0;
185 * @brief Returns the name of the game directory.
187 * @return A string containing the name of the game directory.
189 virtual const char *GetGameFolderName() const =0;
192 * @brief Returns the scripting engine interface.
194 * @return A pointer to the scripting engine interface.
196 virtual SourcePawn::ISourcePawnEngine *GetScriptingEngine() =0;
199 * @brief Returns the JIT interface.
201 * @return A pointer to the JIT interface.
203 virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
206 * @brief Returns the adjusted server time.
208 * @return Adjusted server time.
210 virtual time_t GetAdjustedTime() =0;
213 * @brief Sets the global client SourceMod will use for assisted
214 * translations (that is, %t).
216 * @param index Client index.
217 * @return Old global client value.
219 virtual unsigned int SetGlobalTarget(unsigned int index) =0;
222 * @brief Returns the global client SourceMod is currently using
223 * for assisted translations (that is, %t).
225 * @return Global client value.
227 virtual unsigned int GetGlobalTarget() const =0;
231 #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_