extensions/tf2/natives.cpp
branchrefac-jit
changeset 2284 026da5437111
parent 2192 7602d7fb60d9
child 2288 15c77b21589a
     1.1 --- a/extensions/tf2/natives.cpp	Fri Jul 11 06:51:21 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,227 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod Team Fortress 2 Extension
     1.8 - * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - * 
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#include "extension.h"
    1.36 -#include "util.h"
    1.37 -#include "time.h"
    1.38 -#include "RegNatives.h"
    1.39 -
    1.40 -
    1.41 -// native TF2_Burn(client, target)
    1.42 -cell_t TF2_Burn(IPluginContext *pContext, const cell_t *params)
    1.43 -{
    1.44 -	static ICallWrapper *pWrapper = NULL;
    1.45 -
    1.46 -	// CTFPlayerShared::Burn(CTFPlayer*)
    1.47 -	if (!pWrapper)
    1.48 -	{
    1.49 -		REGISTER_NATIVE_ADDR("Burn", 
    1.50 -			PassInfo pass[2]; \
    1.51 -			pass[0].flags = PASSFLAG_BYVAL; \
    1.52 -			pass[0].size = sizeof(CBaseEntity *); \
    1.53 -			pass[0].type = PassType_Basic; \
    1.54 -			pass[1].flags = PASSFLAG_BYVAL; \
    1.55 -			pass[1].size = sizeof(CBaseEntity *); \
    1.56 -			pass[1].type = PassType_Basic; \
    1.57 -			pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
    1.58 -	}
    1.59 -
    1.60 -	CBaseEntity *pEntity;
    1.61 -	if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
    1.62 -	{
    1.63 -		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
    1.64 -	}
    1.65 -
    1.66 -	CBaseEntity *pTarget;
    1.67 -	if (!(pTarget = UTIL_GetCBaseEntity(params[2], true)))
    1.68 -	{
    1.69 -		return pContext->ThrowNativeError("Client index %d is not valid", params[2]);
    1.70 -	}
    1.71 -
    1.72 -	void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
    1.73 -
    1.74 -	unsigned char vstk[sizeof(void *) + sizeof(CBaseEntity *)];
    1.75 -	unsigned char *vptr = vstk;
    1.76 -
    1.77 -	*(void **)vptr = obj;
    1.78 -	vptr += sizeof(void *);
    1.79 -	*(CBaseEntity **)vptr = pTarget;
    1.80 -	vptr += sizeof(CBaseEntity *);
    1.81 -	*(CBaseEntity **)vptr = NULL;
    1.82 -
    1.83 -	pWrapper->Execute(vstk, NULL);
    1.84 -
    1.85 -	return 1;
    1.86 -}
    1.87 -
    1.88 -// native TF2_Invuln(client, bool:enabled)
    1.89 -cell_t TF2_Invuln(IPluginContext *pContext, const cell_t *params)
    1.90 -{
    1.91 -	return pContext->ThrowNativeError("TF2_SetPlayerInvuln is no longer available");
    1.92 -}
    1.93 -
    1.94 -cell_t TF2_Disguise(IPluginContext *pContext, const cell_t *params)
    1.95 -{
    1.96 -	static ICallWrapper *pWrapper = NULL;
    1.97 -
    1.98 -	//CTFPlayerShared::Disguise(int, int)
    1.99 -	if (!pWrapper)
   1.100 -	{
   1.101 -		REGISTER_NATIVE_ADDR("Disguise", 
   1.102 -			PassInfo pass[2]; \
   1.103 -			pass[0].flags = PASSFLAG_BYVAL; \
   1.104 -			pass[0].size = sizeof(int); \
   1.105 -			pass[0].type = PassType_Basic; \
   1.106 -			pass[1].flags = PASSFLAG_BYVAL; \
   1.107 -			pass[1].size = sizeof(int); \
   1.108 -			pass[1].type = PassType_Basic; \
   1.109 -			pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
   1.110 -	}
   1.111 -
   1.112 -	CBaseEntity *pEntity;
   1.113 -	if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
   1.114 -	{
   1.115 -		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
   1.116 -	}
   1.117 -
   1.118 -	void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
   1.119 -
   1.120 -	unsigned char vstk[sizeof(void *) + 2*sizeof(int)];
   1.121 -	unsigned char *vptr = vstk;
   1.122 -
   1.123 -
   1.124 -	*(void **)vptr = obj;
   1.125 -	vptr += sizeof(void *);
   1.126 -	*(int *)vptr = params[2];
   1.127 -	vptr += sizeof(int);
   1.128 -	*(int *)vptr = params[3];
   1.129 -
   1.130 -	pWrapper->Execute(vstk, NULL);
   1.131 -
   1.132 -	return 1;
   1.133 -}
   1.134 -
   1.135 -cell_t TF2_RemoveDisguise(IPluginContext *pContext, const cell_t *params)
   1.136 -{
   1.137 -	static ICallWrapper *pWrapper = NULL;
   1.138 -
   1.139 -	//CTFPlayerShared::RemoveDisguise()
   1.140 -	if (!pWrapper)
   1.141 -	{
   1.142 -		REGISTER_NATIVE_ADDR("RemoveDisguise", 
   1.143 -				pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, NULL, 0))
   1.144 -	}
   1.145 -
   1.146 -	CBaseEntity *pEntity;
   1.147 -	if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
   1.148 -	{
   1.149 -		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
   1.150 -	}
   1.151 -
   1.152 -	void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
   1.153 -
   1.154 -	unsigned char vstk[sizeof(void *)];
   1.155 -	unsigned char *vptr = vstk;
   1.156 -
   1.157 -
   1.158 -	*(void **)vptr = obj;
   1.159 -
   1.160 -	pWrapper->Execute(vstk, NULL);
   1.161 -
   1.162 -	return 1;
   1.163 -}
   1.164 -
   1.165 -cell_t TF2_Respawn(IPluginContext *pContext, const cell_t *params)
   1.166 -{
   1.167 -	static ICallWrapper *pWrapper = NULL;
   1.168 -
   1.169 -	//CTFPlayer::ForceRespawn()
   1.170 -
   1.171 -	if (!pWrapper)
   1.172 -	{
   1.173 -		int offset;
   1.174 -
   1.175 -		if (!g_pGameConf->GetOffset("ForceRespawn", &offset))
   1.176 -		{
   1.177 -			return pContext->ThrowNativeError("Failed to locate function");
   1.178 -		}
   1.179 -
   1.180 -		pWrapper = g_pBinTools->CreateVCall(offset,
   1.181 -											0,
   1.182 -											0,
   1.183 -											NULL,
   1.184 -											NULL,
   1.185 -											0);
   1.186 -
   1.187 -		g_RegNatives.Register(pWrapper);
   1.188 -	}
   1.189 -
   1.190 -	CBaseEntity *pEntity;
   1.191 -	if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
   1.192 -	{
   1.193 -		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
   1.194 -	}
   1.195 -
   1.196 -	unsigned char vstk[sizeof(void *)];
   1.197 -	unsigned char *vptr = vstk;
   1.198 -
   1.199 -
   1.200 -	*(void **)vptr = (void *)pEntity;
   1.201 -
   1.202 -	pWrapper->Execute(vstk, NULL);
   1.203 -
   1.204 -	return 1;
   1.205 -}
   1.206 -
   1.207 -cell_t TF2_GetResourceEntity(IPluginContext *pContext, const cell_t *params)
   1.208 -{
   1.209 -	return g_resourceEntity;
   1.210 -}
   1.211 -
   1.212 -cell_t TF2_GetClass(IPluginContext *pContext, const cell_t *params)
   1.213 -{
   1.214 -	char *str;
   1.215 -	pContext->LocalToString(params[1], &str);
   1.216 -
   1.217 -	return (cell_t)ClassnameToType(str);
   1.218 -}
   1.219 -
   1.220 -sp_nativeinfo_t g_TFNatives[] = 
   1.221 -{
   1.222 -	{"TF2_IgnitePlayer",			TF2_Burn},
   1.223 -	{"TF2_SetPlayerInvuln",			TF2_Invuln},
   1.224 -	{"TF2_RespawnPlayer",			TF2_Respawn},
   1.225 -	{"TF2_DisguisePlayer",			TF2_Disguise},
   1.226 -	{"TF2_RemovePlayerDisguise",	TF2_RemoveDisguise},
   1.227 -	{"TF2_GetResourceEntity",		TF2_GetResourceEntity},
   1.228 -	{"TF2_GetClass",				TF2_GetClass},
   1.229 -	{NULL,							NULL}
   1.230 -};