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