send request get all game data

This commit is contained in:
Tungdv
2025-09-23 13:35:46 +07:00
parent f7023afcb8
commit aa81225c27
5 changed files with 172 additions and 14 deletions
Binary file not shown.
@@ -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<bool> actDone)
{
@@ -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<InventoryItem> inventoryData)
+110 -10
View File
@@ -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);
+56
View File
@@ -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