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

            currentCryptoKey = ThreadSafeRandom.Next();
            hiddenValue      = Encrypt(decrypted, currentCryptoKey);
        }
Esempio n. 2
0
        private Vector3Int InternalDecrypt()
        {
            if (!inited)
            {
                currentCryptoKey = cryptoKey;
                hiddenValue      = Encrypt(zero, cryptoKey);
                fakeValue        = zero;
                fakeValueActive  = false;
                inited           = true;

                return(zero);
            }

            var value = new Vector3Int
            {
                x = TSInt.Decrypt(hiddenValue.x, currentCryptoKey),
                y = TSInt.Decrypt(hiddenValue.y, currentCryptoKey),
                z = TSInt.Decrypt(hiddenValue.z, currentCryptoKey)
            };


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

            return(value);
        }
Esempio n. 3
0
        public static TSVector3Int FromEncrypted(EncryptedVector3Int encrypted)
        {
            var instance = new TSVector3Int();

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

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

            inited = true;
        }
Esempio n. 6
0
        /// <summary>
        /// 解密
        /// </summary>
        public static Vector3Int Decrypt(EncryptedVector3Int value, int key)
        {
            if (key == 0)
            {
                key = cryptoKey;
            }

            var result = new Vector3Int
            {
                x = TSInt.Decrypt(value.x, key),
                y = TSInt.Decrypt(value.y, key),
                z = TSInt.Decrypt(value.z, key)
            };

            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// 设置加密后的值
        /// </summary>
        /// <param name="encrypted"></param>
        public void SetEncrypted(EncryptedVector3Int encrypted)
        {
            inited      = true;
            hiddenValue = encrypted;

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

            if (ObscuredCheatingDetector.ExistsAndIsRunning)
            {
                fakeValueActive = false;
                fakeValue       = InternalDecrypt();
                fakeValueActive = true;
            }
            else
            {
                fakeValueActive = false;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Mimics constructor of regular Vector3Int.
        /// </summary>
        /// <param name="x">X component of the vector</param>
        /// <param name="y">Y component of the vector</param>
        /// <param name="z">Z component of the vector</param>
        public TSVector3Int(int x, int y, int z)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(x, y, z, currentCryptoKey);

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

            inited = true;
        }
Esempio n. 9
0
 /// <summary>
 /// 解密
 /// </summary>
 public static Vector3Int Decrypt(EncryptedVector3Int value)
 {
     return(Decrypt(value, 0));
 }