IPC exec commands
This commit is contained in:
parent
0945d278ad
commit
d860d7d516
4
makefile
4
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)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 6cf552a0bb36e5598406696a02970fcfff10ea75
|
||||
Subproject commit 70ce7ced4e982292410df783967ab486290e7865
|
@ -53,6 +53,11 @@
|
||||
|
||||
bool hack::shutdown = false;
|
||||
|
||||
std::stack<std::string>& hack::command_stack() {
|
||||
static std::stack<std::string> stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
void hack::InitHacks() {
|
||||
}
|
||||
|
||||
@ -157,6 +162,9 @@ void hack::Initialize() {
|
||||
if (TF2) g_GlowObjectManager = *reinterpret_cast<CGlowObjectManager**>(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.");
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,15 @@ class bf_read;
|
||||
class ConCommand;
|
||||
class CCommand;
|
||||
|
||||
#include "beforecheaders.h"
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include "aftercheaders.h"
|
||||
|
||||
namespace hack {
|
||||
|
||||
std::stack<std::string>& command_stack();
|
||||
|
||||
extern bool shutdown;
|
||||
|
||||
void Initialize();
|
||||
|
@ -8,8 +8,10 @@
|
||||
#ifndef HACKS_FOLLOWBOT_H_
|
||||
#define HACKS_FOLLOWBOT_H_
|
||||
|
||||
namespace hacks { namespace shared { namespace followbot {
|
||||
|
||||
|
||||
|
||||
}}}
|
||||
|
||||
#endif /* HACKS_FOLLOWBOT_H_ */
|
||||
|
@ -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) {
|
||||
|
54
src/ipc.cpp
Normal file
54
src/ipc.cpp
Normal file
@ -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));
|
||||
}
|
||||
|
||||
}
|
41
src/ipc.h
Normal file
41
src/ipc.h
Normal file
@ -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<server_data_s, user_data_s>;
|
||||
|
||||
struct server_data_s {
|
||||
bool dummy;
|
||||
};
|
||||
|
||||
struct user_data_s {
|
||||
char name[32];
|
||||
unsigned friendid;
|
||||
};
|
||||
|
||||
extern peer_t* peer;
|
||||
|
||||
void StoreClientData();
|
||||
|
||||
}
|
||||
|
||||
#endif /* IPC_H_ */
|
Reference in New Issue
Block a user