From 7988469198827a614ae49ddbd6174250f01ddf34 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Tue, 2 May 2017 19:29:34 +0300 Subject: [PATCH] cat_name convar & cat_name_set command --- src/globals.cpp | 2 ++ src/globals.h | 2 ++ src/hacks/Misc.cpp | 2 +- src/hooks/PaintTraverse.cpp | 17 +++++++++++++++++ src/hooks/others.cpp | 26 ++++++++++++++++++++++++++ src/hooks/others.h | 3 +++ 6 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/globals.cpp b/src/globals.cpp index f700724c..9f6b94d2 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -20,6 +20,8 @@ void ThirdpersonCallback(IConVar* var, const char* pOldValue, float flOldValue) } } +bool need_name_change = true; +CatVar force_name(CV_STRING, "name", "", "Force name"); CatVar cathook(CV_SWITCH, "enabled", "1", "CatHook enabled", "Disabling this completely disables cathook (can be re-enabled)"); CatVar ignore_taunting(CV_SWITCH, "ignore_taunting", "1", "Ignore taunting", "Aimbot/Triggerbot won't attack taunting enemies"); CatVar send_packets(CV_SWITCH, "sendpackets", "1", "Send packets", "Internal use"); diff --git a/src/globals.h b/src/globals.h index 54546c15..72efbbfa 100644 --- a/src/globals.h +++ b/src/globals.h @@ -25,6 +25,8 @@ extern CatVar force_thirdperson; extern CatVar console_logging; extern CatVar fast_outline; extern CatVar roll_speedhack; +extern CatVar force_name; +extern bool need_name_change; class GlobalSettings { public: diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index d2b25c0f..3a33c915 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -325,7 +325,7 @@ CatVar crit_suppress(CV_SWITCH, "crit_suppress", "0", "Disable random crits", "C CatVar anti_afk(CV_SWITCH, "anti_afk", "0", "Anti-AFK", "Sends random commands to prevent being kicked from server"); CatVar tauntslide(CV_SWITCH, "tauntslide", "0", "TF2C tauntslide", "Allows moving and shooting while taunting"); -CatCommand name("name", "Change name", [](const CCommand& args) { +CatCommand name("name_set", "Immediate name change", [](const CCommand& args) { if (args.ArgC() < 2) { logging::Info("Set a name, silly"); return; diff --git a/src/hooks/PaintTraverse.cpp b/src/hooks/PaintTraverse.cpp index 0c7f4e89..7b1fa5c7 100644 --- a/src/hooks/PaintTraverse.cpp +++ b/src/hooks/PaintTraverse.cpp @@ -13,6 +13,7 @@ #include "../segvcatch/segvcatch.h" #include "../copypasted/CSignature.h" #include "../profiler.h" +#include "../netmessage.h" CatVar clean_screenshots(CV_SWITCH, "clean_screenshots", "1", "Clean screenshots", "Don't draw visuals while taking a screenshot"); CatVar disable_visuals(CV_SWITCH, "no_visuals", "0", "Disable ALL drawing", "Completely hides cathook"); @@ -57,6 +58,18 @@ void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) { g_ISurface->SetCursorAlwaysVisible(vis); } + if (force_name.convar->m_StringLength > 2 && need_name_change) { + INetChannel* ch = (INetChannel*)g_IEngine->GetNetChannelInfo(); + if (ch) { + logging::Info("Sending new name"); + NET_SetConVar setname("name", force_name.GetString()); + setname.SetNetChannel(ch); + setname.SetReliable(false); + ch->SendNetMsg(setname, false); + need_name_change = false; + } + } + if (call_default) SAFE_CALL(((PaintTraverse_t*)hooks::hkPanel->GetMethod(hooks::offPaintTraverse))(p, vp, fr, ar)); // To avoid threading problems. @@ -111,6 +124,10 @@ void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) { #endif AddSideString("Press 'INSERT' key to open/close cheat menu.", GUIColor()); AddSideString("Use mouse to navigate in menu.", GUIColor()); + const char* name = (force_name.convar->m_StringLength > 2 ? force_name.GetString() : "*Not Set*"); + AddSideString(""); // foolish + AddSideString(format("Custom Name: ", name), GUIColor()); + AddSideString(format("Custom Disconnect Reason: ", (disconnect_reason.convar->m_StringLength > 3 ? disconnect_reason.GetString() : "*Not Set*")), GUIColor()); } if (CE_GOOD(g_pLocalPlayer->entity) && !g_Settings.bInvalid) { diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index 1d7e56ce..bef57313 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -289,16 +289,42 @@ void LevelInit_hook(void* thisptr, const char* newmap) { //if (TF) LEVEL_INIT(SpyAlert); chat_stack::Reset(); hacks::shared::spam::Reset(); + need_name_change = true; + if (force_name.convar->m_StringLength > 2) { + //static ConVar* name_cv = g_ICvar->FindVar("name"); + INetChannel* ch = (INetChannel*)g_IEngine->GetNetChannelInfo(); + if (ch) { + logging::Info("Sending new name"); + NET_SetConVar setname("name", force_name.GetString()); + setname.SetNetChannel(ch); + setname.SetReliable(false); + ch->SendNetMsg(setname, false); + //name_cv->m_pszString = strfmt("%s", force_name.GetString()); + } + } } bool CanInspect_hook(IClientEntity*) { return true; } void LevelShutdown_hook(void* thisptr) { + need_name_change = true; playerlist::Save(); ((LevelShutdown_t*) hooks::hkClientMode->GetMethod(hooks::offLevelShutdown))(thisptr); g_Settings.bInvalid = true; hacks::shared::aimbot::Reset(); chat_stack::Reset(); hacks::shared::spam::Reset(); + if (force_name.convar->m_StringLength > 2) { + //static ConVar* name_cv = g_ICvar->FindVar("name"); + INetChannel* ch = (INetChannel*)g_IEngine->GetNetChannelInfo(); + if (ch) { + logging::Info("Sending new name"); + NET_SetConVar setname("name", force_name.GetString()); + setname.SetNetChannel(ch); + setname.SetReliable(false); + ch->SendNetMsg(setname, false); + //name_cv->m_pszString = strfmt("%s", force_name.GetString()); + } + } } diff --git a/src/hooks/others.h b/src/hooks/others.h index 4bfe8d83..8f5f67ba 100644 --- a/src/hooks/others.h +++ b/src/hooks/others.h @@ -12,6 +12,9 @@ class INetMessage; class CViewSetup; class bf_read; class SDL_Window; +class CatVar; + +extern CatVar disconnect_reason; bool CanPacket_hook(void*); int IN_KeyEvent_hook(void*, int, int, const char*);