From 8a30ff393132a65cb6ebc0b18c5e369d82800180 Mon Sep 17 00:00:00 2001 From: Jesse <69196954+ThisAMJ@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:32:58 +1000 Subject: [PATCH] feat: ultimate partner SAR detection orange says hello (plaintext but unlikely to be accidental lmao) blue receives, now knows orange has sar, sends acknowledgement back, now both players know they have sar this happens once per partnership, not every load --- src/Features/NetMessage.cpp | 31 ++++++++++++++++++++++++++++--- src/Features/NetMessage.hpp | 4 ++++ src/Features/Session.cpp | 2 ++ src/Modules/Server.cpp | 5 ++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Features/NetMessage.cpp b/src/Features/NetMessage.cpp index 50a1b351e..ba361149e 100644 --- a/src/Features/NetMessage.cpp +++ b/src/Features/NetMessage.cpp @@ -22,6 +22,7 @@ // if orange: whether we've sent the ready packet bool g_orangeReady = false; bool g_partnerHasSAR = false; +bool g_session_init = false; static size_t g_expected_len = 0; static std::string g_partial; @@ -58,9 +59,20 @@ static bool readyToSend() { } } +void NetMessage::SessionStarted() { + if (engine->IsCoop() && !engine->IsSplitscreen()) { + if (!g_session_init && engine->IsOrange()) { + g_session_init = true; + engine->ExecuteCommand("say \"" SAR_MSG_HELLO "\""); + } + } else { + g_session_init = false; + g_partnerHasSAR = false; + } +} + void NetMessage::SessionEnded() { g_orangeReady = false; - g_partnerHasSAR = false; } struct QueuedMsg { @@ -162,8 +174,8 @@ void NetMessage::SendMsg(const char *type, const void *data, size_t size) { return; } - // If the partner doesn't have SAR, only send sync messages - if (!readyToSend() || (!g_partnerHasSAR && !!strcmp(type, "__sync"))) { + // If the partner doesn't have SAR, don't send messages + if (!readyToSend() || !g_partnerHasSAR) { g_queued.push({ std::string(type), std::vector((const uint8_t *)data, (const uint8_t *)data + size), @@ -229,6 +241,19 @@ void NetMessage::Update() { bool NetMessage::ChatData(std::string str) { if (str.size() < 4) return false; + if (str == SAR_MSG_HELLO) { + if (!engine->IsOrange()) { + g_partnerHasSAR = true; + engine->ExecuteCommand("say \"" SAR_MSG_HELLO_ACK "\""); + } + return true; + } else if (str == SAR_MSG_HELLO_ACK) { + if (engine->IsOrange()) { + g_partnerHasSAR = true; + } + return true; + } + std::string prefix = str.substr(0, 4); bool has_prefix = true; bool cont, orange; diff --git a/src/Features/NetMessage.hpp b/src/Features/NetMessage.hpp index e9ff41474..742212a99 100644 --- a/src/Features/NetMessage.hpp +++ b/src/Features/NetMessage.hpp @@ -6,10 +6,14 @@ extern bool g_orangeReady; extern bool g_partnerHasSAR; +#define SAR_MSG_HELLO "Hello! I have \x07SourceAutoRecord\x07, a plugin mainly used for speedrunning." +#define SAR_MSG_HELLO_ACK "&^@$Yes hello I also have \x07SourceAutoRecord\x07 thank you for checking before spamming chat." + namespace NetMessage { void RegisterHandler(const char *type, void (*handler)(const void *data, size_t size)); void SendMsg(const char *type, const void *data, size_t size); bool ChatData(std::string str); void Update(); + void SessionStarted(); void SessionEnded(); }; // namespace NetMessage diff --git a/src/Features/Session.cpp b/src/Features/Session.cpp index 2920e0121..10055c5b6 100644 --- a/src/Features/Session.cpp +++ b/src/Features/Session.cpp @@ -71,6 +71,8 @@ void Session::Started(bool menu) { return; } + NetMessage::SessionStarted(); + if (menu) { console->Print("Session started! (menu)\n"); this->Rebase(engine->GetTick()); diff --git a/src/Modules/Server.cpp b/src/Modules/Server.cpp index bbdd9b1f6..161aec35e 100644 --- a/src/Modules/Server.cpp +++ b/src/Modules/Server.cpp @@ -1071,7 +1071,10 @@ CON_COMMAND(sar_give_betsrighter, "sar_give_betsrighter [n] - gives the player i } DETOUR_COMMAND(Server::say) { auto clientidx = UTIL_GetCommandClientIndex(); - if (args.ArgC() != 2 || Utils::StartsWith(args[1], "&^") || !networkManager.HandleGhostSay(args[1], clientidx)) { + if (args.ArgC() != 2 || + Utils::StartsWith(args[1], "&^") || + !strcmp(args[1], "\"" SAR_MSG_HELLO "\"") || + !networkManager.HandleGhostSay(args[1], clientidx)) { g_wasChatType = 0; Server::say_callback(args); }