plugins/include/functions.inc
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 4162 233f56c20263
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     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.
    12  * 
    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
    16  * details.
    17  *
    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/>.
    20  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _functions_included
    34  #endinput
    35 #endif
    36 #define _functions_included
    37  
    38 #define SP_PARAMFLAG_BYREF	(1<<0)	/**< Internal use only. */
    39 
    40 /**
    41  * Describes the various ways to pass parameters to functions or forwards.
    42  */
    43 enum ParamType
    44 {
    45 	Param_Any			= 0,							/**< Any data type can be pushed */
    46 	Param_Cell			= (1<<1),						/**< Only basic cells can be pushed */
    47 	Param_Float			= (2<<1),						/**< Only floats can be pushed */
    48 	Param_String		= (3<<1)|SP_PARAMFLAG_BYREF,	/**< Only strings can be pushed */
    49 	Param_Array			= (4<<1)|SP_PARAMFLAG_BYREF,	/**< Only arrays can be pushed */
    50 	Param_VarArgs		= (5<<1),						/**< Same as "..." in plugins, anything can be pushed, but it will always be byref */
    51 	Param_CellByRef		= (1<<1)|SP_PARAMFLAG_BYREF,	/**< Only a cell by reference can be pushed */
    52 	Param_FloatByRef	= (2<<1)|SP_PARAMFLAG_BYREF		/**< Only a float by reference can be pushed */
    53 };
    54 
    55 /**
    56  * Defines how a forward iterates through plugin functions.
    57  */
    58 enum ExecType
    59 {
    60 	ET_Ignore	= 0,	/**< Ignore all return values, return 0 */
    61 	ET_Single	= 1,	/**< Only return the last exec, ignore all others */
    62 	ET_Event	= 2,	/**< Acts as an event with the Actions defined in core.inc, no mid-Stops allowed, returns highest */
    63 	ET_Hook		= 3		/**< Acts as a hook with the Actions defined in core.inc, mid-Stops allowed, returns highest */
    64 };
    65 
    66 /**
    67  * @section Flags that are used with Call_PushArrayEx() and Call_PushStringEx()
    68  */
    69  
    70 #define SM_PARAM_COPYBACK		(1<<0)		/**< Copy an array/reference back after call */
    71 
    72 #define SM_PARAM_STRING_UTF8	(1<<0)		/**< String should be UTF-8 handled */
    73 #define SM_PARAM_STRING_COPY	(1<<1)		/**< String should be copied into the plugin */
    74 #define SM_PARAM_STRING_BINARY	(1<<2)		/**< Treat the string as a binary string */
    75 
    76 /**
    77  * @endsection
    78  */
    79 
    80 /**
    81  * @section Error codes
    82  */
    83 #define SP_ERROR_NONE					0	/**< No error occurred */
    84 #define SP_ERROR_FILE_FORMAT			1	/**< File format unrecognized */
    85 #define SP_ERROR_DECOMPRESSOR			2	/**< A decompressor was not found */
    86 #define SP_ERROR_HEAPLOW				3	/**< Not enough space left on the heap */
    87 #define SP_ERROR_PARAM					4	/**< Invalid parameter or parameter type */
    88 #define SP_ERROR_INVALID_ADDRESS		5	/**< A memory address was not valid */
    89 #define SP_ERROR_NOT_FOUND				6	/**< The object in question was not found */
    90 #define SP_ERROR_INDEX					7	/**< Invalid index parameter */
    91 #define SP_ERROR_STACKLOW				8	/**< Nnot enough space left on the stack */
    92 #define SP_ERROR_NOTDEBUGGING			9	/**< Debug mode was not on or debug section not found */
    93 #define SP_ERROR_INVALID_INSTRUCTION	10	/**< Invalid instruction was encountered */
    94 #define SP_ERROR_MEMACCESS				11	/**< Invalid memory access */
    95 #define SP_ERROR_STACKMIN				12	/**< Stack went beyond its minimum value */
    96 #define SP_ERROR_HEAPMIN				13  /**< Heap went beyond its minimum value */
    97 #define SP_ERROR_DIVIDE_BY_ZERO			14	/**< Division by zero */
    98 #define SP_ERROR_ARRAY_BOUNDS			15	/**< Array index is out of bounds */
    99 #define SP_ERROR_INSTRUCTION_PARAM		16	/**< Instruction had an invalid parameter */
   100 #define SP_ERROR_STACKLEAK				17  /**< A native leaked an item on the stack */
   101 #define SP_ERROR_HEAPLEAK				18  /**< A native leaked an item on the heap */
   102 #define SP_ERROR_ARRAY_TOO_BIG			19	/**< A dynamic array is too big */
   103 #define SP_ERROR_TRACKER_BOUNDS			20	/**< Tracker stack is out of bounds */
   104 #define SP_ERROR_INVALID_NATIVE			21	/**< Native was pending or invalid */
   105 #define SP_ERROR_PARAMS_MAX				22	/**< Maximum number of parameters reached */
   106 #define SP_ERROR_NATIVE					23	/**< Error originates from a native */
   107 #define SP_ERROR_NOT_RUNNABLE			24	/**< Function or plugin is not runnable */
   108 #define SP_ERROR_ABORTED				25	/**< Function call was aborted */
   109 
   110 /**
   111  * @endsection
   112  */
   113 
   114 /**
   115  * Gets a function id from a function name. 
   116  *
   117  * @param plugin			Handle of the plugin that contains the function.
   118 							Pass INVALID_HANDLE to search in the calling plugin.
   119  * @param name				Name of the function.
   120  * @return 					Function id or INVALID_FUNCTION if not found.
   121  * @error					Invalid or corrupt plugin handle.
   122  */
   123 native Function:GetFunctionByName(Handle:plugin, const String:name[]);
   124 
   125 /**
   126  * Creates a global forward.
   127  *
   128  * @note The name used to create the forward is used as its public function in all target plugins.
   129  * @note This is ideal for global, static forwards that are never changed.
   130  * @note Global forwards cannot be cloned.
   131  * @note Use CloseHandle() to destroy these.
   132  *
   133  * @param name				Name of public function to use in forward.
   134  * @param type				Execution type to be used.
   135  * @param ...				Variable number of parameter types (up to 32).
   136  * @return 					Handle to new global forward.
   137  * @error					More than 32 paramater types passed.
   138  */
   139 native Handle:CreateGlobalForward(const String:name[], ExecType:type, ParamType:...);
   140 
   141 /**
   142  * Creates a private forward.
   143  *
   144  * @note No functions are automatically added. Use AddToForward() to do this.
   145  * @note Private forwards can be cloned.
   146  * @note Use CloseHandle() to destroy these.
   147  *
   148  * @param type				Execution type to be used.
   149  * @param ...				Variable number of parameter types (up to 32).
   150  * @return 					Handle to new private forward.
   151  * @error					More than 32 paramater types passed.
   152  */
   153 native Handle:CreateForward(ExecType:type, ParamType:...);
   154 
   155 /**
   156  * Returns the number of functions in a global or private forward's call list.
   157  *
   158  * @param fwd				Handle to global or private forward.
   159  * @return					Number of functions in forward.
   160  * @error					Invalid or corrupt forward handle.
   161  */
   162 native GetForwardFunctionCount(Handle:fwd);
   163 
   164 /**
   165  * Adds a function to a private forward's call list.
   166  *
   167  * @note Cannot be used during an incompleted call.
   168  *
   169  * @param fwd				Handle to private forward.
   170  * @param plugin			Handle of the plugin that contains the function.
   171  *							Pass INVALID_HANDLE to specify the calling plugin.
   172  * @param func				Function to add to forward.
   173  * @return					True on success, false otherwise.
   174  * @error					Invalid or corrupt private forward handle, invalid or corrupt plugin handle, or invalid function.
   175  */
   176 native bool:AddToForward(Handle:fwd, Handle:plugin, Function:func);
   177 
   178 /**
   179  * Removes a function from a private forward's call list.
   180  *
   181  * @note Only removes one instance.
   182  * @note Functions will be removed automatically if their parent plugin is unloaded.
   183  *
   184  * @param fwd				Handle to private forward.
   185  * @param plugin			Handle of the plugin that contains the function.
   186  *							Pass INVALID_HANDLE to specify the calling plugin.
   187  * @param func				Function to remove from forward.
   188  * @return					True on success, false otherwise.
   189  * @error					Invalid or corrupt private forward handle, invalid or corrupt plugin handle, or invalid function.
   190  */
   191 native bool:RemoveFromForward(Handle:fwd, Handle:plugin, Function:func);
   192 
   193 /**
   194  * Removes all instances of a plugin from a private forward's call list.
   195  *
   196  * @note Functions will be removed automatically if their parent plugin is unloaded.
   197  *
   198  * @param fwd				Handle to private forward.
   199  * @param plugin			Handle of the plugin to remove instances of.
   200  *							Pass INVALID_HANDLE to specify the calling plugin.
   201  * @return					Number of functions removed from forward.
   202  * @error					Invalid or corrupt private forward handle or invalid or corrupt plugin handle.
   203  */
   204 native RemoveAllFromForward(Handle:fwd, Handle:plugin);
   205 
   206 /**
   207  * Starts a call to functions in a forward's call list.
   208  *
   209  * @note Cannot be used during an incompleted call.
   210  *
   211  * @param fwd				Handle to global or private forward.
   212  * @noreturn
   213  * @error					Invalid or corrupt forward handle or called before another call has completed.
   214  */
   215 native Call_StartForward(Handle:fwd);
   216 
   217 /**
   218  * Starts a call to a function.
   219  *
   220  * @note Cannot be used during an incompleted call.
   221  *
   222  * @param plugin			Handle of the plugin that contains the function.
   223  *							Pass INVALID_HANDLE to specify the calling plugin.
   224  * @param func				Function to call.
   225  * @noreturn
   226  * @error					Invalid or corrupt plugin handle, invalid function, or called before another call has completed.
   227  */
   228 native Call_StartFunction(Handle:plugin, Function:func);
   229 
   230 /**
   231  * Pushes a cell onto the current call.
   232  *
   233  * @note Cannot be used before a call has been started.
   234  *
   235  * @param value				Cell value to push.
   236  * @noreturn
   237  * @error					Called before a call has been started.
   238  */
   239 native Call_PushCell(any:value);
   240 
   241 /**
   242  * Pushes a cell by reference onto the current call.
   243  *
   244  * @note Cannot be used before a call has been started.
   245  *
   246  * @param value				Cell reference to push.
   247  * @noreturn
   248  * @error					Called before a call has been started.
   249  */
   250 native Call_PushCellRef(&any:value);
   251 
   252 /**
   253  * Pushes a float onto the current call.
   254  *
   255  * @note Cannot be used before a call has been started.
   256  *
   257  * @param value				Floating point value to push.
   258  * @noreturn
   259  * @error					Called before a call has been started.
   260  */
   261 native Call_PushFloat(Float:value);
   262 
   263 /**
   264  * Pushes a float by reference onto the current call.
   265  *
   266  * @note Cannot be used before a call has been started.
   267  *
   268  * @param value				Floating point reference to push.
   269  * @noreturn
   270  * @error					Called before a call has been started.
   271  */
   272 native Call_PushFloatRef(&Float:value);
   273 
   274 /**
   275  * Pushes an array onto the current call.
   276  *
   277  * @note Changes to array are not copied back to caller. Use PushArrayEx() to do this.
   278  * @note Cannot be used before a call has been started.
   279  *
   280  * @param value				Array to push.
   281  * @param size				Size of array.
   282  * @noreturn
   283  * @error					Called before a call has been started.
   284  */
   285 native Call_PushArray(const any:value[], size);
   286 
   287 /**
   288  * Pushes an array onto the current call.
   289  *
   290  * @note Cannot be used before a call has been started.
   291  *
   292  * @param value				Array to push.
   293  * @param size				Size of array.
   294  * @param cpflags			Whether or not changes should be copied back to the input array.
   295  *							See SP_PARAM_* constants for details.
   296  * @noreturn
   297  * @error					Called before a call has been started.
   298  */
   299 native Call_PushArrayEx(any:value[], size, cpflags);
   300 
   301 /**
   302  * Pushes a string onto the current call.
   303  *
   304  * @note Changes to string are not copied back to caller. Use PushStringEx() to do this.
   305  * @note Cannot be used before a call has been started.
   306  *
   307  * @param value				String to push.
   308  * @noreturn
   309  * @error					Called before a call has been started.
   310  */
   311 native Call_PushString(const String:value[]);
   312 
   313 /**
   314  * Pushes a string onto the current call.
   315  *
   316  * @note Cannot be used before a call has been started.
   317  *
   318  * @param value				String to push.
   319  * @param length			Length of string buffer.
   320  * @param szflags			Flags determining how string should be handled.
   321  *							See SP_PARAM_STRING_* constants for details.
   322  *							The default (0) is to push ASCII.
   323  * @param cpflags			Whether or not changes should be copied back to the input array.
   324  *							See SP_PARAM_* constants for details.		
   325  * @noreturn
   326  * @error					Called before a call has been started.
   327  */
   328 native Call_PushStringEx(String:value[], length, szflags, cpflags);
   329 
   330 /**
   331  * Completes a call to a function or forward's call list.
   332  *
   333  * @note Cannot be used before a call has been started.
   334  *
   335  * @param result			Return value of function or forward's call list.		
   336  * @return					SP_ERROR_NONE on success, any other integer on failure.
   337  * @error					Called before a call has been started.
   338  */
   339 native Call_Finish(&any:result=0);
   340 
   341 /**
   342  * Cancels a call to a function or forward's call list.
   343  *
   344  * @note Cannot be used before a call has been started.
   345  *		
   346  * @noreturn
   347  * @error					Called before a call has been started.
   348  */
   349 native Call_Cancel();
   350 
   351 /**
   352  * Defines a native function.
   353  *
   354  * It is not necessary to validate the parameter count 
   355  *
   356  * @param plugin			Handle of the calling plugin.
   357  * @param numParams			Number of parameters passed to the native.
   358  * @return 					Value for the native call to return.
   359  */
   360 functag public NativeCall(Handle:plugin, numParams);
   361 
   362 /**
   363  * Creates a dynamic native.  This should only be called in AskPluginLoad(), or 
   364  * else you risk not having your native shared with other plugins.
   365  *
   366  * @param name				Name of the dynamic native; must be unique amongst
   367  *							all other registered dynamic natives.
   368  * @param func				Function to use as the dynamic native.
   369  * @noreturn
   370  */
   371 native CreateNative(const String:name[], NativeCall:func);
   372 
   373 /**
   374  * Throws an error in the calling plugin of a native, instead of your own plugin.
   375  *
   376  * @param error				Error code to use.
   377  * @param fmt				Error message format.
   378  * @param ...				Format arguments.
   379  */
   380 native ThrowNativeError(error, const String:fmt[], any:...);
   381 
   382 /**
   383  * Retrieves the string length from a native parameter string.  This is useful 
   384  * fetching the entire string using dynamic arrays.
   385  * @note If this function succeeds, Get/SetNativeString will also succeed.
   386  *
   387  * @param param				Parameter number, starting from 1.
   388  * @param length			Stores the length of the string.
   389  * @return					SP_ERROR_NONE on success, any other integer on failure.
   390  * @error					Invalid parameter number or calling from a non-native function.
   391  */
   392 native GetNativeStringLength(param, &length);
   393 
   394 /**
   395  * Retrieves a string from a native parameter.
   396  * @note Output conditions are undefined on failure.
   397  *
   398  * @param param				Parameter number, starting from 1.
   399  * @param buffer			Buffer to store the string in.
   400  * @param maxlength			Maximum length of the buffer.
   401  * @param bytes				Optionally store the number of bytes written.
   402  * @return					SP_ERROR_NONE on success, any other integer on failure.
   403  * @error					Invalid parameter number or calling from a non-native function.
   404  */
   405 native GetNativeString(param, String:buffer[], maxlength, &bytes=0);
   406 
   407 /**
   408  * Sets a string in a native parameter.
   409  * @note Output conditions are undefined on failure.
   410  *
   411  * @param param				Parameter number, starting from 1.
   412  * @param source			Source string to use.
   413  * @param maxlength			Maximum number of bytes to write.
   414  * @param utf8				If false, string will not be written
   415  *							with UTF8 safety.
   416  * @param bytes				Optionally store the number of bytes written.
   417  * @return					SP_ERROR_NONE on success, any other integer on failure.
   418  * @error					Invalid parameter number or calling from a non-native function.
   419  */
   420 native SetNativeString(param, const String:source[], maxlength, bool:utf8=true, &bytes=0);
   421 
   422 /**
   423  * Gets a cell from a native parameter.
   424  *
   425  * @param param				Parameter number, starting from 1.
   426  * @return					Cell value at the parameter number.
   427  * @error					Invalid parameter number or calling from a non-native function.
   428  */
   429 native any:GetNativeCell(param);
   430 
   431 /**
   432  * Gets a cell from a native parameter, by reference.
   433  *
   434  * @param param				Parameter number, starting from 1.
   435  * @return					Cell value at the parameter number.
   436  * @error					Invalid parameter number or calling from a non-native function.
   437  */
   438 native any:GetNativeCellRef(param);
   439 
   440 /**
   441  * Sets a cell from a native parameter, by reference.
   442  *
   443  * @param param				Parameter number, starting from 1.
   444  * @param value				Cell value at the parameter number to set by reference.
   445  * @noreturn
   446  * @error					Invalid parameter number or calling from a non-native function.
   447  */
   448 native SetNativeCellRef(param, any:value);
   449 
   450 /**
   451  * Gets an array from a native parameter (always by reference).
   452  *
   453  * @param param				Parameter number, starting from 1.
   454  * @param local				Local array to copy into.
   455  * @param size				Maximum size of local array.
   456  * @return					SP_ERROR_NONE on success, anything else on failure.
   457  * @error					Invalid parameter number or calling from a non-native function.
   458  */
   459 native GetNativeArray(param, any:local[], size);
   460 
   461 /**
   462  * Copies a local array into a native parameter array (always by reference).
   463  * 
   464  * @param param				Parameter number, starting from 1.
   465  * @param local				Local array to copy from.
   466  * @param size				Size of the local array to copy.
   467  * @return					SP_ERROR_NONE on success, anything else on failure.
   468  * @error					Invalid parameter number or calling from a non-native function.
   469  */
   470 native SetNativeArray(param, const any:local[], size);
   471 
   472 /**
   473  * Formats a string using parameters from a native.
   474  *
   475  * @note All parameter indexes start at 1.
   476  * @note If the input and output buffers overlap, the contents
   477  *  of the output buffer at the end is undefined.
   478  *
   479  * @param out_param			Output parameter number to write to.  If 0, out_string is used.
   480  * @param fmt_param			Format parameter number.  If 0, fmt_string is used.
   481  * @param vararg_param		First variable parameter number.
   482  * @param out_len			Output string buffer maximum length (always required).
   483  * @param written			Optionally stores the number of bytes written.
   484  * @param out_string		Output string buffer to use if out_param is not used.
   485  * @param fmt_string		Format string to use if fmt_param is not used.
   486  * @return					SP_ERROR_NONE on success, anything else on failure.
   487  */
   488 native FormatNativeString(out_param, 
   489 						  fmt_param, 
   490 						  vararg_param, 
   491 						  out_len,
   492 						  &written=0,
   493 						  String:out_string[]="",
   494 						  const String:fmt_string[]="");
   495 
   496 /**
   497  * Defines a RequestFrame Callback.
   498  *
   499  * @param data			Data passed to the RequestFrame native.
   500  * @noreturn
   501  */
   502 functag public RequestFrameCallback(any:data);
   503 
   504 /**
   505  * Creates a single use Next Frame hook.
   506  *
   507  * @param Function	Function to call on the next frame.
   508  * @param data			Value to be passed on the invocation of the Function.
   509  * @noreturn
   510  */
   511 native RequestFrame(RequestFrameCallback:Function, any:data=0);