From b185375f779102e912ae0a4e733d12367f19a171 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Fri, 28 Jul 2017 12:17:13 +0300 Subject: [PATCH] cat_wb_split, cat_wb_duck, cat_chat_log --- src/chatlog.cpp | 61 +++++++++++++++++++++++++++++++++++++++++ src/chatlog.hpp | 14 ++++++++++ src/hacks/Walkbot.cpp | 63 +++++++++++++++++++++---------------------- src/hooks/others.cpp | 56 +++++++++++++++++++------------------- 4 files changed, 134 insertions(+), 60 deletions(-) create mode 100644 src/chatlog.cpp create mode 100644 src/chatlog.hpp diff --git a/src/chatlog.cpp b/src/chatlog.cpp new file mode 100644 index 00000000..c508eb15 --- /dev/null +++ b/src/chatlog.cpp @@ -0,0 +1,61 @@ +/* + * chatlog.cpp + * + * Created on: Jul 28, 2017 + * Author: nullifiedcat + */ + +#include "common.h" +#include "init.hpp" + +namespace chatlog { + +CatVar enabled(CV_SWITCH, "chat_log", "0", "Chat log", "Log chat to file"); +CatVar message_template(CV_STRING, "chat_log_template", "[U:1:%u] %n: %m", "Log template", "%u - SteamID\n%n - name\n%m - message"); + +class RAIILog { +public: + RAIILog() { + stream.open("cathook/chat.log", std::ios::out | std::ios::app); + } + ~RAIILog() { + stream.close(); + } + void log(const std::string& msg) { + if (stream.bad()) { + logging::Info("[ERROR] RAIILog stream is bad!"); + return; + } + stream << msg << "\n"; + stream.flush(); + } + std::ofstream stream; +}; + +RAIILog& logger() { + static RAIILog object {}; + return object; +} + +void LogMessage(int eid, std::string message) { + if (!enabled) { + return; + } + player_info_s info; + if (not g_IEngine->GetPlayerInfo(eid, &info)) + return; + std::string name(info.name); + for (auto& x : name) { + if (x < 32) x = '*'; + } + for (auto& x : message) { + if (x < 32) x = '*'; + } + std::string msg(message_template.GetString()); + ReplaceString(msg, "%u", std::to_string(info.friendsID)); + ReplaceString(msg, "%n", name); + ReplaceString(msg, "%m", message); + logger().log(msg); +} + +} diff --git a/src/chatlog.hpp b/src/chatlog.hpp new file mode 100644 index 00000000..bd5ed276 --- /dev/null +++ b/src/chatlog.hpp @@ -0,0 +1,14 @@ +/* + * chatlog.hpp + * + * Created on: Jul 28, 2017 + * Author: nullifiedcat + */ + +#pragma once + +namespace chatlog { + +void LogMessage(int eid, std::string message); + +} diff --git a/src/hacks/Walkbot.cpp b/src/hacks/Walkbot.cpp index 5d36a007..e2926b9b 100644 --- a/src/hacks/Walkbot.cpp +++ b/src/hacks/Walkbot.cpp @@ -372,6 +372,28 @@ CatCommand c_select_node("wb_select", "Select node", []() { state::active_node = state::closest_node; } }); +// Makes a new node in the middle of connection between 2 nodes +CatCommand c_split_connection("wb_split", "Split connection", []() { + if (not (state::node_good(state::active_node) and state::node_good(state::closest_node))) + return; + + if (state::active_node == state::closest_node) + return; + + auto& a = state::nodes[state::active_node]; + auto& b = state::nodes[state::closest_node]; + + a.unlink(state::closest_node); + b.unlink(state::active_node); + + index_t node = CreateNode((a.xyz() + b.xyz()) / 2); + auto& n = state::nodes[node]; + a.link(node); + n.link(state::active_node); + b.link(node); + n.link(state::closest_node); + +}); // Deletes closest node and its connections CatCommand c_delete_node("wb_delete", "Delete node", []() { DeleteNode(state::closest_node); @@ -441,41 +463,17 @@ CatCommand c_disconnect_single_node("wb_disconnect_single", "Connect nodes (one- a.unlink(state::closest_node); }); -// Updates duck flag on region of nodes (selected to closest) -// Updates a single closest node if no node is selected -CatCommand c_update_duck("wb_duck", "Update duck flags", []() { - logging::Info("< DISABLED >"); - /*index_t a = state::active_node; - index_t b = state::closest_node; - - if (not (state::node_good(a) and state::node_good(b))) +// Toggles jump flag on closest node +CatCommand c_update_duck("wb_duck", "Toggle duck flag", []() { + if (not state::node_good(state::closest_node)) return; - index_t current = state::closest_node; + auto& n = state::nodes[state::closest_node]; - do { - auto& n = state::nodes[current]; - if (g_pUserCmd->buttons & IN_DUCK) - n.flags |= NF_DUCK; - else - n.flags &= ~NF_DUCK; - if (n.connection_count > 2) { - logging::Info("[wb] More than 2 connections on a node - instructions unclear, got my duck stuck in 'if' block"); - return; - } - bool found_next = false; - for (size_t i = 0; i < n.connection_count; i++) { - if (n.connections[i] != current) { - current = n.connections[i]; - found_next = true; - break; - } - } - if (not found_next) { - logging::Info("[wb] Dead end? Can't find next node after %u", current); - break; - } - } while (state::node_good(current) and (current != a));*/ + if (n.flags & NF_DUCK) + n.flags &= ~NF_DUCK; + else + n.flags |= NF_DUCK; }); // Toggles jump flag on closest node CatCommand c_update_jump("wb_jump", "Toggle jump flag", []() { @@ -723,6 +721,7 @@ void UpdateWalker() { logging::Info("[wb] Reached node %u, moving to %u", state::last_node, state::active_node); if (state::node_good(state::active_node)) { if (state::nodes[state::active_node].flags & NF_JUMP) { + g_pUserCmd->buttons |= IN_DUCK; g_pUserCmd->buttons |= IN_JUMP; jump_ticks = 6; } diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index 17a2aaa2..dc699288 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -7,6 +7,7 @@ #include "../common.h" #include "../netmessage.h" +#include "../chatlog.hpp" #include "../hack.h" #include "ucccccp.hpp" #include "hookedmethods.h" @@ -411,36 +412,35 @@ bool DispatchUserMessage_hook(void* _this, int type, bf_read& buf) { static const DispatchUserMessage_t original = (DispatchUserMessage_t)hooks::client.GetMethod(offsets::DispatchUserMessage()); SEGV_BEGIN; - if (clean_chat || crypt_chat) { - if (type == 4) { - loop_index = 0; - s = buf.GetNumBytesLeft(); - if (s < 256) { - data = (char*)alloca(s); - for (i = 0; i < s; i++) - data[i] = buf.ReadByte(); - j = 0; - std::string name; - std::string message; - for (i = 0; i < 3; i++) { - while ((c = data[j++]) && (loop_index < 128)) { - loop_index++; - if (clean_chat) - if ((c == '\n' || c == '\r') && (i == 1 || i == 2)) data[j - 1] = '*'; - if (i == 1) name.push_back(c); - if (i == 2) message.push_back(c); - } + if (type == 4) { + loop_index = 0; + s = buf.GetNumBytesLeft(); + if (s < 256) { + data = (char*)alloca(s); + for (i = 0; i < s; i++) + data[i] = buf.ReadByte(); + j = 0; + std::string name; + std::string message; + for (i = 0; i < 3; i++) { + while ((c = data[j++]) && (loop_index < 128)) { + loop_index++; + if (clean_chat) + if ((c == '\n' || c == '\r') && (i == 1 || i == 2)) data[j - 1] = '*'; + if (i == 1) name.push_back(c); + if (i == 2) message.push_back(c); } - if (crypt_chat) { - if (message.find("!!") == 0) { - if (ucccccp::validate(message)) { - PrintChat("\x07%06X%s\x01: %s", 0xe05938, name.c_str(), ucccccp::decrypt(message).c_str()); - } - } - } - buf = bf_read(data, s); - buf.Seek(0); } + if (crypt_chat) { + if (message.find("!!") == 0) { + if (ucccccp::validate(message)) { + PrintChat("\x07%06X%s\x01: %s", 0xe05938, name.c_str(), ucccccp::decrypt(message).c_str()); + } + } + } + chatlog::LogMessage(data[0], message); + buf = bf_read(data, s); + buf.Seek(0); } } if (dispatch_log) {