@@ -18,15 +18,46 @@ namespace {
18
18
std::shared_ptr<Hook> ExecuteCommandListsHook;
19
19
}
20
20
21
- void CheckTearingSupport () {
21
+ // doing file read operations in DXHooks is a little silly but im too tired to find a better way
22
+ bool DXHooks::IsGfxVSyncEnabled () {
23
+ wchar_t userProfile[MAX_PATH];
24
+ DWORD pathLen = GetEnvironmentVariableW (L" USERPROFILE" , userProfile, MAX_PATH);
25
+ if (pathLen == 0 || pathLen >= MAX_PATH) {
26
+ return true ;
27
+ }
28
+
29
+ std::wstring optionsPath (userProfile);
30
+ optionsPath +=
31
+ L" \\ AppData\\ Local\\ Packages\\ Microsoft.MinecraftUWP_8wekyb3d8bbwe\\ LocalState\\ games\\ com.mojang\\ minecraftpe\\ options.txt" ;
32
+
33
+ std::ifstream file (optionsPath.c_str ());
34
+ if (!file.is_open ()) {
35
+ return true ;
36
+ }
37
+
38
+ std::string line;
39
+ while (std::getline (file, line)) {
40
+ std::erase (line, ' \r ' );
41
+ if (line.find (" gfx_vsync:" ) == 0 ) {
42
+ return line != " gfx_vsync:0" ;
43
+ }
44
+ }
45
+
46
+ // default to enabled
47
+ return true ;
48
+ }
49
+
50
+ void DXHooks::CheckTearingSupport () {
22
51
ComPtr<IDXGIFactory5> factory5;
23
52
if (SUCCEEDED (CreateDXGIFactory1 (IID_PPV_ARGS (&factory5)))) {
24
53
BOOL allowTearing = FALSE ;
25
54
if (SUCCEEDED (factory5->CheckFeatureSupport (
26
55
DXGI_FEATURE_PRESENT_ALLOW_TEARING,
27
56
&allowTearing,
28
57
sizeof (allowTearing)))) {
29
- tearingSupported = allowTearing;
58
+ if (allowTearing && !DXHooks::IsGfxVSyncEnabled ()) {
59
+ tearingSupported = true ;
60
+ }
30
61
}
31
62
}
32
63
}
@@ -100,11 +131,11 @@ HRESULT __stdcall DXHooks::SwapChain_ResizeBuffers(
100
131
}
101
132
102
133
HRESULT __stdcall DXHooks::CommandQueue_ExecuteCommandLists (ID3D12CommandQueue* queue, UINT NumCommandLists,
103
- ID3D12CommandList* const * ppCommandLists) {
104
- auto lock = Latite::getRenderer ().lock ();
105
- Latite::getRenderer ().setCommandQueue (queue);
106
- return ExecuteCommandListsHook->oFunc <decltype (&CommandQueue_ExecuteCommandLists)>()(
107
- queue, NumCommandLists, ppCommandLists);
134
+ ID3D12CommandList* const * ppCommandLists) {
135
+ auto lock = Latite::getRenderer ().lock ();
136
+ Latite::getRenderer ().setCommandQueue (queue);
137
+ return ExecuteCommandListsHook->oFunc <decltype (&CommandQueue_ExecuteCommandLists)>()(
138
+ queue, NumCommandLists, ppCommandLists);
108
139
}
109
140
110
141
DXHooks::DXHooks () : HookGroup(" DirectX" ) {
@@ -116,7 +147,7 @@ DXHooks::DXHooks() : HookGroup("DirectX") {
116
147
ComPtr<ID3D11DeviceContext> dctx;
117
148
ComPtr<ID3D12CommandQueue> cqueue;
118
149
119
- CheckTearingSupport ();
150
+ DXHooks:: CheckTearingSupport ();
120
151
121
152
ThrowIfFailed (CreateDXGIFactory (IID_PPV_ARGS (&factory)));
122
153
ThrowIfFailed (factory->EnumAdapters (0 , adapter.GetAddressOf ()));
@@ -147,13 +178,13 @@ DXHooks::DXHooks() : HookGroup("DirectX") {
147
178
swapChainDesc.OutputWindow = hWnd;
148
179
swapChainDesc.SampleDesc .Count = 1 ;
149
180
swapChainDesc.Windowed = TRUE ;
150
-
181
+
151
182
D3D_FEATURE_LEVEL lvl[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1 };
152
183
153
184
D3D_FEATURE_LEVEL featureLevel;
154
- auto hr = D3D11CreateDeviceAndSwapChain (nullptr , D3D_DRIVER_TYPE_HARDWARE, nullptr , 0 , lvl, 2 , D3D11_SDK_VERSION,
155
- &swapChainDesc, swapChain.GetAddressOf (), device.GetAddressOf (),
156
- &featureLevel, dctx.GetAddressOf ());
185
+ auto hr = D3D11CreateDeviceAndSwapChain (nullptr , D3D_DRIVER_TYPE_HARDWARE, nullptr , 0 , lvl, 2 , D3D11_SDK_VERSION,
186
+ &swapChainDesc, swapChain.GetAddressOf (), device.GetAddressOf (),
187
+ &featureLevel, dctx.GetAddressOf ());
157
188
158
189
uintptr_t * vftable = *reinterpret_cast <uintptr_t **>(swapChain.Get ());
159
190
uintptr_t * cqueueVftable = nullptr ;
@@ -168,7 +199,7 @@ DXHooks::DXHooks() : HookGroup("DirectX") {
168
199
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
169
200
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
170
201
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
171
-
202
+
172
203
ThrowIfFailed (device12->CreateCommandQueue (&queueDesc, IID_PPV_ARGS (&cqueue)));
173
204
cqueueVftable = *reinterpret_cast <uintptr_t **>(cqueue.Get ());
174
205
}
@@ -177,13 +208,13 @@ DXHooks::DXHooks() : HookGroup("DirectX") {
177
208
DestroyWindow (hWnd);
178
209
UnregisterClass (L" dummywnd" , Latite::get ().dllInst );
179
210
180
- ComPtr<IDXGIFactory2> factory2;
181
- if (SUCCEEDED (factory.As (&factory2))) {
182
- void ** vtable = *(void ***)factory2.Get ();
183
- MH_CreateHook (vtable[16 ], DXHooks::CreateSwapChainForCoreWindowHook,
184
- (void **)&origCreateSwapChain);
185
- MH_EnableHook (vtable[16 ]);
186
- }
211
+ ComPtr<IDXGIFactory2> factory2;
212
+ if (SUCCEEDED (factory.As (&factory2))) {
213
+ void ** vtable = *(void ***)factory2.Get ();
214
+ MH_CreateHook (vtable[16 ], DXHooks::CreateSwapChainForCoreWindowHook,
215
+ (void **)&origCreateSwapChain);
216
+ MH_EnableHook (vtable[16 ]);
217
+ }
187
218
188
219
PresentHook = addHook (vftable[8 ], SwapChain_Present, " IDXGISwapChain::Present" );
189
220
ResizeBuffersHook = addHook (vftable[13 ], SwapChain_ResizeBuffers, " IDXGISwapChain::ResizeBuffers" );
0 commit comments