#include "Main.h" #include "Input.h" #include "Output.h" #include "table.h" struct tentry { int sector; unsigned char u[4]; }; struct entry { int sector; int sizes[3]; }; #define fullsize 206213120 #define offset 0x83b78 #define N 437 CODE_BEGINS struct entry tab[N]; virtual int startup() throw (GeneralException) { int i, j, s, dcount = 1; Input * f; Output * t; int alreadycounted = 0; 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 = new Input("slus_006.62"); f->seek(offset); for (i = 0; i < N; i++) { 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) << 8); tab[i].sizes[2] = (te.u[2] >> 4) | (te.u[3] << 4); 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]); } delete f; f = new Input("pe.img"); for (i = 0; i < N; i++) { printm(M_INFO, "Dumping room %i\n", i + 1); if (!tab[i].sizes[0]) continue; f->seek(tab[i].sector * 2048); for (j = 0; j < 3; j++) { fn.set("rooms/room-%04i-%02i.out", i + 1, j); t = new Output(fn); for (s = 0; s < tab[i].sizes[j]; s++) { f->read(buff, 2048); t->write(buff, 2048); } delete t; } } for (i = 0; i < N; i++) { printm(M_INFO, "Dumping script %i\n", i + 1); found = empty = 0; if (!tab[i].sizes[0]) continue; f->seek((tab[i].sector + tab[i].sizes[0] + tab[i].sizes[1]) * 2048); orig = f->tell(); fn.set("scripts/room-%04i.txt", i); t = new Output(fn); #if 0 f->read(&truesize, 4); f->seek(truesize - 4, SEEK_CUR); while (!found) { f->read(&ptr, 4); f->seek(-8, SEEK_CUR); pos = f->tell(); if ((ptr >> 24) == 1) { ptr &= 0x00ffffff; f->seek(orig + ptr); f->read(&sig, 4); if ((sig & 0xffff) == 0xfe) { f->seek(pos); f->read(&size, 4); pos = ptr + orig; found = 1; } else if (sig != 0x4f414b41) { /* AKAO */ delete t; empty = 1; break; } } f->seek(pos); } if (empty) continue; #else truesize = f->readU32(); ptr = f->readU32(); f->seek(orig + ptr + 32, SEEK_SET); ptr = f->readU32(); if (!(ptr & 0xfff00000)) continue; f->seek(orig + (ptr & 0xfffff) + 8); size = f->readU32(); ptr = f->readU32(); pos = orig + (ptr & 0xfffff); f->seek(pos); #endif printm(M_INFO, "Found %i bytes of text at %i\n", size, pos); for (j = 0; j < size; j++) { b = f->readU8(); if (b <= MAXCHAR) { t->writeU8(table[b]); } else { switch(b) { case 0xf7: t->writeU8('\n'); break; case 0xf8: (*t) << "\n"; break; case 0xf9: (*t) << "\n\n"; break; case 0xfa: (*t) << ""; break; case 0xfb: j++; j++; a1 = f->readU8(); switch(a1) { case 0: (*t) << ""; break; case 1: (*t) << ""; break; case 9: a2 = f->readU8(); (*t) << "\n"; break; case 7: a2 = f->readU8(); (*t) << ""; break; default: (*t) << ""; break; } break; case 0xfe: j++; b = f->readU8(); (*t) << "\n"; break; case 0xff: (*t) << "\n\n"; break; default: (*t) << String().set("", b); } } } delete t; } delete f; return 0; } CODE_ENDS