From a8a8c30543d7cc9d25ccddc18787554f16fdcf20 Mon Sep 17 00:00:00 2001 From: aMannus Date: Wed, 21 May 2025 22:59:59 +0200 Subject: [PATCH 1/2] Implement hook for archipelago --- .../GameInteractor_HookTable.h | 2 ++ .../game-interactor/GameInteractor_Hooks.cpp | 6 ++++++ .../game-interactor/GameInteractor_Hooks.h | 3 +++ .../Enhancements/randomizer/hook_handlers.cpp | 5 +++++ soh/soh/Network/Archipelago/Archipelago.cpp | 20 ++++++++++++++++++- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h b/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h index e70c0d33e..40f633ada 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h @@ -69,3 +69,5 @@ DEFINE_HOOK(OnSetGameLanguage, ()); DEFINE_HOOK(OnFileDropped, (std::string filePath)); DEFINE_HOOK(OnAssetAltChange, ()); DEFINE_HOOK(OnKaleidoUpdate, ()); + +DEFINE_HOOK(OnRandomizerItemGivenHooks, (uint32_t rc)); diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp index 08f2660dd..677b7dae0 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp @@ -301,3 +301,9 @@ void GameInteractor_RegisterOnAssetAltChange(void (*fn)(void)) { void GameInteractor_ExecuteOnKaleidoUpdate() { GameInteractor::Instance->ExecuteHooks(); } + +// Mark: Randomizer + +void GameInteractor_ExecuteOnRandomizerItemGivenHooks(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 cd8e7962e..7d2893841 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h @@ -81,6 +81,9 @@ void GameInteractor_RegisterOnAssetAltChange(void (*fn)(void)); // Mark: - Pause Menu void GameInteractor_ExecuteOnKaleidoUpdate(); +// Mark: - Randomizer +void GameInteractor_ExecuteOnRandomizerItemGivenHooks(uint32_t rc); + #ifdef __cplusplus } #endif diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index 6689e3e0a..f02d275e3 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -346,6 +346,8 @@ void RandomizerOnPlayerUpdateForRCQueueHandler() { } } + GameInteractor_ExecuteOnRandomizerItemGivenHooks((uint32_t)rc); + randomizerQueuedChecks.pop(); } @@ -2408,6 +2410,9 @@ void RandomizerRegisterHooks() { GameInteractor::Instance->RegisterGameHook([](int32_t fileNum) { ShipInit::Init("IS_RANDO"); + // Add condition around this to only fire when loading into an Archipelago save file + ShipInit::Init("IS_ARCHIPELAGO"); + randomizerQueuedChecks = std::queue(); randomizerQueuedCheck = RC_UNKNOWN_CHECK; randomizerQueuedItemEntry = GET_ITEM_NONE; diff --git a/soh/soh/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index d603cd1d7..d0449f034 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -11,6 +11,7 @@ #include "soh/Enhancements/randomizer/randomizerTypes.h" #include "soh/Enhancements/randomizer/static_data.h" #include "soh/Enhancements/game-interactor/GameInteractor.h" +#include "soh/ShipInit.hpp" ArchipelagoClient::ArchipelagoClient() { std::string uuid = ap_get_uuid("uuid"); @@ -115,7 +116,7 @@ void ArchipelagoClient::CheckLocation(RandomizerCheck SoH_check_id) { std::string logMessage = "[LOG] Checked: " + ap_name + "(" + std::to_string(ap_item_id) + "), sending to AP server"; ArchipelagoConsole_SendMessage(logMessage.c_str()); -// currently not sending, because i only get so many real chances + // currently not sending, because i only get so many real chances if(!IsConnected()) { return; } @@ -199,3 +200,20 @@ const char* ArchipelagoClient::GetConnectionStatus() { return ""; } } + +// Implement this properly once we have some kind of indication within a save file wether the player is in a normal +// rando save or an archipelago one. +#define IS_ARCHIPELAGO true + +void RegisterArchipelago() { + COND_HOOK(GameInteractor::OnRandomizerItemGivenHooks, IS_ARCHIPELAGO, + [](uint32_t rc) { + if (rc == RC_ARCHIPELAGO_RECIEVED_ITEM) { + // Update lastReceivedIndex + } else { + ArchipelagoClient::GetInstance().CheckLocation((RandomizerCheck)rc); + } + }); +} + +static RegisterShipInitFunc initFunc(RegisterArchipelago, { "IS_ARCHIPELAGO" }); From 1510c23684d8f8afbae102a06ac8e8672ac2dbe5 Mon Sep 17 00:00:00 2001 From: aMannus Date: Wed, 21 May 2025 23:14:30 +0200 Subject: [PATCH 2/2] Remove duplicate location sending --- soh/soh/Enhancements/randomizer/hook_handlers.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index f02d275e3..c3a0a37ca 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -382,13 +382,6 @@ void RandomizerOnItemReceiveHandler(GetItemEntry receivedItemEntry) { SPDLOG_INFO("Item received mod {} item {} from RC {}", receivedItemEntry.modIndex, receivedItemEntry.itemId, static_cast(randomizerQueuedCheck)); - // todo maybe move to seperate function - // let arhipelago know we got this check - if(randomizerQueuedCheck != RC_ARCHIPELAGO_RECIEVED_ITEM) { - ArchipelagoClient& ap_client = ArchipelagoClient::GetInstance(); - ap_client.CheckLocation(randomizerQueuedCheck); - } - loc->SetCheckStatus(RCSHOW_COLLECTED); CheckTracker::SpoilAreaFromCheck(randomizerQueuedCheck); CheckTracker::RecalculateAllAreaTotals();