Skip to content

Commit 0fadf60

Browse files
committed
Merge 'Move setting of Save context flags from Patches to Savecontext' (#2367)
2 parents f9be287 + a4ebbab commit 0fadf60

3 files changed

Lines changed: 220 additions & 209 deletions

File tree

Patches.py

Lines changed: 4 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from OcarinaSongs import patch_songs
2727
from MQ import patch_files, File, update_dmadata, insert_space, add_relocations
2828
from Rom import Rom
29-
from SaveContext import SaveContext, Scenes, FlagType
29+
from SaveContext import SaveContext, Scenes, FlagType, write_settings_dependent_save_context_flags
3030
from SceneFlags import build_xflag_tables, build_xflags_from_world, get_alt_list_bytes
3131
from Sounds import move_audiobank_table
3232
from Spoiler import Spoiler
@@ -845,162 +845,10 @@ def set_entrance_updates(entrances: Iterable[Entrance]) -> None:
845845
rom.write_bytes(rom.sym('PASSWORD'), spoiler.password)
846846

847847
# Initial Save Data
848-
if not world.settings.useful_cutscenes and 'Forest Temple' not in world.settings.dungeon_shortcuts:
849-
save_context.write_bits(0x00D4 + 0x03 * 0x1C + 0x04 + 0x0, 0x08) # Forest Temple switch flag (Poe Sisters cutscene)
850-
851-
if 'Deku Tree' in world.settings.dungeon_shortcuts:
852-
# Deku Tree, flags are the same between vanilla/MQ
853-
save_context.write_permanent_flag(Scenes.DEKU_TREE, FlagType.SWITCH, 0x1, 0x01) # Deku Block down
854-
save_context.write_permanent_flag(Scenes.DEKU_TREE, FlagType.CLEAR, 0x2, 0x02) # Deku 231/312
855-
save_context.write_permanent_flag(Scenes.DEKU_TREE, FlagType.SWITCH, 0x3, 0x20) # Deku 1st Web
856-
save_context.write_permanent_flag(Scenes.DEKU_TREE, FlagType.SWITCH, 0x3, 0x40) # Deku 2nd Web
857-
858-
if 'Dodongos Cavern' in world.settings.dungeon_shortcuts:
859-
# Dodongo's Cavern, flags are the same between vanilla/MQ
860-
save_context.write_permanent_flag(Scenes.DODONGOS_CAVERN, FlagType.SWITCH, 0x3, 0x80) # DC Entrance Mud Wall
861-
save_context.write_permanent_flag(Scenes.DODONGOS_CAVERN, FlagType.SWITCH, 0x0, 0x04) # DC Mouth
862-
# Extra permanent flag in MQ for the child route
863-
if world.dungeon_mq['Dodongos Cavern']:
864-
save_context.write_permanent_flag(Scenes.DODONGOS_CAVERN, FlagType.SWITCH, 0x0, 0x02) # Armos wall switch
865-
866-
if 'Jabu Jabus Belly' in world.settings.dungeon_shortcuts:
867-
# Jabu
868-
if not world.dungeon_mq['Jabu Jabus Belly']:
869-
save_context.write_permanent_flag(Scenes.JABU_JABU, FlagType.SWITCH, 0x0, 0x20) # Jabu Pathway down
870-
else:
871-
save_context.write_permanent_flag(Scenes.JABU_JABU, FlagType.SWITCH, 0x1, 0x20) # Jabu Lobby Slingshot Door open
872-
save_context.write_permanent_flag(Scenes.JABU_JABU, FlagType.SWITCH, 0x0, 0x20) # Jabu Pathway down
873-
save_context.write_permanent_flag(Scenes.JABU_JABU, FlagType.CLEAR, 0x2, 0x01) # Jabu Red Slimy Thing defeated
874-
save_context.write_permanent_flag(Scenes.JABU_JABU, FlagType.SWITCH, 0x2, 0x08) # Jabu Red Slimy Thing not in front of boss lobby
875-
save_context.write_permanent_flag(Scenes.JABU_JABU, FlagType.SWITCH, 0x1, 0x10) # Jabu Boss Door Switch Activated
876-
877-
if 'Forest Temple' in world.settings.dungeon_shortcuts:
878-
# Forest, flags are the same between vanilla/MQ
879-
save_context.write_permanent_flag(Scenes.FOREST_TEMPLE, FlagType.SWITCH, 0x0, 0x10) # Forest Elevator up
880-
save_context.write_permanent_flag(Scenes.FOREST_TEMPLE, FlagType.SWITCH, 0x1, 0x01 + 0x02 + 0x04) # Forest Basement Puzzle Done
881-
882-
if 'Fire Temple' in world.settings.dungeon_shortcuts:
883-
# Fire, flags are the same between vanilla/MQ
884-
save_context.write_permanent_flag(Scenes.FIRE_TEMPLE, FlagType.SWITCH, 0x2, 0x40) # Fire Pillar down
885-
886-
if 'Spirit Temple' in world.settings.dungeon_shortcuts:
887-
# Spirit
888-
if not world.dungeon_mq['Spirit Temple']:
889-
save_context.write_permanent_flag(Scenes.SPIRIT_TEMPLE, FlagType.SWITCH, 0x1, 0x80) # Spirit Chains
890-
save_context.write_permanent_flag(Scenes.SPIRIT_TEMPLE, FlagType.SWITCH, 0x2, 0x02 + 0x08 + 0x10) # Spirit main room elevator (N block, Rusted Switch, E block)
891-
save_context.write_permanent_flag(Scenes.SPIRIT_TEMPLE, FlagType.SWITCH, 0x3, 0x10) # Spirit Face
892-
else:
893-
save_context.write_permanent_flag(Scenes.SPIRIT_TEMPLE, FlagType.SWITCH, 0x2, 0x10) # Spirit Bombchu Boulder
894-
save_context.write_permanent_flag(Scenes.SPIRIT_TEMPLE, FlagType.SWITCH, 0x2, 0x02) # Spirit Silver Block
895-
save_context.write_permanent_flag(Scenes.SPIRIT_TEMPLE, FlagType.SWITCH, 0x1, 0x80) # Spirit Chains
896-
save_context.write_permanent_flag(Scenes.SPIRIT_TEMPLE, FlagType.SWITCH, 0x3, 0x10) # Spirit Face
897-
898-
if 'Shadow Temple' in world.settings.dungeon_shortcuts:
899-
# Shadow
900-
if not world.dungeon_mq['Shadow Temple']:
901-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.SWITCH, 0x0, 0x08) # Shadow Truthspinner
902-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.SWITCH, 0x0, 0x20) # Shadow Boat Block
903-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.SWITCH, 0x1, 0x01) # Shadow Bird Bridge
904-
else:
905-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.SWITCH, 0x2, 0x08) # Shadow Truthspinner
906-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.SWITCH, 0x3, 0x20) # Shadow Fire Arrow Platform
907-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.SWITCH, 0x3, 0x80) # Shadow Spinning Blades room Skulltulas defeated
908-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.CLEAR, 0x3, 0x40) # Shadow Spinning Blades room Skulltulas defeated
909-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.SWITCH, 0x0, 0x20) # Shadow Boat Block
910-
save_context.write_permanent_flag(Scenes.SHADOW_TEMPLE, FlagType.SWITCH, 0x1, 0x01) # Shadow Bird Bridge
911-
912-
if world.region_has_shortcuts('King Dodongo Boss Room'):
913-
save_context.write_permanent_flag(Scenes.KING_DODONGO_LOBBY, FlagType.SWITCH, 0x3, 0x02) # DC Boss Floor
914-
848+
save_context.write_qol_save_context_flags()
849+
write_settings_dependent_save_context_flags(save_context, world)
915850
set_spirit_shortcut_actors(rom) # Change elevator starting position to avoid waiting a half cycle from the temple entrance
916851

917-
if world.settings.plant_beans:
918-
save_context.write_permanent_flag(Scenes.GRAVEYARD, FlagType.SWITCH, 0x3, 0x08) # Plant Graveyard bean
919-
save_context.write_permanent_flag(Scenes.ZORAS_RIVER, FlagType.SWITCH, 0x3, 0x08) # Plant Zora's River bean
920-
save_context.write_permanent_flag(Scenes.KOKIRI_FOREST, FlagType.SWITCH, 0x2, 0x02) # Plant Kokiri Forest bean
921-
save_context.write_permanent_flag(Scenes.LAKE_HYLIA, FlagType.SWITCH, 0x3, 0x02) # Plant Lake Hylia bean
922-
save_context.write_permanent_flag(Scenes.GERUDO_VALLEY, FlagType.SWITCH, 0x3, 0x08) # Plant Gerudo Valley bean
923-
save_context.write_permanent_flag(Scenes.LOST_WOODS, FlagType.SWITCH, 0x3, 0x10) # Plant Lost Woods bridge bean
924-
save_context.write_permanent_flag(Scenes.LOST_WOODS, FlagType.SWITCH, 0x1, 0x04) # Plant Lost Woods theater bean
925-
save_context.write_permanent_flag(Scenes.DESERT_COLOSSUS, FlagType.SWITCH, 0x0, 0x1) # Plant Desert Colossus bean
926-
save_context.write_permanent_flag(Scenes.DEATH_MOUNTAIN_TRAIL, FlagType.SWITCH, 0x3, 0x40) # Plant Death Mountain Trail bean
927-
save_context.write_permanent_flag(Scenes.DEATH_MOUNTAIN_CRATER, FlagType.SWITCH, 0x3, 0x08) # Plant Death Mountain Crater bean
928-
929-
save_context.write_bits(0x00D4 + 0x05 * 0x1C + 0x04 + 0x1, 0x01) # Water temple switch flag (Ruto)
930-
save_context.write_bits(0x00D4 + 0x51 * 0x1C + 0x04 + 0x2, 0x08) # Hyrule Field switch flag (Owl)
931-
save_context.write_bits(0x00D4 + 0x55 * 0x1C + 0x04 + 0x0, 0x80) # Kokiri Forest switch flag (Owl)
932-
save_context.write_bits(0x00D4 + 0x56 * 0x1C + 0x04 + 0x2, 0x40) # Sacred Forest Meadow switch flag (Owl)
933-
save_context.write_bits(0x00D4 + 0x5B * 0x1C + 0x04 + 0x2, 0x01) # Lost Woods switch flag (Owl)
934-
save_context.write_bits(0x00D4 + 0x5B * 0x1C + 0x04 + 0x3, 0x80) # Lost Woods switch flag (Owl)
935-
save_context.write_bits(0x00D4 + 0x5C * 0x1C + 0x04 + 0x0, 0x80) # Desert Colossus switch flag (Owl)
936-
save_context.write_bits(0x00D4 + 0x5F * 0x1C + 0x04 + 0x3, 0x20) # Hyrule Castle switch flag (Owl)
937-
save_context.write_bits(0x0F2B, 0x20) # Spoke to Lake Hylia Owl once
938-
939-
save_context.write_bits(0x0ED4, 0x10) # "Met Deku Tree"
940-
save_context.write_bits(0x0ED5, 0x20) # "Deku Tree Opened Mouth"
941-
save_context.write_bits(0x0ED6, 0x08) # "Rented Horse From Ingo"
942-
save_context.write_bits(0x0ED6, 0x10) # "Spoke to Mido After Deku Tree's Death"
943-
save_context.write_bits(0x0EDA, 0x08) # "Began Nabooru Battle"
944-
save_context.write_bits(0x0EDC, 0x80) # "Entered the Master Sword Chamber"
945-
if world.settings.skip_reward_from_rauru:
946-
save_context.write_bits(0x0EDD, 0x20) # "Pulled Master Sword from Pedestal"
947-
save_context.write_bits(0x0EE0, 0x80) # "Spoke to Kaepora Gaebora by Lost Woods"
948-
save_context.write_bits(0x0EE7, 0x20) # "Nabooru Captured by Twinrova"
949-
save_context.write_bits(0x0EE7, 0x10) # "Spoke to Nabooru in Spirit Temple"
950-
save_context.write_bits(0x0EED, 0x20) # "Sheik, Spawned at Master Sword Pedestal as Adult"
951-
save_context.write_bits(0x0EED, 0x01) # "Nabooru Ordered to Fight by Twinrova"
952-
save_context.write_bits(0x0EED, 0x80) # "Watched Ganon's Tower Collapse / Caught by Gerudo"
953-
save_context.write_bits(0x0EF9, 0x01) # "Greeted by Saria"
954-
save_context.write_bits(0x0F0A, 0x04) # "Spoke to Ingo Once as Adult"
955-
save_context.write_bits(0x0F0F, 0x40) # "Met Poe Collector in Ruined Market"
956-
if not world.settings.useful_cutscenes:
957-
save_context.write_bits(0x0F1A, 0x04) # "Met Darunia in Fire Temple"
958-
959-
save_context.write_bits(0x0ED7, 0x01) # "Spoke to Child Malon at Castle or Market"
960-
save_context.write_bits(0x0ED7, 0x20) # "Spoke to Child Malon at Ranch"
961-
save_context.write_bits(0x0ED7, 0x40) # "Invited to Sing With Child Malon"
962-
save_context.write_bits(0x0F09, 0x10) # "Met Child Malon at Castle or Market"
963-
save_context.write_bits(0x0F09, 0x20) # "Child Malon Said Epona Was Scared of You"
964-
965-
save_context.write_bits(0x0F21, 0x04) # "Ruto in JJ (M3) Talk First Time"
966-
save_context.write_bits(0x0F21, 0x02) # "Ruto in JJ (M2) Meet Ruto"
967-
if world.settings.ruto_already_f1_jabu and not world.dungeon_mq['Jabu Jabus Belly']:
968-
save_context.write_bits(0x0F21, 0x80) # Ruto in JJ, Spawns on F1 instead of B1
969-
970-
save_context.write_bits(0x0EE2, 0x01) # "Began Ganondorf Battle"
971-
save_context.write_bits(0x0EE3, 0x80) # "Began Bongo Bongo Battle"
972-
save_context.write_bits(0x0EE3, 0x40) # "Began Barinade Battle"
973-
save_context.write_bits(0x0EE3, 0x20) # "Began Twinrova Battle"
974-
save_context.write_bits(0x0EE3, 0x10) # "Began Morpha Battle"
975-
save_context.write_bits(0x0EE3, 0x08) # "Began Volvagia Battle"
976-
save_context.write_bits(0x0EE3, 0x04) # "Began Phantom Ganon Battle"
977-
save_context.write_bits(0x0EE3, 0x02) # "Began King Dodongo Battle"
978-
save_context.write_bits(0x0EE3, 0x01) # "Began Gohma Battle"
979-
980-
save_context.write_bits(0x0EE8, 0x01) # "Entered Deku Tree"
981-
save_context.write_bits(0x0EE9, 0x80) # "Entered Temple of Time"
982-
save_context.write_bits(0x0EE9, 0x40) # "Entered Goron City"
983-
save_context.write_bits(0x0EE9, 0x20) # "Entered Hyrule Castle"
984-
save_context.write_bits(0x0EE9, 0x10) # "Entered Zora's Domain"
985-
save_context.write_bits(0x0EE9, 0x08) # "Entered Kakariko Village"
986-
save_context.write_bits(0x0EE9, 0x02) # "Entered Death Mountain Trail"
987-
save_context.write_bits(0x0EE9, 0x01) # "Entered Hyrule Field"
988-
save_context.write_bits(0x0EEA, 0x04) # "Entered Ganon's Castle (Exterior)"
989-
save_context.write_bits(0x0EEA, 0x02) # "Entered Death Mountain Crater"
990-
save_context.write_bits(0x0EEA, 0x01) # "Entered Desert Colossus"
991-
save_context.write_bits(0x0EEB, 0x80) # "Entered Zora's Fountain"
992-
save_context.write_bits(0x0EEB, 0x40) # "Entered Graveyard"
993-
save_context.write_bits(0x0EEB, 0x20) # "Entered Jabu-Jabu's Belly"
994-
save_context.write_bits(0x0EEB, 0x10) # "Entered Lon Lon Ranch"
995-
save_context.write_bits(0x0EEB, 0x08) # "Entered Gerudo's Fortress"
996-
save_context.write_bits(0x0EEB, 0x04) # "Entered Gerudo Valley"
997-
save_context.write_bits(0x0EEB, 0x02) # "Entered Lake Hylia"
998-
save_context.write_bits(0x0EEB, 0x01) # "Entered Dodongo's Cavern"
999-
save_context.write_bits(0x0F08, 0x08) # "Entered Hyrule Castle"
1000-
1001-
if world.dungeon_mq['Shadow Temple']:
1002-
save_context.write_bits(0x019F, 0x80) # "Turn On Clear Wall Blocking Hover Boots Room"
1003-
1004852
# Set the number of chickens to collect
1005853
rom.write_byte(0x00E1E523, world.settings.chicken_count)
1006854

@@ -1049,22 +897,6 @@ def calculate_traded_flags(world):
1049897
if world.settings.complete_mask_quest:
1050898
rom.write_byte(rom.sym('COMPLETE_MASK_QUEST'), 1)
1051899

1052-
if world.skip_child_zelda:
1053-
if all(trade_item not in world.settings.shuffle_child_trade for trade_item in ('Weird Egg', 'Chicken')):
1054-
save_context.write_bits(0x0ED7, 0x04) # "Obtained Malon's Item"
1055-
save_context.write_bits(0x0ED7, 0x08) # "Woke Talon in castle"
1056-
save_context.write_bits(0x0ED7, 0x10) # "Talon has fled castle"
1057-
save_context.write_bits(0x0EDD, 0x01) # "Obtained Zelda's Letter"
1058-
save_context.write_bits(0x0EDE, 0x02) # "Learned Zelda's Lullaby"
1059-
save_context.write_bits(0x00D4 + 0x5F * 0x1C + 0x04 + 0x3, 0x10) # "Moved crates to access the courtyard"
1060-
if 'Zeldas Letter' in world.distribution.starting_items:
1061-
if world.settings.open_kakariko != 'closed':
1062-
save_context.write_bits(0x0F07, 0x40) # "Spoke to Gate Guard About Mask Shop"
1063-
if world.settings.complete_mask_quest:
1064-
save_context.write_bits(0x0F07, 0x80) # "Soldier Wears Keaton Mask"
1065-
save_context.write_bits(0x0EF6, 0x8F) # "Sold Masks & Unlocked Masks" / "Obtained Mask of Truth"
1066-
save_context.write_bits(0x0EE4, 0xF0) # "Paid Back Mask Fees"
1067-
1068900
if world.settings.zora_fountain == 'open':
1069901
save_context.write_bits(0x0EDB, 0x08) # "Moved King Zora"
1070902
elif world.settings.zora_fountain == 'adult':
@@ -1149,12 +981,6 @@ def calculate_traded_flags(world):
1149981
else:
1150982
rom.write_int32(symbol, 0)
1151983

1152-
if world.settings.open_forest == 'open':
1153-
save_context.write_bits(0xED5, 0x10) # "Showed Mido Sword & Shield"
1154-
1155-
if world.settings.open_door_of_time:
1156-
save_context.write_bits(0xEDC, 0x08) # "Opened the Door of Time"
1157-
1158984
# "fast-ganon" stuff
1159985
symbol = rom.sym('NO_ESCAPE_SEQUENCE')
1160986
if world.settings.no_escape_sequence:
@@ -1163,36 +989,6 @@ def calculate_traded_flags(world):
1163989
rom.write_byte(symbol, 0x01)
1164990
else:
1165991
rom.write_byte(symbol, 0x00)
1166-
if world.skipped_trials['Forest']:
1167-
save_context.write_bits(0x0EEA, 0x08) # "Completed Forest Trial"
1168-
if world.skipped_trials['Fire']:
1169-
save_context.write_bits(0x0EEA, 0x40) # "Completed Fire Trial"
1170-
if world.skipped_trials['Water']:
1171-
save_context.write_bits(0x0EEA, 0x10) # "Completed Water Trial"
1172-
if world.skipped_trials['Spirit']:
1173-
save_context.write_bits(0x0EE8, 0x20) # "Completed Spirit Trial"
1174-
if world.skipped_trials['Shadow']:
1175-
save_context.write_bits(0x0EEA, 0x20) # "Completed Shadow Trial"
1176-
if world.skipped_trials['Light']:
1177-
save_context.write_bits(0x0EEA, 0x80) # "Completed Light Trial"
1178-
if world.settings.trials == 0:
1179-
save_context.write_bits(0x0EED, 0x08) # "Dispelled Ganon's Tower Barrier"
1180-
1181-
# open gerudo fortress
1182-
if world.settings.gerudo_fortress == 'open':
1183-
if not world.settings.shuffle_gerudo_card:
1184-
save_context.write_bits(0x00A5, 0x40) # Give Gerudo Card
1185-
save_context.write_bits(0x0EE7, 0x0F) # Free all 4 carpenters
1186-
save_context.write_bits(0x00D4 + 0x0C * 0x1C + 0x04 + 0x1, 0x0F) # Thieves' Hideout switch flags (started all fights)
1187-
save_context.write_bits(0x00D4 + 0x0C * 0x1C + 0x04 + 0x2, 0x01) # Thieves' Hideout switch flags (heard yells/unlocked doors)
1188-
save_context.write_bits(0x00D4 + 0x0C * 0x1C + 0x04 + 0x3, 0xFE) # Thieves' Hideout switch flags (heard yells/unlocked doors)
1189-
save_context.write_bits(0x00D4 + 0x0C * 0x1C + 0x0C + 0x2, 0xD4) # Thieves' Hideout collection flags (picked up keys, marks fights finished as well)
1190-
elif world.settings.gerudo_fortress == 'fast':
1191-
save_context.write_bits(0x0EE7, 0x0E) # Free 3 carpenters
1192-
save_context.write_bits(0x00D4 + 0x0C * 0x1C + 0x04 + 0x1, 0x0D) # Thieves' Hideout switch flags (started all fights)
1193-
save_context.write_bits(0x00D4 + 0x0C * 0x1C + 0x04 + 0x2, 0x01) # Thieves' Hideout switch flags (heard yells/unlocked doors)
1194-
save_context.write_bits(0x00D4 + 0x0C * 0x1C + 0x04 + 0x3, 0xDC) # Thieves' Hideout switch flags (heard yells/unlocked doors)
1195-
save_context.write_bits(0x00D4 + 0x0C * 0x1C + 0x0C + 0x2, 0xC4) # Thieves' Hideout collection flags (picked up keys, marks fights finished as well)
1196992

1197993
# Add a gate opening guard on the Wasteland side of the Gerudo Fortress' gate
1198994
# Overrides the generic guard at the bottom of the ladder in Gerudo Fortress
@@ -1399,7 +1195,7 @@ def calculate_traded_flags(world):
13991195
rom.write_byte(symbol, 0x01)
14001196

14011197
if world.settings.skip_some_minigame_phases:
1402-
save_context.write_bits(0x00D4 + 0x48 * 0x1C + 0x08 + 0x3, 0x10) # Beat First Dampe Race (& Chest Spawned)
1198+
save_context.write_permanent_flag(Scenes.WINDMILL, FlagType.CLEAR, 0x3, 0x10) # Beat First Dampe Race (& Chest Spawned)
14031199
rom.write_byte(rom.sym('CHAIN_HBA_REWARDS'), 1)
14041200
# Update the first horseback archery text to make it clear both rewards are available from the start
14051201
update_message_by_id(messages, 0x6040, "Hey newcomer, you have a fine \x01horse!\x04I don't know where you stole \x01it from, but...\x04OK, how about challenging this \x01\x05\x41horseback archery\x05\x40?\x04Once the horse starts galloping,\x01shoot the targets with your\x01arrows. \x04Let's see how many points you \x01can score. You get 20 arrows.\x04If you can score \x05\x411,000 points\x05\x40, I will \x01give you something good! And even \x01more if you score \x05\x411,500 points\x05\x40!\x0B\x02")

0 commit comments

Comments
 (0)