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