-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStructResolver.h
More file actions
70 lines (54 loc) · 2.94 KB
/
StructResolver.h
File metadata and controls
70 lines (54 loc) · 2.94 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
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef STRUCT_RESOLVER
#define STRUCT_RESOLVER
#include "TypeUtility.h"
struct StructResolver {
private:
template <typename T, int gameAddress> struct Instance;
template <typename T, bool implemented, int gameAddress> struct InternalResolver;
template <typename T, int gameAddress> struct InternalResolver<T, true, gameAddress> {
static T* const ptr;
};
template <typename T, int gameAddress> struct InternalResolver<T, false, gameAddress> {
static T* const ptr;
};
template <int address> struct AddressUsageKeeper {
static bool initialized;
};
static void initialize(
bool& initialized, bool isImplemented, int gameAddress, const void* structPtr, const char* typeName);
public:
template <typename T, bool implemented, int gameAddress> struct Resolver {
private:
// only use this for internal logic and declarations/definitions
static const bool isImplemented = OPEN_SHC_IMPLEMENTED(implemented);
struct Initializer {
Initializer();
};
static const Initializer initializer;
public:
typedef typename InternalResolver<T, isImplemented, gameAddress> Ptr;
};
};
template <typename T, int gameAddress>
T* const StructResolver::InternalResolver<T, false, gameAddress>::ptr = reinterpret_cast<T*>(gameAddress);
template <typename T, int gameAddress>
T* const StructResolver::InternalResolver<T, true, gameAddress>::ptr
= &StructResolver::Instance<T, gameAddress>::instance;
template <int address> bool StructResolver::AddressUsageKeeper<address>::initialized = false;
template <typename T, bool implemented, int gameAddress>
const typename StructResolver::Resolver<T, implemented, gameAddress>::Initializer
StructResolver::Resolver<T, implemented, gameAddress>::initializer;
template <typename T, bool implemented, int gameAddress>
StructResolver::Resolver<T, implemented, gameAddress>::Initializer::Initializer()
{
initialize(AddressUsageKeeper<gameAddress>::initialized, isImplemented, gameAddress, Ptr::ptr, getTypeName<T>());
}
#define MACRO_STRUCT_RESOLVER(STRUCT_TYPE, IMPLEMENTED, GAME_ADDRESS) \
template struct StructResolver::Resolver<STRUCT_TYPE, IMPLEMENTED, GAME_ADDRESS>; \
typedef StructResolver::Resolver<STRUCT_TYPE, IMPLEMENTED, GAME_ADDRESS>::Ptr
#define MACRO_STRUCT_INSTANCE(GAME_ADDRESS) \
template <typename T> struct StructResolver::Instance<T, GAME_ADDRESS> { \
static T instance; \
}; \
template <typename T> T StructResolver::Instance<T, GAME_ADDRESS>::instance
#endif // STRUCT_RESOLVER