Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
135 lines (109 loc) · 4.44 KB
/
Copy pathmain.cpp
File metadata and controls
135 lines (109 loc) · 4.44 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
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
#include <algorithm>
#include <iostream>
#include <filesystem>
#include <fstream>
#include <string>
#include <vector>
void makeFile(const std::string& inputFilename, const std::string& outputFilename, const std::string& namespaceName) {
static std::string unorderedMapStr = "std::unordered_map<std::string_view, std::string_view>";
std::string inputFile = "res/" + inputFilename;
std::string outputFile = "maps/" + outputFilename + ".cpp";
std::filesystem::create_directory("maps");
std::ifstream input(inputFile);
std::ofstream outputCpp(outputFile);
std::cout << "Beginning file " << outputFile << '\n';
std::string buffer;
getline(input, buffer);
outputCpp << "#include <unordered_map>\n#include <string_view>\n\nnamespace " << namespaceName << " {\n\n";
if(buffer == "CLASSES") {
struct classData {
std::string deobf;
std::string obf;
};
std::vector<classData> vec;
while(input && buffer != "FIELDS") {
getline(input, buffer);
if(buffer == "FIELDS")
break;
auto split0 = 0;
auto split1 = buffer.find(" ");
std::string deobf = buffer.substr(split0, split1);
std::string obf = buffer.substr(split1 + 1);
vec.push_back({deobf, obf});
}
std::sort(vec.begin(), vec.end(), [&](const classData& l, const classData& r){
return (l.deobf.compare(r.deobf) <= 0);
});
outputCpp << unorderedMapStr << " classMap = {\n";
for(const auto& clazz : vec)
outputCpp << "\t{ \"" << clazz.deobf << "\", \"" << clazz.obf << "\" },\n";
outputCpp << "};\n\n";
std::cout << "Created " << vec.size() << " class mappings\n";
}
if(buffer == "FIELDS") {
struct fieldData {
std::string deobf;
std::string obf;
};
std::vector<fieldData> vec;
while(input && buffer != "METHODS") {
getline(input, buffer);
if(buffer == "METHODS")
break;
auto split0 = 0;
auto split1 = buffer.find(" ");
std::string deobf = buffer.substr(split0, split1);
std::string obf = buffer.substr(split1 + 1);
vec.push_back({deobf, obf});
}
std::sort(vec.begin(), vec.end(), [&](const fieldData& l, const fieldData& r){
return (l.deobf.compare(r.deobf) <= 0);
});
outputCpp << unorderedMapStr << " fieldMap = {\n";
for(const auto& field : vec)
outputCpp << "\t{ \"" << field.deobf << "\", \"" << field.obf << "\" },\n";
outputCpp << "};\n\n";
std::cout << "Created " << vec.size() << " field mappings\n";
}
if(buffer == "METHODS") {
struct methodData {
std::string deobf;
std::string deobfSig;
std::string obf;
std::string obfSig;
};
std::vector<methodData> vec;
while(input) {
getline(input, buffer);
if(buffer.empty())
break;
auto split0 = 0;
auto split1 = buffer.find(" ");
auto split2 = buffer.find(" ", split1 + 1);
auto split3 = buffer.find(" ", split2 + 1);
std::string deobf = buffer.substr(split0, split1);
std::string deobfSig = buffer.substr(split1 + 1, split2 - split1 - 1);
std::string obf = buffer.substr(split2 + 1, split3 - split2 - 1);
std::string obfSig = buffer.substr(split3 + 1);
vec.push_back({ deobf, deobfSig, obf, obfSig });
}
std::sort(vec.begin(), vec.end(), [&](const methodData& l, const methodData& r){
return (l.deobf.compare(r.deobf) <= 0);
});
outputCpp << unorderedMapStr << " methodMap = {\n";
for(const auto& method : vec)
outputCpp << "\t{ \"" << method.deobf << "|" << method.deobfSig << "\", \"" << method.obf << '|' << method.obfSig << "\" },\n";
outputCpp << "};\n\n";
std::cout << "Created " << vec.size() << " method mappings\n";
}
outputCpp << "}\n";
outputCpp.close();
std::cout << "Finished file " << outputFile << "\n\n";
}
int main() {
std::cout << "Tool started..\n\n";
makeFile("vanilla_mappings.txt", "vanilla_hardcode", "VanillaHardcode");
makeFile("forge_mappings.txt", "forge_hardcode", "ForgeHardcode");
std::cout << "Finished\n";
return 0;
}