1.1 --- a/extensions/sdktools/vdecoder.cpp Sat Jun 16 15:40:22 2007 +0000
1.2 +++ b/extensions/sdktools/vdecoder.cpp Sat Jun 16 18:03:05 2007 +0000
1.3 @@ -68,12 +68,10 @@
1.4 }
1.5 case Valve_CBaseEntity:
1.6 case Valve_CBasePlayer:
1.7 - case Valve_POD:
1.8 case Valve_Edict:
1.9 case Valve_String:
1.10 {
1.11 - if (pass != PassType_Basic
1.12 - || (info->flags & PASSFLAG_BYREF))
1.13 + if (pass != PassType_Basic || (info->flags & PASSFLAG_BYREF))
1.14 {
1.15 return 0;
1.16 }
1.17 @@ -82,12 +80,44 @@
1.18 info->size = sizeof(void *);
1.19 return sizeof(void *);
1.20 }
1.21 + case Valve_POD:
1.22 + {
1.23 + info->type = PassType_Basic;
1.24 + info->flags = flags;
1.25 + if (flags & PASSFLAG_ASPOINTER)
1.26 + {
1.27 + info->size = sizeof(int *);
1.28 + return sizeof(int *) + sizeof(int);
1.29 + } else {
1.30 + info->size = sizeof(int);
1.31 + return sizeof(int);
1.32 + }
1.33 + }
1.34 + case Valve_Bool:
1.35 + {
1.36 + info->type = PassType_Basic;
1.37 + info->flags = flags;
1.38 + if (flags & PASSFLAG_ASPOINTER)
1.39 + {
1.40 + info->size = sizeof(bool *);
1.41 + return sizeof(bool *) + sizeof(bool);
1.42 + } else {
1.43 + info->size = sizeof(bool);
1.44 + return sizeof(bool);
1.45 + }
1.46 + }
1.47 case Valve_Float:
1.48 {
1.49 info->type = PassType_Float;
1.50 info->flags = flags;
1.51 - info->size = sizeof(float);
1.52 - return sizeof(float);
1.53 + if (flags & PASSFLAG_ASPOINTER)
1.54 + {
1.55 + info->size = sizeof(float *);
1.56 + return sizeof(float *) + sizeof(float);
1.57 + } else {
1.58 + info->size = sizeof(float);
1.59 + return sizeof(float);
1.60 + }
1.61 }
1.62 }
1.63
1.64 @@ -96,20 +126,19 @@
1.65
1.66 DataStatus EncodeValveParam(IPluginContext *pContext,
1.67 cell_t param,
1.68 - ValveType type,
1.69 - PassType pass,
1.70 + const ValvePassInfo *data,
1.71 const void *buffer)
1.72 {
1.73 - switch (type)
1.74 + switch (data->vtype)
1.75 {
1.76 case Valve_Vector:
1.77 {
1.78 Vector *v = NULL;
1.79
1.80 - if (pass == PassType_Basic)
1.81 + if (data->type == PassType_Basic)
1.82 {
1.83 v = *(Vector **)((unsigned char *)buffer + sizeof(Vector *));
1.84 - } else if (pass == PassType_Object) {
1.85 + } else if (data->type == PassType_Object) {
1.86 v = (Vector *)buffer;
1.87 }
1.88
1.89 @@ -126,10 +155,10 @@
1.90 {
1.91 QAngle *q = NULL;
1.92
1.93 - if (pass == PassType_Basic)
1.94 + if (data->type == PassType_Basic)
1.95 {
1.96 q = *(QAngle **)((unsigned char *)buffer + sizeof(QAngle *));
1.97 - } else if (pass == PassType_Object) {
1.98 + } else if (data->type == PassType_Object) {
1.99 q = (QAngle *)buffer;
1.100 }
1.101
1.102 @@ -180,10 +209,29 @@
1.103 cell_t *addr;
1.104 pContext->LocalToPhysAddr(param, &addr);
1.105
1.106 + if (data->flags & PASSFLAG_ASPOINTER)
1.107 + {
1.108 + buffer = (char *)buffer + sizeof(void *);
1.109 + }
1.110 +
1.111 *addr = *(cell_t *)buffer;
1.112
1.113 return Data_Okay;
1.114 }
1.115 + case Valve_Bool:
1.116 + {
1.117 + cell_t *addr;
1.118 + pContext->LocalToPhysAddr(param, &addr);
1.119 +
1.120 + if (data->flags & PASSFLAG_ASPOINTER)
1.121 + {
1.122 + buffer = (char *)buffer + sizeof(bool *);
1.123 + }
1.124 +
1.125 + *addr = *(bool *)buffer ? 1 : 0;
1.126 +
1.127 + return Data_Okay;
1.128 + }
1.129 }
1.130
1.131 return Data_Fail;
1.132 @@ -191,12 +239,10 @@
1.133
1.134 DataStatus DecodeValveParam(IPluginContext *pContext,
1.135 cell_t param,
1.136 - ValveType vtype,
1.137 - unsigned int vflags,
1.138 - PassType type,
1.139 + const ValvePassInfo *data,
1.140 void *buffer)
1.141 {
1.142 - switch (vtype)
1.143 + switch (data->vtype)
1.144 {
1.145 case Valve_Vector:
1.146 {
1.147 @@ -205,7 +251,7 @@
1.148 err = pContext->LocalToPhysAddr(param, &addr);
1.149
1.150 unsigned char *mem = (unsigned char *)buffer;
1.151 - if (type == PassType_Basic)
1.152 + if (data->type == PassType_Basic)
1.153 {
1.154 /* Store the object in the next N bytes, and store
1.155 * a pointer to that object right beforehand.
1.156 @@ -214,7 +260,7 @@
1.157
1.158 if (addr == pContext->GetNullRef(SP_NULL_VECTOR))
1.159 {
1.160 - if (vflags & VDECODE_FLAG_ALLOWNULL)
1.161 + if (data->decflags & VDECODE_FLAG_ALLOWNULL)
1.162 {
1.163 *realPtr = NULL;
1.164 return Data_Okay;
1.165 @@ -252,7 +298,7 @@
1.166 err = pContext->LocalToPhysAddr(param, &addr);
1.167
1.168 unsigned char *mem = (unsigned char *)buffer;
1.169 - if (type == PassType_Basic)
1.170 + if (data->type == PassType_Basic)
1.171 {
1.172 /* Store the object in the next N bytes, and store
1.173 * a pointer to that object right beforehand.
1.174 @@ -261,7 +307,7 @@
1.175
1.176 if (addr == pContext->GetNullRef(SP_NULL_VECTOR))
1.177 {
1.178 - if (!(vflags & VDECODE_FLAG_ALLOWNULL))
1.179 + if (!(data->decflags & VDECODE_FLAG_ALLOWNULL))
1.180 {
1.181 pContext->ThrowNativeError("NULL not allowed");
1.182 return Data_Fail;
1.183 @@ -295,7 +341,7 @@
1.184 case Valve_CBasePlayer:
1.185 {
1.186 edict_t *pEdict;
1.187 - if (vflags & VDECODE_FLAG_BYREF)
1.188 + if (data->decflags & VDECODE_FLAG_BYREF)
1.189 {
1.190 cell_t *addr;
1.191 pContext->LocalToPhysAddr(param, &addr);
1.192 @@ -304,7 +350,7 @@
1.193 if (param >= 1 && param <= playerhelpers->GetMaxClients())
1.194 {
1.195 IGamePlayer *player = playerhelpers->GetGamePlayer(param);
1.196 - if ((vflags & VDECODE_FLAG_ALLOWNOTINGAME)
1.197 + if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME)
1.198 && !player->IsConnected())
1.199 {
1.200 pContext->ThrowNativeError("Client %d is not connected", param);
1.201 @@ -315,7 +361,7 @@
1.202 }
1.203 pEdict = player->GetEdict();
1.204 } else if (param == -1) {
1.205 - if (vflags & VDECODE_FLAG_ALLOWNULL)
1.206 + if (data->decflags & VDECODE_FLAG_ALLOWNULL)
1.207 {
1.208 pEdict = NULL;
1.209 } else {
1.210 @@ -323,7 +369,7 @@
1.211 return Data_Fail;
1.212 }
1.213 } else if (param == 0) {
1.214 - if (vflags & VDECODE_FLAG_ALLOWWORLD)
1.215 + if (data->decflags & VDECODE_FLAG_ALLOWWORLD)
1.216 {
1.217 pEdict = engine->PEntityOfEntIndex(0);
1.218 } else {
1.219 @@ -361,7 +407,7 @@
1.220 case Valve_CBaseEntity:
1.221 {
1.222 edict_t *pEdict;
1.223 - if (vflags & VDECODE_FLAG_BYREF)
1.224 + if (data->decflags & VDECODE_FLAG_BYREF)
1.225 {
1.226 cell_t *addr;
1.227 pContext->LocalToPhysAddr(param, &addr);
1.228 @@ -370,7 +416,7 @@
1.229 if (param >= 1 && param <= playerhelpers->GetMaxClients())
1.230 {
1.231 IGamePlayer *player = playerhelpers->GetGamePlayer(param);
1.232 - if ((vflags & VDECODE_FLAG_ALLOWNOTINGAME)
1.233 + if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME)
1.234 && !player->IsConnected())
1.235 {
1.236 pContext->ThrowNativeError("Client %d is not connected", param);
1.237 @@ -381,7 +427,7 @@
1.238 }
1.239 pEdict = player->GetEdict();
1.240 } else if (param == -1) {
1.241 - if (vflags & VDECODE_FLAG_ALLOWNULL)
1.242 + if (data->decflags & VDECODE_FLAG_ALLOWNULL)
1.243 {
1.244 pEdict = NULL;
1.245 } else {
1.246 @@ -389,7 +435,7 @@
1.247 return Data_Fail;
1.248 }
1.249 } else if (param == 0) {
1.250 - if (vflags & VDECODE_FLAG_ALLOWWORLD)
1.251 + if (data->decflags & VDECODE_FLAG_ALLOWWORLD)
1.252 {
1.253 pEdict = engine->PEntityOfEntIndex(0);
1.254 } else {
1.255 @@ -431,7 +477,7 @@
1.256 case Valve_Edict:
1.257 {
1.258 edict_t *pEdict;
1.259 - if (vflags & VDECODE_FLAG_BYREF)
1.260 + if (data->decflags & VDECODE_FLAG_BYREF)
1.261 {
1.262 cell_t *addr;
1.263 pContext->LocalToPhysAddr(param, &addr);
1.264 @@ -440,7 +486,7 @@
1.265 if (param >= 1 && param <= playerhelpers->GetMaxClients())
1.266 {
1.267 IGamePlayer *player = playerhelpers->GetGamePlayer(param);
1.268 - if ((vflags & VDECODE_FLAG_ALLOWNOTINGAME)
1.269 + if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME)
1.270 && !player->IsConnected())
1.271 {
1.272 pContext->ThrowNativeError("Client %d is not connected", param);
1.273 @@ -451,7 +497,7 @@
1.274 }
1.275 pEdict = player->GetEdict();
1.276 } else if (param == -1) {
1.277 - if (vflags & VDECODE_FLAG_ALLOWNULL)
1.278 + if (data->decflags & VDECODE_FLAG_ALLOWNULL)
1.279 {
1.280 pEdict = NULL;
1.281 } else {
1.282 @@ -459,7 +505,7 @@
1.283 return Data_Fail;
1.284 }
1.285 } else if (param == 0) {
1.286 - if (vflags & VDECODE_FLAG_ALLOWWORLD)
1.287 + if (data->decflags & VDECODE_FLAG_ALLOWWORLD)
1.288 {
1.289 pEdict = engine->PEntityOfEntIndex(0);
1.290 } else {
1.291 @@ -483,15 +529,36 @@
1.292 case Valve_POD:
1.293 case Valve_Float:
1.294 {
1.295 - if (vflags & VDECODE_FLAG_BYREF)
1.296 + if (data->decflags & VDECODE_FLAG_BYREF)
1.297 {
1.298 cell_t *addr;
1.299 pContext->LocalToPhysAddr(param, &addr);
1.300 param = *addr;
1.301 }
1.302 + if (data->flags & PASSFLAG_ASPOINTER)
1.303 + {
1.304 + *(void **)buffer = (char *)buffer + sizeof(void *);
1.305 + buffer = *(void **)buffer;
1.306 + }
1.307 *(cell_t *)buffer = param;
1.308 return Data_Okay;
1.309 }
1.310 + case Valve_Bool:
1.311 + {
1.312 + if (data->decflags & VDECODE_FLAG_BYREF)
1.313 + {
1.314 + cell_t *addr;
1.315 + pContext->LocalToPhysAddr(param, &addr);
1.316 + param = *addr;
1.317 + }
1.318 + if (data->flags & PASSFLAG_ASPOINTER)
1.319 + {
1.320 + *(bool **)buffer = (bool *)((char *)buffer + sizeof(bool *));
1.321 + buffer = *(bool **)buffer;
1.322 + }
1.323 + *(bool *)buffer = param ? true : false;
1.324 + return Data_Okay;
1.325 + }
1.326 case Valve_String:
1.327 {
1.328 char *addr;