1 #pragma once
2
3 #include <assert.h>
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include <string.h>
7 #include <stdio.h>
8
9 #include "hook-helpers.h"
10
11 #define EVENT_CAPTURE_RESTART L"CaptureHook_Restart"
12 #define EVENT_CAPTURE_STOP L"CaptureHook_Stop"
13
14 #define EVENT_HOOK_READY L"CaptureHook_HookReady"
15 #define EVENT_HOOK_EXIT L"CaptureHook_Exit"
16
17 #define EVENT_HOOK_INIT L"CaptureHook_Initialize"
18
19 #define WINDOW_HOOK_KEEPALIVE L"CaptureHook_KeepAlive"
20
21 #define MUTEX_TEXTURE1 L"CaptureHook_TextureMutex1"
22 #define MUTEX_TEXTURE2 L"CaptureHook_TextureMutex2"
23
24 #define SHMEM_HOOK_INFO L"CaptureHook_HookInfo"
25 #define SHMEM_TEXTURE L"CaptureHook_Texture"
26
27 #define PIPE_NAME "CaptureHook_Pipe"
28
29 #pragma pack(push, 8)
30
31 struct d3d8_offsets {
32 uint32_t present;
33 };
34
35 struct d3d9_offsets {
36 uint32_t present;
37 uint32_t present_ex;
38 uint32_t present_swap;
39 uint32_t d3d9_clsoff;
40 uint32_t is_d3d9ex_clsoff;
41 };
42
43 struct d3d12_offsets {
44 uint32_t execute_command_lists;
45 };
46
47 struct dxgi_offsets {
48 uint32_t present;
49 uint32_t resize;
50
51 uint32_t present1;
52 };
53
54 struct dxgi_offsets2 {
55 uint32_t release;
56 };
57
58 struct ddraw_offsets {
59 uint32_t surface_create;
60 uint32_t surface_restore;
61 uint32_t surface_release;
62 uint32_t surface_unlock;
63 uint32_t surface_blt;
64 uint32_t surface_flip;
65 uint32_t surface_set_palette;
66 uint32_t palette_set_entries;
67 };
68
69 struct shmem_data {
70 volatile int last_tex;
71 uint32_t tex1_offset;
72 uint32_t tex2_offset;
73 };
74
75 struct shtex_data {
76 uint32_t tex_handle;
77 };
78
79 enum capture_type {
80 CAPTURE_TYPE_MEMORY,
81 CAPTURE_TYPE_TEXTURE,
82 };
83
84 struct graphics_offsets {
85 struct d3d8_offsets d3d8;
86 struct d3d9_offsets d3d9;
87 struct dxgi_offsets dxgi;
88 struct ddraw_offsets ddraw;
89 struct dxgi_offsets2 dxgi2;
90 struct d3d12_offsets d3d12;
91 };
92
93 struct hook_info {
94 /* hook version */
95 uint32_t hook_ver_major;
96 uint32_t hook_ver_minor;
97
98 /* capture info */
99 enum capture_type type;
100 uint32_t window;
101 uint32_t format;
102 uint32_t cx;
103 uint32_t cy;
104 uint32_t UNUSED_base_cx;
105 uint32_t UNUSED_base_cy;
106 uint32_t pitch;
107 uint32_t map_id;
108 uint32_t map_size;
109 bool flip;
110
111 /* additional options */
112 uint64_t frame_interval;
113 bool UNUSED_use_scale;
114 bool force_shmem;
115 bool capture_overlay;
116 bool allow_srgb_alias;
117
118 /* hook addresses */
119 struct graphics_offsets offsets;
120
121 uint32_t reserved[126];
122 };
123 static_assert(sizeof(struct hook_info) == 648, "ABI compatibility");
124
125 #pragma pack(pop)
126
127 #define GC_MAPPING_FLAGS (FILE_MAP_READ | FILE_MAP_WRITE)
128
create_hook_info(DWORD id)129 static inline HANDLE create_hook_info(DWORD id)
130 {
131 HANDLE handle = NULL;
132
133 wchar_t new_name[64];
134 const int len = swprintf(new_name, _countof(new_name),
135 SHMEM_HOOK_INFO L"%lu", id);
136 if (len > 0) {
137 handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
138 PAGE_READWRITE, 0,
139 sizeof(struct hook_info), new_name);
140 }
141
142 return handle;
143 }
144