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

Diff Legend

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