-
Notifications
You must be signed in to change notification settings - Fork 0
/
dinput8.h
59 lines (49 loc) · 1.89 KB
/
dinput8.h
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
#pragma once
#include "iniConfig.h"
#define LOG(...) do { if (logFile) { fprintf(logFile, __VA_ARGS__); fflush(logFile); } } while (false)
extern FILE *logFile;
extern iniConfig config;
extern BYTE **pBase;
extern BYTE **pWorld;
template<class T = void> T* GetBasePtr(int offset) { return (T*)(*pBase + offset); }
template<class T = void> T* GetWorldPtr(std::initializer_list<int> offsets)
{
BYTE **result = pWorld;
for (auto offset : offsets)
if (*result)
result = (BYTE**)(*result + offset);
return (T*)*result;
}
namespace Hooks
{
void CreateHook(LPCSTR msg, LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal, bool enable = true);
void SwitchHook(LPCSTR msg, LPVOID pTarget, bool enable);
bool Find(LPCSTR msg, BYTE *start, BYTE *end, BYTE *signature, size_t len, BYTE **offset);
bool FindSignature(LPCSTR msg, BYTE *signature, size_t len, BYTE **offset);
bool FindData(LPCSTR msg, BYTE *signature, size_t len, BYTE **offset);
template <class T>
void CreateHook(LPCSTR msg, LPVOID pTarget, LPVOID pDetour, T** ppOriginal, bool enable = true)
{
CreateHook(msg, pTarget, pDetour, reinterpret_cast<LPVOID*>(ppOriginal), enable);
}
template<size_t len> bool Find(LPCSTR msg, BYTE* start, BYTE* end, BYTE(&signature)[len], BYTE **offset)
{
return Find(msg, start, end, signature, len, offset);
}
template<size_t len> bool FindSignature(LPCSTR msg, BYTE(&signature)[len], BYTE **offset)
{
return FindSignature(msg, signature, len, offset);
}
template<size_t len> bool FindData(LPCSTR msg, BYTE(&signature)[len], BYTE **offset)
{
return FindData(msg, signature, len, offset);
}
template<class T> void Set(T *address, std::initializer_list<T> args)
{
DWORD oldProtect;
VirtualProtect(address, args.size() * sizeof(T), PAGE_EXECUTE_READWRITE, &oldProtect);
for (auto &arg : args)
*(address++) = arg;
VirtualProtect(address, args.size() * sizeof(T), oldProtect, &oldProtect);
}
}