-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoot_build.rtl
3311 lines (2877 loc) · 91.2 KB
/
oot_build.rtl
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
/*********************************************************************
* <z64.me> zzrtl script for extracting assets from OoT *
* audiobank(), audioseq(), audiotable(), restrictionflag(), *
* message(), entrancecutscene(), and mapselect() by Jared Johnson *
* audio-file asm hack by Zel *
*********************************************************************/
/*USE THE CONFIG.TSV FILE TO SELECT YOUR ROM*/
/* global variables are initialized before they are set based on each rom, this makes it possible to set debug/1.0 in the config file*/
char *g_tsv;
int IS_DEBUG; int ACTOR_FOLDER; int N_ROGO; int N_ROGO_DMA; int N_ROGO_SIZE; int DMA_RAM; int AUDIOBANK_PTR; int AUDIOSEQ_PTR; int AUDIOTABLE_PTR;int VANILLA;
int USE_CACHED_AUDIO; int TBL_OBJECT;int TBL_OBJECT_ENTRIES;int TBL_ACTOR;int TBL_ACTOR_ENTRIES;int TBL_PARTICLE;int TBL_PARTICLE_ENTRIES;
int TBL_SCENE;int TBL_SCENE_ENTRIES;int TBL_ROUTE;int TBL_ROUTE_ENTRIES;int TBL_MAP_SELECT_FILE;int TBL_MAP_SELECT;int TBL_MAP_SELECT_ENTRIES;
int TBL_AUDIOSAMPLE; int TBL_AUDIOBANK;int TBL_AUDIOBANK_FILE;int TBL_AUDIOBANK_SIZE;int TBL_SEQUENCEINSTRUMENTSET;int TBL_SEQUENCE_FILE;
int TBL_AUDIOSEQ;int TBL_ENTRANCECUTSCENE;int TBL_ENTRANCECUTSCENE_ENTRIES;int TBL_MESSAGE; int TBL_MESSAGE_DATA_SIZE; int TBL_MESSAGE_TOOL;
int TBL_MESSAGE_ENTRIES;int TBL_MESSAGE_DATA; int TBL_RESTRICTIONFLAG; int TBL_RESTRICTIONFLAG_ENTRIES;int TBL_DMA;int TBL_AUDIOTABLE_FILE;
int TBL_DMA_ENTRIES;int TBL_OVL_GAMESTATE;int TBL_OVL_PLAYER; int TBL_OVL_MAPMARK;int TITLECARD_W;int TITLECARD_H;int VRAM_CODE;int VROM_CODE;
int VROM_PLAYER;int DMA_ITEM_FIELD;int DMA_ITEM_LOCALIZED; int DMA_CODE;int DMA_OVL_TITLE;int DMA_OVL_SELECT;int DMA_OVL_OPENING;
int DMA_OVL_FILE_CHOOSE;int DMA_OVL_KALEIDO_SCOPE;int DMA_OVL_PLAYER_ACTOR; int DMA_OVL_MAP_MARK_DATA;int DMA_ACTOR_FIRST;int DMA_ACTOR_LAST;
int DMA_OBJECT_FIRST;int DMA_OBJECT_LAST;int DMA_G_PN_FIRST;int DMA_G_PN_LAST;int DMA_SKYBOX_FIRST;int DMA_SKYBOX_LAST;int DMA_PRERENDER_FIRST;
int DMA_PRERENDER_LAST;int DMA_SCENE_FIRST;int DMA_SCENE_LAST;int DMA_UNUSED_FIRST;int DMA_UNUSED_LAST;int DMA_SOFTSPRITE;int DMA_BLANK_FIRST;
int DMA_BLANK_LAST;int ACTID_LINK;int OFS_OVL_PLAYER_ACTOR_INIT_HI;int OFS_OVL_PLAYER_ACTOR_INIT_LO;int OFS_OVL_PLAYER_ACTOR_DEST_HI;
int OFS_OVL_PLAYER_ACTOR_DEST_LO;int OFS_OVL_PLAYER_ACTOR_MAIN_HI;int OFS_OVL_PLAYER_ACTOR_MAIN_LO;int OFS_OVL_PLAYER_ACTOR_DRAW_HI;
int OFS_OVL_PLAYER_ACTOR_DRAW_LO;int OFS_OVL_KALEIDO_SCOPE_INIT_HI;int OFS_OVL_KALEIDO_SCOPE_INIT_LO;int OFS_OVL_KALEIDO_SCOPE_DRAW_HI;
int OFS_OVL_KALEIDO_SCOPE_DRAW_LO;
/* OoT debug variables*/
void
debugvariables()
{
IS_DEBUG = 1
; TBL_OBJECT = 0x00B9E6C8 // object table
; N_ROGO = 0x01AA1000 // N_Rogo location
; N_ROGO_SIZE = 0x00002DC0 // size of N_Rogo file
; N_ROGO_DMA = 938 // n rogo dma index
; TBL_OBJECT_ENTRIES = 402 // object count
; TBL_ACTOR = 0x00B8D440 // actor overlay table
; TBL_ACTOR_ENTRIES = 471 // actor overlay count
; TBL_PARTICLE = 0x00B8CB50 // particle overlay table
; TBL_PARTICLE_ENTRIES = 37 // particle overlay count
; TBL_SCENE = 0x00BA0BB0 // scene table
; TBL_SCENE_ENTRIES = 110 // scene count
; TBL_ROUTE = 0x00B9F360 // route table
; TBL_ROUTE_ENTRIES = 1556 // route count
; TBL_MAP_SELECT_FILE = 0x00003060 // map select file
; TBL_MAP_SELECT = 0x00001430 // map select table relative to ovl_select file
; TBL_MAP_SELECT_ENTRIES = 125 // number of map select entries
; TBL_AUDIOBANK = 0x00BCC270 // audiobanktable
; TBL_AUDIOBANK_FILE = 0x00019030 // audiobank file
; TBL_AUDIOBANK_SIZE = 0x0002BDC0 // audiobank file-size
; TBL_SEQUENCEINSTRUMENTSET = 0x00BCC4E0 // instrument set table
; TBL_SEQUENCE_FILE = 0x00044DF0 // sequence file offset
; TBL_AUDIOSEQ = 0x00BCC6A0 // sequence pointer table
; TBL_AUDIOTABLE_FILE = 0x00094870 // pointer to the audiotable
; TBL_ENTRANCECUTSCENE = 0x00B95394 // entrancecutscene table
; TBL_ENTRANCECUTSCENE_ENTRIES = 34 // entrancecutscene count
; TBL_MESSAGE = 0x00BC24C0 // offset for message table
; TBL_MESSAGE_ENTRIES = 2116 // entrancecutscene count
; TBL_MESSAGE_DATA = 0x008C6000 //offset for english text
; TBL_RESTRICTIONFLAG = 0x00B9CA10 // offset for restricitonflag table
; TBL_RESTRICTIONFLAG_ENTRIES = 73 // restrictionflag count
; TBL_DMA = 0x00012F70 // dma table
; TBL_DMA_ENTRIES = 1548 // dma entries
; TBL_OVL_GAMESTATE = 0x00B969D0 // ovl_title
; TBL_OVL_PLAYER = 0x00BA4340 // ovl_kaleido_scope
; TBL_OVL_MAPMARK = 0x00B97298 // ovl_map_mark_data
; TITLECARD_W = 144 // title card dimensions
; TITLECARD_H = 24 // use 72 to include de; fr
; VRAM_CODE = 0x8001CE60 // vram start of code
; VROM_CODE = 0x00A94000 // vrom start of code
; VROM_PLAYER = 0x00C010B0 // vrom start of player_actor
; DMA_ITEM_FIELD = 9 // icon_item_field_static
; DMA_ITEM_LOCALIZED = 14 // last icon_item_x_static
; DMA_CODE = 28
; DMA_OVL_TITLE = 29
; DMA_OVL_SELECT = 30
; DMA_OVL_OPENING = 31
; DMA_OVL_FILE_CHOOSE = 32
; DMA_OVL_KALEIDO_SCOPE = 33
; DMA_OVL_PLAYER_ACTOR = 34
; DMA_OVL_MAP_MARK_DATA = 35
; DMA_ACTOR_FIRST = 36 // En_Test
; DMA_ACTOR_LAST = 497 // Shot_Sun
; DMA_OBJECT_FIRST = 498 // gameplay_keep
; DMA_OBJECT_LAST = 879 // object_zl4
; DMA_G_PN_FIRST = 880 // g_pn_01
; DMA_G_PN_LAST = 936 // g_pn_57
; DMA_SKYBOX_FIRST = 941 // vr_fine0_static
; DMA_SKYBOX_LAST = 960 // vr_holy1_pal_static
; DMA_PRERENDER_FIRST = 961 // vr_MDVR_static
; DMA_PRERENDER_LAST = 1004 // vr_FCVR_pal_static
; DMA_SCENE_FIRST = 1007 // syotes_scene
; DMA_SCENE_LAST = 1517 // test01_room_0
; DMA_UNUSED_FIRST = 1518 // bump_texture_static
; DMA_UNUSED_LAST = 1530 // anime_texture_6_static
; DMA_SOFTSPRITE = 1531 // softsprite_matrix_static
; DMA_BLANK_FIRST = 1532 // first blank dma entry
; DMA_BLANK_LAST = 1547 // last blank dma entry
; ACTID_LINK = 0 // link's actor id
// hard-coded function pointers for ovl_player_actor
; OFS_OVL_PLAYER_ACTOR_INIT_HI = 0x00B288F8 // init
; OFS_OVL_PLAYER_ACTOR_INIT_LO = 0x00B28900
; OFS_OVL_PLAYER_ACTOR_DEST_HI = 0x00B28908 // dest
; OFS_OVL_PLAYER_ACTOR_DEST_LO = 0x00B28914
; OFS_OVL_PLAYER_ACTOR_MAIN_HI = 0x00B2891C // main (update)
; OFS_OVL_PLAYER_ACTOR_MAIN_LO = 0x00B28928
; OFS_OVL_PLAYER_ACTOR_DRAW_HI = 0x00B28930 // draw
; OFS_OVL_PLAYER_ACTOR_DRAW_LO = 0x00B2893C
// hard-coded function pointers for ovl_kaleido_scope
; OFS_OVL_KALEIDO_SCOPE_INIT_HI = 0x00B33208 // init
; OFS_OVL_KALEIDO_SCOPE_INIT_LO = 0x00B3320C
; OFS_OVL_KALEIDO_SCOPE_DRAW_HI = 0x00B33218 // draw
; OFS_OVL_KALEIDO_SCOPE_DRAW_LO = 0x00B33220
; DMA_RAM = 0x80016DA0 //location of dma table in ram
; AUDIOBANK_PTR = 0x00B5A4C0 //pointer to audiobank entry
; AUDIOSEQ_PTR = 0x00B5A4AC //pointer to audioseq entry
; AUDIOTABLE_PTR = 0x00B5A4D4 //pointer to audiotable entry
;
}
/* OoT NTSC 1.0 */
void
ocarinaoftimevariables()
{
IS_DEBUG = 0
;TBL_OBJECT = 0x00B6EF58 // object table
;TBL_OBJECT_ENTRIES = 402 // object count
;TBL_ACTOR = 0x00B5E490 // actor overlay table
;TBL_ACTOR_ENTRIES = 471 // actor overlay count
;TBL_PARTICLE = 0x00B5DBA0 // particle overlay table
;TBL_PARTICLE_ENTRIES = 37 // particle overlay count
;TBL_SCENE = 0x00B71440 // scene table
;TBL_SCENE_ENTRIES = 101 // scene count
;TBL_ROUTE = 0x00B6FBF0 // route table
;TBL_ROUTE_ENTRIES = 1556 // route count
;TBL_MAP_SELECT_FILE = 0x00B9E400 // map select file
;TBL_MAP_SELECT = 0x000013D0 // map select table relative to ovl_select file
;TBL_MAP_SELECT_ENTRIES = 115 // number of map select entries
;TBL_AUDIOSAMPLE = 0x00B8A1D0 // audiosample table
;TBL_AUDIOBANK = 0x00B896A0 // audiobanktable
;TBL_AUDIOBANK_FILE = 0x0000D390 // audiobank file
;TBL_AUDIOBANK_SIZE = 0x0001CA50 // audiobank file-size
;TBL_SEQUENCEINSTRUMENTSET = 0x00B89910 // instrument set table
;TBL_SEQUENCE_FILE = 0x00029DE0 // sequence file offset
;TBL_AUDIOTABLE_FILE = 0x00079470 // pointer to the audiotable
;TBL_AUDIOSEQ = 0x00B89AD0 // sequence pointer table
;TBL_ENTRANCECUTSCENE = 0x00B65C64 // entrancecutscene table
;TBL_ENTRANCECUTSCENE_ENTRIES = 33 // entrancecutscene count
; TBL_MESSAGE = 0x00B849EC // offset for message table
; TBL_MESSAGE_ENTRIES = 2116 // entrancecutscene count
; TBL_MESSAGE_DATA = 0x0092D000 //offset for english text
; TBL_MESSAGE_DATA_SIZE = 0x00038120
;TBL_RESTRICTIONFLAG = 0x00B6D2B0 // offset for restricitonflag table
;TBL_RESTRICTIONFLAG_ENTRIES = 73 // restrictionflag count
;TBL_DMA = 0x00007430 // dma table
;TBL_DMA_ENTRIES = 1526 // dma entries
;TBL_OVL_GAMESTATE = 0x00B672A0 // game state overlay table
;TBL_OVL_PLAYER = 0x00B743E0 // pause/player ovl table
;TBL_OVL_MAPMARK = 0x00B67B58 // map_mark_data ovl table
;TITLECARD_W = 144 // title card dimensions
;TITLECARD_H = 48 // use 24 for jp only
;VRAM_CODE = 0x800110A0 // vram start of code
;VROM_CODE = 0x00A87000 // vrom start of code
;VROM_PLAYER = 0x00BCDB70 // vrom start of player_actor
;DMA_ITEM_FIELD = 10 // icon_item_field_static
;DMA_ITEM_LOCALIZED = 14 // last icon_item_x_static
;DMA_CODE = 27
;DMA_OVL_TITLE = 29
; DMA_OVL_SELECT = 30
; DMA_OVL_OPENING = 31
; DMA_OVL_FILE_CHOOSE = 32
; DMA_OVL_KALEIDO_SCOPE = 33
; DMA_OVL_PLAYER_ACTOR = 34
; DMA_OVL_MAP_MARK_DATA = 35
;DMA_ACTOR_FIRST = 36 // En_Test
;DMA_ACTOR_LAST = 497 // Shot_Sun
;DMA_OBJECT_FIRST = 498 // gameplay_keep
;DMA_OBJECT_LAST = 879 // object_zl4
;DMA_G_PN_FIRST = 880 // g_pn_01
;DMA_G_PN_LAST = 936 // g_pn_57
;DMA_SKYBOX_FIRST = 941 // vr_fine0_static
;DMA_SKYBOX_LAST = 960 // vr_holy1_pal_static
;DMA_PRERENDER_FIRST = 961 // vr_MDVR_static
;DMA_PRERENDER_LAST = 1004 // vr_FCVR_pal_static
;DMA_SCENE_FIRST = 1007 // ddan_scene
;DMA_SCENE_LAST = 1495 // ganontikasonogo_room_1
;DMA_UNUSED_FIRST = 1496 // bump_texture_static
;DMA_UNUSED_LAST = 1508 // anime_texture_6_static
;DMA_SOFTSPRITE = 1509 // softsprite_matrix_static
;DMA_BLANK_FIRST = 1510 // first blank dma entry
;DMA_BLANK_LAST = 1525 // last blank dma entry
;ACTID_LINK = 0 // link's actor id
// hard-coded function pointers for ovl_player_actor
;OFS_OVL_PLAYER_ACTOR_INIT_HI = 0x00B0D5B8 // init
;OFS_OVL_PLAYER_ACTOR_INIT_LO = 0x00B0D5C0
;OFS_OVL_PLAYER_ACTOR_DEST_HI = 0x00B0D5C8 // dest
;OFS_OVL_PLAYER_ACTOR_DEST_LO = 0x00B0D5D4
;OFS_OVL_PLAYER_ACTOR_MAIN_HI = 0x00B0D5DC // main (update)
;OFS_OVL_PLAYER_ACTOR_MAIN_LO = 0x00B0D5E8
;OFS_OVL_PLAYER_ACTOR_DRAW_HI = 0x00B0D5F0 // draw
;OFS_OVL_PLAYER_ACTOR_DRAW_LO = 0x00B0D5FC
// hard-coded function pointers for ovl_kaleido_scope
;OFS_OVL_KALEIDO_SCOPE_INIT_HI = 0x00B0FE48 // init
;OFS_OVL_KALEIDO_SCOPE_INIT_LO = 0x00B0FE50
;OFS_OVL_KALEIDO_SCOPE_DRAW_HI = 0x00B0FE58 // draw
;OFS_OVL_KALEIDO_SCOPE_DRAW_LO = 0x00B0FE64
;DMA_RAM = 0x8000B140 //dma table location in ram
;AUDIOBANK_PTR = 0x00B2E840 //audiobank entry location
;AUDIOSEQ_PTR = 0x00B2E82C //auidoseq entry
;AUDIOTABLE_PTR = 0x00B2E854 //audiotable entry
;
}
/* valid (fmt, bpp) options for png functions */
enum n64texconv_fmt
{
N64TEXCONV_RGBA = 0
, N64TEXCONV_YUV
, N64TEXCONV_CI
, N64TEXCONV_IA
, N64TEXCONV_I
};
enum n64texconv_bpp
{
N64TEXCONV_4 = 0
, N64TEXCONV_8
, N64TEXCONV_16
, N64TEXCONV_32
};
enum bool
{
false = 0
, true = 1
, compress = 1
};
/* helper function that zeroes out skipped table entries */
void
skip_test(struct rom *rom, int index, int *last, int table, int stride)
{
/* skipped one or more entries between invocations */
if (index > *last + 1)
{
/* advance to first skipped entry */
*last = *last + 1;
/* zero out skipped entries */
memset(
rom.raw(table + *last * stride)
, 0
, (index - *last) * stride
);
}
/* update last known index */
*last = index;
}
/* helper function that writes lui, addiu pair into rom; hi and lo
must be rom offsets of lui and addiu opcodes, respectively */
void
split_ptr(struct rom *rom, int ptr, int hi, int lo, int correct)
{
int v;
int tell;
/* back up rom address */
tell = rom.tell();
/* update hi part of pointer */
rom.seek(hi + 2);
v = u16(ptr >> 16);
if (correct && (u16(ptr) & 0x8000))
v++;
rom.write16(v);
/* update low part of pointer */
rom.seek(lo + 2);
rom.write16(ptr);
/* restore rom address */
rom.seek(tell);
}
/*builds a customized map select using mapselect.tsv and scene folder names*/
void
mapselect(struct rom *rom)
{
struct folder *list;
struct folder *list2;
struct conf *table;
struct conf *table2;
struct conf *nametable;
FILE *data;
int *data2;
int sz;
int pointer;
int index;
int var;
int done;
int var2;
int var3;
char *name;
int sceneid;
int spawnid;
/*allocate data*/
data = malloc(1024);
data2 = malloc(1024);
/*message user*/
printf("mapselect...");
/*enter the ovl_select folder*/
dir_enter("system");
dir_enter("ovl_select");
/*enters vanilla folder if needed*/
if (!file_exists("ovl_select.zovl"))
{dir_enter(VANILLA);}
/*load ovl file and create new file*/
data = loadfile("ovl_select - copy.bin",&sz, 0);
data2 = fopen("ovl_select.zovl","wb");
/*leaves vanilla*/
if (!dir_exists(VANILLA))
{dir_leave();}
/*leave ovl-select folder and enter the scene folder*/
dir_leave();
dir_leave();
dir_enter("scene");
/*load the mapselect and rout tables*/
if (!file_exists("mapselect.tsv"))
{dir_enter(VANILLA);}
table2 = loadfile("mapselect.tsv", 0, 0);
if (!dir_exists(VANILLA))
{dir_leave();}
if (!file_exists("route.tsv"))
{dir_enter(VANILLA);}
table = loadfile("route.tsv",0,0);
if (!dir_exists(VANILLA))
{dir_leave();}
/*creates the header for nametable and opens lists of scene folders*/
nametable = new_string("index\tname\n",0);
list2 = list2.new(0);
dir_enter(VANILLA);
list = list.new(0);
dir_leave();
/*cycles through all the scenes, writing their names to the scene folder*/
index = 0;
done = 0;
while (index < list.max() || index < list2.max())
{
/*checks the list for a matching id and get's it's name*/
if (list2.count() && list2.index() == index && done == 0)
{
name = list2.name();
if (list2.index() < list2.max())
{list2.next();}
else
{done = 1;}
}
else
{
while (list.index() < index)
{list.next();}
if (list.index() == index)
{
dir_enter(VANILLA);
name = list.name();
list.next();
}
else
{name = "0 - !Scene Missing!";}
}
nametable = new_string(nametable, "null\t", name,"\n", 0);
/* leave directory */
if (!dir_exists(VANILLA))
{dir_leave();}
index++;
/* go to next entry in list */
}
list.free();
list2.free();
/*copy the first part of the ovl-select file, which we don't change*/
var = 0;
while (var < TBL_MAP_SELECT)
{
fprintf(data2,"%c", get8(&data[var]));
var++;
}
/*copies the second part of the file, updateing the offsets the strings and entrance ids.*/
pointer = var;
if (TBL_MAP_SELECT == 0x1430)
{var3 = 0x09;}
else
{var3 = 0x51;}
while ((var - (pointer))/12 < TBL_MAP_SELECT_ENTRIES)
{
/*get the entrance id*/
sscanf(tsv_col_row(table2,"entrance index", (var - (pointer-4))/12 + 1 ), "%03X", &var2);
/*writes a map-select entry and updates entrance id and string offset*/
if (TBL_MAP_SELECT == 0x1430)
{fprintf(data2, "%c%c%c%c",0x80,0x80,0x26+var3/0x100,var3);
fprintf(data2, "%c%c%c%c",0x80,0x80,0x0B,0xAC);}
else
{fprintf(data2, "%c%c%c%c",0x80,0x80,0x23+var3/0x100,var3);
fprintf(data2, "%c%c%c%c",0x80,0x80,0x09,0xE0);}
fprintf(data2, "%c%c%c%c",0x00,0x00,var2/0x100, var2);
var3 = var3 + 0x1A;
var = var + 12;
}
//fprintf(data2, "%c", 0xFF);
pointer = var;
while (get32(&data[var]) != 0x20313A53)
{
fprintf(data2, "%c", get8(&data[var]));
var++;
}
/*setting up for writing the map entries*/
pointer = var;
var = 1;
/*writes the names of all the scenes to the data*/
while (var < TBL_MAP_SELECT_ENTRIES + 1)
{
/*finds the scene's id by cross referencing the entrance index in the routing table. also get's the spawn id*/
sscanf(tsv_col_row(table2,"entrance index", var), "%X", &var3);
sscanf(tsv_col_row(table,"scene",var3 + 1), "%X", &sceneid);
spawnid = tsv_col_row(table,"spawn",var3 + 1);
/*makes a list in the scene folder*/
if (tsv_col_row(nametable, "name", sceneid + 1))
{name = tsv_col_row(nametable, "name", sceneid + 1);}
else
{name = "!Scene Missing!";}
var2 = 0;
/*we advance through the name to get the actual name*/
while (get8(&name[var2]) != get8(" ") && var2 < 5)
{var2++;}
var2++;
if (get8(&name[var2]) == get8("-") || get8(&name[var2+1]) == get8("-") || get8(&name[var2+2]) == get8("-"))
{while (get8(&name[var2]) != get8("-"))
{var2++;}
var2++;
if (get8(&name[var2]) == get8(" "))
{var2++;}
}
/*we add the spawn id only if it is greater than 0*/
if (strcmp(spawnid, "0") && strcmp(name,"!scene missing!"))
{
strcat(name, "-");
strcat(name, spawnid);
}
var3 = 0;
/*we write the map-select number and advance the forward depending on how many characters the number is*/
fprintf(data2,"%c%d:",0x00,var);
if (var >= 100)
{var3 = var3 + 5;}
else
{
if (var >= 10)
{var3 = var3 + 4;}
else
{var3 = var3 + 3;}
}
pointer = pointer + var3;
/*now we write as much of the name as we can fit inside of 0x1A bytes*/
while (var3 < 0x1A)
{
fprintf(data2,"%c", get8(&name[var2]));
pointer++;
var3++;
var2++;
}
/*we count our advancement*/
var++;
}
/*then we copy the rest of the file copying some english text over things*/
while (pointer < sz)
{
name = "Adult Link ***Child Link ***********Night ******Day ***Cutscene00**Cutscene01**Cutscene02**Cutscene03**Cutscene04**Cutscene05**Cutscene06**Cutscene07**Cutscene08**Cutscene09**Cutscene10";
fprintf(data2, "%c", get8(&data[pointer]));
pointer++;
if (get32(&data[pointer]) == 0x8D313728)
{
var = 0;
while (var < 0xD2)
{if (get8(&name[var]) == 0x2A)
{
fprintf(data2,"%c", get8(&data[pointer]));
}
else
{
fprintf(data2,"%c", get8(&name[var]));
}
var++;
pointer++;
}
}
}
/*clean up and leave the folders*/
dir_leave();
free(table);
free(table2);
free(nametable);
fclose(data2);
free(data);
printf("success!\n");
}
void
system_overlay(struct rom *rom)
{
struct conf *conf;
struct folder *list;
char *filename;
char *ovl;
FILE *fp;
int *entry;
int *Oarr;
int *arr;
char *name;
int vram;
int vram_sz;
int ptr;
int i;
/* system overlays aligned 0x10 in retail */
rom.align(0x10);
/* overlay filenames */
filename =
"ovl_title\0" /* n64 logo animation */
"ovl_select\0" /* map select */
"ovl_opening\0" /* initialized title screen */
"ovl_file_choose\0" /* file select screen */
"ovl_kaleido_scope\0" /* pause screen */
"ovl_player_actor\0" /* link's actor */
"ovl_map_mark_data\0" /* minimap icon data */
;
/* create a list of offsets to individual overlay table entries */
entry = int_array(
7 // num elements
, TBL_OVL_GAMESTATE + 2 * 48 // ovl_title
, TBL_OVL_GAMESTATE + 1 * 48 // ovl_select
, TBL_OVL_GAMESTATE + 4 * 48 // ovl_opening
, TBL_OVL_GAMESTATE + 5 * 48 // ovl_file_choose
, TBL_OVL_PLAYER + 0 * 28 // ovl_kaleido_scope
, TBL_OVL_PLAYER + 1 * 28 // ovl_player_actor
, TBL_OVL_MAPMARK // ovl_map_mark_data
);
/* create array of offsets to hard-coded split function pointers */
Oarr = int_array(
19 // num elements
// these all contain none
, 0 // ovl_title
, 0 // ovl_select
, 0 // ovl_opening
, 0 // ovl_file_choose
, OFS_OVL_KALEIDO_SCOPE_INIT_HI // ovl_kaleido_scope
, OFS_OVL_KALEIDO_SCOPE_INIT_LO
, OFS_OVL_KALEIDO_SCOPE_DRAW_HI
, OFS_OVL_KALEIDO_SCOPE_DRAW_LO
, 0
, OFS_OVL_PLAYER_ACTOR_INIT_HI // ovl_player_actor
, OFS_OVL_PLAYER_ACTOR_INIT_LO
, OFS_OVL_PLAYER_ACTOR_DEST_HI
, OFS_OVL_PLAYER_ACTOR_DEST_LO
, OFS_OVL_PLAYER_ACTOR_MAIN_HI
, OFS_OVL_PLAYER_ACTOR_MAIN_LO
, OFS_OVL_PLAYER_ACTOR_DRAW_HI
, OFS_OVL_PLAYER_ACTOR_DRAW_LO
, 0
, 0 // ovl_map_mark_data
);
i = 0;
arr = Oarr;
while (i < 7)
{
if (!dir_exists(substring(filename, i)))
{die(new_string("Missing overlay: ", substring(filename, i),".zovl",0));}
/* enter overlay name directory */
dir_enter(substring(filename, i));
/* go to table entry (skip first word) */
rom.seek(entry[i] + 4);
/*if there is no custom overlay file we go to vanilla folder*/
if (!file_exists(new_string(substring(filename, i),".zovl",0)) && dir_exists(VANILLA))
{dir_enter(VANILLA);}
/* inject file */
ovl = rom.inject("*.zovl", compress);
if (!ovl)
{die(new_string("Missing overlay: ", substring(filename, i),".zovl",0));}
/* get overlay vram size */
vram_sz = ovl_vram_sz(ovl, rom.file_sz());
/*if there is now custom conf file we go to vanilla folder*/
if (!file_exists("conf.txt") && dir_exists(VANILLA))
{dir_enter(VANILLA);}
/* parse configuration file */
conf = conf.new("conf.txt", "list");
while (*arr)
{
/* function pointers in conf are in same order as array */
ptr = conf.get_int(0);
/* write split function pointer into rom */
split_ptr(rom, ptr, arr[0], arr[1], true);
/* advance to next item */
arr = arr + 2;
conf.next();
}
arr++; /* skip trailing 0 */
rom.write32(rom.file_start()); /* vrom start */
rom.write32(rom.file_end()); /* vrom end */
if (conf.exists("vram")) /* custom vram */
{
vram = conf.get_int("vram");
rom.write32(vram); /* vram start */
}
else
vram = rom.read32(); /* vram start */
rom.write32(vram + vram_sz); /* vram end */
/* game state overlays */
if (i < 4)
{
rom.seek_cur(4);
rom.write32(conf.get_int("init"));
rom.write32(conf.get_int("dest"));
rom.seek_cur(12);
rom.write32(conf.get_int("size"));
}
/* ovl_map_mark_data */
else if (i == 6)
rom.write32(conf.get_int("dungeon_mark_data"));
if (!dir_exists(VANILLA))
{dir_leave();}
/* advance to next */
dir_leave();
conf.free();
i++;
}
/* cleanup */
free(Oarr);
}
void
systemdir(struct rom *rom)
{
dir_enter("system");
system_overlay(rom);
dir_leave();
}
void
audiotable(struct rom *rom)
{
FILE *table;
struct folder *list;
struct folder *list2;
struct rom *buildfile;
char *data;
char *typelocation;
int sz;
int done;
int tablename;
int var;
int dataname;
int index;
int listindex;
int messagefix;
int maxsample;
typelocation = malloc(256);
/*checks if we should build with cached audio files*/
if (!USE_CACHED_AUDIO)
{
/*enter directory creating non-vanilla list and enters vanilla folder and makes a vanilla list*/
dir_enter("audio");
dir_enter("audiotable");
list2 = list2.new(0);
dir_enter(VANILLA);
list = list.new(0);
/*creates a huge file to write data to*/
rom.extract("audiotable.bin", 0x0, 0x3000000);
buildfile = buildfile.new("audiotable.bin");
/*open the audiotable for writing and write header*/
table = fopen("audiotable.tsv","wb");
fprintf(table, "start\tlength\tname\n");
/*cycle through all the samples*/
index = 0;
listindex = 0;
if (list.max() > list2.max())
{maxsample = list.max();}
else
{maxsample = list2.max();}
done = 0;
while (list.remaining() || (list2.remaining() && done == 0))
{
/*display message*/
printf("\raudiotable %d/%d: ", listindex, maxsample);
/*checks for non-vanilla samples and enters the sample folder*/
if (list2.remaining() && list2.count() && (list.remaining() == 0 || list2.index() <= list.index()) && done == 0)
{
dir_leave();
dir_enter(list2.name());
if (list2.remaining() <= 1)
{done = 1;}
}
else
{dir_enter(list.name());}
/*gets to the sample and writes the sample data to file*/
buildfile.seek(index);
if (file_exists("sample.bin"))
{data = loadfile("sample.bin",&sz, false);}
else
{data = loadfile("RawSound.bin",&sz, false);}
buildfile.write(data,sz);
/*adds the sample offsets and name to the audiotable.tsv and rounds index up to new size, double checking if it's a vanilla sample or not*/
dir_leave();
if (dir_exists(VANILLA))
{
/*writes blank samples if there is a gan samples*/
while (listindex < list2.index())
{
fprintf(table, "NULL\tNULL\tNULL\n");
listindex++;
}
fprintf(table, "%X\t%X\t%s\n", index, sz, list2.name());
list2.next();
dir_enter(VANILLA);
}
else
{fprintf(table, "%X\t%X\t%s\n", index, sz, list.name());}
/*writes blank samples in if there's a gap in sample indexes*/
index = (index + sz+15)/16*16;
if (list.remaining())
{
list.next();
while (list.remaining() && listindex + 1 < list.index())
{
fprintf(table, "NULL\tNULL\tNULL\n");
listindex++;
}
}
listindex ++;
}
/*extracts the buildfile for injecting later in audiodma*/
buildfile.extract("audiotable.bin", 0, index);
buildfile.free();
/*leave the directory*/
fclose(table);
dir_leave();
dir_leave();
dir_leave();
printf("success!\n");
}
}
void
dopredictors(struct rom *buildfile, int *predictordata, int *looppredictordata,int *predictornumber,int *looppredictornumber, bankpointer)
{
FILE *fp;
int *dat1;
int *dat2;
int *dat3;
int var;
int index;
int pointer;
int startpointer;
int offset1;
int offset2;
int sz;
int *name;
int testvar;
int sz2;
int test1;
int test2;
int test3;
/*allocate data for name and store a pointer to return to for writing*/
name = malloc(256);
startpointer = buildfile.tell();
/*load sample config file and write the precision*/
dat3 = loadfile("config.tsv",0,0);
buildfile.seek_cur(-8);
sscanf(tsv_col_row(dat3, "precision", 1), "%X", &var);
buildfile.write8(var);
/*loads the predictors*/
if (file_exists("predictors.bin"))
{dat1 = loadfile("predictors.bin", &sz, 0);}
else
{dat1 = loadfile("Predictors.bin", &sz, 0);}
/*sets up to compare predictor to other predictors already in the bank*/
pointer = 1;
test1 = 0;
index = 0;
/*loops through the predictors stored in the bank to if there is a match*/
while (index < *predictornumber && test1 == 0)
{
sscanf(tsv_col_row(*predictordata, "offset", pointer),"%X", &offset1);
buildfile.seek(bankpointer + offset1);
pointer = pointer + 1;
test1 = 1;
var = 0;
while (var < sz/4 && test1 == 1)
{
if (buildfile.read32() != get32(&dat1[var]))
{
test1 = 0;
}
var = var + 1;
}
index ++;
}
/*checks if there are looppredictors*/
if (file_exists("looppredictors.bin") || file_exists("LoopPredictors.bin"))
{
/*loads the loop predictors file*/
if (file_exists("looppredictors.bin"))
{dat2 = loadfile("looppredictors.bin", &sz2, 0);}
else
{dat2 = loadfile("LoopPredictors.bin", &sz2, 0);}
/*sets up the test for if there are identical looppredictors*/
pointer = 1;
test3 = 0;
index =0;
/*check if the data is all 0s like n64soundtool will export*/
while (test3 ==0 && index < sz2)
{
if (get8(&dat2[index]) != 0x00)
{test3 = 1;}
index++;
}
/*if it's not 0s it compares to other looppredictors*/
if (test3 == 1)
{
test2 = 0;
index = 0;
/*loops through the looppredictors stored in the bank to if there is a match*/
while (index < *looppredictornumber && test2 == 0)
{
sscanf(tsv_col_row(*looppredictordata, "offset", pointer),"%X", &offset2);
buildfile.seek(bankpointer + offset2);
pointer = pointer + 1;
test2 = 1;
var = 0;
while (var < sz2 && test2 == 1)
{
if (buildfile.read8() != get8(&dat2[var]))
{
test2 = 0;
}
var = var + 4;
}
index ++;
}
}
}
/*returns to the starting pointer and writes gets offsets depending on the test above*/
buildfile.seek(startpointer);
if (test1 == 0)
{
offset1 = buildfile.tell() - bankpointer + 8;
}
if (test2 == 0)
{
offset2 = buildfile.tell() - bankpointer + 8;
if (test1 == 0)
{
offset2 = offset2 + (sz+15)/16*16;
}
}
/*writes the offsets*/
buildfile.write32(offset2);
buildfile.write32(offset1);
/*if it's a new predictor we write the predictor data and adds it to the bank's list of predictors for comparing*/
if (test1 == 0)
{
sprintf(name, "%X", buildfile.tell()-bankpointer);
*predictordata = new_string(*predictordata, name, "\t","what","\n", 0);
*predictornumber = *predictornumber + 1;
buildfile.write(dat1, sz);
while(sz < (sz+15)/16*16)
{
buildfile.write8(0);
sz++;
}
}
/*writes the loop details*/
sscanf(tsv_col_row(dat3, "loopstart", 1), "%X", &var);
buildfile.write32(var);
sscanf(tsv_col_row(dat3, "loopend ", 1), "%X", &var);
buildfile.write32(var);
sscanf(tsv_col_row(dat3, "loopcount", 1), "%X", &var);
buildfile.write32(var);
sscanf(tsv_col_row(dat3, "looptail ", 1), "%X", &var);
buildfile.write32(var);
/*checks if there are looppredictors*/
if (file_exists("looppredictors.bin") || file_exists("LoopPredictors.bin") && (test2 == 0 && test3 != 0))
{
sprintf(name, "%X", buildfile.tell()-bankpointer);
*looppredictordata = new_string(*looppredictordata, name, "\t","what","\n", 0);
*looppredictornumber = *looppredictornumber + 1;
buildfile.write(dat2, sz2);
free(dat2);
}
free(dat1);