From 5ff8ec62e073a0fb422691614324d9efb057090d Mon Sep 17 00:00:00 2001 From: "A.W. Stanley" Date: Sun, 7 Nov 2010 19:09:34 -0500 Subject: [PATCH] Added TF2_IsPlayerInDuel native to TF2 extension (bug 4695, r=psychonic). --- extensions/tf2/natives.cpp | 37 +++++++++++++++++++++++++++++++++++++ gamedata/sm-tf2.games.txt | 6 ++++++ plugins/include/tf2.inc | 9 +++++++++ 3 files changed, 52 insertions(+) diff --git a/extensions/tf2/natives.cpp b/extensions/tf2/natives.cpp index 29aed779..d5c58535 100644 --- a/extensions/tf2/natives.cpp +++ b/extensions/tf2/natives.cpp @@ -475,6 +475,42 @@ cell_t TF2_GetClass(IPluginContext *pContext, const cell_t *params) return (cell_t)ClassnameToType(str); } +// native TF2_IsPlayerInDuel(client) +cell_t TF2_IsPlayerInDuel(IPluginContext *pContext, const cell_t *params) +{ + static ICallWrapper *pWrapper = NULL; + + // DuelMiniGame_IsPlayerInDuel(CTFPlayer *) + if (!pWrapper) + { + REGISTER_NATIVE_ADDR("IsPlayerInDuel", + PassInfo pass[1]; \ + pass[0].flags = PASSFLAG_BYVAL; \ + pass[0].size = sizeof(CBaseEntity *); \ + pass[0].type = PassType_Basic; \ + PassInfo ret; \ + ret.flags = PASSFLAG_BYVAL; \ + ret.size = sizeof(bool); \ + ret.type = PassType_Basic; \ + pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &ret, pass, 1)) + } + + CBaseEntity *pPlayer; + if (!(pPlayer = UTIL_GetCBaseEntity(params[1], true))) + { + return pContext->ThrowNativeError("Client index %d is not valid", params[1]); + } + + unsigned char vstk[sizeof(CBaseEntity *)]; + unsigned char *vptr = vstk; + *(CBaseEntity **)vptr = pPlayer; + + bool retValue; + pWrapper->Execute(vstk, &retValue); + + return (retValue) ? 1 : 0; +} + sp_nativeinfo_t g_TFNatives[] = { {"TF2_IgnitePlayer", TF2_Burn}, @@ -490,5 +526,6 @@ sp_nativeinfo_t g_TFNatives[] = {"TF2_SetPlayerPowerPlay", TF2_SetPowerplayEnabled}, {"TF2_StunPlayer", TF2_StunPlayer}, {"TF2_MakeBleed", TF2_MakeBleed}, + {"TF2_IsPlayerInDuel", TF2_IsPlayerInDuel}, {NULL, NULL} }; diff --git a/gamedata/sm-tf2.games.txt b/gamedata/sm-tf2.games.txt index 823b6772..92c6401c 100644 --- a/gamedata/sm-tf2.games.txt +++ b/gamedata/sm-tf2.games.txt @@ -93,6 +93,12 @@ "windows" "\x51\x56\x8B\xF1\x8B\x8E\x2A\x2A\x2A\x2A\x8B\x01\x8B\x90\x2A\x2A\x2A\x2A\xFF\xD2\x84\xC0\x0F\x2A\x2A\x2A\x2A\x2A\x6A\x19\x8D" "linux" "@_ZN15CTFPlayerShared9MakeBleedEP9CTFPlayerP13CTFWeaponBasef" } + "IsPlayerInDuel" + { + "library" "server" + "windows" "\x83\xEC\x08\x2A\x2A\x2A\x2A\x33\xC0\x89\x04\x24\x89\x44\x24\x04\x8D\x04\x24\x50\x2A\x2A\x2A\x2A\x2A\x84\xC0\x2A\x2A\x83\xC4\x08\xC3" + "linux" "@_Z21DuelMiniGame_IsInDuelP9CTFPlayer" + } } "Offsets" { diff --git a/plugins/include/tf2.inc b/plugins/include/tf2.inc index 1b50b80a..8aa9c3fc 100644 --- a/plugins/include/tf2.inc +++ b/plugins/include/tf2.inc @@ -272,6 +272,14 @@ forward Action:TF2_CalcIsAttackCritical(client, weapon, String:weaponname[], &bo */ forward Action:TF2_OnGetHoliday(&TFHoliday:holiday); +/** + * Returns whether or not a client (Player) is in a duel. + * + * @param client Client Index. + * @return Boolean of whether or not the client/player is dueling. + */ +native bool:TF2_IsPlayerInDuel(client); + /** * Do not edit below this line! */ @@ -302,5 +310,6 @@ public __ext_tf2_SetNTVOptional() MarkNativeAsOptional("TF2_MakeBleed"); MarkNativeAsOptional("TF2_GetResourceEntity"); MarkNativeAsOptional("TF2_GetClass"); + MarkNativeAsOptional("TF2_IsPlayerInDuel"); } #endif