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*, CTFWeaponBase*)
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 *) + 2*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_AddCondition(IPluginContext *pContext, const cell_t *params)
164 static ICallWrapper *pWrapper = NULL;
166 // CTFPlayerShared::AddCond(int, float)
169 REGISTER_NATIVE_ADDR("AddCondition",
171 pass[0].flags = PASSFLAG_BYVAL; \
172 pass[0].size = sizeof(int); \
173 pass[0].type = PassType_Basic; \
174 pass[1].flags = PASSFLAG_BYVAL; \
175 pass[1].size = sizeof(float); \
176 pass[1].type = PassType_Basic; \
177 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
180 CBaseEntity *pEntity;
181 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
183 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
186 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
188 unsigned char vstk[sizeof(void *) + sizeof(int) + sizeof(float)];
189 unsigned char *vptr = vstk;
191 *(void **)vptr = obj;
192 vptr += sizeof(void *);
193 *(int *)vptr = params[2];
195 *(float *)vptr = *(float *)¶ms[3];
197 pWrapper->Execute(vstk, NULL);
202 cell_t TF2_RemoveCondition(IPluginContext *pContext, const cell_t *params)
204 static ICallWrapper *pWrapper = NULL;
206 // CTFPlayerShared::RemoveCond(int)
209 REGISTER_NATIVE_ADDR("RemoveCondition",
211 pass[0].flags = PASSFLAG_BYVAL; \
212 pass[0].size = sizeof(int); \
213 pass[0].type = PassType_Basic; \
214 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 1))
217 CBaseEntity *pEntity;
218 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
220 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
223 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
225 unsigned char vstk[sizeof(void *) + sizeof(int)];
226 unsigned char *vptr = vstk;
228 *(void **)vptr = obj;
229 vptr += sizeof(void *);
230 *(int *)vptr = params[2];
232 pWrapper->Execute(vstk, NULL);
237 cell_t TF2_StunPlayer(IPluginContext *pContext, const cell_t *params)
239 static ICallWrapper *pWrapper = NULL;
241 // CTFPlayerShared::StunPlayer(float, float, int, CTFPlayer *)
244 REGISTER_NATIVE_ADDR("StunPlayer",
246 pass[0].flags = PASSFLAG_BYVAL; \
247 pass[0].size = sizeof(float); \
248 pass[0].type = PassType_Basic; \
249 pass[1].flags = PASSFLAG_BYVAL; \
250 pass[1].size = sizeof(float); \
251 pass[1].type = PassType_Basic; \
252 pass[2].flags = PASSFLAG_BYVAL; \
253 pass[2].size = sizeof(int); \
254 pass[2].type = PassType_Basic; \
255 pass[3].flags = PASSFLAG_BYVAL; \
256 pass[3].size = sizeof(CBaseEntity *); \
257 pass[3].type = PassType_Basic; \
258 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 4))
261 CBaseEntity *pEntity;
262 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
264 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
267 bool bByPlayer = (params[5] != 0);
268 CBaseEntity *pAttacker = NULL;
269 if (bByPlayer && !(pAttacker = UTIL_GetCBaseEntity(params[5], true)))
271 return pContext->ThrowNativeError("Attacker index %d is not valid", params[5]);
274 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
276 unsigned char vstk[sizeof(void *) + 2*sizeof(float) + sizeof(int) + sizeof(CBaseEntity *)];
277 unsigned char *vptr = vstk;
279 *(void **)vptr = obj;
280 vptr += sizeof(void *);
281 *(float *)vptr = sp_ctof(params[2]);
282 vptr += sizeof(float);
283 *(float *)vptr = sp_ctof(params[3]);
284 vptr += sizeof(float);
285 *(int *)vptr = params[4];
287 *(CBaseEntity **)vptr = pAttacker;
289 pWrapper->Execute(vstk, NULL);
294 cell_t TF2_SetPowerplayEnabled(IPluginContext *pContext, const cell_t *params)
296 static ICallWrapper *pWrapper = NULL;
298 // CTFPlayer::SetPowerPlayEnabled(bool)
301 REGISTER_NATIVE_ADDR("SetPowerplayEnabled",
303 pass[0].flags = PASSFLAG_BYVAL; \
304 pass[0].size = sizeof(bool); \
305 pass[0].type = PassType_Basic; \
306 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 1))
309 CBaseEntity *pEntity;
310 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
312 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
315 bool bEnablePP = false;
321 unsigned char vstk[sizeof(void *) + sizeof(bool)];
322 unsigned char *vptr = vstk;
324 *(void **)vptr = (void *)pEntity;
325 vptr += sizeof(void *);
326 *(bool *)vptr = bEnablePP;
328 pWrapper->Execute(vstk, NULL);
333 cell_t TF2_Respawn(IPluginContext *pContext, const cell_t *params)
335 static ICallWrapper *pWrapper = NULL;
337 //CTFPlayer::ForceRespawn()
343 if (!g_pGameConf->GetOffset("ForceRespawn", &offset))
345 return pContext->ThrowNativeError("Failed to locate function");
348 pWrapper = g_pBinTools->CreateVCall(offset,
355 g_RegNatives.Register(pWrapper);
358 CBaseEntity *pEntity;
359 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
361 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
364 unsigned char vstk[sizeof(void *)];
365 unsigned char *vptr = vstk;
368 *(void **)vptr = (void *)pEntity;
370 pWrapper->Execute(vstk, NULL);
375 cell_t TF2_Regenerate(IPluginContext *pContext, const cell_t *params)
377 static ICallWrapper *pWrapper = NULL;
379 //CTFPlayer::Regenerate()
383 REGISTER_NATIVE_ADDR("Regenerate",
384 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, NULL, 0));
387 CBaseEntity *pEntity;
388 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
390 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
392 pWrapper->Execute(&pEntity, NULL);
397 cell_t TF2_GetResourceEntity(IPluginContext *pContext, const cell_t *params)
399 return g_resourceEntity;
402 cell_t TF2_GetClass(IPluginContext *pContext, const cell_t *params)
405 pContext->LocalToString(params[1], &str);
407 return (cell_t)ClassnameToType(str);
410 sp_nativeinfo_t g_TFNatives[] =
412 {"TF2_IgnitePlayer", TF2_Burn},
413 {"TF2_SetPlayerInvuln", TF2_Invuln},
414 {"TF2_RespawnPlayer", TF2_Respawn},
415 {"TF2_DisguisePlayer", TF2_Disguise},
416 {"TF2_RemovePlayerDisguise", TF2_RemoveDisguise},
417 {"TF2_GetResourceEntity", TF2_GetResourceEntity},
418 {"TF2_GetClass", TF2_GetClass},
419 {"TF2_RegeneratePlayer", TF2_Regenerate},
420 {"TF2_AddCondition", TF2_AddCondition},
421 {"TF2_RemoveCondition", TF2_RemoveCondition},
422 {"TF2_SetPlayerPowerPlay", TF2_SetPowerplayEnabled},
423 {"TF2_StunPlayer", TF2_StunPlayer},