fix(network): Adds UOG & Fixes ConnectUO packet (#552)

- [X] Adds UOG Extended and Compact (0xF1 0x51 packet)
- [X] Fixes ConnectUO bad length
This commit is contained in:
Kamron Batman 2021-03-15 16:18:28 -07:00 committed by GitHub
parent 5e3b42bf9c
commit c50322c0e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 196 additions and 38 deletions

View file

@ -193,7 +193,7 @@ namespace Server.Buffers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Append(uint value)
{
int bufferLength = Utility.CountDigits(value);
int bufferLength = value.CountDigits();
int pos = _length;
if ((uint)pos + (uint)bufferLength >= _chars.Length)

View file

@ -478,7 +478,7 @@ namespace Server
top = zBottom;
}
avg = Math.Abs(zTop - zBottom) > Math.Abs(zLeft - zRight)
avg = (zTop - zBottom).Abs() > (zLeft - zRight).Abs()
? FloorAverage(zLeft, zRight)
: FloorAverage(zTop, zBottom);
}

View file

@ -9086,8 +9086,8 @@ namespace Server
var rx = (dx - dy) * 44;
var ry = (dx + dy) * 44;
var ax = Math.Abs(rx);
var ay = Math.Abs(ry);
var ax = rx.Abs();
var ay = ry.Abs();
Direction ret;

View file

@ -577,8 +577,8 @@ namespace Server
var dx = to.X - from.X;
var dy = to.Y - from.Y;
var adx = Math.Abs(dx);
var ady = Math.Abs(dy);
var adx = Abs(dx);
var ady = Abs(dy);
if (adx >= ady * 3)
{
@ -1395,7 +1395,21 @@ namespace Server
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int CountDigits(uint value)
public static int Abs(this int value)
{
int mask = value >> 31;
return (value + mask) ^ mask;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Abs(this long value)
{
long mask = value >> 63;
return (value + mask) ^ mask;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int CountDigits(this uint value)
{
int digits = 1;
if (value >= 100000)
@ -1428,6 +1442,47 @@ namespace Server
return digits;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int CountDigits(this int value)
{
int absValue = Abs(value);
int digits = 1;
if (absValue >= 100000)
{
absValue /= 100000;
digits += 5;
}
if (absValue < 10)
{
// no-op
}
else if (absValue < 100)
{
digits++;
}
else if (absValue < 1000)
{
digits += 2;
}
else if (absValue < 10000)
{
digits += 3;
}
else
{
digits += 4;
}
if (value < 0)
{
digits += 1; // negative
}
return digits;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint DivRem(uint a, uint b, out uint result)
{