extensions/sdktools/vdecoder.h
author Scott Ehlert <ds@alliedmods.net>
Sun Jul 08 09:46:27 2007 +0000 (2007-07-08)
changeset 1065 11756fc9fb63
parent 1031 d9cf44ddcd9c
child 1233 e9cfc03b9bb8
permissions -rw-r--r--
Wowzers
-Added support for CGameRules calls to SDKTools
-Changed some game names in sdktools.games.txt to descriptions
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod SDK Tools 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  * 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.
    16  * 
    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.
    20  *
    21  * Version: $Id$
    22  */
    23 
    24 #ifndef _INCLUDE_SOURCEMOD_VDECODER_H_
    25 #define _INCLUDE_SOURCEMOD_VDECODER_H_
    26 
    27 #include <sm_platform.h>
    28 #include <sp_vm_api.h>
    29 #include <extensions/IBinTools.h>
    30 
    31 using namespace SourceMod;
    32 using namespace SourcePawn;
    33 
    34 /**
    35  * @brief Encapsulates types from the SDK
    36  */
    37 enum ValveType
    38 {
    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 */
    48 };
    49 
    50 enum DataStatus
    51 {
    52 	Data_Fail = 0,
    53 	Data_Okay = 1,
    54 };
    55 
    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 */
    60 
    61 #define VENCODE_FLAG_COPYBACK		(1<<0)		/**< Copy back data */
    62 
    63 #define PASSFLAG_ASPOINTER			(1<<30)		/**< Not an actual passflag, used internally */
    64 
    65 /**
    66  * @brief Valve pre-defined calling types
    67  */
    68 enum ValveCallType
    69 {
    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) */
    74 };
    75 
    76 /**
    77  * @brief Valve parameter info
    78  */
    79 struct ValvePassInfo
    80 {
    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 */
    88 };
    89 
    90 struct ValveCall;
    91 
    92 /**
    93  * @brief Converts a valve parameter to a bintools parameter.
    94  *
    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.
   101  */
   102 size_t ValveParamToBinParam(ValveType type, 
   103 					  PassType pass,
   104 					  unsigned int flags,
   105 					  PassInfo *info,
   106 					  bool &needs_extra);
   107 
   108 /**
   109  * @brief Decodes data from a plugin to native data.
   110  *
   111  * Note: If you're going to return false, make sure to 
   112  * throw an error.
   113  *
   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.
   118  */
   119 DataStatus DecodeValveParam(IPluginContext *pContext,
   120 					  cell_t param,
   121 					  const ValveCall *pCall,
   122 					  const ValvePassInfo *vdata,
   123 					  void *buffer);
   124 
   125 /**
   126  * @brief Encodes native data back into a plugin.
   127  *
   128  * Note: If you're going to return false, make sure to 
   129  * throw an error.
   130  *
   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.
   135  */
   136 DataStatus EncodeValveParam(IPluginContext *pContext,
   137 					  cell_t param,
   138 					  const ValveCall *pCall,
   139 					  const ValvePassInfo *vdata,
   140 					  const void *buffer);
   141 
   142 #endif //_INCLUDE_SOURCEMOD_VDECODER_H_