From d643b133cc55a1284ddb670f366bca68a50d1dd6 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Fri, 18 Aug 2017 12:30:25 +0300 Subject: [PATCH 1/6] delete extra IPC thread, update simple-ipc --- simple-ipc | 2 +- src/hooks/others.cpp | 3 +++ src/ipc.cpp | 21 +-------------------- src/ipc.h | 1 - 4 files changed, 5 insertions(+), 22 deletions(-) diff --git a/simple-ipc b/simple-ipc index 94b3e53b..98934e75 160000 --- a/simple-ipc +++ b/simple-ipc @@ -1 +1 @@ -Subproject commit 94b3e53b00ac5be465ebe44ea5fe1b1fbc18aa8f +Subproject commit 98934e7579ac276ba1a1972db3e1eb741c789068 diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index 21bb4b12..28ecfa6d 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -427,6 +427,9 @@ void FrameStageNotify_hook(void* _this, int stage) { static Timer ipc_timer {}; if (ipc_timer.test_and_set(1000)) { if (ipc::peer) { + if (ipc::peer->HasCommands()) { + ipc::peer->ProcessCommands(); + } ipc::Heartbeat(); ipc::UpdateTemporaryData(); } diff --git a/src/ipc.cpp b/src/ipc.cpp index 8a2bfcbb..eef2fa75 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -16,19 +16,6 @@ namespace ipc { -std::atomic thread_running(false); -pthread_t listener_thread { 0 }; - -void* listen(void*) { - while (thread_running) { - if (peer->HasCommands()) { - peer->ProcessCommands(); - } - usleep(10000); - } - return 0; -} - CatCommand fix_deadlock("ipc_fix_deadlock", "Fix deadlock", []() { if (peer) { pthread_mutex_unlock(&peer->memory->mutex); @@ -36,7 +23,7 @@ CatCommand fix_deadlock("ipc_fix_deadlock", "Fix deadlock", []() { }); CatCommand connect("ipc_connect", "Connect to IPC server", []() { - if (peer || thread_running) { + if (peer) { logging::Info("Already connected!"); return; } @@ -60,8 +47,6 @@ CatCommand connect("ipc_connect", "Connect to IPC server", []() { data.total_score = o_total_score; StoreClientData(); Heartbeat(); - thread_running = true; - pthread_create(&listener_thread, nullptr, listen, nullptr); } catch (std::exception& error) { logging::Info("Runtime error: %s", error.what()); delete peer; @@ -83,10 +68,7 @@ CatCommand lobby("ipc_lobby", "Join a lobby", [](const CCommand& args) { peer->SendMessage(format("connect_lobby ", lobby64).c_str(), 0, ipc::commands::execute_client_cmd, 0, 0); }); CatCommand disconnect("ipc_disconnect", "Disconnect from IPC server", []() { - thread_running = false; - pthread_join(listener_thread, nullptr); if (peer) delete peer; - listener_thread = 0; peer = nullptr; }); CatCommand exec("ipc_exec", "Execute command (first argument = bot ID)", [](const CCommand& args) { @@ -163,7 +145,6 @@ void UpdateServerAddress(bool shutdown) { s_addr = g_IEngine->GetNetChannelInfo()->GetAddress(); } - peer_t::MutexLock lock(peer); user_data_s& data = peer->memory->peer_user_data[peer->client_id]; data.friendid = g_ISteamUser->GetSteamID().GetAccountID(); strncpy(data.server, s_addr, sizeof(data.server)); diff --git a/src/ipc.h b/src/ipc.h index 6a5dc326..481d468f 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -39,7 +39,6 @@ extern CatCommand exec_all; extern CatCommand lobby; extern CatVar server_name; -extern pthread_t listener_thread; constexpr unsigned cathook_magic_number = 0x0DEADCA7; struct server_data_s { From ae9a1df287a6adfa79a3ef67c91b6993cea0e13b Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Fri, 18 Aug 2017 12:43:38 +0300 Subject: [PATCH 2/6] update sources to reflect changes in makefile --- .cproject | 2 +- src/common.h | 4 ++-- src/drawmgr.cpp | 2 +- src/gui/im/Schema.cpp | 2 +- src/hack.cpp | 2 +- src/hacks/AutoHeal.cpp | 2 +- src/hacks/ESP.cpp | 2 +- src/hacks/FollowBot.cpp | 2 +- src/hacks/FollowBot.h | 3 ++- src/hacks/Walkbot.cpp | 2 +- src/hooks/CreateMove.cpp | 8 ++++---- src/hooks/others.cpp | 11 ++++++----- src/ipc.cpp | 2 +- src/ipc.h | 2 +- 14 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.cproject b/.cproject index 186b5238..1bc6e9f1 100644 --- a/.cproject +++ b/.cproject @@ -66,7 +66,7 @@ - +