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>
74 * Declare this as a struct in your plugin to expose its information.
77 * public Plugin:myinfo =
86 * Called when the plugin is fully initialized and all known external references are resolved.
87 * This is called even if the plugin type is "private."
88 * @note Errors in this function will cause the plugin to stop running.
92 forward OnPluginStart();
95 * Called before OnPluginStart, in case the plugin wants to check for load failure.
96 * This is called even if the plugin type is "private." Any natives from modules are
97 * not available at this point. Thus, this forward should only be used for explicit
98 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
100 * @note It is not safe to call externally resolved natives until OnPluginStart().
101 * @note Any sort of RTE in this function will cause the plugin to fail loading.
103 * @param myself Handle to the plugin.
104 * @param late Whether or not the plugin was loaded "late" (after map load).
105 * @param error Error message buffer in case load failed.
106 * @param err_max Maximum number of characters for error message buffer.
107 * @return True if load success, false otherwise.
109 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
112 * Called when the plugin is about to be unloaded.
116 forward OnPluginEnd();
119 * Called when the plugin's pause status is changing.
121 * @param pause True if the plugin is being paused, false otherwise.
124 forward OnPluginPauseChange(bool:pause);
127 * Called before every server frame. Note that you should avoid
128 * doing expensive computations here, and you should declare large
129 * local arrays using 'decl' instead of 'new'.
131 forward OnGameFrame();
134 * Called when the map is loaded.
136 * @note This used to be OnServerLoad(), which is now deprecated.
137 * Plugins still using the old forward will work.
139 forward OnMapStart();
142 * Called right before a map ends.
147 * Called when the map has loaded, servercfgfile (server.cfg) has been
148 * executed, and all plugin configs are done executing. This is the best
149 * place to inialize plugin functions which are based on cvar data.
151 * @note This will always be called once and only once per map. It will be
152 * called after OnMapStart().
156 forward OnConfigsExecuted();
159 * @deprecated Use OnConfigsExecuted() instead.
161 #pragma deprecated Use OnConfigsExecuted() instead
162 forward OnServerCfg();
165 * Called after all plugins have been loaded.
167 forward OnAllPluginsLoaded();
170 * Returns the calling plugin's Handle.
172 * @return Handle of the calling plugin.
174 native Handle:GetMyHandle();
177 * Returns an iterator that can be used to search through plugins.
179 * @return Handle to iterate with. Must be closed via
181 * @error Invalid Handle.
183 native Handle:GetPluginIterator();
186 * Returns whether there are more plugins available in the iterator.
188 * @param iter Handle to the plugin iterator.
189 * @return True on more plugins, false otherwise.
190 * @error Invalid Handle.
192 native bool:MorePlugins(Handle:iter);
195 * Returns the current plugin in the iterator and advances the iterator.
197 * @param iter Handle to the plugin iterator.
198 * @return Current plugin the iterator is at, before
199 * the iterator is advanced.
200 * @error Invalid Handle.
202 native Handle:ReadPlugin(Handle:iter);
205 * Returns a plugin's status.
207 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
208 * @return Status code for the plugin.
209 * @error Invalid Handle.
211 native PluginStatus:GetPluginStatus(Handle:plugin);
214 * Retrieves a plugin's file name relative to the plugins folder.
216 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
217 * @param buffer Buffer to the store the file name.
218 * @param maxlength Maximum length of the name buffer.
220 * @error Invalid Handle.
222 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
225 * Retrieves whether or not a plugin is being debugged.
227 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
228 * @return True if being debugged, false otherwise.
229 * @error Invalid Handle.
231 native bool:IsPluginDebugging(Handle:hndl);
234 * Retrieves a plugin's public info.
236 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
237 * @param info Plugin info property to retrieve.
238 * @param buffer Buffer to store info in.
239 * @param maxlength Maximum length of buffer.
240 * @return True on success, false if property is not available.
241 * @error Invalid Handle.
243 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
246 * Causes the plugin to enter a failed state. An error will be thrown and
247 * the plugin will be paused until it is unloaded or reloaded.
249 * @param string Message to print.
251 * @error Always throws SP_ERROR_ABORT.
253 native SetFailState(const String:string[]);
256 * Aborts the current callback and throws an error. This function
257 * does not return in that no code is executed following it.
259 * @param format String format.
260 * @param ... Format arguments.
264 native ThrowError(const String:fmt[], any:...);
267 * Logs a plugin message to the SourceMod logs.
269 * @param format String format.
270 * @param ... Format arguments.
273 native LogMessage(const String:format[], any:...);
276 * Logs a plugin error message to the SourceMod logs.
278 * @param format String format.
279 * @param ... Format arguments.
282 native LogError(const String:format[], any:...);
285 * Gets the system time as a unix timestamp.
287 * @param bigStamp Optional array to store the 64bit timestamp in.
288 * @return 32bit timestamp (number of seconds since unix epoch).
290 native GetTime(bigStamp[2]={0,0});
293 * Produces a date and/or time string value for a timestamp.
295 * See this URL for valid parameters:
296 * http://opengroup.org/onlinepubs/007908799/xsh/strftime.html
298 * @param buffer Destination string buffer.
299 * @param maxlength Maximum length of output string buffer.
300 * @param format Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format).
301 * @param stamp Optional time stamp.
303 * @error Buffer too small or invalid time format.
305 native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
308 * Loads a game config file.
310 * @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
311 * and the extension should be omitted.
312 * @return A handle to the game config file or INVALID_HANDLE in failure.
314 native Handle:LoadGameConfigFile(const String:file[]);
317 * Returns an offset value.
319 * @param gc Game config handle.
320 * @param key Key to retrieve from the offset section.
321 * @return An offset, or -1 on failure.
323 native GameConfGetOffset(Handle:gc, const String:key[]);
326 * Gets the value of a key from the "Keys" section.
328 * @param gc Game config handle.
329 * @param key Key to retrieve from the Keys section.
330 * @param buffer Destination string buffer.
331 * @param maxlen Maximum length of output string buffer.
332 * @return True if key existed, false otherwise.
334 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
337 * Returns the operating system's "tick count," which is a number of
338 * milliseconds since the operating system loaded. This can be used
339 * for basic benchmarks.
341 * @return Tick count in milliseconds.
343 native GetSysTickCount();
346 * Specifies that the given config file should be executed after plugin load.
347 * OnConfigsExecuted() will not be called until the config file has executed,
348 * but it will be called if the execution fails.
350 * @param autoCreate If true, and the config file does not exist, such a config
351 * file will be automatically created and populated with
352 * information from the plugin's registered cvars.
353 * @param name Name of the config file, excluding the .cfg extension.
354 * If empty, <plugin.filename.cfg> is assumed.
355 * @param folder Folder under cfg/ to use. By default this is "sourcemod."
358 native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
361 * Sets a native as optional, such that if it is unloaded, removed,
362 * or otherwise non-existent, the plugin will still work. Calling
363 * removed natives results in a run-time error.
365 * @param name Native name.
368 native MarkNativeAsOptional(const String:name[]);
371 * Registers a library name for identifying as a dependency to
374 * @param name Library name.
377 native RegPluginLibrary(const String:name[]);
380 * Returns whether a library exists.
382 * @param name Library name.
383 * @return True if exists, false otherwise.
385 native bool:LibraryExists(const String:name[]);
388 * Called after a library (plugin) is added that the
389 * current plugin references optionally.
391 * @param name Library name.
393 forward OnLibraryAdded(const String:name[]);
396 * Called right before a library (plugin) is removed that the
397 * current plugin references optionally.
399 * @param name Library name.
401 forward OnLibraryRemoved(const String:name[]);