Ejemplo n.º 1
0
        /// <summary>
        /// 使用随机的新密钥
        /// </summary>
        public void RandomizeCryptoKey()
        {
            var decrypted = InternalDecrypt();

            currentCryptoKey = ThreadSafeRandom.Next();
            hiddenValue      = Encrypt(decrypted, currentCryptoKey);
        }
Ejemplo n.º 2
0
        private Quaternion InternalDecrypt()
        {
            if (!inited)
            {
                currentCryptoKey = cryptoKey;
                hiddenValue      = Encrypt(identity);
                fakeValue        = identity;
                fakeValueActive  = false;
                inited           = true;

                return(identity);
            }

            Quaternion value;

            value.x = TSFloat.Decrypt(hiddenValue.x, currentCryptoKey);
            value.y = TSFloat.Decrypt(hiddenValue.y, currentCryptoKey);
            value.z = TSFloat.Decrypt(hiddenValue.z, currentCryptoKey);
            value.w = TSFloat.Decrypt(hiddenValue.w, currentCryptoKey);

            if (ObscuredCheatingDetector.ExistsAndIsRunning && fakeValueActive && !CompareQuaternionsWithTolerance(value, fakeValue))
            {
                ObscuredCheatingDetector.Instance.OnCheatingDetected();
            }

            return(value);
        }
Ejemplo n.º 3
0
        public static TSQuaternion FromEncrypted(EncryptedQuaternion encrypted)
        {
            var instance = new TSQuaternion();

            instance.SetEncrypted(encrypted);
            return(instance);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 在SetNewCryptoKey()之后使用
 /// 使用新的密钥加密当前实例
 /// </summary>
 public void ApplyNewCryptoKey()
 {
     if (currentCryptoKey != cryptoKey)
     {
         hiddenValue      = Encrypt(InternalDecrypt(), cryptoKey);
         currentCryptoKey = cryptoKey;
     }
 }
Ejemplo n.º 5
0
        private TSQuaternion(Quaternion value)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(value);

#if UNITY_EDITOR
            fakeValue       = value;
            fakeValueActive = true;
#else
            var detectorRunning = ObscuredCheatingDetector.ExistsAndIsRunning;
            fakeValue       = detectorRunning ? value : identity;
            fakeValueActive = detectorRunning;
#endif

            inited = true;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 解密
        /// </summary>
        public static Quaternion Decrypt(EncryptedQuaternion value, int key)
        {
            if (key == 0)
            {
                key = cryptoKey;
            }

            Quaternion result;

            result.x = TSFloat.Decrypt(value.x, key);
            result.y = TSFloat.Decrypt(value.y, key);
            result.z = TSFloat.Decrypt(value.z, key);
            result.w = TSFloat.Decrypt(value.w, key);

            return(result);
        }
Ejemplo n.º 7
0
        public TSQuaternion(float x, float y, float z, float w)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(x, y, z, w, currentCryptoKey);

            if (ObscuredCheatingDetector.ExistsAndIsRunning)
            {
                fakeValue       = new Quaternion(x, y, z, w);
                fakeValueActive = true;
            }
            else
            {
                fakeValue       = identity;
                fakeValueActive = false;
            }

#if UNITY_EDITOR
#endif

            inited = true;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 设置加密后的值
        /// </summary>
        /// <param name="encrypted"></param>
        public void SetEncrypted(EncryptedQuaternion encrypted)
        {
            inited      = true;
            hiddenValue = encrypted;

            if (currentCryptoKey == 0)
            {
                currentCryptoKey = cryptoKey;
            }

            if (ObscuredCheatingDetector.ExistsAndIsRunning)
            {
                fakeValueActive = false;
                fakeValue       = InternalDecrypt();
                fakeValueActive = true;
            }
            else
            {
                fakeValueActive = false;
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 解密
 /// </summary>
 public static Quaternion Decrypt(EncryptedQuaternion value)
 {
     return(Decrypt(value, 0));
 }