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