diff --git a/makefile b/makefile index c9768453..58660df2 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,8 @@ CXX=g++ CXXFLAGS=-std=gnu++14 -D_POSIX=1 -DRAD_TELEMETRY_DISABLED -DLINUX=1 -D_LINUX=1 -DPOSIX=1 -DGNUC=1 -D_DEVELOPER=1 -DNO_MALLOC_OVERRIDE -O3 -g3 -ggdb -w -shared -Wall -Wno-unknown-pragmas -fmessage-length=0 -m32 -fvisibility=hidden -fPIC SDKFOLDER=$(realpath source-sdk-2013/mp/src) -INCLUDES=-I$(SDKFOLDER)/public -I$(SDKFOLDER)/mathlib -I$(SDKFOLDER)/common -I$(SDKFOLDER)/public/tier1 -I$(SDKFOLDER)/public/tier0 -I$(SDKFOLDER) +SIMPLE_IPC_DIR = $(realpath simple-ipc/src/include) +INCLUDES=-I$(SIMPLE_IPC_DIR) -I$(SDKFOLDER)/public -I$(SDKFOLDER)/mathlib -I$(SDKFOLDER)/common -I$(SDKFOLDER)/public/tier1 -I$(SDKFOLDER)/public/tier0 -I$(SDKFOLDER) CXXFLAGS += $(INCLUDES) LIB_DIR=lib LDFLAGS=-m32 -fno-gnu-unique -D_GLIBCXX_USE_CXX11_ABI=0 -shared -L$(realpath $(LIB_DIR)) @@ -10,7 +11,6 @@ SRC_DIR = src OUT_NAME = libcathook.so TARGET_DIR = bin TARGET = $(TARGET_DIR)/$(OUT_NAME) -SIMPLE_IPC_DIR = simple-ipc/src/include SOURCES = $(shell find $(SRC_DIR) -name "*.cpp" -print) SOURCES += $(shell find $(SIMPLE_IPC_DIR) -name "*.cpp" -print) OBJECTS = $(SOURCES:.cpp=.o) diff --git a/simple-ipc b/simple-ipc index 6cf552a0..70ce7ced 160000 --- a/simple-ipc +++ b/simple-ipc @@ -1 +1 @@ -Subproject commit 6cf552a0bb36e5598406696a02970fcfff10ea75 +Subproject commit 70ce7ced4e982292410df783967ab486290e7865 diff --git a/src/hack.cpp b/src/hack.cpp index 21ec90c3..d09831d4 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -53,6 +53,11 @@ bool hack::shutdown = false; +std::stack& hack::command_stack() { + static std::stack stack; + return stack; +} + void hack::InitHacks() { } @@ -157,6 +162,9 @@ void hack::Initialize() { if (TF2) g_GlowObjectManager = *reinterpret_cast(gSignatures.GetClientSignature("C1 E0 05 03 05") + 5); InitStrings(); hacks::shared::killsay::Init(); + hack::command_stack().push("exec cat_autoexec"); + hack::command_stack().push("cat_killsay_reload"); + hack::command_stack().push("cat_spam_reload"); logging::Info("Init done."); } diff --git a/src/hack.h b/src/hack.h index ac6eea5a..07254f2e 100644 --- a/src/hack.h +++ b/src/hack.h @@ -15,8 +15,15 @@ class bf_read; class ConCommand; class CCommand; +#include "beforecheaders.h" +#include +#include +#include "aftercheaders.h" + namespace hack { +std::stack& command_stack(); + extern bool shutdown; void Initialize(); diff --git a/src/hacks/FollowBot.h b/src/hacks/FollowBot.h index 2056d64a..65b8f26b 100644 --- a/src/hacks/FollowBot.h +++ b/src/hacks/FollowBot.h @@ -8,8 +8,10 @@ #ifndef HACKS_FOLLOWBOT_H_ #define HACKS_FOLLOWBOT_H_ +namespace hacks { namespace shared { namespace followbot { +}}} #endif /* HACKS_FOLLOWBOT_H_ */ diff --git a/src/hooks/PaintTraverse.cpp b/src/hooks/PaintTraverse.cpp index 318dfdea..407c5933 100644 --- a/src/hooks/PaintTraverse.cpp +++ b/src/hooks/PaintTraverse.cpp @@ -39,19 +39,16 @@ void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) { if (call_default) SAFE_CALL(((PaintTraverse_t*)hooks::hkPanel->GetMethod(hooks::offPaintTraverse))(p, vp, fr, ar)); + // To avoid threading problems. + while (!hack::command_stack().empty()) { + g_IEngine->ExecuteClientCmd(hack::command_stack().top().c_str()); + hack::command_stack().pop(); + } PROF_SECTION(PaintTraverse); if (vp == panel_top) draw_flag = true; if (!cathook) return; // Because of single-multi thread shit I'm gonna put this thing riiiight here. - static bool autoexec_done = false; - if (!autoexec_done) { - g_IEngine->ExecuteClientCmd("exec cat_autoexec"); - g_IEngine->ExecuteClientCmd("cat_killsay_reload"); - g_IEngine->ExecuteClientCmd("cat_spam_reload"); - autoexec_done = true; - } - if (!panel_top) { const char* name = g_IPanel->GetName(vp); if (strlen(name) > 4) { diff --git a/src/ipc.cpp b/src/ipc.cpp new file mode 100644 index 00000000..059d7870 --- /dev/null +++ b/src/ipc.cpp @@ -0,0 +1,54 @@ +/* + * ipc.cpp + * + * Created on: Mar 19, 2017 + * Author: nullifiedcat + */ + +#include "ipc.h" + +#include "common.h" + +namespace ipc { + +void CommandCallback(cat_ipc::command_s& command, void* payload) { + if (!strcmp("exec", (const char*)command.cmd_data) && payload) { + hack::command_stack().push(std::string((const char*)payload)); + } +} + +CatCommand connect("ipc_connect", "Connect to IPC server", []() { + if (peer) { + logging::Info("Already connected!"); + return; + } + peer = new peer_t(std::string(server_name.GetString()), false, false); + peer->Connect(); + peer->SetCallback(CommandCallback); + StoreClientData(); +}); +CatCommand disconnect("ipc_disconnect", "Disconnect from IPC server", []() { + if (peer) delete peer; + peer = nullptr; +}); +CatCommand exec("ipc_exec", "Execute command (first argument = bot ID)", [](const CCommand& args) { + unsigned target_id = atoi(args.Arg(1)); + std::string command = std::string(args.ArgS()); + command = command.substr(command.find(' ', 0) + 1); + peer->SendMessage("exec", (1 << target_id), command.c_str(), command.length() + 1); +}); +CatCommand exec_all("ipc_exec_all", "Execute command (on every peer)", [](const CCommand& args) { + peer->SendMessage("exec", 0, args.ArgS(), strlen(args.ArgS()) + 1); +}); +CatVar server_name(CV_STRING, "ipc_server", "cathook_ipc_server", "IPC server name"); + +peer_t* peer { nullptr }; + +void StoreClientData() { + peer_t::MutexLock lock; + user_data_s& data = peer->memory->peer_user_data[peer->client_id]; + data.friendid = g_ISteamUser->GetSteamID().GetAccountID(); + strncpy(data.name, g_ISteamFriends->GetPersonaName(), sizeof(data.name)); +} + +} diff --git a/src/ipc.h b/src/ipc.h new file mode 100644 index 00000000..34a1db27 --- /dev/null +++ b/src/ipc.h @@ -0,0 +1,41 @@ +/* + * ipc.h + * + * Created on: Mar 19, 2017 + * Author: nullifiedcat + */ + +#ifndef IPC_H_ +#define IPC_H_ + +#include "ipcb.hpp" + +class CatCommand; +class CatVar; + +namespace ipc { + +extern CatCommand connect; +extern CatCommand disconnect; +extern CatCommand exec; +extern CatCommand exec_all; +extern CatVar server_name; + +using peer_t = cat_ipc::Peer; + +struct server_data_s { + bool dummy; +}; + +struct user_data_s { + char name[32]; + unsigned friendid; +}; + +extern peer_t* peer; + +void StoreClientData(); + +} + +#endif /* IPC_H_ */