private Vector2Int InternalDecrypt() { if (!inited) { currentCryptoKey = cryptoKey; hiddenValue = Encrypt(zero); fakeValue = zero; fakeValueActive = false; inited = true; return(zero); } var value = new Vector2Int { x = ObscuredInt.Decrypt(hiddenValue.x, currentCryptoKey), y = ObscuredInt.Decrypt(hiddenValue.y, currentCryptoKey) }; if (Detectors.ObscuredCheatingDetector.ExistsAndIsRunning && fakeValueActive && value != fakeValue) { Detectors.ObscuredCheatingDetector.Instance.OnCheatingDetected(); } return(value); }
/// <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); }
/// <summary> /// Mimics constructor of regular Vector2Int. /// </summary> /// <param name="x">X component of the vector</param> /// <param name="y">Y component of the vector</param> public ObscuredVector2Int(int x, int y) { currentCryptoKey = cryptoKey; hiddenValue = Encrypt(x, y, currentCryptoKey); inited = true; }
public void RandomizeCryptoKey() { var decrypted = InternalDecrypt(); currentCryptoKey = GenerateKey(); hiddenValue = Encrypt(decrypted, currentCryptoKey); }
private ObscuredVector2Int(Vector2Int value) { currentCryptoKey = cryptoKey; hiddenValue = Encrypt(value); inited = true; }
/// <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 ObscuredVector2Int FromEncrypted(RawEncryptedVector2Int encrypted) { var instance = new ObscuredVector2Int(); instance.SetEncrypted(encrypted); return(instance); }
/// <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; } }
/// <summary> /// Decrypts passed value you got from Encrypt() using same key. /// </summary> /// \sa Encrypt() public static Vector2Int Decrypt(RawEncryptedVector2Int value, int key) { var result = new Vector2Int { x = ObscuredInt.Decrypt(value.x, key), y = ObscuredInt.Decrypt(value.y, key) }; return(result); }
/// <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); }
/// <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(RawEncryptedVector2Int encrypted) { inited = true; hiddenValue = encrypted; if (currentCryptoKey == 0) { currentCryptoKey = cryptoKey; } }
private ObscuredVector2Int(Vector2Int value) { currentCryptoKey = cryptoKey; hiddenValue = Encrypt(value); var detectorRunning = Detectors.ObscuredCheatingDetector.ExistsAndIsRunning; fakeValue = detectorRunning ? value : zero; fakeValueActive = detectorRunning; inited = true; }
private ObscuredVector2Int(Vector2Int 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; }
/// <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(RawEncryptedVector2Int encrypted, int key) { inited = true; hiddenValue = encrypted; currentCryptoKey = key; if (Detectors.ObscuredCheatingDetector.ExistsAndIsRunning) { fakeValueActive = false; fakeValue = InternalDecrypt(); fakeValueActive = true; } else { fakeValueActive = false; } }
/// <summary> /// Mimics constructor of regular Vector2Int. /// </summary> /// <param name="x">X component of the vector</param> /// <param name="y">Y component of the vector</param> public ObscuredVector2Int(int x, int y) { currentCryptoKey = cryptoKey; hiddenValue = Encrypt(x, y, currentCryptoKey); if (Detectors.ObscuredCheatingDetector.ExistsAndIsRunning) { fakeValue = new Vector2Int(x, y); fakeValueActive = true; } else { fakeValue = zero; fakeValueActive = false; } inited = true; }
private Vector2Int InternalDecrypt() { if (!inited) { currentCryptoKey = cryptoKey; hiddenValue = Encrypt(zero); inited = true; return(zero); } var value = new Vector2Int { x = ObscuredInt.Decrypt(hiddenValue.x, currentCryptoKey), y = ObscuredInt.Decrypt(hiddenValue.y, currentCryptoKey) }; return(value); }
private Vector2Int 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); }
public void SetEncrypted(RawEncryptedVector2Int encrypted) { }
public static Vector2Int Decrypt(RawEncryptedVector2Int value) { throw new Exception(); }
/// <summary> /// Use it to decrypt RawEncryptedVector2Int you got from Encrypt(), uses default crypto key. /// </summary> public static Vector2Int Decrypt(RawEncryptedVector2Int value) { return(Decrypt(value, 0)); }