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 983 by alloc, Sun Mar 16 20:06:52 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_Symbols.h"
9 > #include "Oni/Oni.h"
10 > #include "_Version.h"
11  
12   #include "Inifile_Reader.h"
13  
14 < bool patch_alttab = true;
14 < bool patch_argb8888 = true;
15 < bool patch_binkplay = true;
16 < bool patch_bsl = true;
17 < bool patch_cheater = true;
18 < bool patch_cheatsenabled = true;
19 < bool patch_cheattable = true;
20 < bool patch_clipcursor = true;
21 < bool patch_cooldowntimer = true;
22 < bool patch_daodandisplayenum = true;
23 < bool patch_directinput = true;
24 < bool patch_disablecmdline = true;
25 < bool patch_flatline = true;
26 < bool patch_fonttexturecache = true;
27 < bool patch_getcmdline = true;
28 < bool patch_hdscreens_lowres = true;
29 < bool patch_highres_console = true;
30 < bool patch_kickguns = false;
31 < bool patch_killvtune = true;
32 < bool patch_largetextures = true;
33 < bool patch_levelplugins = true;
34 < bool patch_newweapon = true;
35 < bool patch_nomultibyte = true;
36 < bool patch_optionsvisible = true;
37 < bool patch_particledisablebit = false;
38 < bool patch_pathfinding = true;
39 < bool patch_projaware = true;
40 < bool patch_safeprintf = true;
41 < bool patch_showalllasersights = false;
42 < bool patch_throwtest = false;
43 < bool patch_usedaodangl = true;
44 < bool patch_usegettickcount = true;
45 < bool patch_wpfadetime = true;
46 <
47 < bool opt_border = true;
48 < bool opt_gamma = true;
49 < bool opt_topmost = false;
50 < bool opt_usedaodanbsl = true;
14 > #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
15  
16 < bool patch_chinese = true;
16 > static const char* iniName = "daodan.ini";
17 > static const char* helpFile = "daodan_help.txt";
18  
19 + static const char* defaultSection = "options";
20  
21 < enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section;
21 > static char invalidCurParamaters[2000] = "";
22 > static char invalidTotalParamaters[4000] = "";
23 >
24 > void DDrConfig_PrintHelp();
25 >
26 >
27 > ConfigSection_t config[] = {
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 >                { "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 >                { "characterawareness",
51 >                        "Makes AI remember the player.",
52 >                        C_BOOL,
53 >                        {.intBoolVal = true},
54 >                        {.intBoolVal = true} },
55 >                { "cheatsenabled",
56 >                        "Enables cheats without having to beat the game first.",
57 >                        C_BOOL,
58 >                        {.intBoolVal = true},
59 >                        {.intBoolVal = true} },
60 >                { "cheattable",
61 >                        "Replaces Oni's cheat table with table that includes new cheats including devmode.",
62 >                        C_BOOL,
63 >                        {.intBoolVal = true},
64 >                        {.intBoolVal = true} },
65 >                { "cooldowntimer",
66 >                        "Disables weapon cooldown exploit.",
67 >                        C_BOOL,
68 >                        {.intBoolVal = true},
69 >                        {.intBoolVal = true} },
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 >                { "projaware",
81 >                        "Allows AI to dodge incoming gunfire properly.",
82 >                        C_BOOL,
83 >                        {.intBoolVal = true},
84 >                        {.intBoolVal = true} },
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 >                { 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 >                { "daodangl",
104 >                        "Provides an improved windowed mode (-noswitch).",
105 >                        C_BOOL,
106 >                        {.intBoolVal = true},
107 >                        {.intBoolVal = true} },
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 >                { "gamma",
114 >                        "Enable gamma slider in fullscreen, disable in windowed mode.",
115 >                        C_BOOL,
116 >                        {.intBoolVal = true},
117 >                        {.intBoolVal = true} },
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 >                { "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 >                { "showalllasersights",
129 >                        "Show all (also enemies') weapon lasersights.",
130 >                        C_BOOL,
131 >                        {.intBoolVal = false},
132 >                        {.intBoolVal = false} },
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 >                { 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 >                { "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 >                { 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 >                { "d_regen",
170 >                        "Enables script command d_regen (query/set regeneration for any character).",
171 >                        C_BOOL,
172 >                        {.intBoolVal = true},
173 >                        {.intBoolVal = true} },
174 >                { "daodanbsl",
175 >                        "Adds new BSL commands.",
176 >                        C_BOOL,
177 >                        {.intBoolVal = true},
178 >                        {.intBoolVal = true} },
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 >                { "largetextures",
185 >                        "Textures up to 512x512 can be used.",
186 >                        C_BOOL,
187 >                        {.intBoolVal = true},
188 >                        {.intBoolVal = true} },
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 >        { "oni", "Original Oni Options", {
197 >                { "debug",
198 >                        "Not useful, probably does nothing.",
199 >                        EXT_BOOL,
200 >                        {.intBoolVal = false },
201 >                        {.extBoolVal = &AKgDebug_DebugMaps } },
202 >                { "debugfiles",
203 >                        "Logs called BSL functions to script_debug.txt.",
204 >                        EXT_BOOL,
205 >                        {.intBoolVal = false },
206 >                        {.extBoolVal = &BFgDebugFileEnable } },
207 >                { "findsounds",
208 >                        "Not useful, extends output of sound_list_broken_links.",
209 >                        EXT_BOOL,
210 >                        {.intBoolVal = false },
211 >                        {.extBoolVal = &SSgSearchOnDisk } },
212 >                { "ignore_private_data",
213 >                        "Not useful, probably does nothing.",
214 >                        EXT_BOOL,
215 >                        {.intBoolVal = false },
216 >                        {.extBoolVal = &opt_ignore_private_data } },
217 >                { "sound",
218 >                        "Enable sound.",
219 >                        EXT_BOOL,
220 >                        {.intBoolVal = true },
221 >                        {.extBoolVal = &opt_sound } },
222 >                { "switch",
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 >                { "usegettickcount",
271 >                        "Replaces Oni's timing functions with more accurate ones.",
272 >                        C_BOOL,
273 >                        {.intBoolVal = true},
274 >                        {.intBoolVal = true} },
275 >                { 0, 0, 0, {0}, {0} }
276 >        } }
277 > };
278  
279 < bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
279 >
280 > void DDrConfig_Print()
281 > {
282 >        for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
283 >                for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
284 >                        switch (co->type) {
285 >                                case C_STRING:
286 >                                        STARTUPMESSAGE("Option %s.%s = %s (def %s)", config[s].name, co->name, co->value.stringVal, co->defaultValue.stringVal);
287 >                                        break;
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 >                        }
296 >                }
297 >        }
298 > }
299 >
300 > void DDrConfig_PrintHelp()
301   {
302 <        if (newsection)
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 <                if (!_stricmp(section, "options"))
310 <                        ini_section = s_options;
311 <                else if (!_stricmp(section, "patch"))
312 <                        ini_section = s_patch;
313 <                else if (!_stricmp(section, "bsl"))
314 <                        ini_section = s_bsl;
315 <                else if (!_stricmp(section, "language"))
316 <                        ini_section = s_language;
317 <                else
318 <                {
319 <                        ini_section = s_unknown;
320 <                        DDrStartupMessage("Daodan: Unrecognised ini section \"%s\"", section);
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 <        
76 <        switch (ini_section)
343 >        else
344          {
345 <                case s_options:
346 <                        if (!_stricmp(name, "border"))
347 <                                opt_border = !_stricmp(inifile_cleanstr(value), "true");
348 <                        else if (!_stricmp(name, "debug"))
349 <                                AKgDebug_DebugMaps = !_stricmp(inifile_cleanstr(value), "true");
350 <                        else if (!_stricmp(name, "debugfiles"))
351 <                                BFgDebugFileEnable = !_stricmp(inifile_cleanstr(value), "true");
352 <                        else if (!_stricmp(name, "findsounds"))
353 <                                SSgSearchOnDisk = !_stricmp(inifile_cleanstr(value), "true");
354 <                        else if (!_stricmp(name, "gamma"))
355 <                                opt_gamma = !_stricmp(inifile_cleanstr(value), "true");
356 <                        else if (!_stricmp(name, "ignore_private_data"))
357 <                                opt_ignore_private_data = !_stricmp(inifile_cleanstr(value), "true");
358 <                        else if (!_stricmp(name, "nomultibyte"))
359 <                                patch_nomultibyte = !_stricmp(inifile_cleanstr(value), "true");
360 <                        else if (!_stricmp(name, "sound"))
361 <                                opt_sound = !_stricmp(inifile_cleanstr(value), "true");
362 <                        else if (!_stricmp(name, "switch"))
363 <                                M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true");
364 <                        else if (!_stricmp(name, "topmost"))
365 <                                opt_topmost = !_stricmp(inifile_cleanstr(value), "true");
366 <                        else if (!_stricmp(name, "usedaodanbsl"))
367 <                                opt_usedaodanbsl = !_stricmp(inifile_cleanstr(value), "true");
368 <                        else
369 <                                DDrStartupMessage("Daodan: Unrecognised ini option \"%s\"", name);
370 <                        break;
371 <                case s_patch:
372 <                        if (!_stricmp(name, "alttab"))
373 <                                patch_alttab = !_stricmp(inifile_cleanstr(value), "true");
374 <                        else if (!_stricmp(name, "argb8888"))
375 <                                patch_argb8888 = !_stricmp(inifile_cleanstr(value), "true");
376 <                        else if (!_stricmp(name, "binkplay"))
377 <                                patch_binkplay = !_stricmp(inifile_cleanstr(value), "true");
111 <                        else if (!_stricmp(name, "bsl"))
112 <                                patch_bsl = !_stricmp(inifile_cleanstr(value), "true");
113 <                        else if (!_stricmp(name, "cheater"))
114 <                                patch_cheater = !_stricmp(inifile_cleanstr(value), "true");
115 <                        else if (!_stricmp(name, "cheatsenabled"))
116 <                                patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true");
117 <                        else if (!_stricmp(name, "cheattable"))
118 <                                patch_cheattable = !_stricmp(inifile_cleanstr(value), "true");
119 <                        else if (!_stricmp(name, "clipcursor"))
120 <                                patch_clipcursor = !_stricmp(inifile_cleanstr(value), "true");
121 <                        else if (!_stricmp(name, "cooldowntimer"))
122 <                                patch_cooldowntimer = !_stricmp(inifile_cleanstr(value), "true");
123 <                        else if (!_stricmp(name, "daodandisplayenum"))
124 <                                patch_daodandisplayenum = !_stricmp(inifile_cleanstr(value), "true");
125 <                        else if (!_stricmp(name, "directinput"))
126 <                                patch_directinput = !_stricmp(inifile_cleanstr(value), "true");
127 <                        else if (!_stricmp(name, "disablecmdline"))
128 <                                patch_disablecmdline = !_stricmp(inifile_cleanstr(value), "true");
129 <                        else if (!_stricmp(name, "flatline"))
130 <                                patch_flatline = !_stricmp(inifile_cleanstr(value), "true");
131 <                        else if (!_stricmp(name, "fonttexturecache"))
132 <                                patch_fonttexturecache = !_stricmp(inifile_cleanstr(value), "true");
133 <                        else if (!_stricmp(name, "getcmdline"))
134 <                                patch_getcmdline = !_stricmp(inifile_cleanstr(value), "true");
135 <                        else if (!_stricmp(name, "hdscreens_lowres"))
136 <                                patch_hdscreens_lowres = !_stricmp(inifile_cleanstr(value), "true");
137 <                        else if (!_stricmp(name, "highres_console"))
138 <                                patch_highres_console = !_stricmp(inifile_cleanstr(value), "true");
139 <                        else if (!_stricmp(name, "kickguns"))
140 <                                patch_kickguns = !_stricmp(inifile_cleanstr(value), "true");
141 <                        else if (!_stricmp(name, "killvtune"))
142 <                                patch_killvtune = !_stricmp(inifile_cleanstr(value), "true");
143 <                        else if (!_stricmp(name, "largetextures"))
144 <                                patch_largetextures = !_stricmp(inifile_cleanstr(value), "true");
145 <                        else if (!_stricmp(name, "levelplugins"))
146 <                                patch_levelplugins = !_stricmp(inifile_cleanstr(value), "true");
147 <                        else if (!_stricmp(name, "nomultibyte"))
148 <                                patch_nomultibyte = !_stricmp(inifile_cleanstr(value), "true");
149 <                        else if (!_stricmp(name, "newweap"))
150 <                                patch_newweapon = !_stricmp(inifile_cleanstr(value), "true");
151 <                        else if (!_stricmp(name, "optionsvisible"))
152 <                                patch_optionsvisible = !_stricmp(inifile_cleanstr(value), "true");
153 <                        else if (!_stricmp(name, "particledisablebit"))
154 <                                patch_particledisablebit = !_stricmp(inifile_cleanstr(value), "true");
155 <                        else if (!_stricmp(name, "pathfinding"))
156 <                                patch_pathfinding = !_stricmp(inifile_cleanstr(value), "true");
157 <                        else if (!_stricmp(name, "projaware"))
158 <                                patch_projaware = !_stricmp(inifile_cleanstr(value), "true");
159 <                        else if (!_stricmp(name, "safeprintf"))
160 <                                patch_safeprintf = !_stricmp(inifile_cleanstr(value), "true");
161 <                        else if (!_stricmp(name, "showalllasersights"))
162 <                                patch_showalllasersights = !_stricmp(inifile_cleanstr(value), "true");
163 <                        else if (!_stricmp(name, "throwtest"))
164 <                                patch_throwtest = !_stricmp(inifile_cleanstr(value), "true");
165 <                        else if (!_stricmp(name, "usedaodangl"))
166 <                                patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true");
167 <                        else if (!_stricmp(name, "usegettickcount"))
168 <                                patch_usegettickcount = !_stricmp(inifile_cleanstr(value), "true");
169 <                        else if (!_stricmp(name, "wpfadetime"))
170 <                                patch_wpfadetime = !_stricmp(inifile_cleanstr(value), "true");
345 >                STARTUPMESSAGE("Writing Daodan help file failed", 0);
346 >        }
347 > }
348 >
349 > const char* DDrConfig_GetOptionTypeName(OptionType_t type)
350 > {
351 >        switch (type) {
352 >                case C_INT:
353 >                        return "Int";
354 >                case C_BOOL:
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:
363 >                        return "unknown";
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 <                                DDrStartupMessage("Daodan: Unrecognised ini patch \"%s\"", name);
380 <                        break;
381 <                case s_language:
382 <                        if (!_stricmp(name, "chinese"))
383 <                                patch_chinese = !_stricmp(inifile_cleanstr(value), "true");
384 <                        else if (!_stricmp(name, "blam"))
385 <                                DDrPatch__strdup((int*)(OniExe + 0x0010fb73), value);
386 <                        else if (!_stricmp(name, "damn"))
387 <                                DDrPatch__strdup((int*)(OniExe + 0x0010fb6e), value);
388 <                        else if (!_stricmp(name, "savepoint"))
389 <                        {
390 <                                char* str = _strdup(value);
391 <                                DDrPatch_Int32((int*)(OniExe + 0x000fd730), (int)str);
392 <                                DDrPatch_Int32((int*)(OniExe + 0x000fd738), (int)str);
393 <                        }
394 <                        else if (!_stricmp(name, "syndicatewarehouse"))
395 <                        {
396 <                                char* str = _strdup(value);
397 <                                DDrPatch_Int32((int*)(OniExe + 0x000fd71a), (int)str);
398 <                                DDrPatch_Int32((int*)(OniExe + 0x0010ef75), (int)str);
399 <                        }
400 <                        else if (!_stricmp(name, "shapeshifter_on"))
401 <                                DDr_CheatTable[0].message_on = _strdup(value);
402 <                        else if (!_stricmp(name, "shapeshifter_off"))
403 <                                DDr_CheatTable[0].message_off = _strdup(value);
404 <                        else if (!_stricmp(name, "liveforever_on"))
405 <                                DDr_CheatTable[1].message_on = _strdup(value);
406 <                        else if (!_stricmp(name, "liveforever_off"))
407 <                                DDr_CheatTable[1].message_off = _strdup(value);
408 <                        else if (!_stricmp(name, "touchofdeath_on"))
409 <                                DDr_CheatTable[2].message_on = _strdup(value);
410 <                        else if (!_stricmp(name, "touchofdeath_off"))
411 <                                DDr_CheatTable[2].message_off = _strdup(value);
412 <                        else if (!_stricmp(name, "canttouchthis_on"))
413 <                                DDr_CheatTable[3].message_on = _strdup(value);
414 <                        else if (!_stricmp(name, "canttouchthis_off"))
415 <                                DDr_CheatTable[3].message_off = _strdup(value);
416 <                        else if (!_stricmp(name, "fatloot_on"))
417 <                                DDr_CheatTable[4].message_on = _strdup(value);
418 <                        else if (!_stricmp(name, "glassworld_on"))
419 <                                DDr_CheatTable[5].message_on = _strdup(value);
420 <                        else if (!_stricmp(name, "glassworld_off"))
421 <                                DDr_CheatTable[5].message_off = _strdup(value);
422 <                        else if (!_stricmp(name, "winlevel_on"))
423 <                                DDr_CheatTable[6].message_on = _strdup(value);
424 <                        else if (!_stricmp(name, "loselevel_on"))
425 <                                DDr_CheatTable[7].message_on = _strdup(value);
426 <                        else if (!_stricmp(name, "bighead_on"))
427 <                                DDr_CheatTable[8].message_on = _strdup(value);
221 <                        else if (!_stricmp(name, "bighead_off"))
222 <                                DDr_CheatTable[8].message_off = _strdup(value);
223 <                        else if (!_stricmp(name, "minime_on"))
224 <                                DDr_CheatTable[9].message_on = _strdup(value);
225 <                        else if (!_stricmp(name, "minime_off"))
226 <                                DDr_CheatTable[9].message_off = _strdup(value);
227 <                        else if (!_stricmp(name, "superammo_on"))
228 <                                DDr_CheatTable[10].message_on = _strdup(value);
229 <                        else if (!_stricmp(name, "superammo_off"))
230 <                                DDr_CheatTable[10].message_off = _strdup(value);
231 <                        else if (!_stricmp(name, "devmode_on"))
232 <                        {
233 <                                char* str = _strdup(value);
234 <                                DDr_CheatTable[11].message_on = str;
235 <                                DDr_CheatTable[cheat_x].message_on = str;
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];
411 >        strcpy(section, fullOptName);
412 >
413 >        char* option = strchr(section, '.');
414 >        if (option == 0) {
415 >                STARTUPMESSAGE("Could not find option separator in \"%s\"", fullOptName);
416 >                return 0;
417 >        }
418 >        *option++ = 0;
419 >
420 >        char isWildcardSection = !_stricmp(section, "*");
421 >
422 >        for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
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 <                        else if (!_stricmp(name, "devmode_off"))
430 <                        {
431 <                                char* str = _strdup(value);
240 <                                DDr_CheatTable[11].message_off = str;
241 <                                DDr_CheatTable[cheat_x].message_off = str;
429 >                        if (!isWildcardSection) {
430 >                                STARTUPMESSAGE("Could not find option \"%s\" in section \"%s\"", option, section);
431 >                                return 0;
432                          }
433 <                        else if (!_stricmp(name, "reservoirdogs_on"))
244 <                                DDr_CheatTable[12].message_on = _strdup(value);
245 <                        else if (!_stricmp(name, "reservoirdogs_off"))
246 <                                DDr_CheatTable[12].message_off = _strdup(value);
247 <                        else if (!_stricmp(name, "roughjustice_on"))
248 <                                DDr_CheatTable[13].message_on = _strdup(value);
249 <                        else if (!_stricmp(name, "roughjustice_off"))
250 <                                DDr_CheatTable[13].message_off = _strdup(value);
251 <                        else if (!_stricmp(name, "chenille_on"))
252 <                                DDr_CheatTable[14].message_on = _strdup(value);
253 <                        else if (!_stricmp(name, "chenille_off"))
254 <                                DDr_CheatTable[14].message_off = _strdup(value);
255 <                        else if (!_stricmp(name, "behemoth_on"))
256 <                                DDr_CheatTable[15].message_on = _strdup(value);
257 <                        else if (!_stricmp(name, "behemoth_off"))
258 <                                DDr_CheatTable[15].message_off = _strdup(value);
259 <                        else if (!_stricmp(name, "elderrune_on"))
260 <                                DDr_CheatTable[16].message_on = _strdup(value);
261 <                        else if (!_stricmp(name, "elderrune_off"))
262 <                                DDr_CheatTable[16].message_off = _strdup(value);
263 <                        else if (!_stricmp(name, "moonshadow_on"))
264 <                                DDr_CheatTable[17].message_on = _strdup(value);
265 <                        else if (!_stricmp(name, "moonshadow_off"))
266 <                                DDr_CheatTable[17].message_off = _strdup(value);
267 <                        else if (!_stricmp(name, "munitionfrenzy_on"))
268 <                                DDr_CheatTable[18].message_on = _strdup(value);
269 <                        else if (!_stricmp(name, "fistsoflegend_on"))
270 <                                DDr_CheatTable[19].message_on = _strdup(value);
271 <                        else if (!_stricmp(name, "fistsoflegend_off"))
272 <                                DDr_CheatTable[19].message_off = _strdup(value);
273 <                        else if (!_stricmp(name, "killmequick_on"))
274 <                                DDr_CheatTable[20].message_on = _strdup(value);
275 <                        else if (!_stricmp(name, "killmequick_off"))
276 <                                DDr_CheatTable[20].message_off = _strdup(value);
277 <                        else if (!_stricmp(name, "carousel_on"))
278 <                                DDr_CheatTable[21].message_on = _strdup(value);
279 <                        else if (!_stricmp(name, "carousel_off"))
280 <                                DDr_CheatTable[21].message_off = _strdup(value);
281 <                        else
282 <                                DDrStartupMessage("Daodan: Unrecognised ini language item \"%s\"", name);
283 <                        break;
284 <                case s_bsl:
285 <                default:
286 <                        break;
433 >                }
434          }
435 <        
436 <        return true;
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  
442 < void DDrConfig(int argc, char* argv[])
442 >
443 >
444 > ConfigOption_t* DDrConfig_GetOptOfType(const char* fullOptName, OptionType_t type)
445   {
446 <        int i;
447 <        char* section;
448 <        char* option;
449 <        bool falseoption;
446 >        ConfigOption_t* co = DDrConfig_GetOption(fullOptName);
447 >        if (co == 0)
448 >                return 0;
449 >
450 >        if (co->type != type) {
451 >                STARTUPMESSAGE("Option \"%s\" is not of type %s", fullOptName, DDrConfig_GetOptionTypeName(type));
452 >                return 0;
453 >        }
454 >        return co;
455 > }
456 >
457  
458  
459 <        // Tell Oni to not load non levelX_final-files by default:
460 <        opt_ignore_private_data = false;
459 > void DDrConfig_InitExtBools()
460 > {
461 >        for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
462 >                for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
463 >                        if (co->type == EXT_BOOL) {
464 >                                *co->value.extBoolVal = co->defaultValue.intBoolVal;
465 >                        }
466 >                }
467 >        }
468 > }
469  
303        // Enable sound by default:
304        opt_sound = true;
470  
471  
472 <        if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
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 <                FILE* fp;
480 <                DDrStartupMessage("Daodan: daodan.ini doesn't exist, creating");
481 <                fp = fopen("daodan.ini", "w");
482 <                if (fp)
483 <                {
484 <                        fputs("[Options]\n", fp);
485 <                        fputs("[Patch]\n", fp);
486 <                        fputs("[BSL]\n", fp);
487 <                        fputs("[Language]\n", fp);
488 <                        fclose(fp);
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 <        
494 <        DDrStartupMessage("Daodan: Parsing daodan.ini...");
495 <        if (!inifile_read("daodan.ini", DDrIniCallback))
496 <                DDrStartupMessage("Daodan: Error reading daodan.ini, check your syntax!");
497 <        DDrStartupMessage("Daodan: Finished parsing");
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 > {
502 >        char fullOptName[50];
503 >
504 >        if (!_stricmp(section, "patch"))
505 >                section = "patches";
506 >
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);
519 +                                break;
520 +                        case C_BOOL:
521 +                                co->value.intBoolVal = !_stricmp(value, "true");
522 +                                break;
523 +                        case C_STRING:
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");
533 +                                break;
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  
550 <        DDrStartupMessage("Daodan: Parsing command line...");
551 <        for (i = 1; i < argc; i ++)
550 > bool DDrConfig_ParseCommandLine(int argc, char* argv[])
551 > {
552 >        for (int i = 1; i < argc; i ++)
553          {
554                  if (argv[i][0] == '-')
555                  {
556 <                        section = argv[i] + 1;
557 <                        if ((option = strchr(argv[i], '.')))
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 <                                *option = '\0';
338 <                                falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] == 'o' || option[2] == 'O');
339 <                                if (i < (argc - 1) && argv[i + 1][0] != '-')
340 <                                        DDrIniCallback(section, true, option + 1, argv[++i]);
341 <                                else
342 <                                        DDrIniCallback(section, true, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true"));
343 <                                *option = '.';
568 >                                DDrIniCallback("*", option, argv[++i]);
569                          }
570                          else
571 +                        // Implicit value
572                          {
573 <                                falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] == 'o' || section[1] == 'O');
348 <                                ini_section = s_options;
349 <                                if (i < (argc - 1) && argv[i + 1][0] != '-')
350 <                                        DDrIniCallback(NULL, false, section, argv[++i]);
351 <                                else
352 <                                        DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), (falseoption ? "false" : "true"));
573 >                                DDrIniCallback("*", option, (invertedOption ? "false" : "true"));
574                          }
575                  }
576                  else
577                  {
578 <                        DDrStartupMessage("Daodan: Parse error \"%s\"", argv[i]);
579 <                        break;
578 >                        STARTUPMESSAGE("Parse error \"%s\"", argv[i]);
579 >                        return false;
580                  }
581          }
582 <        DDrStartupMessage("Daodan: Finished parsing");
582 >        return true;
583 > }
584 >
585 > void DDrConfig(int argc, char* argv[])
586 > {
587 >        STARTUPMESSAGE("Initializing standard booleans", 0);
588 >        DDrConfig_InitExtBools();
589 >
590 >        if (GetFileAttributes(iniName) == INVALID_FILE_ATTRIBUTES)
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 >        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 >        DDrConfig_ParseCommandLine(argc, argv);
606 >        STARTUPMESSAGE("Finished parsing", 0);
607 >
608 >        if (strlen(invalidCurParamaters) > 0)
609 >        {
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 >        }
622 >
623 >        DDrConfig_WriteIni();
624 >
625 > //      DDrConfig_Print();
626   }
627  

Diff Legend

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