This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
102 lines (78 loc) · 2.47 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
#include <Windows.h>
#include <vector>
// Types
typedef void(__thiscall* onplaytest_t)(void*, void*);
typedef void(__thiscall* cctouches_t)(void*, void*, void*);
// Globals
static bool g_hasPushStacked = 0;
static onplaytest_t g_onPlaytest = nullptr;
static cctouches_t g_onTouchBegan = nullptr;
static cctouches_t g_onTouchEnded = nullptr;
// Helpers
static bool writeMemory(
std::uintptr_t const address,
std::vector<std::uint8_t> const& bytes)
{
DWORD p = 0;
if (::VirtualProtect(
reinterpret_cast<LPVOID>(address),
bytes.size(),
PAGE_EXECUTE_READWRITE,
&p) == TRUE)
{
return ::WriteProcessMemory(
::GetCurrentProcess(),
reinterpret_cast<LPVOID>(address),
bytes.data(),
bytes.size(),
NULL) == TRUE;
}
return false;
}
static bool writePtr(
std::uintptr_t const address,
std::uintptr_t const ptr)
{
auto const p = reinterpret_cast<std::uint8_t const*>(&ptr);
return ::writeMemory(
address,
std::vector<std::uint8_t>(p, p + sizeof(std::uintptr_t)));
}
// Callback
static void __fastcall onplaytestHook(void* self, void* edx, void* param)
{
if (!g_hasPushStacked)
g_onPlaytest(self, param);
}
static void __fastcall ontouchbeganHook(void* self, void* edx, void* param1, void* param2)
{
g_hasPushStacked = true;
g_onTouchBegan(self, param1, param2);
}
static void __fastcall ontouchendedHook(void* self, void* edx, void* param1, void* param2)
{
g_hasPushStacked = false;
g_onTouchEnded(self, param1, param2);
}
// Main
DWORD WINAPI MainThread(LPVOID)
{
auto base = reinterpret_cast<std::uintptr_t>(GetModuleHandleA(NULL));
g_onPlaytest = reinterpret_cast<onplaytest_t>(base + 0x87600);
g_onTouchBegan = reinterpret_cast<cctouches_t>(base + 0x907B0);
g_onTouchEnded = reinterpret_cast<cctouches_t>(base + 0x911A0);
auto const onPlaytestAddr1 = base + 0x76E53;
auto const onPlaytestAddr2 = base + 0x92109;
writePtr(onPlaytestAddr1 + 1, reinterpret_cast<std::uintptr_t>(&onplaytestHook));
writePtr(onPlaytestAddr2 + 1, reinterpret_cast<std::uintptr_t>(&onplaytestHook) - onPlaytestAddr2 - 5);
writePtr(base + 0x2997D0, reinterpret_cast<std::uintptr_t>(&ontouchbeganHook));
writePtr(base + 0x2997D8, reinterpret_cast<std::uintptr_t>(&ontouchendedHook));
}
// Entrypoint
BOOL WINAPI DllMain(HINSTANCE dll, DWORD const reason, LPVOID)
{
DisableThreadLibraryCalls(dll);
if (reason == DLL_PROCESS_ATTACH)
CreateThread(0, 0, &MainThread, 0, 0, 0);
return TRUE;
}