ref: 73a7155f7f77816312e2c05ef0559fe520aba6c9
parent: 5baed18b311a8f745f5a51080a3aabdd2071cdf7
author: Snesrev <snesrev@protonmail.com>
date: Sat Oct 8 23:01:34 EDT 2022
Fix messed up module index when using bottles in a transition (#126) This was caused by the door transition code assuming that the module and submodule indexes were 7,0. But when using a bottle this got changed to module 14, which was then incorrectly modified.
--- a/dungeon.c
+++ b/dungeon.c
@@ -2052,6 +2052,7 @@
}
void Dungeon_StartInterRoomTrans_Left() {
+ assert(submodule_index == 0);
link_quadrant_x ^= 1;
Dungeon_AdjustQuadrant();
RoomBounds_SubA(&room_bounds_x);
@@ -2058,7 +2059,7 @@
Dung_SaveDataForCurrentRoom();
DungeonTransition_AdjustCamera_X(link_quadrant_x ^ 1);
HandleEdgeTransition_AdjustCameraBoundaries(3);
- submodule_index++;
+ submodule_index = 1;
if (link_quadrant_x) {
RoomBounds_SubB(&room_bounds_x);
BYTE(dungeon_room_index_prev) = dungeon_room_index;
@@ -2072,7 +2073,7 @@
}
dungeon_room_index--;
}
- submodule_index += 1;
+ submodule_index = 2;
if (room_transitioning_flags & 1) {
link_is_on_lower_level ^= 1;
link_is_on_lower_level_mirror = link_is_on_lower_level;
@@ -2091,6 +2092,7 @@
}
void Dungeon_StartInterRoomTrans_Up() {
+ assert(submodule_index == 0);
link_quadrant_y ^= 2;
Dungeon_AdjustQuadrant();
RoomBounds_SubA(&room_bounds_y);
@@ -2097,7 +2099,7 @@
Dung_SaveDataForCurrentRoom();
DungeonTransition_AdjustCamera_Y(link_quadrant_y ^ 2);
HandleEdgeTransition_AdjustCameraBoundaries(1);
- submodule_index++;
+ submodule_index = 1;
if (link_quadrant_y) {
RoomBounds_SubB(&room_bounds_y);
BYTE(dungeon_room_index_prev) = dungeon_room_index;
@@ -2119,7 +2121,7 @@
Dungeon_AdjustAfterSpiralStairs();
}
BYTE(dungeon_room_index) -= 0x10;
- submodule_index += 1;
+ submodule_index = 2;
if (room_transitioning_flags & 1) {
link_is_on_lower_level ^= 1;
link_is_on_lower_level_mirror = link_is_on_lower_level;
@@ -2133,6 +2135,7 @@
}
void Dungeon_StartInterRoomTrans_Down() {
+ assert(submodule_index == 0);
link_quadrant_y ^= 2;
Dungeon_AdjustQuadrant();
RoomBounds_AddA(&room_bounds_y);
@@ -2139,7 +2142,7 @@
Dung_SaveDataForCurrentRoom();
DungeonTransition_AdjustCamera_Y(link_quadrant_y);
HandleEdgeTransition_AdjustCameraBoundaries(0);
- submodule_index++;
+ submodule_index = 1;
if (!link_quadrant_y) {
RoomBounds_AddB(&room_bounds_y);
BYTE(dungeon_room_index_prev) = dungeon_room_index;
@@ -2153,7 +2156,7 @@
Dungeon_AdjustAfterSpiralStairs();
}
BYTE(dungeon_room_index) += 16;
- submodule_index += 1;
+ submodule_index = 2;
if (room_transitioning_flags & 1) {
link_is_on_lower_level ^= 1;
link_is_on_lower_level_mirror = link_is_on_lower_level;
@@ -7958,6 +7961,7 @@
}
void Dungeon_StartInterRoomTrans_Right() { // 82b63a
+ assert(submodule_index == 0);
link_quadrant_x ^= 1;
Dungeon_AdjustQuadrant();
RoomBounds_AddA(&room_bounds_x);
@@ -7964,7 +7968,7 @@
Dung_SaveDataForCurrentRoom();
DungeonTransition_AdjustCamera_X(link_quadrant_x);
HandleEdgeTransition_AdjustCameraBoundaries(2);
- submodule_index++;
+ submodule_index = 1;
if (!link_quadrant_x) {
RoomBounds_AddB(&room_bounds_x);
BYTE(dungeon_room_index_prev) = dungeon_room_index;
@@ -7978,7 +7982,7 @@
}
dungeon_room_index += 1;
}
- submodule_index += 1;
+ submodule_index = 2;
if (room_transitioning_flags & 1) {
link_is_on_lower_level ^= 1;
link_is_on_lower_level_mirror = link_is_on_lower_level;
--- a/player.c
+++ b/player.c
@@ -242,14 +242,20 @@
Link_HandleYItem();
if (sram_progress_indicator != 0) {
Link_HandleSwordCooldown();
- if (link_player_handler_state == 3) {
- link_x_vel = link_y_vel = 0;
- goto getout_dostuff;
- }
}
}
}
+ // Ensure we're not handling potions. Things further
+ // down don't assume this and change the module indexes randomly.
+ // Also check for spin attack for some reason.
+ if ((enhanced_features0 & kFeatures0_MiscBugFixes) && main_module_index == 14 && submodule_index != 2 ||
+ link_player_handler_state == 3) {
+ link_x_vel = link_y_vel = 0;
+ goto getout_dostuff;
+ }
+
+
Link_HandleCape_passive_LiftCheck();
if (link_incapacitated_timer) {
link_moving_against_diag_tile = 0;
@@ -6062,6 +6068,14 @@
link_x_page_movement_delta = 0;
link_y_page_movement_delta = 0;
+
+ // Using a potion might have changed us into a different module, and the routines
+ // below just increment the submodule value, causing all kinds of havoc.
+ // There's an added return to catch the same behavior a bit up, but this one catches more cases,
+ // at the expense of link already having done his movement, so by returning here we might
+ // miss handling the door causing other kinds of issues.
+ if ((enhanced_features0 & kFeatures0_MiscBugFixes) && !(main_module_index == 7 && submodule_index == 0))
+ return;
if (link_direction_last & 0xC && is_standing_in_doorway == 1) {
if (link_direction_last & 4) {