-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmm_dump.rtl
More file actions
491 lines (406 loc) · 11.9 KB
/
mm_dump.rtl
File metadata and controls
491 lines (406 loc) · 11.9 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
/*************************************************************
* /Zel/ & z64.me zzrtl script for extracting assets from MM *
*************************************************************/
/* global variables */
char *g_tsv;
/* MM U */
enum {
TBL_OBJECT = 0x00C58C80 // object table
, TBL_OBJECT_ENTRIES = 643 // object count
, TBL_ACTOR = 0x00C45510 // actor overlay table
, TBL_ACTOR_ENTRIES = 690 // actor overlay count
, TBL_PARTICLE = 0x00C449E0 // particle overlay table
, TBL_PARTICLE_ENTRIES = 39 // particle overlay count
, TBL_SCENE = 0x00C5A1E0 // scene table
, TBL_SCENE_ENTRIES = 113 // scene count
, TBL_DMA = 0x0001A500 // dma table
, TBL_DMA_ENTRIES = 1568 // dma entries
, VRAM_CODE = 0x800A5AC0 // vram start of code
, VROM_CODE = 0x00B3C000 // vrom start of code
, VROM_PLAYER = 0x00CA7F00 // vrom start of player_actor
, DMA_ICON_ITEM_FIELD = 10 // icon_item_field_static
, DMA_ICON_ITEM_DUNGEON // icon_item_dungeon_static
, DMA_ICON_ITEM_GAMEOVER // icon_item_gameover_static
, DMA_MAP_NAME_STATIC // map_name_static
, DMA_UNK_14 // [?]
, DMA_MAP_I_STATIC = 15 // map_i_static
, DMA_UNK_23 = 23 // [?]
, DMA_UNK_24
, DMA_CODE = 31 // code
, DMA_ACTOR_FIRST = 39 // En_Test
, DMA_ACTOR_LAST = 648 // En_Rsn
, DMA_OBJECT_FIRST = 649 // gameplay_keep
, DMA_OBJECT_LAST = 1113 // object_gi_mask13
, DMA_EXCEPT = 1127 // clock face days
, DMA_SCENE_FIRST = 1137 // Z2_20SICHITAI2
, DMA_SCENE_LAST = 1537 // Z2_ALLEY_room_0
, DMA_UNUSED_FIRST = 1538 // bump_texture_static
, DMA_UNUSED_LAST = 1567 // null
, ACTID_LINK = 0 // link's actor id
};
enum bool
{
false = 0
, true = 1
, compress = 1
};
void
archive(struct rom *rom)
{
FILE *fp;
char *filename;
char *outname;
char *name;
int i;
/* allocate buffer */
outname = malloc(64);
/* archive filenames */
filename =
"map_i_static\0" /* dungeon room minimaps */
"map_grand_static\0" /* overworld minimaps */
"item_name_static\0" /* pause menu item names */
"spot_name_static\0" /* pause menu location names */
"icon_item_static\0" /* icons + pause menu assets */
"icon_item_24_static\0" /* quest status, dungeon icons */
"unused\0" /* unused/deleted archive */
"icon_bomber_static\0" /* bomber's notebook icons */
;
/* enter and parse folder */
dir_enter("archive");
/* write a note about zzyarman */
fp = fopen("README.txt", "wb");
fprintf(fp, "use zzyarman to edit .yar files -> z64.me/zzyarman");
fclose(fp);
i = 0;
while (i < 8)
{
name = substring(filename, i);
/* if name is not "unused" */
if (strcmp(name, "unused"))
{
/* create out file name with extension */
sprintf(outname, "%s.yar", name);
/* dump file */
rom.extract_dma(outname, i + DMA_MAP_I_STATIC);
}
/* advance to next */
i++;
}
/* cleanup */
free(outname);
dir_leave();
}
void
scene(struct rom *rom)
{
FILE *fp;
char *b;
char *b_end;
char *room_name;
char *name;
char room_count;
int index;
int start;
int end;
int msg_id;
int config;
int sz;
/* allocate room name */
room_name = malloc(16);
/* 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 * 16);
/* parse table entry */
start = rom.read32(); /* vrom start */
end = rom.read32(); /* vrom end */
msg_id = rom.read16(); /* area name text */
rom.read8(); /* padding */
config = rom.read8(); /* texture animation */
rom.read32(); /* padding */
/* 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));
}
}
/* write table settings to conf.txt */
fp = fopen("conf.txt", "wb");
fprintf(fp, "msg_id %d\n", msg_id);
fprintf(fp, "config %d\n", config);
fclose(fp);
/* leave directory */
dir_leave();
/* advance to next entry */
index++;
}
/* cleanup */
dir_leave();
free(room_name);
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 = "mm-u.z64";
/* initialize name lists */
g_tsv = loadfile("mm_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 */
archive(rom);
object(rom);
actor(rom);
particle(rom);
scene(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 \"'%s'+0x%08X\"\n", name, VROM_PLAYER);
fclose(fp);
/* cleanup */
rom.free();
return 0;
}