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