Converts Item & Entity Packets (#326)
- [X] Converts World Item packets - [X] Converter Remove Entity packets - [X] Updates `LOSBlocker` and `Blocker` - [X] Fixes a few bugs - [X] Converts container packets Bumps release version
This commit is contained in:
parent
c41906d3c7
commit
77f665502b
26 changed files with 1351 additions and 1606 deletions
|
|
@ -0,0 +1,196 @@
|
|||
using System;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network
|
||||
{
|
||||
[Collection("Sequential Tests")]
|
||||
public class ContainerPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void TestContainerDisplay()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort gumpId = 100;
|
||||
|
||||
var expected = new ContainerDisplay(serial, gumpId).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDisplayContainer(serial, gumpId);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerDisplayHS()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort gumpId = 100;
|
||||
|
||||
var expected = new ContainerDisplayHS(serial, gumpId).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = ns.ProtocolChanges | ProtocolChanges.ContainerGridLines | ProtocolChanges.HighSeas;
|
||||
ns.SendDisplayContainer(serial, gumpId);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplaySpellbook()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
|
||||
var expected = new DisplaySpellbook(serial).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDisplaySpellbook(serial);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplaySpellbookHS()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
|
||||
var expected = new DisplaySpellbookHS(serial).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = ns.ProtocolChanges | ProtocolChanges.ContainerGridLines | ProtocolChanges.HighSeas;
|
||||
ns.SendDisplaySpellbook(serial);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestNewSpellbookContent()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort graphic = 100;
|
||||
ushort offset = 10;
|
||||
ulong content = 0x123456789ABCDEF0;
|
||||
bool opl = ObjectPropertyList.Enabled;
|
||||
|
||||
var expected = new NewSpellbookContent(serial, graphic, offset, content).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = ns.ProtocolChanges | ProtocolChanges.ContainerGridLines | ProtocolChanges.NewSpellbook;
|
||||
ObjectPropertyList.Enabled = true;
|
||||
ns.SendSpellbookContent(serial, graphic, offset, content);
|
||||
ObjectPropertyList.Enabled = opl;
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSpellbookContent()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort offset = 10;
|
||||
ushort graphic = 100;
|
||||
ulong content = 0x123456789ABCDEF0;
|
||||
|
||||
var expected = new SpellbookContent(serial, offset, content).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendSpellbookContent(serial, graphic, offset, content);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSpellbookContent6017()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort offset = 10;
|
||||
ushort graphic = 100;
|
||||
ulong content = 0x123456789ABCDEF0;
|
||||
|
||||
var expected = new SpellbookContent6017(serial, offset, content).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges |= ProtocolChanges.ContainerGridLines;
|
||||
ns.SendSpellbookContent(serial, graphic, offset, content);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerContentUpdate()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
var item = new Item(serial);
|
||||
|
||||
var expected = new ContainerContentUpdate(item).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendContainerContentUpdate(item);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerContentUpdate6017()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
var item = new Item(serial);
|
||||
|
||||
var expected = new ContainerContentUpdate6017(item).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges |= ProtocolChanges.ContainerGridLines;
|
||||
ns.SendContainerContentUpdate(item);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerContent()
|
||||
{
|
||||
var cont = new Container(World.NewItem);
|
||||
cont.AddItem(new Item(World.NewItem));
|
||||
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var expected = new ContainerContent(m, cont).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendContainerContent(m, cont);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerContent6017()
|
||||
{
|
||||
var cont = new Container(World.NewItem);
|
||||
cont.AddItem(new Item(World.NewItem));
|
||||
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var expected = new ContainerContent6017(m, cont).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges |= ProtocolChanges.ContainerGridLines;
|
||||
ns.SendContainerContent(m, cont);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,270 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public sealed class DisplaySpellbook : Packet
|
||||
{
|
||||
public DisplaySpellbook(Serial book) : base(0x24, 7)
|
||||
{
|
||||
Stream.Write(book);
|
||||
Stream.Write((short)-1);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DisplaySpellbookHS : Packet
|
||||
{
|
||||
public DisplaySpellbookHS(Serial book) : base(0x24, 9)
|
||||
{
|
||||
Stream.Write(book);
|
||||
Stream.Write((short)-1);
|
||||
Stream.Write((short)0x7D);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NewSpellbookContent : Packet
|
||||
{
|
||||
public NewSpellbookContent(Serial spellbook, int graphic, int offset, ulong content) : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(23);
|
||||
|
||||
Stream.Write((short)0x1B);
|
||||
Stream.Write((short)0x01);
|
||||
|
||||
Stream.Write(spellbook);
|
||||
Stream.Write((short)graphic);
|
||||
Stream.Write((short)offset);
|
||||
|
||||
for (var i = 0; i < 8; ++i)
|
||||
{
|
||||
Stream.Write((byte)(content >> (i * 8)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SpellbookContent : Packet
|
||||
{
|
||||
public SpellbookContent(Serial spellbook, int offset, ulong content) : base(0x3C)
|
||||
{
|
||||
EnsureCapacity(5 + 64 * 19);
|
||||
|
||||
var written = 0;
|
||||
|
||||
Stream.Write((ushort)0);
|
||||
|
||||
ulong mask = 1;
|
||||
|
||||
for (var i = 0; i < 64; ++i, mask <<= 1)
|
||||
{
|
||||
if ((content & mask) != 0)
|
||||
{
|
||||
Stream.Write(0x7FFFFFFF - i);
|
||||
Stream.Write((ushort)0);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((ushort)(i + offset));
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((short)0);
|
||||
Stream.Write(spellbook);
|
||||
Stream.Write((short)0);
|
||||
|
||||
++written;
|
||||
}
|
||||
}
|
||||
|
||||
Stream.Seek(3, SeekOrigin.Begin);
|
||||
Stream.Write((ushort)written);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SpellbookContent6017 : Packet
|
||||
{
|
||||
public SpellbookContent6017(Serial spellbook, int offset, ulong content) : base(0x3C)
|
||||
{
|
||||
EnsureCapacity(5 + 64 * 20);
|
||||
|
||||
var written = 0;
|
||||
|
||||
Stream.Write((ushort)0);
|
||||
|
||||
ulong mask = 1;
|
||||
|
||||
for (var i = 0; i < 64; ++i, mask <<= 1)
|
||||
{
|
||||
if ((content & mask) != 0)
|
||||
{
|
||||
Stream.Write(0x7FFFFFFF - i);
|
||||
Stream.Write((ushort)0);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((ushort)(i + offset));
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((byte)0); // Grid Location?
|
||||
Stream.Write(spellbook);
|
||||
Stream.Write((short)0);
|
||||
|
||||
++written;
|
||||
}
|
||||
}
|
||||
|
||||
Stream.Seek(3, SeekOrigin.Begin);
|
||||
Stream.Write((ushort)written);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ContainerDisplay : Packet
|
||||
{
|
||||
public ContainerDisplay(Serial cont, int gumpId) : base(0x24, 7)
|
||||
{
|
||||
Stream.Write(cont);
|
||||
Stream.Write((short)gumpId);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ContainerDisplayHS : Packet
|
||||
{
|
||||
public ContainerDisplayHS(Serial cont, int gumpId) : base(0x24, 9)
|
||||
{
|
||||
Stream.Write(cont);
|
||||
Stream.Write((short)gumpId);
|
||||
Stream.Write((short)0x7D);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ContainerContentUpdate : Packet
|
||||
{
|
||||
public ContainerContentUpdate(Item item) : base(0x25, 20)
|
||||
{
|
||||
Serial parentSerial;
|
||||
|
||||
if (item.Parent is Item parentItem)
|
||||
{
|
||||
parentSerial = parentItem.Serial;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: ContainerContentUpdate on item with !(parent is Item)");
|
||||
parentSerial = Serial.Zero;
|
||||
}
|
||||
|
||||
Stream.Write(item.Serial);
|
||||
Stream.Write((ushort)item.ItemID);
|
||||
Stream.Write((byte)0); // signed, itemID offset
|
||||
Stream.Write((ushort)Math.Min(item.Amount, ushort.MaxValue));
|
||||
Stream.Write((short)item.X);
|
||||
Stream.Write((short)item.Y);
|
||||
Stream.Write(parentSerial);
|
||||
Stream.Write((ushort)(item.QuestItem ? Item.QuestItemHue : item.Hue));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ContainerContentUpdate6017 : Packet
|
||||
{
|
||||
public ContainerContentUpdate6017(Item item) : base(0x25, 21)
|
||||
{
|
||||
Serial parentSerial;
|
||||
|
||||
if (item.Parent is Item parentItem)
|
||||
{
|
||||
parentSerial = parentItem.Serial;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: ContainerContentUpdate on item with !(parent is Item)");
|
||||
parentSerial = Serial.Zero;
|
||||
}
|
||||
|
||||
Stream.Write(item.Serial);
|
||||
Stream.Write((ushort)item.ItemID);
|
||||
Stream.Write((byte)0); // signed, itemID offset
|
||||
Stream.Write((ushort)Math.Min(item.Amount, ushort.MaxValue));
|
||||
Stream.Write((short)item.X);
|
||||
Stream.Write((short)item.Y);
|
||||
Stream.Write((byte)0); // Grid Location?
|
||||
Stream.Write(parentSerial);
|
||||
Stream.Write((ushort)(item.QuestItem ? Item.QuestItemHue : item.Hue));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ContainerContent : Packet
|
||||
{
|
||||
public ContainerContent(Mobile beholder, Item beheld) : base(0x3C)
|
||||
{
|
||||
var items = beheld.Items;
|
||||
var count = items.Count;
|
||||
|
||||
EnsureCapacity(5 + count * 19);
|
||||
|
||||
var pos = Stream.Position;
|
||||
|
||||
var written = 0;
|
||||
|
||||
Stream.Write((ushort)0);
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
var child = items[i];
|
||||
|
||||
if (!child.Deleted && beholder.CanSee(child))
|
||||
{
|
||||
var loc = child.Location;
|
||||
|
||||
Stream.Write(child.Serial);
|
||||
Stream.Write((ushort)child.ItemID);
|
||||
Stream.Write((byte)0); // signed, itemID offset
|
||||
Stream.Write((ushort)Math.Min(child.Amount, ushort.MaxValue));
|
||||
Stream.Write((short)loc.X);
|
||||
Stream.Write((short)loc.Y);
|
||||
Stream.Write(beheld.Serial);
|
||||
Stream.Write((ushort)(child.QuestItem ? Item.QuestItemHue : child.Hue));
|
||||
|
||||
++written;
|
||||
}
|
||||
}
|
||||
|
||||
Stream.Seek(pos, SeekOrigin.Begin);
|
||||
Stream.Write((ushort)written);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ContainerContent6017 : Packet
|
||||
{
|
||||
public ContainerContent6017(Mobile beholder, Item beheld) : base(0x3C)
|
||||
{
|
||||
var items = beheld.Items;
|
||||
var count = items.Count;
|
||||
|
||||
EnsureCapacity(5 + count * 20);
|
||||
|
||||
var pos = Stream.Position;
|
||||
|
||||
var written = 0;
|
||||
|
||||
Stream.Write((ushort)0);
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
var child = items[i];
|
||||
|
||||
if (!child.Deleted && beholder.CanSee(child))
|
||||
{
|
||||
var loc = child.Location;
|
||||
|
||||
Stream.Write(child.Serial);
|
||||
Stream.Write((ushort)child.ItemID);
|
||||
Stream.Write((byte)0); // signed, itemID offset
|
||||
Stream.Write((ushort)Math.Min(child.Amount, ushort.MaxValue));
|
||||
Stream.Write((short)loc.X);
|
||||
Stream.Write((short)loc.Y);
|
||||
Stream.Write((byte)0); // Grid Location?
|
||||
Stream.Write(beheld.Serial);
|
||||
Stream.Write((ushort)(child.QuestItem ? Item.QuestItemHue : child.Hue));
|
||||
|
||||
++written;
|
||||
}
|
||||
}
|
||||
|
||||
Stream.Seek(pos, SeekOrigin.Begin);
|
||||
Stream.Write((ushort)written);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,87 +34,13 @@ namespace Server.Tests.Network
|
|||
Direction = Direction.Left
|
||||
};
|
||||
|
||||
var data = new WorldItem(item).Compile();
|
||||
var expected = new WorldItem(item).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[20]; // Max size
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendWorldItem(item);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x1A);
|
||||
pos += 2; // Length
|
||||
|
||||
if (item.Amount != 0)
|
||||
{
|
||||
expectedData.Write(ref pos, serial | 0x80000000);
|
||||
}
|
||||
else
|
||||
{
|
||||
expectedData.Write(ref pos, serial & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
if (item is BaseMulti)
|
||||
{
|
||||
expectedData.Write(ref pos, (ushort)(item.ItemID | 0x4000));
|
||||
}
|
||||
else
|
||||
{
|
||||
expectedData.Write(ref pos, (ushort)item.ItemID);
|
||||
}
|
||||
|
||||
if (item.Amount != 0)
|
||||
{
|
||||
expectedData.Write(ref pos, (ushort)item.Amount);
|
||||
}
|
||||
|
||||
var direction = (byte)item.Direction;
|
||||
var x = (ushort)(item.X & 0x7FFF);
|
||||
|
||||
if (direction != 0)
|
||||
{
|
||||
x |= 0x8000;
|
||||
}
|
||||
|
||||
expectedData.Write(ref pos, x);
|
||||
|
||||
var hue = item.Hue;
|
||||
var flags = item.GetPacketFlags();
|
||||
var y = (ushort)(item.Y & 0x3FFF);
|
||||
|
||||
if (hue != 0)
|
||||
{
|
||||
y |= 0x8000;
|
||||
}
|
||||
|
||||
if (flags != 0)
|
||||
{
|
||||
y |= 0x4000;
|
||||
}
|
||||
|
||||
expectedData.Write(ref pos, y);
|
||||
|
||||
if (direction != 0)
|
||||
{
|
||||
expectedData.Write(ref pos, direction);
|
||||
}
|
||||
|
||||
expectedData.Write(ref pos, (byte)item.Z);
|
||||
|
||||
if (hue != 0)
|
||||
{
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
}
|
||||
|
||||
if (flags != 0)
|
||||
{
|
||||
expectedData.Write(ref pos, (byte)flags);
|
||||
}
|
||||
|
||||
// Length
|
||||
expectedData.Slice(1, 2).Write((ushort)pos);
|
||||
|
||||
// Slice the data to match in size
|
||||
data = data.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -142,34 +68,14 @@ namespace Server.Tests.Network
|
|||
Location = new Point3D(1000, 100, -10)
|
||||
};
|
||||
|
||||
var loc = item.Location;
|
||||
var isMulti = item is BaseMulti;
|
||||
var expected = new WorldItemSA(item).Compile();
|
||||
|
||||
var data = new WorldItemSA(item).Compile();
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = ns.ProtocolChanges | ProtocolChanges.StygianAbyss;
|
||||
ns.SendWorldItem(item);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[24];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xF3); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x1);
|
||||
expectedData.Write(ref pos, (byte)(isMulti ? 0x2 : 0x00)); // Item Type (Regular, or Multi)
|
||||
expectedData.Write(ref pos, item.Serial);
|
||||
expectedData.Write(ref pos, (ushort)(item.ItemID & (isMulti ? 0x3FFF : 0xFFFF)));
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0)
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (ushort)item.Amount); // Amount (min?)
|
||||
expectedData.Write(ref pos, (ushort)item.Amount); // Amount (max?)
|
||||
expectedData.Write(ref pos, loc); // X, Y, Z
|
||||
expectedData.Write(ref pos, (byte)item.Light); // Light
|
||||
expectedData.Write(ref pos, (ushort)item.Hue); // Hue
|
||||
expectedData.Write(ref pos, (byte)item.GetPacketFlags()); // Flags
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -197,410 +103,14 @@ namespace Server.Tests.Network
|
|||
Location = new Point3D(1000, 100, -10)
|
||||
};
|
||||
|
||||
var loc = item.Location;
|
||||
var isMulti = item is BaseMulti;
|
||||
var expected = new WorldItemHS(item).Compile();
|
||||
|
||||
var data = new WorldItemHS(item).Compile();
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = ns.ProtocolChanges | ProtocolChanges.StygianAbyss | ProtocolChanges.HighSeas;
|
||||
ns.SendWorldItem(item);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[26];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xF3); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x1);
|
||||
expectedData.Write(ref pos, (byte)(isMulti ? 0x2 : 0x00)); // Item Type (Regular, or Multi)
|
||||
expectedData.Write(ref pos, item.Serial);
|
||||
expectedData.Write(ref pos, (ushort)(item.ItemID & (isMulti ? 0x3FFF : 0xFFFF)));
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (ushort)item.Amount); // Amount (min?)
|
||||
expectedData.Write(ref pos, (ushort)item.Amount); // Amount (max?)
|
||||
expectedData.Write(ref pos, loc); // X, Y, Z
|
||||
expectedData.Write(ref pos, (byte)item.Light); // Light
|
||||
expectedData.Write(ref pos, (ushort)item.Hue); // Hue
|
||||
expectedData.Write(ref pos, (byte)item.GetPacketFlags()); // Flags
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0); // ??
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerDisplay()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort gumpId = 100;
|
||||
|
||||
var data = new ContainerDisplay(serial, gumpId).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[7];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x24); // Packet ID
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, gumpId);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerDisplayHS()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort gumpId = 100;
|
||||
|
||||
var data = new ContainerDisplayHS(serial, gumpId).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[9];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x24); // Packet ID
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, gumpId);
|
||||
expectedData.Write(ref pos, (ushort)0x7D); // Max Items?
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplaySpellbook()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
|
||||
var data = new DisplaySpellbook(serial).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[7];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x24); // Packet ID
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)0xFFFF); // Gump ID
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplaySpellbookHS()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
|
||||
var data = new DisplaySpellbookHS(serial).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[9];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x24); // Packet ID
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)0xFFFF); // Gump ID
|
||||
expectedData.Write(ref pos, (ushort)0x7D); // Max Items?
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestNewSpellbookContent()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort graphic = 100;
|
||||
ushort offset = 10;
|
||||
ulong content = 0x123456789ABCDEF0;
|
||||
|
||||
var data = new NewSpellbookContent(serial, graphic, offset, content).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[23];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x17); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x1B); // Sub-packet
|
||||
expectedData.Write(ref pos, (ushort)0x1); // Command
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, graphic);
|
||||
expectedData.Write(ref pos, offset);
|
||||
expectedData.WriteLE(ref pos, content);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSpellbookContent()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort offset = 10;
|
||||
ulong content = 0x123456789ABCDEF0;
|
||||
|
||||
var data = new SpellbookContent(serial, offset, content).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + 64 * 19]; // Max size
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3C); // Packet ID
|
||||
pos += 4; // Length + spell count
|
||||
|
||||
ushort count = 0;
|
||||
|
||||
for (var i = 0; i < 64; i++)
|
||||
{
|
||||
if ((content & (1ul << i)) != 0)
|
||||
{
|
||||
expectedData.Write(ref pos, 0x7FFFFFFF - i);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos += 3;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)(i + offset));
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0); // X. Y
|
||||
#else
|
||||
pos += 4;
|
||||
#endif
|
||||
expectedData.Write(ref pos, serial);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 2;
|
||||
#endif
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
expectedData.Slice(1, 2).Write((ushort)pos); // Length
|
||||
expectedData.Slice(3, 2).Write(count); // Count
|
||||
|
||||
expectedData = expectedData.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSpellbookContent6017()
|
||||
{
|
||||
Serial serial = 0x1000;
|
||||
ushort offset = 10;
|
||||
ulong content = 0x123456789ABCDEF0;
|
||||
|
||||
var data = new SpellbookContent6017(serial, offset, content).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + 64 * 20]; // Max size
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3C); // Packet ID
|
||||
pos += 4; // Length + spell count
|
||||
|
||||
ushort count = 0;
|
||||
|
||||
for (var i = 0; i < 64; i++)
|
||||
{
|
||||
if ((content & (1ul << i)) != 0)
|
||||
{
|
||||
expectedData.Write(ref pos, 0x7FFFFFFF - i);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos += 3;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)(i + offset));
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0); // X. Y
|
||||
expectedData.Write(ref pos, (byte)0); // Grid Location
|
||||
#else
|
||||
pos += 5;
|
||||
#endif
|
||||
expectedData.Write(ref pos, serial);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 2;
|
||||
#endif
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
expectedData.Slice(1, 2).Write((ushort)pos); // Length
|
||||
expectedData.Slice(3, 2).Write(count); // Count
|
||||
|
||||
expectedData = expectedData.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerContentUpdate()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
var item = new Item(serial);
|
||||
|
||||
var data = new ContainerContentUpdate(item).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[20];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x25); // Packet ID
|
||||
expectedData.Write(ref pos, item.Serial);
|
||||
expectedData.Write(ref pos, (ushort)item.ItemID);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // ItemID offset
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)Math.Min(item.Amount, ushort.MaxValue));
|
||||
expectedData.Write(ref pos, (ushort)item.X);
|
||||
expectedData.Write(ref pos, (ushort)item.Y);
|
||||
expectedData.Write(ref pos, item.Parent?.Serial ?? Serial.Zero);
|
||||
expectedData.Write(ref pos, (ushort)(item.QuestItem ? Item.QuestItemHue : item.Hue));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerContentUpdate6017()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
var item = new Item(serial);
|
||||
|
||||
var data = new ContainerContentUpdate6017(item).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[21];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x25); // Packet ID
|
||||
expectedData.Write(ref pos, item.Serial);
|
||||
expectedData.Write(ref pos, (ushort)item.ItemID);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // ItemID offset
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)Math.Min(item.Amount, ushort.MaxValue));
|
||||
expectedData.Write(ref pos, (ushort)item.X);
|
||||
expectedData.Write(ref pos, (ushort)item.Y);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // Grid Location?
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, item.Parent?.Serial ?? Serial.Zero);
|
||||
expectedData.Write(ref pos, (ushort)(item.QuestItem ? Item.QuestItemHue : item.Hue));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerContent()
|
||||
{
|
||||
var cont = new Container(World.NewItem);
|
||||
cont.AddItem(new Item(World.NewItem));
|
||||
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var data = new ContainerContent(m, cont).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + cont.Items.Count * 19]; // Max Size
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3C); // Packet ID
|
||||
pos += 4; // Length + Count
|
||||
|
||||
ushort count = 0;
|
||||
|
||||
var itemCount = cont.Items.Count;
|
||||
for (var i = 0; i < itemCount; i++)
|
||||
{
|
||||
var child = cont.Items[i];
|
||||
if (child.Deleted || !m.CanSee(child))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
expectedData.Write(ref pos, child.Serial);
|
||||
expectedData.Write(ref pos, (ushort)child.ItemID);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // ItemID offset
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)Math.Min(child.Amount, ushort.MaxValue));
|
||||
expectedData.Write(ref pos, (ushort)child.X);
|
||||
expectedData.Write(ref pos, (ushort)child.Y);
|
||||
expectedData.Write(ref pos, cont.Serial);
|
||||
expectedData.Write(ref pos, (ushort)(child.QuestItem ? Item.QuestItemHue : child.Hue));
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
expectedData.Slice(1, 2).Write((ushort)pos); // Length
|
||||
expectedData.Slice(3, 2).Write(count); // Count
|
||||
|
||||
expectedData = expectedData.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestContainerContent6017()
|
||||
{
|
||||
var cont = new Container(World.NewItem);
|
||||
cont.AddItem(new Item(World.NewItem));
|
||||
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var data = new ContainerContent6017(m, cont).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + cont.Items.Count * 20];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3C); // Packet ID
|
||||
pos += 4; // Length + Count
|
||||
|
||||
ushort count = 0;
|
||||
|
||||
var itemCount = cont.Items.Count;
|
||||
for (var i = 0; i < itemCount; i++)
|
||||
{
|
||||
var child = cont.Items[i];
|
||||
if (child.Deleted || !m.CanSee(child))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
expectedData.Write(ref pos, child.Serial);
|
||||
expectedData.Write(ref pos, (ushort)child.ItemID);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // ItemID offset
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)Math.Min(child.Amount, ushort.MaxValue));
|
||||
expectedData.Write(ref pos, (ushort)child.X);
|
||||
expectedData.Write(ref pos, (ushort)child.Y);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // Grid Location?
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, cont.Serial);
|
||||
expectedData.Write(ref pos, (ushort)(child.QuestItem ? Item.QuestItemHue : child.Hue));
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
expectedData.Slice(1, 2).Write((ushort)pos); // Length
|
||||
expectedData.Slice(3, 2).Write(count); // Count
|
||||
|
||||
expectedData = expectedData.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,208 @@
|
|||
using Server.Items;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public sealed class WorldItem : Packet
|
||||
{
|
||||
public WorldItem(Item item) : base(0x1A)
|
||||
{
|
||||
EnsureCapacity(20);
|
||||
|
||||
// 14 base length
|
||||
// +2 - Amount
|
||||
// +2 - Hue
|
||||
// +1 - Flags
|
||||
|
||||
var serial = item.Serial.Value;
|
||||
var itemID = item.ItemID & 0x3FFF;
|
||||
var amount = item.Amount;
|
||||
var loc = item.Location;
|
||||
var x = loc.X;
|
||||
var y = loc.Y;
|
||||
var hue = item.Hue;
|
||||
var flags = item.GetPacketFlags();
|
||||
var direction = (int)item.Direction;
|
||||
|
||||
if (amount != 0)
|
||||
{
|
||||
serial |= 0x80000000;
|
||||
}
|
||||
else
|
||||
{
|
||||
serial &= 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
Stream.Write(serial);
|
||||
|
||||
if (item is BaseMulti)
|
||||
{
|
||||
Stream.Write((short)(itemID | 0x4000));
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((short)itemID);
|
||||
}
|
||||
|
||||
if (amount != 0)
|
||||
{
|
||||
Stream.Write((short)amount);
|
||||
}
|
||||
|
||||
x &= 0x7FFF;
|
||||
|
||||
if (direction != 0)
|
||||
{
|
||||
x |= 0x8000;
|
||||
}
|
||||
|
||||
Stream.Write((short)x);
|
||||
|
||||
y &= 0x3FFF;
|
||||
|
||||
if (hue != 0)
|
||||
{
|
||||
y |= 0x8000;
|
||||
}
|
||||
|
||||
if (flags != 0)
|
||||
{
|
||||
y |= 0x4000;
|
||||
}
|
||||
|
||||
Stream.Write((short)y);
|
||||
|
||||
if (direction != 0)
|
||||
{
|
||||
Stream.Write((byte)direction);
|
||||
}
|
||||
|
||||
Stream.Write((sbyte)loc.Z);
|
||||
|
||||
if (hue != 0)
|
||||
{
|
||||
Stream.Write((ushort)hue);
|
||||
}
|
||||
|
||||
if (flags != 0)
|
||||
{
|
||||
Stream.Write((byte)flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class WorldItemSA : Packet
|
||||
{
|
||||
public WorldItemSA(Item item) : base(0xF3, 24)
|
||||
{
|
||||
Stream.Write((short)0x1);
|
||||
|
||||
var itemID = item.ItemID;
|
||||
|
||||
if (item is BaseMulti)
|
||||
{
|
||||
Stream.Write((byte)0x02);
|
||||
|
||||
Stream.Write(item.Serial);
|
||||
|
||||
itemID &= 0x3FFF;
|
||||
|
||||
Stream.Write((short)itemID);
|
||||
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0x00);
|
||||
|
||||
Stream.Write(item.Serial);
|
||||
|
||||
itemID &= 0x7FFF;
|
||||
|
||||
Stream.Write((short)itemID);
|
||||
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
|
||||
var amount = item.Amount;
|
||||
Stream.Write((short)amount);
|
||||
Stream.Write((short)amount);
|
||||
|
||||
var loc = item.Location;
|
||||
Stream.Write((short)loc.X);
|
||||
Stream.Write((short)loc.Y);
|
||||
Stream.Write((sbyte)loc.Z);
|
||||
|
||||
Stream.Write((byte)item.Light);
|
||||
Stream.Write((short)item.Hue);
|
||||
Stream.Write((byte)item.GetPacketFlags());
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class WorldItemHS : Packet
|
||||
{
|
||||
public WorldItemHS(Item item) : base(0xF3, 26)
|
||||
{
|
||||
Stream.Write((short)0x1);
|
||||
|
||||
var itemID = item.ItemID;
|
||||
|
||||
if (item is BaseMulti)
|
||||
{
|
||||
Stream.Write((byte)0x02);
|
||||
|
||||
Stream.Write(item.Serial);
|
||||
|
||||
itemID &= 0x3FFF;
|
||||
|
||||
Stream.Write((ushort)itemID);
|
||||
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0x00);
|
||||
|
||||
Stream.Write(item.Serial);
|
||||
|
||||
itemID &= 0xFFFF;
|
||||
|
||||
Stream.Write((ushort)itemID);
|
||||
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
|
||||
var amount = item.Amount;
|
||||
Stream.Write((short)amount);
|
||||
Stream.Write((short)amount);
|
||||
|
||||
var loc = item.Location;
|
||||
Stream.Write((short)loc.X);
|
||||
Stream.Write((short)loc.Y);
|
||||
Stream.Write((sbyte)loc.Z);
|
||||
|
||||
Stream.Write((byte)item.Light);
|
||||
Stream.Write((short)item.Hue);
|
||||
Stream.Write((byte)item.GetPacketFlags());
|
||||
|
||||
Stream.Write((short)0x00); // ??
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OPLInfo : Packet
|
||||
{
|
||||
/*public OPLInfo( ObjectPropertyList list ) : base( 0xBF )
|
||||
{
|
||||
EnsureCapacity( 13 );
|
||||
|
||||
m_Stream.Write( (short) 0x10 );
|
||||
m_Stream.Write( (int) list.Entity.Serial );
|
||||
m_Stream.Write( (int) list.Hash );
|
||||
}*/
|
||||
|
||||
public OPLInfo(Serial serial, int hash) : base(0xDC, 9)
|
||||
{
|
||||
Stream.Write(serial);
|
||||
Stream.Write(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue