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