-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllmain.cpp
More file actions
57 lines (43 loc) · 1.71 KB
/
dllmain.cpp
File metadata and controls
57 lines (43 loc) · 1.71 KB
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
#define NOMINMAX
#include <Windows.h>
#include <cstdlib>
#include <libhat/scanner.hpp>
#include <libhat/signature.hpp>
#include <MinHook.h>
// MinHook will redirect Dimension::getTimeOfDay to this function, replacing its behavior with our own code.
static float hk_getTimeOfDay(void* _this, int32_t time, float alpha) {
static float value = 0.f;
value += 0.00001f;
value = std::fmodf(value, 1.f);
return value;
}
static DWORD WINAPI startup(LPVOID dll) {
constexpr auto signature = hat::compile_signature<"44 8B C2 B8 F1 19 76 05 F7 EA">();
hat::scan_result scanResult = hat::find_pattern(signature, ".text");
std::byte* getTimeOfDay = scanResult.get();
// Initialize MinHook.
MH_Initialize();
// Hook getTimeOfDay.
LPVOID original;
MH_CreateHook(getTimeOfDay, &hk_getTimeOfDay, &original);
MH_EnableHook(getTimeOfDay);
// Exiting this thread without calling FreeLibraryAndExitThread on `dll` will cause the DLL to remain injected forever.
return 0;
}
// `DllMain` is the function that will be called by Windows when your mod is injected into the game's process.
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
// DLL_PROCESS_ATTACH means the DLL is being initialized.
// We create a new thread to call `startup`.
// This is necessary since we can't use most Windows APIs inside DllMain.
CreateThread(nullptr, 0, &startup, hinstDLL, 0, nullptr);
break;
case DLL_PROCESS_DETACH:
// DLL_PROCESS_DETACH means that the DLL is being ejected,
// or that the game is shutting down.
default:
break;
}
return TRUE;
}