ref: 666269029dbd79b2fdbe46131d853af9b2801cdf
parent: f204e14291040b4dc054c83ccf81b3e57257ab15
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue May 7 09:18:32 EDT 2019
Made Config.cpp ASM-accurate
--- a/msvc2003/devilution/comparer-config.toml
+++ b/msvc2003/devilution/comparer-config.toml
@@ -272,6 +272,14 @@
addr = 0x40AC90
[[func]]
+name = "LoadConfigData"
+addr = 0x40AD60
+
+[[func]]
+name = "DefaultConfigData"
+addr = 0x40AE30
+
+[[func]]
name = "Call_Escape"
addr = 0x40DD70
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -11,7 +11,10 @@
#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));
@@ -18,14 +21,17 @@
//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,22 +48,32 @@
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;
--- a/src/Config.h
+++ b/src/Config.h
@@ -2,6 +2,8 @@
#include <stdint.h>
+#include "WindowsWrapper.h"
+
struct CONFIG
{
char proof[0x20];
@@ -14,5 +16,5 @@
int32_t joystick_button[8];
};
-bool LoadConfigData(CONFIG *conf);
+BOOL LoadConfigData(CONFIG *conf);
void DefaultConfigData(CONFIG *conf);