public/ISourceMod.h
author David Anderson <dvander@alliedmods.net>
Sun Oct 28 08:02:24 2007 +0000 (2007-10-28)
changeset 1648 3c8256da48b9
parent 1411 a6e52857a881
child 1668 e1700463d1d8
permissions -rw-r--r--
added experimental extension interface for loading external extensions from mm:s
hard-bumped the extension api
     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 
    44 #define SMINTERFACE_SOURCEMOD_NAME		"ISourceMod"
    45 #define SMINTERFACE_SOURCEMOD_VERSION	3
    46 
    47 /**
    48 * @brief Forward declaration of the KeyValues class.
    49 */
    50 class KeyValues;
    51 
    52 namespace SourceMod
    53 {
    54 	/**
    55 	 * @brief Describes various ways of formatting a base path.
    56 	 */
    57 	enum PathType
    58 	{
    59 		Path_None = 0,			/**< No base path */
    60 		Path_Game,				/**< Base path is absolute mod folder */
    61 		Path_SM,				/**< Base path is absolute to SourceMod */
    62 		Path_SM_Rel,			/**< Base path is relative to SourceMod */
    63 	};
    64 
    65 	/**
    66 	 * @brief Contains miscellaneous helper functions.
    67 	 */
    68 	class ISourceMod : public SMInterface
    69 	{
    70 	public:
    71 		virtual const char *GetInterfaceName()
    72 		{
    73 			return SMINTERFACE_SOURCEMOD_NAME;
    74 		}
    75 		virtual unsigned int GetInterfaceVersion()
    76 		{
    77 			return SMINTERFACE_SOURCEMOD_VERSION;
    78 		}
    79 	public:
    80 		/**
    81 		 * @brief Returns the full path to the game directory.
    82 		 *
    83 		 * @return			A string containing the full game path.
    84 		 */
    85 		virtual const char *GetGamePath() const =0;
    86 
    87 		/**
    88 		 * @brief Returns the full path to the SourceMod directory.
    89 		 *
    90 		 * @return			A string containing the full SourceMod path.
    91 		 */
    92 		virtual const char *GetSourceModPath() const =0;
    93 
    94 		/**
    95 		 * @brief Builds a platform path for a specific target base path.
    96 		 *
    97 		 * @param type		Type of path to use as a base.
    98 		 * @param buffer	Buffer to write to.
    99 		 * @param maxlength	Size of buffer.
   100 		 * @param format	Format string.
   101 		 * @param ...		Format arguments.
   102 		 * @return			Number of bytes written.
   103 		 */
   104 		virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...) =0;
   105 
   106 		/**
   107 		 * @brief Logs a message to the SourceMod logs.
   108 		 *
   109 		 * @param pExt		Extension calling this function.
   110 		 * @param format	Message format.
   111 		 * @param ...		Message format parameters.
   112 		 */
   113 		virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
   114 
   115 		/**
   116 		 * @brief Logs a message to the SourceMod error logs.
   117 		 *
   118 		 * @param pExt		Extension calling this function.
   119 		 * @param format	Message format.
   120 		 * @param ...		Message format parameters.
   121 		 */
   122 		virtual void LogError(IExtension *pExt, const char *format, ...) =0;
   123 
   124 		/**
   125 		 * @brief Formats a string from a native.
   126 		 *
   127 		 * @param buffer		Buffer to store message.
   128 		 * @param maxlength		Maximum length of buffer (including null terminator).
   129 		 * @param pContext		Pointer to the plugin's context.
   130 		 * @param params		Parameter array that was passed to the native.
   131 		 * @param param			Parameter index where format string and variable arguments begin.
   132 		 *						Note: parameter indexes start at 1.
   133 		 * @return				Number of bytes written, not including the null terminator.
   134 		 */
   135 		virtual size_t FormatString(char *buffer, 
   136 									size_t maxlength, 
   137 									SourcePawn::IPluginContext *pContext,
   138 									const cell_t *params,
   139 									unsigned int param) =0;
   140 
   141 		/**
   142 		 * @brief Creates a data pack object.
   143 		 *
   144 		 * @return			A new IDataPack object.
   145 		 */
   146 		virtual IDataPack *CreateDataPack() =0;
   147 
   148 		/**
   149 		 * @brief Releases a data pack's resources so it can be re-used.
   150 		 *
   151 		 * @param pack		An IDataPack object to release.
   152 		 */
   153 		virtual void FreeDataPack(IDataPack *pack) =0;
   154 
   155 		/**
   156 		 * @brief Not implemented, do not use.
   157 		 *
   158 		 * @param readonly	Ignored
   159 		 * @return			0
   160 		 */
   161 		virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
   162 
   163 		/**
   164 		 * @brief Retrieves a KeyValues pointer from a handle.
   165 		 *
   166 		 * @param hndl		Handle_t from which to retrieve contents.
   167 		 * @param err		Optional address to store a possible handle error.
   168 		 * @param root		If true it will return the root KeyValues pointer for the whole structure.
   169 		 *
   170 		 * @return			The KeyValues pointer, or NULL for any error encountered.
   171 		 */
   172 		virtual KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false) =0;
   173 
   174 		/**
   175 		 * @brief Returns the name of the game directory.
   176 		 *
   177 		 * @return			A string containing the name of the game directory.
   178 		 */
   179 		virtual const char *GetGameFolderName() const =0;
   180 
   181 		/**
   182 		 * @brief Returns the scripting engine interface.
   183 		 *
   184 		 * @return			A pointer to the scripting engine interface.
   185 		 */
   186 		virtual SourcePawn::ISourcePawnEngine *GetScriptingEngine() =0;
   187 
   188 		/**
   189 		 * @brief Returns the JIT interface.
   190 		 *
   191 		 * @return			A pointer to the JIT interface.
   192 		 */
   193 		virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
   194 
   195 		/**
   196 		 * @brief Returns the adjusted server time.
   197 		 *
   198 		 * @return			Adjusted server time.
   199 		 */
   200 		virtual time_t GetAdjustedTime() =0;
   201 	};
   202 }
   203 
   204 #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_