diff --git a/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll b/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll index 1314ad896c..776bc44ed8 100644 Binary files a/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll and b/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll differ diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index 67f91ff834..51dbbdb754 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -8,7 +8,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; -using UnityEditor.ShaderGraph.Internal; using UnityEngine; using UnityEngine.SceneManagement; @@ -152,10 +151,13 @@ namespace BrewMonster.Network } } - public static void RequestAllTasks(Action callback = null) + #region Task + public static void c2s_CmdGetAllData(bool byPack, bool byEquip, bool byTask) { - Instance._gameSession.c2s_CmdTaskData(0, null,0, null,0, null,0, null,0, null); + Debug.Log("[Dat]- SendCmdGetAllData"); + Instance._gameSession.c2s_SendCmdGetAllData(byPack, byEquip, byTask); } + #endregion public void LoadScene(string sceneName, LoadSceneMode mode, Action actDone) { diff --git a/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs b/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs index d4796cc350..0de98e8e0b 100644 --- a/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs +++ b/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs @@ -135,7 +135,7 @@ namespace BrewMonster.UI Logger.Log("Entered world successfully."); // Request all known packages: 0=Inventory,1=Equipment,2=Task UnityGameSession.RequestAllInventoriesAsync(() => { Logger.Log("Sent Inventory Detail Requests (all packs)"); }, 0, 1, 2); - UnityGameSession.RequestAllTasks(() => { Logger.Log("[Dat] Sent RequestAllTasks (all packs)"); }); + UnityGameSession.c2s_CmdGetAllData(true, true, false); } //private void OnInventoryReceived(List inventoryData) diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 7799702955..c74e5b3491 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -3,19 +3,20 @@ using CSNetwork; using CSNetwork.GPDataType; using CSNetwork.Protocols; using CSNetwork.Protocols.RPCData; +using PerfectWorld.Scripts.Managers; +using PerfectWorld.Scripts.Task; using System; using System.IO; +using System.Linq; +using System.Runtime.InteropServices; using System.Text; using TMPro; +using Unity.VisualScripting; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.SceneManagement; using UnityEngine.UI; using Scene = UnityEngine.SceneManagement.Scene; -using System.Runtime.InteropServices; -using Unity.VisualScripting; -using PerfectWorld.Scripts.Managers; -using PerfectWorld.Scripts.Task; public class CECHostPlayer : MonoBehaviour { @@ -199,26 +200,22 @@ public class CECHostPlayer : MonoBehaviour { Debug.LogWarning("HoangDev : ProcessMessageProcessMessageProcessMessage"); var messageId = (int)Msg.dwMsg; - Debug.LogError("Message id: " + messageId); switch (messageId) { case int value when value == EC_MsgDef.MSG_HST_CORRECTPOS: OnMsgHstCorrectPos(Msg); break; case int value when value == EC_MsgDef.MSG_HST_GOTO: OnMsgHstGoto(Msg); break; case int value when value == EC_MsgDef.MSG_HST_IVTRINFO: { - Debug.LogError("MSG_HST_IVTRINFO"); OnMsgHstIvtrInfo(Msg); break; } case int value when value == EC_MsgDef.MSG_HST_OWNITEMINFO: { - Debug.LogError("MSG_HST_OWNITEMINFO"); OnMsgHstOwnItemInfo(Msg); break; } case int value when value == EC_MsgDef.MSG_HST_TASKDATA: { - Debug.LogError("OnMsgHstTaskData"); OnMsgHstTaskData(Msg); break; } @@ -296,8 +293,111 @@ public class CECHostPlayer : MonoBehaviour int cmd = Convert.ToInt32(Msg.dwParam2); if (cmd == CommandID.TASK_DATA) { + //var data = Msg.dwParam1 as byte[]; + //cmd_task_data pCmd = new cmd_task_data(); + //int offset = 0; + + //pCmd.active_list_size = BitConverter.ToUInt32(data, offset); + //offset += 8; + //pCmd.active_list = data.Skip(offset).Take((int)pCmd.active_list_size).ToArray(); + //offset += (int)pCmd.active_list_size; + + //pCmd.finished_list_size = BitConverter.ToUInt32(data, offset); + //offset += 8; + //pCmd.finished_list = data.Skip(offset).Take((int)pCmd.finished_list_size).ToArray(); + //offset += (int)pCmd.finished_list_size; + + //pCmd.finished_time_list_size = BitConverter.ToUInt32(data, offset); + //offset += 8; + //pCmd.finished_time_list = data.Skip(offset).Take((int)pCmd.finished_time_list_size).ToArray(); + //offset += (int)pCmd.finished_time_list_size; + + //pCmd.finished_count_size = BitConverter.ToUInt32(data, offset); + //offset += 8; + //pCmd.finished_count = data.Skip(offset).Take((int)pCmd.finished_count_size).ToArray(); + //offset += (int)pCmd.finished_count_size; + + //pCmd.storage_task_size = BitConverter.ToUInt32(data, offset); + //offset += 8; + //pCmd.storage_task = data.Skip(offset).Take((int)pCmd.storage_task_size).ToArray(); + //offset += (int)pCmd.storage_task_size; + var data = Msg.dwParam1 as byte[]; - cmd_task_data pCmd = (cmd_task_data)Msg.dwParam1; + cmd_task_data pCmd = new cmd_task_data(); + int offset = 0; + + Debug.Log($"Total data length: {data?.Length ?? 0}"); + + try + { + // Active List + Debug.Log($"[Before active_list_size] offset = {offset}"); + if (offset + 4 > data.Length) throw new Exception("Not enough data for active_list_size"); + pCmd.active_list_size = BitConverter.ToUInt32(data, offset); + offset += 4; + + Debug.Log($"[active_list] start = {offset}, size = {pCmd.active_list_size}"); + if (offset + pCmd.active_list_size > data.Length) throw new Exception("Not enough data for active_list"); + pCmd.active_list = data.Skip(offset).Take((int)pCmd.active_list_size).ToArray(); + offset += (int)pCmd.active_list_size; + + // Finished List + Debug.Log($"[Before finished_list_size] offset = {offset}"); + if (offset + 4 > data.Length) throw new Exception("Not enough data for finished_list_size"); + pCmd.finished_list_size = BitConverter.ToUInt32(data, offset); + offset += 4; + + Debug.Log($"[finished_list] start = {offset}, size = {pCmd.finished_list_size}"); + if (offset + pCmd.finished_list_size > data.Length) throw new Exception("Not enough data for finished_list"); + pCmd.finished_list = data.Skip(offset).Take((int)pCmd.finished_list_size).ToArray(); + offset += (int)pCmd.finished_list_size; + + // Finished Time List + Debug.Log($"[Before finished_time_list_size] offset = {offset}"); + if (offset + 4 > data.Length) throw new Exception("Not enough data for finished_time_list_size"); + pCmd.finished_time_list_size = BitConverter.ToUInt32(data, offset); + offset += 4; + + Debug.Log($"[finished_time_list] start = {offset}, size = {pCmd.finished_time_list_size}"); + if (offset + pCmd.finished_time_list_size > data.Length) throw new Exception("Not enough data for finished_time_list"); + pCmd.finished_time_list = data.Skip(offset).Take((int)pCmd.finished_time_list_size).ToArray(); + offset += (int)pCmd.finished_time_list_size; + + // Finished Count + Debug.Log($"[Before finished_count_size] offset = {offset}"); + if (offset + 4 > data.Length) throw new Exception("Not enough data for finished_count_size"); + pCmd.finished_count_size = BitConverter.ToUInt32(data, offset); + offset += 4; + + Debug.Log($"[finished_count] start = {offset}, size = {pCmd.finished_count_size}"); + if (offset + pCmd.finished_count_size > data.Length) throw new Exception("Not enough data for finished_count"); + pCmd.finished_count = data.Skip(offset).Take((int)pCmd.finished_count_size).ToArray(); + offset += (int)pCmd.finished_count_size; + + // Storage Task + Debug.Log($"[Before storage_task_size] offset = {offset}"); + if (offset + 4 > data.Length) throw new Exception("Not enough data for storage_task_size"); + pCmd.storage_task_size = BitConverter.ToUInt32(data, offset); + offset += 4; + + Debug.Log($"[storage_task] start = {offset}, size = {pCmd.storage_task_size}"); + if (offset + pCmd.storage_task_size > data.Length) throw new Exception("Not enough data for storage_task"); + pCmd.storage_task = data.Skip(offset).Take((int)pCmd.storage_task_size).ToArray(); + offset += (int)pCmd.storage_task_size; + + Debug.Log($"Finished parsing cmd_task_data. Final offset = {offset}"); + } + catch (Exception ex) + { + Debug.LogError($"[cmd_task_data parsing failed] Exception: {ex.GetType().Name} - {ex.Message}"); + Debug.LogError($"Current offset: {offset}, data length: {data?.Length ?? 0}"); + } + + + + //IntPtr ptr = (IntPtr)Msg.dwParam1; + //cmd_task_data data = cmd_task_data.FromPointer(ptr); + //cmd_task_data pCmd; //ASSERT(pCmd); //int iActiveListSize = (int)pCmd->active_list_size; @@ -324,7 +424,7 @@ public class CECHostPlayer : MonoBehaviour //pData += sizeof(int); //void* pStorageTaskListBuf = pData; //pData += iStorageTasksListSize; - + //A3DRELEASE(m_pTaskInterface); m_pTaskInterface = new CECTaskInterface(this); diff --git a/Assets/Scripts/EC_GPDataType.cs b/Assets/Scripts/EC_GPDataType.cs index f5ec910a4c..7e0de4b22d 100644 --- a/Assets/Scripts/EC_GPDataType.cs +++ b/Assets/Scripts/EC_GPDataType.cs @@ -1,7 +1,15 @@ using CSNetwork.GPDataType; using System; +using System.Runtime.InteropServices; using UnityEngine; +struct cmd_get_all_data +{ + byte byPack; // Get detail info. flag + byte byEquip; + byte byTask; +}; + struct cmd_player_move { Vector3 vCurPos; @@ -38,6 +46,54 @@ struct cmd_task_data public uint storage_task_size; public byte[] storage_task; + + public static cmd_task_data FromPointer(IntPtr ptr) + { + // Copy enough memory into managed buffer (you can optimize this later) + int maxExpectedSize = 1024 * 10; + byte[] buffer = new byte[maxExpectedSize]; + Marshal.Copy(ptr, buffer, 0, buffer.Length); + + return FromBuffer(buffer); + } + + public static cmd_task_data FromBuffer(byte[] buffer) + { + cmd_task_data result = new cmd_task_data(); + int offset = 0; + + result.active_list_size = (uint)ReadULong(buffer, ref offset); + result.active_list = ReadBytes(buffer, ref offset, (int)result.active_list_size); + + result.finished_list_size = (uint)ReadULong(buffer, ref offset); + result.finished_list = ReadBytes(buffer, ref offset, (int)result.finished_list_size); + + result.finished_time_list_size = (uint)ReadULong(buffer, ref offset); + result.finished_time_list = ReadBytes(buffer, ref offset, (int)result.finished_time_list_size); + + result.finished_count_size = (uint)ReadULong(buffer, ref offset); + result.finished_count = ReadBytes(buffer, ref offset, (int)result.finished_count_size); + + result.storage_task_size = (uint)ReadULong(buffer, ref offset); + result.storage_task = ReadBytes(buffer, ref offset, (int)result.storage_task_size); + + return result; + } + + private static ulong ReadULong(byte[] buffer, ref int offset) + { + ulong value = BitConverter.ToUInt64(buffer, offset); + offset += 8; + return value; + } + + private static byte[] ReadBytes(byte[] buffer, ref int offset, int count) + { + byte[] result = new byte[count]; + Buffer.BlockCopy(buffer, offset, result, 0, count); + offset += count; + return result; + } }; struct cmd_task_var_data