From 995d1f294bcf868c56ac675940bdd930e3dfb9b5 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sat, 14 Oct 2023 05:00:27 +0200 Subject: [PATCH] #252 add presets for Nox --- inc/config.h | 1 + src/config.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/inc/config.h b/inc/config.h index dc35419..e0d6a72 100644 --- a/inc/config.h +++ b/inc/config.h @@ -4,6 +4,7 @@ #define WIN32_LEAN_AND_MEAN #include +#define FILE_EXISTS(a) (GetFileAttributes(a) != INVALID_FILE_ATTRIBUTES) typedef struct CNCDDRAWCONFIG { diff --git a/src/config.c b/src/config.c index 46dd242..08508ae 100644 --- a/src/config.c +++ b/src/config.c @@ -858,6 +858,16 @@ static void cfg_create_ini() "renderer=direct3d9\n" "nonexclusive=false\n" "windowed=false\n" + "maxgameticks=-1\n" + "\n" + "; Nox Reloaded\n" + "[NoxReloaded]\n" + "maxgameticks=-1\n" + "\n" + "; Nox GOG\n" + "[Game/2]\n" + "checkfile=.\\nox.cfg\n" + "maxgameticks=-1\n" "\n" "; Outlaws\n" "[olwin]\n" @@ -1091,19 +1101,53 @@ static DWORD cfg_get_string(LPCSTR key, LPCSTR default_value, LPSTR out_string, DWORD s = GetPrivateProfileStringA( g_config.process_file_name, key, "", out_string, out_size, g_config.ini_path); + char buf[MAX_PATH] = { 0 }; + if (s > 0) { - char buf[MAX_PATH] = { 0 }; - if (GetPrivateProfileStringA( g_config.process_file_name, "checkfile", "", buf, sizeof(buf), g_config.ini_path) > 0) { - if (GetFileAttributes(buf) != INVALID_FILE_ATTRIBUTES) + if (FILE_EXISTS(buf)) + { return s; + } + else + { + char section[MAX_PATH] = { 0 }; + _snprintf(section, sizeof(section), "%s?%d", g_config.process_file_name, 2); + + s = GetPrivateProfileStringA(section, key, "", out_string, out_size, g_config.ini_path); + + if (s > 0) + { + if (GetPrivateProfileStringA(section, "checkfile", "", buf, sizeof(buf), g_config.ini_path) > 0) + { + if (FILE_EXISTS(buf)) + return s; + } + } + } } else return s; } + else + { + char section[MAX_PATH] = { 0 }; + _snprintf(section, sizeof(section), "%s/%d", g_config.process_file_name, 2); + + s = GetPrivateProfileStringA(section, key, "", out_string, out_size, g_config.ini_path); + + if (s > 0) + { + if (GetPrivateProfileStringA(section, "checkfile", "", buf, sizeof(buf), g_config.ini_path) > 0) + { + if (FILE_EXISTS(buf)) + return s; + } + } + } return GetPrivateProfileStringA("ddraw", key, default_value, out_string, out_size, g_config.ini_path); }