plugins/include/sdktools.inc
author Borja Ferrer <faluco@alliedmods.net>
Fri Aug 03 01:58:34 2007 +0000 (2007-08-03)
changeset 1256 76416aff76c3
parent 1240 79eebacc9d02
child 1330 ab94316bb52b
permissions -rw-r--r--
yay fixed comments
     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 _sdktools_included
    17   #endinput
    18 #endif
    19 #define _sdktools_included
    20 
    21 #include <core>
    22 #include <sdktools_engine>
    23 #include <sdktools_functions>
    24 #if !defined SDKTOOLS_DISABLE_SOUNDAPI
    25 #include <sdktools_sound>
    26 #endif
    27 #include <sdktools_stringtables>
    28 #include <sdktools_trace>
    29 #include <sdktools_tempents>
    30 #include <sdktools_tempents_stocks>
    31 #include <sdktools_voice>
    32 
    33 enum SDKCallType
    34 {
    35 	SDKCall_Static,		/**< Static call */
    36 	SDKCall_Entity,		/**< CBaseEntity call */
    37 	SDKCall_Player,		/**< CBasePlayer call */
    38 	SDKCall_GameRules,	/**< CGameRules call */
    39 	SDKCall_EntityList,	/**< CGlobalEntityList call */ 
    40 };
    41 
    42 enum SDKLibrary
    43 {
    44 	SDKLibrary_Server,	/**< server.dll/server_i486.so */
    45 	SDKLibrary_Engine,	/**< engine.dll/engine_*.so */
    46 };
    47 
    48 enum SDKFuncConfSource
    49 {
    50 	SDKConf_Virtual = 0,	/**< Read a virtual index from the Offsets section */
    51 	SDKConf_Signature = 1,	/**< Read a signature from the Signatures section */
    52 };
    53 
    54 enum SDKType
    55 {
    56 	SDKType_CBaseEntity,	/**< CBaseEntity (always as pointer) */
    57 	SDKType_CBasePlayer,	/**< CBasePlayer (always as pointer) */
    58 	SDKType_Vector,			/**< Vector (pointer, byval, or byref) */
    59 	SDKType_QAngle,			/**< QAngles (pointer, byval, or byref) */
    60 	SDKType_PlainOldData,	/**< Integer/generic data <=32bit (any) */
    61 	SDKType_Float,			/**< Float (any) */
    62 	SDKType_Edict,			/**< edict_t (always as pointer) */
    63 	SDKType_String,			/**< NULL-terminated string (always as pointer) */
    64 	SDKType_Bool,			/**< Boolean (any) */
    65 };
    66 
    67 enum SDKPassMethod
    68 {
    69 	SDKPass_Pointer,		/**< Pass as a pointer */
    70 	SDKPass_Plain,			/**< Pass as plain data */
    71 	SDKPass_ByValue,		/**< Pass an object by value */
    72 	SDKPass_ByRef,			/**< Pass an object by reference */
    73 };
    74 
    75 #define VDECODE_FLAG_ALLOWNULL		(1<<0)		/**< Allow NULL for pointers */
    76 #define VDECODE_FLAG_ALLOWNOTINGAME	(1<<1)		/**< Allow players not in game */
    77 #define VDECODE_FLAG_ALLOWWORLD		(1<<2)		/**< Allow World entity */
    78 #define VDECODE_FLAG_BYREF			(1<<3)		/**< Floats/ints by reference */
    79 
    80 #define VENCODE_FLAG_COPYBACK		(1<<0)		/**< Copy back data once done */
    81 
    82 /**
    83  * Starts the preparation of an SDK call.
    84  *
    85  * @param type			Type of function call this will be.
    86  * @noreturn
    87  */
    88 native StartPrepSDKCall(SDKCallType:type);
    89 
    90 /**
    91  * Sets the virtual index of the SDK call if it is virtual.
    92  *
    93  * @param vtblidx		Virtual table index.
    94  * @noreturn
    95  */
    96 native PrepSDKCall_SetVirtual(vtblidx);
    97 
    98 /**
    99  * Finds an address in a library and sets it as the address to use for the SDK call.
   100  *
   101  * @param lib			Library to use.
   102  * @param signature		Binary data to search for in the library.  If it starts with '@',
   103  *						the bytes parameter is ignored and the signature is interpreted
   104  *						as a symbol lookup in the library.
   105  * @param bytes			Number of bytes in the binary search string.
   106  * @return				True on success, false if nothing was found.
   107  */
   108 native bool:PrepSDKCall_SetSignature(SDKLibrary:lib, const String:signature[], bytes);
   109 
   110 /**
   111  * Finds an address or virtual function index in a GameConfig file and sets it as
   112  * the calling information for the SDK call.
   113  *
   114  * @param gameconf		GameConfig Handle, or INVALID_HANDLE to use sdktools.games.txt.
   115  * @param source		Whether to look in Offsets or Signatures.
   116  * @param name			Name of the property to find.
   117  * @return				True on success, false if nothing was found.
   118  */
   119 native bool:PrepSDKCall_SetFromConf(Handle:gameconf, SDKFuncConfSource:source, const String:name[]);
   120 
   121 /**
   122  * Sets the return information of an SDK call.  Do not call this if there is no return data.
   123  * This must be called if there is a return value (i.e. it is not necessarily safe to ignore 
   124  * the data).
   125  *
   126  * @param type			Data type to convert to/from.
   127  * @param pass			How the data is passed in C++.
   128  * @param decflags		Flags on decoding from the plugin to C++.
   129  * @param encflags		Flags on encoding from C++ to the plugin.
   130  * @noreturn
   131  */
   132 native PrepSDKCall_SetReturnInfo(SDKType:type, SDKPassMethod:pass, decflags=0, encflags=0);
   133 
   134 /**
   135  * Adds a parameter to the calling convention.  This should be called in normal ascending order.
   136  *
   137  * @param type			Data type to convert to/from.
   138  * @param pass			How the data is passed in C++.
   139  * @param decflags		Flags on decoding from the plugin to C++.
   140  * @param encflags		Flags on encoding from C++ to the plugin.
   141  * @noreturn
   142  */
   143 native PrepSDKCall_AddParameter(SDKType:type, SDKPassMethod:pass, decflags=0, encflags=0);
   144 
   145 /**
   146  * Finalizes an SDK call preparation and returns the resultant Handle.
   147  *
   148  * @return				A new SDKCall Handle on success, or INVALID_HANDLE on failure.
   149  */
   150 native Handle:EndPrepSDKCall();
   151 
   152 /**
   153  * Calls an SDK function with the given parameters.
   154  *
   155  * If the call type is Entity or Player, the index MUST ALWAYS be the FIRST parameter passed.
   156  * If the call type is GameRules, then nothing special needs to be passed.
   157  * If the return value is a Vector or QAngles, the SECOND parameter must be a Float[3].
   158  * If the return value is a string, the THIRD parameter must be a String buffer, and the
   159  *  FOURTH parameter must be the maximum length.
   160  * All parameters must be passed after the above is followed.  Failure to follow these 
   161  *  rules will result in crashes or wildly unexpected behavior!
   162  *
   163  * If the return value is a float or integer, the return value will be this value.
   164  * If the return value is a CBaseEntity, CBasePlayer, or edict, the return value will
   165  *   always be the entity index, or -1 for NULL.
   166  *
   167  * @param call			SDKCall Handle.
   168  * @param ...			Call Parameters.
   169  * @return				Simple return value, if any.
   170  * @error				Invalid Handle or internal decoding error.
   171  */
   172 native any:SDKCall(Handle:call, any:...);
   173 
   174 
   175 /**
   176  * Do not edit below this line!
   177  */
   178 public Extension:__ext_sdktools = 
   179 {
   180 	name = "SDKTools",
   181 	file = "sdktools.ext",
   182 #if defined AUTOLOAD_EXTENSIONS
   183 	autoload = 1,
   184 #else
   185 	autoload = 0,
   186 #endif
   187 #if defined REQUIRE_EXTENSIONS
   188 	required = 1,
   189 #else
   190 	required = 0,
   191 #endif
   192 };