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 990 by alloc, Wed Apr 2 00:48:54 2014 UTC vs.
Revision 1162 by rossy, Sun Oct 24 02:50:32 2021 UTC

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

Diff Legend

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