diff --git a/src/chatlog.cpp b/src/chatlog.cpp index e8f52076..e3d98aa3 100644 --- a/src/chatlog.cpp +++ b/src/chatlog.cpp @@ -37,7 +37,7 @@ public: stream.open("cathook/chat-" + uname + ".log", std::ios::out | std::ios::app); } void log(const std::string& msg) { - if (stream.bad()) { + if (stream.bad() or not stream.is_open()) { logging::Info("[ERROR] RAIILog stream is bad!"); open(); return; diff --git a/src/hacks/Walkbot.cpp b/src/hacks/Walkbot.cpp index c614fd55..bd12d78e 100644 --- a/src/hacks/Walkbot.cpp +++ b/src/hacks/Walkbot.cpp @@ -939,21 +939,25 @@ void CheckLivingSpace() { } int count = 0; unsigned highest = 0; + std::vector botlist {}; for (unsigned i = 1; i < cat_ipc::max_peers; i++) { if (!ipc::peer->memory->peer_data[i].free) { for (auto& k : players) { if (ipc::peer->memory->peer_user_data[i].friendid && k == ipc::peer->memory->peer_user_data[i].friendid) { + botlist.push_back(i); count++; highest = i; } } } } - if (ipc::peer->client_id != highest) return; - if (count > int(wb_abandon_too_many_bots)) { + if (ipc::peer->client_id == highest && count > int(wb_abandon_too_many_bots)) { static Timer timer {}; if (timer.test_and_set(1000 * 5)) { - logging::Info("Found %d other bots in-game, abandoning.", count); + logging::Info("Found %d other bots in-game, abandoning (%u)", count, ipc::peer->client_id); + for (auto i : botlist) { + logging::Info("-> Bot %d with ID %u", i, ipc::peer->memory->peer_user_data[i].friendid); + } g_TFGCClientSystem->SendExitMatchmaking(true); } } diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index 068e230f..8e15b48e 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -311,9 +311,22 @@ bool StolenName(){ return false; } +static CatVar ipc_name(CV_STRING, "name_ipc", "", "IPC Name"); + const char* GetFriendPersonaName_hook(ISteamFriends* _this, CSteamID steamID) { static const GetFriendPersonaName_t original = (GetFriendPersonaName_t)hooks::steamfriends.GetMethod(offsets::GetFriendPersonaName()); +#if IPC_ENABLED + if (ipc::peer) { + static std::string namestr(ipc_name.GetString()); + namestr.assign(ipc_name.GetString()); + if (namestr.length() > 3) { + ReplaceString(namestr, "%%", std::to_string(ipc::peer->client_id)); + return namestr.c_str(); + } + } +#endif + // Check User settings if namesteal is allowed if (namesteal && steamID == g_ISteamUser->GetSteamID()) { @@ -390,8 +403,10 @@ void FrameStageNotify_hook(void* _this, int stage) { #if IPC_ENABLED static Timer ipc_timer {}; if (ipc_timer.test_and_set(1000)) { - if (ipc::peer) + if (ipc::peer) { + ipc::Heartbeat(); ipc::UpdateTemporaryData(); + } } #endif hacks::shared::autojoin::UpdateSearch(); diff --git a/src/ipc.cpp b/src/ipc.cpp index 3d4f2953..532348e1 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -170,6 +170,12 @@ void StoreClientData() { strncpy(data.name, g_ISteamFriends->GetPersonaName(), sizeof(data.name)); } + +void Heartbeat() { + user_data_s& data = peer->memory->peer_user_data[peer->client_id]; + data.heartbeat = time(nullptr); +} + static CatVar ipc_update_list(CV_SWITCH, "ipc_update_list", "1", "IPC Auto-Ignore", "Automaticly assign playerstates for bots"); void UpdatePlayerlist() { if (peer && ipc_update_list) { diff --git a/src/ipc.h b/src/ipc.h index 20619c6b..9a3b7254 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -13,6 +13,7 @@ #include "beforecheaders.h" #include "ipcb.hpp" #include "pthread.h" +#include #include "aftercheaders.h" class CatCommand; @@ -59,12 +60,14 @@ struct user_data_s { int score; int last_score; int total_score; + time_t heartbeat; }; using peer_t = cat_ipc::Peer; extern peer_t* peer; +void Heartbeat(); void UpdateTemporaryData(); void UpdateServerAddress(bool shutdown = false); void StoreClientData();