forked from AmazingAmpharos/OoT-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 233
/
Cosmetics.py
1360 lines (1163 loc) · 57.9 KB
/
Cosmetics.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
import json
import logging
import os
import random
from collections.abc import Iterable, Callable
from itertools import chain
from typing import TYPE_CHECKING, Optional, Any
import Colors
import IconManip
import Music
import Sounds
from JSONDump import dump_obj, CollapseList, CollapseDict, AlignedDict
from Plandomizer import InvalidFileException
from Utils import data_path
from version import __version__
if TYPE_CHECKING:
from Rom import Rom
from Settings import Settings
def patch_targeting(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# Set default targeting option to Hold
if settings.default_targeting == 'hold':
rom.write_byte(0xB71E6D, 0x01)
else:
rom.write_byte(0xB71E6D, 0x00)
def patch_dpad(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# Display D-Pad HUD
if settings.display_dpad != 'off':
rom.write_byte(symbols['CFG_DISPLAY_DPAD'], 0x01)
else:
rom.write_byte(symbols['CFG_DISPLAY_DPAD'], 0x00)
def patch_dpad_info(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# Display D-Pad HUD in pause menu for either dungeon info or equips
if settings.dpad_dungeon_menu:
rom.write_byte(symbols['CFG_DPAD_DUNGEON_INFO_ENABLE'], 0x01)
else:
rom.write_byte(symbols['CFG_DPAD_DUNGEON_INFO_ENABLE'], 0x00)
def patch_music(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch music
if settings.background_music != 'normal' or settings.fanfares != 'normal' or log.src_dict.get('bgm', {}):
Music.restore_music(rom)
Music.randomize_music(rom, settings, log, symbols)
else:
Music.restore_music(rom)
# Remove battle music
if settings.disable_battle_music:
rom.write_byte(0xBE447F, 0x00)
def patch_model_colors(rom: Rom, color: Optional[list[int]], model_addresses: tuple[list[int], list[int], list[int]]) -> None:
main_addresses, dark_addresses, light_addresses = model_addresses
if color is None:
for address in main_addresses + dark_addresses + light_addresses:
original = rom.original.read_bytes(address, 3)
rom.write_bytes(address, original)
return
for address in main_addresses:
rom.write_bytes(address, color)
darkened_color = list(map(lambda main_color: int(max((main_color - 0x32) * 0.6, 0)), color))
for address in dark_addresses:
rom.write_bytes(address, darkened_color)
lightened_color = list(map(lambda main_color: int(min((main_color / 0.6) + 0x32, 255)), color))
for address in light_addresses:
rom.write_bytes(address, lightened_color)
def patch_tunic_icon(rom: Rom, tunic: str, color: Optional[list[int]], rainbow: bool = False) -> None:
# patch tunic icon colors
icon_locations = {
'Kokiri Tunic': 0x007FE000,
'Goron Tunic': 0x007FF000,
'Zora Tunic': 0x00800000,
}
if color is not None:
tunic_icon = IconManip.generate_rainbow_tunic_icon() if rainbow else IconManip.generate_tunic_icon(color)
else:
tunic_icon = rom.original.read_bytes(icon_locations[tunic], 0x1000)
rom.write_bytes(icon_locations[tunic], tunic_icon)
def patch_tunic_colors(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# Need to check for the existence of the CFG_TUNIC_COLORS symbol.
# This was added with rainbow tunic but custom tunic colors should still support older patch versions.
tunic_address = symbols.get('CFG_TUNIC_COLORS', 0x00B6DA38) # Use new tunic color ROM address. Fall back to vanilla tunic color ROM address.
tunics = [
('Kokiri Tunic', 'kokiri_color', tunic_address),
('Goron Tunic', 'goron_color', tunic_address+3),
('Zora Tunic', 'zora_color', tunic_address+6),
]
tunic_color_list = Colors.get_tunic_colors()
rainbow_error = None
for tunic, tunic_setting, address in tunics:
tunic_option = getattr(settings, tunic_setting)
# Handle Plando
if log.src_dict.get('equipment_colors', {}).get(tunic, {}).get('color', '') and log.src_dict['equipment_colors'][tunic][':option'] != 'Rainbow':
tunic_option = log.src_dict['equipment_colors'][tunic]['color']
# Handle random
if tunic_option == 'Random Choice':
tunic_option = random.choice(tunic_color_list)
# Handle Rainbow Tunic
if tunic_option == 'Rainbow':
# Check to make sure that rainbow tunic is supported by the current patch version
if 'CFG_RAINBOW_TUNIC_ENABLED' in symbols:
bit_shifts = {'Kokiri Tunic': 0, 'Goron Tunic': 1, 'Zora Tunic': 2}
# get symbol
rainbow_tunic_symbol = symbols['CFG_RAINBOW_TUNIC_ENABLED']
# read the current value
setting = rom.read_byte(rainbow_tunic_symbol)
# Write bits for each tunic
setting |= 1 << bit_shifts[tunic]
rom.write_byte(rainbow_tunic_symbol, setting)
else:
rainbow_error = "Rainbow Tunics are not supported by this patch version. Using 'Completely Random' as a substitute."
tunic_option = 'Completely Random'
# handle completely random
if tunic_option == 'Completely Random':
color = Colors.generate_random_color()
# grab the color from the list
elif tunic_option in Colors.tunic_colors:
color = list(Colors.tunic_colors[tunic_option])
elif tunic_option == 'Rainbow':
color = list(Colors.Color(0x00, 0x00, 0x00))
# build color from hex code
else:
color = Colors.hex_to_color(tunic_option)
tunic_option = 'Custom'
rom.write_bytes(address, color)
# patch the tunic icon
if [tunic, tunic_option] not in [['Kokiri Tunic', 'Kokiri Green'], ['Goron Tunic', 'Goron Red'], ['Zora Tunic', 'Zora Blue']]:
patch_tunic_icon(rom, tunic, color, tunic_option == 'Rainbow')
else:
patch_tunic_icon(rom, tunic, None)
log.equipment_colors[tunic] = CollapseDict({
':option': tunic_option,
'color': Colors.color_to_hex(color),
})
if rainbow_error:
log.errors.append(rainbow_error)
def patch_navi_colors(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch navi colors
navi = [
# colors for Navi
('Navi Idle', 'navi_color_default',
[0x00B5E184], # Default (Player)
symbols.get('CFG_RAINBOW_NAVI_IDLE_INNER_ENABLED', None), symbols.get('CFG_RAINBOW_NAVI_IDLE_OUTER_ENABLED', None)),
('Navi Targeting Enemy', 'navi_color_enemy',
[0x00B5E19C, 0x00B5E1BC], # Enemy, Boss
symbols.get('CFG_RAINBOW_NAVI_ENEMY_INNER_ENABLED', None), symbols.get('CFG_RAINBOW_NAVI_ENEMY_OUTER_ENABLED', None)),
('Navi Targeting NPC', 'navi_color_npc',
[0x00B5E194], # NPC
symbols.get('CFG_RAINBOW_NAVI_NPC_INNER_ENABLED', None), symbols.get('CFG_RAINBOW_NAVI_NPC_OUTER_ENABLED', None)),
('Navi Targeting Prop', 'navi_color_prop',
[0x00B5E174, 0x00B5E17C, 0x00B5E18C, 0x00B5E1A4, 0x00B5E1AC,
0x00B5E1B4, 0x00B5E1C4, 0x00B5E1CC, 0x00B5E1D4], # Everything else
symbols.get('CFG_RAINBOW_NAVI_PROP_INNER_ENABLED', None), symbols.get('CFG_RAINBOW_NAVI_PROP_OUTER_ENABLED', None)),
]
navi_color_list = Colors.get_navi_colors()
rainbow_error = None
for navi_action, navi_setting, navi_addresses, rainbow_inner_symbol, rainbow_outer_symbol in navi:
navi_option_inner = getattr(settings, f'{navi_setting}_inner')
navi_option_outer = getattr(settings, f'{navi_setting}_outer')
plando_colors = log.src_dict.get('misc_colors', {}).get(navi_action, {}).get('colors', [])
# choose a random choice for the whole group
if navi_option_inner == 'Random Choice':
navi_option_inner = random.choice(navi_color_list)
if navi_option_outer == 'Random Choice':
navi_option_outer = random.choice(navi_color_list)
if navi_option_outer == '[Same as Inner]':
navi_option_outer = navi_option_inner
colors = []
option_dict = {}
for address_index, address in enumerate(navi_addresses):
address_colors = {}
colors.append(address_colors)
for index, (navi_part, option, rainbow_symbol) in enumerate([
('inner', navi_option_inner, rainbow_inner_symbol),
('outer', navi_option_outer, rainbow_outer_symbol),
]):
color = None
# Plando
if len(plando_colors) > address_index and plando_colors[address_index].get(navi_part, ''):
color = Colors.hex_to_color(plando_colors[address_index][navi_part])
# set rainbow option
if rainbow_symbol is not None and option == 'Rainbow':
rom.write_byte(rainbow_symbol, 0x01)
color = [0x00, 0x00, 0x00]
elif rainbow_symbol is not None:
rom.write_byte(rainbow_symbol, 0x00)
elif option == 'Rainbow':
rainbow_error = "Rainbow Navi is not supported by this patch version. Using 'Completely Random' as a substitute."
option = 'Completely Random'
# completely random is random for every subgroup
if color is None and option == 'Completely Random':
color = Colors.generate_random_color()
# grab the color from the list
if color is None and option in Colors.NaviColors:
color = list(Colors.NaviColors[option][index])
# build color from hex code
if color is None:
color = Colors.hex_to_color(option)
option = 'Custom'
# Check color validity
if color is None:
raise Exception(f'Invalid {navi_part} color {option} for {navi_action}')
address_colors[navi_part] = color
option_dict[navi_part] = option
# write color
color = address_colors['inner'] + [0xFF] + address_colors['outer'] + [0xFF]
rom.write_bytes(address, color)
# Get the colors into the log.
log.misc_colors[navi_action] = CollapseDict({
':option_inner': option_dict['inner'],
':option_outer': option_dict['outer'],
'colors': [],
})
if option_dict['inner'] != "Rainbow" or option_dict['outer'] != "Rainbow" or rainbow_error:
for address_colors in colors:
address_colors_str = CollapseDict()
log.misc_colors[navi_action]['colors'].append(address_colors_str)
for part, color in address_colors.items():
if log.misc_colors[navi_action][f':option_{part}'] != "Rainbow" or rainbow_error:
address_colors_str[part] = Colors.color_to_hex(color)
else:
del log.misc_colors[navi_action]['colors']
if rainbow_error:
log.errors.append(rainbow_error)
def patch_sword_trails(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch sword trail duration
rom.write_byte(0x00BEFF8C, settings.sword_trail_duration)
# patch sword trail colors
sword_trails = [
('Sword Trail', 'sword_trail_color',
[(0x00BEFF7C, 0xB0, 0x40, 0xB0, 0xFF), (0x00BEFF84, 0x20, 0x00, 0x10, 0x00)],
symbols.get('CFG_RAINBOW_SWORD_INNER_ENABLED', None), symbols.get('CFG_RAINBOW_SWORD_OUTER_ENABLED', None)),
]
sword_trail_color_list = Colors.get_sword_trail_colors()
rainbow_error = None
for trail_name, trail_setting, trail_addresses, rainbow_inner_symbol, rainbow_outer_symbol in sword_trails:
option_inner = getattr(settings, f'{trail_setting}_inner')
option_outer = getattr(settings, f'{trail_setting}_outer')
plando_colors = log.src_dict.get('misc_colors', {}).get(trail_name, {}).get('colors', [])
# handle random choice
if option_inner == 'Random Choice':
option_inner = random.choice(sword_trail_color_list)
if option_outer == 'Random Choice':
option_outer = random.choice(sword_trail_color_list)
if option_outer == '[Same as Inner]':
option_outer = option_inner
colors = []
option_dict = {}
for address_index, (address, inner_transparency, inner_white_transparency, outer_transparency, outer_white_transparency) in enumerate(trail_addresses):
address_colors = {}
colors.append(address_colors)
transparency_dict = {}
for index, (trail_part, option, rainbow_symbol, white_transparency, transparency) in enumerate([
('inner', option_inner, rainbow_inner_symbol, inner_white_transparency, inner_transparency),
('outer', option_outer, rainbow_outer_symbol, outer_white_transparency, outer_transparency),
]):
color = None
# Plando
if len(plando_colors) > address_index and plando_colors[address_index].get(trail_part, ''):
color = Colors.hex_to_color(plando_colors[address_index][trail_part])
# set rainbow option
if rainbow_symbol is not None and option == 'Rainbow':
rom.write_byte(rainbow_symbol, 0x01)
color = [0x00, 0x00, 0x00]
elif rainbow_symbol is not None:
rom.write_byte(rainbow_symbol, 0x00)
elif option == 'Rainbow':
rainbow_error = "Rainbow Sword Trail is not supported by this patch version. Using 'Completely Random' as a substitute."
option = 'Completely Random'
# completely random is random for every subgroup
if color is None and option == 'Completely Random':
color = Colors.generate_random_color()
# grab the color from the list
if color is None and option in Colors.sword_trail_colors:
color = list(Colors.sword_trail_colors[option])
# build color from hex code
if color is None:
color = Colors.hex_to_color(option)
option = 'Custom'
# Check color validity
if color is None:
raise Exception(f'Invalid {trail_part} color {option} for {trail_name}')
# handle white transparency
if option == 'White':
transparency_dict[trail_part] = white_transparency
else:
transparency_dict[trail_part] = transparency
address_colors[trail_part] = color
option_dict[trail_part] = option
# write color
color = address_colors['outer'] + [transparency_dict['outer']] + address_colors['inner'] + [transparency_dict['inner']]
rom.write_bytes(address, color)
# Get the colors into the log.
log.misc_colors[trail_name] = CollapseDict({
':option_inner': option_dict['inner'],
':option_outer': option_dict['outer'],
'colors': [],
})
if option_dict['inner'] != "Rainbow" or option_dict['outer'] != "Rainbow" or rainbow_error:
for address_colors in colors:
address_colors_str = CollapseDict()
log.misc_colors[trail_name]['colors'].append(address_colors_str)
for part, color in address_colors.items():
if log.misc_colors[trail_name][f':option_{part}'] != "Rainbow" or rainbow_error:
address_colors_str[part] = Colors.color_to_hex(color)
else:
del log.misc_colors[trail_name]['colors']
if rainbow_error:
log.errors.append(rainbow_error)
def patch_bombchu_trails(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch bombchu trail colors
bombchu_trails = [
('Bombchu Trail', 'bombchu_trail_color', Colors.get_bombchu_trail_colors(), Colors.bombchu_trail_colors,
(symbols['CFG_BOMBCHU_TRAIL_INNER_COLOR'], symbols['CFG_BOMBCHU_TRAIL_OUTER_COLOR'],
symbols['CFG_RAINBOW_BOMBCHU_TRAIL_INNER_ENABLED'], symbols['CFG_RAINBOW_BOMBCHU_TRAIL_OUTER_ENABLED'])),
]
patch_trails(rom, settings, log, bombchu_trails)
def patch_boomerang_trails(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch boomerang trail colors
boomerang_trails = [
('Boomerang Trail', 'boomerang_trail_color', Colors.get_boomerang_trail_colors(), Colors.boomerang_trail_colors,
(symbols['CFG_BOOM_TRAIL_INNER_COLOR'], symbols['CFG_BOOM_TRAIL_OUTER_COLOR'],
symbols['CFG_RAINBOW_BOOM_TRAIL_INNER_ENABLED'], symbols['CFG_RAINBOW_BOOM_TRAIL_OUTER_ENABLED'])),
]
patch_trails(rom, settings, log, boomerang_trails)
def patch_trails(rom: Rom, settings: Settings, log: CosmeticsLog, trails) -> None:
for trail_name, trail_setting, trail_color_list, trail_color_dict, trail_symbols in trails:
color_inner_symbol, color_outer_symbol, rainbow_inner_symbol, rainbow_outer_symbol = trail_symbols
option_inner = getattr(settings, f'{trail_setting}_inner')
option_outer = getattr(settings, f'{trail_setting}_outer')
plando_colors = log.src_dict.get('misc_colors', {}).get(trail_name, {}).get('colors', [])
# handle random choice
if option_inner == 'Random Choice':
option_inner = random.choice(trail_color_list)
if option_outer == 'Random Choice':
option_outer = random.choice(trail_color_list)
if option_outer == '[Same as Inner]':
option_outer = option_inner
option_dict = {}
colors = {}
for index, (trail_part, option, rainbow_symbol, color_symbol) in enumerate([
('inner', option_inner, rainbow_inner_symbol, color_inner_symbol),
('outer', option_outer, rainbow_outer_symbol, color_outer_symbol),
]):
color = None
# Plando
if len(plando_colors) > 0 and plando_colors[0].get(trail_part, ''):
color = Colors.hex_to_color(plando_colors[0][trail_part])
# set rainbow option
if option == 'Rainbow':
rom.write_byte(rainbow_symbol, 0x01)
color = [0x00, 0x00, 0x00]
else:
rom.write_byte(rainbow_symbol, 0x00)
# handle completely random
if color is None and option == 'Completely Random':
# Specific handling for inner bombchu trails for contrast purposes.
if trail_name == 'Bombchu Trail' and trail_part == 'inner':
fixed_dark_color = [0, 0, 0]
color = [0, 0, 0]
# Avoid colors which have a low contrast so the bombchu ticking is still visible
while Colors.contrast_ratio(color, fixed_dark_color) <= 4:
color = Colors.generate_random_color()
else:
color = Colors.generate_random_color()
# grab the color from the list
if color is None and option in trail_color_dict:
color = list(trail_color_dict[option])
# build color from hex code
if color is None:
color = Colors.hex_to_color(option)
option = 'Custom'
option_dict[trail_part] = option
colors[trail_part] = color
# write color
rom.write_bytes(color_symbol, color)
# Get the colors into the log.
log.misc_colors[trail_name] = CollapseDict({
':option_inner': option_dict['inner'],
':option_outer': option_dict['outer'],
'colors': [],
})
if option_dict['inner'] != "Rainbow" or option_dict['outer'] != "Rainbow":
colors_str = CollapseDict()
log.misc_colors[trail_name]['colors'].append(colors_str)
for part, color in colors.items():
if log.misc_colors[trail_name][f':option_{part}'] != "Rainbow":
colors_str[part] = Colors.color_to_hex(color)
else:
del log.misc_colors[trail_name]['colors']
def patch_gauntlet_colors(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch gauntlet colors
gauntlets = [
('Silver Gauntlets', 'silver_gauntlets_color', 0x00B6DA44,
([0x173B4CC], [0x173B4D4, 0x173B50C, 0x173B514], [])), # GI Model DList colors
('Gold Gauntlets', 'golden_gauntlets_color', 0x00B6DA47,
([0x173B4EC], [0x173B4F4, 0x173B52C, 0x173B534], [])), # GI Model DList colors
]
gauntlet_color_list = Colors.get_gauntlet_colors()
for gauntlet, gauntlet_setting, address, model_addresses in gauntlets:
gauntlet_option = getattr(settings, gauntlet_setting)
# Handle Plando
if log.src_dict.get('equipment_colors', {}).get(gauntlet, {}).get('color', ''):
gauntlet_option = log.src_dict['equipment_colors'][gauntlet]['color']
# handle random
if gauntlet_option == 'Random Choice':
gauntlet_option = random.choice(gauntlet_color_list)
# handle completely random
if gauntlet_option == 'Completely Random':
color = Colors.generate_random_color()
# grab the color from the list
elif gauntlet_option in Colors.gauntlet_colors:
color = list(Colors.gauntlet_colors[gauntlet_option])
# build color from hex code
else:
color = Colors.hex_to_color(gauntlet_option)
gauntlet_option = 'Custom'
rom.write_bytes(address, color)
if settings.correct_model_colors:
patch_model_colors(rom, color, model_addresses)
else:
patch_model_colors(rom, None, model_addresses)
log.equipment_colors[gauntlet] = CollapseDict({
':option': gauntlet_option,
'color': Colors.color_to_hex(color),
})
def patch_shield_frame_colors(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch shield frame colors
shield_frames = [
('Mirror Shield Frame', 'mirror_shield_frame_color',
[0xFA7274, 0xFA776C, 0xFAA27C, 0xFAC564, 0xFAC984, 0xFAEDD4],
([0x1616FCC], [0x1616FD4], [])),
]
shield_frame_color_list = Colors.get_shield_frame_colors()
for shield_frame, shield_frame_setting, addresses, model_addresses in shield_frames:
shield_frame_option = getattr(settings, shield_frame_setting)
# Handle Plando
if log.src_dict.get('equipment_colors', {}).get(shield_frame, {}).get('color', ''):
shield_frame_option = log.src_dict['equipment_colors'][shield_frame]['color']
# handle random
if shield_frame_option == 'Random Choice':
shield_frame_option = random.choice(shield_frame_color_list)
# handle completely random
if shield_frame_option == 'Completely Random':
color = [random.getrandbits(8), random.getrandbits(8), random.getrandbits(8)]
# grab the color from the list
elif shield_frame_option in Colors.shield_frame_colors:
color = list(Colors.shield_frame_colors[shield_frame_option])
# build color from hex code
else:
color = Colors.hex_to_color(shield_frame_option)
shield_frame_option = 'Custom'
for address in addresses:
rom.write_bytes(address, color)
if settings.correct_model_colors and shield_frame_option != 'Red':
patch_model_colors(rom, color, model_addresses)
else:
patch_model_colors(rom, None, model_addresses)
log.equipment_colors[shield_frame] = CollapseDict({
':option': shield_frame_option,
'color': Colors.color_to_hex(color),
})
def patch_heart_colors(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch heart colors
hearts = [
('Heart Color', 'heart_color', symbols['CFG_HEART_COLOR'], 0xBB0994,
([0x14DA474, 0x14DA594, 0x14B701C, 0x14B70DC, 0x160929C, 0x1609304, 0x160939C],
[0x14B70FC, 0x14DA494, 0x14DA5B4, 0x14B700C, 0x14B702C, 0x14B703C, 0x14B704C, 0x14B705C,
0x14B706C, 0x14B707C, 0x14B708C, 0x14B709C, 0x14B70AC, 0x14B70BC, 0x14B70CC, 0x16092A4],
[0x16092FC, 0x1609394])), # GI Model and Potion DList colors
]
heart_color_list = Colors.get_heart_colors()
for heart, heart_setting, symbol, file_select_address, model_addresses in hearts:
heart_option = getattr(settings, heart_setting)
# Handle Plando
if log.src_dict.get('ui_colors', {}).get(heart, {}).get('color', ''):
heart_option = log.src_dict['ui_colors'][heart]['color']
# handle random
if heart_option == 'Random Choice':
heart_option = random.choice(heart_color_list)
# handle completely random
if heart_option == 'Completely Random':
color = Colors.generate_random_color()
# grab the color from the list
elif heart_option in Colors.heart_colors:
color = list(Colors.heart_colors[heart_option])
# build color from hex code
else:
color = Colors.hex_to_color(heart_option)
heart_option = 'Custom'
rom.write_int16s(symbol, color) # symbol for ingame HUD
rom.write_int16s(file_select_address, color) # file select normal hearts
if heart_option != 'Red':
rom.write_int16s(file_select_address + 6, color) # file select DD hearts
else:
original_dd_color = rom.original.read_bytes(file_select_address + 6, 6)
rom.write_bytes(file_select_address + 6, original_dd_color)
if settings.correct_model_colors and heart_option != 'Red':
patch_model_colors(rom, color, model_addresses) # heart model colors
IconManip.patch_overworld_icon(rom, color, 0xF43D80) # Overworld Heart Icon
else:
patch_model_colors(rom, None, model_addresses)
IconManip.patch_overworld_icon(rom, None, 0xF43D80)
log.ui_colors[heart] = CollapseDict({
':option': heart_option,
'color': Colors.color_to_hex(color),
})
def patch_magic_colors(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# patch magic colors
magic = [
('Magic Meter Color', 'magic_color', symbols["CFG_MAGIC_COLOR"],
([0x154C654, 0x154CFB4, 0x160927C, 0x160927C, 0x16092E4, 0x1609344],
[0x154C65C, 0x154CFBC, 0x1609284],
[0x16092DC, 0x160933C])), # GI Model and Potion DList colors
]
magic_color_list = Colors.get_magic_colors()
for magic_color, magic_setting, symbol, model_addresses in magic:
magic_option = getattr(settings, magic_setting)
# Handle Plando
if log.src_dict.get('ui_colors', {}).get(magic_color, {}).get('color', ''):
magic_option = log.src_dict['ui_colors'][magic_color]['color']
if magic_option == 'Random Choice':
magic_option = random.choice(magic_color_list)
if magic_option == 'Completely Random':
color = Colors.generate_random_color()
elif magic_option in Colors.magic_colors:
color = list(Colors.magic_colors[magic_option])
else:
color = Colors.hex_to_color(magic_option)
magic_option = 'Custom'
rom.write_int16s(symbol, color)
if magic_option != 'Green' and settings.correct_model_colors:
patch_model_colors(rom, color, model_addresses)
IconManip.patch_overworld_icon(rom, color, 0xF45650, data_path('icons/magicSmallExtras.raw')) # Overworld Small Pot
IconManip.patch_overworld_icon(rom, color, 0xF47650, data_path('icons/magicLargeExtras.raw')) # Overworld Big Pot
else:
patch_model_colors(rom, None, model_addresses)
IconManip.patch_overworld_icon(rom, None, 0xF45650)
IconManip.patch_overworld_icon(rom, None, 0xF47650)
log.ui_colors[magic_color] = CollapseDict({
':option': magic_option,
'color': Colors.color_to_hex(color),
})
def patch_button_colors(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
buttons = [
('A Button Color', 'a_button_color', Colors.a_button_colors,
[('A Button Color', symbols['CFG_A_BUTTON_COLOR'],
None),
('Text Cursor Color', symbols['CFG_TEXT_CURSOR_COLOR'],
[(0xB88E81, 0xB88E85, 0xB88E9)]), # Initial Inner Color
('Shop Cursor Color', symbols['CFG_SHOP_CURSOR_COLOR'],
None),
('Save/Death Cursor Color', None,
[(0xBBEBC2, 0xBBEBC3, 0xBBEBD6), (0xBBEDDA, 0xBBEDDB, 0xBBEDDE)]), # Save Cursor / Death Cursor
('Pause Menu A Cursor Color', None,
[(0xBC7849, 0xBC784B, 0xBC784D), (0xBC78A9, 0xBC78AB, 0xBC78AD), (0xBC78BB, 0xBC78BD, 0xBC78BF)]), # Inner / Pulse 1 / Pulse 2
('Pause Menu A Icon Color', None,
[(0x845754, 0x845755, 0x845756)]),
('A Note Color', symbols['CFG_A_NOTE_COLOR'], # For Textbox Song Display
[(0xBB299A, 0xBB299B, 0xBB299E), (0xBB2C8E, 0xBB2C8F, 0xBB2C92), (0xBB2F8A, 0xBB2F8B, 0xBB2F96)]), # Pause Menu Song Display
]),
('B Button Color', 'b_button_color', Colors.b_button_colors,
[('B Button Color', symbols['CFG_B_BUTTON_COLOR'],
None),
]),
('C Button Color', 'c_button_color', Colors.c_button_colors,
[('C Button Color', symbols['CFG_C_BUTTON_COLOR'],
None),
('Pause Menu C Cursor Color', None,
[(0xBC7843, 0xBC7845, 0xBC7847), (0xBC7891, 0xBC7893, 0xBC7895), (0xBC78A3, 0xBC78A5, 0xBC78A7)]), # Inner / Pulse 1 / Pulse 2
('Pause Menu C Icon Color', None,
[(0x8456FC, 0x8456FD, 0x8456FE)]),
('C Note Color', symbols['CFG_C_NOTE_COLOR'], # For Textbox Song Display
[(0xBB2996, 0xBB2997, 0xBB29A2), (0xBB2C8A, 0xBB2C8B, 0xBB2C96), (0xBB2F86, 0xBB2F87, 0xBB2F9A)]), # Pause Menu Song Display
]),
('Start Button Color', 'start_button_color', Colors.start_button_colors,
[('Start Button Color', None,
[(0xAE9EC6, 0xAE9EC7, 0xAE9EDA)]),
]),
]
for button, button_setting, button_colors, patches in buttons:
button_option = getattr(settings, button_setting)
color_set = None
colors = {}
log_dict = CollapseDict({':option': button_option, 'colors': {}})
log.ui_colors[button] = log_dict
# Setup Plando
plando_colors = log.src_dict.get('ui_colors', {}).get(button, {}).get('colors', {})
# handle random
if button_option == 'Random Choice':
button_option = random.choice(list(button_colors.keys()))
# handle completely random
if button_option == 'Completely Random':
fixed_font_color = [10, 10, 10]
color = [0, 0, 0]
# Avoid colors which have a low contrast with the font inside buttons (eg. the A letter)
while Colors.contrast_ratio(color, fixed_font_color) <= 3:
color = Colors.generate_random_color()
# grab the color from the list
elif button_option in button_colors:
color_set = [button_colors[button_option]] if isinstance(button_colors[button_option][0], int) else list(button_colors[button_option])
color = color_set[0]
# build color from hex code
else:
color = Colors.hex_to_color(button_option)
button_option = 'Custom'
log_dict[':option'] = button_option
# apply all button color patches
for i, (patch, symbol, byte_addresses) in enumerate(patches):
if plando_colors.get(patch, ''):
colors[patch] = Colors.hex_to_color(plando_colors[patch])
elif color_set is not None and len(color_set) > i and color_set[i]:
colors[patch] = color_set[i]
else:
colors[patch] = color
if symbol:
rom.write_int16s(symbol, colors[patch])
if byte_addresses:
for r_addr, g_addr, b_addr in byte_addresses:
rom.write_byte(r_addr, colors[patch][0])
rom.write_byte(g_addr, colors[patch][1])
rom.write_byte(b_addr, colors[patch][2])
log_dict['colors'][patch] = Colors.color_to_hex(colors[patch])
def patch_sfx(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# Configurable Sound Effects
sfx_config = [
('sfx_navi_overworld', Sounds.SoundHooks.NAVI_OVERWORLD),
('sfx_navi_enemy', Sounds.SoundHooks.NAVI_ENEMY),
('sfx_low_hp', Sounds.SoundHooks.HP_LOW),
('sfx_menu_cursor', Sounds.SoundHooks.MENU_CURSOR),
('sfx_menu_select', Sounds.SoundHooks.MENU_SELECT),
('sfx_nightfall', Sounds.SoundHooks.NIGHTFALL),
('sfx_horse_neigh', Sounds.SoundHooks.HORSE_NEIGH),
('sfx_hover_boots', Sounds.SoundHooks.BOOTS_HOVER),
('sfx_iron_boots', Sounds.SoundHooks.BOOTS_IRON),
('sfx_silver_rupee', Sounds.SoundHooks.SILVER_RUPEE),
('sfx_boomerang_throw', Sounds.SoundHooks.BOOMERANG_THROW),
('sfx_hookshot_chain', Sounds.SoundHooks.HOOKSHOT_CHAIN),
('sfx_arrow_shot', Sounds.SoundHooks.ARROW_SHOT),
('sfx_slingshot_shot', Sounds.SoundHooks.SLINGSHOT_SHOT),
('sfx_magic_arrow_shot', Sounds.SoundHooks.MAGIC_ARROW_SHOT),
('sfx_bombchu_move', Sounds.SoundHooks.BOMBCHU_MOVE),
('sfx_get_small_item', Sounds.SoundHooks.GET_SMALL_ITEM),
('sfx_explosion', Sounds.SoundHooks.EXPLOSION),
('sfx_daybreak', Sounds.SoundHooks.DAYBREAK),
('sfx_cucco', Sounds.SoundHooks.CUCCO),
]
sound_dict = Sounds.get_patch_dict()
sounds_keyword_label = {sound.value.keyword: sound.value.label for sound in Sounds.Sounds}
sounds_label_keyword = {sound.value.label: sound.value.keyword for sound in Sounds.Sounds}
for setting, hook in sfx_config:
selection = getattr(settings, setting)
# Handle Plando
if log.src_dict.get('sfx', {}).get(hook.value.name, ''):
selection_label = log.src_dict['sfx'][hook.value.name]
if selection_label == 'Default':
selection = 'default'
elif selection_label in sounds_label_keyword:
selection = sounds_label_keyword[selection_label]
sound_id = 0
if selection == 'default':
for loc in hook.value.locations:
sound_id = rom.original.read_int16(loc)
rom.write_int16(loc, sound_id)
else:
if selection == 'random-choice':
selection = random.choice(Sounds.get_hook_pool(hook)).value.keyword
elif selection == 'random-ear-safe':
selection = random.choice(Sounds.get_hook_pool(hook, True)).value.keyword
elif selection == 'completely-random':
selection = random.choice(Sounds.standard).value.keyword
sound_id = sound_dict[selection]
if hook.value.sfx_flag and sound_id > 0x7FF:
sound_id -= 0x800
for loc in hook.value.locations:
rom.write_int16(loc, sound_id)
if selection == 'default':
log.sfx[hook.value.name] = 'Default'
else:
log.sfx[hook.value.name] = sounds_keyword_label[selection]
# Use the get small item sound for pots/crate/freestandings shuffle
if setting == 'sfx_get_small_item' and 'GET_ITEM_SEQ_ID' in symbols:
rom.write_int16(symbols['GET_ITEM_SEQ_ID'], sound_id)
def patch_instrument(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# Player Instrument
instruments = {
#'none': 0x00,
'ocarina': 0x01,
'malon': 0x02,
'whistle': 0x03,
'harp': 0x04,
'grind-organ': 0x05,
'flute': 0x06,
#'another_ocarina': 0x07,
}
ocarina_options = settings.setting_infos['sfx_ocarina'].choices
ocarina_options_inv = {v: k for k, v in ocarina_options.items()}
choice = settings.sfx_ocarina
if log.src_dict.get('sfx', {}).get('Ocarina', '') and log.src_dict['sfx']['Ocarina'] in ocarina_options_inv:
choice = ocarina_options_inv[log.src_dict['sfx']['Ocarina']]
if choice == 'random-choice':
choice = random.choice(list(instruments.keys()))
rom.write_byte(0x00B53C7B, instruments[choice])
rom.write_byte(0x00B4BF6F, instruments[choice]) # For Lost Woods Skull Kids' minigame in Lost Woods
log.sfx['Ocarina'] = ocarina_options[choice]
def read_default_voice_data(rom: Rom) -> dict[str, dict[str, int]]:
audiobank = 0xD390
audiotable = 0x79470
soundbank = audiobank + rom.read_int32(audiobank + 0x4)
n_sfx = 0x88 # bank 00 sfx ids starting from 00
# Read sound bank entries. This table (usually at 0x109F0) has information on each entry in the bank
# Each entry is 8 bytes, the first 4 are the offset in audiobank, second are almost always 0x3F200000
# In the audiobank entry, each sfx has 0x20 bytes of info. The first 4 bytes are the length of the
# raw sample and the following 4 bytes are the offset in the audiotable for the raw sample
soundbank_entries = {}
for i in range(n_sfx):
audiobank_offset = rom.read_int32(soundbank + i*0x8)
sfxid = f"00-00{i:02x}"
soundbank_entries[sfxid] = {
"length": rom.read_int32(audiobank + audiobank_offset),
"romoffset": audiotable + rom.read_int32(audiobank + audiobank_offset + 0x4)
}
return soundbank_entries
def patch_silent_voice(rom: Rom, sfxidlist: Iterable[int], soundbank_entries: dict[str, dict[str, int]], log: CosmeticsLog) -> None:
binsfxfilename = os.path.join(data_path('Voices'), 'SilentVoiceSFX.bin')
if not os.path.isfile(binsfxfilename):
log.errors.append(f"Could not find silent voice sfx at {binsfxfilename}. Skipping voice patching")
return
# Load the silent voice sfx file
with open(binsfxfilename, 'rb') as binsfxin:
binsfx = bytearray() + binsfxin.read(-1)
# Pad it to length and patch it into every id in sfxidlist
for decid in sfxidlist:
sfxid = f"00-00{decid:02x}"
injectme = binsfx.ljust(soundbank_entries[sfxid]["length"], b'\0')
# Write the binary sfx to the rom
rom.write_bytes(soundbank_entries[sfxid]["romoffset"], injectme)
def apply_voice_patch(rom: Rom, voice_path: str, soundbank_entries: dict[str, dict[str, int]]) -> None:
if not os.path.exists(voice_path):
return
# Loop over all the files in the directory and apply each binary sfx file to the rom
for binsfxfilename in os.listdir(voice_path):
if binsfxfilename.endswith(".bin"):
sfxid = binsfxfilename.split('.')[0].lower()
# Load the binary sound file and pad it to be the same length as the default file
with open(os.path.join(voice_path, binsfxfilename), 'rb') as binsfxin:
binsfx = bytearray() + binsfxin.read(-1)
binsfx = binsfx.ljust(soundbank_entries[sfxid]["length"], b'\0')
# Write the binary sfx to the rom
rom.write_bytes(soundbank_entries[sfxid]["romoffset"], binsfx)
def patch_voices(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# Reset the audiotable back to default to prepare patching voices and read data
rom.write_bytes(0x00079470, rom.original.read_bytes(0x00079470, 0x460AD0))
if settings.generating_patch_file:
if settings.sfx_link_child != 'Default' or settings.sfx_link_adult != 'Default':
log.errors.append("Link's Voice is not patched into outputted ZPF.")
return
soundbank_entries = read_default_voice_data(rom)
voice_ages = (
('Child', settings.sfx_link_child, Sounds.get_voice_sfx_choices(0, False), chain([0x14, 0x87], range(0x1C, 0x36+1), range(0x3E, 0x4C+1))),
('Adult', settings.sfx_link_adult, Sounds.get_voice_sfx_choices(1, False), chain([0x37, 0x38, 0x3C, 0x3D, 0x86], range(0x00, 0x13+1), range(0x15, 0x1B+1), range(0x4D, 0x58+1)))
)
for name, voice_setting, choices, silence_sfx_ids in voice_ages:
# Handle Plando
log_key = f'{name} Voice'
voice_setting = log.src_dict['sfx'][log_key] if log.src_dict.get('sfx', {}).get(log_key, '') else voice_setting
# Resolve Random option
if voice_setting == 'Random':
voice_setting = random.choice(choices)
# Special case patch the silent voice (this is separate because one .bin file is used for every sfx)
if voice_setting == 'Silent':
patch_silent_voice(rom, silence_sfx_ids, soundbank_entries, log)
elif voice_setting != 'Default':
age_path = os.path.join(data_path('Voices'), name)
voice_path = os.path.join(age_path, voice_setting) if os.path.isdir(os.path.join(age_path, voice_setting)) else None
# If we don't have a confirmed directory for this voice, do a case-insensitive directory search.
if voice_path is None:
voice_dirs = [f for f in os.listdir(age_path) if os.path.isdir(os.path.join(age_path, f))] if os.path.isdir(age_path) else []
for directory in voice_dirs:
if directory.casefold() == voice_setting.casefold():
voice_path = os.path.join(age_path, directory)
break
if voice_path is None:
log.errors.append(f"{name} Voice not patched: Cannot find voice data directory: {os.path.join(age_path, voice_setting)}")
break
apply_voice_patch(rom, voice_path, soundbank_entries)
# Write the setting to the log
log.sfx[log_key] = voice_setting
def patch_music_changes(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
# Music tempo changes
if settings.speedup_music_for_last_triforce_piece:
rom.write_byte(symbols['CFG_SPEEDUP_MUSIC_FOR_LAST_TRIFORCE_PIECE'], 0x01)
else:
rom.write_byte(symbols['CFG_SPEEDUP_MUSIC_FOR_LAST_TRIFORCE_PIECE'], 0x00)
log.speedup_music_for_last_triforce_piece = settings.speedup_music_for_last_triforce_piece
if settings.slowdown_music_when_lowhp:
rom.write_byte(symbols['CFG_SLOWDOWN_MUSIC_WHEN_LOWHP'], 0x01)
else:
rom.write_byte(symbols['CFG_SLOWDOWN_MUSIC_WHEN_LOWHP'], 0x00)
log.slowdown_music_when_lowhp = settings.slowdown_music_when_lowhp
def patch_correct_model_colors(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
if settings.correct_model_colors:
rom.write_byte(symbols['CFG_CORRECT_MODEL_COLORS'], 0x01)
else:
rom.write_byte(symbols['CFG_CORRECT_MODEL_COLORS'], 0x00)
log.correct_model_colors = settings.correct_model_colors
def patch_yaxis(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
if settings.uninvert_y_axis_in_first_person_camera:
rom.write_byte(symbols['CFG_UNINVERT_YAXIS_IN_FIRST_PERSON_CAMERA'], 0x01)
else:
rom.write_byte(symbols['CFG_UNINVERT_YAXIS_IN_FIRST_PERSON_CAMERA'], 0x00)
log.uninvert_y_axis_in_first_person_camera = settings.uninvert_y_axis_in_first_person_camera
def patch_dpad_left(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
if settings.display_dpad == 'left':
rom.write_byte(symbols['CFG_DPAD_ON_THE_LEFT'], 0x01)
else:
rom.write_byte(symbols['CFG_DPAD_ON_THE_LEFT'], 0x00)
log.display_dpad = settings.display_dpad
def patch_input_viewer(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
if settings.input_viewer:
rom.write_byte(symbols['CFG_INPUT_VIEWER'], 0x01)
else:
rom.write_byte(symbols['CFG_INPUT_VIEWER'], 0x00)
log.display_dpad = settings.display_dpad
def patch_song_names(rom: Rom, settings: Settings, log: CosmeticsLog, symbols: dict[str, int]) -> None:
bytes_to_write = []
rom.write_byte(symbols['CFG_SONG_NAME_STATE'], 0x00)
if settings.display_custom_song_names != 'off':
if settings.display_custom_song_names == 'top':
rom.write_byte(symbols['CFG_SONG_NAME_STATE'], 0x01)
if settings.display_custom_song_names == 'pause':
rom.write_byte(symbols['CFG_SONG_NAME_STATE'], 0x02)
for index, song_name in enumerate(log.bgm.values()):
if index >= 47:
break
if song_name == 'None':
text_bytes = [ord('\0')] * 50
else:
if len(song_name) > 50:
song_name_cropped = song_name[:50]
text_bytes = [ord('?' if ord(c) >= 0x80 else c) for c in song_name_cropped]
else:
text_bytes = [ord('?' if ord(c) >= 0x80 else c) for c in song_name] + [ord('\0')] * (50 - len(song_name))
bytes_to_write += text_bytes
rom.write_bytes(symbols['CFG_SONG_NAMES'], bytes_to_write)