Seems related to Silky, which is probably misnamed.
1 // Dumper for Fortissimo EXS's script
2
3 #include <stdlib.h>
4 #include <stdint.h>
5 #include <stdio.h>
6
7 bool is_jis_surrogate(uint8_t c)
8 {
9 if(c >= 0x80 and c <= 0xA0) return true;
10 if(c >= 0xE0) return true;
11 return false;
12 }
13
14 bool silent = false;
15 bool debug = false;
16
17 void output(int c)
18 {
19 if (!silent) printf("%c", c);
20 }
21
22 void print_string(FILE * f)
23 {
24 if (!silent and debug) printf("printing from %X\n", ftell(f));
25 int c = fgetc(f);
26 while(c > 0 and c < 0x100)
27 {
28 c = (c+0x20)%0x100;
29 if(is_jis_surrogate(c))
30 {
31 if (!silent) output(c);
32 c = fgetc(f);
33 if(c == 0) break;
34 output((c+0x20)%0x100);
35 }
36 else
37 {
38 if(c == 0x0A)
39 {
40 //output(c);
41 }
42 else
43 {
44 if (!silent) output(c);
45 }
46 }
47 c = fgetc(f);
48 }
49 if (!silent) puts("");
50 }
51
52 #define eat_string() \
53 { \
54 c = fgetc(f); \
55 while(c > 0) \
56 c = fgetc(f); \
57 }
58
59 int main(int argc, char ** argv)
60 {
61 // feed .MES files
62 for(int i = 1; i < argc; i++)
63 {
64 auto f = fopen(argv[i], "rb");
65
66 if(!f) return puts("failed to open"), 0;
67
68 if (debug) printf("reading %s\n", argv[i]);
69
70 uint32_t numlines;
71 fread(&numlines, 4, 1, f);
72
73 uint32_t startpoint = numlines*4;
74
75 fseek(f, startpoint, SEEK_CUR);
76
77 if (debug) printf("startpoint 0x%X\n", startpoint);
78
79 uint8_t last_command = 0;
80 uint32_t last_command_location = 0;
81
82 int c = 0;
83 while(1)
84 {
85 c = fgetc(f);
86 if(c < 0) break;
87
88 // Opcode handling to stay in sync. Not proper reverse engineering, 95% guesswork.
89 switch(c)
90 {
91 case 0x6B: // like a scene header of some sort
92 last_command = c;
93 last_command_location = ftell(f)-1;
94
95 fseek(f, 1, SEEK_CUR);
96 continue;
97 case 0x00:
98 case 0x02:
99 case 0x03:
100 case 0x04:
101 case 0x05:
102 case 0x07:
103 case 0x08:
104 case 0x09:
105 case 0x0A:
106 case 0x0B:
107 case 0x0D:
108 case 0x0E:
109 case 0x0F:
110 case 0x11:
111 case 0x12:
112 case 0x13:
113 case 0x14:
114 case 0x15:
115 case 0x16:
116 case 0x17:
117 case 0x19:
118 case 0x1A:
119 case 0x1B:
120 case 0x1C:
121 case 0x1E:
122 case 0x21:
123 case 0x22:
124 case 0x26: // ????
125 last_command = c;
126 last_command_location = ftell(f)-1;
127
128 fseek(f, 2, SEEK_CUR);
129 continue;
130 case 0x51: // ?
131 case 0x52: // ?
132 case 0x53: // ?
133 case 0x54: // ?
134 case 0x55: // ?
135 case 0x56: // ? (related to 3F and 40?)
136 case 0x57: // ?
137 case 0x58: // ?
138 case 0x5D: // ?
139 case 0x5E: // ?
140 case 0x5F: // ?
141 case 0x60: // ?
142 case 0x61: // ?
143 case 0x62: // ?
144 case 0x64: // ?
145 case 0x66: // ?
146 case 0x67: // ?
147 case 0x68: // ?
148 last_command = c;
149 last_command_location = ftell(f)-1;
150
151 fseek(f, 8, SEEK_CUR);
152 continue;
153 case 0x30: // stack related?
154 case 0x31: // ? (system\stat_chip06)
155 case 0x32: // ? (system\gotitle)
156 case 0x33: // ? (system\cgpage01)
157 case 0x35: // ? (SCEAN_START) (SCEAN_NEXT1) ("00") (advmenu_start)
158 case 0x36: // voice related
159 case 0x37: // (return_sub)
160 case 0x38: // play movie? (movie\ff_op_fripside.mpg)
161 case 0x3A: // ? (SCEAN_NEXT1) (return_txt) (CloseMes)
162 case 0x3B: // ? (advmenu_start)
163 case 0x3C: // ? ("logo_end0")
164 case 0x3F: // ? (SCEAN_END)
165 case 0x40: // ? (SCEAN_START)
166 case 0x43: // ? (@tスキップしますか?)
167 case 0x44: // ? ("00") ("01")
168 case 0x45: // ? ("最初からシーンを再生")
169 case 0x47: // voice related
170 case 0x48: // voice related
171 case 0x49: // ? (music_play_end)
172 case 0x4B: // ? ("1.00")
173 last_command = c;
174 last_command_location = ftell(f)-1;
175
176 eat_string();
177 continue;
178 case 0x2A: // ? (system\messwin)
179 case 0x2B: // music related
180 case 0x2D: // ? (advmenu)
181 case 0x2C: // music related
182 case 0x2E: // related to end of scene file
183 last_command = c;
184 last_command_location = ftell(f)-1;
185
186 fseek(f, 1, SEEK_CUR); // slot?
187 eat_string();
188 continue;
189 case 0x4D: // ? (speaker name?)
190 case 0x4E: // "normal" text
191 case 0x4F: // choice
192 last_command = c;
193 last_command_location = ftell(f)-1;
194
195 if(c != 0x4D)
196 print_string(f);
197 else
198 eat_string();
199 continue;
200 }
201 if(c < 0)
202 break;
203
204 printf("Unknown command %02X at %08X in %s\n", uint8_t(c), ftell(f)-1, argv[i]);
205 printf("Next byte is %02X\n", fgetc(f));
206 printf("Last command was %02X at %08X\n", last_command, last_command_location);
207 exit(0);
208 }
209 fclose(f);
210 if (!silent) puts("");
211 }
212 }