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