win-capture: Avoid obs functions in init_hooks

master
Zachary Lund 2018-04-24 13:45:56 -07:00
parent 30d967eafa
commit 6475a1c000
2 changed files with 27 additions and 20 deletions

View File

@ -153,11 +153,11 @@ failed:
return !ver_mismatch;
}
bool load_graphics_offsets(bool is32bit)
bool load_graphics_offsets(bool is32bit, const char *config_path)
{
char *offset_exe_path = NULL;
struct dstr offset_exe = {0};
char *config_ini = NULL;
struct dstr config_ini = {0};
struct dstr str = {0};
os_process_pipe_t *pp;
bool success = false;
@ -188,10 +188,12 @@ bool load_graphics_offsets(bool is32bit)
dstr_ncat(&str, data, len);
}
config_ini = obs_module_config_path(is32bit ? "32.ini" : "64.ini");
os_quick_write_utf8_file_safe(config_ini, str.array, str.len, false,
dstr_copy(&config_ini, config_path);
dstr_cat(&config_ini, is32bit ? "32.ini" : "64.ini");
os_quick_write_utf8_file_safe(config_ini.array, str.array, str.len, false,
"tmp", NULL);
bfree(config_ini);
dstr_free(&config_ini);
success = load_offsets_from_string(is32bit ? &offsets32 : &offsets64,
str.array);
@ -208,17 +210,18 @@ error:
return success;
}
bool load_cached_graphics_offsets(bool is32bit)
bool load_cached_graphics_offsets(bool is32bit, const char *config_path)
{
char *config_ini = NULL;
struct dstr config_ini = {0};
bool success;
config_ini = obs_module_config_path(is32bit ? "32.ini" : "64.ini");
dstr_copy(&config_ini, config_path);
dstr_cat(&config_ini, is32bit ? "32.ini" : "64.ini");
success = load_offsets_from_file(is32bit ? &offsets32 : &offsets64,
config_ini);
config_ini.array);
if (!success)
success = load_graphics_offsets(is32bit);
success = load_graphics_offsets(is32bit, config_path);
bfree(config_ini);
dstr_free(&config_ini);
return success;
}

View File

@ -14,8 +14,8 @@ extern struct obs_source_info game_capture_info;
static HANDLE init_hooks_thread = NULL;
extern bool cached_versions_match(void);
extern bool load_cached_graphics_offsets(bool is32bit);
extern bool load_graphics_offsets(bool is32bit);
extern bool load_cached_graphics_offsets(bool is32bit, const char *config_path);
extern bool load_graphics_offsets(bool is32bit, const char *config_path);
/* temporary, will eventually be erased once we figure out how to create both
* 32bit and 64bit versions of the helpers/hook */
@ -27,20 +27,22 @@ extern bool load_graphics_offsets(bool is32bit);
#define USE_HOOK_ADDRESS_CACHE false
static DWORD WINAPI init_hooks(LPVOID unused)
static DWORD WINAPI init_hooks(LPVOID param)
{
char *config_path = param;
if (USE_HOOK_ADDRESS_CACHE &&
cached_versions_match() &&
load_cached_graphics_offsets(IS32BIT)) {
load_cached_graphics_offsets(IS32BIT, config_path)) {
load_cached_graphics_offsets(!IS32BIT);
load_cached_graphics_offsets(!IS32BIT, config_path);
obs_register_source(&game_capture_info);
} else if (load_graphics_offsets(IS32BIT)) {
load_graphics_offsets(!IS32BIT);
} else if (load_graphics_offsets(IS32BIT, config_path)) {
load_graphics_offsets(!IS32BIT, config_path);
}
UNUSED_PARAMETER(unused);
bfree(config_path);
return 0;
}
@ -85,7 +87,9 @@ bool obs_module_load(void)
obs_register_source(&window_capture_info);
init_hooks_thread = CreateThread(NULL, 0, init_hooks, NULL, 0, NULL);
char *config_path = obs_module_config_path(NULL);
init_hooks_thread = CreateThread(NULL, 0, init_hooks, config_path, 0, NULL);
obs_register_source(&game_capture_info);
return true;