ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/Daodan_Config.c
Revision: 993
Committed: Sun Apr 6 17:06:02 2014 UTC (11 years, 6 months ago) by alloc
Content type: text/x-csrc
File size: 17049 byte(s)
Log Message:
Daodan:
- Fix #74
- Fix #75
- Fix #72

File Contents

# Content
1 #include <windows.h>
2 #include <string.h>
3
4 #include "Daodan_Cheater.h"
5 #include "Daodan_Config.h"
6 #include "Daodan_Patch.h"
7 #include "Daodan_Utility.h"
8
9 #include "Oni/Oni.h"
10
11 #include "Inifile_Reader.h"
12
13 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
14
15 static const char* iniName = "daodan.ini";
16
17 ConfigSection_t config[] = {
18 { "patches", "Patches", {
19 { "alttab",
20 "Allows user to switch applications while in Oni (Alt-Tab) and use Windows key, however it may enable the screensaver as well.",
21 C_BOOL,
22 {.intBoolVal = true},
23 {.intBoolVal = true} },
24 { "argb8888",
25 "Textures using ARGB8888 can be used.",
26 C_BOOL,
27 {.intBoolVal = true},
28 {.intBoolVal = true} },
29 { "binkplay",
30 "Fix binkplay calls to use GDI and outro same mode as intro.",
31 C_BOOL,
32 {.intBoolVal = true},
33 {.intBoolVal = true} },
34 { "bsl",
35 "Enables d_regen (unfinished) and prevents fly-in portraits from being stretched when playing in widescreen resolutions.",
36 C_BOOL,
37 {.intBoolVal = true},
38 {.intBoolVal = true} },
39 { "cheater",
40 "Adds new cheat codes (see section below).",
41 C_BOOL,
42 {.intBoolVal = true},
43 {.intBoolVal = true} },
44 { "cheatsenabled",
45 "Enables cheats without having to beat the game first.",
46 C_BOOL,
47 {.intBoolVal = true},
48 {.intBoolVal = true} },
49 { "cheattable",
50 "Replaces Oni's cheat table with table that includes new cheats (see section below).",
51 C_BOOL,
52 {.intBoolVal = true},
53 {.intBoolVal = true} },
54 { "chinese",
55 "Allow for chinese fonts to be shown.",
56 C_BOOL,
57 {.intBoolVal = true},
58 {.intBoolVal = true} },
59 { "clipcursor",
60 "Limit cursor to Oni's window.",
61 C_BOOL,
62 {.intBoolVal = true},
63 {.intBoolVal = true} },
64 { "cooldowntimer",
65 "Disables weapon cooldown exploit.",
66 C_BOOL,
67 {.intBoolVal = true},
68 {.intBoolVal = true} },
69 { "daodandisplayenum",
70 "Offers more display modes in the Options menu.",
71 C_BOOL,
72 {.intBoolVal = true},
73 {.intBoolVal = true} },
74 { "directinput",
75 "Forces on DirectInput.",
76 C_BOOL,
77 {.intBoolVal = true},
78 {.intBoolVal = true} },
79 { "disablecmdline",
80 "Replaces existing command line parser with Daodan's in order to add new commands. Meant to be used with getcmdline.",
81 C_BOOL,
82 {.intBoolVal = true},
83 {.intBoolVal = true} },
84 { "fonttexturecache",
85 "Doubles size of font texture cache.",
86 C_BOOL,
87 {.intBoolVal = true},
88 {.intBoolVal = true} },
89 { "getcmdline",
90 "Replaces existing command line parser with Daodan's in order to add new commands. Meant to be used with disablecmdline.",
91 C_BOOL,
92 {.intBoolVal = true},
93 {.intBoolVal = true} },
94 { "hdscreens_lowres",
95 "???",
96 C_BOOL,
97 {.intBoolVal = true},
98 {.intBoolVal = true} },
99 { "highres_console",
100 "Fixes bug where console line becomes invisible at higher resolutions.",
101 C_BOOL,
102 {.intBoolVal = true},
103 {.intBoolVal = true} },
104 { "kickguns",
105 "Unfinished, do not use.",
106 C_BOOL,
107 {.intBoolVal = false},
108 {.intBoolVal = false} },
109 { "largetextures",
110 "Textures up to 512x512 can be used.",
111 C_BOOL,
112 {.intBoolVal = true},
113 {.intBoolVal = true} },
114 { "levelplugins",
115 "Allows level files to be loaded from the GDF which do not end in \"_Final\".",
116 C_BOOL,
117 {.intBoolVal = true},
118 {.intBoolVal = true} },
119 { "newweap",
120 "Picking up a weapon displays a message containing the weapon name and amount of ammo.",
121 C_BOOL,
122 {.intBoolVal = true},
123 {.intBoolVal = true} },
124 { "nomultibyte",
125 "Enables languages which use multibyte coding (such as Chinese).",
126 C_BOOL,
127 {.intBoolVal = true},
128 {.intBoolVal = true} },
129 { "optionsvisible",
130 "Always show options button in main menu, even when pausing from a game.",
131 C_BOOL,
132 {.intBoolVal = true},
133 {.intBoolVal = true} },
134 { "particledisablebit",
135 "Unlocks particle action disabling/enabling bits for all events so that a particle event can occur multiple times.",
136 C_BOOL,
137 {.intBoolVal = false},
138 {.intBoolVal = false} },
139 { "pathfinding",
140 "Multiplies size of pathfinding grid cache by eight in order to prevent crashes in large levels.",
141 C_BOOL,
142 {.intBoolVal = true},
143 {.intBoolVal = true} },
144 { "projaware",
145 "Allows AI to dodge incoming gunfire properly.",
146 C_BOOL,
147 {.intBoolVal = true},
148 {.intBoolVal = true} },
149 { "safeprintf",
150 "Replaces Oni's function that prints to startup.txt with a safer one.",
151 C_BOOL,
152 {.intBoolVal = true},
153 {.intBoolVal = true} },
154 { "showalllasersights",
155 "Show all (also enemies') weapon lasersights.",
156 C_BOOL,
157 {.intBoolVal = false},
158 {.intBoolVal = false} },
159 { "showtriggervolumes",
160 "Allows BSL variable \"show_triggervolumes\" to work when set to 1.",
161 C_BOOL,
162 {.intBoolVal = true},
163 {.intBoolVal = true} },
164 { "throwtest",
165 "Not recommended for use; experiment with allowing enemies to be thrown over railings.",
166 C_BOOL,
167 {.intBoolVal = false},
168 {.intBoolVal = false} },
169 { "usedaodangl",
170 "Provides an improved windowed mode (-noswitch); this patch is known to break the hiding of the Windows taskbar in fullscreen mode.",
171 C_BOOL,
172 {.intBoolVal = true},
173 {.intBoolVal = true} },
174 { "usegettickcount",
175 "Replaces Oni's timing functions with more accurate ones.",
176 C_BOOL,
177 {.intBoolVal = true},
178 {.intBoolVal = true} },
179 { "wpfadetime",
180 "Adds working function for existing BSL command wp_fadetime, sets fade time to 4800.",
181 C_BOOL,
182 {.intBoolVal = true},
183 {.intBoolVal = true} },
184 { 0, 0, 0, {0}, {0} }
185 } },
186 { "options", "Options", {
187 { "border",
188 "If \"windowhack\" patch is active, make sure game window has border in windowed mode.",
189 C_BOOL,
190 {.intBoolVal = true},
191 {.intBoolVal = true} },
192 { "debug",
193 "???",
194 EXT_BOOL,
195 {.intBoolVal = false },
196 {.extBoolVal = &AKgDebug_DebugMaps } },
197 { "debugfiles",
198 "???",
199 EXT_BOOL,
200 {.intBoolVal = false },
201 {.extBoolVal = &BFgDebugFileEnable } },
202 { "findsounds",
203 "???",
204 EXT_BOOL,
205 {.intBoolVal = false },
206 {.extBoolVal = &SSgSearchOnDisk } },
207 { "gamma",
208 "Enable gamma slider in fullscreen.",
209 C_BOOL,
210 {.intBoolVal = true},
211 {.intBoolVal = true} },
212 { "ignore_private_data",
213 "???",
214 EXT_BOOL,
215 {.intBoolVal = false },
216 {.extBoolVal = &opt_ignore_private_data } },
217 { "sound",
218 "???",
219 EXT_BOOL,
220 {.intBoolVal = true },
221 {.extBoolVal = &opt_sound } },
222 { "switch",
223 "Always switch screen to resolution on Oni's Options screen, making the game fullscreen; opposite of Oni's built-in argument \"noswitch\".",
224 EXT_BOOL,
225 {.intBoolVal = true},
226 {.extBoolVal = &M3gResolutionSwitch} },
227 { "topmost",
228 "Keep game window on top in windowed mode, even when switching applications.",
229 C_BOOL,
230 {.intBoolVal = false},
231 {.intBoolVal = false} },
232 { "usedaodanbsl",
233 "Adds new BSL commands (see below).",
234 C_BOOL,
235 {.intBoolVal = true},
236 {.intBoolVal = true} },
237 { "language",
238 "Localization for hardcoded strings (e.g. \"Savepoints\").",
239 C_STRING,
240 {.stringVal = "en"},
241 {.stringVal = "en"} },
242 { 0, 0, 0, {0}, {0} }
243 } }
244 };
245
246
247 void DDrConfig_Print()
248 {
249 for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
250 for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
251 switch (co->type) {
252 case C_STRING:
253 STARTUPMESSAGE("Option %s.%s = %s (def %s)", config[s].name, co->name, co->value.stringVal, co->defaultValue.stringVal);
254 break;
255 case EXT_BOOL:
256 STARTUPMESSAGE("Option %s.%s = %d (def %d)", config[s].name, co->name, *co->value.extBoolVal, co->defaultValue.intBoolVal);
257 break;
258 default:
259 STARTUPMESSAGE("Option %s.%s = %d (def %d)", config[s].name, co->name, co->value.intBoolVal, co->defaultValue.intBoolVal);
260 }
261 }
262 }
263 }
264
265 const char* DDrConfig_GetOptionTypeName(OptionType_t type)
266 {
267 switch (type) {
268 case C_INT:
269 return "Int";
270 case C_BOOL:
271 return "Bool";
272 case C_STRING:
273 return "String";
274 case EXT_BOOL:
275 return "pBool";
276 default:
277 return "unknown";
278 }
279 }
280
281 static ConfigOption_t* DDrConfig_GetOption(const char* fullOptName)
282 {
283 char section[50];
284 strcpy(section, fullOptName);
285
286 char* option = strchr(section, '.');
287 if (option == 0) {
288 STARTUPMESSAGE("Could not find option separator in \"%s\"", fullOptName);
289 return 0;
290 }
291 *option++ = 0;
292
293 for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
294 if (!_stricmp(config[s].name, section)) {
295 for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
296 if (!_stricmp(co->name, option)) {
297 return co;
298 }
299 }
300 STARTUPMESSAGE("Could not find option \"%s\" in section \"%s\"", option, section);
301 return 0;
302 }
303 }
304 STARTUPMESSAGE("Could not find section \"%s\" for option \"%s\"", section, option);
305 return 0;
306 }
307
308
309
310 ConfigOption_t* DDrConfig_GetOptOfType(const char* fullOptName, OptionType_t type)
311 {
312 ConfigOption_t* co = DDrConfig_GetOption(fullOptName);
313 if (co == 0)
314 return 0;
315
316 if (co->type != type) {
317 STARTUPMESSAGE("Option \"%s\" is not of type %s", fullOptName, DDrConfig_GetOptionTypeName(type));
318 return 0;
319 }
320 return co;
321 }
322
323
324 void DDrConfig_InitExtBools()
325 {
326 for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
327 for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
328 if (co->type == EXT_BOOL) {
329 *co->value.extBoolVal = co->defaultValue.intBoolVal;
330 }
331 }
332 }
333 }
334
335
336
337 void DDrIniCallback(char* section, char* name, char* value)
338 {
339 static char curSection[20];
340 char fullOptName[50];
341
342 if (!_stricmp(section, "patch"))
343 section = "patches";
344
345 strcpy(curSection, section);
346
347 strcpy(fullOptName, curSection);
348 fullOptName[strlen(curSection)] = '.';
349 strcpy(fullOptName+strlen(curSection)+1, name);
350
351 ConfigOption_t* co = DDrConfig_GetOption(fullOptName);
352
353 if (co)
354 {
355 switch (co->type) {
356 case C_INT:
357 co->value.intBoolVal = strtol(value, NULL, 0);
358 break;
359 case C_BOOL:
360 co->value.intBoolVal = !_stricmp(value, "true");
361 break;
362 case C_STRING:
363 co->value.stringVal = value;
364 break;
365 case EXT_BOOL:
366 *(co->value.extBoolVal) = !_stricmp(value, "true");
367 break;
368 default:
369 STARTUPMESSAGE("Config value type unknown: %d", co->type);
370 }
371 }
372 }
373
374 void DDrConfig_WriteTemplateIni()
375 {
376 FILE* fp;
377 STARTUPMESSAGE("%s doesn't exist, creating", iniName);
378 fp = fopen(iniName, "w");
379 if (fp)
380 {
381 for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
382 fprintf(fp, "[%s]\n", config[s].name);
383 }
384 fclose(fp);
385 }
386 }
387
388
389 void DDrConfig(int argc, char* argv[])
390 {
391 int i;
392 char* section;
393 char* option;
394 bool falseoption;
395
396 DDrConfig_InitExtBools();
397
398 if (GetFileAttributes(iniName) == INVALID_FILE_ATTRIBUTES)
399 DDrConfig_WriteTemplateIni();
400
401 STARTUPMESSAGE("Parsing daodan.ini...", 0);
402 if (!Inifile_Read(iniName, DDrIniCallback))
403 STARTUPMESSAGE("Error reading daodan.ini, check your syntax!", 0);
404 STARTUPMESSAGE("Finished parsing", 0);
405
406
407
408 STARTUPMESSAGE("Parsing command line...", 0);
409 for (i = 1; i < argc; i ++)
410 {
411 if (argv[i][0] == '-')
412 {
413 section = argv[i] + 1;
414 if ((option = strchr(argv[i], '.')))
415 {
416 *option = '\0';
417 falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] == 'o' || option[2] == 'O');
418 if (i < (argc - 1) && argv[i + 1][0] != '-')
419 DDrIniCallback(section, option + 1, argv[++i]);
420 else
421 DDrIniCallback(section, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true"));
422 *option = '.';
423 }
424 else
425 {
426 falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] == 'o' || section[1] == 'O');
427 if (i < (argc - 1) && argv[i + 1][0] != '-')
428 DDrIniCallback("options", section, argv[++i]);
429 else
430 DDrIniCallback("options", section + (falseoption ? 2 : 0), (falseoption ? "false" : "true"));
431 }
432 }
433 else
434 {
435 STARTUPMESSAGE("Parse error \"%s\"", argv[i]);
436 break;
437 }
438 }
439 STARTUPMESSAGE("Finished parsing", 0);
440 }
441
442
443 /*
444 case s_language:
445 else if (!_stricmp(name, "blam"))
446 DDrPatch__strdup((int*)(OniExe + 0x0010fb73), value);
447 else if (!_stricmp(name, "damn"))
448 DDrPatch__strdup((int*)(OniExe + 0x0010fb6e), value);
449 else if (!_stricmp(name, "savepoint"))
450 {
451 char* str = _strdup(value);
452 DDrPatch_Int32((int*)(OniExe + 0x000fd730), (int)str);
453 DDrPatch_Int32((int*)(OniExe + 0x000fd738), (int)str);
454 }
455 else if (!_stricmp(name, "syndicatewarehouse"))
456 {
457 char* str = _strdup(value);
458 DDrPatch_Int32((int*)(OniExe + 0x000fd71a), (int)str);
459 DDrPatch_Int32((int*)(OniExe + 0x0010ef75), (int)str);
460 }
461 else if (!_stricmp(name, "shapeshifter_on"))
462 DDr_CheatTable[0].message_on = _strdup(value);
463 else if (!_stricmp(name, "shapeshifter_off"))
464 DDr_CheatTable[0].message_off = _strdup(value);
465 else if (!_stricmp(name, "liveforever_on"))
466 DDr_CheatTable[1].message_on = _strdup(value);
467 else if (!_stricmp(name, "liveforever_off"))
468 DDr_CheatTable[1].message_off = _strdup(value);
469 else if (!_stricmp(name, "touchofdeath_on"))
470 DDr_CheatTable[2].message_on = _strdup(value);
471 else if (!_stricmp(name, "touchofdeath_off"))
472 DDr_CheatTable[2].message_off = _strdup(value);
473 else if (!_stricmp(name, "canttouchthis_on"))
474 DDr_CheatTable[3].message_on = _strdup(value);
475 else if (!_stricmp(name, "canttouchthis_off"))
476 DDr_CheatTable[3].message_off = _strdup(value);
477 else if (!_stricmp(name, "fatloot_on"))
478 DDr_CheatTable[4].message_on = _strdup(value);
479 else if (!_stricmp(name, "glassworld_on"))
480 DDr_CheatTable[5].message_on = _strdup(value);
481 else if (!_stricmp(name, "glassworld_off"))
482 DDr_CheatTable[5].message_off = _strdup(value);
483 else if (!_stricmp(name, "winlevel_on"))
484 DDr_CheatTable[6].message_on = _strdup(value);
485 else if (!_stricmp(name, "loselevel_on"))
486 DDr_CheatTable[7].message_on = _strdup(value);
487 else if (!_stricmp(name, "bighead_on"))
488 DDr_CheatTable[8].message_on = _strdup(value);
489 else if (!_stricmp(name, "bighead_off"))
490 DDr_CheatTable[8].message_off = _strdup(value);
491 else if (!_stricmp(name, "minime_on"))
492 DDr_CheatTable[9].message_on = _strdup(value);
493 else if (!_stricmp(name, "minime_off"))
494 DDr_CheatTable[9].message_off = _strdup(value);
495 else if (!_stricmp(name, "superammo_on"))
496 DDr_CheatTable[10].message_on = _strdup(value);
497 else if (!_stricmp(name, "superammo_off"))
498 DDr_CheatTable[10].message_off = _strdup(value);
499 else if (!_stricmp(name, "devmode_on"))
500 {
501 char* str = _strdup(value);
502 DDr_CheatTable[11].message_on = str;
503 DDr_CheatTable[cheat_x].message_on = str;
504 }
505 else if (!_stricmp(name, "devmode_off"))
506 {
507 char* str = _strdup(value);
508 DDr_CheatTable[11].message_off = str;
509 DDr_CheatTable[cheat_x].message_off = str;
510 }
511 else if (!_stricmp(name, "reservoirdogs_on"))
512 DDr_CheatTable[12].message_on = _strdup(value);
513 else if (!_stricmp(name, "reservoirdogs_off"))
514 DDr_CheatTable[12].message_off = _strdup(value);
515 else if (!_stricmp(name, "roughjustice_on"))
516 DDr_CheatTable[13].message_on = _strdup(value);
517 else if (!_stricmp(name, "roughjustice_off"))
518 DDr_CheatTable[13].message_off = _strdup(value);
519 else if (!_stricmp(name, "chenille_on"))
520 DDr_CheatTable[14].message_on = _strdup(value);
521 else if (!_stricmp(name, "chenille_off"))
522 DDr_CheatTable[14].message_off = _strdup(value);
523 else if (!_stricmp(name, "behemoth_on"))
524 DDr_CheatTable[15].message_on = _strdup(value);
525 else if (!_stricmp(name, "behemoth_off"))
526 DDr_CheatTable[15].message_off = _strdup(value);
527 else if (!_stricmp(name, "elderrune_on"))
528 DDr_CheatTable[16].message_on = _strdup(value);
529 else if (!_stricmp(name, "elderrune_off"))
530 DDr_CheatTable[16].message_off = _strdup(value);
531 else if (!_stricmp(name, "moonshadow_on"))
532 DDr_CheatTable[17].message_on = _strdup(value);
533 else if (!_stricmp(name, "moonshadow_off"))
534 DDr_CheatTable[17].message_off = _strdup(value);
535 else if (!_stricmp(name, "munitionfrenzy_on"))
536 DDr_CheatTable[18].message_on = _strdup(value);
537 else if (!_stricmp(name, "fistsoflegend_on"))
538 DDr_CheatTable[19].message_on = _strdup(value);
539 else if (!_stricmp(name, "fistsoflegend_off"))
540 DDr_CheatTable[19].message_off = _strdup(value);
541 else if (!_stricmp(name, "killmequick_on"))
542 DDr_CheatTable[20].message_on = _strdup(value);
543 else if (!_stricmp(name, "killmequick_off"))
544 DDr_CheatTable[20].message_off = _strdup(value);
545 else if (!_stricmp(name, "carousel_on"))
546 DDr_CheatTable[21].message_on = _strdup(value);
547 else if (!_stricmp(name, "carousel_off"))
548 DDr_CheatTable[21].message_off = _strdup(value);
549 */
550