From 488de0014e946533ede4f4e5dbccd6b6142f4082 Mon Sep 17 00:00:00 2001 From: pheadxdll Date: Mon, 26 Jul 2010 11:06:08 -0400 Subject: [PATCH] Added TF2_MakeBleed native to TF2 ext (bug 4542, r=fyren,psychonic). --- extensions/tf2/natives.cpp | 52 ++++++++++++++++++++++++++++++++++++++ gamedata/sm-tf2.games.txt | 7 +++++ plugins/include/tf2.inc | 11 ++++++++ 3 files changed, 70 insertions(+) diff --git a/extensions/tf2/natives.cpp b/extensions/tf2/natives.cpp index 0a86fe1e..bc01de24 100644 --- a/extensions/tf2/natives.cpp +++ b/extensions/tf2/natives.cpp @@ -34,6 +34,57 @@ #include "time.h" #include "RegNatives.h" +// native TF2_MakeBleed(client, victim, Float:duration) +cell_t TF2_MakeBleed(IPluginContext *pContext, const cell_t *params) +{ + static ICallWrapper *pWrapper = NULL; + + // CTFPlayerShared::MakeBleed(CTFPlayer*, CTFWeaponBase*, float) + if(!pWrapper) + { + REGISTER_NATIVE_ADDR("MakeBleed", + PassInfo pass[3]; \ + pass[0].flags = PASSFLAG_BYVAL; \ + pass[0].size = sizeof(CBaseEntity *); \ + pass[0].type = PassType_Basic; \ + pass[1].flags = PASSFLAG_BYVAL; \ + pass[1].size = sizeof(CBaseEntity *); \ + pass[1].type = PassType_Basic; \ + pass[2].flags = PASSFLAG_BYVAL; \ + pass[2].size = sizeof(float); \ + pass[2].type = PassType_Basic; \ + pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 3)) + } + + CBaseEntity *pEntity; + if (!(pEntity = UTIL_GetCBaseEntity(params[1], true))) + { + return pContext->ThrowNativeError("Client index %d is not valid", params[1]); + } + + CBaseEntity *pTarget; + if (!(pTarget = UTIL_GetCBaseEntity(params[2], true))) + { + return pContext->ThrowNativeError("Client index %d is not valid", params[2]); + } + + void *obj = (void *)((uint8_t *)pEntity + playerSharedOffset->actual_offset); + + unsigned char vstk[sizeof(void *) + 2*sizeof(CBaseEntity *) + sizeof(float)]; + unsigned char *vptr = vstk; + + *(void **)vptr = obj; + vptr += sizeof(void *); + *(CBaseEntity **)vptr = pTarget; + vptr += sizeof(CBaseEntity *); + *(CBaseEntity **)vptr = NULL; + vptr += sizeof(CBaseEntity *); + *(float *)vptr = sp_ctof(params[3]); + + pWrapper->Execute(vstk, NULL); + + return 1; +} // native TF2_Burn(client, target) cell_t TF2_Burn(IPluginContext *pContext, const cell_t *params) @@ -421,5 +472,6 @@ sp_nativeinfo_t g_TFNatives[] = {"TF2_RemoveCondition", TF2_RemoveCondition}, {"TF2_SetPlayerPowerPlay", TF2_SetPowerplayEnabled}, {"TF2_StunPlayer", TF2_StunPlayer}, + {"TF2_MakeBleed", TF2_MakeBleed}, {NULL, NULL} }; diff --git a/gamedata/sm-tf2.games.txt b/gamedata/sm-tf2.games.txt index 51be92c9..c276810a 100644 --- a/gamedata/sm-tf2.games.txt +++ b/gamedata/sm-tf2.games.txt @@ -99,6 +99,13 @@ "linux" "@_ZN12CTFGameRules10GetHolidayEv" "mac" "@_ZN12CTFGameRules10GetHolidayEv" } + "MakeBleed" + { + "library" "server" + "windows" "\x56\x8B\xF1\x8B\x8E\x2A\x2A\x2A\x2A\x8B\x2A\x8B\x90\x2A\x2A\x2A\x2A\xFF\xD2\x84\xC0\x0F\x2A\x2A\x2A\x2A\x2A\x8B\x86\x2A\x2A\x2A\x2A\xC1" + "linux" "@_ZN15CTFPlayerShared9MakeBleedEP9CTFPlayerP13CTFWeaponBasef" + "mac" "@_ZN15CTFPlayerShared9MakeBleedEP9CTFPlayerP13CTFWeaponBasef" + } } "Offsets" { diff --git a/plugins/include/tf2.inc b/plugins/include/tf2.inc index 3f92a60f..740a8276 100644 --- a/plugins/include/tf2.inc +++ b/plugins/include/tf2.inc @@ -217,6 +217,16 @@ native TF2_RemovePlayerDisguise(client); */ native TF2_StunPlayer(client, Float:duration, Float:slowdown=0.0, stunflags, attacker=0); +/** + * Induces the bleed effect on a client + * + * @param client Player's index. + * @param victim Victim's index. + * @param float Duration of bleeding (in seconds). + * @noreturn + */ +native TF2_MakeBleed(client, victim, Float:duration); + /** * Retrieves the entity index of the CPlayerResource entity * @@ -286,6 +296,7 @@ public __ext_tf2_SetNTVOptional() MarkNativeAsOptional("TF2_DisguisePlayer"); MarkNativeAsOptional("TF2_RemovePlayerDisguise"); MarkNativeAsOptional("TF2_StunPlayer"); + MakeNativeAsOptional("TF2_MakeBleed"); MarkNativeAsOptional("TF2_GetResourceEntity"); MarkNativeAsOptional("TF2_GetClass"); }