summaryrefslogtreecommitdiff
path: root/PE/extract-rooms.cpp
blob: a23026f5cbd35b24a1d037351bbc935a52bcd14f (plain)
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
#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 438

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;

    verbosity = M_INFO;

    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  (%02x %02x %02x %02x)\n", i, tab[i].sector * 2048,
	       tab[i].sizes[0], tab[i].sizes[1], tab[i].sizes[2], te.u[0], te.u[1], te.u[2], te.u[3]);
    }
    
    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);
	
	extracttext(f, t, size);

	delete t;
    }

    delete f;
    return 0;
}
CODE_ENDS