diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h b/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h index 6066c906c..c0c3672da 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h @@ -71,4 +71,5 @@ DEFINE_HOOK(OnAssetAltChange, ()); DEFINE_HOOK(OnKaleidoUpdate, ()); DEFINE_HOOK(OnRandomizerItemGivenHooks, (uint32_t rc)); -DEFINE_HOOK(OnArchipelagoItemRecieved, (uint32_t rc)); +DEFINE_HOOK(OnArchipelagoItemRecieved, (uint32_t rg)); +DEFINE_HOOK(OnRandomizerExternalCheck, (uint32_t rc)); diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp index c1bc5e17d..393df5b2c 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp @@ -309,6 +309,10 @@ void GameInteractor_ExecuteOnRandomizerItemGivenHooks(uint32_t rc) { } // MARK: Archipelago -void GameInteractor_ExecuteOnArchipelagoItemRecieved(uint32_t rc) { - GameInteractor::Instance->ExecuteHooks(rc); +void GameInteractor_ExecuteOnArchipelagoItemRecieved(uint32_t rg) { + GameInteractor::Instance->ExecuteHooks(rg); +} + +void GameInteractor_ExecuteOnRandomizerExternalCheck(uint32_t rc) { + GameInteractor::Instance->ExecuteHooks(rc); } diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h index 8a1f13608..da276455a 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h @@ -85,7 +85,8 @@ void GameInteractor_ExecuteOnKaleidoUpdate(); void GameInteractor_ExecuteOnRandomizerItemGivenHooks(uint32_t rc); // Mark: - Archipelago -void GameInteractor_ExecuteOnArchipelagoItemRecieved(uint32_t rc); +void GameInteractor_ExecuteOnArchipelagoItemRecieved(uint32_t rg); +void GameInteractor_ExecuteOnRandomizerExternalCheck(uint32_t rc); #ifdef __cplusplus } diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index a9b209b7b..f21a59312 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -286,6 +286,10 @@ void RandomizerOnSceneFlagSetHandler(int16_t sceneNum, int16_t flagType, int16_t randomizerQueuedChecks.push(rc); } +void RandomizerOnExternalCheckHandler(uint32_t randomizerCheck) { + randomizerQueuedChecks.push(static_cast(randomizerCheck)); +} + static Vec3f spawnPos = { 0.0f, -999.0f, 0.0f }; void RandomizerOnPlayerUpdateForRCQueueHandler() { @@ -2525,9 +2529,8 @@ void RandomizerRegisterHooks() { onCuccoOrChickenHatchHook = GameInteractor::Instance->RegisterGameHook( RandomizerOnCuccoOrChickenHatch); - // TODO Implement propeerly when we can read what kind of game we're playing from the save file - COND_HOOK(GameInteractor::OnArchipelagoItemRecieved, IS_ARCHIPELAGO, ArchipelagoOnRecieveItem); + COND_HOOK(GameInteractor::OnRandomizerExternalCheck, IS_ARCHIPELAGO, RandomizerOnExternalCheckHandler) if (RAND_GET_OPTION(RSK_FISHSANITY) != RO_FISHSANITY_OFF) { OTRGlobals::Instance->gRandoContext->GetFishsanity()->InitializeFromSave(); diff --git a/soh/soh/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index 7f52b5a13..a33ea6a99 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -109,7 +109,9 @@ bool ArchipelagoClient::StartClient() { }); // todo maybe move these functions to a lambda, since they don't have to be static anymore apClient->set_location_checked_handler([&](const std::list locations) { - // todo implement me + for(const int64_t apLoc : locations) { + QueueExternalCheck(apLoc); + } }); return true; @@ -171,10 +173,16 @@ void ArchipelagoClient::SynchSentLocations() { 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. + QueueExternalCheck(apLoc); } } +void ArchipelagoClient::QueueExternalCheck(const int64_t apLocation) { + const std::string checkName = apClient->get_location_name(apLocation, AP_Client_consts::AP_GAME_NAME); + const uint32_t RC = static_cast(Rando::StaticData::locationNameToEnum[checkName]); + GameInteractor_ExecuteOnRandomizerExternalCheck(RC); +} + bool ArchipelagoClient::IsConnected() { return apClient->get_state() == APClient::State::SLOT_CONNECTED; } diff --git a/soh/soh/Network/Archipelago/Archipelago.h b/soh/soh/Network/Archipelago/Archipelago.h index e077125e7..9b517f6a2 100644 --- a/soh/soh/Network/Archipelago/Archipelago.h +++ b/soh/soh/Network/Archipelago/Archipelago.h @@ -49,6 +49,7 @@ class ArchipelagoClient{ void OnItemReceived(const ApItem apItem); void QueueItem(const ApItem item); + void QueueExternalCheck(int64_t apLocation); void SendGameWon();