Exemple #1
0
        private decimal InternalDecrypt()
        {
            if (!inited)
            {
                currentCryptoKey = cryptoKey;
                hiddenValue      = InternalEncrypt(0m);
                fakeValue        = 0m;
                fakeValueActive  = false;
                inited           = true;

                return(0m);
            }

            var union = new DecimalLongBytesUnion();

            union.b16 = hiddenValue;

            union.l1 = union.l1 ^ currentCryptoKey;
            union.l2 = union.l2 ^ currentCryptoKey;

            var decrypted = union.d;

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

            return(decrypted);
        }
Exemple #2
0
        /// <summary>
        /// 使用随机的新密钥
        /// </summary>
        public void RandomizeCryptoKey()
        {
            var decrypted = InternalDecrypt();

            currentCryptoKey = ThreadSafeRandom.Next();
            hiddenValue      = InternalEncrypt(decrypted, currentCryptoKey);
        }
Exemple #3
0
        /// <summary>
        /// 设置加密后的值
        /// </summary>
        /// <param name="encrypted"></param>
        public void SetEncrypted(decimal encrypted)
        {
            inited = true;
            var union = new DecimalLongBytesUnion();

            union.d = encrypted;

            hiddenValue = union.b16;

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

            if (ObscuredCheatingDetector.ExistsAndIsRunning)
            {
                fakeValueActive = false;
                fakeValue       = InternalDecrypt();
                fakeValueActive = true;
            }
            else
            {
                fakeValueActive = false;
            }
        }
Exemple #4
0
 /// <summary>
 /// 在SetNewCryptoKey()之后使用
 /// 使用新的密钥加密当前实例
 /// </summary>
 public void ApplyNewCryptoKey()
 {
     if (currentCryptoKey != cryptoKey)
     {
         hiddenValue      = InternalEncrypt(InternalDecrypt(), cryptoKey);
         currentCryptoKey = cryptoKey;
     }
 }
Exemple #5
0
        private TSDecimal(decimal value)
        {
            currentCryptoKey = cryptoKey;
            hiddenValue      = InternalEncrypt(value);

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

            inited = true;
        }