3 * =============================================================================
4 * SourceMod SDKTools Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_VDECODER_H_
33 #define _INCLUDE_SOURCEMOD_VDECODER_H_
35 #include <sm_platform.h>
36 #include <sp_vm_api.h>
37 #include <extensions/IBinTools.h>
39 using namespace SourceMod;
40 using namespace SourcePawn;
43 * @brief Encapsulates types from the SDK
47 Valve_CBaseEntity, /**< CBaseEntity */
48 Valve_CBasePlayer, /**< CBasePlayer (disallow normal ents) */
49 Valve_Vector, /**< Vector */
50 Valve_QAngle, /**< QAngle */
51 Valve_POD, /**< Plain old data */
52 Valve_Float, /**< Float */
53 Valve_Edict, /**< Edict */
54 Valve_String, /**< String */
55 Valve_Bool, /**< Boolean */
64 #define VDECODE_FLAG_ALLOWNULL (1<<0) /**< Allow NULL for pointers */
65 #define VDECODE_FLAG_ALLOWNOTINGAME (1<<1) /**< Allow players not in game */
66 #define VDECODE_FLAG_ALLOWWORLD (1<<2) /**< Allow World entity */
67 #define VDECODE_FLAG_BYREF (1<<3) /**< Floats/ints by reference */
69 #define VENCODE_FLAG_COPYBACK (1<<0) /**< Copy back data */
71 #define PASSFLAG_ASPOINTER (1<<30) /**< Not an actual passflag, used internally */
74 * @brief Valve pre-defined calling types
78 ValveCall_Static, /**< Static call */
79 ValveCall_Entity, /**< Thiscall (CBaseEntity implicit first parameter) */
80 ValveCall_Player, /**< Thiscall (CBasePlayer implicit first parameter) */
81 ValveCall_GameRules, /**< Thiscall (CGameRules implicit first paramater) */
82 ValveCall_EntityList, /**< Thiscall (CGlobalEntityList 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_