From 5882b1ab3f409f52cd165d00666c852aff1121d9 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Fri, 8 Jan 2021 23:55:23 -0800 Subject: [PATCH] fix(core): Fixes OPL packets (#395) - [X] Fixes an issue with OPL packets using the wrong endianness and not updating the position properly. - [X] Fixes an issue with SpanWriter not updating bytes written when it is used adhoc. - [X] Moves packet creation for OPL inside the SendInfoTo function. Bumps release version --- Projects/Server/Buffers/SpanWriter.cs | 2 +- Projects/Server/Items/Item.cs | 9 +++++++-- .../Server/Network/Packets/IncomingEntityPackets.cs | 2 ++ Projects/Server/ObjectPropertyList.cs | 10 +++++----- Projects/UOContent/Items/Misc/Corpses/Corpse.cs | 2 +- Projects/UOContent/Multis/HouseFoundation.cs | 2 +- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Projects/Server/Buffers/SpanWriter.cs b/Projects/Server/Buffers/SpanWriter.cs index 73740af99..7ca8952e5 100644 --- a/Projects/Server/Buffers/SpanWriter.cs +++ b/Projects/Server/Buffers/SpanWriter.cs @@ -365,7 +365,7 @@ namespace System.Buffers Grow(newPosition - _buffer.Length + 1); } - return _position = newPosition; + return Position = newPosition; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Projects/Server/Items/Item.cs b/Projects/Server/Items/Item.cs index c62a1d360..e078aa692 100644 --- a/Projects/Server/Items/Item.cs +++ b/Projects/Server/Items/Item.cs @@ -1152,7 +1152,7 @@ namespace Server Span opl = ObjectPropertyList.Enabled ? stackalloc byte[OutgoingEntityPackets.OPLPacketLength] : null; if (opl != null) { - OutgoingEntityPackets.CreateOPLInfo(opl, this); + opl.InitializePacket(); } var eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange()); @@ -3094,8 +3094,13 @@ namespace Server public virtual int GetUpdateRange(Mobile m) => 18; - public virtual void SendInfoTo(NetState ns, ReadOnlySpan world, ReadOnlySpan opl = default) + public virtual void SendInfoTo(NetState ns, ReadOnlySpan world, Span opl) { + if (opl != null && opl[0] == 0) + { + OutgoingEntityPackets.CreateOPLInfo(opl, this); + } + SendWorldPacketTo(ns, world); SendOPLPacketTo(ns, opl); } diff --git a/Projects/Server/Network/Packets/IncomingEntityPackets.cs b/Projects/Server/Network/Packets/IncomingEntityPackets.cs index ab629a83f..d2ebe2af8 100644 --- a/Projects/Server/Network/Packets/IncomingEntityPackets.cs +++ b/Projects/Server/Network/Packets/IncomingEntityPackets.cs @@ -13,6 +13,8 @@ * along with this program. If not, see . * *************************************************************************/ +using System; + namespace Server.Network { public static class IncomingEntityPackets diff --git a/Projects/Server/ObjectPropertyList.cs b/Projects/Server/ObjectPropertyList.cs index 55d7d4aeb..5092e0173 100644 --- a/Projects/Server/ObjectPropertyList.cs +++ b/Projects/Server/ObjectPropertyList.cs @@ -117,19 +117,19 @@ namespace Server AddHash(arguments.GetHashCode(StringComparison.Ordinal)); } - int strLength = Utility.Unicode.GetByteCount(arguments); - + int strLength = arguments.Length * 2; int length = _position + 6 + strLength; while (length > _buffer.Length) { Flush(); } - var writer = new SpanWriter(_buffer); - writer.Seek(_position, SeekOrigin.Begin); + var writer = new SpanWriter(_buffer.AsSpan(_position)); writer.Write(number); writer.Write((ushort)strLength); - writer.WriteBigUni(arguments); + writer.WriteLittleUni(arguments); + + _position += writer.BytesWritten; } public void Add(int number, string format, object arg0) diff --git a/Projects/UOContent/Items/Misc/Corpses/Corpse.cs b/Projects/UOContent/Items/Misc/Corpses/Corpse.cs index 94df03186..c8593bcc8 100644 --- a/Projects/UOContent/Items/Misc/Corpses/Corpse.cs +++ b/Projects/UOContent/Items/Misc/Corpses/Corpse.cs @@ -825,7 +825,7 @@ namespace Server.Items } } - public override void SendInfoTo(NetState ns, ReadOnlySpan world, ReadOnlySpan opl = default) + public override void SendInfoTo(NetState ns, ReadOnlySpan world, Span opl) { base.SendInfoTo(ns, world, opl); diff --git a/Projects/UOContent/Multis/HouseFoundation.cs b/Projects/UOContent/Multis/HouseFoundation.cs index 4869d67ab..fd05b69ad 100644 --- a/Projects/UOContent/Multis/HouseFoundation.cs +++ b/Projects/UOContent/Multis/HouseFoundation.cs @@ -888,7 +888,7 @@ namespace Server.Multis stateToSend.SendGeneralInfoTo(ns); } - public override void SendInfoTo(NetState ns, ReadOnlySpan world, ReadOnlySpan opl = default) + public override void SendInfoTo(NetState ns, ReadOnlySpan world, Span opl) { base.SendInfoTo(ns, world, opl);