public/ISourceMod.h
author David Anderson <dvander@alliedmods.net>
Tue Feb 06 19:00:58 2007 +0000 (2007-02-06)
changeset 440 1d8333f9baed
parent 432 77112e9620fa
child 484 d254e257cac2
permissions -rw-r--r--
added interface spec for data packs
     1 /**
     2  * ===============================================================
     3  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     4  * ===============================================================
     5  *
     6  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
     7  * used or modified under the Terms and Conditions of its License Agreement, 
     8  * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
     9  * works must be licensed under the GNU General Public License (version 2 or 
    10  * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    11  * 
    12  * To view the latest information, see: http://www.sourcemod.net/license.php
    13  *
    14  * Version: $Id$
    15  */
    16 
    17 #ifndef _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
    18 #define _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
    19 
    20 /**
    21  * @file ISourceMod.h
    22  * @brief Defines miscellanious helper functions useful to extensions.
    23  */
    24 
    25 #include <IShareSys.h>
    26 #include <sp_vm_api.h>
    27 
    28 #define SMINTERFACE_SOURCEMOD_NAME		"ISourceMod"
    29 #define SMINTERFACE_SOURCEMOD_VERSION	1
    30 
    31 namespace SourceMod
    32 {
    33 	/**
    34 	 * @brief Describes various ways of formatting a base path.
    35 	 */
    36 	enum PathType
    37 	{
    38 		Path_None = 0,			/**< No base path */
    39 		Path_Game,				/**< Base path is absolute mod folder */
    40 		Path_SM,				/**< Base path is absolute to SourceMod */
    41 		Path_SM_Rel,			/**< Base path is relative to SourceMod */
    42 	};
    43 
    44 	/**
    45 	 * @brief Contains miscellanious helper functions.
    46 	 */
    47 	class ISourceMod : public SMInterface
    48 	{
    49 	public:
    50 		virtual const char *GetInterfaceName()
    51 		{
    52 			return SMINTERFACE_SOURCEMOD_NAME;
    53 		}
    54 		virtual unsigned int GetInterfaceVersion()
    55 		{
    56 			return SMINTERFACE_SOURCEMOD_VERSION;
    57 		}
    58 	public:
    59 		/**
    60 		 * @brief Returns the full path to the mod directory.
    61 		 *
    62 		 * @return			A string containing the full mod path.
    63 		 */
    64 		virtual const char *GetModPath() =0;
    65 
    66 		/**
    67 		 * @brief Returns the full path to the SourceMod directory.
    68 		 *
    69 		 * @return			A string containing the full SourceMod path.
    70 		 */
    71 		virtual const char *GetSourceModPath() =0;
    72 
    73 		/**
    74 		 * @brief Builds a platform path for a specific target base path.
    75 		 *
    76 		 * @param type		Type of path to use as a base.
    77 		 * @param buffer	Buffer to write to.
    78 		 * @param maxlength	Size of buffer.
    79 		 * @param format	Format string.
    80 		 * @param ...		Format arguments.
    81 		 * @return			Number of bytes written.
    82 		 */
    83 		virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...) =0;
    84 
    85 		/**
    86 		 * @brief Logs a message to the SourceMod logs.
    87 		 *
    88 		 * @param pExt		Extension calling this function.
    89 		 * @param format	Message format.
    90 		 * @param ...		Message format parameters.
    91 		 */
    92 		virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
    93 
    94 		/**
    95 		 * @brief Logs a message to the SourceMod error logs.
    96 		 *
    97 		 * @param pExt		Extension calling this function.
    98 		 * @param format	Message format.
    99 		 * @param ...		Message format parameters.
   100 		 */
   101 		virtual void LogError(IExtension *pExt, const char *format, ...) =0;
   102 
   103 		/**
   104 		 * @brief Formats a string from a native.
   105 		 *
   106 		 * @param buffer		Buffer to store message.
   107 		 * @param maxlength		Maximum length of buffer (inculding null terminator).
   108 		 * @param pContext		Pointer to the plugin's context.
   109 		 * @param params		Parameter array that was passed to the native.
   110 		 * @param param			Parameter index where format string and variable arguments begin.
   111 		 *						Note: parameter indexes start at 1.
   112 		 * @return				Number of bytes written, not including the null terminator.
   113 		 */
   114 		virtual size_t FormatString(char *buffer, 
   115 									size_t maxlength, 
   116 									SourcePawn::IPluginContext *pContext,
   117 									const cell_t *params,
   118 									unsigned int param) =0;
   119 
   120 #if 0
   121 		/**
   122 		 * @brief Creates a data pack object.
   123 		 *
   124 		 * @return			A new IDataPack object.
   125 		 */
   126 		virtual IDataPack *CreateDataPack() =0;
   127 
   128 		/**
   129 		 * @brief Releases a data pack's resources so it can be re-used.
   130 		 *
   131 		 * @param pack		An IDataPack object to release.
   132 		 */
   133 		virtual void FreeDataPack(IDataPack *pack) =0;
   134 
   135 		/**
   136 		 * @brief Returns the automated data pack handle type.
   137 		 *
   138 		 * The readonly data type is the parent of the writable type.  
   139 		 * Note that calling CloseHandle() on either type will release the data pack.
   140 		 * The readonly type is inheritable, but due to limitations of the Handle System,
   141 		 * the writable type is not.
   142 		 *
   143 		 * @param readonly	If true, the readonly type will be returned.
   144 		 * @return			The Handle type for storing generic data packs.
   145 		 */
   146 		 virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
   147 #endif
   148 	};
   149 }
   150 
   151 #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_