private Vector2 InternalDecrypt() { if (!inited) { currentCryptoKey = cryptoKey; hiddenValue = Encrypt(zero); fakeValue = zero; fakeValueActive = false; inited = true; return(zero); } Vector2 value; value.x = TSFloat.Decrypt(hiddenValue.x, currentCryptoKey); value.y = TSFloat.Decrypt(hiddenValue.y, currentCryptoKey); if (ObscuredCheatingDetector.ExistsAndIsRunning && fakeValueActive && !CompareVectorsWithTolerance(value, fakeValue)) { ObscuredCheatingDetector.Instance.OnCheatingDetected(); } return(value); }
/// <summary> /// 使用随机的新密钥 /// </summary> public void RandomizeCryptoKey() { var decrypted = InternalDecrypt(); currentCryptoKey = ThreadSafeRandom.Next(); hiddenValue = Encrypt(decrypted, currentCryptoKey); }
public static TSVector2 FromEncrypted(EncryptedVector2 encrypted) { var instance = new TSVector2(); instance.SetEncrypted(encrypted); return(instance); }
/// <summary> /// 在SetNewCryptoKey()之后使用 /// 使用新的密钥加密当前实例 /// </summary> public void ApplyNewCryptoKey() { if (currentCryptoKey != cryptoKey) { hiddenValue = Encrypt(InternalDecrypt(), cryptoKey); currentCryptoKey = cryptoKey; } }
/// <summary> /// 解密 /// </summary> public static Vector2 Decrypt(EncryptedVector2 value, int key) { if (key == 0) { key = cryptoKey; } Vector2 result; result.x = TSFloat.Decrypt(value.x, key); result.y = TSFloat.Decrypt(value.y, key); return(result); }
private TSVector2(Vector2 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; }
/// <summary> /// Mimics constructor of regular Vector2. /// </summary> /// <param name="x">X component of the vector</param> /// <param name="y">Y component of the vector</param> public TSVector2(float x, float y) { currentCryptoKey = cryptoKey; hiddenValue = Encrypt(x, y, currentCryptoKey); if (ObscuredCheatingDetector.ExistsAndIsRunning) { fakeValue = new Vector2(x, y); fakeValueActive = true; } else { fakeValue = zero; fakeValueActive = false; } inited = true; }
/// <summary> /// 设置加密后的值 /// </summary> /// <param name="encrypted"></param> public void SetEncrypted(EncryptedVector2 encrypted) { inited = true; hiddenValue = encrypted; if (currentCryptoKey == 0) { currentCryptoKey = cryptoKey; } if (ObscuredCheatingDetector.ExistsAndIsRunning) { fakeValueActive = false; fakeValue = InternalDecrypt(); fakeValueActive = true; } else { fakeValueActive = false; } }
/// <summary> /// 解密 /// </summary> public static Vector2 Decrypt(EncryptedVector2 value) { return(Decrypt(value, 0)); }