ShuffleFreestanding: ShipInit (#5583)

This commit is contained in:
Philip Dubé 2025-06-19 21:53:15 +00:00 committed by GitHub
commit 7f3aac36b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 33 deletions

View file

@ -1,17 +1,17 @@
#include "ShuffleFreestanding.h"
#include <soh/OTRGlobals.h>
extern "C" {
#include "variables.h"
#include "functions.h"
extern PlayState* gPlayState;
}
extern void EnItem00_DrawRandomizedItem(EnItem00* enItem00, PlayState* play);
void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs) {
va_list args;
va_copy(args, originalArgs);
void RegisterShuffleFreestanding() {
bool shouldRegister = IS_RANDO && RAND_GET_OPTION(RSK_SHUFFLE_FREESTANDING);
if (id == VB_ITEM00_DESPAWN) {
COND_VB_SHOULD(VB_ITEM00_DESPAWN, shouldRegister, {
EnItem00* item00 = va_arg(args, EnItem00*);
// Heart pieces and small keys are handled by default non-freestanding shuffles.
@ -22,14 +22,16 @@ void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* sh
uint32_t params = TWO_ACTOR_PARAMS((int32_t)item00->actor.world.pos.x, (int32_t)item00->actor.world.pos.z);
Rando::Location* loc =
OTRGlobals::Instance->gRandomizer->GetCheckObjectFromActor(item00->actor.id, gPlayState->sceneNum, params);
RandomizerCheck randomizerCheck = loc->GetRandomizerCheck();
if (Rando::Context::GetInstance()->GetItemLocation(randomizerCheck)->HasObtained()) {
return;
}
uint8_t isDungeon = loc->IsDungeon();
uint8_t freestandingSetting = RAND_GET_OPTION(RSK_SHUFFLE_FREESTANDING);
RandomizerCheck randomizerCheck = loc->GetRandomizerCheck();
bool checkObtained = Rando::Context::GetInstance()->GetItemLocation(randomizerCheck)->HasObtained();
// Don't change to randomized item if current freestanding item isn't shuffled or already obtained.
if ((freestandingSetting == RO_SHUFFLE_FREESTANDING_OVERWORLD && isDungeon) ||
(freestandingSetting == RO_SHUFFLE_FREESTANDING_DUNGEONS && !isDungeon) || checkObtained ||
(freestandingSetting == RO_SHUFFLE_FREESTANDING_DUNGEONS && !isDungeon) ||
randomizerCheck == RC_UNKNOWN_CHECK) {
return;
}
@ -41,7 +43,7 @@ void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* sh
item00->actor.draw = (ActorFunc)EnItem00_DrawRandomizedItem;
*should = false;
}
});
}
void Rando::StaticData::RegisterFreestandingLocations() {
@ -284,4 +286,5 @@ void Rando::StaticData::RegisterFreestandingLocations() {
// clang-format on
}
static RegisterShipInitFunc initFunc(Rando::StaticData::RegisterFreestandingLocations);
static RegisterShipInitFunc registerShuffleFreestanding(RegisterShuffleFreestanding, { "IS_RANDO" });
static RegisterShipInitFunc registerShuffleFreestandingLocations(Rando::StaticData::RegisterFreestandingLocations);

View file

@ -1,9 +0,0 @@
#ifndef SHUFFLE_FREESTANDING_H
#define SHUFFLE_FREESTANDING_H
#include <z64.h>
#include <soh/OTRGlobals.h>
void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs);
#endif

View file

@ -8,7 +8,6 @@
#include "soh/Enhancements/randomizer/dungeon.h"
#include "soh/Enhancements/randomizer/fishsanity.h"
#include "soh/Enhancements/randomizer/static_data.h"
#include "soh/Enhancements/randomizer/ShuffleFreestanding.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/SohGui/ImGuiUtils.h"
@ -2330,8 +2329,6 @@ void RandomizerRegisterHooks() {
static uint32_t fishsanityOnVanillaBehaviorHook = 0;
static uint32_t fishsanityOnItemReceiveHook = 0;
static uint32_t shuffleFreestandingOnVanillaBehaviorHook = 0;
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnLoadGame>([](int32_t fileNum) {
ShipInit::Init("IS_RANDO");
@ -2365,9 +2362,6 @@ void RandomizerRegisterHooks() {
fishsanityOnVanillaBehaviorHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnItemReceive>(fishsanityOnItemReceiveHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnVanillaBehavior>(
shuffleFreestandingOnVanillaBehaviorHook);
onFlagSetHook = 0;
onSceneFlagSetHook = 0;
onPlayerUpdateForRCQueueHook = 0;
@ -2393,8 +2387,6 @@ void RandomizerRegisterHooks() {
fishsanityOnVanillaBehaviorHook = 0;
fishsanityOnItemReceiveHook = 0;
shuffleFreestandingOnVanillaBehaviorHook = 0;
if (!IS_RANDO)
return;
@ -2459,11 +2451,5 @@ void RandomizerRegisterHooks() {
fishsanityOnItemReceiveHook = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnItemReceive>(
Rando::Fishsanity::OnItemReceiveHandler);
}
if (RAND_GET_OPTION(RSK_SHUFFLE_FREESTANDING) != RO_SHUFFLE_FREESTANDING_OFF) {
shuffleFreestandingOnVanillaBehaviorHook =
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnVanillaBehavior>(
ShuffleFreestanding_OnVanillaBehaviorHandler);
}
});
}