Modularize Pause Warp hook (#5869)

* Modularize Pause Warp hook

* Make RegisterPauseMenuHooks static

* Merge pausewarp.c into hook module

* Use brackets with if statements

* Fix timer bug with spoiling items
This commit is contained in:
Jordan Longstaff
2025-10-28 23:52:18 -04:00
committed by GitHub
parent 48f4f56bac
commit a419b431a7
3 changed files with 37 additions and 30 deletions

View File

@@ -2457,10 +2457,6 @@ void Interface_RandoRestoreSwordless(void);
s32 Ship_CalcShouldDrawAndUpdate(PlayState* play, Actor* actor, Vec3f* projectedPos, f32 projectedW, bool* shouldDraw,
bool* shouldUpdate);
//Pause Warp
void PauseWarp_HandleSelection();
void PauseWarp_Execute();
// #endregion
#ifdef __cplusplus

View File

@@ -1,8 +1,21 @@
#include "custom-message/CustomMessageTypes.h"
#include "global.h"
#include "z64.h"
#include "game-interactor/GameInteractor.h"
#include "soh/OTRGlobals.h"
#include <string>
#include "soh/Enhancements/custom-message/CustomMessageTypes.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include "soh/ShipInit.hpp"
extern "C" {
#include "functions.h"
#include "macros.h"
#include "variables.h"
extern PlayState* gPlayState;
u8 Randomizer_GetSettingValue(RandomizerSettingKey);
}
static constexpr int32_t CVAR_PAUSE_WARP_DEFAULT = 0;
#define CVAR_PAUSE_WARP_NAME CVAR_ENHANCEMENT("PauseWarp")
#define CVAR_PAUSE_WARP_VALUE CVarGetInteger(CVAR_PAUSE_WARP_NAME, CVAR_PAUSE_WARP_DEFAULT)
static const int songMessageMap[] = {
TEXT_WARP_MINUET_OF_FOREST, TEXT_WARP_BOLERO_OF_FIRE, TEXT_WARP_SERENADE_OF_WATER,
@@ -30,7 +43,7 @@ static const int songAudioMap[] = {
static bool isWarpActive = false;
void PauseWarp_Execute() {
static void PauseWarp_Execute() {
if (!isWarpActive || gPlayState->msgCtx.msgMode != MSGMODE_NONE) {
return;
}
@@ -48,13 +61,14 @@ void PauseWarp_Execute() {
for (int i = 0; i < ARRAY_COUNT(ocarinaSongMap); i++) {
if (gPlayState->msgCtx.lastPlayedSong == ocarinaSongMap[i]) {
gPlayState->nextEntranceIndex = entranceIndexMap[i];
func_80088AF0(gPlayState);
return;
}
}
gPlayState->transitionTrigger = TRANS_TRIGGER_OFF;
}
void ActivateWarp(PauseContext* pauseCtx, int song) {
static void ActivateWarp(PauseContext* pauseCtx, int song) {
Audio_OcaSetInstrument(0);
Interface_SetDoAction(gPlayState, DO_ACTION_NONE);
pauseCtx->state = 0x12;
@@ -70,7 +84,7 @@ void ActivateWarp(PauseContext* pauseCtx, int song) {
isWarpActive = true;
}
void PauseWarp_HandleSelection() {
static void PauseWarp_HandleSelection() {
if (gSaveContext.inventory.items[SLOT_OCARINA] != ITEM_NONE) {
int aButtonPressed = CHECK_BTN_ALL(gPlayState->state.input->press.button, BTN_A);
int song = gPlayState->pauseCtx.cursorPoint[PAUSE_QUEST];
@@ -122,3 +136,18 @@ void PauseWarp_HandleSelection() {
}
}
}
static void RegisterPauseMenuHooks() {
COND_HOOK(OnKaleidoUpdate, CVAR_PAUSE_WARP_VALUE, [] {
if (GameInteractor::IsSaveLoaded()) {
PauseWarp_HandleSelection();
}
});
COND_HOOK(OnGameFrameUpdate, CVAR_PAUSE_WARP_VALUE, [] {
if (GameInteractor::IsSaveLoaded()) {
PauseWarp_Execute();
}
});
}
static RegisterShipInitFunc initFunc(RegisterPauseMenuHooks, { CVAR_PAUSE_WARP_NAME });

View File

@@ -858,23 +858,6 @@ void RegisterFloorSwitchesHook() {
});
}
void RegisterPauseMenuHooks() {
static bool pauseWarpHooksRegistered = false;
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([&]() {
if (!GameInteractor::IsSaveLoaded() || !CVarGetInteger(CVAR_ENHANCEMENT("PauseWarp"), 0)) {
pauseWarpHooksRegistered = false;
return;
}
if (!pauseWarpHooksRegistered) {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnKaleidoUpdate>(
[]() { PauseWarp_HandleSelection(); });
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>(
[]() { PauseWarp_Execute(); });
pauseWarpHooksRegistered = true;
}
});
}
void RegisterCustomSkeletons() {
static int8_t previousTunic = -1;
@@ -917,7 +900,6 @@ void InitMods() {
RegisterFloorSwitchesHook();
RegisterPatchHandHandler();
RegisterHurtContainerModeHandler();
RegisterPauseMenuHooks();
RandoKaleido_RegisterHooks();
RegisterCustomSkeletons();
}