ds@1952: /**
ds@1952: * vim: set ts=4 :
ds@1952: * =============================================================================
pred@1963: * SourceMod Team Fortress 2 Extension
ds@1952: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
ds@1952: * =============================================================================
ds@1952: *
ds@1952: * This program is free software; you can redistribute it and/or modify it under
ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952: * Free Software Foundation.
ds@1952: *
ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1952: * details.
ds@1952: *
ds@1952: * You should have received a copy of the GNU General Public License along with
ds@1952: * this program. If not, see .
ds@1952: *
ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1952: * this exception to all derivative works. AlliedModders LLC defines further
ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952: * or .
ds@1952: *
ds@1952: * Version: $Id$
ds@1952: */
ds@1952:
ds@1952: #include "extension.h"
pred@1963: #include "util.h"
pred@1963: #include "time.h"
ds@1952: #include "RegNatives.h"
ds@1952:
ds@1952:
pred@1963: // native TF2_Burn(client, target)
ds@1952: cell_t TF2_Burn(IPluginContext *pContext, const cell_t *params)
ds@1952: {
ds@1952: static ICallWrapper *pWrapper = NULL;
ds@1952:
ds@1952: // CTFPlayerShared::Burn(CTFPlayer*)
ds@1952: if (!pWrapper)
ds@1952: {
ds@1952: REGISTER_NATIVE_ADDR("Burn",
ds@2097: PassInfo pass[2]; \
ds@1952: pass[0].flags = PASSFLAG_BYVAL; \
ds@1952: pass[0].size = sizeof(CBaseEntity *); \
ds@1952: pass[0].type = PassType_Basic; \
ds@2097: pass[1].flags = PASSFLAG_BYVAL; \
ds@2097: pass[1].size = sizeof(CBaseEntity *); \
ds@2097: pass[1].type = PassType_Basic; \
ds@2097: pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
ds@1952: }
ds@1952:
ds@1952: CBaseEntity *pEntity;
pred@1963: if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
ds@1952: {
ds@1952: return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
ds@1952: }
ds@1952:
pred@1963: CBaseEntity *pTarget;
pred@1963: if (!(pTarget = UTIL_GetCBaseEntity(params[2], true)))
pred@1963: {
pred@1963: return pContext->ThrowNativeError("Client index %d is not valid", params[2]);
pred@1963: }
pred@1963:
pred@1963: void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
ds@1952:
ds@1952: unsigned char vstk[sizeof(void *) + sizeof(CBaseEntity *)];
ds@1952: unsigned char *vptr = vstk;
ds@1952:
ds@1952: *(void **)vptr = obj;
ds@1952: vptr += sizeof(void *);
pred@1963: *(CBaseEntity **)vptr = pTarget;
ds@2097: vptr += sizeof(CBaseEntity *);
ds@2097: *(CBaseEntity **)vptr = NULL;
ds@1952:
ds@1952: pWrapper->Execute(vstk, NULL);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
pred@1963: // native TF2_Invuln(client, bool:enabled)
ds@1952: cell_t TF2_Invuln(IPluginContext *pContext, const cell_t *params)
ds@1952: {
pred@2039: return pContext->ThrowNativeError("TF2_SetPlayerInvuln is no longer available");
pred@1963: }
pred@1963:
pred@1963: cell_t TF2_Disguise(IPluginContext *pContext, const cell_t *params)
pred@1963: {
pred@1963: static ICallWrapper *pWrapper = NULL;
pred@1963:
pred@1963: //CTFPlayerShared::Disguise(int, int)
pred@1963: if (!pWrapper)
pred@1963: {
pred@1963: REGISTER_NATIVE_ADDR("Disguise",
pred@1963: PassInfo pass[2]; \
pred@1963: pass[0].flags = PASSFLAG_BYVAL; \
pred@1963: pass[0].size = sizeof(int); \
pred@1963: pass[0].type = PassType_Basic; \
pred@1963: pass[1].flags = PASSFLAG_BYVAL; \
pred@1963: pass[1].size = sizeof(int); \
pred@1963: pass[1].type = PassType_Basic; \
pred@1963: pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
pred@1963: }
pred@1963:
pred@1963: CBaseEntity *pEntity;
pred@1963: if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
pred@1963: {
pred@1963: return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
pred@1963: }
pred@1963:
pred@1963: void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
pred@1963:
pred@1963: unsigned char vstk[sizeof(void *) + 2*sizeof(int)];
pred@1963: unsigned char *vptr = vstk;
pred@1963:
pred@1963:
pred@1963: *(void **)vptr = obj;
pred@1963: vptr += sizeof(void *);
pred@1963: *(int *)vptr = params[2];
pred@1963: vptr += sizeof(int);
pred@1963: *(int *)vptr = params[3];
ds@1952:
ds@1952: pWrapper->Execute(vstk, NULL);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
pred@1963: cell_t TF2_RemoveDisguise(IPluginContext *pContext, const cell_t *params)
pred@1963: {
pred@1963: static ICallWrapper *pWrapper = NULL;
pred@1963:
pred@1963: //CTFPlayerShared::RemoveDisguise()
pred@1963: if (!pWrapper)
pred@1963: {
pred@1963: REGISTER_NATIVE_ADDR("RemoveDisguise",
pred@1963: pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, NULL, 0))
pred@1963: }
pred@1963:
pred@1963: CBaseEntity *pEntity;
pred@1963: if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
pred@1963: {
pred@1963: return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
pred@1963: }
pred@1963:
pred@1963: void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
pred@1963:
pred@1963: unsigned char vstk[sizeof(void *)];
pred@1963: unsigned char *vptr = vstk;
pred@1963:
pred@1963:
pred@1963: *(void **)vptr = obj;
pred@1963:
pred@1963: pWrapper->Execute(vstk, NULL);
pred@1963:
pred@1963: return 1;
pred@1963: }
pred@1963:
pred@1963: cell_t TF2_Respawn(IPluginContext *pContext, const cell_t *params)
pred@1963: {
pred@1963: static ICallWrapper *pWrapper = NULL;
pred@1963:
pred@1963: //CTFPlayer::ForceRespawn()
pred@1963:
pred@1963: if (!pWrapper)
pred@1963: {
pred@1963: int offset;
pred@1963:
pred@1963: if (!g_pGameConf->GetOffset("ForceRespawn", &offset))
pred@1963: {
pred@1963: return pContext->ThrowNativeError("Failed to locate function");
pred@1963: }
pred@1963:
pred@1963: pWrapper = g_pBinTools->CreateVCall(offset,
pred@1963: 0,
pred@1963: 0,
pred@1963: NULL,
pred@1963: NULL,
pred@1963: 0);
pred@1963:
pred@1963: g_RegNatives.Register(pWrapper);
pred@1963: }
pred@1963:
pred@1963: CBaseEntity *pEntity;
pred@1963: if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
pred@1963: {
pred@1963: return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
pred@1963: }
pred@1963:
pred@1963: unsigned char vstk[sizeof(void *)];
pred@1963: unsigned char *vptr = vstk;
pred@1963:
pred@1963:
pred@1963: *(void **)vptr = (void *)pEntity;
pred@1963:
pred@1963: pWrapper->Execute(vstk, NULL);
pred@1963:
pred@1963: return 1;
pred@1963: }
pred@1963:
pred@1963: cell_t TF2_GetResourceEntity(IPluginContext *pContext, const cell_t *params)
pred@1963: {
pred@1963: return g_resourceEntity;
pred@1963: }
pred@1963:
pred@1963: cell_t TF2_GetClass(IPluginContext *pContext, const cell_t *params)
pred@1963: {
pred@1963: char *str;
pred@1963: pContext->LocalToString(params[1], &str);
pred@1963:
pred@1963: return (cell_t)ClassnameToType(str);
pred@1963: }
ds@1952:
ds@1952: sp_nativeinfo_t g_TFNatives[] =
ds@1952: {
pred@1963: {"TF2_IgnitePlayer", TF2_Burn},
pred@1963: {"TF2_SetPlayerInvuln", TF2_Invuln},
pred@1963: {"TF2_RespawnPlayer", TF2_Respawn},
pred@1963: {"TF2_DisguisePlayer", TF2_Disguise},
pred@1963: {"TF2_RemovePlayerDisguise", TF2_RemoveDisguise},
pred@1963: {"TF2_GetResourceEntity", TF2_GetResourceEntity},
pred@1963: {"TF2_GetClass", TF2_GetClass},
ds@1952: {NULL, NULL}
ds@1952: };