extensions/sdktools/vdecoder.h
author David Anderson <dvander@alliedmods.net>
Wed Aug 01 02:48:11 2007 +0000 (2007-08-01)
changeset 1233 e9cfc03b9bb8
parent 1065 11756fc9fb63
child 1240 79eebacc9d02
permissions -rw-r--r--
updated sdktools license headers
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourceMod SDKTools Extension
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * ================================================================
     7  *
     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.
    11  * 
    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.
    16  *
    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/>.
    19  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_SOURCEMOD_VDECODER_H_
    34 #define _INCLUDE_SOURCEMOD_VDECODER_H_
    35 
    36 #include <sm_platform.h>
    37 #include <sp_vm_api.h>
    38 #include <extensions/IBinTools.h>
    39 
    40 using namespace SourceMod;
    41 using namespace SourcePawn;
    42 
    43 /**
    44  * @brief Encapsulates types from the SDK
    45  */
    46 enum ValveType
    47 {
    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 */
    57 };
    58 
    59 enum DataStatus
    60 {
    61 	Data_Fail = 0,
    62 	Data_Okay = 1,
    63 };
    64 
    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 */
    69 
    70 #define VENCODE_FLAG_COPYBACK		(1<<0)		/**< Copy back data */
    71 
    72 #define PASSFLAG_ASPOINTER			(1<<30)		/**< Not an actual passflag, used internally */
    73 
    74 /**
    75  * @brief Valve pre-defined calling types
    76  */
    77 enum ValveCallType
    78 {
    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) */
    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_