0B09尝试解析

This commit is contained in:
Longfeng Qin 2024-11-26 00:07:24 +08:00
parent b446a4a8ad
commit da74671a48
6 changed files with 140 additions and 18 deletions

View File

@ -228,8 +228,11 @@ namespace PSO2SERVER
handler.HandlePacket(this, flags1, packet, 0, size);
else
{
Logger.WriteWarning("[<--未解析] 0x{0:X2} - 0x{1:X2} (UNK) (Flags {2}) ({3} 字节)", typeA,
//Logger.WriteWarning("[<--未解析] 0x{0:X2} - 0x{1:X2} (UNK) (Flags {2}) ({3} 字节)", typeA,
// typeB, (PacketFlags)flags1, size);
var info = string.Format("[<--未解析] 0x{0:X2} - 0x{1:X2} (UNK) (Flags {2}) ({3} 字节)", typeA,
typeB, (PacketFlags)flags1, size);
Logger.WriteUnkHex(info, packet);
LogUnkClientPacket(typeA, typeB, flags1, flags2, packet);
}

View File

@ -78,6 +78,65 @@ namespace PSO2SERVER
AddLine(ConsoleColor.Red, text);
}
public static void WriteUnkHex(string text, byte[] array)
{
AddLine(ConsoleColor.Red, text);
// Calculate lines
var lines = 0;
for (var i = 0; i < array.Length; i++)
if ((i % 16) == 0)
lines++;
for (var i = 0; i < lines; i++)
{
var hexString = string.Empty;
// Address
hexString += string.Format("{0:X8} ", i * 16);
// Bytes
for (var j = 0; j < 16; j++)
{
if (j + (i * 16) >= array.Length)
break;
// Append the hex byte with an extra space for every 8 bytes
if (j % 8 == 0 && j > 0)
hexString += ' ';
hexString += string.Format("{0:X2} ", array[j + (i * 16)]);
}
// Spacing
while (hexString.Length < 16 * 4)
hexString += ' ';
// ASCII
for (var j = 0; j < 16; j++)
{
if (j + (i * 16) >= array.Length)
break;
var asciiChar = (char)array[j + (i * 16)];
if (asciiChar == (char)0x00)
asciiChar = '.';
hexString += asciiChar;
}
// Strip off unnecessary stuff
hexString = hexString.Replace('\a', ' '); // Alert beeps
hexString = hexString.Replace('\n', ' '); // Newlines
hexString = hexString.Replace('\r', ' '); // Carriage returns
hexString = hexString.Replace('\\', ' '); // Escape break
AddLine(ConsoleColor.Red, hexString);
WriteFile(hexString);
}
}
public static void WriteHex(string text, byte[] array)
{
AddLine(ConsoleColor.DarkCyan, text);

View File

@ -0,0 +1,48 @@
using System;
using PSO2SERVER.Models;
using PSO2SERVER.Packets.PSOPackets;
namespace PSO2SERVER.Packets.Handlers
{
[PacketHandlerAttr(0x0B, 0x09)]
class MinimapRevealRequest : PacketHandler
{
// 定义 MinimapRevealRequestPacket 数据包结构
public struct MinimapRevealRequestPacket
{
// 未知字段32位无符号整数
public uint unk1;
// 玩家进入的区域块的ID
public uint chunk_id;
// 地图上区域块的列坐标
public uint map_column;
// 地图上区域块的行坐标
public uint map_row;
}
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
//var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
//Logger.WriteHex(info, data);
if (context.Character == null)
return;
var reader = new PacketReader(data, position, size);
// 从接收到的字节数组中解析数据到结构体
MinimapRevealRequestPacket packet = new MinimapRevealRequestPacket
{
unk1 = reader.ReadUInt32(), // 从数据包中解析unk1
chunk_id = reader.ReadUInt32(), // 从数据包中解析chunk_id
map_column = reader.ReadUInt32(), // 从数据包中解析map_column
map_row = reader.ReadUInt32() // 从数据包中解析map_row
};
// 打印解析后的数据
Logger.Write($"解析的地图数据包: unk1 = {packet.unk1}, Chunk ID = {packet.chunk_id}, Column = {packet.map_column}, Row = {packet.map_row}");
}
}
}

View File

@ -1,16 +0,0 @@
using System;
using PSO2SERVER.Models;
using PSO2SERVER.Packets.PSOPackets;
namespace PSO2SERVER.Packets.Handlers
{
//[PacketHandlerAttr(0x0B, 0x09)]
//class _0B_09_UNK : PacketHandler
//{
// public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
// {
// //var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
// //Logger.WriteHex(info, data);
// }
//}
}

View File

@ -8,6 +8,29 @@ namespace PSO2SERVER.Packets.PSOPackets
{
public class MinimapRevealPacket : Packet
{
private ObjectHeader unk1 { get; set; }
private ObjectHeader party { get; set; }
private uint zone_id { get; set; }
private byte[] unk2 { get; set; } = new byte[10];
// 构造函数,允许在创建时初始化字段
public MinimapRevealPacket(ObjectHeader unk1, ObjectHeader party, uint zone_id, byte[] unk2)
{
this.unk1 = unk1;
this.party = party;
this.zone_id = zone_id;
// 如果传入的 unk2 长度小于 10则填充剩余部分为 0
if (unk2.Length <= 10)
{
this.unk2 = unk2.Concat(new byte[10 - unk2.Length]).ToArray();
}
else
{
// 如果传入的 unk2 长度大于 10则截取前 10 字节
this.unk2 = unk2.Take(10).ToArray();
}
}
public MinimapRevealPacket()
{
@ -18,6 +41,11 @@ namespace PSO2SERVER.Packets.PSOPackets
public override byte[] Build()
{
var pkt = new PacketWriter();
pkt.WriteStruct(unk1);
pkt.WriteStruct(party);
pkt.Write(zone_id);
for (var i = 0; i < 10; i++)
pkt.Write(unk2[i]);
return pkt.ToArray();
}

View File

@ -192,7 +192,7 @@
<Compile Include="Packets\Handlers\04-ObjectHandler\04-71-MovementEndHandler.cs" />
<Compile Include="Packets\Handlers\07-ChatHandler\07-3D-UNK.cs" />
<Compile Include="Packets\Handlers\0B-QuestHandler\0B-CD-AcceptStoryQuestHandler.cs" />
<Compile Include="Packets\Handlers\0B-QuestHandler\0B-09-UNK.cs" />
<Compile Include="Packets\Handlers\0B-QuestHandler\0B-09-MinimapRevealRequest.cs" />
<Compile Include="Packets\Handlers\0B-QuestHandler\0B-15-QuestCounterAvailableHander.cs" />
<Compile Include="Packets\Handlers\0B-QuestHandler\0B-17-QuestListRequestHandler.cs" />
<Compile Include="Packets\Handlers\0B-QuestHandler\0B-19-QuestDifficultyRequestHandler.cs" />