fix: Fixes spawner timer deserialization, decimal deserialization, and adds potion keg reverse lookup (#1711)

### Summary
* Fixes spawner timer deserialization
* Adds a check for a null timer and allows the timer to get recreated
* Adds PotionKeg reverse lookup
* Heavily optimizes decimal serialize/deserialize
This commit is contained in:
Kamron Batman 2024-03-28 13:34:12 -07:00 committed by GitHub
parent 70575e1517
commit 1a7e7c7c70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 126 additions and 49 deletions

View file

@ -19,6 +19,7 @@ using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Server.Text;
@ -290,6 +291,15 @@ public class BufferWriter : IGenericWriter
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Write(decimal value)
{
Span<int> buffer = stackalloc int[sizeof(decimal) / 4];
decimal.GetBits(value, buffer);
Write(MemoryMarshal.Cast<int, byte>(buffer));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalWriteString(string value)
{

View file

@ -39,6 +39,7 @@ public interface IGenericWriter
void Write(bool value);
void Write(Serial serial);
void Write(Type type);
void Write(decimal value);
void Write(DateTime value)
{
@ -79,20 +80,12 @@ public interface IGenericWriter
Write((byte)bytesWritten);
Write(stack[..bytesWritten]);
}
void Write(TimeSpan value)
{
Write(value.Ticks);
}
public void Write(decimal value)
{
var bits = decimal.GetBits(value);
for (var i = 0; i < 4; ++i)
{
Write(bits[i]);
}
}
void WriteEncodedInt(int value)
{
var v = (uint)value;