Binary script with a separate text table file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4
5 #include <deque>
6
7 void fread_or_die(void * a, size_t b, int c, FILE * d)
8 {
9 int got = fread(a, b, c, d);
10 if(feof(d)) {puts("feof"); exit(0);}
11 if(ferror(d)) {puts("ferror"); exit(0);}
12 if(got != c) {exit(0);}
13 }
14
15 int main()
16 {
17 auto fs = fopen("SCRIPT.SRC", "rb");
18 auto ft = fopen("TEXT.DAT", "rb");
19 auto fo = fopen("script.txt", "wb");
20
21 fseek(fs, 12, SEEK_SET);
22
23 std::deque<uint32_t> stack;
24
25 while(!feof(fs) and !ferror(fs))
26 {
27
28 uint32_t command;
29 fread_or_die(&command, 4, 1, fs);
30 if(command != 0x0001001F and command != 0x00010017)
31 continue;
32 if(command == 0x0001001F)
33 {
34 uint32_t value;
35 fread_or_die(&value, 4, 1, fs);
36 stack.push_front(value);
37 }
38 if(command == 0x00010017)
39 {
40 uint32_t value;
41 fread_or_die(&value, 4, 1, fs);
42 if(value == 0x00020002)
43 {
44 stack.pop_front();
45 stack.pop_front();
46 uint32_t addr = stack.front()+4;
47 stack.clear();
48 fseek(ft, addr, SEEK_SET);
49 int c = fgetc(ft);
50 while(c != 0)
51 {
52 fputc(c, fo);
53 c = fgetc(ft);
54 }
55 fputc('\n', fo);
56 }
57 }
58
59
60 }
61 }