Skip to content

Commit

Permalink
Merge pull request #11 from Megghy/main
Browse files Browse the repository at this point in the history
fix NetTeleportPylonModule, complete NetLiquidModule
  • Loading branch information
cc004 authored Oct 24, 2021
2 parents 56370d3 + 7dff2e7 commit e42fb42
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 2 deletions.
15 changes: 15 additions & 0 deletions TrProtocol/Models/LiquidChange.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
14 changes: 14 additions & 0 deletions TrProtocol/Models/LiquidData.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
17 changes: 17 additions & 0 deletions TrProtocol/Models/LiquidType.cs
Original file line number Diff line number Diff line change
@@ -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<LiquidType>))]
public enum LiquidType : byte
{
Water = 1,
Lava = 2,
Honey = 3
}
}
17 changes: 17 additions & 0 deletions TrProtocol/Models/PylonPacketType.cs
Original file line number Diff line number Diff line change
@@ -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<PylonPacketType>))]
public enum PylonPacketType : byte
{
PylonWasAdded,
PylonWasRemoved,
PlayerRequestsTeleport
}
}
3 changes: 1 addition & 2 deletions TrProtocol/Packets/Modules/NetLiquidModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
1 change: 1 addition & 0 deletions TrProtocol/Packets/Modules/NetTeleportPylonModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand Down
46 changes: 46 additions & 0 deletions TrProtocol/Serializers/LiquidDataSerializer.cs
Original file line number Diff line number Diff line change
@@ -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<LiquidData>
{
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);
}
}
}
}
}

0 comments on commit e42fb42

Please sign in to comment.