forked from LagoLunatic/wwrando
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tweaks.py
2440 lines (1961 loc) · 120 KB
/
tweaks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import copy
import math
import os
import re
from collections import OrderedDict
from collections import namedtuple
from random import Random
from typing import List, Dict, TYPE_CHECKING
import customizer
from asm import patcher
from classes.location import Location
from fs_helpers import *
from logic.extras import DUNGEON_NAME_DICT
from wwlib import texture_utils
from wwlib.rel import REL
from wwrando_paths import ASSETS_PATH, ASM_PATH, SEEDGEN_PATH, DATA_PATH
if TYPE_CHECKING:
from randomizer import Randomizer
try:
from keys.seed_key import SEED_KEY
except ImportError:
SEED_KEY = ""
ORIGINAL_FREE_SPACE_RAM_ADDRESS = 0x803FCFA8
ORIGINAL_DOL_SIZE = 0x3A52C0
MAXIMUM_ADDITIONAL_STARTING_ITEMS = 47
def set_new_game_starting_spawn_id(randomizer: 'Randomizer', spawn_id):
randomizer.dol.write_data(write_u8, 0x80058BAF, spawn_id)
def set_new_game_starting_room_index(randomizer: 'Randomizer', room_index):
randomizer.dol.write_data(write_u8, 0x80058BA7, room_index)
def change_ship_starting_island(randomizer: 'Randomizer', starting_island_room_index):
island_dzx = randomizer.get_arc("files/res/Stage/sea/Room%d.arc" % starting_island_room_index).get_file("room.dzr")
ship_spawns = island_dzx.entries_by_type("SHIP")
island_ship_spawn_0 = next(x for x in ship_spawns if x.ship_id == 0)
sea_dzx = randomizer.get_arc("files/res/Stage/sea/Stage.arc").get_file("stage.dzs")
sea_actors = sea_dzx.entries_by_type("ACTR")
ship_actor = next(x for x in sea_actors if x.name == "Ship")
ship_actor.x_pos = island_ship_spawn_0.x_pos
ship_actor.y_pos = island_ship_spawn_0.y_pos
ship_actor.z_pos = island_ship_spawn_0.z_pos
ship_actor.y_rot = island_ship_spawn_0.y_rot
ship_actor.save_changes()
def skip_wakeup_intro_and_start_at_dock(randomizer: 'Randomizer'):
# When the player starts a new game they usually start at spawn ID 206, which plays the wakeup event and puts the player on Aryll's lookout.
# We change the starting spawn ID to 0, which does not play the wakeup event and puts the player on the dock next to the ship.
set_new_game_starting_spawn_id(randomizer, 0)
def start_ship_at_outset(randomizer: 'Randomizer'):
# Change the King of Red Lion's default position so that he appears on Outset at the start of the game.
change_ship_starting_island(randomizer, 44)
def make_all_text_instant(randomizer: 'Randomizer'):
for msg in randomizer.bmg.messages:
msg.initial_draw_type = 1 # Instant initial draw type
# Get rid of wait commands
msg.string = re.sub(
r"\\\{1A 07 00 00 07 [0-9a-f]{2} [0-9a-f]{2}\}",
"",
msg.string, 0, re.IGNORECASE
)
# Get rid of wait+dismiss commands
# Exclude message 7726, for Maggie's Father throwing rupees at you. He only spawns the rupees past a certain frame of his animation, so if you skipped past the text too quickly you wouldn't get any rupees.
# Exclude message 2488, for Orca talking to you after you learn the Hurricane Spin. Without the wait+dismiss he would wind up repeating some of his lines once.
if msg.message_id != 7726 and msg.message_id != 2488:
msg.string = re.sub(
r"\\\{1A 07 00 00 04 [0-9a-f]{2} [0-9a-f]{2}\}",
"",
msg.string, 0, re.IGNORECASE
)
# Get rid of wait+dismiss (prompt) commands
msg.string = re.sub(
r"\\\{1A 07 00 00 03 [0-9a-f]{2} [0-9a-f]{2}\}",
"",
msg.string, 0, re.IGNORECASE
)
# Also change the B button to act as a hold-to-skip button during dialogue.
patcher.apply_patch(randomizer, "b_button_skips_text")
def fix_deku_leaf_model(randomizer: 'Randomizer'):
# The Deku Leaf is a unique object not used for other items. It's easy to change what item it gives you, but the visual model cannot be changed.
# So instead we replace the unique Deku Leaf actor ("itemDek") with a more general actor that can be for any field item ("item").
dzx = randomizer.get_arc("files/res/Stage/Omori/Room0.arc").get_file("room.dzr")
deku_leaf_actors = [actor for actor in dzx.entries_by_type("ACTR") if actor.name == "itemDek"]
for actor in deku_leaf_actors:
actor.name = "item"
actor.params = 0x01FF0000 # Misc params, one of which makes the item not fade out over time
actor.item_id = 0x34 # Deku Leaf
actor.item_pickup_flag = 2 # This is the same item pickup flag that itemDek originally had in its params.
actor.activation_switch_index = 0xFF # Necessary for the item to be pickupable.
actor.save_changes()
def allow_all_items_to_be_field_items(randomizer: 'Randomizer'):
# Most items cannot be field items (items that appear freely floating on the ground) because they don't have a field model defined.
# Here we copy the regular item get model to the field model so that any item can be a field item.
# We also change the code run when you touch the item so that these items play out the full item get animation with text, instead of merely popping up above the player's head like a rupee.
# And we change the Y offsets so the items don't appear lodged inside the floor, and can be picked up easily.
# And also change the radius for items that had 0 radius so the player doesn't need to be right inside the item to pick it up.
# Also change the code run by items during the wait state, which affects the physics when shot out of Gohdan's nose for example.
item_resources_list_start = 0x803842B0
field_item_resources_list_start = 0x803866B0
itemGetExecute_switch_statement_entries_list_start = 0x8038CA6C
mode_wait_switch_statement_entries_list_start = 0x8038CC7C
for item_id in randomizer.item_ids_without_a_field_model:
if item_id in [0x39, 0x3A, 0x3E]:
# Master Swords don't have a proper item get model defined, so we need to use the Hero's Sword instead.
item_id_to_copy_from = 0x38
# We also change the item get model too, not just the field model.
item_resources_addr_to_fix = item_resources_list_start + item_id * 0x24
elif item_id in [0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72]:
# Songs use the Pirate's Charm model by default, so we change it to use the Wind Waker model instead.
item_id_to_copy_from = 0x22
# We also change the item get model too, not just the field model.
item_resources_addr_to_fix = item_resources_list_start + item_id * 0x24
elif item_id == 0xB2:
# The Magic Meter Upgrade has no model, so we have to copy the Green Potion model.
item_id_to_copy_from = 0x52
# We also change the item get model too, not just the field model.
item_resources_addr_to_fix = item_resources_list_start + item_id * 0x24
else:
item_id_to_copy_from = item_id
item_resources_addr_to_fix = None
item_resources_addr_to_copy_from = item_resources_list_start + item_id_to_copy_from * 0x24
field_item_resources_addr = field_item_resources_list_start + item_id * 0x1C
arc_name_pointer = randomizer.arc_name_pointers[item_id_to_copy_from]
if item_id == 0xAA:
# Hurricane Spin, switch it to using the custom scroll model instead of the sword model.
arc_name_pointer = randomizer.main_custom_symbols["hurricane_spin_item_resource_arc_name"]
item_resources_addr_to_fix = item_resources_list_start + item_id * 0x24
randomizer.dol.write_data(write_u32, field_item_resources_addr, arc_name_pointer)
if item_resources_addr_to_fix:
randomizer.dol.write_data(write_u32, item_resources_addr_to_fix, arc_name_pointer)
data1 = randomizer.dol.read_data(read_bytes, item_resources_addr_to_copy_from + 8, 0xD)
data2 = randomizer.dol.read_data(read_bytes, item_resources_addr_to_copy_from + 0x1C, 4)
randomizer.dol.write_data(write_bytes, field_item_resources_addr + 4, data1)
randomizer.dol.write_data(write_bytes, field_item_resources_addr + 0x14, data2)
if item_resources_addr_to_fix:
randomizer.dol.write_data(write_bytes, item_resources_addr_to_fix + 8, data1)
randomizer.dol.write_data(write_bytes, item_resources_addr_to_fix + 0x1C, data2)
# Also nop out the 7 lines of code that initialize the arc filename pointer for the 6 songs and the Hurricane Spin.
# These lines would overwrite the changes we made to their arc names.
for address in [0x800C1970, 0x800C1978, 0x800C1980, 0x800C1988, 0x800C1990, 0x800C1998, 0x800C1BA8]:
randomizer.dol.write_data(write_u32, address, 0x60000000) # nop
# Fix which code runs when the player touches the field item to pick the item up.
for item_id in range(0, 0x83 + 1):
# Update the switch statement cases in function itemGetExecute for items that originally used the default case (0x800F6C8C).
# This default case wouldn't give the player the item. It would just appear above the player's head for a moment like a Rupee and not be added to the player's inventory.
# We switch it to case 0x800F675C, which will use the proper item get event with all the animations, text, etc.
location_of_items_switch_statement_case = itemGetExecute_switch_statement_entries_list_start + item_id * 4
original_switch_case = randomizer.dol.read_data(read_u32, location_of_items_switch_statement_case)
if original_switch_case == 0x800F6C8C:
randomizer.dol.write_data(write_u32, location_of_items_switch_statement_case, 0x800F675C)
# Also change the switch case in itemGetExecute used by items with IDs 0x84+ to go to 800F675C as well.
randomizer.dol.write_data(write_u32, 0x800F6468, 0x418102F4) # bgt 0x800F675C
# Update the visual Y offsets so the item doesn't look like it's halfway inside the floor and difficult to see.
# First update the default case of the switch statement in the function getYOffset so that it reads from 803F9E84 (value: 23.0), instead of 803F9E80 (value: 0.0).
randomizer.dol.write_data(write_u32, 0x800F4CD0, 0xC022A184) # lfs f1, -0x5E7C(rtoc)
# And fix then Big Key so it uses the default case with the 23.0 offset, instead of using the 0.0 offset. (Other items already use the default case, so we don't need to fix any besides Big Key.)
randomizer.dol.write_data(write_u32, 0x8038C8B8 + 0x4E * 4, 0x800F4CD0)
# We also change the Y offset of the hitbox for any items that have 0 for the Y offset.
# Without this change the item would be very difficult to pick up, the only way would be to stand on top of it and do a spin attack.
# And also change the radius of the hitbox for items that have 0 for the radius.
extra_item_data_list_start = 0x803882B0
for item_id in range(0, 0xFF + 1):
item_extra_data_entry_addr = extra_item_data_list_start + 4 * item_id
original_y_offset = randomizer.dol.read_data(read_u8, item_extra_data_entry_addr + 1)
if original_y_offset == 0:
randomizer.dol.write_data(write_u8, item_extra_data_entry_addr + 1, 0x28) # Y offset of 0x28
original_radius = randomizer.dol.read_data(read_u8, item_extra_data_entry_addr + 2)
if original_radius == 0:
randomizer.dol.write_data(write_u8, item_extra_data_entry_addr + 2, 0x28) # Radius of 0x28
for item_id in range(0x20, 0x44 + 1):
# Update the switch statement cases in function mode_wait for certain items that originally used the default case (0x800F8190 - leads to calling itemActionForRupee).
# This default case caused items to have the physics of rupees, which causes them to shoot out too far from Gohdan's nose.
# We switch it to case 0x800F8160 (itemActionForArrow), which is what heart containers and heart pieces use.
location_of_items_switch_statement_case = mode_wait_switch_statement_entries_list_start + item_id * 4
randomizer.dol.write_data(write_u32, location_of_items_switch_statement_case, 0x800F8160)
# Also change the switch case used by items with IDs 0x4C+ to go to 800F8160 as well.
randomizer.dol.write_data(write_u32, 0x800F8138, 0x41810028) # bgt 0x800F8160
# Also add the Vscroll.arc containing the Hurricane Spin's custom model to the GCM's filesystem.
vscroll_arc_path = os.path.join(ASSETS_PATH, "Vscroll.arc")
with open(vscroll_arc_path, "rb") as f:
data = BytesIO(f.read())
randomizer.add_new_raw_file("files/res/Object/Vscroll.arc", data)
def remove_shop_item_forced_uniqueness_bit(randomizer: 'Randomizer'):
# Some shop items have a bit set that disallows you from buying the item if you already own one of that item.
# This can be undesirable depending on what we randomize the items to be, so we unset this bit.
# Also, Beedle doesn't have a message to say when you try to buy an item with this bit you already own. So the game would just crash if the player tried to buy these items while already owning them.
shop_item_data_list_start = 0x80375E1C
for shop_item_index in [0, 0xB, 0xC,
0xD]: # Bait Bag, Empty Bottle, Piece of Heart, and Treasure Chart 4 in Beedle's shops
shop_item_data_addr = shop_item_data_list_start + shop_item_index * 0x10
buy_requirements_bitfield = randomizer.dol.read_data(read_u8, shop_item_data_addr + 0xC)
buy_requirements_bitfield = (
buy_requirements_bitfield & (~2)) # Bit 02 specifies that the player must not already own this item
randomizer.dol.write_data(write_u8, shop_item_data_addr + 0xC, buy_requirements_bitfield)
def remove_forsaken_fortress_2_cutscenes(randomizer: 'Randomizer'):
# Removes the rescuing-Aryll cutscene played by the spawn when you enter the Forsaken Fortress tower.
dzx = randomizer.get_arc("files/res/Stage/M2tower/Room0.arc").get_file("room.dzr")
spawn = next(spawn for spawn in dzx.entries_by_type("PLYR") if spawn.spawn_id == 16)
spawn.evnt_index = 0xFF
spawn.save_changes()
# Removes the Ganon cutscene by making the door to his room lead back to the start of Forsaken Fortress instead.
exit = next((exit for exit in dzx.entries_by_type("SCLS") if exit.dest_stage_name == "M2ganon"), None)
if exit:
exit.dest_stage_name = "sea"
exit.room_index = 1
exit.spawn_id = 0
exit.save_changes()
def make_items_progressive(randomizer: 'Randomizer'):
# This makes items progressive, so even if you get them out of order, they will always be upgraded, never downgraded.
patcher.apply_patch(randomizer, "make_items_progressive")
# Update the item get funcs for the items to point to our custom progressive item get funcs instead.
item_get_funcs_list = 0x803888C8
for sword_item_id in [0x38, 0x39, 0x3A, 0x3D, 0x3E]:
sword_item_get_func_addr = item_get_funcs_list + sword_item_id * 4
randomizer.dol.write_data(write_u32, sword_item_get_func_addr,
randomizer.main_custom_symbols["progressive_sword_item_func"])
for shield_item_id in [0x3B, 0x3C]:
shield_item_get_func_addr = item_get_funcs_list + shield_item_id * 4
randomizer.dol.write_data(write_u32, shield_item_get_func_addr,
randomizer.main_custom_symbols["progressive_shield_item_func"])
for bow_item_id in [0x27, 0x35, 0x36]:
bow_item_get_func_addr = item_get_funcs_list + bow_item_id * 4
randomizer.dol.write_data(write_u32, bow_item_get_func_addr, randomizer.main_custom_symbols["progressive_bow_func"])
for wallet_item_id in [0xAB, 0xAC]:
wallet_item_get_func_addr = item_get_funcs_list + wallet_item_id * 4
randomizer.dol.write_data(write_u32, wallet_item_get_func_addr,
randomizer.main_custom_symbols["progressive_wallet_item_func"])
for bomb_bag_item_id in [0xAD, 0xAE]:
bomb_bag_item_get_func_addr = item_get_funcs_list + bomb_bag_item_id * 4
randomizer.dol.write_data(write_u32, bomb_bag_item_get_func_addr,
randomizer.main_custom_symbols["progressive_bomb_bag_item_func"])
for quiver_item_id in [0xAF, 0xB0]:
quiver_item_get_func_addr = item_get_funcs_list + quiver_item_id * 4
randomizer.dol.write_data(write_u32, quiver_item_get_func_addr,
randomizer.main_custom_symbols["progressive_quiver_item_func"])
for picto_box_item_id in [0x23, 0x26]:
picto_box_item_get_func_addr = item_get_funcs_list + picto_box_item_id * 4
randomizer.dol.write_data(write_u32, picto_box_item_get_func_addr,
randomizer.main_custom_symbols["progressive_picto_box_item_func"])
# Register which item ID is for which progressive item.
randomizer.register_renamed_item(0x38, "Progressive Sword")
randomizer.register_renamed_item(0x3B, "Progressive Shield")
randomizer.register_renamed_item(0x27, "Progressive Bow")
randomizer.register_renamed_item(0xAB, "Progressive Wallet")
randomizer.register_renamed_item(0xAD, "Progressive Bomb Bag")
randomizer.register_renamed_item(0xAF, "Progressive Quiver")
randomizer.register_renamed_item(0x23, "Progressive Picto Box")
# Modify the item get funcs for bombs and the hero's bow to nop out the code that sets your current and max bombs/arrows to 30.
# Without this change, getting bombs after a bomb bag upgrade would negate the bomb bag upgrade.
# Note that normally making this change would cause the player to have 0 max bombs/arrows if they get bombs/bow before any bomb bag/quiver upgrades.
# But in the new game start code, we set the player's current and max bombs and arrows to 30, so that is no longer an issue.
randomizer.dol.write_data(write_u32, 0x800C36C0, 0x60000000) # Don't set current bombs
randomizer.dol.write_data(write_u32, 0x800C36C4, 0x60000000) # Don't set max bombs
randomizer.dol.write_data(write_u32, 0x800C346C, 0x60000000) # Don't set current arrows
randomizer.dol.write_data(write_u32, 0x800C3470, 0x60000000) # Don't set max arrows
# Modify the item get func for deku leaf to nop out the part where it adds to your magic meter.
# Instead we start the player with a magic meter when they start a new game.
# This way other items can use the magic meter before the player gets deku leaf.
randomizer.dol.write_data(write_u32, 0x800C375C, 0x60000000) # Don't set max magic meter
randomizer.dol.write_data(write_u32, 0x800C3768, 0x60000000) # Don't set current magic meter
def make_sail_behave_like_swift_sail(randomizer: 'Randomizer'):
# Causes the wind direction to always change to face the direction KoRL is facing as long as the sail is out.
# Also doubles KoRL's speed.
# And changes the textures to match the swift sail from HD.
# Apply the asm patch.
patcher.apply_patch(randomizer, "swift_sail")
# Update the pause menu name for the sail.
msg = randomizer.bmg.messages_by_id[463]
msg.string = "Swift Sail"
new_sail_tex_image_path = os.path.join(ASSETS_PATH, "swift sail texture.png")
new_sail_icon_image_path = os.path.join(ASSETS_PATH, "swift sail icon.png")
new_sail_itemget_tex_image_path = os.path.join(ASSETS_PATH, "swift sail item get texture.png")
if not randomizer.using_custom_sail_texture:
# Modify the sail's texture while sailing (only if the custom player model didn't already change the sail texture).
ship_arc = randomizer.get_arc("files/res/Object/Ship.arc")
sail_image = ship_arc.get_file("new_ho1.bti")
sail_image.replace_image_from_path(new_sail_tex_image_path)
sail_image.save_changes()
# Modify the sail's item icon.
itemicon_arc = randomizer.get_arc("files/res/Msg/itemicon.arc")
sail_icon_image = itemicon_arc.get_file("sail_00.bti")
sail_icon_image.replace_image_from_path(new_sail_icon_image_path)
sail_icon_image.save_changes()
# Modify the sail's item get texture.
sail_itemget_arc = randomizer.get_arc("files/res/Object/Vho.arc")
sail_itemget_model = sail_itemget_arc.get_file("vho.bdl")
sail_itemget_tex_image = sail_itemget_model.tex1.textures_by_name["Vho"][0]
sail_itemget_tex_image.replace_image_from_path(new_sail_itemget_tex_image_path)
sail_itemget_model.save_changes()
def add_ganons_tower_warp_to_ff2(randomizer: 'Randomizer'):
# Normally the warp object from Forsaken Fortress down to Ganon's Tower only appears in FF3.
# But we changed Forsaken Fortress to remain permanently as FF2.
# So we need to add the warp object to FF2 as well so the player can conveniently go between the sea and Ganon's Tower.
# To do this we copy the warp entity from layer 2 onto layer 1.
dzx = randomizer.get_arc("files/res/Stage/sea/Room1.arc").get_file("room.dzr")
layer_2_actors = dzx.entries_by_type_and_layer("ACTR", 2)
layer_2_warp = next(x for x in layer_2_actors if x.name == "Warpmj")
layer_1_warp = dzx.add_entity("ACTR", layer=1)
layer_1_warp.name = layer_2_warp.name
layer_1_warp.params = layer_2_warp.params
layer_1_warp.x_pos = layer_2_warp.x_pos
layer_1_warp.y_pos = layer_2_warp.y_pos
layer_1_warp.z_pos = layer_2_warp.z_pos
layer_1_warp.x_rot = layer_2_warp.x_rot
layer_1_warp.y_rot = layer_2_warp.y_rot
layer_1_warp.z_rot = layer_2_warp.z_rot
layer_1_warp.enemy_number = layer_2_warp.enemy_number
dzx.save_changes()
def add_chest_in_place_medli_grappling_hook_gift(randomizer: 'Randomizer'):
# Add a chest in place of Medli locked in the jail cell at the peak of Dragon Roost Cavern.
dzs = randomizer.get_arc("files/res/Stage/M_Dra09/Stage.arc").get_file("stage.dzs")
chest_in_jail = dzs.add_entity("TRES", layer=None)
chest_in_jail.name = "takara3"
chest_in_jail.params = 0xFF000000
chest_in_jail.switch_to_set = 0xFF
chest_in_jail.chest_type = 2
chest_in_jail.opened_flag = 0x11
chest_in_jail.x_pos = -1620.81
chest_in_jail.y_pos = 13600
chest_in_jail.z_pos = 263.034
chest_in_jail.room_num = 9
chest_in_jail.y_rot = 0xCC16
chest_in_jail.item_id = randomizer.item_name_to_id["Grappling Hook"]
dzs.save_changes()
dzs = randomizer.get_arc("files/res/Stage/M_NewD2/Stage.arc").get_file("stage.dzs")
dummy_chest = dzs.add_entity("TRES", layer=None)
dummy_chest.name = chest_in_jail.name
dummy_chest.params = chest_in_jail.params
dummy_chest.switch_to_set = chest_in_jail.switch_to_set
dummy_chest.chest_type = chest_in_jail.chest_type
dummy_chest.opened_flag = chest_in_jail.opened_flag
dummy_chest.x_pos = chest_in_jail.x_pos
dummy_chest.y_pos = chest_in_jail.y_pos
dummy_chest.z_pos = chest_in_jail.z_pos
dummy_chest.room_num = chest_in_jail.room_num
dummy_chest.y_rot = chest_in_jail.y_rot
dummy_chest.item_id = 0xFF
dzs.save_changes()
def add_chest_in_place_queen_fairy_cutscene(randomizer: 'Randomizer'):
# Add a chest in place of the Queen Fairy cutscene inside Mother Isle.
dzx = randomizer.get_arc("files/res/Stage/sea/Room9.arc").get_file("room.dzr")
mother_island_chest = dzx.add_entity("TRES", layer=None)
mother_island_chest.name = "takara3"
mother_island_chest.params = 0xFF000000
mother_island_chest.switch_to_set = 0xFF
mother_island_chest.chest_type = 2
mother_island_chest.opened_flag = 0x1C
mother_island_chest.x_pos = -180031
mother_island_chest.y_pos = 723
mother_island_chest.z_pos = -199995
mother_island_chest.room_num = 9
mother_island_chest.y_rot = 0x1000
mother_island_chest.item_id = randomizer.item_name_to_id["Progressive Bow"]
dzx.save_changes()
def add_cube_to_earth_temple_first_room(randomizer: 'Randomizer'):
# If the player enters Earth Temple, uses Medli to cross the gap, brings Medli into the next room, then leaves Earth Temple, Medli will no longer be in the first room.
# This can softlock the player if they don't have Deku Leaf to get across the gap in that first room.
# So we add a cube to that first room so the player can just climb up.
dzx = randomizer.get_arc("files/res/Stage/M_Dai/Room0.arc").get_file("room.dzr")
cube = dzx.add_entity("ACTR", layer=None)
cube.name = "Ecube"
cube.params = 0x8C00FF00
cube.x_pos = -6986.07
cube.y_pos = -600
cube.z_pos = 4077.37
dzx.save_changes()
def add_more_magic_jars(randomizer: 'Randomizer'):
# Add more magic jar drops to locations where it can be very inconvenient to not have them.
# Dragon Roost Cavern doesn't have any magic jars in it since you normally wouldn't have Deku Leaf for it.
# But since using Deku Leaf in DRC can be required by the randomizer, it can be annoying to not have any way to refill MP.
# We change several skulls that originally dropped nothing when destroyed to drop magic jars instead.
drc_center_room = randomizer.get_arc("files/res/Stage/M_NewD2/Room2.arc").get_file("room.dzr")
actors = drc_center_room.entries_by_type("ACTR")
skulls = [actor for actor in actors if actor.name == "Odokuro"]
skulls[2].item_id = randomizer.item_name_to_id["Small Magic Jar (Pickup)"]
skulls[2].save_changes()
skulls[5].item_id = randomizer.item_name_to_id["Large Magic Jar (Pickup)"]
skulls[5].save_changes()
drc_before_boss_room = randomizer.get_arc("files/res/Stage/M_NewD2/Room10.arc").get_file("room.dzr")
actors = drc_before_boss_room.entries_by_type("ACTR")
skulls = [actor for actor in actors if actor.name == "Odokuro"]
skulls[0].item_id = randomizer.item_name_to_id["Large Magic Jar (Pickup)"]
skulls[0].save_changes()
skulls[9].item_id = randomizer.item_name_to_id["Large Magic Jar (Pickup)"]
skulls[9].save_changes()
# The grass on the small elevated islands around DRI have a lot of grass that can drop magic, but it's not guaranteed.
# Add a new piece of grass to each of the 2 small islands that are guaranteed to drop magic.
dri = randomizer.get_arc("files/res/Stage/sea/Room13.arc").get_file("room.dzr")
grass1 = dri.add_entity("ACTR", layer=None)
grass1.name = "kusax1"
grass1.grass_type = 0
grass1.grass_subtype = 0
grass1.grass_item_drop_type = 0x38 # 62.50% chance of small magic, 37.50% chance of large magic
grass1.x_pos = 209694
grass1.y_pos = 1900
grass1.z_pos = -202463
grass2 = dri.add_entity("ACTR", layer=None)
grass2.name = "kusax1"
grass2.grass_type = 0
grass2.grass_subtype = 0
grass2.grass_item_drop_type = 0x38 # 62.50% chance of small magic, 37.50% chance of large magic
grass2.x_pos = 209333
grass2.y_pos = 1300
grass2.z_pos = -210145
dri.save_changes()
# Make one of the pots next to the entrance to the TotG miniboss always drop large magic.
totg_before_miniboss_room = randomizer.get_arc("files/res/Stage/Siren/Room14.arc").get_file("room.dzr")
actors = totg_before_miniboss_room.entries_by_type("ACTR")
pots = [actor for actor in actors if actor.name == "kotubo"]
pots[1].item_id = randomizer.item_name_to_id["Large Magic Jar (Pickup)"]
pots[1].save_changes()
def remove_title_and_ending_videos(randomizer: 'Randomizer'):
# Remove the huge video files that play during the ending and if you sit on the title screen a while.
# We replace them with a very small blank video file to save space.
blank_video_path = os.path.join(ASSETS_PATH, "blank.thp")
with open(blank_video_path, "rb") as f:
new_data = BytesIO(f.read())
randomizer.replace_raw_file("files/thpdemo/title_loop.thp", new_data)
randomizer.replace_raw_file("files/thpdemo/end_st_epilogue.thp", new_data)
def modify_title_screen_logo(randomizer: 'Randomizer'):
new_title_image_path = os.path.join(ASSETS_PATH, "title.png")
new_subtitle_image_path = os.path.join(ASSETS_PATH, "subtitle.png")
tlogoe_arc = randomizer.get_arc("files/res/Object/TlogoE.arc")
title_image = tlogoe_arc.get_file("logo_zelda_main.bti")
title_image.replace_image_from_path(new_title_image_path)
title_image.save_changes()
subtitle_model = tlogoe_arc.get_file("subtitle_start_anim_e.bdl")
subtitle_image = subtitle_model.tex1.textures_by_name["logo_sub_e"][0]
subtitle_image.replace_image_from_path(new_subtitle_image_path)
subtitle_model.save_changes()
subtitle_glare_model = tlogoe_arc.get_file("subtitle_kirari_e.bdl")
subtitle_glare_image = subtitle_glare_model.tex1.textures_by_name["logo_sub_e"][0]
subtitle_glare_image.replace_image_from_path(new_subtitle_image_path)
subtitle_glare_model.save_changes()
# Move where the subtitle is drawn downwards a bit so the word "the" doesn't get covered up by the main logo.
title_rel = randomizer.get_rel("files/rels/d_a_title.rel")
y_pos = title_rel.read_data(read_float, 0x1F44)
y_pos -= 13.0
title_rel.write_data(write_float, 0x1F44, y_pos)
# Move the sparkle particle effect down a bit to fit the taller logo better.
# (This has the side effect of also moving down the clouds below the ship, but this is not noticeable.)
data = tlogoe_arc.get_file_entry("title_logo_e.blo").data
write_u16(data, 0x162, 0x106) # Increase Y pos by 16 pixels (0xF6 -> 0x106)
def update_game_name_icon_and_banners(randomizer: 'Randomizer'):
new_game_name = "Wind Waker Randomized %s" % randomizer.seed
banner_data = randomizer.get_raw_file("files/opening.bnr")
write_magic_str(banner_data, 0x1860, new_game_name, 0x40)
new_game_id = "GZLE99"
boot_data = randomizer.get_raw_file("sys/boot.bin")
write_magic_str(boot_data, 0, new_game_id, 6)
new_memory_card_game_name = "Wind Waker Randomizer"
randomizer.dol.write_data(write_magic_str, 0x80339690, new_memory_card_game_name, 21)
new_image_file_path = os.path.join(ASSETS_PATH, "banner.png")
image_format = texture_utils.ImageFormat.RGB5A3
palette_format = texture_utils.PaletteFormat.RGB5A3
image_data, _, _, image_width, image_height = texture_utils.encode_image_from_path(new_image_file_path,
image_format, palette_format)
assert image_width == 96
assert image_height == 32
assert data_len(image_data) == 0x1800
image_data.seek(0)
write_bytes(banner_data, 0x20, image_data.read())
cardicon_arc = randomizer.get_arc("files/res/CardIcon/cardicon.arc")
memory_card_icon_file_path = os.path.join(ASSETS_PATH, "memory card icon.png")
memory_card_icon = cardicon_arc.get_file("ipl_icon1.bti")
memory_card_icon.replace_image_from_path(memory_card_icon_file_path)
memory_card_icon.save_changes()
memory_card_banner_file_path = os.path.join(ASSETS_PATH, "memory card banner.png")
memory_card_banner = cardicon_arc.get_file("ipl_banner.bti")
memory_card_banner.replace_image_from_path(memory_card_banner_file_path)
memory_card_banner.save_changes()
def allow_dungeon_items_to_appear_anywhere(randomizer: 'Randomizer'):
item_get_funcs_list = 0x803888C8
item_resources_list_start = 0x803842B0
field_item_resources_list_start = 0x803866B0
dungeon_items = [
("DRC", "Small Key", 0x13),
("DRC", "Big Key", 0x14),
("DRC", "Dungeon Map", 0x1B),
("DRC", "Compass", 0x1C),
("FW", "Small Key", 0x1D),
("FW", "Big Key", 0x40),
("FW", "Dungeon Map", 0x41),
("FW", "Compass", 0x5A),
("TotG", "Small Key", 0x5B),
("TotG", "Big Key", 0x5C),
("TotG", "Dungeon Map", 0x5D),
("TotG", "Compass", 0x5E),
("FF", "Dungeon Map", 0x5F),
("FF", "Compass", 0x60),
("ET", "Small Key", 0x73),
("ET", "Big Key", 0x74),
("ET", "Dungeon Map", 0x75),
("ET", "Compass", 0x76),
("WT", "Small Key", 0x77),
("WT", "Big Key", 0x81),
("WT", "Dungeon Map", 0x84),
("WT", "Compass", 0x85),
]
for short_dungeon_name, base_item_name, item_id in dungeon_items:
item_name = short_dungeon_name + " " + base_item_name
base_item_id = randomizer.item_name_to_id[base_item_name]
dungeon_name = DUNGEON_NAME_DICT[short_dungeon_name]
# Register the proper item ID for this item with the randomizer.
randomizer.register_renamed_item(item_id, item_name)
# Update the item get funcs for the dungeon items to point to our custom item get funcs instead.
custom_symbol_name = item_name.lower().replace(" ", "_") + "_item_get_func"
item_get_func_addr = item_get_funcs_list + item_id * 4
randomizer.dol.write_data(write_u32, item_get_func_addr, randomizer.main_custom_symbols[custom_symbol_name])
# Add item get messages for the items.
if base_item_name == "Small Key":
description_format_string = "\\{1A 05 00 00 01}You got %s \\{1A 06 FF 00 00 01}%s small key\\{1A 06 FF 00 00 00}!"
description = word_wrap_string(
description_format_string % (get_indefinite_article(dungeon_name), dungeon_name))
elif base_item_name == "Big Key":
description_format_string = "\\{1A 05 00 00 01}You got the \\{1A 06 FF 00 00 01}%s Big Key\\{1A 06 FF 00 00 00}!"
description = word_wrap_string(description_format_string % dungeon_name)
elif base_item_name == "Dungeon Map":
description_format_string = "\\{1A 05 00 00 01}You got the \\{1A 06 FF 00 00 01}%s Dungeon Map\\{1A 06 FF 00 00 00}!"
description = word_wrap_string(description_format_string % dungeon_name)
elif base_item_name == "Compass":
description_format_string = "\\{1A 05 00 00 01}You got the \\{1A 06 FF 00 00 01}%s Compass\\{1A 06 FF 00 00 00}!"
description = word_wrap_string(description_format_string % dungeon_name)
msg = randomizer.bmg.add_new_message(101 + item_id)
msg.string = description
msg.text_box_type = 9 # Item get message box
msg.initial_draw_type = 2 # Slow initial message speed
msg.display_item_id = item_id
# Update item resources and field item resources so the models/icons show correctly for these items.
item_resources_addr_to_copy_from = item_resources_list_start + base_item_id * 0x24
field_item_resources_addr_to_copy_from = field_item_resources_list_start + base_item_id * 0x24
item_resources_addr = item_resources_list_start + item_id * 0x24
field_item_resources_addr = field_item_resources_list_start + item_id * 0x1C
arc_name_pointer = randomizer.arc_name_pointers[base_item_id]
randomizer.dol.write_data(write_u32, field_item_resources_addr, arc_name_pointer)
randomizer.dol.write_data(write_u32, item_resources_addr, arc_name_pointer)
item_icon_filename_pointer = randomizer.icon_name_pointer[base_item_id]
randomizer.dol.write_data(write_u32, item_resources_addr + 4, item_icon_filename_pointer)
data1 = randomizer.dol.read_data(read_bytes, item_resources_addr_to_copy_from + 8, 0xD)
randomizer.dol.write_data(write_bytes, item_resources_addr + 8, data1)
randomizer.dol.write_data(write_bytes, field_item_resources_addr + 4, data1)
data2 = randomizer.dol.read_data(read_bytes, item_resources_addr_to_copy_from + 0x1C, 4)
randomizer.dol.write_data(write_bytes, item_resources_addr + 0x1C, data2)
randomizer.dol.write_data(write_bytes, field_item_resources_addr + 0x14, data2)
data3 = randomizer.dol.read_data(read_bytes, item_resources_addr_to_copy_from + 0x15, 7)
randomizer.dol.write_data(write_bytes, item_resources_addr + 0x15, data3)
data4 = randomizer.dol.read_data(read_bytes, item_resources_addr_to_copy_from + 0x20, 4)
randomizer.dol.write_data(write_bytes, item_resources_addr + 0x20, data4)
data5 = randomizer.dol.read_data(read_bytes, field_item_resources_addr_to_copy_from + 0x11, 3)
randomizer.dol.write_data(write_bytes, field_item_resources_addr + 0x11, data5)
data6 = randomizer.dol.read_data(read_bytes, field_item_resources_addr_to_copy_from + 0x18, 4)
randomizer.dol.write_data(write_bytes, field_item_resources_addr + 0x18, data6)
def word_wrap_string(string, max_line_length=34):
index_in_str = 0
wordwrapped_str = ""
current_word = ""
current_word_length = 0
length_of_curr_line = 0
while index_in_str < len(string):
char = string[index_in_str]
if char == "\\":
assert string[index_in_str + 1] == "{"
substr = string[index_in_str:]
control_code_str_len = substr.index("}") + 1
substr = substr[:control_code_str_len]
current_word += substr
index_in_str += control_code_str_len
elif char == "\n":
wordwrapped_str += current_word
wordwrapped_str += char
length_of_curr_line = 0
current_word = ""
current_word_length = 0
index_in_str += 1
elif char == " ":
wordwrapped_str += current_word
wordwrapped_str += char
length_of_curr_line += current_word_length + len(char)
current_word = ""
current_word_length = 0
index_in_str += 1
else:
current_word += char
current_word_length += 1
index_in_str += 1
if length_of_curr_line + current_word_length > max_line_length:
wordwrapped_str += "\n"
length_of_curr_line = 0
if current_word_length > max_line_length:
wordwrapped_str += current_word + "\n"
current_word = ""
wordwrapped_str += current_word
return wordwrapped_str
def get_indefinite_article(string):
first_letter = string.strip()[0].lower()
if first_letter in ["a", "e", "i", "o", "u"]:
return "an"
else:
return "a"
def upper_first_letter(string):
first_letter = string[0].upper()
return first_letter + string[1:]
def pad_string_to_next_4_lines(string):
lines = string.split("\n")
padding_lines_needed = (4 - len(lines) % 4) % 4
for i in range(padding_lines_needed):
lines.append("")
return "\n".join(lines) + "\n"
def remove_ballad_of_gales_warp_in_cutscene(randomizer: 'Randomizer'):
for island_index in range(1, 49 + 1):
dzx = randomizer.get_arc("files/res/Stage/sea/Room%d.arc" % island_index).get_file("room.dzr")
for spawn in dzx.entries_by_type("PLYR"):
if spawn.spawn_type == 9: # Spawn type is warping in on a cyclone
spawn.spawn_type = 2 # Change to spawn type of instantly spawning on KoRL instead
spawn.save_changes()
def fix_shop_item_y_offsets(randomizer: 'Randomizer'):
shop_item_display_data_list_start = 0x8034FD10
for item_id in range(0, 0xFE + 1):
display_data_addr = shop_item_display_data_list_start + item_id * 0x20
y_offset = randomizer.dol.read_data(read_float, display_data_addr + 0x10)
if y_offset == 0 and item_id not in [0x10, 0x11, 0x12]:
# If the item didn't originally have a Y offset we need to give it one so it's not sunken into the pedestal.
# Only exception are for items 10 11 and 12 - arrow refill pickups. Those have no Y offset but look fine already.
new_y_offset = 20.0
randomizer.dol.write_data(write_float, display_data_addr + 0x10, new_y_offset)
def update_shop_item_descriptions(randomizer: 'Randomizer', locations: List[Location]):
item_name = filter((lambda loc: loc.name == "GreatSeaBeedleShop20Rupee"),
locations).__next__().current_item.simple_offset_rep()
cost = 20
msg = randomizer.bmg.messages_by_id[3906]
msg.string = "\\{1A 06 FF 00 00 01}%s %d Rupees\\{1A 06 FF 00 00 00}" % (item_name, cost)
msg = randomizer.bmg.messages_by_id[3909]
msg.string = "%s %d Rupees\nWill you buy it?\n\\{1A 05 00 00 08}I'll buy it\nNo thanks" % (item_name, cost)
item_name = filter((lambda loc: loc.name == "RockSpireBeedle500RupeeItem"),
locations).__next__().current_item.simple_offset_rep()
cost = 500
msg = randomizer.bmg.messages_by_id[12106]
msg.string = "\\{1A 06 FF 00 00 01}%s %d Rupees\n\\{1A 06 FF 00 00 00}This is my last one." % (item_name, cost)
msg = randomizer.bmg.messages_by_id[12109]
msg.string = "This \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00} is a mere \\{1A 06 FF 00 00 01}%d Rupees\\{1A 06 FF 00 00 00}!\nBuy it! Buy it! Buy buy buy!\n\\{1A 05 00 00 08}I'll buy it\nNo thanks" % (
item_name, cost)
item_name = filter((lambda loc: loc.name == "RockSpireBeedle950RupeeItem"),
locations).__next__().current_item.simple_offset_rep()
cost = 950
msg = randomizer.bmg.messages_by_id[12107]
msg.string = "\\{1A 06 FF 00 00 01}%s %d Rupees\n\\{1A 06 FF 00 00 00}This is my last one of these, too." % (
item_name, cost)
msg = randomizer.bmg.messages_by_id[12110]
msg.string = "This \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00} is only \\{1A 06 FF 00 00 01}%d Rupees\\{1A 06 FF 00 00 00}!\nBuy it! Buy it! Buy buy buy!\n\\{1A 05 00 00 08}I'll buy it\nNo thanks" % (
item_name, cost)
item_name = filter((lambda loc: loc.name == "RockSpireBeedle900RupeeItem"),
locations).__next__().current_item.simple_offset_rep()
cost = 900
msg = randomizer.bmg.messages_by_id[12108]
msg.string = "\\{1A 06 FF 00 00 01}%s %d Rupees\n\\{1A 06 FF 00 00 00}The price may be high, but it'll pay\noff handsomely in the end!" % (
item_name, cost)
msg = randomizer.bmg.messages_by_id[12111]
msg.string = "This \\{1A 06 FF 00 00 01}%s \\{1A 06 FF 00 00 00}is just \\{1A 06 FF 00 00 01}%d Rupees!\\{1A 06 FF 00 00 00}\nBuy it! Buy it! Buy buy buy!\n\\{1A 05 00 00 08}I'll buy it\nNo thanks" % (
item_name, cost)
def update_auction_item_names(randomizer: 'Randomizer', locations: List[Location]):
item_name = filter((lambda loc: loc.name == "WindfallAuction5Rupee"),
locations).__next__().current_item.simple_offset_rep()
msg = randomizer.bmg.messages_by_id[7441]
msg.string = "\\{1A 06 FF 00 00 01}%s" % item_name
item_name = filter((lambda loc: loc.name == "WindfallAuction40Rupee"),
locations).__next__().current_item.simple_offset_rep()
msg = randomizer.bmg.messages_by_id[7440]
msg.string = "\\{1A 06 FF 00 00 01}%s" % item_name
item_name = filter((lambda loc: loc.name == "WindfallAuction60Rupee"),
locations).__next__().current_item.simple_offset_rep()
msg = randomizer.bmg.messages_by_id[7442]
msg.string = "\\{1A 06 FF 00 00 01}%s" % item_name
item_name = filter((lambda loc: loc.name == "WindfallAuction80Rupee"),
locations).__next__().current_item.simple_offset_rep()
msg = randomizer.bmg.messages_by_id[7443]
msg.string = "\\{1A 06 FF 00 00 01}%s" % item_name
def update_battlesquid_item_names(randomizer: 'Randomizer', locations: List[Location]):
item_name = filter((lambda loc: loc.name == "WindfallBattleSquidFirstPrize"),
locations).__next__().current_item.simple_offset_rep()
msg = randomizer.bmg.messages_by_id[7520]
msg.string = "\\{1A 05 01 00 8E}Hoorayyy! Yayyy! Yayyy!\nOh, thank you, Mr. Sailor!\n\n\n"
msg.string += word_wrap_string(
"Please take this \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00} as a sign of our gratitude. You are soooooo GREAT!" % item_name,
max_line_length=43
)
item_name = filter((lambda loc: loc.name == "WindfallBattleSquidSecondPrize"),
locations).__next__().current_item.simple_offset_rep()
msg = randomizer.bmg.messages_by_id[7521]
msg.string = "\\{1A 05 01 00 8E}Hoorayyy! Yayyy! Yayyy!\nOh, thank you so much, Mr. Sailor!\n\n\n"
msg.string += word_wrap_string(
"This is our thanks to you! It's been passed down on our island for many years, so don't tell the island elder, OK? Here...\\{1A 06 FF 00 00 01}\\{1A 05 00 00 39} \\{1A 06 FF 00 00 00}Please accept this \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}!" % item_name,
max_line_length=43
)
# The high score one doesn't say the item name in text anywhere, so no need to update it.
# item_name = self.logic.done_item_locations["Windfall Island - Battlesquid - 20 Shots or Less Prize"]
# msg = self.bmg.messages_by_id[7523]
def update_item_names_in_letter_advertising_rock_spire_shop(randomizer: 'Randomizer', locations: List[Location]):
item_name_1 = filter((lambda loc: loc.name == "RockSpireBeedle500RupeeItem"),
locations).__next__().current_item.simple_offset_rep()
item_name_2 = filter((lambda loc: loc.name == "RockSpireBeedle950RupeeItem"),
locations).__next__().current_item.simple_offset_rep()
item_name_3 = filter((lambda loc: loc.name == "RockSpireBeedle900RupeeItem"),
locations).__next__().current_item.simple_offset_rep()
msg = randomizer.bmg.messages_by_id[3325]
lines: List[AnyStr] = msg.string.split("\n")
unchanged_string_before = "\n".join(lines[0:8]) + "\n"
unchanged_string_after = "\n".join(lines[12:])
hint_string = "Do you have need of %s \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}, %s \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}, or %s \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}? We have them at special bargain prices." % (
get_indefinite_article(item_name_1), item_name_1,
get_indefinite_article(item_name_2), item_name_2,
get_indefinite_article(item_name_3), item_name_3,
)
# Letters have 2 spaces at the start of each line, so word wrap to 39 chars instead of 43, then add 2 spaces to each line.
hint_string = word_wrap_string(hint_string, max_line_length=39)
hint_string = pad_string_to_next_4_lines(hint_string)
hint_lines = hint_string.split("\n")
leading_spaces_hint_lines = []
for hint_line in hint_lines:
if hint_line == "":
leading_spaces_hint_lines.append(hint_line)
else:
leading_spaces_hint_lines.append(" " + hint_line)
hint_string = "\n".join(leading_spaces_hint_lines)
msg.string = unchanged_string_before
msg.string += hint_string
msg.string += unchanged_string_after
def update_savage_labyrinth_hint_tablet(randomizer: 'Randomizer', locations: List[Location]):
# Update the tablet on the first floor of savage labyrinth to give hints as to the items inside the labyrinth.
floor_30_item_name = filter((lambda loc: loc.name == "OutsetSavageFloor30Chest"),
locations).__next__().current_item.simple_offset_rep()
floor_50_item_name = filter((lambda loc: loc.name == "OutsetSavageFloor50Chest"),
locations).__next__().current_item.simple_offset_rep()
floor_30_is_progress = False
floor_50_is_progress = False
floor_30_item_name = get_hint_item_name(floor_30_item_name)
floor_50_item_name = get_hint_item_name(floor_50_item_name)
if floor_30_is_progress and not floor_30_item_name in randomizer.progress_item_hints:
raise Exception("Could not find progress item hint for item: %s" % floor_30_item_name)
if floor_50_is_progress and not floor_50_item_name in randomizer.progress_item_hints:
raise Exception("Could not find progress item hint for item: %s" % floor_50_item_name)
if floor_30_is_progress and floor_50_is_progress:
floor_30_item_hint = randomizer.progress_item_hints[floor_30_item_name]
floor_50_item_hint = randomizer.progress_item_hints[floor_50_item_name]
hint = "\\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}" % floor_30_item_hint
hint += " and "
hint += "\\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}" % floor_50_item_hint
hint += " await"
elif floor_30_is_progress:
floor_30_item_hint = randomizer.progress_item_hints[floor_30_item_name]
hint = "\\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}" % floor_30_item_hint
hint += " and "
hint += "challenge"
hint += " await"
elif floor_50_is_progress:
floor_50_item_hint = randomizer.progress_item_hints[floor_50_item_name]
hint = "challenge"
hint += " and "
hint += "\\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}" % floor_50_item_hint
hint += " await"
else:
hint = "challenge"
hint += " awaits"
msg = randomizer.bmg.messages_by_id[837]
msg.string = "\\{1A 07 FF 00 01 00 96}\\{1A 06 FF 00 00 01}The Savage Labyrinth\n\\{1A 07 FF 00 01 00 64}\n\n\n"
msg.string += word_wrap_string(
"\\{1A 06 FF 00 00 00}Deep in the never-ending darkness, the way to %s." % hint,
max_line_length=43
)
def insert_world_id(randomizer: 'Randomizer', world_id: int):
randomizer.dol.write_data(write_u8, randomizer.main_custom_symbols["inject_world_id"] + 3, world_id + 1)
def randomize_and_update_hints(randomizer: 'Randomizer'):
hints = []
unique_items_given_hint_for = []
possible_item_locations: List[Location] = list(randomizer.logic.done_item_locations.keys())
randomizer.rng.shuffle(possible_item_locations)
num_fishman_hints = 15
desired_num_hints = 1 + num_fishman_hints
min_num_hints_needed = 1 + 1
while True:
if not possible_item_locations:
if len(hints) >= min_num_hints_needed:
break
elif len(hints) >= 1:
# Succeeded at making at least 1 hint but not enough to reach the minimum.
# So duplicate the hint(s) we DID make to fill up the missing slots.
unique_hints = hints.copy()
while len(hints) < min_num_hints_needed:
hints += unique_hints
hints = hints[:min_num_hints_needed]
break
else:
raise Exception("No valid items to give hints for")
location_name = possible_item_locations.pop()
if location_name in randomizer.race_mode_required_locations:
# You already know which boss locations have a required item and which don't in race mode by looking at the sea chart.
continue
if location_name == "Two-Eye Reef - Big Octo Great Fairy":
# We don't want this Great Fairy to hint at her own item.
continue
item_name = randomizer.logic.done_item_locations[location_name]
if item_name not in randomizer.logic.all_progress_items:
continue
if randomizer.logic.is_dungeon_item(item_name) and not randomizer.options.get("keylunacy"):
continue
item_name = get_hint_item_name(item_name)
if item_name == "Bait Bag":
# Can't access fishmen hints until you already have the bait bag
continue
if len(hints) >= desired_num_hints:
break
zone_name, specific_location_name = randomizer.logic.split_location_name_by_zone(location_name)
is_dungeon = "Dungeon" in randomizer.logic.item_locations[location_name]["Types"]
is_puzzle_cave = "Puzzle Secret Cave" in randomizer.logic.item_locations[location_name]["Types"]
is_combat_cave = "Combat Secret Cave" in randomizer.logic.item_locations[location_name]["Types"]
is_savage = "Savage Labyrinth" in randomizer.logic.item_locations[location_name]["Types"]
if zone_name in randomizer.dungeon_and_cave_island_locations and (
is_dungeon or is_puzzle_cave or is_combat_cave or is_savage):
# If the location is in a dungeon or cave, use the hint for whatever island the dungeon/cave is located on.