ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/Daodan_Config.c
(Generate patch)

Comparing Daodan/src/Daodan_Config.c (file contents):
Revision 993 by alloc, Sun Apr 6 17:06:02 2014 UTC vs.
Revision 1007 by alloc, Fri Jul 4 15:42:25 2014 UTC

# Line 1 | Line 1
1   #include <windows.h>
2   #include <string.h>
3 + #include <time.h>
4  
4 #include "Daodan_Cheater.h"
5   #include "Daodan_Config.h"
6   #include "Daodan_Patch.h"
7 < #include "Daodan_Utility.h"
7 > #include "Patches/Utility.h"
8  
9   #include "Oni/Oni.h"
10 + #include "_Version.h"
11  
12   #include "Inifile_Reader.h"
13  
14   #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
15  
16   static const char* iniName = "daodan.ini";
17 + static const char* helpFile = "daodan_help.txt";
18 +
19 + static const char* defaultSection = "options";
20 +
21 + static char invalidCurParamaters[2000] = "";
22 + static char invalidTotalParamaters[4000] = "";
23 +
24 + void DDrConfig_PrintHelp();
25 +
26  
27   ConfigSection_t config[] = {
28 <        { "patches", "Patches", {
29 <                { "alttab",
30 <                        "Allows user to switch applications while in Oni (Alt-Tab) and use Windows key, however it may enable the screensaver as well.",
31 <                        C_BOOL,
32 <                        {.intBoolVal = true},
33 <                        {.intBoolVal = true} },
34 <                { "argb8888",
35 <                        "Textures using ARGB8888 can be used.",
36 <                        C_BOOL,
37 <                        {.intBoolVal = true},
38 <                        {.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.",
28 >        { "", "Command line only", {
29 >                { "help",
30 >                        "Generates this help file.",
31 >                        C_CMD,
32 >                        {.intBoolVal = 0},
33 >                        {.callback = DDrConfig_PrintHelp} },
34 >                { 0, 0, 0, {0}, {0} }
35 >        } },
36 >        { "devmode", "Developer Mode", {
37 >                { "highres_console",
38 >                        "Fixes bug where console line becomes invisible at higher resolutions.",
39                          C_BOOL,
40                          {.intBoolVal = true},
41                          {.intBoolVal = true} },
42 <                { "cheater",
43 <                        "Adds new cheat codes (see section below).",
42 >                { "showtriggervolumes",
43 >                        "Allows BSL variable \"show_triggervolumes\" and Ctrl+Shift+X (in devmode) to work.",
44                          C_BOOL,
45                          {.intBoolVal = true},
46                          {.intBoolVal = true} },
47 +                { 0, 0, 0, {0}, {0} }
48 +        } },
49 +        { "gameplay", "Gameplay", {
50                  { "cheatsenabled",
51                          "Enables cheats without having to beat the game first.",
52                          C_BOOL,
53                          {.intBoolVal = true},
54                          {.intBoolVal = true} },
55                  { "cheattable",
56 <                        "Replaces Oni's cheat table with table that includes new cheats (see section below).",
56 >                        "Replaces Oni's cheat table with table that includes new cheats including devmode.",
57                          C_BOOL,
58                          {.intBoolVal = true},
59                          {.intBoolVal = true} },
60 <                { "chinese",
61 <                        "Allow for chinese fonts to be shown.",
60 >                { "cooldowntimer",
61 >                        "Disables weapon cooldown exploit.",
62                          C_BOOL,
63                          {.intBoolVal = true},
64                          {.intBoolVal = true} },
65 <                { "clipcursor",
66 <                        "Limit cursor to Oni's window.",
65 >                { "kickguns",
66 >                        "EXPERIMENTAL! Unfinished, do not use.",
67 >                        C_BOOL,
68 >                        {.intBoolVal = false},
69 >                        {.intBoolVal = false} },
70 >                { "pathfinding",
71 >                        "Size of pathfinding grid cache increased by eight times in order to prevent crashes in large levels.",
72                          C_BOOL,
73                          {.intBoolVal = true},
74                          {.intBoolVal = true} },
75 <                { "cooldowntimer",
76 <                        "Disables weapon cooldown exploit.",
75 >                { "projaware",
76 >                        "Allows AI to dodge incoming gunfire properly.",
77                          C_BOOL,
78                          {.intBoolVal = true},
79                          {.intBoolVal = true} },
80 <                { "daodandisplayenum",
81 <                        "Offers more display modes in the Options menu.",
80 >                { "throwtest",
81 >                        "EXPERIMENTAL! Experiment with allowing enemies to be thrown over railings.",
82 >                        C_BOOL,
83 >                        {.intBoolVal = false},
84 >                        {.intBoolVal = false} },
85 >                { "wpfadetime",
86 >                        "Adds working function for existing BSL command wp_fadetime, sets fade time to 4800.",
87                          C_BOOL,
88                          {.intBoolVal = true},
89                          {.intBoolVal = true} },
90 <                { "directinput",
91 <                        "Forces on DirectInput.",
90 >                { 0, 0, 0, {0}, {0} }
91 >        } },
92 >        { "graphics", "Graphics", {
93 >                { "binkplay",
94 >                        "Fix binkplay calls to use GDI and outro same mode as intro.",
95                          C_BOOL,
96                          {.intBoolVal = true},
97                          {.intBoolVal = true} },
98 <                { "disablecmdline",
99 <                        "Replaces existing command line parser with Daodan's in order to add new commands. Meant to be used with getcmdline.",
98 >                { "daodangl",
99 >                        "Provides an improved windowed mode (-noswitch).",
100                          C_BOOL,
101                          {.intBoolVal = true},
102                          {.intBoolVal = true} },
103 <                { "fonttexturecache",
104 <                        "Doubles size of font texture cache.",
103 >                { "displayenum",
104 >                        "Offers a more accurate list of available display modes in the Options menu.",
105                          C_BOOL,
106                          {.intBoolVal = true},
107                          {.intBoolVal = true} },
108 <                { "getcmdline",
109 <                        "Replaces existing command line parser with Daodan's in order to add new commands. Meant to be used with disablecmdline.",
108 >                { "gamma",
109 >                        "Enable gamma slider in fullscreen, disable in windowed mode.",
110                          C_BOOL,
111                          {.intBoolVal = true},
112                          {.intBoolVal = true} },
113 <                { "hdscreens_lowres",
114 <                        "???",
113 >                { "newweap",
114 >                        "Standing above a weapon displays a message containing the weapon name and amount of ammo.",
115                          C_BOOL,
116                          {.intBoolVal = true},
117                          {.intBoolVal = true} },
118 <                { "highres_console",
119 <                        "Fixes bug where console line becomes invisible at higher resolutions.",
118 >                { "optionsvisible",
119 >                        "Always show options button in main menu, even when pausing from a game.",
120                          C_BOOL,
121                          {.intBoolVal = true},
122                          {.intBoolVal = true} },
123 <                { "kickguns",
124 <                        "Unfinished, do not use.",
123 >                { "showalllasersights",
124 >                        "Show all (also enemies') weapon lasersights.",
125                          C_BOOL,
126                          {.intBoolVal = false},
127                          {.intBoolVal = false} },
128 <                { "largetextures",
129 <                        "Textures up to 512x512 can be used.",
128 >                { "widescreenportraits",
129 >                        "Prevents fly-in portraits from being stretched when playing in widescreen resolutions.",
130                          C_BOOL,
131                          {.intBoolVal = true},
132                          {.intBoolVal = true} },
133 <                { "levelplugins",
134 <                        "Allows level files to be loaded from the GDF which do not end in \"_Final\".",
133 >                { 0, 0, 0, {0}, {0} }
134 >        } },
135 >        { "language", "Language", {
136 >                { "chinese",
137 >                        "Allow for chinese fonts to be shown if the required DLL is available.",
138                          C_BOOL,
139                          {.intBoolVal = true},
140                          {.intBoolVal = true} },
141 <                { "newweap",
142 <                        "Picking up a weapon displays a message containing the weapon name and amount of ammo.",
141 >                { "fonttexturecache",
142 >                        "Doubles size of font texture cache.",
143                          C_BOOL,
144                          {.intBoolVal = true},
145                          {.intBoolVal = true} },
146 +                { "language",
147 +                        "Localization for hardcoded strings (e.g. \"Savepoints\").",
148 +                        C_STRING,
149 +                        {.stringVal = "en"},
150 +                        {.stringVal = "en"} },
151                  { "nomultibyte",
152                          "Enables languages which use multibyte coding (such as Chinese).",
153                          C_BOOL,
154                          {.intBoolVal = true},
155                          {.intBoolVal = true} },
156 <                { "optionsvisible",
157 <                        "Always show options button in main menu, even when pausing from a game.",
158 <                        C_BOOL,
159 <                        {.intBoolVal = true},
160 <                        {.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.",
156 >                { 0, 0, 0, {0}, {0} }
157 >        } },
158 >        { "modding", "Modding", {
159 >                { "argb8888",
160 >                        "Allows using textures with ARGB8888.",
161                          C_BOOL,
162                          {.intBoolVal = true},
163                          {.intBoolVal = true} },
164 <                { "safeprintf",
165 <                        "Replaces Oni's function that prints to startup.txt with a safer one.",
164 >                { "d_regen",
165 >                        "Enables script command d_regen (query/set regeneration for any character).",
166                          C_BOOL,
167                          {.intBoolVal = true},
168                          {.intBoolVal = true} },
169 <                { "showalllasersights",
170 <                        "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.",
169 >                { "daodanbsl",
170 >                        "Adds new BSL commands.",
171                          C_BOOL,
172                          {.intBoolVal = true},
173                          {.intBoolVal = true} },
174 <                { "throwtest",
175 <                        "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.",
174 >                { "hdscreens_lowres",
175 >                        "Allow HD intro/ending screens on game resolutions smaller than 1024x768.",
176                          C_BOOL,
177                          {.intBoolVal = true},
178                          {.intBoolVal = true} },
179 <                { "usegettickcount",
180 <                        "Replaces Oni's timing functions with more accurate ones.",
179 >                { "largetextures",
180 >                        "Textures up to 512x512 can be used.",
181                          C_BOOL,
182                          {.intBoolVal = true},
183                          {.intBoolVal = true} },
184 <                { "wpfadetime",
185 <                        "Adds working function for existing BSL command wp_fadetime, sets fade time to 4800.",
184 >                { "levelplugins",
185 >                        "Allows level files to be loaded which do not end in \"_Final\".",
186                          C_BOOL,
187                          {.intBoolVal = true},
188                          {.intBoolVal = true} },
189                  { 0, 0, 0, {0}, {0} }
190          } },
191 <        { "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} },
191 >        { "oni", "Original Oni Options", {
192                  { "debug",
193 <                        "???",
193 >                        "Not useful, probably does nothing.",
194                          EXT_BOOL,
195                          {.intBoolVal = false },
196                          {.extBoolVal = &AKgDebug_DebugMaps } },
197                  { "debugfiles",
198 <                        "???",
198 >                        "Logs called BSL functions to script_debug.txt.",
199                          EXT_BOOL,
200                          {.intBoolVal = false },
201                          {.extBoolVal = &BFgDebugFileEnable } },
202                  { "findsounds",
203 <                        "???",
203 >                        "Not useful, extends output of sound_list_broken_links.",
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} },
207                  { "ignore_private_data",
208 <                        "???",
208 >                        "Not useful, probably does nothing.",
209                          EXT_BOOL,
210                          {.intBoolVal = false },
211                          {.extBoolVal = &opt_ignore_private_data } },
212                  { "sound",
213 <                        "???",
213 >                        "Enable sound.",
214                          EXT_BOOL,
215                          {.intBoolVal = true },
216                          {.extBoolVal = &opt_sound } },
217                  { "switch",
218 <                        "Always switch screen to resolution on Oni's Options screen, making the game fullscreen; opposite of Oni's built-in argument \"noswitch\".",
218 >                        "Switch to fullscreen instead of staying in a window.",
219                          EXT_BOOL,
220                          {.intBoolVal = true},
221                          {.extBoolVal = &M3gResolutionSwitch} },
222 +                { 0, 0, 0, {0}, {0} }
223 +        } },
224 +        { "windows", "Windows", {
225 +                { "alttab",
226 +                        "Allows to Alt-Tab out of Oni and use Windows key. May enable the screensaver as well.",
227 +                        C_BOOL,
228 +                        {.intBoolVal = true},
229 +                        {.intBoolVal = true} },
230 +                { "border",
231 +                        "Add a border if in windowed mode and \"usedaodangl\" patch is active.",
232 +                        C_BOOL,
233 +                        {.intBoolVal = true},
234 +                        {.intBoolVal = true} },
235 +                { "clipcursor",
236 +                        "Limit cursor to Oni's window.",
237 +                        C_BOOL,
238 +                        {.intBoolVal = true},
239 +                        {.intBoolVal = true} },
240 +                { "directinput",
241 +                        "Enforces the usage of DirectInput on every system. Should be off for Linux/Wine.",
242 +                        C_BOOL,
243 +                        {.intBoolVal = true},
244 +                        {.intBoolVal = true} },
245 +                { "disablecmdline",
246 +                        "Disables Oni's existing command line parser as Daodan has its own.",
247 +                        C_BOOL,
248 +                        {.intBoolVal = true},
249 +                        {.intBoolVal = true} },
250 +                { "killvtune",
251 +                        "Prevent loading of vtuneapi.dll.",
252 +                        C_BOOL,
253 +                        {.intBoolVal = false},
254 +                        {.intBoolVal = false} },
255 +                { "safeprintf",
256 +                        "Replaces Oni's function that prints to startup.txt with a safer one.",
257 +                        C_BOOL,
258 +                        {.intBoolVal = true},
259 +                        {.intBoolVal = true} },
260                  { "topmost",
261                          "Keep game window on top in windowed mode, even when switching applications.",
262                          C_BOOL,
263                          {.intBoolVal = false},
264                          {.intBoolVal = false} },
265 <                { "usedaodanbsl",
266 <                        "Adds new BSL commands (see below).",
265 >                { "usegettickcount",
266 >                        "Replaces Oni's timing functions with more accurate ones.",
267                          C_BOOL,
268                          {.intBoolVal = true},
269                          {.intBoolVal = true} },
237                { "language",
238                        "Localization for hardcoded strings (e.g. \"Savepoints\").",
239                        C_STRING,
240                        {.stringVal = "en"},
241                        {.stringVal = "en"} },
270                  { 0, 0, 0, {0}, {0} }
271          } }
272   };
# Line 255 | Line 283 | void DDrConfig_Print()
283                                  case EXT_BOOL:
284                                          STARTUPMESSAGE("Option %s.%s = %d (def %d)", config[s].name, co->name, *co->value.extBoolVal, co->defaultValue.intBoolVal);
285                                          break;
286 +                                case C_CMD:
287 +                                        break;
288                                  default:
289                                          STARTUPMESSAGE("Option %s.%s = %d (def %d)", config[s].name, co->name, co->value.intBoolVal, co->defaultValue.intBoolVal);
290                          }
# Line 262 | Line 292 | void DDrConfig_Print()
292          }
293   }
294  
295 + void DDrConfig_PrintHelp()
296 + {
297 +        STARTUPMESSAGE("Writing Daodan help file (%s)", helpFile);
298 +
299 +        FILE* fp;
300 +        remove(helpFile);
301 +        fp = fopen(helpFile, "w");
302 +        if (fp)
303 +        {
304 +                time_t rawtime;
305 +                struct tm* timeinfo;
306 +                char buffer[80];
307 +                time(&rawtime);
308 +                timeinfo = localtime(&rawtime);
309 +                strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
310 +                
311 +                fprintf(fp, "Daodan help - generated on %s for Daodan v."DAODAN_VERSION_STRING"\n\n", buffer);
312 +                fprintf(fp, "List of Daodan configuration parameters:\n");
313 +                for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
314 +                        fprintf(fp, "    %s - %s:\n", config[s].name, config[s].description);
315 +                        for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
316 +                                char* name = co->name;
317 +                                char* desc = co->description;
318 +                                const char* tName = DDrConfig_GetOptionTypeName(co->type);
319 +                                const char* val = DDrConfig_GetOptionValueString(co, 1);
320 +                                if (!val)
321 +                                        val = "";
322 +                                fprintf(fp, "        %-22s %6s=%-5s %s\n", name, tName, val, desc);
323 +                        }
324 +                        fprintf(fp, "\n");
325 +                }
326 +                fprintf(fp, "\nConfiguration parameters can be either set in daodan.ini or passed on command line.\n\n");
327 +                fprintf(fp, "In daodan.ini each section of parameters has its own section in the ini file started by [section name]. Parameters are given within that section by their name only, followed by an equals sign and the desired value. Example:\n");
328 +                fprintf(fp, "    [sectionX]\n    parameterName = false\n");
329 +                fprintf(fp, "\nTo pass the parameter on the command line:\n");
330 +                fprintf(fp, "    Oni.exe -parameterName false\n");
331 +                fprintf(fp, "For bool parameters the value can be ommitted so it is regarded as \"true\":\n");
332 +                fprintf(fp, "    Oni.exe -parameterName\n");
333 +                fprintf(fp, "To disable a bool parameter you can prefix \"no\" to the parameter name like this:\n");
334 +                fprintf(fp, "    Oni.exe -noparameterName\n");
335 +
336 +                fclose(fp);
337 +        }
338 +        else
339 +        {
340 +                STARTUPMESSAGE("Writing Daodan help file failed", 0);
341 +        }
342 + }
343 +
344   const char* DDrConfig_GetOptionTypeName(OptionType_t type)
345   {
346          switch (type) {
# Line 271 | Line 350 | const char* DDrConfig_GetOptionTypeName(
350                          return "Bool";
351                  case C_STRING:
352                          return "String";
353 +                case C_CMD:
354 +                        return "Cmd";
355                  case EXT_BOOL:
356                          return "pBool";
357                  default:
# Line 278 | Line 359 | const char* DDrConfig_GetOptionTypeName(
359          }
360   }
361  
362 + const char* DDrConfig_GetOptionValueString(ConfigOption_t* opt, char printdefault)
363 + {
364 +        OptionValue_t* optVal = (printdefault ? &opt->defaultValue : &opt->value);
365 +        int boolV = optVal->intBoolVal;
366 +        char* val = 0;
367 +        switch (opt->type) {
368 +                case C_STRING:
369 +                        return optVal->stringVal;
370 +                case EXT_BOOL:
371 +                        if (printdefault)
372 +                                return (boolV ? "true" : "false");
373 +                        else
374 +                                return (*optVal->extBoolVal ? "true" : "false");
375 +                case C_BOOL:
376 +                        return (boolV ? "true" : "false");
377 +                case C_CMD:
378 +                        return 0;
379 +                default:
380 +                        val = malloc(20);
381 +                        sprintf(val, "%d", boolV);
382 +                        return val;
383 +        }
384 + }
385 +
386 + char DDrConfig_NonDefaultOptionValue(ConfigOption_t* opt)
387 + {
388 +        switch (opt->type) {
389 +                case C_STRING:
390 +                        return _stricmp(opt->defaultValue.stringVal, opt->value.stringVal);
391 +                case EXT_BOOL:
392 +                        return !opt->defaultValue.intBoolVal != !*opt->value.extBoolVal;
393 +                case C_BOOL:
394 +                        return !opt->defaultValue.intBoolVal != !opt->value.intBoolVal;
395 +                case C_CMD:
396 +                        return 0;
397 +                case C_INT:
398 +                        return opt->defaultValue.intBoolVal != opt->value.intBoolVal;
399 +        }
400 +        return 0;
401 + }
402 +
403   static ConfigOption_t* DDrConfig_GetOption(const char* fullOptName)
404   {
405          char section[50];
# Line 290 | Line 412 | static ConfigOption_t* DDrConfig_GetOpti
412          }
413          *option++ = 0;
414  
415 +        char isWildcardSection = !_stricmp(section, "*");
416 +
417          for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
418 <                if (!_stricmp(config[s].name, section)) {
418 >                if (isWildcardSection || !_stricmp(config[s].name, section)) {
419                          for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
420                                  if (!_stricmp(co->name, option)) {
421                                          return co;
422                                  }
423                          }
424 <                        STARTUPMESSAGE("Could not find option \"%s\" in section \"%s\"", option, section);
425 <                        return 0;
424 >                        if (!isWildcardSection) {
425 >                                STARTUPMESSAGE("Could not find option \"%s\" in section \"%s\"", option, section);
426 >                                return 0;
427 >                        }
428                  }
429          }
430 <        STARTUPMESSAGE("Could not find section \"%s\" for option \"%s\"", section, option);
430 >        if (!isWildcardSection)
431 >                STARTUPMESSAGE("Could not find section \"%s\" for option \"%s\"", section, option);
432 >        else
433 >                STARTUPMESSAGE("Could not find option \"%s\"", option);
434          return 0;
435   }
436  
# Line 321 | Line 450 | ConfigOption_t* DDrConfig_GetOptOfType(c
450   }
451  
452  
453 +
454   void DDrConfig_InitExtBools()
455   {
456          for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
# Line 334 | Line 464 | void DDrConfig_InitExtBools()
464  
465  
466  
467 < void DDrIniCallback(char* section, char* name, char* value)
467 > void DDrConfig_WriteIni()
468 > {
469 >        FILE* fp;
470 >        STARTUPMESSAGE("%s doesn't exist, creating", iniName);
471 >        fp = fopen(iniName, "w");
472 >        if (fp)
473 >        {
474 >                for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
475 >                        if (strlen(config[s].name)) {
476 >                                fprintf(fp, "[%s]\n", config[s].name);
477 >                                for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
478 >                                        char* name = co->name;
479 >                                        const char* val = DDrConfig_GetOptionValueString(co, 0);
480 >                                        if (val && DDrConfig_NonDefaultOptionValue(co))
481 >                                                fprintf(fp, "%s = %s\n", name, val);
482 >                                }
483 >                                fprintf(fp, "\n");
484 >                        }
485 >                }
486 >                fclose(fp);
487 >        }
488 >        else
489 >        {
490 >                STARTUPMESSAGE("Writing %s template file failed", iniName);
491 >        }
492 > }
493 >
494 >
495 > void DDrIniCallback(const char* section, const char* name, const char* value)
496   {
339        static char curSection[20];
497          char fullOptName[50];
498  
499          if (!_stricmp(section, "patch"))
500                  section = "patches";
501  
502 <        strcpy(curSection, section);
503 <
504 <        strcpy(fullOptName, curSection);
348 <        fullOptName[strlen(curSection)] = '.';
349 <        strcpy(fullOptName+strlen(curSection)+1, name);
502 >        strcpy(fullOptName, section);
503 >        fullOptName[strlen(section)] = '.';
504 >        strcpy(fullOptName+strlen(section)+1, name);
505  
506          ConfigOption_t* co = DDrConfig_GetOption(fullOptName);
507  
508          if (co)
509          {
510 +                char* buf = 0;
511                  switch (co->type) {
512                          case C_INT:
513                                  co->value.intBoolVal = strtol(value, NULL, 0);
# Line 360 | Line 516 | void DDrIniCallback(char* section, char*
516                                  co->value.intBoolVal = !_stricmp(value, "true");
517                                  break;
518                          case C_STRING:
519 <                                co->value.stringVal = value;
519 >                                buf = malloc(strlen(value)+1);
520 >                                strcpy(buf, value);
521 >                                co->value.stringVal = buf;
522 >                                break;
523 >                        case C_CMD:
524 >                                co->value.callback();
525                                  break;
526                          case EXT_BOOL:
527                                  *(co->value.extBoolVal) = !_stricmp(value, "true");
# Line 368 | Line 529 | void DDrIniCallback(char* section, char*
529                          default:
530                                  STARTUPMESSAGE("Config value type unknown: %d", co->type);
531                  }
532 +        } else {
533 +                char buf[100];
534 +                if (!_stricmp(section, "*"))
535 +                        sprintf(buf, "  %s\n", name);
536 +                else
537 +                        sprintf(buf, "  %s.%s\n", section, name);
538 +                if (strlen(buf) + strlen(invalidCurParamaters) < sizeof(invalidCurParamaters) - 1) {
539 +                        strcpy(invalidCurParamaters + strlen(invalidCurParamaters), buf);
540 +                }
541          }
542   }
543  
544 < void DDrConfig_WriteTemplateIni()
544 >
545 > bool DDrConfig_ParseCommandLine(int argc, char* argv[])
546   {
547 <        FILE* fp;
377 <        STARTUPMESSAGE("%s doesn't exist, creating", iniName);
378 <        fp = fopen(iniName, "w");
379 <        if (fp)
547 >        for (int i = 1; i < argc; i ++)
548          {
549 <                for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
550 <                        fprintf(fp, "[%s]\n", config[s].name);
549 >                if (argv[i][0] == '-')
550 >                {
551 >                        char* option;
552 >                        bool invertedOption;
553 >
554 >                        option = argv[i]+1;
555 >
556 >                        invertedOption = (option[0] == 'n' || option[0] == 'N') && (option[1] == 'o' || option[1] == 'O');
557 >                        if (invertedOption)
558 >                                option += 2;
559 >
560 >                        if (i < (argc - 1) && argv[i+1][0] != '-')
561 >                        // Has value in next field
562 >                        {
563 >                                DDrIniCallback("*", option, argv[++i]);
564 >                        }
565 >                        else
566 >                        // Implicit value
567 >                        {
568 >                                DDrIniCallback("*", option, (invertedOption ? "false" : "true"));
569 >                        }
570 >                }
571 >                else
572 >                {
573 >                        STARTUPMESSAGE("Parse error \"%s\"", argv[i]);
574 >                        return false;
575                  }
384                fclose(fp);
576          }
577 +        return true;
578   }
579  
388
580   void DDrConfig(int argc, char* argv[])
581   {
582 <        int i;
392 <        char* section;
393 <        char* option;
394 <        bool falseoption;
395 <
582 >        STARTUPMESSAGE("Initializing standard booleans", 0);
583          DDrConfig_InitExtBools();
584  
585          if (GetFileAttributes(iniName) == INVALID_FILE_ATTRIBUTES)
586 <                DDrConfig_WriteTemplateIni();
586 >                DDrConfig_WriteIni();
587          
588          STARTUPMESSAGE("Parsing daodan.ini...", 0);
589          if (!Inifile_Read(iniName, DDrIniCallback))
590                  STARTUPMESSAGE("Error reading daodan.ini, check your syntax!", 0);
591          STARTUPMESSAGE("Finished parsing", 0);
592  
593 <
593 >        if (strlen(invalidCurParamaters) > 0)
594 >        {
595 >                sprintf(invalidTotalParamaters, "In %s:\n%s\n", iniName, invalidCurParamaters);
596 >                invalidCurParamaters[0] = 0;
597 >        }
598  
599          STARTUPMESSAGE("Parsing command line...", 0);
600 <        for (i = 1; i < argc; i ++)
600 >        DDrConfig_ParseCommandLine(argc, argv);
601 >        STARTUPMESSAGE("Finished parsing", 0);
602 >
603 >        if (strlen(invalidCurParamaters) > 0)
604          {
605 <                if (argv[i][0] == '-')
606 <                {
607 <                        section = argv[i] + 1;
608 <                        if ((option = strchr(argv[i], '.')))
609 <                        {
610 <                                *option = '\0';
611 <                                falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] == 'o' || option[2] == 'O');
612 <                                if (i < (argc - 1) && argv[i + 1][0] != '-')
613 <                                        DDrIniCallback(section, option + 1, argv[++i]);
614 <                                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;
605 >                sprintf(invalidTotalParamaters, "%sOn command line:\n%s\n", invalidTotalParamaters, invalidCurParamaters);
606 >        }
607 >
608 >        if (strlen(invalidTotalParamaters) > 0)
609 >        {
610 >                char msg[4096];
611 >                sprintf(msg, "Invalid parameters given:\n%sContinue launching Oni?", invalidTotalParamaters);
612 >                int res = MessageBox(NULL, msg, "Parameters invalid", MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON1);
613 >                if (res == IDNO) {
614 >                        exit(0);
615                  }
616          }
439        STARTUPMESSAGE("Finished parsing", 0);
440 }
617  
618 +        DDrConfig_WriteIni();
619  
620 < /*
621 <                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 < */      
620 > //      DDrConfig_Print();
621 > }
622  

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)