3 * =============================================================================
4 * SourceMod Team Fortress 2 Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "extension.h"
35 #include "RegNatives.h"
38 // native TF2_Burn(client, target)
39 cell_t TF2_Burn(IPluginContext *pContext, const cell_t *params)
41 static ICallWrapper *pWrapper = NULL;
43 // CTFPlayerShared::Burn(CTFPlayer*)
46 REGISTER_NATIVE_ADDR("Burn",
48 pass[0].flags = PASSFLAG_BYVAL; \
49 pass[0].size = sizeof(CBaseEntity *); \
50 pass[0].type = PassType_Basic; \
51 pass[1].flags = PASSFLAG_BYVAL; \
52 pass[1].size = sizeof(CBaseEntity *); \
53 pass[1].type = PassType_Basic; \
54 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
58 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
60 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
64 if (!(pTarget = UTIL_GetCBaseEntity(params[2], true)))
66 return pContext->ThrowNativeError("Client index %d is not valid", params[2]);
69 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
71 unsigned char vstk[sizeof(void *) + sizeof(CBaseEntity *)];
72 unsigned char *vptr = vstk;
75 vptr += sizeof(void *);
76 *(CBaseEntity **)vptr = pTarget;
77 vptr += sizeof(CBaseEntity *);
78 *(CBaseEntity **)vptr = NULL;
80 pWrapper->Execute(vstk, NULL);
85 // native TF2_Invuln(client, bool:enabled)
86 cell_t TF2_Invuln(IPluginContext *pContext, const cell_t *params)
88 return pContext->ThrowNativeError("TF2_SetPlayerInvuln is no longer available");
91 cell_t TF2_Disguise(IPluginContext *pContext, const cell_t *params)
93 static ICallWrapper *pWrapper = NULL;
95 //CTFPlayerShared::Disguise(int, int)
98 REGISTER_NATIVE_ADDR("Disguise",
100 pass[0].flags = PASSFLAG_BYVAL; \
101 pass[0].size = sizeof(int); \
102 pass[0].type = PassType_Basic; \
103 pass[1].flags = PASSFLAG_BYVAL; \
104 pass[1].size = sizeof(int); \
105 pass[1].type = PassType_Basic; \
106 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
109 CBaseEntity *pEntity;
110 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
112 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
115 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
117 unsigned char vstk[sizeof(void *) + 2*sizeof(int)];
118 unsigned char *vptr = vstk;
121 *(void **)vptr = obj;
122 vptr += sizeof(void *);
123 *(int *)vptr = params[2];
125 *(int *)vptr = params[3];
127 pWrapper->Execute(vstk, NULL);
132 cell_t TF2_RemoveDisguise(IPluginContext *pContext, const cell_t *params)
134 static ICallWrapper *pWrapper = NULL;
136 //CTFPlayerShared::RemoveDisguise()
139 REGISTER_NATIVE_ADDR("RemoveDisguise",
140 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, NULL, 0))
143 CBaseEntity *pEntity;
144 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
146 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
149 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
151 unsigned char vstk[sizeof(void *)];
152 unsigned char *vptr = vstk;
155 *(void **)vptr = obj;
157 pWrapper->Execute(vstk, NULL);
162 cell_t TF2_Respawn(IPluginContext *pContext, const cell_t *params)
164 static ICallWrapper *pWrapper = NULL;
166 //CTFPlayer::ForceRespawn()
172 if (!g_pGameConf->GetOffset("ForceRespawn", &offset))
174 return pContext->ThrowNativeError("Failed to locate function");
177 pWrapper = g_pBinTools->CreateVCall(offset,
184 g_RegNatives.Register(pWrapper);
187 CBaseEntity *pEntity;
188 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
190 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
193 unsigned char vstk[sizeof(void *)];
194 unsigned char *vptr = vstk;
197 *(void **)vptr = (void *)pEntity;
199 pWrapper->Execute(vstk, NULL);
204 cell_t TF2_GetResourceEntity(IPluginContext *pContext, const cell_t *params)
206 return g_resourceEntity;
209 cell_t TF2_GetClass(IPluginContext *pContext, const cell_t *params)
212 pContext->LocalToString(params[1], &str);
214 return (cell_t)ClassnameToType(str);
217 sp_nativeinfo_t g_TFNatives[] =
219 {"TF2_IgnitePlayer", TF2_Burn},
220 {"TF2_SetPlayerInvuln", TF2_Invuln},
221 {"TF2_RespawnPlayer", TF2_Respawn},
222 {"TF2_DisguisePlayer", TF2_Disguise},
223 {"TF2_RemovePlayerDisguise", TF2_RemoveDisguise},
224 {"TF2_GetResourceEntity", TF2_GetResourceEntity},
225 {"TF2_GetClass", TF2_GetClass},