-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.cpp
More file actions
333 lines (279 loc) · 6.33 KB
/
setup.cpp
File metadata and controls
333 lines (279 loc) · 6.33 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#include "stdafx.h"
#include "setup.h"
#include "main.h"
#include "inih/ini.h"
char* ReadLine(char* buf, long size, FILE* fp)
{
long c;
if (fgets(buf, size, fp))
{
if (!strchr(buf, '\n'))
do c = fgetc(fp); while (c != EOF && c != '\n');
return buf;
}
return NULL;
}
long ConfigurationHandler(void* data, const char* section, const char* entry, const char* value)
{
SETUP_STRUCT* cfg;
cfg = (SETUP_STRUCT*)data;
if (!_stricmp(section, "options"))
{
if (cfg->options.idx < 1)
{
if (entry == NULL && value == NULL)
cfg->options.idx++;
else if (!_stricmp(entry, "number"))
{
if (!cfg->options.set.number.on)
{
if (!ParseIntegers(value, &cfg->options.set.number.cnt, 1))
{
ShowError("Cutscene number must be an integer");
return 0;
}
if (cfg->options.set.number.cnt < 1 || cfg->options.set.number.cnt > 255)
{
ShowError("Cutscene number must be between 1 and 255");
return 0;
}
cfg->options.set.number.on = 1;
}
}
else if (!_stricmp(entry, "camera"))
{
if (!cfg->options.set.camera.on)
{
strcpy_s(cfg->options.set.camera.cnt, 200, value);
if (cfg->options.set.camera.cnt[0] == '\0')
{
ShowError("Camera node name must be non-empty");
return 0;
}
cfg->options.set.camera.on = 1;
}
}
else if (!_stricmp(entry, "origin"))
{
if (!cfg->options.set.origin.on)
{
if (!ParseIntegers(value, (long*)&cfg->options.set.origin.cnt, 3))
{
ShowError("Origin must be composed of three integers separated by commas");
return 0;
}
if (cfg->options.set.origin.cnt.x < 0 || cfg->options.set.origin.cnt.x > 131071)
{
ShowError("X coordinate of origin must be between 0 and 131071");
return 0;
}
if (cfg->options.set.origin.cnt.y < -32768 || cfg->options.set.origin.cnt.y > 32767)
{
ShowError("Y coordinate of origin must be between -32768 and 32767");
return 0;
}
if (cfg->options.set.origin.cnt.z < 0 || cfg->options.set.origin.cnt.z > 131071)
{
ShowError("Z coordinate of origin must be between 0 and 131071");
return 0;
}
cfg->options.set.origin.on = 1;
}
}
else if (!_stricmp(entry, "audio"))
{
if (!cfg->options.set.audio.on)
{
if (!ParseIntegers(value, &cfg->options.set.audio.cnt, 1))
{
ShowError("Audio must be an integer");
return 0;
}
if (cfg->options.set.audio.cnt < 0 || cfg->options.set.audio.cnt > 255)
{
ShowError("Audio must be between 0 and 255");
return 0;
}
cfg->options.set.audio.on = 1;
}
}
}
}
else if (!_stricmp(section, "lara"))
{
if (cfg->lara.idx < 1)
{
if (entry == NULL && value == NULL)
cfg->lara.idx++;
else if (!_stricmp(entry, "name"))
{
if (!cfg->lara.set.name.on)
{
strcpy_s(cfg->lara.set.name.cnt, 200, value);
if (cfg->lara.set.name.cnt[0] == '\0')
{
ShowError("Lara node name must be non-empty");
return 0;
}
cfg->lara.set.name.on = 1;
}
}
}
}
else if (!_stricmp(section, "actor"))
{
if (cfg->actor.idx < 99)
{
if (entry == NULL && value == NULL)
cfg->actor.idx++;
else if (!_stricmp(entry, "name"))
{
if (!cfg->actor.set[cfg->actor.idx].name.on)
{
strcpy_s(cfg->actor.set[cfg->actor.idx].name.cnt, 200, value);
if (cfg->actor.set[cfg->actor.idx].name.cnt[0] == '\0')
{
ShowError("Actor %d node name must be non-empty", cfg->actor.idx + 1);
return 0;
}
cfg->actor.set[cfg->actor.idx].name.on = 1;
}
}
else if (!_stricmp(entry, "slot"))
{
if (!cfg->actor.set[cfg->actor.idx].slot.on)
{
if (!ParseIntegers(value, &cfg->actor.set[cfg->actor.idx].slot.cnt, 1))
{
ShowError("Actor %d slot must be an integer", cfg->actor.idx + 1);
return 0;
}
if (cfg->actor.set[cfg->actor.idx].slot.cnt < 1 || cfg->actor.set[cfg->actor.idx].slot.cnt > 519)
{
ShowError("Actor %d slot must be between 1 and 519", cfg->actor.idx + 1);
return 0;
}
cfg->actor.set[cfg->actor.idx].slot.on = 1;
}
}
}
}
return 1;
}
void InitialiseConfiguration(SETUP_STRUCT* cfg)
{
cfg->options.set.number.on = 0;
cfg->options.set.camera.on = 0;
cfg->options.set.origin.on = 0;
cfg->options.set.audio.on = 0;
cfg->options.idx = -1;
cfg->lara.set.name.on = 0;
cfg->lara.idx = -1;
for (int i = 0; i < 99; i++)
{
cfg->actor.set[i].name.on = 0;
cfg->actor.set[i].slot.on = 0;
}
cfg->actor.idx = -1;
}
long CheckConfiguration(SETUP_STRUCT* cfg)
{
if (cfg->options.idx > 0)
cfg->options.idx = 0;
if (cfg->lara.idx > 0)
cfg->lara.idx = 0;
if (cfg->actor.idx > 98)
cfg->actor.idx = 98;
if (cfg->options.idx == -1)
{
ShowError("Options section must be present");
return 0;
}
if (!cfg->options.set.number.on)
{
ShowError("Cutscene number must be informed");
return 0;
}
if (!cfg->options.set.camera.on)
{
ShowError("Camera node name must be informed");
return 0;
}
if (cfg->lara.idx != -1 && !cfg->lara.set.name.on)
{
ShowError("Lara node name must be informed");
return 0;
}
for (int i = 0; i <= cfg->actor.idx; i++)
{
if (!cfg->actor.set[i].name.on)
{
ShowError("Actor %d node name must be informed", i + 1);
return 0;
}
if (!cfg->actor.set[i].slot.on)
{
ShowError("Actor %d slot must be informed", i + 1);
return 0;
}
}
return 1;
}
long ParseIntegers(const char* value, long* arr, long len)
{
char* str;
char* tok;
char* ctx;
char* end;
long n, r;
r = 1;
str = _strdup(value);
if (str)
{
tok = strtok_s(str, ",", &ctx);
for (int i = 0; i < len; i++)
{
if (!tok)
{
r = 0;
break;
}
n = strtol(tok, &end, 10);
if (*end != '\0')
{
r = 0;
break;
}
arr[i] = n;
tok = strtok_s(NULL, ",", &ctx);
}
if (tok)
r = 0;
free(str);
}
else
r = 0;
return r;
}
long GetConfiguration(const char* filename, SETUP_STRUCT* cfg)
{
FILE* fp;
long r, line;
r = 0;
InitialiseConfiguration(cfg);
if (!fopen_s(&fp, filename, "r"))
{
line = ini_parse_stream((ini_reader)ReadLine, fp, (ini_handler)ConfigurationHandler, cfg);
if (!line)
{
if (CheckConfiguration(cfg))
r = 1;
}
else
ShowError("Line %d cannot be parsed", line);
fclose(fp);
}
else
ShowError("cutseq script cannot be opened");
return r;
}