#include #include int main(int argc, char *argv[]) { FILE *dff; unsigned int offset, size; int header, vcount; int temp; if (argc < 3) { printf("Usage: %s dff address\n", argv[0]); printf("Address = Address of \"Native Data PLG\" (hex)\n"); exit(1); } if ((dff = fopen(argv[1], "rb")) == NULL) exit(2); sscanf(argv[2], "%X", &offset); /* * Jump to "offset", check for Native Data PLG section, read size, * check is version == VC PS2, skip 12 bytes. * We are now at the beginning of the struct containing the data. */ fseek(dff, offset, 0); fread(&temp, 4, 1, dff); if (temp != 0x510) { printf("Not a Native Data PLG\n"); exit(3); } fread(&size, 4, 1, dff); fread(&temp, 4, 1, dff); if (temp != 0x0c02ffff) { printf("Not a Vice City PS2 file\n"); exit(3); } /* Since we took the size of the parent section, */ /* we have to substract 12 */ fseek(dff, 12, SEEK_CUR); size -= 12; /* Loop through struct and skip Vertex, */ /* UV, Vertex Color, and Normals sections. */ while ((size+offset) > (ftell(dff))) { temp = getc(dff) << 24; temp += getc(dff) << 16; temp += getc(dff) << 8; temp += getc(dff); header = temp & 0xffff00ff; switch (header) { case 0x00800068: vcount = (temp & 0x0000ff00) >> 8; printf("Vertex header detected, skipping,\ %d Vertices\n", vcount); fseek(dff, vcount*12, SEEK_CUR); if ((vcount * 12) % 16 != 0) fseek(dff, 16-(vcount * 12 % 16), SEEK_CUR); break; case 0x01800064: vcount = (temp & 0x0000ff00) >> 8; printf("UV header detected, skipping, \ %d Vertices\n", vcount); fseek(dff, vcount*8, SEEK_CUR); if ((vcount * 8) % 16 != 0) fseek(dff, 16-(vcount * 8 % 16), SEEK_CUR); break; case 0x02C0006e: vcount = (temp & 0x0000ff00) >> 8; printf("Vertex color header detected, skipping, \ %d Vertices\n", vcount); fseek(dff, vcount*4, SEEK_CUR); if ((vcount * 4) % 16 != 0) fseek(dff, 16-(vcount * 4 % 16), SEEK_CUR); break; case 0x0380006a: vcount = (temp & 0x0000ff00) >> 8; printf("Normal header detected, skipping, \ %d Vertices\n", vcount); fseek(dff, vcount*3, SEEK_CUR); if ((vcount * 3) % 16 != 0) fseek(dff, 16-(vcount * 3) % 16, SEEK_CUR); break; default: printf("%lX: %08X\n", ftell(dff), temp); } } return 0; }