-
Notifications
You must be signed in to change notification settings - Fork 7
/
dllmain.cpp
122 lines (99 loc) · 2.82 KB
/
dllmain.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include "dx9/dx9.h"
#include "Utils/ScreenCapture.h"
#include "Utils/Esp.h"
#include "minhook/include/MinHook.h"
#pragma comment(lib, "minhook/libMinHook-x86-v141-mtd.lib")
#include "Utils/Interface.h"
#include "Config.h"
void* pD3D9Device[119];
static dx9::tEndScene endScene;
static dx9::tEndScene oEndScene = nullptr;
static bool isHackUninstall = false;
float boxHeightModifier = 1.2;
int imgCnt = 0;
int timer = SCREENSHOT_DELAY + 1;
void MainLoop(LPDIRECT3DDEVICE9 lpD3D9Device)
{
if (GetAsyncKeyState(VK_INSERT) & 0x01) {
isHackUninstall = true;
}
if ((GetAsyncKeyState(VK_HOME) & 0x01) || (GetAsyncKeyState(MOUSE_WHEELED) & 0x01)) {
timer = 0;
LOG("Saved a screenshot!");
return;
}
if (GetAsyncKeyState(VK_NUMPAD8) & 0x01) {
boxHeightModifier += 0.1;
}
if (GetAsyncKeyState(VK_NUMPAD2) & 0x01) {
boxHeightModifier -= 0.1;
}
timer++;
if (timer == SCREENSHOT_DELAY) {
ScreenCapture::CaptureAnImage(dx9::GetProcessWindow());
}
if (timer >= SCREENSHOT_DELAY) {
Esp::run(lpD3D9Device);
}
}
HRESULT APIENTRY hkEndScene(LPDIRECT3DDEVICE9 lpD3D9Device)
{
MainLoop(lpD3D9Device);
return oEndScene(lpD3D9Device);
}
DWORD WINAPI HackThread(LPVOID params)
{
AllocConsole();
FILE* fp;
freopen_s(&fp, "CONOUT$", "w", stdout);
HMODULE hMod = (HMODULE)params;
if (!dx9::GetD3D9Device(pD3D9Device, sizeof(pD3D9Device))) {
LOG("Unable to get D3D9 Device");
goto bail;
}
LOG("Found EndScene Entry Point:");
LOG(oEndScene);
if (MH_Initialize() != MB_OK)
{
LOG("Unable to initialize minhook");
goto bail;
}
LOG("Hooking endscene");
endScene = (dx9::tEndScene)pD3D9Device[42];
LOG("Hooked endScene at " + std::to_string((int)endScene));
MH_CreateHook((LPVOID)endScene, (LPVOID)hkEndScene, (LPVOID*)&oEndScene);
MH_EnableHook((LPVOID)endScene);
//initialize interfaces(this part is borrowed from Osiris)
interfaces = std::make_unique<const Interfaces>();
while (!isHackUninstall) {
Sleep(500);
}
MH_DisableHook(MH_ALL_HOOKS);
MH_Uninitialize();
bail:
fclose(fp);
FreeLibraryAndExitThread(hMod, NULL);
return NULL;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
HANDLE hThread = CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)HackThread, hModule, NULL, nullptr);
CloseHandle(hThread);
break;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}