public/ISourceMod.h
author Scott Ehlert <ds@alliedmods.net>
Thu Mar 22 21:50:20 2007 +0000 (2007-03-22)
changeset 653 ef60870067ff
parent 484 d254e257cac2
child 682 a70055d6d3b3
permissions -rw-r--r--
More consistency of some sort...

Oh god, what has possessed me to do this?
     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 miscellanious helper functions useful to extensions.
    24  */
    25 
    26 #include <IShareSys.h>
    27 #include <sp_vm_api.h>
    28 #include <IDataPack.h>
    29 
    30 #define SMINTERFACE_SOURCEMOD_NAME		"ISourceMod"
    31 #define SMINTERFACE_SOURCEMOD_VERSION	1
    32 
    33 namespace SourceMod
    34 {
    35 	/**
    36 	 * @brief Describes various ways of formatting a base path.
    37 	 */
    38 	enum PathType
    39 	{
    40 		Path_None = 0,			/**< No base path */
    41 		Path_Game,				/**< Base path is absolute mod folder */
    42 		Path_SM,				/**< Base path is absolute to SourceMod */
    43 		Path_SM_Rel,			/**< Base path is relative to SourceMod */
    44 	};
    45 
    46 	/**
    47 	 * @brief Contains miscellaneous helper functions.
    48 	 */
    49 	class ISourceMod : public SMInterface
    50 	{
    51 	public:
    52 		virtual const char *GetInterfaceName()
    53 		{
    54 			return SMINTERFACE_SOURCEMOD_NAME;
    55 		}
    56 		virtual unsigned int GetInterfaceVersion()
    57 		{
    58 			return SMINTERFACE_SOURCEMOD_VERSION;
    59 		}
    60 	public:
    61 		/**
    62 		 * @brief Returns the full path to the mod directory.
    63 		 *
    64 		 * @return			A string containing the full mod path.
    65 		 */
    66 		virtual const char *GetModPath() const =0;
    67 
    68 		/**
    69 		 * @brief Returns the full path to the SourceMod directory.
    70 		 *
    71 		 * @return			A string containing the full SourceMod path.
    72 		 */
    73 		virtual const char *GetSourceModPath() const =0;
    74 
    75 		/**
    76 		 * @brief Builds a platform path for a specific target base path.
    77 		 *
    78 		 * @param type		Type of path to use as a base.
    79 		 * @param buffer	Buffer to write to.
    80 		 * @param maxlength	Size of buffer.
    81 		 * @param format	Format string.
    82 		 * @param ...		Format arguments.
    83 		 * @return			Number of bytes written.
    84 		 */
    85 		virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...) =0;
    86 
    87 		/**
    88 		 * @brief Logs a message to the SourceMod logs.
    89 		 *
    90 		 * @param pExt		Extension calling this function.
    91 		 * @param format	Message format.
    92 		 * @param ...		Message format parameters.
    93 		 */
    94 		virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
    95 
    96 		/**
    97 		 * @brief Logs a message to the SourceMod error logs.
    98 		 *
    99 		 * @param pExt		Extension calling this function.
   100 		 * @param format	Message format.
   101 		 * @param ...		Message format parameters.
   102 		 */
   103 		virtual void LogError(IExtension *pExt, const char *format, ...) =0;
   104 
   105 		/**
   106 		 * @brief Formats a string from a native.
   107 		 *
   108 		 * @param buffer		Buffer to store message.
   109 		 * @param maxlength		Maximum length of buffer (inculding null terminator).
   110 		 * @param pContext		Pointer to the plugin's context.
   111 		 * @param params		Parameter array that was passed to the native.
   112 		 * @param param			Parameter index where format string and variable arguments begin.
   113 		 *						Note: parameter indexes start at 1.
   114 		 * @return				Number of bytes written, not including the null terminator.
   115 		 */
   116 		virtual size_t FormatString(char *buffer, 
   117 									size_t maxlength, 
   118 									SourcePawn::IPluginContext *pContext,
   119 									const cell_t *params,
   120 									unsigned int param) =0;
   121 
   122 		/**
   123 		 * @brief Creates a data pack object.
   124 		 *
   125 		 * @return			A new IDataPack object.
   126 		 */
   127 		virtual IDataPack *CreateDataPack() =0;
   128 
   129 		/**
   130 		 * @brief Releases a data pack's resources so it can be re-used.
   131 		 *
   132 		 * @param pack		An IDataPack object to release.
   133 		 */
   134 		virtual void FreeDataPack(IDataPack *pack) =0;
   135 
   136 		/**
   137 		 * @brief Returns the automated data pack handle type.
   138 		 *
   139 		 * The readonly data type is the parent of the writable type.  
   140 		 * Note that calling CloseHandle() on either type will release the data pack.
   141 		 * The readonly type is inheritable, but due to limitations of the Handle System,
   142 		 * the writable type is not.
   143 		 *
   144 		 * @param readonly	If true, the readonly type will be returned.
   145 		 * @return			The Handle type for storing generic data packs.
   146 		 */
   147 		 virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
   148 	};
   149 }
   150 
   151 #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_