Ejemplo n.º 1
0
        private Vector2Int InternalDecrypt()
        {
            if (!inited)
            {
                currentCryptoKey = cryptoKey;
                hiddenValue      = Encrypt(zero);
                fakeValue        = zero;
                fakeValueActive  = false;
                inited           = true;

                return(zero);
            }

            var value = new Vector2Int
            {
                x = ObscuredInt.Decrypt(hiddenValue.x, currentCryptoKey),
                y = ObscuredInt.Decrypt(hiddenValue.y, currentCryptoKey)
            };

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

            return(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows to change current crypto key to the new random value and re-encrypt variable using it.
        /// Use it for extra protection against 'unknown value' search.
        /// Just call it sometimes when your variable doesn't change to fool the cheater.
        /// </summary>
        public void RandomizeCryptoKey()
        {
            var decrypted = InternalDecrypt();

            currentCryptoKey = ThreadSafeRandom.Next();
            hiddenValue      = Encrypt(decrypted, currentCryptoKey);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Mimics constructor of regular Vector2Int.
        /// </summary>
        /// <param name="x">X component of the vector</param>
        /// <param name="y">Y component of the vector</param>
        public ObscuredVector2Int(int x, int y)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(x, y, currentCryptoKey);

            inited = true;
        }
Ejemplo n.º 4
0
        public void RandomizeCryptoKey()
        {
            var decrypted = InternalDecrypt();

            currentCryptoKey = GenerateKey();
            hiddenValue      = Encrypt(decrypted, currentCryptoKey);
        }
Ejemplo n.º 5
0
        private ObscuredVector2Int(Vector2Int value)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(value);

            inited = true;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates and fills obscured variable with raw encrypted value previously got from GetEncrypted().
        /// </summary>
        /// Literally does same job as SetEncrypted() but makes new instance instead of filling existing one,
        /// making it easier to initialize new variables from saved encrypted values.
        ///
        /// Make sure this obscured type currently has same crypto key as when encrypted value was got with GetEncrypted().
        /// It will be same (default) if you did not used SetNewCryptoKey().
        /// <param name="encrypted">Raw encrypted value you got from GetEncrypted().</param>
        /// <returns>New obscured variable initialized from specified encrypted value.</returns>
        /// \sa GetEncrypted(), SetEncrypted()
        public static ObscuredVector2Int FromEncrypted(RawEncryptedVector2Int encrypted)
        {
            var instance = new ObscuredVector2Int();

            instance.SetEncrypted(encrypted);
            return(instance);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Use it after SetNewCryptoKey() to re-encrypt current instance using new crypto key.
 /// </summary>
 public void ApplyNewCryptoKey()
 {
     if (currentCryptoKey != cryptoKey)
     {
         hiddenValue      = Encrypt(InternalDecrypt(), cryptoKey);
         currentCryptoKey = cryptoKey;
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Decrypts passed value you got from Encrypt() using same key.
        /// </summary>
        /// \sa Encrypt()
        public static Vector2Int Decrypt(RawEncryptedVector2Int value, int key)
        {
            var result = new Vector2Int
            {
                x = ObscuredInt.Decrypt(value.x, key),
                y = ObscuredInt.Decrypt(value.y, key)
            };

            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Allows to change current crypto key to the new random value and re-encrypt variable using it.
        /// Use it for extra protection against 'unknown value' search.
        /// Just call it sometimes when your variable doesn't change to fool the cheater.
        /// </summary>
        public void RandomizeCryptoKey()
        {
            var decrypted = InternalDecrypt();

            do
            {
                currentCryptoKey = Random.Range(int.MinValue, int.MaxValue);
            } while (currentCryptoKey == 0);
            hiddenValue = Encrypt(decrypted, currentCryptoKey);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Allows to explicitly set current obscured value.
        /// </summary>
        /// Use it in conjunction with GetEncrypted().<br/>
        /// Useful for loading data stored in obscured state.
        public void SetEncrypted(RawEncryptedVector2Int encrypted)
        {
            inited      = true;
            hiddenValue = encrypted;

            if (currentCryptoKey == 0)
            {
                currentCryptoKey = cryptoKey;
            }
        }
Ejemplo n.º 11
0
        private ObscuredVector2Int(Vector2Int value)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(value);

            var detectorRunning = Detectors.ObscuredCheatingDetector.ExistsAndIsRunning;

            fakeValue       = detectorRunning ? value : zero;
            fakeValueActive = detectorRunning;

            inited = true;
        }
Ejemplo n.º 12
0
        private ObscuredVector2Int(Vector2Int value)
        {
            currentCryptoKey = GenerateKey();
            hiddenValue      = Encrypt(value, currentCryptoKey);

#if UNITY_EDITOR
            fakeValue       = value;
            fakeValueActive = true;
#else
            var detectorRunning = Detectors.ObscuredCheatingDetector.ExistsAndIsRunning;
            fakeValue       = detectorRunning ? value : Zero;
            fakeValueActive = detectorRunning;
#endif
            inited = true;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Allows to explicitly set current obscured value. Crypto key should be same as when encrypted value was got with GetEncrypted().
        /// </summary>
        /// Use it in conjunction with GetEncrypted().<br/>
        /// Useful for loading data stored in obscured state.
        /// \sa FromEncrypted()
        public void SetEncrypted(RawEncryptedVector2Int encrypted, int key)
        {
            inited           = true;
            hiddenValue      = encrypted;
            currentCryptoKey = key;

            if (Detectors.ObscuredCheatingDetector.ExistsAndIsRunning)
            {
                fakeValueActive = false;
                fakeValue       = InternalDecrypt();
                fakeValueActive = true;
            }
            else
            {
                fakeValueActive = false;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Mimics constructor of regular Vector2Int.
        /// </summary>
        /// <param name="x">X component of the vector</param>
        /// <param name="y">Y component of the vector</param>
        public ObscuredVector2Int(int x, int y)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(x, y, currentCryptoKey);

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

            inited = true;
        }
Ejemplo n.º 15
0
        private Vector2Int InternalDecrypt()
        {
            if (!inited)
            {
                currentCryptoKey = cryptoKey;
                hiddenValue      = Encrypt(zero);
                inited           = true;

                return(zero);
            }

            var value = new Vector2Int
            {
                x = ObscuredInt.Decrypt(hiddenValue.x, currentCryptoKey),
                y = ObscuredInt.Decrypt(hiddenValue.y, currentCryptoKey)
            };

            return(value);
        }
Ejemplo n.º 16
0
        private Vector2Int InternalDecrypt()
        {
            if (!inited)
            {
                currentCryptoKey = GenerateKey();
                hiddenValue      = Encrypt(Zero, currentCryptoKey);
                fakeValue        = Zero;
                fakeValueActive  = false;
                inited           = true;

                return(Zero);
            }

            var decrypted = Decrypt(hiddenValue, currentCryptoKey);

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

            return(decrypted);
        }
Ejemplo n.º 17
0
 public void SetEncrypted(RawEncryptedVector2Int encrypted)
 {
 }
Ejemplo n.º 18
0
 public static Vector2Int Decrypt(RawEncryptedVector2Int value)
 {
     throw new Exception();
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Use it to decrypt RawEncryptedVector2Int you got from Encrypt(), uses default crypto key.
 /// </summary>
 public static Vector2Int Decrypt(RawEncryptedVector2Int value)
 {
     return(Decrypt(value, 0));
 }