diff --git a/TrProtocol/Models/LiquidChange.cs b/TrProtocol/Models/LiquidChange.cs new file mode 100644 index 00000000..5bb4684f --- /dev/null +++ b/TrProtocol/Models/LiquidChange.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrProtocol.Models +{ + public struct LiquidChange + { + public ShortPosition Position { get; set; } + public byte LiquidAmount { get; set; } + public LiquidType LiquidType { get; set; } + } +} diff --git a/TrProtocol/Models/LiquidData.cs b/TrProtocol/Models/LiquidData.cs new file mode 100644 index 00000000..62f32361 --- /dev/null +++ b/TrProtocol/Models/LiquidData.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrProtocol.Models +{ + public partial struct LiquidData + { + public ushort TotalChanges { get; set; } + public LiquidChange[] LiquidChanges { get; set; } + } +} diff --git a/TrProtocol/Models/LiquidType.cs b/TrProtocol/Models/LiquidType.cs new file mode 100644 index 00000000..12d6f28f --- /dev/null +++ b/TrProtocol/Models/LiquidType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TrProtocol.Serializers; + +namespace TrProtocol.Models +{ + [Serializer(typeof(ByteEnumSerializer))] + public enum LiquidType : byte + { + Water = 1, + Lava = 2, + Honey = 3 + } +} diff --git a/TrProtocol/Models/PylonPacketType.cs b/TrProtocol/Models/PylonPacketType.cs new file mode 100644 index 00000000..d825b1b4 --- /dev/null +++ b/TrProtocol/Models/PylonPacketType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TrProtocol.Serializers; + +namespace TrProtocol.Models +{ + [Serializer(typeof(ByteEnumSerializer))] + public enum PylonPacketType : byte + { + PylonWasAdded, + PylonWasRemoved, + PlayerRequestsTeleport + } +} diff --git a/TrProtocol/Packets/Modules/NetLiquidModule.cs b/TrProtocol/Packets/Modules/NetLiquidModule.cs index 69701dcb..6a1fade8 100644 --- a/TrProtocol/Packets/Modules/NetLiquidModule.cs +++ b/TrProtocol/Packets/Modules/NetLiquidModule.cs @@ -6,7 +6,6 @@ public class NetLiquidModule : NetModulesPacket { public override MessageID Type => MessageID.NetModules; public override NetModuleType ModuleType => NetModuleType.NetLiquidModule; - public ushort Count { get; set; } - public byte[] Changes { get; set; } + public LiquidData LiquidChanges { get; set; } } } \ No newline at end of file diff --git a/TrProtocol/Packets/Modules/NetTeleportPylonModule.cs b/TrProtocol/Packets/Modules/NetTeleportPylonModule.cs index 6d614e49..4790149a 100644 --- a/TrProtocol/Packets/Modules/NetTeleportPylonModule.cs +++ b/TrProtocol/Packets/Modules/NetTeleportPylonModule.cs @@ -6,6 +6,7 @@ public class NetTeleportPylonModule : NetModulesPacket { public override MessageID Type => MessageID.NetModules; public override NetModuleType ModuleType => NetModuleType.NetTeleportPylonModule; + public PylonPacketType PylonPacketType { get; set; } public ShortPosition Position { get; set; } public TeleportPylonType PylonType { get; set; } } diff --git a/TrProtocol/Serializers/LiquidDataSerializer.cs b/TrProtocol/Serializers/LiquidDataSerializer.cs new file mode 100644 index 00000000..424a099c --- /dev/null +++ b/TrProtocol/Serializers/LiquidDataSerializer.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Channels; + +namespace TrProtocol.Models +{ + [Serializer(typeof(LiquidDataSerializer))] + public partial struct LiquidData + { + private class LiquidDataSerializer : FieldSerializer + { + protected override LiquidData _Read(BinaryReader br) + { + var liquid = new LiquidData() + { + TotalChanges = br.ReadUInt16() + }; + var changes = new LiquidChange[liquid.TotalChanges]; + for (int i = 0; i < liquid.TotalChanges; i++) + { + changes[i] = new LiquidChange() + { + Position = new(br.ReadInt16(), br.ReadInt16()), + LiquidAmount = br.ReadByte(), + LiquidType = (LiquidType)br.ReadByte() + }; + } + liquid.LiquidChanges = changes; + return liquid; + } + + protected override void _Write(BinaryWriter bw, LiquidData t) +{ + bw.Write(t.TotalChanges); + foreach (LiquidChange change in t.LiquidChanges) + { + bw.Write(change.Position.X); + bw.Write(change.Position.Y); + bw.Write(change.LiquidAmount); + bw.Write((byte)change.LiquidType); + } + } + } + } +}