Просмотр исходного кода

win-capture: Check hook version before capture init

Checks the hook version to ensure compatibility with hook DLL.  It's
unlikely it'll ever be necessary to increment the hook version, but this
is just a precautionary thing that allows a hook DLL to make sure it's
rejected by an older OBS version if needed.  Again however, very
unlikely that the major version will ever be incremented.
jp9000 5 лет назад
Родитель
Сommit
7e78c17ace

+ 12 - 0
plugins/win-capture/game-capture.c

@@ -10,6 +10,7 @@
 #include "obfuscate.h"
 #include "inject-library.h"
 #include "graphics-hook-info.h"
+#include "graphics-hook-ver.h"
 #include "window-helpers.h"
 #include "cursor-capture.h"
 #include "app-helpers.h"
@@ -1610,6 +1611,17 @@ static bool start_capture(struct game_capture *gc)
 {
 	debug("Starting capture");
 
+	/* prevent from using a DLL version that's higher than current */
+	if (gc->global_hook_info->hook_ver_major > HOOK_VER_MAJOR) {
+		warn("cannot initialize hook, DLL hook version is "
+		     "%" PRIu32 ".%" PRIu32
+		     ", current plugin hook major version is %d.%d",
+		     gc->global_hook_info->hook_ver_major,
+		     gc->global_hook_info->hook_ver_minor, HOOK_VER_MAJOR,
+		     HOOK_VER_MINOR);
+		return false;
+	}
+
 	if (gc->global_hook_info->type == CAPTURE_TYPE_MEMORY) {
 		if (!init_shmem_capture(gc)) {
 			return false;

+ 6 - 0
plugins/win-capture/graphics-hook-info.h

@@ -80,6 +80,10 @@ struct graphics_offsets {
 };
 
 struct hook_info {
+	/* hook version */
+	uint32_t hook_ver_major;
+	uint32_t hook_ver_minor;
+
 	/* capture info */
 	enum capture_type type;
 	uint32_t window;
@@ -101,6 +105,8 @@ struct hook_info {
 
 	/* hook addresses */
 	struct graphics_offsets offsets;
+
+	uint32_t reserved[128];
 };
 
 #pragma pack(pop)

+ 5 - 0
plugins/win-capture/graphics-hook/graphics-hook.c

@@ -1,6 +1,7 @@
 #include <windows.h>
 #include <psapi.h>
 #include "graphics-hook.h"
+#include "../graphics-hook-ver.h"
 #include "../obfuscate.h"
 #include "../funchook.h"
 
@@ -539,6 +540,8 @@ bool capture_init_shtex(struct shtex_data **data, HWND window, uint32_t base_cx,
 	*data = shmem_info;
 	(*data)->tex_handle = (uint32_t)handle;
 
+	global_hook_info->hook_ver_major = HOOK_VER_MAJOR;
+	global_hook_info->hook_ver_minor = HOOK_VER_MINOR;
 	global_hook_info->window = (uint32_t)(uintptr_t)window;
 	global_hook_info->type = CAPTURE_TYPE_TEXTURE;
 	global_hook_info->format = format;
@@ -732,6 +735,8 @@ bool capture_init_shmem(struct shmem_data **data, HWND window, uint32_t base_cx,
 	(*data)->tex1_offset = (uint32_t)align_pos;
 	(*data)->tex2_offset = (*data)->tex1_offset + aligned_tex;
 
+	global_hook_info->hook_ver_major = HOOK_VER_MAJOR;
+	global_hook_info->hook_ver_minor = HOOK_VER_MINOR;
 	global_hook_info->window = (uint32_t)(uintptr_t)window;
 	global_hook_info->type = CAPTURE_TYPE_MEMORY;
 	global_hook_info->format = format;