-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpatcher.h
85 lines (61 loc) · 1.62 KB
/
patcher.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
//
// Created by RedbeanW on 9/16/2022.
//
#pragma once
#include <vector>
#include <unordered_map>
#include <fstream>
#include <utility>
#include "utils.h"
using std::vector;
using std::unordered_map;
using std::string;
using std::fstream;
enum class Platform {
Win10,
Android,
IOS
};
class MCPatcher {
public:
~MCPatcher();
enum class DataType {
NORMAL, // e.g. 0E
ALL // e.g. ??
};
struct ByteEntity {
DataType mType = DataType::NORMAL;
BYTE mData = 0x00;
struct Replacer {
bool mEnabled = false;
BYTE mData = 0x00;
} mReplacer;
};
struct PatchEntity {
vector<ByteEntity> mBytes;
void add(const ByteEntity& entity) {
mBytes.emplace_back(entity);
};
[[nodiscard]] bool valid() const {
return !mBytes.empty();
};
};
void registerPatch(Platform platform, const string& name, const PatchEntity& patch);
bool target(const string& path);
bool apply(Platform);
fstream& getImage();
unordered_map<string, PatchEntity>& getPatches(Platform);
static PatchEntity compile(string patchExpression);
private:
unordered_map<Platform, unordered_map<string, PatchEntity>> mPatches;
fstream mImage;
using Address = long long;
vector<std::pair<Address, BYTE>> handleBytes(const vector<ByteEntity> &bytes);
};
#include <exception>
class CompileFailed : public std::exception {
public:
[[nodiscard]] const char* what() const noexcept override {
return "Failed to compile patch expression.";
};
};