forked from kiwon0319/GFDecompress
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Downloader.cs
257 lines (207 loc) · 9.23 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
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("검색된 데이터 버전: " + dataVersion);
}
//stc 다운
public void downloadStc() {
string url = getStcUrl();
// 삭제 후 폴더 생성
if (Directory.Exists("stc"))
Directory.Delete("stc", true);
Directory.CreateDirectory("stc");
Console.WriteLine("최신 데이터 다운로드 중...");
Console.WriteLine("Url: " + 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("다운로드 성공");
Console.WriteLine("압축해제 중...");
ZipFile.ExtractToDirectory("./stc/stc.zip","./stc");
Console.WriteLine("압축해제 성공");
Console.WriteLine("압축파일 삭제...");
File.Delete("./stc/stc.zip");
Console.WriteLine("완료!");
}
catch (Exception e){
Console.WriteLine(e);
}
}
//어셋 다운
public void downloadAsset() {
string key = "kxwL8X2+fgM=";
string iv = "M9lp+7j2Jdwqr+Yj1h+A";
byte[] bkey = Convert.FromBase64String(key);
byte[] biv = Convert.FromBase64String(iv);
string encryptedVersion = Crypto.GetDesEncryted($"{minversion}_{abVersion}_AndroidResConfigData", 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 error = null;
Python.run("Scripts\\deserializer.py", $"Assets_raw\\{location}\\{filename}", ref output, ref error);
Console.WriteLine("textes.ab 다운받는 중...");
string[] textes = new string[2];
int i = 0;
while (true) {
string str = output.ReadLine();
if (str == null)
break;
textes[i] = str;
i++;
}
string url = textes[0] + textes[1] + ".dat";
if(url == ".dat")
{
Console.WriteLine("deserializer.py가 존재하지 않습니다. 파일이 존재하는지 다시 한번 확인해주세요.");
Environment.Exit(1);
}
Console.WriteLine(url);
client.DownloadFile(url, $"Assets_raw\\{location}\\textes.zip");
Console.WriteLine("압축해제 중...");
try
{
ZipFile.ExtractToDirectory($"Assets_raw\\{location}\\textes.zip", $"Assets_raw\\{location}");
}
catch {
File.Delete($"Assets_raw\\{location}\\asset_textes.ab");
ZipFile.ExtractToDirectory($"Assets_raw\\{location}\\textes.zip", $"Assets_raw\\{location}");
}
Console.WriteLine("압축파일 삭제");
File.Delete($"Assets_raw\\{location}\\textes.zip");
//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/";
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/";
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://s3-ap-northeast-1.amazonaws.com/gf1-jpfile-server/";
return "https://d2p0tz30gps08r.cloudfront.net/";
case "en":
//return "http://gf-transit.sunborngame.com/";
return "http://dkn3dfwjnmzcj.cloudfront.net/";
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());
}
}
}