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