public/ISourceMod.h
author David Anderson <dvander@alliedmods.net>
Tue Nov 27 02:19:39 2007 +0000 (2007-11-27)
changeset 1729 0f60cc4ce8bb
parent 1690 7cc4f79a0416
child 1894 e6efc8ffa47a
permissions -rw-r--r--
added amb1191 - absolute paths
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     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.
    11  * 
    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
    15  * details.
    16  *
    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/>.
    19  *
    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>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
    33 #define _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
    34 
    35 /**
    36  * @file ISourceMod.h
    37  * @brief Defines miscellaneous helper functions useful to extensions.
    38  */
    39 
    40 #include <IHandleSys.h>
    41 #include <sp_vm_api.h>
    42 #include <IDataPack.h>
    43 #include <time.h>
    44 
    45 #define SMINTERFACE_SOURCEMOD_NAME		"ISourceMod"
    46 #define SMINTERFACE_SOURCEMOD_VERSION	4
    47 
    48 /**
    49 * @brief Forward declaration of the KeyValues class.
    50 */
    51 class KeyValues;
    52 
    53 namespace SourceMod
    54 {
    55 	/**
    56 	 * @brief Describes various ways of formatting a base path.
    57 	 */
    58 	enum PathType
    59 	{
    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 */
    64 	};
    65 
    66 	/**
    67 	 * @brief Contains miscellaneous helper functions.
    68 	 */
    69 	class ISourceMod : public SMInterface
    70 	{
    71 	public:
    72 		virtual const char *GetInterfaceName()
    73 		{
    74 			return SMINTERFACE_SOURCEMOD_NAME;
    75 		}
    76 		virtual unsigned int GetInterfaceVersion()
    77 		{
    78 			return SMINTERFACE_SOURCEMOD_VERSION;
    79 		}
    80 	public:
    81 		/**
    82 		 * @brief Returns the full path to the game directory.
    83 		 *
    84 		 * @return			A string containing the full game path.
    85 		 */
    86 		virtual const char *GetGamePath() const =0;
    87 
    88 		/**
    89 		 * @brief Returns the full path to the SourceMod directory.
    90 		 *
    91 		 * @return			A string containing the full SourceMod path.
    92 		 */
    93 		virtual const char *GetSourceModPath() const =0;
    94 
    95 		/**
    96 		 * @brief Builds a platform path for a specific target base path.
    97 		 *
    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:
   103 		 *
   104 		 * file://C:/Temp/file.txt
   105 		 * file:///tmp/file.txt
   106 		 *
   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.
   113 		 */
   114 		virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...) =0;
   115 
   116 		/**
   117 		 * @brief Logs a message to the SourceMod logs.
   118 		 *
   119 		 * @param pExt		Extension calling this function.
   120 		 * @param format	Message format.
   121 		 * @param ...		Message format parameters.
   122 		 */
   123 		virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
   124 
   125 		/**
   126 		 * @brief Logs a message to the SourceMod error logs.
   127 		 *
   128 		 * @param pExt		Extension calling this function.
   129 		 * @param format	Message format.
   130 		 * @param ...		Message format parameters.
   131 		 */
   132 		virtual void LogError(IExtension *pExt, const char *format, ...) =0;
   133 
   134 		/**
   135 		 * @brief Formats a string from a native.
   136 		 *
   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.
   144 		 */
   145 		virtual size_t FormatString(char *buffer, 
   146 									size_t maxlength, 
   147 									SourcePawn::IPluginContext *pContext,
   148 									const cell_t *params,
   149 									unsigned int param) =0;
   150 
   151 		/**
   152 		 * @brief Creates a data pack object.
   153 		 *
   154 		 * @return			A new IDataPack object.
   155 		 */
   156 		virtual IDataPack *CreateDataPack() =0;
   157 
   158 		/**
   159 		 * @brief Releases a data pack's resources so it can be re-used.
   160 		 *
   161 		 * @param pack		An IDataPack object to release.
   162 		 */
   163 		virtual void FreeDataPack(IDataPack *pack) =0;
   164 
   165 		/**
   166 		 * @brief Not implemented, do not use.
   167 		 *
   168 		 * @param readonly	Ignored
   169 		 * @return			0
   170 		 */
   171 		virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
   172 
   173 		/**
   174 		 * @brief Retrieves a KeyValues pointer from a handle.
   175 		 *
   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.
   179 		 *
   180 		 * @return			The KeyValues pointer, or NULL for any error encountered.
   181 		 */
   182 		virtual KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false) =0;
   183 
   184 		/**
   185 		 * @brief Returns the name of the game directory.
   186 		 *
   187 		 * @return			A string containing the name of the game directory.
   188 		 */
   189 		virtual const char *GetGameFolderName() const =0;
   190 
   191 		/**
   192 		 * @brief Returns the scripting engine interface.
   193 		 *
   194 		 * @return			A pointer to the scripting engine interface.
   195 		 */
   196 		virtual SourcePawn::ISourcePawnEngine *GetScriptingEngine() =0;
   197 
   198 		/**
   199 		 * @brief Returns the JIT interface.
   200 		 *
   201 		 * @return			A pointer to the JIT interface.
   202 		 */
   203 		virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
   204 
   205 		/**
   206 		 * @brief Returns the adjusted server time.
   207 		 *
   208 		 * @return			Adjusted server time.
   209 		 */
   210 		virtual time_t GetAdjustedTime() =0;
   211 
   212 		/**
   213 		 * @brief Sets the global client SourceMod will use for assisted 
   214 		 * translations (that is, %t).
   215 		 *
   216 		 * @param index		Client index.
   217 		 * @return			Old global client value.
   218 		 */
   219 		virtual unsigned int SetGlobalTarget(unsigned int index) =0;
   220 
   221 		/**
   222 		 * @brief Returns the global client SourceMod is currently using 
   223 		 * for assisted translations (that is, %t).
   224 		 *
   225 		 * @return			Global client value.
   226 		 */
   227 		virtual unsigned int GetGlobalTarget() const =0;
   228 	};
   229 }
   230 
   231 #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_