extensions/tf2/natives.cpp
changeset 2939 3d62874b9071
parent 2673 87d4d9f3cbc3
child 2943 1bbdb33fee53
     1.1 --- a/extensions/tf2/natives.cpp	Thu Mar 11 22:00:46 2010 -0500
     1.2 +++ b/extensions/tf2/natives.cpp	Thu Mar 18 11:35:05 2010 -0400
     1.3 @@ -159,6 +159,120 @@
     1.4  	return 1;
     1.5  }
     1.6  
     1.7 +cell_t TF2_AddCondition(IPluginContext *pContext, const cell_t *params)
     1.8 +{
     1.9 +	static ICallWrapper *pWrapper = NULL;
    1.10 +
    1.11 +	// CTFPlayerShared::AddCond(int, float)
    1.12 +	if (!pWrapper)
    1.13 +	{
    1.14 +		REGISTER_NATIVE_ADDR("AddCondition", 
    1.15 +			PassInfo pass[2]; \
    1.16 +			pass[0].flags = PASSFLAG_BYVAL; \
    1.17 +			pass[0].size = sizeof(int); \
    1.18 +			pass[0].type = PassType_Basic; \
    1.19 +			pass[1].flags = PASSFLAG_BYVAL; \
    1.20 +			pass[1].size = sizeof(float); \
    1.21 +			pass[1].type = PassType_Basic; \
    1.22 +			pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
    1.23 +	}
    1.24 +
    1.25 +	CBaseEntity *pEntity;
    1.26 +	if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
    1.27 +	{
    1.28 +		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
    1.29 +	}
    1.30 +
    1.31 +	void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
    1.32 +
    1.33 +	unsigned char vstk[sizeof(void *) + sizeof(int) + sizeof(float)];
    1.34 +	unsigned char *vptr = vstk;
    1.35 +
    1.36 +	*(void **)vptr = obj;
    1.37 +	vptr += sizeof(void *);
    1.38 +	*(int *)vptr = params[2];
    1.39 +	vptr += sizeof(int);
    1.40 +	*(float *)vptr = *(float *)&params[3];
    1.41 +
    1.42 +	pWrapper->Execute(vstk, NULL);
    1.43 +
    1.44 +	return 1;
    1.45 +}
    1.46 +
    1.47 +cell_t TF2_RemoveCondition(IPluginContext *pContext, const cell_t *params)
    1.48 +{
    1.49 +	static ICallWrapper *pWrapper = NULL;
    1.50 +
    1.51 +	// CTFPlayerShared::RemoveCond(int)
    1.52 +	if (!pWrapper)
    1.53 +	{
    1.54 +		REGISTER_NATIVE_ADDR("RemoveCondition", 
    1.55 +			PassInfo pass[1]; \
    1.56 +			pass[0].flags = PASSFLAG_BYVAL; \
    1.57 +			pass[0].size = sizeof(int); \
    1.58 +			pass[0].type = PassType_Basic; \
    1.59 +			pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 1))
    1.60 +	}
    1.61 +
    1.62 +	CBaseEntity *pEntity;
    1.63 +	if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
    1.64 +	{
    1.65 +		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
    1.66 +	}
    1.67 +
    1.68 +	void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
    1.69 +
    1.70 +	unsigned char vstk[sizeof(void *) + sizeof(int)];
    1.71 +	unsigned char *vptr = vstk;
    1.72 +
    1.73 +	*(void **)vptr = obj;
    1.74 +	vptr += sizeof(void *);
    1.75 +	*(int *)vptr = params[2];
    1.76 +
    1.77 +	pWrapper->Execute(vstk, NULL);
    1.78 +
    1.79 +	return 1;
    1.80 +}
    1.81 +
    1.82 +cell_t TF2_SetPowerplayEnabled(IPluginContext *pContext, const cell_t *params)
    1.83 +{
    1.84 +	static ICallWrapper *pWrapper = NULL;
    1.85 +
    1.86 +	// CTFPlayer::SetPowerPlayEnabled(bool)
    1.87 +	if (!pWrapper)
    1.88 +	{
    1.89 +		REGISTER_NATIVE_ADDR("SetPowerplayEnabled", 
    1.90 +			PassInfo pass[1]; \
    1.91 +			pass[0].flags = PASSFLAG_BYVAL; \
    1.92 +			pass[0].size = sizeof(bool); \
    1.93 +			pass[0].type = PassType_Basic; \
    1.94 +			pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 1))
    1.95 +	}
    1.96 +
    1.97 +	CBaseEntity *pEntity;
    1.98 +	if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
    1.99 +	{
   1.100 +		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
   1.101 +	}
   1.102 +
   1.103 +	bool bEnablePP = false;
   1.104 +	if (params[2] != 0)
   1.105 +	{
   1.106 +		bEnablePP = true;
   1.107 +	}
   1.108 +
   1.109 +	unsigned char vstk[sizeof(void *) + sizeof(bool)];
   1.110 +	unsigned char *vptr = vstk;
   1.111 +
   1.112 +	*(void **)vptr = (void *)pEntity;
   1.113 +	vptr += sizeof(void *);
   1.114 +	*(bool *)vptr = bEnablePP;
   1.115 +
   1.116 +	pWrapper->Execute(vstk, NULL);
   1.117 +
   1.118 +	return 1;
   1.119 +}
   1.120 +
   1.121  cell_t TF2_Respawn(IPluginContext *pContext, const cell_t *params)
   1.122  {
   1.123  	static ICallWrapper *pWrapper = NULL;
   1.124 @@ -201,6 +315,28 @@
   1.125  	return 1;
   1.126  }
   1.127  
   1.128 +cell_t TF2_Regenerate(IPluginContext *pContext, const cell_t *params)
   1.129 +{
   1.130 +	static ICallWrapper *pWrapper = NULL;
   1.131 +
   1.132 +	//CTFPlayer::Regenerate()
   1.133 +
   1.134 +	if (!pWrapper)
   1.135 +	{
   1.136 +		REGISTER_NATIVE_ADDR("Regenerate", 
   1.137 +			pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, NULL, 0));
   1.138 +	}
   1.139 +
   1.140 +	CBaseEntity *pEntity;
   1.141 +	if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
   1.142 +	{
   1.143 +		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
   1.144 +	}
   1.145 +	pWrapper->Execute(&pEntity, NULL);
   1.146 +
   1.147 +	return 1;
   1.148 +}
   1.149 +
   1.150  cell_t TF2_GetResourceEntity(IPluginContext *pContext, const cell_t *params)
   1.151  {
   1.152  	return g_resourceEntity;
   1.153 @@ -223,5 +359,9 @@
   1.154  	{"TF2_RemovePlayerDisguise",	TF2_RemoveDisguise},
   1.155  	{"TF2_GetResourceEntity",		TF2_GetResourceEntity},
   1.156  	{"TF2_GetClass",				TF2_GetClass},
   1.157 +	{"TF2_RegeneratePlayer",		TF2_Regenerate},
   1.158 +	{"TF2_AddCondition",			TF2_AddCondition},
   1.159 +	{"TF2_RemoveCondition",			TF2_RemoveCondition},
   1.160 +	{"TF2_SetPlayerPowerPlay",	TF2_SetPowerplayEnabled},
   1.161  	{NULL,							NULL}
   1.162  };