private float InternalDecrypt() { if (!inited) { currentCryptoKey = cryptoKey; hiddenValue = InternalEncrypt(0f); fakeValue = 0f; inited = true; } int num = cryptoKey; if (currentCryptoKey != cryptoKey) { num = currentCryptoKey; } FloatIntBytesUnion floatIntBytesUnion = default(FloatIntBytesUnion); floatIntBytesUnion.b1 = hiddenValue[0]; floatIntBytesUnion.b2 = hiddenValue[1]; floatIntBytesUnion.b3 = hiddenValue[2]; floatIntBytesUnion.b4 = hiddenValue[3]; floatIntBytesUnion.i ^= num; float f = floatIntBytesUnion.f; if (onCheatingDetected != null && fakeValue != 0f && Math.Abs(f - fakeValue) > 1E-06f) { onCheatingDetected(); onCheatingDetected = null; } return(f); }
/// <summary> /// Use it to decrypt int you got from Encrypt(float) back to float, uses passed crypto key. /// </summary> public static float Decrypt(int value, int key) { var u = new FloatIntBytesUnion(); u.i = value ^ key; return(u.f); }
private float InternalDecrypt() { if (!inited) { currentCryptoKey = cryptoKey; hiddenValue = InternalEncrypt(0); inited = true; } int key = cryptoKey; if (currentCryptoKey != cryptoKey) { key = currentCryptoKey; } var union = new FloatIntBytesUnion(); union.b1 = hiddenValue[0]; union.b2 = hiddenValue[1]; union.b3 = hiddenValue[2]; union.b4 = hiddenValue[3]; union.i = union.i ^ key; float decrypted = union.f; return(decrypted); }
private float InternalDecrypt() { if (!inited) { currentCryptoKey = cryptoKey; hiddenValue = InternalEncrypt(0); fakeValue = 0; inited = true; } var union = new FloatIntBytesUnion(); union.b1 = hiddenValue[0]; union.b2 = hiddenValue[1]; union.b3 = hiddenValue[2]; union.b4 = hiddenValue[3]; union.i = union.i ^ currentCryptoKey; float decrypted = union.f; if (Detectors.ObscuredCheatingDetector.IsRunning && fakeValue != 0 && Math.Abs(decrypted - fakeValue) > Detectors.ObscuredCheatingDetector.Instance.floatEpsilon) { Detectors.ObscuredCheatingDetector.Instance.OnCheatingDetected(); } return(decrypted); }
public static float Decrypt(int value, int key) { FloatIntBytesUnion floatIntBytesUnion = default(FloatIntBytesUnion); floatIntBytesUnion.i = (value ^ key); return(floatIntBytesUnion.f); }
public static int Encrypt(float value, int key) { FloatIntBytesUnion floatIntBytesUnion = default(FloatIntBytesUnion); floatIntBytesUnion.f = value; floatIntBytesUnion.i ^= key; return(floatIntBytesUnion.i); }
/// <summary> /// Use this simple encryption method to encrypt any float value, uses passed crypto key. /// </summary> public static int Encrypt(float value, int key) { var u = new FloatIntBytesUnion(); u.f = value; u.i = u.i ^ key; return(u.i); }
/// <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(int encrypted) { inited = true; FloatIntBytesUnion union = new FloatIntBytesUnion(); union.i = encrypted; hiddenValue = new[] { union.b1, union.b2, union.b3, union.b4 }; }
/// <summary> /// Allows to pick current obscured value as is. /// </summary> /// Use it in conjunction with SetEncrypted().<br/> /// Useful for saving data in obscured state. public int GetEncrypted() { ApplyNewCryptoKey(); var union = new FloatIntBytesUnion(); union.b4 = hiddenValue; return(union.i); }
/// <summary> /// Use it to decrypt int you got from Encrypt(float) back to float, uses passed crypto key. /// </summary> /// Make sure you're using key at least of 1000000000 value to improve security. public static float Decrypt(int value, int key) { var u = new FloatIntBytesUnion { i = value }; u.b4.UnShuffle(); u.i ^= key; return(u.f); }
/// <summary> /// Use this simple encryption method to encrypt any float value, uses passed crypto key. /// </summary> /// Make sure you're using key at least of 1000000000 value to improve security. public static int Encrypt(float value, int key) { var u = new FloatIntBytesUnion { f = value }; u.i = u.i ^ key; u.b4.Shuffle(); return(u.i); }
public void SetEncrypted(int encrypted) { var union = new FloatIntBytesUnion(); union.i = encrypted; hiddenValue[0] = union.b1; hiddenValue[1] = union.b2; hiddenValue[2] = union.b3; hiddenValue[3] = union.b4; }
public static float Decrypt(int value, int key) { if (key == 0) { key = cryptoKey; } var u = new FloatIntBytesUnion(); u.i = value ^ key; return(u.f); }
/// <summary> /// Allows to pick current obscured value as is. /// </summary> /// Use it in conjunction with SetEncrypted().<br/> /// Useful for saving data in obscured state. public int GetEncrypted() { ApplyNewCryptoKey(); var union = new FloatIntBytesUnion(); union.b1 = hiddenValue[0]; union.b2 = hiddenValue[1]; union.b3 = hiddenValue[2]; union.b4 = hiddenValue[3]; return(union.i); }
/// <summary> /// Allows to update the raw encrypted value to the newer encryption format. /// </summary> /// Use when you have some encrypted values saved somewhere with previous ACTk version /// and you wish to set them using SetEncrypted() to the newer ACTk version obscured type. /// Current migration variants: /// from 0 or 1 to 2 - migrate obscured type from ACTk 1.5.2.0-1.5.8.0 to the 1.5.9.0+ format /// <param name="encrypted">Encrypted value you got from previous ACTk version obscured type with GetEncrypted().</param> /// <param name="fromVersion">Source format version.</param> /// <param name="toVersion">Target format version.</param> /// <returns>Migrated raw encrypted value which you may use for SetEncrypted(0 later.</returns> public static int MigrateEncrypted(int encrypted, byte fromVersion = 0, byte toVersion = 2) { var u = new FloatIntBytesUnion { i = encrypted }; if (fromVersion < 2 && toVersion == 2) { u.b4.Shuffle(); } return(u.i); }
/// <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(int encrypted) { FloatIntBytesUnion union = new FloatIntBytesUnion(); union.i = encrypted; hiddenValue = new[] { union.b1, union.b2, union.b3, union.b4 }; if (Detectors.ObscuredCheatingDetector.isRunning) { fakeValue = InternalDecrypt(); } }
/// <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(int encrypted) { inited = true; var union = new FloatIntBytesUnion(); union.i = encrypted; hiddenValue = union.b4; if (currentCryptoKey == 0) { currentCryptoKey = cryptoKey; } }
/// <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(int encrypted) { inited = true; FloatIntBytesUnion union = new FloatIntBytesUnion(); union.i = encrypted; hiddenValue = union.b4; if (Detectors.ObscuredCheatingDetector.IsRunning) { fakeValue = InternalDecrypt(); } }
public int GetEncrypted() { if (currentCryptoKey != cryptoKey) { float value = InternalDecrypt(); hiddenValue = InternalEncrypt(value); currentCryptoKey = cryptoKey; } FloatIntBytesUnion floatIntBytesUnion = default(FloatIntBytesUnion); floatIntBytesUnion.b1 = hiddenValue[0]; floatIntBytesUnion.b2 = hiddenValue[1]; floatIntBytesUnion.b3 = hiddenValue[2]; floatIntBytesUnion.b4 = hiddenValue[3]; return(floatIntBytesUnion.i); }
private static byte[] InternalEncrypt(float value, int key) { int currKey = key; if (currKey == 0) { currKey = cryptoKey; } var u = new FloatIntBytesUnion(); u.f = value; u.i = u.i ^ currKey; return(new[] { u.b1, u.b2, u.b3, u.b4 }); }
public void SetEncrypted(int encrypted) { FloatIntBytesUnion floatIntBytesUnion = default(FloatIntBytesUnion); floatIntBytesUnion.i = encrypted; hiddenValue = new byte[4] { floatIntBytesUnion.b1, floatIntBytesUnion.b2, floatIntBytesUnion.b3, floatIntBytesUnion.b4 }; if (onCheatingDetected != null) { fakeValue = InternalDecrypt(); } }
private static ACTkByte4 InternalEncrypt(float value, int key) { var currentKey = key; if (currentKey == 0) { currentKey = cryptoKey; } var u = new FloatIntBytesUnion(); u.f = value; u.i = u.i ^ currentKey; return(u.b4); }
private static void InternalEncrypt(byte[] bytes, float value, int key = 0) { if (key == 0) { key = cryptoKey; } var u = new FloatIntBytesUnion(); u.f = value; u.i = u.i ^ key; bytes[0] = u.b1; bytes[1] = u.b2; bytes[2] = u.b3; bytes[3] = u.b4; }
public int GetEncrypted() { if (currentCryptoKey != cryptoKey) { float temp = InternalDecrypt(); InternalEncrypt(hiddenValue, temp, cryptoKey); currentCryptoKey = cryptoKey; } var union = new FloatIntBytesUnion(); union.b1 = hiddenValue[0]; union.b2 = hiddenValue[1]; union.b3 = hiddenValue[2]; union.b4 = hiddenValue[3]; return(union.i); }
private static byte[] InternalEncrypt(float value, int key) { int num = key; if (num == 0) { num = cryptoKey; } FloatIntBytesUnion floatIntBytesUnion = default(FloatIntBytesUnion); floatIntBytesUnion.f = value; floatIntBytesUnion.i ^= num; return(new byte[4] { floatIntBytesUnion.b1, floatIntBytesUnion.b2, floatIntBytesUnion.b3, floatIntBytesUnion.b4 }); }
private float InternalDecrypt() { int key = cryptoKey; if (currentCryptoKey != cryptoKey) { key = currentCryptoKey; } var union = new FloatIntBytesUnion(); union.b1 = hiddenValue[0]; union.b2 = hiddenValue[1]; union.b3 = hiddenValue[2]; union.b4 = hiddenValue[3]; union.i = union.i ^ key; return(union.f); }
private float InternalDecrypt() { if (!inited) { currentCryptoKey = GenerateKey(); hiddenValue = Encrypt(0, currentCryptoKey); fakeValue = 0; fakeValueActive = false; inited = true; return(0); } #if ACTK_OBSCURED_AUTO_MIGRATION if (hiddenValueOldByte4.b1 != 0 || hiddenValueOldByte4.b2 != 0 || hiddenValueOldByte4.b3 != 0 || hiddenValueOldByte4.b4 != 0) { var union = new FloatIntBytesUnion { b4 = hiddenValueOldByte4 }; union.b4.Shuffle(); hiddenValue = union.i; hiddenValueOldByte4.b1 = 0; hiddenValueOldByte4.b2 = 0; hiddenValueOldByte4.b3 = 0; hiddenValueOldByte4.b4 = 0; } #endif var decrypted = Decrypt(hiddenValue, currentCryptoKey); if (Detectors.ObscuredCheatingDetector.ExistsAndIsRunning && fakeValueActive && Math.Abs(decrypted - fakeValue) > Detectors.ObscuredCheatingDetector.Instance.floatEpsilon) { Detectors.ObscuredCheatingDetector.Instance.OnCheatingDetected(); } return(decrypted); }
private float InternalDecrypt() { if (!inited) { currentCryptoKey = cryptoKey; hiddenValue = InternalEncrypt(0); inited = true; return(0); } var union = new FloatIntBytesUnion(); union.b4 = hiddenValue; union.i = union.i ^ currentCryptoKey; var decrypted = union.f; return(decrypted); }
/// <summary> /// Decrypts passed value you got from Encrypt() using same key. /// </summary> /// \sa Encrypt() public static float Decrypt(int value, int key) { return(FloatIntBytesUnion.XorIntToFloat(value, key)); }
private static bool MigrateObject(SerializedObject so, string label, string[] typesToMigrate) { var modified = false; var sp = so.GetIterator(); if (sp == null) { return(false); } while (sp.NextVisible(true)) { if (sp.propertyType != SerializedPropertyType.Generic) { continue; } var type = sp.type; if (Array.IndexOf(typesToMigrate, type) == -1) { continue; } switch (type) { case "ObscuredDouble": { var hiddenValue = sp.FindPropertyRelative("hiddenValue"); if (hiddenValue == null) { continue; } var fakeValue = sp.FindPropertyRelative("fakeValue"); var migratedVersion = sp.FindPropertyRelative("migratedVersion"); if (migratedVersion != null) { if (migratedVersion.stringValue == MigrationVersion) { if (!fakeValue.prefabOverride) { continue; } } migratedVersion.stringValue = MigrationVersion; } var hiddenValueOldProperty = sp.FindPropertyRelative("hiddenValueOldByte8"); var hiddenValueOld = default(ACTkByte8); var oldValueExists = false; if (hiddenValueOldProperty != null) { if (hiddenValueOldProperty.FindPropertyRelative("b1") != null) { hiddenValueOld.b1 = (byte)hiddenValueOldProperty.FindPropertyRelative("b1").intValue; hiddenValueOld.b2 = (byte)hiddenValueOldProperty.FindPropertyRelative("b2").intValue; hiddenValueOld.b3 = (byte)hiddenValueOldProperty.FindPropertyRelative("b3").intValue; hiddenValueOld.b4 = (byte)hiddenValueOldProperty.FindPropertyRelative("b4").intValue; hiddenValueOld.b5 = (byte)hiddenValueOldProperty.FindPropertyRelative("b5").intValue; hiddenValueOld.b6 = (byte)hiddenValueOldProperty.FindPropertyRelative("b6").intValue; hiddenValueOld.b7 = (byte)hiddenValueOldProperty.FindPropertyRelative("b7").intValue; hiddenValueOld.b8 = (byte)hiddenValueOldProperty.FindPropertyRelative("b8").intValue; if (hiddenValueOld.b1 != 0 || hiddenValueOld.b2 != 0 || hiddenValueOld.b3 != 0 || hiddenValueOld.b4 != 0 || hiddenValueOld.b5 != 0 || hiddenValueOld.b6 != 0 || hiddenValueOld.b7 != 0 || hiddenValueOld.b8 != 0) { oldValueExists = true; } } } if (oldValueExists) { var union = new LongBytesUnion { b8 = hiddenValueOld }; union.b8.Shuffle(); hiddenValue.longValue = union.l; hiddenValueOldProperty.FindPropertyRelative("b1").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b2").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b3").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b4").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b5").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b6").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b7").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b8").intValue = 0; Debug.Log(ACTkConstants.LogPrefix + "Migrated property " + sp.displayName + ":" + type + " at the object " + label); modified = true; } break; } case "ObscuredFloat": { var hiddenValue = sp.FindPropertyRelative("hiddenValue"); if (hiddenValue == null) { continue; } var fakeValue = sp.FindPropertyRelative("fakeValue"); var migratedVersion = sp.FindPropertyRelative("migratedVersion"); if (migratedVersion != null) { if (migratedVersion.stringValue == MigrationVersion) { if (!fakeValue.prefabOverride) { continue; } } migratedVersion.stringValue = MigrationVersion; } var hiddenValueOldProperty = sp.FindPropertyRelative("hiddenValueOldByte4"); var hiddenValueOld = default(ACTkByte4); var oldValueExists = false; if (hiddenValueOldProperty != null) { if (hiddenValueOldProperty.FindPropertyRelative("b1") != null) { hiddenValueOld.b1 = (byte)hiddenValueOldProperty.FindPropertyRelative("b1").intValue; hiddenValueOld.b2 = (byte)hiddenValueOldProperty.FindPropertyRelative("b2").intValue; hiddenValueOld.b3 = (byte)hiddenValueOldProperty.FindPropertyRelative("b3").intValue; hiddenValueOld.b4 = (byte)hiddenValueOldProperty.FindPropertyRelative("b4").intValue; if (hiddenValueOld.b1 != 0 || hiddenValueOld.b2 != 0 || hiddenValueOld.b3 != 0 || hiddenValueOld.b4 != 0) { oldValueExists = true; } } } if (oldValueExists) { var union = new FloatIntBytesUnion { b4 = hiddenValueOld }; union.b4.Shuffle(); hiddenValue.longValue = union.i; hiddenValueOldProperty.FindPropertyRelative("b1").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b2").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b3").intValue = 0; hiddenValueOldProperty.FindPropertyRelative("b4").intValue = 0; Debug.Log(ACTkConstants.LogPrefix + "Migrated property " + sp.displayName + ":" + type + " at the object " + label); modified = true; } break; } case "ObscuredVector2": { var hiddenValue = sp.FindPropertyRelative("hiddenValue"); if (hiddenValue == null) { continue; } var fakeValue = sp.FindPropertyRelative("fakeValue"); var migratedVersion = sp.FindPropertyRelative("migratedVersion"); if (migratedVersion != null) { if (migratedVersion.stringValue == MigrationVersion) { if (!fakeValue.prefabOverride) { continue; } } migratedVersion.stringValue = MigrationVersion; } var hiddenValueX = hiddenValue.FindPropertyRelative("x"); var hiddenValueY = hiddenValue.FindPropertyRelative("y"); var union = new FloatIntBytesUnion { i = hiddenValueX.intValue }; union.b4.Shuffle(); hiddenValueX.intValue = union.i; union.i = hiddenValueY.intValue; union.b4.Shuffle(); hiddenValueY.intValue = union.i; Debug.Log(ACTkConstants.LogPrefix + "Migrated property " + sp.displayName + ":" + type + " at the object " + label); modified = true; break; } case "ObscuredVector3": { var hiddenValue = sp.FindPropertyRelative("hiddenValue"); if (hiddenValue == null) { continue; } var fakeValue = sp.FindPropertyRelative("fakeValue"); var migratedVersion = sp.FindPropertyRelative("migratedVersion"); if (migratedVersion != null) { if (migratedVersion.stringValue == MigrationVersion) { if (!fakeValue.prefabOverride) { continue; } } migratedVersion.stringValue = MigrationVersion; } var hiddenValueX = hiddenValue.FindPropertyRelative("x"); var hiddenValueY = hiddenValue.FindPropertyRelative("y"); var hiddenValueZ = hiddenValue.FindPropertyRelative("z"); var union = new FloatIntBytesUnion { i = hiddenValueX.intValue }; union.b4.Shuffle(); hiddenValueX.intValue = union.i; union.i = hiddenValueY.intValue; union.b4.Shuffle(); hiddenValueY.intValue = union.i; union.i = hiddenValueZ.intValue; union.b4.Shuffle(); hiddenValueZ.intValue = union.i; Debug.Log(ACTkConstants.LogPrefix + "Migrated property " + sp.displayName + ":" + type + " at the object " + label); modified = true; break; } case "ObscuredQuaternion": { var hiddenValue = sp.FindPropertyRelative("hiddenValue"); if (hiddenValue == null) { continue; } var fakeValue = sp.FindPropertyRelative("fakeValue"); var migratedVersion = sp.FindPropertyRelative("migratedVersion"); if (migratedVersion != null) { if (migratedVersion.stringValue == MigrationVersion) { if (!fakeValue.prefabOverride) { continue; } } migratedVersion.stringValue = MigrationVersion; } var hiddenValueX = hiddenValue.FindPropertyRelative("x"); var hiddenValueY = hiddenValue.FindPropertyRelative("y"); var hiddenValueZ = hiddenValue.FindPropertyRelative("z"); var hiddenValueW = hiddenValue.FindPropertyRelative("w"); var union = new FloatIntBytesUnion { i = hiddenValueX.intValue }; union.b4.Shuffle(); hiddenValueX.intValue = union.i; union.i = hiddenValueY.intValue; union.b4.Shuffle(); hiddenValueY.intValue = union.i; union.i = hiddenValueZ.intValue; union.b4.Shuffle(); hiddenValueZ.intValue = union.i; union.i = hiddenValueW.intValue; union.b4.Shuffle(); hiddenValueW.intValue = union.i; Debug.Log(ACTkConstants.LogPrefix + "Migrated property " + sp.displayName + ":" + type + " at the object " + label); modified = true; break; } case "ObscuredString": { modified = MigrateObscuredStringIfNecessary(sp); break; } } } return(modified); }