diff --git a/msvc2003/devilution/comparer-config.toml b/msvc2003/devilution/comparer-config.toml index 9b675d93..922dd4ff 100644 --- a/msvc2003/devilution/comparer-config.toml +++ b/msvc2003/devilution/comparer-config.toml @@ -271,6 +271,14 @@ addr = 0x40ABC0 name = "SetCaret" addr = 0x40AC90 +[[func]] +name = "LoadConfigData" +addr = 0x40AD60 + +[[func]] +name = "DefaultConfigData" +addr = 0x40AE30 + [[func]] name = "Call_Escape" addr = 0x40DD70 diff --git a/src/Config.cpp b/src/Config.cpp index 1b7c7bc4..c9b12710 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -11,21 +11,27 @@ #include "Tags.h" #include "Types.h" -bool LoadConfigData(CONFIG *conf) +static const char* const config_filename = "Config.dat"; // Not the original name +static const char* const config_magic = "DOUKUTSU20041206"; // Not the original name + +BOOL LoadConfigData(CONFIG *conf) { //Clear old config data memset(conf, 0, sizeof(CONFIG)); //Get path char path[PATH_LENGTH]; - sprintf(path, "%s/%s", gModulePath, "Config.dat"); + sprintf(path, "%s/%s", gModulePath, config_filename); //Open file FILE *fp = fopen(path, "rb"); if (fp == NULL) - return false; + return FALSE; //Read data +#ifdef NONPORTABLE + size_t fread_result = fread(conf, sizeof(CONFIG), 1, fp); // Not the original name +#else //Read the version id and font name fread(conf->proof, sizeof(conf->proof), 1, fp); fread(conf->font_name, sizeof(conf->font_name), 1, fp); @@ -42,23 +48,33 @@ bool LoadConfigData(CONFIG *conf) conf->bJoystick = File_ReadLE32(fp); for (int button = 0; button < 8; button++) conf->joystick_button[button] = File_ReadLE32(fp); +#endif //Close file fclose(fp); - //Check if version is correct, return that it succeeded - if (!strcmp(conf->proof, "DOUKUTSU20041206")) - return true; + //Check if version is not correct, and return if it failed +#ifdef NONPORTABLE + if (fread_result != 1 || strcmp(conf->proof, config_magic)) +#else + if (strcmp(conf->proof, config_magic)) +#endif + { + memset(conf, 0, sizeof(CONFIG)); + return FALSE; + } - //If not, return that it failed - return false; + return TRUE; } void DefaultConfigData(CONFIG *conf) { - //Claer old config data + //Clear old config data memset(conf, 0, sizeof(CONFIG)); + //Fun fact: The Linux port added this line: + //conf->display_mode = 1; + //Reset joystick settings (as these can't simply be set to 0) conf->bJoystick = 1; conf->joystick_button[0] = 2; diff --git a/src/Config.h b/src/Config.h index f7981004..c61e1947 100644 --- a/src/Config.h +++ b/src/Config.h @@ -2,6 +2,8 @@ #include +#include "WindowsWrapper.h" + struct CONFIG { char proof[0x20]; @@ -14,5 +16,5 @@ struct CONFIG int32_t joystick_button[8]; }; -bool LoadConfigData(CONFIG *conf); +BOOL LoadConfigData(CONFIG *conf); void DefaultConfigData(CONFIG *conf);