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 992 by alloc, Sat Apr 5 10:19:11 2014 UTC vs.
Revision 996 by alloc, Wed Apr 9 09:12:52 2014 UTC

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

Diff Legend

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