1.1 --- a/extensions/sdktools/extension.cpp Sat Jun 16 15:40:22 2007 +0000
1.2 +++ b/extensions/sdktools/extension.cpp Sat Jun 16 18:03:05 2007 +0000
1.3 @@ -23,6 +23,7 @@
1.4
1.5 #include "extension.h"
1.6 #include "vcallbuilder.h"
1.7 +#include "vnatives.h"
1.8
1.9 /**
1.10 * @file extension.cpp
1.11 @@ -43,6 +44,7 @@
1.12 {
1.13 sharesys->AddDependency(myself, "bintools.ext", true, true);
1.14 sharesys->AddNatives(myself, g_CallNatives);
1.15 + sharesys->AddNatives(myself, g_Natives);
1.16
1.17 if (!gameconfs->LoadGameConfigFile("sdktools.games", &g_pGameConf, error, maxlength))
1.18 {
1.19 @@ -65,6 +67,15 @@
1.20
1.21 void SDKTools::SDK_OnUnload()
1.22 {
1.23 + List<ValveCall *>::iterator iter;
1.24 + for (iter = g_RegCalls.begin();
1.25 + iter != g_RegCalls.end();
1.26 + iter++)
1.27 + {
1.28 + delete (*iter);
1.29 + }
1.30 + g_RegCalls.clear();
1.31 +
1.32 gameconfs->CloseGameConfigFile(g_pGameConf);
1.33 }
1.34
2.1 --- a/extensions/sdktools/msvc8/sdktools.vcproj Sat Jun 16 15:40:22 2007 +0000
2.2 +++ b/extensions/sdktools/msvc8/sdktools.vcproj Sat Jun 16 18:03:05 2007 +0000
2.3 @@ -197,6 +197,10 @@
2.4 RelativePath="..\vdecoder.cpp"
2.5 >
2.6 </File>
2.7 + <File
2.8 + RelativePath="..\vnatives.cpp"
2.9 + >
2.10 + </File>
2.11 </Filter>
2.12 <Filter
2.13 Name="Header Files"
2.14 @@ -215,6 +219,10 @@
2.15 RelativePath="..\vdecoder.h"
2.16 >
2.17 </File>
2.18 + <File
2.19 + RelativePath="..\vnatives.h"
2.20 + >
2.21 + </File>
2.22 </Filter>
2.23 <Filter
2.24 Name="Resource Files"
3.1 --- a/extensions/sdktools/vcallbuilder.h Sat Jun 16 15:40:22 2007 +0000
3.2 +++ b/extensions/sdktools/vcallbuilder.h Sat Jun 16 18:03:05 2007 +0000
3.3 @@ -9,29 +9,6 @@
3.4 using namespace SourceHook;
3.5
3.6 /**
3.7 - * @brief Valve pre-defined calling types
3.8 - */
3.9 -enum ValveCallType
3.10 -{
3.11 - ValveCall_Static, /**< Static call */
3.12 - ValveCall_Entity, /**< Thiscall (CBaseEntity implicit first parameter) */
3.13 - ValveCall_Player, /**< Thiscall (CBasePlayer implicit first parameter) */
3.14 -};
3.15 -
3.16 -/**
3.17 - * @brief Valve parameter info
3.18 - */
3.19 -struct ValvePassInfo
3.20 -{
3.21 - ValveType vtype; /**< IN: Valve type */
3.22 - unsigned int decflags; /**< IN: VDECODE_FLAG_* */
3.23 - unsigned int encflags; /**< IN: VENCODE_FLAG_* */
3.24 - PassType type; /**< IN: Pass information */
3.25 - unsigned int flags; /**< IN: Pass flags */
3.26 - size_t offset; /**< OUT: stack offset */
3.27 -};
3.28 -
3.29 -/**
3.30 * @brief Info necessary to call a Valve function
3.31 */
3.32 struct ValveCall
4.1 --- a/extensions/sdktools/vcaller.cpp Sat Jun 16 15:40:22 2007 +0000
4.2 +++ b/extensions/sdktools/vcaller.cpp Sat Jun 16 18:03:05 2007 +0000
4.3 @@ -29,9 +29,10 @@
4.4 {
4.5 type = PassType_Basic;
4.6 if (vtype == Valve_POD
4.7 - || vtype == Valve_Float)
4.8 + || vtype == Valve_Float
4.9 + || vtype == Valve_Bool)
4.10 {
4.11 - flags = PASSFLAG_BYREF;
4.12 + flags = PASSFLAG_ASPOINTER;
4.13 } else {
4.14 flags = PASSFLAG_BYVAL;
4.15 }
4.16 @@ -169,7 +170,7 @@
4.17 ValvePassInfo *info = &s_params[s_numparams++];
4.18 info->vtype = (ValveType)params[1];
4.19 DecodePassMethod(info->vtype, (SDKPassMethod)params[2], info->type, info->flags);
4.20 - info->decflags = params[3];
4.21 + info->decflags = params[3] | VDECODE_FLAG_BYREF;
4.22 info->encflags = params[4];
4.23
4.24 return 1;
4.25 @@ -227,9 +228,7 @@
4.26 }
4.27 if (DecodeValveParam(pContext,
4.28 params[startparam],
4.29 - vc->thisinfo->vtype,
4.30 - vc->thisinfo->decflags | VDECODE_FLAG_BYREF,
4.31 - vc->thisinfo->type,
4.32 + vc->thisinfo,
4.33 ptr) == Data_Fail)
4.34 {
4.35 vc->stk_put(ptr);
4.36 @@ -264,9 +263,7 @@
4.37 }
4.38 if (DecodeValveParam(pContext,
4.39 params[p],
4.40 - vc->vparams[i].vtype,
4.41 - vc->vparams[i].decflags | VDECODE_FLAG_BYREF,
4.42 - vc->vparams[i].type,
4.43 + &(vc->vparams[i]),
4.44 ptr + vc->vparams[i].offset) == Data_Fail)
4.45 {
4.46 vc->stk_put(ptr);
4.47 @@ -290,8 +287,7 @@
4.48 {
4.49 if (EncodeValveParam(pContext,
4.50 startparam + i,
4.51 - vc->vparams[i].vtype,
4.52 - vc->vparams[i].type,
4.53 + &vc->vparams[i],
4.54 ptr + vc->vparams[i].offset) == Data_Fail)
4.55 {
4.56 vc->stk_put(ptr);
4.57 @@ -325,7 +321,7 @@
4.58 {
4.59 return pContext->ThrowNativeError("Expected argument (2) for Float[3] storage");
4.60 }
4.61 - if (EncodeValveParam(pContext, params[retparam], vc->retinfo->vtype, vc->retinfo->type, vc->retbuf)
4.62 + if (EncodeValveParam(pContext, params[retparam], vc->retinfo, vc->retbuf)
4.63 == Data_Fail)
4.64 {
4.65 return 0;
4.66 @@ -351,6 +347,13 @@
4.67 return -1;
4.68 }
4.69 return engine->IndexOfEdict(pEdict);
4.70 + } else if (vc->retinfo->vtype == Valve_Bool) {
4.71 + bool *addr = (bool *)vc->retbuf;
4.72 + if (vc->retinfo->flags & PASSFLAG_BYREF)
4.73 + {
4.74 + addr = *(bool **)addr;
4.75 + }
4.76 + return *addr ? 1 : 0;
4.77 } else {
4.78 cell_t *addr = (cell_t *)vc->retbuf;
4.79 if (vc->retinfo->flags & PASSFLAG_BYREF)
5.1 --- a/extensions/sdktools/vdecoder.cpp Sat Jun 16 15:40:22 2007 +0000
5.2 +++ b/extensions/sdktools/vdecoder.cpp Sat Jun 16 18:03:05 2007 +0000
5.3 @@ -68,12 +68,10 @@
5.4 }
5.5 case Valve_CBaseEntity:
5.6 case Valve_CBasePlayer:
5.7 - case Valve_POD:
5.8 case Valve_Edict:
5.9 case Valve_String:
5.10 {
5.11 - if (pass != PassType_Basic
5.12 - || (info->flags & PASSFLAG_BYREF))
5.13 + if (pass != PassType_Basic || (info->flags & PASSFLAG_BYREF))
5.14 {
5.15 return 0;
5.16 }
5.17 @@ -82,12 +80,44 @@
5.18 info->size = sizeof(void *);
5.19 return sizeof(void *);
5.20 }
5.21 + case Valve_POD:
5.22 + {
5.23 + info->type = PassType_Basic;
5.24 + info->flags = flags;
5.25 + if (flags & PASSFLAG_ASPOINTER)
5.26 + {
5.27 + info->size = sizeof(int *);
5.28 + return sizeof(int *) + sizeof(int);
5.29 + } else {
5.30 + info->size = sizeof(int);
5.31 + return sizeof(int);
5.32 + }
5.33 + }
5.34 + case Valve_Bool:
5.35 + {
5.36 + info->type = PassType_Basic;
5.37 + info->flags = flags;
5.38 + if (flags & PASSFLAG_ASPOINTER)
5.39 + {
5.40 + info->size = sizeof(bool *);
5.41 + return sizeof(bool *) + sizeof(bool);
5.42 + } else {
5.43 + info->size = sizeof(bool);
5.44 + return sizeof(bool);
5.45 + }
5.46 + }
5.47 case Valve_Float:
5.48 {
5.49 info->type = PassType_Float;
5.50 info->flags = flags;
5.51 - info->size = sizeof(float);
5.52 - return sizeof(float);
5.53 + if (flags & PASSFLAG_ASPOINTER)
5.54 + {
5.55 + info->size = sizeof(float *);
5.56 + return sizeof(float *) + sizeof(float);
5.57 + } else {
5.58 + info->size = sizeof(float);
5.59 + return sizeof(float);
5.60 + }
5.61 }
5.62 }
5.63
5.64 @@ -96,20 +126,19 @@
5.65
5.66 DataStatus EncodeValveParam(IPluginContext *pContext,
5.67 cell_t param,
5.68 - ValveType type,
5.69 - PassType pass,
5.70 + const ValvePassInfo *data,
5.71 const void *buffer)
5.72 {
5.73 - switch (type)
5.74 + switch (data->vtype)
5.75 {
5.76 case Valve_Vector:
5.77 {
5.78 Vector *v = NULL;
5.79
5.80 - if (pass == PassType_Basic)
5.81 + if (data->type == PassType_Basic)
5.82 {
5.83 v = *(Vector **)((unsigned char *)buffer + sizeof(Vector *));
5.84 - } else if (pass == PassType_Object) {
5.85 + } else if (data->type == PassType_Object) {
5.86 v = (Vector *)buffer;
5.87 }
5.88
5.89 @@ -126,10 +155,10 @@
5.90 {
5.91 QAngle *q = NULL;
5.92
5.93 - if (pass == PassType_Basic)
5.94 + if (data->type == PassType_Basic)
5.95 {
5.96 q = *(QAngle **)((unsigned char *)buffer + sizeof(QAngle *));
5.97 - } else if (pass == PassType_Object) {
5.98 + } else if (data->type == PassType_Object) {
5.99 q = (QAngle *)buffer;
5.100 }
5.101
5.102 @@ -180,10 +209,29 @@
5.103 cell_t *addr;
5.104 pContext->LocalToPhysAddr(param, &addr);
5.105
5.106 + if (data->flags & PASSFLAG_ASPOINTER)
5.107 + {
5.108 + buffer = (char *)buffer + sizeof(void *);
5.109 + }
5.110 +
5.111 *addr = *(cell_t *)buffer;
5.112
5.113 return Data_Okay;
5.114 }
5.115 + case Valve_Bool:
5.116 + {
5.117 + cell_t *addr;
5.118 + pContext->LocalToPhysAddr(param, &addr);
5.119 +
5.120 + if (data->flags & PASSFLAG_ASPOINTER)
5.121 + {
5.122 + buffer = (char *)buffer + sizeof(bool *);
5.123 + }
5.124 +
5.125 + *addr = *(bool *)buffer ? 1 : 0;
5.126 +
5.127 + return Data_Okay;
5.128 + }
5.129 }
5.130
5.131 return Data_Fail;
5.132 @@ -191,12 +239,10 @@
5.133
5.134 DataStatus DecodeValveParam(IPluginContext *pContext,
5.135 cell_t param,
5.136 - ValveType vtype,
5.137 - unsigned int vflags,
5.138 - PassType type,
5.139 + const ValvePassInfo *data,
5.140 void *buffer)
5.141 {
5.142 - switch (vtype)
5.143 + switch (data->vtype)
5.144 {
5.145 case Valve_Vector:
5.146 {
5.147 @@ -205,7 +251,7 @@
5.148 err = pContext->LocalToPhysAddr(param, &addr);
5.149
5.150 unsigned char *mem = (unsigned char *)buffer;
5.151 - if (type == PassType_Basic)
5.152 + if (data->type == PassType_Basic)
5.153 {
5.154 /* Store the object in the next N bytes, and store
5.155 * a pointer to that object right beforehand.
5.156 @@ -214,7 +260,7 @@
5.157
5.158 if (addr == pContext->GetNullRef(SP_NULL_VECTOR))
5.159 {
5.160 - if (vflags & VDECODE_FLAG_ALLOWNULL)
5.161 + if (data->decflags & VDECODE_FLAG_ALLOWNULL)
5.162 {
5.163 *realPtr = NULL;
5.164 return Data_Okay;
5.165 @@ -252,7 +298,7 @@
5.166 err = pContext->LocalToPhysAddr(param, &addr);
5.167
5.168 unsigned char *mem = (unsigned char *)buffer;
5.169 - if (type == PassType_Basic)
5.170 + if (data->type == PassType_Basic)
5.171 {
5.172 /* Store the object in the next N bytes, and store
5.173 * a pointer to that object right beforehand.
5.174 @@ -261,7 +307,7 @@
5.175
5.176 if (addr == pContext->GetNullRef(SP_NULL_VECTOR))
5.177 {
5.178 - if (!(vflags & VDECODE_FLAG_ALLOWNULL))
5.179 + if (!(data->decflags & VDECODE_FLAG_ALLOWNULL))
5.180 {
5.181 pContext->ThrowNativeError("NULL not allowed");
5.182 return Data_Fail;
5.183 @@ -295,7 +341,7 @@
5.184 case Valve_CBasePlayer:
5.185 {
5.186 edict_t *pEdict;
5.187 - if (vflags & VDECODE_FLAG_BYREF)
5.188 + if (data->decflags & VDECODE_FLAG_BYREF)
5.189 {
5.190 cell_t *addr;
5.191 pContext->LocalToPhysAddr(param, &addr);
5.192 @@ -304,7 +350,7 @@
5.193 if (param >= 1 && param <= playerhelpers->GetMaxClients())
5.194 {
5.195 IGamePlayer *player = playerhelpers->GetGamePlayer(param);
5.196 - if ((vflags & VDECODE_FLAG_ALLOWNOTINGAME)
5.197 + if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME)
5.198 && !player->IsConnected())
5.199 {
5.200 pContext->ThrowNativeError("Client %d is not connected", param);
5.201 @@ -315,7 +361,7 @@
5.202 }
5.203 pEdict = player->GetEdict();
5.204 } else if (param == -1) {
5.205 - if (vflags & VDECODE_FLAG_ALLOWNULL)
5.206 + if (data->decflags & VDECODE_FLAG_ALLOWNULL)
5.207 {
5.208 pEdict = NULL;
5.209 } else {
5.210 @@ -323,7 +369,7 @@
5.211 return Data_Fail;
5.212 }
5.213 } else if (param == 0) {
5.214 - if (vflags & VDECODE_FLAG_ALLOWWORLD)
5.215 + if (data->decflags & VDECODE_FLAG_ALLOWWORLD)
5.216 {
5.217 pEdict = engine->PEntityOfEntIndex(0);
5.218 } else {
5.219 @@ -361,7 +407,7 @@
5.220 case Valve_CBaseEntity:
5.221 {
5.222 edict_t *pEdict;
5.223 - if (vflags & VDECODE_FLAG_BYREF)
5.224 + if (data->decflags & VDECODE_FLAG_BYREF)
5.225 {
5.226 cell_t *addr;
5.227 pContext->LocalToPhysAddr(param, &addr);
5.228 @@ -370,7 +416,7 @@
5.229 if (param >= 1 && param <= playerhelpers->GetMaxClients())
5.230 {
5.231 IGamePlayer *player = playerhelpers->GetGamePlayer(param);
5.232 - if ((vflags & VDECODE_FLAG_ALLOWNOTINGAME)
5.233 + if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME)
5.234 && !player->IsConnected())
5.235 {
5.236 pContext->ThrowNativeError("Client %d is not connected", param);
5.237 @@ -381,7 +427,7 @@
5.238 }
5.239 pEdict = player->GetEdict();
5.240 } else if (param == -1) {
5.241 - if (vflags & VDECODE_FLAG_ALLOWNULL)
5.242 + if (data->decflags & VDECODE_FLAG_ALLOWNULL)
5.243 {
5.244 pEdict = NULL;
5.245 } else {
5.246 @@ -389,7 +435,7 @@
5.247 return Data_Fail;
5.248 }
5.249 } else if (param == 0) {
5.250 - if (vflags & VDECODE_FLAG_ALLOWWORLD)
5.251 + if (data->decflags & VDECODE_FLAG_ALLOWWORLD)
5.252 {
5.253 pEdict = engine->PEntityOfEntIndex(0);
5.254 } else {
5.255 @@ -431,7 +477,7 @@
5.256 case Valve_Edict:
5.257 {
5.258 edict_t *pEdict;
5.259 - if (vflags & VDECODE_FLAG_BYREF)
5.260 + if (data->decflags & VDECODE_FLAG_BYREF)
5.261 {
5.262 cell_t *addr;
5.263 pContext->LocalToPhysAddr(param, &addr);
5.264 @@ -440,7 +486,7 @@
5.265 if (param >= 1 && param <= playerhelpers->GetMaxClients())
5.266 {
5.267 IGamePlayer *player = playerhelpers->GetGamePlayer(param);
5.268 - if ((vflags & VDECODE_FLAG_ALLOWNOTINGAME)
5.269 + if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME)
5.270 && !player->IsConnected())
5.271 {
5.272 pContext->ThrowNativeError("Client %d is not connected", param);
5.273 @@ -451,7 +497,7 @@
5.274 }
5.275 pEdict = player->GetEdict();
5.276 } else if (param == -1) {
5.277 - if (vflags & VDECODE_FLAG_ALLOWNULL)
5.278 + if (data->decflags & VDECODE_FLAG_ALLOWNULL)
5.279 {
5.280 pEdict = NULL;
5.281 } else {
5.282 @@ -459,7 +505,7 @@
5.283 return Data_Fail;
5.284 }
5.285 } else if (param == 0) {
5.286 - if (vflags & VDECODE_FLAG_ALLOWWORLD)
5.287 + if (data->decflags & VDECODE_FLAG_ALLOWWORLD)
5.288 {
5.289 pEdict = engine->PEntityOfEntIndex(0);
5.290 } else {
5.291 @@ -483,15 +529,36 @@
5.292 case Valve_POD:
5.293 case Valve_Float:
5.294 {
5.295 - if (vflags & VDECODE_FLAG_BYREF)
5.296 + if (data->decflags & VDECODE_FLAG_BYREF)
5.297 {
5.298 cell_t *addr;
5.299 pContext->LocalToPhysAddr(param, &addr);
5.300 param = *addr;
5.301 }
5.302 + if (data->flags & PASSFLAG_ASPOINTER)
5.303 + {
5.304 + *(void **)buffer = (char *)buffer + sizeof(void *);
5.305 + buffer = *(void **)buffer;
5.306 + }
5.307 *(cell_t *)buffer = param;
5.308 return Data_Okay;
5.309 }
5.310 + case Valve_Bool:
5.311 + {
5.312 + if (data->decflags & VDECODE_FLAG_BYREF)
5.313 + {
5.314 + cell_t *addr;
5.315 + pContext->LocalToPhysAddr(param, &addr);
5.316 + param = *addr;
5.317 + }
5.318 + if (data->flags & PASSFLAG_ASPOINTER)
5.319 + {
5.320 + *(bool **)buffer = (bool *)((char *)buffer + sizeof(bool *));
5.321 + buffer = *(bool **)buffer;
5.322 + }
5.323 + *(bool *)buffer = param ? true : false;
5.324 + return Data_Okay;
5.325 + }
5.326 case Valve_String:
5.327 {
5.328 char *addr;
6.1 --- a/extensions/sdktools/vdecoder.h Sat Jun 16 15:40:22 2007 +0000
6.2 +++ b/extensions/sdktools/vdecoder.h Sat Jun 16 18:03:05 2007 +0000
6.3 @@ -21,6 +21,7 @@
6.4 Valve_Float, /**< Float */
6.5 Valve_Edict, /**< Edict */
6.6 Valve_String, /**< String */
6.7 + Valve_Bool, /**< Boolean */
6.8 };
6.9
6.10 enum DataStatus
6.11 @@ -36,6 +37,31 @@
6.12
6.13 #define VENCODE_FLAG_COPYBACK (1<<0) /**< Copy back data */
6.14
6.15 +#define PASSFLAG_ASPOINTER (1<<30) /**< Not an actual passflag, used internally */
6.16 +
6.17 +/**
6.18 + * @brief Valve pre-defined calling types
6.19 + */
6.20 +enum ValveCallType
6.21 +{
6.22 + ValveCall_Static, /**< Static call */
6.23 + ValveCall_Entity, /**< Thiscall (CBaseEntity implicit first parameter) */
6.24 + ValveCall_Player, /**< Thiscall (CBasePlayer implicit first parameter) */
6.25 +};
6.26 +
6.27 +/**
6.28 + * @brief Valve parameter info
6.29 + */
6.30 +struct ValvePassInfo
6.31 +{
6.32 + ValveType vtype; /**< IN: Valve type */
6.33 + unsigned int decflags; /**< IN: VDECODE_FLAG_* */
6.34 + unsigned int encflags; /**< IN: VENCODE_FLAG_* */
6.35 + PassType type; /**< IN: Pass information */
6.36 + unsigned int flags; /**< IN: Pass flags */
6.37 + size_t offset; /**< OUT: stack offset */
6.38 +};
6.39 +
6.40 /**
6.41 * @brief Converts a valve parameter to a bintools parameter.
6.42 *
6.43 @@ -59,16 +85,12 @@
6.44 *
6.45 * @param pContext Plugin context.
6.46 * @param param Parameter value from params array.
6.47 - * @param type Valve type.
6.48 - * @param pass Pass info from bin tools.
6.49 * @param buffer Buffer space in the virutal stack.
6.50 * @return True on success, false otherwise.
6.51 */
6.52 DataStatus DecodeValveParam(IPluginContext *pContext,
6.53 cell_t param,
6.54 - ValveType type,
6.55 - unsigned int vflags,
6.56 - PassType pass,
6.57 + const ValvePassInfo *vdata,
6.58 void *buffer);
6.59
6.60 /**
6.61 @@ -79,15 +101,12 @@
6.62 *
6.63 * @param pContext Plugin context.
6.64 * @param param Parameter value from params array.
6.65 - * @param type Valve type.
6.66 - * @param pass Pass info from bin tools.
6.67 * @param buffer Buffer space in the virutal stack.
6.68 * @return True on success, false otherwise.
6.69 */
6.70 DataStatus EncodeValveParam(IPluginContext *pContext,
6.71 cell_t param,
6.72 - ValveType type,
6.73 - PassType pass,
6.74 + const ValvePassInfo *vdata,
6.75 const void *buffer);
6.76
6.77 #endif //_INCLUDE_SOURCEMOD_VDECODER_H_
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/extensions/sdktools/vnatives.cpp Sat Jun 16 18:03:05 2007 +0000
7.3 @@ -0,0 +1,182 @@
7.4 +#include "extension.h"
7.5 +#include "vcallbuilder.h"
7.6 +#include "vnatives.h"
7.7 +
7.8 +List<ValveCall *> g_RegCalls;
7.9 +
7.10 +inline void InitPass(ValvePassInfo &info, ValveType vtype, PassType type, unsigned int flags)
7.11 +{
7.12 + info.decflags = 0;
7.13 + info.encflags = 0;
7.14 + info.flags = flags;
7.15 + info.type = type;
7.16 + info.vtype = vtype;
7.17 +}
7.18 +
7.19 +#define START_CALL() \
7.20 + unsigned char *vptr = pCall->stk_get();
7.21 +
7.22 +#define FINISH_CALL_SIMPLE(vret) \
7.23 + pCall->call->Execute(vptr, vret); \
7.24 + pCall->stk_put(vptr);
7.25 +
7.26 +#define ENCODE_VALVE_PARAM(num, which, vnum) \
7.27 + if (EncodeValveParam(pContext, \
7.28 + params[num], \
7.29 + &pCall->which[vnum], \
7.30 + vptr + pCall->which[vnum].offset) \
7.31 + == Data_Fail) \
7.32 + { \
7.33 + return 0; \
7.34 + }
7.35 +
7.36 +#define DECODE_VALVE_PARAM(num, which, vnum) \
7.37 + if (DecodeValveParam(pContext, \
7.38 + params[num], \
7.39 + &pCall->which[vnum], \
7.40 + vptr + pCall->which[vnum].offset) \
7.41 + == Data_Fail) \
7.42 + { \
7.43 + return 0; \
7.44 + }
7.45 +
7.46 +bool CreateBaseCall(const char *name,
7.47 + ValveCallType vcalltype,
7.48 + const ValvePassInfo *retinfo,
7.49 + const ValvePassInfo params[],
7.50 + unsigned int numParams,
7.51 + ValveCall **vaddr)
7.52 +{
7.53 + int offset;
7.54 + ValveCall *call;
7.55 + if (g_pGameConf->GetOffset(name, &offset))
7.56 + {
7.57 + call = CreateValveVCall(offset, vcalltype, retinfo, params, numParams);
7.58 + if (call)
7.59 + {
7.60 + g_RegCalls.push_back(call);
7.61 + }
7.62 + *vaddr = call;
7.63 + return true;
7.64 + } else {
7.65 + void *addr;
7.66 + if (g_pGameConf->GetMemSig(name, &addr))
7.67 + {
7.68 + call = CreateValveCall(addr, vcalltype, retinfo, params, numParams);
7.69 + if (call)
7.70 + {
7.71 + g_RegCalls.push_back(call);
7.72 + }
7.73 + *vaddr = call;
7.74 + return true;
7.75 + }
7.76 + }
7.77 + return false;
7.78 +}
7.79 +
7.80 +
7.81 +static cell_t RemovePlayerItem(IPluginContext *pContext, const cell_t *params)
7.82 +{
7.83 + static ValveCall *pCall = NULL;
7.84 + if (!pCall)
7.85 + {
7.86 + ValvePassInfo pass[2];
7.87 + InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, 0);
7.88 + InitPass(pass[1], Valve_Bool, PassType_Basic, 0);
7.89 + if (!CreateBaseCall("RemovePlayerItem", ValveCall_Player, &pass[1], &pass[0], 1, &pCall))
7.90 + {
7.91 + return pContext->ThrowNativeError("\"RemovePlayerItem\" not supported by this mod");
7.92 + } else if (!pCall) {
7.93 + return pContext->ThrowNativeError("\"RemovePlayerItem\" wrapper failed to initialized");
7.94 + }
7.95 + }
7.96 +
7.97 + bool ret;
7.98 + START_CALL();
7.99 + DECODE_VALVE_PARAM(1, thisinfo, 0);
7.100 + DECODE_VALVE_PARAM(2, vparams, 0);
7.101 + FINISH_CALL_SIMPLE(&ret);
7.102 + return ret ? 1 : 0;
7.103 +}
7.104 +
7.105 +static cell_t GiveNamedItem(IPluginContext *pContext, const cell_t *params)
7.106 +{
7.107 + static ValveCall *pCall = NULL;
7.108 + if (!pCall)
7.109 + {
7.110 + ValvePassInfo pass[3];
7.111 + InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
7.112 + InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
7.113 + InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
7.114 + if (!CreateBaseCall("GiveNamedItem", ValveCall_Player, &pass[2], pass, 2, &pCall))
7.115 + {
7.116 + return pContext->ThrowNativeError("\"GiveNamedItem\" not supported by this mod");
7.117 + } else if (!pCall) {
7.118 + return pContext->ThrowNativeError("\"GiveNamedItem\" wrapper failed to initialized");
7.119 + }
7.120 + }
7.121 +
7.122 + CBaseEntity *pEntity = NULL;
7.123 + START_CALL();
7.124 + DECODE_VALVE_PARAM(1, thisinfo, 0);
7.125 + DECODE_VALVE_PARAM(2, vparams, 0);
7.126 + DECODE_VALVE_PARAM(3, vparams, 1);
7.127 + FINISH_CALL_SIMPLE(&pEntity);
7.128 +
7.129 + if (pEntity == NULL)
7.130 + {
7.131 + return -1;
7.132 + }
7.133 +
7.134 + edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
7.135 + if (!pEdict)
7.136 + {
7.137 + return -1;
7.138 + }
7.139 +
7.140 + return engine->IndexOfEdict(pEdict);
7.141 +}
7.142 +
7.143 +static cell_t GetPlayerWeaponSlot(IPluginContext *pContext, const cell_t *params)
7.144 +{
7.145 + static ValveCall *pCall = NULL;
7.146 + if (!pCall)
7.147 + {
7.148 + ValvePassInfo pass[2];
7.149 + InitPass(pass[0], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
7.150 + InitPass(pass[1], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
7.151 + if (!CreateBaseCall("Weapon_GetSlot", ValveCall_Player, &pass[1], pass, 1, &pCall))
7.152 + {
7.153 + return pContext->ThrowNativeError("\"Weapon_GetSlot\" not supported by this mod");
7.154 + } else if (!pCall) {
7.155 + return pContext->ThrowNativeError("\"Weapon_GetSlot\" wrapper failed to initialized");
7.156 + }
7.157 + }
7.158 +
7.159 + CBaseEntity *pEntity;
7.160 + START_CALL();
7.161 + DECODE_VALVE_PARAM(1, thisinfo, 0);
7.162 + DECODE_VALVE_PARAM(2, vparams, 0);
7.163 + FINISH_CALL_SIMPLE(&pEntity);
7.164 +
7.165 + if (pEntity == NULL)
7.166 + {
7.167 + return -1;
7.168 + }
7.169 +
7.170 + edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
7.171 + if (!pEdict)
7.172 + {
7.173 + return -1;
7.174 + }
7.175 +
7.176 + return engine->IndexOfEdict(pEdict);
7.177 +}
7.178 +
7.179 +sp_nativeinfo_t g_Natives[] =
7.180 +{
7.181 + {"RemovePlayerItem", RemovePlayerItem},
7.182 + {"GivePlayerItem", GiveNamedItem},
7.183 + {"GetPlayerWeaponSlot", GetPlayerWeaponSlot},
7.184 + {NULL, NULL},
7.185 +};
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/extensions/sdktools/vnatives.h Sat Jun 16 18:03:05 2007 +0000
8.3 @@ -0,0 +1,9 @@
8.4 +#ifndef _INCLUDE_SDKTOOLS_VNATIVES_H_
8.5 +#define _INCLUDE_SDKTOOLS_VNATIVES_H_
8.6 +
8.7 +#include <sh_list.h>
8.8 +
8.9 +extern List<ValveCall *> g_RegCalls;
8.10 +extern sp_nativeinfo_t g_Natives[];
8.11 +
8.12 +#endif //_INCLUDE_SDKTOOLS_VNATIVES_H_
9.1 --- a/gamedata/sdktools.games.txt Sat Jun 16 15:40:22 2007 +0000
9.2 +++ b/gamedata/sdktools.games.txt Sat Jun 16 18:03:05 2007 +0000
9.3 @@ -14,6 +14,16 @@
9.4 "windows" "329"
9.5 "linux" "330"
9.6 }
9.7 + "RemovePlayerItem"
9.8 + {
9.9 + "windows" "226"
9.10 + "linux" "227"
9.11 + }
9.12 + "Weapon_GetSlot"
9.13 + {
9.14 + "windows" "224"
9.15 + "linux" "225"
9.16 + }
9.17 }
9.18 }
9.19 }
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/plugins/include/sdktools.inc Sat Jun 16 18:03:05 2007 +0000
10.3 @@ -0,0 +1,179 @@
10.4 +/**
10.5 + * vim: set ts=4 :
10.6 + * ===============================================================
10.7 + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
10.8 + * ===============================================================
10.9 + *
10.10 + * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
10.11 + * or modified under the Terms and Conditions of its License Agreement, which is found
10.12 + * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10.13 + * may change at any time. To view the latest information, see:
10.14 + * http://www.sourcemod.net/license.php
10.15 + *
10.16 + * Version: $Id$
10.17 + */
10.18 +
10.19 +#if defined _sdktools_included
10.20 + #endinput
10.21 +#endif
10.22 +#define _sdktools_included
10.23 +
10.24 +#include <core>
10.25 +#include <sdktools_functions>
10.26 +
10.27 +enum SDKCallType
10.28 +{
10.29 + SDKCall_Static, /**< Static call */
10.30 + SDKCall_Entity, /**< CBaseEntity call */
10.31 + SDKCall_Player, /**< CBasePlayer call */
10.32 +};
10.33 +
10.34 +enum SDKLibrary
10.35 +{
10.36 + SDKLibrary_Server, /**< server.dll/server_i486.so */
10.37 + SDKLibrary_Engine, /**< engine.dll/engine_*.so */
10.38 +};
10.39 +
10.40 +enum SDKFuncConfSource
10.41 +{
10.42 + SDKConf_Virtual = 0, /**< Read a virtual index from the Offsets section */
10.43 + SDKConf_Signature = 1, /**< Read a signature from the Signatures section */
10.44 +};
10.45 +
10.46 +enum SDKType
10.47 +{
10.48 + SDKType_CBaseEntity, /**< CBaseEntity (always as pointer) */
10.49 + SDKType_CBasePlayer, /**< CBasePlayer (always as pointer) */
10.50 + SDKType_Vector, /**< Vector (pointer, byval, or byref) */
10.51 + SDKType_QAngle, /**< QAngles (pointer, byval, or byref) */
10.52 + SDKType_PlainOldData, /**< Integer/generic data <=32bit (any) */
10.53 + SDKType_Float, /**< Float (any) */
10.54 + SDKType_Edict, /**< edict_t (always as pointer) */
10.55 + SDKType_String, /**< NULL-terminated string (always as pointer) */
10.56 +};
10.57 +
10.58 +enum SDKPassMethod
10.59 +{
10.60 + SDKPass_Pointer, /**< Pass as a pointer */
10.61 + SDKPass_Plain, /**< Pass as plain data */
10.62 + SDKPass_ByValue, /**< Pass an object by value */
10.63 + SDKPass_ByRef, /**< Pass an object by reference */
10.64 +};
10.65 +
10.66 +#define VDECODE_FLAG_ALLOWNULL (1<<0) /**< Allow NULL for pointers */
10.67 +#define VDECODE_FLAG_ALLOWNOTINGAME (1<<1) /**< Allow players not in game */
10.68 +#define VDECODE_FLAG_ALLOWWORLD (1<<2) /**< Allow World entity */
10.69 +#define VDECODE_FLAG_BYREF (1<<3) /**< Floats/ints by reference */
10.70 +
10.71 +#define VENCODE_FLAG_COPYBACK (1<<0) /**< Copy back data once done */
10.72 +
10.73 +/**
10.74 + * Starts the preparation of an SDK call.
10.75 + *
10.76 + * @param type Type of function call this will be.
10.77 + * @noreturn
10.78 + */
10.79 +native StartPrepSDKCall(SDKCallType:type);
10.80 +
10.81 +/**
10.82 + * Sets the virtual index of the SDK call if it is virtual.
10.83 + *
10.84 + * @param vtblidx Virtual table index.
10.85 + * @noreturn
10.86 + */
10.87 +native PrepSDKCall_SetVirtual(vtblidx);
10.88 +
10.89 +/**
10.90 + * Finds an address in a library and sets it as the address to use for the SDK call.
10.91 + *
10.92 + * @param lib Library to use.
10.93 + * @param signature Binary data to search for in the library. If it starts with '@',
10.94 + * the bytes parameter is ignored and the signature is interpreted
10.95 + * as a symbol lookup in the library.
10.96 + * @param bytes Number of bytes in the binary search string.
10.97 + * @return True on success, false if nothing was found.
10.98 + */
10.99 +native bool:PrepSDKCall_SetSignature(SDKLibrary:lib, const String:signature[], bytes);
10.100 +
10.101 +/**
10.102 + * Finds an address or virtual function index in a GameConfig file and sets it as
10.103 + * the calling information for the SDK call.
10.104 + *
10.105 + * @param gameconf GameConfig Handle, or INVALID_HANDLE to use sdktools.games.txt.
10.106 + * @param source Whether to look in Offsets or Signatures.
10.107 + * @param name Name of the property to find.
10.108 + * @return True on success, false if nothing was found.
10.109 + */
10.110 +native bool:PrepSDKCall_SetFromConf(Handle:gameconf, SDKFuncConfSource:source, const String:name[]);
10.111 +
10.112 +/**
10.113 + * Sets the return information of an SDK call. Do not call this if there is no return data.
10.114 + * This must be called if there is a return value (i.e. it is not necessarily safe to ignore
10.115 + * the data).
10.116 + *
10.117 + * @param type Data type to convert to/from.
10.118 + * @param pass How the data is passed in C++.
10.119 + * @param decflags Flags on decoding from the plugin to C++.
10.120 + * @param encflags Flags on encoding from C++ to the plugin.
10.121 + * @noreturn
10.122 + */
10.123 +native PrepSDKCall_SetReturnInfo(SDKType:type, SDKPassMethod:pass, decflags=0, encflags=0);
10.124 +
10.125 +/**
10.126 + * Adds a parameter to the calling convention. This should be called in normal ascending order.
10.127 + *
10.128 + * @param type Data type to convert to/from.
10.129 + * @param pass How the data is passed in C++.
10.130 + * @param decflags Flags on decoding from the plugin to C++.
10.131 + * @param encflags Flags on encoding from C++ to the plugin.
10.132 + * @noreturn
10.133 + */
10.134 +native PrepSDKCall_AddParameter(SDKType:type, SDKPassMethod:pass, decflags=0, encflags=0);
10.135 +
10.136 +/**
10.137 + * Finalizes an SDK call preparation and returns the resultant Handle.
10.138 + *
10.139 + * @return A new SDKCall Handle on success, or INVALID_HANDLE on failure.
10.140 + */
10.141 +native Handle:EndPrepSDKCall();
10.142 +
10.143 +/**
10.144 + * Calls an SDK function with the given parameters.
10.145 + *
10.146 + * If the call type is Entity or Player, the index MUST ALWAYS be the FIRST parameter passed.
10.147 + * If the return value is a Vector or QAngles, the SECOND parameter must be a Float[3].
10.148 + * If the return value is a string, the THIRD parameter must be a String buffer, and the
10.149 + * FOURTH parameter must be the maximum length.
10.150 + * All parameters must be passed after the above is followed. Failure to follow these
10.151 + * rules will result in crashes or wildly unexpected behavior!
10.152 + *
10.153 + * If the return value is a float or integer, the return value will be this value.
10.154 + * If the return value is a CBaseEntity, CBasePlayer, or edict, the return value will
10.155 + * always be the entity index, or -1 for NULL.
10.156 + *
10.157 + * @param call SDKCall Handle.
10.158 + * @param ... Call Parameters.
10.159 + * @return Simple return value, if any.
10.160 + * @error Invalid Handle or internal decoding error.
10.161 + */
10.162 +native any:SDKCall(Handle:call, any:...);
10.163 +
10.164 +
10.165 +/**
10.166 + * Do not edit below this line!
10.167 + */
10.168 +public Extension:__ext_sdktools =
10.169 +{
10.170 + name = "SDKTools",
10.171 + file = "sdktools.ext",
10.172 +#if defined AUTOLOAD_EXTENSIONS
10.173 + autoload = 1,
10.174 +#else
10.175 + autoload = 0,
10.176 +#endif
10.177 +#if defined REQUIRE_EXTENSIONS
10.178 + required = 1,
10.179 +#else
10.180 + required = 0,
10.181 +#endif
10.182 +};
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/plugins/include/sdktools_functions.inc Sat Jun 16 18:03:05 2007 +0000
11.3 @@ -0,0 +1,51 @@
11.4 +/**
11.5 + * vim: set ts=4 :
11.6 + * ===============================================================
11.7 + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
11.8 + * ===============================================================
11.9 + *
11.10 + * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
11.11 + * or modified under the Terms and Conditions of its License Agreement, which is found
11.12 + * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
11.13 + * may change at any time. To view the latest information, see:
11.14 + * http://www.sourcemod.net/license.php
11.15 + *
11.16 + * Version: $Id$
11.17 + */
11.18 +
11.19 +#if defined _sdktools_functions_included
11.20 + #endinput
11.21 +#endif
11.22 +#define _sdktools_functions_included
11.23 +
11.24 +/**
11.25 + * Removes a player's item.
11.26 + *
11.27 + * @param client Client index.
11.28 + * @param item CBaseCombatWeapon entity index.
11.29 + * @return True on success, false otherwise.
11.30 + * @error Invalid client or entity, lack of mod support, or client not in
11.31 + * game.
11.32 + */
11.33 +native bool:RemovePlayerItem(client, item);
11.34 +
11.35 +/**
11.36 + * Gives a named item to a player.
11.37 + *
11.38 + * @param client Client index.
11.39 + * @param item Item classname (such as weapon_ak47).
11.40 + * @param iSubType Unknown.
11.41 + * @return Entity index on success, or -1 on failure.
11.42 + * @error Invalid client or client not in game, or lack of mod support.
11.43 + */
11.44 +native GivePlayerItem(client, const String:item[], iSubType=0);
11.45 +
11.46 +/**
11.47 + * Returns the weapon in a player's slot.
11.48 + *
11.49 + * @param client Client index.
11.50 + * @param slot Slot index (mod specific).
11.51 + * @return Entity index on success, -1 if no weapon existed.
11.52 + * @error Invalid client or client notin game, or lack of mod support.
11.53 + */
11.54 +native GetPlayerWeaponSlot(client, slot);
11.55 \ No newline at end of file