From 9a827214fa09c3d333390668fccf9f4f55e3a5bd Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Mon, 13 Nov 2023 18:23:29 +0100 Subject: [PATCH] feat: implement ChannelSelectionResponse packet data --- Wonderking/Packets/OperationCode.cs | 3 +- Wonderking/Packets/Outgoing/BaseStats.cs | 14 ++++ .../ChannelSelectionResponsePacket.cs | 71 +++++++++++++++++++ Wonderking/Packets/Outgoing/CharacterData.cs | 16 +++++ Wonderking/Packets/Outgoing/JobData.cs | 12 ++++ 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 Wonderking/Packets/Outgoing/BaseStats.cs create mode 100644 Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs create mode 100644 Wonderking/Packets/Outgoing/CharacterData.cs create mode 100644 Wonderking/Packets/Outgoing/JobData.cs diff --git a/Wonderking/Packets/OperationCode.cs b/Wonderking/Packets/OperationCode.cs index f8b9eea..c866557 100644 --- a/Wonderking/Packets/OperationCode.cs +++ b/Wonderking/Packets/OperationCode.cs @@ -4,5 +4,6 @@ public enum OperationCode : ushort { LoginInfo = 11, LoginResponse = 12, - ChannelSelection + ChannelSelection = 13, + ChannelSelectionResponse = 13 } diff --git a/Wonderking/Packets/Outgoing/BaseStats.cs b/Wonderking/Packets/Outgoing/BaseStats.cs new file mode 100644 index 0000000..61b9bf9 --- /dev/null +++ b/Wonderking/Packets/Outgoing/BaseStats.cs @@ -0,0 +1,14 @@ +using System.Runtime.InteropServices; + +namespace Wonderking.Packets.Outgoing; + +[StructLayout(LayoutKind.Auto)] +public struct BaseStats +{ + public required short Strength { get; set; } + public required short Dexterity { get; set; } + public required short Intelligence { get; set; } + public required short Vitality { get; set; } + public required short Luck { get; set; } + public required short Wisdom { get; set; } +} diff --git a/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs b/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs new file mode 100644 index 0000000..100f7dc --- /dev/null +++ b/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs @@ -0,0 +1,71 @@ +using System.Buffers.Binary; +using System.Text; + +namespace Wonderking.Packets.Outgoing; + +[PacketId(OperationCode.ChannelSelectionResponse)] +public class ChannelSelectionResponsePacket : IPacket +{ + public required byte UnknownFlag { get; set; } + public required string Endpoint { get; set; } + public required ushort Port { get; set; } + public required CharacterData[] Characters { get; set; } + + public void Deserialize(byte[] data) + { + throw new NotSupportedException(); + } + + public byte[] Serialize() + { + Span data = stackalloc byte[1 + 16 + 2 + 2 + 132 * this.Characters.Length]; + data.Clear(); + data[0] = this.UnknownFlag; + Encoding.ASCII.GetBytes(this.Endpoint, data.Slice(1, 16)); + BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(17, 2), this.Port); + BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(19, 2), (ushort)this.Characters.Length); + + // Character Data + for (var i = 0; i < Characters.Length; i++) + { + var character = Characters[i]; + BinaryPrimitives.WriteInt32LittleEndian(data.Slice(21, 4), i); + Encoding.ASCII.GetBytes(character.Name, data.Slice(25 + (i * 132), 16)); + + // Job Data + data[41 + (i * 132)] = character.Job.FirstJob; + data[42 + (i * 132)] = character.Job.SecondJob; + data[43 + (i * 132)] = character.Job.ThirdJob; + data[44 + (i * 132)] = character.Job.FourthJob; + + data[45 + (i * 132)] = character.Gender; + data[46 + (i * 132)] = character.Level; + data[47 + (i * 132)] = character.Unknown; + data[48 + (i * 132)] = (byte)character.Experience; + + // Stats + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(49 + (i * 132), 2), character.Stats.Strength); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(51 + (i * 132), 2), character.Stats.Dexterity); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(53 + (i * 132), 2), character.Stats.Intelligence); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(55 + (i * 132), 2), character.Stats.Vitality); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(57 + (i * 132), 2), character.Stats.Luck); + BinaryPrimitives.WriteInt16LittleEndian(data.Slice(59 + (i * 132), 2), character.Stats.Wisdom); + + BinaryPrimitives.WriteInt32LittleEndian(data.Slice(61 + (i * 132), 4), character.Health); + BinaryPrimitives.WriteInt32LittleEndian(data.Slice(65 + (i * 132), 4), character.Mana); + + for (var j = 0; j < 20; j++) + { + // Equipped Items + BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(69 + (i * 132) + (j * 2), 2), + character.EquippedItems[j] ?? 0); + + // Equipped Cash Items + BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(109 + (i * 132) + (j * 2), 2), + character.EquippedCashItems[j] ?? 0); + } + } + + return data.ToArray(); + } +} diff --git a/Wonderking/Packets/Outgoing/CharacterData.cs b/Wonderking/Packets/Outgoing/CharacterData.cs new file mode 100644 index 0000000..6e401b6 --- /dev/null +++ b/Wonderking/Packets/Outgoing/CharacterData.cs @@ -0,0 +1,16 @@ +namespace Wonderking.Packets.Outgoing; + +public struct CharacterData +{ + public required string Name { get; set; } + public required JobData Job { get; set; } + public required byte Gender { get; set; } + public required byte Level { get; set; } + public required byte Unknown { get; set; } + public required float Experience { get; set; } + public required BaseStats Stats { get; set; } + public required int Health { get; set; } + public required int Mana { get; set; } + public required ushort?[] EquippedItems { get; set; } + public required ushort?[] EquippedCashItems { get; set; } +} diff --git a/Wonderking/Packets/Outgoing/JobData.cs b/Wonderking/Packets/Outgoing/JobData.cs new file mode 100644 index 0000000..89d0b0a --- /dev/null +++ b/Wonderking/Packets/Outgoing/JobData.cs @@ -0,0 +1,12 @@ +using System.Runtime.InteropServices; + +namespace Wonderking.Packets.Outgoing; + +[StructLayout(LayoutKind.Auto)] +public struct JobData +{ + public required byte FirstJob { get; set; } + public required byte SecondJob { get; set; } + public required byte ThirdJob { get; set; } + public required byte FourthJob { get; set; } +}