68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using PSO2SERVER.Models;
|
||
using System;
|
||
using System.Runtime.InteropServices;
|
||
using System.Text;
|
||
|
||
namespace PSO2SERVER.Protocol.Packets
|
||
{
|
||
public class SkitItemAddResponsePacket : Packet
|
||
{
|
||
// Skit name - fixed length of 0x20 bytes (32 bytes).
|
||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x20)]
|
||
public byte[] skit_name;
|
||
|
||
// Unknown field (u32)
|
||
public uint unk;
|
||
|
||
// 默认构造函数
|
||
public SkitItemAddResponsePacket()
|
||
{
|
||
// 默认情况下,skit_name 初始化为空的字节数组
|
||
skit_name = new byte[0x20];
|
||
}
|
||
|
||
// 带参数的构造函数,方便直接初始化字段
|
||
public SkitItemAddResponsePacket(string skitName, uint unkValue)
|
||
{
|
||
// 初始化 skit_name 字段为 32 字节
|
||
skit_name = new byte[0x20];
|
||
// 将字符串转换为字节数组并填充到 skit_name 中
|
||
byte[] nameBytes = Encoding.ASCII.GetBytes(skitName);
|
||
Array.Copy(nameBytes, skit_name, Math.Min(nameBytes.Length, 0x20));
|
||
// 设置 unk 字段的值
|
||
unk = unkValue;
|
||
}
|
||
|
||
// 获取 skit_name 字段作为字符串,去除 null 字符
|
||
public string GetSkitName()
|
||
{
|
||
return Encoding.ASCII.GetString(skit_name).TrimEnd('\0');
|
||
}
|
||
|
||
#region implemented abstract members of Packet
|
||
|
||
// 构建数据包的方法
|
||
public override byte[] Build()
|
||
{
|
||
var pkt = new PacketWriter();
|
||
|
||
// 写入 skit_name 字段
|
||
pkt.Write(skit_name, 0, skit_name.Length);
|
||
|
||
// 写入 unk 字段
|
||
pkt.Write(unk);
|
||
|
||
// 返回构建好的字节数组
|
||
return pkt.ToArray();
|
||
}
|
||
|
||
// 获取数据包头
|
||
public override PacketHeader GetHeader()
|
||
{
|
||
return new PacketHeader(0x23, 0x0C, PacketFlags.None);
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|