fix: Fixes sending packets and sidesteps a major issue with stackalloc and PGO in .NET 8 (#1607)

### Summary
- Works around a sneaky edge case bug in the JIT with stackalloc where sometimes the buffer is not zero'd.
- Fixes SendDisplayBoatHS
- Fixes sending health bars in the `SendEverything()` logic.
- Fixes a bug in sizing for some string helper functions.

### Developer Note
We are enabled `SkipLocalsInit` - do not rely on `stackalloc` to be zero'd. To zero the buffer, use `span.Clear();`

Closes #1606
This commit is contained in:
Kamron Batman 2023-11-21 12:18:20 -08:00 committed by GitHub
parent 79ba1ea917
commit 03f850fe03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 67 additions and 76 deletions

View file

@ -15,7 +15,10 @@
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Runtime.CompilerServices;
using Server.Items;
using Server.Text;
namespace Server.Network;
@ -25,6 +28,7 @@ public static class OutgoingEntityPackets
public const int RemoveEntityLength = 5;
public const int MaxWorldEntityPacketLength = 26;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CreateOPLInfo(Span<byte> buffer, Item item) =>
CreateOPLInfo(buffer, item.Serial, item.PropertyList.Hash);
@ -41,6 +45,7 @@ public static class OutgoingEntityPackets
writer.Write(hash);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SendOPLInfo(this NetState ns, IObjectPropertyListEntity obj) =>
ns.SendOPLInfo(obj.Serial, obj.PropertyList.Hash);

View file

@ -604,9 +604,7 @@ public static class OutgoingMobilePackets
}
Span<bool> layers = stackalloc bool[256];
#if NO_LOCAL_INIT
layers.Clear();
#endif
layers.Clear();
var eq = beheld.Items;
var maxLength = 23 + (eq.Count + 2) * 9;