Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Add unpack game data.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexstr committed May 28, 2020
1 parent 010bebf commit 969f375
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 18 deletions.
1 change: 1 addition & 0 deletions FGOAssetsModifyTool/FGOAssetsModifyTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="CatAndMouseGame.cs" />
<Compile Include="Crc32.cs" />
<Compile Include="FNV1a.cs" />
<Compile Include="HttpRequest.cs" />
<Compile Include="MasterDataUnpacker.cs" />
<Compile Include="MiniMessagePacker.cs" />
<Compile Include="Program.cs" />
Expand Down
44 changes: 44 additions & 0 deletions FGOAssetsModifyTool/HttpRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Net;
using System.Text;
using System.Collections.Generic;
using System.IO;

namespace FGOAssetsModifyTool
{
class HttpRequest
{
public static string PhttpReq(string url, string parameters)
{

HttpWebRequest hRequest = (HttpWebRequest)HttpWebRequest.Create(url);
hRequest.CookieContainer = new CookieContainer();

hRequest.Accept = "gzip, identity";
hRequest.UserAgent = "Dalvik/2.1.0 (Linux; U; Android 6.0.1; MI 6 Build/V417IR)";
hRequest.ServicePoint.Expect100Continue = false;
hRequest.KeepAlive = true;
hRequest.Method = "POST";

hRequest.ContentType = "application/x-www-form-urlencoded";

bool first = true;

hRequest.ContentLength = parameters.Length;

byte[] dataParsed = Encoding.UTF8.GetBytes(parameters);
hRequest.GetRequestStream().Write(dataParsed, 0, dataParsed.Length);


hRequest.Timeout = 5 * 1000;

HttpWebResponse response = (HttpWebResponse)hRequest.GetResponse();

Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
}
}
68 changes: 50 additions & 18 deletions FGOAssetsModifyTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Text.RegularExpressions;

namespace FGOAssetsModifyTool
{
class Program
Expand All @@ -22,16 +24,17 @@ static void DisplayMenu()
"6: 加密剧情文本(scripts)\n" +
"7: 解密剧情文本(scripts)\n" +
"8: 把国服文本转换为日服适用\n" +
"9: 计算CRC值\n" +
"9: 从服务器下载游戏数据\n" +
"0: 导出资源名 - 实际文件名\n" +
"11: [gamedata/top]解密master(卡池信息)\n" +
"12: [gamedata/top]解密assetbundle(文件夹名)\n" +
"11: [gamedata/top]解密master(游戏数据)\n" +
"12: [gamedata/top]解密assetbundle(assets文件夹名)\n" +
"13: [gamedata/top]解密webview(url)\n" +
"69: 切换为美服密钥\n" +
"67: 切换为国服密钥");
int arg = Convert.ToInt32(Console.ReadLine());
string path = Directory.GetCurrentDirectory();
DirectoryInfo folder = new DirectoryInfo(path + @"\Android\");
DirectoryInfo gamedata = new DirectoryInfo(path + @"\Android\gamedata\");
DirectoryInfo decrypt = new DirectoryInfo(path + @"\Decrypt\");
DirectoryInfo encrypt = new DirectoryInfo(path + @"\Encrypt\");
DirectoryInfo decryptScripts = new DirectoryInfo(path + @"\DecryptScripts\");
Expand Down Expand Up @@ -186,7 +189,10 @@ static void DisplayMenu()
}
case 8:
{
JObject jp = JObject.Parse(File.ReadAllText(decrypt.FullName + "JP.txt"));
string jptext = File.ReadAllText(decrypt.FullName + "JP.txt");
jptext = Regex.Replace(jptext, @".*//.*\n", "", RegexOptions.Multiline);
jptext = Regex.Replace(jptext, "\"$", "\",", RegexOptions.Multiline);
JObject jp = JObject.Parse(jptext);
JObject cn = JObject.Parse(File.ReadAllText(decrypt.FullName + "CN.txt"));
JObject no = new JObject();
foreach (JProperty jProperty in jp.Properties())
Expand All @@ -206,11 +212,32 @@ static void DisplayMenu()
}
case 9:
{
foreach (FileInfo file in encrypt.GetFiles("*.bin"))
string result = HttpRequest.PhttpReq("https://game.fate-go.jp/gamedata/top", "appVer=2.13.2");
JObject res = JObject.Parse(result);
if (res["response"][0]["fail"]["action"] != null)
{
Console.WriteLine(file.Name + "\r\nsize: " + file.Length + "\r\ncrc: " + Crc32.Compute(File.ReadAllBytes(file.FullName)));
Console.WriteLine("======================================");
if(res["response"][0]["fail"]["action"].ToString() == "app_version_up")
{
string tmp = res["response"][0]["fail"]["detail"].ToString();
tmp = Regex.Replace(tmp, @".*新ver.:(.*)、現.*", "$1", RegexOptions.Singleline);
Console.WriteLine("new version: " + tmp.ToString());
result = HttpRequest.PhttpReq("https://game.fate-go.jp/gamedata/top", "appVer=" + tmp.ToString());
res = JObject.Parse(result);
}
else
{
break;
}
}
if (!Directory.Exists(gamedata.FullName))
Directory.CreateDirectory(gamedata.FullName);
File.WriteAllText(gamedata.FullName + "raw", result);
File.WriteAllText(gamedata.FullName + "assetbundle", res["response"][0]["success"]["assetbundle"].ToString());
Console.WriteLine("Writing file to: " + gamedata.FullName + "assetbundle");
File.WriteAllText(gamedata.FullName + "master", res["response"][0]["success"]["master"].ToString());
Console.WriteLine("Writing file to: " + gamedata.FullName + "master");
File.WriteAllText(gamedata.FullName + "webview", res["response"][0]["success"]["webview"].ToString());
Console.WriteLine("Writing file to: " + gamedata.FullName + "webview");
break;
}
case 0:
Expand Down Expand Up @@ -255,33 +282,38 @@ static void DisplayMenu()
}
case 11:
{
//卡池信息
string data = File.ReadAllText(folder.FullName + "master");
//游戏数据
string data = File.ReadAllText(gamedata.FullName + "master");
if (!Directory.Exists(gamedata.FullName + "unpack_master"))
Directory.CreateDirectory(gamedata.FullName + "unpack_master");
Dictionary<string, byte[]> masterData = (Dictionary<string, byte[]>)MasterDataUnpacker.MouseGame2Unpacker(Convert.FromBase64String(data));
JObject job = new JObject();
MiniMessagePacker miniMessagePacker = new MiniMessagePacker();
List<Object> unpackeditem = (List<Object>)miniMessagePacker.Unpack(masterData["mstGacha"]);
string json = JsonConvert.SerializeObject(unpackeditem, Formatting.Indented);
File.WriteAllText(folder.FullName + "masterData.txt", json);
Console.WriteLine("Writing file to: " + folder.FullName + "masterData.txt");
foreach(KeyValuePair<string, byte[]> item in masterData)
{
List<object> unpackeditem = (List<object>)miniMessagePacker.Unpack(item.Value);
string json = JsonConvert.SerializeObject(unpackeditem, Formatting.Indented);
File.WriteAllText(gamedata.FullName + "unpack_master/" + item.Key, json);
Console.WriteLine("Writing file to: " + gamedata.FullName + "unpack_master/" + item.Key);
}
break;
}
case 12:
{
string data = File.ReadAllText(folder.FullName + "assetbundle");
string data = File.ReadAllText(gamedata.FullName + "assetbundle");
Dictionary<string, object> dictionary = (Dictionary<string, object>)MasterDataUnpacker.MouseInfoMsgPack(Convert.FromBase64String(data));
string str = null;
foreach (var a in dictionary)
{
str += a.Key + ": " + a.Value.ToString() + "\r\n";
}
File.WriteAllText(folder.FullName + "assetbundle.txt", str);
File.WriteAllText(gamedata.FullName + "assetbundle.txt", str);
Console.WriteLine("folder name: " + dictionary["folderName"].ToString());
break;
}
case 13:
{
string data = File.ReadAllText(folder.FullName + "webview");
string data = File.ReadAllText(gamedata.FullName + "webview");
Dictionary<string, object> dictionary = (Dictionary<string, object>)MasterDataUnpacker.MouseGame2MsgPack(Convert.FromBase64String(data));
string str = "baseURL: " + dictionary["baseURL"].ToString() + "\r\ncontactURL: " + dictionary["contactURL"].ToString() + "\r\n";
Console.WriteLine(str);
Expand All @@ -290,8 +322,8 @@ static void DisplayMenu()
{
str += a.Key + ": " + a.Value.ToString() + "\r\n";
}
File.WriteAllText(folder.FullName + "webview.txt", str);
Console.WriteLine("Writing file to: " + folder.FullName + "webview.txt");
File.WriteAllText(gamedata.FullName + "webview.txt", str);
Console.WriteLine("Writing file to: " + gamedata.FullName + "webview.txt");
break;
}
default:
Expand Down

0 comments on commit 969f375

Please sign in to comment.