win-capture: Create all named objects within hook
All named objects (including file mapped shared memory) need to be created within the hook itself due to the fact that UWP programs cannot access named objects outside of the UWP process. Because shared memory needs to be created within the hook, the capture loop cannot start until the shared memory has been filled with valid data. Creating an additional "initialize" event fixes this issue. Additionally, changed the way that named kernel objects are opened/created. Before, there were functions that would first try to open named objects and then implicitly create them if opening failed (assuming that if the hook didn't create it first, game capture would), now it's been changed so that you can only either explicitly open or create.
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
#define EVENT_HOOK_READY "CaptureHook_HookReady"
|
||||
#define EVENT_HOOK_EXIT "CaptureHook_Exit"
|
||||
|
||||
#define EVENT_HOOK_INIT "CaptureHook_Initialize"
|
||||
|
||||
#define WINDOW_HOOK_KEEPALIVE L"CaptureHook_KeepAlive"
|
||||
|
||||
#define MUTEX_TEXTURE1 "CaptureHook_TextureMutex1"
|
||||
@@ -103,19 +105,19 @@ struct hook_info {
|
||||
|
||||
#define GC_MAPPING_FLAGS (FILE_MAP_READ | FILE_MAP_WRITE)
|
||||
|
||||
static inline HANDLE get_hook_info(DWORD id)
|
||||
static inline HANDLE create_hook_info(DWORD id)
|
||||
{
|
||||
HANDLE handle;
|
||||
char new_name[64];
|
||||
sprintf(new_name, "%s%lu", SHMEM_HOOK_INFO, id);
|
||||
|
||||
handle = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL,
|
||||
PAGE_READWRITE, 0, sizeof(struct hook_info), new_name);
|
||||
|
||||
if (!handle && GetLastError() == ERROR_ALREADY_EXISTS) {
|
||||
handle = OpenFileMappingA(GC_MAPPING_FLAGS, false,
|
||||
new_name);
|
||||
}
|
||||
|
||||
return handle;
|
||||
return CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
|
||||
0, sizeof(struct hook_info), new_name);
|
||||
}
|
||||
|
||||
static inline HANDLE open_hook_info(DWORD id)
|
||||
{
|
||||
char new_name[64];
|
||||
sprintf(new_name, "%s%lu", SHMEM_HOOK_INFO, id);
|
||||
|
||||
return OpenFileMappingA(GC_MAPPING_FLAGS, false, new_name);
|
||||
}
|
||||
|
Reference in New Issue
Block a user