diff --git a/Multiplicity.Packets/AddNPCBuff.cs b/Multiplicity.Packets/AddNPCBuff.cs
index 2e975c8..b862016 100644
--- a/Multiplicity.Packets/AddNPCBuff.cs
+++ b/Multiplicity.Packets/AddNPCBuff.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
br.Write(Buff);
br.Write(Time);
diff --git a/Multiplicity.Packets/AddPlayerBuff.cs b/Multiplicity.Packets/AddPlayerBuff.cs
index ba571e4..aa4ca31 100644
--- a/Multiplicity.Packets/AddPlayerBuff.cs
+++ b/Multiplicity.Packets/AddPlayerBuff.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -13,7 +14,7 @@ public class AddPlayerBuff : TerrariaPacket
public byte Buff { get; set; }
- public short Time { get; set; }
+ public int Time { get; set; }
///
/// Initializes a new instance of the class.
@@ -33,7 +34,7 @@ public AddPlayerBuff(BinaryReader br)
{
this.PlayerID = br.ReadByte();
this.Buff = br.ReadByte();
- this.Time = br.ReadInt16();
+ this.Time = br.ReadInt32();
}
public override string ToString()
@@ -45,7 +46,7 @@ public override string ToString()
public override short GetLength()
{
- return (short)(4);
+ return (short)(6);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Buff);
br.Write(Time);
diff --git a/Multiplicity.Packets/AlterItemDrop.cs b/Multiplicity.Packets/AlterItemDrop.cs
index c34460d..f510848 100644
--- a/Multiplicity.Packets/AlterItemDrop.cs
+++ b/Multiplicity.Packets/AlterItemDrop.cs
@@ -7,6 +7,7 @@
// Copyright (c) 2016 Celant
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -54,49 +55,123 @@ public AlterItemDrop(BinaryReader br)
{
this.ItemIndex = br.ReadInt16();
this.Flags1 = br.ReadByte();
- this.PackedColorValue = br.ReadUInt32();
- this.Damage = br.ReadUInt16();
- this.Knockback = br.ReadSingle();
- this.UseAnimation = br.ReadUInt16();
- this.UseTime = br.ReadUInt16();
- this.Shoot = br.ReadInt16();
- this.ShootSpeed = br.ReadSingle();
- this.Flags2 = br.ReadByte();
- this.Width = br.ReadInt16();
- this.Height = br.ReadInt16();
- this.Scale = br.ReadSingle();
- this.Ammo = br.ReadInt16();
- this.UseAmmo = br.ReadInt16();
- this.NotAmmo = br.ReadBoolean();
+ if (this.Flags1.ReadBit(0))
+ this.PackedColorValue = br.ReadUInt32();
+ if (this.Flags1.ReadBit(1))
+ this.Damage = br.ReadUInt16();
+ if (this.Flags1.ReadBit(2))
+ this.Knockback = br.ReadSingle();
+ if (this.Flags1.ReadBit(3))
+ this.UseAnimation = br.ReadUInt16();
+ if (this.Flags1.ReadBit(4))
+ this.UseTime = br.ReadUInt16();
+ if (this.Flags1.ReadBit(5))
+ this.Shoot = br.ReadInt16();
+ if (this.Flags1.ReadBit(6))
+ this.ShootSpeed = br.ReadSingle();
+
+ if (this.Flags1.ReadBit(7))
+ {
+ this.Flags2 = br.ReadByte();
+ if (this.Flags2.ReadBit(0))
+ this.Width = br.ReadInt16();
+ if (this.Flags2.ReadBit(1))
+ this.Height = br.ReadInt16();
+ if (this.Flags2.ReadBit(2))
+ this.Scale = br.ReadSingle();
+ if (this.Flags2.ReadBit(3))
+ this.Ammo = br.ReadInt16();
+ if (this.Flags2.ReadBit(4))
+ this.UseAmmo = br.ReadInt16();
+ if (this.Flags2.ReadBit(5))
+ this.NotAmmo = br.ReadBoolean();
+ }
}
public override short GetLength()
{
- return 37;
+ short length = 3;
+
+ if (this.Flags1.ReadBit(0))
+ length += 4;
+ if (this.Flags1.ReadBit(1))
+ length += 2;
+ if (this.Flags1.ReadBit(2))
+ length += 4;
+ if (this.Flags1.ReadBit(3))
+ length += 2;
+ if (this.Flags1.ReadBit(4))
+ length += 2;
+ if (this.Flags1.ReadBit(5))
+ length += 2;
+ if (this.Flags1.ReadBit(6))
+ length += 4;
+
+ if (this.Flags1.ReadBit(7))
+ {
+ length += 1;
+ if (this.Flags2.ReadBit(0))
+ length += 2;
+ if (this.Flags2.ReadBit(1))
+ length += 2;
+ if (this.Flags2.ReadBit(2))
+ length += 4;
+ if (this.Flags2.ReadBit(3))
+ length += 2;
+ if (this.Flags2.ReadBit(4))
+ length += 2;
+ if (this.Flags2.ReadBit(5))
+ length += 1;
+ }
+
+ return length;
}
public override void ToStream(Stream stream, bool includeHeader = true)
{
- base.ToStream(stream, includeHeader);
+ /*
+ * Length and ID headers get written in the base packet class.
+ */
+ if (includeHeader)
+ {
+ base.ToStream(stream, includeHeader);
+ }
using (BinaryWriter bw = new BinaryWriter(stream, System.Text.Encoding.UTF8, leaveOpen: true))
{
bw.Write(ItemIndex);
bw.Write(Flags1);
- bw.Write(PackedColorValue);
- bw.Write(Damage);
- bw.Write(Knockback);
- bw.Write(UseAnimation);
- bw.Write(UseTime);
- bw.Write(Shoot);
- bw.Write(ShootSpeed);
- bw.Write(Flags2);
- bw.Write(Width);
- bw.Write(Height);
- bw.Write(Scale);
- bw.Write(Ammo);
- bw.Write(UseAmmo);
- bw.Write(NotAmmo);
+ if (Flags1.ReadBit(1))
+ bw.Write(PackedColorValue);
+ if (this.Flags1.ReadBit(2))
+ bw.Write(Damage);
+ if (this.Flags1.ReadBit(4))
+ bw.Write(Knockback);
+ if (this.Flags1.ReadBit(8))
+ bw.Write(UseAnimation);
+ if (this.Flags1.ReadBit(16))
+ bw.Write(UseTime);
+ if (this.Flags1.ReadBit(32))
+ bw.Write(Shoot);
+ if (this.Flags1.ReadBit(64))
+ bw.Write(ShootSpeed);
+
+ if (this.Flags1.ReadBit(128))
+ {
+ bw.Write(Flags2);
+ if (this.Flags2.ReadBit(1))
+ bw.Write(Width);
+ if (this.Flags2.ReadBit(1))
+ bw.Write(Height);
+ if (this.Flags2.ReadBit(1))
+ bw.Write(Scale);
+ if (this.Flags2.ReadBit(1))
+ bw.Write(Ammo);
+ if (this.Flags2.ReadBit(1))
+ bw.Write(UseAmmo);
+ if (this.Flags2.ReadBit(1))
+ bw.Write(NotAmmo);
+ }
}
}
diff --git a/Multiplicity.Packets/AnglerQuest.cs b/Multiplicity.Packets/AnglerQuest.cs
index 182834a..f9a34a0 100644
--- a/Multiplicity.Packets/AnglerQuest.cs
+++ b/Multiplicity.Packets/AnglerQuest.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Quest);
br.Write(Completed);
}
diff --git a/Multiplicity.Packets/CatchNPC.cs b/Multiplicity.Packets/CatchNPC.cs
index 98fdb14..339fe28 100644
--- a/Multiplicity.Packets/CatchNPC.cs
+++ b/Multiplicity.Packets/CatchNPC.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
br.Write(Who);
}
diff --git a/Multiplicity.Packets/ChatMessage.cs b/Multiplicity.Packets/ChatMessage.cs
index 18cc971..c88f59f 100644
--- a/Multiplicity.Packets/ChatMessage.cs
+++ b/Multiplicity.Packets/ChatMessage.cs
@@ -18,7 +18,7 @@ public class ChatMessage : TerrariaPacket
///
/// Gets or sets the MessageColor - Client cannot change colors|
///
- public Color MessageColor { get; set; }
+ public ColorStruct MessageColor { get; set; }
public string Message { get; set; }
@@ -60,7 +60,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
diff --git a/Multiplicity.Packets/ChatMessagev2.cs b/Multiplicity.Packets/ChatMessagev2.cs
index e8d280a..5f59d71 100644
--- a/Multiplicity.Packets/ChatMessagev2.cs
+++ b/Multiplicity.Packets/ChatMessagev2.cs
@@ -1,7 +1,8 @@
using System;
-using System.Drawing;
using System.IO;
using Multiplicity.Packets.Extensions;
+using System.Drawing;
+using Multiplicity.Packets.Models;
namespace Multiplicity.Packets
{
@@ -12,16 +13,14 @@ public class ChatMessagev2 : TerrariaPacket
{
///
- /// Gets or sets the PlayerID - If 255 Then No Name|
+ /// Gets or sets the MessageColor - Client cannot change colors|
///
- public byte PlayerID { get; set; }
+ public ColorStruct MessageColor { get; set; }
///
- /// Gets or sets the MessageColor - Client cannot change colors|
+ /// Gets or sets the Message - |-|
///
- public Color MessageColor { get; set; }
-
- public string Message { get; set; }
+ public NetworkText Message { get; set; }
public short MessageLength { get; set; }
@@ -41,23 +40,21 @@ public ChatMessagev2()
public ChatMessagev2(BinaryReader br)
: base(br)
{
- this.PlayerID = br.ReadByte();
this.MessageColor = br.ReadColor();
- this.Message = br.ReadString();
+ this.Message = br.ReadNetworkText();
this.MessageLength = br.ReadInt16();
}
public override string ToString()
{
- return
- $"[ChatMessagev2: PlayerID = {PlayerID} MessageColor = {MessageColor} Message = {Message} MessageLength = {MessageLength}]";
+ return $"[ChatMessagev2: MessageColor = {MessageColor} Message = {Message.Text} MessageLength = {MessageLength}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(7 + Message.Length);
+ return (short)(5 + Message.GetLength());
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -65,7 +62,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -77,8 +75,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
- br.Write(PlayerID);
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(MessageColor);
br.Write(Message);
br.Write(MessageLength);
diff --git a/Multiplicity.Packets/ChestItem.cs b/Multiplicity.Packets/ChestItem.cs
index 851e729..92c3cce 100644
--- a/Multiplicity.Packets/ChestItem.cs
+++ b/Multiplicity.Packets/ChestItem.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -44,8 +45,7 @@ public ChestItem(BinaryReader br)
public override string ToString()
{
- return
- $"[ChestItem: ChestID = {ChestID} ItemSlot = {ItemSlot} Stack = {Stack} Prefix = {Prefix} ItemNetID = {ItemNetID}]";
+ return $"[ChestItem: ChestID = {ChestID} ItemSlot = {ItemSlot} Stack = {Stack} Prefix = {Prefix} ItemNetID = {ItemNetID}]";
}
#region implemented abstract members of TerrariaPacket
@@ -60,7 +60,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -72,7 +73,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(ChestID);
br.Write(ItemSlot);
br.Write(Stack);
diff --git a/Multiplicity.Packets/ClientUUID.cs b/Multiplicity.Packets/ClientUUID.cs
index fdd8af1..5b1366b 100644
--- a/Multiplicity.Packets/ClientUUID.cs
+++ b/Multiplicity.Packets/ClientUUID.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -34,7 +36,7 @@ public ClientUUID(BinaryReader br)
public override string ToString()
{
- return $"[ClientUUID: {UUID}]";
+ return $"[ClientUUID: UUID = {UUID}]";
}
#region implemented abstract members of TerrariaPacket
@@ -49,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -61,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(UUID);
}
}
diff --git a/Multiplicity.Packets/ColorStruct.cs b/Multiplicity.Packets/ColorStruct.cs
new file mode 100644
index 0000000..e671aab
--- /dev/null
+++ b/Multiplicity.Packets/ColorStruct.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Multiplicity.Packets
+{
+ public struct ColorStruct
+ {
+ public byte R { get; set; }
+ public byte G { get; set; }
+ public byte B { get; set; }
+ }
+}
diff --git a/Multiplicity.Packets/CombatTextString.cs b/Multiplicity.Packets/CombatTextString.cs
new file mode 100644
index 0000000..933a3e9
--- /dev/null
+++ b/Multiplicity.Packets/CombatTextString.cs
@@ -0,0 +1,86 @@
+using System;
+using System.IO;
+using Multiplicity.Packets.Extensions;
+using Multiplicity.Packets.Models;
+
+namespace Multiplicity.Packets
+{
+ ///
+ /// The CombatTextString (0x77) packet.
+ ///
+ public class CombatTextString : TerrariaPacket
+ {
+
+ public float X { get; set; }
+
+ public float Y { get; set; }
+
+ public ColorStruct Color { get; set; }
+
+ public NetworkText CombatText { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public CombatTextString()
+ : base((byte)PacketTypes.CombatTextString)
+ {
+
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// br
+ public CombatTextString(BinaryReader br)
+ : base(br)
+ {
+ this.X = br.ReadSingle();
+ this.Y = br.ReadSingle();
+ this.Color = br.ReadColor();
+ this.CombatText = br.ReadNetworkText();
+ }
+
+ public override string ToString()
+ {
+ return $"[CombatTextString: X = {X}, Y = {Y}, Color = {Color}, CombatText = {CombatText}]";
+ }
+
+ #region implemented abstract members of TerrariaPacket
+
+ public override short GetLength()
+ {
+ return (short)(11 + CombatText.GetLength());
+ }
+
+ public override void ToStream(Stream stream, bool includeHeader = true)
+ {
+ /*
+ * Length and ID headers get written in the base packet class.
+ */
+ if (includeHeader)
+ {
+ base.ToStream(stream, includeHeader);
+ }
+
+ /*
+ * Always make sure to not close the stream when serializing.
+ *
+ * It is up to the caller to decide if the underlying stream
+ * gets closed. If this is a network stream we do not want
+ * the regressions of unconditionally closing the TCP socket
+ * once the payload of data has been sent to the client.
+ */
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
+ br.Write(X);
+ br.Write(Y);
+ br.Write(Color);
+ br.Write(CombatText);
+ }
+ }
+
+ #endregion
+
+ }
+}
diff --git a/Multiplicity.Packets/CompleteAnglerQuestToday.cs b/Multiplicity.Packets/CompleteAnglerQuestToday.cs
index 9efca0c..813e4b9 100644
--- a/Multiplicity.Packets/CompleteAnglerQuestToday.cs
+++ b/Multiplicity.Packets/CompleteAnglerQuestToday.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -28,7 +30,7 @@ public CompleteAnglerQuestToday(BinaryReader br)
public override string ToString()
{
- return string.Format("[CompleteAnglerQuestToday]");
+ return $"[CompleteAnglerQuestToday:]";
}
#region implemented abstract members of TerrariaPacket
@@ -43,7 +45,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -55,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
}
}
diff --git a/Multiplicity.Packets/CompleteConnectionandSpawn.cs b/Multiplicity.Packets/CompleteConnectionandSpawn.cs
index ba802c1..e0488db 100644
--- a/Multiplicity.Packets/CompleteConnectionandSpawn.cs
+++ b/Multiplicity.Packets/CompleteConnectionandSpawn.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -28,7 +30,7 @@ public CompleteConnectionandSpawn(BinaryReader br)
public override string ToString()
{
- return string.Format("[CompleteConnectionandSpawn]");
+ return $"[CompleteConnectionandSpawn:]";
}
#region implemented abstract members of TerrariaPacket
@@ -43,7 +45,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -55,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
}
}
diff --git a/Multiplicity.Packets/ConnectRequest.cs b/Multiplicity.Packets/ConnectRequest.cs
index 30bd1e8..5e0a914 100644
--- a/Multiplicity.Packets/ConnectRequest.cs
+++ b/Multiplicity.Packets/ConnectRequest.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -22,16 +24,6 @@ public ConnectRequest()
}
- ///
- /// Initializes a new instance of the class.
- ///
- /// The version to be set in the packet
- public ConnectRequest(string version)
- : base((byte)PacketTypes.ConnectRequest)
- {
- this.Version = version;
- }
-
///
/// Initializes a new instance of the class.
///
@@ -59,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -71,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Version);
}
}
diff --git a/Multiplicity.Packets/ContinueConnecting.cs b/Multiplicity.Packets/ContinueConnecting.cs
index 402521f..9525ec3 100644
--- a/Multiplicity.Packets/ContinueConnecting.cs
+++ b/Multiplicity.Packets/ContinueConnecting.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -46,7 +48,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -58,7 +61,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
}
}
diff --git a/Multiplicity.Packets/ContinueConnecting2.cs b/Multiplicity.Packets/ContinueConnecting2.cs
index a00ff1e..7967a0e 100644
--- a/Multiplicity.Packets/ContinueConnecting2.cs
+++ b/Multiplicity.Packets/ContinueConnecting2.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -28,7 +30,7 @@ public ContinueConnecting2(BinaryReader br)
public override string ToString()
{
- return string.Format("[ContinueConnecting2]");
+ return $"[ContinueConnecting2:]";
}
#region implemented abstract members of TerrariaPacket
@@ -43,7 +45,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -55,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
}
}
diff --git a/Multiplicity.Packets/CreateCombatText.cs b/Multiplicity.Packets/CreateCombatText.cs
index 66f9d84..63c7c70 100644
--- a/Multiplicity.Packets/CreateCombatText.cs
+++ b/Multiplicity.Packets/CreateCombatText.cs
@@ -1,6 +1,7 @@
-using System.Drawing;
+using System;
using System.IO;
using Multiplicity.Packets.Extensions;
+using System.Drawing;
namespace Multiplicity.Packets
{
@@ -14,9 +15,9 @@ public class CreateCombatText : TerrariaPacket
public float Y { get; set; }
- public Color Color { get; set; }
+ public ColorStruct Color { get; set; }
- public string Text { get; set; }
+ public int HealAmount { get; set; }
///
/// Initializes a new instance of the class.
@@ -37,19 +38,19 @@ public CreateCombatText(BinaryReader br)
this.X = br.ReadSingle();
this.Y = br.ReadSingle();
this.Color = br.ReadColor();
- this.Text = br.ReadString();
+ this.HealAmount = br.ReadInt32();
}
public override string ToString()
{
- return $"[CreateCombatText: X = {X} Y = {Y} Color = {Color} Text = {Text}]";
+ return $"[CreateCombatText: X = {X} Y = {Y} Color = {Color} HealAmount = {HealAmount}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(12 + Text.Length);
+ return (short)(15);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -57,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -69,11 +71,12 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
br.Write(Color);
- br.Write(Text);
+ br.Write(HealAmount);
}
}
diff --git a/Multiplicity.Packets/CreateTemporaryAnimation.cs b/Multiplicity.Packets/CreateTemporaryAnimation.cs
index b32df27..5c403aa 100644
--- a/Multiplicity.Packets/CreateTemporaryAnimation.cs
+++ b/Multiplicity.Packets/CreateTemporaryAnimation.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -56,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(AnimationType);
br.Write(TileType);
br.Write(X);
diff --git a/Multiplicity.Packets/CrystalInvasionSendWaitTime.cs b/Multiplicity.Packets/CrystalInvasionSendWaitTime.cs
index 92edc03..a0f7ab2 100644
--- a/Multiplicity.Packets/CrystalInvasionSendWaitTime.cs
+++ b/Multiplicity.Packets/CrystalInvasionSendWaitTime.cs
@@ -1,29 +1,42 @@
-using System.IO;
+using System;
+using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
///
- /// The CrystalInvasionSendWaitTime (74) packet.
+ /// The CrystalInvasionSendWaitTime (0x74) packet.
///
public class CrystalInvasionSendWaitTime : TerrariaPacket
{
- public int NextWaveTime { get; set; }
+ ///
+ /// Gets or sets the TimeUntilNextWave - 1800 (30s) between waves, 30 (5s) when starting|
+ ///
+ public int TimeUntilNextWave { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
public CrystalInvasionSendWaitTime()
: base((byte)PacketTypes.CrystalInvasionSendWaitTime)
{
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// br
public CrystalInvasionSendWaitTime(BinaryReader br)
: base(br)
{
- NextWaveTime = br.ReadInt32();
+ this.TimeUntilNextWave = br.ReadInt32();
}
public override string ToString()
{
- return $"[CrystalInvasionSendWaitTime: NextWaveTime = {NextWaveTime}]";
+ return $"[CrystalInvasionSendWaitTime: TimeUntilNextWave = {TimeUntilNextWave}]";
}
#region implemented abstract members of TerrariaPacket
@@ -53,10 +66,11 @@ public override void ToStream(Stream stream, bool includeHeader = true)
*/
using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
{
- br.Write(NextWaveTime);
+ br.Write(TimeUntilNextWave);
}
}
#endregion
+
}
}
diff --git a/Multiplicity.Packets/CrystalInvasionStart.cs b/Multiplicity.Packets/CrystalInvasionStart.cs
index 02a7a7c..7f8acb6 100644
--- a/Multiplicity.Packets/CrystalInvasionStart.cs
+++ b/Multiplicity.Packets/CrystalInvasionStart.cs
@@ -1,12 +1,15 @@
-using System.IO;
+using System;
+using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
///
- /// The CrystalInvasionStart (71) packet.
+ /// The CrystalInvasionStart (0x71) packet.
///
public class CrystalInvasionStart : TerrariaPacket
{
+
public short X { get; set; }
public short Y { get; set; }
@@ -27,8 +30,8 @@ public CrystalInvasionStart()
public CrystalInvasionStart(BinaryReader br)
: base(br)
{
- X = br.ReadInt16();
- Y = br.ReadInt16();
+ this.X = br.ReadInt16();
+ this.Y = br.ReadInt16();
}
public override string ToString()
@@ -69,5 +72,6 @@ public override void ToStream(Stream stream, bool includeHeader = true)
}
#endregion
+
}
}
diff --git a/Multiplicity.Packets/CrystalInvasionWipeAll.cs b/Multiplicity.Packets/CrystalInvasionWipeAll.cs
index c6f14bd..794a51e 100644
--- a/Multiplicity.Packets/CrystalInvasionWipeAll.cs
+++ b/Multiplicity.Packets/CrystalInvasionWipeAll.cs
@@ -1,12 +1,15 @@
-using System.IO;
+using System;
+using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
///
- /// The CrystalInvasionWipeAll (72) packet.
+ /// The CrystalInvasionWipeAll (0x72) packet.
///
public class CrystalInvasionWipeAll : TerrariaPacket
{
+
///
/// Initializes a new instance of the class.
///
@@ -23,12 +26,11 @@ public CrystalInvasionWipeAll()
public CrystalInvasionWipeAll(BinaryReader br)
: base(br)
{
-
}
public override string ToString()
{
- return $"[CrystalInvaionWipeAll]";
+ return $"[CrystalInvasionWipeAll:]";
}
#region implemented abstract members of TerrariaPacket
@@ -62,5 +64,6 @@ public override void ToStream(Stream stream, bool includeHeader = true)
}
#endregion
+
}
}
diff --git a/Multiplicity.Packets/Deprecated.cs b/Multiplicity.Packets/Deprecated.cs
index a38b4cd..cef9442 100644
--- a/Multiplicity.Packets/Deprecated.cs
+++ b/Multiplicity.Packets/Deprecated.cs
@@ -1,5 +1,6 @@
-using System;
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -12,7 +13,7 @@ public class Deprecated : TerrariaPacket
///
/// Initializes a new instance of the class.
///
- public Deprecated()
+ public Deprecated()
: base((byte)PacketTypes.Deprecated)
{
@@ -22,15 +23,14 @@ public Deprecated()
/// Initializes a new instance of the class.
///
/// br
- public Deprecated(BinaryReader br)
+ public Deprecated(BinaryReader br)
: base(br)
{
-
}
public override string ToString()
{
- return string.Format("[Deprecated]");
+ return $"[Deprecated:]";
}
#region implemented abstract members of TerrariaPacket
@@ -45,7 +45,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -57,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
}
}
diff --git a/Multiplicity.Packets/DestroyProjectile.cs b/Multiplicity.Packets/DestroyProjectile.cs
index 0dfcb85..9956840 100644
--- a/Multiplicity.Packets/DestroyProjectile.cs
+++ b/Multiplicity.Packets/DestroyProjectile.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(ProjectileID);
br.Write(Owner);
}
diff --git a/Multiplicity.Packets/Disconnect.cs b/Multiplicity.Packets/Disconnect.cs
index 88aeddd..e2e3e1d 100644
--- a/Multiplicity.Packets/Disconnect.cs
+++ b/Multiplicity.Packets/Disconnect.cs
@@ -1,4 +1,7 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
+using Multiplicity.Packets.Models;
namespace Multiplicity.Packets
{
@@ -8,7 +11,7 @@ namespace Multiplicity.Packets
public class Disconnect : TerrariaPacket
{
- public string Reason { get; set; }
+ public NetworkText Reason { get; set; }
///
/// Initializes a new instance of the class.
@@ -19,16 +22,6 @@ public Disconnect()
}
- ///
- /// Initializes a new instance of the class.
- ///
- /// Reason for disconnecting the client.
- public Disconnect(string reason)
- : base((byte)PacketTypes.Disconnect)
- {
- this.Reason = reason;
- }
-
///
/// Initializes a new instance of the class.
///
@@ -36,19 +29,19 @@ public Disconnect(string reason)
public Disconnect(BinaryReader br)
: base(br)
{
- this.Reason = br.ReadString();
+ this.Reason = br.ReadNetworkText();
}
public override string ToString()
{
- return $"[Disconnect: Reason = {Reason}]";
+ return $"[Disconnect: Reason = {Reason.Text}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(1 + Reason.Length);
+ return (short)(0 + Reason.GetLength());
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -56,7 +49,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +62,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Reason);
}
}
diff --git a/Multiplicity.Packets/DoorToggle.cs b/Multiplicity.Packets/DoorToggle.cs
index d412043..7f6d66b 100644
--- a/Multiplicity.Packets/DoorToggle.cs
+++ b/Multiplicity.Packets/DoorToggle.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -62,7 +63,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -74,7 +76,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Action);
br.Write(TileX);
br.Write(TileY);
diff --git a/Multiplicity.Packets/Extensions/BinaryReader.Extensions.cs b/Multiplicity.Packets/Extensions/BinaryReader.Extensions.cs
index d5afbe4..5211d19 100644
--- a/Multiplicity.Packets/Extensions/BinaryReader.Extensions.cs
+++ b/Multiplicity.Packets/Extensions/BinaryReader.Extensions.cs
@@ -1,14 +1,21 @@
-using System.Drawing;
+using System;
+using System.Drawing;
using System.IO;
+using Multiplicity.Packets.Models;
namespace Multiplicity.Packets.Extensions
{
public static class BinaryReaderExtensions
{
- public static Color ReadColor(this BinaryReader br)
+ public static ColorStruct ReadColor(this BinaryReader br)
{
byte[] colourPayload = br.ReadBytes(3);
- return Color.FromArgb(colourPayload[0], colourPayload[1], colourPayload[2]);
+ return new ColorStruct() { R = colourPayload[0], G = colourPayload[1], B = colourPayload[2] };
+ }
+
+ public static NetworkText ReadNetworkText(this BinaryReader br)
+ {
+ return new NetworkText(br);
}
}
}
diff --git a/Multiplicity.Packets/Extensions/BinaryWriter.Extensions.cs b/Multiplicity.Packets/Extensions/BinaryWriter.Extensions.cs
index abdd819..efb743e 100644
--- a/Multiplicity.Packets/Extensions/BinaryWriter.Extensions.cs
+++ b/Multiplicity.Packets/Extensions/BinaryWriter.Extensions.cs
@@ -1,19 +1,19 @@
using System.IO;
+using Multiplicity.Packets.Models;
namespace Multiplicity.Packets.Extensions
{
public static class BinaryWriterExtensions
{
- public static void Write(this BinaryWriter bw, System.Drawing.Color color)
+ public static void Write(this BinaryWriter bw, ColorStruct color)
{
- byte[] rgb = new byte[3];
-
- rgb[0] = (byte)color.R;
- rgb[1] = (byte)color.G;
- rgb[2] = (byte)color.B;
-
- bw.Write(rgb, 0, 3);
+ bw.Write(new byte[3] { color.R, color.G, color.B }, 0, 3);
}
+
+ public static void Write(this BinaryWriter bw, NetworkText text)
+ {
+ text.ToStream(bw);
+ }
}
}
diff --git a/Multiplicity.Packets/ForceItemIntoNearestChest.cs b/Multiplicity.Packets/ForceItemIntoNearestChest.cs
index f639402..06671ae 100644
--- a/Multiplicity.Packets/ForceItemIntoNearestChest.cs
+++ b/Multiplicity.Packets/ForceItemIntoNearestChest.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -46,7 +48,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -58,7 +61,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(InventorySlot);
}
}
diff --git a/Multiplicity.Packets/GetChestContents.cs b/Multiplicity.Packets/GetChestContents.cs
index 904e6ab..17f1b3c 100644
--- a/Multiplicity.Packets/GetChestContents.cs
+++ b/Multiplicity.Packets/GetChestContents.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(TileX);
br.Write(TileY);
}
diff --git a/Multiplicity.Packets/GetChestName.cs b/Multiplicity.Packets/GetChestName.cs
index b7fc2c9..0cd55d7 100644
--- a/Multiplicity.Packets/GetChestName.cs
+++ b/Multiplicity.Packets/GetChestName.cs
@@ -1,59 +1,85 @@
-//
-// ChestName.cs
-//
-// Author:
-// Luke S
-//
-// Copyright (c) 2016 Luke S
-
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
+ ///
+ /// The GetChestName (0x45) packet.
+ ///
public class GetChestName : TerrariaPacket
{
+
public short ChestID { get; set; }
- public short X { get; set; }
- public short Y { get; set; }
+
+ public short ChestX { get; set; }
+
+ public short ChestY { get; set; }
+
public string Name { get; set; }
- public GetChestName(short chestID, short x, short y, string name)
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetChestName()
: base((byte)PacketTypes.GetChestName)
{
- this.ChestID = chestID;
- this.X = x;
- this.Y = y;
- this.Name = name;
+
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// br
public GetChestName(BinaryReader br)
: base(br)
{
this.ChestID = br.ReadInt16();
- this.X = br.ReadInt16();
- this.Y = br.ReadInt16();
+ this.ChestX = br.ReadInt16();
+ this.ChestY = br.ReadInt16();
this.Name = br.ReadString();
}
+ public override string ToString()
+ {
+ return $"[GetChestName: ChestID = {ChestID} ChestX = {ChestX} ChestY = {ChestY} Name = {Name}]";
+ }
+
+ #region implemented abstract members of TerrariaPacket
+
+ public override short GetLength()
+ {
+ return (short)(7 + Name.Length);
+ }
+
public override void ToStream(Stream stream, bool includeHeader = true)
{
- base.ToStream(stream, includeHeader);
+ /*
+ * Length and ID headers get written in the base packet class.
+ */
+ if (includeHeader)
+ {
+ base.ToStream(stream, includeHeader);
+ }
- using (BinaryWriter bw = new BinaryWriter(stream, System.Text.Encoding.UTF8, leaveOpen: true))
+ /*
+ * Always make sure to not close the stream when serializing.
+ *
+ * It is up to the caller to decide if the underlying stream
+ * gets closed. If this is a network stream we do not want
+ * the regressions of unconditionally closing the TCP socket
+ * once the payload of data has been sent to the client.
+ */
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
{
- bw.Write(this.ChestID);
- bw.Write(this.X);
- bw.Write(this.Y);
- bw.Write(this.Name);
+ br.Write(ChestID);
+ br.Write(ChestX);
+ br.Write(ChestY);
+ br.Write(Name);
}
}
- public override short GetLength()
- {
- return (short)(6 + this.Name.Length);
- }
+ #endregion
- public override string ToString() =>
- $"[{nameof(GetChestName)}: ChestID={ChestID},X={X},Y={Y},Name={Name}]";
}
}
diff --git a/Multiplicity.Packets/GetSection.cs b/Multiplicity.Packets/GetSection.cs
index a07db6a..0cff2ce 100644
--- a/Multiplicity.Packets/GetSection.cs
+++ b/Multiplicity.Packets/GetSection.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -56,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
}
diff --git a/Multiplicity.Packets/GrowFX.cs b/Multiplicity.Packets/GrowFX.cs
index 553de11..97048eb 100644
--- a/Multiplicity.Packets/GrowFX.cs
+++ b/Multiplicity.Packets/GrowFX.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -17,6 +18,8 @@ public class GrowFX : TerrariaPacket
public byte Height { get; set; }
+ public short TreeGore { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -37,18 +40,19 @@ public GrowFX(BinaryReader br)
this.X = br.ReadInt16();
this.Y = br.ReadInt16();
this.Height = br.ReadByte();
+ this.TreeGore = br.ReadInt16();
}
public override string ToString()
{
- return $"[GrowFX: GrowEffect = {GrowEffect} X = {X} Y = {Y} Height = {Height}]";
+ return $"[GrowFX: GrowEffect = {GrowEffect} X = {X} Y = {Y} Height = {Height} TreeGore = {TreeGore}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(6);
+ return (short)(8);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -56,7 +60,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,11 +73,13 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(GrowEffect);
br.Write(X);
br.Write(Y);
br.Write(Height);
+ br.Write(TreeGore);
}
}
diff --git a/Multiplicity.Packets/HealEffect.cs b/Multiplicity.Packets/HealEffect.cs
index 19f0d09..d03d40f 100644
--- a/Multiplicity.Packets/HealEffect.cs
+++ b/Multiplicity.Packets/HealEffect.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(HealAmount);
}
diff --git a/Multiplicity.Packets/HealOtherPlayer.cs b/Multiplicity.Packets/HealOtherPlayer.cs
index 5390e57..0a5205e 100644
--- a/Multiplicity.Packets/HealOtherPlayer.cs
+++ b/Multiplicity.Packets/HealOtherPlayer.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(HealAmount);
}
diff --git a/Multiplicity.Packets/HitSwitch.cs b/Multiplicity.Packets/HitSwitch.cs
index 9384bc5..cb5bed7 100644
--- a/Multiplicity.Packets/HitSwitch.cs
+++ b/Multiplicity.Packets/HitSwitch.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
}
diff --git a/Multiplicity.Packets/KillPortal.cs b/Multiplicity.Packets/KillPortal.cs
index 40cea31..070839f 100644
--- a/Multiplicity.Packets/KillPortal.cs
+++ b/Multiplicity.Packets/KillPortal.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,7 +48,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -59,7 +61,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(ProjectileIndex);
}
}
diff --git a/Multiplicity.Packets/ManaEffect.cs b/Multiplicity.Packets/ManaEffect.cs
index ecc5dff..9cda453 100644
--- a/Multiplicity.Packets/ManaEffect.cs
+++ b/Multiplicity.Packets/ManaEffect.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(ManaAmount);
}
diff --git a/Multiplicity.Packets/MassWireOperation.cs b/Multiplicity.Packets/MassWireOperation.cs
index 89c9441..3b41cb9 100644
--- a/Multiplicity.Packets/MassWireOperation.cs
+++ b/Multiplicity.Packets/MassWireOperation.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,8 +48,7 @@ public MassWireOperation(BinaryReader br)
public override string ToString()
{
- return
- $"[MassWireOperation: StartX = {StartX} StartY = {StartY} EndX = {EndX} EndY = {EndY} ToolMode = {ToolMode}]";
+ return $"[MassWireOperation: StartX = {StartX} StartY = {StartY} EndX = {EndX} EndY = {EndY} ToolMode = {ToolMode}]";
}
#region implemented abstract members of TerrariaPacket
@@ -63,7 +63,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -75,7 +76,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(StartX);
br.Write(StartY);
br.Write(EndX);
diff --git a/Multiplicity.Packets/MassWireOperationConsume.cs b/Multiplicity.Packets/MassWireOperationConsume.cs
index cea9834..88ec5c6 100644
--- a/Multiplicity.Packets/MassWireOperationConsume.cs
+++ b/Multiplicity.Packets/MassWireOperationConsume.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(ItemType);
br.Write(Quantity);
br.Write(PlayerID);
diff --git a/Multiplicity.Packets/MinionAttackTargetUpdate.cs b/Multiplicity.Packets/MinionAttackTargetUpdate.cs
index a6afdbe..0a709fb 100644
--- a/Multiplicity.Packets/MinionAttackTargetUpdate.cs
+++ b/Multiplicity.Packets/MinionAttackTargetUpdate.cs
@@ -1,13 +1,16 @@
-using System.IO;
+using System;
+using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
///
- /// The MinionAttackTargetUpdate (73) packet.
+ /// The MinionAttackTargetUpdate (0x73) packet.
///
public class MinionAttackTargetUpdate : TerrariaPacket
{
- public byte PlayerId { get; set; }
+
+ public byte PlayerID { get; set; }
public short MinionAttackTarget { get; set; }
@@ -27,13 +30,13 @@ public MinionAttackTargetUpdate()
public MinionAttackTargetUpdate(BinaryReader br)
: base(br)
{
- PlayerId = br.ReadByte();
- MinionAttackTarget = br.ReadInt16();
+ this.PlayerID = br.ReadByte();
+ this.MinionAttackTarget = br.ReadInt16();
}
public override string ToString()
{
- return $"[MinionAttackTargetUpdate: PlayerId = {PlayerId} MinionAttackTarget = {MinionAttackTarget}]";
+ return $"[MinionAttackTargetUpdate: PlayerID = {PlayerID} MinionAttackTarget = {MinionAttackTarget}]";
}
#region implemented abstract members of TerrariaPacket
@@ -63,11 +66,12 @@ public override void ToStream(Stream stream, bool includeHeader = true)
*/
using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
{
- br.Write(PlayerId);
+ br.Write(PlayerID);
br.Write(MinionAttackTarget);
}
}
#endregion
+
}
}
diff --git a/Multiplicity.Packets/Models/NetworkText.cs b/Multiplicity.Packets/Models/NetworkText.cs
new file mode 100644
index 0000000..bf86784
--- /dev/null
+++ b/Multiplicity.Packets/Models/NetworkText.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Multiplicity.Packets.Extensions;
+
+namespace Multiplicity.Packets.Models
+{
+ ///
+ /// Represents an translatable string of text
+ ///
+ public class NetworkText
+ {
+ public enum Mode : byte
+ {
+ Literal = 0,
+ Formattable,
+ LocalizationKey,
+ }
+
+ ///
+ /// Mode of the text
+ ///
+ public byte TextMode { get; set; }
+
+ ///
+ /// The text itself
+ ///
+ public string Text { get; set; }
+
+ ///
+ /// The length of the SubstitutionList
+ ///
+ public byte SubstitutionListLength { get; set; }
+
+ ///
+ /// A list of substitutions to make
+ ///
+ public NetworkText[] SubstitutionList { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public NetworkText()
+ {
+
+ }
+
+ ///
+ /// Reads from the given reader and initializes a new instance of the class.
+ ///
+ /// Reader to initialize instance from.
+ public NetworkText(BinaryReader br)
+ {
+ this.TextMode = br.ReadByte();
+ this.Text = br.ReadString();
+ if (this.TextMode != (byte) Mode.Literal)
+ {
+ this.SubstitutionListLength = br.ReadByte();
+ this.SubstitutionList = new NetworkText[(int)SubstitutionListLength];
+
+ for (int i = 0; i < this.SubstitutionListLength; i++)
+ {
+ this.SubstitutionList[i] = br.ReadNetworkText();
+ }
+ }
+ }
+
+ ///
+ /// Writes this instance to the given BinaryWriter.
+ ///
+ /// BinaryWriter to write contents to.
+ public void ToStream(BinaryWriter bw)
+ {
+ bw.Write(TextMode);
+ bw.Write(Text);
+ if (this.TextMode != (byte) Mode.Literal)
+ {
+ bw.Write(SubstitutionList.Length);
+
+ for (int i = 0; i < this.SubstitutionListLength; i++)
+ {
+ bw.Write(this.SubstitutionList[i]);
+ }
+ }
+ }
+
+ ///
+ /// Gets the length of the NetworkText object in bytes.
+ ///
+ /// The length in bytes.
+ public short GetLength()
+ {
+ short length = 1;
+
+ // Length of the text in bytes (Terraria only supports extended ASCII)
+ // Add 1 to accomodate for the string length byte
+ length += (short)(1 + (short)this.Text.Length);
+
+ if (this.TextMode != (byte) Mode.Literal)
+ {
+ length += 1;
+ for (int i = 0; i < this.SubstitutionListLength; i++)
+ {
+ length += this.SubstitutionList[i].GetLength();
+ }
+ }
+
+ return length;
+ }
+ }
+}
diff --git a/Multiplicity.Packets/ModifyTile.cs b/Multiplicity.Packets/ModifyTile.cs
index 90a2078..d3cbdc8 100644
--- a/Multiplicity.Packets/ModifyTile.cs
+++ b/Multiplicity.Packets/ModifyTile.cs
@@ -1,5 +1,6 @@
-using System;
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -10,9 +11,7 @@ public class ModifyTile : TerrariaPacket
{
///
- /// Gets or sets the Action - 0 = Kill Tile, 1 = Place Tile, 2 = Kill Wall, 3 = Place Wall, 4 = Kill Tile No Item, 5 = Place Wire
- /// 6 = Kill Wire, 7 = Pound Tile, 8 = Place Actuator, 9 = Kill Actuator, 10 = Place Wire2, 11 = Kill Wire2, 12 = Place Wire3, 13 = Kill Wire3
- /// 14 = Slope Tile, 15 = Frame Track, 16 = Place Wire4, 17 = Kill Wire4, 18 = Poke Logic Gate, 19 = Actuate
+ /// Gets or sets the Action - Values: 0 = KillTile, 1 = PlaceTile, 2 = KillWall, 3 = PlaceWall, 4 = KillTileNoItem, 5 = PlaceWire, 6 = KillWire, 7 = PoundTile, 8 = PlaceActuator, 9 = KillActuator, 10 = PlaceWire2, 11 = KillWire2, 12 = PlaceWire3, 13 = KillWire3, 14 = SlopeTile, 15 = FrameTrack, 16 = PlaceWire4, 17 = KillWire4, 18 = PokeLogicGate, 19 = Actuate|
///
public byte Action { get; set; }
@@ -20,15 +19,21 @@ public class ModifyTile : TerrariaPacket
public short TileY { get; set; }
- public short EditData { get; set; }
+ ///
+ /// Gets or sets the Var1 - KillTile (Fail: Bool), PlaceTile (Type: Byte), KillWall (Fail: Bool), PlaceWall (Type: Byte), KillTileNoItem (Fail: Bool), SlopeTile (Slope: Byte)|
+ ///
+ public short Var1 { get; set; }
- public byte Style { get; set; }
+ ///
+ /// Gets or sets the Var2 - Var2: PlaceTile (Style: Byte)|
+ ///
+ public byte Var2 { get; set; }
///
/// Initializes a new instance of the class.
///
- public ModifyTile()
- : base((byte)PacketTypes.ModifyTile)
+ public ModifyTile()
+ : base((byte)PacketTypes.ModifyTile)
{
}
@@ -37,19 +42,19 @@ public ModifyTile()
/// Initializes a new instance of the class.
///
/// br
- public ModifyTile(BinaryReader br)
+ public ModifyTile(BinaryReader br)
: base(br)
{
this.Action = br.ReadByte();
this.TileX = br.ReadInt16();
this.TileY = br.ReadInt16();
- this.EditData = br.ReadInt16();
- this.Style = br.ReadByte();
+ this.Var1 = br.ReadInt16();
+ this.Var2 = br.ReadByte();
}
public override string ToString()
{
- return $"[ModifyTile: Action = {Action} TileX = {TileX} TileY = {TileY} EditData = {EditData} Style = {Style}]";
+ return $"[ModifyTile: Action = {Action} TileX = {TileX} TileY = {TileY} Var1 = {Var1} Var2 = {Var2}]";
}
#region implemented abstract members of TerrariaPacket
@@ -64,7 +69,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -76,12 +82,13 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Action);
br.Write(TileX);
br.Write(TileY);
- br.Write(EditData);
- br.Write(Style);
+ br.Write(Var1);
+ br.Write(Var2);
}
}
diff --git a/Multiplicity.Packets/Multiplicity.Packets.csproj b/Multiplicity.Packets/Multiplicity.Packets.csproj
index 1fd5ae0..680d015 100644
--- a/Multiplicity.Packets/Multiplicity.Packets.csproj
+++ b/Multiplicity.Packets/Multiplicity.Packets.csproj
@@ -34,9 +34,10 @@
-
+
+
@@ -172,6 +173,11 @@
+
+
+ if not exist "$(ProjectDir)_BuildResult" mkdir "$(ProjectDir)_BuildResult"
+copy /Y "$(TargetDir)$(TargetName).dll" "$(ProjectDir)_BuildResult\$(TargetName).dll
+
\ No newline at end of file
diff --git a/Multiplicity.Packets/NPCHomeUpdate.cs b/Multiplicity.Packets/NPCHomeUpdate.cs
index 5aab499..9148078 100644
--- a/Multiplicity.Packets/NPCHomeUpdate.cs
+++ b/Multiplicity.Packets/NPCHomeUpdate.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -41,8 +42,7 @@ public NPCHomeUpdate(BinaryReader br)
public override string ToString()
{
- return
- $"[NPCHomeUpdate: NPCID = {NPCID} HomeTileX = {HomeTileX} HomeTileY = {HomeTileY} Homeless = {Homeless}]";
+ return $"[NPCHomeUpdate: NPCID = {NPCID} HomeTileX = {HomeTileX} HomeTileY = {HomeTileY} Homeless = {Homeless}]";
}
#region implemented abstract members of TerrariaPacket
@@ -57,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -69,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
br.Write(HomeTileX);
br.Write(HomeTileY);
diff --git a/Multiplicity.Packets/NPCStrike.cs b/Multiplicity.Packets/NPCStrike.cs
index 9548a86..a78a72e 100644
--- a/Multiplicity.Packets/NPCStrike.cs
+++ b/Multiplicity.Packets/NPCStrike.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -44,8 +45,7 @@ public NPCStrike(BinaryReader br)
public override string ToString()
{
- return
- $"[NPCStrike: NPCID = {NPCID} Damage = {Damage} Knockback = {Knockback} Direction = {Direction} Crit = {Crit}]";
+ return $"[NPCStrike: NPCID = {NPCID} Damage = {Damage} Knockback = {Knockback} Direction = {Direction} Crit = {Crit}]";
}
#region implemented abstract members of TerrariaPacket
@@ -60,7 +60,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -72,7 +73,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
br.Write(Damage);
br.Write(Knockback);
diff --git a/Multiplicity.Packets/NPCTeleportThroughPortal.cs b/Multiplicity.Packets/NPCTeleportThroughPortal.cs
index 543a49e..a1d88c1 100644
--- a/Multiplicity.Packets/NPCTeleportThroughPortal.cs
+++ b/Multiplicity.Packets/NPCTeleportThroughPortal.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,8 +48,7 @@ public NPCTeleportThroughPortal(BinaryReader br)
public override string ToString()
{
- return
- $"[NPCTeleportThroughPortal: NPCID = {NPCID} PortalColorIndex = {PortalColorIndex} NewPositionX = {NewPositionX} NewPositionY = {NewPositionY} VelocityX = {VelocityX} VelocityY = {VelocityY}]";
+ return $"[NPCTeleportThroughPortal: NPCID = {NPCID} PortalColorIndex = {PortalColorIndex} NewPositionX = {NewPositionX} NewPositionY = {NewPositionY} VelocityX = {VelocityX} VelocityY = {VelocityY}]";
}
#region implemented abstract members of TerrariaPacket
@@ -63,7 +63,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -75,7 +76,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
br.Write(PortalColorIndex);
br.Write(NewPositionX);
diff --git a/Multiplicity.Packets/NPCUpdate.cs b/Multiplicity.Packets/NPCUpdate.cs
index 0bd10a7..47a7062 100644
--- a/Multiplicity.Packets/NPCUpdate.cs
+++ b/Multiplicity.Packets/NPCUpdate.cs
@@ -1,5 +1,7 @@
using System;
+using System.Collections.Generic;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -19,10 +21,19 @@ public enum NPCUpdateFlags : byte
public class NPCUpdate : TerrariaPacket
{
- protected short _npcLifeBytes = 1;
- protected bool _releaseOwner = false;
+ public static readonly int[] NetIDMap = new int[]
+ {
+ 81,81,1,1,1,1,1,1,1,1,6,6,31,31,77,42,42,176,176,176,176,173,173,183,183,3,
+ 3,132,132,186,186,187,187,188,188,189,189,190,191,192,193,194,2,200,200,21,
+ 21,201,201,202,202,203,203,223,223,231,231,232,232,233,233,234,234,235,235
+ };
+ public static readonly HashSet npcCatchable = new HashSet()
+ {
+ 46,55,74,148,149,297,298,299,300,355,356,357,358,359,360,361,362,363,364,
+ 365,366,367,374,377,539,538,484,485,486,487,442,443,444,445,446,447,448
+ };
- public short NPCID { get; protected set; }
+ public short NPCID { get; set; }
public float PositionX { get; set; }
@@ -32,23 +43,26 @@ public class NPCUpdate : TerrariaPacket
public float VelocityY { get; set; }
- public byte Target { get; set; }
+ public ushort Target { get; set; }
- public NPCUpdateFlags Flags { get; set; }
-
- public int? Life { get; set; }
+ public byte Flags { get; set; }
public float[] AI { get; set; }
public short NPCNetID { get; set; }
+ public byte LifeBytes { get; set; }
+
+ public int Life { get; set; }
+
public byte ReleaseOwner { get; set; }
+ public int NPCType { get; set; }
+
public NPCUpdate()
: base((byte)PacketTypes.NPCUpdate)
{
- this.NPCID = NPCID;
- this.AI = new float[4];
+
}
public NPCUpdate(BinaryReader br)
@@ -59,92 +73,61 @@ public NPCUpdate(BinaryReader br)
this.PositionY = br.ReadSingle();
this.VelocityX = br.ReadSingle();
this.VelocityY = br.ReadSingle();
- this.Target = br.ReadByte();
- this.Flags = (NPCUpdateFlags)br.ReadByte();
-
+ this.Target = br.ReadUInt16();
+ this.Flags = br.ReadByte();
this.AI = new float[4];
-
- for (int i = 0; i < 4; i++)
- {
- float ai = 0;
-
- if (((byte)Flags & (1 << (i + 2))) != 0)
- {
- ai = br.ReadSingle();
- }
-
- AI[i] = ai;
- }
-
+ if (this.Flags.ReadBit(2))
+ this.AI[0] = br.ReadSingle();
+ if (this.Flags.ReadBit(3))
+ this.AI[1] = br.ReadSingle();
+ if (this.Flags.ReadBit(4))
+ this.AI[2] = br.ReadSingle();
+ if (this.Flags.ReadBit(5))
+ this.AI[3] = br.ReadSingle();
this.NPCNetID = br.ReadInt16();
-
- if ((Flags & NPCUpdateFlags.FullLife) == NPCUpdateFlags.None)
+ if (!this.Flags.ReadBit(7))
{
- /*
- * This is a fucking filthy hack, have to take stream length
- * as a way to work out how much packet buffer we have left
- * because the Terraria process has a runtime dictionary of NPC
- * life bytes which tells the packet processor how many bytes of
- * the NPC life there is in the packet.
- *
- * We don't have access to this information short of blurting
- * up our on dictionary of NPC life bytes in which I would rather
- * kill myself than do.
- */
- long bufferLeft = br.BaseStream.Length - br.BaseStream.Position;
-
- if (bufferLeft >= 4)
- {
- this.Life = (int)br.ReadInt32();
- _npcLifeBytes = 4;
- }
- else if (bufferLeft >= 2)
- {
- this.Life = (int)br.ReadInt16();
- _npcLifeBytes = 2;
- }
+ this.LifeBytes = br.ReadByte();
+ if (this.LifeBytes == 1)
+ this.Life = br.ReadByte();
+ else if (this.LifeBytes == 2)
+ this.Life = br.ReadInt16();
else
- {
- this.Life = (int)br.ReadSByte();
- _npcLifeBytes = 1;
- }
+ this.Life = br.ReadInt32();
}
-
- if (br.BaseStream.Length - br.BaseStream.Position > 0)
- {
- _releaseOwner = true;
+ this.NPCType = NPCTypeFromNetID(this.NPCNetID);
+ if (this.NPCType >= 0 && this.NPCType < 580 && npcCatchable.Contains((short)this.NPCType))
this.ReleaseOwner = br.ReadByte();
- }
}
- public override short GetLength()
+ public static int NPCTypeFromNetID(int id)
{
- short fixedLen = 22;
-
- /*
- * Dynamic packet sizes fucking suck balls
- */
-
- for (int i = 0; i < 4; i++)
+ if (id < 0)
{
- if (((byte)Flags & (1 << (i + 2))) != 0)
- {
- fixedLen += 4;
- }
- }
-
-
- if ((Flags & NPCUpdateFlags.FullLife) == NPCUpdateFlags.None)
- {
- fixedLen += _npcLifeBytes;
- }
-
- if (_releaseOwner)
- {
- fixedLen += 1;
+ return NetIDMap[-id - 1];
}
+ return id;
+ }
- return fixedLen;
+ public override short GetLength()
+ {
+ short length = 23;
+
+ if (this.Flags.ReadBit(2))
+ length++;
+ if (this.Flags.ReadBit(3))
+ length++;
+ if (this.Flags.ReadBit(4))
+ length++;
+ if (this.Flags.ReadBit(5))
+ length++;
+ if (!this.Flags.ReadBit(7))
+ length += (short)(1 + this.LifeBytes);
+ this.NPCType = NPCTypeFromNetID(this.NPCNetID);
+ if (this.NPCType >= 0 && this.NPCType < 580 && npcCatchable.Contains((short)this.NPCType))
+ length++;
+
+ return length;
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -159,45 +142,36 @@ public override void ToStream(Stream stream, bool includeHeader = true)
bw.Write(this.VelocityX);
bw.Write(this.VelocityY);
bw.Write(this.Target);
- bw.Write((byte)this.Flags);
-
- for (int i = 0; i < 4; i++)
- {
- if (((byte)Flags & (1 << (i + 2))) != 0)
- {
- bw.Write(AI[i]);
- }
- }
-
- bw.Write(NPCNetID);
-
- if ((Flags & NPCUpdateFlags.FullLife) == NPCUpdateFlags.None)
- {
- switch (_npcLifeBytes)
- {
- case 4:
- bw.Write(Life.Value);
- break;
- case 2:
- bw.Write((short)Life.Value);
- break;
- case 1:
- bw.Write((sbyte)Life.Value);
- break;
- }
- }
-
- if (_releaseOwner)
+ bw.Write(this.Flags);
+ if (this.Flags.ReadBit(2))
+ bw.Write(this.AI[0]);
+ if (this.Flags.ReadBit(3))
+ bw.Write(this.AI[1]);
+ if (this.Flags.ReadBit(4))
+ bw.Write(this.AI[2]);
+ if (this.Flags.ReadBit(5))
+ bw.Write(this.AI[3]);
+ bw.Write(this.NPCNetID);
+ if (!this.Flags.ReadBit(7))
{
- bw.Write(ReleaseOwner);
+ bw.Write(this.LifeBytes);
+ if (this.LifeBytes == 1)
+ bw.Write((byte)this.Life);
+ else if (this.LifeBytes == 2)
+ bw.Write((short)this.Life);
+ else
+ bw.Write((int)this.Life);
}
+ this.NPCType = NPCTypeFromNetID(this.NPCNetID);
+ if (this.NPCType >= 0 && this.NPCType < 580 && npcCatchable.Contains((short)this.NPCType))
+ bw.Write(this.ReleaseOwner);
}
}
public override string ToString()
{
- return string.Format("[NPCUpdate: NPCID={0}, PositionX={1}, PositionY={2}, VelocityX={3}, VelocityY={4}, Target={5}, Flags={6}, Life={7}, AI={8}, NPCNetID={9}, ReleaseOwner={10}]",
- NPCID, PositionX, PositionY, VelocityX, VelocityY, Target, Flags, Life, AI, NPCNetID, ReleaseOwner);
+ return string.Format("[NPCUpdate: NPCID={0}, PositionX={1}, PositionY={2}, VelocityX={3}, VelocityY={4}, Target={5}, Flags={6}]",
+ NPCID, PositionX, PositionY, VelocityX, VelocityY, Target, Flags);
}
}
}
diff --git a/Multiplicity.Packets/NebulaLevelUpRequest.cs b/Multiplicity.Packets/NebulaLevelUpRequest.cs
index f27807a..5efa1fa 100644
--- a/Multiplicity.Packets/NebulaLevelUpRequest.cs
+++ b/Multiplicity.Packets/NebulaLevelUpRequest.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -46,8 +48,7 @@ public NebulaLevelUpRequest(BinaryReader br)
public override string ToString()
{
- return
- $"[NebulaLevelUpRequest: PlayerID = {PlayerID} LevelUpType = {LevelUpType} OriginX = {OriginX} OriginY = {OriginY}]";
+ return $"[NebulaLevelUpRequest: PlayerID = {PlayerID} LevelUpType = {LevelUpType} OriginX = {OriginX} OriginY = {OriginY}]";
}
#region implemented abstract members of TerrariaPacket
@@ -62,7 +63,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -74,7 +76,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(LevelUpType);
br.Write(OriginX);
diff --git a/Multiplicity.Packets/NotifyPlayerNPCKilled.cs b/Multiplicity.Packets/NotifyPlayerNPCKilled.cs
index 50de270..eb1ac60 100644
--- a/Multiplicity.Packets/NotifyPlayerNPCKilled.cs
+++ b/Multiplicity.Packets/NotifyPlayerNPCKilled.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,7 +48,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -59,7 +61,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
}
}
diff --git a/Multiplicity.Packets/NotifyPlayerOfEvent.cs b/Multiplicity.Packets/NotifyPlayerOfEvent.cs
index fc734a2..72c9d10 100644
--- a/Multiplicity.Packets/NotifyPlayerOfEvent.cs
+++ b/Multiplicity.Packets/NotifyPlayerOfEvent.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,7 +48,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -59,7 +61,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(EventID);
}
}
diff --git a/Multiplicity.Packets/NumberOfAnglerQuestsCompleted.cs b/Multiplicity.Packets/NumberOfAnglerQuestsCompleted.cs
index fa88642..c182846 100644
--- a/Multiplicity.Packets/NumberOfAnglerQuestsCompleted.cs
+++ b/Multiplicity.Packets/NumberOfAnglerQuestsCompleted.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -35,8 +36,7 @@ public NumberOfAnglerQuestsCompleted(BinaryReader br)
public override string ToString()
{
- return
- $"[NumberOfAnglerQuestsCompleted: PlayerID = {PlayerID} AnglerQuestsCompleted = {AnglerQuestsCompleted}]";
+ return $"[NumberOfAnglerQuestsCompleted: PlayerID = {PlayerID} AnglerQuestsCompleted = {AnglerQuestsCompleted}]";
}
#region implemented abstract members of TerrariaPacket
@@ -51,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -63,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(AnglerQuestsCompleted);
}
diff --git a/Multiplicity.Packets/PacketTypes.cs b/Multiplicity.Packets/PacketTypes.cs
index 21b868e..2e681b2 100644
--- a/Multiplicity.Packets/PacketTypes.cs
+++ b/Multiplicity.Packets/PacketTypes.cs
@@ -119,7 +119,8 @@ public enum PacketTypes : byte
/*115*/ MinionAttackTargetUpdate,
/*116*/ CrystalInvasionSendWaitTime,
/*117*/ PlayerHurtV2,
- /*118*/ PlayerDeathV2
+ /*118*/ PlayerDeathV2,
+ /*119*/ CombatTextString
}
}
diff --git a/Multiplicity.Packets/PaintTile.cs b/Multiplicity.Packets/PaintTile.cs
index fa7d7b6..354646b 100644
--- a/Multiplicity.Packets/PaintTile.cs
+++ b/Multiplicity.Packets/PaintTile.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
br.Write(Color);
diff --git a/Multiplicity.Packets/PaintWall.cs b/Multiplicity.Packets/PaintWall.cs
index 103b50b..d82b9ce 100644
--- a/Multiplicity.Packets/PaintWall.cs
+++ b/Multiplicity.Packets/PaintWall.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
br.Write(Color);
diff --git a/Multiplicity.Packets/PlaceChest.cs b/Multiplicity.Packets/PlaceChest.cs
index c28d1de..02b9f22 100644
--- a/Multiplicity.Packets/PlaceChest.cs
+++ b/Multiplicity.Packets/PlaceChest.cs
@@ -1,62 +1,80 @@
-using System.IO;
+using System;
+using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
- ///
- /// The PlaceChest (34) packet.
- ///
- public class PlaceChest : TerrariaPacket
- {
- public byte Action { get; set; }
- public short X { get; set; }
- public short Y { get; set; }
- public short Style { get; set; }
- public short ChestID { get; set; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- public PlaceChest() : base((byte)PacketTypes.PlaceChest) { }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// br
- public PlaceChest(BinaryReader br)
- : base(br)
- {
- Action = br.ReadByte();
- X = br.ReadInt16();
- Y = br.ReadInt16();
- Style = br.ReadInt16();
-
- //ID = br.ReadInt16();
- ChestID = 0; //TODO: Client detection? This is particular field is server->client only
- }
-
- public override string ToString()
- {
- return $"[{nameof(PlaceChest)}: Action={Action},X={X},Y={Y},Style={Style}]";
- }
-
- #region implemented abstract members of TerrariaPacket
-
- public override short GetLength()
- {
- return (short)(7);
- }
-
- public override void ToStream(Stream stream, bool includeHeader = true)
- {
- /*
+ ///
+ /// The PlaceChest (0x22) packet.
+ ///
+ public class PlaceChest : TerrariaPacket
+ {
+
+ ///
+ /// Gets or sets the ChestID - BitFlags:0 = Place Chest, 1 = Kill Chest, 2 = Place Dresser, 3 = Kill Dresser. 4 = Place Containers2, 5 = Kill Containers2|
+ ///
+ public byte ChestID { get; set; }
+
+ public short TileX { get; set; }
+
+ public short TileY { get; set; }
+
+ ///
+ /// Gets or sets the Style - FrameX(Chest type)|
+ ///
+ public short Style { get; set; }
+
+ ///
+ /// Gets or sets the ChestIDtodestroy - ID if client is receiving packet, else 0|
+ ///
+ public short ChestIDtodestroy { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public PlaceChest()
+ : base((byte)PacketTypes.PlaceChest)
+ {
+
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// br
+ public PlaceChest(BinaryReader br)
+ : base(br)
+ {
+ this.ChestID = br.ReadByte();
+ this.TileX = br.ReadInt16();
+ this.TileY = br.ReadInt16();
+ this.Style = br.ReadInt16();
+ this.ChestIDtodestroy = br.ReadInt16();
+ }
+
+ public override string ToString()
+ {
+ return $"[PlaceChest: ChestID = {ChestID} TileX = {TileX} TileY = {TileY} Style = {Style} ChestIDtodestroy = {ChestIDtodestroy}]";
+ }
+
+ #region implemented abstract members of TerrariaPacket
+
+ public override short GetLength()
+ {
+ return (short)(9);
+ }
+
+ public override void ToStream(Stream stream, bool includeHeader = true)
+ {
+ /*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader)
- {
- base.ToStream(stream, includeHeader);
- }
+ if (includeHeader)
+ {
+ base.ToStream(stream, includeHeader);
+ }
- /*
+ /*
* Always make sure to not close the stream when serializing.
*
* It is up to the caller to decide if the underlying stream
@@ -64,16 +82,17 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter writer = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
- {
- writer.Write(Action);
- writer.Write(X);
- writer.Write(Y);
- writer.Write(Style);
- writer.Write(ChestID);
- }
- }
-
- #endregion
- }
-}
\ No newline at end of file
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
+ br.Write(ChestID);
+ br.Write(TileX);
+ br.Write(TileY);
+ br.Write(Style);
+ br.Write(ChestIDtodestroy);
+ }
+ }
+
+ #endregion
+
+ }
+}
diff --git a/Multiplicity.Packets/PlaceItemFrame.cs b/Multiplicity.Packets/PlaceItemFrame.cs
index 6eb35b6..7b1e3ca 100644
--- a/Multiplicity.Packets/PlaceItemFrame.cs
+++ b/Multiplicity.Packets/PlaceItemFrame.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -59,7 +60,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -71,7 +73,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
br.Write(ItemId);
diff --git a/Multiplicity.Packets/PlaceObject.cs b/Multiplicity.Packets/PlaceObject.cs
index 29c6369..b0fdd4e 100644
--- a/Multiplicity.Packets/PlaceObject.cs
+++ b/Multiplicity.Packets/PlaceObject.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,8 +51,7 @@ public PlaceObject(BinaryReader br)
public override string ToString()
{
- return
- $"[PlaceObject: X = {X} Y = {Y} Type = {Type} Style = {Style} Alternate = {Alternate} Random = {Random} Direction = {Direction}]";
+ return $"[PlaceObject: X = {X} Y = {Y} Type = {Type} Style = {Style} Alternate = {Alternate} Random = {Random} Direction = {Direction}]";
}
#region implemented abstract members of TerrariaPacket
@@ -66,7 +66,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -78,7 +79,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
br.Write(Type);
diff --git a/Multiplicity.Packets/PlaceTileEntity.cs b/Multiplicity.Packets/PlaceTileEntity.cs
index 263ad14..3b70dec 100644
--- a/Multiplicity.Packets/PlaceTileEntity.cs
+++ b/Multiplicity.Packets/PlaceTileEntity.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -56,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
br.Write(Type);
diff --git a/Multiplicity.Packets/PlayMusicItem.cs b/Multiplicity.Packets/PlayMusicItem.cs
index daa4a3e..5f8a49b 100644
--- a/Multiplicity.Packets/PlayMusicItem.cs
+++ b/Multiplicity.Packets/PlayMusicItem.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -49,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -61,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Note);
}
diff --git a/Multiplicity.Packets/PlayerActive.cs b/Multiplicity.Packets/PlayerActive.cs
index 01ce93e..5a25333 100644
--- a/Multiplicity.Packets/PlayerActive.cs
+++ b/Multiplicity.Packets/PlayerActive.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Active);
}
diff --git a/Multiplicity.Packets/PlayerDeathV2.cs b/Multiplicity.Packets/PlayerDeathV2.cs
index a190646..ba3716e 100644
--- a/Multiplicity.Packets/PlayerDeathV2.cs
+++ b/Multiplicity.Packets/PlayerDeathV2.cs
@@ -8,8 +8,6 @@ namespace Multiplicity.Packets
///
public class PlayerDeathV2 : TerrariaPacket
{
- private int _packetLength;
-
public byte PlayerId { get; set; }
///
@@ -87,52 +85,21 @@ public PlayerDeathV2(BinaryReader br)
PlayerDeathReason = br.ReadByte();
if (PlayerDeathReason.ReadBit(0))
- {
FromPlayerIndex = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(1))
- {
FromNpcIndex = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(2))
- {
FromProjectileIndex = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(3))
- {
FromOther = br.ReadByte();
- _packetLength += 1;
- }
-
if (PlayerDeathReason.ReadBit(4))
- {
FromProjectileType = br.ReadInt16();
- _length += 2;
- }
-
if (PlayerDeathReason.ReadBit(5))
- {
FromItemType = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(6))
- {
FromItemPrefix = br.ReadByte();
- _packetLength += 1;
- }
-
if (PlayerDeathReason.ReadBit(7))
- {
FromCustomReason = br.ReadString();
- _packetLength += FromCustomReason.Length;
- }
Damage = br.ReadInt16();
HitDirection = br.ReadByte();
@@ -149,7 +116,24 @@ public override string ToString()
public override short GetLength()
{
- return (short)(6 + _length);
+ int _packetLength = 0;
+ if (PlayerDeathReason.ReadBit(0))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(1))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(2))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(3))
+ _packetLength += 1;
+ if (PlayerDeathReason.ReadBit(4))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(5))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(6))
+ _packetLength += 1;
+ if (PlayerDeathReason.ReadBit(7))
+ _packetLength += 1 + FromCustomReason.Length;
+ return (short)(6 + _packetLength);
}
public override void ToStream(Stream stream, bool includeHeader = true)
diff --git a/Multiplicity.Packets/PlayerDodge.cs b/Multiplicity.Packets/PlayerDodge.cs
index 10f4154..d798662 100644
--- a/Multiplicity.Packets/PlayerDodge.cs
+++ b/Multiplicity.Packets/PlayerDodge.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -52,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -64,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Flag);
}
diff --git a/Multiplicity.Packets/PlayerHP.cs b/Multiplicity.Packets/PlayerHP.cs
index b36694e..f008e80 100644
--- a/Multiplicity.Packets/PlayerHP.cs
+++ b/Multiplicity.Packets/PlayerHP.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(HP);
br.Write(MaxHP);
diff --git a/Multiplicity.Packets/PlayerHurtV2.cs b/Multiplicity.Packets/PlayerHurtV2.cs
index 6465327..3d79c7e 100644
--- a/Multiplicity.Packets/PlayerHurtV2.cs
+++ b/Multiplicity.Packets/PlayerHurtV2.cs
@@ -8,8 +8,6 @@ namespace Multiplicity.Packets
///
public class PlayerHurtV2 : TerrariaPacket
{
- private int _packetLength;
-
public byte PlayerId { get; set; }
///
@@ -68,7 +66,7 @@ public class PlayerHurtV2 : TerrariaPacket
///
public byte Flags { get; set; }
- public byte CooldownCounter { get; set; }
+ public sbyte CooldownCounter { get; set; }
///
/// Initializes a new instance of the class.
@@ -90,56 +88,26 @@ public PlayerHurtV2(BinaryReader br)
PlayerDeathReason = br.ReadByte();
if (PlayerDeathReason.ReadBit(0))
- {
FromPlayerIndex = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(1))
- {
FromNpcIndex = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(2))
- {
FromProjectileIndex = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(3))
- {
FromOther = br.ReadByte();
- _packetLength += 1;
- }
-
if (PlayerDeathReason.ReadBit(4))
- {
FromProjectileType = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(5))
- {
FromItemType = br.ReadInt16();
- _packetLength += 2;
- }
-
if (PlayerDeathReason.ReadBit(6))
- {
FromItemPrefix = br.ReadByte();
- _packetLength += 1;
- }
-
if (PlayerDeathReason.ReadBit(7))
- {
FromCustomReason = br.ReadString();
- _packetLength += FromCustomReason.Length;
- }
Damage = br.ReadInt16();
HitDirection = br.ReadByte();
Flags = br.ReadByte();
+ CooldownCounter = br.ReadSByte();
}
public override string ToString()
@@ -152,7 +120,24 @@ public override string ToString()
public override short GetLength()
{
- return (short)(6 + _length);
+ int _packetLength = 0;
+ if (PlayerDeathReason.ReadBit(0))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(1))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(2))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(3))
+ _packetLength += 1;
+ if (PlayerDeathReason.ReadBit(4))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(5))
+ _packetLength += 2;
+ if (PlayerDeathReason.ReadBit(6))
+ _packetLength += 1;
+ if (PlayerDeathReason.ReadBit(7))
+ _packetLength += 1 + FromCustomReason.Length;
+ return (short)(7 + _packetLength);
}
public override void ToStream(Stream stream, bool includeHeader = true)
diff --git a/Multiplicity.Packets/PlayerInfo.cs b/Multiplicity.Packets/PlayerInfo.cs
index 33f076c..a88917f 100644
--- a/Multiplicity.Packets/PlayerInfo.cs
+++ b/Multiplicity.Packets/PlayerInfo.cs
@@ -1,6 +1,7 @@
-using System.Drawing;
+using System;
using System.IO;
using Multiplicity.Packets.Extensions;
+using System.Drawing;
namespace Multiplicity.Packets
{
@@ -29,19 +30,19 @@ public class PlayerInfo : TerrariaPacket
public byte HideMisc { get; set; }
- public Color HairColor { get; set; }
+ public ColorStruct HairColor { get; set; }
- public Color SkinColor { get; set; }
+ public ColorStruct SkinColor { get; set; }
- public Color EyeColor { get; set; }
+ public ColorStruct EyeColor { get; set; }
- public Color ShirtColor { get; set; }
+ public ColorStruct ShirtColor { get; set; }
- public Color UnderShirtColor { get; set; }
+ public ColorStruct UnderShirtColor { get; set; }
- public Color PantsColor { get; set; }
+ public ColorStruct PantsColor { get; set; }
- public Color ShoeColor { get; set; }
+ public ColorStruct ShoeColor { get; set; }
public byte Difficulty { get; set; }
@@ -81,8 +82,7 @@ public PlayerInfo(BinaryReader br)
public override string ToString()
{
- return
- $"[PlayerInfo: PlayerID = {PlayerID} SkinVarient = {SkinVarient} Hair = {Hair} Name = {Name} HairDye = {HairDye} HideVisuals = {HideVisuals} HideVisuals2 = {HideVisuals2} HideMisc = {HideMisc} HairColor = {HairColor} SkinColor = {SkinColor} EyeColor = {EyeColor} ShirtColor = {ShirtColor} UnderShirtColor = {UnderShirtColor} PantsColor = {PantsColor} ShoeColor = {ShoeColor} Difficulty = {Difficulty}]";
+ return $"[PlayerInfo: PlayerID = {PlayerID} SkinVarient = {SkinVarient} Hair = {Hair} Name = {Name} HairDye = {HairDye} HideVisuals = {HideVisuals} HideVisuals2 = {HideVisuals2} HideMisc = {HideMisc} HairColor = {HairColor} SkinColor = {SkinColor} EyeColor = {EyeColor} ShirtColor = {ShirtColor} UnderShirtColor = {UnderShirtColor} PantsColor = {PantsColor} ShoeColor = {ShoeColor} Difficulty = {Difficulty}]";
}
#region implemented abstract members of TerrariaPacket
@@ -97,7 +97,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -109,7 +110,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(SkinVarient);
br.Write(Hair);
diff --git a/Multiplicity.Packets/PlayerInventorySlot.cs b/Multiplicity.Packets/PlayerInventorySlot.cs
index 5aa3b8f..d23b018 100644
--- a/Multiplicity.Packets/PlayerInventorySlot.cs
+++ b/Multiplicity.Packets/PlayerInventorySlot.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,8 +48,7 @@ public PlayerInventorySlot(BinaryReader br)
public override string ToString()
{
- return
- $"[PlayerInventorySlot: PlayerID = {PlayerID} SlotID = {SlotID} Stack = {Stack} Prefix = {Prefix} ItemNetID = {ItemNetID}]";
+ return $"[PlayerInventorySlot: PlayerID = {PlayerID} SlotID = {SlotID} Stack = {Stack} Prefix = {Prefix} ItemNetID = {ItemNetID}]";
}
#region implemented abstract members of TerrariaPacket
@@ -63,7 +63,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -75,7 +76,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(SlotID);
br.Write(Stack);
diff --git a/Multiplicity.Packets/PlayerItemAnimation.cs b/Multiplicity.Packets/PlayerItemAnimation.cs
index 50215e1..4f9b06d 100644
--- a/Multiplicity.Packets/PlayerItemAnimation.cs
+++ b/Multiplicity.Packets/PlayerItemAnimation.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -38,8 +39,7 @@ public PlayerItemAnimation(BinaryReader br)
public override string ToString()
{
- return
- $"[PlayerItemAnimation: PlayerID = {PlayerID} ItemRotation = {ItemRotation} ItemAnimation = {ItemAnimation}]";
+ return $"[PlayerItemAnimation: PlayerID = {PlayerID} ItemRotation = {ItemRotation} ItemAnimation = {ItemAnimation}]";
}
#region implemented abstract members of TerrariaPacket
@@ -54,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -66,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(ItemRotation);
br.Write(ItemAnimation);
diff --git a/Multiplicity.Packets/PlayerMana.cs b/Multiplicity.Packets/PlayerMana.cs
index 2b74058..51fced3 100644
--- a/Multiplicity.Packets/PlayerMana.cs
+++ b/Multiplicity.Packets/PlayerMana.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Mana);
br.Write(MaxMana);
diff --git a/Multiplicity.Packets/PlayerNPCTeleport.cs b/Multiplicity.Packets/PlayerNPCTeleport.cs
index 817c6c2..545df8e 100644
--- a/Multiplicity.Packets/PlayerNPCTeleport.cs
+++ b/Multiplicity.Packets/PlayerNPCTeleport.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -59,7 +60,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -71,7 +73,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Flags);
br.Write(TargetID);
br.Write(X);
diff --git a/Multiplicity.Packets/PlayerTeam.cs b/Multiplicity.Packets/PlayerTeam.cs
index 8cda465..21f1cb5 100644
--- a/Multiplicity.Packets/PlayerTeam.cs
+++ b/Multiplicity.Packets/PlayerTeam.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -49,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -61,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Team);
}
diff --git a/Multiplicity.Packets/PlayerTeleportThroughPortal.cs b/Multiplicity.Packets/PlayerTeleportThroughPortal.cs
index f3b2183..7e3a809 100644
--- a/Multiplicity.Packets/PlayerTeleportThroughPortal.cs
+++ b/Multiplicity.Packets/PlayerTeleportThroughPortal.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,8 +48,7 @@ public PlayerTeleportThroughPortal(BinaryReader br)
public override string ToString()
{
- return
- $"[PlayerTeleportThroughPortal: PlayerID = {PlayerID} PortalColorIndex = {PortalColorIndex} NewPositionX = {NewPositionX} NewPositionY = {NewPositionY} VelocityX = {VelocityX} VelocityY = {VelocityY}]";
+ return $"[PlayerTeleportThroughPortal: PlayerID = {PlayerID} PortalColorIndex = {PortalColorIndex} NewPositionX = {NewPositionX} NewPositionY = {NewPositionY} VelocityX = {VelocityX} VelocityY = {VelocityY}]";
}
#region implemented abstract members of TerrariaPacket
@@ -63,7 +63,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -75,7 +76,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(PortalColorIndex);
br.Write(NewPositionX);
diff --git a/Multiplicity.Packets/PlayerZone.cs b/Multiplicity.Packets/PlayerZone.cs
index 768f9d4..a143e64 100644
--- a/Multiplicity.Packets/PlayerZone.cs
+++ b/Multiplicity.Packets/PlayerZone.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -20,6 +22,16 @@ public class PlayerZone : TerrariaPacket
///
public byte Zone2 { get; set; }
+ ///
+ /// Gets or sets the Zone3 - 1 = Overworld, 2 = Dirt Layer, 4 = Rock Layer, 8 = Underworld, 16 = Beach, 32 = Rain, 64 = Sandstorm|
+ ///
+ public byte Zone3 { get; set; }
+
+ ///
+ /// Gets or sets the Zone4 - 1 = Old One's Army|
+ ///
+ public byte Zone4 { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -39,18 +51,20 @@ public PlayerZone(BinaryReader br)
this.PlayerID = br.ReadByte();
this.Zone1 = br.ReadByte();
this.Zone2 = br.ReadByte();
+ this.Zone3 = br.ReadByte();
+ this.Zone4 = br.ReadByte();
}
public override string ToString()
{
- return $"[PlayerZone: PlayerID = {PlayerID} Zone1 = {Zone1} Zone2 = {Zone2}]";
+ return $"[PlayerZone: PlayerID = {PlayerID} Zone1 = {Zone1} Zone2 = {Zone2} Zone3 = {Zone3} Zone4 = {Zone4}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(3);
+ return (short)(5);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -58,7 +72,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -70,10 +85,13 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Zone1);
br.Write(Zone2);
+ br.Write(Zone3);
+ br.Write(Zone4);
}
}
diff --git a/Multiplicity.Packets/PoofofSmoke.cs b/Multiplicity.Packets/PoofofSmoke.cs
index 888f5ba..187d18e 100644
--- a/Multiplicity.Packets/PoofofSmoke.cs
+++ b/Multiplicity.Packets/PoofofSmoke.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PackedVector);
}
}
diff --git a/Multiplicity.Packets/ProjectileUpdate.cs b/Multiplicity.Packets/ProjectileUpdate.cs
index 7ba832a..9fd5779 100644
--- a/Multiplicity.Packets/ProjectileUpdate.cs
+++ b/Multiplicity.Packets/ProjectileUpdate.cs
@@ -1,175 +1,121 @@
-using System.IO;
+using System;
+using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
- ///
- /// The ProjectileUpdate (27) packet.
- ///
- public class ProjectileUpdate : TerrariaPacket
- {
- //Always sent
- public short ProjectileID { get; set; }
- public float PositionX { get; set; }
- public float PositionY { get; set; }
- public float VelocityX { get; set; }
- public float VelocityY { get; set; }
- public float KnockBack { get; set; }
- public short Damage { get; set; }
- public byte Owner { get; set; }
- public short Type { get; set; }
- public AIFlags Flags { get; set; }
-
- //Sent conditionally
- public float[] AI { get; set; }
- public short UUID { get; set; }
-
- public const int MaxAI = 2;
-
- public bool HasAI0
- {
- get
- {
- return (this.Flags & AIFlags.AI0) != 0;
- }
- set
- {
- if (value)
- {
- this.Flags |= AIFlags.AI0;
- }
- else
- {
- this.Flags &= ~AIFlags.AI0;
- }
- }
- }
-
- public bool HasAI1
- {
- get
- {
- return (this.Flags & AIFlags.AI1) != 0;
- }
- set
- {
- if (value)
- {
- this.Flags |= AIFlags.AI1;
- }
- else
- {
- this.Flags &= ~AIFlags.AI1;
- }
- }
- }
-
- public bool HasUUID
- {
- get
- {
- return (this.Flags & AIFlags.HasUUID) != 0;
- }
- set
- {
- if (value)
- {
- this.Flags |= AIFlags.HasUUID;
- }
- else
- {
- this.Flags &= ~AIFlags.HasUUID;
- }
- }
- }
-
- [System.Flags]
- public enum AIFlags : byte
- {
- AI0 = 1,
- AI1 = 2,
- HasUUID = 4
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- public ProjectileUpdate()
- : base((byte)PacketTypes.ProjectileUpdate)
- {
-
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// br
- public ProjectileUpdate(BinaryReader br)
- : base(br)
- {
- this.ProjectileID = br.ReadInt16();
- this.PositionX = br.ReadSingle();
- this.PositionY = br.ReadSingle();
- this.VelocityX = br.ReadSingle();
- this.VelocityY = br.ReadSingle();
- this.KnockBack = br.ReadSingle();
- this.Damage = br.ReadInt16();
- this.Owner = br.ReadByte();
- this.Type = br.ReadInt16();
- this.Flags = (AIFlags)br.ReadByte();
-
- this.AI = new float[MaxAI];
- for (var i = 0; i < MaxAI; i++)
- {
- if (((byte)this.Flags & (1 << i)) != 0)
- {
- this.AI[i] = br.ReadSingle();
- }
- else
- {
- this.AI[i] = 0f;
- }
- }
-
- if (HasUUID)
- {
- this.UUID = br.ReadInt16();
- }
- }
-
- public override string ToString()
- {
- return $"[{nameof(ProjectileUpdate)}: ProjectileID={ProjectileID},PositionX={PositionX}," +
- $"PositionY={PositionY},VelocityX={VelocityX},VelocityY={VelocityY},KnockBack={KnockBack}," +
- $"Damage={Damage},Owner={Owner},Type={Type},Flags={Flags},UUID={UUID}]";
- }
-
- #region implemented abstract members of TerrariaPacket
-
- public override short GetLength()
- {
- short length = 28;
-
- if (HasAI0)
- length += 4;
- if (HasAI1)
- length += 4;
- if (HasUUID)
- length += 2;
-
- return length;
- }
-
- public override void ToStream(Stream stream, bool includeHeader = true)
- {
- /*
+ ///
+ /// The ProjectileUpdate (0x1B) packet.
+ ///
+ public class ProjectileUpdate : TerrariaPacket
+ {
+
+ public short ProjectileID { get; set; }
+
+ public float PositionX { get; set; }
+
+ public float PositionY { get; set; }
+
+ public float VelocityX { get; set; }
+
+ public float VelocityY { get; set; }
+
+ public float KnockBack { get; set; }
+
+ public short Damage { get; set; }
+
+ ///
+ /// Gets or sets the Owner - Player ID|
+ ///
+ public byte Owner { get; set; }
+
+ public short Type { get; set; }
+
+ ///
+ /// Gets or sets the AIFlags - BitFlags: 0 = AI[0] is Present, 1 = AI[1] is Present, 2 = Needs UUID|
+ ///
+ public byte AIFlags { get; set; }
+
+ ///
+ /// Gets or sets the AI0 - Requires the AI0 flag to be set in order to be sent down the wire|
+ ///
+ public float AI0 { get; set; }
+
+ ///
+ /// Gets or sets the AI1 - Requires the AI1 flag to be set in order to be sent down the wire|
+ ///
+ public float AI1 { get; set; }
+
+ ///
+ /// Gets or sets the ProjUUID - Requires the Needs UUID flag to be set in order to be sent down the wire|
+ ///
+ public short ProjUUID { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public ProjectileUpdate()
+ : base((byte)PacketTypes.ProjectileUpdate)
+ {
+
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// br
+ public ProjectileUpdate(BinaryReader br)
+ : base(br)
+ {
+ this.ProjectileID = br.ReadInt16();
+ this.PositionX = br.ReadSingle();
+ this.PositionY = br.ReadSingle();
+ this.VelocityX = br.ReadSingle();
+ this.VelocityY = br.ReadSingle();
+ this.KnockBack = br.ReadSingle();
+ this.Damage = br.ReadInt16();
+ this.Owner = br.ReadByte();
+ this.Type = br.ReadInt16();
+ this.AIFlags = br.ReadByte();
+
+ if (this.AIFlags.ReadBit(0))
+ this.AI0 = br.ReadSingle();
+ if (this.AIFlags.ReadBit(1))
+ this.AI1 = br.ReadSingle();
+ if (this.AIFlags.ReadBit(2))
+ this.ProjUUID = br.ReadInt16();
+ }
+
+ public override string ToString()
+ {
+ return $"[ProjectileUpdate: ProjectileID = {ProjectileID} PositionX = {PositionX} PositionY = {PositionY} VelocityX = {VelocityX} VelocityY = {VelocityY} KnockBack = {KnockBack} Damage = {Damage} Owner = {Owner} Type = {Type} AIFlags = {AIFlags} AI0 = {AI0} AI1 = {AI1} ProjUUID = {ProjUUID}]";
+ }
+
+ #region implemented abstract members of TerrariaPacket
+
+ public override short GetLength()
+ {
+ byte length = 28;
+ if (this.AIFlags.ReadBit(0))
+ length += 4;
+ if (this.AIFlags.ReadBit(1))
+ length += 4;
+ if (this.AIFlags.ReadBit(2))
+ length += 2;
+ return (short)(length);
+ }
+
+ public override void ToStream(Stream stream, bool includeHeader = true)
+ {
+ /*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader)
- {
- base.ToStream(stream, includeHeader);
- }
+ if (includeHeader)
+ {
+ base.ToStream(stream, includeHeader);
+ }
- /*
+ /*
* Always make sure to not close the stream when serializing.
*
* It is up to the caller to decide if the underlying stream
@@ -177,34 +123,28 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter writer = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
- {
- writer.Write(ProjectileID);
- writer.Write(PositionX);
- writer.Write(PositionY);
- writer.Write(VelocityX);
- writer.Write(VelocityY);
- writer.Write(KnockBack);
- writer.Write(Damage);
- writer.Write(Owner);
- writer.Write(Type);
- writer.Write((byte)Flags);
-
- for (var i = 0; i < MaxAI; i++)
- {
- if (((byte)this.Flags & (1 << i)) != 0)
- {
- writer.Write(this.AI[i]);
- }
- }
-
- if (HasUUID)
- {
- writer.Write(this.UUID);
- }
- }
- }
-
- #endregion
- }
-}
\ No newline at end of file
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
+ br.Write(ProjectileID);
+ br.Write(PositionX);
+ br.Write(PositionY);
+ br.Write(VelocityX);
+ br.Write(VelocityY);
+ br.Write(KnockBack);
+ br.Write(Damage);
+ br.Write(Owner);
+ br.Write(Type);
+ br.Write(AIFlags);
+ if (this.AIFlags.ReadBit(0))
+ br.Write(AI0);
+ if (this.AIFlags.ReadBit(1))
+ br.Write(AI1);
+ if (this.AIFlags.ReadBit(2))
+ br.Write(ProjUUID);
+ }
+ }
+
+ #endregion
+
+ }
+}
diff --git a/Multiplicity.Packets/ReleaseNPC.cs b/Multiplicity.Packets/ReleaseNPC.cs
index a697cb1..62ad2a2 100644
--- a/Multiplicity.Packets/ReleaseNPC.cs
+++ b/Multiplicity.Packets/ReleaseNPC.cs
@@ -1,5 +1,6 @@
-using System;
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -13,14 +14,17 @@ public class ReleaseNPC : TerrariaPacket
public int Y { get; set; }
- public short Type { get; set; }
+ public short NPCType { get; set; }
+ ///
+ /// Gets or sets the Style - Sent to NPC AI[2]|
+ ///
public byte Style { get; set; }
///
/// Initializes a new instance of the class.
///
- public ReleaseNPC()
+ public ReleaseNPC()
: base((byte)PacketTypes.ReleaseNPC)
{
@@ -30,18 +34,18 @@ public ReleaseNPC()
/// Initializes a new instance of the class.
///
/// br
- public ReleaseNPC(BinaryReader br)
+ public ReleaseNPC(BinaryReader br)
: base(br)
{
this.X = br.ReadInt32();
this.Y = br.ReadInt32();
- this.Type = br.ReadInt16();
+ this.NPCType = br.ReadInt16();
this.Style = br.ReadByte();
}
public override string ToString()
{
- return $"[ReleaseNPC: X = {X} Y = {Y} Type = {Type} Style = {Style}]";
+ return $"[ReleaseNPC: X = {X} Y = {Y} NPCType = {NPCType} Style = {Style}]";
}
#region implemented abstract members of TerrariaPacket
@@ -56,7 +60,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,10 +73,11 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
- br.Write(Type);
+ br.Write(NPCType);
br.Write(Style);
}
}
diff --git a/Multiplicity.Packets/RemoveItemOwner.cs b/Multiplicity.Packets/RemoveItemOwner.cs
index dc92804..3b4d783 100644
--- a/Multiplicity.Packets/RemoveItemOwner.cs
+++ b/Multiplicity.Packets/RemoveItemOwner.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,7 +48,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -59,7 +61,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(ItemIndex);
}
}
diff --git a/Multiplicity.Packets/ReportInvasionProgress.cs b/Multiplicity.Packets/ReportInvasionProgress.cs
index 6e8d0c3..4254702 100644
--- a/Multiplicity.Packets/ReportInvasionProgress.cs
+++ b/Multiplicity.Packets/ReportInvasionProgress.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -41,8 +42,7 @@ public ReportInvasionProgress(BinaryReader br)
public override string ToString()
{
- return
- $"[ReportInvasionProgress: Progress = {Progress} MaxProgress = {MaxProgress} Icon = {Icon} Wave = {Wave}]";
+ return $"[ReportInvasionProgress: Progress = {Progress} MaxProgress = {MaxProgress} Icon = {Icon} Wave = {Wave}]";
}
#region implemented abstract members of TerrariaPacket
@@ -57,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -69,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Progress);
br.Write(MaxProgress);
br.Write(Icon);
diff --git a/Multiplicity.Packets/RequestPassword.cs b/Multiplicity.Packets/RequestPassword.cs
index 1b45fbe..67a9f32 100644
--- a/Multiplicity.Packets/RequestPassword.cs
+++ b/Multiplicity.Packets/RequestPassword.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -28,7 +30,7 @@ public RequestPassword(BinaryReader br)
public override string ToString()
{
- return string.Format("[RequestPassword]");
+ return $"[RequestPassword:]";
}
#region implemented abstract members of TerrariaPacket
@@ -43,7 +45,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -55,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
}
}
diff --git a/Multiplicity.Packets/RequestSign.cs b/Multiplicity.Packets/RequestSign.cs
index 5e8761f..b9a5b24 100644
--- a/Multiplicity.Packets/RequestSign.cs
+++ b/Multiplicity.Packets/RequestSign.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
}
diff --git a/Multiplicity.Packets/SectionTileFrame.cs b/Multiplicity.Packets/SectionTileFrame.cs
index 78fa1f2..0942e2f 100644
--- a/Multiplicity.Packets/SectionTileFrame.cs
+++ b/Multiplicity.Packets/SectionTileFrame.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -56,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(StartX);
br.Write(StartY);
br.Write(EndX);
diff --git a/Multiplicity.Packets/SendPassword.cs b/Multiplicity.Packets/SendPassword.cs
index 2b02a76..608314e 100644
--- a/Multiplicity.Packets/SendPassword.cs
+++ b/Multiplicity.Packets/SendPassword.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -46,7 +48,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -58,7 +61,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Password);
}
}
diff --git a/Multiplicity.Packets/SendSection.cs b/Multiplicity.Packets/SendSection.cs
index 1ebfa7c..004331e 100644
--- a/Multiplicity.Packets/SendSection.cs
+++ b/Multiplicity.Packets/SendSection.cs
@@ -9,16 +9,6 @@ namespace Multiplicity.Packets
public class SendSection : TerrariaPacket
{
- public bool Compressed { get; set; }
-
- public int XStart { get; set; }
-
- public int YStart { get; set; }
-
- public short Width { get; set; }
-
- public short Height { get; set; }
-
public byte[] TilePayload { get; set; }
///
@@ -68,10 +58,7 @@ public SendSection(BinaryReader br)
}
*/
- this.XStart = br.ReadInt32();
- this.YStart = br.ReadInt32();
- this.Width = br.ReadInt16();
- this.Height = br.ReadInt16();
+ // I hate myself for this, but there's no easy way to check if compressed and read the packet
this.TilePayload = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
}
@@ -79,14 +66,14 @@ public SendSection(BinaryReader br)
public override string ToString()
{
return
- $"[SendSection Compressed: {Compressed}, X: {XStart}, Y: {YStart}, Width: {Width}, Height: {Height} TileData: {TilePayload.Length/1024:0.###} kB]";
+ $"[SendSection Compressed: TileData: {TilePayload.Length/1024:0.###} kB]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short) (13 + TilePayload.Length);
+ return (short) (TilePayload.Length);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -108,11 +95,6 @@ public override void ToStream(Stream stream, bool includeHeader = true)
*/
using (BinaryWriter bw = new BinaryWriter(stream, System.Text.Encoding.UTF8, leaveOpen: true))
{
- bw.Write(Compressed);
- bw.Write(XStart);
- bw.Write(YStart);
- bw.Write(Width);
- bw.Write(Height);
bw.Write(TilePayload);
}
}
diff --git a/Multiplicity.Packets/SendTileSquare.cs b/Multiplicity.Packets/SendTileSquare.cs
index c791ff7..6658fe3 100644
--- a/Multiplicity.Packets/SendTileSquare.cs
+++ b/Multiplicity.Packets/SendTileSquare.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -9,12 +10,21 @@ namespace Multiplicity.Packets
public class SendTileSquare : TerrariaPacket
{
+ public ushort PlayerID { get; set; }
+
+ ///
+ /// Gets or sets the TileChangeType - Only if != 0|
+ ///
+ public byte TileChangeType { get; set; }
+
public short Size { get; set; }
public short TileX { get; set; }
public short TileY { get; set; }
+ public byte[] TilePayload { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -31,21 +41,31 @@ public SendTileSquare()
public SendTileSquare(BinaryReader br)
: base(br)
{
+ this.PlayerID = br.ReadUInt16();
+
+ int num24 = 32768;
+ int num25 = (uint)(this.PlayerID & num24) > 0U ? 1 : 0;
+
+ if (num25 != 0)
+ this.TileChangeType = br.ReadByte();
+
this.Size = br.ReadInt16();
this.TileX = br.ReadInt16();
this.TileY = br.ReadInt16();
+
+ this.TilePayload = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
}
public override string ToString()
{
- return $"[SendTileSquare: Size = {Size} TileX = {TileX} TileY = {TileY}]";
+ return $"[SendTileSquare: PlayerID = {PlayerID} TileChangeType = {TileChangeType} Size = {Size} TileX = {TileX} TileY = {TileY} TileData: {TilePayload.Length / 1024:0.###} kB]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(6);
+ return (short)(9 + TilePayload.Length);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -53,7 +73,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,10 +86,20 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
+ br.Write(PlayerID);
+
+ int num24 = 32768;
+ int num25 = (uint)(this.PlayerID & num24) > 0U ? 1 : 0;
+
+ if (num25 != 0)
+ br.Write(TileChangeType);
+
br.Write(Size);
br.Write(TileX);
br.Write(TileY);
+ br.Write(TilePayload);
}
}
diff --git a/Multiplicity.Packets/SetActiveNPC.cs b/Multiplicity.Packets/SetActiveNPC.cs
index fb6fcc8..3d0da60 100644
--- a/Multiplicity.Packets/SetActiveNPC.cs
+++ b/Multiplicity.Packets/SetActiveNPC.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(NpcTalkTarget);
}
diff --git a/Multiplicity.Packets/SetChestName.cs b/Multiplicity.Packets/SetChestName.cs
index a42c0b0..3afb15f 100644
--- a/Multiplicity.Packets/SetChestName.cs
+++ b/Multiplicity.Packets/SetChestName.cs
@@ -1,74 +1,79 @@
-using System;
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
- ///
- /// The SetChestName (33) packet.
- ///
- public class SetChestName : TerrariaPacket
- {
- public short ChestID { get; set; }
- public short X { get; set; }
- public short Y { get; set; }
- public byte NameLength { get; set; }
- public string Name { get; set; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- public SetChestName() : base((byte)PacketTypes.SetChestName) { }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// br
- public SetChestName(BinaryReader br)
- : base(br)
- {
- ChestID = br.ReadInt16();
-
- X = br.ReadInt16();
- Y = br.ReadInt16();
- NameLength = br.ReadByte();
- Name = String.Empty;
-
- if (NameLength != 0)
- {
- if (NameLength <= 20)
- Name = br.ReadString();
- else if (NameLength != 255)
- NameLength = 0;
- }
- }
-
- public override string ToString()
- {
- return $"[{nameof(SetChestName)}: ChestID={ChestID},X={X},Y={Y},TextLength={NameLength},Text={Name}]";
- }
-
- #region implemented abstract members of TerrariaPacket
-
- public override short GetLength()
- {
- const short Length = 7;
- if (Name == null)
- return Length;
-
- return (short)(Length + Name.Length);
- }
-
- public override void ToStream(Stream stream, bool includeHeader = true)
- {
- /*
+ ///
+ /// The SetChestName (0x21) packet.
+ ///
+ public class SetChestName : TerrariaPacket
+ {
+
+ public short ChestID { get; set; }
+
+ public short ChestX { get; set; }
+
+ public short ChestY { get; set; }
+
+ public byte NameLength { get; set; }
+
+ ///
+ /// Gets or sets the ChestName - Only if length > 0 && <= 20|
+ ///
+ public string ChestName { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public SetChestName()
+ : base((byte)PacketTypes.SetChestName)
+ {
+
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// br
+ public SetChestName(BinaryReader br)
+ : base(br)
+ {
+ this.ChestID = br.ReadInt16();
+ this.ChestX = br.ReadInt16();
+ this.ChestY = br.ReadInt16();
+ this.NameLength = br.ReadByte();
+ this.ChestName = String.Empty;
+
+ if (this.NameLength >= 0 && this.NameLength <= 20)
+ this.ChestName = br.ReadString();
+ else
+ this.NameLength = 0;
+ }
+
+ public override string ToString()
+ {
+ return $"[SetChestName: ChestID = {ChestID} ChestX = {ChestX} ChestY = {ChestY} NameLength = {NameLength} ChestName = {ChestName}]";
+ }
+
+ #region implemented abstract members of TerrariaPacket
+
+ public override short GetLength()
+ {
+ return (short)(8 + ChestName?.Length);
+ }
+
+ public override void ToStream(Stream stream, bool includeHeader = true)
+ {
+ /*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader)
- {
- base.ToStream(stream, includeHeader);
- }
+ if (includeHeader)
+ {
+ base.ToStream(stream, includeHeader);
+ }
- /*
+ /*
* Always make sure to not close the stream when serializing.
*
* It is up to the caller to decide if the underlying stream
@@ -76,19 +81,19 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter writer = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
- {
- writer.Write(ChestID);
- writer.Write(X);
- writer.Write(Y);
- if (Name != null)
- {
- writer.Write(NameLength);
- writer.Write(Name);
- }
- }
- }
-
- #endregion
- }
-}
\ No newline at end of file
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
+ br.Write(ChestID);
+ br.Write(ChestX);
+ br.Write(ChestY);
+ NameLength = (byte)ChestName?.Length;
+ br.Write(NameLength);
+ if (ChestName != null)
+ br.Write(ChestName);
+ }
+ }
+
+ #endregion
+
+ }
+}
diff --git a/Multiplicity.Packets/SetLiquid.cs b/Multiplicity.Packets/SetLiquid.cs
index 9a6b37b..708c285 100644
--- a/Multiplicity.Packets/SetLiquid.cs
+++ b/Multiplicity.Packets/SetLiquid.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -56,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
br.Write(Liquid);
diff --git a/Multiplicity.Packets/SetNPCKillCount.cs b/Multiplicity.Packets/SetNPCKillCount.cs
index e6b9cc1..d8f91c0 100644
--- a/Multiplicity.Packets/SetNPCKillCount.cs
+++ b/Multiplicity.Packets/SetNPCKillCount.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCType);
br.Write(KillCount);
}
diff --git a/Multiplicity.Packets/SetNPCShopItem.cs b/Multiplicity.Packets/SetNPCShopItem.cs
index b5fe31a..57eb1bf 100644
--- a/Multiplicity.Packets/SetNPCShopItem.cs
+++ b/Multiplicity.Packets/SetNPCShopItem.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,8 +51,7 @@ public SetNPCShopItem(BinaryReader br)
public override string ToString()
{
- return
- $"[SetNPCShopItem: Slot = {Slot} ItemType = {ItemType} Stack = {Stack} Prefix = {Prefix} Value = {Value} Flags = {Flags}]";
+ return $"[SetNPCShopItem: Slot = {Slot} ItemType = {ItemType} Stack = {Stack} Prefix = {Prefix} Value = {Value} Flags = {Flags}]";
}
#region implemented abstract members of TerrariaPacket
@@ -66,7 +66,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -78,7 +79,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Slot);
br.Write(ItemType);
br.Write(Stack);
diff --git a/Multiplicity.Packets/SetPlayerStealth.cs b/Multiplicity.Packets/SetPlayerStealth.cs
index 3842265..a159250 100644
--- a/Multiplicity.Packets/SetPlayerStealth.cs
+++ b/Multiplicity.Packets/SetPlayerStealth.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -49,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -61,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Player);
br.Write(Stealth);
}
diff --git a/Multiplicity.Packets/SocialHandshake.cs b/Multiplicity.Packets/SocialHandshake.cs
index 55e2a62..e073053 100644
--- a/Multiplicity.Packets/SocialHandshake.cs
+++ b/Multiplicity.Packets/SocialHandshake.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -28,7 +30,7 @@ public SocialHandshake(BinaryReader br)
public override string ToString()
{
- return string.Format("[SocialHandshake]");
+ return $"[SocialHandshake:]";
}
#region implemented abstract members of TerrariaPacket
@@ -43,7 +45,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -55,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
}
}
diff --git a/Multiplicity.Packets/SpawnBossInvasion.cs b/Multiplicity.Packets/SpawnBossInvasion.cs
index bfcf0e1..fb108e3 100644
--- a/Multiplicity.Packets/SpawnBossInvasion.cs
+++ b/Multiplicity.Packets/SpawnBossInvasion.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Type);
}
diff --git a/Multiplicity.Packets/SpawnPlayer.cs b/Multiplicity.Packets/SpawnPlayer.cs
index ca87211..953c0e4 100644
--- a/Multiplicity.Packets/SpawnPlayer.cs
+++ b/Multiplicity.Packets/SpawnPlayer.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(SpawnX);
br.Write(SpawnY);
diff --git a/Multiplicity.Packets/SpecialNPCEffect.cs b/Multiplicity.Packets/SpecialNPCEffect.cs
index 6794052..4ee8249 100644
--- a/Multiplicity.Packets/SpecialNPCEffect.cs
+++ b/Multiplicity.Packets/SpecialNPCEffect.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -52,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -64,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(Type);
}
diff --git a/Multiplicity.Packets/Status.cs b/Multiplicity.Packets/Status.cs
index bff8220..f02a73f 100644
--- a/Multiplicity.Packets/Status.cs
+++ b/Multiplicity.Packets/Status.cs
@@ -1,5 +1,7 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
+using Multiplicity.Packets.Models;
namespace Multiplicity.Packets
{
@@ -14,7 +16,7 @@ public class Status : TerrariaPacket
///
public int StatusMax { get; set; }
- public string StatusText { get; set; }
+ public NetworkText StatusText { get; set; }
///
/// Initializes a new instance of the class.
@@ -33,19 +35,19 @@ public Status(BinaryReader br)
: base(br)
{
this.StatusMax = br.ReadInt32();
- this.StatusText = br.ReadString();
+ this.StatusText = br.ReadNetworkText();
}
public override string ToString()
{
- return $"[Status: StatusMax = {StatusMax} StatusText = {StatusText}]";
+ return $"[Status: StatusMax = {StatusMax} StatusText = {StatusText.Text}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(5 + StatusText.Length);
+ return (short)(4 + StatusText.GetLength());
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -53,7 +55,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +68,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(StatusMax);
br.Write(StatusText);
}
diff --git a/Multiplicity.Packets/StrikeNPCwithHeldItem.cs b/Multiplicity.Packets/StrikeNPCwithHeldItem.cs
index ffd0c9c..32ebd86 100644
--- a/Multiplicity.Packets/StrikeNPCwithHeldItem.cs
+++ b/Multiplicity.Packets/StrikeNPCwithHeldItem.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
br.Write(PlayerID);
}
diff --git a/Multiplicity.Packets/SyncEmoteBubble.cs b/Multiplicity.Packets/SyncEmoteBubble.cs
index 4442738..2e4b4cc 100644
--- a/Multiplicity.Packets/SyncEmoteBubble.cs
+++ b/Multiplicity.Packets/SyncEmoteBubble.cs
@@ -1,5 +1,6 @@
-using System;
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -13,21 +14,30 @@ public class SyncEmoteBubble : TerrariaPacket
public byte AnchorType { get; set; }
+ ///
+ /// Gets or sets the MetaData - Only if AnchorType != 255|
+ ///
public ushort MetaData { get; set; }
- public byte LifeTime { get; set; }
-
- public byte Emote { get; set; }
+ ///
+ /// Gets or sets the Lifetime - Only if AnchorType != 255|
+ ///
+ public byte Lifetime { get; set; }
///
- /// Only sent if Emote is less than 0
+ /// Gets or sets the Emote - Only if AnchorType != 255|
///
- public short MetaData2 { get; set; }
+ public byte Emote { get; set; }
+
+ ///
+ /// Gets or sets the EmoteMetaData - Only sent if AnchorType != 255 and Emote < 0|
+ ///
+ public short EmoteMetaData { get; set; }
///
/// Initializes a new instance of the class.
///
- public SyncEmoteBubble()
+ public SyncEmoteBubble()
: base((byte)PacketTypes.SyncEmoteBubble)
{
@@ -36,28 +46,41 @@ public SyncEmoteBubble()
///
/// Initializes a new instance of the class.
///
- ///
- public SyncEmoteBubble(BinaryReader br)
+ /// br
+ public SyncEmoteBubble(BinaryReader br)
: base(br)
{
- this.EmoteID = br.ReadInt32();
- this.AnchorType = br.ReadByte();
- this.MetaData = br.ReadUInt16();
- this.LifeTime = br.ReadByte();
- this.Emote = br.ReadByte();
- this.MetaData2 = br.ReadInt16();
+ this.EmoteID = br.ReadInt32();
+ this.AnchorType = br.ReadByte();
+ if (this.AnchorType != 255)
+ {
+ this.MetaData = br.ReadUInt16();
+ this.Lifetime = br.ReadByte();
+ this.Emote = br.ReadByte();
+ if (this.Emote < 0)
+ this.EmoteMetaData = br.ReadInt16();
+ }
+
}
public override string ToString()
{
- return $"[SyncEmoteBubble: EmoteID = {EmoteID} AnchorType = {AnchorType} MetaData = {MetaData} LifeTime = {LifeTime} Emote = {Emote} MetaData2 = {MetaData2}]";
+ return $"[SyncEmoteBubble: EmoteID = {EmoteID} AnchorType = {AnchorType} MetaData = {MetaData} Lifetime = {Lifetime} Emote = {Emote} EmoteMetaData = {EmoteMetaData}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(11);
+ short length = 5;
+
+ if (this.AnchorType != 255)
+ {
+ length += 4;
+ if (this.Emote < 0)
+ length += 2;
+ }
+ return length;
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -65,7 +88,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -77,18 +101,22 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(EmoteID);
br.Write(AnchorType);
- br.Write(MetaData);
- br.Write(LifeTime);
- br.Write(Emote);
- br.Write(MetaData2);
+ if (this.AnchorType != 255)
+ {
+ br.Write(MetaData);
+ br.Write(Lifetime);
+ br.Write(Emote);
+ if (this.Emote < 0)
+ br.Write(EmoteMetaData);
+ }
}
}
#endregion
-
}
}
diff --git a/Multiplicity.Packets/SyncExtraValue.cs b/Multiplicity.Packets/SyncExtraValue.cs
index 7731b6e..cba8ee3 100644
--- a/Multiplicity.Packets/SyncExtraValue.cs
+++ b/Multiplicity.Packets/SyncExtraValue.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -56,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCIndex);
br.Write(ExtraValue);
br.Write(X);
diff --git a/Multiplicity.Packets/SyncPlayerChestIndex.cs b/Multiplicity.Packets/SyncPlayerChestIndex.cs
index ce5d1a8..e6ffca6 100644
--- a/Multiplicity.Packets/SyncPlayerChestIndex.cs
+++ b/Multiplicity.Packets/SyncPlayerChestIndex.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Player);
br.Write(Chest);
}
diff --git a/Multiplicity.Packets/TeleportationPotion.cs b/Multiplicity.Packets/TeleportationPotion.cs
index 4527509..bfa3e50 100644
--- a/Multiplicity.Packets/TeleportationPotion.cs
+++ b/Multiplicity.Packets/TeleportationPotion.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -28,7 +30,7 @@ public TeleportationPotion(BinaryReader br)
public override string ToString()
{
- return string.Format("[TeleportationPotion]");
+ return $"[TeleportationPotion:]";
}
#region implemented abstract members of TerrariaPacket
@@ -43,7 +45,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -55,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
}
}
diff --git a/Multiplicity.Packets/TerrariaPacket.cs b/Multiplicity.Packets/TerrariaPacket.cs
index e2b7ed6..1087ed6 100644
--- a/Multiplicity.Packets/TerrariaPacket.cs
+++ b/Multiplicity.Packets/TerrariaPacket.cs
@@ -140,7 +140,8 @@ public abstract class TerrariaPacket : TerrariaNetworkObject
/*115*/ { PacketTypes.MinionAttackTargetUpdate, (br) => new MinionAttackTargetUpdate(br) },
/*116*/ { PacketTypes.CrystalInvasionSendWaitTime, (br) => new CrystalInvasionSendWaitTime(br) },
/*117*/ { PacketTypes.PlayerHurtV2, (br) => new PlayerHurtV2(br) },
- /*118*/ { PacketTypes.PlayerDeathV2, (br) => new PlayerDeathV2(br) }
+ /*118*/ { PacketTypes.PlayerDeathV2, (br) => new PlayerDeathV2(br) },
+ /*119*/ { PacketTypes.CombatTextString, (br) => new CombatTextString(br) }
};
///
diff --git a/Multiplicity.Packets/Time.cs b/Multiplicity.Packets/Time.cs
index 1870a51..ba41fa7 100644
--- a/Multiplicity.Packets/Time.cs
+++ b/Multiplicity.Packets/Time.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -56,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(DayTime);
br.Write(TimeValue);
br.Write(SunModY);
diff --git a/Multiplicity.Packets/ToggleBirthdayParty.cs b/Multiplicity.Packets/ToggleBirthdayParty.cs
index 27c5452..f2159fa 100644
--- a/Multiplicity.Packets/ToggleBirthdayParty.cs
+++ b/Multiplicity.Packets/ToggleBirthdayParty.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -28,7 +30,7 @@ public ToggleBirthdayParty(BinaryReader br)
public override string ToString()
{
- return string.Format("[ToggleBirthdayParty]");
+ return $"[ToggleBirthdayParty:]";
}
#region implemented abstract members of TerrariaPacket
@@ -43,7 +45,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -55,7 +58,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
}
}
diff --git a/Multiplicity.Packets/ToggleGemLock.cs b/Multiplicity.Packets/ToggleGemLock.cs
index e517af3..33d6ded 100644
--- a/Multiplicity.Packets/ToggleGemLock.cs
+++ b/Multiplicity.Packets/ToggleGemLock.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(X);
br.Write(Y);
br.Write(On);
diff --git a/Multiplicity.Packets/TogglePVP.cs b/Multiplicity.Packets/TogglePVP.cs
index d3d1b77..b1d036f 100644
--- a/Multiplicity.Packets/TogglePVP.cs
+++ b/Multiplicity.Packets/TogglePVP.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(PVPEnabled);
}
diff --git a/Multiplicity.Packets/TravellingMerchantInventory.cs b/Multiplicity.Packets/TravellingMerchantInventory.cs
index 604b16a..e9cafcd 100644
--- a/Multiplicity.Packets/TravellingMerchantInventory.cs
+++ b/Multiplicity.Packets/TravellingMerchantInventory.cs
@@ -8,6 +8,8 @@ namespace Multiplicity.Packets
public class TravellingMerchantInventory : TerrariaPacket
{
+ public short[] Items { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -24,6 +26,9 @@ public TravellingMerchantInventory()
public TravellingMerchantInventory(BinaryReader br)
: base(br)
{
+ Items = new short[40];
+ for (int i = 0; i < 40; i++)
+ Items[i] = br.ReadInt16();
}
public override string ToString()
@@ -35,7 +40,7 @@ public override string ToString()
public override short GetLength()
{
- return (short)(0);
+ return (short)(80);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -55,7 +60,10 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
+ for (int i = 0; i < 40; i++)
+ br.Write(Items[i]);
}
}
diff --git a/Multiplicity.Packets/Unlock.cs b/Multiplicity.Packets/Unlock.cs
index d911637..3ad7a26 100644
--- a/Multiplicity.Packets/Unlock.cs
+++ b/Multiplicity.Packets/Unlock.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -56,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -68,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Type);
br.Write(X);
br.Write(Y);
diff --git a/Multiplicity.Packets/UpdateGoodEvil.cs b/Multiplicity.Packets/UpdateGoodEvil.cs
index 8186870..5fd9f8b 100644
--- a/Multiplicity.Packets/UpdateGoodEvil.cs
+++ b/Multiplicity.Packets/UpdateGoodEvil.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -52,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -64,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Good);
br.Write(Evil);
br.Write(Crimson);
diff --git a/Multiplicity.Packets/UpdateItemDrop.cs b/Multiplicity.Packets/UpdateItemDrop.cs
index fd50dee..2f4ea8a 100644
--- a/Multiplicity.Packets/UpdateItemDrop.cs
+++ b/Multiplicity.Packets/UpdateItemDrop.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -62,8 +63,7 @@ public UpdateItemDrop(BinaryReader br)
public override string ToString()
{
- return
- $"[UpdateItemDrop: ItemID = {ItemID} PositionX = {PositionX} PositionY = {PositionY} VelocityX = {VelocityX} VelocityY = {VelocityY} StackSize = {StackSize} Prefix = {Prefix} NoDelay = {NoDelay} ItemNetID = {ItemNetID}]";
+ return $"[UpdateItemDrop: ItemID = {ItemID} PositionX = {PositionX} PositionY = {PositionY} VelocityX = {VelocityX} VelocityY = {VelocityY} StackSize = {StackSize} Prefix = {Prefix} NoDelay = {NoDelay} ItemNetID = {ItemNetID}]";
}
#region implemented abstract members of TerrariaPacket
@@ -78,7 +78,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -90,7 +91,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(ItemID);
br.Write(PositionX);
br.Write(PositionY);
diff --git a/Multiplicity.Packets/UpdateItemDrop2.cs b/Multiplicity.Packets/UpdateItemDrop2.cs
index 0b400d1..66a524e 100644
--- a/Multiplicity.Packets/UpdateItemDrop2.cs
+++ b/Multiplicity.Packets/UpdateItemDrop2.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -62,8 +63,7 @@ public UpdateItemDrop2(BinaryReader br)
public override string ToString()
{
- return
- $"[UpdateItemDrop2: ItemID = {ItemID} PositionX = {PositionX} PositionY = {PositionY} VelocityX = {VelocityX} VelocityY = {VelocityY} StackSize = {StackSize} Prefix = {Prefix} NoDelay = {NoDelay} ItemNetID = {ItemNetID}]";
+ return $"[UpdateItemDrop2: ItemID = {ItemID} PositionX = {PositionX} PositionY = {PositionY} VelocityX = {VelocityX} VelocityY = {VelocityY} StackSize = {StackSize} Prefix = {Prefix} NoDelay = {NoDelay} ItemNetID = {ItemNetID}]";
}
#region implemented abstract members of TerrariaPacket
@@ -78,7 +78,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -90,7 +91,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(ItemID);
br.Write(PositionX);
br.Write(PositionY);
diff --git a/Multiplicity.Packets/UpdateItemOwner.cs b/Multiplicity.Packets/UpdateItemOwner.cs
index d27d1bb..dcfa6f5 100644
--- a/Multiplicity.Packets/UpdateItemOwner.cs
+++ b/Multiplicity.Packets/UpdateItemOwner.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -50,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -62,7 +64,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(ItemID);
br.Write(PlayerID);
}
diff --git a/Multiplicity.Packets/UpdateMinionTarget.cs b/Multiplicity.Packets/UpdateMinionTarget.cs
index 6a939d9..5a07c46 100644
--- a/Multiplicity.Packets/UpdateMinionTarget.cs
+++ b/Multiplicity.Packets/UpdateMinionTarget.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -52,7 +54,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -64,7 +67,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
br.Write(TargetX);
br.Write(TargetY);
diff --git a/Multiplicity.Packets/UpdateMoonLordCountdown.cs b/Multiplicity.Packets/UpdateMoonLordCountdown.cs
index 9c08789..69b6195 100644
--- a/Multiplicity.Packets/UpdateMoonLordCountdown.cs
+++ b/Multiplicity.Packets/UpdateMoonLordCountdown.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -47,7 +48,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -59,7 +61,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(MoonLordCountdown);
}
}
diff --git a/Multiplicity.Packets/UpdateNPCBuff.cs b/Multiplicity.Packets/UpdateNPCBuff.cs
index 10791fc..10c7f31 100644
--- a/Multiplicity.Packets/UpdateNPCBuff.cs
+++ b/Multiplicity.Packets/UpdateNPCBuff.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -15,6 +16,22 @@ public class UpdateNPCBuff : TerrariaPacket
public short Time { get; set; }
+ public byte BuffID2 { get; set; }
+
+ public short Time2 { get; set; }
+
+ public byte BuffID3 { get; set; }
+
+ public short Time3 { get; set; }
+
+ public byte BuffID4 { get; set; }
+
+ public short Time4 { get; set; }
+
+ public byte BuffID5 { get; set; }
+
+ public short Time5 { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -34,18 +51,26 @@ public UpdateNPCBuff(BinaryReader br)
this.NPCID = br.ReadInt16();
this.BuffID = br.ReadByte();
this.Time = br.ReadInt16();
+ this.BuffID2 = br.ReadByte();
+ this.Time2 = br.ReadInt16();
+ this.BuffID3 = br.ReadByte();
+ this.Time3 = br.ReadInt16();
+ this.BuffID4 = br.ReadByte();
+ this.Time4 = br.ReadInt16();
+ this.BuffID5 = br.ReadByte();
+ this.Time5 = br.ReadInt16();
}
public override string ToString()
{
- return $"[UpdateNPCBuff: NPCID = {NPCID} BuffID = {BuffID} Time = {Time}]";
+ return $"[UpdateNPCBuff: NPCID = {NPCID} BuffID = {BuffID} Time = {Time} BuffID2 = {BuffID2} Time2 = {Time2} BuffID3 = {BuffID3} Time3 = {Time3} BuffID4 = {BuffID4} Time4 = {Time4} BuffID5 = {BuffID5} Time5 = {Time5}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(5);
+ return (short)(17);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -53,7 +78,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,10 +91,19 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
br.Write(BuffID);
br.Write(Time);
+ br.Write(BuffID2);
+ br.Write(Time2);
+ br.Write(BuffID3);
+ br.Write(Time3);
+ br.Write(BuffID4);
+ br.Write(Time4);
+ br.Write(BuffID5);
+ br.Write(Time5);
}
}
diff --git a/Multiplicity.Packets/UpdateNPCName.cs b/Multiplicity.Packets/UpdateNPCName.cs
index ca4c7bd..deb3f98 100644
--- a/Multiplicity.Packets/UpdateNPCName.cs
+++ b/Multiplicity.Packets/UpdateNPCName.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -12,7 +13,7 @@ public class UpdateNPCName : TerrariaPacket
public short NPCID { get; set; }
///
- /// Gets or sets the Name - Read-only from the client|
+ /// Gets or sets the Name - Only if client is receiving packet|
///
public string Name { get; set; }
@@ -33,7 +34,10 @@ public UpdateNPCName(BinaryReader br)
: base(br)
{
this.NPCID = br.ReadInt16();
- this.Name = br.ReadString();
+
+ if (br.BaseStream.Length > br.BaseStream.Position) {
+ this.Name = br.ReadString();
+ }
}
public override string ToString()
@@ -45,7 +49,12 @@ public override string ToString()
public override short GetLength()
{
- return (short)(3 + Name.Length);
+ int length = 2;
+
+ if (!string.IsNullOrEmpty(Name)) {
+ length += 1 + Name.Length;
+ }
+ return (short)length;
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -53,7 +62,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -65,9 +75,13 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(NPCID);
- br.Write(Name);
+ if (!string.IsNullOrEmpty(Name))
+ {
+ br.Write(Name);
+ }
}
}
diff --git a/Multiplicity.Packets/UpdatePlayer.cs b/Multiplicity.Packets/UpdatePlayer.cs
index 17bf1d7..9622da7 100644
--- a/Multiplicity.Packets/UpdatePlayer.cs
+++ b/Multiplicity.Packets/UpdatePlayer.cs
@@ -1,86 +1,124 @@
-using System;
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
- [Flags]
- public enum PlayerControlFlags : byte
- {
- None = 0,
- Up = 1,
- Down = 1 << 1,
- Left = 1 << 2,
- Right = 1 << 3,
- Jump = 1 << 4,
- UseItem = 1 << 5,
- Direction = 1 << 6
- }
-
- [Flags]
- public enum PulleyDirectionFlags : byte
- {
- None = 0,
- Direction1 = 1,
- Direction2 = 1 << 1
- }
-
- public class UpdatePlayer : TerrariaPacket
- {
- public byte PlayerID { get; protected set; }
- public PlayerControlFlags Control { get; set; }
- public byte SelectedItem { get; set; }
- public float PositionX { get; set; }
- public float PositionY { get; set; }
- public float VelocityX { get; set; }
- public float VelocityY { get; set; }
- public PulleyDirectionFlags Pulley { get; set; }
-
- public UpdatePlayer()
- : base((byte)PacketTypes.UpdatePlayer)
- {
-
- }
-
- public UpdatePlayer(BinaryReader br)
- : base(br)
- {
- PlayerID = br.ReadByte();
- Control = (PlayerControlFlags)br.ReadByte();
- SelectedItem = br.ReadByte();
- PositionX = br.ReadSingle();
- PositionY = br.ReadSingle();
- VelocityX = br.ReadSingle();
- VelocityY = br.ReadSingle();
- Pulley = (PulleyDirectionFlags)br.ReadByte();
- }
-
- public override short GetLength()
- {
- return 20;
- }
-
- public override void ToStream(Stream stream, bool includeHeader = true)
- {
- base.ToStream(stream, includeHeader);
-
- using (BinaryWriter bw = new BinaryWriter(stream, System.Text.Encoding.UTF8, leaveOpen: true))
- {
- bw.Write(PlayerID);
- bw.Write((byte)Control);
- bw.Write(SelectedItem);
- bw.Write(PositionX);
- bw.Write(PositionY);
- bw.Write(VelocityX);
- bw.Write(VelocityY);
- bw.Write((byte)Pulley);
- }
- }
-
- public override string ToString()
- {
- return
- $"[UpdatePlayer: PlayerID={PlayerID}, Control={Control}, SelectedItem={SelectedItem}, PositionX={PositionX}, PositionY={PositionY}, VelocityX={VelocityX}, VelocityY={VelocityY}, Pulley={Pulley}]";
- }
- }
-}
+ ///
+ /// The UpdatePlayer (0xD) packet.
+ ///
+ public class UpdatePlayer : TerrariaPacket
+ {
+
+ public byte PlayerID { get; set; }
+
+ ///
+ /// Gets or sets the Control - BitFlags: ControlUp = 1, ControlDown = 2, ControlLeft = 4, ControlRight = 8, ControlJump = 16, ControlUseItem = 32, Direction = 64|
+ ///
+ public byte Control { get; set; }
+
+ ///
+ /// Gets or sets the Pulley - BitFlags: 0 = None, 1 = Direction, 2 = Direction, 4 = Update Velocity, 8 = Vortex Stealth Active, 16 = Gravity Direction, 32 = Shield Raised|
+ ///
+ public byte Pulley { get; set; }
+
+ public byte SelectedItem { get; set; }
+
+ public float PositionX { get; set; }
+
+ public float PositionY { get; set; }
+
+ ///
+ /// Gets or sets the VelocityX - Not sent if Update Velocity is not set|
+ ///
+ public float VelocityX { get; set; }
+
+ ///
+ /// Gets or sets the VelocityY - Not sent if Update Velocity is not set|
+ ///
+ public float VelocityY { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public UpdatePlayer()
+ : base((byte)PacketTypes.UpdatePlayer)
+ {
+
+ }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// br
+ public UpdatePlayer(BinaryReader br)
+ : base(br)
+ {
+ this.PlayerID = br.ReadByte();
+ this.Control = br.ReadByte();
+ this.Pulley = br.ReadByte();
+ this.SelectedItem = br.ReadByte();
+ this.PositionX = br.ReadSingle();
+ this.PositionY = br.ReadSingle();
+
+ if (this.Pulley.ReadBit(2))
+ {
+ this.VelocityX = br.ReadSingle();
+ this.VelocityY = br.ReadSingle();
+ }
+ }
+
+ public override string ToString()
+ {
+ return $"[UpdatePlayer: PlayerID = {PlayerID} Control = {Control} Pulley = {Pulley} SelectedItem = {SelectedItem} PositionX = {PositionX} PositionY = {PositionY} VelocityX = {VelocityX} VelocityY = {VelocityY}]";
+ }
+
+ #region implemented abstract members of TerrariaPacket
+
+ public override short GetLength()
+ {
+ byte length = 12;
+ if (Pulley.ReadBit(2))
+ length += 8;
+ return (short)(length);
+ }
+
+ public override void ToStream(Stream stream, bool includeHeader = true)
+ {
+ /*
+ * Length and ID headers get written in the base packet class.
+ */
+ if (includeHeader)
+ {
+ base.ToStream(stream, includeHeader);
+ }
+
+ /*
+ * Always make sure to not close the stream when serializing.
+ *
+ * It is up to the caller to decide if the underlying stream
+ * gets closed. If this is a network stream we do not want
+ * the regressions of unconditionally closing the TCP socket
+ * once the payload of data has been sent to the client.
+ */
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
+ br.Write(PlayerID);
+ br.Write(Control);
+ br.Write(Pulley);
+ br.Write(SelectedItem);
+ br.Write(PositionX);
+ br.Write(PositionY);
+
+ if (this.Pulley.ReadBit(2))
+ {
+ br.Write(VelocityX);
+ br.Write(VelocityY);
+ }
+ }
+ }
+
+ #endregion
+
+ }
+}
diff --git a/Multiplicity.Packets/UpdatePlayerBuff.cs b/Multiplicity.Packets/UpdatePlayerBuff.cs
index 57f8956..2e93b23 100644
--- a/Multiplicity.Packets/UpdatePlayerBuff.cs
+++ b/Multiplicity.Packets/UpdatePlayerBuff.cs
@@ -1,4 +1,6 @@
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -10,6 +12,8 @@ public class UpdatePlayerBuff : TerrariaPacket
public byte PlayerID { get; set; }
+ public byte[] BuffType { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -27,6 +31,7 @@ public UpdatePlayerBuff(BinaryReader br)
: base(br)
{
this.PlayerID = br.ReadByte();
+ this.BuffType = br.ReadBytes(22);
}
public override string ToString()
@@ -38,7 +43,7 @@ public override string ToString()
public override short GetLength()
{
- return (short)(1);
+ return (short)(23);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -46,7 +51,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -58,8 +64,10 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(PlayerID);
+ br.Write(BuffType);
}
}
diff --git a/Multiplicity.Packets/UpdateShieldStrengths.cs b/Multiplicity.Packets/UpdateShieldStrengths.cs
index 3981fe2..b860e6f 100644
--- a/Multiplicity.Packets/UpdateShieldStrengths.cs
+++ b/Multiplicity.Packets/UpdateShieldStrengths.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -41,8 +42,7 @@ public UpdateShieldStrengths(BinaryReader br)
public override string ToString()
{
- return
- $"[UpdateShieldStrengths: SolarTowerShield = {SolarTowerShield} VortexTowerShield = {VortexTowerShield} NebulaTowerShield = {NebulaTowerShield} StardustTowerShield = {StardustTowerShield}]";
+ return $"[UpdateShieldStrengths: SolarTowerShield = {SolarTowerShield} VortexTowerShield = {VortexTowerShield} NebulaTowerShield = {NebulaTowerShield} StardustTowerShield = {StardustTowerShield}]";
}
#region implemented abstract members of TerrariaPacket
@@ -57,7 +57,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -69,7 +70,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(SolarTowerShield);
br.Write(VortexTowerShield);
br.Write(NebulaTowerShield);
diff --git a/Multiplicity.Packets/UpdateSign.cs b/Multiplicity.Packets/UpdateSign.cs
index c4fde7c..b6a11a7 100644
--- a/Multiplicity.Packets/UpdateSign.cs
+++ b/Multiplicity.Packets/UpdateSign.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -59,7 +60,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -71,7 +73,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(SignID);
br.Write(X);
br.Write(Y);
diff --git a/Multiplicity.Packets/UpdateTileEntity.cs b/Multiplicity.Packets/UpdateTileEntity.cs
index a17c98c..0e80952 100644
--- a/Multiplicity.Packets/UpdateTileEntity.cs
+++ b/Multiplicity.Packets/UpdateTileEntity.cs
@@ -1,5 +1,6 @@
-using System;
+using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -9,30 +10,54 @@ namespace Multiplicity.Packets
public class UpdateTileEntity : TerrariaPacket
{
- public int EntityID { get; set; }
+ public int Key { get; set; }
- public bool Remove { get; set; }
+ public bool IsRemove { get; set; }
- public byte EntityType { get; set; }
+ ///
+ /// Gets or sets the TileEntityType - If Remove? == false|
+ ///
+ public byte TileEntityType { get; set; }
- public int Id { get; set; }
+ ///
+ /// Gets or sets the ID - If Remove? == false|
+ ///
+ public int TileID { get; set; }
+ ///
+ /// Gets or sets the X - If Remove? == false|
+ ///
public short X { get; set; }
+ ///
+ /// Gets or sets the Y - If Remove? == false|
+ ///
public short Y { get; set; }
- public short Npc { get; set; }
+ ///
+ /// Gets or sets the NPC - If Remove? == false && Type = 0|
+ ///
+ public short NPC { get; set; }
+ ///
+ /// Gets or sets the ItemType - If Remove? == false|
+ ///
public short ItemType { get; set; }
+ ///
+ /// Gets or sets the Prefix - If Remove? == false|
+ ///
public byte Prefix { get; set; }
+ ///
+ /// Gets or sets the Stack - If Remove? == false|
+ ///
public short Stack { get; set; }
///
/// Initializes a new instance of the class.
///
- public UpdateTileEntity()
+ public UpdateTileEntity()
: base((byte)PacketTypes.UpdateTileEntity)
{
@@ -41,31 +66,44 @@ public UpdateTileEntity()
///
/// Initializes a new instance of the class.
///
- ///
- public UpdateTileEntity(BinaryReader br) : base(br)
+ /// br
+ public UpdateTileEntity(BinaryReader br)
+ : base(br)
{
- this.EntityID = br.ReadInt32();
- this.Remove = br.ReadBoolean();
- this.EntityType = br.ReadByte();
- this.Id = br.ReadInt32();
- this.X = br.ReadInt16();
- this.Y = br.ReadInt16();
- this.Npc = br.ReadInt16();
- this.ItemType = br.ReadInt16();
- this.Prefix = br.ReadByte();
- this.Stack = br.ReadInt16();
+ this.Key = br.ReadInt32();
+ this.IsRemove = br.ReadBoolean();
+
+ if (!this.IsRemove)
+ {
+ this.TileEntityType = br.ReadByte();
+ this.TileID = br.ReadInt32();
+ this.X = br.ReadInt16();
+ this.Y = br.ReadInt16();
+ if (this.TileEntityType == 0)
+ this.NPC = br.ReadInt16();
+ this.ItemType = br.ReadInt16();
+ this.Prefix = br.ReadByte();
+ this.Stack = br.ReadInt16();
+ }
}
public override string ToString()
{
- return $"[UpdateTileEntity: EntityID = {EntityID} Remove = {Remove} EntityType = {EntityType} Id = {Id} X = {X} Y = {Y} NPC = {Npc} ItemType = {ItemType} Prefix = {Prefix} Stack = {Stack}]";
+ return $"[UpdateTileEntity: Key = {Key} IsRemove = {IsRemove} TileEntityType = {TileEntityType} TileID = {TileID} X = {X} Y = {Y} NPC = {NPC} ItemType = {ItemType} Prefix = {Prefix} Stack = {Stack}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(21);
+ short length = 5;
+ if (!IsRemove)
+ {
+ length += 14;
+ if (TileEntityType == 0)
+ length += 2;
+ }
+ return (short)(length);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -86,17 +124,23 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
- br.Write(EntityID);
- br.Write(Remove);
- br.Write(EntityType);
- br.Write(Id);
- br.Write(X);
- br.Write(Y);
- br.Write(Npc);
- br.Write(ItemType);
- br.Write(Prefix);
- br.Write(Stack);
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
+ br.Write(Key);
+ br.Write(IsRemove);
+
+ if (!this.IsRemove)
+ {
+ br.Write(TileEntityType);
+ br.Write(TileID);
+ br.Write(X);
+ br.Write(Y);
+ if (this.TileEntityType == 0)
+ br.Write(NPC);
+ br.Write(ItemType);
+ br.Write(Prefix);
+ br.Write(Stack);
+ }
}
}
diff --git a/Multiplicity.Packets/WiredCannonShot.cs b/Multiplicity.Packets/WiredCannonShot.cs
index 4acb6ba..3bb2381 100644
--- a/Multiplicity.Packets/WiredCannonShot.cs
+++ b/Multiplicity.Packets/WiredCannonShot.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -53,8 +54,7 @@ public WiredCannonShot(BinaryReader br)
public override string ToString()
{
- return
- $"[WiredCannonShot: Damage = {Damage} Knockback = {Knockback} X = {X} Y = {Y} Angle = {Angle} Ammo = {Ammo} PlayerID = {PlayerID}]";
+ return $"[WiredCannonShot: Damage = {Damage} Knockback = {Knockback} X = {X} Y = {Y} Angle = {Angle} Ammo = {Ammo} PlayerID = {PlayerID}]";
}
#region implemented abstract members of TerrariaPacket
@@ -69,7 +69,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -81,7 +82,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Damage);
br.Write(Knockback);
br.Write(X);
diff --git a/Multiplicity.Packets/WorldInfo.cs b/Multiplicity.Packets/WorldInfo.cs
index 071b3b1..ae75281 100644
--- a/Multiplicity.Packets/WorldInfo.cs
+++ b/Multiplicity.Packets/WorldInfo.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using Multiplicity.Packets.Extensions;
namespace Multiplicity.Packets
{
@@ -34,6 +35,10 @@ public class WorldInfo : TerrariaPacket
public string WorldName { get; set; }
+ public byte[] WorldUniqueID { get; set; }
+
+ public ulong WorldGeneratorVersion { get; set; }
+
public byte MoonType { get; set; }
public byte TreeBackground { get; set; }
@@ -102,14 +107,27 @@ public class WorldInfo : TerrariaPacket
///
public byte EventInfo2 { get; set; }
+ ///
+ /// Gets or sets the EventInfo3 - BitFlags: 1 = Expert Mode, 2 = FastForwardTime, 3 = Slime Rain, 4 = Downed Slime King, 5 = Downed Queen Bee, 6 = Downed Fishron, 7 = Downed Martians, 8 = Downed Ancient Cultist|
+ ///
public byte EventInfo3 { get; set; }
+ ///
+ /// Gets or sets the EventInfo4 - BitFlags: 1 = Downed Moon Lord, 2 = Downed Pumking, 3 = Downed Mourning Wood, 4 = Downed Ice Queen, 5 = Downed Santank, 6 = Downed Everscream, 7 = Downed Golem, 8 = Birthday Party|
+ ///
public byte EventInfo4 { get; set; }
+ ///
+ /// Gets or sets the EventInfo5 - BitFlags: 1 = Downed Pirates, 2 = Downed Frost Legion, 3 = Downed Goblins, 4 = Sandstorm, 5 = DD2 Event, 6 = Downed DD2 Tier 1, 7 = Downed DD2 Tier 2, 8 = Downed DD2 Tier 3|
+ ///
+ public byte EventInfo5 { get; set; }
+
public sbyte InvasionType { get; set; }
public ulong LobbyID { get; set; }
+ public float SandstormSeverity { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -137,6 +155,8 @@ public WorldInfo(BinaryReader br)
this.RockLayer = br.ReadInt16();
this.WorldID = br.ReadInt32();
this.WorldName = br.ReadString();
+ this.WorldUniqueID = br.ReadBytes(16);
+ this.WorldGeneratorVersion = br.ReadUInt64();
this.MoonType = br.ReadByte();
this.TreeBackground = br.ReadByte();
this.CorruptionBackground = br.ReadByte();
@@ -170,21 +190,22 @@ public WorldInfo(BinaryReader br)
this.EventInfo2 = br.ReadByte();
this.EventInfo3 = br.ReadByte();
this.EventInfo4 = br.ReadByte();
+ this.EventInfo5 = br.ReadByte();
this.InvasionType = br.ReadSByte();
this.LobbyID = br.ReadUInt64();
+ this.SandstormSeverity = br.ReadSingle();
}
public override string ToString()
{
- return
- $"[WorldInfo: Time = {Time} DayandMoonInfo = {DayandMoonInfo} MoonPhase = {MoonPhase} MaxTilesX = {MaxTilesX} MaxTilesY = {MaxTilesY} SpawnX = {SpawnX} SpawnY = {SpawnY} WorldSurface = {WorldSurface} RockLayer = {RockLayer} WorldID = {WorldID} WorldName = {WorldName} MoonType = {MoonType} TreeBackground = {TreeBackground} CorruptionBackground = {CorruptionBackground} JungleBackground = {JungleBackground} SnowBackground = {SnowBackground} HallowBackground = {HallowBackground} CrimsonBackground = {CrimsonBackground} DesertBackground = {DesertBackground} OceanBackground = {OceanBackground} IceBackStyle = {IceBackStyle} JungleBackStyle = {JungleBackStyle} HellBackStyle = {HellBackStyle} WindSpeedSet = {WindSpeedSet} CloudNumber = {CloudNumber} Tree1 = {Tree1} Tree2 = {Tree2} Tree3 = {Tree3} TreeStyle1 = {TreeStyle1} TreeStyle2 = {TreeStyle2} TreeStyle3 = {TreeStyle3} TreeStyle4 = {TreeStyle4} CaveBack1 = {CaveBack1} CaveBack2 = {CaveBack2} CaveBack3 = {CaveBack3} CaveBackStyle1 = {CaveBackStyle1} CaveBackStyle2 = {CaveBackStyle2} CaveBackStyle3 = {CaveBackStyle3} CaveBackStyle4 = {CaveBackStyle4} Rain = {Rain} EventInfo = {EventInfo} EventInfo2 = {EventInfo2} EventInfo3 = {EventInfo3} EventInfo4 = {EventInfo4} InvasionType = {InvasionType} LobbyID = {LobbyID}]";
+ return $"[WorldInfo: Time = {Time} DayandMoonInfo = {DayandMoonInfo} MoonPhase = {MoonPhase} MaxTilesX = {MaxTilesX} MaxTilesY = {MaxTilesY} SpawnX = {SpawnX} SpawnY = {SpawnY} WorldSurface = {WorldSurface} RockLayer = {RockLayer} WorldID = {WorldID} WorldName = {WorldName} WorldUniqueID = {WorldUniqueID} WorldGeneratorVersion = {WorldGeneratorVersion} MoonType = {MoonType} TreeBackground = {TreeBackground} CorruptionBackground = {CorruptionBackground} JungleBackground = {JungleBackground} SnowBackground = {SnowBackground} HallowBackground = {HallowBackground} CrimsonBackground = {CrimsonBackground} DesertBackground = {DesertBackground} OceanBackground = {OceanBackground} IceBackStyle = {IceBackStyle} JungleBackStyle = {JungleBackStyle} HellBackStyle = {HellBackStyle} WindSpeedSet = {WindSpeedSet} CloudNumber = {CloudNumber} Tree1 = {Tree1} Tree2 = {Tree2} Tree3 = {Tree3} TreeStyle1 = {TreeStyle1} TreeStyle2 = {TreeStyle2} TreeStyle3 = {TreeStyle3} TreeStyle4 = {TreeStyle4} CaveBack1 = {CaveBack1} CaveBack2 = {CaveBack2} CaveBack3 = {CaveBack3} CaveBackStyle1 = {CaveBackStyle1} CaveBackStyle2 = {CaveBackStyle2} CaveBackStyle3 = {CaveBackStyle3} CaveBackStyle4 = {CaveBackStyle4} Rain = {Rain} EventInfo = {EventInfo} EventInfo2 = {EventInfo2} EventInfo3 = {EventInfo3} EventInfo4 = {EventInfo4} EventInfo5 = {EventInfo5} InvasionType = {InvasionType} LobbyID = {LobbyID}]";
}
#region implemented abstract members of TerrariaPacket
public override short GetLength()
{
- return (short)(89 + WorldName.Length);
+ return (short)(118 + WorldName.Length);
}
public override void ToStream(Stream stream, bool includeHeader = true)
@@ -192,7 +213,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
/*
* Length and ID headers get written in the base packet class.
*/
- if (includeHeader) {
+ if (includeHeader)
+ {
base.ToStream(stream, includeHeader);
}
@@ -204,7 +226,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
* the regressions of unconditionally closing the TCP socket
* once the payload of data has been sent to the client.
*/
- using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true)) {
+ using (BinaryWriter br = new BinaryWriter(stream, new System.Text.UTF8Encoding(), leaveOpen: true))
+ {
br.Write(Time);
br.Write(DayandMoonInfo);
br.Write(MoonPhase);
@@ -216,6 +239,8 @@ public override void ToStream(Stream stream, bool includeHeader = true)
br.Write(RockLayer);
br.Write(WorldID);
br.Write(WorldName);
+ br.Write(WorldUniqueID);
+ br.Write(WorldGeneratorVersion);
br.Write(MoonType);
br.Write(TreeBackground);
br.Write(CorruptionBackground);
@@ -249,8 +274,10 @@ public override void ToStream(Stream stream, bool includeHeader = true)
br.Write(EventInfo2);
br.Write(EventInfo3);
br.Write(EventInfo4);
+ br.Write(EventInfo5);
br.Write(InvasionType);
br.Write(LobbyID);
+ br.Write(SandstormSeverity);
}
}
diff --git a/Multiplicity.Packets/_BuildResult/Multiplicity.Packets.dll b/Multiplicity.Packets/_BuildResult/Multiplicity.Packets.dll
new file mode 100644
index 0000000..7c5675b
Binary files /dev/null and b/Multiplicity.Packets/_BuildResult/Multiplicity.Packets.dll differ