-
Notifications
You must be signed in to change notification settings - Fork 24
/
dllmain.cpp
190 lines (158 loc) · 4.62 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "pch.h"
#include "Global.h"
#include "Utils.h"
#include "CleanCheat.h"
#define GAME_VIEW_PORT_INDEX 0x02 // Maybe you need to change that number
typedef void (__thiscall* ProcessEventType)(CG::UObject*, CG::UFunction*, void*);
typedef void (__thiscall* PostRenderType)(CG::UGameViewportClient*, CG::UCanvas*);
ProcessEventType OProcessEvent = nullptr;
PostRenderType OPostRender = nullptr;
bool Unload = false;
bool Once = false;
bool Working = false;
bool InitCleanCheat()
{
// Init CleanCheat
CleanCheatOptions options;
options.UseLogger = true;
CleanCheat::Init(options);
LevelActorsRunner* lvlRunner = CleanCheat::Runners->LevelActors;
// Features
bool featuresInit = true;
featuresInit &= lvlRunner->Features->Chams->Init();
if (!featuresInit)
{
LOG("Features initialize failed");
return false;
}
if (!lvlRunner->Init())
{
LOG("Runner registration failed");
return false;
}
return CleanCheat::Start();
}
void DllUnload()
{
Unload = true;
CleanCheat::Discard();
}
void __stdcall ProcessEventHook(CG::UObject* thiz, CG::UFunction* function, void* parms)
{
//LOG("%s", function->GetFullName().c_str());
OProcessEvent(thiz, function, parms);
}
void __stdcall PostRenderHook(CG::UGameViewportClient* gameViewportClient, CG::UCanvas* canvas)
{
// Hook ProcessEvent from game thread, otherwise some games will crash
try
{
if (!Once)
{
Once = true;
CleanCheat::Hook->Detour(reinterpret_cast<void**>(&OProcessEvent), reinterpret_cast<void*>(&ProcessEventHook));
LOG("Hook 'ProcessEvent' ... Success");
}
}
catch (...)
{
LOG("Error: %s", "Hook 'ProcessEvent' falied");
}
// Unload
if (GetAsyncKeyState(UNLOAD_KEY) & 1)
{
Unload = true;
DllUnload();
goto Exit;
}
if (Unload)
goto Exit;
// Shared data
if (!CleanCheat::SharedData)
goto Exit;
//canvas->K2_DrawLine({0.0, 0.0}, {50.0, 50.0}, 1.f, {1.f, 1.f, 1.f, 1.f});
CleanCheat::Tick(canvas);
Exit:
OPostRender(gameViewportClient, canvas);
}
void MainEntryPoint(HMODULE hModule)
{
// SDK
if (!CG::InitSdk())
{
MessageBox(nullptr, TEXT("SDK initialization failed"), TEXT("Error"), MB_OK);
return;
}
LOG("SDK Initialized successfully");
// CleanCheat
if (!InitCleanCheat())
{
LOG("CleanCheat initialization failed");
return;
}
LOG("ModuleBase: %p", static_cast<void*>(GetModuleHandleA(nullptr)));
// GWorld
CG::UWorld* gWorld = *CG::UWorld::GWorld;
if (!gWorld)
{
LOG("GWorld is nullptr");
return;
}
LOG("GWorld: %p", gWorld);
// LocalPlayer
CG::ULocalPlayer* localPlayer = Utils::GetLocalPlayer();
if (!localPlayer)
{
LOG("localPlayer is nullptr");
return;
}
LOG("LocalPlayer: %p", localPlayer);
// PostRender
LOG("ViewportClient : 0x%llx", reinterpret_cast<uintptr_t>(localPlayer->ViewportClient));
std::vector<CG::UGameViewportClient*> gameViewportClients = CG::UObject::FindObjects<CG::UGameViewportClient>();
LOG("GameViewportClientCount: %d", static_cast<int>(gameViewportClients.size()));
CG::UGameViewportClient*& gameViewportClient = gameViewportClients[GAME_VIEW_PORT_INDEX];
void** gameViewportClientVmt = *reinterpret_cast<void***>(gameViewportClient);
LOG("PostRender : 0x%llx", reinterpret_cast<uintptr_t>(gameViewportClientVmt[POST_RENDER_INDEX]));
CleanCheat::Hook->SwapVmt(
gameViewportClient,
POST_RENDER_INDEX,
reinterpret_cast<void*>(&PostRenderHook),
reinterpret_cast<void**>(&OPostRender));
// ProcessEvent
void** localPlayerVmt = *reinterpret_cast<void***>(localPlayer);
OProcessEvent = reinterpret_cast<ProcessEventType>(localPlayerVmt[PROCESS_EVENT_INDEX]);
LOG("ProcessEvents : 0x%llx", reinterpret_cast<uintptr_t>(OProcessEvent));
}
BOOL APIENTRY DllMain(const HMODULE hModule, const DWORD ulReasonForCall, LPVOID lpReserved)
{
if (ulReasonForCall != DLL_PROCESS_ATTACH)
return TRUE;
bool error = false;
try
{
MainEntryPoint(hModule);
}
catch (const std::exception& e)
{
LOG("Error: %s", e.what());
error = true;
}
catch (const std::string& ex)
{
LOG("Error: %s", ex.c_str());
error = true;
}
catch (...)
{
LOG("Error!!!!!!!");
error = true;
}
if (error)
{
constexpr int sleep = 5 * 1000;
Sleep(sleep);
DllUnload();
}
return TRUE;
}