Upload from upload_mods.ps1
This commit is contained in:
22
Scripts/Utilities/PlatformIndependentHash.cs
Normal file
22
Scripts/Utilities/PlatformIndependentHash.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public static class PlatformIndependentHash
|
||||
{
|
||||
public static int StringToInt32(string str)
|
||||
{
|
||||
byte[] encoded = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
return BitConverter.ToInt32(encoded, 0);
|
||||
}
|
||||
|
||||
public static UInt16 StringToUInt16(string str)
|
||||
{
|
||||
byte[] encoded = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
return (UInt16)BitConverter.ToUInt32(encoded, 0);
|
||||
}
|
||||
}
|
||||
|
||||
31
Scripts/Utilities/StreamUtilsCompressed.cs
Normal file
31
Scripts/Utilities/StreamUtilsCompressed.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public static class StreamUtilsCompressed
|
||||
{
|
||||
public static void Write(BinaryWriter _bw, Vector3 vec)
|
||||
{
|
||||
_bw.Write(Mathf.FloatToHalf(vec.x));
|
||||
_bw.Write(Mathf.FloatToHalf(vec.y));
|
||||
_bw.Write(Mathf.FloatToHalf(vec.z));
|
||||
}
|
||||
|
||||
public static Vector3 ReadHalfVector3(BinaryReader _br)
|
||||
{
|
||||
return new Vector3(Mathf.HalfToFloat(_br.ReadUInt16()), Mathf.HalfToFloat(_br.ReadUInt16()), Mathf.HalfToFloat(_br.ReadUInt16()));
|
||||
}
|
||||
|
||||
public static void Write(BinaryWriter _bw, Quaternion rot)
|
||||
{
|
||||
_bw.Write(Mathf.FloatToHalf(rot.x));
|
||||
_bw.Write(Mathf.FloatToHalf(rot.y));
|
||||
_bw.Write(Mathf.FloatToHalf(rot.z));
|
||||
_bw.Write(Mathf.FloatToHalf(rot.w));
|
||||
}
|
||||
|
||||
public static Quaternion ReadHalfQuaternion(BinaryReader _br)
|
||||
{
|
||||
return new Quaternion(Mathf.HalfToFloat(_br.ReadUInt16()), Mathf.HalfToFloat(_br.ReadUInt16()), Mathf.HalfToFloat(_br.ReadUInt16()), Mathf.HalfToFloat(_br.ReadUInt16()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user