public/ISourceMod.h
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 3401 98f3a34c1396
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2010 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	13
    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 Called when a game frame is fired.
    68 	 *
    69 	 * @param simulating		Whether or not the game is ticking.
    70 	 */
    71 	typedef void (*GAME_FRAME_HOOK)(bool simulating);
    72 
    73 	/**
    74 	 * @brief Function type for FrameAction callbacks.
    75 	 *
    76 	 * @param data				User data pointer.
    77 	 */
    78 	typedef void (*FRAMEACTION)(void *data);
    79 
    80 	/**
    81 	 * @brief Contains miscellaneous helper functions.
    82 	 */
    83 	class ISourceMod : public SMInterface
    84 	{
    85 	public:
    86 		virtual const char *GetInterfaceName()
    87 		{
    88 			return SMINTERFACE_SOURCEMOD_NAME;
    89 		}
    90 		virtual unsigned int GetInterfaceVersion()
    91 		{
    92 			return SMINTERFACE_SOURCEMOD_VERSION;
    93 		}
    94 	public:
    95 		/**
    96 		 * @brief Returns the full path to the game directory.
    97 		 *
    98 		 * @return			A string containing the full game path.
    99 		 */
   100 		virtual const char *GetGamePath() const =0;
   101 
   102 		/**
   103 		 * @brief Returns the full path to the SourceMod directory.
   104 		 *
   105 		 * @return			A string containing the full SourceMod path.
   106 		 */
   107 		virtual const char *GetSourceModPath() const =0;
   108 
   109 		/**
   110 		 * @brief Builds a platform path for a specific target base path.
   111 		 *
   112 		 * If the path starts with the string "file://" and the PathType is 
   113 		 * not relative, then the "file://" portion is stripped off, and the 
   114 		 * rest of the path is used without any modification (except for 
   115 		 * correcting slashes).  This can be used to override the path 
   116 		 * builder to supply alternate absolute paths.  Examples:
   117 		 *
   118 		 * file://C:/Temp/file.txt
   119 		 * file:///tmp/file.txt
   120 		 *
   121 		 * @param type		Type of path to use as a base.
   122 		 * @param buffer	Buffer to write to.
   123 		 * @param maxlength	Size of buffer.
   124 		 * @param format	Format string.
   125 		 * @param ...		Format arguments.
   126 		 * @return			Number of bytes written.
   127 		 */
   128 		virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...) =0;
   129 
   130 		/**
   131 		 * @brief Logs a message to the SourceMod logs.
   132 		 *
   133 		 * @param pExt		Extension calling this function.
   134 		 * @param format	Message format.
   135 		 * @param ...		Message format parameters.
   136 		 */
   137 		virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
   138 
   139 		/**
   140 		 * @brief Logs a message to the SourceMod error logs.
   141 		 *
   142 		 * @param pExt		Extension calling this function.
   143 		 * @param format	Message format.
   144 		 * @param ...		Message format parameters.
   145 		 */
   146 		virtual void LogError(IExtension *pExt, const char *format, ...) =0;
   147 
   148 		/**
   149 		 * @brief Formats a string from a native.
   150 		 *
   151 		 * @param buffer		Buffer to store message.
   152 		 * @param maxlength		Maximum length of buffer (including null terminator).
   153 		 * @param pContext		Pointer to the plugin's context.
   154 		 * @param params		Parameter array that was passed to the native.
   155 		 * @param param			Parameter index where format string and variable arguments begin.
   156 		 *						Note: parameter indexes start at 1.
   157 		 * @return				Number of bytes written, not including the null terminator.
   158 		 */
   159 		virtual size_t FormatString(char *buffer, 
   160 									size_t maxlength, 
   161 									SourcePawn::IPluginContext *pContext,
   162 									const cell_t *params,
   163 									unsigned int param) =0;
   164 
   165 		/**
   166 		 * @brief Creates a data pack object.
   167 		 *
   168 		 * @return			A new IDataPack object.
   169 		 */
   170 		virtual IDataPack *CreateDataPack() =0;
   171 
   172 		/**
   173 		 * @brief Releases a data pack's resources so it can be re-used.
   174 		 *
   175 		 * @param pack		An IDataPack object to release.
   176 		 */
   177 		virtual void FreeDataPack(IDataPack *pack) =0;
   178 
   179 		/**
   180 		 * @brief Not implemented, do not use.
   181 		 *
   182 		 * @param readonly	Ignored
   183 		 * @return			0
   184 		 */
   185 		virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
   186 
   187 		/**
   188 		 * @brief Retrieves a KeyValues pointer from a handle.
   189 		 *
   190 		 * @param hndl		Handle_t from which to retrieve contents.
   191 		 * @param err		Optional address to store a possible handle error.
   192 		 * @param root		If true it will return the root KeyValues pointer for the whole structure.
   193 		 *
   194 		 * @return			The KeyValues pointer, or NULL for any error encountered.
   195 		 */
   196 		virtual KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false) =0;
   197 
   198 		/**
   199 		 * @brief Returns the name of the game directory.
   200 		 *
   201 		 * @return			A string containing the name of the game directory.
   202 		 */
   203 		virtual const char *GetGameFolderName() const =0;
   204 
   205 		/**
   206 		 * @brief Returns the scripting engine interface.
   207 		 *
   208 		 * @return			A pointer to the scripting engine interface.
   209 		 */
   210 		virtual SourcePawn::ISourcePawnEngine *GetScriptingEngine() =0;
   211 
   212 		/**
   213 		 * @brief Deprecated, do not use.
   214 		 *
   215 		 * @return			NULL.
   216 		 */
   217 		virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
   218 
   219 		/**
   220 		 * @brief Returns the adjusted server time.
   221 		 *
   222 		 * @return			Adjusted server time.
   223 		 */
   224 		virtual time_t GetAdjustedTime() =0;
   225 
   226 		/**
   227 		 * @brief Sets the global client SourceMod will use for assisted 
   228 		 * translations (that is, %t).
   229 		 *
   230 		 * @param index		Client index.
   231 		 * @deprecated		Use ITranslator::GetGlobalTarget() instead.
   232 		 * @return			Old global client value.
   233 		 */
   234 		virtual unsigned int SetGlobalTarget(unsigned int index) =0;
   235 
   236 		/**
   237 		 * @brief Returns the global client SourceMod is currently using 
   238 		 * for assisted translations (that is, %t).
   239 		 *
   240 		 * @deprecated		Use ITranslator::GetGlobalTarget() instead.
   241 		 * @return			Global client value.
   242 		 */
   243 		virtual unsigned int GetGlobalTarget() const =0;
   244 
   245 		/**
   246 		 * @brief Adds a function to be called each game frame.
   247 		 *
   248 		 * @param hook		Hook function.
   249 		 */
   250 		virtual void AddGameFrameHook(GAME_FRAME_HOOK hook) =0;
   251 
   252 		/**
   253 		 * @brief Removes one game frame hook matching the given function.
   254 		 *
   255 		 * @param hook		Hook function.
   256 		 */
   257 		virtual void RemoveGameFrameHook(GAME_FRAME_HOOK hook) =0;
   258 
   259 		/**
   260 		 * @brief Platform-safe wrapper around snprintf().
   261 		 *
   262 		 * @param buffer	String buffer.
   263 		 * @param maxlength	Maximum length of buffer.
   264 		 * @param fmt		Format specifier string.
   265 		 * @param ...		Format arguments.
   266 		 * @return			Number of bytes (not including null terminator) written.
   267 		 */
   268 		virtual size_t Format(char *buffer, size_t maxlength, const char *fmt, ...) = 0;
   269 
   270 		/**
   271 		 * @brief Platform-safe wrapper around vsnprintf().
   272 		 *
   273 		 * @param buffer	String buffer.
   274 		 * @param maxlength	Maximum length of buffer.
   275 		 * @param fmt		Format specifier string.
   276 		 * @param ap		Format arguments.
   277 		 * @return			Number of bytes (not including null terminator) written.
   278 		 */
   279 		virtual size_t FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap) = 0;
   280 
   281 		/**
   282 		 * @brief Adds an action to be executed on the next available frame.
   283 		 *
   284 		 * This function is thread safe.
   285 		 *
   286 		 * @param fn		Function to execute.
   287 		 * @param data		Data to pass to function.
   288 		 */
   289 		virtual void AddFrameAction(FRAMEACTION fn, void *data) = 0;
   290 
   291 		/**
   292 		 * @brief Retrieves a core.cfg configuration value.
   293 		 *
   294 		 * @param key		Core.cfg key phrase.
   295 		 * @return			Value string, or NULL on failure.
   296 		 *					The string will be destroyed on core.cfg reparses.
   297 		 */
   298 		virtual const char *GetCoreConfigValue(const char *key) = 0;
   299 
   300 		/**
   301 		 * @brief Returns SourceMod's Metamod:Source plugin ID.
   302 		 *
   303 		 * @return			Metamod:Source PluginId.
   304 		 */
   305 		virtual int GetPluginId() = 0;
   306 
   307 		
   308 		/**
   309 		 * @brief Returns SourceHook's API version.
   310 		 *
   311 		 * @return			SourceHook API version number.
   312 		 */
   313 		virtual int GetShApiVersion() = 0;
   314 
   315 		/**
   316 		 * @brief Returns whether or not a map is currently running.
   317 		 *
   318 		 * @return			True if a map is currently running, otherwise false.
   319 		 */
   320 		virtual bool IsMapRunning() = 0;
   321 	};
   322 }
   323 
   324 #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_