From ea95ca0a9a0747ba83efcfa53af08c2a17ea6933 Mon Sep 17 00:00:00 2001 From: Jerom Venneker Date: Fri, 23 May 2025 19:28:42 +0200 Subject: [PATCH] Enabled Connecting and check synching when already in game --- soh/soh/Network/Archipelago/Archipelago.cpp | 36 +++++++++++++++------ soh/soh/Network/Archipelago/Archipelago.h | 2 ++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/soh/soh/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index fc8252e59..7a5b4bd47 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -62,6 +62,13 @@ bool ArchipelagoClient::StartClient() { apClient->set_slot_connected_handler([&](const nlohmann::json) { ArchipelagoConsole_SendMessage("[LOG] Connected.", false); ArchipelagoClient::StartLocationScouts(); + + // if we are already in game when we connect + // we won't have to request an itemSynch + if(GameInteractor::IsSaveLoaded(true)) { + SynchSentLocations(); + SynchRecievedLocations(); + } }); apClient->set_items_received_handler([&](const std::list& items) { @@ -101,15 +108,21 @@ bool ArchipelagoClient::StartClient() { } void ArchipelagoClient::GameLoaded() { - // if its not an AP save, disconnect - if(!IS_ARCHIPELAGO) { - if(apClient != nullptr) { - apClient->reset(); - } + if(apClient == nullptr) { return; } + // if its not an AP save, disconnect + if(!IS_ARCHIPELAGO) { + apClient->reset(); + return; + } + + ArchipelagoConsole_SendMessage("[LOG] Synching Items and Locations."); + SynchItems(); + SynchSentLocations(); + SynchRecievedLocations(); } void ArchipelagoClient::StartLocationScouts() { @@ -126,8 +139,12 @@ void ArchipelagoClient::StartLocationScouts() { } void ArchipelagoClient::SynchItems() { - ArchipelagoConsole_SendMessage("[LOG] Synching Items and Locations."); + // Send a Synch request to get any items we may have missed + ArchipelagoConsole_SendMessage("[LOG] Sending synch request"); + apClient->Sync(); +} +void ArchipelagoClient::SynchSentLocations() { // send already checked locations std::list checkedLocations; for(const auto& loc : Rando::StaticData::GetLocationTable()) { @@ -141,14 +158,13 @@ void ArchipelagoClient::SynchItems() { ArchipelagoConsole_SendMessage(locationLog.c_str()); apClient->LocationChecks(checkedLocations); +} + +void ArchipelagoClient::SynchRecievedLocations() { // Open checks that have been found previously but went unsaved for(const int64_t apLoc : apClient->get_checked_locations()) { // TODO call location checked function to open any unopened checks. } - - // Send a Synch request to get any items we may have missed - ArchipelagoConsole_SendMessage("[LOG] Sending synch request"); - apClient->Sync(); } bool ArchipelagoClient::IsConnected() { diff --git a/soh/soh/Network/Archipelago/Archipelago.h b/soh/soh/Network/Archipelago/Archipelago.h index cb05fe849..6967d7e14 100644 --- a/soh/soh/Network/Archipelago/Archipelago.h +++ b/soh/soh/Network/Archipelago/Archipelago.h @@ -33,6 +33,8 @@ class ArchipelagoClient{ void GameLoaded(); void StartLocationScouts(); void SynchItems(); + void SynchSentLocations(); + void SynchRecievedLocations(); // getters const std::string GetSlotName() const;