-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSpeedHack.cpp
86 lines (75 loc) · 2.39 KB
/
SpeedHack.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
//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
//
// Copyright(C) 2017 One Thawt <[email protected]>
// https://github.com/onethawt
//
// Everyone is permitted to copy and distribute verbatim or modified
// copies of this license document, and changing it is allowed as long
// as the name is changed.
//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.
//
#include <Windows.h>
#include <detours.h>
#include <cstdint>
DWORD (WINAPI *dGetTickCount)(void) = GetTickCount;
DWORD (WINAPI *dtimeGetTime)(void) = timeGetTime;
BOOL(WINAPI *dQueryPerformanceCounter)(LARGE_INTEGER *lpPerformanceCount) = QueryPerformanceCounter;
DWORD BaseTickCount;
DWORD BaseGetTime;
int64_t BasePerformanceCount;
DWORD Acceleration = 5;
DWORD WINAPI GetTickCountHook()
{
auto currentTickCount = dGetTickCount();
return BaseTickCount + ((currentTickCount - BaseTickCount) * Acceleration);
}
DWORD WINAPI timeGetTimeHook()
{
auto currentGetTime = dtimeGetTime();
return BaseGetTime + ((currentGetTime - BaseGetTime) * Acceleration);
}
BOOL WINAPI QueryPerformanceCounterHook(LARGE_INTEGER *lpPerformanceCount)
{
int64_t currentPerformanceCount;
if (!dQueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(¤tPerformanceCount))) return FALSE;
auto newTime = currentPerformanceCount + ((currentPerformanceCount - BasePerformanceCount) * Acceleration);
*lpPerformanceCount = *reinterpret_cast<LARGE_INTEGER*>(&newTime);
return TRUE;
}
DWORD WINAPI InitializeHooks(LPVOID lpParam)
{
BaseTickCount = GetTickCount();
BaseGetTime = timeGetTime();
QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&BasePerformanceCount));
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)dGetTickCount, GetTickCountHook);
DetourAttach(&(PVOID&)dtimeGetTime, timeGetTimeHook);
DetourAttach(&(PVOID&)dQueryPerformanceCounter, QueryPerformanceCounterHook);
DetourTransactionCommit();
return 0;
}
BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle,
IN DWORD nReason,
IN LPVOID Reserved)
{
HANDLE hThread = nullptr;
switch (nReason)
{
case DLL_PROCESS_ATTACH:
hThread = CreateThread(nullptr, 0, InitializeHooks, nullptr, 0, nullptr);
break;
case DLL_PROCESS_DETACH:
break;
default:
break;
}
if (hThread != nullptr) return TRUE;
return FALSE;
}