-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoot_dump.rtl
More file actions
841 lines (714 loc) · 22 KB
/
oot_dump.rtl
File metadata and controls
841 lines (714 loc) · 22 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
/********************************************************
* <z64.me> zzrtl script for extracting assets from OoT *
********************************************************/
/* global variables */
char *g_tsv;
/* how to use */
/* uncomment the enum associated with the OoT version you *
* are targeting, and comment out or delete the others */
/* OoT debug */
enum {
TBL_OBJECT = 0x00B9E6C8 // object table
, 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_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
, DMA_OVL_SELECT
, DMA_OVL_OPENING
, DMA_OVL_FILE_CHOOSE
, DMA_OVL_KALEIDO_SCOPE
, DMA_OVL_PLAYER_ACTOR
, DMA_OVL_MAP_MARK_DATA
, 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
};
/* OoT NTSC 1.0
enum {
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_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
, DMA_OVL_OPENING
, DMA_OVL_FILE_CHOOSE
, DMA_OVL_KALEIDO_SCOPE
, DMA_OVL_PLAYER_ACTOR
, DMA_OVL_MAP_MARK_DATA
, 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;
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);
/* 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);
/* advance to next */
dir_leave();
fclose(fp);
i++;
}
/* cleanup */
free(outname);
free(Oarr);
dir_leave();
}
void
systemdir(struct rom *rom)
{
dir_enter("system");
system_overlay(rom);
dir_leave();
}
void
route(struct rom *rom)
{
FILE *fp;
char *music;
char *card;
int fadeout;
int fadein;
int index;
int scene;
int spawn;
int var;
int sep;
/* separator whitespace */
sep = 8;
/* open route.txt for writing */
fp = fopen("route.txt", "wb");
/* print table header */
fprintf(fp, "%-*s", sep, "index");
fprintf(fp, "%-*s", sep, "scene");
fprintf(fp, "%-*s", sep, "spawn");
fprintf(fp, "%-*s", sep, "music");
fprintf(fp, "%-*s", sep, "title");
fprintf(fp, "%-*s", sep, "fadein");
fprintf(fp, "%-*s", sep, "fadeout");
fprintf(fp, "\n");
index = 0;
while (index < TBL_ROUTE_ENTRIES)
{
/* go to table entry */
rom.seek(TBL_ROUTE + index * 4);
/* parse table entry */
scene = rom.read8();
spawn = rom.read8();
var = rom.read16();
/* unpack var */
music = (var & 0x8000) ? "go" : "stop";
card = (var & 0x4000) ? "on" : "off" ;
fadein = (var & 0x3F80) >> 7;
fadeout = (var & 0x007F);
/* print table entry */
fprintf(fp, "0x%04X", index);
fprintf(fp, "%*d", sep, scene);
fprintf(fp, "%*d", sep, spawn);
fprintf(fp, "%*s", sep, music);
fprintf(fp, "%*s", sep, card);
fprintf(fp, "%*d", sep, fadein);
fprintf(fp, "%*d", sep, fadeout);
fprintf(fp, "\n");
/* advance to next entry */
index++;
}
fclose(fp);
}
void
scene(struct rom *rom)
{
FILE *fp;
char *b;
char *b_end;
char *room_name;
void *title_buf;
char room_count;
int index;
int start;
int end;
int scard;
int ecard;
int rinit;
int unk_a;
int unk_b;
int sz;
/* allocate room name */
room_name = malloc(16);
/* allocate reusable title card memory */
title_buf = malloc(TITLECARD_W * TITLECARD_H * 4);
/* enter and parse folder */
dir_enter("scene");
/* repeats for every item in the list */
index = 0;
while (index < TBL_SCENE_ENTRIES)
{
/* display progress */
printf("\r""scene %d/%d: ", index, TBL_SCENE_ENTRIES - 1);
/* create and enter directory */
dir_enter(
dir_mkname(
index
, tsv_col_row(g_tsv, "scene", index + 1)
)
);
/* go to table entry */
rom.seek(TBL_SCENE + index * 20);
/* parse table entry */
start = rom.read32(); /* vrom start */
end = rom.read32(); /* vrom end */
scard = rom.read32(); /* title card start */
ecard = rom.read32(); /* title card end */
unk_a = rom.read8(); /* unknown */
rinit = rom.read8(); /* render init func id */
unk_b = rom.read8(); /* unknown */
/* used entries have non-zero start */
if (start)
{
/* extract file */
rom.extract("scene.zscene", start, end);
sz = end - start;
/* grab raw scene data */
b = rom.raw(start);
b_end = b + sz;
/* search scene header for room command (0x04) */
while (b < b_end && *b != 0x04)
{
/* end loop conditions */
if (
*b == 0x14 /* end command */
|| u8(*b) >= 0x20 /* invalid command */
)
b = b_end;
/* advance to next header command */
b = b + 8;
}
/* failed to locate room command, or it is invalid */
if (
b >= b_end /* no room command found */
|| b[1] <= 0 /* invalid room count */
|| get16(b+2) /* bytes 2, 3 aren't 0 */
|| b[4] != 0x02 /* invalid ram segment */
|| (b[7] & 3) /* unaligned pointer */
|| get24(b+5) + b[1]*8 > sz /* pointer exceeds file */
)
die("invalid scene (%08X - %08X)", start, end);
/* grab room list pointed to by 0x04 command */
room_count = b[1];
b = rom.raw(start + get24(b+5)) + room_count * 8;
/* extract each room */
while (room_count)
{
/* decrement */
room_count--;
b = b - 8;
/* extract file */
sprintf(room_name, "room_%d.zmap", room_count);
rom.extract(room_name, get32(b), get32(b+4));
}
}
/* if title card is used, its start will be non-zero */
if (scard)
{
/* extract title.png */
rom.extract_png(
"title.png"
, title_buf
, scard
, 0
, TITLECARD_W
, TITLECARD_H
, N64TEXCONV_IA
, N64TEXCONV_8
);
}
/* write table settings to conf.txt */
fp = fopen("conf.txt", "wb");
fprintf(fp, "unk_a %d\n", unk_a);
fprintf(fp, "unk_b %d\n", unk_b);
fprintf(fp, "shader %d\n", rinit);
fclose(fp);
/* leave directory */
dir_leave();
/* advance to next entry */
index++;
}
/* cleanup */
dir_leave();
free(room_name);
free(title_buf);
printf("success!\n");
}
void
particle(struct rom *rom)
{
FILE *fp;
int index;
int start;
int end;
int vram;
int ivar;
int unk;
/* enter and parse folder */
dir_enter("particle");
/* repeats for every item in the list */
index = 0;
while (index < TBL_PARTICLE_ENTRIES)
{
/* display progress */
printf("\r""particle %d/%d: ", index, TBL_PARTICLE_ENTRIES - 1);
/* create and enter directory */
dir_enter(
dir_mkname(
index
, tsv_col_row(g_tsv, "particle", index + 1)
)
);
/* go to table entry */
rom.seek(TBL_PARTICLE + index * 28);
/* parse table entry */
start = rom.read32(); /* vrom start */
end = rom.read32(); /* vrom end */
vram = rom.read32(); /* vram start */
rom.read32(); /* vram end */
rom.read32(); /* ram address */
ivar = rom.read32(); /* init vars */
unk = rom.read32(); /* unknown */
/* used entries have non-zero start */
if (start)
{
/* go to rom offset of this particle overlay's init vars */
rom.seek(start + (ivar - vram));
/* handle "tuna" */
/* NOTE: this is used for easy auto-detection in the build *
* script; if you have a different preferred method *
* of managing the initialization variables, you're *
* free to change the scripts to use your own logic */
rom.write("tuna", 4);
/* extract file */
rom.extract("actor.zovl", start, end);
}
/* write vram and unk to conf.txt */
fp = fopen("conf.txt", "wb");
fprintf(fp, "vram 0x%08X\n", vram);
fprintf(fp, "unknown 0x%08X\n", unk);
fclose(fp);
/* leave directory */
dir_leave();
/* advance to next entry */
index++;
}
/* cleanup */
dir_leave();
printf("success!\n");
}
void
actor(struct rom *rom)
{
FILE *fp;
char *name;
int index;
int start;
int end;
int vram;
int ivar;
int atype;
int naddr;
/* enter and parse folder */
dir_enter("actor");
/* repeats for every item in the list */
index = 0;
while (index < TBL_ACTOR_ENTRIES)
{
/* display progress */
printf("\r""actor %d/%d: ", index, TBL_ACTOR_ENTRIES - 1);
/* go to table entry */
rom.seek(TBL_ACTOR + index * 32);
/* parse table entry */
start = rom.read32(); /* vrom start */
end = rom.read32(); /* vrom end */
vram = rom.read32(); /* vram start */
rom.read32(); /* vram end */
rom.read32(); /* ram address */
ivar = rom.read32(); /* init vars */
naddr = rom.read32(); /* name addr */
atype = rom.read16(); /* alloc type */
/* get name string */
/* NOTE: an assumption is being made that naddr falls inside *
* code's vram; this is fine for roms that have not been *
* drastically altered, and naddr is always 0 on retail *
* roms anyway; just be aware of this if you have issues */
if (g_tsv)
name = tsv_col_row(g_tsv, "actor", index + 1);
else if (naddr)
name = rom.raw((naddr - VRAM_CODE) + VROM_CODE);
else
name = 0;
/* create and enter directory */
dir_enter(dir_mkname(index, name));
/* used entries have non-zero start */
if (start)
{
/* go to rom offset of this actor overlay's init vars */
rom.seek(start + (ivar - vram));
/* handle 0xDEAD 0xBEEF */
/* NOTE: this is no longer used, in favor of pulling the *
* initialization variable address from the ivar *
* field in conf.txt; uncomment if you need it */
//rom.write16(0xDEAD); /* 0x0000: table index */
//rom.seek_cur(8); /* 0x0002: advance to 0xA */
//rom.write16(0xBEEF); /* 0x000A: padding */
/* extract file */
rom.extract("actor.zovl", start, end);
}
/* write vram and atype to conf.txt */
fp = fopen("conf.txt", "wb");
fprintf(fp, "allocation 0x%04X\n", atype);
fprintf(fp, "vram 0x%08X\n", vram);
/* ivar override for actors that don't reference files */
//if (!start && ivar) /* uncomment this if you want DEAD BEEF */
fprintf(fp, "ivar 0x%08X\n", ivar);
fclose(fp);
/* leave directory */
dir_leave();
/* advance to next entry */
index++;
}
/* cleanup */
dir_leave();
printf("success!\n");
}
void
object(struct rom *rom)
{
int index;
int start;
int end;
/* enter and parse folder */
dir_enter("object");
/* repeats for every item in the list */
index = 0;
while (index < TBL_OBJECT_ENTRIES)
{
/* display progress */
printf("\r""object %d/%d: ", index, TBL_OBJECT_ENTRIES - 1);
/* create and enter directory */
dir_enter(
dir_mkname(
index
, tsv_col_row(g_tsv, "object", index + 1)
)
);
/* go to table entry */
rom.seek(TBL_OBJECT + index * 8);
/* parse table entry */
start = rom.read32();
end = rom.read32();
/* extract file */
rom.extract("zobj.zobj", start, end);
/* leave directory */
dir_leave();
/* advance to next entry */
index++;
}
/* cleanup */
dir_leave();
printf("success!\n");
}
int
main(int argc, char **argv)
{
struct rom *rom;
char *name;
FILE *fp;
/* name of rom */
/* NOTE: the rom of the given name must exist *
* in the same directory as this .rtl */
name = "oot-debug.z64";
/* initialize name lists */
g_tsv = loadfile("oot_names.tsv", 0, true/*file is optional*/);
/* folder naming style */
dir_use_style("pre");
/* load rom */
rom = rom.new(name);
/* dma table (dmadata) offset and number of entries */
rom.dma(TBL_DMA, TBL_DMA_ENTRIES);
/* dump rom */
systemdir(rom);
object(rom);
actor(rom);
particle(rom);
scene(rom);
route(rom);
/* create .zzrpl */
name = rom.filename();
fp = fopen("project.zzrpl", "wb");
fprintf(fp, "zzrtl v0.01\n");
fprintf(fp, "baserom \"%s\"\n", name);
/* zzplayas support */
fprintf(fp, "ZZPLAYAS_VROM_CODE \"'%s'+0x%08X\"\n", name, VROM_CODE);
fprintf(fp, "ZZPLAYAS_VROM_PLAYER \"'system/overlay/ovl_player_actor/ovl_player_actor.zovl'\"\n");
fclose(fp);
/* cleanup */
rom.free();
return 0;
}