Skip to content

Instantly share code, notes, and snippets.

@jasielmacedo
Last active March 16, 2017 17:08
Show Gist options
  • Save jasielmacedo/b896d0e162bb70a32842c232d23bd629 to your computer and use it in GitHub Desktop.
Save jasielmacedo/b896d0e162bb70a32842c232d23bd629 to your computer and use it in GitHub Desktop.
Every variable in game is important and unsecured ints can be changed using Cheat Engine. This class can obfuscate your int
using UnityEngine;
using System.Collections;
public struct IntObfuscator
{
private int m_offset;
private int m_value;
public IntObfuscator(int value = 0)
{
System.Random rand = new System.Random();
m_offset = rand.Next(-1000,1000);
this.m_value = value + m_offset;
}
void define(int value = 0)
{
System.Random rand = new System.Random();
m_offset = rand.Next(-1000,1000);
this.m_value = value + m_offset;
}
public int Value
{
get
{
return m_value - m_offset;
}
set{
define(value);
}
}
public void Dispose()
{
m_offset = 0;
m_value = 0;
}
public int ToInt()
{
return this.Value;
}
public override string ToString()
{
return Value.ToString();
}
public static explicit operator IntObfuscator(int a){ return new IntObfuscator(a); }
public static implicit operator int(IntObfuscator a){ return a.Value; }
public static explicit operator IntObfuscator(string a){ return new IntObfuscator(int.Parse(a)); }
public static implicit operator string(IntObfuscator a){ return a.Value.ToString(); }
public static IntObfuscator operator +(IntObfuscator a, IntObfuscator b){ return new IntObfuscator(a.Value + b.Value); }
public static IntObfuscator operator +(IntObfuscator a, int b){ return new IntObfuscator(a.Value + b); }
public static IntObfuscator operator -(IntObfuscator a, IntObfuscator b){ return new IntObfuscator(a.Value - b.Value); }
public static IntObfuscator operator -(IntObfuscator a, int b){ return new IntObfuscator(a.Value - b); }
public static IntObfuscator operator *(IntObfuscator a, IntObfuscator b){ return new IntObfuscator(a.Value * b.Value); }
public static IntObfuscator operator *(IntObfuscator a, int b){ return new IntObfuscator(a.Value * b); }
public static IntObfuscator operator /(IntObfuscator a, IntObfuscator b){ return new IntObfuscator(a.Value * b.Value); }
public static IntObfuscator operator /(IntObfuscator a, int b){ return new IntObfuscator(a.Value * b); }
public static bool operator ==(IntObfuscator a, IntObfuscator b){ return a.Value == b.Value; }
public static bool operator ==(IntObfuscator a, int b){ return a.Value == b; }
public static bool operator !=(IntObfuscator a, IntObfuscator b){ return a.Value != b.Value; }
public static bool operator !=(IntObfuscator a, int b){ return a.Value != b; }
public static bool operator >=(IntObfuscator a, IntObfuscator b){ return a.Value >= b.Value; }
public static bool operator >=(IntObfuscator a, int b){ return a.Value >= b; }
public static bool operator >(IntObfuscator a, IntObfuscator b){ return a.Value > b.Value; }
public static bool operator >(IntObfuscator a, int b){ return a.Value > b; }
public static bool operator <=(IntObfuscator a, IntObfuscator b){ return a.Value <= b.Value; }
public static bool operator <=(IntObfuscator a, int b){ return a.Value <= b; }
public static bool operator <(IntObfuscator a, IntObfuscator b){ return a.Value < b.Value; }
public static bool operator <(IntObfuscator a, int b){ return a.Value < b; }
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment