Update CS:GO team score gamedata.
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"
37 // native TF2_MakeBleed(client, attacker, Float:duration)
38 cell_t TF2_MakeBleed(IPluginContext *pContext, const cell_t *params)
40 static ICallWrapper *pWrapper = NULL;
42 // CTFPlayerShared::MakeBleed(CTFPlayer*, CTFWeaponBase*, float, int=4)
45 REGISTER_NATIVE_ADDR("MakeBleed",
47 pass[0].flags = PASSFLAG_BYVAL; \
48 pass[0].size = sizeof(CBaseEntity *); \
49 pass[0].type = PassType_Basic; \
50 pass[1].flags = PASSFLAG_BYVAL; \
51 pass[1].size = sizeof(CBaseEntity *); \
52 pass[1].type = PassType_Basic; \
53 pass[2].flags = PASSFLAG_BYVAL; \
54 pass[2].size = sizeof(float); \
55 pass[2].type = PassType_Basic; \
56 pass[3].flags = PASSFLAG_BYVAL; \
57 pass[3].size = sizeof(int); \
58 pass[3].type = PassType_Basic; \
59 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 4))
63 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
65 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
68 CBaseEntity *pAttacker;
69 if (!(pAttacker = UTIL_GetCBaseEntity(params[2], true)))
71 return pContext->ThrowNativeError("Client index %d is not valid", params[2]);
74 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
76 unsigned char vstk[sizeof(void *) + 2*sizeof(CBaseEntity *) + sizeof(float)];
77 unsigned char *vptr = vstk;
80 vptr += sizeof(void *);
81 *(CBaseEntity **)vptr = pAttacker;
82 vptr += sizeof(CBaseEntity *);
83 *(CBaseEntity **)vptr = NULL;
84 vptr += sizeof(CBaseEntity *);
85 *(float *)vptr = sp_ctof(params[3]);
86 vptr += sizeof(float);
89 pWrapper->Execute(vstk, NULL);
94 // native TF2_Burn(client, target)
95 cell_t TF2_Burn(IPluginContext *pContext, const cell_t *params)
97 static ICallWrapper *pWrapper = NULL;
99 // CTFPlayerShared::Burn(CTFPlayer*, CTFWeaponBase*)
102 REGISTER_NATIVE_ADDR("Burn",
104 pass[0].flags = PASSFLAG_BYVAL; \
105 pass[0].size = sizeof(CBaseEntity *); \
106 pass[0].type = PassType_Basic; \
107 pass[1].flags = PASSFLAG_BYVAL; \
108 pass[1].size = sizeof(CBaseEntity *); \
109 pass[1].type = PassType_Basic; \
110 pass[2].flags = PASSFLAG_BYVAL; \
111 pass[2].size = sizeof(float); \
112 pass[2].type = PassType_Basic; \
113 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 3))
116 CBaseEntity *pEntity;
117 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
119 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
122 CBaseEntity *pTarget;
123 if (!(pTarget = UTIL_GetCBaseEntity(params[2], true)))
125 return pContext->ThrowNativeError("Client index %d is not valid", params[2]);
128 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
130 unsigned char vstk[sizeof(void *) + 2*sizeof(CBaseEntity *)];
131 unsigned char *vptr = vstk;
133 *(void **)vptr = obj;
134 vptr += sizeof(void *);
135 *(CBaseEntity **)vptr = pTarget;
136 vptr += sizeof(CBaseEntity *);
137 *(CBaseEntity **)vptr = NULL;
138 vptr += sizeof(CBaseEntity *);
139 *(float *)vptr = -1.0f;
141 pWrapper->Execute(vstk, NULL);
146 // native TF2_Invuln(client, bool:enabled)
147 cell_t TF2_Invuln(IPluginContext *pContext, const cell_t *params)
149 return pContext->ThrowNativeError("TF2_SetPlayerInvuln is no longer available");
152 cell_t TF2_Disguise(IPluginContext *pContext, const cell_t *params)
154 static ICallWrapper *pWrapper = NULL;
156 //CTFPlayerShared::Disguise(int, int, CTFPlayer *)
159 REGISTER_NATIVE_ADDR("Disguise",
161 pass[0].flags = PASSFLAG_BYVAL; \
162 pass[0].size = sizeof(int); \
163 pass[0].type = PassType_Basic; \
164 pass[1].flags = PASSFLAG_BYVAL; \
165 pass[1].size = sizeof(int); \
166 pass[1].type = PassType_Basic; \
167 pass[2].flags = PASSFLAG_BYVAL; \
168 pass[2].size = sizeof(CBaseEntity *); \
169 pass[2].type = PassType_Basic; \
170 pass[3].flags = PASSFLAG_BYVAL; \
171 pass[3].size = sizeof(bool); \
172 pass[3].type = PassType_Basic; \
173 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 4))
176 CBaseEntity *pEntity;
177 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
179 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
182 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
184 CBaseEntity *pTarget = NULL;
185 // Compatibility fix for the newly-added target parameter
186 if (params[0] >= 4 && params[4] > 0 && !(pTarget = UTIL_GetCBaseEntity(params[4], true)))
188 return pContext->ThrowNativeError("Target client index %d is not valid", params[4]);
191 unsigned char vstk[sizeof(void *) + 2*sizeof(int) + sizeof(bool)];
192 unsigned char *vptr = vstk;
195 *(void **)vptr = obj;
196 vptr += sizeof(void *);
197 *(int *)vptr = params[2];
199 *(int *)vptr = params[3];
201 *(CBaseEntity **)vptr = pTarget;
202 vptr += sizeof(CBaseEntity *);
203 *(bool *)vptr = true;
205 pWrapper->Execute(vstk, NULL);
210 cell_t TF2_RemoveDisguise(IPluginContext *pContext, const cell_t *params)
212 static ICallWrapper *pWrapper = NULL;
214 //CTFPlayerShared::RemoveDisguise()
217 REGISTER_NATIVE_ADDR("RemoveDisguise",
218 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, NULL, 0))
221 CBaseEntity *pEntity;
222 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
224 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
227 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
229 unsigned char vstk[sizeof(void *)];
230 unsigned char *vptr = vstk;
233 *(void **)vptr = obj;
235 pWrapper->Execute(vstk, NULL);
240 cell_t TF2_AddCondition(IPluginContext *pContext, const cell_t *params)
242 static ICallWrapper *pWrapper = NULL;
244 // CTFPlayerShared::AddCond(int, float, CBaseEntity *)
247 REGISTER_NATIVE_ADDR("AddCondition",
249 pass[0].flags = PASSFLAG_BYVAL; \
250 pass[0].size = sizeof(int); \
251 pass[0].type = PassType_Basic; \
252 pass[1].flags = PASSFLAG_BYVAL; \
253 pass[1].size = sizeof(float); \
254 pass[1].type = PassType_Basic; \
255 pass[2].flags = PASSFLAG_BYVAL; \
256 pass[2].size = sizeof(CBaseEntity *); \
257 pass[2].type = PassType_Basic; \
258 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 3))
261 CBaseEntity *pEntity;
262 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
264 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
267 CBaseEntity *pInflictor = NULL;
268 // Compatibility fix for the new inflictor parameter; TF2 seems to only use player entities in it
269 if (params[0] >= 4 && params[4] > 0 && !(pInflictor = UTIL_GetCBaseEntity(params[4], true)))
271 return pContext->ThrowNativeError("Inflictor index %d is not valid", params[4]);
274 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
276 unsigned char vstk[sizeof(void *) + sizeof(int) + sizeof(float) + sizeof(CBaseEntity *)];
277 unsigned char *vptr = vstk;
279 *(void **)vptr = obj;
280 vptr += sizeof(void *);
281 *(int *)vptr = params[2];
283 *(float *)vptr = *(float *)¶ms[3];
284 vptr += sizeof(float);
285 *(CBaseEntity **)vptr = pInflictor;
287 pWrapper->Execute(vstk, NULL);
292 cell_t TF2_RemoveCondition(IPluginContext *pContext, const cell_t *params)
294 static ICallWrapper *pWrapper = NULL;
296 // CTFPlayerShared::RemoveCond(int, bool)
299 REGISTER_NATIVE_ADDR("RemoveCondition",
301 pass[0].flags = PASSFLAG_BYVAL; \
302 pass[0].size = sizeof(int); \
303 pass[0].type = PassType_Basic; \
304 pass[1].flags = PASSFLAG_BYVAL; \
305 pass[1].size = sizeof(bool); \
306 pass[1].type = PassType_Basic; \
307 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
310 CBaseEntity *pEntity;
311 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
313 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
316 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
318 unsigned char vstk[sizeof(void *) + sizeof(int) + sizeof(bool)];
319 unsigned char *vptr = vstk;
321 *(void **)vptr = obj;
322 vptr += sizeof(void *);
323 *(int *)vptr = params[2];
325 *(bool *)vptr = true;
327 pWrapper->Execute(vstk, NULL);
332 cell_t TF2_StunPlayer(IPluginContext *pContext, const cell_t *params)
334 static ICallWrapper *pWrapper = NULL;
336 // CTFPlayerShared::StunPlayer(float, float, int, CTFPlayer *)
339 REGISTER_NATIVE_ADDR("StunPlayer",
341 pass[0].flags = PASSFLAG_BYVAL; \
342 pass[0].size = sizeof(float); \
343 pass[0].type = PassType_Basic; \
344 pass[1].flags = PASSFLAG_BYVAL; \
345 pass[1].size = sizeof(float); \
346 pass[1].type = PassType_Basic; \
347 pass[2].flags = PASSFLAG_BYVAL; \
348 pass[2].size = sizeof(int); \
349 pass[2].type = PassType_Basic; \
350 pass[3].flags = PASSFLAG_BYVAL; \
351 pass[3].size = sizeof(CBaseEntity *); \
352 pass[3].type = PassType_Basic; \
353 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 4))
356 CBaseEntity *pEntity;
357 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
359 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
362 bool bByPlayer = (params[5] != 0);
363 CBaseEntity *pAttacker = NULL;
364 if (bByPlayer && !(pAttacker = UTIL_GetCBaseEntity(params[5], true)))
366 return pContext->ThrowNativeError("Attacker index %d is not valid", params[5]);
369 void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset);
371 unsigned char vstk[sizeof(void *) + 2*sizeof(float) + sizeof(int) + sizeof(CBaseEntity *)];
372 unsigned char *vptr = vstk;
374 *(void **)vptr = obj;
375 vptr += sizeof(void *);
376 *(float *)vptr = sp_ctof(params[2]);
377 vptr += sizeof(float);
378 *(float *)vptr = sp_ctof(params[3]);
379 vptr += sizeof(float);
380 *(int *)vptr = params[4];
382 *(CBaseEntity **)vptr = pAttacker;
384 pWrapper->Execute(vstk, NULL);
389 cell_t TF2_SetPowerplayEnabled(IPluginContext *pContext, const cell_t *params)
391 static ICallWrapper *pWrapper = NULL;
393 // CTFPlayer::SetPowerPlayEnabled(bool)
396 REGISTER_NATIVE_ADDR("SetPowerplayEnabled",
398 pass[0].flags = PASSFLAG_BYVAL; \
399 pass[0].size = sizeof(bool); \
400 pass[0].type = PassType_Basic; \
401 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 1))
404 CBaseEntity *pEntity;
405 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
407 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
410 bool bEnablePP = false;
416 unsigned char vstk[sizeof(void *) + sizeof(bool)];
417 unsigned char *vptr = vstk;
419 *(void **)vptr = (void *)pEntity;
420 vptr += sizeof(void *);
421 *(bool *)vptr = bEnablePP;
423 pWrapper->Execute(vstk, NULL);
428 cell_t TF2_Respawn(IPluginContext *pContext, const cell_t *params)
430 static ICallWrapper *pWrapper = NULL;
432 //CTFPlayer::ForceRespawn()
438 if (!g_pGameConf->GetOffset("ForceRespawn", &offset))
440 return pContext->ThrowNativeError("Failed to locate function");
443 pWrapper = g_pBinTools->CreateVCall(offset,
450 g_RegNatives.Register(pWrapper);
453 CBaseEntity *pEntity;
454 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
456 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
459 unsigned char vstk[sizeof(void *)];
460 unsigned char *vptr = vstk;
463 *(void **)vptr = (void *)pEntity;
465 pWrapper->Execute(vstk, NULL);
470 cell_t TF2_Regenerate(IPluginContext *pContext, const cell_t *params)
472 static ICallWrapper *pWrapper = NULL;
474 //CTFPlayer::Regenerate( bool=true )
478 REGISTER_NATIVE_ADDR("Regenerate",
480 pass[0].flags = PASSFLAG_BYVAL; \
481 pass[0].size = sizeof(bool); \
482 pass[0].type = PassType_Basic; \
483 pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 1))
486 CBaseEntity *pEntity;
487 if (!(pEntity = UTIL_GetCBaseEntity(params[1], true)))
489 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
492 unsigned char vstk[sizeof(void *) + sizeof(bool)];
493 unsigned char *vptr = vstk;
495 *(void **)vptr = (void *)pEntity;
496 vptr += sizeof(void *);
497 *(bool *)vptr = true;
499 pWrapper->Execute(vstk, NULL);
504 cell_t TF2_GetResourceEntity(IPluginContext *pContext, const cell_t *params)
506 return g_resourceEntity;
509 cell_t TF2_GetClass(IPluginContext *pContext, const cell_t *params)
512 pContext->LocalToString(params[1], &str);
514 return (cell_t)ClassnameToType(str);
517 // native TF2_IsPlayerInDuel(client)
518 cell_t TF2_IsPlayerInDuel(IPluginContext *pContext, const cell_t *params)
520 static ICallWrapper *pWrapper = NULL;
522 // DuelMiniGame_IsPlayerInDuel(CTFPlayer *)
525 REGISTER_NATIVE_ADDR("IsPlayerInDuel",
527 pass[0].flags = PASSFLAG_BYVAL; \
528 pass[0].size = sizeof(CBaseEntity *); \
529 pass[0].type = PassType_Basic; \
531 ret.flags = PASSFLAG_BYVAL; \
532 ret.size = sizeof(bool); \
533 ret.type = PassType_Basic; \
534 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &ret, pass, 1))
537 CBaseEntity *pPlayer;
538 if (!(pPlayer = UTIL_GetCBaseEntity(params[1], true)))
540 return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
543 unsigned char vstk[sizeof(CBaseEntity *)];
544 unsigned char *vptr = vstk;
545 *(CBaseEntity **)vptr = pPlayer;
548 pWrapper->Execute(vstk, &retValue);
550 return (retValue) ? 1 : 0;
553 // native bool:TF2_IsHolidayActive(TFHoliday:holiday);
554 cell_t TF2_IsHolidayActive(IPluginContext *pContext, const cell_t *params)
556 static ICallWrapper *pWrapper = NULL;
558 // UTIL_IsHolidayActive(int)
561 REGISTER_NATIVE_ADDR("IsHolidayActive",
563 pass[0].flags = PASSFLAG_BYVAL; \
564 pass[0].size = sizeof(int); \
565 pass[0].type = PassType_Basic; \
567 ret.flags = PASSFLAG_BYVAL; \
568 ret.size = sizeof(bool); \
569 ret.type = PassType_Basic; \
570 pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &ret, pass, 1))
573 unsigned char vstk[sizeof(int)];
574 unsigned char *vptr = vstk;
575 *(int *)vptr = params[1];
579 pWrapper->Execute(vstk, &retValue);
581 return (retValue) ? 1 : 0;
584 sp_nativeinfo_t g_TFNatives[] =
586 {"TF2_IgnitePlayer", TF2_Burn},
587 {"TF2_SetPlayerInvuln", TF2_Invuln},
588 {"TF2_RespawnPlayer", TF2_Respawn},
589 {"TF2_DisguisePlayer", TF2_Disguise},
590 {"TF2_RemovePlayerDisguise", TF2_RemoveDisguise},
591 {"TF2_GetResourceEntity", TF2_GetResourceEntity},
592 {"TF2_GetClass", TF2_GetClass},
593 {"TF2_RegeneratePlayer", TF2_Regenerate},
594 {"TF2_AddCondition", TF2_AddCondition},
595 {"TF2_RemoveCondition", TF2_RemoveCondition},
596 {"TF2_SetPlayerPowerPlay", TF2_SetPowerplayEnabled},
597 {"TF2_StunPlayer", TF2_StunPlayer},
598 {"TF2_MakeBleed", TF2_MakeBleed},
599 {"TF2_IsPlayerInDuel", TF2_IsPlayerInDuel},
600 {"TF2_IsHolidayActive", TF2_IsHolidayActive},