-
Notifications
You must be signed in to change notification settings - Fork 0
/
fflags.hpp
229 lines (188 loc) · 7.31 KB
/
fflags.hpp
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
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* ░▒█▀▀▀░▒█▀▀▀░█░░█▀▀▄░█▀▀▀░░░▒█░░▒█░█▀▀▄░█▀▀▄░▄▀▀▄░▄▀▀▄░█▀▀░█▀▀▄
* ░▒█▀▀░░▒█▀▀░░█░░█▄▄█░█░▀▄░░░▒█▒█▒█░█▄▄▀░█▄▄█░█▄▄█░█▄▄█░█▀▀░█▄▄▀
* ░▒█░░░░▒█░░░░▀▀░▀░░▀░▀▀▀▀░░░▒▀▄▀▄▀░▀░▀▀░▀░░▀░█░░░░█░░░░▀▀▀░▀░▀▀
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Written by Excel. FFlag-Wrapper under the MIT License.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* https://github.com/ItzzExcel/FFlag-Wrapper/
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Yes, it's that simple.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#define AUTOCREATE_JSON_FILE
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <atlstr.h>
#include <shlobj.h>
#include <experimental/filesystem>
#include <nlohmann/json.hpp>
namespace fs = std::experimental::filesystem;
using json = nlohmann::json;
namespace FFlags {
bool ALLOW_BLOXSTRAP = false;
bool __DirectoryExists(const std::string folderPath) {
DWORD attributes = GetFileAttributesA(folderPath.c_str());
if (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
return true;
}
else {
return false;
}
}
std::string __GetUserFolderPath() {
wchar_t path[MAX_PATH];
if (SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path) == S_OK) {
size_t convertedChars = 0;
char narrowPath[MAX_PATH] = { NULL };
if (wcstombs_s(&convertedChars, narrowPath, path, MAX_PATH) == 0) {
return std::string(narrowPath);
}
else {
return "";
}
}
else {
return "";
}
}
bool __IsFile(const std::string filePath) {
DWORD attributes = GetFileAttributesA(filePath.c_str());
if (attributes != INVALID_FILE_ATTRIBUTES && !(attributes & FILE_ATTRIBUTE_DIRECTORY))
return true;
else
return false;
}
bool __DoFile(const std::string filePath, const std::string content) {
try {
std::ofstream outFile(filePath);
if (outFile.is_open()) {
outFile << content;
outFile.close();
return true;
}
else {
return false;
}
}
catch (const std::exception& ex) {
std::cerr << "Error: " << ex.what() << std::endl;
return false;
}
}
bool __DoDirectory(const std::string& path) {
if (CreateDirectoryA(path.c_str(), NULL) == 0) {
DWORD error = GetLastError();
if (error == ERROR_ALREADY_EXISTS) {
return true;
}
else {
std::cerr << "Error: Failed to create directory. Error code: " << error << std::endl;
return false;
}
}
else {
return true;
}
}
std::string __GetRobloxFolder() {
if (ALLOW_BLOXSTRAP == true) {
std::string bloxstrapPath = __GetUserFolderPath() + "\\AppData\\Local\\Bloxstrap\\Modifications\\ClientSettings";
if (__DirectoryExists(bloxstrapPath))
return bloxstrapPath;
}
std::string robloxPath = __GetUserFolderPath() + "\\AppData\\Local\\Roblox\\Versions";
if (fs::exists(robloxPath) && fs::is_directory(robloxPath)) {
for (const auto& entry : fs::directory_iterator(robloxPath)) {
if (fs::is_directory(entry.path()) && fs::exists(entry.path() / "RobloxPlayerBeta.exe")) {
return entry.path().string() + "\\ClientSettings";
}
}
}
return "\0";
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - */
bool Write(std::string FFlag, std::string Value) {
std::string filePath = __GetRobloxFolder() + "\\ClientAppSettings.json";
try {
json jsonData;
#ifdef AUTOCREATE_JSON_FILE
if (!__DirectoryExists(__GetRobloxFolder()))
__DoDirectory(__GetRobloxFolder());
if (!__IsFile(filePath))
__DoFile(filePath, "{}");
#endif
std::ifstream inputFile(filePath);
inputFile >> jsonData;
inputFile.close();
jsonData[FFlag] = Value;
std::ofstream outputFile(filePath);
outputFile << std::setw(2) << jsonData << std::endl;
outputFile.close();
return true;
}
catch (const std::exception& ex) {
throw std::runtime_error("Error updating file: " + std::string(ex.what()));
}
}
std::string Read(std::string FFlag) {
std::string filePath = __GetRobloxFolder() + "\\ClientAppSettings.json";
#ifdef AUTOCREATE_JSON_FILE
if (!__DirectoryExists(__GetRobloxFolder()))
__DoDirectory(__GetRobloxFolder());
if (!__IsFile(filePath))
__DoFile(filePath, "{}");
#endif
try {
std::ifstream inputFile(filePath);
json jsonData;
inputFile >> jsonData;
inputFile.close();
if (jsonData.contains(FFlag)) {
return jsonData[FFlag].get<std::string>();
}
else {
return "null";
}
}
catch (const std::exception& ex) {
std::cerr << "Error:\t" << ex.what() << std::endl;
return "null";
}
}
bool Delete(std::string FFlag) {
std::string filePath = __GetRobloxFolder() + "\\ClientAppSettings.json";
#ifdef AUTOCREATE_JSON_FILE
if (!__DirectoryExists(__GetRobloxFolder()))
__DoDirectory(__GetRobloxFolder());
if (!__IsFile(filePath))
__DoFile(filePath, "{}");
#endif
try {
std::ifstream inputFile(filePath);
json jsonData;
inputFile >> jsonData;
inputFile.close();
if (jsonData.contains(FFlag)) {
jsonData.erase(FFlag);
std::ofstream outputFile(filePath);
outputFile << std::setw(2) << jsonData << std::endl;
outputFile.close();
return true;
}
else {
std::cerr << "Error: The value does not exist." << std::endl;
return false;
}
}
catch (const std::exception& ex) {
std::cerr << "Error:\t" << ex.what() << std::endl;
return false;
}
}
}