mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
HLAPI: GetStableHashCode added too
This commit is contained in:
parent
07ab30f366
commit
1b33f7d633
20
Mirror/Runtime/Extensions.cs
Normal file
20
Mirror/Runtime/Extensions.cs
Normal file
@ -0,0 +1,20 @@
|
||||
namespace Mirror
|
||||
{
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
// string.GetHashCode is not guaranteed to be the same on all machines, but
|
||||
// we need one that is the same on all machines. simple and stupid:
|
||||
// IMPORTANT: needs to be same one as in Weaver
|
||||
public static int GetStableHashCode(this string text)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hash = 23;
|
||||
foreach (char c in text)
|
||||
hash = hash * 31 + c;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -65,6 +65,7 @@
|
||||
<Compile Include="ClientScene.cs" />
|
||||
<Compile Include="CustomAttributes.cs" />
|
||||
<Compile Include="DotNetCompatibility.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="LocalConnections.cs" />
|
||||
<Compile Include="LogFilter.cs" />
|
||||
<Compile Include="Messages.cs" />
|
||||
|
@ -123,4 +123,21 @@ public static bool UnpackMessage(byte[] message, out ushort msgType, out byte[]
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Utils
|
||||
{
|
||||
// string.GetHashCode is not guaranteed to be the same on all machines, but
|
||||
// we need one that is the same on all machines. simple and stupid:
|
||||
// IMPORTANT: needs to be the same one as in Weaver
|
||||
public static int GetStableHashCode(string text)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hash = 23;
|
||||
foreach (char c in text)
|
||||
hash = hash * 31 + c;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user