-
Notifications
You must be signed in to change notification settings - Fork 85
/
tweaks.py
2703 lines (2249 loc) · 131 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
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from randomizer import WWRandomizer
from gclib.bti import BTI
from gclib.j3d import BDL
import re
import os
from io import BytesIO
from dataclasses import dataclass
import copy
import math
import colorsys
from gclib import fs_helpers as fs
from asm import patcher
from gclib import texture_utils
from gclib.rel import REL
from gclib.bmg import TextBoxType
import gclib.gx_enums as GX
from wwrando_paths import ASSETS_PATH, ASM_PATH
import customizer
from logic.item_types import PROGRESS_ITEMS, NONPROGRESS_ITEMS, CONSUMABLE_ITEMS, DUPLICATABLE_CONSUMABLE_ITEMS
from data_tables import DataTables
from wwlib.events import EventList
from wwlib.dzx import DZx, DZxLayer, ACTR, EVNT, FILI, PLYR, SCLS, SCOB, SHIP, TGDR, TRES, Pale
from options.wwrando_options import SwordMode
try:
from keys.seed_key import SEED_KEY # type: ignore
except ImportError:
SEED_KEY = ""
ORIGINAL_FREE_SPACE_RAM_ADDRESS = 0x803FCFA8
ORIGINAL_DOL_SIZE = 0x3A52C0
# Number of slots allocated for starting items (when changing this also update the code in custom_funcs.asm)
MAXIMUM_ADDITIONAL_STARTING_ITEMS = 86
def set_new_game_starting_spawn_id(self: WWRandomizer, spawn_id: int):
self.dol.write_data(fs.write_u8, 0x80058BAF, spawn_id)
def set_new_game_starting_room(self: WWRandomizer, room_number: int):
self.dol.write_data(fs.write_u8, 0x80058BA7, room_number)
def change_ship_starting_island(self: WWRandomizer, room_number: int):
island_dzx = self.get_arc(f"files/res/Stage/sea/Room{room_number}.arc").get_file("room.dzr", DZx)
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 = self.get_arc("files/res/Stage/sea/Stage.arc").get_file("stage.dzs", DZx)
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(self: WWRandomizer):
# 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(self, 0)
def start_ship_at_outset(self: WWRandomizer):
# Change the King of Red Lions' default position so that he appears on Outset at the start of the game.
change_ship_starting_island(self, 44)
def make_all_text_instant(self: WWRandomizer):
for msg in self.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(self, "b_button_skips_text")
def fix_deku_leaf_model(self: WWRandomizer):
# 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 = self.get_arc("files/res/Stage/Omori/Room0.arc").get_file("room.dzr", DZx)
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 = self.item_name_to_id["Deku Leaf"]
actor.item_pickup_flag = 2 # This is the same item pickup flag that itemDek originally had in its params.
actor.enable_activation_switch = 0xFF # Necessary for the item to be pickupable.
actor.save_changes()
def allow_all_items_to_be_field_items(self: WWRandomizer):
# 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 self.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 in [0xB1, 0xB2]:
# The Magic Meter and Magic Meter Upgrade have no models, 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 = self.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 = self.main_custom_symbols["hurricane_spin_item_resource_arc_name"]
item_resources_addr_to_fix = item_resources_list_start + item_id*0x24
self.dol.write_data(fs.write_u32, field_item_resources_addr, arc_name_pointer)
if item_resources_addr_to_fix:
self.dol.write_data(fs.write_u32, item_resources_addr_to_fix, arc_name_pointer)
data1 = self.dol.read_data(fs.read_bytes, item_resources_addr_to_copy_from+8, 0xD)
data2 = self.dol.read_data(fs.read_bytes, item_resources_addr_to_copy_from+0x1C, 4)
self.dol.write_data(fs.write_bytes, field_item_resources_addr+4, data1)
self.dol.write_data(fs.write_bytes, field_item_resources_addr+0x14, data2)
if item_resources_addr_to_fix:
self.dol.write_data(fs.write_bytes, item_resources_addr_to_fix+8, data1)
self.dol.write_data(fs.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]:
self.dol.write_data(fs.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 = self.dol.read_data(fs.read_u32, location_of_items_switch_statement_case)
if original_switch_case == 0x800F6C8C:
self.dol.write_data(fs.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.
self.dol.write_data(fs.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).
self.dol.write_data(fs.write_u32, 0x800F4CD0, 0xC022A184) # lfs f1, -0x5E7C(rtoc)
# And fix the 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.)
self.dol.write_data(fs.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.
item_info_list_start = 0x803882B0
for item_id in range(0, 0xFF+1):
item_info_entry_addr = item_info_list_start+4*item_id
original_y_offset = self.dol.read_data(fs.read_u8, item_info_entry_addr+1)
if original_y_offset == 0:
self.dol.write_data(fs.write_u8, item_info_entry_addr+1, 0x28) # Y offset of 0x28
original_radius = self.dol.read_data(fs.read_u8, item_info_entry_addr+2)
if original_radius == 0:
self.dol.write_data(fs.write_u8, item_info_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
self.dol.write_data(fs.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.
self.dol.write_data(fs.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())
self.add_new_raw_file("files/res/Object/Vscroll.arc", data)
def remove_shop_item_forced_uniqueness_bit(self: WWRandomizer):
# 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 = self.dol.read_data(fs.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
self.dol.write_data(fs.write_u8, shop_item_data_addr+0xC, buy_requirements_bitfield)
def remove_forsaken_fortress_2_cutscenes(self: WWRandomizer):
# Removes the rescuing Aryll cutscene played by the spawn when you enter the Forsaken Fortress tower.
dzx = self.get_arc("files/res/Stage/M2tower/Room0.arc").get_file("room.dzr", DZx)
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(self: WWRandomizer):
# This makes items progressive, so even if you get them out of order, they will always be upgraded, never downgraded.
patcher.apply_patch(self, "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
self.dol.write_data(fs.write_u32, sword_item_get_func_addr, self.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
self.dol.write_data(fs.write_u32, shield_item_get_func_addr, self.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
self.dol.write_data(fs.write_u32, bow_item_get_func_addr, self.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
self.dol.write_data(fs.write_u32, wallet_item_get_func_addr, self.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
self.dol.write_data(fs.write_u32, bomb_bag_item_get_func_addr, self.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
self.dol.write_data(fs.write_u32, quiver_item_get_func_addr, self.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
self.dol.write_data(fs.write_u32, picto_box_item_get_func_addr, self.main_custom_symbols["progressive_picto_box_item_func"])
for magic_meter_item_id in [0xB1, 0xB2]:
magic_meter_item_get_func_addr = item_get_funcs_list + magic_meter_item_id*4
self.dol.write_data(fs.write_u32, magic_meter_item_get_func_addr, self.main_custom_symbols["progressive_magic_meter_item_func"])
# Register which item ID is for which progressive item.
self.register_renamed_item(0x38, "Progressive Sword")
self.register_renamed_item(0x3B, "Progressive Shield")
self.register_renamed_item(0x27, "Progressive Bow")
self.register_renamed_item(0xAB, "Progressive Wallet")
self.register_renamed_item(0xAD, "Progressive Bomb Bag")
self.register_renamed_item(0xAF, "Progressive Quiver")
self.register_renamed_item(0x23, "Progressive Picto Box")
self.register_renamed_item(0xB1, "Progressive Magic Meter")
# 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.
self.dol.write_data(fs.write_u32, 0x800C36C0, 0x60000000) # Don't set current bombs
self.dol.write_data(fs.write_u32, 0x800C36C4, 0x60000000) # Don't set max bombs
self.dol.write_data(fs.write_u32, 0x800C346C, 0x60000000) # Don't set current arrows
self.dol.write_data(fs.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 make the magic meter a seperate item that the player starts with by default.
# This way other items can use the magic meter before the player gets deku leaf.
self.dol.write_data(fs.write_u32, 0x800C375C, 0x60000000) # Don't set max magic meter
self.dol.write_data(fs.write_u32, 0x800C3768, 0x60000000) # Don't set current magic meter
# Add an item get message for the normal magic meter since it didn't have one in vanilla.
magic_meter_item_id = 0xB1
description = "\\{1A 05 00 00 01}You got \\{1A 06 FF 00 00 01}magic power\\{1A 06 FF 00 00 00}!\nNow you can use magic items!"
msg = self.bmg.add_new_message(101 + magic_meter_item_id)
msg.string = description
msg.text_box_type = TextBoxType.ITEM_GET
msg.initial_draw_type = 2 # Slow initial message speed
msg.display_item_id = magic_meter_item_id
def make_sail_behave_like_swift_sail(self: WWRandomizer):
# 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(self, "swift_sail")
# Update the pause menu name for the sail.
msg = self.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 self.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 = self.get_arc("files/res/Object/Ship.arc")
sail_image = ship_arc.get_file("new_ho1.bti", BTI)
sail_image.replace_image_from_path(new_sail_tex_image_path)
sail_image.save_changes()
# Modify the sail's item icon.
itemicon_arc = self.get_arc("files/res/Msg/itemicon.arc")
sail_icon_image = itemicon_arc.get_file("sail_00.bti", 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 = self.get_arc("files/res/Object/Vho.arc")
sail_itemget_model = sail_itemget_arc.get_file("vho.bdl", 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()
def add_ganons_tower_warp_to_ff2(self: WWRandomizer):
# 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 = self.get_arc("files/res/Stage/sea/Room1.arc").get_file("room.dzr", DZx)
layer_2_actors = dzx.entries_by_type_and_layer(ACTR, layer=DZxLayer.Layer2)
layer_2_warp = next(x for x in layer_2_actors if x.name == "Warpmj")
layer_1_warp = dzx.add_entity(ACTR, layer=DZxLayer.Layer1)
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(self: WWRandomizer):
# Add a chest in place of Medli locked in the jail cell at the peak of Dragon Roost Cavern.
dzs = self.get_arc("files/res/Stage/M_Dra09/Stage.arc").get_file("stage.dzs", DZx)
chest_in_jail = dzs.add_entity(TRES)
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 = self.item_name_to_id["Grappling Hook"]
dzs.save_changes()
dzs = self.get_arc("files/res/Stage/M_NewD2/Stage.arc").get_file("stage.dzs", DZx)
dummy_chest = dzs.add_entity(TRES)
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(self: WWRandomizer):
# Add a chest in place of the Queen Fairy cutscene inside Mother Isle.
dzx = self.get_arc("files/res/Stage/sea/Room9.arc").get_file("room.dzr", DZx)
mother_island_chest = dzx.add_entity(TRES)
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 = self.item_name_to_id["Progressive Bow"]
dzx.save_changes()
def add_cube_to_earth_temple_first_room(self: WWRandomizer):
# 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 = self.get_arc("files/res/Stage/M_Dai/Room0.arc").get_file("room.dzr", DZx)
cube = dzx.add_entity(ACTR)
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(self: WWRandomizer):
# 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 = self.get_arc("files/res/Stage/M_NewD2/Room2.arc").get_file("room.dzr", DZx)
actors = drc_center_room.entries_by_type(ACTR)
skulls = [actor for actor in actors if actor.name == "Odokuro"]
skulls[2].dropped_item_id = self.item_name_to_id["Small Magic Jar (Pickup)"]
skulls[2].save_changes()
skulls[5].dropped_item_id = self.item_name_to_id["Large Magic Jar (Pickup)"]
skulls[5].save_changes()
drc_before_boss_room = self.get_arc("files/res/Stage/M_NewD2/Room10.arc").get_file("room.dzr", DZx)
actors = drc_before_boss_room.entries_by_type(ACTR)
skulls = [actor for actor in actors if actor.name == "Odokuro"]
skulls[0].dropped_item_id = self.item_name_to_id["Large Magic Jar (Pickup)"]
skulls[0].save_changes()
skulls[9].dropped_item_id = self.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 = self.get_arc("files/res/Stage/sea/Room13.arc").get_file("room.dzr", DZx)
grass1 = dri.add_entity(ACTR)
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)
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 = self.get_arc("files/res/Stage/Siren/Room14.arc").get_file("room.dzr", DZx)
actors = totg_before_miniboss_room.entries_by_type(ACTR)
pots = [actor for actor in actors if actor.name == "kotubo"]
pots[1].dropped_item_id = self.item_name_to_id["Large Magic Jar (Pickup)"]
pots[1].save_changes()
def remove_title_and_ending_videos(self: WWRandomizer):
# 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())
self.replace_raw_file("files/thpdemo/title_loop.thp", new_data)
self.replace_raw_file("files/thpdemo/end_st_epilogue.thp", new_data)
def modify_title_screen_logo(self: WWRandomizer):
new_title_image_path = os.path.join(ASSETS_PATH, "title.png")
new_subtitle_image_path = os.path.join(ASSETS_PATH, "subtitle.png")
tlogoe_arc = self.get_arc("files/res/Object/TlogoE.arc")
title_image = tlogoe_arc.get_file("logo_zelda_main.bti", 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", 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()
subtitle_glare_model = tlogoe_arc.get_file("subtitle_kirari_e.bdl", 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()
# Move where the subtitle is drawn downwards a bit so the word "the" doesn't get covered up by the main logo.
title_rel = self.get_rel("files/rels/d_a_title.rel")
y_pos = title_rel.read_data(fs.read_float, 0x1F44)
y_pos -= 13.0
title_rel.write_data(fs.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
fs.write_u16(data, 0x162, 0x106) # Increase Y pos by 16 pixels (0xF6 -> 0x106)
def update_game_name_icon_and_banners(self: WWRandomizer):
new_game_name = "Wind Waker Randomized %s" % self.seed
banner_data = self.get_raw_file("files/opening.bnr")
fs.write_magic_str(banner_data, 0x1860, new_game_name, 0x40)
new_game_id = "GZLE99"
boot_data = self.get_raw_file("sys/boot.bin")
fs.write_magic_str(boot_data, 0, new_game_id, 6)
new_memory_card_game_name = "Wind Waker Randomizer"
self.dol.write_data(fs.write_magic_str, 0x80339690, new_memory_card_game_name, 21)
new_image_file_path = os.path.join(ASSETS_PATH, "banner.png")
image_format = GX.ImageFormat.RGB5A3
palette_format = GX.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 fs.data_len(image_data) == 0x1800
image_data.seek(0)
fs.write_bytes(banner_data, 0x20, image_data.read())
cardicon_arc = self.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", 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", 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(self: WWRandomizer):
item_get_funcs_list = 0x803888C8
item_resources_list_start = 0x803842B0
field_item_resources_list_start = 0x803866B0
item_info_list_start = 0x803882B0
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 = self.item_name_to_id[base_item_name]
dungeon_name = self.logic.DUNGEON_NAMES[short_dungeon_name]
# Register the proper item ID for this item with the randomizer.
self.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
self.dol.write_data(fs.write_u32, item_get_func_addr, self.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 = 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 = 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 = 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 = description_format_string % dungeon_name
msg = self.bmg.add_new_message(101 + item_id)
msg.text_box_type = TextBoxType.ITEM_GET
msg.initial_draw_type = 2 # Slow initial message speed
msg.display_item_id = item_id
msg.string = description
msg.word_wrap_string(self.bfn)
# 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 = self.arc_name_pointers[base_item_id]
self.dol.write_data(fs.write_u32, field_item_resources_addr, arc_name_pointer)
self.dol.write_data(fs.write_u32, item_resources_addr, arc_name_pointer)
item_icon_filename_pointer = self.icon_name_pointer[base_item_id]
self.dol.write_data(fs.write_u32, item_resources_addr+4, item_icon_filename_pointer)
data1 = self.dol.read_data(fs.read_bytes, item_resources_addr_to_copy_from+8, 0xD)
self.dol.write_data(fs.write_bytes, item_resources_addr+8, data1)
self.dol.write_data(fs.write_bytes, field_item_resources_addr+4, data1)
data2 = self.dol.read_data(fs.read_bytes, item_resources_addr_to_copy_from+0x1C, 4)
self.dol.write_data(fs.write_bytes, item_resources_addr+0x1C, data2)
self.dol.write_data(fs.write_bytes, field_item_resources_addr+0x14, data2)
data3 = self.dol.read_data(fs.read_bytes, item_resources_addr_to_copy_from+0x15, 7)
self.dol.write_data(fs.write_bytes, item_resources_addr+0x15, data3)
data4 = self.dol.read_data(fs.read_bytes, item_resources_addr_to_copy_from+0x20, 4)
self.dol.write_data(fs.write_bytes, item_resources_addr+0x20, data4)
data5 = self.dol.read_data(fs.read_bytes, field_item_resources_addr_to_copy_from+0x11, 3)
self.dol.write_data(fs.write_bytes, field_item_resources_addr+0x11, data5)
data6 = self.dol.read_data(fs.read_bytes, field_item_resources_addr_to_copy_from+0x18, 4)
self.dol.write_data(fs.write_bytes, field_item_resources_addr+0x18, data6)
# Also set the item info for all custom dungeon items to match the vanilla dungeon items.
# This includes the bit that causes the item to not fade out over time.
if base_item_name == "Small Key":
item_info_value = 0x14281E05
elif base_item_name == "Big Key":
item_info_value = 0x00282805
else:
item_info_value = 0x00282800
item_info_entry_addr = item_info_list_start+4*item_id
self.dol.write_data(fs.write_u32, item_info_entry_addr, item_info_value)
def get_indefinite_article(string: str):
first_letter = string.strip()[0].lower()
if first_letter in ["a", "e", "i", "o", "u"]:
return "an"
else:
return "a"
def add_article_before_item_name(item_name: str):
"""Adds a grammatical article ("a", "an", "the", or nothing) in front an item's name."""
article = None
if re.search(r"\d$", item_name):
article = None
elif (PROGRESS_ITEMS + NONPROGRESS_ITEMS).count(item_name) > 1:
article = get_indefinite_article(item_name)
elif item_name in CONSUMABLE_ITEMS:
article = get_indefinite_article(item_name)
elif item_name in DUPLICATABLE_CONSUMABLE_ITEMS:
article = get_indefinite_article(item_name)
elif item_name.lower().endswith(" small key"):
article = get_indefinite_article(item_name)
elif item_name.endswith(" Trap Chest"):
article = get_indefinite_article(item_name)
elif item_name in ["Delivery Bag", "Boat's Sail", "Note to Mom"]:
article = get_indefinite_article(item_name)
elif item_name in ["Beedle's Chart", "Bombs", "Tingle's Chart", "Maggie's Letter", "Father's Letter"]:
article = None
elif item_name in ["Nayru's Pearl", "Din's Pearl", "Farore's Pearl"]:
article = None
else:
article = "the"
if article:
item_name = article + " " + item_name
return item_name
def upper_first_letter(string):
first_letter = string[0].upper()
return first_letter + string[1:]
def remove_ballad_of_gales_warp_in_cutscene(self: WWRandomizer):
for island_index in range(1, 49+1):
dzx = self.get_arc("files/res/Stage/sea/Room%d.arc" % island_index).get_file("room.dzr", DZx)
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(self: WWRandomizer):
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 = self.dol.read_data(fs.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 exceptions are for items 10 11 and 12 - arrow refill pickups. Those have no Y offset but look fine already.
new_y_offset = 20.0
self.dol.write_data(fs.write_float, display_data_addr+0x10, new_y_offset)
def update_shop_item_descriptions(self: WWRandomizer):
item_name = self.logic.done_item_locations["The Great Sea - Beedle's Shop Ship - 20 Rupee Item"]
cost = 20
msg = self.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 = self.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 = self.logic.done_item_locations["Rock Spire Isle - Beedle's Special Shop Ship - 500 Rupee Item"]
cost = 500
msg = self.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 = self.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 = self.logic.done_item_locations["Rock Spire Isle - Beedle's Special Shop Ship - 950 Rupee Item"]
cost = 950
msg = self.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 = self.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 = self.logic.done_item_locations["Rock Spire Isle - Beedle's Special Shop Ship - 900 Rupee Item"]
cost = 900
msg = self.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 = self.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(self: WWRandomizer):
item_name = self.logic.done_item_locations["Windfall Island - 5 Rupee Auction"]
msg = self.bmg.messages_by_id[7441]
msg.string = "\\{1A 06 FF 00 00 01}%s" % item_name
item_name = self.logic.done_item_locations["Windfall Island - 40 Rupee Auction"]
msg = self.bmg.messages_by_id[7440]
msg.string = "\\{1A 06 FF 00 00 01}%s" % item_name
item_name = self.logic.done_item_locations["Windfall Island - 60 Rupee Auction"]
msg = self.bmg.messages_by_id[7442]
msg.string = "\\{1A 06 FF 00 00 01}%s" % item_name
item_name = self.logic.done_item_locations["Windfall Island - 80 Rupee Auction"]
msg = self.bmg.messages_by_id[7443]
msg.string = "\\{1A 06 FF 00 00 01}%s" % item_name
def update_battlesquid_item_names(self: WWRandomizer):
item_name = self.logic.done_item_locations["Windfall Island - Battlesquid - First Prize"]
msg = self.bmg.messages_by_id[7520]
msg.string = (
"\\{1A 05 01 00 8E}Hoorayyy! Yayyy! Yayyy!\nOh, thank you, Mr. Sailor!\n\n\n"
"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
)
msg.word_wrap_string(self.bfn)
item_name = self.logic.done_item_locations["Windfall Island - Battlesquid - Second Prize"]
msg = self.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"
"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
)
msg.word_wrap_string(self.bfn)
# 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(self: WWRandomizer):
item_name_1 = self.logic.done_item_locations["Rock Spire Isle - Beedle's Special Shop Ship - 500 Rupee Item"]
item_name_2 = self.logic.done_item_locations["Rock Spire Isle - Beedle's Special Shop Ship - 950 Rupee Item"]
item_name_3 = self.logic.done_item_locations["Rock Spire Isle - Beedle's Special Shop Ship - 900 Rupee Item"]
msg = self.bmg.messages_by_id[3325]
lines = 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}, " % (get_indefinite_article(item_name_1), item_name_1) +
"%s \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}, " % (get_indefinite_article(item_name_2), item_name_2) +
"or %s \\{1A 06 FF 00 00 01}%s\\{1A 06 FF 00 00 00}? " % (get_indefinite_article(item_name_3), item_name_3) +
"We have them at special bargain prices."
)
# Letters are supposed to have 2 spaces at the start of each line, so word wrap to a reduced width
# to account for that, and then add the 2 spaces to each line.
space_width = self.bfn.get_char_width(" ")
hint_string = msg.word_wrap_string_part(self.bfn, hint_string, extra_line_length=-2*space_width)
hint_string = msg.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 shorten_zephos_event(self: WWRandomizer):
# Make the Zephos event end when the player gets the item from the shrine, before Zephos actually appears.
event_list = self.get_arc("files/res/Stage/sea/Stage.arc").get_file("event_list.dat", EventList)
wind_shrine_event = event_list.events_by_name["TACT_HT"]
zephos = next(actor for actor in wind_shrine_event.actors if actor.name == "Hr")
link = next(actor for actor in wind_shrine_event.actors if actor.name == "Link")
camera = next(actor for actor in wind_shrine_event.actors if actor.name == "CAMERA")
zephos.actions = zephos.actions[0:7]
link.actions = link.actions[0:7]
camera.actions = camera.actions[0:5]
wind_shrine_event.ending_flags = [
zephos.actions[-1].flag_id_to_set,
link.actions[-1].flag_id_to_set,
camera.actions[-1].flag_id_to_set,
]
def update_korl_dialogue(self: WWRandomizer):
msg = self.bmg.messages_by_id[3443]
msg.string = "\\{1A 05 00 00 00}, the sea is all yours.\n"
msg.string += "Make sure you explore every corner\n"
msg.string += "in search of items to help you. Remember\n"
msg.string += "that your quest is to defeat Ganondorf."
def set_num_starting_triforce_shards(self: WWRandomizer):
num_shards_address = self.main_custom_symbols["num_triforce_shards_to_start_with"]
self.dol.write_data(fs.write_u8, num_shards_address, self.options.num_starting_triforce_shards)
def set_starting_health(self: WWRandomizer):
heart_pieces = self.options.starting_pohs
heart_containers = self.options.starting_hcs * 4
starting_health = heart_containers + heart_pieces
starting_quarter_hearts_address = self.main_custom_symbols["starting_quarter_hearts"]
self.dol.write_data(fs.write_u16, starting_quarter_hearts_address, starting_health)
if starting_health < 8:
patcher.apply_patch(self, "remove_low_health_beep_anim")
def set_starting_magic(self: WWRandomizer, starting_magic):
starting_magic_address = self.main_custom_symbols["starting_magic"]
self.dol.write_data(fs.write_u8, starting_magic_address, starting_magic)
def add_pirate_ship_to_windfall(self: WWRandomizer):
windfall_dzr = self.get_arc("files/res/Stage/sea/Room11.arc").get_file("room.dzr", DZx)
ship_dzr = self.get_arc("files/res/Stage/Asoko/Room0.arc").get_file("room.dzr", DZx)
ship_dzs = self.get_arc("files/res/Stage/Asoko/Stage.arc").get_file("stage.dzs", DZx)
event_list = self.get_arc("files/res/Stage/Asoko/Stage.arc").get_file("event_list.dat", EventList)
windfall_layer_2_actors = windfall_dzr.entries_by_type_and_layer(ACTR, layer=DZxLayer.Layer2)
layer_2_pirate_ship = next(x for x in windfall_layer_2_actors if x.name == "Pirates")
default_layer_pirate_ship = windfall_dzr.add_entity(ACTR)
default_layer_pirate_ship.name = layer_2_pirate_ship.name
default_layer_pirate_ship.params = layer_2_pirate_ship.params
default_layer_pirate_ship.x_pos = layer_2_pirate_ship.x_pos
default_layer_pirate_ship.y_pos = layer_2_pirate_ship.y_pos
default_layer_pirate_ship.z_pos = layer_2_pirate_ship.z_pos
default_layer_pirate_ship.x_rot = layer_2_pirate_ship.x_rot
default_layer_pirate_ship.y_rot = layer_2_pirate_ship.y_rot
default_layer_pirate_ship.z_rot = layer_2_pirate_ship.z_rot
default_layer_pirate_ship.enemy_number = layer_2_pirate_ship.enemy_number
# Change the door to not require a password.
default_layer_pirate_ship.pirate_ship_door_type = 0
windfall_dzr.save_changes()
# Remove Niko from the ship to get rid of his events.
for layer_num in [2, 3]:
actors_on_this_layer = ship_dzr.entries_by_type_and_layer(ACTR, layer=layer_num)
niko = next(x for x in actors_on_this_layer if x.name == "P2b")
ship_dzr.remove_entity(niko, ACTR, layer=layer_num)
# Add Aryll to the ship instead.
aryll = ship_dzr.add_entity(ACTR)
aryll.name = "Ls1"
aryll.which_aryll = 0 # Looking out of her lookout (though we change her animation to just stand there via asm).
aryll.x_pos = 600
aryll.y_pos = -550
aryll.z_pos = -200
aryll.y_rot = 0xC000
# Change Aryll's text when you talk to her.
msg = self.bmg.messages_by_id[3008]
#msg.initial_sound = 1 # "Ah!"
#msg.initial_sound = 2 # "Wah!?"
#msg.initial_sound = 7 # "Auhh!?"
#msg.initial_sound = 95 # "Hai!"
#msg.initial_sound = 104 # "Oyyyy!"
#msg.initial_sound = 105 # "Hoyyyy!"
msg.initial_sound = 106 # "Haiiii~!"
msg.construct_string_from_parts(self.bfn, [
"'Hoy! Big Brother!\n" + "Wanna play a game? It's fun, trust me!",
"Just \\{1A 06 FF 00 00 01}step on this button\\{1A 06 FF 00 00 00}, "
"and try to swing across the ropes to reach that door over there before time's up!"
])
# We need to make the pirate ship stage (Asoko) load the wave bank with Aryll's voice in it.
stage_bgm_info_list_start = 0x8039C30C
second_dynamic_scene_waves_list_start = 0x8039C2E4
asoko_spot_id = 0xC
new_second_scene_wave_index = 0x0E # Second dynamic scene wave indexes 0E-13 are unused free slots, so we use one of them.
isle_link_0_aw_index = 0x19 # The index of IsleLink_0.aw, the wave bank containing Aryll's voice.
asoko_bgm_info_ptr = stage_bgm_info_list_start + asoko_spot_id*4
new_second_scene_wave_ptr = second_dynamic_scene_waves_list_start + new_second_scene_wave_index*2
self.dol.write_data(fs.write_u8, asoko_bgm_info_ptr+3, new_second_scene_wave_index)
self.dol.write_data(fs.write_u8, new_second_scene_wave_ptr+0, isle_link_0_aw_index)
# Add a custom event where Aryll notices if the player got trapped in the chest room after the timer ran out and opens the door for them.
event = event_list.add_event("AryllOpensDoor")
camera = event.add_actor("CAMERA")
camera.staff_type = 2
aryll_actor = event.add_actor("Ls1")
aryll_actor.staff_type = 0
link = event.add_actor("Link")
link.staff_type = 0
act = camera.add_action("FIXEDFRM", properties=[
("Eye", (aryll.x_pos, aryll.y_pos+90, aryll.z_pos-120)),
("Center", (aryll.x_pos, aryll.y_pos+70, aryll.z_pos)),
("Fovy", 60.0),
("Timer", 30),
])
# Make Aryll look at the player.
act = aryll_actor.add_action("LOK_PLYER", properties=[
("prm_0", 8),
])
# Some of Aryll's animations that can be used here (incomplete list):
# 2: Arms behind back, lightly moving body
# 4: Arms behind back, swaying head back and forth
# 5: Idle