Fix bad serials (#304)

- [X] Fixes bad serial calculations
- [X] Tightens HexStrings

Bumps release version
Updates documentation
This commit is contained in:
Kamron Batman 2020-11-08 12:09:26 -08:00 • committed by GitHub
parent b0c1076cb5
commit ae436cb55f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 76 additions and 51 deletions

View file

@ -0,0 +1,39 @@
using System;
using System.Buffers;
using Server.Network;
namespace Server.Tests.Network
{
public static class AttributeNormalizerUtilities
{
public static void WriteAttribute(this Span<byte> data, ref int pos, int cur, int max, bool normalize)
{
if (normalize && AttributeNormalizer.Enabled && max != 0)
{
var maximum = AttributeNormalizer.Maximum;
data.Write(ref pos, (ushort)maximum);
data.Write(ref pos, (ushort)(cur * maximum / max));
return;
}
data.Write(ref pos, (ushort)max);
data.Write(ref pos, (ushort)cur);
}
public static void WriteReverseAttribute(this Span<byte> data, ref int pos, int cur, int max, bool normalize)
{
if (normalize && AttributeNormalizer.Enabled && max != 0)
{
var maximum = AttributeNormalizer.Maximum;
data.Write(ref pos, (ushort)(cur * maximum / max));
data.Write(ref pos, (ushort)maximum);
return;
}
data.Write(ref pos, (ushort)cur);
data.Write(ref pos, (ushort)max);
}
}
}

View file

@ -0,0 +1,46 @@
using System;
using System.Buffers;
using System.IO.Compression;
using System.Text;
namespace Server.Tests.Network
{
public static class GumpUtilities
{
public const string NoMove = "{ nomove }";
public const string NoClose = "{ noclose }";
public const string NoDispose = "{ nodispose }";
public const string NoResize = "{ noresize }";
public static readonly byte[] NoMoveBuffer = Encoding.ASCII.GetBytes("{ nomove }");
public static readonly byte[] NoCloseBuffer = Encoding.ASCII.GetBytes("{ noclose }");
public static readonly byte[] NoDisposeBuffer = Encoding.ASCII.GetBytes("{ nodispose }");
public static readonly byte[] NoResizeBuffer = Encoding.ASCII.GetBytes("{ noresize }");
public static void WritePacked(this Span<byte> dest, ref int pos, ReadOnlySpan<byte> source)
{
var length = source.Length;
if (length == 0)
{
#if NO_LOCAL_INIT
dest.Write(ref pos, 0);
#else
pos += 4;
#endif
return;
}
var packLength = (ulong)dest.Length - 8;
ZlibError ce = Zlib.Pack(dest.Slice(pos + 8), ref packLength, source, ZlibQuality.Default);
if (ce != ZlibError.Okay)
{
Console.WriteLine("ZLib error: {0} (#{1})", ce, (int)ce);
}
dest.Write(ref pos, (int)(4 + packLength));
dest.Write(ref pos, length);
pos += (int)packLength;
}
}
}

View file

@ -0,0 +1,14 @@
using System;
using Server.Network;
namespace Server.Tests.Network
{
public static class PacketTestUtilities
{
public static Span<byte> Compile(this Packet p) =>
p.Compile(false, out var length).AsSpan(0, length);
public static NetState CreateTestNetState() =>
new NetState(new MockSocket());
}
}