-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrel.html
More file actions
1498 lines (1344 loc) · 71.1 KB
/
rel.html
File metadata and controls
1498 lines (1344 loc) · 71.1 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>DynamicR — MKWii StaticR.rel — Editor Suite</title>
<style>
:root { --bg:#0f1115; --muted:#a0a4ae; --text:#e6e7ea; --brand:#7aa2ff; }
html, body { height:100%; }
body { margin:0; font:14px/1.45 system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif; color:var(--text); background:#0f1115; }
.container { max-width: 1200px; margin: 28px auto 64px; padding: 0 18px; }
header { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom: 18px; }
.title { font-weight:700; font-size:20px; letter-spacing:0.3px; }
.subtitle { color: var(--muted); font-size:12px; }
.card { background: linear-gradient(180deg, #1c2130, #151924); border:1px solid rgba(255,255,255,0.06); border-radius:16px; box-shadow: 0 15px 40px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04); overflow:hidden; }
.card h2 { margin:0; padding:18px 24px; font-size:14px; letter-spacing:0.2px; background: linear-gradient(0deg, rgba(255,255,255,0.03), rgba(255,255,255,0.07)); border-bottom:1px solid rgba(255,255,255,0.06); display:flex; align-items:center; justify-content:space-between; }
.card .body { padding:28px; }
.row { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.kv { display:grid; grid-template-columns: 160px 1fr; gap:10px; align-items:center; }
.btn { display:inline-flex; align-items:center; gap:8px; background:#1e2433; color:var(--text); border:1px solid rgba(255,255,255,0.08); padding:8px 12px; border-radius:10px; cursor:pointer; user-select:none; }
.btn.primary { background:#27314a; border-color:rgba(122,162,255,0.35); color:#eaf0ff; }
.btn.ok { background:#1c2b24; border-color:rgba(76,195,138,0.3); color:#c8f5e3; }
.muted { color:var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }
.hr { height:1px; background:rgba(255,255,255,0.08); margin:12px 0; }
.palette-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap:12px; }
.swatch { display:flex; align-items:center; gap:10px; padding:10px; background:#121620; border:1px solid rgba(255,255,255,0.12); border-radius:10px; }
.swatch .box { width:34px; height:24px; border-radius:6px; border:1px solid rgba(255,255,255,0.25); }
input[type="color"] { width: 40px; height: 28px; padding:0; border:none; background:transparent; }
input[type="text"], input[type="number"], select { background:#121620; color:var(--text); border:1px solid rgba(255,255,255,0.14); border-radius:8px; padding:6px 8px; }
.small { font-size: 12px; }
</style>
<style>
/* High-contrast chips for Character Order Table DnD */
#cotDnD .chip {
background: #f1f5f9; /* slate-100 */
color: #111827; /* near-black */
border: 1px solid #cbd5e1; /* slate-300 */
border-radius: 10px;
padding: 6px 10px;
font-weight: 600;
line-height: 1.2;
cursor: grab;
user-select: none;
box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
#cotDnD .chip:hover {
background: #e5e7eb; /* gray-200 */
box-shadow: 0 2px 4px rgba(0,0,0,.08);
}
#cotDnD .chip:active {
cursor: grabbing;
transform: scale(0.98);
}
</style>
<style>
/* Soft warning box for duplicate character entries */
#cotWarn strong { font-weight: 700; }
#cotWarn code { background: transparent; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
</style>
</head>
<body>
<div class="container">
<header>
<div>
<div class="title">DynamicR — <span class="muted">MKWii StaticR.rel</span> — <span style="color:#c9e6ff">Editor Suite</span> — v1.2</div>
<div class="subtitle">Extensive <code>StaticR.rel</code> tool suite. Client-side only with region detection. Sponsored by ChatGPT 5 Thinking. Tested on PAL only.<br>Credits to <a href="https://mariokartwii.com/member.php?action=profile&uid=1">Vega</a> and <a href="https://mariokartwii.com/member.php?action=profile&uid=447">Ro</a> for their research and documentations. This tool is inspired by <a href="https://wiki.tockdom.com/wiki/User:Atlas">Atlas</a>' <a href="https://wiki.tockdom.com/wiki/StaticR.rel_Tool">StaticR.rel Tool</a>.</div>
</div>
<div class="row">
<button id="btnSave" class="btn ok" disabled>⬇ Apply & download patched <span class="mono">StaticR.rel</span></button>
<button id="btnRevert" class="btn" disabled>↩ Revert</button>
</div>
</header>
<section class="card">
<h2>1) Load <code class="mono">StaticR.rel</code></h2>
<div class="body">
<div class="row" style="justify-content:center; gap:12px;">
<label class="btn primary" for="file">Choose file…</label>
<input id="file" type="file" accept=",.rel" hidden />
<div class="muted">…or drag & drop your <span class="mono">StaticR.rel</span> here</div>
</div>
<div class="hr"></div>
<div class="kv">
<div class="muted">Loaded file</div>
<div id="fileInfo" class="mono">—</div>
<div class="muted">Region</div>
<div>
<select id="region">
<option value="auto">Auto (SHA-256 → heuristics)</option>
<option value="NTSC-U">NTSC-U (USA)</option>
<option value="PAL">PAL (EUR)</option>
<option value="NTSC-J">NTSC-J (JPN)</option>
<option value="NTSC-K">NTSC-K (KOR)</option>
</select>
</div>
<div class="muted">Assumed base</div>
<div id="base" class="mono">—</div>
</div>
<div class="hr"></div>
<details>
<summary class="muted">How region was chosen</summary>
<div id="detectExplain" class="mono muted" style="padding-top:6px">—</div>
</details>
</div>
</section>
<section class="card">
<h2>2) Editors</h2>
<div class="body">
<div class="row" style="justify-content:space-between; gap:24px; flex-wrap:wrap;">
<div style="flex:1; min-width:480px;">
<h3 class="mono">Region Line Colors (9× RGBA8)</h3>
<div class="row" style="margin-bottom:8px">
<div class="muted">Offset</div>
<input id="offRegionLine" class="mono" size="12" />
<button class="btn" id="btnLoadRegionLine">Load</button>
</div>
<div id="regionLineGrid" class="palette-grid"></div>
</div>
<div style="flex:1; min-width:480px;">
<h3 class="mono">Mii Suit Colors (12× RGBA8)</h3>
<div class="row" style="margin-bottom:8px">
<div class="muted">Offset</div>
<input id="offMii" class="mono" size="12" />
<button class="btn" id="btnLoadMii">Load</button>
</div>
<div id="miiGrid" class="palette-grid"></div>
</div>
</div>
<div class="hr"></div>
<div class="row" style="justify-content:space-between; gap:24px; flex-wrap:wrap;">
<div style="flex:1; min-width:480px;">
<h3 class="mono">Menu Colors</h3>
<div class="row" style="margin-bottom:8px">
<div class="muted">Offset</div>
<input id="offMenu" class="mono" size="12" />
<button class="btn" id="btnLoadMenu">Load</button>
<span class="muted small">Encoding:</span>
<select id="menuMode" title="Choose how Menu colors are stored">
<option value="rgba8" selected>RGBA8 (00RR 00GG 00BB 00AA) — 18 entries, Atlas</option>
</select>
</div>
<div id="menuGrid" class="palette-grid"></div>
<div class="small muted">
<span id="menuHint">RGBA8 mode treats the table as 18× entries at 8-byte stride: <span class="mono">00RR 00GG 00BB 00AA</span> (Atlas-style).</span>.</span>
</div>
</div>
<div style="flex:1; min-width:480px;">
<h3 class="mono">HUD Color (4× f32 @ fixed offsets)</h3>
<div class="row" style="margin-bottom:8px">
<div class="muted">Offset</div>
<input id="offHUD" class="mono" size="12" />
<button class="btn" id="btnLoadHUD">Load</button>
<span class="muted small">Mode:</span> <select id="hudMode" title="Choose how HUD color is stored"><option value="simple" selected>Simple (White / Yellow / Dark Green)</option><option value="f32">Floats (4× BE f32)</option><option value="atlas">Atlas (Beta, RGB @ (off&~3)+4)</option></select> <span class="muted small">Reads 4× big-endian float from 4-byte aligned address near the given offset (wiki: <code>Change Color of HUD</code>).</span>
</div>
<div id="hudGrid" class="palette-grid"></div>
</div>
</div>
</div>
</section>
<section class="card">
<h2>2b) Fake Item Box Color Modifier</h2>
<div class="body">
<div class="kv">
<div class="muted">First patch offset</div>
<div class="mono" id="fake1Off">—</div>
<div class="muted">First patch value</div>
<div class="row">
<span id="fake1Cur" class="mono small">—</span>
<input id="fake1Hex" class="mono" size="10" placeholder="8 hex (BE)" />
<button class="btn" id="btnFake1Write">Write</button>
<button class="btn ok" id="btnFake1Real">Looks like real</button>
</div>
<div class="muted">Second patch offset</div>
<div class="mono" id="fake2Off">—</div>
<div class="muted">Second patch value</div>
<div class="row">
<span id="fake2Cur" class="mono small">—</span>
<input id="fake2Hex" class="mono" size="10" placeholder="8 hex (BE)" />
<button class="btn" id="btnFake2Write">Write</button>
<button class="btn ok" id="btnFake2Real">Looks like real</button>
</div>
</div>
<div class="small muted" style="margin-top:8px">
Values are written as big-endian u32. Quick set: First = <span class="mono">0x4BC00000</span>, Second = <span class="mono">0x40000000</span>. Offsets per region from the wiki.
</div>
</div>
</section>
<section class="card">
<h2>3) Item Behavior Modifier</h2>
<div class="body">
<div class="kv" style="row-gap:10px; align-items:center">
<div class="muted">Item</div>
<div class="row">
<select id="itemBehItem" style="min-width:220px"></select>
<button class="btn" id="btnLoadItemBeh">Load</button>
</div>
<div class="muted">Offset (current region)</div>
<div class="mono" id="itemBehOff">—</div>
<div class="muted">Standard value</div>
<div class="mono" id="itemBehStd">—</div>
<div class="muted">Current value</div>
<div class="mono" id="itemBehCur">—</div>
<div class="muted">Desired behavior</div>
<div class="row">
<select id="itemBehSelect" style="min-width:280px">
<option value="0">00 — Use Item (e.g. Bullet Bill)</option>
<option value="1">01 — Fire Item (e.g. Red Shell)</option>
<option value="2">02 — Trailing Kart (e.g. Triple Banana)</option>
<option value="3">03 — Circling Kart (e.g. Triple Shell)</option>
</select>
<button class="btn primary" id="btnWriteItemBeh">Write</button>
<button class="btn" id="btnResetItemBeh">Reset to Standard</button>
</div>
</div>
<div class="small muted" style="margin-top:12px">
Values are written as big-endian <span class="mono">u32</span> (0x00000000–0x00000003). Offsets per region from the Tockdom wiki.
</div>
</div>
</section>
<section class="card">
<h2>4) Engine Class Modifier</h2>
<div class="body">
<div class="kv" style="row-gap:10px; align-items:center">
<div class="muted">Engine Class</div>
<div class="row">
<select id="engClassSelect" style="min-width:260px"></select>
<button class="btn" id="btnLoadEngineClass">Load</button>
</div>
<div class="muted">Offset (current region)</div>
<div class="mono" id="engOff">—</div>
<div class="muted">Standard value</div>
<div class="mono" id="engStd">—</div>
<div class="muted">Current value</div>
<div class="mono" id="engCur">—</div>
<div class="muted">Desired multiplier (f32)</div>
<div class="row">
<input id="engValue" type="number" step="0.01" min="0.50" max="2.50" style="width:120px" />
<button class="btn primary" id="btnWriteEngineClass">Write</button>
<button class="btn" id="btnResetEngineClass">Reset to Standard</button>
</div>
</div>
<div class="small muted" style="margin-top:12px">
Values are written as big-endian <span class="mono">f32</span>. Offsets per region from the attached Tockdom documentation.
</div>
</div>
</section>
<section class="card">
<h2>5) Menu Character Display Position</h2>
<div class="body">
<div class="kv" style="row-gap:10px; align-items:center">
<div class="muted">Offset (current region)</div>
<div class="mono" id="mcdpOff">—</div>
<div class="muted">Standard values (f32)</div>
<div class="mono" id="mcdpStd">x = -190.000, y = 0.000, scale = 1.000</div>
<div class="muted">Current values (f32)</div>
<div class="mono" id="mcdpCur">—</div>
<div class="muted">Desired values</div>
<div class="row" style="gap:8px; flex-wrap:wrap">
<label> x: <input id="mcdpX" type="number" step="0.1" style="width:110px"></label>
<label> y: <input id="mcdpY" type="number" step="0.1" style="width:110px"></label>
<label> scale: <input id="mcdpS" type="number" step="0.01" min="0.10" max="5.00" style="width:110px"></label>
<button class="btn" id="btnLoadMCDP">Load</button>
<button class="btn primary" id="btnWriteMCDP">Write</button>
<button class="btn" id="btnResetMCDP">Reset to Standard</button>
</div>
</div>
<div class="small muted" style="margin-top:12px">
Three consecutive <span class="mono">f32</span> values: <span class="mono">x</span> (horizontal from center), <span class="mono">y</span> (vertical from center),
and <span class="mono">scale</span>. Values are big-endian. Offsets per region from the attached documentation.
</div>
</div>
</section>
<section class="card">
<h2>6) Race Points (Offline / Friend Rooms)</h2>
<div class="body">
<div class="kv" style="row-gap:10px; align-items:center">
<div class="muted">Base offset (current region)</div>
<div class="mono" id="ptsBaseOff">—</div>
<div class="muted">Definition size</div>
<div class="mono">144 bytes (12 groups × 12 bytes)</div>
<div class="muted">Player count</div>
<div class="row">
<select id="ptsPlayerCount" style="min-width:160px">
<option value="1">1 player</option>
<option value="2">2 players</option>
<option value="3">3 players</option>
<option value="4">4 players</option>
<option value="5">5 players</option>
<option value="6">6 players</option>
<option value="7">7 players</option>
<option value="8">8 players</option>
<option value="9">9 players</option>
<option value="10">10 players</option>
<option value="11">11 players</option>
<option value="12">12 players</option>
</select>
<button class="btn" id="btnPtsLoad">Load</button>
</div>
<div class="muted">Group offset</div>
<div class="mono" id="ptsGroupOff">—</div>
<div class="muted">Standard values</div>
<div class="mono" id="ptsStd">—</div>
<div class="muted">Current values</div>
<div class="mono" id="ptsCur">—</div>
<div class="muted">Desired values (per finishing position)</div>
<div id="ptsInputs" class="row" style="gap:6px; flex-wrap:wrap"></div>
<div class="row" style="gap:8px">
<button class="btn primary" id="btnPtsWrite">Write</button>
<button class="btn" id="btnPtsReset">Reset to Standard</button>
</div>
</div>
<div class="small muted" style="margin-top:12px">
Each player-count group stores up to 12 one-byte values (big-endian is irrelevant for bytes). Only the first <em>N</em> bytes are used for N players; the remaining bytes are unused. Offsets per region are based on the Tockdom documentation.
</div>
</div>
</section>
<section class="card">
<h2>7) Character Order Table</h2>
<div class="body">
<div class="kv" style="row-gap:10px; align-items:center">
<div class="muted">Base offset (current region)</div>
<div class="mono" id="cotBaseOff">—</div>
<div class="muted">Table size</div>
<div class="mono">0x60 bytes (24 entries × 4 bytes)</div>
<div class="muted">Current table (decoded)</div>
<div class="mono" id="cotCur">—</div>
<div class="muted">Edit slots (left → right)</div>
<div id="cotGrid" class="row" style="gap:8px; flex-wrap:wrap"></div>
<div class="muted">Drag & drop order (left → right)</div>
<div id="cotDnD" class="row" style="gap:8px; flex-wrap:wrap"></div>
<div id="cotWarn" class="small" style="display:none; margin:8px 0; padding:8px 10px; border-radius:8px; border:1px solid #F59E0B; background:#FEF3C7; color:#78350F;">
<!-- Duplicate warning text goes here -->
</div>
<div class="row" style="gap:8px">
<button class="btn" id="btnCOTLoad">Load</button>
<button class="btn primary" id="btnCOTWrite">Write</button>
<button class="btn" id="btnCOTFillAsc">Fill ascending by code</button>
</div>
</div>
<div class="small muted" style="margin-top:12px">
Each entry is the 32‑bit big‑endian value of the character’s identifier (see identifiers list). As you unlock characters, right‑hand slots appear in the UI. Offsets per region from the attached documentation.
</div>
</div>
</section>
</div>
<script>
// ===== Region bases & heuristics =====
const BASES = { 'NTSC-U':0x8050BF60, 'PAL':0x805102E0, 'NTSC-J':0x8050FC60, 'NTSC-K':0x804FE300 };
// Heuristics (credit Ro)
const HEUR_BUNDLE1 = { 'NTSC-U':[0x80831CCC,0x80831DC0], 'PAL':[0x808512E0,0x808513D4], 'NTSC-J':[0x8085094C,0x80850A40], 'NTSC-K':[0x8083F6A0,0x8083F794] };
const HEUR_B1_WORD = 0x88030014;
const HEUR_BUNDLE2 = { 'NTSC-U':[0x80831BD8], 'PAL':[0x808511EC], 'NTSC-J':[0x80850858], 'NTSC-K':[0x8083F5AC] };
const HEUR_B2_WORD = HEUR_B1_WORD;
// Known retail SHA-256 signatures (user-supplied)
const KNOWN_SHA256 = {
'16d9d146112541fefea701ecb5bc1a496f9d50e4a752fbb5b6778e7c6399f67d':'PAL',
'1168107f8fdef27a356df76036db55afe4fbf7752606dbac991726701133a617':'NTSC-U',
'88539012d357a1420724e51dc7e351192ce696da4b0045994895518a3fad6fae':'NTSC-J',
'f441b08e4ccc2d64aadcac8429973f10ea6b1cc8f175500fc084983775f7b3e5':'NTSC-K',
};
const KNOWN_SIZE = { 4903876:'PAL', 4902804:'NTSC-U', 4901564:'NTSC-J', 4905468:'NTSC-K' };
// Confirmed color tables (file offsets per region)
const OFFS_REGION_LINE = { 'PAL':0x00399B14, 'NTSC-U':0x0039856C, 'NTSC-J':0x003992F4, 'NTSC-K':0x00399F54 }; // 9×RGBA8
const OFFS_MII = { 'PAL':0x00394838, 'NTSC-U':0x003941F8, 'NTSC-J':0x00394018, 'NTSC-K':0x00394C78 }; // 12×RGBA8
const OFFS_MENU_RGB = { 'PAL':0x003859E0, 'NTSC-U':0x00383DB8, 'NTSC-J':0x003856B0, 'NTSC-K':0x003862E8 }; // base for both modes
// HUD "Change Color of HUD" (wiki) — align to 4 for f32
const OFFS_HUD = { 'PAL':0x00399346, 'NTSC-U':0x00397F9E, 'NTSC-J':0x00398B26, 'NTSC-K':0x00399786 };
// Fake Item Box Color Modifier offsets
const OFFS_FAKEBOX_1 = { 'PAL':0x003953E0, 'NTSC-U':0x00394DA0, 'NTSC-J':0x00394BC0, 'NTSC-K':0x00395820 };
const OFFS_FAKEBOX_2 = { 'PAL':0x00395EF0, 'NTSC-U':0x00395540, 'NTSC-J':0x003956D0, 'NTSC-K':0x00396330 };
const FAKEBOX_REAL_1 = 0x4BC00000;
const FAKEBOX_REAL_2 = 0x40000000;
// ===== State =====
let fileHandle=null, original=null, bytes=null, view=null, shaSeen=null, detectedRegion=null;
// ===== Helpers =====
const $ = s=>document.querySelector(s);
const hex = (n,w=2)=>'0x'+(n>>>0).toString(16).toUpperCase().padStart(w,'0');
const toHex2 = v=>v.toString(16).toUpperCase().padStart(2,'0');
const fromHex = s=>parseInt(String(s).trim().replace(/[^0-9A-Fa-f]/g,''),16)>>>0;
async function sha256(u8){ const h=await crypto.subtle.digest('SHA-256', u8); return Array.from(new Uint8Array(h)).map(b=>b.toString(16).padStart(2,'0')).join(''); }
function setDisabled(id, v){ const el=document.getElementById(id); if (el) el.disabled=!!v; }
function renderDetectExplain(region, reason){
const el = document.getElementById('detectExplain');
if (!el){ return; }
const size = bytes?.length||0;
const sigRegion = shaSeen ? (KNOWN_SHA256[shaSeen]||null) : null;
// Heuristic summaries
const heur = {};
const heur2 = {};
if (bytes && view){
for (const [reg, base] of Object.entries(BASES)){
let m1=0, t1=(HEUR_BUNDLE1[reg]||[]).length;
for (const a of (HEUR_BUNDLE1[reg]||[])){ const off=(a-base)>>>0; if (off+4<=bytes.length && view.getUint32(off,false)===HEUR_B1_WORD) m1++; }
heur[reg]={match:m1,total:t1};
let m2=0, t2=(HEUR_BUNDLE2[reg]||[]).length;
for (const a of (HEUR_BUNDLE2[reg]||[])){ const off=(a-base)>>>0; if (off+4<=bytes.length && view.getUint32(off,false)===HEUR_B2_WORD) m2++; }
heur2[reg]={match:m2,total:t2};
}
}
const parts1 = Object.keys(heur).length ? `Heuristic #1 (Ro): ${Object.keys(heur).map(r=>`${r} ${heur[r].match}/${heur[r].total}`).join(' • ')}` : '';
const parts2 = Object.keys(heur2).length ? `Heuristic #2 (Ro): ${Object.keys(heur2).map(r=>`${r} ${heur2[r].match}/${heur2[r].total}`).join(' • ')}` : '';
el.innerHTML = [
region ? `Chosen: <span class="mono">${region}</span> <span class="muted">(${reason})</span>` : null,
shaSeen ? `Signature: ${sigRegion?('match '+sigRegion):'no match'} <span class="mono">SHA-256 ${shaSeen.slice(0,8)}…</span> • size ${size.toLocaleString()} bytes` : `Size ${size.toLocaleString()} bytes`,
parts1, parts2
].filter(Boolean).map(s=>`<div>${s}</div>`).join('');
}
function pickRegion(){
if (KNOWN_SHA256[shaSeen]) return {region:KNOWN_SHA256[shaSeen], reason:'detected'};
// Heur1
const c1=[];
for (const [reg,base] of Object.entries(BASES)){
const addrs=HEUR_BUNDLE1[reg]; if(!addrs) continue;
let ok=true;
for (const a of addrs){ const off=(a-base)>>>0; if(off+4>bytes.length){ok=false;break;} if(view.getUint32(off,false)!==HEUR_B1_WORD){ok=false;break;} }
if(ok) c1.push(reg);
}
if (c1.length===1) return {region:c1[0], reason:'heuristic: Ro #1'};
// Heur2
const c2=[];
for (const [reg,base] of Object.entries(BASES)){
const addrs=HEUR_BUNDLE2[reg]; if(!addrs) continue;
let ok=true;
for (const a of addrs){ const off=(a-base)>>>0; if(off+4>bytes.length){ok=false;break;} if(view.getUint32(off,false)!==HEUR_B2_WORD){ok=false;break;} }
if(ok) c2.push(reg);
}
if (c2.length===1) return {region:c2[0], reason:'heuristic: Ro #2'};
return {region:null, reason:'ambiguous'};
}
function currentRegion(){ const sel=document.getElementById('region').value; if (sel && sel!=='auto') return sel; return KNOWN_SHA256[shaSeen]||KNOWN_SIZE[bytes?.length]||null; }
// ===== Color I/O =====
function readRGBA(off,count){ const out=[]; for(let i=0;i<count;i++){ const o=off+i*4; out.push([bytes[o],bytes[o+1],bytes[o+2],bytes[o+3]]);} return out; }
function writeRGBA(off,arr){ for(let i=0;i<arr.length;i++){ const o=off+i*4; const [r,g,b,a]=arr[i]; bytes[o]=r; bytes[o+1]=g; bytes[o+2]=b; bytes[o+3]=a; } }
function readRGB16(off,count){ let p=off; const out=[]; for(let i=0;i<count;i++){ const r=(bytes[p]<<8|bytes[p+1])&0xFFFF; const g=(bytes[p+2]<<8|bytes[p+3])&0xFFFF; const b=(bytes[p+4]<<8|bytes[p+5])&0xFFFF; out.push([r&0xFF,g&0xFF,b&0xFF]); p+=6; } return out; }
function writeRGB16(off,arr){ let p=off; for(const [r8,g8,b8] of arr){ bytes[p]=0; bytes[p+1]=r8&0xFF; bytes[p+2]=0; bytes[p+3]=g8&0xFF; bytes[p+4]=0; bytes[p+5]=b8&0xFF; p+=6; } }
// Menu RGBA8 (Atlas-style) 18 entries × 8B = 00RR 00GG 00BB 00AA
function readMenuRGBA8(off, count = 18){ const out=[]; let p=off>>>0; for(let i=0;i<count;i++,p+=8){ out.push([bytes[p+1],bytes[p+3],bytes[p+5],bytes[p+7]]); } return out; }
function writeMenuRGBA8(off, arr){ let p=off>>>0; for(const [r,g,b,a] of arr){ bytes[p]=0;bytes[p+1]=r&0xFF; bytes[p+2]=0;bytes[p+3]=g&0xFF; bytes[p+4]=0;bytes[p+5]=b&0xFF; bytes[p+6]=0;bytes[p+7]=a&0xFF; p+=8; } }
function readF32BE(off){ const b=(off&~3)>>>0; const v=new DataView(bytes.buffer).getFloat32(b,false); return { at:b, value:v }; }
function writeF32BE(off,val){ const b=(off&~3)>>>0; new DataView(bytes.buffer).setFloat32(b,val,false); }
// ===== Swatch =====
function makeSwatch(parent, label, rgba, onChange, withAlpha = true) {
const el = document.createElement('div'); el.className = 'swatch';
const box = document.createElement('div'); box.className = 'box';
const lab = document.createElement('div'); lab.textContent = label; lab.style.minWidth = '64px';
const col = document.createElement('input'); col.type = 'color'; col.value = `#${toHex2(rgba[0])}${toHex2(rgba[1])}${toHex2(rgba[2])}`;
const hexIn = document.createElement('input'); hexIn.type='text'; hexIn.className='mono'; hexIn.size = withAlpha?10:8; hexIn.placeholder = withAlpha?'RRGGBBAA':'RRGGBB';
hexIn.value = withAlpha ? `${toHex2(rgba[0])}${toHex2(rgba[1])}${toHex2(rgba[2])}${toHex2(rgba[3] ?? 255)}`
: `${toHex2(rgba[0])}${toHex2(rgba[1])}${toHex2(rgba[2])}`;
let a = null;
if (withAlpha) { a = document.createElement('input'); a.type='number'; a.min=0; a.max=255; a.value=rgba[3] ?? 255; a.style.width='72px'; a.title='Alpha'; }
function preview(r,g,b,aa){ box.style.background = `rgba(${r},${g},${b},${(aa/255).toFixed(3)})`; }
function sync(){ const r=parseInt(col.value.slice(1,3),16), g=parseInt(col.value.slice(3,5),16), b=parseInt(col.value.slice(5,7),16); const aa=withAlpha?Math.max(0,Math.min(255,(parseInt(a.value||'255',10)|0))):255; preview(r,g,b,aa); hexIn.value = withAlpha?`${toHex2(r)}${toHex2(g)}${toHex2(b)}${toHex2(aa)}`:`${toHex2(r)}${toHex2(g)}${toHex2(b)}`; onChange([r,g,b,aa]); enableSave(); }
function syncHex(){ let v=hexIn.value.replace(/[^0-9A-Fa-f]/g,''); if(withAlpha){ v=v.slice(0,8).padEnd(8,'F'); const r=parseInt(v.slice(0,2),16), g=parseInt(v.slice(2,4),16), b=parseInt(v.slice(4,6),16), aa=parseInt(v.slice(6,8),16); col.value=`#${toHex2(r)}${toHex2(g)}${toHex2(b)}`; a.value=aa; preview(r,g,b,aa); onChange([r,g,b,aa]); } else { v=v.slice(0,6).padEnd(6,'F'); const r=parseInt(v.slice(0,2),16), g=parseInt(v.slice(2,4),16), b=parseInt(v.slice(4,6),16), aa=255; hexIn.value=v.toUpperCase(); col.value=`#${toHex2(r)}${toHex2(g)}${toHex2(b)}`; preview(r,g,b,aa); onChange([r,g,b,aa]); } enableSave(); }
col.addEventListener('input', sync); if (withAlpha) a.addEventListener('input', sync); hexIn.addEventListener('change', syncHex);
if (withAlpha) el.append(box, lab, col, a, hexIn); else el.append(box, lab, col, hexIn);
preview(rgba[0],rgba[1],rgba[2], withAlpha ? (rgba[3] ?? 255) : 255); parent.appendChild(el);
}
// ===== Panels =====
function fillRegionLine(){ const off=fromHex(document.getElementById('offRegionLine').value); const vals=readRGBA(off,9); const grid=document.getElementById('regionLineGrid'); grid.innerHTML=''; vals.forEach((rgba,i)=> makeSwatch(grid, String(i+1), rgba, v=>{ const arr=readRGBA(off,9); arr[i]=v; writeRGBA(off,arr); })); }
function fillMii(){ const off=fromHex(document.getElementById('offMii').value); const vals=readRGBA(off,12); const grid=document.getElementById('miiGrid'); grid.innerHTML=''; vals.forEach((rgba,i)=> makeSwatch(grid, String(i+1), rgba, v=>{ const arr=readRGBA(off,12); arr[i]=v; writeRGBA(off,arr); })); }
function fillMenu(){
const off = fromHex(document.getElementById('offMenu').value);
const grid = document.getElementById('menuGrid'); grid.innerHTML='';
const count = 18;
const rgba = readMenuRGBA8(off, count); // 00RR 00GG 00BB 00AA
rgba.forEach((px,i)=> makeSwatch(grid, String(i+1), px, v=>{ const arr=readMenuRGBA8(off,count); arr[i]=v; writeMenuRGBA8(off,arr); }, true));
document.getElementById('menuHint').textContent = 'RGBA8 mode treats the table as 18× entries at 8-byte stride: 00RR 00GG 00BB 00AA (Atlas-style).';
}
function fillHUD(){
const off = fromHex(document.getElementById('offHUD').value);
const mode = (document.getElementById('hudMode')?.value) || 'f32';
const grid = document.getElementById('hudGrid');
grid.innerHTML = '';
if (!bytes || Number.isNaN(off)) { return; }
// simple mode: three presets by setting P2 (W1) only
if (mode === 'simple'){
const base = (off & ~3) >>> 0;
const addr = base + 4; // P2 (W1)
const grid = document.getElementById('hudGrid');
if (addr + 3 >= bytes.length){
const el=document.createElement('div'); el.className='muted mono'; el.textContent='Out of bounds at '+hex(addr,6); grid.appendChild(el);
return;
}
const dv=new DataView(bytes.buffer);
const cur = dv.getFloat32(addr, false);
const row=document.createElement('div'); row.className='swatch'; row.style.flexWrap='wrap';
const lab=document.createElement('div'); lab.textContent='Simple HUD Color'; lab.style.minWidth='160px';
function makeRadio(id, label, val){
const wrap=document.createElement('label');
wrap.style.marginRight='12px';
wrap.style.display='inline-flex';
wrap.style.alignItems='center';
wrap.style.gap='6px';
const r=document.createElement('input'); r.type='radio'; r.name='hudSimple'; r.value=String(val); r.id=id;
const span=document.createElement('span'); span.textContent=label;
wrap.append(r, span);
r.addEventListener('change', ()=>{
const f = parseFloat(r.value);
if (!Number.isFinite(f)) return;
dv.setFloat32(addr, f, false);
enableSave();
});
return wrap;
}
const rWhite = makeRadio('hudSimpleWhite','White (P2 = 175.9)', 175.9);
const rYellow= makeRadio('hudSimpleYellow','Yellow (P2 = 176.0)', 176.0);
const rGreen = makeRadio('hudSimpleGreen','Dark Green (P2 = 176.1)', 176.1);
// select radio based on current value
const eps=1e-3;
if (Math.abs(cur - 175.9) < eps) rWhite.querySelector('input').checked = true;
else if (Math.abs(cur - 176.0) < eps) rYellow.querySelector('input').checked = true;
else if (cur > 176.0) rGreen.querySelector('input').checked = true;
const addrDiv=document.createElement('div'); addrDiv.className='mono muted'; addrDiv.textContent = hex(addr,6)+' (P2 @ W1, BE f32)'; addrDiv.style.flexBasis='100%';
row.append(lab, rWhite, rYellow, rGreen, addrDiv);
grid.appendChild(row);
const note=document.createElement('div'); note.className='small muted';
note.textContent = 'Rules (this PAL build): P2 < 176 → White; P2 = 176 → Yellow; P2 > 176 → Green. P4 ≥ ~1.10 also forces Green.';
grid.appendChild(note);
return;
}if (mode === 'f32'){
const base = (off & ~3) >>> 0;
if (base + 12 >= bytes.length){
const el=document.createElement('div'); el.className='muted mono'; el.textContent='Out of bounds for 4×f32 at '+hex(base,6); grid.appendChild(el);
return;
}
const dv=new DataView(bytes.buffer);
const vals=[ dv.getFloat32(base+0,false), dv.getFloat32(base+4,false), dv.getFloat32(base+8,false), dv.getFloat32(base+12,false) ];
vals.forEach((f,i)=>{
const el=document.createElement('div'); el.className='swatch';
const lab=document.createElement('div'); lab.textContent='P'+(i+1); lab.style.minWidth='64px';
const inp=document.createElement('input'); inp.type='number'; inp.step='0.01'; inp.value=Number.isFinite(f)?String(f):'0'; inp.style.width='120px';
const hexv=document.createElement('div'); hexv.className='mono muted'; hexv.textContent = hex(base+4*i,6);
inp.addEventListener('input',()=>{ let v=parseFloat(inp.value); if(!Number.isFinite(v)) v=0; dv.setFloat32(base+4*i, v, false); enableSave(); });
el.append(lab, inp, hexv); grid.appendChild(el);
});
return;
}
// atlas mode (Beta): writes RGB as 4 bytes [R,G,B,0x00] at (off&~3)+4 (the second 32-bit word)
if (mode === 'atlas'){
const base = (off & ~3) >>> 0;
const addr = base + 4;
if (addr + 3 >= bytes.length){
const el=document.createElement('div'); el.className='muted mono'; el.textContent='Out of bounds at '+hex(addr,6); grid.appendChild(el);
return;
}
let r = bytes[addr], g = bytes[addr+1], b = bytes[addr+2], a = bytes[addr+3];
const toHex2 = x => (x&0xFF).toString(16).toUpperCase().padStart(2,'0');
const toCss = () => '#'+toHex2(r)+toHex2(g)+toHex2(b);
const row=document.createElement('div'); row.className='swatch'; row.style.flexWrap='wrap';
const lab=document.createElement('div'); lab.textContent='Color (Atlas RGB)'; lab.style.minWidth='140px';
// Color input and live preview
const color=document.createElement('input'); color.type='color'; color.value = toCss();
color.style.width='48px'; color.style.height='32px'; color.style.padding='0'; color.style.border='none';
const preview=document.createElement('div');
preview.title='Preview';
preview.style.width='24px'; preview.style.height='24px';
preview.style.border='1px solid #999'; preview.style.borderRadius='4px';
preview.style.backgroundColor = toCss();
color.addEventListener('input', ()=>{
const v = color.value.replace('#','');
if (v.length===6){
r = parseInt(v.slice(0,2),16); g = parseInt(v.slice(2,4),16); b = parseInt(v.slice(4,6),16);
bytes[addr] = r; bytes[addr+1] = g; bytes[addr+2] = b; bytes[addr+3] = 0x00;
rIn.value = String(r); gIn.value = String(g); bIn.value = String(b);
preview.style.backgroundColor = toCss();
enableSave();
}
});
// Numeric RGB inputs
const rIn=document.createElement('input'); rIn.type='number'; rIn.min='0'; rIn.max='255'; rIn.step='1'; rIn.style.width='70px'; rIn.value=String(r);
const gIn=document.createElement('input'); gIn.type='number'; gIn.min='0'; gIn.max='255'; gIn.step='1'; gIn.style.width='70px'; gIn.value=String(g);
const bIn=document.createElement('input'); bIn.type='number'; bIn.min='0'; bIn.max='255'; bIn.step='1'; bIn.style.width='70px'; bIn.value=String(b);
function writeRGB(){
let R = Math.max(0, Math.min(255, parseInt(rIn.value||'0',10)|0));
let G = Math.max(0, Math.min(255, parseInt(gIn.value||'0',10)|0));
let B = Math.max(0, Math.min(255, parseInt(bIn.value||'0',10)|0));
r = R; g = G; b = B;
bytes[addr] = r; bytes[addr+1] = g; bytes[addr+2] = b; bytes[addr+3] = 0x00;
color.value = toCss();
preview.style.backgroundColor = toCss();
enableSave();
}
rIn.addEventListener('change', writeRGB);
gIn.addEventListener('change', writeRGB);
bIn.addEventListener('change', writeRGB);
const addrDiv=document.createElement('div'); addrDiv.className='mono muted'; addrDiv.textContent = hex(addr,6)+' [R,G,B,00]';
// Alpha info on its own line to avoid clipping
const aLine=document.createElement('div'); aLine.style.flexBasis='100%';
const aInfo=document.createElement('div'); aInfo.className='mono muted';
aInfo.textContent = 'A=0x';
const aHex=document.createElement('span'); aHex.textContent = toHex2(a);
aInfo.appendChild(aHex);
aInfo.appendChild(document.createTextNode(' (written as 00)'));
aLine.appendChild(aInfo);
row.append(lab, color, preview, rIn, gIn, bIn, addrDiv, aLine);
grid.appendChild(row);
const note=document.createElement('div'); note.className='small muted';
note.textContent = 'Atlas mode writes RGB as 4 bytes [R,G,B,00] at (off&~3)+4 (the second 32-bit word).';
grid.appendChild(note);
return;
}
}
// ==== Fake Item Box helpers ====
function u32toHex(u){ return (u>>>0).toString(16).toUpperCase().padStart(8,'0'); }
function readFakeBox(){
const reg=currentRegion(); const o1=OFFS_FAKEBOX_1[reg]; const o2=OFFS_FAKEBOX_2[reg];
const off1El=document.getElementById('fake1Off'); const off2El=document.getElementById('fake2Off');
const cur1=document.getElementById('fake1Cur'); const cur2=document.getElementById('fake2Cur');
if(!bytes||!reg||o1==null||o2==null){ if(off1El) off1El.textContent='—'; if(off2El) off2El.textContent='—'; if(cur1) cur1.textContent='—'; if(cur2) cur2.textContent='—'; return; }
off1El.textContent=hex(o1,6); off2El.textContent=hex(o2,6);
const v1=view.getUint32(o1,false), v2=view.getUint32(o2,false);
if(cur1) cur1.textContent=`0x${u32toHex(v1)}`; if(cur2) cur2.textContent=`0x${u32toHex(v2)}`;
const in1=document.getElementById('fake1Hex'); const in2=document.getElementById('fake2Hex');
if(in1 && !in1.value) in1.value=u32toHex(v1); if(in2 && !in2.value) in2.value=u32toHex(v2);
}
function writeFake(which,val){ const reg=currentRegion(); if(!bytes||!reg){ alert('Load file / choose region first'); return; } const off = which===1?OFFS_FAKEBOX_1[reg]:OFFS_FAKEBOX_2[reg]; view.setUint32(off, (val>>>0), false); enableSave(); readFakeBox(); }
// ===== Save / Revert =====
function enableSave(){ setDisabled('btnSave', false); setDisabled('btnRevert', false); }
function revert(){ if(!original||!bytes) return; bytes.set(original); view=new DataView(bytes.buffer); setDisabled('btnSave', true); setDisabled('btnRevert', true); initForRegion(document.getElementById('region').value); }
function save(){ const blob=new Blob([bytes],{type:'application/octet-stream'}); const a=document.createElement('a'); const baseName=(fileHandle?.name||'StaticR.rel').replace(/\.[^.]+$/,''); a.href=URL.createObjectURL(blob); a.download=baseName+'.patched.rel'; document.body.appendChild(a); a.click(); a.remove(); setTimeout(()=>URL.revokeObjectURL(a.href),1500); setDisabled('btnRevert', false); }
// ===== Region init =====
function initForRegion(reg){
if(!reg || !OFFS_REGION_LINE[reg]) return;
document.getElementById('offRegionLine').value=hex(OFFS_REGION_LINE[reg],6);
document.getElementById('offMii').value=hex(OFFS_MII[reg],6);
document.getElementById('offMenu').value=hex(OFFS_MENU_RGB[reg],6);
document.getElementById('offHUD').value=hex(OFFS_HUD[reg],6);
document.getElementById('menuMode').value='rgba8';
fillRegionLine(); fillMii(); fillMenu(); fillHUD(); readFakeBox();
refreshItemBehaviorUI(); refreshEngineClassUI(); refreshMCDPUI(); refreshPtsUI(); refreshCOTUI(); }
// ===== File I/O & detection =====
function loadFile(f){
if(!f) return;
fileHandle=f;
const fr=new FileReader();
fr.onload=async()=>{
const buf=fr.result;
original=new Uint8Array(buf);
bytes=new Uint8Array(buf.slice(0));
view=new DataView(bytes.buffer);
document.getElementById('fileInfo').textContent=`${f.name} — ${bytes.length.toLocaleString()} bytes`;
setDisabled('btnSave', true); setDisabled('btnRevert', true);
// detect sig
detectedRegion = KNOWN_SIZE[bytes.length] || null;
try { shaSeen = await sha256(bytes); if (KNOWN_SHA256[shaSeen]) detectedRegion = KNOWN_SHA256[shaSeen]; } catch {}
const det = pickRegion(); // uses heuristics too
const autoRegion = det.region || detectedRegion || KNOWN_SIZE[bytes.length] || null;
if (autoRegion && BASES[autoRegion]){
document.getElementById('region').value = autoRegion;
document.getElementById('base').textContent = hex(BASES[autoRegion],8) + ` (${det.reason || 'detected'})`;
initForRegion(autoRegion);
renderDetectExplain(autoRegion, det.reason || 'detected');
} else {
document.getElementById('base').textContent = '(ambiguous) choose region';
renderDetectExplain(null, 'ambiguous');
readFakeBox();
}
};
fr.readAsArrayBuffer(f);
}
// ===== Wire up =====
const dropArea = document.querySelector('section input#file').parentElement.parentElement;
dropArea.addEventListener('dragover', e=>{ e.preventDefault(); });
dropArea.addEventListener('drop', e=>{ e.preventDefault(); const f=e.dataTransfer.files[0]; loadFile(f); });
document.getElementById('file').addEventListener('change', e=> loadFile(e.target.files[0]));
document.getElementById('region').addEventListener('change', ()=>{
if (!bytes) return;
const reg = document.getElementById('region').value;
if (reg && reg !== 'auto'){
document.getElementById('base').textContent = hex(BASES[reg],8) + ' (manual)';
initForRegion(reg);
renderDetectExplain(reg, 'manual');
} else {
const det = pickRegion();
const autoRegion = det.region || detectedRegion || KNOWN_SIZE[bytes.length] || null;
if (autoRegion && BASES[autoRegion]){
document.getElementById('region').value = autoRegion;
document.getElementById('base').textContent = hex(BASES[autoRegion],8) + ` (${det.reason || 'detected'})`;
initForRegion(autoRegion);
renderDetectExplain(autoRegion, det.reason || 'detected');
}
}
});
document.getElementById('btnLoadRegionLine').addEventListener('click', fillRegionLine);
document.getElementById('btnLoadMii').addEventListener('click', fillMii);
document.getElementById('btnLoadMenu').addEventListener('click', fillMenu);
document.getElementById('btnLoadHUD').addEventListener('click', fillHUD);
document.getElementById('hudMode')?.addEventListener('change', ()=>{ if(bytes) fillHUD(); });
document.getElementById('menuMode').addEventListener('change', ()=>{ if(bytes) fillMenu(); });
document.getElementById('btnSave').addEventListener('click', save);
document.getElementById('btnRevert').addEventListener('click', revert);
// Fake box buttons
document.getElementById('btnFake1Write').addEventListener('click', ()=>{ const v=(document.getElementById('fake1Hex').value||'').replace(/[^0-9A-Fa-f]/g,'').padStart(8,'0'); writeFake(1, parseInt(v,16)>>>0); });
document.getElementById('btnFake2Write').addEventListener('click', ()=>{ const v=(document.getElementById('fake2Hex').value||'').replace(/[^0-9A-Fa-f]/g,'').padStart(8,'0'); writeFake(2, parseInt(v,16)>>>0); });
document.getElementById('btnFake1Real').addEventListener('click', ()=>{ document.getElementById('fake1Hex').value = u32toHex(FAKEBOX_REAL_1); writeFake(1, FAKEBOX_REAL_1); });
document.getElementById('btnFake2Real').addEventListener('click', ()=>{ document.getElementById('fake2Hex').value = u32toHex(FAKEBOX_REAL_2); writeFake(2, FAKEBOX_REAL_2); });
// Wire up Item Behavior UI
document.addEventListener('DOMContentLoaded', populateItemBehList);
document.getElementById('btnLoadItemBeh').addEventListener('click', refreshItemBehaviorUI);
document.getElementById('itemBehItem').addEventListener('change', refreshItemBehaviorUI);
document.getElementById('itemBehSelect').addEventListener('change', ()=>{
const v = parseInt(document.getElementById('itemBehSelect').value,10)>>>0;
writeItemBehavior(v);
});
document.getElementById('btnWriteItemBeh').addEventListener('click', ()=>{
const v = parseInt(document.getElementById('itemBehSelect').value,10)>>>0;
writeItemBehavior(v);
});
document.getElementById('btnResetItemBeh').addEventListener('click', ()=>{
const item = document.getElementById('itemBehItem').value;
if (!ITEM_BEHAVIOR[item]) return;
writeItemBehavior(ITEM_BEHAVIOR[item].std>>>0);
});
// ===== Item Behavior Modifier (quick win) =====
// Offsets per region (file offsets), and the standard/default value (0..3).
const ITEM_BEHAVIOR = {
'Banana': { offs: { 'PAL':0x00395084, 'NTSC-U':0x00394A44, 'NTSC-J':0x00394864, 'NTSC-K':0x003954C4 }, std: 0x01 },
'Triple Banana': { offs: { 'PAL':0x003950A0, 'NTSC-U':0x00394A60, 'NTSC-J':0x00394880, 'NTSC-K':0x003954E0 }, std: 0x02 },
'Bob-omb': { offs: { 'PAL':0x0039519C, 'NTSC-U':0x00394B5C, 'NTSC-J':0x0039497C, 'NTSC-K':0x003955DC }, std: 0x01 },
'Fake Item Box': { offs: { 'PAL':0x003953FC, 'NTSC-U':0x00394DBC, 'NTSC-J':0x00394BDC, 'NTSC-K':0x0039583C }, std: 0x01 },
'Mushroom': { offs: { 'PAL':0x00395670, 'NTSC-U':0x00394F50, 'NTSC-J':0x00394E50, 'NTSC-K':0x00395AB0 }, std: 0x00 },
'Triple Mushroom': { offs: { 'PAL':0x0039568C, 'NTSC-U':0x00394F6C, 'NTSC-J':0x00394E6C, 'NTSC-K':0x00395ACC }, std: 0x00 },
'Golden Mushroom': { offs: { 'PAL':0x003956F8, 'NTSC-U':0x00394FA0, 'NTSC-J':0x00394ED8, 'NTSC-K':0x00395B38 }, std: 0x00 },
'Red Shell': { offs: { 'PAL':0x00395734, 'NTSC-U':0x00394FDC, 'NTSC-J':0x00394F14, 'NTSC-K':0x00395B74 }, std: 0x01 },
'Triple Red Shell': { offs: { 'PAL':0x00395750, 'NTSC-U':0x00394FF8, 'NTSC-J':0x00394F30, 'NTSC-K':0x00395B90 }, std: 0x03 },
'Blue Shell': { offs: { 'PAL':0x0039584C, 'NTSC-U':0x003950F4, 'NTSC-J':0x0039502C, 'NTSC-K':0x00395C8C }, std: 0x01 },
'Green Shell': { offs: { 'PAL':0x00395A3C, 'NTSC-U':0x003952E4, 'NTSC-J':0x0039521C, 'NTSC-K':0x00395E7C }, std: 0x01 },
'Triple Green Shell':{ offs: { 'PAL':0x00395A58, 'NTSC-U':0x00395300, 'NTSC-J':0x00395238, 'NTSC-K':0x00395E90 }, std: 0x03 },
'Star': { offs: { 'PAL':0x00395ED8, 'NTSC-U':0x00395528, 'NTSC-J':0x003956B8, 'NTSC-K':0x00396318 }, std: 0x00 },
'Lightning': { offs: { 'PAL':0x00395F88, 'NTSC-U':0x003955D8, 'NTSC-J':0x00395768, 'NTSC-K':0x003963C8 }, std: 0x00 },
'Blooper': { offs: { 'PAL':0x003955B0, 'NTSC-U':0x00396E10, 'NTSC-J':0x00394D90, 'NTSC-K':0x003959F0 }, std: 0x00 },
'Mega Mushroom': { offs: { 'PAL':0x003956C0, 'NTSC-U':0x00396ED0, 'NTSC-J':0x00394EA0, 'NTSC-K':0x00395B00 }, std: 0x00 },
'Bullet Bill': { offs: { 'PAL':0x00395628, 'NTSC-U':0x00396E88, 'NTSC-J':0x00394E08, 'NTSC-K':0x00395A68 }, std: 0x00 },
'Thunder Cloud': { offs: { 'PAL':0x00395B2C, 'NTSC-U':0x00396F0C, 'NTSC-J':0x0039530C, 'NTSC-K':0x00395F6C }, std: 0x00 },
'POW Block': { offs: { 'PAL':0x00395CBC, 'NTSC-U':0x0039709C, 'NTSC-J':0x0039549C, 'NTSC-K':0x003960FC }, std: 0x00 },
};
const BEHAVIOR_LABELS = {
0: 'Use Item', 1: 'Fire Item', 2: 'Trailing Kart', 3: 'Circling Kart'
};
function populateItemBehList(){
const sel = document.getElementById('itemBehItem');
if (!sel) return;
sel.innerHTML = '';
Object.keys(ITEM_BEHAVIOR).forEach(name=>{
const opt=document.createElement('option'); opt.value=name; opt.textContent=name; sel.appendChild(opt);
});
sel.value = sel.value || 'Banana';
}
function currentItemBehaviorOffset(){
const reg = currentRegion();
const item = document.getElementById('itemBehItem')?.value;
if (!bytes || !reg || !ITEM_BEHAVIOR[item]) return null;
const off = ITEM_BEHAVIOR[item].offs[reg];
return (typeof off === 'number') ? off : null;
}
function refreshItemBehaviorUI(){
const offSpan = document.getElementById('itemBehOff');
const curSpan = document.getElementById('itemBehCur');
const stdSpan = document.getElementById('itemBehStd');
const sel = document.getElementById('itemBehSelect');
const item = document.getElementById('itemBehItem')?.value;
const reg = currentRegion();
if (!bytes || !reg || !ITEM_BEHAVIOR[item]){
if (offSpan) offSpan.textContent='—';
if (curSpan) curSpan.textContent='—';
if (stdSpan) stdSpan.textContent='—';
return;
}
const off = ITEM_BEHAVIOR[item].offs[reg];
const std = ITEM_BEHAVIOR[item].std >>> 0;
if (offSpan) offSpan.textContent = typeof off==='number' ? hex(off,6) : '—';
if (stdSpan) stdSpan.textContent = '0x' + (std>>>0).toString(16).toUpperCase().padStart(8,'0') + ` (${std} — ${BEHAVIOR_LABELS[std]||'?'})`;
if (typeof off==='number'){
const v = view.getUint32(off, false) >>> 0;
if (curSpan) curSpan.textContent = '0x' + v.toString(16).toUpperCase().padStart(8,'0') + ` (${v} — ${BEHAVIOR_LABELS[v]||'?'})`;
if (sel) sel.value = String(Math.min(3, Math.max(0, v|0)));
} else {
if (curSpan) curSpan.textContent = '—';
}
}
function writeItemBehavior(value){
const off = currentItemBehaviorOffset();
if (off==null) return;
const v = (value>>>0) & 0xFFFFFFFF;
view.setUint32(off, v, false);
enableSave();
refreshItemBehaviorUI();
}
// ===== Engine Class Modifier =====
// Offsets per region and standard float values (from Tockdom).
const ENGINE_CLASS = {
'50cc': { offs: { 'PAL':0x003A59F4, 'NTSC-U':0x003A54B4, 'NTSC-J':0x003A51D4, 'NTSC-K':0x003A5E4C }, std: 0.8 },
'100cc / Spectate': { offs: { 'PAL':0x003A59F8, 'NTSC-U':0x003A54B8, 'NTSC-J':0x003A51D8, 'NTSC-K':0x003A5E50 }, std: 0.9 },
'150cc / Mirror / Time Trials': { offs: { 'PAL':0x003A59FC, 'NTSC-U':0x003A54BC, 'NTSC-J':0x003A51DC, 'NTSC-K':0x003A5E54 }, std: 1.0 },
'Battle': { offs: { 'PAL':0x003A5A00, 'NTSC-U':0x003A54C0, 'NTSC-J':0x003A51E0, 'NTSC-K':0x003A5E58 }, std: 0.7 },
};
function populateEngClassList(){
const sel = document.getElementById('engClassSelect');
if (!sel) return;
sel.innerHTML = '';
Object.keys(ENGINE_CLASS).forEach(name=>{
const opt=document.createElement('option'); opt.value=name; opt.textContent=name; sel.appendChild(opt);
});
if (!sel.value) sel.value = '150cc / Mirror / Time Trials';
}
function currentEngineClassOffset(){
const reg = currentRegion();
const key = document.getElementById('engClassSelect')?.value;
if (!bytes || !reg || !ENGINE_CLASS[key]) return null;
const off = ENGINE_CLASS[key].offs[reg];
return (typeof off === 'number') ? off : null;
}
function refreshEngineClassUI(){
const offSpan = document.getElementById('engOff');
const curSpan = document.getElementById('engCur');
const stdSpan = document.getElementById('engStd');
const input = document.getElementById('engValue');
const key = document.getElementById('engClassSelect')?.value;
const reg = currentRegion();
if (!bytes || !reg || !ENGINE_CLASS[key]){
if (offSpan) offSpan.textContent='—';
if (curSpan) curSpan.textContent='—';
if (stdSpan) stdSpan.textContent='—';
if (input) input.value='';
return;
}
const off = ENGINE_CLASS[key].offs[reg];
const std = ENGINE_CLASS[key].std;
if (offSpan) offSpan.textContent = typeof off==='number' ? hex(off,6) : '—';
if (stdSpan) stdSpan.textContent = `${std.toFixed(3)} (f32)`;
if (typeof off==='number'){
const f = view.getFloat32(off, false);
const u = view.getUint32(off, false)>>>0;
if (curSpan) curSpan.textContent = `${f.toFixed(3)} (0x${u.toString(16).toUpperCase().padStart(8,'0')})`;
if (input) input.value = String(f.toFixed(3));
} else {
if (curSpan) curSpan.textContent = '—';
if (input) input.value = '';
}
}
function writeEngineClass(value){
const off = currentEngineClassOffset();
if (off==null) return;
const f = Number(value);
if (!Number.isFinite(f)) return;
view.setFloat32(off, f, false); // big-endian f32
enableSave();
refreshEngineClassUI();
}
// Wire up Engine Class UI
document.addEventListener('DOMContentLoaded', populateEngClassList);
document.getElementById('btnLoadEngineClass').addEventListener('click', refreshEngineClassUI);
document.getElementById('engClassSelect').addEventListener('change', refreshEngineClassUI);
document.getElementById('engValue').addEventListener('change', ()=>{
const v = parseFloat(document.getElementById('engValue').value);
if (Number.isFinite(v)) writeEngineClass(v);
});
document.getElementById('btnWriteEngineClass').addEventListener('click', ()=>{
const v = parseFloat(document.getElementById('engValue').value);
if (Number.isFinite(v)) writeEngineClass(v);
});
document.getElementById('btnResetEngineClass').addEventListener('click', ()=>{
const key = document.getElementById('engClassSelect').value;
if (!ENGINE_CLASS[key]) return;
writeEngineClass(ENGINE_CLASS[key].std);
});
// ===== Menu Character Display Position (MCDP) =====
// Offsets per region (from Tockdom doc). At offset: x, y, scale (each f32, big-endian).
const MCDP_OFFS = { 'PAL':0x00385DC0, 'NTSC-U':0x00388728, 'NTSC-J':0x00349A90, 'NTSC-K':0x003866C8 };
const MCDP_STD = { x:-190.0, y:0.0, s:1.0 };
function mcdpOffset(){
const reg = currentRegion();
if (!bytes || !reg) return null;
const off = MCDP_OFFS[reg];
return (typeof off==='number') ? off : null;
}
function refreshMCDPUI(){
const offSpan = document.getElementById('mcdpOff');
const curSpan = document.getElementById('mcdpCur');
const xIn = document.getElementById('mcdpX');
const yIn = document.getElementById('mcdpY');
const sIn = document.getElementById('mcdpS');
const off = mcdpOffset();
if (offSpan) offSpan.textContent = (off!=null) ? hex(off,6) : '—';