1.1 --- a/extensions/tf2/natives.cpp Thu Jan 10 22:01:36 2008 +0000
1.2 +++ b/extensions/tf2/natives.cpp Thu Jan 17 00:31:58 2008 +0000
1.3 @@ -30,6 +30,16 @@
1.4 */
1.5
1.6 #include "extension.h"
1.7 +#include "RegNatives.h"
1.8 +
1.9 +#define REGISTER_NATIVE_ADDR(name, code) \
1.10 + void *addr; \
1.11 + if (!g_pGameConf->GetMemSig(name, &addr)) \
1.12 + { \
1.13 + return pContext->ThrowNativeError("Failed to locate function"); \
1.14 + } \
1.15 + code; \
1.16 + g_RegNatives.Register(pWrapper);
1.17
1.18 inline CBaseEntity *GetCBaseEntity(int num, bool onlyPlayers)
1.19 {
1.20 @@ -61,7 +71,89 @@
1.21 return pUnk->GetBaseEntity();
1.22 }
1.23
1.24 +
1.25 +// native TF2_Burn(client)
1.26 +cell_t TF2_Burn(IPluginContext *pContext, const cell_t *params)
1.27 +{
1.28 + static ICallWrapper *pWrapper = NULL;
1.29 +
1.30 + // CTFPlayerShared::Burn(CTFPlayer*)
1.31 + if (!pWrapper)
1.32 + {
1.33 + REGISTER_NATIVE_ADDR("Burn",
1.34 + PassInfo pass[1]; \
1.35 + pass[0].flags = PASSFLAG_BYVAL; \
1.36 + pass[0].size = sizeof(CBaseEntity *); \
1.37 + pass[0].type = PassType_Basic; \
1.38 + pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 1))
1.39 + }
1.40 +
1.41 + CBaseEntity *pEntity;
1.42 + if (!(pEntity=GetCBaseEntity(params[1], true)))
1.43 + {
1.44 + return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
1.45 + }
1.46 +
1.47 + void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->GetOffset());
1.48 +
1.49 + unsigned char vstk[sizeof(void *) + sizeof(CBaseEntity *)];
1.50 + unsigned char *vptr = vstk;
1.51 +
1.52 + *(void **)vptr = obj;
1.53 + vptr += sizeof(void *);
1.54 + *(CBaseEntity **)vptr = pEntity;
1.55 +
1.56 + pWrapper->Execute(vstk, NULL);
1.57 +
1.58 + return 1;
1.59 +}
1.60 +
1.61 +// native TF2_Invuln(client, bool:something, bool:anothersomething)
1.62 +cell_t TF2_Invuln(IPluginContext *pContext, const cell_t *params)
1.63 +{
1.64 + static ICallWrapper *pWrapper = NULL;
1.65 +
1.66 + //CTFPlayerShared::SetInvulnerable(bool, bool)
1.67 + if (!pWrapper)
1.68 + {
1.69 + REGISTER_NATIVE_ADDR("Invuln",
1.70 + PassInfo pass[2]; \
1.71 + pass[0].flags = PASSFLAG_BYVAL; \
1.72 + pass[0].size = sizeof(bool); \
1.73 + pass[0].type = PassType_Basic; \
1.74 + pass[1].flags = PASSFLAG_BYVAL; \
1.75 + pass[1].size = sizeof(bool); \
1.76 + pass[1].type = PassType_Basic; \
1.77 + pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
1.78 + }
1.79 +
1.80 + CBaseEntity *pEntity;
1.81 + if (!(pEntity=GetCBaseEntity(params[1], true)))
1.82 + {
1.83 + return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
1.84 + }
1.85 +
1.86 + void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->GetOffset());
1.87 +
1.88 + unsigned char vstk[sizeof(void *) + 2*sizeof(bool)];
1.89 + unsigned char *vptr = vstk;
1.90 +
1.91 +
1.92 + *(void **)vptr = obj;
1.93 + vptr += sizeof(bool);
1.94 + *(bool *)vptr = !!params[2];
1.95 + vptr += sizeof(bool);
1.96 + *(bool *)vptr = !!params[3];
1.97 +
1.98 + pWrapper->Execute(vstk, NULL);
1.99 +
1.100 + return 1;
1.101 +}
1.102 +
1.103 +
1.104 sp_nativeinfo_t g_TFNatives[] =
1.105 {
1.106 + {"TF2_Burn", TF2_Burn},
1.107 + {"TF2_Invuln", TF2_Invuln},
1.108 {NULL, NULL}
1.109 };