Selaa lähdekoodia

win-capture: Try window handle 0 if actual handle fails

Certain UWP programs can't obtain a normal window handle from their API
for whatever reason (this was observed with minecraft win10 edition), so
if the normal window handle on the map fails, try window handle 0
instead.
jp9000 5 vuotta sitten
vanhempi
sitoutus
f1cb1a42cc
1 muutettua tiedostoa jossa 19 lisäystä ja 6 poistoa
  1. 19 6
      plugins/win-capture/game-capture.c

+ 19 - 6
plugins/win-capture/game-capture.c

@@ -1239,6 +1239,17 @@ static inline bool init_events(struct game_capture *gc)
 
 enum capture_result { CAPTURE_FAIL, CAPTURE_RETRY, CAPTURE_SUCCESS };
 
+static inline bool init_data_map(struct game_capture *gc, HWND window)
+{
+	wchar_t name[64];
+	swprintf(name, 64, SHMEM_TEXTURE "_%" PRIu64 "_",
+		 (uint64_t)(uintptr_t)window);
+
+	gc->hook_data_map =
+		open_map_plus_id(gc, name, gc->global_hook_info->map_id);
+	return !!gc->hook_data_map;
+}
+
 static inline enum capture_result init_capture_data(struct game_capture *gc)
 {
 	gc->cx = gc->global_hook_info->cx;
@@ -1252,15 +1263,17 @@ static inline enum capture_result init_capture_data(struct game_capture *gc)
 
 	CloseHandle(gc->hook_data_map);
 
-	wchar_t name[64];
-	swprintf(name, 64, SHMEM_TEXTURE "_%" PRIu64 "_",
-		 (uint64_t)(uintptr_t)gc->window);
+	DWORD error = 0;
+	if (!init_data_map(gc, gc->window)) {
+		error = GetLastError();
 
-	gc->hook_data_map =
-		open_map_plus_id(gc, name, gc->global_hook_info->map_id);
+		/* if there's an error, try with 0 (for UWP programs) */
+		if (init_data_map(gc, NULL)) {
+			error = 0;
+		}
+	}
 
 	if (!gc->hook_data_map) {
-		DWORD error = GetLastError();
 		if (error == 2) {
 			return CAPTURE_RETRY;
 		} else {