Just a thought I had. It is good to protect a game from being interfered with by custom made trainers, DIY trainer tools like CheatEngine or packet editors. Encoding or even encrypting critical variables when you send them across a network or store them in memory or file would be a way to do that. Doing something to prevent cheating is important if you have a game that could be ruined by it, e.g. online multiplayer games and/or a game that relies on slow accumulation of in-game items and stats.
Here is a little bit of code showing a simple example of it could be done:-
In the above example the variable money is protected by simple bXOR encoding and a 16bit shift. The variable moneynorm is stored normally. I tested the routine using CheatEngine to "cheat" by trying to find and change the stored variables in memory. It is easy with moneynorm but very difficult with money (without knowing how the value is being encoded). Such a technique won't stop a very determined & experienced cheater but is fairly good basic protection. Its also not very expensive for CPU - its a fast way to do it. It would be possible to encrypt stored variables instead but that would be more CPU intensive and some countries have restrictions on the use of encryption.
Does anyone else use techniques like this or have other ideas about how to protect games from cheaters?
Here is a little bit of code showing a simple example of it could be done:-
Code (glbasic) Select
GLOBAL money%, moneynorm%, ivalue%, uvalue%
WHILE KEY(01) = 0
ivalue = RND(32000) // This is the value to assign to money
uvalue = RND(32000) // This is the value to assign to moneynorm
money = ASL(bXOR(ivalue, 21845), 16)
moneynorm = uvalue
ivalue = 0
uvalue = 0
WHILE KEY (57) = 0
PRINT "Money variable decoded is "+bXOR(ASR(money, 16), 21845), 0, 00
PRINT "Encoded stored value is "+money, 0, 10
PRINT "Moneynorm variable unencoded is "+moneynorm, 0, 30
PRINT "Unencoded stored value is "+moneynorm, 0, 40
PRINT "Press space for next value assignment", 0, 60
SHOWSCREEN
WEND
WEND
END
In the above example the variable money is protected by simple bXOR encoding and a 16bit shift. The variable moneynorm is stored normally. I tested the routine using CheatEngine to "cheat" by trying to find and change the stored variables in memory. It is easy with moneynorm but very difficult with money (without knowing how the value is being encoded). Such a technique won't stop a very determined & experienced cheater but is fairly good basic protection. Its also not very expensive for CPU - its a fast way to do it. It would be possible to encrypt stored variables instead but that would be more CPU intensive and some countries have restrictions on the use of encryption.
Does anyone else use techniques like this or have other ideas about how to protect games from cheaters?