Repository navigation
Expand file tree
/
Copy pathdllmain.cpp
More file actions
75 lines (62 loc) · 1.86 KB
/
Copy pathdllmain.cpp
File metadata and controls
75 lines (62 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <windows.h>
#include <process.h>
#include "mono_api.h"
#include "ultrawide_fix.h"
#include "config.h"
#include "log.h"
// System exports to spoof the real DXGI.dll
#pragma comment(linker, "/export:CreateDXGIFactory=C:\\Windows\\System32\\dxgi.CreateDXGIFactory")
#pragma comment(linker, "/export:CreateDXGIFactory1=C:\\Windows\\System32\\dxgi.CreateDXGIFactory1")
#pragma comment(linker, "/export:CreateDXGIFactory2=C:\\Windows\\System32\\dxgi.CreateDXGIFactory2")
#pragma comment(linker, "/export:DXGIDeclareAdapterRemovalSupport=C:\\Windows\\System32\\dxgi.DXGIDeclareAdapterRemovalSupport")
namespace
{
constexpr DWORD kInitialDelayMs = 5000;
constexpr DWORD kMonoWaitMs = 1000;
constexpr DWORD kApplyIntervalMs = 16;
HMODULE g_selfModule = nullptr;
MonoApi WaitForMono()
{
while (true)
{
MonoApi api = ResolveMonoApi();
if (api.IsValid())
{
Log("Mono runtime resolved");
return api;
}
Sleep(kMonoWaitMs);
}
}
}
void UltrawideLoop(void*)
{
LogInit();
Sleep(kInitialDelayMs);
Log("Loop started");
MonoApi api = WaitForMono();
MonoDomain* domain = api.get_root_domain();
if (!domain)
{
Log("No root domain — aborting");
return;
}
api.thread_attach(domain);
Log("Thread attached to Mono domain");
const TargetResolution target = ResolveTargetResolution(g_selfModule);
while (true)
{
ApplyResolution(api, target);
Sleep(kApplyIntervalMs);
}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
g_selfModule = hModule;
DisableThreadLibraryCalls(hModule);
_beginthread(UltrawideLoop, 0, nullptr);
}
return TRUE;
}