forked from 36base/GFDecompress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDownloader.cs
327 lines (270 loc) · 11.7 KB
/
Downloader.cs
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
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO.Compression;
using System.Dynamic;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace GFDecompress
{
class Downloader
{
string dataVersion;
string clientVersion;
double minversion;
string abVersion;
string location;
//생성자
public Downloader(string _location = "kr") {
location = _location;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(getGameHost(location) + "Index/version");
req.UserAgent = "Dalvik/2.1.0 (Linux; U; Android 9; SM-N935k Build/PPR1.180610.011)";
req.Headers.Add("X-Unity-Version", "2017.4.33f1");
req.ContentType = @"application/x-www-form-urlencoded";
HttpWebResponse wResp = (HttpWebResponse)req.GetResponse();
Stream respPostStream = wResp.GetResponseStream();
StreamReader readerpost = new StreamReader(respPostStream);
JObject obj = JObject.Parse(readerpost.ReadToEnd());
dataVersion = obj["data_version"].ToString();
clientVersion = obj["client_version"].ToString();
minversion = Math.Round(double.Parse(clientVersion) / 100) * 10;
abVersion = obj["ab_version"].ToString();
Console.WriteLine("Retrived data version: " + dataVersion);
}
//stc 다운
public void downloadStc() {
string url = getStcUrl();
// 삭제 후 폴더 생성
if (Directory.Exists("stc"))
Directory.Delete("stc", true);
Directory.CreateDirectory("stc");
Console.WriteLine("\n Downloading latest stc data from " + url);
foreach (var item in new DirectoryInfo("stc").GetFiles())
{
if (item.Name == "desktop.ini")
continue;
File.Delete($"stc/{item.Name}");
}
try
{
WebClient client = new WebClient();
client.DownloadFile(getStcUrl(), "./stc/stc.zip");
Console.WriteLine("Downloaded successfullly");
Console.WriteLine("Decompressing");
ZipFile.ExtractToDirectory("./stc/stc.zip","./stc");
Console.WriteLine("Decompression succesful");
Console.WriteLine("Deleting compressed file");
File.Delete("./stc/stc.zip");
Console.WriteLine("Deleted succesfully" + Environment.NewLine);
}
catch (Exception e){
Console.WriteLine(e);
}
}
//어셋 다운
public void downloadAsset(string server) {
string key = "kxwL8X2+fgM=";
string iv = "M9lp+7j2Jdwqr+Yj1h+A";
byte[] bkey = Convert.FromBase64String(key);
byte[] biv = Convert.FromBase64String(iv);
string encryptedVersion = "";
encryptedVersion = Crypto.GetDesEncryted($"{minversion}_{abVersion}_AndroidResConfigData2018", bkey, biv.Take(8).ToArray());
string filename = Regex.Replace(encryptedVersion, @"[^a-zA-Z0-9]", "") + ".txt";
if (!Directory.Exists("Assets_raw"))
Directory.CreateDirectory("Assets_raw");
if (!Directory.Exists($"Assets_raw\\{location}"))
Directory.CreateDirectory($"Assets_raw\\{location}");
WebClient client = new WebClient();
client.DownloadFile(getAssetUrl(filename), $"Assets_raw\\{location}\\{filename}");
StreamReader output = null;
StreamReader output2 = null;
StreamReader output3 = null;
StreamReader output4 = null;
StreamReader error = null;
StreamReader error2 = null;
StreamReader error3 = null;
StreamReader error4 = null;
Python.run("Scripts\\deserializer.py", $"Assets_raw\\{location}\\{filename}", ref output, ref error);
Python.run("Scripts\\deserializer2.py", $"Assets_raw\\{location}\\{filename}", ref output2, ref error2);
Python.run("Scripts\\deserializer3.py", $"Assets_raw\\{location}\\{filename}", ref output3, ref error3);
Python.run("Scripts\\deserializer4.py", $"Assets_raw\\{location}\\{filename}", ref output4, ref error4);
Console.WriteLine("Downloading textes.ab, texttable.ab, avgtext.ab, textlpatch.ab");
string[] textes = new string[2];
string[] texttable = new string[2];
string[] avgtext = new string[2];
string[] textlpatch = new string[2];
int i = 0;
while (true) {
string str = output.ReadLine();
if (str == null)
break;
textes[i] = str;
i++;
}
int j = 0;
while (true)
{
string str2 = output2.ReadLine();
if (str2 == null)
break;
texttable[j] = str2;
j++;
}
int k = 0;
while (true)
{
string str3 = output3.ReadLine();
if (str3 == null)
break;
avgtext[k] = str3;
k++;
}
int l = 0;
while (true)
{
string str4 = output4.ReadLine();
if (str4 == null)
break;
textlpatch[l] = str4;
l++;
}
string url = textes[0] + textes[1] + ".ab";
string url2 = texttable[0] + texttable[1] + ".ab";
string url3 = avgtext[0] + avgtext[1] + ".ab";
string url4 = textlpatch[0] + textlpatch[1] + ".ab";
if (url == ".ab")
{
Console.WriteLine("Error with deserializer.py, make sure it exists (redownload from this GitHub) and make sure Python with unitypack is installed.");
Console.ReadKey();
Environment.Exit(1);
}
if (url2 == ".ab")
{
Console.WriteLine("Error with deserializer2.py, make sure it exists (redownload from this GitHub) and make sure Python with unitypack is installed.");
Console.ReadKey();
Environment.Exit(1);
}
if (url3 == ".ab")
{
Console.WriteLine("Error with deserializer3.py, make sure it exists (redownload from this GitHub) and make sure Python with unitypack is installed.");
Console.ReadKey();
Environment.Exit(1);
}
if (url4 == ".ab")
{
Console.WriteLine("Error with deserializer4.py, make sure it exists (redownload from this GitHub) and make sure Python with unitypack is installed.");
Console.ReadKey();
Environment.Exit(1);
}
Console.WriteLine(url);
client.DownloadFile(url, $"Assets_raw\\{location}\\asset_textes.ab");
Console.WriteLine(url2);
client.DownloadFile(url2, $"Assets_raw\\{location}\\asset_texttable.ab");
Console.WriteLine(url3);
client.DownloadFile(url3, $"Assets_raw\\{location}\\asset_textavg.ab");
if (textlpatch[1] != null)
{
Console.WriteLine(url4);
client.DownloadFile(url4, $"Assets_raw\\{location}\\asset_textlpatch.ab");
}
//Console.WriteLine("에셋 추출 중...");
//ProcessStartInfo extractor = new ProcessStartInfo("Scripts\\extractexe\\extract.exe", $@"Assets_raw\\{location}\\asset_textes.ab");
//Process extract = Process.Start(extractor);
//extract.WaitForExit();
//Python.run("Scripts\\extractpy\\abunpack.py", $"-0 Asset\\{location} Assets_raw\\{location}\\asset_textes.ab", ref output, ref error);
//Console.WriteLine(error.ReadToEnd());
}
public string getStcUrl() {
var md5Hash = MD5.Create();
string hash = Crypto.GetMd5Hash(md5Hash, dataVersion);
return getCDNHost(location) + "data/stc_" + dataVersion + hash + ".zip";
}
public string getAssetUrl(string filename) {
return getUpdateHost(location) + filename;
}
public long getCurrentTime() {
var timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
return (long)timeSpan.TotalSeconds;
}
public string getGameHost(string _location) {
switch (_location) {
case "kr":
return "http://gf-game.girlfrontline.co.kr/index.php/1001/";
case "jp":
return "http://gfjp-game.sunborngame.com/index.php/1001/";
case "en":
return "http://gf-game.sunborngame.com/index.php/1001/";
case "tw":
return "http://sn-game.txwy.tw/index.php/1001/";
default:
return "http://gfcn-game.gw.merge.sunborngame.com/index.php/1000/";
}
}
public string getCDNHost(string _location)
{
switch (_location) {
case "kr":
return "http://gfkrcdn.imtxwy.com/";
case "jp":
return "https://gfjp-cdn.sunborngame.com/";
case "en":
return "https://gfus-cdn.sunborngame.com/";
case "tw":
return "http://sncdn.imtxwy.com/";
default:
return "http://gf-cn.cdn.sunborngame.com/";
}
}
public string getUpdateHost(string _location) {
switch (_location) {
case "kr":
return "http://sn-list.girlfrontline.co.kr/";
case "jp":
return "https://gfjp-cdn.sunborngame.com/";
case "en":
return "http://gfus-cdn.sunborngame.com/";
case "tw":
return "http://sn-list.txwy.tw/";
default:
return "http://gf-cn.cdn.sunborngame.com/";
}
}
}
public class Crypto {
public static string GetMd5Hash(MD5 md5Hash, string input)
{
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
public static string GetDesEncryted(string _data, byte[] _key, byte[] _iv) {
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = _key;
des.IV = _iv;
MemoryStream ms = new MemoryStream();
CryptoStream stream = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
byte[] data = Encoding.UTF8.GetBytes(_data.ToCharArray());
stream.Write(data, 0, data.Length);
stream.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
}
}