plugins/include/sourcemod.inc
author Phong Dang <teame06@gmail.com>
Wed Aug 01 18:22:53 2007 +0000 (2007-08-01)
changeset 1245 bb0611ab4bed
parent 1221 f2dc55c0ab6f
child 1268 9360f5ea2289
permissions -rw-r--r--
Updated license header.
     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 used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15 
    16 #if defined _sourcemod_included
    17  #endinput
    18 #endif
    19 #define _sourcemod_included
    20 
    21 /**
    22  * Plugin public information.
    23  */
    24 struct Plugin
    25 {
    26    const String:name[],			/**< Plugin Name */
    27    const String:description[],	/**< Plugin Description */
    28    const String:author[],		/**< Plugin Author */
    29    const String:version[],		/**< Plugin Version */
    30    const String:url[],			/**< Plugin URL */
    31 };
    32 
    33 #include <core>
    34 #include <float>
    35 #include <vector>
    36 #include <string>
    37 #include <handles>
    38 #include <functions>
    39 #include <files>
    40 #include <timers>
    41 #include <admin>
    42 #include <dbi>
    43 #include <lang>
    44 #include <sorting>
    45 #include <textparse>
    46 #include <clients>
    47 #include <console>
    48 #include <events>
    49 #include <bitbuffer>
    50 #include <usermessages>
    51 #include <keyvalues>
    52 #include <menus>
    53 #include <halflife>
    54 #include <adt>
    55 
    56 /**
    57  * Declare this as a struct in your plugin to expose its information.
    58  * Example:
    59  *
    60  * public Plugin:myinfo =
    61  * {
    62  *    name = "My Plugin",
    63  *    //etc
    64  * };
    65  */
    66 public Plugin:myinfo;
    67  
    68 /**
    69  * Called when the plugin is fully initialized and all known external references are resolved.
    70  * This is called even if the plugin type is "private."
    71  * @note Errors in this function will cause the plugin to stop running.
    72  *
    73  * @noreturn
    74  */
    75 forward OnPluginStart();
    76  
    77 /**
    78  * Called before OnPluginStart, in case the plugin wants to check for load failure.
    79  * This is called even if the plugin type is "private."  Any natives from modules are 
    80  * not available at this point.  Thus, this forward should only be used for explicit 
    81  * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
    82  * 
    83  * @note It is not safe to call externally resolved natives until OnPluginStart().
    84  * @note Any sort of RTE in this function will cause the plugin to fail loading.
    85  *
    86  * @param myself	Handle to the plugin.
    87  * @param late		Whether or not the plugin was loaded "late" (after map load).
    88  * @param error		Error message buffer in case load failed.
    89  * @param err_max	Maximum number of characters for error message buffer.
    90  * @return			True if load success, false otherwise.
    91  */
    92 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
    93 
    94 /**
    95  * Called when the plugin is about to be unloaded.
    96  *
    97  * @noreturn
    98  */
    99 forward OnPluginEnd();
   100 
   101 /**
   102  * Called when the plugin's pause status is changing.
   103  *
   104  * @param pause			True if the plugin is being paused, false otherwise.
   105  * @noreturn
   106  */
   107 forward OnPluginPauseChange(bool:pause);
   108 
   109 /**
   110  * Called before every server frame.  Note that you should avoid
   111  * doing expensive computations here, and you should declare large
   112  * local arrays using 'decl' instead of 'new'.
   113  */
   114 forward OnGameFrame();
   115 
   116 /**
   117  * Called when the map is loaded.
   118  *
   119  * @note This used to be OnServerLoad(), which is now deprecated.
   120  * Plugins still using the old forward will work.
   121  */
   122 forward OnMapStart();
   123 
   124 /**
   125  * Called right before a map ends.
   126  */
   127 forward OnMapEnd();
   128 
   129 /**
   130  * Called when the map has loaded, servercfgfile (server.cfg) has been 
   131  * executed, and all plugin configs are done executing.  This is the best
   132  * place to inialize plugin functions which are based on cvar data.  
   133  *
   134  * @note This will always be called once and only once per map.  It will be 
   135  * called after OnMapStart().
   136  *
   137  * @noreturn
   138  */
   139 forward OnConfigsExecuted();
   140 
   141 /**
   142  * @deprecated Use OnConfigsExecuted() instead.
   143  */
   144 forward OnServerCfg();
   145 
   146 /**
   147  * Called after all plugins have been loaded.
   148  */
   149 forward OnAllPluginsLoaded();
   150 
   151 /**
   152  * Returns the calling plugin's Handle.
   153  *
   154  * @return				Handle of the calling plugin.
   155  */
   156 native Handle:GetMyHandle();
   157 
   158 /**
   159  * Returns an iterator that can be used to search through plugins.
   160  *
   161  * @return				Handle to iterate with.  Must be closed via 
   162  * 						CloseHandle().
   163  * @error				Invalid Handle.
   164  */
   165 native Handle:GetPluginIterator();
   166 
   167 /**
   168  * Returns whether there are more plugins available in the iterator.
   169  *
   170  * @param iter			Handle to the plugin iterator.
   171  * @return				True on more plugins, false otherwise.
   172  * @error				Invalid Handle.
   173  */
   174 native bool:MorePlugins(Handle:iter);
   175 
   176 /**
   177  * Returns the current plugin in the iterator and advances the iterator.
   178  *
   179  * @param iter			Handle to the plugin iterator.
   180  * @return				Current plugin the iterator is at, before
   181  *						the iterator is advanced.
   182  * @error				Invalid Handle.
   183  */
   184 native Handle:ReadPlugin(Handle:iter);
   185 
   186 /**
   187  * Returns a plugin's status.
   188  *
   189  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   190  * @return				Status code for the plugin.
   191  * @error				Invalid Handle.
   192  */
   193 native PluginStatus:GetPluginStatus(Handle:plugin);
   194 
   195 /**
   196  * Retrieves a plugin's file name relative to the plugins folder.
   197  *
   198  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   199  * @param buffer		Buffer to the store the file name.
   200  * @param maxlength		Maximum length of the name buffer.
   201  * @noreturn
   202  * @error				Invalid Handle.
   203  */
   204 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
   205 
   206 /**
   207  * Retrieves whether or not a plugin is being debugged.
   208  *
   209  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   210  * @return				True if being debugged, false otherwise.
   211  * @error				Invalid Handle.
   212  */
   213 native bool:IsPluginDebugging(Handle:hndl);
   214 
   215 /**
   216  * Retrieves a plugin's public info.
   217  *
   218  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   219  * @param info			Plugin info property to retrieve.
   220  * @param buffer		Buffer to store info in.
   221  * @param maxlength		Maximum length of buffer.
   222  * @return				True on success, false if property is not available.
   223  * @error				Invalid Handle.
   224  */
   225 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
   226 
   227 /**
   228  * Causes the plugin to enter a failed state.  An error will be thrown and
   229  * the plugin will be paused until it is unloaded or reloaded.
   230  *
   231  * @param string		Message to print.
   232  * @noreturn
   233  * @error				Always throws SP_ERROR_ABORT.
   234  */
   235 native SetFailState(const String:string[]);
   236 
   237 /**
   238  * Aborts the current callback and throws an error.  This function
   239  * does not return in that no code is executed following it.
   240  *
   241  * @param format		String format.
   242  * @param ...			Format arguments.
   243  * @noreturn
   244  * @error				Always!
   245  */
   246 native ThrowError(const String:fmt[], any:...);
   247 
   248 /**
   249  * Logs a plugin message to the SourceMod logs.
   250  *
   251  * @param format		String format.
   252  * @param ...			Format arguments.
   253  * @noreturn
   254  */
   255 native LogMessage(const String:format[], any:...);
   256 
   257 /**
   258  * Logs a plugin error message to the SourceMod logs.
   259  *
   260  * @param format		String format.
   261  * @param ...			Format arguments.
   262  * @noreturn
   263  */
   264 native LogError(const String:format[], any:...);
   265 
   266 /**
   267  * Gets the system time as a unix timestamp.
   268  *
   269  * @param bigStamp		Optional array to store the 64bit timestamp in.
   270  * @return				32bit timestamp (number of seconds since unix epoch).
   271  */
   272 native GetTime(bigStamp[2]={0,0});
   273 
   274 /**
   275  * Format date and time.
   276  *
   277  * @param buffer		Destination string buffer.
   278  * @param maxlength		Maximum length of output string buffer.
   279  * @param format		Formatting rules.
   280  * @param stamp			Optional time stamp.
   281  * @noreturn
   282  */
   283 native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
   284 
   285 /**
   286  * Loads a game config file.
   287  *
   288  * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
   289  *					and the extension should be omitted.
   290  * @return			A handle to the game config file or INVALID_HANDLE in failure.
   291  */
   292 native Handle:LoadGameConfigFile(const String:file[]);
   293 
   294 /**
   295  * Returns an offset value.
   296  *
   297  * @param gc			Game config handle.
   298  * @param key			Key to retrieve from the offset section.
   299  * @return			An offset, or -1 on failure.
   300  */
   301 native GameConfGetOffset(Handle:gc, const String:key[]);
   302 
   303 /**
   304  * Gets the value of a key from the "Keys" section.
   305  *
   306  * @param gc			Game config handle.
   307  * @param key			Key to retrieve from the Keys section.
   308  * @param buffer		Destination string buffer.
   309  * @param maxlen		Maximum length of output string buffer.
   310  * @return				True if key existed, false otherwise.
   311  */
   312 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
   313 
   314 /**
   315  * Returns the operating system's "tick count," which is a number of 
   316  * milliseconds since the operating system loaded.  This can be used
   317  * for basic benchmarks.
   318  *
   319  * @return				Tick count in milliseconds.
   320  */
   321 native GetSysTickCount();
   322 
   323 /**
   324  * Specifies that the given config file should be executed after plugin load.
   325  * OnConfigsExecuted() will not be called until the config file has executed, 
   326  * but it will be called if the execution fails.
   327  *
   328  * @param autoCreate	If true, and the config file does not exist, such a config
   329  *						file will be automatically created and populated with
   330  *						information from the plugin's registered cvars.
   331  * @param name			Name of the config file, excluding the .cfg extension.
   332  *						If empty, <plugin.filename.cfg> is assumed.
   333  * @param folder		Folder under cfg/ to use.  By default this is "sourcemod."
   334  * @noreturn
   335  */
   336 native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
   337 
   338 /**
   339  * Sets a native as optional, such that if it is unloaded, removed,
   340  * or otherwise non-existent, the plugin will still work.  Calling
   341  * removed natives results in a run-time error.
   342  *
   343  * @param name			Native name.
   344  * @noreturn
   345  */
   346 native MarkNativeAsOptional(const String:name[]);
   347 
   348 /**
   349  * Registers a library name for identifying as a dependency to 
   350  * other plugins.
   351  *
   352  * @param name			Library name.
   353  * @noreturn
   354  */
   355 native RegPluginLibrary(const String:name[]);
   356 
   357 /**
   358  * Returns whether a library exists.
   359  *
   360  * @param name			Library name.
   361  * @return				True if exists, false otherwise.
   362  */
   363 native bool:LibraryExists(const String:name[]);
   364 
   365 /**
   366  * Called after a library (plugin) is added that the 
   367  * current plugin references optionally.
   368  *
   369  * @param name			Library name.
   370  */
   371 forward OnLibraryAdded(const String:name[]);
   372 
   373 /**
   374  * Called right before a library (plugin) is removed that the 
   375  * current plugin references optionally.
   376  *
   377  * @param name			Library name.
   378  */
   379 forward OnLibraryRemoved(const String:name[]);
   380 
   381 #include <helpers>
   382 #include <entity>