forked from sstokic-tgm/Gladiatorcheatz-v2.1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIfaceMngr.hpp
56 lines (44 loc) · 1.2 KB
/
IfaceMngr.hpp
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
#pragma once
namespace Iface
{
class IfaceMngr
{
public:
class InterfaceReg
{
private:
using InstantiateInterfaceFn = void*(*)();
public:
InstantiateInterfaceFn m_CreateFn;
const char *m_pName;
InterfaceReg *m_pNext;
};
template<typename T>
static T *getIface(const char *modName, const char *ifaceName, bool exact = false)
{
T *iface = nullptr;
InterfaceReg *ifaceRegList;
int partMatchLen = strlen(ifaceName);
DWORD ifaceFn = reinterpret_cast<DWORD>(GetProcAddress(GetModuleHandleA(modName), "CreateInterface"));
if (!ifaceFn)
return nullptr;
unsigned int jmpStart = (unsigned int)(ifaceFn)+4;
unsigned int jmpTarget = jmpStart + *(unsigned int*)(jmpStart + 1) + 5;
ifaceRegList = **reinterpret_cast<InterfaceReg***>(jmpTarget + 6);
for (InterfaceReg *cur = ifaceRegList; cur; cur = cur->m_pNext)
{
if (exact == true)
{
if (strcmp(cur->m_pName, ifaceName) == 0)
iface = reinterpret_cast<T*>(cur->m_CreateFn());
}
else
{
if (!strncmp(cur->m_pName, ifaceName, partMatchLen) && std::atoi(cur->m_pName + partMatchLen) > 0)
iface = reinterpret_cast<T*>(cur->m_CreateFn());
}
}
return iface;
}
};
}