fix(core): Fixes item mask in incoming mobile packet (#568)
- [X] FIxes the item mask in incoming mobile packet - [X] Streamlines some of the send info stuff - [X] Adds a few missing packet initializations
This commit is contained in:
parent
ee61c5a257
commit
b51bab5f1d
9 changed files with 27 additions and 32 deletions
|
|
@ -554,7 +554,7 @@ namespace Server.Tests.Network
|
||||||
var itemID = item.ItemID & itemIdMask;
|
var itemID = item.ItemID & itemIdMask;
|
||||||
var writeHue = newPacket || hue != 0;
|
var writeHue = newPacket || hue != 0;
|
||||||
|
|
||||||
if (!newPacket)
|
if (!newPacket && writeHue)
|
||||||
{
|
{
|
||||||
itemID |= 0x8000;
|
itemID |= 0x8000;
|
||||||
}
|
}
|
||||||
|
|
@ -585,7 +585,7 @@ namespace Server.Tests.Network
|
||||||
var itemID = beheld.HairItemID & itemIdMask;
|
var itemID = beheld.HairItemID & itemIdMask;
|
||||||
var writeHue = newPacket || hue != 0;
|
var writeHue = newPacket || hue != 0;
|
||||||
|
|
||||||
if (!newPacket)
|
if (!newPacket && writeHue)
|
||||||
{
|
{
|
||||||
itemID |= 0x8000;
|
itemID |= 0x8000;
|
||||||
}
|
}
|
||||||
|
|
@ -616,7 +616,7 @@ namespace Server.Tests.Network
|
||||||
var itemID = beheld.FacialHairItemID & itemIdMask;
|
var itemID = beheld.FacialHairItemID & itemIdMask;
|
||||||
var writeHue = newPacket || hue != 0;
|
var writeHue = newPacket || hue != 0;
|
||||||
|
|
||||||
if (!newPacket)
|
if (!newPacket && writeHue)
|
||||||
{
|
{
|
||||||
itemID |= 0x8000;
|
itemID |= 0x8000;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1147,7 +1147,7 @@ namespace Server
|
||||||
{
|
{
|
||||||
if (state.HighSeas)
|
if (state.HighSeas)
|
||||||
{
|
{
|
||||||
var length = OutgoingEntityPackets.CreateWorldEntity(hsWorldItem, this, true, true);
|
var length = OutgoingEntityPackets.CreateWorldEntity(hsWorldItem, this, true);
|
||||||
if (length != hsWorldItem.Length)
|
if (length != hsWorldItem.Length)
|
||||||
{
|
{
|
||||||
hsWorldItem = hsWorldItem.SliceToLength(length);
|
hsWorldItem = hsWorldItem.SliceToLength(length);
|
||||||
|
|
@ -1157,7 +1157,7 @@ namespace Server
|
||||||
}
|
}
|
||||||
else if (state.StygianAbyss)
|
else if (state.StygianAbyss)
|
||||||
{
|
{
|
||||||
var length = OutgoingEntityPackets.CreateWorldEntity(saWorldItem, this, true, false);
|
var length = OutgoingEntityPackets.CreateWorldEntity(saWorldItem, this, false);
|
||||||
if (length != saWorldItem.Length)
|
if (length != saWorldItem.Length)
|
||||||
{
|
{
|
||||||
saWorldItem = saWorldItem.SliceToLength(length);
|
saWorldItem = saWorldItem.SliceToLength(length);
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ namespace Server.Network
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Span<byte> buffer = stackalloc byte[OPLPacketLength];
|
Span<byte> buffer = stackalloc byte[OPLPacketLength].InitializePacket();
|
||||||
CreateOPLInfo(buffer, serial, hash);
|
CreateOPLInfo(buffer, serial, hash);
|
||||||
|
|
||||||
ns.Send(buffer);
|
ns.Send(buffer);
|
||||||
|
|
@ -82,7 +82,7 @@ namespace Server.Network
|
||||||
ns.Send(buffer);
|
ns.Send(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int CreateWorldEntity(Span<byte> buffer, IEntity entity, bool isSA, bool isHS)
|
public static int CreateWorldEntity(Span<byte> buffer, IEntity entity, bool isHS)
|
||||||
{
|
{
|
||||||
if (buffer[0] != 0)
|
if (buffer[0] != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +121,7 @@ namespace Server.Network
|
||||||
type = 1;
|
type = 1;
|
||||||
gfx = mobile.BodyValue;
|
gfx = mobile.BodyValue;
|
||||||
hue = mobile.Hue;
|
hue = mobile.Hue;
|
||||||
flags = mobile.GetPacketFlags(isSA);
|
flags = mobile.GetPacketFlags(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Write((byte)type);
|
writer.Write((byte)type);
|
||||||
|
|
@ -136,7 +136,7 @@ namespace Server.Network
|
||||||
writer.Write((short)(entity.Y & 0x3FFF));
|
writer.Write((short)(entity.Y & 0x3FFF));
|
||||||
writer.Write((sbyte)entity.Z);
|
writer.Write((sbyte)entity.Z);
|
||||||
|
|
||||||
writer.Write((byte)light);
|
writer.Write(light);
|
||||||
writer.Write((short)hue);
|
writer.Write((short)hue);
|
||||||
writer.Write((byte)flags);
|
writer.Write((byte)flags);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,13 @@ namespace Server.Network
|
||||||
{
|
{
|
||||||
if (buffer[0] != 0)
|
if (buffer[0] != 0)
|
||||||
{
|
{
|
||||||
|
// This assumes the packet was sliced properly
|
||||||
return buffer.Length;
|
return buffer.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
var itemID = item is BaseMulti ? item.ItemID | 0x4000 : item.ItemID & 0x3FFF;
|
var itemID = item is BaseMulti ? item.ItemID | 0x4000 : item.ItemID & 0x3FFF;
|
||||||
var hasAmount = item.Amount != 0;
|
|
||||||
var amount = item.Amount;
|
var amount = item.Amount;
|
||||||
|
var hasAmount = amount != 0;
|
||||||
var serial = hasAmount ? item.Serial | 0x80000000 : item.Serial & 0x7FFFFFFF;
|
var serial = hasAmount ? item.Serial | 0x80000000 : item.Serial & 0x7FFFFFFF;
|
||||||
var loc = item.Location;
|
var loc = item.Location;
|
||||||
var hue = item.Hue;
|
var hue = item.Hue;
|
||||||
|
|
@ -52,7 +53,7 @@ namespace Server.Network
|
||||||
writer.Write(serial);
|
writer.Write(serial);
|
||||||
writer.Write((ushort)itemID);
|
writer.Write((ushort)itemID);
|
||||||
|
|
||||||
if (amount != 0)
|
if (hasAmount)
|
||||||
{
|
{
|
||||||
writer.Write((ushort)amount);
|
writer.Write((ushort)amount);
|
||||||
}
|
}
|
||||||
|
|
@ -60,24 +61,24 @@ namespace Server.Network
|
||||||
writer.Write((ushort)x);
|
writer.Write((ushort)x);
|
||||||
writer.Write((ushort)y);
|
writer.Write((ushort)y);
|
||||||
|
|
||||||
if (direction != 0)
|
if (hasDirection)
|
||||||
{
|
{
|
||||||
writer.Write((byte)direction);
|
writer.Write((byte)direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Write((sbyte)loc.Z);
|
writer.Write((sbyte)loc.Z);
|
||||||
|
|
||||||
if (hue != 0)
|
if (hasHue)
|
||||||
{
|
{
|
||||||
writer.Write((ushort)hue);
|
writer.Write((ushort)hue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags != 0)
|
if (hasFlags)
|
||||||
{
|
{
|
||||||
writer.Write((byte)flags);
|
writer.Write((byte)flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return writer.Position;
|
return writer.BytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendWorldItem(this NetState ns, Item item)
|
public static void SendWorldItem(this NetState ns, Item item)
|
||||||
|
|
@ -87,10 +88,10 @@ namespace Server.Network
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Span<byte> buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength];
|
Span<byte> buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength].InitializePacket();
|
||||||
|
|
||||||
var length = ns.StygianAbyss ?
|
var length = ns.StygianAbyss ?
|
||||||
OutgoingEntityPackets.CreateWorldEntity(buffer, item, ns.StygianAbyss, ns.HighSeas) :
|
OutgoingEntityPackets.CreateWorldEntity(buffer, item, ns.HighSeas) :
|
||||||
CreateWorldItem(buffer, item);
|
CreateWorldItem(buffer, item);
|
||||||
|
|
||||||
ns.Send(buffer.SliceToLength(length));
|
ns.Send(buffer.SliceToLength(length));
|
||||||
|
|
|
||||||
|
|
@ -628,7 +628,7 @@ namespace Server.Network
|
||||||
var itemID = item.ItemID & itemIdMask;
|
var itemID = item.ItemID & itemIdMask;
|
||||||
var writeHue = newPacket || hue != 0;
|
var writeHue = newPacket || hue != 0;
|
||||||
|
|
||||||
if (!newPacket)
|
if (!newPacket && writeHue)
|
||||||
{
|
{
|
||||||
itemID |= 0x8000;
|
itemID |= 0x8000;
|
||||||
}
|
}
|
||||||
|
|
@ -651,7 +651,7 @@ namespace Server.Network
|
||||||
var itemID = beheld.HairItemID & itemIdMask;
|
var itemID = beheld.HairItemID & itemIdMask;
|
||||||
var writeHue = newPacket || hue != 0;
|
var writeHue = newPacket || hue != 0;
|
||||||
|
|
||||||
if (!newPacket)
|
if (!newPacket && writeHue)
|
||||||
{
|
{
|
||||||
itemID |= 0x8000;
|
itemID |= 0x8000;
|
||||||
}
|
}
|
||||||
|
|
@ -674,7 +674,7 @@ namespace Server.Network
|
||||||
var itemID = beheld.FacialHairItemID & itemIdMask;
|
var itemID = beheld.FacialHairItemID & itemIdMask;
|
||||||
var writeHue = newPacket || hue != 0;
|
var writeHue = newPacket || hue != 0;
|
||||||
|
|
||||||
if (!newPacket)
|
if (!newPacket && writeHue)
|
||||||
{
|
{
|
||||||
itemID |= 0x8000;
|
itemID |= 0x8000;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,13 @@ namespace Server.Items
|
||||||
private void SendGMItem(NetState ns)
|
private void SendGMItem(NetState ns)
|
||||||
{
|
{
|
||||||
// GM Packet
|
// GM Packet
|
||||||
Span<byte> buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength];
|
Span<byte> buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength].InitializePacket();
|
||||||
|
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
if (ns.StygianAbyss)
|
if (ns.StygianAbyss)
|
||||||
{
|
{
|
||||||
length = OutgoingEntityPackets.CreateWorldEntity(buffer, this, ns.StygianAbyss, ns.HighSeas);
|
length = OutgoingEntityPackets.CreateWorldEntity(buffer, this, ns.HighSeas);
|
||||||
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
|
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,13 @@ namespace Server.Items
|
||||||
private void SendGMItem(NetState ns)
|
private void SendGMItem(NetState ns)
|
||||||
{
|
{
|
||||||
// GM Packet
|
// GM Packet
|
||||||
Span<byte> buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength];
|
Span<byte> buffer = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength].InitializePacket();
|
||||||
|
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
if (ns.StygianAbyss)
|
if (ns.StygianAbyss)
|
||||||
{
|
{
|
||||||
length = OutgoingEntityPackets.CreateWorldEntity(buffer, this, ns.StygianAbyss, ns.HighSeas);
|
length = OutgoingEntityPackets.CreateWorldEntity(buffer, this, ns.HighSeas);
|
||||||
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
|
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,6 @@ namespace Server.Multis.Boats
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSA = ns.StygianAbyss;
|
|
||||||
bool isHS = ns.HighSeas;
|
|
||||||
|
|
||||||
var minLength = PacketContainerBuilder.MinPacketLength
|
var minLength = PacketContainerBuilder.MinPacketLength
|
||||||
+ OutgoingEntityPackets.MaxWorldEntityPacketLength
|
+ OutgoingEntityPackets.MaxWorldEntityPacketLength
|
||||||
* 5; // Minimum of boat, hold, planks, and the player
|
* 5; // Minimum of boat, hold, planks, and the player
|
||||||
|
|
@ -95,7 +92,7 @@ namespace Server.Multis.Boats
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.InitializePacket();
|
buffer.InitializePacket();
|
||||||
var bytesWritten = OutgoingEntityPackets.CreateWorldEntity(buffer, entity, isSA, isHS);
|
var bytesWritten = OutgoingEntityPackets.CreateWorldEntity(buffer, entity, true);
|
||||||
builder.Advance(bytesWritten);
|
builder.Advance(bytesWritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,6 @@ namespace Server.Network
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSA = ns.StygianAbyss;
|
|
||||||
bool isHS = ns.HighSeas;
|
|
||||||
|
|
||||||
var minLength = PacketContainerBuilder.MinPacketLength
|
var minLength = PacketContainerBuilder.MinPacketLength
|
||||||
+ OutgoingEntityPackets.MaxWorldEntityPacketLength
|
+ OutgoingEntityPackets.MaxWorldEntityPacketLength
|
||||||
* estimatedCount;
|
* estimatedCount;
|
||||||
|
|
@ -46,7 +43,7 @@ namespace Server.Network
|
||||||
foreach (var entity in entities)
|
foreach (var entity in entities)
|
||||||
{
|
{
|
||||||
buffer.InitializePacket();
|
buffer.InitializePacket();
|
||||||
var bytesWritten = OutgoingEntityPackets.CreateWorldEntity(buffer, entity, isSA, isHS);
|
var bytesWritten = OutgoingEntityPackets.CreateWorldEntity(buffer, entity, true);
|
||||||
builder.Advance(bytesWritten);
|
builder.Advance(bytesWritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue