summaryrefslogtreecommitdiff
path: root/PE/extract-rooms.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'PE/extract-rooms.cpp')
-rw-r--r--PE/extract-rooms.cpp173
1 files changed, 173 insertions, 0 deletions
diff --git a/PE/extract-rooms.cpp b/PE/extract-rooms.cpp
new file mode 100644
index 0000000..92bfb6f
--- /dev/null
+++ b/PE/extract-rooms.cpp
@@ -0,0 +1,173 @@
+#include <stdio.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
+
+struct entry tab[N];
+
+int main(void) {
+ int i, j, s, dcount = 1;
+ FILE * f, * t;
+ int alreadycounted = 0;
+ char fn[50], 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);
+
+ for (i = 0; i < N; i++) {
+ fread(&te, sizeof(struct tentry), 1, f);
+ 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,
+ tab[i].sizes[0], tab[i].sizes[1], tab[i].sizes[2]);
+ }
+
+ fclose(f);
+
+ f = fopen("pe.img", "r");
+
+ for (i = 0; i < N; i++) {
+ fprintf(stderr, "Dumping room %i\n", i);
+
+ if (!tab[i].sizes[0])
+ continue;
+
+ fseek(f, tab[i].sector * 2048, SEEK_SET);
+ for (j = 0; j < 3; j++) {
+ sprintf(fn, "rooms/room-%04i-%02i.out", i, j);
+
+ t = fopen(fn, "w");
+
+ for (s = 0; s < tab[i].sizes[j]; s++) {
+ fread(buff, 2048, 1, f);
+ fwrite(buff, 2048, 1, t);
+ }
+
+ fclose(t);
+ }
+ }
+
+ for (i = 0; i < N; i++) {
+ fprintf(stderr, "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);
+
+ sprintf(fn, "scripts/room-%04i.txt", i);
+ t = fopen(fn, "w");
+
+ fread(&truesize, 4, 1, f);
+ fseek(f, truesize - 4, SEEK_CUR);
+
+ while (!found) {
+ fread(&ptr, 4, 1, f);
+ fseek(f, -8, SEEK_CUR);
+ pos = ftell(f);
+ if ((ptr >> 24) == 1) {
+ ptr &= 0x00ffffff;
+ fseek(f, orig + ptr, SEEK_SET);
+ fread(&sig, 4, 1, f);
+ if ((sig & 0xffff) == 0xfe) {
+ fseek(f, pos, SEEK_SET);
+ fread(&size, 4, 1, f);
+ pos = ptr + orig;
+ found = 1;
+ } else if (sig != 0x4f414b41) { /* AKAO */
+ fclose(t);
+ empty = 1;
+ break;
+ }
+ }
+ fseek(f, pos, SEEK_SET);
+ }
+
+ if (empty)
+ continue;
+
+ fprintf(stderr, "Found %i bytes of text at %i\n", size, pos);
+
+ for (j = 0; j < size; j++) {
+ b = fgetc(f);
+
+ if (b <= MAXCHAR) {
+ fputc(table[b], t);
+ } else {
+ switch(b) {
+ case 0xf7:
+ fputc('\n', t);
+ break;
+ case 0xf8:
+ fprintf(t, "<PAUSE>\n");
+ break;
+ case 0xf9:
+ fprintf(t, "\n<TCLOSE>\n");
+ break;
+ case 0xfa:
+ fprintf(t, "<AYA>");
+ break;
+ case 0xfb:
+ j++;
+ j++;
+ a1 = fgetc(f);
+ switch(a1) {
+ case 0:
+ fprintf(t, "<TAG0>");
+ break;
+ case 1:
+ fprintf(t, "<TAG1>");
+ break;
+ case 9:
+ a2 = fgetc(f);
+ fprintf(t, "<CHOICES %i>\n", a2);
+ break;
+ case 7:
+ a2 = fgetc(f);
+ fprintf(t, "<TIMER %i>", a2);
+ break;
+ default:
+ fprintf(t, "<UNKCMD %i>", a1);
+ break;
+ }
+ break;
+ case 0xfe:
+ j++;
+ b = fgetc(f);
+ fprintf(t, "<PT%i>\n", b);
+ break;
+ case 0xff:
+ fprintf(t, "\n<CLOSE>\n");
+ break;
+ default:
+ fprintf(t, "<UNK %02X>", b);
+ }
+ }
+ }
+
+ fclose(t);
+ }
+
+ return 0;
+}