-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
60 lines (49 loc) · 1.51 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
#include "main.h"
RakNetTime HOOK_RakNet_GetTime()
{
static bool& initialized = *reinterpret_cast<bool*>(0x81A19C4);
static timeval& initialTime = *reinterpret_cast<timeval*>(0x81A19BC);
if (!initialized)
{
gettimeofday(&initialTime, NULL);
initialized = true;
}
struct timeval tv;
gettimeofday(&tv, NULL);
return 1000 * (tv.tv_sec - initialTime.tv_sec) + (tv.tv_usec - initialTime.tv_usec) / 1000;
}
RakNetTimeNS HOOK_RakNet_GetTimeNS()
{
static bool& initialized = *reinterpret_cast<bool*>(0x81A19C4);
static timeval& initialTime = *reinterpret_cast<timeval*>(0x81A19BC);
if (!initialized)
{
gettimeofday(&initialTime, NULL);
initialized = true;
}
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_usec - initialTime.tv_usec + 1000000LL * (tv.tv_sec - initialTime.tv_sec);
}
bool Unlock(void* address, unsigned int len)
{
size_t iPageSize = getpagesize();
size_t iAddr = (reinterpret_cast<unsigned int>(address) / iPageSize) * iPageSize;
return !mprotect(reinterpret_cast<void*>(iAddr), len, PROT_READ | PROT_WRITE | PROT_EXEC);
}
void InstallJump(void* addr, void* func)
{
Unlock(addr, 5);
*reinterpret_cast<uint8_t*>(addr) = 0xE9;
*reinterpret_cast<uint32_t*>(addr + 1) = (reinterpret_cast<uint32_t>(func) - reinterpret_cast<uint32_t>(addr) - 5);
}
PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
{
return SUPPORTS_VERSION;
}
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
{
InstallJump(0x805FBE0, HOOK_RakNet_GetTime);
InstallJump(0x805FC60, HOOK_RakNet_GetTimeNS);
return true;
}