From 7cb24c35f66cac25dfe12f46d978e86c2f5d6266 Mon Sep 17 00:00:00 2001 From: neon1 <> Date: Thu, 24 Oct 2019 01:20:28 +0200 Subject: [PATCH] Hitmarker: CBaseEntity__OnTakeDamage --- Hitmarker/gamedata/Hitmarker.games.txt | 32 +++++++++++++++++ Hitmarker/scripting/Hitmarker.sp | 49 +++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Hitmarker/gamedata/Hitmarker.games.txt diff --git a/Hitmarker/gamedata/Hitmarker.games.txt b/Hitmarker/gamedata/Hitmarker.games.txt new file mode 100644 index 00000000..c3d94681 --- /dev/null +++ b/Hitmarker/gamedata/Hitmarker.games.txt @@ -0,0 +1,32 @@ +"Games" +{ + "cstrike" + { + "Signatures" + { + "CBaseEntity::OnTakeDamage" + { + "library" "server" + "linux" "@_ZN11CBaseEntity12OnTakeDamageERK15CTakeDamageInfo" + } + } + + "Functions" + { + "CBaseEntity__OnTakeDamage" + { + "signature" "CBaseEntity::OnTakeDamage" + "callconv" "thiscall" + "return" "int" + "this" "entity" + "arguments" + { + "info" + { + "type" "objectptr" + } + } + } + } + } +} \ No newline at end of file diff --git a/Hitmarker/scripting/Hitmarker.sp b/Hitmarker/scripting/Hitmarker.sp index c82c3da5..b1fd747f 100644 --- a/Hitmarker/scripting/Hitmarker.sp +++ b/Hitmarker/scripting/Hitmarker.sp @@ -4,6 +4,7 @@ #include #include #include +#include #define SPECMODE_NONE 0 #define SPECMODE_FIRSTPERSON 4 @@ -42,7 +43,7 @@ public Plugin myinfo = name = "Hitmarker", author = "Neon & Nano", description = "Players can enable or disable their hitmarkers while shooting zombies or bosses", - version = "2.0.0", + version = "3.0.0", }; //---------------------------------------------------------------------------------------------------- @@ -59,6 +60,20 @@ public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int erro //---------------------------------------------------------------------------------------------------- public void OnPluginStart() { + Handle g_hOnTakeDamageDetour; + Handle hGameData = LoadGameConfigFile("Hitmarker.games"); + if(!hGameData) + SetFailState("Failed to load Hitmarker gamedata."); + + g_hOnTakeDamageDetour = DHookCreateFromConf(hGameData, "CBaseEntity__OnTakeDamage"); + if(!g_hOnTakeDamageDetour) + SetFailState("Failed to setup detour for CBaseEntity__OnTakeDamage"); + + delete hGameData; + + if(!DHookEnableDetour(g_hOnTakeDamageDetour, true, Detour_OnTakeDamage)) + SetFailState("Failed to detour CBaseEntity__OnTakeDamage."); + g_hCookie_ShowBossHitmarker = RegClientCookie("hitmarker_boss", "", CookieAccess_Private); g_hCookie_ShowZombieHitmarker = RegClientCookie("hitmarker_zombie", "", CookieAccess_Private); g_hCookie_HitmarkerSound = RegClientCookie("hitmarker_sound", "", CookieAccess_Private); @@ -408,6 +423,7 @@ public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int se //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- +/* public void OnBossDamaged(CBoss Boss, CConfig Config, int client, float damage) { if (!IsValidClient(client)) @@ -428,6 +444,37 @@ public void OnBossDamaged(CBoss Boss, CConfig Config, int client, float damage) ShowOverlay(spec); } } +*/ +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public MRESReturn Detour_OnTakeDamage(int entity, Handle hReturn, Handle hParams) +{ + int client = DHookGetParamObjectPtrVar(hParams, 1, 3*(3*4) + 0, ObjectValueType_Ehandle); + //https://github.com/alliedmodders/hl2sdk/blob/css/game/shared/takedamageinfo.h#L115 + //float dmg = DHookGetParamObjectPtrVar(hParams, 1, 48, ObjectValueType_Float); + //int ret = DHookGetReturn(hReturn); + + if (!IsValidClient(client)) + return MRES_Ignored; + + if (g_bShowBossHitmarker[client]) + ShowOverlay(client); + + for (int spec = 1; spec <= MaxClients; spec++) + { + if (!IsClientInGame(spec) || !IsClientObserver(spec) || !g_bShowBossHitmarker[spec]) + continue; + + int specMode = GetClientSpectatorMode(spec); + int specTarget = GetClientSpectatorTarget(spec); + + if ((specMode == SPECMODE_FIRSTPERSON) && specTarget == client) + ShowOverlay(spec); + } + + return MRES_Ignored; +} //---------------------------------------------------------------------------------------------------- // Purpose: