--- Daodan/src/Daodan_Config.c 2014/04/06 17:06:02 993 +++ Daodan/src/Daodan_Config.c 2014/04/07 10:33:27 994 @@ -1,18 +1,25 @@ #include #include +#include -#include "Daodan_Cheater.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" #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"; + +void DDrConfig_PrintHelp(); + ConfigSection_t config[] = { { "patches", "Patches", { @@ -92,7 +99,7 @@ ConfigSection_t config[] = { {.intBoolVal = true}, {.intBoolVal = true} }, { "hdscreens_lowres", - "???", + "Allow HD screens with resolution < 1024*768.", C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, @@ -209,8 +216,13 @@ ConfigSection_t config[] = { C_BOOL, {.intBoolVal = true}, {.intBoolVal = true} }, + { "help", + "Generates this help file.", + C_CMD, + {.intBoolVal = 0}, + {.callback = DDrConfig_PrintHelp} }, { "ignore_private_data", - "???", + "? No effect ?", EXT_BOOL, {.intBoolVal = false }, {.extBoolVal = &opt_ignore_private_data } }, @@ -255,6 +267,8 @@ void DDrConfig_Print() 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); } @@ -262,6 +276,75 @@ void DDrConfig_Print() } } +void DDrConfig_PrintHelp() +{ + STARTUPMESSAGE("Writing Daodan help file (%s)", helpFile); + + FILE* fp; + remove(helpFile); + fp = fopen(helpFile, "w"); + if (fp) + { + 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); + 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); + } + 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 -sectionX.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, "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"); + + fclose(fp); + } + else + { + STARTUPMESSAGE("Writing Daodan help file failed", 0); + } +} + const char* DDrConfig_GetOptionTypeName(OptionType_t type) { switch (type) { @@ -271,6 +354,8 @@ const char* DDrConfig_GetOptionTypeName( return "Bool"; case C_STRING: return "String"; + case C_CMD: + return "Cmd"; case EXT_BOOL: return "pBool"; default: @@ -321,6 +406,7 @@ ConfigOption_t* DDrConfig_GetOptOfType(c } + void DDrConfig_InitExtBools() { for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { @@ -334,7 +420,26 @@ void DDrConfig_InitExtBools() -void DDrIniCallback(char* section, char* name, char* value) +void DDrConfig_WriteTemplateIni() +{ + FILE* fp; + STARTUPMESSAGE("%s doesn't exist, creating", iniName); + fp = fopen(iniName, "w"); + if (fp) + { + for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { + fprintf(fp, "[%s]\n", config[s].name); + } + fclose(fp); + } + else + { + STARTUPMESSAGE("Writing %s template file failed", iniName); + } +} + + +void DDrIniCallback(const char* section, const char* name, const char* value) { static char curSection[20]; char fullOptName[50]; @@ -352,6 +457,7 @@ void DDrIniCallback(char* section, char* if (co) { + char* buf = 0; switch (co->type) { case C_INT: co->value.intBoolVal = strtol(value, NULL, 0); @@ -360,7 +466,12 @@ void DDrIniCallback(char* section, char* co->value.intBoolVal = !_stricmp(value, "true"); break; case C_STRING: - co->value.stringVal = value; + 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"); @@ -371,28 +482,62 @@ void DDrIniCallback(char* section, char* } } -void DDrConfig_WriteTemplateIni() + +bool DDrConfig_ParseCommandLine(int argc, char* argv[]) { - FILE* fp; - STARTUPMESSAGE("%s doesn't exist, creating", iniName); - fp = fopen(iniName, "w"); - if (fp) + for (int i = 1; i < argc; i ++) { - for (unsigned int s = 0; s < ARRAY_SIZE(config); s++) { - fprintf(fp, "[%s]\n", config[s].name); + 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; + } + + 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 + { + DDrIniCallback(section, option, argv[++i]); + } + else + // Implicit value + { + DDrIniCallback(section, option, (invertedOption ? "false" : "true")); + } + + if (optionsep) + *optionsep = '.'; + } + else + { + STARTUPMESSAGE("Parse error \"%s\"", argv[i]); + return false; } - fclose(fp); } + return true; } - void DDrConfig(int argc, char* argv[]) { - int i; - char* section; - char* option; - bool falseoption; - + STARTUPMESSAGE("Initializing standard booleans", 0); DDrConfig_InitExtBools(); if (GetFileAttributes(iniName) == INVALID_FILE_ATTRIBUTES) @@ -406,145 +551,9 @@ void DDrConfig(int argc, char* argv[]) STARTUPMESSAGE("Parsing command line...", 0); - for (i = 1; i < argc; i ++) - { - if (argv[i][0] == '-') - { - section = argv[i] + 1; - if ((option = strchr(argv[i], '.'))) - { - *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, option + 1, argv[++i]); - else - DDrIniCallback(section, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true")); - *option = '.'; - } - else - { - falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] == 'o' || section[1] == 'O'); - if (i < (argc - 1) && argv[i + 1][0] != '-') - DDrIniCallback("options", section, argv[++i]); - else - DDrIniCallback("options", section + (falseoption ? 2 : 0), (falseoption ? "false" : "true")); - } - } - else - { - STARTUPMESSAGE("Parse error \"%s\"", argv[i]); - break; - } - } + DDrConfig_ParseCommandLine(argc, argv); STARTUPMESSAGE("Finished parsing", 0); -} - -/* - case s_language: - 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; - } - else if (!_stricmp(name, "devmode_off")) - { - char* str = _strdup(value); - DDr_CheatTable[11].message_off = str; - DDr_CheatTable[cheat_x].message_off = str; - } - 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); -*/ +// DDrConfig_Print(); +}