From f0b13ed13458883d35369cff2c76275ff1ab404a Mon Sep 17 00:00:00 2001 From: Mikhail Date: Tue, 24 Dec 2024 14:19:43 -0500 Subject: [PATCH] Match behavior of official server better --- EpinelPS/Database/JsonDb.cs | 7 +++++ .../LobbyServer/ContentsOpen/GetUnlocked.cs | 27 ++++++++++++++++++- EpinelPS/LobbyServer/LobbyMsgHandler.cs | 17 +++++++++++- .../LobbyServer/Wallet/WalletRefreshCharge.cs | 8 +++--- EpinelPS/Utils/NetUtils.cs | 6 +++++ EpinelPS/Utils/PacketDecryption.cs | 6 +++-- EpinelPS/Utils/RewardUtils.cs | 21 +++++++++++++-- 7 files changed, 83 insertions(+), 9 deletions(-) diff --git a/EpinelPS/Database/JsonDb.cs b/EpinelPS/Database/JsonDb.cs index 2bc7dc5..f0d8393 100644 --- a/EpinelPS/Database/JsonDb.cs +++ b/EpinelPS/Database/JsonDb.cs @@ -131,6 +131,13 @@ namespace EpinelPS.Database { public bool ButtonAnimationPlayed = false; public bool PopupAnimationPlayed = false; + + public UnlockData() {} + public UnlockData(bool button, bool popup) + { + ButtonAnimationPlayed = button; + PopupAnimationPlayed = popup; + } } public class MogMinigameInfo diff --git a/EpinelPS/LobbyServer/ContentsOpen/GetUnlocked.cs b/EpinelPS/LobbyServer/ContentsOpen/GetUnlocked.cs index 3c173fe..519c586 100644 --- a/EpinelPS/LobbyServer/ContentsOpen/GetUnlocked.cs +++ b/EpinelPS/LobbyServer/ContentsOpen/GetUnlocked.cs @@ -1,3 +1,4 @@ +using EpinelPS.Database; using EpinelPS.Utils; namespace EpinelPS.LobbyServer.ContentsOpen @@ -10,9 +11,33 @@ namespace EpinelPS.LobbyServer.ContentsOpen var req = await ReadData(); var user = GetUser(); + // This request is used for showing the "Collection Item Unlocked" Popup and button unlock animation + var response = new ResGetContentsOpenUnlockInfo(); - // This request is used for showing the "Collection Item Unlocked" Popup and button unlock animation + if (user.ContentsOpenUnlocked.Count == 0) + { + // These Always returned as true by official server + // Fixes "Recruitment unlocked" during chapter 0 + // TODO: Don't hardcode this, maybe its in GameData + + user.ContentsOpenUnlocked.Add(3, new(true, true)); + user.ContentsOpenUnlocked.Add(4, new(true, true)); + user.ContentsOpenUnlocked.Add(6, new(true, true)); + user.ContentsOpenUnlocked.Add(15, new(true, true)); + user.ContentsOpenUnlocked.Add(16, new(true, true)); + user.ContentsOpenUnlocked.Add(18, new(true, true)); + user.ContentsOpenUnlocked.Add(19, new(true, true)); + JsonDb.Save(); + } + response.ContentsOpenUnlockInfoList.Add(new NetContentsOpenUnlockInfo() + { + ContentsOpenTableId = 3, + IsUnlockButtonPlayed = true, + IsUnlockPopupPlayed = true, + }); + + foreach (var item in user.ContentsOpenUnlocked) { response.ContentsOpenUnlockInfoList.Add(new NetContentsOpenUnlockInfo() diff --git a/EpinelPS/LobbyServer/LobbyMsgHandler.cs b/EpinelPS/LobbyServer/LobbyMsgHandler.cs index 40203e9..971d473 100644 --- a/EpinelPS/LobbyServer/LobbyMsgHandler.cs +++ b/EpinelPS/LobbyServer/LobbyMsgHandler.cs @@ -56,8 +56,18 @@ namespace EpinelPS.LobbyServer protected abstract Task HandleAsync(); + + private void PrintMessage(T data) where T : IMessage, new() + { + var str = (string)data.GetType().InvokeMember("ToString", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod, null, data, null); + Console.WriteLine(str); + } protected async Task WriteDataAsync(T data) where T : IMessage, new() { + Console.WriteLine("Writing " + data.GetType().Name); + PrintMessage(data); + Console.WriteLine(); + if (ctx == null) { var ms = new MemoryStream(); @@ -71,7 +81,8 @@ namespace EpinelPS.LobbyServer { ctx.Response.ContentType = "application/octet-stream+protobuf"; ctx.Response.ContentLength = data.CalculateSize(); - bool encrypted = false; + bool encrypted = ctx.Request.Headers.ContentEncoding.Contains("enc"); + encrypted = false; //TODO implement, although client does not complain var responseBytes = encrypted ? new MemoryStream() : ctx.Response.Body; var x = new CodedOutputStream(responseBytes); data.WriteTo(x); @@ -102,6 +113,10 @@ namespace EpinelPS.LobbyServer T msg = new(); msg.MergeFrom(bin.Contents); + Console.WriteLine("Reading " + msg.GetType().Name); + PrintMessage(msg); + Console.WriteLine(); + UserId = bin.UserId; UsedAuthToken = bin.UsedAuthToken; diff --git a/EpinelPS/LobbyServer/Wallet/WalletRefreshCharge.cs b/EpinelPS/LobbyServer/Wallet/WalletRefreshCharge.cs index dec1d0b..356d240 100644 --- a/EpinelPS/LobbyServer/Wallet/WalletRefreshCharge.cs +++ b/EpinelPS/LobbyServer/Wallet/WalletRefreshCharge.cs @@ -10,9 +10,11 @@ namespace EpinelPS.LobbyServer.Wallet var req = await ReadData(); var user = GetUser(); - var response = new ResRefreshChargeCurrencyData(); - response.FreeCash = new(); - response.ChargeCash = new(); + ResRefreshChargeCurrencyData response = new() + { + FreeCash = new() { Type = (int)CurrencyType.FreeCash }, + ChargeCash = new() { Type = (int)CurrencyType.ChargeCash } + }; foreach (var item in user.Currency) { diff --git a/EpinelPS/Utils/NetUtils.cs b/EpinelPS/Utils/NetUtils.cs index b94ac88..8290467 100644 --- a/EpinelPS/Utils/NetUtils.cs +++ b/EpinelPS/Utils/NetUtils.cs @@ -126,6 +126,12 @@ namespace EpinelPS.Utils items.Add(item); } + foreach (var item in reward.UserItems) + { + // TODO: do these need to be combined? + result.UserItems.Add(item); + } + foreach (var c in reward.Character) { Console.WriteLine("MergeRewards - TODO Character"); diff --git a/EpinelPS/Utils/PacketDecryption.cs b/EpinelPS/Utils/PacketDecryption.cs index 5b83ff6..df05a27 100644 --- a/EpinelPS/Utils/PacketDecryption.cs +++ b/EpinelPS/Utils/PacketDecryption.cs @@ -187,8 +187,10 @@ namespace EpinelPS.Utils // prep payload MemoryStream msm = new(); - msm.WriteByte(88); - msm.WriteByte(0); + msm.WriteByte(67); + msm.WriteByte(129); + + // TODO: write message length msm.Write(message); diff --git a/EpinelPS/Utils/RewardUtils.cs b/EpinelPS/Utils/RewardUtils.cs index 8954cf7..32f82b1 100644 --- a/EpinelPS/Utils/RewardUtils.cs +++ b/EpinelPS/Utils/RewardUtils.cs @@ -106,11 +106,20 @@ namespace EpinelPS.Utils { newItem.Count += item.reward_value; + // Tell the client the reward and its amount ret.Item.Add(new NetItemData() { Count = item.reward_value, Tid = item.reward_id, - Isn = newItem.Isn + //Isn = newItem.Isn + }); + + // Tell the client the new amount of this item + ret.UserItems.Add(new NetUserItemData() + { + Isn = newItem.Isn, + Tid = newItem.ItemType, + Count = newItem.Count }); } else @@ -127,7 +136,15 @@ namespace EpinelPS.Utils { Count = item.reward_value, Tid = item.reward_id, - Isn = id + //Isn = id + }); + + // Tell the client the new amount of this item (which is the same as user did not have item previously) + ret.UserItems.Add(new NetUserItemData() + { + Isn = id, + Tid = item.reward_id, + Count = item.reward_value }); } }