Adds style cop (#109)
This commit is contained in:
parent
3e715bcb60
commit
556a17aba8
1725 changed files with 33831 additions and 38046 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
|
|
@ -9,11 +8,11 @@ namespace Server.Utilities
|
|||
{
|
||||
public static ConstructorInfo GetConstructor(Type type, Predicate<ConstructorInfo> predicate = null)
|
||||
{
|
||||
ConstructorInfo emptyCtor = type.GetConstructor(Type.EmptyTypes);
|
||||
var emptyCtor = type.GetConstructor(Type.EmptyTypes);
|
||||
|
||||
if (emptyCtor != null && predicate?.Invoke(emptyCtor) != false) return emptyCtor;
|
||||
|
||||
ConstructorInfo optionalCtor = type.GetConstructors().SingleOrDefault(info =>
|
||||
var optionalCtor = type.GetConstructors().SingleOrDefault(info =>
|
||||
predicate?.Invoke(info) != false && info.GetParameters().All(x => x.IsOptional));
|
||||
|
||||
if (optionalCtor != null) return optionalCtor;
|
||||
|
|
@ -40,25 +39,25 @@ namespace Server.Utilities
|
|||
{
|
||||
if (predicate?.Invoke(info) == false) return false;
|
||||
|
||||
List<ParameterInfo> paramList = info.GetParameters().ToList();
|
||||
var paramList = info.GetParameters().ToList();
|
||||
|
||||
// If more args are given than parameters, skip.
|
||||
if (args.Length > paramList.Count) return false;
|
||||
|
||||
// check all given args map to params.
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
// if a null reference is passed, but the type is not nullable
|
||||
if (args[i] == null && paramList[i].ParameterType.IsValueType
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
// if a null reference is passed, but the type is not nullable
|
||||
if ((args[i] == null && paramList[i].ParameterType.IsValueType)
|
||||
// or if an arg is not null and is not assignable to the parameter type, skip.
|
||||
|| !(args[i] == null || paramList[i].ParameterType.IsAssignableFrom(args[i])))
|
||||
return false;
|
||||
|
||||
// If there are more parameters, check if they any are not optional, if any are not, skip.
|
||||
// Otherwise all checks have passed. We have found a match
|
||||
// Otherwise all checks have passed. We have found a match
|
||||
return args.Length <= paramList.Count || paramList.GetRange(args.Length, paramList.Count - args.Length)
|
||||
.All(x => x.IsOptional);
|
||||
.All(x => x.IsOptional);
|
||||
});
|
||||
|
||||
|
||||
if (ctor != null) return ctor;
|
||||
}
|
||||
|
||||
|
|
@ -72,12 +71,12 @@ namespace Server.Utilities
|
|||
|
||||
public static object CreateInstance(Type type, Predicate<ConstructorInfo> constructorPredicate = null)
|
||||
{
|
||||
ConstructorInfo cctor = GetConstructor(type, constructorPredicate);
|
||||
ParameterInfo[] args = cctor.GetParameters();
|
||||
var cctor = GetConstructor(type, constructorPredicate);
|
||||
var args = cctor.GetParameters();
|
||||
|
||||
if (args.Length == 0) return cctor.Invoke(Type.EmptyTypes);
|
||||
|
||||
object[] argList = new object[args.Length];
|
||||
var argList = new object[args.Length];
|
||||
Array.Fill(argList, Type.Missing);
|
||||
return cctor.Invoke(argList);
|
||||
}
|
||||
|
|
@ -87,12 +86,15 @@ namespace Server.Utilities
|
|||
{
|
||||
if (args == null || args.Length == 0) return CreateInstance(type, constructorPredicate);
|
||||
|
||||
ConstructorInfo cctor = GetConstructor(type, constructorPredicate, args.Select(x => x?.GetType()).ToArray());
|
||||
var cctor = GetConstructor(type, constructorPredicate, args.Select(x => x?.GetType()).ToArray());
|
||||
return cctor.Invoke(args);
|
||||
}
|
||||
|
||||
public static object CreateInstance(Type type, params object[] args) => CreateInstance(type, null, args);
|
||||
public static T CreateInstance<T>(Predicate<ConstructorInfo> constructorPredicate = null) => (T)CreateInstance(typeof(T), constructorPredicate);
|
||||
|
||||
public static T CreateInstance<T>(Predicate<ConstructorInfo> constructorPredicate = null) =>
|
||||
(T)CreateInstance(typeof(T), constructorPredicate);
|
||||
|
||||
public static T CreateInstance<T>(params object[] args) => (T)CreateInstance(typeof(T), null, args);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: DRng64.cs - Created: 2019/12/30 - Updated: 2019/12/30 *
|
||||
* *
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
|
|
@ -38,21 +39,15 @@ namespace Server
|
|||
Success = 1
|
||||
}
|
||||
|
||||
[DllImport("libdrng", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern RDRandError rdrand_64(ref ulong rand, bool retry);
|
||||
|
||||
[DllImport("libdrng", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe RDRandError rdrand_get_bytes(int n, byte* buffer);
|
||||
|
||||
public bool IsSupported()
|
||||
{
|
||||
ulong r = 0;
|
||||
return rdrand_64(ref r, true) == RDRandError.Success;
|
||||
return SafeNativeMethods.rdrand_64(ref r, true) == RDRandError.Success;
|
||||
}
|
||||
|
||||
private static unsafe void GetBytes(byte* pBuffer, int count)
|
||||
{
|
||||
rdrand_get_bytes(count, pBuffer);
|
||||
SafeNativeMethods.rdrand_get_bytes(count, pBuffer);
|
||||
}
|
||||
|
||||
public override void GetBytes(byte[] data)
|
||||
|
|
@ -69,7 +64,10 @@ namespace Server
|
|||
public override unsafe void GetBytes(Span<byte> data)
|
||||
{
|
||||
if (data.Length > 0)
|
||||
fixed (byte* ptr = data) GetBytes(ptr, data.Length);
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
GetBytes(ptr, data.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetNonZeroBytes(byte[] data)
|
||||
|
|
@ -86,8 +84,8 @@ namespace Server
|
|||
GetBytes(data);
|
||||
|
||||
// Find the first zero in the remaining portion.
|
||||
int indexOfFirst0Byte = data.Length;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
var indexOfFirst0Byte = data.Length;
|
||||
for (var i = 0; i < data.Length; i++)
|
||||
if (data[i] == 0)
|
||||
{
|
||||
indexOfFirst0Byte = i;
|
||||
|
|
@ -95,13 +93,23 @@ namespace Server
|
|||
}
|
||||
|
||||
// If there were any zeros, shift down all non-zeros.
|
||||
for (int i = indexOfFirst0Byte + 1; i < data.Length; i++)
|
||||
if (data[i] != 0) data[indexOfFirst0Byte++] = data[i];
|
||||
for (var i = indexOfFirst0Byte + 1; i < data.Length; i++)
|
||||
if (data[i] != 0)
|
||||
data[indexOfFirst0Byte++] = data[i];
|
||||
|
||||
// Request new random bytes if necessary; dont re-use
|
||||
// existing bytes since they were shifted down.
|
||||
data = data.Slice(indexOfFirst0Byte);
|
||||
}
|
||||
}
|
||||
|
||||
internal class SafeNativeMethods
|
||||
{
|
||||
[DllImport("libdrng", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern RDRandError rdrand_64(ref ulong rand, bool retry);
|
||||
|
||||
[DllImport("libdrng", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe RDRandError rdrand_get_bytes(int n, byte* buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: Random.cs - Created: 2019/12/30 - Updated: 2019/01/05 *
|
||||
* *
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ namespace Server.Utilities
|
|||
/// Disposing the reference is expected to return itself back into the
|
||||
/// original pool that created it.
|
||||
/// </remarks>
|
||||
public interface IRef : IDisposable { }
|
||||
public interface IRef : IDisposable
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base implementation of the <see cref="IRef"/> interface.
|
||||
|
|
@ -23,6 +25,7 @@ namespace Server.Utilities
|
|||
private readonly RefPool<TDerived> m_Pool;
|
||||
public BaseRef(RefPool<TDerived> pool) => m_Pool = pool;
|
||||
protected abstract void OnDispose();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
OnDispose();
|
||||
|
|
@ -37,6 +40,7 @@ namespace Server.Utilities
|
|||
public class RefPool<TRef> where TRef : IRef
|
||||
{
|
||||
public delegate TRef Generator(RefPool<TRef> targetPool);
|
||||
|
||||
public const int DEFAULT_RESOURCE_RETENTION = 10;
|
||||
|
||||
private readonly Stack<TRef> m_Resources = new Stack<TRef>();
|
||||
|
|
@ -68,12 +72,14 @@ namespace Server.Utilities
|
|||
m_MaxRefrenceRetention = maxRefrenceRetention;
|
||||
while (--preGenerateCount >= 0) m_Resources.Push(generator(this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a resource reference that is managed by this <see cref="RefPool{TRef}"/>. If the pool is has unused resources,
|
||||
/// it will remove one from the pool and return it; otherwise, a new resource will be generated.
|
||||
/// </summary>
|
||||
/// <returns>Unused resource, or a new resource if no unused resources available.</returns>
|
||||
public TRef Get() => m_Resources.TryPop(out TRef item) ? item : m_Generator(this);
|
||||
public TRef Get() => m_Resources.TryPop(out var item) ? item : m_Generator(this);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a resource reference to the pool of unused resources.
|
||||
/// </summary>
|
||||
|
|
@ -84,27 +90,37 @@ namespace Server.Utilities
|
|||
m_Resources.Push(queueRef);
|
||||
}
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
|
||||
public class QueueRef<T> : Queue<T>, IRef
|
||||
{
|
||||
private readonly RefPool<QueueRef<T>> m_Pool;
|
||||
private QueueRef(RefPool<QueueRef<T>> pool) => m_Pool = pool;
|
||||
|
||||
/// <summary>Clears the queue and returns this resource to its parent resource pool.</summary>
|
||||
public void Dispose() { Clear(); m_Pool.Return(this); }
|
||||
public void Dispose()
|
||||
{
|
||||
Clear();
|
||||
m_Pool.Return(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generator function for creating instances of the <see cref="QueueRef{T}"/> resource.
|
||||
/// </summary>
|
||||
public static RefPool<QueueRef<T>>.Generator Generate = (targetPool) => new QueueRef<T>(targetPool);
|
||||
public static RefPool<QueueRef<T>>.Generator Generate = targetPool => new QueueRef<T>(targetPool);
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
|
||||
public class StackRef<T> : Stack<T>, IRef
|
||||
{
|
||||
private readonly RefPool<StackRef<T>> m_Pool;
|
||||
private StackRef(RefPool<StackRef<T>> pool) => m_Pool = pool;
|
||||
|
||||
/// <summary>Clears the stack and returns this resource to its parent resource pool.</summary>
|
||||
public void Dispose() { Clear(); m_Pool.Return(this); }
|
||||
public void Dispose()
|
||||
{
|
||||
Clear();
|
||||
m_Pool.Return(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generator function for creating instances of the <see cref="StackRef{T}"/> resource.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ namespace Server
|
|||
{
|
||||
_ipAddressTable ??= new Dictionary<IPAddress, IPAddress>();
|
||||
|
||||
if (!_ipAddressTable.TryGetValue(ipAddress, out IPAddress interned))
|
||||
if (!_ipAddressTable.TryGetValue(ipAddress, out var interned))
|
||||
{
|
||||
interned = ipAddress;
|
||||
_ipAddressTable[ipAddress] = interned;
|
||||
|
|
@ -157,7 +157,7 @@ namespace Server
|
|||
|
||||
public static bool IsValidIP(string text)
|
||||
{
|
||||
IPMatch(text, IPAddress.None, out bool valid);
|
||||
IPMatch(text, IPAddress.None, out var valid);
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
|
@ -169,14 +169,14 @@ namespace Server
|
|||
if (str == null)
|
||||
return "";
|
||||
|
||||
bool hasOpen = str.IndexOf('<') >= 0;
|
||||
bool hasClose = str.IndexOf('>') >= 0;
|
||||
bool hasPound = str.IndexOf('#') >= 0;
|
||||
var hasOpen = str.IndexOf('<') >= 0;
|
||||
var hasClose = str.IndexOf('>') >= 0;
|
||||
var hasPound = str.IndexOf('#') >= 0;
|
||||
|
||||
if (!hasOpen && !hasClose && !hasPound)
|
||||
return str;
|
||||
|
||||
StringBuilder sb = new StringBuilder(str);
|
||||
var sb = new StringBuilder(str);
|
||||
|
||||
if (hasOpen)
|
||||
sb.Replace('<', '(');
|
||||
|
|
@ -193,59 +193,24 @@ namespace Server
|
|||
public static bool IPMatchCIDR(string cidr, IPAddress ip)
|
||||
{
|
||||
if (ip == null || ip.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
return false; //Just worry about IPv4 for now
|
||||
return false; // Just worry about IPv4 for now
|
||||
|
||||
var bytes = new byte[4];
|
||||
var split = cidr.Split('.');
|
||||
var cidrBits = false;
|
||||
var cidrLength = 0;
|
||||
|
||||
/*
|
||||
string[] str = cidr.Split( '/' );
|
||||
|
||||
if ( str.Length != 2 )
|
||||
return false;
|
||||
|
||||
/* **************************************************
|
||||
IPAddress cidrPrefix;
|
||||
|
||||
if ( !IPAddress.TryParse( str[0], out cidrPrefix ) )
|
||||
return false;
|
||||
* */
|
||||
|
||||
/*
|
||||
string[] dotSplit = str[0].Split( '.' );
|
||||
|
||||
if ( dotSplit.Length != 4 ) //At this point and time, and for speed sake, we'll only worry about IPv4
|
||||
return false;
|
||||
|
||||
byte[] bytes = new byte[4];
|
||||
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
byte.TryParse( dotSplit[i], out bytes[i] );
|
||||
}
|
||||
var part = 0;
|
||||
|
||||
uint cidrPrefix = OrderedAddressValue( bytes );
|
||||
var partBase = 10;
|
||||
|
||||
int cidrLength = Utility.ToInt32( str[1] );
|
||||
//The below solution is the fastest solution of the three
|
||||
var pattern = split[i];
|
||||
|
||||
*/
|
||||
|
||||
byte[] bytes = new byte[4];
|
||||
string[] split = cidr.Split('.');
|
||||
bool cidrBits = false;
|
||||
int cidrLength = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int part = 0;
|
||||
|
||||
int partBase = 10;
|
||||
|
||||
string pattern = split[i];
|
||||
|
||||
for (int j = 0; j < pattern.Length; j++)
|
||||
for (var j = 0; j < pattern.Length; j++)
|
||||
{
|
||||
char c = pattern[j];
|
||||
|
||||
var c = pattern[j];
|
||||
|
||||
if (c == 'x' || c == 'X')
|
||||
{
|
||||
|
|
@ -253,7 +218,7 @@ namespace Server
|
|||
}
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
int offset = c - '0';
|
||||
var offset = c - '0';
|
||||
|
||||
if (cidrBits)
|
||||
{
|
||||
|
|
@ -268,7 +233,7 @@ namespace Server
|
|||
}
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
{
|
||||
int offset = 10 + (c - 'a');
|
||||
var offset = 10 + (c - 'a');
|
||||
|
||||
if (cidrBits)
|
||||
{
|
||||
|
|
@ -283,7 +248,7 @@ namespace Server
|
|||
}
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
{
|
||||
int offset = 10 + (c - 'A');
|
||||
var offset = 10 + (c - 'A');
|
||||
|
||||
if (cidrBits)
|
||||
{
|
||||
|
|
@ -298,7 +263,7 @@ namespace Server
|
|||
}
|
||||
else if (c == '/')
|
||||
{
|
||||
if (cidrBits || i != 3) //If there's two '/' or the '/' isn't in the last byte
|
||||
if (cidrBits || i != 3) // If there's two '/' or the '/' isn't in the last byte
|
||||
return false;
|
||||
|
||||
partBase = 10;
|
||||
|
|
@ -318,12 +283,12 @@ namespace Server
|
|||
|
||||
public static bool IPMatchCIDR(IPAddress cidrPrefix, IPAddress ip, int cidrLength)
|
||||
{
|
||||
//Ignore IPv6 for now
|
||||
// Ignore IPv6 for now
|
||||
if (cidrPrefix == null || ip == null || cidrPrefix.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
return false;
|
||||
|
||||
uint cidrValue = SwapUnsignedInt((uint)GetLongAddressValue(cidrPrefix));
|
||||
uint ipValue = SwapUnsignedInt((uint)GetLongAddressValue(ip));
|
||||
var cidrValue = SwapUnsignedInt((uint)GetLongAddressValue(cidrPrefix));
|
||||
var ipValue = SwapUnsignedInt((uint)GetLongAddressValue(ip));
|
||||
|
||||
return IPMatchCIDR(cidrValue, ipValue, cidrLength);
|
||||
}
|
||||
|
|
@ -333,17 +298,17 @@ namespace Server
|
|||
if (ip == null || ip.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
return false;
|
||||
|
||||
uint ipValue = SwapUnsignedInt((uint)GetLongAddressValue(ip));
|
||||
var ipValue = SwapUnsignedInt((uint)GetLongAddressValue(ip));
|
||||
|
||||
return IPMatchCIDR(cidrPrefixValue, ipValue, cidrLength);
|
||||
}
|
||||
|
||||
public static bool IPMatchCIDR(uint cidrPrefixValue, uint ipValue, int cidrLength)
|
||||
{
|
||||
if (cidrLength <= 0 || cidrLength >= 32) //if invalid cidr Length, just compare IPs
|
||||
if (cidrLength <= 0 || cidrLength >= 32) // if invalid cidr Length, just compare IPs
|
||||
return cidrPrefixValue == ipValue;
|
||||
|
||||
uint mask = uint.MaxValue << 32 - cidrLength;
|
||||
var mask = uint.MaxValue << (32 - cidrLength);
|
||||
|
||||
return (cidrPrefixValue & mask) == (ipValue & mask);
|
||||
}
|
||||
|
|
@ -353,33 +318,33 @@ namespace Server
|
|||
if (bytes.Length != 4)
|
||||
return 0;
|
||||
|
||||
return (uint)(bytes[0] << 0x18 | bytes[1] << 0x10 | bytes[2] << 8 | bytes[3]) & 0xffffffff;
|
||||
return (uint)((bytes[0] << 0x18) | (bytes[1] << 0x10) | (bytes[2] << 8) | bytes[3]) & 0xffffffff;
|
||||
}
|
||||
|
||||
private static uint SwapUnsignedInt(uint source) =>
|
||||
(source & 0x000000FF) << 0x18
|
||||
| (source & 0x0000FF00) << 8
|
||||
| (source & 0x00FF0000) >> 8
|
||||
| (source & 0xFF000000) >> 0x18;
|
||||
((source & 0x000000FF) << 0x18)
|
||||
| ((source & 0x0000FF00) << 8)
|
||||
| ((source & 0x00FF0000) >> 8)
|
||||
| ((source & 0xFF000000) >> 0x18);
|
||||
|
||||
public static bool TryConvertIPv6toIPv4(ref IPAddress address)
|
||||
{
|
||||
if (!Socket.OSSupportsIPv6 || address.AddressFamily == AddressFamily.InterNetwork)
|
||||
return true;
|
||||
|
||||
byte[] addr = address.GetAddressBytes();
|
||||
if (addr.Length == 16) //sanity 0 - 15 //10 11 //12 13 14 15
|
||||
var addr = address.GetAddressBytes();
|
||||
if (addr.Length == 16) // sanity 0 - 15 //10 11 //12 13 14 15
|
||||
{
|
||||
if (addr[10] != 0xFF || addr[11] != 0xFF)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (var i = 0; i < 10; i++)
|
||||
if (addr[i] != 0)
|
||||
return false;
|
||||
|
||||
byte[] v4Addr = new byte[4];
|
||||
var v4Addr = new byte[4];
|
||||
|
||||
for (int i = 0; i < 4; i++) v4Addr[i] = addr[12 + i];
|
||||
for (var i = 0; i < 4; i++) v4Addr[i] = addr[12 + i];
|
||||
|
||||
address = new IPAddress(v4Addr);
|
||||
return true;
|
||||
|
|
@ -392,9 +357,9 @@ namespace Server
|
|||
{
|
||||
valid = true;
|
||||
|
||||
string[] split = val.Split('.');
|
||||
var split = val.Split('.');
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (var i = 0; i < 4; ++i)
|
||||
{
|
||||
int lowPart, highPart;
|
||||
|
||||
|
|
@ -405,7 +370,7 @@ namespace Server
|
|||
}
|
||||
else
|
||||
{
|
||||
string pattern = split[i];
|
||||
var pattern = split[i];
|
||||
|
||||
if (pattern == "*")
|
||||
{
|
||||
|
|
@ -417,13 +382,13 @@ namespace Server
|
|||
lowPart = 0;
|
||||
highPart = 0;
|
||||
|
||||
bool highOnly = false;
|
||||
int lowBase = 10;
|
||||
int highBase = 10;
|
||||
var highOnly = false;
|
||||
var lowBase = 10;
|
||||
var highBase = 10;
|
||||
|
||||
for (int j = 0; j < pattern.Length; ++j)
|
||||
for (var j = 0; j < pattern.Length; ++j)
|
||||
{
|
||||
char c = pattern[j];
|
||||
var c = pattern[j];
|
||||
|
||||
if (c == '?')
|
||||
{
|
||||
|
|
@ -448,7 +413,7 @@ namespace Server
|
|||
}
|
||||
else if (c >= '0' && c <= '9')
|
||||
{
|
||||
int offset = c - '0';
|
||||
var offset = c - '0';
|
||||
|
||||
if (!highOnly)
|
||||
{
|
||||
|
|
@ -461,7 +426,7 @@ namespace Server
|
|||
}
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
{
|
||||
int offset = 10 + (c - 'a');
|
||||
var offset = 10 + (c - 'a');
|
||||
|
||||
if (!highOnly)
|
||||
{
|
||||
|
|
@ -474,7 +439,7 @@ namespace Server
|
|||
}
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
{
|
||||
int offset = 10 + (c - 'A');
|
||||
var offset = 10 + (c - 'A');
|
||||
|
||||
if (!highOnly)
|
||||
{
|
||||
|
|
@ -487,13 +452,13 @@ namespace Server
|
|||
}
|
||||
else
|
||||
{
|
||||
valid = false; //high & lowp art would be 0 if it got to here.
|
||||
valid = false; // high & lowp art would be 0 if it got to here.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int b = (byte)(GetAddressValue(ip) >> i * 8);
|
||||
int b = (byte)(GetAddressValue(ip) >> (i * 8));
|
||||
|
||||
if (b < lowPart || b > highPart)
|
||||
return false;
|
||||
|
|
@ -502,7 +467,8 @@ namespace Server
|
|||
return true;
|
||||
}
|
||||
|
||||
public static bool IPMatchClassC(IPAddress ip1, IPAddress ip2) => (GetAddressValue(ip1) & 0xFFFFFF) == (GetAddressValue(ip2) & 0xFFFFFF);
|
||||
public static bool IPMatchClassC(IPAddress ip1, IPAddress ip2) =>
|
||||
(GetAddressValue(ip1) & 0xFFFFFF) == (GetAddressValue(ip2) & 0xFFFFFF);
|
||||
|
||||
public static int InsensitiveCompare(string first, string second) => Insensitive.Compare(first, second);
|
||||
|
||||
|
|
@ -510,11 +476,11 @@ namespace Server
|
|||
|
||||
public static Direction GetDirection(IPoint2D from, IPoint2D to)
|
||||
{
|
||||
int dx = to.X - from.X;
|
||||
int dy = to.Y - from.Y;
|
||||
var dx = to.X - from.X;
|
||||
var dy = to.Y - from.Y;
|
||||
|
||||
int adx = Math.Abs(dx);
|
||||
int ady = Math.Abs(dy);
|
||||
var adx = Math.Abs(dx);
|
||||
var ady = Math.Abs(dy);
|
||||
|
||||
if (adx >= ady * 3) return dx > 0 ? Direction.East : Direction.West;
|
||||
|
||||
|
|
@ -525,55 +491,6 @@ namespace Server
|
|||
return dy > 0 ? Direction.Left : Direction.Up;
|
||||
}
|
||||
|
||||
/* Should probably be rewritten to use an ITile interface
|
||||
|
||||
public static bool CanMobileFit( int z, StaticTile[] tiles )
|
||||
{
|
||||
int checkHeight = 15;
|
||||
int checkZ = z;
|
||||
|
||||
for ( int i = 0; i < tiles.Length; ++i )
|
||||
{
|
||||
StaticTile tile = tiles[i];
|
||||
|
||||
if ( ((checkZ + checkHeight) > tile.Z && checkZ < (tile.Z + tile.Height))*/
|
||||
/* || (tile.Z < (checkZ + checkHeight) && (tile.Z + tile.Height) > checkZ)*/ /* )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( checkHeight == 0 && tile.Height == 0 && checkZ == tile.Z )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsInContact( StaticTile check, StaticTile[] tiles )
|
||||
{
|
||||
int checkHeight = check.Height;
|
||||
int checkZ = check.Z;
|
||||
|
||||
for ( int i = 0; i < tiles.Length; ++i )
|
||||
{
|
||||
StaticTile tile = tiles[i];
|
||||
|
||||
if ( ((checkZ + checkHeight) > tile.Z && checkZ < (tile.Z + tile.Height))*/
|
||||
/* || (tile.Z < (checkZ + checkHeight) && (tile.Z + tile.Height) > checkZ)*/ /* )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( checkHeight == 0 && tile.Height == 0 && checkZ == tile.Z )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
public static object GetArrayCap(Array array, int index, object emptyValue = null)
|
||||
{
|
||||
if (array.Length > 0)
|
||||
|
|
@ -588,7 +505,8 @@ namespace Server
|
|||
return emptyValue;
|
||||
}
|
||||
|
||||
public static SkillName RandomSkill() => m_AllSkills[Random(m_AllSkills.Length - (Core.ML ? 0 : Core.SE ? 1 : Core.AOS ? 3 : 6))];
|
||||
public static SkillName RandomSkill() =>
|
||||
m_AllSkills[Random(m_AllSkills.Length - (Core.ML ? 0 : Core.SE ? 1 : Core.AOS ? 3 : 6))];
|
||||
|
||||
public static SkillName RandomCombatSkill() => m_CombatSkills[Random(m_CombatSkills.Length)];
|
||||
|
||||
|
|
@ -598,21 +516,21 @@ namespace Server
|
|||
{
|
||||
if (bottom.m_X < top.m_X)
|
||||
{
|
||||
int swap = top.m_X;
|
||||
var swap = top.m_X;
|
||||
top.m_X = bottom.m_X;
|
||||
bottom.m_X = swap;
|
||||
}
|
||||
|
||||
if (bottom.m_Y < top.m_Y)
|
||||
{
|
||||
int swap = top.m_Y;
|
||||
var swap = top.m_Y;
|
||||
top.m_Y = bottom.m_Y;
|
||||
bottom.m_Y = swap;
|
||||
}
|
||||
|
||||
if (bottom.m_Z < top.m_Z)
|
||||
{
|
||||
int swap = top.m_Z;
|
||||
var swap = top.m_Z;
|
||||
top.m_Z = bottom.m_Z;
|
||||
bottom.m_Z = swap;
|
||||
}
|
||||
|
|
@ -629,19 +547,19 @@ namespace Server
|
|||
output.WriteLine(" 0 1 2 3 4 5 6 7 8 9 A B C D E F");
|
||||
output.WriteLine(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
|
||||
|
||||
int byteIndex = 0;
|
||||
var byteIndex = 0;
|
||||
|
||||
int whole = length >> 4;
|
||||
int rem = length & 0xF;
|
||||
var whole = length >> 4;
|
||||
var rem = length & 0xF;
|
||||
|
||||
for (int i = 0; i < whole; ++i, byteIndex += 16)
|
||||
for (var i = 0; i < whole; ++i, byteIndex += 16)
|
||||
{
|
||||
StringBuilder bytes = new StringBuilder(49);
|
||||
StringBuilder chars = new StringBuilder(16);
|
||||
var bytes = new StringBuilder(49);
|
||||
var chars = new StringBuilder(16);
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
for (var j = 0; j < 16; ++j)
|
||||
{
|
||||
int c = input.ReadByte();
|
||||
var c = input.ReadByte();
|
||||
|
||||
bytes.Append(c.ToString("X2"));
|
||||
|
||||
|
|
@ -665,13 +583,13 @@ namespace Server
|
|||
|
||||
if (rem != 0)
|
||||
{
|
||||
StringBuilder bytes = new StringBuilder(49);
|
||||
StringBuilder chars = new StringBuilder(rem);
|
||||
var bytes = new StringBuilder(49);
|
||||
var chars = new StringBuilder(rem);
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
for (var j = 0; j < 16; ++j)
|
||||
if (j < rem)
|
||||
{
|
||||
int c = input.ReadByte();
|
||||
var c = input.ReadByte();
|
||||
|
||||
bytes.Append(c.ToString("X2"));
|
||||
|
||||
|
|
@ -727,7 +645,7 @@ namespace Server
|
|||
{
|
||||
if (bound1 > bound2)
|
||||
{
|
||||
int i = bound1;
|
||||
var i = bound1;
|
||||
bound1 = bound2;
|
||||
bound2 = i;
|
||||
}
|
||||
|
|
@ -771,31 +689,38 @@ namespace Server
|
|||
|
||||
public static List<TOutput> SafeConvertList<TInput, TOutput>(List<TInput> list) where TOutput : class
|
||||
{
|
||||
List<TOutput> output = new List<TOutput>(list.Capacity);
|
||||
if ((list?.Capacity ?? 0) == 0)
|
||||
return new List<TOutput>();
|
||||
|
||||
var output = new List<TOutput>(list.Capacity);
|
||||
output.AddRange(list.OfType<TOutput>());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
#region To[Something]
|
||||
|
||||
public static bool ToBoolean(string value)
|
||||
{
|
||||
bool.TryParse(value, out bool b);
|
||||
#pragma warning disable CA1806 // Do not ignore method results
|
||||
bool.TryParse(value, out var b);
|
||||
#pragma warning restore CA1806 // Do not ignore method results
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public static double ToDouble(string value)
|
||||
{
|
||||
double.TryParse(value, out double d);
|
||||
#pragma warning disable CA1806 // Do not ignore method results
|
||||
double.TryParse(value, out var d);
|
||||
#pragma warning restore CA1806 // Do not ignore method results
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public static TimeSpan ToTimeSpan(string value)
|
||||
{
|
||||
TimeSpan.TryParse(value, out TimeSpan t);
|
||||
#pragma warning disable CA1806 // Do not ignore method results
|
||||
TimeSpan.TryParse(value, out var t);
|
||||
#pragma warning restore CA1806 // Do not ignore method results
|
||||
|
||||
return t;
|
||||
}
|
||||
|
|
@ -804,10 +729,12 @@ namespace Server
|
|||
{
|
||||
int i;
|
||||
|
||||
#pragma warning disable CA1806 // Do not ignore method results
|
||||
if (value.StartsWith("0x"))
|
||||
int.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i);
|
||||
else
|
||||
int.TryParse(value, out i);
|
||||
#pragma warning restore CA1806 // Do not ignore method results
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
@ -816,17 +743,25 @@ namespace Server
|
|||
{
|
||||
uint i;
|
||||
|
||||
#pragma warning disable CA1806 // Do not ignore method results
|
||||
if (value.StartsWith("0x"))
|
||||
uint.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i);
|
||||
else
|
||||
uint.TryParse(value, out i);
|
||||
#pragma warning restore CA1806 // Do not ignore method results
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public static bool ToInt32(string value, out int i) =>
|
||||
value.StartsWith("0x")
|
||||
? int.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i)
|
||||
: int.TryParse(value, out i);
|
||||
|
||||
#region Get[Something]
|
||||
public static bool ToUInt32(string value, out uint i) =>
|
||||
value.StartsWith("0x")
|
||||
? uint.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i)
|
||||
: uint.TryParse(value, out i);
|
||||
|
||||
public static double GetXMLDouble(string doubleString, double defaultValue)
|
||||
{
|
||||
|
|
@ -836,7 +771,7 @@ namespace Server
|
|||
}
|
||||
catch
|
||||
{
|
||||
return double.TryParse(doubleString, out double val) ? val : defaultValue;
|
||||
return double.TryParse(doubleString, out var val) ? val : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -848,7 +783,7 @@ namespace Server
|
|||
}
|
||||
catch
|
||||
{
|
||||
return int.TryParse(intString, out int val) ? val : defaultValue;
|
||||
return int.TryParse(intString, out var val) ? val : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -860,7 +795,7 @@ namespace Server
|
|||
}
|
||||
catch
|
||||
{
|
||||
return uint.TryParse(uintString, out uint val) ? val : defaultValue;
|
||||
return uint.TryParse(uintString, out var val) ? val : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -872,7 +807,7 @@ namespace Server
|
|||
}
|
||||
catch
|
||||
{
|
||||
return DateTime.TryParse(dateTimeString, out DateTime d) ? d : defaultValue;
|
||||
return DateTime.TryParse(dateTimeString, out var d) ? d : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -884,7 +819,7 @@ namespace Server
|
|||
}
|
||||
catch
|
||||
{
|
||||
return DateTimeOffset.TryParse(dateTimeOffsetString, out DateTimeOffset d) ? d : defaultValue;
|
||||
return DateTimeOffset.TryParse(dateTimeOffsetString, out var d) ? d : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -900,7 +835,8 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public static string GetAttribute(XmlElement node, string attributeName, string defaultValue = null) => node?.Attributes[attributeName]?.Value ?? defaultValue;
|
||||
public static string GetAttribute(XmlElement node, string attributeName, string defaultValue = null) =>
|
||||
node?.Attributes[attributeName]?.Value ?? defaultValue;
|
||||
|
||||
public static string GetText(XmlElement node, string defaultValue) => node == null ? defaultValue : node.InnerText;
|
||||
|
||||
|
|
@ -908,10 +844,6 @@ namespace Server
|
|||
|
||||
public static long GetLongAddressValue(IPAddress address) => BitConverter.ToInt64(address.GetAddressBytes(), 0);
|
||||
|
||||
#endregion
|
||||
|
||||
#region In[...]Range
|
||||
|
||||
public static bool InRange(Point3D p1, Point3D p2, int range) =>
|
||||
p1.m_X >= p2.m_X - range
|
||||
&& p1.m_X <= p2.m_X + range
|
||||
|
|
@ -936,17 +868,13 @@ namespace Server
|
|||
&& p1.Y >= p2.Y - 18
|
||||
&& p1.Y <= p2.Y + 18;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Random
|
||||
|
||||
//4d6+8 would be: Utility.Dice( 4, 6, 8 )
|
||||
// 4d6+8 would be: Utility.Dice( 4, 6, 8 )
|
||||
public static int Dice(uint numDice, uint numSides, int bonus)
|
||||
{
|
||||
int total = 0;
|
||||
uint sides = numSides;
|
||||
var total = 0;
|
||||
var sides = numSides;
|
||||
|
||||
for (int i = 0; i < numDice; ++i)
|
||||
for (var i = 0; i < numDice; ++i)
|
||||
total += (int)RandomImpl.Next(sides) + 1;
|
||||
|
||||
return total + bonus;
|
||||
|
|
@ -954,11 +882,11 @@ namespace Server
|
|||
|
||||
public static void Shuffle<T>(IList<T> list)
|
||||
{
|
||||
int count = list.Count;
|
||||
for (int i = count - 1; i > 0; i--)
|
||||
var count = list.Count;
|
||||
for (var i = count - 1; i > 0; i--)
|
||||
{
|
||||
int r = (int)RandomImpl.Next((uint)count);
|
||||
T swap = list[r];
|
||||
var r = (int)RandomImpl.Next((uint)count);
|
||||
var swap = list[r];
|
||||
list[r] = list[i];
|
||||
list[i] = swap;
|
||||
}
|
||||
|
|
@ -974,12 +902,14 @@ namespace Server
|
|||
{
|
||||
if (min > max)
|
||||
{
|
||||
int copy = min;
|
||||
var copy = min;
|
||||
min = max;
|
||||
max = copy;
|
||||
}
|
||||
else if (min == max)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
|
||||
return min + (int)RandomImpl.Next((uint)(max - min + 1));
|
||||
}
|
||||
|
|
@ -995,7 +925,7 @@ namespace Server
|
|||
|
||||
public static int Random(int count) => (int)RandomImpl.Next((uint)count);
|
||||
|
||||
public static int Random(uint count) => (int)RandomImpl.Next(count);
|
||||
public static uint Random(uint count) => RandomImpl.Next(count);
|
||||
|
||||
public static void RandomBytes(byte[] buffer) => RandomImpl.GetBytes(buffer);
|
||||
|
||||
|
|
@ -1003,10 +933,6 @@ namespace Server
|
|||
|
||||
public static double RandomDouble() => RandomImpl.NextDouble();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Random Hues
|
||||
|
||||
/// <summary>
|
||||
/// Random pink, blue, green, orange, red or yellow hue
|
||||
/// </summary>
|
||||
|
|
@ -1101,9 +1027,6 @@ namespace Server
|
|||
/// Random hue from 0x62, 0x71, 0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59
|
||||
/// </summary>
|
||||
public static int RandomBrightHue() =>
|
||||
RandomDouble() < 0.1 ? RandomList(0x62, 0x71) :
|
||||
RandomList(0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59);
|
||||
|
||||
#endregion
|
||||
RandomDouble() < 0.1 ? RandomList(0x62, 0x71) : RandomList(0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: Xoshiro256PlusPlus.cs *
|
||||
* Created: 2019/12/29 - Updated: 2019/12/30 *
|
||||
|
|
@ -36,7 +36,7 @@ namespace Server
|
|||
public Xoshiro256PlusPlus(ulong seed)
|
||||
{
|
||||
var mix = new SplitMix64(seed);
|
||||
ulong[] state = new ulong[4];
|
||||
var state = new ulong[4];
|
||||
mix.FillArray(state);
|
||||
_s0 = state[0];
|
||||
_s1 = state[1];
|
||||
|
|
@ -57,7 +57,7 @@ namespace Server
|
|||
{
|
||||
if (max <= 1u << 12)
|
||||
{
|
||||
if (max == 0) throw new ArgumentOutOfRangeException();
|
||||
if (max == 0) throw new ArgumentOutOfRangeException(nameof(max));
|
||||
return (uint)(((ulong)NextUInt32() * max) >> 32);
|
||||
}
|
||||
|
||||
|
|
@ -77,11 +77,11 @@ namespace Server
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ulong NextUInt64()
|
||||
{
|
||||
ulong r1 = (_s1 << 2) + _s1;
|
||||
ulong r2 = (r1 << 7) | (r1 >> 57);
|
||||
ulong rslt = (r2 << 3) + r2;
|
||||
var r1 = (_s1 << 2) + _s1;
|
||||
var r2 = (r1 << 7) | (r1 >> 57);
|
||||
var rslt = (r2 << 3) + r2;
|
||||
|
||||
ulong t = _s1 << 17;
|
||||
var t = _s1 << 17;
|
||||
|
||||
_s2 ^= _s0;
|
||||
_s3 ^= _s1;
|
||||
|
|
@ -100,7 +100,7 @@ namespace Server
|
|||
{
|
||||
if (max <= uint.MaxValue) return Next((uint)max);
|
||||
|
||||
if (max <= 1ul << 38) return ((NextUInt32() * max >> 32) + (NextUInt32() & ((1u << 26) - 1)) * max) >> 26;
|
||||
if (max <= 1ul << 38) return (((NextUInt32() * max) >> 32) + (NextUInt32() & ((1u << 26) - 1)) * max) >> 26;
|
||||
|
||||
ulong r, v, limit = (ulong)-(long)max;
|
||||
do
|
||||
|
|
@ -112,6 +112,7 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool NextBool() => NextUInt64() < 1ul << 63;
|
||||
|
||||
public override void GetBytes(byte[] data)
|
||||
|
|
@ -124,24 +125,24 @@ namespace Server
|
|||
{
|
||||
if (b.Length == 0) return;
|
||||
|
||||
ulong s0 = _s0;
|
||||
ulong s1 = _s1;
|
||||
ulong s2 = _s2;
|
||||
ulong s3 = _s3;
|
||||
var s0 = _s0;
|
||||
var s1 = _s1;
|
||||
var s2 = _s2;
|
||||
var s3 = _s3;
|
||||
|
||||
int i = 0;
|
||||
var i = 0;
|
||||
|
||||
fixed (byte* pBuffer = b)
|
||||
{
|
||||
ulong* pULong = (ulong*)pBuffer;
|
||||
var pULong = (ulong*)pBuffer;
|
||||
|
||||
for (int bound = b.Length / sizeof(ulong); i < bound; i++)
|
||||
for (var bound = b.Length / sizeof(ulong); i < bound; i++)
|
||||
{
|
||||
ulong r1 = (s1 << 2) + s1;
|
||||
ulong r2 = (r1 << 7) | (r1 >> 57);
|
||||
var r1 = (s1 << 2) + s1;
|
||||
var r2 = (r1 << 7) | (r1 >> 57);
|
||||
pULong[i] = (r2 << 3) + r2;
|
||||
|
||||
ulong t = s1 << 17;
|
||||
var t = s1 << 17;
|
||||
s2 ^= s0;
|
||||
s3 ^= s1;
|
||||
s1 ^= s2;
|
||||
|
|
@ -157,11 +158,11 @@ namespace Server
|
|||
|
||||
if (i < b.Length)
|
||||
{
|
||||
ulong r1 = (s1 << 2) + s1;
|
||||
ulong r2 = (r1 << 7) | (r1 >> 57);
|
||||
ulong rslt = (r2 << 3) + r2;
|
||||
var r1 = (s1 << 2) + s1;
|
||||
var r2 = (r1 << 7) | (r1 >> 57);
|
||||
var rslt = (r2 << 3) + r2;
|
||||
|
||||
ulong t = s1 << 17;
|
||||
var t = s1 << 17;
|
||||
|
||||
s2 ^= s0;
|
||||
s3 ^= s1;
|
||||
|
|
@ -188,10 +189,10 @@ namespace Server
|
|||
public double NextDouble() => (NextUInt64() >> 11) * (1.0 / (1ul << 53));
|
||||
|
||||
private static readonly ulong[] JUMP =
|
||||
{0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c};
|
||||
{ 0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c };
|
||||
|
||||
private static readonly ulong[] LONG_JUMP =
|
||||
{0x76e15d3efefdcbbf, 0xc5004e441c522fb3, 0x77710069854ee241, 0x39109bb02acbe635};
|
||||
{ 0x76e15d3efefdcbbf, 0xc5004e441c522fb3, 0x77710069854ee241, 0x39109bb02acbe635 };
|
||||
|
||||
public void Jump() => Jump(JUMP);
|
||||
|
||||
|
|
@ -204,19 +205,19 @@ namespace Server
|
|||
ulong s2 = 0;
|
||||
ulong s3 = 0;
|
||||
|
||||
for (int i = 0; i < jumps.Length; i++)
|
||||
for (int b = 0; b < 64; b++)
|
||||
{
|
||||
if ((jumps[i] & 1ul << b) != 0)
|
||||
for (var i = 0; i < jumps.Length; i++)
|
||||
for (var b = 0; b < 64; b++)
|
||||
{
|
||||
s0 ^= _s0;
|
||||
s1 ^= _s1;
|
||||
s2 ^= _s2;
|
||||
s3 ^= _s3;
|
||||
}
|
||||
if ((jumps[i] & (1ul << b)) != 0)
|
||||
{
|
||||
s0 ^= _s0;
|
||||
s1 ^= _s1;
|
||||
s2 ^= _s2;
|
||||
s3 ^= _s3;
|
||||
}
|
||||
|
||||
NextUInt64();
|
||||
}
|
||||
NextUInt64();
|
||||
}
|
||||
|
||||
_s0 = s0;
|
||||
_s1 = s1;
|
||||
|
|
@ -226,14 +227,14 @@ namespace Server
|
|||
|
||||
public Xoshiro256PlusPlus Split()
|
||||
{
|
||||
Xoshiro256PlusPlus rng = new Xoshiro256PlusPlus(_s0, _s1, _s2, _s3);
|
||||
var rng = new Xoshiro256PlusPlus(_s0, _s1, _s2, _s3);
|
||||
rng.Jump();
|
||||
return rng;
|
||||
}
|
||||
|
||||
public Xoshiro256PlusPlus LongSplit()
|
||||
{
|
||||
Xoshiro256PlusPlus rng = new Xoshiro256PlusPlus(_s0, _s1, _s2, _s3);
|
||||
var rng = new Xoshiro256PlusPlus(_s0, _s1, _s2, _s3);
|
||||
rng.LongJump();
|
||||
return rng;
|
||||
}
|
||||
|
|
@ -248,7 +249,7 @@ namespace Server
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ulong Next()
|
||||
{
|
||||
ulong z = x += 0x9e3779b97f4a7c15;
|
||||
var z = x += 0x9e3779b97f4a7c15;
|
||||
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
|
||||
z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
|
||||
return z ^ (z >> 31);
|
||||
|
|
@ -257,7 +258,7 @@ namespace Server
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void FillArray(ulong[] arr)
|
||||
{
|
||||
for (int i = 0; i < arr.Length; i++) arr[i] = Next();
|
||||
for (var i = 0; i < arr.Length; i++) arr[i] = Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue