This repository was archived by the owner on Dec 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllmain.cpp
More file actions
109 lines (93 loc) · 2.92 KB
/
Copy pathdllmain.cpp
File metadata and controls
109 lines (93 loc) · 2.92 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
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
#define _WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <d3d9.h>
#include <minhook/include/MinHook.h>
#include <kiero/kiero.h>
#include <backends/imgui_impl_win32.h>
#include <backends/imgui_impl_dx9.h>
#include <cstdio>
#include <iostream>
#include "ui.hpp"
#include "hooks.hpp"
typedef long(__stdcall* Reset)(LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
static Reset oReset = nullptr;
typedef long(__stdcall* EndScene)(LPDIRECT3DDEVICE9);
static EndScene oEndScene = nullptr;
HWND hwnd = nullptr;
using std::cout;
using std::endl;
static long __stdcall hkReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
{
ImGui_ImplDX9_InvalidateDeviceObjects();
long result = oReset(pDevice, pPresentationParameters);
ImGui_ImplDX9_CreateDeviceObjects();
return result;
}
WNDPROC oWndProc = NULL;
LRESULT CALLBACK hkWindowProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam,
_In_ LPARAM lParam) {
return ::CallWindowProcA(oWndProc, hwnd, uMsg, wParam, lParam);
}
static long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice)
{
static bool init = false;
if (!init)
{
D3DDEVICE_CREATION_PARAMETERS params;
pDevice->GetCreationParameters(¶ms);
hwnd = params.hFocusWindow;
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
ImGui_ImplWin32_Init(hwnd);
ImGui_ImplDX9_Init(pDevice);
// oWndProc = (WNDPROC)::SetWindowLongPtr((HWND)hwnd, GWLP_WNDPROC, (LONG)hkWindowProc);
init = true;
}
ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
ui_render();
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
return oEndScene(pDevice);
}
static void impl_d3d9_init()
{
hwnd = FindWindowA(nullptr, "I Wanna Be The Boshy");
std::cout << "hwnd: " << hwnd << '\n';
std::cout << "init: " << kiero::init(kiero::RenderType::Auto) << '\n';
std::cout << "hkReset: " << kiero::bind(16, (void**)&oReset, hkReset) << '\n';
std::cout << "hkEndScene: " << kiero::bind(42, (void**)&oEndScene, hkEndScene) << '\n';
}
static int MyThread()
{
#if defined(_DEBUG)
AllocConsole();
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
freopen_s((FILE**)stdin, "CONIN$", "r", stdin);
#endif
impl_d3d9_init();
init_hooks();
MH_EnableHook(MH_ALL_HOOKS);
return 0;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
DisableThreadLibraryCalls(hModule);
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)MyThread, nullptr, 0, nullptr);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}