-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPatchManager.h
86 lines (69 loc) · 1.57 KB
/
PatchManager.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
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
#ifndef PATCH_MANAGER_H
#define PATCH_MANAGER_H
#include "basetypes.h"
#include <memory.h>
#define MAX_PATCH_LABELS (64)
#define MAX_PATCH_ENTRIES (64)
enum class PatchType
{
PatchType_Rel8 = 0,
PatchType_Rel16,
PatchType_Rel32,
PatchType_Rel64,
PatchType_Abs32,
PatchType_Abs64
};
struct PatchInfo
{
uint8 *patchPtr;
uint8 *basePtr;
uint32 destLabel;
PatchType patchType;
};
class PatchManager
{
public:
PatchInfo patchData[MAX_PATCH_ENTRIES];
uint8 *labelPointers[MAX_PATCH_LABELS];
uint32 numPatches;
uint32 numLabels;
PatchManager()
{
memset(this,0,sizeof(PatchManager));
}
void ApplyPatches();
void ClearPatches()
{
numPatches = 0;
}
void ClearLabels()
{
numLabels = 0;
}
void Reset()
{
numPatches = 0;
numLabels = 0;
}
void AddPatch(uint8 * const patchPtr, const PatchType patchType, uint8 * const basePtr, const uint32 destLabel)
{
assert(numPatches < MAX_PATCH_ENTRIES);
patchData[numPatches].patchPtr = patchPtr;
patchData[numPatches].patchType = patchType;
patchData[numPatches].basePtr = basePtr;
patchData[numPatches].destLabel = destLabel;
numPatches++;
}
void SetLabelPointer(const uint32 labelIndex, uint8 * const ptr)
{
assert(labelIndex < MAX_PATCH_LABELS);
labelPointers[labelIndex] = ptr;
numLabels++;
}
uint8 *GetLabelPointer(const uint32 labelIndex) const
{
assert(labelIndex < MAX_PATCH_LABELS);
return labelPointers[labelIndex];
}
};
#endif