Skip to content

Commit 8a30ff3

Browse files
committed
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
1 parent c39f066 commit 8a30ff3

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/Features/NetMessage.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// if orange: whether we've sent the ready packet
2323
bool g_orangeReady = false;
2424
bool g_partnerHasSAR = false;
25+
bool g_session_init = false;
2526

2627
static size_t g_expected_len = 0;
2728
static std::string g_partial;
@@ -58,9 +59,20 @@ static bool readyToSend() {
5859
}
5960
}
6061

62+
void NetMessage::SessionStarted() {
63+
if (engine->IsCoop() && !engine->IsSplitscreen()) {
64+
if (!g_session_init && engine->IsOrange()) {
65+
g_session_init = true;
66+
engine->ExecuteCommand("say \"" SAR_MSG_HELLO "\"");
67+
}
68+
} else {
69+
g_session_init = false;
70+
g_partnerHasSAR = false;
71+
}
72+
}
73+
6174
void NetMessage::SessionEnded() {
6275
g_orangeReady = false;
63-
g_partnerHasSAR = false;
6476
}
6577

6678
struct QueuedMsg {
@@ -162,8 +174,8 @@ void NetMessage::SendMsg(const char *type, const void *data, size_t size) {
162174
return;
163175
}
164176

165-
// If the partner doesn't have SAR, only send sync messages
166-
if (!readyToSend() || (!g_partnerHasSAR && !!strcmp(type, "__sync"))) {
177+
// If the partner doesn't have SAR, don't send messages
178+
if (!readyToSend() || !g_partnerHasSAR) {
167179
g_queued.push({
168180
std::string(type),
169181
std::vector<uint8_t>((const uint8_t *)data, (const uint8_t *)data + size),
@@ -229,6 +241,19 @@ void NetMessage::Update() {
229241
bool NetMessage::ChatData(std::string str) {
230242
if (str.size() < 4) return false;
231243

244+
if (str == SAR_MSG_HELLO) {
245+
if (!engine->IsOrange()) {
246+
g_partnerHasSAR = true;
247+
engine->ExecuteCommand("say \"" SAR_MSG_HELLO_ACK "\"");
248+
}
249+
return true;
250+
} else if (str == SAR_MSG_HELLO_ACK) {
251+
if (engine->IsOrange()) {
252+
g_partnerHasSAR = true;
253+
}
254+
return true;
255+
}
256+
232257
std::string prefix = str.substr(0, 4);
233258
bool has_prefix = true;
234259
bool cont, orange;

src/Features/NetMessage.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
extern bool g_orangeReady;
77
extern bool g_partnerHasSAR;
88

9+
#define SAR_MSG_HELLO "Hello! I have \x07SourceAutoRecord\x07, a plugin mainly used for speedrunning."
10+
#define SAR_MSG_HELLO_ACK "&^@$Yes hello I also have \x07SourceAutoRecord\x07 thank you for checking before spamming chat."
11+
912
namespace NetMessage {
1013
void RegisterHandler(const char *type, void (*handler)(const void *data, size_t size));
1114
void SendMsg(const char *type, const void *data, size_t size);
1215
bool ChatData(std::string str);
1316
void Update();
17+
void SessionStarted();
1418
void SessionEnded();
1519
}; // namespace NetMessage

src/Features/Session.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ void Session::Started(bool menu) {
7171
return;
7272
}
7373

74+
NetMessage::SessionStarted();
75+
7476
if (menu) {
7577
console->Print("Session started! (menu)\n");
7678
this->Rebase(engine->GetTick());

src/Modules/Server.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,10 @@ CON_COMMAND(sar_give_betsrighter, "sar_give_betsrighter [n] - gives the player i
10711071
}
10721072
DETOUR_COMMAND(Server::say) {
10731073
auto clientidx = UTIL_GetCommandClientIndex();
1074-
if (args.ArgC() != 2 || Utils::StartsWith(args[1], "&^") || !networkManager.HandleGhostSay(args[1], clientidx)) {
1074+
if (args.ArgC() != 2 ||
1075+
Utils::StartsWith(args[1], "&^") ||
1076+
!strcmp(args[1], "\"" SAR_MSG_HELLO "\"") ||
1077+
!networkManager.HandleGhostSay(args[1], clientidx)) {
10751078
g_wasChatType = 0;
10761079
Server::say_callback(args);
10771080
}

0 commit comments

Comments
 (0)