5
5
#define EXPORT extern " C" __declspec(dllexport)
6
6
7
7
namespace {
8
+ hook::library::Detour GetSystemMetricsDetour;
9
+ hook::library::Detour ExitProcessDetour;
10
+ hook::library::Detour GetThreadContextDetour;
11
+
12
+ DECLSPEC_NORETURN void ExitProcessStub (UINT uExitCode) {
13
+ if (uExitCode) {
14
+ LOG_ERROR (" ExitProcess with {}" , uExitCode);
15
+ hook::error::DumpStackTraceFrom (alogs::LVL_ERROR);
16
+ }
17
+ else {
18
+ LOG_INFO (" ExitProcess with {}" , uExitCode);
19
+ hook::error::DumpStackTraceFrom (alogs::LVL_INFO);
20
+ }
21
+ ExitProcessDetour.Call (uExitCode);
22
+ }
23
+
24
+ BOOL WINAPI GetThreadContextStub (HANDLE hThread, LPCONTEXT lpContext) {
25
+ LOG_INFO (" GetThreadContext({}, {})" , hThread, (void *)lpContext);
26
+ return GetThreadContextDetour.Call <BOOL>(hThread, lpContext);
27
+ }
28
+ int GetSystemMetricsStub (int nIndex) {
29
+ LOG_INFO (" GetSystemMetrics({}) / {}" , nIndex, GetCurrentThread ());
30
+ return GetSystemMetricsDetour.Call <int >(nIndex);
31
+ }
8
32
void Main () {
9
33
alogs::setfile (" acts-mwiii.log" );
10
34
alogs::setlevel (alogs::LVL_TRACE);
11
- LOG_INFO (" Init fast inject dll" );
35
+ LOG_INFO (" Init MWIII dll" );
12
36
13
- hook::error::InstallErrorHooks (false );
37
+ hook::error::InstallErrorHooks (true );
14
38
hook::error::EnableHeavyDump ();
15
39
40
+ hook::library::Library kernel32 = " kernel32.dll" ;
41
+ hook::library::Library user32 = " user32.dll" ;
42
+
43
+ GetSystemMetricsDetour.Create (user32[" GetSystemMetrics" ], GetSystemMetricsStub);
44
+ ExitProcessDetour.Create (kernel32[" ExitProcess" ], ExitProcessStub);
45
+ GetThreadContextDetour.Create (kernel32[" GetThreadContext" ], GetThreadContextStub);
46
+
16
47
17
48
// hook::library::InitScanContainer("acts-mwiii.scan");
18
49
@@ -28,29 +59,24 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD Reason, LPVOID lpVoid) {
28
59
return TRUE ;
29
60
}
30
61
31
-
32
- // hook dxgi.dll for auto injection
33
- EXPORT HRESULT CreateDXGIFactory1 (void * riid, void * ppFactory) {
34
- static auto func = [] {
35
- hook::library::Library dxgi{ " dxgi.dll" , true };
36
-
37
- if (!dxgi) throw std::runtime_error (utils::va (" can't find system dxgi.dll" ));
38
-
39
- return reinterpret_cast <decltype (&CreateDXGIFactory1)>(dxgi[" CreateDXGIFactory1" ]);
40
- }();
41
-
42
- return func (riid, ppFactory);
62
+ namespace {
63
+ int64_t DiscordCreateFake () {
64
+ LOG_WARNING (" Tried to get discord_game_sdk_old.dll#DiscordCreate(), but failed, did the user renamed discord_game_sdk to discord_game_sdk_old?" );
65
+ return 0 ;
66
+ }
43
67
}
44
68
45
-
46
- EXPORT HRESULT CreateDXGIFactory (void * riid, void * ppFactory) {
69
+ // 000000001368F14C DiscordCreate discord_game_sdk
70
+ // hook discord_game_sdk.dll for auto injection
71
+ EXPORT int64_t DiscordCreate () {
47
72
static auto func = [] {
48
- hook::library::Library dxgi { " dxgi .dll" , true };
73
+ hook::library::Library discord_game_sdk { " discord_game_sdk_old .dll" , true };
49
74
50
- if (!dxgi) throw std::runtime_error ( utils::va ( " can't find system dxgi.dll " )) ;
75
+ if (!discord_game_sdk) return DiscordCreateFake ;
51
76
52
- return reinterpret_cast <decltype (&CreateDXGIFactory )>(dxgi[ " CreateDXGIFactory " ]);
77
+ return reinterpret_cast <decltype (&DiscordCreate )>(discord_game_sdk[ " DiscordCreate " ]);
53
78
}();
54
79
55
- return func (riid, ppFactory );
80
+ return func ();
56
81
}
82
+
0 commit comments