cat_wb_split, cat_wb_duck, cat_chat_log
This commit is contained in:
parent
57595c6c11
commit
b185375f77
61
src/chatlog.cpp
Normal file
61
src/chatlog.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
src/chatlog.hpp
Normal file
14
src/chatlog.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* chatlog.hpp
|
||||||
|
*
|
||||||
|
* Created on: Jul 28, 2017
|
||||||
|
* Author: nullifiedcat
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace chatlog {
|
||||||
|
|
||||||
|
void LogMessage(int eid, std::string message);
|
||||||
|
|
||||||
|
}
|
@ -372,6 +372,28 @@ CatCommand c_select_node("wb_select", "Select node", []() {
|
|||||||
state::active_node = state::closest_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
|
// Deletes closest node and its connections
|
||||||
CatCommand c_delete_node("wb_delete", "Delete node", []() {
|
CatCommand c_delete_node("wb_delete", "Delete node", []() {
|
||||||
DeleteNode(state::closest_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);
|
a.unlink(state::closest_node);
|
||||||
});
|
});
|
||||||
// Updates duck flag on region of nodes (selected to closest)
|
// Toggles jump flag on closest node
|
||||||
// Updates a single closest node if no node is selected
|
CatCommand c_update_duck("wb_duck", "Toggle duck flag", []() {
|
||||||
CatCommand c_update_duck("wb_duck", "Update duck flags", []() {
|
if (not state::node_good(state::closest_node))
|
||||||
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)))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
index_t current = state::closest_node;
|
auto& n = state::nodes[state::closest_node];
|
||||||
|
|
||||||
do {
|
if (n.flags & NF_DUCK)
|
||||||
auto& n = state::nodes[current];
|
n.flags &= ~NF_DUCK;
|
||||||
if (g_pUserCmd->buttons & IN_DUCK)
|
else
|
||||||
n.flags |= NF_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));*/
|
|
||||||
});
|
});
|
||||||
// Toggles jump flag on closest node
|
// Toggles jump flag on closest node
|
||||||
CatCommand c_update_jump("wb_jump", "Toggle jump flag", []() {
|
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);
|
logging::Info("[wb] Reached node %u, moving to %u", state::last_node, state::active_node);
|
||||||
if (state::node_good(state::active_node)) {
|
if (state::node_good(state::active_node)) {
|
||||||
if (state::nodes[state::active_node].flags & NF_JUMP) {
|
if (state::nodes[state::active_node].flags & NF_JUMP) {
|
||||||
|
g_pUserCmd->buttons |= IN_DUCK;
|
||||||
g_pUserCmd->buttons |= IN_JUMP;
|
g_pUserCmd->buttons |= IN_JUMP;
|
||||||
jump_ticks = 6;
|
jump_ticks = 6;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../netmessage.h"
|
#include "../netmessage.h"
|
||||||
|
#include "../chatlog.hpp"
|
||||||
#include "../hack.h"
|
#include "../hack.h"
|
||||||
#include "ucccccp.hpp"
|
#include "ucccccp.hpp"
|
||||||
#include "hookedmethods.h"
|
#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());
|
static const DispatchUserMessage_t original = (DispatchUserMessage_t)hooks::client.GetMethod(offsets::DispatchUserMessage());
|
||||||
SEGV_BEGIN;
|
SEGV_BEGIN;
|
||||||
if (clean_chat || crypt_chat) {
|
if (type == 4) {
|
||||||
if (type == 4) {
|
loop_index = 0;
|
||||||
loop_index = 0;
|
s = buf.GetNumBytesLeft();
|
||||||
s = buf.GetNumBytesLeft();
|
if (s < 256) {
|
||||||
if (s < 256) {
|
data = (char*)alloca(s);
|
||||||
data = (char*)alloca(s);
|
for (i = 0; i < s; i++)
|
||||||
for (i = 0; i < s; i++)
|
data[i] = buf.ReadByte();
|
||||||
data[i] = buf.ReadByte();
|
j = 0;
|
||||||
j = 0;
|
std::string name;
|
||||||
std::string name;
|
std::string message;
|
||||||
std::string message;
|
for (i = 0; i < 3; i++) {
|
||||||
for (i = 0; i < 3; i++) {
|
while ((c = data[j++]) && (loop_index < 128)) {
|
||||||
while ((c = data[j++]) && (loop_index < 128)) {
|
loop_index++;
|
||||||
loop_index++;
|
if (clean_chat)
|
||||||
if (clean_chat)
|
if ((c == '\n' || c == '\r') && (i == 1 || i == 2)) data[j - 1] = '*';
|
||||||
if ((c == '\n' || c == '\r') && (i == 1 || i == 2)) data[j - 1] = '*';
|
if (i == 1) name.push_back(c);
|
||||||
if (i == 1) name.push_back(c);
|
if (i == 2) message.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) {
|
if (dispatch_log) {
|
||||||
|
Reference in New Issue
Block a user