diff --git a/soh/soh/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index 78bbad867f9..7bf185df21e 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -146,6 +146,9 @@ bool ArchipelagoClient::StartClient() { ResetQueue(); SynchSentLocations(); SynchReceivedLocations(); + if (gPlayState != nullptr) { + ArchipelagoClient::SetDataStorage("scene", gPlayState->sceneNum); + } } }); @@ -531,6 +534,21 @@ void ArchipelagoClient::ResetQueue() { std::swap(receiveQueue, empty); } +void ArchipelagoClient::OnSceneInit(uint16_t sceneNum) { + if (!ArchipelagoClient::IsConnected()) + return; + if (gPlayState == nullptr) + return; + ArchipelagoClient::SetDataStorage("scene", sceneNum); +} + +void ArchipelagoClient::SetDataStorage(const std::string& key, const nlohmann::json& value) const { + std::string full_key = + std::format("oot_soh_{}_{}_{}", key, apClient->get_team_number(), apClient->get_player_number()); + std::list operations = { { "replace", value } }; + apClient->Set(full_key, 0, false, operations); +} + bool ArchipelagoClient::slotMatch(const std::string& slotName, const std::string& roomHash) { if (apClient == nullptr) { return false; @@ -796,6 +814,10 @@ void RegisterArchipelago() { COND_HOOK(GameInteractor::OnPlayerDeath, IS_ARCHIPELAGO, []() { ArchipelagoClient::GetInstance().SendDeathLink(); }); -} + + COND_HOOK(GameInteractor::OnSceneInit, IS_ARCHIPELAGO, + [](int16_t sceneNum) { ArchipelagoClient::GetInstance().OnSceneInit(sceneNum); + }); + } static RegisterShipInitFunc initFunc(RegisterArchipelago, { "IS_ARCHIPELAGO" }); diff --git a/soh/soh/Network/Archipelago/Archipelago.h b/soh/soh/Network/Archipelago/Archipelago.h index 06f0318ff5a..25eecf702a1 100644 --- a/soh/soh/Network/Archipelago/Archipelago.h +++ b/soh/soh/Network/Archipelago/Archipelago.h @@ -68,6 +68,10 @@ class ArchipelagoClient { void Poll(); void ResetQueue(); + void OnSceneInit(uint16_t sceneNum); + + void SetDataStorage(const std::string& key, const nlohmann::json& value) const; + bool slotMatch(const std::string& slotName, const std::string& roomHash); std::unique_ptr apClient;