Implement hook for archipelago

This commit is contained in:
aMannus
2025-05-21 22:59:59 +02:00
parent 513684d9a2
commit a8a8c30543
5 changed files with 35 additions and 1 deletions

View File

@@ -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));

View File

@@ -301,3 +301,9 @@ void GameInteractor_RegisterOnAssetAltChange(void (*fn)(void)) {
void GameInteractor_ExecuteOnKaleidoUpdate() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnKaleidoUpdate>();
}
// Mark: Randomizer
void GameInteractor_ExecuteOnRandomizerItemGivenHooks(uint32_t rc) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnRandomizerItemGivenHooks>(rc);
}

View File

@@ -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

View File

@@ -346,6 +346,8 @@ void RandomizerOnPlayerUpdateForRCQueueHandler() {
}
}
GameInteractor_ExecuteOnRandomizerItemGivenHooks((uint32_t)rc);
randomizerQueuedChecks.pop();
}
@@ -2408,6 +2410,9 @@ void RandomizerRegisterHooks() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnLoadGame>([](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<RandomizerCheck>();
randomizerQueuedCheck = RC_UNKNOWN_CHECK;
randomizerQueuedItemEntry = GET_ITEM_NONE;

View File

@@ -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" });