-
Notifications
You must be signed in to change notification settings - Fork 1
/
inputlag.cpp
54 lines (43 loc) · 1.54 KB
/
inputlag.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
#include "windows.h"
#include "cocos2d.h"
#include "MinHook.h"
#include "hackpro_ext.h"
// original function pointers
void (__thiscall *fpMainLoop)(cocos2d::CCDirector *self);
void (__thiscall *fpPollEvents)(cocos2d::CCEGLView *self);
// hook functions
void __thiscall hkMainLoop(cocos2d::CCDirector *self) {
fpPollEvents(self->getOpenGLView());
fpMainLoop(self);
}
void __thiscall hkPollEvents(void *self) {};
// mega hack callbacks
void __stdcall enableHooks(void *) {
MH_EnableHook(MH_ALL_HOOKS);
}
void __stdcall disableHooks(void *) {
MH_DisableHook(MH_ALL_HOOKS);
}
DWORD WINAPI thread(LPVOID lpParameter) {
MH_Initialize();
const HINSTANCE cocos = GetModuleHandleA("libcocos2d.dll");
MH_CreateHook(reinterpret_cast<LPVOID>(reinterpret_cast<uintptr_t>(cocos) + 0xffb10), hkMainLoop, reinterpret_cast<LPVOID *>(&fpMainLoop));
MH_CreateHook(GetProcAddress(cocos, "?pollEvents@CCEGLView@cocos2d@@QAEXXZ"), hkPollEvents, reinterpret_cast<LPVOID *>(&fpPollEvents));
if (InitialiseHackpro()) {
if (HackproIsReady()) {
void *extension = HackproInitialiseExt("Input Lag");
void *checkbox = HackproAddCheckbox(extension, "-1 frame", enableHooks, disableHooks);
HackproSetCheckbox(checkbox, true);
HackproCommitExt(extension);
}
} else {
MH_EnableHook(MH_ALL_HOOKS);
}
return 0;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
CreateThread(0, 0, thread, 0, 0, 0);
return TRUE;
}