Ejemplo n.º 1
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 ObscuredVector3Int(int x, int y, int z)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(x, y, z, currentCryptoKey);

            inited = true;
        }
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>
        /// 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 ObscuredVector3Int FromEncrypted(RawEncryptedVector3Int encrypted)
        {
            var instance = new ObscuredVector3Int();

            instance.SetEncrypted(encrypted);
            return(instance);
        }
Ejemplo n.º 4
0
        public void RandomizeCryptoKey()
        {
            var decrypted = InternalDecrypt();

            currentCryptoKey = GenerateKey();
            hiddenValue      = Encrypt(decrypted, currentCryptoKey);
        }
Ejemplo n.º 5
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 = ObscuredInt.Decrypt(hiddenValue.x, currentCryptoKey),
                y = ObscuredInt.Decrypt(hiddenValue.y, currentCryptoKey),
                z = ObscuredInt.Decrypt(hiddenValue.z, currentCryptoKey)
            };


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

            return(value);
        }
Ejemplo n.º 6
0
        private ObscuredVector3Int(Vector3Int value)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(value);

            inited = true;
        }
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>
        /// 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.º 9
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(RawEncryptedVector3Int encrypted)
        {
            inited      = true;
            hiddenValue = encrypted;

            if (currentCryptoKey == 0)
            {
                currentCryptoKey = cryptoKey;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Decrypts passed value you got from Encrypt() using same key.
        /// </summary>
        /// \sa Encrypt()
        public static Vector3Int Decrypt(RawEncryptedVector3Int value, int key)
        {
            var result = new Vector3Int
            {
                x = ObscuredInt.Decrypt(value.x, key),
                y = ObscuredInt.Decrypt(value.y, key),
                z = ObscuredInt.Decrypt(value.z, key)
            };

            return(result);
        }
Ejemplo n.º 11
0
        private ObscuredVector3Int(Vector3Int value)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(value);

            var detectorRunning = Detectors.ObscuredCheatingDetector.ExistsAndIsRunning;

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

            inited = true;
        }
Ejemplo n.º 12
0
        private ObscuredVector3Int(Vector3Int 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(RawEncryptedVector3Int 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
        private Vector3Int InternalDecrypt()
        {
            if (!inited)
            {
                currentCryptoKey = cryptoKey;
                hiddenValue      = Encrypt(zero, cryptoKey);
                inited           = true;

                return(zero);
            }

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

            return(value);
        }
Ejemplo n.º 15
0
        private Vector3Int 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.º 16
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 ObscuredVector3Int(int x, int y, int z)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = Encrypt(x, y, z, currentCryptoKey);

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

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