3 * ===============================================================
4 * SourceMod SDK Tools Extension
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ===============================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifndef _INCLUDE_SOURCEMOD_VDECODER_H_
25 #define _INCLUDE_SOURCEMOD_VDECODER_H_
27 #include <sm_platform.h>
28 #include <sp_vm_api.h>
29 #include <extensions/IBinTools.h>
31 using namespace SourceMod;
32 using namespace SourcePawn;
35 * @brief Encapsulates types from the SDK
39 Valve_CBaseEntity, /**< CBaseEntity */
40 Valve_CBasePlayer, /**< CBasePlayer (disallow normal ents) */
41 Valve_Vector, /**< Vector */
42 Valve_QAngle, /**< QAngle */
43 Valve_POD, /**< Plain old data */
44 Valve_Float, /**< Float */
45 Valve_Edict, /**< Edict */
46 Valve_String, /**< String */
47 Valve_Bool, /**< Boolean */
56 #define VDECODE_FLAG_ALLOWNULL (1<<0) /**< Allow NULL for pointers */
57 #define VDECODE_FLAG_ALLOWNOTINGAME (1<<1) /**< Allow players not in game */
58 #define VDECODE_FLAG_ALLOWWORLD (1<<2) /**< Allow World entity */
59 #define VDECODE_FLAG_BYREF (1<<3) /**< Floats/ints by reference */
61 #define VENCODE_FLAG_COPYBACK (1<<0) /**< Copy back data */
63 #define PASSFLAG_ASPOINTER (1<<30) /**< Not an actual passflag, used internally */
66 * @brief Valve pre-defined calling types
70 ValveCall_Static, /**< Static call */
71 ValveCall_Entity, /**< Thiscall (CBaseEntity implicit first parameter) */
72 ValveCall_Player, /**< Thiscall (CBasePlayer implicit first parameter) */
73 ValveCall_GameRules, /**< Thiscall (CGameRules implicit first paramater) */
77 * @brief Valve parameter info
81 ValveType vtype; /**< IN: Valve type */
82 unsigned int decflags; /**< IN: VDECODE_FLAG_* */
83 unsigned int encflags; /**< IN: VENCODE_FLAG_* */
84 PassType type; /**< IN: Pass information */
85 unsigned int flags; /**< IN: Pass flags */
86 size_t offset; /**< OUT: stack offset */
87 size_t obj_offset; /**< OUT: object offset at end of the stack */
93 * @brief Converts a valve parameter to a bintools parameter.
95 * @param type Valve type.
96 * @param pass Either basic or object.
97 * @param flags Either BYVAL or BYREF.
98 * @param info Buffer to store param info in.
99 * @return Number of bytes this will use in the virtual stack,
100 * or 0 if conversion was impossible.
102 size_t ValveParamToBinParam(ValveType type,
109 * @brief Decodes data from a plugin to native data.
111 * Note: If you're going to return false, make sure to
114 * @param pContext Plugin context.
115 * @param param Parameter value from params array.
116 * @param buffer Buffer space in the virutal stack.
117 * @return True on success, false otherwise.
119 DataStatus DecodeValveParam(IPluginContext *pContext,
121 const ValveCall *pCall,
122 const ValvePassInfo *vdata,
126 * @brief Encodes native data back into a plugin.
128 * Note: If you're going to return false, make sure to
131 * @param pContext Plugin context.
132 * @param param Parameter value from params array.
133 * @param buffer Buffer space in the virutal stack.
134 * @return True on success, false otherwise.
136 DataStatus EncodeValveParam(IPluginContext *pContext,
138 const ValveCall *pCall,
139 const ValvePassInfo *vdata,
142 #endif //_INCLUDE_SOURCEMOD_VDECODER_H_