public/ISourceMod.h
author David Anderson <dvander@alliedmods.net>
Wed Jun 06 17:34:35 2007 +0000 (2007-06-06)
changeset 888 b3c080b0e9bb
parent 735 249a3babc5ac
child 1191 054147e50960
permissions -rw-r--r--
- fixed a serious bug where %T arguments were read backwards (they now match the wiki documentation of phrase and then client)
- fixed a bug where the argument count for %T was not checked properly
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     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.
    12  * 
    13  * To view the latest information, see: http://www.sourcemod.net/license.php
    14  *
    15  * Version: $Id$
    16  */
    17 
    18 #ifndef _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
    19 #define _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
    20 
    21 /**
    22  * @file ISourceMod.h
    23  * @brief Defines miscellaneous helper functions useful to extensions.
    24  */
    25 
    26 #include <IHandleSys.h>
    27 #include <sp_vm_api.h>
    28 #include <IDataPack.h>
    29 
    30 #define SMINTERFACE_SOURCEMOD_NAME		"ISourceMod"
    31 #define SMINTERFACE_SOURCEMOD_VERSION	3
    32 
    33 /**
    34 * @brief Forward declaration of the KeyValues class.
    35 */
    36 class KeyValues;
    37 
    38 namespace SourceMod
    39 {
    40 	/**
    41 	 * @brief Describes various ways of formatting a base path.
    42 	 */
    43 	enum PathType
    44 	{
    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 */
    49 	};
    50 
    51 	/**
    52 	 * @brief Contains miscellaneous helper functions.
    53 	 */
    54 	class ISourceMod : public SMInterface
    55 	{
    56 	public:
    57 		virtual const char *GetInterfaceName()
    58 		{
    59 			return SMINTERFACE_SOURCEMOD_NAME;
    60 		}
    61 		virtual unsigned int GetInterfaceVersion()
    62 		{
    63 			return SMINTERFACE_SOURCEMOD_VERSION;
    64 		}
    65 	public:
    66 		/**
    67 		 * @brief Returns the full path to the game directory.
    68 		 *
    69 		 * @return			A string containing the full game path.
    70 		 */
    71 		virtual const char *GetGamePath() const =0;
    72 
    73 		/**
    74 		 * @brief Returns the full path to the SourceMod directory.
    75 		 *
    76 		 * @return			A string containing the full SourceMod path.
    77 		 */
    78 		virtual const char *GetSourceModPath() const =0;
    79 
    80 		/**
    81 		 * @brief Builds a platform path for a specific target base path.
    82 		 *
    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.
    89 		 */
    90 		virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...) =0;
    91 
    92 		/**
    93 		 * @brief Logs a message to the SourceMod logs.
    94 		 *
    95 		 * @param pExt		Extension calling this function.
    96 		 * @param format	Message format.
    97 		 * @param ...		Message format parameters.
    98 		 */
    99 		virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
   100 
   101 		/**
   102 		 * @brief Logs a message to the SourceMod error logs.
   103 		 *
   104 		 * @param pExt		Extension calling this function.
   105 		 * @param format	Message format.
   106 		 * @param ...		Message format parameters.
   107 		 */
   108 		virtual void LogError(IExtension *pExt, const char *format, ...) =0;
   109 
   110 		/**
   111 		 * @brief Formats a string from a native.
   112 		 *
   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.
   120 		 */
   121 		virtual size_t FormatString(char *buffer, 
   122 									size_t maxlength, 
   123 									SourcePawn::IPluginContext *pContext,
   124 									const cell_t *params,
   125 									unsigned int param) =0;
   126 
   127 		/**
   128 		 * @brief Creates a data pack object.
   129 		 *
   130 		 * @return			A new IDataPack object.
   131 		 */
   132 		virtual IDataPack *CreateDataPack() =0;
   133 
   134 		/**
   135 		 * @brief Releases a data pack's resources so it can be re-used.
   136 		 *
   137 		 * @param pack		An IDataPack object to release.
   138 		 */
   139 		virtual void FreeDataPack(IDataPack *pack) =0;
   140 
   141 		/**
   142 		 * @brief Returns the automated data pack handle type.
   143 		 *
   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.
   148 		 *
   149 		 * @param readonly	If true, the read-only type will be returned.
   150 		 * @return			The Handle type for storing generic data packs.
   151 		 */
   152 		virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
   153 
   154 		/**
   155 		 * @brief Retrieves a KeyValues pointer from a handle.
   156 		 *
   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.
   160 		 *
   161 		 * @return			The KeyValues pointer, or NULL for any error encountered.
   162 		 */
   163 		virtual KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false) =0;
   164 
   165 		/**
   166 		 * @brief Returns the name of the game directory.
   167 		 *
   168 		 * @return			A string containing the name of the game directory.
   169 		 */
   170 		virtual const char *GetGameFolderName() const =0;
   171 
   172 		/**
   173 		 * @brief Returns the scripting engine interface.
   174 		 *
   175 		 * @return			A pointer to the scripting engine interface.
   176 		 */
   177 		virtual SourcePawn::ISourcePawnEngine *GetScriptingEngine() =0;
   178 
   179 		/**
   180 		 * @brief Returns the JIT interface.
   181 		 *
   182 		 * @return			A pointer to the JIT interface.
   183 		 */
   184 		virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
   185 	};
   186 }
   187 
   188 #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_