--- Daodan/src/Daodan_Config.c 2014/04/05 10:19:11 992 +++ Daodan/src/Daodan_Config.c 2015/03/23 23:29:19 1017 @@ -1,366 +1,636 @@ #include #include +#include -#include "Daodan_Cheater.h" +#include "Daodan.h" #include "Daodan_Config.h" #include "Daodan_Patch.h" -#include "Daodan_Utility.h" +#include "Patches/Utility.h" #include "Oni/Oni.h" +#include "_Version.h" #include "Inifile_Reader.h" -bool patch_alttab = true; -bool patch_argb8888 = true; -bool patch_binkplay = true; -bool patch_bsl = true; -bool patch_cheater = true; -bool patch_cheatsenabled = true; -bool patch_cheattable = true; -bool patch_clipcursor = true; -bool patch_cooldowntimer = true; -bool patch_daodandisplayenum = true; -bool patch_directinput = true; -bool patch_disablecmdline = true; -bool patch_flatline = true; -bool patch_fonttexturecache = true; -bool patch_getcmdline = true; -bool patch_hdscreens_lowres = true; -bool patch_highres_console = true; -bool patch_kickguns = false; -bool patch_killvtune = true; -bool patch_largetextures = true; -bool patch_levelplugins = true; -bool patch_newweapon = true; -bool patch_nomultibyte = true; -bool patch_optionsvisible = true; -bool patch_particledisablebit = false; -bool patch_pathfinding = true; -bool patch_projaware = true; -bool patch_safeprintf = true; -bool patch_showalllasersights = false; -bool patch_showtriggervolumes = true; -bool patch_throwtest = false; -bool patch_usedaodangl = true; -bool patch_usegettickcount = true; -bool patch_wpfadetime = true; - -bool opt_border = true; -bool opt_gamma = true; -bool opt_topmost = false; -bool opt_usedaodanbsl = true; +static const char* iniName = "daodan.ini"; +static const char* helpFile = "daodan_help.txt"; -bool patch_chinese = true; +static const char* defaultSection = "options"; +static char invalidCurParamaters[2000] = ""; +static char invalidTotalParamaters[4000] = ""; -enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section; +void DDrConfig_PrintHelp(); + + +ConfigSection_t config[] = { + { "", "Command line only", { + { "help", + "Generates this help file.", + C_CMD, + {.intBoolVal = 0}, + {.callback = DDrConfig_PrintHelp} }, + { 0, 0, 0, {0}, {0} } + } }, + { "devmode", "Developer Mode", { + { "highres_console", + "Fixes bug where console line becomes invisible at higher resolutions.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "showtriggervolumes", + "Allows BSL variable \"show_triggervolumes\" and Ctrl+Shift+X (in devmode) to work.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { 0, 0, 0, {0}, {0} } + } }, + { "gameplay", "Gameplay", { + { "bindablecheats", + "Allows cheats to be bound to keys. Requires 'customactions' and 'cheattable' to be true.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "characterawareness", + "Makes AI remember the player.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "cheatsenabled", + "Enables cheats without having to beat the game first.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "cheattable", + "Replaces Oni's cheat table with table that includes new cheats including devmode.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "cooldowntimer", + "Disables weapon cooldown exploit.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "customactions", + "Allows more actions to be bound through Daodan.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "kickguns", + "EXPERIMENTAL! Unfinished, do not use.", + C_BOOL, + {.intBoolVal = false}, + {.intBoolVal = false} }, + { "pathfinding", + "Size of pathfinding grid cache increased by eight times in order to prevent crashes in large levels.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "projaware", + "Allows AI to dodge incoming gunfire properly.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "throwtest", + "EXPERIMENTAL! Experiment with allowing enemies to be thrown over railings.", + C_BOOL, + {.intBoolVal = false}, + {.intBoolVal = false} }, + { "wpfadetime", + "Adds working function for existing BSL command wp_fadetime, sets fade time to 4800.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { 0, 0, 0, {0}, {0} } + } }, + { "graphics", "Graphics", { + { "binkplay", + "Fix binkplay calls to use GDI and outro same mode as intro.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "daodangl", + "Provides an improved windowed mode (-noswitch).", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "displayenum", + "Offers a more accurate list of available display modes in the Options menu.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "gamma", + "Enable gamma slider in fullscreen, disable in windowed mode.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "newweap", + "Standing above a weapon displays a message containing the weapon name and amount of ammo.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "optionsvisible", + "Always show options button in main menu, even when pausing from a game.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "showalllasersights", + "Show all (also enemies') weapon lasersights.", + C_BOOL, + {.intBoolVal = false}, + {.intBoolVal = false} }, + { "widescreenportraits", + "Prevents fly-in portraits from being stretched when playing in widescreen resolutions.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { 0, 0, 0, {0}, {0} } + } }, + { "language", "Language", { + { "chinese", + "Allow for chinese fonts to be shown if the required DLL is available.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "fonttexturecache", + "Doubles size of font texture cache.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "language", + "Localization for hardcoded strings (e.g. \"Savepoints\").", + C_STRING, + {.stringVal = "en"}, + {.stringVal = "en"} }, + { "nomultibyte", + "Enables languages which use multibyte coding (such as Chinese).", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { 0, 0, 0, {0}, {0} } + } }, + { "modding", "Modding", { + { "argb8888", + "Allows using textures with ARGB8888.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "d_regen", + "Enables script command d_regen (query/set regeneration for any character).", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "daodanbsl", + "Adds new BSL commands.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "hdscreens_lowres", + "Allow HD intro/ending screens on game resolutions smaller than 1024x768.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "largetextures", + "Textures up to 512x512 can be used.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "levelplugins", + "Allows level files to be loaded which do not end in \"_Final\".", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { 0, 0, 0, {0}, {0} } + } }, + { "oni", "Original Oni Options", { + { "debug", + "Not useful, probably does nothing.", + EXT_BOOL, + {.intBoolVal = false }, + {.extBoolVal = &AKgDebug_DebugMaps } }, + { "debugfiles", + "Logs called BSL functions to script_debug.txt.", + EXT_BOOL, + {.intBoolVal = false }, + {.extBoolVal = &BFgDebugFileEnable } }, + { "findsounds", + "Not useful, extends output of sound_list_broken_links.", + EXT_BOOL, + {.intBoolVal = false }, + {.extBoolVal = &SSgSearchOnDisk } }, + { "ignore_private_data", + "Not useful, probably does nothing.", + EXT_BOOL, + {.intBoolVal = false }, + {.extBoolVal = &opt_ignore_private_data } }, + { "sound", + "Enable sound.", + EXT_BOOL, + {.intBoolVal = true }, + {.extBoolVal = &opt_sound } }, + { "switch", + "Switch to fullscreen instead of staying in a window.", + EXT_BOOL, + {.intBoolVal = true}, + {.extBoolVal = &M3gResolutionSwitch} }, + { 0, 0, 0, {0}, {0} } + } }, + { "windows", "Windows", { + { "alttab", + "Allows to Alt-Tab out of Oni and use Windows key. May enable the screensaver as well.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "border", + "Add a border if in windowed mode and \"usedaodangl\" patch is active.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "clipcursor", + "Limit cursor to Oni's window.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "directinput", + "Enforces the usage of DirectInput on every system. Should be off for Linux/Wine.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "disablecmdline", + "Disables Oni's existing command line parser as Daodan has its own.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "killvtune", + "Prevent loading of vtuneapi.dll.", + C_BOOL, + {.intBoolVal = false}, + {.intBoolVal = false} }, + { "safeprintf", + "Replaces Oni's function that prints to startup.txt with a safer one.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "topmost", + "Keep game window on top in windowed mode, even when switching applications.", + C_BOOL, + {.intBoolVal = false}, + {.intBoolVal = false} }, + { "usegettickcount", + "Replaces Oni's timing functions with more accurate ones.", + C_BOOL, + {.intBoolVal = true}, + {.intBoolVal = true} }, + { 0, 0, 0, {0}, {0} } + } } +}; -bool DDrIniCallback(char* section, bool newsection, char* name, char* value) + +void DDrConfig_Print() +{ + for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { + for (ConfigOption_t* co = config[s].options; co->name != 0; co++) { + switch (co->type) { + case C_STRING: + STARTUPMESSAGE("Option %s.%s = %s (def %s)", config[s].name, co->name, co->value.stringVal, co->defaultValue.stringVal); + break; + case EXT_BOOL: + STARTUPMESSAGE("Option %s.%s = %d (def %d)", config[s].name, co->name, *co->value.extBoolVal, co->defaultValue.intBoolVal); + break; + case C_CMD: + break; + default: + STARTUPMESSAGE("Option %s.%s = %d (def %d)", config[s].name, co->name, co->value.intBoolVal, co->defaultValue.intBoolVal); + } + } + } +} + +void DDrConfig_PrintHelp() { - if (newsection) + STARTUPMESSAGE("Writing Daodan help file (%s)", helpFile); + + FILE* fp; + remove(helpFile); + fp = fopen(helpFile, "w"); + if (fp) { - if (!_stricmp(section, "options")) - ini_section = s_options; - else if (!_stricmp(section, "patch") || !_stricmp(section, "patches")) - ini_section = s_patch; - else if (!_stricmp(section, "bsl")) - ini_section = s_bsl; - else if (!_stricmp(section, "language")) - ini_section = s_language; - else - { - ini_section = s_unknown; - DDrStartupMessage("Daodan: Unrecognised ini section \"%s\"", section); + time_t rawtime; + struct tm* timeinfo; + char buffer[80]; + time(&rawtime); + timeinfo = localtime(&rawtime); + strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo); + + fprintf(fp, "Daodan help - generated on %s for Daodan v."DAODAN_VERSION_STRING"\n\n", buffer); + fprintf(fp, "List of Daodan configuration parameters:\n"); + for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { + fprintf(fp, " %s - %s:\n", config[s].name, config[s].description); + for (ConfigOption_t* co = config[s].options; co->name != 0; co++) { + char* name = co->name; + char* desc = co->description; + const char* tName = DDrConfig_GetOptionTypeName(co->type); + const char* val = DDrConfig_GetOptionValueString(co, 1); + if (!val) + val = ""; + fprintf(fp, " %-22s %6s=%-5s %s\n", name, tName, val, desc); + } + fprintf(fp, "\n"); } + fprintf(fp, "\nConfiguration parameters can be either set in daodan.ini or passed on command line.\n\n"); + 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"); + fprintf(fp, " [sectionX]\n parameterName = false\n"); + fprintf(fp, "\nTo pass the parameter on the command line:\n"); + fprintf(fp, " Oni.exe -parameterName false\n"); + fprintf(fp, "For bool parameters the value can be ommitted so it is regarded as \"true\":\n"); + fprintf(fp, " Oni.exe -parameterName\n"); + fprintf(fp, "To disable a bool parameter you can prefix \"no\" to the parameter name like this:\n"); + fprintf(fp, " Oni.exe -noparameterName\n"); + + fclose(fp); } - - switch (ini_section) + else { - case s_options: - if (!_stricmp(name, "border")) - opt_border = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "debug")) - AKgDebug_DebugMaps = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "debugfiles")) - BFgDebugFileEnable = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "findsounds")) - SSgSearchOnDisk = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "gamma")) - opt_gamma = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "ignore_private_data")) - opt_ignore_private_data = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "nomultibyte")) - patch_nomultibyte = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "sound")) - opt_sound = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "switch")) - M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "topmost")) - opt_topmost = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "usedaodanbsl")) - opt_usedaodanbsl = !_stricmp(inifile_cleanstr(value), "true"); - else - DDrStartupMessage("Daodan: Unrecognised ini option \"%s\"", name); - break; - case s_patch: - if (!_stricmp(name, "alttab")) - patch_alttab = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "argb8888")) - patch_argb8888 = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "binkplay")) - patch_binkplay = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "bsl")) - patch_bsl = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "cheater")) - patch_cheater = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "cheatsenabled")) - patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "cheattable")) - patch_cheattable = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "clipcursor")) - patch_clipcursor = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "cooldowntimer")) - patch_cooldowntimer = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "daodandisplayenum")) - patch_daodandisplayenum = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "directinput")) - patch_directinput = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "disablecmdline")) - patch_disablecmdline = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "flatline")) - patch_flatline = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "fonttexturecache")) - patch_fonttexturecache = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "getcmdline")) - patch_getcmdline = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "hdscreens_lowres")) - patch_hdscreens_lowres = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "highres_console")) - patch_highres_console = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "kickguns")) - patch_kickguns = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "killvtune")) - patch_killvtune = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "largetextures")) - patch_largetextures = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "levelplugins")) - patch_levelplugins = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "nomultibyte")) - patch_nomultibyte = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "newweap")) - patch_newweapon = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "optionsvisible")) - patch_optionsvisible = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "particledisablebit")) - patch_particledisablebit = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "pathfinding")) - patch_pathfinding = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "projaware")) - patch_projaware = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "safeprintf")) - patch_safeprintf = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "showalllasersights")) - patch_showalllasersights = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "showtriggervolumes")) - patch_showtriggervolumes = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "throwtest")) - patch_throwtest = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "usedaodangl")) - patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "usegettickcount")) - patch_usegettickcount = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "wpfadetime")) - patch_wpfadetime = !_stricmp(inifile_cleanstr(value), "true"); + STARTUPMESSAGE("Writing Daodan help file failed", 0); + } +} + +const char* DDrConfig_GetOptionTypeName(OptionType_t type) +{ + switch (type) { + case C_INT: + return "Int"; + case C_BOOL: + return "Bool"; + case C_STRING: + return "String"; + case C_CMD: + return "Cmd"; + case EXT_BOOL: + return "pBool"; + default: + return "unknown"; + } +} + +const char* DDrConfig_GetOptionValueString(ConfigOption_t* opt, char printdefault) +{ + OptionValue_t* optVal = (printdefault ? &opt->defaultValue : &opt->value); + int boolV = optVal->intBoolVal; + char* val = 0; + switch (opt->type) { + case C_STRING: + return optVal->stringVal; + case EXT_BOOL: + if (printdefault) + return (boolV ? "true" : "false"); else - DDrStartupMessage("Daodan: Unrecognised ini patch \"%s\"", name); - break; - case s_language: - if (!_stricmp(name, "chinese")) - patch_chinese = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "blam")) - DDrPatch__strdup((int*)(OniExe + 0x0010fb73), value); - else if (!_stricmp(name, "damn")) - DDrPatch__strdup((int*)(OniExe + 0x0010fb6e), value); - else if (!_stricmp(name, "savepoint")) - { - char* str = _strdup(value); - DDrPatch_Int32((int*)(OniExe + 0x000fd730), (int)str); - DDrPatch_Int32((int*)(OniExe + 0x000fd738), (int)str); - } - else if (!_stricmp(name, "syndicatewarehouse")) - { - char* str = _strdup(value); - DDrPatch_Int32((int*)(OniExe + 0x000fd71a), (int)str); - DDrPatch_Int32((int*)(OniExe + 0x0010ef75), (int)str); - } - else if (!_stricmp(name, "shapeshifter_on")) - DDr_CheatTable[0].message_on = _strdup(value); - else if (!_stricmp(name, "shapeshifter_off")) - DDr_CheatTable[0].message_off = _strdup(value); - else if (!_stricmp(name, "liveforever_on")) - DDr_CheatTable[1].message_on = _strdup(value); - else if (!_stricmp(name, "liveforever_off")) - DDr_CheatTable[1].message_off = _strdup(value); - else if (!_stricmp(name, "touchofdeath_on")) - DDr_CheatTable[2].message_on = _strdup(value); - else if (!_stricmp(name, "touchofdeath_off")) - DDr_CheatTable[2].message_off = _strdup(value); - else if (!_stricmp(name, "canttouchthis_on")) - DDr_CheatTable[3].message_on = _strdup(value); - else if (!_stricmp(name, "canttouchthis_off")) - DDr_CheatTable[3].message_off = _strdup(value); - else if (!_stricmp(name, "fatloot_on")) - DDr_CheatTable[4].message_on = _strdup(value); - else if (!_stricmp(name, "glassworld_on")) - DDr_CheatTable[5].message_on = _strdup(value); - else if (!_stricmp(name, "glassworld_off")) - DDr_CheatTable[5].message_off = _strdup(value); - else if (!_stricmp(name, "winlevel_on")) - DDr_CheatTable[6].message_on = _strdup(value); - else if (!_stricmp(name, "loselevel_on")) - DDr_CheatTable[7].message_on = _strdup(value); - else if (!_stricmp(name, "bighead_on")) - DDr_CheatTable[8].message_on = _strdup(value); - else if (!_stricmp(name, "bighead_off")) - DDr_CheatTable[8].message_off = _strdup(value); - else if (!_stricmp(name, "minime_on")) - DDr_CheatTable[9].message_on = _strdup(value); - else if (!_stricmp(name, "minime_off")) - DDr_CheatTable[9].message_off = _strdup(value); - else if (!_stricmp(name, "superammo_on")) - DDr_CheatTable[10].message_on = _strdup(value); - else if (!_stricmp(name, "superammo_off")) - DDr_CheatTable[10].message_off = _strdup(value); - else if (!_stricmp(name, "devmode_on")) - { - char* str = _strdup(value); - DDr_CheatTable[11].message_on = str; - DDr_CheatTable[cheat_x].message_on = str; + return (*optVal->extBoolVal ? "true" : "false"); + case C_BOOL: + return (boolV ? "true" : "false"); + case C_CMD: + return 0; + default: + val = malloc(20); + sprintf(val, "%d", boolV); + return val; + } +} + +char DDrConfig_NonDefaultOptionValue(ConfigOption_t* opt) +{ + switch (opt->type) { + case C_STRING: + return _stricmp(opt->defaultValue.stringVal, opt->value.stringVal); + case EXT_BOOL: + return !opt->defaultValue.intBoolVal != !*opt->value.extBoolVal; + case C_BOOL: + return !opt->defaultValue.intBoolVal != !opt->value.intBoolVal; + case C_CMD: + return 0; + case C_INT: + return opt->defaultValue.intBoolVal != opt->value.intBoolVal; + } + return 0; +} + +static ConfigOption_t* DDrConfig_GetOption(const char* fullOptName) +{ + char section[50]; + strcpy(section, fullOptName); + + char* option = strchr(section, '.'); + if (option == 0) { + STARTUPMESSAGE("Could not find option separator in \"%s\"", fullOptName); + return 0; + } + *option++ = 0; + + char isWildcardSection = !_stricmp(section, "*"); + + for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { + if (isWildcardSection || !_stricmp(config[s].name, section)) { + for (ConfigOption_t* co = config[s].options; co->name != 0; co++) { + if (!_stricmp(co->name, option)) { + return co; + } } - else if (!_stricmp(name, "devmode_off")) - { - char* str = _strdup(value); - DDr_CheatTable[11].message_off = str; - DDr_CheatTable[cheat_x].message_off = str; + if (!isWildcardSection) { + STARTUPMESSAGE("Could not find option \"%s\" in section \"%s\"", option, section); + return 0; } - else if (!_stricmp(name, "reservoirdogs_on")) - DDr_CheatTable[12].message_on = _strdup(value); - else if (!_stricmp(name, "reservoirdogs_off")) - DDr_CheatTable[12].message_off = _strdup(value); - else if (!_stricmp(name, "roughjustice_on")) - DDr_CheatTable[13].message_on = _strdup(value); - else if (!_stricmp(name, "roughjustice_off")) - DDr_CheatTable[13].message_off = _strdup(value); - else if (!_stricmp(name, "chenille_on")) - DDr_CheatTable[14].message_on = _strdup(value); - else if (!_stricmp(name, "chenille_off")) - DDr_CheatTable[14].message_off = _strdup(value); - else if (!_stricmp(name, "behemoth_on")) - DDr_CheatTable[15].message_on = _strdup(value); - else if (!_stricmp(name, "behemoth_off")) - DDr_CheatTable[15].message_off = _strdup(value); - else if (!_stricmp(name, "elderrune_on")) - DDr_CheatTable[16].message_on = _strdup(value); - else if (!_stricmp(name, "elderrune_off")) - DDr_CheatTable[16].message_off = _strdup(value); - else if (!_stricmp(name, "moonshadow_on")) - DDr_CheatTable[17].message_on = _strdup(value); - else if (!_stricmp(name, "moonshadow_off")) - DDr_CheatTable[17].message_off = _strdup(value); - else if (!_stricmp(name, "munitionfrenzy_on")) - DDr_CheatTable[18].message_on = _strdup(value); - else if (!_stricmp(name, "fistsoflegend_on")) - DDr_CheatTable[19].message_on = _strdup(value); - else if (!_stricmp(name, "fistsoflegend_off")) - DDr_CheatTable[19].message_off = _strdup(value); - else if (!_stricmp(name, "killmequick_on")) - DDr_CheatTable[20].message_on = _strdup(value); - else if (!_stricmp(name, "killmequick_off")) - DDr_CheatTable[20].message_off = _strdup(value); - else if (!_stricmp(name, "carousel_on")) - DDr_CheatTable[21].message_on = _strdup(value); - else if (!_stricmp(name, "carousel_off")) - DDr_CheatTable[21].message_off = _strdup(value); - else - DDrStartupMessage("Daodan: Unrecognised ini language item \"%s\"", name); - break; - case s_bsl: - default: - break; + } } - - return true; + if (!isWildcardSection) + STARTUPMESSAGE("Could not find section \"%s\" for option \"%s\"", section, option); + else + STARTUPMESSAGE("Could not find option \"%s\"", option); + return 0; } -void DDrConfig(int argc, char* argv[]) + + +ConfigOption_t* DDrConfig_GetOptOfType(const char* fullOptName, OptionType_t type) { - int i; - char* section; - char* option; - bool falseoption; + ConfigOption_t* co = DDrConfig_GetOption(fullOptName); + if (co == 0) + return 0; + + if (co->type != type) { + STARTUPMESSAGE("Option \"%s\" is not of type %s", fullOptName, DDrConfig_GetOptionTypeName(type)); + return 0; + } + return co; +} + - // Tell Oni to not load non levelX_final-files by default: - opt_ignore_private_data = false; +void DDrConfig_InitExtBools() +{ + for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { + for (ConfigOption_t* co = config[s].options; co->name != 0; co++) { + if (co->type == EXT_BOOL) { + *co->value.extBoolVal = co->defaultValue.intBoolVal; + } + } + } +} - // Enable sound by default: - opt_sound = true; - if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES) +void DDrConfig_WriteIni() +{ + FILE* fp; + STARTUPMESSAGE("%s doesn't exist, creating", iniName); + fp = fopen(iniName, "w"); + if (fp) { - FILE* fp; - DDrStartupMessage("Daodan: daodan.ini doesn't exist, creating"); - fp = fopen("daodan.ini", "w"); - if (fp) - { - fputs("[Options]\n", fp); - fputs("[Patch]\n", fp); - fputs("[BSL]\n", fp); - fputs("[Language]\n", fp); - fclose(fp); + for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { + if (strlen(config[s].name)) { + fprintf(fp, "[%s]\n", config[s].name); + for (ConfigOption_t* co = config[s].options; co->name != 0; co++) { + char* name = co->name; + const char* val = DDrConfig_GetOptionValueString(co, 0); + if (val && DDrConfig_NonDefaultOptionValue(co)) + fprintf(fp, "%s = %s\n", name, val); + } + fprintf(fp, "\n"); + } } + fclose(fp); } - - DDrStartupMessage("Daodan: Parsing daodan.ini..."); - if (!inifile_read("daodan.ini", DDrIniCallback)) - DDrStartupMessage("Daodan: Error reading daodan.ini, check your syntax!"); - DDrStartupMessage("Daodan: Finished parsing"); + else + { + STARTUPMESSAGE("Writing %s template file failed", iniName); + } +} + + +void DDrIniCallback(const char* section, const char* name, const char* value) +{ + char fullOptName[50]; + + if (!_stricmp(section, "patch")) + section = "patches"; + + strcpy(fullOptName, section); + fullOptName[strlen(section)] = '.'; + strcpy(fullOptName+strlen(section)+1, name); + ConfigOption_t* co = DDrConfig_GetOption(fullOptName); + + if (co) + { + char* buf = 0; + switch (co->type) { + case C_INT: + co->value.intBoolVal = strtol(value, NULL, 0); + break; + case C_BOOL: + co->value.intBoolVal = !_stricmp(value, "true"); + break; + case C_STRING: + buf = malloc(strlen(value)+1); + strcpy(buf, value); + co->value.stringVal = buf; + break; + case C_CMD: + co->value.callback(); + break; + case EXT_BOOL: + *(co->value.extBoolVal) = !_stricmp(value, "true"); + break; + default: + STARTUPMESSAGE("Config value type unknown: %d", co->type); + } + } else { + char buf[100]; + if (!_stricmp(section, "*")) + sprintf(buf, " %s\n", name); + else + sprintf(buf, " %s.%s\n", section, name); + if (strlen(buf) + strlen(invalidCurParamaters) < sizeof(invalidCurParamaters) - 1) { + strcpy(invalidCurParamaters + strlen(invalidCurParamaters), buf); + } + } +} - DDrStartupMessage("Daodan: Parsing command line..."); - for (i = 1; i < argc; i ++) +bool DDrConfig_ParseCommandLine(int argc, char* argv[]) +{ + for (int i = 1; i < argc; i ++) { if (argv[i][0] == '-') { - section = argv[i] + 1; - if ((option = strchr(argv[i], '.'))) + char* option; + bool invertedOption; + + option = argv[i]+1; + + invertedOption = (option[0] == 'n' || option[0] == 'N') && (option[1] == 'o' || option[1] == 'O'); + if (invertedOption) + option += 2; + + if (i < (argc - 1) && argv[i+1][0] != '-') + // Has value in next field { - *option = '\0'; - falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] == 'o' || option[2] == 'O'); - if (i < (argc - 1) && argv[i + 1][0] != '-') - DDrIniCallback(section, true, option + 1, argv[++i]); - else - DDrIniCallback(section, true, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true")); - *option = '.'; + DDrIniCallback("*", option, argv[++i]); } else + // Implicit value { - falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] == 'o' || section[1] == 'O'); - ini_section = s_options; - if (i < (argc - 1) && argv[i + 1][0] != '-') - DDrIniCallback(NULL, false, section, argv[++i]); - else - DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), (falseoption ? "false" : "true")); + DDrIniCallback("*", option, (invertedOption ? "false" : "true")); } } else { - DDrStartupMessage("Daodan: Parse error \"%s\"", argv[i]); - break; + STARTUPMESSAGE("Parse error \"%s\"", argv[i]); + return false; } } - DDrStartupMessage("Daodan: Finished parsing"); + return true; +} + +void DDrConfig(int argc, char* argv[]) +{ + STARTUPMESSAGE("Initializing standard booleans", 0); + DDrConfig_InitExtBools(); + + if (GetFileAttributes(iniName) == INVALID_FILE_ATTRIBUTES) + DDrConfig_WriteIni(); + + STARTUPMESSAGE("Parsing daodan.ini...", 0); + if (!Inifile_Read(iniName, DDrIniCallback)) + STARTUPMESSAGE("Error reading daodan.ini, check your syntax!", 0); + STARTUPMESSAGE("Finished parsing", 0); + + if (strlen(invalidCurParamaters) > 0) + { + sprintf(invalidTotalParamaters, "In %s:\n%s\n", iniName, invalidCurParamaters); + invalidCurParamaters[0] = 0; + } + + STARTUPMESSAGE("Parsing command line...", 0); + DDrConfig_ParseCommandLine(argc, argv); + STARTUPMESSAGE("Finished parsing", 0); + + if (strlen(invalidCurParamaters) > 0) + { + sprintf(invalidTotalParamaters, "%sOn command line:\n%s\n", invalidTotalParamaters, invalidCurParamaters); + } + + if (strlen(invalidTotalParamaters) > 0) + { + char msg[4096]; + sprintf(msg, "Invalid parameters given:\n%sContinue launching Oni?", invalidTotalParamaters); + int res = MessageBox(NULL, msg, "Parameters invalid", MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON1); + if (res == IDNO) { + exit(0); + } + } + + DDrConfig_WriteIni(); + +// DDrConfig_Print(); }