-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUABReplacer.cpp
381 lines (333 loc) · 15.7 KB
/
UABReplacer.cpp
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
// UABReplacer.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include "Utils.h"
bool shapingUAB(unsigned int option, char* targetpath, char* outputpath)
{
ifstream ifs(targetpath, ios::in | ios::binary);
if (!ifs) {
system("cls");
printf_s("File: %s\n", targetpath);
printf_s("ifstream failed to execute.\n");
return EXIT_FAILURE;
}
ofstream ofs(outputpath, ios::out);
if (!ofs) {
system("cls");
printf_s("File: %s\n", outputpath);
printf_s("ofstream failed to execute.\n");
return EXIT_FAILURE;
}
switch (option)
{
case 0:
{
ifs.seekg(0, SEEK_END);
streamoff size = ifs.tellg();
ifs.seekg(0, SEEK_SET);
char* buffer_c_str = new char[(size_t)size];
string original_buffer, regex_buffer_v1, regex_buffer_v2;
vector<string> sorted_buffer;
while (!ifs.eof()) {
ifs.read(buffer_c_str, sizeof(buffer_c_str));
original_buffer.append(buffer_c_str, (size_t)ifs.gcount());
}
ifs.close();
delete[] buffer_c_str;
printf_s("AssetBundle Mainfest is being reshaped... (1/23)");
regex_buffer_v1 = regex_all(original_buffer, regex("[^a-z0-9\\._][^a-z0-9\\._]+"), "\"resource\": ");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (2/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex("[\"][^a-z0-9\\._\":\\s]+"), "");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (3/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex(".unity3d"), ".unity3d,\n--------------------\n");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (4/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex("\\xD90"), "\",\n\"index\": \"");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (5/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex("[a-z0-9][^a-z0-9\\._:\",\\+^\\s]+"), "");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (6/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex("[a-z0-9][a-z0-9][^a-z0-9\\._:\",\\+^\\s]+"), "");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (7/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex("[^a-z0-9\\n][a-z0-9][a-z0-9][^a-z0-9\\._:\",\\+^\\s]+"), "");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (8/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex("\\xCD"), "#");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (9/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex("#[a-z0-9]+"), "");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (10/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex("\"resource\": .\"resource\":"), "\"resource\": "); // Replace duplicate lines of text.
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (11/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex("^(?!.*unity3d).*(?=\"resource\": ).*$"), ""); // Deleted assetbundle hash.
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (12/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex("^(?!.*unity3d).*(?=\"resource\": ).*(?!.*[^a-z0-9]+).*$"), "");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (13/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex("^#.*:"), "\"resource\":");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (14/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex(" .*[:]"), "");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (15/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex("^\\..*:"), "\"resource\":");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (16/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex(".*[^a-z0-9\":,\\s\\n\\.\\+_-]+"), "\"resource\": ");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (17/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex("^_\""), "\"");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (18/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex("^_"), "\"resource\": ");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (19/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex("^\\."), "\"resource\": unknown_resource."); // Replace '.unity3d' only resource string with 'unknown_resource.unity3d'.
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (20/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex(" \\."), " ");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (21/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex(" "), " ");
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (22/23)");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex(": 0.unity3d"), ": dummy_resource.unity3d"); // Replace '0.unity3d' only resource string with 'dummy_resource.unity3d'.
system("cls");
printf_s("AssetBundle Mainfest is being reshaped... (23/23)");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex(": _"), ": ");
system("cls");
ofs << "Unity AssetBundle Manifest File\nShapaded by: UABMReplacer - version 1.0\n\nCopyright (C) 2021 - XyLe, All Rights Reserved.\n\n";
ofs << regex_buffer_v1;
ofs.close();
//sortAll(outputpath, outputpath);
system("cls");
return EXIT_SUCCESS;
}
case 1:
{
ifs.seekg(0, SEEK_END);
streamoff size = ifs.tellg();
ifs.seekg(0, SEEK_SET);
char* buffer_c_str = new char[(size_t)size];
string original_buffer, regex_buffer_v1, regex_buffer_v2, user_input_v1, user_input_v2, user_cont;
vector<string> sorted_buffer;
while (!ifs.eof()) {
ifs.read(buffer_c_str, sizeof(buffer_c_str));
original_buffer.append(buffer_c_str, (size_t)ifs.gcount());
}
ifs.close();
delete[] buffer_c_str;
int lp = 0, ctd = 0, ct = 0;
while (lp == 0) {
printf_s("Enter a regular expression.\n>>");
cin >> user_input_v1;
system("cls");
printf_s("Enter the string to be replaced when a match is made.\n>>");
cin >> user_input_v2;
system("cls");
if (ct != 0) {
if (ctd % 2 == 0) {
printf_s("AssetBundle Mainfest is being reshaped... \nPlease wait a moment.");
regex_buffer_v1 = regex_all(regex_buffer_v2, regex(user_input_v1), user_input_v2);
}
else {
printf_s("AssetBundle Mainfest is being reshaped... \nPlease wait a moment.");
regex_buffer_v2 = regex_all(regex_buffer_v1, regex(user_input_v1), user_input_v2);
}
ctd++;
}
else {
printf_s("AssetBundle Mainfest is being reshaped... \nPlease wait a moment.");
regex_buffer_v1 = regex_all(original_buffer, regex(user_input_v1), user_input_v2);
ctd++;
}
system("cls");
printf_s("The replacement has been completed.\nDo you want to continue with the replacement? (y/n)");
cin >> user_cont;
system("cls");
if (user_cont != "y") {
lp = 1;
break;
}
else {
ct++;
continue;
}
}
system("cls");
ofs << "Unity AssetBundle Mainfest File\nShapaded by: UABMReplacer - version 1.0\n\nCopyright (C) 2021 - XyLe, All Rights Reserved.\n\n";
if (ct != 0 && ctd % 2 == 0) {
ofs << regex_buffer_v2;
}
else {
ofs << regex_buffer_v1;
}
ofs.close();
system("cls");
return EXIT_SUCCESS;
}
default:
system("cls");
printf_s("Invalid option.");
return EXIT_FAILURE;
}
}
bool sortAll(char* targetpath, char* outputpath) {
vector<double> data;
ifstream fin(targetpath);
if (!fin.is_open()) return 1;
ofstream fout(outputpath);
if (!fout.is_open()) return 1;
data.assign(std::istream_iterator<double>(fin), std::istream_iterator<double>());
sort(data.begin(), data.end());
fout << "Unity AssetBundle Manifest File\nShapaded by: UABMReplacer - version 1.0\n\nCopyright (C) 2021 - XyLe, All Rights Reserved.\n\n";
for (double item : data) {
fout << item;
}
fout.close();
return 0;
}
int main(int argc, char* argv[])
{
if (argc != 4) {
printf_s("UABMReplacer - Unity AssetBundle Mainfest shaping utility");
printf_s("\nCopyright (C) 2021 - XyLe, All Rights Reserved.");
printf_s("\n\nUsage: uabmr <INPUT_FILE> <OPTIONS> <OUTPUT_FILE>");
printf_s("\n\n<INPUT_FILE>: Specifies the full path of the file to be formed.");
printf_s("\n<OPTIONS>: Specify any options.");
printf_s("\n<OUTPUT_FILE>: Specify the full path to save the file after it is formed.");
printf_s("\n\nOPTIONS\n\n -d: Shaping the UABM in the usual way. (default)\n -s: Shaping UABM in a unique way (for advanced users)\n\n");
return -1;
}
else
{
string strargv = argv[2];
if (strargv.compare("-d") != 1) {
if (get_ext(argv[1]).compare(".data") != 1) {
bool ret = shapingUAB(0, argv[1], argv[3]);
if (ret != 1) {
system("cls");
printf_s("All processes have completed successfully.");
return EXIT_SUCCESS;
}
else {
remove(argv[3]);
system("cls");
printf_s("No file will be output because an error has occurred.");
return EXIT_FAILURE;
}
}
else if (get_ext(argv[1]).compare(".txt") != 1) {
bool ret = shapingUAB(0, argv[1], argv[3]);
if (ret != 1) {
system("cls");
printf_s("All processes have completed successfully.");
return EXIT_SUCCESS;
}
else {
remove(argv[3]);
system("cls");
printf_s("No file will be output because an error has occurred.");
return EXIT_FAILURE;
}
}
else if (get_ext(argv[1]).compare(".unity3d") != 1) {
bool ret = shapingUAB(0, argv[1], argv[3]);
if (ret != 1) {
system("cls");
printf_s("All processes have completed successfully.");
return EXIT_SUCCESS;
}
else {
remove(argv[3]);
system("cls");
printf_s("No file will be output because an error has occurred.");
return EXIT_FAILURE;
}
}
else {
system("cls");
printf_s("An unexpected error has occurred.");
printf_s("\nThe file format of argument 1 is invalid.");
printf_s("\nThe format must be one of the following: .txt, .data, .unity3d");
return EXIT_FAILURE;
}
}
else if (strargv.compare("-s") != 1) {
if (get_ext(argv[1]).compare(".data") != 1) {
bool ret = shapingUAB(1, argv[1], argv[3]);
if (ret != 1) {
system("cls");
printf_s("All processes have completed successfully.");
return EXIT_SUCCESS;
}
else {
remove(argv[3]);
system("cls");
printf_s("No file will be output because an error has occurred.");
return EXIT_FAILURE;
}
}
else if (get_ext(argv[1]).compare(".txt") != 1) {
bool ret = shapingUAB(1, argv[1], argv[3]);
if (ret != 1) {
system("cls");
printf_s("All processes have completed successfully.");
return EXIT_SUCCESS;
}
else {
remove(argv[3]);
system("cls");
printf_s("No file will be output because an error has occurred.");
return EXIT_FAILURE;
}
}
else if (get_ext(argv[1]).compare(".unity3d") != 1) {
bool ret = shapingUAB(1, argv[1], argv[3]);
if (ret != 1) {
system("cls");
printf_s("All processes have completed successfully.");
return EXIT_SUCCESS;
}
else {
remove(argv[3]);
system("cls");
printf_s("No file will be output because an error has occurred.");
return EXIT_FAILURE;
}
}
else {
system("cls");
printf_s("An unexpected error has occurred.");
printf_s("\nThe file format of argument 1 is invalid.");
printf_s("\nThe format must be one of the following: .txt, .data, .unity3d");
return EXIT_FAILURE;
}
}
else {
printf_s("UABMReplacer - Unity AssetBundle Mainfest shaping utility");
printf_s("\nCopyright (C) 2021 - XyLe, All Rights Reserved.");
printf_s("\n\nUsage: uabmr <INPUT_FILE> <OPTIONS> <OUTPUT_FILE>");
printf_s("\n\n<INPUT_FILE>: Specifies the full path of the file to be formed.");
printf_s("\n<OPTIONS>: Specify any options.");
printf_s("\n<OUTPUT_FILE>: Specify the full path to save the file after it is formed.");
printf_s("\n\nOPTIONS\n\n -d: Shaping the UABM in the usual way. (default)\n -s: Shaping UABM in a unique way (for advanced users)\n\n");
return -1;
}
}
}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー
// 作業を開始するためのヒント:
// 1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します
// 2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
// 3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
// 4. エラー一覧ウィンドウを使用してエラーを表示します
// 5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
// 6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します