2014-12-31 23:59:24 -08:00
|
|
|
#include <windows.h>
|
2014-03-05 10:43:14 -07:00
|
|
|
#include <obs-module.h>
|
2015-08-01 14:45:17 -07:00
|
|
|
#include <util/windows/win-version.h>
|
2015-10-03 23:30:00 -07:00
|
|
|
#include <util/platform.h>
|
2014-03-05 10:43:14 -07:00
|
|
|
|
|
|
|
OBS_DECLARE_MODULE()
|
2014-07-09 22:12:57 -07:00
|
|
|
OBS_MODULE_USE_DEFAULT_LOCALE("win-capture", "en-US")
|
2018-09-11 01:51:38 -07:00
|
|
|
MODULE_EXPORT const char *obs_module_description(void)
|
|
|
|
{
|
|
|
|
return "Windows game/screen/window capture";
|
|
|
|
}
|
2014-03-05 10:43:14 -07:00
|
|
|
|
2014-12-31 23:59:24 -08:00
|
|
|
extern struct obs_source_info duplicator_capture_info;
|
2014-03-05 10:43:14 -07:00
|
|
|
extern struct obs_source_info monitor_capture_info;
|
2014-04-07 01:20:36 -07:00
|
|
|
extern struct obs_source_info window_capture_info;
|
2014-11-10 17:35:02 -08:00
|
|
|
extern struct obs_source_info game_capture_info;
|
|
|
|
|
2016-11-14 16:32:02 -08:00
|
|
|
static HANDLE init_hooks_thread = NULL;
|
|
|
|
|
2015-10-03 23:30:00 -07:00
|
|
|
extern bool cached_versions_match(void);
|
2018-04-24 13:45:56 -07:00
|
|
|
extern bool load_cached_graphics_offsets(bool is32bit, const char *config_path);
|
2020-11-14 14:25:51 -08:00
|
|
|
extern bool load_graphics_offsets(bool is32bit, bool use_hook_address_cache,
|
|
|
|
const char *config_path);
|
2014-11-10 17:35:02 -08:00
|
|
|
|
|
|
|
/* temporary, will eventually be erased once we figure out how to create both
|
|
|
|
* 32bit and 64bit versions of the helpers/hook */
|
|
|
|
#ifdef _WIN64
|
|
|
|
#define IS32BIT false
|
|
|
|
#else
|
|
|
|
#define IS32BIT true
|
|
|
|
#endif
|
2014-03-05 10:43:14 -07:00
|
|
|
|
2020-11-14 14:25:51 -08:00
|
|
|
static const bool use_hook_address_cache = false;
|
2016-03-21 13:54:50 -07:00
|
|
|
|
2018-04-24 13:45:56 -07:00
|
|
|
static DWORD WINAPI init_hooks(LPVOID param)
|
2016-11-14 16:32:02 -08:00
|
|
|
{
|
2018-04-24 13:45:56 -07:00
|
|
|
char *config_path = param;
|
|
|
|
|
2020-11-14 14:25:51 -08:00
|
|
|
if (use_hook_address_cache && cached_versions_match() &&
|
2018-04-24 13:45:56 -07:00
|
|
|
load_cached_graphics_offsets(IS32BIT, config_path)) {
|
2016-11-14 16:32:02 -08:00
|
|
|
|
2018-04-24 13:45:56 -07:00
|
|
|
load_cached_graphics_offsets(!IS32BIT, config_path);
|
2016-11-14 16:32:02 -08:00
|
|
|
obs_register_source(&game_capture_info);
|
|
|
|
|
2020-11-14 14:25:51 -08:00
|
|
|
} else if (load_graphics_offsets(IS32BIT, use_hook_address_cache,
|
|
|
|
config_path)) {
|
|
|
|
load_graphics_offsets(!IS32BIT, use_hook_address_cache,
|
|
|
|
config_path);
|
2016-11-14 16:32:02 -08:00
|
|
|
}
|
|
|
|
|
2018-04-24 13:45:56 -07:00
|
|
|
bfree(config_path);
|
2016-11-14 16:32:02 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wait_for_hook_initialization(void)
|
|
|
|
{
|
|
|
|
static bool initialized = false;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
if (init_hooks_thread) {
|
|
|
|
WaitForSingleObject(init_hooks_thread, INFINITE);
|
|
|
|
CloseHandle(init_hooks_thread);
|
|
|
|
init_hooks_thread = NULL;
|
|
|
|
}
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 05:28:59 -08:00
|
|
|
void init_hook_files(void);
|
|
|
|
|
2021-06-07 08:00:29 -04:00
|
|
|
bool graphics_uses_d3d11 = false;
|
2021-06-07 08:38:33 -04:00
|
|
|
bool wgc_supported = false;
|
2021-06-07 08:00:29 -04:00
|
|
|
|
2014-07-27 12:42:43 -07:00
|
|
|
bool obs_module_load(void)
|
2014-03-05 10:43:14 -07:00
|
|
|
{
|
2015-08-01 14:45:17 -07:00
|
|
|
struct win_version_info ver;
|
2014-12-31 23:59:24 -08:00
|
|
|
bool win8_or_above = false;
|
2015-10-03 23:30:00 -07:00
|
|
|
char *config_dir;
|
|
|
|
|
2021-06-07 08:38:33 -04:00
|
|
|
struct win_version_info win1903 = {
|
|
|
|
.major = 10, .minor = 0, .build = 18362, .revis = 0};
|
|
|
|
|
2015-10-03 23:30:00 -07:00
|
|
|
config_dir = obs_module_config_path(NULL);
|
|
|
|
if (config_dir) {
|
|
|
|
os_mkdirs(config_dir);
|
|
|
|
bfree(config_dir);
|
|
|
|
}
|
2014-12-31 23:59:24 -08:00
|
|
|
|
2015-08-01 14:45:17 -07:00
|
|
|
get_win_ver(&ver);
|
2014-12-31 23:59:24 -08:00
|
|
|
|
2015-08-01 14:45:17 -07:00
|
|
|
win8_or_above = ver.major > 6 || (ver.major == 6 && ver.minor >= 2);
|
2014-12-31 23:59:24 -08:00
|
|
|
|
|
|
|
obs_enter_graphics();
|
2021-06-07 08:00:29 -04:00
|
|
|
graphics_uses_d3d11 = gs_get_device_type() == GS_DEVICE_DIRECT3D_11;
|
|
|
|
obs_leave_graphics();
|
2014-12-31 23:59:24 -08:00
|
|
|
|
2021-06-07 08:38:33 -04:00
|
|
|
if (graphics_uses_d3d11)
|
|
|
|
wgc_supported = win_version_compare(&ver, &win1903) >= 0;
|
|
|
|
|
2021-06-07 08:00:29 -04:00
|
|
|
if (win8_or_above && graphics_uses_d3d11)
|
2014-12-31 23:59:24 -08:00
|
|
|
obs_register_source(&duplicator_capture_info);
|
|
|
|
else
|
|
|
|
obs_register_source(&monitor_capture_info);
|
|
|
|
|
2014-04-07 01:20:36 -07:00
|
|
|
obs_register_source(&window_capture_info);
|
2014-11-10 17:35:02 -08:00
|
|
|
|
2018-04-24 13:45:56 -07:00
|
|
|
char *config_path = obs_module_config_path(NULL);
|
|
|
|
|
2020-02-27 05:28:59 -08:00
|
|
|
init_hook_files();
|
2018-04-24 13:45:56 -07:00
|
|
|
init_hooks_thread =
|
|
|
|
CreateThread(NULL, 0, init_hooks, config_path, 0, NULL);
|
2016-11-14 16:32:02 -08:00
|
|
|
obs_register_source(&game_capture_info);
|
2014-11-10 17:35:02 -08:00
|
|
|
|
2014-03-05 10:43:14 -07:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-14 16:32:02 -08:00
|
|
|
|
|
|
|
void obs_module_unload(void)
|
|
|
|
{
|
|
|
|
wait_for_hook_initialization();
|
|
|
|
}
|