This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
118 lines (95 loc) · 2.41 KB
/
main.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
#define GMMODULE
#include "Interface.h"
#include "kiero.h"
#include "d3d9.h"
#include "Windows.h"
#include "minhook/include/MinHook.h"
#include "backends/imgui_impl_win32.h"
#include "backends/imgui_impl_dx9.h"
GMOD_MODULE_OPEN()
{
return 0;
}
GMOD_MODULE_CLOSE()
{
return 0;
}
static WNDPROC oWndProc = NULL;
static HWND gmWindow = NULL;
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
typedef long(__stdcall* Reset)(LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
static Reset oReset = NULL;
typedef long(__stdcall* EndScene)(LPDIRECT3DDEVICE9);
static EndScene oEndScene = NULL;
long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice)
{
static bool init = false;
if (!init)
{
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags = ImGuiConfigFlags_NoMouseCursorChange;
ImGui_ImplWin32_Init(gmWindow);
ImGui_ImplDX9_Init(pDevice);
init = true;
}
ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
ImGui::ShowDemoWindow();
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
return oEndScene(pDevice);
}
LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
if (true && ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
return true;
return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
}
BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam)
{
DWORD wndProcId;
GetWindowThreadProcessId(handle, &wndProcId);
if (GetCurrentProcessId() != wndProcId)
return TRUE;
gmWindow = handle;
return FALSE;
}
HWND GetProcessWindow()
{
gmWindow = NULL;
EnumWindows(EnumWindowsCallback, NULL);
return gmWindow;
}
DWORD WINAPI MainThread(LPVOID lpReserved)
{
bool attached = false;
do
{
if (kiero::init(kiero::RenderType::D3D9) == kiero::Status::Success)
{
kiero::bind(42, (void**)&oEndScene, hkEndScene);
do
gmWindow = GetProcessWindow();
while (gmWindow == NULL);
oWndProc = (WNDPROC)SetWindowLongPtr(gmWindow, GWL_WNDPROC, (LONG_PTR)WndProc);
attached = true;
}
} while (!attached);
return TRUE;
}
BOOL WINAPI DllMain(HMODULE hMod, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hMod);
CreateThread(nullptr, 0, MainThread, hMod, 0, nullptr);
break;
case DLL_PROCESS_DETACH:
kiero::shutdown();
break;
}
return TRUE;
}