Forum rules - please read before posting.

Protect Variables from hacks.

I'm building for android and using global variables for Gems and Energy in my game. There is an application for Android called Lucky Patcher which can be used on running games to patch at runtime and modify variables. Gems are a premium in currency my game and knowing that players can change this Variable easily is literally breaking the value of my game completely. I'm not a programmer so please let me know how can I protect my variables from this?


  • This may be more of a general Unity question, and I'm not aware of how "Lucky Patcher" works. Is it able to modify variables at the time an app is running? Or only modify save-game file values?

  • It's able to modify variables at the time an app is running.

  • edited June 17

    You could consider the use of encryption and have your "Gems" variable be an encrypted string based off an integer value.

    There's many techniques to do so, so you'd need to look for one that works for you - but essentially you could try:

    1. Use a script's private variable to store the true (Integer) value
    2. Update your game's logic to read this variable instead of the Global Variable
    3. Using a String variable instead of an Integer
    4. When saving, use encryption to set the Global String Variable from this Integer
    5. When loading, use decryption to convert it back to an Integer

    With this technique, the encryption steps (#3-#5) would only be necessary to get saving working. Steps #1-2 would need to be done first, however, and would be tricky since you'd only be able to access the Integer value through script - not through AC's Actions.

    How is your "Gems" variable currently referenced by your project?

  • My gems Variable is an integer and I update the value using AC actions. Increasing by either a positive value or a negative value. I'm also using playmaker in my project. But mostly I'm using AC for my Global integer variables of Gems and Global float variable for Energy.

  • edited June 20

    Here's an example script that replaces the need for Integer/Float variables for Gems and Energy with String variables (named "Gems" and "Energy" respectively:

    using System;
    using UnityEngine;
    using AC;
    public static class EncryptedData
        private const string gemsVariable = "Gems";
        private const string energyVariable = "Energy";
        public static int Gems
                string encryptedString = GlobalVariables.GetVariable (gemsVariable).TextValue;
                return Decrypt (encryptedString);
                string encryptedString = Encrypt (value);
                GlobalVariables.GetVariable (gemsVariable).TextValue = encryptedString;
        public static float Energy
                string encryptedString = GlobalVariables.GetVariable (energyVariable).TextValue;
                return Decrypt (encryptedString) / 1000;
                string encryptedString = Encrypt ((int) value * 1000);
                GlobalVariables.GetVariable (energyVariable).TextValue = encryptedString;
        private static int Decrypt (string value)
            if(value.Length!=6) return 0;
            return BitConverter.ToInt32(Convert.FromBase64String(value + "=="),0);
        private static string Encrypt (int value)
            return Convert.ToBase64String(BitConverter.GetBytes(value)).Replace("==","");

    Note that this does not use encryption - just a Base-64 encoding. The Decrypt/Encrypt functions will need to be replaced with a proper encoding algorithm of your choice, but this will serve as a proof-of-concept.

    This is a static class, so you can access your Gems and Energy values through custom script with:

  • Hello, since I lack knowledge in programming with C#, I find myself in a difficult situation.

    Is it necessary to use code for this task? Alternatively, could I create a detailed action list to store and restore the values of Gems (integer) and Energy (float) in separate string variables whenever the values need to be updated? I would rename these string variables or hide them somehow in a way that makes it more challenging for hackers to locate them.

    I'm mentioning this because I currently lack the necessary resources to integrate my own custom code, unless you are able to assist me. Considering the significant impact on the game economy, I must find a solution and cannot overlook this issue at any cost. Hence, perhaps I can find a workaround that makes it more difficult for the vulnerability to be exposed

  • If there a finite number of e.g. Gems, you could have a "conversion" ActionList that manually turns 1 => Apple, 2 => Orange etc. Otherwise, code would be necessary.

    Encryption and IAPs are not a part of AC, but any skilled Unity programmer for hire should be able to help with this.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.