1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

make cfg ini functions public

This commit is contained in:
FunkyFr3sh 2021-09-16 02:25:22 +02:00
parent 58a86abfc8
commit 8702ffe44a
5 changed files with 38 additions and 30 deletions

View File

@ -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

View File

@ -125,7 +125,6 @@ typedef struct CNCDDRAW
BOOL fixpitch;
int fixchilds;
BOOL fixwndprochook;
BOOL fixmousehook;
BOOL fixnotresponding;
BOOL d3d9linear;
BOOL gdilinear;

View File

@ -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);

View File

@ -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))

View File

@ -2,6 +2,7 @@
#include <windowsx.h>
#include <math.h>
#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);