diff options
author | pixel <pixel> | 2003-09-06 00:40:35 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-09-06 00:40:35 +0000 |
commit | a75df1a6b4c2788b80b3916e072ff945ee03748f (patch) | |
tree | 6c2d4b2ee281dfe561fd90dc85713bc0a34ed604 /PE/extract-rooms.cpp | |
parent | 44adf768555ecd211f90cbf4d87b44ba42044d86 (diff) |
Fixed Parasite Eve
Diffstat (limited to 'PE/extract-rooms.cpp')
-rw-r--r-- | PE/extract-rooms.cpp | 116 |
1 files changed, 61 insertions, 55 deletions
diff --git a/PE/extract-rooms.cpp b/PE/extract-rooms.cpp index 92bfb6f..3af349e 100644 --- a/PE/extract-rooms.cpp +++ b/PE/extract-rooms.cpp @@ -1,4 +1,6 @@ -#include <stdio.h> +#include "Main.h" +#include "Input.h" +#include "Output.h" #include "table.h" struct tentry { @@ -15,159 +17,163 @@ struct entry { #define offset 0x83b78 #define N 437 +CODE_BEGINS struct entry tab[N]; -int main(void) { +virtual int startup() throw (GeneralException) { int i, j, s, dcount = 1; - FILE * f, * t; + Input * f; + Output * t; int alreadycounted = 0; - char fn[50], buff[2048]; + String fn; + char buff[2048]; unsigned char b, a1, a2; struct tentry te; unsigned long orig, pos, truesize, ptr, sig, size; int found, empty; - f = fopen("slus_006.62", "r"); - fseek(f, offset, SEEK_SET); + f = new Input("slus_006.62"); + f->seek(offset); for (i = 0; i < N; i++) { - fread(&te, sizeof(struct tentry), 1, f); + f->read(&te, sizeof(struct tentry)); tab[i].sector = te.sector; tab[i].sizes[0] = te.u[0]; tab[i].sizes[1] = te.u[1] | (te.u[2] & 0xf); tab[i].sizes[2] = (te.u[2] >> 4) | (te.u[3] << 4); - printf("entry %3i - offset: %9i, sizes = %4i %4i %4i\n", i, tab[i].sector * 2048, + printm(M_INFO, "entry %3i - offset: %9i, sizes = %4i %4i %4i\n", i, tab[i].sector * 2048, tab[i].sizes[0], tab[i].sizes[1], tab[i].sizes[2]); } - fclose(f); + delete f; - f = fopen("pe.img", "r"); + f = new Input("pe.img"); for (i = 0; i < N; i++) { - fprintf(stderr, "Dumping room %i\n", i); + printm(M_INFO, "Dumping room %i\n", i); if (!tab[i].sizes[0]) continue; - fseek(f, tab[i].sector * 2048, SEEK_SET); + f->seek(tab[i].sector * 2048); for (j = 0; j < 3; j++) { - sprintf(fn, "rooms/room-%04i-%02i.out", i, j); + fn.set("rooms/room-%04i-%02i.out", i, j); - t = fopen(fn, "w"); + t = new Output(fn); for (s = 0; s < tab[i].sizes[j]; s++) { - fread(buff, 2048, 1, f); - fwrite(buff, 2048, 1, t); + f->read(buff, 2048); + t->write(buff, 2048); } - - fclose(t); + delete t; } } for (i = 0; i < N; i++) { - fprintf(stderr, "Dumping script %i\n", i); + printm(M_INFO, "Dumping script %i\n", i); found = empty = 0; if (!tab[i].sizes[0]) continue; - fseek(f, (tab[i].sector + tab[i].sizes[0] + tab[i].sizes[1]) * 2048, SEEK_SET); - orig = ftell(f); + f->seek((tab[i].sector + tab[i].sizes[0] + tab[i].sizes[1]) * 2048); + orig = f->tell(); - sprintf(fn, "scripts/room-%04i.txt", i); - t = fopen(fn, "w"); + fn.set("scripts/room-%04i.txt", i); + t = new Output(fn); - fread(&truesize, 4, 1, f); - fseek(f, truesize - 4, SEEK_CUR); + f->read(&truesize, 4); + f->seek(truesize - 4, SEEK_CUR); while (!found) { - fread(&ptr, 4, 1, f); - fseek(f, -8, SEEK_CUR); - pos = ftell(f); + f->read(&ptr, 4); + f->seek(-8, SEEK_CUR); + pos = f->tell(); if ((ptr >> 24) == 1) { ptr &= 0x00ffffff; - fseek(f, orig + ptr, SEEK_SET); - fread(&sig, 4, 1, f); + f->seek(orig + ptr); + f->read(&sig, 4); if ((sig & 0xffff) == 0xfe) { - fseek(f, pos, SEEK_SET); - fread(&size, 4, 1, f); + f->seek(pos); + f->read(&size, 4); pos = ptr + orig; found = 1; } else if (sig != 0x4f414b41) { /* AKAO */ - fclose(t); + delete t; empty = 1; break; } } - fseek(f, pos, SEEK_SET); + f->seek(pos); } if (empty) continue; - fprintf(stderr, "Found %i bytes of text at %i\n", size, pos); + printm(M_INFO, "Found %i bytes of text at %i\n", size, pos); for (j = 0; j < size; j++) { - b = fgetc(f); + b = f->readU8(); if (b <= MAXCHAR) { - fputc(table[b], t); + t->writeU8(table[b]); } else { switch(b) { case 0xf7: - fputc('\n', t); + t->writeU8('\n'); break; case 0xf8: - fprintf(t, "<PAUSE>\n"); + (*t) << "<PAUSE>\n"; break; case 0xf9: - fprintf(t, "\n<TCLOSE>\n"); + (*t) << "\n<TCLOSE>\n"; break; case 0xfa: - fprintf(t, "<AYA>"); + (*t) << "<AYA>"; break; case 0xfb: j++; j++; - a1 = fgetc(f); + a1 = f->readU8(); switch(a1) { case 0: - fprintf(t, "<TAG0>"); + (*t) << "<TAG0>"; break; case 1: - fprintf(t, "<TAG1>"); + (*t) << "<TAG1>"; break; case 9: - a2 = fgetc(f); - fprintf(t, "<CHOICES %i>\n", a2); + a2 = f->readU8(); + (*t) << "<CHOICES " << a2 << ">\n"; break; case 7: - a2 = fgetc(f); - fprintf(t, "<TIMER %i>", a2); + a2 = f->readU8(); + (*t) << "<TIMER " << a2 << ">"; break; default: - fprintf(t, "<UNKCMD %i>", a1); + (*t) << "<UNKCMD " << a1 << ">"; break; } break; case 0xfe: j++; - b = fgetc(f); - fprintf(t, "<PT%i>\n", b); + b = f->readU8(); + (*t) << "<PT" << b << ">\n"; break; case 0xff: - fprintf(t, "\n<CLOSE>\n"); + (*t) << "\n<CLOSE>\n"; break; default: - fprintf(t, "<UNK %02X>", b); + (*t) << String().set("<UNK %02X>", b); } } } - fclose(t); + delete t; } - + + delete f; return 0; } +CODE_ENDS
\ No newline at end of file |