diff --git a/src/hack.cpp b/src/hack.cpp index 6492d795..a959645c 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -270,6 +270,7 @@ void hack::Initialize() { logging::Info("SDL hooking done"); g_IGameEventManager->AddListener(&adv_event_listener, false); hacks::shared::anticheat::Init(); + hacks::tf2::healarrow::Init(); InitSpinner(); logging::Info("Initialized Fidget Spinner"); diff --git a/src/hacks/HealArrows.cpp b/src/hacks/HealArrows.cpp index c3e8d046..00523148 100644 --- a/src/hacks/HealArrows.cpp +++ b/src/hacks/HealArrows.cpp @@ -10,11 +10,53 @@ namespace hacks { namespace tf2 { namespace healarrow { static CatVar healarrow_charge(CV_FLOAT, "healarrow_charge", "0.25", "Healarrow Charge"); -static CatVar healarrow_timeout(CV_FLOAT, "healarrow_timeout", "12.5", "Healarrow Timeout"); +static CatVar healarrow_timeout(CV_FLOAT, "healarrow_timeout", "2", "Healarrow Timeout"); static CatVar healarrow(CV_SWITCH, "healarrow", "0", "Heal Arrow"); +static CatVar healarrow_callout(CV_SWITCH, "healarrow_callout", "0", "Call Out", "Send a message to chat when you heal someone with an arrow"); +static CatVar healarrow_callout_message(CV_STRING, "healarrow_callout_text", "Hey %%, I've just healed you for $$ HP! Your health is now ##.", "Call Out Text", "Formatting:\n%% - player name\n$$ - healing amount\n## - new health\n@@ - old health"); float healarrow_time = 0.0f; +class HealArrowListener : public IGameEventListener { +public: + virtual void FireGameEvent(KeyValues* event) { + if (!healarrow) return; + if (!healarrow_callout) return; + if (CE_BAD(LOCAL_W)) return; + if (LOCAL_W->m_iClassID != CL_CLASS(CTFCompoundBow)) return; + std::string name(event->GetName()); + if (name == "player_hurt") { + int attacker = event->GetInt("attacker"); + int victim = event->GetInt("userid"); + int eid = g_IEngine->GetPlayerForUserID(attacker); + int vid = g_IEngine->GetPlayerForUserID(victim); + if (eid == g_IEngine->GetLocalPlayer()) { + int damageamount = event->GetInt("damageamount"); + if (damageamount < 0) { + player_info_s pinfo; + if (g_IEngine->GetPlayerInfo(vid, &pinfo)) { + std::string msg(healarrow_callout_message.GetString()); + ReplaceString(msg, "$$", std::to_string(-damageamount)); + auto v_entity = ENTITY(vid); + if (CE_GOOD(v_entity)) { + ReplaceString(msg, "##", std::to_string(CE_INT(v_entity, netvar.iHealth) - damageamount)); + ReplaceString(msg, "@@", std::to_string(CE_INT(v_entity, netvar.iHealth))); + } + ReplaceString(msg, "%%", pinfo.name); + chat_stack::Say(msg); + } + } + } + } + } +}; + +HealArrowListener listener; + +void Init() { + g_IGameEventManager->AddListener(&listener, false); +} + void CreateMove() { if (CE_BAD(LOCAL_W)) return; if (healarrow) { diff --git a/src/hacks/HealArrows.hpp b/src/hacks/HealArrows.hpp index 8f1f2a46..9e8bfd02 100644 --- a/src/hacks/HealArrows.hpp +++ b/src/hacks/HealArrows.hpp @@ -11,5 +11,6 @@ namespace hacks { namespace tf2 { namespace healarrow { void CreateMove(); void Draw(); +void Init(); }}} diff --git a/tf-settings/menu.json b/tf-settings/menu.json index 6aa6386a..6a8797c9 100644 --- a/tf-settings/menu.json +++ b/tf-settings/menu.json @@ -449,7 +449,9 @@ "list": [ "healarrow", "healarrow_charge", - "healarrow_timeout" + "healarrow_timeout", + "healarrow_callout", + "healarrow_callout_text" ] }, { diff --git a/update-data b/update-data index a851671e..3d594f93 100755 --- a/update-data +++ b/update-data @@ -1,6 +1,7 @@ #!/usr/bin/env bash echo "Searching for Team Fortress 2" +echo "Please wait..." find / -type d -name "Team Fortress 2" 2>/dev/null | while read path; do if [ -e "$path/tf/gameinfo.txt" ]; then @@ -10,6 +11,7 @@ find / -type d -name "Team Fortress 2" 2>/dev/null | while read path; do ln -s "$path/cathook" "Data Folder" rsync -avh --progress tf-settings/ "$path/cathook" echo "Symbolic link created (Data Folder)" + echo "You can close this window" read -p "Press ENTER to continue" fi fi