Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Multiplicity.Packets/AddNPCBuff.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using Multiplicity.Packets.Extensions;

namespace Multiplicity.Packets
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions Multiplicity.Packets/AddPlayerBuff.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using Multiplicity.Packets.Extensions;

namespace Multiplicity.Packets
{
Expand All @@ -13,7 +14,7 @@ public class AddPlayerBuff : TerrariaPacket

public byte Buff { get; set; }

public short Time { get; set; }
public int Time { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="AddPlayerBuff"/> class.
Expand All @@ -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()
Expand All @@ -45,15 +46,16 @@ public override string ToString()

public override short GetLength()
{
return (short)(4);
return (short)(6);
}

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);
}

Expand All @@ -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);
Expand Down
135 changes: 105 additions & 30 deletions Multiplicity.Packets/AlterItemDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Copyright (c) 2016 Celant

using System.IO;
using Multiplicity.Packets.Extensions;

namespace Multiplicity.Packets
{
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions Multiplicity.Packets/AnglerQuest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using Multiplicity.Packets.Extensions;

namespace Multiplicity.Packets
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions Multiplicity.Packets/CatchNPC.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using Multiplicity.Packets.Extensions;

namespace Multiplicity.Packets
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions Multiplicity.Packets/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ChatMessage : TerrariaPacket
/// <summary>
/// Gets or sets the MessageColor - Client cannot change colors|
/// </summary>
public Color MessageColor { get; set; }
public ColorStruct MessageColor { get; set; }

public string Message { get; set; }

Expand Down Expand Up @@ -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);
}

Expand Down
28 changes: 13 additions & 15 deletions Multiplicity.Packets/ChatMessagev2.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -12,16 +13,14 @@ public class ChatMessagev2 : TerrariaPacket
{

/// <summary>
/// Gets or sets the PlayerID - If 255 Then No Name|
/// Gets or sets the MessageColor - Client cannot change colors|
/// </summary>
public byte PlayerID { get; set; }
public ColorStruct MessageColor { get; set; }

/// <summary>
/// Gets or sets the MessageColor - Client cannot change colors|
/// Gets or sets the Message - |-|
/// </summary>
public Color MessageColor { get; set; }

public string Message { get; set; }
public NetworkText Message { get; set; }

public short MessageLength { get; set; }

Expand All @@ -41,31 +40,30 @@ 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)
{
/*
* Length and ID headers get written in the base packet class.
*/
if (includeHeader) {
if (includeHeader)
{
base.ToStream(stream, includeHeader);
}

Expand All @@ -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);
Expand Down
Loading