From 8702ffe44a3e0a8a03131a3fcf23fa9801f769ba Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Thu, 16 Sep 2021 02:25:22 +0200 Subject: [PATCH] make cfg ini functions public --- inc/config.h | 4 ++++ inc/dd.h | 1 - src/config.c | 58 +++++++++++++++++++++++++--------------------- src/mouse.c | 2 +- src/winapi_hooks.c | 3 ++- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/inc/config.h b/inc/config.h index 19a98d7..f70523c 100644 --- a/inc/config.h +++ b/inc/config.h @@ -21,4 +21,8 @@ extern CNCDDRAWCONFIG g_config; void cfg_load(); void cfg_save(); +BOOL cfg_get_bool(LPCSTR key, BOOL default_value); +int cfg_get_int(LPCSTR key, int default_value); +DWORD cfg_get_string(LPCSTR key, LPCSTR default_value, LPSTR out_string, DWORD out_size); + #endif diff --git a/inc/dd.h b/inc/dd.h index b119a79..e22b25e 100644 --- a/inc/dd.h +++ b/inc/dd.h @@ -125,7 +125,6 @@ typedef struct CNCDDRAW BOOL fixpitch; int fixchilds; BOOL fixwndprochook; - BOOL fixmousehook; BOOL fixnotresponding; BOOL d3d9linear; BOOL gdilinear; diff --git a/src/config.c b/src/config.c index 5bdeb79..50311c8 100644 --- a/src/config.c +++ b/src/config.c @@ -10,10 +10,7 @@ #include "hook.h" #include "debug.h" - -static BOOL cfg_get_bool(LPCSTR key, BOOL default_value); -static int cfg_get_int(LPCSTR key, int default_value); -static DWORD cfg_get_string(LPCSTR key, LPCSTR default_value, LPSTR out_string, DWORD out_size); +static void cfg_init_paths(); static void cfg_create_ini(); CNCDDRAWCONFIG g_config = @@ -23,25 +20,7 @@ void cfg_load() { char tmp[256]; - /* get process filename and directory */ - if (GetModuleFileNameA(NULL, g_config.game_path, sizeof(g_config.game_path) - 1) > 0) - { - _splitpath(g_config.game_path, NULL, NULL, g_config.process_file_name, NULL); - - char* end = strstr(g_config.game_path, g_config.process_file_name); - - if (end) - { - *end = 0; - } - else - { - g_config.game_path[0] = 0; - } - } - - /* set up settings ini */ - strncpy(g_config.ini_path, ".\\ddraw.ini", sizeof(g_config.ini_path) - 1); + cfg_init_paths(); if (GetFileAttributes(g_config.ini_path) == INVALID_FILE_ATTRIBUTES) cfg_create_ini(); @@ -62,7 +41,6 @@ void cfg_load() g_ddraw->fixpitch = cfg_get_bool("fixpitch", FALSE); g_ddraw->fixchilds = cfg_get_int("fixchilds", FIX_CHILDS_DETECT_PAINT); g_ddraw->fixwndprochook = cfg_get_bool("fixwndprochook", FALSE); - g_ddraw->fixmousehook = cfg_get_bool("fixmousehook", FALSE); g_ddraw->fixnotresponding = cfg_get_bool("fixnotresponding", FALSE); g_ddraw->releasealt = cfg_get_bool("releasealt", FALSE); g_ddraw->d3d9linear = cfg_get_bool("d3d9linear", TRUE); @@ -952,8 +930,34 @@ static void cfg_create_ini() } } -static DWORD cfg_get_string(LPCSTR key, LPCSTR default_value, LPSTR out_string, DWORD out_size) +static void cfg_init_paths() { + /* get process filename and directory */ + if (GetModuleFileNameA(NULL, g_config.game_path, sizeof(g_config.game_path) - 1) > 0) + { + _splitpath(g_config.game_path, NULL, NULL, g_config.process_file_name, NULL); + + char* end = strstr(g_config.game_path, g_config.process_file_name); + + if (end) + { + *end = 0; + } + else + { + g_config.game_path[0] = 0; + } + } + + /* set up settings ini */ + strncpy(g_config.ini_path, ".\\ddraw.ini", sizeof(g_config.ini_path) - 1); +} + +DWORD cfg_get_string(LPCSTR key, LPCSTR default_value, LPSTR out_string, DWORD out_size) +{ + if (!g_config.ini_path[0]) + cfg_init_paths(); + DWORD s = GetPrivateProfileStringA( g_config.process_file_name, key, "", out_string, out_size, g_config.ini_path); @@ -974,7 +978,7 @@ static DWORD cfg_get_string(LPCSTR key, LPCSTR default_value, LPSTR out_string, return GetPrivateProfileStringA("ddraw", key, default_value, out_string, out_size, g_config.ini_path); } -static BOOL cfg_get_bool(LPCSTR key, BOOL default_value) +BOOL cfg_get_bool(LPCSTR key, BOOL default_value) { char value[8]; cfg_get_string(key, default_value ? "Yes" : "No", value, sizeof(value)); @@ -982,7 +986,7 @@ static BOOL cfg_get_bool(LPCSTR key, BOOL default_value) return (_stricmp(value, "yes") == 0 || _stricmp(value, "true") == 0 || _stricmp(value, "1") == 0); } -static int cfg_get_int(LPCSTR key, int default_value) +int cfg_get_int(LPCSTR key, int default_value) { char def_value[16]; _snprintf(def_value, sizeof(def_value), "%d", default_value); diff --git a/src/mouse.c b/src/mouse.c index 5ef10d3..de48611 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -95,7 +95,7 @@ void mouse_unlock() LRESULT CALLBACK mouse_hook_proc(int Code, WPARAM wParam, LPARAM lParam) { - if (!g_ddraw || !g_ddraw->fixmousehook) + if (!g_ddraw) return g_mouse_proc(Code, wParam, lParam); if (Code < 0 || (!g_ddraw->devmode && !g_ddraw->locked)) diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index 777f817..33be65e 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -2,6 +2,7 @@ #include #include #include "debug.h" +#include "config.h" #include "dd.h" #include "ddraw.h" #include "hook.h" @@ -495,7 +496,7 @@ HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, D return NULL; } - if (idHook == WH_MOUSE && lpfn && !g_mouse_hook) + if (idHook == WH_MOUSE && lpfn && !hmod && !g_mouse_hook && cfg_get_bool("fixmousehook", FALSE)) { g_mouse_proc = lpfn; return g_mouse_hook = real_SetWindowsHookExA(idHook, mouse_hook_proc, hmod, dwThreadId);