From 391dd3d1b6071fd2cffcb87a9170c1d9875aed8f Mon Sep 17 00:00:00 2001 From: Longfeng Qin Date: Tue, 10 Dec 2024 21:54:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=83=A8=E5=88=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8C=85=E5=A4=84=E7=90=86=20=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E6=A0=8F=E7=94=9F=E6=88=90=E5=A4=84=E7=90=86=20=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E7=94=9F=E6=88=90=E5=87=BD=E6=95=B0=E8=BF=98=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=BB=A7=E7=BB=AD=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/Client.cs | 2 + Server/Json/JsonConverteres.cs | 5 +- Server/Models/FixedTypes.cs | 71 +++++++++ Server/Models/Flags.cs | 19 ++- Server/Models/ItemAttributes.cs | 32 ++-- Server/Models/PSOPalette.cs | 137 +++++++----------- .../Handlers/0F-ItemHandler/0F-28-UNK.cs | 16 ++ .../Handlers/0F-ItemHandler/0F-DA-UNK0FDA.cs | 16 ++ .../11-ClientHandler/11-3E-CharacterSpawn.cs | 2 +- .../21-00-LoadPalettesRequest.cs | 19 +++ .../21-02-FullPaletteInfoRequest.cs | 2 +- .../21-PaletteHandler/21-0A-SetDefaultPAs.cs | 52 +++++++ Server/Protocol/Handlers/34-UNK/34-72-UNK.cs | 16 ++ .../Protocol/Handlers/48-UNK/48-16-UNK4816.cs | 16 ++ .../Protocol/Handlers/49-UNK/49-00-UNK4900.cs | 16 ++ .../21-01-LoadPalettePacket.cs | 12 +- .../21-03-FullPaletteInfoPacket.cs | 4 +- .../21-0F-NewDefaultPAsPacket.cs | 14 +- .../23-06-AccountFlagsPacket.cs | 16 +- .../23-07-CharacterFlagsPacket.cs | 16 +- Server/Server.csproj | 7 + 21 files changed, 347 insertions(+), 143 deletions(-) create mode 100644 Server/Protocol/Handlers/0F-ItemHandler/0F-28-UNK.cs create mode 100644 Server/Protocol/Handlers/0F-ItemHandler/0F-DA-UNK0FDA.cs create mode 100644 Server/Protocol/Handlers/21-PaletteHandler/21-00-LoadPalettesRequest.cs create mode 100644 Server/Protocol/Handlers/21-PaletteHandler/21-0A-SetDefaultPAs.cs create mode 100644 Server/Protocol/Handlers/34-UNK/34-72-UNK.cs create mode 100644 Server/Protocol/Handlers/48-UNK/48-16-UNK4816.cs create mode 100644 Server/Protocol/Handlers/49-UNK/49-00-UNK4900.cs diff --git a/Server/Client.cs b/Server/Client.cs index 888929b..334c40e 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -69,6 +69,8 @@ namespace PSO2SERVER public uint MovementTimestamp { get; internal set; } public Party.Party currentParty; + public PSOPalette Palette { get; set; } = new PSOPalette(); + public PSOLocation CurrentLocation; public PSOLocation LastLocation; diff --git a/Server/Json/JsonConverteres.cs b/Server/Json/JsonConverteres.cs index ca7d420..358a04c 100644 --- a/Server/Json/JsonConverteres.cs +++ b/Server/Json/JsonConverteres.cs @@ -19,10 +19,7 @@ namespace PSO2SERVER.Json var fixedList = new FixedList(list.Count); // 将 list 中的元素添加到 FixedList 中 - foreach (var item in list) - { - fixedList.Add(item); - } + fixedList.SetListItem(list); return fixedList; } diff --git a/Server/Models/FixedTypes.cs b/Server/Models/FixedTypes.cs index 365a49f..2b39fcf 100644 --- a/Server/Models/FixedTypes.cs +++ b/Server/Models/FixedTypes.cs @@ -7,6 +7,8 @@ using System.Text; using System.Threading.Tasks; using System.Collections; using System.Xml.Linq; +using System.IO; +using PSO2SERVER.Protocol; namespace PSO2SERVER.Models { @@ -47,6 +49,7 @@ namespace PSO2SERVER.Models _data.Add(item); } + public void Insert(int index, T item) { if (index < 0 || index > _data.Count) @@ -57,6 +60,7 @@ namespace PSO2SERVER.Models _data.Insert(index, item); } + public void RemoveAt(int index) { if (index < 0 || index >= _data.Count) @@ -72,6 +76,73 @@ namespace PSO2SERVER.Models _data.RemoveAt(_data.Count - 1); } + + public void SetItem(int index, T value) + { + // 如果 index 超出当前长度,但没有超出最大容量,进行扩展 + if (index >= _data.Count) + { + // 如果 index 没有超过最大容量 + if (index < _capacity) + { + // 扩展 _data 列表,填充默认值 + while (_data.Count <= index && _data.Count < _capacity) + { + _data.Add(default(T)); + } + } + else + { + throw new ArgumentOutOfRangeException(nameof(index), "索引超出最大容量."); + } + } + + // 赋值 + _data[index] = value; + } + + public void SetListItem(List value) + { + // 截取最大容量的值,如果传入的值超过了 _capacity + if (value.Count > _capacity) + { + value = value.Take(_capacity).ToList(); + } + + // 更新已有的元素 + for (var i = 0; i < _data.Count && i < value.Count; i++) + { + _data[i] = value[i]; + } + + // 如果 value 的长度超过当前 _data 长度并且未超过最大容量,则扩展 _data 长度 + if (value.Count > _data.Count) + { + // 计算要增加的元素数量 + int elementsToAdd = value.Count - _data.Count; + + // 添加元素,确保不超过最大容量 + for (var i = 0; i < elementsToAdd && _data.Count < _capacity; i++) + { + _data.Add(default(T)); // 填充默认值 + } + + // 将传入的 value 中剩余的元素(超出 _data 长度部分)复制到 _data + for (var i = _data.Count; i < value.Count; i++) + { + _data[i] = value[i]; + } + } + } + + public void SetAll(T newValue) + { + for (int i = 0; i < _data.Count; i++) + { + _data[i] = newValue; + } + } + public void Clear() { _data.Clear(); diff --git a/Server/Models/Flags.cs b/Server/Models/Flags.cs index aca7807..29abb2f 100644 --- a/Server/Models/Flags.cs +++ b/Server/Models/Flags.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Security.AccessControl; using PSO2SERVER.Protocol.Packets; @@ -57,20 +58,18 @@ namespace PSO2SERVER.Models public AccountFlagsPacket ToAccountFlags() { - return new AccountFlagsPacket - { - Flags = new List(flags), - Params = new List(paramsList) - }; + var aflags = new AccountFlagsPacket(); + aflags.Flags.SetListItem(flags); + aflags.Params.SetListItem(paramsList); + return aflags; } public CharacterFlagsPacket ToCharFlags() { - return new CharacterFlagsPacket - { - Flags = new List(flags), - Params = new List(paramsList) - }; + var cflags = new CharacterFlagsPacket(); + cflags.Flags.SetListItem(flags); + cflags.Params.SetListItem(paramsList); + return cflags; } private static byte SetBit(byte byteValue, byte index, byte val) diff --git a/Server/Models/ItemAttributes.cs b/Server/Models/ItemAttributes.cs index 6871fbc..c291525 100644 --- a/Server/Models/ItemAttributes.cs +++ b/Server/Models/ItemAttributes.cs @@ -258,7 +258,7 @@ namespace PSO2SERVER.Models [JsonProperty("unk8")] [JsonConverter(typeof(FixedListConverter))] - public FixedList Unk8 { get; set; } = new FixedList(0x04); + public FixedList Unk8 { get; set; } = new FixedList(0x04, 0); // Equipable races [JsonProperty("race")] @@ -584,62 +584,62 @@ namespace PSO2SERVER.Models public class Data7 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x38); + public FixedList unk { get; set; } = new FixedList(0x38, 0); } public class Data8 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x10); + public FixedList unk { get; set; } = new FixedList(0x10, 0); } public class Data9 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x3C); + public FixedList unk { get; set; } = new FixedList(0x3C, 0); } public class Data10 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x24); + public FixedList unk { get; set; } = new FixedList(0x24, 0); } public class Data11 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x10); + public FixedList unk { get; set; } = new FixedList(0x10, 0); } public class Data12 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x24); + public FixedList unk { get; set; } = new FixedList(0x24, 0); } public class Data13 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x50); + public FixedList unk { get; set; } = new FixedList(0x50, 0); } public class Data14 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x7C); + public FixedList unk { get; set; } = new FixedList(0x7C, 0); } public class Data15 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x10); + public FixedList unk { get; set; } = new FixedList(0x10, 0); } public class Data16 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x12); + public FixedList unk { get; set; } = new FixedList(0x12, 0); } public class Data17 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x5A); + public FixedList unk { get; set; } = new FixedList(0x5A, 0); } public class Data18 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x08); + public FixedList unk { get; set; } = new FixedList(0x08, 0); } public class ShortData { @@ -648,17 +648,17 @@ namespace PSO2SERVER.Models public class Data19 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x54); + public FixedList unk { get; set; } = new FixedList(0x54, 0); } public class Data19Vita { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x2C); + public FixedList unk { get; set; } = new FixedList(0x2C, 0); } public class Data20 { [JsonConverter(typeof(FixedListConverter))] - public FixedList unk { get; set; } = new FixedList(0x1C); + public FixedList unk { get; set; } = new FixedList(0x1C, 0); } public struct GenderDmg diff --git a/Server/Models/PSOPalette.cs b/Server/Models/PSOPalette.cs index c69ab97..3f214c0 100644 --- a/Server/Models/PSOPalette.cs +++ b/Server/Models/PSOPalette.cs @@ -16,7 +16,7 @@ namespace PSO2SERVER.Models [JsonProperty("items")] [JsonConverter(typeof(FixedListConverter))] // Items in the subpalette. - public FixedList Items { get; set; } = new FixedList(0x0C); + public FixedList Items { get; set; } = new FixedList(0x0C, new PalettePA()); // 从字节流中读取数据 public void ReadFromStream(PacketReader reader) @@ -27,7 +27,7 @@ namespace PSO2SERVER.Models // 读取每个 PalettePA var palettePA = new PalettePA(); palettePA.ReadFromStream(reader); - Items.Add(palettePA); // 将读取的数据存储到 FixedList 中 + Items.SetItem(i, palettePA); } } @@ -58,7 +58,6 @@ namespace PSO2SERVER.Models public PalettePA() { - } public PalettePA(byte id, byte category, byte unk, byte level) @@ -88,14 +87,14 @@ namespace PSO2SERVER.Models public class WeaponPalette { - public ulong Uuid { get; set; } - public uint Unk1 { get; set; } - public PalettePA Unk2 { get; set; } - public PalettePA Unk3 { get; set; } - public PalettePA Unk4 { get; set; } + public ulong Uuid { get; set; } = 0; + public uint Unk1 { get; set; } = 0; + public PalettePA Unk2 { get; set; } = new PalettePA(); + public PalettePA Unk3 { get; set; } = new PalettePA(); + public PalettePA Unk4 { get; set; } = new PalettePA(); public uint[] Unk { get; set; } = new uint[3]; - public uint PetId { get; set; } - public PalettePA[] Skills { get; set; } = new PalettePA[6]; + public uint PetId { get; set; } = 0; + public List Skills { get; set; } = new List(6); public WeaponPalette() { @@ -116,9 +115,8 @@ namespace PSO2SERVER.Models Unk[i] = reader.ReadUInt32(); } PetId = reader.ReadUInt32(); - for (int i = 0; i < Skills.Length; i++) + for (int i = 0; i < Skills.Count; i++) { - Skills[i] = new PalettePA(); Skills[i].ReadFromStream(reader); } } @@ -144,90 +142,59 @@ namespace PSO2SERVER.Models public class PSOPalette { - public struct Palette + public uint CurPalette { get; set; } = 0; + public uint CurSubpalette { get; set; } = 0; + public uint CurBook { get; set; } = 0; + public FixedList Palettes { get; set; } = new FixedList(6, new WeaponPalette()); + public FixedList Subpalettes { get; set; } = new FixedList(6, new SubPalette()); + public List DefaultPas { get; set; } = new List(); + + public PSOPalette() { } + + public void ReadFromStream(PacketReader reader) { - public uint CurPalette; - public uint CurSubpalette; - public uint CurBook; - public WeaponPalette[] Palettes; - public SubPalette[] Subpalettes; - public List DefaultPas; + CurPalette = reader.ReadUInt32(); + CurSubpalette = reader.ReadUInt32(); + CurBook = reader.ReadUInt32(); - // 构造函数 - public static Palette Create() + for (int i = 0; i < Palettes.Length; i++) { - Palette palette = new Palette - { - CurPalette = 0, - CurSubpalette = 0, - CurBook = 0, - Palettes = new WeaponPalette[6], - Subpalettes = new SubPalette[6], - DefaultPas = new List() - }; - - // 初始化 Palettes - for (int i = 0; i < palette.Palettes.Length; i++) - { - palette.Palettes[i] = new WeaponPalette(); - } - - // 初始化 Subpalettes(根据需要可以进行自定义初始化) - for (int i = 0; i < palette.Subpalettes.Length; i++) - { - palette.Subpalettes[i] = new SubPalette(); // 这里可以根据需要进行初始化 - } - - return palette; + Palettes[i].ReadFromStream(reader); } - public void ReadFromStream(PacketReader reader) + for (int i = 0; i < Subpalettes.Length; i++) { - CurPalette = reader.ReadUInt32(); - CurSubpalette = reader.ReadUInt32(); - CurBook = reader.ReadUInt32(); - - for (int i = 0; i < Palettes.Length; i++) - { - Palettes[i].ReadFromStream(reader); - } - - for (int i = 0; i < Subpalettes.Length; i++) - { - Subpalettes[i].ReadFromStream(reader); - } - - int defaultPasCount = reader.ReadInt32(); // 假设先读入数量 - DefaultPas.Clear(); - for (int i = 0; i < defaultPasCount; i++) - { - DefaultPas.Add(reader.ReadUInt32()); - } + Subpalettes[i].ReadFromStream(reader); } - public void WriteToStream(PacketWriter writer) + int defaultPasCount = reader.ReadInt32(); // 假设先读入数量 + DefaultPas.Clear(); + for (int i = 0; i < defaultPasCount; i++) { - writer.Write(CurPalette); - writer.Write(CurSubpalette); - writer.Write(CurBook); - - for (int i = 0; i < Palettes.Length; i++) - { - Palettes[i].WriteToStream(writer); - } - - for (int i = 0; i < Subpalettes.Length; i++) - { - Subpalettes[i].WriteToStream(writer); - } - - writer.Write(DefaultPas.Count); - foreach (var value in DefaultPas) - { - writer.Write(value); - } + DefaultPas.Add(reader.ReadUInt32()); } } + public void WriteToStream(PacketWriter writer) + { + writer.Write(CurPalette); + writer.Write(CurSubpalette); + writer.Write(CurBook); + + for (int i = 0; i < Palettes.Length; i++) + { + Palettes[i].WriteToStream(writer); + } + + for (int i = 0; i < Subpalettes.Length; i++) + { + Subpalettes[i].WriteToStream(writer); + } + + foreach (var value in DefaultPas) + { + writer.Write(value); + } + } } } diff --git a/Server/Protocol/Handlers/0F-ItemHandler/0F-28-UNK.cs b/Server/Protocol/Handlers/0F-ItemHandler/0F-28-UNK.cs new file mode 100644 index 0000000..6e6803d --- /dev/null +++ b/Server/Protocol/Handlers/0F-ItemHandler/0F-28-UNK.cs @@ -0,0 +1,16 @@ +using System; +using PSO2SERVER.Models; +using PSO2SERVER.Protocol.Packets; + +namespace PSO2SERVER.Protocol.Handlers +{ + [PacketHandlerAttr(0x0F, 0x28)] + public class _0F_28_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); + } + } +} diff --git a/Server/Protocol/Handlers/0F-ItemHandler/0F-DA-UNK0FDA.cs b/Server/Protocol/Handlers/0F-ItemHandler/0F-DA-UNK0FDA.cs new file mode 100644 index 0000000..2921842 --- /dev/null +++ b/Server/Protocol/Handlers/0F-ItemHandler/0F-DA-UNK0FDA.cs @@ -0,0 +1,16 @@ +using System; +using PSO2SERVER.Models; +using PSO2SERVER.Protocol.Packets; + +namespace PSO2SERVER.Protocol.Handlers +{ + [PacketHandlerAttr(0x0F, 0xDA)] + public class _0F_DA_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); + } + } +} diff --git a/Server/Protocol/Handlers/11-ClientHandler/11-3E-CharacterSpawn.cs b/Server/Protocol/Handlers/11-ClientHandler/11-3E-CharacterSpawn.cs index 6acdfd2..760ad35 100644 --- a/Server/Protocol/Handlers/11-ClientHandler/11-3E-CharacterSpawn.cs +++ b/Server/Protocol/Handlers/11-ClientHandler/11-3E-CharacterSpawn.cs @@ -47,7 +47,7 @@ namespace PSO2SERVER.Protocol.Handlers //context.SendPacket(File.ReadAllBytes("testbed/237.23-7.210.189.208.30.bin")); // 先给一个空的 Palette - context.SendPacket(new LoadPalettePacket()); + context.SendPacket(new LoadPalettePacket(context.Palette)); // memset packet - Enables menus TODO // Also holds event items and likely other stuff too diff --git a/Server/Protocol/Handlers/21-PaletteHandler/21-00-LoadPalettesRequest.cs b/Server/Protocol/Handlers/21-PaletteHandler/21-00-LoadPalettesRequest.cs new file mode 100644 index 0000000..1ec387d --- /dev/null +++ b/Server/Protocol/Handlers/21-PaletteHandler/21-00-LoadPalettesRequest.cs @@ -0,0 +1,19 @@ +using System; +using PSO2SERVER.Models; +using PSO2SERVER.Protocol.Packets; + +namespace PSO2SERVER.Protocol.Handlers +{ + [PacketHandlerAttr(0x21, 0x00)] + public class LoadPalettesRequest : 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); + + //TODO + context.SendPacket(new LoadPalettePacket(context.Palette)); + } + } +} diff --git a/Server/Protocol/Handlers/21-PaletteHandler/21-02-FullPaletteInfoRequest.cs b/Server/Protocol/Handlers/21-PaletteHandler/21-02-FullPaletteInfoRequest.cs index 2ccffa5..83cf90d 100644 --- a/Server/Protocol/Handlers/21-PaletteHandler/21-02-FullPaletteInfoRequest.cs +++ b/Server/Protocol/Handlers/21-PaletteHandler/21-02-FullPaletteInfoRequest.cs @@ -12,7 +12,7 @@ namespace PSO2SERVER.Protocol.Handlers var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length); Logger.WriteHex(info, data); - var Palette = PSOPalette.Palette.Create(); + var Palette = new PSOPalette(); context.SendPacket(new FullPaletteInfoPacket(Palette)); } diff --git a/Server/Protocol/Handlers/21-PaletteHandler/21-0A-SetDefaultPAs.cs b/Server/Protocol/Handlers/21-PaletteHandler/21-0A-SetDefaultPAs.cs new file mode 100644 index 0000000..347bb04 --- /dev/null +++ b/Server/Protocol/Handlers/21-PaletteHandler/21-0A-SetDefaultPAs.cs @@ -0,0 +1,52 @@ +using System; +using PSO2SERVER.Models; +using PSO2SERVER.Protocol.Packets; + +namespace PSO2SERVER.Protocol.Handlers +{ + [PacketHandlerAttr(0x21, 0x0A)] + public class SetDefaultPAs : PacketHandler + { + public class SetDefaultPAsPacket + { + public FixedList Default { get; set; } = new FixedList(0x1A0, 0); + + // 从数据流中读取数据并填充到 Default 列表 + public static SetDefaultPAsPacket ReadFromStream(PacketReader reader) + { + // 假设 Default 是该类的静态字段,因此直接访问 + SetDefaultPAsPacket packet = new SetDefaultPAsPacket(); + + // 从流中读取 uint 类型的数据并填充到 Default 列表 + for (var i = 0; i < (int)packet.Default.Capacity; i++) + { + packet.Default[i] = reader.ReadUInt32(); // 读取 uint 值并存入 Default 列表 + } + + return packet; + } + + // 将 Default 列表的数据写入到数据流 + public void WriteToStream(PacketWriter writer) + { + // 将 Default 列表中的每个 uint 元素写入数据流 + for (var i = 0; i < (int)Default.Capacity; i++) + { + writer.Write(Default[i]); // 写入 uint 值 + } + } + } + + 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); + + var reader = new PacketReader(data, position, size); + var packet = SetDefaultPAsPacket.ReadFromStream(reader); + + + context.SendPacket(new NewDefaultPAsPacket(packet.Default)); + } + } +} \ No newline at end of file diff --git a/Server/Protocol/Handlers/34-UNK/34-72-UNK.cs b/Server/Protocol/Handlers/34-UNK/34-72-UNK.cs new file mode 100644 index 0000000..ca993b0 --- /dev/null +++ b/Server/Protocol/Handlers/34-UNK/34-72-UNK.cs @@ -0,0 +1,16 @@ +using System; +using PSO2SERVER.Models; +using PSO2SERVER.Protocol.Packets; + +namespace PSO2SERVER.Protocol.Handlers +{ + [PacketHandlerAttr(0x34, 0x72)] + public class _34_72_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); + } + } +} diff --git a/Server/Protocol/Handlers/48-UNK/48-16-UNK4816.cs b/Server/Protocol/Handlers/48-UNK/48-16-UNK4816.cs new file mode 100644 index 0000000..ec83726 --- /dev/null +++ b/Server/Protocol/Handlers/48-UNK/48-16-UNK4816.cs @@ -0,0 +1,16 @@ +using System; +using PSO2SERVER.Models; +using PSO2SERVER.Protocol.Packets; + +namespace PSO2SERVER.Protocol.Handlers +{ + [PacketHandlerAttr(0x48, 0x16)] + public class _48_16_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); + } + } +} diff --git a/Server/Protocol/Handlers/49-UNK/49-00-UNK4900.cs b/Server/Protocol/Handlers/49-UNK/49-00-UNK4900.cs new file mode 100644 index 0000000..1b3f9d6 --- /dev/null +++ b/Server/Protocol/Handlers/49-UNK/49-00-UNK4900.cs @@ -0,0 +1,16 @@ +using System; +using PSO2SERVER.Models; +using PSO2SERVER.Protocol.Packets; + +namespace PSO2SERVER.Protocol.Handlers +{ + [PacketHandlerAttr(0x49, 0x00)] + public class _49_00_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); + } + } +} diff --git a/Server/Protocol/Packets/21-PalettePacket/21-01-LoadPalettePacket.cs b/Server/Protocol/Packets/21-PalettePacket/21-01-LoadPalettePacket.cs index ab44538..ecf284b 100644 --- a/Server/Protocol/Packets/21-PalettePacket/21-01-LoadPalettePacket.cs +++ b/Server/Protocol/Packets/21-PalettePacket/21-01-LoadPalettePacket.cs @@ -13,22 +13,22 @@ namespace PSO2SERVER.Protocol.Packets public WeaponPalette[] Palettes { get; set; } = new WeaponPalette[6]; public SubPalette[] Subpalettes { get; set; } = new SubPalette[6]; - public LoadPalettePacket() + public LoadPalettePacket(PSOPalette palette) { - CurPalette = 1; - CurSubpalette = 0; - CurBook = 0; + CurPalette = palette.CurPalette; + CurSubpalette = palette.CurSubpalette; + CurBook = palette.CurBook; // 初始化 Palettes for (int i = 0; i < Palettes.Length; i++) { - Palettes[i] = new WeaponPalette(); + Palettes[i] = palette.Palettes[i]; } // 初始化 Subpalettes(根据需要可以进行自定义初始化) for (int i = 0; i < Subpalettes.Length; i++) { - Subpalettes[i] = new SubPalette(); // 这里可以根据需要进行初始化 + Subpalettes[i] = palette.Subpalettes[i]; // 这里可以根据需要进行初始化 } } diff --git a/Server/Protocol/Packets/21-PalettePacket/21-03-FullPaletteInfoPacket.cs b/Server/Protocol/Packets/21-PalettePacket/21-03-FullPaletteInfoPacket.cs index b92af58..807f4ed 100644 --- a/Server/Protocol/Packets/21-PalettePacket/21-03-FullPaletteInfoPacket.cs +++ b/Server/Protocol/Packets/21-PalettePacket/21-03-FullPaletteInfoPacket.cs @@ -10,9 +10,9 @@ namespace PSO2SERVER.Protocol.Packets { public class FullPaletteInfoPacket : Packet { - private Palette Palette = Palette.Create(); + private PSOPalette Palette = new PSOPalette(); - public FullPaletteInfoPacket(Palette palette) + public FullPaletteInfoPacket(PSOPalette palette) { this.Palette = palette; } diff --git a/Server/Protocol/Packets/21-PalettePacket/21-0F-NewDefaultPAsPacket.cs b/Server/Protocol/Packets/21-PalettePacket/21-0F-NewDefaultPAsPacket.cs index 0ac197a..1521dc9 100644 --- a/Server/Protocol/Packets/21-PalettePacket/21-0F-NewDefaultPAsPacket.cs +++ b/Server/Protocol/Packets/21-PalettePacket/21-0F-NewDefaultPAsPacket.cs @@ -11,14 +11,16 @@ namespace PSO2SERVER.Protocol.Packets { public const int SeekAfter = 0x240; // 576 bytes - public FixedList Default { get; set; } = new FixedList(0x1A0); + public FixedList Default { get; set; } = new FixedList(0x1A0, 0); public NewDefaultPAsPacket(List Default) { - foreach (var item in Default) - { - this.Default.Add(item); - } + this.Default.SetListItem(Default); + } + + public NewDefaultPAsPacket(FixedList Default) + { + this.Default = Default; } public void ReadFromStream(PacketReader reader) @@ -28,7 +30,7 @@ namespace PSO2SERVER.Protocol.Packets // 读取 Default for (int i = 0; i < Default.Capacity; i++) { - Default.Add(reader.ReadUInt32()); + Default.SetItem(i, reader.ReadUInt32()); } } diff --git a/Server/Protocol/Packets/23-FlagPackets/23-06-AccountFlagsPacket.cs b/Server/Protocol/Packets/23-FlagPackets/23-06-AccountFlagsPacket.cs index e6f14fe..5c2932d 100644 --- a/Server/Protocol/Packets/23-FlagPackets/23-06-AccountFlagsPacket.cs +++ b/Server/Protocol/Packets/23-FlagPackets/23-06-AccountFlagsPacket.cs @@ -9,14 +9,18 @@ namespace PSO2SERVER.Protocol.Packets public class AccountFlagsPacket : Packet { // Accounts flags (0x400 bytes) - public List Flags { get; set; } + public FixedList Flags { get; set; } = new FixedList(0x400, 0); // Accounts parameters (0x100 bytes) - public List Params { get; set; } + public FixedList Params { get; set; } = new FixedList(0x100, 0); public AccountFlagsPacket() { - Flags = new List(new byte[0x400]); - Params = new List(new uint[0x100]); + } + + public AccountFlagsPacket(FixedList Flags, FixedList Params) + { + this.Flags = Flags; + this.Params = Params; } #region implemented abstract members of Packet @@ -24,8 +28,8 @@ namespace PSO2SERVER.Protocol.Packets public override byte[] Build() { var pkt = new PacketWriter(); - pkt.Write(new byte[0x400]); - pkt.Write(new byte[0x400]); + pkt.WriteList(Flags); + pkt.WriteList(Params); return pkt.ToArray(); } diff --git a/Server/Protocol/Packets/23-FlagPackets/23-07-CharacterFlagsPacket.cs b/Server/Protocol/Packets/23-FlagPackets/23-07-CharacterFlagsPacket.cs index 55a540e..6051de5 100644 --- a/Server/Protocol/Packets/23-FlagPackets/23-07-CharacterFlagsPacket.cs +++ b/Server/Protocol/Packets/23-FlagPackets/23-07-CharacterFlagsPacket.cs @@ -12,17 +12,21 @@ namespace PSO2SERVER.Protocol.Packets /// /// Character flags. /// - public List Flags { get; set; } + public FixedList Flags { get; set; } = new FixedList(0xC00, 0); /// /// Character parameters. /// - public List Params { get; set; } + public FixedList Params { get; set; } = new FixedList(0x100, 0); public CharacterFlagsPacket() { - Flags = new List(new byte[0xC00]); - Params = new List(new uint[0x100]); + } + + public CharacterFlagsPacket(FixedList Flags, FixedList Params) + { + this.Flags = Flags; + this.Params = Params; } #region implemented abstract members of Packet @@ -30,8 +34,8 @@ namespace PSO2SERVER.Protocol.Packets public override byte[] Build() { var pkt = new PacketWriter(); - pkt.Write(new byte[0xC00]); - pkt.Write(new byte[0x400]); + pkt.WriteList(Flags); + pkt.WriteList(Params); return pkt.ToArray(); } diff --git a/Server/Server.csproj b/Server/Server.csproj index 8c01233..b346c40 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -332,6 +332,7 @@ + @@ -347,6 +348,8 @@ + + @@ -398,6 +401,10 @@ + + + +