From 78b08a9069d337e3ee1c6c6ef70ce3b0509682b5 Mon Sep 17 00:00:00 2001 From: walon Date: Wed, 14 May 2025 14:16:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dnan=E6=B5=AE=E7=82=B9?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E7=9A=84bug=E3=80=82cpu=E4=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=B0=83=E6=95=B4nan=E6=95=B0=E7=9A=84=E5=B0=BE?= =?UTF-8?q?=E6=95=B0=E3=80=82=E6=80=AA=E4=BA=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/EncryptorBase.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Runtime/EncryptorBase.cs b/Runtime/EncryptorBase.cs index 7c1c5bd..c6ea6af 100644 --- a/Runtime/EncryptorBase.cs +++ b/Runtime/EncryptorBase.cs @@ -42,29 +42,49 @@ namespace Obfuz public virtual float Encrypt(float value, int opts, int salt) { + if (float.IsNaN(value) || float.IsInfinity(value)) + { + return value; + } ref int intValue = ref UnsafeUtility.As(ref value); - intValue = Encrypt(intValue, opts, salt); + int xorValue = ((1 << 23) - 1) & (opts ^ salt); + intValue ^= xorValue; return value; } public virtual float Decrypt(float value, int opts, int salt) { + if (float.IsNaN(value) || float.IsInfinity(value)) + { + return value; + } ref int intValue = ref UnsafeUtility.As(ref value); - intValue = Decrypt(intValue, opts, salt); + int xorValue = ((1 << 23) - 1) & (opts ^ salt); + intValue ^= xorValue; return value; } public virtual double Encrypt(double value, int opts, int salt) { + if (double.IsNaN(value) || double.IsInfinity(value)) + { + return value; + } ref long longValue = ref UnsafeUtility.As(ref value); - longValue = Encrypt(longValue, opts, salt); + long xorValue = ((1L << 52) - 1) & (((long)opts << 32) | (uint)salt); + longValue ^= xorValue; return value; } public virtual double Decrypt(double value, int opts, int salt) { + if (double.IsNaN(value) || double.IsInfinity(value)) + { + return value; + } ref long longValue = ref UnsafeUtility.As(ref value); - longValue = Decrypt(longValue, opts, salt); + long xorValue = ((1L << 52) - 1) & (((long)opts << 32) | (uint)salt); + longValue ^= xorValue; return value; }