Skip to content

Commit

Permalink
Let temples remain as they are during cycle resets for doors and free…
Browse files Browse the repository at this point in the history
…standing fairies.
  • Loading branch information
PhlexPlexico committed Feb 2, 2024
1 parent 4f89422 commit e7581c7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 102 deletions.
9 changes: 9 additions & 0 deletions code/include/game/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,15 @@ namespace game {
static_assert(offsetof(GlobalContext, gap_8384) == 0x8384);
static_assert(sizeof(GlobalContext) == 0x11030);

struct PersistentSceneCycleFlags {
u32 switch0;
u32 switch1;
u32 chest;
u32 collectible;
};
static_assert(sizeof(PersistentSceneCycleFlags) == 0x10);

PersistentSceneCycleFlags* GetPersistentCycleStruct();
} // namespace game

#endif
4 changes: 2 additions & 2 deletions code/include/rnd/custom_entrances.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extern "C" {

namespace rnd {
extern "C" {
bool SceneEntranceOverride();
bool IsTempleScene(int);
bool SceneEntranceOverride();
void ForceTempleFlags();
}
} // namespace rnd

Expand Down
16 changes: 2 additions & 14 deletions code/mm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,10 @@ SECTIONS{
*(.patch_RemoveMysteryMilkTimer)
}

/* .patch_TempleAsLastScence 0x1C9310 : {
*(.patch_TempleAsLastScence)
}*/

.patch_DoNotResetTempleFlags 0x1c936c : {
*(.patch_AttemptKeepChestsClosed)
.patch_DoNotResetTempleFlags 0x1C936C : {
*(.patch_DoNotResetTempleFlags)
}

/* .patch_tmp 0x545a30 : {
*(.patch_tmp)
} */

/*.patch_tmp2 0x1c93cc : {
*(.patch_tmp2)
} */

.patch_DoNotRemoveKeys 0x1C9B94 : {
*(.patch_DoNotRemoveKeys)
}
Expand Down
49 changes: 3 additions & 46 deletions code/source/asm/hooks.s
Original file line number Diff line number Diff line change
Expand Up @@ -71,56 +71,13 @@ doNotOverrideCutscene:
bl 0x22A7F8
b 0x1B1838

.global hook_TempleAsLastScene
hook_TempleAsLastScene:
push {r0-r12, lr}
bl IsTempleScene
cmp r0,#0x1
pop {r0-r12, lr}
beq 0x1C936C
@ original instruction.
push {lr}
bl 0x190A54
pop {lr}
bx lr

.global hook_DebugHook
hook_DebugHook:
push {r0-r12,lr}
mov r5, r0
bl printR1
pop {r0-r12,lr}
str r2, [r1], #20
bx lr

.global hook_DoNotResetFlagsGeneric
hook_DoNotResetFlagsGeneric:
push {r0-r12, lr}
bl IsTempleScene
cmp r0,#0x1
pop {r0-r12, lr}
beq templeCaseGeneric
@beq 0x1C93C8
add r0,r0,#0x1
bx lr
templeCaseGeneric:
add r0,r0,#0x1
add r0,r0,#0x1
bx lr

.global hook_DoNotResetTempleFlags
hook_DoNotResetTempleFlags:
mov r0, #0x0
push {r0-r12, lr}
bl IsTempleScene
cmp r0,#0x1
bl ForceTempleFlags
pop {r0-r12, lr}
bne templeCase
@beq 0x1C93C8
b 0x1C9370
templeCase:
add r0,r0,#0x1
b 0x1C9370
mov r0,#0x0
bx lr

.global hook_ChangeSOHToCustomText
hook_ChangeSOHToCustomText:
Expand Down
22 changes: 1 addition & 21 deletions code/source/asm/patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,14 @@ patch_OverrideCutsceneNextEntrance:
patch_RemoveMysteryMilkTimer:
nop

@ There's a check on gctx->scene here that we
@ should ignore if we are a temple to avoid
@ resetting any doors.
.section .patch_TempleAsLastScence
.global patch_TempleAsLastScence
patch_TempleAsLastScence:
@bl hook_TempleAsLastScene

@ Skip past all the fairy and
@ door resetting if we are the temples
@ as we don't want to softlock users
@ if they have already used their keys.
.section .patch_DoNotResetTempleFlags
.global patch_DoNotResetTempleFlags
patch_DoNotResetTempleFlags:
b hook_DoNotResetTempleFlags

.section .patch_tmp
.global patch_tmp
patch_tmp:
bl hook_DoNotResetFlagsGeneric

.section .patch_tmp2
.global patch_tmp2
patch_tmp2:
nop
cmp r0,#0x75
nop
bl hook_DoNotResetTempleFlags

@ Skips past a loop that resets all
@ values in the each dungeon for
Expand Down
5 changes: 5 additions & 0 deletions code/source/game/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ namespace game {
rnd::util::GetPointer<void(GlobalContext*)>(0x230ec8)(this);
}

// Grabs the persistent cycle flags for cycle reset.
PersistentSceneCycleFlags* GetPersistentCycleStruct() {
return rnd::util::GetPointer<PersistentSceneCycleFlags>(0x6A017C);
}

} // namespace game
26 changes: 7 additions & 19 deletions code/source/rnd/custom_entrances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,13 @@ namespace rnd {
return didWarp;
}

bool IsTempleScene(int scene) {

if (scene == (int)game::SceneId::Woodfall || scene == (int)game::SceneId::SnowheadTemple ||
scene == (int)game::SceneId::GreatBayTemple || scene == (int)game::SceneId::StoneTowerTemple ||
scene == (int)game::SceneId::StoneTowerTempleInverted) {
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
rnd::util::Print("%s: We are a temple scene! ID is %#04x returning true %u\n", __func__, (s16)scene, true);
#endif
return true;
}

else
return false;
}

void printR1(int scene) {
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
rnd::util::Print("%s: We are a temple scene! ID is %s\n", __func__, (s16)scene);
#endif
void ForceTempleFlags() {
game::PersistentSceneCycleFlags* cycleFlags = game::GetPersistentCycleStruct();
cycleFlags[(u32)game::SceneId::WoodfallTemple].switch1 = 0xFFFFFFFF;
cycleFlags[(u32)game::SceneId::SnowheadTemple].switch1 = 0xFFFFFFFF;
cycleFlags[(u32)game::SceneId::GreatBayTemple].switch1 = 0xFFFFFFFF;
cycleFlags[(u32)game::SceneId::StoneTowerTemple].switch1 = 0xFFFFFFFF;
cycleFlags[(u32)game::SceneId::StoneTowerTempleInverted].switch1 = 0xFFFFFFFF;
}
}

Expand Down

0 comments on commit e7581c7

Please sign in to comment.