How to prevent cheating with Gamecih?

前端 未结 10 1554
孤独总比滥情好
孤独总比滥情好 2021-01-31 12:07

Background

I\'ve had problems for quite a while now with players cheating in my android game. For a strict single-player game this wouldn\'t be a big is

10条回答
  •  不知归路
    2021-01-31 12:37

    You can check periodically if your value has changed when it was not supposed to.

    For example, you can store in a separate hidden flag the fact that the health value has changed. If your check method does detect a change in the value, and the flag is not set, then you can tell that the change was illegal.

    For example :

    void incrementHealth(int amount) {
        health = health + amout;
        hiddenCheck.hasChanged = true;
        }
    

    and in a separate method which must be invoked periodically :

    void checkHealth() {
        if (hiddenCheck.hasChanged) {
            // change is valid
            hiddenCheck.hasChanged = false;
            hiddenCheck.lastKnownValue = health;
            } else {
                if (hiddenCheck.lastKnownValue != health) {
                    // An illegal change has occured ! Punish the hacker !
                    }
                }
            }
       }
    

提交回复
热议问题