From 41eee3591c7a38f87e9ed002c6cec562c483f321 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Tue, 2 May 2017 15:34:21 +0300 Subject: [PATCH] Remove "cat_spam_newlines" --- src/gui/ncc/Menu.cpp | 2 +- src/hacks/Spam.cpp | 4 ++-- src/hacks/Spam.h | 1 - src/hooks/CreateMove.cpp | 2 +- src/hooks/others.cpp | 14 +++++++++++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/gui/ncc/Menu.cpp b/src/gui/ncc/Menu.cpp index 160a7e92..174e0477 100644 --- a/src/gui/ncc/Menu.cpp +++ b/src/gui/ncc/Menu.cpp @@ -526,7 +526,7 @@ static const std::string list_tf2 = R"( "Chat Options Menu" "killsay" "spam" - "spam_newlines" + "chat_newlines" "clean_chat" ] diff --git a/src/hacks/Spam.cpp b/src/hacks/Spam.cpp index 807ff799..65b95e60 100644 --- a/src/hacks/Spam.cpp +++ b/src/hacks/Spam.cpp @@ -13,8 +13,8 @@ namespace hacks { namespace shared { namespace spam { CatVar enabled(CV_SWITCH, "spam", "0", "Chat spam", "Enable Spam"); +//static CatEnum spam_enum({""}); CatVar filename(CV_STRING, "spam_file", "spam.txt", "Spam file (~/.cathook/...)", "Spam file name. Each line should be no longer than 100 characters, file must be located in ~/.cathook folder"); -CatVar newlines(CV_SWITCH, "spam_newlines", "1", "Spam newlines", "If enabled, several newlines will be added before each message"); CatCommand reload("spam_reload", "Reload spam file", Reload); int current_index { 0 }; @@ -28,7 +28,7 @@ void CreateMove() { if (g_GlobalVars->curtime - last_spam > 0.8f) { if (chat_stack::stack.empty()) { if (current_index >= file.LineCount()) current_index = 0; - std::string spamString = (newlines ? format("\n\n\n\n\n\n\n\n\n\n\n\n", file.Line(current_index)) : file.Line(current_index)); + std::string spamString = file.Line(current_index); ReplaceString(spamString, "\\n", "\n"); chat_stack::stack.push(spamString); current_index++; diff --git a/src/hacks/Spam.h b/src/hacks/Spam.h index 1c9282fe..ff7ea820 100644 --- a/src/hacks/Spam.h +++ b/src/hacks/Spam.h @@ -18,7 +18,6 @@ namespace hacks { namespace shared { namespace spam { extern CatVar enabled; extern CatVar filename; -extern CatVar newlines; extern CatCommand reload; void CreateMove(); diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 8dea7664..4cc74cc9 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -94,7 +94,7 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) { hooks::hkNetChannel = new hooks::VMTHook(); hooks::hkNetChannel->Init(ch, 0); hooks::hkNetChannel->HookMethod((void*)CanPacket_hook, hooks::offCanPacket); - //hooks::hkNetChannel->HookMethod((void*)SendNetMsg_hook, hooks::offSendNetMsg); + hooks::hkNetChannel->HookMethod((void*)SendNetMsg_hook, hooks::offSendNetMsg); hooks::hkNetChannel->HookMethod((void*)Shutdown_hook, hooks::offShutdown); hooks::hkNetChannel->Apply(); } diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index f7c6df37..e75a4038 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -107,9 +107,21 @@ static CatCommand minus_use_action_slot_item_server("-cat_use_action_slot_item_s g_IEngine->ServerCmdKeyValues(kv); }); -// Not used anymore.. +static CatVar newlines_msg(CV_INT, "chat_newlines", "0", "Prefix newlines", "Add # newlines before each your message"); + bool SendNetMsg_hook(void* thisptr, INetMessage& msg, bool bForceReliable = false, bool bVoice = false) { SEGV_BEGIN; + // net_StringCmd + if (msg.GetType() == 4 && newlines_msg) { + std::string str(msg.ToString()); + if (str.find("net_StringCmd: \"say \"") == 0) { + std::string newlines = std::string((int)newlines_msg, '\n'); + str.insert(21, newlines); + str = str.substr(16, str.length() - 17); + NET_StringCmd stringcmd(str.c_str()); + return ((SendNetMsg_t*)hooks::hkNetChannel->GetMethod(hooks::offSendNetMsg))(thisptr, stringcmd, bForceReliable, bVoice); + } + } if (log_sent && msg.GetType() != 3 && msg.GetType() != 9) { logging::Info("=> %s [%i] %s", msg.GetName(), msg.GetType(), msg.ToString()); unsigned char buf[4096];