From 43e02bd19adaf24e15a13eee3fe940785a9d80fb Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Sun, 31 Dec 2017 13:19:47 +0300 Subject: [PATCH] vote logging --- include/common.hpp | 1 + include/votelogger.hpp | 19 ++++++++++++++ src/hacks/CatBot.cpp | 1 - src/hooks/others.cpp | 13 ++++++++-- src/votelogger.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 include/votelogger.hpp create mode 100644 src/votelogger.cpp diff --git a/include/common.hpp b/include/common.hpp index d29b9aa5..6ed18d34 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -100,6 +100,7 @@ #include "tfmm.hpp" #include "hooks/hookedmethods.hpp" #include "classinfo/classinfo.hpp" +#include "votelogger.hpp" #include "crits.hpp" #include "textmode.hpp" #include "backpacktf.hpp" diff --git a/include/votelogger.hpp b/include/votelogger.hpp new file mode 100644 index 00000000..61e14f37 --- /dev/null +++ b/include/votelogger.hpp @@ -0,0 +1,19 @@ +/* + * votelogger.hpp + * + * Created on: Dec 31, 2017 + * Author: nullifiedcat + */ + +#pragma once + +class bf_read; + +namespace votelogger +{ + +void user_message(bf_read& buffer, int type); + +} + + diff --git a/src/hacks/CatBot.cpp b/src/hacks/CatBot.cpp index 9b85164b..6c405058 100644 --- a/src/hacks/CatBot.cpp +++ b/src/hacks/CatBot.cpp @@ -84,7 +84,6 @@ void do_random_votekick() player_info_s info; if (!g_IEngine->GetPlayerInfo(g_IEngine->GetPlayerForUserID(target), &info)) return; - logging::Info("Calling vote to kick '%s' [U:1:%u] (%d / %u)", info.name, info.friendsID, target, targets.size()); hack::ExecuteCommand("callvote kick " + std::to_string(target) + " cheating"); } diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index ea28dde0..272a0336 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -667,8 +667,8 @@ void FrameStageNotify_hook(void *_this, int stage) std::lock_guard guard(hack::command_stack_mutex); while (!hack::command_stack().empty()) { - logging::Info("executing %s", - hack::command_stack().top().c_str()); + //logging::Info("executing %s", + // hack::command_stack().top().c_str()); g_IEngine->ClientCmd_Unrestricted( hack::command_stack().top().c_str()); hack::command_stack().pop(); @@ -782,7 +782,16 @@ bool DispatchUserMessage_hook(void *_this, int type, bf_read &buf) if (dispatch_log) { logging::Info("D> %i", type); + std::ostringstream str{}; + while (buf.GetNumBytesLeft()) + { + unsigned char byte = buf.ReadByte(); + str << std::hex << std::setw(2) << std::setfill('0') << static_cast(byte) << ' '; + } + logging::Info("MESSAGE %d, DATA = [ %s ]", type, str.str().c_str()); + buf.Seek(0); } + votelogger::user_message(buf, type); return original(_this, type, buf); } diff --git a/src/votelogger.cpp b/src/votelogger.cpp new file mode 100644 index 00000000..c155101c --- /dev/null +++ b/src/votelogger.cpp @@ -0,0 +1,59 @@ +/* + * votelogger.cpp + * + * Created on: Dec 31, 2017 + * Author: nullifiedcat + */ + +#include "common.hpp" + +namespace votelogger +{ + +static CatVar enabled(CV_SWITCH, "votelog", "0", "Log votes"); + +void user_message(bf_read& buffer, int type) +{ + if (!enabled) + return; + + switch (type) + { + case 45: + // Call Vote Failed + break; + case 46: { + unsigned char caller = buffer.ReadByte(); + // unknown + buffer.ReadByte(); + char reason[64]; + char name[64]; + buffer.ReadString(reason, 64, false, nullptr); + buffer.ReadString(name, 64, false, nullptr); + unsigned char eid = buffer.ReadByte(); + buffer.Seek(0); + eid >>= 1; + + unsigned steamID = 0; + player_info_s info; + if (g_IEngine->GetPlayerInfo(eid, &info)) + { + steamID = info.friendsID; + } + + logging::Info("Vote called to kick %s [U:1:%u] for %s", name, steamID, reason); + break; + } + case 47: + logging::Info("Vote passed"); + break; + case 48: + logging::Info("Vote failed"); + break; + case 49: + logging::Info("VoteSetup?"); + break; + } +} + +}