public/ISourceMod.h
author David Anderson <dvander@alliedmods.net>
Mon May 26 07:52:27 2008 +0000 (2008-05-26)
changeset 2088 c84cd855ca10
parent 2042 4a2faafca477
child 2193 db7c6362f3f2
permissions -rw-r--r--
committed two forgotten files and updated the linux makefile
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#ifndef _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
ds@1952
    33
#define _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
ds@1952
    34
ds@1952
    35
/**
ds@1952
    36
 * @file ISourceMod.h
ds@1952
    37
 * @brief Defines miscellaneous helper functions useful to extensions.
ds@1952
    38
 */
ds@1952
    39
ds@1952
    40
#include <IHandleSys.h>
ds@1952
    41
#include <sp_vm_api.h>
ds@1952
    42
#include <IDataPack.h>
ds@1952
    43
#include <time.h>
ds@1952
    44
ds@1952
    45
#define SMINTERFACE_SOURCEMOD_NAME		"ISourceMod"
ds@1952
    46
#define SMINTERFACE_SOURCEMOD_VERSION	7
ds@1952
    47
ds@1952
    48
/**
ds@1952
    49
* @brief Forward declaration of the KeyValues class.
ds@1952
    50
*/
ds@1952
    51
class KeyValues;
ds@1952
    52
ds@1952
    53
namespace SourceMod
ds@1952
    54
{
ds@1952
    55
	/**
ds@1952
    56
	 * @brief Describes various ways of formatting a base path.
ds@1952
    57
	 */
ds@1952
    58
	enum PathType
ds@1952
    59
	{
ds@1952
    60
		Path_None = 0,			/**< No base path */
ds@1952
    61
		Path_Game,				/**< Base path is absolute mod folder */
ds@1952
    62
		Path_SM,				/**< Base path is absolute to SourceMod */
ds@1952
    63
		Path_SM_Rel,			/**< Base path is relative to SourceMod */
ds@1952
    64
	};
ds@1952
    65
ds@1952
    66
	/**
ds@1952
    67
	 * @brief Called when a game frame is fired.
ds@1952
    68
	 *
ds@1952
    69
	 * @param simulating		Whether or not the game is ticking.
ds@1952
    70
	 */
ds@1952
    71
	typedef void (*GAME_FRAME_HOOK)(bool simulating);
ds@1952
    72
ds@1952
    73
	/**
ds@1952
    74
	 * @brief Contains miscellaneous helper functions.
ds@1952
    75
	 */
ds@1952
    76
	class ISourceMod : public SMInterface
ds@1952
    77
	{
ds@1952
    78
	public:
ds@1952
    79
		virtual const char *GetInterfaceName()
ds@1952
    80
		{
ds@1952
    81
			return SMINTERFACE_SOURCEMOD_NAME;
ds@1952
    82
		}
ds@1952
    83
		virtual unsigned int GetInterfaceVersion()
ds@1952
    84
		{
ds@1952
    85
			return SMINTERFACE_SOURCEMOD_VERSION;
ds@1952
    86
		}
ds@1952
    87
	public:
ds@1952
    88
		/**
ds@1952
    89
		 * @brief Returns the full path to the game directory.
ds@1952
    90
		 *
ds@1952
    91
		 * @return			A string containing the full game path.
ds@1952
    92
		 */
ds@1952
    93
		virtual const char *GetGamePath() const =0;
ds@1952
    94
ds@1952
    95
		/**
ds@1952
    96
		 * @brief Returns the full path to the SourceMod directory.
ds@1952
    97
		 *
ds@1952
    98
		 * @return			A string containing the full SourceMod path.
ds@1952
    99
		 */
ds@1952
   100
		virtual const char *GetSourceModPath() const =0;
ds@1952
   101
ds@1952
   102
		/**
ds@1952
   103
		 * @brief Builds a platform path for a specific target base path.
ds@1952
   104
		 *
ds@1952
   105
		 * If the path starts with the string "file://" and the PathType is 
ds@1952
   106
		 * not relative, then the "file://" portion is stripped off, and the 
ds@1952
   107
		 * rest of the path is used without any modification (except for 
ds@1952
   108
		 * correcting slashes).  This can be used to override the path 
ds@1952
   109
		 * builder to supply alternate absolute paths.  Examples:
ds@1952
   110
		 *
ds@1952
   111
		 * file://C:/Temp/file.txt
ds@1952
   112
		 * file:///tmp/file.txt
ds@1952
   113
		 *
ds@1952
   114
		 * @param type		Type of path to use as a base.
ds@1952
   115
		 * @param buffer	Buffer to write to.
ds@1952
   116
		 * @param maxlength	Size of buffer.
ds@1952
   117
		 * @param format	Format string.
ds@1952
   118
		 * @param ...		Format arguments.
ds@1952
   119
		 * @return			Number of bytes written.
ds@1952
   120
		 */
ds@1952
   121
		virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...) =0;
ds@1952
   122
ds@1952
   123
		/**
ds@1952
   124
		 * @brief Logs a message to the SourceMod logs.
ds@1952
   125
		 *
ds@1952
   126
		 * @param pExt		Extension calling this function.
ds@1952
   127
		 * @param format	Message format.
ds@1952
   128
		 * @param ...		Message format parameters.
ds@1952
   129
		 */
ds@1952
   130
		virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
ds@1952
   131
ds@1952
   132
		/**
ds@1952
   133
		 * @brief Logs a message to the SourceMod error logs.
ds@1952
   134
		 *
ds@1952
   135
		 * @param pExt		Extension calling this function.
ds@1952
   136
		 * @param format	Message format.
ds@1952
   137
		 * @param ...		Message format parameters.
ds@1952
   138
		 */
ds@1952
   139
		virtual void LogError(IExtension *pExt, const char *format, ...) =0;
ds@1952
   140
ds@1952
   141
		/**
ds@1952
   142
		 * @brief Formats a string from a native.
ds@1952
   143
		 *
ds@1952
   144
		 * @param buffer		Buffer to store message.
ds@1952
   145
		 * @param maxlength		Maximum length of buffer (including null terminator).
ds@1952
   146
		 * @param pContext		Pointer to the plugin's context.
ds@1952
   147
		 * @param params		Parameter array that was passed to the native.
ds@1952
   148
		 * @param param			Parameter index where format string and variable arguments begin.
ds@1952
   149
		 *						Note: parameter indexes start at 1.
ds@1952
   150
		 * @return				Number of bytes written, not including the null terminator.
ds@1952
   151
		 */
ds@1952
   152
		virtual size_t FormatString(char *buffer, 
ds@1952
   153
									size_t maxlength, 
ds@1952
   154
									SourcePawn::IPluginContext *pContext,
ds@1952
   155
									const cell_t *params,
ds@1952
   156
									unsigned int param) =0;
ds@1952
   157
ds@1952
   158
		/**
ds@1952
   159
		 * @brief Creates a data pack object.
ds@1952
   160
		 *
ds@1952
   161
		 * @return			A new IDataPack object.
ds@1952
   162
		 */
ds@1952
   163
		virtual IDataPack *CreateDataPack() =0;
ds@1952
   164
ds@1952
   165
		/**
ds@1952
   166
		 * @brief Releases a data pack's resources so it can be re-used.
ds@1952
   167
		 *
ds@1952
   168
		 * @param pack		An IDataPack object to release.
ds@1952
   169
		 */
ds@1952
   170
		virtual void FreeDataPack(IDataPack *pack) =0;
ds@1952
   171
ds@1952
   172
		/**
ds@1952
   173
		 * @brief Not implemented, do not use.
ds@1952
   174
		 *
ds@1952
   175
		 * @param readonly	Ignored
ds@1952
   176
		 * @return			0
ds@1952
   177
		 */
ds@1952
   178
		virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
ds@1952
   179
ds@1952
   180
		/**
ds@1952
   181
		 * @brief Retrieves a KeyValues pointer from a handle.
ds@1952
   182
		 *
ds@1952
   183
		 * @param hndl		Handle_t from which to retrieve contents.
ds@1952
   184
		 * @param err		Optional address to store a possible handle error.
ds@1952
   185
		 * @param root		If true it will return the root KeyValues pointer for the whole structure.
ds@1952
   186
		 *
ds@1952
   187
		 * @return			The KeyValues pointer, or NULL for any error encountered.
ds@1952
   188
		 */
ds@1952
   189
		virtual KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false) =0;
ds@1952
   190
ds@1952
   191
		/**
ds@1952
   192
		 * @brief Returns the name of the game directory.
ds@1952
   193
		 *
ds@1952
   194
		 * @return			A string containing the name of the game directory.
ds@1952
   195
		 */
ds@1952
   196
		virtual const char *GetGameFolderName() const =0;
ds@1952
   197
ds@1952
   198
		/**
ds@1952
   199
		 * @brief Returns the scripting engine interface.
ds@1952
   200
		 *
ds@1952
   201
		 * @return			A pointer to the scripting engine interface.
ds@1952
   202
		 */
ds@1952
   203
		virtual SourcePawn::ISourcePawnEngine *GetScriptingEngine() =0;
ds@1952
   204
ds@1952
   205
		/**
ds@1952
   206
		 * @brief Returns the JIT interface.
ds@1952
   207
		 *
ds@1952
   208
		 * @return			A pointer to the JIT interface.
ds@1952
   209
		 */
ds@1952
   210
		virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
ds@1952
   211
ds@1952
   212
		/**
ds@1952
   213
		 * @brief Returns the adjusted server time.
ds@1952
   214
		 *
ds@1952
   215
		 * @return			Adjusted server time.
ds@1952
   216
		 */
ds@1952
   217
		virtual time_t GetAdjustedTime() =0;
ds@1952
   218
ds@1952
   219
		/**
ds@1952
   220
		 * @brief Sets the global client SourceMod will use for assisted 
ds@1952
   221
		 * translations (that is, %t).
ds@1952
   222
		 *
ds@1952
   223
		 * @param index		Client index.
dvander@2042
   224
		 * @deprecated		Use ITranslator::GetGlobalTarget() instead.
ds@1952
   225
		 * @return			Old global client value.
ds@1952
   226
		 */
ds@1952
   227
		virtual unsigned int SetGlobalTarget(unsigned int index) =0;
ds@1952
   228
ds@1952
   229
		/**
ds@1952
   230
		 * @brief Returns the global client SourceMod is currently using 
ds@1952
   231
		 * for assisted translations (that is, %t).
ds@1952
   232
		 *
dvander@2042
   233
		 * @deprecated		Use ITranslator::GetGlobalTarget() instead.
ds@1952
   234
		 * @return			Global client value.
ds@1952
   235
		 */
ds@1952
   236
		virtual unsigned int GetGlobalTarget() const =0;
ds@1952
   237
ds@1952
   238
		/**
ds@1952
   239
		 * @brief Adds a function to be called each game frame.
ds@1952
   240
		 *
ds@1952
   241
		 * @param hook		Hook function.
ds@1952
   242
		 */
ds@1952
   243
		virtual void AddGameFrameHook(GAME_FRAME_HOOK hook) =0;
ds@1952
   244
ds@1952
   245
		/**
ds@1952
   246
		 * @brief Removes one game frame hook matching the given function.
ds@1952
   247
		 *
ds@1952
   248
		 * @param hook		Hook function.
ds@1952
   249
		 */
ds@1952
   250
		virtual void RemoveGameFrameHook(GAME_FRAME_HOOK hook) =0;
ds@1952
   251
	};
ds@1952
   252
}
ds@1952
   253
ds@1952
   254
#endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_