extensions/sdktools/vdecoder.h
author David Anderson <dvander@alliedmods.net>
Wed Feb 25 20:07:12 2009 -0500 (2009-02-25)
changeset 2607 f3b8bbe17f85
parent 2289 44045ead61cd
child 2901 f5a1cf24f505
permissions -rw-r--r--
Backed out changeset fa286305bd3f
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod SDKTools Extension
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     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.
    11  * 
    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
    15  * details.
    16  *
    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/>.
    19  *
    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>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_VDECODER_H_
    33 #define _INCLUDE_SOURCEMOD_VDECODER_H_
    34 
    35 #include <sm_platform.h>
    36 #include <sp_vm_api.h>
    37 #include <extensions/IBinTools.h>
    38 
    39 using namespace SourceMod;
    40 using namespace SourcePawn;
    41 
    42 /**
    43  * @brief Encapsulates types from the SDK
    44  */
    45 enum ValveType
    46 {
    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 */
    56 };
    57 
    58 enum DataStatus
    59 {
    60 	Data_Fail = 0,
    61 	Data_Okay = 1,
    62 };
    63 
    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 */
    68 
    69 #define VENCODE_FLAG_COPYBACK		(1<<0)		/**< Copy back data */
    70 
    71 #define PASSFLAG_ASPOINTER			(1<<30)		/**< Not an actual passflag, used internally */
    72 
    73 /**
    74  * @brief Valve pre-defined calling types
    75  */
    76 enum ValveCallType
    77 {
    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) */
    83 };
    84 
    85 /**
    86  * @brief Valve parameter info
    87  */
    88 struct ValvePassInfo
    89 {
    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 */
    97 };
    98 
    99 struct ValveCall;
   100 
   101 /**
   102  * @brief Converts a valve parameter to a bintools parameter.
   103  *
   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.
   110  */
   111 size_t ValveParamToBinParam(ValveType type, 
   112 					  PassType pass,
   113 					  unsigned int flags,
   114 					  PassInfo *info,
   115 					  bool &needs_extra);
   116 
   117 /**
   118  * @brief Decodes data from a plugin to native data.
   119  *
   120  * Note: If you're going to return false, make sure to 
   121  * throw an error.
   122  *
   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.
   127  */
   128 DataStatus DecodeValveParam(IPluginContext *pContext,
   129 					  cell_t param,
   130 					  const ValveCall *pCall,
   131 					  const ValvePassInfo *vdata,
   132 					  void *buffer);
   133 
   134 /**
   135  * @brief Encodes native data back into a plugin.
   136  *
   137  * Note: If you're going to return false, make sure to 
   138  * throw an error.
   139  *
   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.
   144  */
   145 DataStatus EncodeValveParam(IPluginContext *pContext,
   146 					  cell_t param,
   147 					  const ValveCall *pCall,
   148 					  const ValvePassInfo *vdata,
   149 					  const void *buffer);
   150 
   151 #endif //_INCLUDE_SOURCEMOD_VDECODER_H_