3 * ================================================================
4 * SourceMod SDKTools 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 * version 3.0, as published by the Free Software Foundation.
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, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #ifndef _INCLUDE_SOURCEMOD_VDECODER_H_
34 #define _INCLUDE_SOURCEMOD_VDECODER_H_
36 #include <sm_platform.h>
37 #include <sp_vm_api.h>
38 #include <extensions/IBinTools.h>
40 using namespace SourceMod;
41 using namespace SourcePawn;
44 * @brief Encapsulates types from the SDK
48 Valve_CBaseEntity, /**< CBaseEntity */
49 Valve_CBasePlayer, /**< CBasePlayer (disallow normal ents) */
50 Valve_Vector, /**< Vector */
51 Valve_QAngle, /**< QAngle */
52 Valve_POD, /**< Plain old data */
53 Valve_Float, /**< Float */
54 Valve_Edict, /**< Edict */
55 Valve_String, /**< String */
56 Valve_Bool, /**< Boolean */
65 #define VDECODE_FLAG_ALLOWNULL (1<<0) /**< Allow NULL for pointers */
66 #define VDECODE_FLAG_ALLOWNOTINGAME (1<<1) /**< Allow players not in game */
67 #define VDECODE_FLAG_ALLOWWORLD (1<<2) /**< Allow World entity */
68 #define VDECODE_FLAG_BYREF (1<<3) /**< Floats/ints by reference */
70 #define VENCODE_FLAG_COPYBACK (1<<0) /**< Copy back data */
72 #define PASSFLAG_ASPOINTER (1<<30) /**< Not an actual passflag, used internally */
75 * @brief Valve pre-defined calling types
79 ValveCall_Static, /**< Static call */
80 ValveCall_Entity, /**< Thiscall (CBaseEntity implicit first parameter) */
81 ValveCall_Player, /**< Thiscall (CBasePlayer implicit first parameter) */
82 ValveCall_GameRules, /**< Thiscall (CGameRules implicit first paramater) */
86 * @brief Valve parameter info
90 ValveType vtype; /**< IN: Valve type */
91 unsigned int decflags; /**< IN: VDECODE_FLAG_* */
92 unsigned int encflags; /**< IN: VENCODE_FLAG_* */
93 PassType type; /**< IN: Pass information */
94 unsigned int flags; /**< IN: Pass flags */
95 size_t offset; /**< OUT: stack offset */
96 size_t obj_offset; /**< OUT: object offset at end of the stack */
102 * @brief Converts a valve parameter to a bintools parameter.
104 * @param type Valve type.
105 * @param pass Either basic or object.
106 * @param flags Either BYVAL or BYREF.
107 * @param info Buffer to store param info in.
108 * @return Number of bytes this will use in the virtual stack,
109 * or 0 if conversion was impossible.
111 size_t ValveParamToBinParam(ValveType type,
118 * @brief Decodes data from a plugin to native data.
120 * Note: If you're going to return false, make sure to
123 * @param pContext Plugin context.
124 * @param param Parameter value from params array.
125 * @param buffer Buffer space in the virutal stack.
126 * @return True on success, false otherwise.
128 DataStatus DecodeValveParam(IPluginContext *pContext,
130 const ValveCall *pCall,
131 const ValvePassInfo *vdata,
135 * @brief Encodes native data back into a plugin.
137 * Note: If you're going to return false, make sure to
140 * @param pContext Plugin context.
141 * @param param Parameter value from params array.
142 * @param buffer Buffer space in the virutal stack.
143 * @return True on success, false otherwise.
145 DataStatus EncodeValveParam(IPluginContext *pContext,
147 const ValveCall *pCall,
148 const ValvePassInfo *vdata,
151 #endif //_INCLUDE_SOURCEMOD_VDECODER_H_