mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-16 08:54:47 +01:00
download new data format
This commit is contained in:
@@ -24,7 +24,9 @@ namespace EpinelPS.Data
|
||||
}
|
||||
|
||||
public byte[] Sha256Hash;
|
||||
public byte[] MpkHash;
|
||||
public int Size;
|
||||
public int MpkSize;
|
||||
|
||||
private ZipFile MainZip;
|
||||
private MemoryStream ZipStream;
|
||||
@@ -210,18 +212,27 @@ namespace EpinelPS.Data
|
||||
return Instance;
|
||||
}
|
||||
|
||||
public GameData(string filePath)
|
||||
public GameData(string filePath, string mpkFilePath)
|
||||
{
|
||||
if (!File.Exists(filePath)) throw new ArgumentException("Static data file must exist", nameof(filePath));
|
||||
|
||||
// disable warnings
|
||||
ZipStream = new();
|
||||
|
||||
// process json data
|
||||
var rawBytes = File.ReadAllBytes(filePath);
|
||||
Sha256Hash = SHA256.HashData(rawBytes);
|
||||
Size = rawBytes.Length;
|
||||
|
||||
LoadGameData(filePath);
|
||||
// process mpk data
|
||||
if (!string.IsNullOrEmpty(mpkFilePath))
|
||||
{
|
||||
var rawBytes2 = File.ReadAllBytes(mpkFilePath);
|
||||
MpkHash = SHA256.HashData(rawBytes2);
|
||||
MpkSize = rawBytes2.Length;
|
||||
}
|
||||
|
||||
LoadGameData(filePath, GameConfig.Root.StaticData);
|
||||
if (MainZip == null) throw new Exception("failed to read zip file");
|
||||
}
|
||||
|
||||
@@ -233,11 +244,11 @@ namespace EpinelPS.Data
|
||||
Modulus = [0x89, 0xD6, 0x66, 0x00, 0x7D, 0xFC, 0x7D, 0xCE, 0x83, 0xA6, 0x62, 0xE3, 0x1A, 0x5E, 0x9A, 0x53, 0xC7, 0x8A, 0x27, 0xF3, 0x67, 0xC1, 0xF3, 0xD4, 0x37, 0xFE, 0x50, 0x6D, 0x38, 0x45, 0xDF, 0x7E, 0x73, 0x5C, 0xF4, 0x9D, 0x40, 0x4C, 0x8C, 0x63, 0x21, 0x97, 0xDF, 0x46, 0xFF, 0xB2, 0x0D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0x6D, 0xC4, 0x25, 0x36, 0x17, 0xDB, 0x54, 0x0C, 0xD8, 0x77, 0x80, 0x9A, 0x00, 0x62, 0x83, 0xDD, 0xB0, 0x06, 0x64, 0xD0, 0x81, 0x5B, 0x0D, 0x23, 0x9E, 0x88, 0xBD],
|
||||
DP = null
|
||||
};
|
||||
private void LoadGameData(string file)
|
||||
private void LoadGameData(string file, StaticData data)
|
||||
{
|
||||
using var fileStream = File.Open(file, FileMode.Open, FileAccess.Read);
|
||||
|
||||
var a = new Rfc2898DeriveBytes(PresharedValue, GameConfig.Root.StaticData.GetSalt2Bytes(), 10000, HashAlgorithmName.SHA256);
|
||||
var a = new Rfc2898DeriveBytes(PresharedValue, data.GetSalt2Bytes(), 10000, HashAlgorithmName.SHA256);
|
||||
var key2 = a.GetBytes(32);
|
||||
|
||||
byte[] decryptionKey = key2[0..16];
|
||||
@@ -277,8 +288,8 @@ namespace EpinelPS.Data
|
||||
throw new Exception("error 3");
|
||||
|
||||
dataMs.Position = 0;
|
||||
var keyDecryptor2 = new Rfc2898DeriveBytes(PresharedValue, GameConfig.Root.StaticData.GetSalt1Bytes(), 10000, HashAlgorithmName.SHA256);
|
||||
var key3 = keyDecryptor2.GetBytes(32);
|
||||
var keyDec2 = new Rfc2898DeriveBytes(PresharedValue, data.GetSalt1Bytes(), 10000, HashAlgorithmName.SHA256);
|
||||
var key3 = keyDec2.GetBytes(32);
|
||||
|
||||
byte[] val2 = key3[0..16];
|
||||
byte[] iv2 = key3[16..32];
|
||||
@@ -347,7 +358,16 @@ namespace EpinelPS.Data
|
||||
var targetFile = await AssetDownloadUtil.DownloadOrGetFileAsync(GameConfig.Root.StaticData.Url, CancellationToken.None);
|
||||
if (targetFile == null) throw new Exception("static data download fail");
|
||||
|
||||
_instance = new(targetFile);
|
||||
if (string.IsNullOrEmpty(GameConfig.Root.StaticDataMpk.Url))
|
||||
{
|
||||
_instance = new(targetFile, "");
|
||||
return;
|
||||
}
|
||||
|
||||
var targetFile2 = await AssetDownloadUtil.DownloadOrGetFileAsync(GameConfig.Root.StaticDataMpk.Url, CancellationToken.None);
|
||||
if (targetFile2 == null) throw new Exception("static data download fail");
|
||||
|
||||
_instance = new(targetFile, targetFile2);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace EpinelPS.LobbyServer.LobbyUser
|
||||
response.OutpostBattleLevel = user.OutpostBattleLevel;
|
||||
response.OutpostBattleTime = new NetOutpostBattleTime() { MaxBattleTime = 864000000000, MaxOverBattleTime = 12096000000000, BattleTime = battleTimeMs };
|
||||
|
||||
response.JukeboxV2 = new NetUserJukeboxDataV2() { CommandBgm = new NetJukeboxBgm() { JukeboxTableId = user.CommanderMusic.TableId, Type = NetJukeboxBgmType.JukeboxTableId, Location = NetJukeboxLocation.CommanderRoom } };
|
||||
response.Jukeboxv2 = new NetUserJukeboxDataV2() { CommandBgm = new NetJukeboxBgm() { JukeboxTableId = user.CommanderMusic.TableId, Type = NetJukeboxBgmType.JukeboxTableId, Location = NetJukeboxLocation.CommanderRoom } };
|
||||
|
||||
|
||||
|
||||
|
||||
29
EpinelPS/LobbyServer/Misc/GetStaticDataPackNew.cs
Normal file
29
EpinelPS/LobbyServer/Misc/GetStaticDataPackNew.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using EpinelPS.Data;
|
||||
using EpinelPS.Utils;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace EpinelPS.LobbyServer.Misc
|
||||
{
|
||||
[PacketPath("/get-static-data-pack-info")]
|
||||
public class GetStaticDataPackNew : LobbyMsgHandler
|
||||
{
|
||||
protected override async Task HandleAsync()
|
||||
{
|
||||
var req = await ReadData<ReqStaticDataPackInfoV2>();
|
||||
|
||||
Console.WriteLine("Requesting " + req.Type);
|
||||
|
||||
StaticData data = req.Type == StaticDataPackType.Mpk ? GameConfig.Root.StaticDataMpk : GameConfig.Root.StaticData;
|
||||
|
||||
var r = new ResStaticDataPackInfoV2();
|
||||
r.Url = data.Url;
|
||||
r.Version = data.Version;
|
||||
r.Size = req.Type == StaticDataPackType.Mpk ? GameData.Instance.MpkSize : GameData.Instance.Size;
|
||||
r.Sha256Sum = ByteString.CopyFrom(req.Type == StaticDataPackType.Mpk ? GameData.Instance.MpkHash : GameData.Instance.Sha256Hash);
|
||||
r.Salt1 = ByteString.CopyFrom(Convert.FromBase64String(data.Salt1));
|
||||
r.Salt2 = ByteString.CopyFrom(Convert.FromBase64String(data.Salt2));
|
||||
|
||||
await WriteDataAsync(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace EpinelPS.LobbyServer.Outpost
|
||||
var response = new ResGetOutpostData
|
||||
{
|
||||
OutpostBattleLevel = user.OutpostBattleLevel,
|
||||
JukeboxV2 = new NetUserJukeboxDataV2() { CommandBgm = new() { Type = NetJukeboxBgmType.JukeboxTableId, JukeboxTableId = user.CommanderMusic.TableId } }
|
||||
Jukeboxv2 = new NetUserJukeboxDataV2() { CommandBgm = new() { Type = NetJukeboxBgmType.JukeboxTableId, JukeboxTableId = user.CommanderMusic.TableId } }
|
||||
};
|
||||
|
||||
// TODO: do not hard code this!
|
||||
@@ -32,7 +32,7 @@ namespace EpinelPS.LobbyServer.Outpost
|
||||
var jukeboxIds = GameData.Instance.jukeboxListDataRecords.Keys.ToList();
|
||||
|
||||
// Update response lists with the IDs
|
||||
response.JukeboxV2.JukeboxTableIds.AddRange(jukeboxIds);
|
||||
response.Jukeboxv2.JukeboxTableIds.AddRange(jukeboxIds);
|
||||
|
||||
response.OutpostBattleLevel = user.OutpostBattleLevel;
|
||||
response.OutpostBattleTime = new NetOutpostBattleTime() { MaxBattleTime = 864000000000, MaxOverBattleTime = 12096000000000, BattleTime = battleTimeMs, OverBattleTime = overBattleTime };
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -393,14 +393,27 @@ namespace EpinelPS.Utils
|
||||
return new RunCmdResponse() { error = "failed to get real server ip, check internet connection" };
|
||||
|
||||
// Get latest static data info from server
|
||||
ResStaticDataPackInfo? staticData = await FetchProtobuf<ResStaticDataPackInfo>(staticDataUrl);
|
||||
ResStaticDataPackInfo? staticData = await FetchProtobuf<ResStaticDataPackInfo, ReqStaticDataPackInfo>(staticDataUrl);
|
||||
if (staticData == null)
|
||||
{
|
||||
Logging.WriteLine("failed to fetch static data", LogType.Error);
|
||||
return new RunCmdResponse() { error = "failed to fetch static data" };
|
||||
}
|
||||
|
||||
ResGetResourceHosts2? resources = await FetchProtobuf<ResGetResourceHosts2>(resourcesUrl);
|
||||
// Get latest static data info from server
|
||||
ResStaticDataPackInfoV2? staticData2 = await FetchProtobuf<ResStaticDataPackInfoV2, ReqStaticDataPackInfoV2>(staticDataUrl.Replace("staticdatapack", "get-static-data-pack-info"),
|
||||
new ReqStaticDataPackInfoV2()
|
||||
{
|
||||
Type = StaticDataPackType.Mpk
|
||||
});
|
||||
if (staticData2 == null)
|
||||
{
|
||||
Logging.WriteLine("failed to fetch static data (2)", LogType.Error);
|
||||
return new RunCmdResponse() { error = "failed to fetch static data (2)" };
|
||||
}
|
||||
|
||||
|
||||
ResGetResourceHosts2? resources = await FetchProtobuf<ResGetResourceHosts2, ReqGetResourceHosts2>(resourcesUrl);
|
||||
if (resources == null)
|
||||
{
|
||||
Logging.WriteLine("failed to fetch resource data", LogType.Error);
|
||||
@@ -412,14 +425,31 @@ namespace EpinelPS.Utils
|
||||
GameConfig.Root.StaticData.Salt2 = staticData.Salt2.ToBase64();
|
||||
GameConfig.Root.StaticData.Version = staticData.Version;
|
||||
GameConfig.Root.StaticData.Url = staticData.Url;
|
||||
|
||||
GameConfig.Root.StaticDataMpk.Salt1 = staticData2.Salt1.ToBase64();
|
||||
GameConfig.Root.StaticDataMpk.Salt2 = staticData2.Salt2.ToBase64();
|
||||
GameConfig.Root.StaticDataMpk.Version = staticData2.Version;
|
||||
GameConfig.Root.StaticDataMpk.Url = staticData2.Url;
|
||||
GameConfig.Save();
|
||||
|
||||
return RunCmdResponse.OK;
|
||||
}
|
||||
|
||||
private static async Task<T?> FetchProtobuf<T>(string url) where T : IMessage, new()
|
||||
private static async Task<T?> FetchProtobuf<T, I>(string url, IMessage? input = null) where T : IMessage, new() where I : IMessage, new()
|
||||
{
|
||||
ByteArrayContent staticDataContent = new([]);
|
||||
byte[] inputBytes = [];
|
||||
|
||||
if(input != null)
|
||||
{
|
||||
using MemoryStream ms = new();
|
||||
CodedOutputStream stream = new CodedOutputStream(ms);
|
||||
input.WriteTo(stream);
|
||||
stream.Flush();
|
||||
|
||||
inputBytes = ms.ToArray();
|
||||
}
|
||||
|
||||
ByteArrayContent staticDataContent = new(inputBytes);
|
||||
client.DefaultRequestHeaders.Host = serverUrl;
|
||||
staticDataContent.Headers.Add("Content-Type", "application/octet-stream+protobuf");
|
||||
connectingServer = serverUrl;
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace EpinelPS.Utils
|
||||
public class GameConfigRoot
|
||||
{
|
||||
public StaticData StaticData { get; set; } = new();
|
||||
public StaticData StaticDataMpk { get; set; } = new();
|
||||
public string ResourceBaseURL { get; set; } = "";
|
||||
public string GameMinVer { get; set; } = "";
|
||||
public string GameMaxVer { get; set; } = "";
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
"Salt1": "5prM5DL0RWmFHRBQEdNUkHjKrsU8wJGUcEjVIzTgR/c=",
|
||||
"Salt2": "B+UfKdkD8k00OcdtwkcoEkqUSrHkKq34Mq+V0tmsmA8="
|
||||
},
|
||||
"StaticDataMpk": {
|
||||
"Url": "https://cloud.nikke-kr.com/prdenv/135-c05aac789a/staticdata/data/qa-250717-07b/419667/mpk/StaticData.pack",
|
||||
"Version": "data/qa-250717-07b/419667",
|
||||
"Salt1": "91x3VgX73cZjR0U8/C98u+VKrhhy4Uhp47/mEND+/RA=",
|
||||
"Salt2": "2kFbbkNPbHU41TF1/ZRzAfVLWHUbBpm9mOnRCXF7+YI="
|
||||
},
|
||||
"ResourceBaseURL": "https://cloud.nikke-kr.com/prdenv/135-bd156d2b15/{Platform}",
|
||||
"GameMinVer": "100.0.1",
|
||||
"GameMaxVer": "150.0.2",
|
||||
|
||||
Reference in New Issue
Block a user