-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoot_dump.rtl
2126 lines (1834 loc) · 59.6 KB
/
oot_dump.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 *
*********************************************************************/
/*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 VROM_CODE_SIZE; int N_ROGO; int N_ROGO_DMA; int N_ROGO_SIZE;int VANILLA;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;int TBL_MAP_SELECT_ENTRIES;int TBL_AUDIOSAMPLE;int TBL_AUDIOTABLE_FILE;int TBL_AUDIOTABLE_FILE_SIZE;
int TBL_AUDIOBANK;int TBL_AUDIOBANK_FILE;int TBL_SEQUENCEINSTRUMENTSET;int TBL_SEQUENCE_FILE;int TBL_AUDIOSEQ;int TBL_ENTRANCECUTSCENE;
int TBL_ENTRANCECUTSCENE_ENTRIES;int TBL_MESSAGE; int TBL_MESSAGE_ENTRIES;int TBL_MESSAGE_DATA;int TBL_MESSAGE_DATA_SIZE; int TBL_RESTRICTIONFLAG;
int TBL_RESTRICTIONFLAG_ENTRIES;int TBL_DMA;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 */
void
debugvariables()
{
IS_DEBUG = 1 //a friendly way to check if we are in debug
;TBL_OBJECT = 0x00B9E6C8 // object table
; N_ROGO = 0x01AA1000 //0938
; N_ROGO_SIZE = 0x00002DC0
; N_ROGO_DMA = 938
; 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 = 0x00001430 // map select table relative to ovl_select file
; TBL_MAP_SELECT_ENTRIES = 125 // number of map select entries
; TBL_AUDIOSAMPLE = 0x00BCCDA0 //audiosample table
; TBL_AUDIOTABLE_FILE = 0x00094870
; TBL_AUDIOTABLE_FILE_SIZE = 0x00451390
; TBL_AUDIOBANK = 0x00BCC270 //audiobanktable
; TBL_AUDIOBANK_FILE = 0x00019030 //audiobank file
; TBL_SEQUENCEINSTRUMENTSET = 0x00BCC4E0 // instrument set table
; TBL_SEQUENCE_FILE = 0x00044DF0 // sequence file offset
; TBL_AUDIOSEQ = 0x00BCC6A0 // sequence pointer table
; 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_CODE_SIZE = 0x0013AF30
; 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
;
}
void
ocarinaoftimevariables()
{
IS_DEBUG = 0 //a friendly way to check for 1.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 = 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_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_CODE_SIZE = 0x00103D30
; 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;
}
/* 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 writes lui, addiu pair into rom; hi and lo
must be rom offsets of lui and addiu opcodes, respectively */
int
join_ptr(struct rom *rom, int hi, int lo, int correct)
{
int v;
int tell;
/* back up rom address */
tell = rom.tell();
/* retrieve hi part of pointer */
rom.seek(hi + 2);
hi = rom.read16();
/* retrieve low part of pointer */
rom.seek(lo + 2);
lo = rom.read16();
/* value correction */
if (correct && (u16(lo) & 0x8000))
hi--;
/* restore rom address */
rom.seek(tell);
return (hi << 16) | lo;
}
void
system_overlay(struct rom *rom)
{
struct conf *conf;
char *funcname;
char *filename;
char *outname;
char *name;
FILE *fp;
FILE *fp2;
int var;
int *entry;
int *Oarr;
int *arr;
int func;
int vram;
int start;
int end;
int ptr;
int i;
//dir_enter("overlay");
/* allocate buffer */
outname = malloc(64);
/* 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 */
;
funcname =
"init\0"
"dest\0"
"main\0"
"draw\0"
;
/* 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)
{
/* enter overlay name directory */
name = substring(filename, i);
dir_enter(name);
dir_enter(VANILLA);
/* go to table entry (skip first word) */
rom.seek(entry[i] + 4);
/* open configuration file */
fp = fopen("conf.txt", "wb");
/* create out file name with extension */
sprintf(outname, "%s.zovl", name);
/* parse table entry */
start = rom.read32(); /* vrom start */
end = rom.read32(); /* vrom end */
vram = rom.read32(); /* vram start */
rom.read32(); /* vram end */
/* write configuration file */
func = 0;
while (*arr)
{
/* get name */
name = substring(funcname, func);
/* hard-coded fix so ovl_kaleido_scope has "draw" */
if (i == 4 && func == 1)
name = "draw";
/* combine split function pointer, write into config file */
ptr = join_ptr(rom, arr[0], arr[1], true);
fprintf(fp, "%s 0x%08X\n", name, ptr);
/* advance to next function */
arr = arr + 2;
func++;
}
arr++; /* skip trailing 0 */
/* game state overlays */
if (i < 4)
{
rom.seek_cur(4);
fprintf(fp, "init 0x%08X\n", rom.read32());
fprintf(fp, "dest 0x%08X\n", rom.read32());
rom.seek_cur(12);
fprintf(fp, "size 0x%08X\n", rom.read32());
}
/* ovl_map_mark_data */
else if (i == 6)
fprintf(fp, "dungeon_mark_data 0x%08X\n", rom.read32());
/* vram */
fprintf(fp, "vram 0x%08X\n", vram);
/* extract file */
rom.extract(outname, start, end);
/*build mapselect table*/
if (!strcmp(name, "ovl_select"))
{
rom.extract("ovl_select - copy.bin", start, end);
dir_leave();
dir_leave();
dir_leave();
dir_enter("scene");
dir_enter(VANILLA);
/*open map select table and write header*/
fp2 = fopen("mapselect.tsv","wb");
fprintf(fp2,"index\tentrance index\n");
/*find the table entries in the rom and write them to the table*/
rom.seek(start + TBL_MAP_SELECT+10);
var = 0;
while (var < TBL_MAP_SELECT_ENTRIES)
{
fprintf(fp2, "%d\t%X\n", var+1, rom.read16());
rom.seek_cur(10);
var++;
}
/*close table file*/
fclose(fp2);
dir_leave();
dir_leave();
dir_enter("system");
dir_enter("ovl_select");
dir_enter(VANILLA);
}
/* advance to next */
dir_leave();
dir_leave();
fclose(fp);
i++;
}
/* cleanup */
free(outname);
free(Oarr);
}
void
systemdir(struct rom *rom)
{
dir_enter("system");
system_overlay(rom);
dir_leave();
}
void
audiotable(struct rom *rom)
{
FILE *fp;
FILE *data;
FILE *data2;
FILE *table;
struct folder *list;
struct folder *list2;
int maxlist;
int index;
int index2;
int var;
int var2;
int name;
int name2;
int sz;
int sz2;
/*allocate name memory (may not be necessary)*/
name = malloc(256);
name2 = malloc(256);
/*open directory*/
dir_enter("audio");
dir_enter("audiotable");
dir_enter(VANILLA);
/*open audiosample-table for writing and enter delete me folder*/
table = fopen("audiotable.tsv", "wb");
dir_enter("_deleteme");
/*print the start of the sample-table file*/
fprintf(table, "start\tlength\tname\n");
/*start a list of the files and dump them into indexes*/
list = list.new(".bin");
index = 0;
maxlist = list.remaining();
while (list.remaining())
{
/*display message in console*/
printf("\raudiotable...%d/%d: ", maxlist-list.remaining(), maxlist-1);
/*open the sample and predictors*/
data = loadfile(list.name(),&sz, 0);
sprintf(name, "_%s", list.name());
data2 = loadfile(name,&sz2, 0);
/*fix the name for writing*/
sscanf(list.name(), "%d- %s", &var, name);
sprintf(name2, "%d-%s",index, name);
/*add sample offset, length, and name to sampletable*/
fprintf(table, "%X\t%X\t%s\n", list.index(), sz,name2);
/*leave deleteme and create a folder for the sample*/
dir_leave();
dir_enter(name2);
/*extract the binary for the sample*/
rom.extract("RawSound.bin", TBL_AUDIOTABLE_FILE + list.index(), TBL_AUDIOTABLE_FILE + list.index()+sz);
/*open the predictors file for writing*/
fp = fopen("Predictors.bin", "wb");
/*extract the predictors by looking for the loop-predictors or end of file(skips first byte which is precision)*/
var = 1;
while ((var < sz2 -16 && get32(&data2[var+ 8]) != 0xFFFFFFFF) || var < 18)
{
fprintf(fp, "%c", get8(&data2[var]));
var ++;
}
fclose(fp);
/*write the loop-info as well as precision from first byte*/
fp = fopen("config.tsv", "wb");
fprintf(fp, "precision\tloopstart\tloopend \tloopcount\tlooptail \n");
fprintf(fp, "%08X\t%08X\t%08X\t%08X\t", get8(&data2[0]),get32(&data2[var]), get32(&data2[var+4]), get32(&data2[var+8]));
fprintf(fp,"%08X\n",get32(&data2[var+12]));
fclose(fp);
/*if there is a loop write the loop-predictors*/
if (get32(&data2[var+ 8]) == 0xFFFFFFFF)
{
fp = fopen("LoopPredictors.bin","wb");
var = var + 16;
while (var < sz2)
{
fprintf(fp, "%c", get8(&data2[var]));
var++;
}
fclose(fp);
}
/*advance the index, free data, and go back to deletemefolder for next sample data*/
list.next();
index ++;
free(data);
free(data2);
dir_leave();
dir_enter("_deleteme");
}
/*leave deleteme and close the audiotable.tsv for writing and open it for reading*/
dir_leave();
list.free();
fclose(table);
table = loadfile("audiotable.tsv", 0, 0);
printf("success!\n");
/*now we are going to fix the audiobanks to have the correct index*/
/*exit the directory and enter the banks*/
dir_leave();
dir_leave();
dir_enter("banks");
dir_enter(VANILLA);
/*loops through all the banks*/
list = list.new(0);
maxlist = list.remaining();
while (list.remaining())
{
/*print message*/
printf("\rfixing audiobank...%d/%d: ", maxlist-list.remaining(), maxlist-1);
/*enter the specific bank's folder*/
dir_enter(list.name());
/*loop through all the instrument files in the bank*/
list2 = list2.new(".tsv");
while (list2.remaining())
{
/*opens the instrument file for reading and later for writing over*/
data = loadfile(list2.name(),&sz,0);
//sprintf(name, "_%s", list2.name());
fp = fopen(list2.name(), "wb");
/*copies the first part of the instrument*/
name2 = tsv_col_row(data,"dcy1rt",2);
var = 0;
while (var < sz && get32(name2) != get32(&data[var]))
{
fprintf(fp, "%c", get8(&data[var]));
var++;
}
/*checks if sample one is full and then finds the sample index, else writes NULL*/
if (strcmp(name2, "NULL"))
{
/*compares the sample offset from file to audiotable.tsv*/
sscanf(name2, "%X", &var2);
name = tsv_col_row(table, "start", 1);
sscanf(name, "%X", &var);
index =0;
while (var < var2)
{
index++;
name = tsv_col_row(table, "start", index + 1);
sscanf(name, "%X", &var);
}
/*writes the new sample index to the instrument file*/
sprintf(name, "%d", index);
sprintf(name, "%s", name);
fprintf(fp, "%s\t%s\t", name, tsv_col_row(data,"dcy1lvl",2));
}
else
{
fprintf(fp, "NULL\tNULLNULL\t");
}
/*checks if sample two is full and then finds the sample index, else writes NULL*/
name2 = tsv_col_row(data,"dcy2rt",2);
if (strcmp(name2, "NULL"))
{
/*compares the sample offset from file to audiotable.tsv*/
sscanf(name2, "%X", &var2);
name = tsv_col_row(table, "start", 1);
sscanf(name, "%X", &var);
index =0;
while (var < var2)
{
index++;
name = tsv_col_row(table, "start", index + 1);
sscanf(name, "%X", &var);
}
/*writes the new sample index to the instrument file*/
sprintf(name, "%d", index);
sprintf(name, "%s", name);
fprintf(fp, "%s\t%s\t", name, tsv_col_row(data,"dcy2lvl",2));
}
else
{
fprintf(fp, "NULL\tNULLNULL\t");
}
/*checks if there is sample three and then finds the sample index, else writes NULL*/
name2 = tsv_col_row(data,"split1",3);
if (strcmp(name2, "NULL"))
{
/*compares the sample offset from file to audiotable.tsv*/
sscanf(name2, "%X", &var2);
name = tsv_col_row(table, "start", 1);
sscanf(name, "%X", &var);
index =0;
while (var < var2)
{
index++;
name = tsv_col_row(table, "start", index + 1);
sscanf(name, "%X", &var);
}
/*writes the new sample index to the instrument file*/
sprintf(name, "%d", index);
sprintf(name, "%s", name);
fprintf(fp, "%s\t%s", name, tsv_col_row(data,"split2",3));
}
else
{
fprintf(fp, "NULL\tNULLNULL\t");
}
/*advances to next instrument and frees the data*/
list2.next();
free(data);
fclose(fp);
}
/*checks if there's drums to update*/
if (file_exists("_drums.tsv"))
{
/*opens the drum file for reading and editing*/
data = loadfile("_drums.tsv",&sz,0);
fp = fopen("_drums.tsv", "wb");
/*copies the beginning of the drum file */
name2 = tsv_col_row(data,"atkrate",3);
var = 0;
while (var < sz && get32(name2) != get32(&data[var]))
{
fprintf(fp, "%c", get8(&data[var]));
var++;
}
/*updates each sample's index in the drum file*/
index2 = 0;
while (tsv_col_row(data,"atkrate",index2 + 4) || tsv_col_row(data,"atklvl",index2 + 4))
{
/*compares the sample offset from file to audiotable.tsv*/
name2 = tsv_col_row(data,"atkrate",index2 + 3);
sscanf(name2, "%X", &var2);
name = tsv_col_row(table, "start", 1);
sscanf(name, "%X", &var);
index =0;
while (var < var2)
{
index ++;
name = tsv_col_row(table, "start", index + 1);
sscanf(name, "%X", &var);
}
/*writes the new sample index to the instrument file*/
sprintf(name, "%d", index);
sprintf(name, "%s", name);
fprintf(fp, "%s\t%s\t%s\t\t\t\n", name, tsv_col_row(data,"atklvl",index2 + 3),tsv_col_row(data,"dcy1rt",index2 + 3));
index2 ++;
}
free(data);
fclose(fp);
}
/*checks if there are sound effects*/
if (file_exists("_soundeffects.tsv"))
{
/*opens the soundeffect file for reading and writing*/
data = loadfile("_soundeffects.tsv",&sz,0);
fp = fopen("_soundeffects.tsv", "wb");
/*copies the beginning of the sfx file */
name2 = tsv_col_row(data,"sample",1);
var = 0;
while (var < sz && get32(name2) != get32(&data[var]))
{
fprintf(fp, "%c", get8(&data[var]));
var++;
}
/*updates each sample's index in the sfx file*/
index2 = 0;
while (tsv_col_row(data,"sample",index2 + 2) || tsv_col_row(data,"pitch",index2 + 2))
{
/*compares the sample offset from file to audiotable.tsv*/
name2 = tsv_col_row(data,"sample",index2 + 1);
sscanf(name2, "%X", &var2);
name = tsv_col_row(table, "start", 1);
sscanf(name, "%X", &var);
index =0;
while (var < var2)
{
index++;
name = tsv_col_row(table, "start", index + 1);
sscanf(name, "%X", &var);
}
/*writes the new sample index to the instrument file*/
sprintf(name, "%d", index);
sprintf(name, "%s", name);
fprintf(fp, "%s\t%s\n", name, tsv_col_row(data,"pitch",index2 + 1));
index2 ++;
}
free(data);
fclose(fp);
}
/*leave the bank and advance to next bank*/
dir_leave();
list.next();
}
/*linebreak for messaging and leaves to the root folder*/
printf("success!\n");
dir_leave();
dir_leave();
dir_leave();
}
void
dumppredictors(struct rom *rom, int file, int bankpointer)
{
int start;
int size;
int var;
/*stores offset to return to after function*/
start = rom.tell();
/*gets the precision unk for the sample and tosses that in with predicotrs ;)*/
rom.seek_cur(-8);
fprintf(file, "%c", rom.read8());
/*gets the predictor offset*/
rom.seek_cur(11);
var = rom.read32();
/*goes to predicotr data and finds size*/
rom.seek(TBL_AUDIOBANK_FILE + bankpointer + var);
rom.seek_cur(4);
size = rom.read32()*32 + 8;
/*returns to start and copies all the predictor data*/
rom.seek_cur(-8);
var = 0;
while (var < size)
{
fprintf(file,"%c", rom.read8());
var++;
}
/*gets offset for loop-info and goes there*/
rom.seek(start);
var = rom.read32();
rom.seek(TBL_AUDIOBANK_FILE + bankpointer + var);
/*checks if there are looppredictors by seeing if the loop info is 0'd*/
size = 32;
var = rom.read32();
rom.seek_cur(4);
var = var + rom.read32() + rom.read32();
if (var == 0)
{
size = 16;
}
else
{
size = 48;
}
/*copies the loop info and maybe the loop predictors*/
rom.seek_cur(-16);
var = 0;
while (var < size)
{
fprintf(file,"%c", rom.read8());
var++;
}
/*return to starting position*/
rom.seek(start);
}
void
dosample(struct rom *rom, sample, samplelength, *samplelist, *samplenum, name2, bankpointer)
{
FILE *datafile;
int var;
int samplename;
/*check if sample already has been dumped*/
//printf("\nweherenow\n");
samplename = malloc(256);
sprintf(samplename, "%X", sample);
var = 0;
//printf("\n%s - %s\n", samplename, strcmp(tsv_col_row(*samplelist, "sample", var+1)));
while (var < *samplenum && strcmp(tsv_col_row(*samplelist, "sample", var+1), samplename))
{
var++;
}
/*if there's no similar sample, dump the sample and predicotrs and add to the list*/
if (var == *samplenum)
{
*samplenum = *samplenum + 1;
*samplelist = new_string(*samplelist,samplename,"\t",0);
sprintf(samplename, "%X", samplelength);
*samplelist = new_string(*samplelist,samplename,"\t",name2,"\n",0);
sprintf(samplename, "_%d- %s -%d.bin",sample,name2,sample+samplelength);
datafile = fopen(samplename, "wb");
dumppredictors(rom, datafile, bankpointer);
fclose(datafile);
sprintf(samplename,"%d- %s -%d.bin",sample,name2,sample+samplelength);
rom.extract(samplename, TBL_AUDIOTABLE_FILE + sample, TBL_AUDIOTABLE_FILE + sample + samplelength);
}
}
void
audiobank(struct rom *rom)
{
FILE *configfile;
FILE *datafile;
int *samplelist;
int samplenum;
int numberofbanks;
int index;
int instrumentindex;
int bankpointer;
int instrumentnumber;
int sampletablenumber;
int sampleoffset;
int sample;
int samplename;
int samplelength;
int drums;
int sfx;
int nameindex;
int nameindex2;
int oldsample;
int instrumentpointer;
int name;
int name2;
int name3;
int var;
int var2;
int sfxnum;
int length;
int pitch1;
int pitch2;
int pitch3;
int dataptr1;
int dataptr2;
int dataptr3;
/*allocate memory for name*/
name = malloc(256);
name2 = malloc(256);
name3 = malloc(256);
samplename = malloc(256);
/*enter audio folder*/
dir_enter("audio");
dir_enter("banks");
dir_enter(VANILLA);
/*find and read the number of audiobanks and create the header for the samplelist*/
rom.seek(TBL_AUDIOBANK);
numberofbanks = rom.read16();
samplelist = new_string("sample\tlength\tname\n",0);
samplenum = 0;
/*dump all the audiobanks until index is at the last bank*/
index = 0;
nameindex =0;
oldsample = -1;
nameindex2 =0;
while (index < numberofbanks - 1)
{
/*display progress*/
printf("\raudiobank %d/%d: ", index, numberofbanks-2);
/*seek to table entry to read bank info*/
rom.seek(TBL_AUDIOBANK + 16 + index*16);
bankpointer = rom.read32();
length = rom.read32();
rom.seek_cur(2);
sampletablenumber = rom.read8();
rom.seek_cur(1);
instrumentnumber = rom.read8();
drums = rom.read8();
sfxnum = rom.read16();
/*sets sample offset for the bank, used later when writing sample pointers.*/
rom.seek(TBL_AUDIOSAMPLE + sampletablenumber*16);
sampleoffset = rom.read32();
/*open the bank folder*/
if (g_tsv)
{
sscanf(tsv_col_row(g_tsv,"audiobank",index + 1), "%s", name2);
sprintf(name,"%d-%s-%X",index,name2,index);
}
else
{name2 = "sample";
sprintf(name,"%d",index);}
dir_enter(name);
/*extracts vanilla data. this is mainly useful for debugging issues in the audio-system*/
rom.extract("_vanilla.bin", TBL_AUDIOBANK_FILE + bankpointer, TBL_AUDIOBANK_FILE + bankpointer + length);
/*checks if there's drums and sfx*/
rom.seek(TBL_AUDIOBANK_FILE + bankpointer);
drums = rom.read32();
sfx = rom.read32();
/*read each instrument and create files and config table*/
instrumentindex = 0;
while (instrumentindex < instrumentnumber)
{
/*find the location of instruments description in the bank*/
rom.seek(TBL_AUDIOBANK_FILE + bankpointer + 8 + instrumentindex*4);
instrumentpointer = rom.read32();
/*if instrument isn't blank*/
if (instrumentpointer > 0)
{
/*advances the naming scheme forward, skipping one instrument in 1.0*/
nameindex++;
if (TBL_AUDIOBANK_FILE != 0x00019030 && nameindex == 57)
{
nameindex++;