-
Notifications
You must be signed in to change notification settings - Fork 1
/
Templates.hh
276 lines (226 loc) · 4.54 KB
/
Templates.hh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#pragma once
namespace UFG
{
template<typename T>
struct qSetBase
{
uint32_t mCount;
uint32_t mBufferSize;
T** mppArray;
};
template<typename T>
struct qArray
{
uint32_t size;
uint32_t capacity;
T* p;
};
template <typename T, size_t N>
struct qSafeArray
{
T array[N];
};
template<typename T, size_t N>
struct qFixedArray
{
uint32_t size;
T p[N];
};
template<typename T>
struct qNode
{
qNode<T>* mPrev;
qNode<T>* mNext;
T* GetBase() { return reinterpret_cast<T*>(this); }
template <uintptr_t N = 0>
T* GetPointer() { return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(this) + N); }
template <uintptr_t N = 0>
T* GetPointerSub() { return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(this) - N); }
void GetVector(std::vector<T*>& m_Vector)
{
for (qNode<T>* i = mNext; i != this; i = i->mNext)
m_Vector.emplace_back(i->GetPointer());
}
void Swap(qNode<T>* p_Node)
{
if (this->mPrev == this) // Is Head?
{
if (this->mNext)
this->mNext->mPrev = p_Node;
this->mNext = p_Node;
p_Node->mPrev = this;
return;
}
// Swap next ptrs
qNode<T>* m_CurrentNext = this->mNext;
this->mNext = p_Node->mNext;
p_Node->mNext = m_CurrentNext;
if (this->mNext)
this->mNext->mPrev = this;
if (p_Node->mNext)
p_Node->mNext->mPrev = p_Node;
// Swap prev ptrs
qNode<T>* m_CurrentPrev = this->mPrev;
this->mPrev = p_Node->mPrev;
p_Node->mPrev = m_CurrentPrev;
if (this->mPrev)
this->mPrev->mNext = this;
if (p_Node->mPrev)
p_Node->mPrev->mNext = p_Node;
}
};
template <typename T>
struct qList
{
qNode<T> mNode;
};
template<typename T>
struct HomerCubic
{
T mDuration;
T mParameter;
T A;
T B;
T C;
T D;
T p0;
T p1;
T v0;
T v1;
};
template <typename T>
struct LinearGraph
{
int nData;
float* fDomain;
T* tRange;
};
template<typename T>
struct qSafePointerBase
{
void* mPrev;
void* mNext;
T* m_pPointer;
};
template<typename T>
struct qSafePointer : qSafePointerBase<T>
{ };
template<typename T>
struct qSafePointerNode
{
qSafePointerNode<T>* vfptr;
qList<qSafePointerBase<T>> m_SafePointerList;
};
template<typename T>
struct qSafePointerWithCallbacksBase
{
qNode<qSafePointerWithCallbacksBase<T>> m_Node;
T* m_pPointer;
uint32_t m_Changed;
T* m_BindClass;
T* m_BindCallback;
T* m_UnbindClass;
T* m_UnbindCallback;
};
template<typename T>
struct qSafePointerWithCallbacks : qSafePointerWithCallbacksBase<T>
{
};
template<typename T>
struct qSafePointerNodeWithCallbacks : qSafePointerNode<T>
{
qList<qSafePointerWithCallbacksBase<T>> m_SafePointerWithCallbackList;
};
template<typename T>
struct RebindingComponentHandle : qNode<RebindingComponentHandle<T>>
{
uint32_t m_TypeUID;
UFG_PAD(0x4);
T* m_pSimComponent;
void* m_pSimObject;
uint32_t m_Changed;
UFG_PAD(0x4);
};
template <typename T>
struct qOffset64
{
int64_t mOffset;
UFG_INLINE bool IsValid()
{
return mOffset;
}
UFG_INLINE T* Get(uint32_t m_Index, uintptr_t m_Size)
{
uintptr_t m_Address = reinterpret_cast<uintptr_t>(this) + mOffset;
return reinterpret_cast<T*>(m_Address + static_cast<uintptr_t>(m_Index) * m_Size);
}
UFG_INLINE T* Get(uint32_t m_Index)
{
return Get(m_Index, sizeof(T));
}
UFG_INLINE T* GetPointer()
{
if (!IsValid()) {
return nullptr;
}
return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(this) + mOffset);
}
UFG_INLINE void Set(void* p_Ptr)
{
if (p_Ptr) {
mOffset = static_cast<int64_t>(reinterpret_cast<uintptr_t>(p_Ptr) - reinterpret_cast<uintptr_t>(&mOffset));
return;
}
mOffset = 0;
}
};
// Bin Stuff
struct BinString
{
int64_t mOffset;
bool IsSet() { return mOffset; }
const char* Get()
{
return reinterpret_cast<const char*>(reinterpret_cast<uintptr_t>(this) + mOffset);
}
};
template <typename T>
struct BinArray
{
int mCount;
qOffset64<T> mData;
};
template <typename T>
struct BinPtrArray
{
int mCount;
qOffset64<qOffset64<T>> mData;
uint32_t GetRealCount()
{
return (static_cast<uint32_t>(mCount) & 0x7FFFFFFFu);
}
T* GetFromIndex(uint32_t p_Index)
{
qOffset64<T>* m_OffsetPtr = mData.GetPointer();
if (m_OffsetPtr)
return m_OffsetPtr[p_Index].GetPointer();
return nullptr;
}
};
// Reflect Stuff
template <typename T>
struct qReflectArray
{
T* mItems;
uint32_t mNumItems;
uint32_t mFlags;
};
// Havok Stuff
template <typename T>
struct HavokArray
{
T* m_data;
int m_size;
int m_capacityAndFlags;
};
}