3 * =============================================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _sourcemod_included
36 #define _sourcemod_included
39 * Plugin public information.
43 const String:name[], /**< Plugin Name */
44 const String:description[], /**< Plugin Description */
45 const String:author[], /**< Plugin Author */
46 const String:version[], /**< Plugin Version */
47 const String:url[], /**< Plugin URL */
67 #include <usermessages>
73 #include <commandfilters>
76 * Declare this as a struct in your plugin to expose its information.
79 * public Plugin:myinfo =
88 * Called when the plugin is fully initialized and all known external references are resolved.
89 * This is called even if the plugin type is "private."
90 * @note Errors in this function will cause the plugin to stop running.
94 forward OnPluginStart();
97 * Called before OnPluginStart, in case the plugin wants to check for load failure.
98 * This is called even if the plugin type is "private." Any natives from modules are
99 * not available at this point. Thus, this forward should only be used for explicit
100 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
102 * @note It is not safe to call externally resolved natives until OnPluginStart().
103 * @note Any sort of RTE in this function will cause the plugin to fail loading.
105 * @param myself Handle to the plugin.
106 * @param late Whether or not the plugin was loaded "late" (after map load).
107 * @param error Error message buffer in case load failed.
108 * @param err_max Maximum number of characters for error message buffer.
109 * @return True if load success, false otherwise.
111 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
114 * Called when the plugin is about to be unloaded.
118 forward OnPluginEnd();
121 * Called when the plugin's pause status is changing.
123 * @param pause True if the plugin is being paused, false otherwise.
126 forward OnPluginPauseChange(bool:pause);
129 * Called before every server frame. Note that you should avoid
130 * doing expensive computations here, and you should declare large
131 * local arrays using 'decl' instead of 'new'.
133 forward OnGameFrame();
136 * Called when the map is loaded.
138 * @note This used to be OnServerLoad(), which is now deprecated.
139 * Plugins still using the old forward will work.
141 forward OnMapStart();
144 * Called right before a map ends.
149 * Called when the map has loaded, servercfgfile (server.cfg) has been
150 * executed, and all plugin configs are done executing. This is the best
151 * place to inialize plugin functions which are based on cvar data.
153 * @note This will always be called once and only once per map. It will be
154 * called after OnMapStart().
158 forward OnConfigsExecuted();
161 * @deprecated Use OnConfigsExecuted() instead.
163 #pragma deprecated Use OnConfigsExecuted() instead
164 forward OnServerCfg();
167 * Called after all plugins have been loaded. This is called once for
168 * every plugin. If a plugin late loads, it will be called immediately
169 * after OnPluginStart().
171 forward OnAllPluginsLoaded();
174 * Called when an action is going to be logged.
176 * @param source Handle to the object logging the action, or INVALID_HANDLE
177 * if Core is logging the action.
178 * @param ident Type of object logging the action (plugin, ext, or core).
179 * @param client Client the action is from; 0 for server, -1 if not applicable.
180 * @param target Client the action is targetting, or -1 if not applicable.
181 * @param message Message that is being logged.
182 * @return Plugin_Continue will cause Core to defaulty log the message.
183 * Plugin_Handled will stop Core from logging the message.
184 * Plugin_Stop is the same as Handled, but prevents any other
185 * plugins from handling the message.
187 forward Action:OnLogAction(Handle:source,
191 const String:message[]);
194 * Returns the calling plugin's Handle.
196 * @return Handle of the calling plugin.
198 native Handle:GetMyHandle();
201 * Returns an iterator that can be used to search through plugins.
203 * @return Handle to iterate with. Must be closed via
205 * @error Invalid Handle.
207 native Handle:GetPluginIterator();
210 * Returns whether there are more plugins available in the iterator.
212 * @param iter Handle to the plugin iterator.
213 * @return True on more plugins, false otherwise.
214 * @error Invalid Handle.
216 native bool:MorePlugins(Handle:iter);
219 * Returns the current plugin in the iterator and advances the iterator.
221 * @param iter Handle to the plugin iterator.
222 * @return Current plugin the iterator is at, before
223 * the iterator is advanced.
224 * @error Invalid Handle.
226 native Handle:ReadPlugin(Handle:iter);
229 * Returns a plugin's status.
231 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
232 * @return Status code for the plugin.
233 * @error Invalid Handle.
235 native PluginStatus:GetPluginStatus(Handle:plugin);
238 * Retrieves a plugin's file name relative to the plugins folder.
240 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
241 * @param buffer Buffer to the store the file name.
242 * @param maxlength Maximum length of the name buffer.
244 * @error Invalid Handle.
246 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
249 * Retrieves whether or not a plugin is being debugged.
251 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
252 * @return True if being debugged, false otherwise.
253 * @error Invalid Handle.
255 native bool:IsPluginDebugging(Handle:hndl);
258 * Retrieves a plugin's public info.
260 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
261 * @param info Plugin info property to retrieve.
262 * @param buffer Buffer to store info in.
263 * @param maxlength Maximum length of buffer.
264 * @return True on success, false if property is not available.
265 * @error Invalid Handle.
267 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
270 * Causes the plugin to enter a failed state. An error will be thrown and
271 * the plugin will be paused until it is unloaded or reloaded.
273 * @param string Message to print.
275 * @error Always throws SP_ERROR_ABORT.
277 native SetFailState(const String:string[]);
280 * Aborts the current callback and throws an error. This function
281 * does not return in that no code is executed following it.
283 * @param format String format.
284 * @param ... Format arguments.
288 native ThrowError(const String:fmt[], any:...);
291 * Logs a plugin message to the SourceMod logs. The log message will be
292 * prefixed by the plugin's logtag (filename).
294 * @param format String format.
295 * @param ... Format arguments.
298 native LogMessage(const String:format[], any:...);
301 * Logs a message to the SourceMod logs without any plugin logtag. This is
302 * useful for re-routing messages from other plugins, for example, messages
305 * @param format String format.
306 * @param ... Format arguments.
309 native LogMessageEx(const String:format[], any:...);
312 * Logs a message to any file. The log message will be in the normal
313 * SourceMod format, with the plugin logtag prepended.
315 * @param file File to write the log message in.
316 * @param format String format.
317 * @param ... Format arguments.
319 * @error File could not be opened/written.
321 native LogToFile(const String:file[], const String:format[], any:...);
324 * Same as LogToFile(), except no plugin logtag is prepended.
326 * @param file File to write the log message in.
327 * @param format String format.
328 * @param ... Format arguments.
330 * @error File could not be opened/written.
332 native LogToFileEx(const String:file[], const String:format[], any:...);
335 * Logs an action from a command or event whereby interception and routing may
336 * be important. This is intended to be a logging version of ShowActivity().
338 * @param client Client performing the action, 0 for server, or -1 if not
340 * @param target Client being targetted, or -1 if not applicable.
341 * @param message Message format.
342 * @param ... Message formatting parameters.
345 native LogAction(client, target, const String:message[], any:...);
348 * Logs a plugin error message to the SourceMod logs.
350 * @param format String format.
351 * @param ... Format arguments.
354 native LogError(const String:format[], any:...);
357 * Gets the system time as a unix timestamp.
359 * @param bigStamp Optional array to store the 64bit timestamp in.
360 * @return 32bit timestamp (number of seconds since unix epoch).
362 native GetTime(bigStamp[2]={0,0});
365 * Produces a date and/or time string value for a timestamp.
367 * See this URL for valid parameters:
368 * http://opengroup.org/onlinepubs/007908799/xsh/strftime.html
370 * @param buffer Destination string buffer.
371 * @param maxlength Maximum length of output string buffer.
372 * @param format Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format).
373 * @param stamp Optional time stamp.
375 * @error Buffer too small or invalid time format.
377 native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
380 * Loads a game config file.
382 * @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
383 * and the extension should be omitted.
384 * @return A handle to the game config file or INVALID_HANDLE in failure.
386 native Handle:LoadGameConfigFile(const String:file[]);
389 * Returns an offset value.
391 * @param gc Game config handle.
392 * @param key Key to retrieve from the offset section.
393 * @return An offset, or -1 on failure.
395 native GameConfGetOffset(Handle:gc, const String:key[]);
398 * Gets the value of a key from the "Keys" section.
400 * @param gc Game config handle.
401 * @param key Key to retrieve from the Keys section.
402 * @param buffer Destination string buffer.
403 * @param maxlen Maximum length of output string buffer.
404 * @return True if key existed, false otherwise.
406 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
409 * Returns the operating system's "tick count," which is a number of
410 * milliseconds since the operating system loaded. This can be used
411 * for basic benchmarks.
413 * @return Tick count in milliseconds.
415 native GetSysTickCount();
418 * Specifies that the given config file should be executed after plugin load.
419 * OnConfigsExecuted() will not be called until the config file has executed,
420 * but it will be called if the execution fails.
422 * @param autoCreate If true, and the config file does not exist, such a config
423 * file will be automatically created and populated with
424 * information from the plugin's registered cvars.
425 * @param name Name of the config file, excluding the .cfg extension.
426 * If empty, <plugin.filename.cfg> is assumed.
427 * @param folder Folder under cfg/ to use. By default this is "sourcemod."
430 native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
433 * Sets a native as optional, such that if it is unloaded, removed,
434 * or otherwise non-existent, the plugin will still work. Calling
435 * removed natives results in a run-time error.
437 * @param name Native name.
440 native MarkNativeAsOptional(const String:name[]);
443 * Registers a library name for identifying as a dependency to
446 * @param name Library name.
449 native RegPluginLibrary(const String:name[]);
452 * Returns whether a library exists. This function should be considered
453 * expensive; it should only be called on plugin to determine availability
454 * of resources. Use OnLibraryAdded()/OnLibraryRemoved() to detect changes
455 * in optional resources.
457 * @param name Library name of a plugin or extension.
458 * @return True if exists, false otherwise.
460 native bool:LibraryExists(const String:name[]);
463 * Returns the status of an extension, by filename.
465 * @param name Extension name (like "sdktools.ext").
466 * @param error Optional error message buffer.
467 * @param maxlength Length of optional error message buffer.
468 * @return -2 if the extension was not found.
469 * -1 if the extension was found but failed to load.
470 * 0 if the extension loaded but reported an error.
471 * 1 if the extension is running without error.
473 native GetExtensionFileStatus(const String:name[], String:error[]="", maxlength=0);
476 * Called after a library is added that the current plugin references
477 * optionally. A library is either a plugin name or extension name, as
478 * exposed via its include file.
480 * @param name Library name.
482 forward OnLibraryAdded(const String:name[]);
485 * Called right before a library is removed that the current plugin references
486 * optionally. A library is either a plugin name or extension name, as
487 * exposed via its include file.
489 * @param name Library name.
491 forward OnLibraryRemoved(const String:name[]);