[838] | 1 | #include <windows.h>
|
---|
| 2 | #include <string.h>
|
---|
[994] | 3 | #include <time.h>
|
---|
[838] | 4 |
|
---|
[1017] | 5 | #include "Daodan.h"
|
---|
[838] | 6 | #include "Daodan_Config.h"
|
---|
| 7 | #include "Daodan_Patch.h"
|
---|
[994] | 8 | #include "Patches/Utility.h"
|
---|
[838] | 9 |
|
---|
[992] | 10 | #include "Oni/Oni.h"
|
---|
[994] | 11 | #include "_Version.h"
|
---|
[838] | 12 |
|
---|
| 13 | #include "Inifile_Reader.h"
|
---|
| 14 |
|
---|
[993] | 15 | static const char* iniName = "daodan.ini";
|
---|
[994] | 16 | static const char* helpFile = "daodan_help.txt";
|
---|
[838] | 17 |
|
---|
[994] | 18 | static const char* defaultSection = "options";
|
---|
| 19 |
|
---|
[1007] | 20 | static char invalidCurParamaters[2000] = "";
|
---|
| 21 | static char invalidTotalParamaters[4000] = "";
|
---|
[995] | 22 |
|
---|
[994] | 23 | void DDrConfig_PrintHelp();
|
---|
| 24 |
|
---|
| 25 |
|
---|
[993] | 26 | ConfigSection_t config[] = {
|
---|
[1000] | 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.",
|
---|
[993] | 38 | C_BOOL,
|
---|
| 39 | {.intBoolVal = true},
|
---|
| 40 | {.intBoolVal = true} },
|
---|
[1000] | 41 | { "showtriggervolumes",
|
---|
| 42 | "Allows BSL variable \"show_triggervolumes\" and Ctrl+Shift+X (in devmode) to work.",
|
---|
[993] | 43 | C_BOOL,
|
---|
| 44 | {.intBoolVal = true},
|
---|
| 45 | {.intBoolVal = true} },
|
---|
[1000] | 46 | { 0, 0, 0, {0}, {0} }
|
---|
| 47 | } },
|
---|
| 48 | { "gameplay", "Gameplay", {
|
---|
[1017] | 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} },
|
---|
[1008] | 54 | { "characterawareness",
|
---|
| 55 | "Makes AI remember the player.",
|
---|
| 56 | C_BOOL,
|
---|
| 57 | {.intBoolVal = true},
|
---|
| 58 | {.intBoolVal = true} },
|
---|
[993] | 59 | { "cheatsenabled",
|
---|
| 60 | "Enables cheats without having to beat the game first.",
|
---|
| 61 | C_BOOL,
|
---|
| 62 | {.intBoolVal = true},
|
---|
| 63 | {.intBoolVal = true} },
|
---|
| 64 | { "cheattable",
|
---|
[995] | 65 | "Replaces Oni's cheat table with table that includes new cheats including devmode.",
|
---|
[993] | 66 | C_BOOL,
|
---|
| 67 | {.intBoolVal = true},
|
---|
| 68 | {.intBoolVal = true} },
|
---|
[1000] | 69 | { "cooldowntimer",
|
---|
| 70 | "Disables weapon cooldown exploit.",
|
---|
[993] | 71 | C_BOOL,
|
---|
| 72 | {.intBoolVal = true},
|
---|
| 73 | {.intBoolVal = true} },
|
---|
[1017] | 74 | { "customactions",
|
---|
| 75 | "Allows more actions to be bound through Daodan.",
|
---|
| 76 | C_BOOL,
|
---|
| 77 | {.intBoolVal = true},
|
---|
| 78 | {.intBoolVal = true} },
|
---|
[1000] | 79 | { "kickguns",
|
---|
| 80 | "EXPERIMENTAL! Unfinished, do not use.",
|
---|
[993] | 81 | C_BOOL,
|
---|
[1000] | 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,
|
---|
[993] | 87 | {.intBoolVal = true},
|
---|
| 88 | {.intBoolVal = true} },
|
---|
[1000] | 89 | { "projaware",
|
---|
| 90 | "Allows AI to dodge incoming gunfire properly.",
|
---|
[993] | 91 | C_BOOL,
|
---|
| 92 | {.intBoolVal = true},
|
---|
| 93 | {.intBoolVal = true} },
|
---|
[1000] | 94 | { "throwtest",
|
---|
| 95 | "EXPERIMENTAL! Experiment with allowing enemies to be thrown over railings.",
|
---|
[995] | 96 | C_BOOL,
|
---|
[1000] | 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,
|
---|
[995] | 102 | {.intBoolVal = true},
|
---|
| 103 | {.intBoolVal = true} },
|
---|
[1000] | 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.",
|
---|
[993] | 109 | C_BOOL,
|
---|
| 110 | {.intBoolVal = true},
|
---|
| 111 | {.intBoolVal = true} },
|
---|
[1000] | 112 | { "daodangl",
|
---|
| 113 | "Provides an improved windowed mode (-noswitch).",
|
---|
[993] | 114 | C_BOOL,
|
---|
| 115 | {.intBoolVal = true},
|
---|
| 116 | {.intBoolVal = true} },
|
---|
[1000] | 117 | { "displayenum",
|
---|
| 118 | "Offers a more accurate list of available display modes in the Options menu.",
|
---|
[993] | 119 | C_BOOL,
|
---|
| 120 | {.intBoolVal = true},
|
---|
| 121 | {.intBoolVal = true} },
|
---|
[1000] | 122 | { "gamma",
|
---|
| 123 | "Enable gamma slider in fullscreen, disable in windowed mode.",
|
---|
[993] | 124 | C_BOOL,
|
---|
| 125 | {.intBoolVal = true},
|
---|
| 126 | {.intBoolVal = true} },
|
---|
[1000] | 127 | { "newweap",
|
---|
| 128 | "Standing above a weapon displays a message containing the weapon name and amount of ammo.",
|
---|
[993] | 129 | C_BOOL,
|
---|
| 130 | {.intBoolVal = true},
|
---|
| 131 | {.intBoolVal = true} },
|
---|
[1000] | 132 | { "optionsvisible",
|
---|
| 133 | "Always show options button in main menu, even when pausing from a game.",
|
---|
[993] | 134 | C_BOOL,
|
---|
| 135 | {.intBoolVal = true},
|
---|
| 136 | {.intBoolVal = true} },
|
---|
[1000] | 137 | { "showalllasersights",
|
---|
| 138 | "Show all (also enemies') weapon lasersights.",
|
---|
[993] | 139 | C_BOOL,
|
---|
| 140 | {.intBoolVal = false},
|
---|
| 141 | {.intBoolVal = false} },
|
---|
[1000] | 142 | { "widescreenportraits",
|
---|
| 143 | "Prevents fly-in portraits from being stretched when playing in widescreen resolutions.",
|
---|
[995] | 144 | C_BOOL,
|
---|
[993] | 145 | {.intBoolVal = true},
|
---|
| 146 | {.intBoolVal = true} },
|
---|
[1000] | 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.",
|
---|
[993] | 152 | C_BOOL,
|
---|
| 153 | {.intBoolVal = true},
|
---|
| 154 | {.intBoolVal = true} },
|
---|
[1000] | 155 | { "fonttexturecache",
|
---|
| 156 | "Doubles size of font texture cache.",
|
---|
[993] | 157 | C_BOOL,
|
---|
| 158 | {.intBoolVal = true},
|
---|
| 159 | {.intBoolVal = true} },
|
---|
[1000] | 160 | { "language",
|
---|
| 161 | "Localization for hardcoded strings (e.g. \"Savepoints\").",
|
---|
| 162 | C_STRING,
|
---|
| 163 | {.stringVal = "en"},
|
---|
| 164 | {.stringVal = "en"} },
|
---|
[993] | 165 | { "nomultibyte",
|
---|
| 166 | "Enables languages which use multibyte coding (such as Chinese).",
|
---|
| 167 | C_BOOL,
|
---|
| 168 | {.intBoolVal = true},
|
---|
| 169 | {.intBoolVal = true} },
|
---|
[1000] | 170 | { 0, 0, 0, {0}, {0} }
|
---|
| 171 | } },
|
---|
| 172 | { "modding", "Modding", {
|
---|
| 173 | { "argb8888",
|
---|
| 174 | "Allows using textures with ARGB8888.",
|
---|
[993] | 175 | C_BOOL,
|
---|
| 176 | {.intBoolVal = true},
|
---|
| 177 | {.intBoolVal = true} },
|
---|
[1000] | 178 | { "d_regen",
|
---|
| 179 | "Enables script command d_regen (query/set regeneration for any character).",
|
---|
[993] | 180 | C_BOOL,
|
---|
| 181 | {.intBoolVal = true},
|
---|
| 182 | {.intBoolVal = true} },
|
---|
[1000] | 183 | { "daodanbsl",
|
---|
[995] | 184 | "Adds new BSL commands.",
|
---|
| 185 | C_BOOL,
|
---|
| 186 | {.intBoolVal = true},
|
---|
| 187 | {.intBoolVal = true} },
|
---|
[1000] | 188 | { "hdscreens_lowres",
|
---|
| 189 | "Allow HD intro/ending screens on game resolutions smaller than 1024x768.",
|
---|
[993] | 190 | C_BOOL,
|
---|
| 191 | {.intBoolVal = true},
|
---|
| 192 | {.intBoolVal = true} },
|
---|
[1000] | 193 | { "largetextures",
|
---|
| 194 | "Textures up to 512x512 can be used.",
|
---|
[993] | 195 | C_BOOL,
|
---|
| 196 | {.intBoolVal = true},
|
---|
| 197 | {.intBoolVal = true} },
|
---|
[1000] | 198 | { "levelplugins",
|
---|
| 199 | "Allows level files to be loaded which do not end in \"_Final\".",
|
---|
[995] | 200 | C_BOOL,
|
---|
| 201 | {.intBoolVal = true},
|
---|
| 202 | {.intBoolVal = true} },
|
---|
[993] | 203 | { 0, 0, 0, {0}, {0} }
|
---|
| 204 | } },
|
---|
[1000] | 205 | { "oni", "Original Oni Options", {
|
---|
[993] | 206 | { "debug",
|
---|
[995] | 207 | "Not useful, probably does nothing.",
|
---|
[993] | 208 | EXT_BOOL,
|
---|
| 209 | {.intBoolVal = false },
|
---|
| 210 | {.extBoolVal = &AKgDebug_DebugMaps } },
|
---|
| 211 | { "debugfiles",
|
---|
[996] | 212 | "Logs called BSL functions to script_debug.txt.",
|
---|
[993] | 213 | EXT_BOOL,
|
---|
| 214 | {.intBoolVal = false },
|
---|
| 215 | {.extBoolVal = &BFgDebugFileEnable } },
|
---|
| 216 | { "findsounds",
|
---|
[995] | 217 | "Not useful, extends output of sound_list_broken_links.",
|
---|
[993] | 218 | EXT_BOOL,
|
---|
| 219 | {.intBoolVal = false },
|
---|
| 220 | {.extBoolVal = &SSgSearchOnDisk } },
|
---|
| 221 | { "ignore_private_data",
|
---|
[995] | 222 | "Not useful, probably does nothing.",
|
---|
[993] | 223 | EXT_BOOL,
|
---|
| 224 | {.intBoolVal = false },
|
---|
| 225 | {.extBoolVal = &opt_ignore_private_data } },
|
---|
| 226 | { "sound",
|
---|
[995] | 227 | "Enable sound.",
|
---|
[993] | 228 | EXT_BOOL,
|
---|
| 229 | {.intBoolVal = true },
|
---|
| 230 | {.extBoolVal = &opt_sound } },
|
---|
| 231 | { "switch",
|
---|
[995] | 232 | "Switch to fullscreen instead of staying in a window.",
|
---|
[993] | 233 | EXT_BOOL,
|
---|
| 234 | {.intBoolVal = true},
|
---|
| 235 | {.extBoolVal = &M3gResolutionSwitch} },
|
---|
[1000] | 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} },
|
---|
[993] | 274 | { "topmost",
|
---|
| 275 | "Keep game window on top in windowed mode, even when switching applications.",
|
---|
| 276 | C_BOOL,
|
---|
| 277 | {.intBoolVal = false},
|
---|
| 278 | {.intBoolVal = false} },
|
---|
[1000] | 279 | { "usegettickcount",
|
---|
| 280 | "Replaces Oni's timing functions with more accurate ones.",
|
---|
| 281 | C_BOOL,
|
---|
| 282 | {.intBoolVal = true},
|
---|
| 283 | {.intBoolVal = true} },
|
---|
[993] | 284 | { 0, 0, 0, {0}, {0} }
|
---|
| 285 | } }
|
---|
| 286 | };
|
---|
[838] | 287 |
|
---|
| 288 |
|
---|
[993] | 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;
|
---|
[994] | 300 | case C_CMD:
|
---|
| 301 | break;
|
---|
[993] | 302 | default:
|
---|
| 303 | STARTUPMESSAGE("Option %s.%s = %d (def %d)", config[s].name, co->name, co->value.intBoolVal, co->defaultValue.intBoolVal);
|
---|
| 304 | }
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
[838] | 308 |
|
---|
[994] | 309 | void DDrConfig_PrintHelp()
|
---|
| 310 | {
|
---|
| 311 | STARTUPMESSAGE("Writing Daodan help file (%s)", helpFile);
|
---|
| 312 |
|
---|
| 313 | FILE* fp;
|
---|
| 314 | remove(helpFile);
|
---|
| 315 | fp = fopen(helpFile, "w");
|
---|
| 316 | if (fp)
|
---|
| 317 | {
|
---|
| 318 | time_t rawtime;
|
---|
| 319 | struct tm* timeinfo;
|
---|
| 320 | char buffer[80];
|
---|
| 321 | time(&rawtime);
|
---|
| 322 | timeinfo = localtime(&rawtime);
|
---|
| 323 | strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
|
---|
| 324 |
|
---|
| 325 | fprintf(fp, "Daodan help - generated on %s for Daodan v."DAODAN_VERSION_STRING"\n\n", buffer);
|
---|
| 326 | fprintf(fp, "List of Daodan configuration parameters:\n");
|
---|
| 327 | for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
|
---|
| 328 | fprintf(fp, " %s - %s:\n", config[s].name, config[s].description);
|
---|
| 329 | for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
|
---|
| 330 | char* name = co->name;
|
---|
| 331 | char* desc = co->description;
|
---|
| 332 | const char* tName = DDrConfig_GetOptionTypeName(co->type);
|
---|
[1000] | 333 | const char* val = DDrConfig_GetOptionValueString(co, 1);
|
---|
| 334 | if (!val)
|
---|
| 335 | val = "";
|
---|
[994] | 336 | fprintf(fp, " %-22s %6s=%-5s %s\n", name, tName, val, desc);
|
---|
| 337 | }
|
---|
| 338 | fprintf(fp, "\n");
|
---|
| 339 | }
|
---|
| 340 | fprintf(fp, "\nConfiguration parameters can be either set in daodan.ini or passed on command line.\n\n");
|
---|
| 341 | 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");
|
---|
| 342 | fprintf(fp, " [sectionX]\n parameterName = false\n");
|
---|
| 343 | fprintf(fp, "\nTo pass the parameter on the command line:\n");
|
---|
[1000] | 344 | fprintf(fp, " Oni.exe -parameterName false\n");
|
---|
[994] | 345 | fprintf(fp, "For bool parameters the value can be ommitted so it is regarded as \"true\":\n");
|
---|
[1000] | 346 | fprintf(fp, " Oni.exe -parameterName\n");
|
---|
[994] | 347 | fprintf(fp, "To disable a bool parameter you can prefix \"no\" to the parameter name like this:\n");
|
---|
[1000] | 348 | fprintf(fp, " Oni.exe -noparameterName\n");
|
---|
[994] | 349 |
|
---|
| 350 | fclose(fp);
|
---|
| 351 | }
|
---|
| 352 | else
|
---|
| 353 | {
|
---|
| 354 | STARTUPMESSAGE("Writing Daodan help file failed", 0);
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 |
|
---|
[993] | 358 | const char* DDrConfig_GetOptionTypeName(OptionType_t type)
|
---|
[838] | 359 | {
|
---|
[993] | 360 | switch (type) {
|
---|
| 361 | case C_INT:
|
---|
| 362 | return "Int";
|
---|
| 363 | case C_BOOL:
|
---|
| 364 | return "Bool";
|
---|
| 365 | case C_STRING:
|
---|
| 366 | return "String";
|
---|
[994] | 367 | case C_CMD:
|
---|
| 368 | return "Cmd";
|
---|
[993] | 369 | case EXT_BOOL:
|
---|
| 370 | return "pBool";
|
---|
| 371 | default:
|
---|
| 372 | return "unknown";
|
---|
| 373 | }
|
---|
| 374 | }
|
---|
| 375 |
|
---|
[1000] | 376 | const char* DDrConfig_GetOptionValueString(ConfigOption_t* opt, char printdefault)
|
---|
| 377 | {
|
---|
| 378 | OptionValue_t* optVal = (printdefault ? &opt->defaultValue : &opt->value);
|
---|
| 379 | int boolV = optVal->intBoolVal;
|
---|
| 380 | char* val = 0;
|
---|
| 381 | switch (opt->type) {
|
---|
| 382 | case C_STRING:
|
---|
| 383 | return optVal->stringVal;
|
---|
| 384 | case EXT_BOOL:
|
---|
| 385 | if (printdefault)
|
---|
| 386 | return (boolV ? "true" : "false");
|
---|
| 387 | else
|
---|
| 388 | return (*optVal->extBoolVal ? "true" : "false");
|
---|
| 389 | case C_BOOL:
|
---|
| 390 | return (boolV ? "true" : "false");
|
---|
| 391 | case C_CMD:
|
---|
| 392 | return 0;
|
---|
| 393 | default:
|
---|
| 394 | val = malloc(20);
|
---|
| 395 | sprintf(val, "%d", boolV);
|
---|
| 396 | return val;
|
---|
| 397 | }
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | char DDrConfig_NonDefaultOptionValue(ConfigOption_t* opt)
|
---|
| 401 | {
|
---|
| 402 | switch (opt->type) {
|
---|
| 403 | case C_STRING:
|
---|
| 404 | return _stricmp(opt->defaultValue.stringVal, opt->value.stringVal);
|
---|
| 405 | case EXT_BOOL:
|
---|
| 406 | return !opt->defaultValue.intBoolVal != !*opt->value.extBoolVal;
|
---|
| 407 | case C_BOOL:
|
---|
| 408 | return !opt->defaultValue.intBoolVal != !opt->value.intBoolVal;
|
---|
| 409 | case C_CMD:
|
---|
| 410 | return 0;
|
---|
| 411 | case C_INT:
|
---|
| 412 | return opt->defaultValue.intBoolVal != opt->value.intBoolVal;
|
---|
| 413 | }
|
---|
| 414 | return 0;
|
---|
| 415 | }
|
---|
| 416 |
|
---|
[993] | 417 | static ConfigOption_t* DDrConfig_GetOption(const char* fullOptName)
|
---|
| 418 | {
|
---|
| 419 | char section[50];
|
---|
| 420 | strcpy(section, fullOptName);
|
---|
| 421 |
|
---|
| 422 | char* option = strchr(section, '.');
|
---|
| 423 | if (option == 0) {
|
---|
| 424 | STARTUPMESSAGE("Could not find option separator in \"%s\"", fullOptName);
|
---|
| 425 | return 0;
|
---|
| 426 | }
|
---|
| 427 | *option++ = 0;
|
---|
| 428 |
|
---|
[1000] | 429 | char isWildcardSection = !_stricmp(section, "*");
|
---|
| 430 |
|
---|
[993] | 431 | for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
|
---|
[1000] | 432 | if (isWildcardSection || !_stricmp(config[s].name, section)) {
|
---|
[993] | 433 | for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
|
---|
| 434 | if (!_stricmp(co->name, option)) {
|
---|
| 435 | return co;
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
[1000] | 438 | if (!isWildcardSection) {
|
---|
| 439 | STARTUPMESSAGE("Could not find option \"%s\" in section \"%s\"", option, section);
|
---|
| 440 | return 0;
|
---|
| 441 | }
|
---|
[993] | 442 | }
|
---|
| 443 | }
|
---|
[1000] | 444 | if (!isWildcardSection)
|
---|
| 445 | STARTUPMESSAGE("Could not find section \"%s\" for option \"%s\"", section, option);
|
---|
| 446 | else
|
---|
| 447 | STARTUPMESSAGE("Could not find option \"%s\"", option);
|
---|
[993] | 448 | return 0;
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 |
|
---|
| 452 |
|
---|
| 453 | ConfigOption_t* DDrConfig_GetOptOfType(const char* fullOptName, OptionType_t type)
|
---|
| 454 | {
|
---|
| 455 | ConfigOption_t* co = DDrConfig_GetOption(fullOptName);
|
---|
| 456 | if (co == 0)
|
---|
| 457 | return 0;
|
---|
| 458 |
|
---|
| 459 | if (co->type != type) {
|
---|
| 460 | STARTUPMESSAGE("Option \"%s\" is not of type %s", fullOptName, DDrConfig_GetOptionTypeName(type));
|
---|
| 461 | return 0;
|
---|
| 462 | }
|
---|
| 463 | return co;
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 |
|
---|
[994] | 467 |
|
---|
[993] | 468 | void DDrConfig_InitExtBools()
|
---|
| 469 | {
|
---|
| 470 | for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
|
---|
| 471 | for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
|
---|
| 472 | if (co->type == EXT_BOOL) {
|
---|
| 473 | *co->value.extBoolVal = co->defaultValue.intBoolVal;
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | }
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 |
|
---|
| 480 |
|
---|
[1000] | 481 | void DDrConfig_WriteIni()
|
---|
[993] | 482 | {
|
---|
[994] | 483 | FILE* fp;
|
---|
| 484 | STARTUPMESSAGE("%s doesn't exist, creating", iniName);
|
---|
| 485 | fp = fopen(iniName, "w");
|
---|
| 486 | if (fp)
|
---|
| 487 | {
|
---|
| 488 | for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) {
|
---|
[1000] | 489 | if (strlen(config[s].name)) {
|
---|
| 490 | fprintf(fp, "[%s]\n", config[s].name);
|
---|
| 491 | for (ConfigOption_t* co = config[s].options; co->name != 0; co++) {
|
---|
| 492 | char* name = co->name;
|
---|
| 493 | const char* val = DDrConfig_GetOptionValueString(co, 0);
|
---|
| 494 | if (val && DDrConfig_NonDefaultOptionValue(co))
|
---|
| 495 | fprintf(fp, "%s = %s\n", name, val);
|
---|
| 496 | }
|
---|
| 497 | fprintf(fp, "\n");
|
---|
| 498 | }
|
---|
[994] | 499 | }
|
---|
| 500 | fclose(fp);
|
---|
| 501 | }
|
---|
| 502 | else
|
---|
| 503 | {
|
---|
| 504 | STARTUPMESSAGE("Writing %s template file failed", iniName);
|
---|
| 505 | }
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 |
|
---|
| 509 | void DDrIniCallback(const char* section, const char* name, const char* value)
|
---|
| 510 | {
|
---|
[993] | 511 | char fullOptName[50];
|
---|
| 512 |
|
---|
| 513 | if (!_stricmp(section, "patch"))
|
---|
| 514 | section = "patches";
|
---|
| 515 |
|
---|
[1000] | 516 | strcpy(fullOptName, section);
|
---|
| 517 | fullOptName[strlen(section)] = '.';
|
---|
| 518 | strcpy(fullOptName+strlen(section)+1, name);
|
---|
[993] | 519 |
|
---|
| 520 | ConfigOption_t* co = DDrConfig_GetOption(fullOptName);
|
---|
| 521 |
|
---|
| 522 | if (co)
|
---|
[838] | 523 | {
|
---|
[994] | 524 | char* buf = 0;
|
---|
[993] | 525 | switch (co->type) {
|
---|
| 526 | case C_INT:
|
---|
| 527 | co->value.intBoolVal = strtol(value, NULL, 0);
|
---|
| 528 | break;
|
---|
| 529 | case C_BOOL:
|
---|
| 530 | co->value.intBoolVal = !_stricmp(value, "true");
|
---|
| 531 | break;
|
---|
| 532 | case C_STRING:
|
---|
[994] | 533 | buf = malloc(strlen(value)+1);
|
---|
| 534 | strcpy(buf, value);
|
---|
| 535 | co->value.stringVal = buf;
|
---|
[993] | 536 | break;
|
---|
[994] | 537 | case C_CMD:
|
---|
| 538 | co->value.callback();
|
---|
| 539 | break;
|
---|
[993] | 540 | case EXT_BOOL:
|
---|
| 541 | *(co->value.extBoolVal) = !_stricmp(value, "true");
|
---|
| 542 | break;
|
---|
| 543 | default:
|
---|
| 544 | STARTUPMESSAGE("Config value type unknown: %d", co->type);
|
---|
[838] | 545 | }
|
---|
[995] | 546 | } else {
|
---|
[1007] | 547 | char buf[100];
|
---|
[1000] | 548 | if (!_stricmp(section, "*"))
|
---|
[1007] | 549 | sprintf(buf, " %s\n", name);
|
---|
[1000] | 550 | else
|
---|
[1007] | 551 | sprintf(buf, " %s.%s\n", section, name);
|
---|
[995] | 552 | if (strlen(buf) + strlen(invalidCurParamaters) < sizeof(invalidCurParamaters) - 1) {
|
---|
| 553 | strcpy(invalidCurParamaters + strlen(invalidCurParamaters), buf);
|
---|
| 554 | }
|
---|
[838] | 555 | }
|
---|
[993] | 556 | }
|
---|
| 557 |
|
---|
[994] | 558 |
|
---|
| 559 | bool DDrConfig_ParseCommandLine(int argc, char* argv[])
|
---|
[993] | 560 | {
|
---|
[994] | 561 | for (int i = 1; i < argc; i ++)
|
---|
[993] | 562 | {
|
---|
[994] | 563 | if (argv[i][0] == '-')
|
---|
| 564 | {
|
---|
| 565 | char* option;
|
---|
| 566 | bool invertedOption;
|
---|
| 567 |
|
---|
[1000] | 568 | option = argv[i]+1;
|
---|
[994] | 569 |
|
---|
| 570 | invertedOption = (option[0] == 'n' || option[0] == 'N') && (option[1] == 'o' || option[1] == 'O');
|
---|
| 571 | if (invertedOption)
|
---|
| 572 | option += 2;
|
---|
| 573 |
|
---|
| 574 | if (i < (argc - 1) && argv[i+1][0] != '-')
|
---|
| 575 | // Has value in next field
|
---|
| 576 | {
|
---|
[1000] | 577 | DDrIniCallback("*", option, argv[++i]);
|
---|
[994] | 578 | }
|
---|
| 579 | else
|
---|
| 580 | // Implicit value
|
---|
| 581 | {
|
---|
[1000] | 582 | DDrIniCallback("*", option, (invertedOption ? "false" : "true"));
|
---|
[994] | 583 | }
|
---|
[993] | 584 | }
|
---|
[994] | 585 | else
|
---|
| 586 | {
|
---|
| 587 | STARTUPMESSAGE("Parse error \"%s\"", argv[i]);
|
---|
| 588 | return false;
|
---|
| 589 | }
|
---|
[993] | 590 | }
|
---|
[994] | 591 | return true;
|
---|
[993] | 592 | }
|
---|
| 593 |
|
---|
| 594 | void DDrConfig(int argc, char* argv[])
|
---|
| 595 | {
|
---|
[994] | 596 | STARTUPMESSAGE("Initializing standard booleans", 0);
|
---|
[993] | 597 | DDrConfig_InitExtBools();
|
---|
| 598 |
|
---|
| 599 | if (GetFileAttributes(iniName) == INVALID_FILE_ATTRIBUTES)
|
---|
[1000] | 600 | DDrConfig_WriteIni();
|
---|
[838] | 601 |
|
---|
[993] | 602 | STARTUPMESSAGE("Parsing daodan.ini...", 0);
|
---|
| 603 | if (!Inifile_Read(iniName, DDrIniCallback))
|
---|
| 604 | STARTUPMESSAGE("Error reading daodan.ini, check your syntax!", 0);
|
---|
| 605 | STARTUPMESSAGE("Finished parsing", 0);
|
---|
| 606 |
|
---|
[995] | 607 | if (strlen(invalidCurParamaters) > 0)
|
---|
| 608 | {
|
---|
[1007] | 609 | sprintf(invalidTotalParamaters, "In %s:\n%s\n", iniName, invalidCurParamaters);
|
---|
[995] | 610 | invalidCurParamaters[0] = 0;
|
---|
| 611 | }
|
---|
[993] | 612 |
|
---|
| 613 | STARTUPMESSAGE("Parsing command line...", 0);
|
---|
[994] | 614 | DDrConfig_ParseCommandLine(argc, argv);
|
---|
[993] | 615 | STARTUPMESSAGE("Finished parsing", 0);
|
---|
[994] | 616 |
|
---|
[995] | 617 | if (strlen(invalidCurParamaters) > 0)
|
---|
| 618 | {
|
---|
[1007] | 619 | sprintf(invalidTotalParamaters, "%sOn command line:\n%s\n", invalidTotalParamaters, invalidCurParamaters);
|
---|
[995] | 620 | }
|
---|
| 621 |
|
---|
| 622 | if (strlen(invalidTotalParamaters) > 0)
|
---|
| 623 | {
|
---|
[1007] | 624 | char msg[4096];
|
---|
| 625 | sprintf(msg, "Invalid parameters given:\n%sContinue launching Oni?", invalidTotalParamaters);
|
---|
[995] | 626 | int res = MessageBox(NULL, msg, "Parameters invalid", MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON1);
|
---|
| 627 | if (res == IDNO) {
|
---|
| 628 | exit(0);
|
---|
| 629 | }
|
---|
| 630 | }
|
---|
| 631 |
|
---|
[1000] | 632 | DDrConfig_WriteIni();
|
---|
| 633 |
|
---|
[994] | 634 | // DDrConfig_Print();
|
---|
[993] | 635 | }
|
---|
| 636 |
|
---|