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