-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspeedhack.cpp
61 lines (52 loc) · 1.53 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
#define NOMINMAX
#define WINMM
#include <Windows.h>
#include <map>
#include <filesystem>
#include "detours.h"
#include "zmod_common.cpp"
typedef BOOL(WINAPI QueryPerformanceCounter_t)(LARGE_INTEGER *lpPerformanceCount);
QueryPerformanceCounter_t *QueryPerformanceCounter_orig = QueryPerformanceCounter;
struct
{
double speedhack;
} globals;
BOOL WINAPI QueryPerformanceCounter_hook(LARGE_INTEGER *lpPerformanceCount)
{
auto ret = QueryPerformanceCounter_orig(lpPerformanceCount);
lpPerformanceCount->QuadPart *= globals.speedhack;
return ret;
}
void module_main(HINSTANCE hinstDLL)
{
zmod::ini ini = {
{{L"zmod_speedhack", L"global_speed_multiplier"}, L"1.0"},
};
auto ini_path = zmod::get_module_path(hinstDLL).replace_filename(L"zmod_speedhack.ini");
if (zmod::file_exists(ini_path))
{
zmod::read_ini_file(ini_path, ini);
}
else
{
zmod::write_ini_file(ini_path, ini);
}
globals.speedhack = std::wcstod(ini[{L"zmod_speedhack", L"global_speed_multiplier"}].c_str(), nullptr);
zmod::set_timer_resolution();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID &)QueryPerformanceCounter_orig, QueryPerformanceCounter_hook);
DetourTransactionCommit();
}
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (!(DisableThreadLibraryCalls(hinstDll)))
;
module_main(hinstDll);
break;
}
return TRUE;
}