From 31119eacb88820597d8e55bccac25511624e1d50 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Thu, 9 Sep 2021 21:32:54 +0200 Subject: [PATCH] #118 fix shaders with ja2 wildfire --- inc/config.h | 3 ++- src/config.c | 29 ++++++++++++++++++++--------- src/render_ogl.c | 12 +++++++++++- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/inc/config.h b/inc/config.h index 2a89718..19a98d7 100644 --- a/inc/config.h +++ b/inc/config.h @@ -10,7 +10,8 @@ typedef struct CNCDDRAWCONFIG RECT window_rect; int window_state; char ini_path[MAX_PATH]; - char process_file_name[96]; + char game_path[MAX_PATH]; + char process_file_name[MAX_PATH]; int save_settings; } CNCDDRAWCONFIG; diff --git a/src/config.c b/src/config.c index db71bbc..19d7c73 100644 --- a/src/config.c +++ b/src/config.c @@ -21,20 +21,31 @@ CNCDDRAWCONFIG g_config = void cfg_load() { - /* set up settings ini */ - char cwd[MAX_PATH]; char tmp[256]; - GetCurrentDirectoryA(sizeof(cwd), cwd); - _snprintf(g_config.ini_path, sizeof(g_config.ini_path), "%s\\ddraw.ini", cwd); + + /* 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); if (GetFileAttributes(g_config.ini_path) == INVALID_FILE_ATTRIBUTES) cfg_create_ini(); - /* get process filename */ - char process_file_path[MAX_PATH] = { 0 }; - GetModuleFileNameA(NULL, process_file_path, MAX_PATH); - _splitpath(process_file_path, NULL, NULL, g_config.process_file_name, NULL); - /* load settings from ini */ g_ddraw->windowed = cfg_get_bool("windowed", FALSE); g_ddraw->border = cfg_get_bool("border", TRUE); diff --git a/src/render_ogl.c b/src/render_ogl.c index ad2c017..87c6b1e 100644 --- a/src/render_ogl.c +++ b/src/render_ogl.c @@ -1,5 +1,6 @@ #include #include +#include "config.h" #include "fps_limiter.h" #include "opengl_utils.h" #include "dd.h" @@ -140,7 +141,16 @@ static void ogl_build_programs() if (g_ogl.main_program) { - g_ogl.scale_program = oglu_build_program_from_file(g_ddraw->shader, wglCreateContextAttribsARB != NULL); + char shader_path[MAX_PATH] = { 0 }; + + strncpy(shader_path, g_ddraw->shader, sizeof(shader_path) - 1); + + if (GetFileAttributes(shader_path) == INVALID_FILE_ATTRIBUTES) + { + _snprintf(shader_path, sizeof(shader_path) - 1, "%s%s", g_config.game_path, g_ddraw->shader); + } + + g_ogl.scale_program = oglu_build_program_from_file(shader_path, wglCreateContextAttribsARB != NULL); } else {