From 114f53beb3c7a97cb80984cc8018e87a7abdcbbd Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Fri, 24 Mar 2017 19:30:32 +0300 Subject: [PATCH] updated IPC --- simple-ipc | 2 +- src/hacks/FollowBot.cpp | 9 ++++++++- src/hacks/FollowBot.h | 3 +++ src/ipc.cpp | 19 ++++++++++++++----- src/ipc.h | 10 ++++++++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/simple-ipc b/simple-ipc index eccb7cc4..b1283901 160000 --- a/simple-ipc +++ b/simple-ipc @@ -1 +1 @@ -Subproject commit eccb7cc43302b1c391b431d4415a7cdaf043fe6b +Subproject commit b12839017432cb2bf9125f969c47edc3bc7a4b71 diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index e6b2a470..9ae3e8ff 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -17,10 +17,17 @@ float lost_time { 0 }; float idle_time { 0 }; int following_idx { 0 }; +void AddMessageHandlers(ipc::peer_t* peer) { + peer->SetCommandHandler(ipc::commands::set_follow_steamid, [](cat_ipc::command_s& command, void* payload) { + logging::Info("IPC Message: now following %ld", *(unsigned*)&command.cmd_data); + hacks::shared::followbot::follow_steamid = *(unsigned*)&command.cmd_data; + }); +} + CatCommand follow_me("fb_follow_me", "Makes all bots follow you", []() { if (ipc::peer) { unsigned id = g_ISteamUser->GetSteamID().GetAccountID(); - ipc::peer->SendMessage("owner", 0, &id, sizeof(id)); + ipc::peer->SendMessage((const char*)&id, 0, ipc::commands::set_follow_steamid, 0, 0); } }); diff --git a/src/hacks/FollowBot.h b/src/hacks/FollowBot.h index 112b794e..98f49045 100644 --- a/src/hacks/FollowBot.h +++ b/src/hacks/FollowBot.h @@ -11,6 +11,8 @@ class CatCommand; class CatVar; +#include "../ipc.h" + namespace hacks { namespace shared { namespace followbot { extern CatCommand move_to_crosshair; @@ -23,6 +25,7 @@ extern int following_idx; void DoWalking(); void PrintDebug(); +void AddMessageHandlers(ipc::peer_t* peer); }}} diff --git a/src/ipc.cpp b/src/ipc.cpp index df41ce03..926c4738 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -17,8 +17,6 @@ void CommandCallback(cat_ipc::command_s& command, void* payload) { //std::lock_guard lock(hack::command_stack_mutex); hack::command_stack().push(std::string((const char*)payload)); } else if (!strcmp("owner", (const char*)command.cmd_data) && payload) { - logging::Info("Bot owner set to %ld", *(unsigned*)payload); - hacks::shared::followbot::follow_steamid = *(unsigned*)payload; } } @@ -52,7 +50,7 @@ CatCommand connect("ipc_connect", "Connect to IPC server", []() { logging::Info("peer count: %i", peer->memory->peer_count); logging::Info("magic number: 0x%08x", peer->memory->global_data.magic_number); logging::Info("magic number offset: 0x%08x", (uintptr_t)&peer->memory->global_data.magic_number - (uintptr_t)peer->memory); - peer->SetCallback(CommandCallback); + hacks::shared::followbot::AddMessageHandlers(peer); StoreClientData(); thread_running = true; pthread_create(&listener_thread, nullptr, listen, nullptr); @@ -87,10 +85,21 @@ CatCommand exec("ipc_exec", "Execute command (first argument = bot ID)", [](cons } 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); + ReplaceString(command, " && ", " ; "); + if (command.length() >= 63) { + peer->SendMessage(0, (1 << target_id), ipc::commands::execute_client_cmd_long, command.c_str(), command.length() + 1); + } else { + peer->SendMessage(command.c_str(), (1 << target_id), ipc::commands::execute_client_cmd, 0, 0); + } }); CatCommand exec_all("ipc_exec_all", "Execute command (on every peer)", [](const CCommand& args) { - peer->SendMessage("exec", 0, args.ArgS(), strlen(args.ArgS()) + 1); + std::string command = args.ArgS(); + ReplaceString(command, " && ", " ; "); + if (command.length() >= 63) { + peer->SendMessage(0, 0, ipc::commands::execute_client_cmd_long, command.c_str(), command.length() + 1); + } else { + peer->SendMessage(command.c_str(), 0, ipc::commands::execute_client_cmd, 0, 0); + } }); CatVar server_name(CV_STRING, "ipc_server", "cathook_followbot_server", "IPC server name"); diff --git a/src/ipc.h b/src/ipc.h index 464cf9aa..0a24c99f 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -8,14 +8,24 @@ #ifndef IPC_H_ #define IPC_H_ +#include "beforecheaders.h" #include "ipcb.hpp" #include "pthread.h" +#include "aftercheaders.h" class CatCommand; class CatVar; namespace ipc { +namespace commands { + +constexpr unsigned execute_client_cmd = 1; +constexpr unsigned set_follow_steamid = 2; +constexpr unsigned execute_client_cmd_long = 3; + +} + extern CatCommand connect; extern CatCommand disconnect; extern CatCommand exec;