--- Daodan/src/Daodan_Config.c 2014/04/07 10:33:27 994 +++ Daodan/src/Daodan_Config.c 2015/03/23 23:29:19 1017 @@ -2,6 +2,7 @@ #include #include +#include "Daodan.h" #include "Daodan_Config.h" #include "Daodan_Patch.h" #include "Patches/Utility.h" @@ -11,40 +12,47 @@ #include "Inifile_Reader.h" -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) - static const char* iniName = "daodan.ini"; static const char* helpFile = "daodan_help.txt"; static const char* defaultSection = "options"; +static char invalidCurParamaters[2000] = ""; +static char invalidTotalParamaters[4000] = ""; + void DDrConfig_PrintHelp(); ConfigSection_t config[] = { - { "patches", "Patches", { - { "alttab", - "Allows user to switch applications while in Oni (Alt-Tab) and use Windows key, however it may enable the screensaver as well.", - C_BOOL, - {.intBoolVal = true}, - {.intBoolVal = true} }, - { "argb8888", - "Textures using ARGB8888 can be used.", + { "", "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} }, - { "binkplay", - "Fix binkplay calls to use GDI and outro same mode as intro.", + { "showtriggervolumes", + "Allows BSL variable \"show_triggervolumes\" and Ctrl+Shift+X (in devmode) to work.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "bsl", - "Enables d_regen (unfinished) and prevents fly-in portraits from being stretched when playing in widescreen resolutions.", + { 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} }, - { "cheater", - "Adds new cheat codes (see section below).", + { "characterawareness", + "Makes AI remember the player.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, @@ -54,17 +62,7 @@ ConfigSection_t config[] = { {.intBoolVal = true}, {.intBoolVal = true} }, { "cheattable", - "Replaces Oni's cheat table with table that includes new cheats (see section below).", - C_BOOL, - {.intBoolVal = true}, - {.intBoolVal = true} }, - { "chinese", - "Allow for chinese fonts to be shown.", - C_BOOL, - {.intBoolVal = true}, - {.intBoolVal = true} }, - { "clipcursor", - "Limit cursor to Oni's window.", + "Replaces Oni's cheat table with table that includes new cheats including devmode.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, @@ -73,63 +71,61 @@ ConfigSection_t config[] = { C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "daodandisplayenum", - "Offers more display modes in the Options menu.", + { "customactions", + "Allows more actions to be bound through Daodan.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "directinput", - "Forces on DirectInput.", + { "kickguns", + "EXPERIMENTAL! Unfinished, do not use.", C_BOOL, - {.intBoolVal = true}, - {.intBoolVal = true} }, - { "disablecmdline", - "Replaces existing command line parser with Daodan's in order to add new commands. Meant to be used with getcmdline.", + {.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} }, - { "fonttexturecache", - "Doubles size of font texture cache.", + { "projaware", + "Allows AI to dodge incoming gunfire properly.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "getcmdline", - "Replaces existing command line parser with Daodan's in order to add new commands. Meant to be used with disablecmdline.", + { "throwtest", + "EXPERIMENTAL! Experiment with allowing enemies to be thrown over railings.", C_BOOL, - {.intBoolVal = true}, - {.intBoolVal = true} }, - { "hdscreens_lowres", - "Allow HD screens with resolution < 1024*768.", + {.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} }, - { "highres_console", - "Fixes bug where console line becomes invisible at higher resolutions.", + { 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} }, - { "kickguns", - "Unfinished, do not use.", - C_BOOL, - {.intBoolVal = false}, - {.intBoolVal = false} }, - { "largetextures", - "Textures up to 512x512 can be used.", + { "daodangl", + "Provides an improved windowed mode (-noswitch).", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "levelplugins", - "Allows level files to be loaded from the GDF which do not end in \"_Final\".", + { "displayenum", + "Offers a more accurate list of available display modes in the Options menu.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "newweap", - "Picking up a weapon displays a message containing the weapon name and amount of ammo.", + { "gamma", + "Enable gamma slider in fullscreen, disable in windowed mode.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "nomultibyte", - "Enables languages which use multibyte coding (such as Chinese).", + { "newweap", + "Standing above a weapon displays a message containing the weapon name and amount of ammo.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, @@ -138,119 +134,153 @@ ConfigSection_t config[] = { C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "particledisablebit", - "Unlocks particle action disabling/enabling bits for all events so that a particle event can occur multiple times.", + { "showalllasersights", + "Show all (also enemies') weapon lasersights.", C_BOOL, {.intBoolVal = false}, {.intBoolVal = false} }, - { "pathfinding", - "Multiplies size of pathfinding grid cache by eight in order to prevent crashes in large levels.", + { "widescreenportraits", + "Prevents fly-in portraits from being stretched when playing in widescreen resolutions.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "projaware", - "Allows AI to dodge incoming gunfire properly.", + { 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} }, - { "safeprintf", - "Replaces Oni's function that prints to startup.txt with a safer one.", + { "fonttexturecache", + "Doubles size of font texture cache.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "showalllasersights", - "Show all (also enemies') weapon lasersights.", + { "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 = false}, - {.intBoolVal = false} }, - { "showtriggervolumes", - "Allows BSL variable \"show_triggervolumes\" to work when set to 1.", + {.intBoolVal = true}, + {.intBoolVal = true} }, + { 0, 0, 0, {0}, {0} } + } }, + { "modding", "Modding", { + { "argb8888", + "Allows using textures with ARGB8888.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "throwtest", - "Not recommended for use; experiment with allowing enemies to be thrown over railings.", + { "d_regen", + "Enables script command d_regen (query/set regeneration for any character).", C_BOOL, - {.intBoolVal = false}, - {.intBoolVal = false} }, - { "usedaodangl", - "Provides an improved windowed mode (-noswitch); this patch is known to break the hiding of the Windows taskbar in fullscreen mode.", + {.intBoolVal = true}, + {.intBoolVal = true} }, + { "daodanbsl", + "Adds new BSL commands.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "usegettickcount", - "Replaces Oni's timing functions with more accurate ones.", + { "hdscreens_lowres", + "Allow HD intro/ending screens on game resolutions smaller than 1024x768.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "wpfadetime", - "Adds working function for existing BSL command wp_fadetime, sets fade time to 4800.", + { "largetextures", + "Textures up to 512x512 can be used.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { 0, 0, 0, {0}, {0} } - } }, - { "options", "Options", { - { "border", - "If \"windowhack\" patch is active, make sure game window has border in windowed mode.", + { "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 } }, - { "gamma", - "Enable gamma slider in fullscreen.", - C_BOOL, - {.intBoolVal = true}, - {.intBoolVal = true} }, - { "help", - "Generates this help file.", - C_CMD, - {.intBoolVal = 0}, - {.callback = DDrConfig_PrintHelp} }, { "ignore_private_data", - "? No effect ?", + "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", - "Always switch screen to resolution on Oni's Options screen, making the game fullscreen; opposite of Oni's built-in argument \"noswitch\".", + "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} }, - { "usedaodanbsl", - "Adds new BSL commands (see below).", + { "usegettickcount", + "Replaces Oni's timing functions with more accurate ones.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, - { "language", - "Localization for hardcoded strings (e.g. \"Savepoints\").", - C_STRING, - {.stringVal = "en"}, - {.stringVal = "en"} }, { 0, 0, 0, {0}, {0} } } } }; @@ -300,25 +330,9 @@ void DDrConfig_PrintHelp() char* name = co->name; char* desc = co->description; const char* tName = DDrConfig_GetOptionTypeName(co->type); - int boolV = co->defaultValue.intBoolVal; - char* val; - switch (co->type) { - case C_STRING: - val = co->defaultValue.stringVal; - break; - case EXT_BOOL: - val = (boolV ? "true" : "false"); - break; - case C_BOOL: - val = (boolV ? "true" : "false"); - break; - case C_CMD: - val = ""; - break; - default: - val = malloc(20); - sprintf(val, "%d", boolV); - } + const char* val = DDrConfig_GetOptionValueString(co, 1); + if (!val) + val = ""; fprintf(fp, " %-22s %6s=%-5s %s\n", name, tName, val, desc); } fprintf(fp, "\n"); @@ -327,15 +341,11 @@ void DDrConfig_PrintHelp() 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 -sectionX.parameterName false\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 -sectionX.parameterName\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 -sectionX.noparameterName\n"); - fprintf(fp, "If no section is given it is assumed to be \"%s\", e.g.\n", defaultSection); - fprintf(fp, " Oni.exe -%s.parametername\n", defaultSection); - fprintf(fp, "can simply be written as\n"); - fprintf(fp, " Oni.exe -parametername\n"); + fprintf(fp, " Oni.exe -noparameterName\n"); fclose(fp); } @@ -363,6 +373,47 @@ const char* DDrConfig_GetOptionTypeName( } } +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 + 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]; @@ -375,18 +426,25 @@ static ConfigOption_t* DDrConfig_GetOpti } *option++ = 0; + char isWildcardSection = !_stricmp(section, "*"); + for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { - if (!_stricmp(config[s].name, section)) { + 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; } } - STARTUPMESSAGE("Could not find option \"%s\" in section \"%s\"", option, section); - return 0; + if (!isWildcardSection) { + STARTUPMESSAGE("Could not find option \"%s\" in section \"%s\"", option, section); + return 0; + } } } - STARTUPMESSAGE("Could not find section \"%s\" for option \"%s\"", section, option); + if (!isWildcardSection) + STARTUPMESSAGE("Could not find section \"%s\" for option \"%s\"", section, option); + else + STARTUPMESSAGE("Could not find option \"%s\"", option); return 0; } @@ -420,7 +478,7 @@ void DDrConfig_InitExtBools() -void DDrConfig_WriteTemplateIni() +void DDrConfig_WriteIni() { FILE* fp; STARTUPMESSAGE("%s doesn't exist, creating", iniName); @@ -428,7 +486,16 @@ void DDrConfig_WriteTemplateIni() if (fp) { for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { - fprintf(fp, "[%s]\n", config[s].name); + 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); } @@ -441,17 +508,14 @@ void DDrConfig_WriteTemplateIni() void DDrIniCallback(const char* section, const char* name, const char* value) { - static char curSection[20]; char fullOptName[50]; if (!_stricmp(section, "patch")) section = "patches"; - strcpy(curSection, section); - - strcpy(fullOptName, curSection); - fullOptName[strlen(curSection)] = '.'; - strcpy(fullOptName+strlen(curSection)+1, name); + strcpy(fullOptName, section); + fullOptName[strlen(section)] = '.'; + strcpy(fullOptName+strlen(section)+1, name); ConfigOption_t* co = DDrConfig_GetOption(fullOptName); @@ -479,6 +543,15 @@ void DDrIniCallback(const char* section, 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); + } } } @@ -489,24 +562,10 @@ bool DDrConfig_ParseCommandLine(int argc { if (argv[i][0] == '-') { - const char* section; - char* optionsep; char* option; bool invertedOption; - if ((optionsep = strchr(argv[i], '.'))) - // Is "section.option" - { - *optionsep = 0; - option = optionsep+1; - section = argv[i]+1; - } - else - // Is just "option" - { - section = defaultSection; - option = argv[i]+1; - } + option = argv[i]+1; invertedOption = (option[0] == 'n' || option[0] == 'N') && (option[1] == 'o' || option[1] == 'O'); if (invertedOption) @@ -515,16 +574,13 @@ bool DDrConfig_ParseCommandLine(int argc if (i < (argc - 1) && argv[i+1][0] != '-') // Has value in next field { - DDrIniCallback(section, option, argv[++i]); + DDrIniCallback("*", option, argv[++i]); } else // Implicit value { - DDrIniCallback(section, option, (invertedOption ? "false" : "true")); + DDrIniCallback("*", option, (invertedOption ? "false" : "true")); } - - if (optionsep) - *optionsep = '.'; } else { @@ -541,19 +597,40 @@ void DDrConfig(int argc, char* argv[]) DDrConfig_InitExtBools(); if (GetFileAttributes(iniName) == INVALID_FILE_ATTRIBUTES) - DDrConfig_WriteTemplateIni(); + 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(); }