# Anti-hacking using maths

49 replies to this topic

### #1 Blue2010

Blue2010

GMC Member

• New Member
• 8 posts

Posted 11 December 2011 - 04:17 AM

Recently I saw something like this to protect the valuable variables in a game, replace x with them;

Begin step;
x = (((22*x)-7)/4)+.123 (packing)

End step;
x = (((x-.123)*4)+7)/22 (unpacking)
if x is now a decimal, then we've been hacking. See below

Alright, if x is a decimal then that means that between the begin step and end step events, the variable has been modified - unless the hacker chooses an extremely random decimal and gamemaker's rounding to 2 decimal places lands a very lucky shot, the game should catch the hacker.

However (I know very little about programs that modify these variables eg Cheatengine) the hacker can change the variable during the begin step, end step or draw events and mess up this method, yes? Does this mean that if the hacker continues to try to modify variables eventually it will work? Does it also mean that the unpacking and checking should occur in the draw event, as that reduces the amount of time a hacking program can modify the variables?
Also, this method will probably slow down the game a bit (does gamemakers rounding decimals reduce the work it has to do?), so how much math would be required to still have a high probability of catching the hacker out, but retain the performance of the game itself?
I'd actually be pretty interested in the probability (with working) of the math I gave above for a variable being changed by 1 or some whole integer.
• 0

### #2 ash47

ash47

O_o

• GMC Member
• 1326 posts

Posted 11 December 2011 - 06:28 AM

Idk about doing all that, personally using the XOR function is really good in terms of protecting variables, if you XOR a number by something like 5, it will go up, then back down, depending on the variable, and makes it really hard to track in stuff like cheat engine, as far as this method goes, seems pretty interesting =P
• 0

### #3 NakedPaulToast

NakedPaulToast

GM Studio/Mac/Win

• GMC Member
• 7203 posts
• Version:GM:Studio

Posted 11 December 2011 - 04:31 PM

Recently I saw something like this to protect the valuable variables in a game, replace x with them;

Begin step;
x = (((22*x)-7)/4)+.123 (packing)

End step;
x = (((x-.123)*4)+7)/22 (unpacking)
if x is now a decimal, then we've been hacking. See below

Alright, if x is a decimal then that means that between the begin step and end step events, the variable has been modified - unless the hacker chooses an extremely random decimal and gamemaker's rounding to 2 decimal places lands a very lucky shot, the game should catch the hacker.

However (I know very little about programs that modify these variables eg Cheatengine) the hacker can change the variable during the begin step, end step or draw events and mess up this method, yes? Does this mean that if the hacker continues to try to modify variables eventually it will work? Does it also mean that the unpacking and checking should occur in the draw event, as that reduces the amount of time a hacking program can modify the variables?
Also, this method will probably slow down the game a bit (does gamemakers rounding decimals reduce the work it has to do?), so how much math would be required to still have a high probability of catching the hacker out, but retain the performance of the game itself?
I'd actually be pretty interested in the probability (with working) of the math I gave above for a variable being changed by 1 or some whole integer.

GameMaker naturally modifies the x variable between the begin step and end step. This won't work.

GameMaker doesn't round variables to two variables, though the string function will for display purposes only.

Edited by NakedPaulToast, 11 December 2011 - 04:31 PM.

• 0

### #4 DZiW

DZiW

GMC Member

• GMC Member
• 727 posts

Posted 11 December 2011 - 08:31 PM

IMO,
1) if the same number gives the same encoded result then it's rather poor approach;
2) if the sensible variables use the same mem offset then it's but useless;
3) if 'protection' makes the software rather complex or oven unstable then;
4) very few games are even worth cheating, let alone made in GM...

Anyway, just add built-in cheat and let those who really want to use it.
• 0

### #5 YellowAfterlife

YellowAfterlife

GMC Member

• Global Moderators
• 3496 posts
• Version:GM:Studio

Posted 11 December 2011 - 08:45 PM

Cheating is critical only for games where online highscores or achievements are available.

For those you may want to have 'verification' variables along with all important ones.
So you would create a script(s) like:
```// score_set(value, skip) - changes score
// value - new score value
// skip - skip verification
if (!argument1) if ((score ^ 77) != score_) global.is_cheating = true;
score = argument0;
score_ = score ^ 77;```
Replace '^ 77' by calculation of choice - be that division, lengthdir, or checksum.

This method leaves variable(s) well exposed, however you will know if player changed something, and take care - be that shutting the game down, resetting their score, or kicking them out just before the end of game (warning: may cause hate).
• 0

### #6 Blue2010

Blue2010

GMC Member

• New Member
• 8 posts

Posted 11 December 2011 - 10:52 PM

Ash, I don't know what you're talking about, are you saying something about 'exclusive or'?

NPT:

GameMaker naturally modifies the x variable between the begin step and end step. This won't work.

GameMaker doesn't round variables to two variables, though the string function will for display purposes only.

Why does GM modify the x variable? I really hope you're not meaning all the variables and mistook my meaning of x being co-ordinate variables...

And yeah, wow, GM doesn't actually round the decimals except when displaying them, which is a bit weird. Again, why was this done...? >_>

DZiW... please don't assume the importance of this protection to be null. Even if it was, that is not the question.

YAL: I don't really see how that helps at all?
• 0

### #7 YellowAfterlife

YellowAfterlife

GMC Member

• Global Moderators
• 3496 posts
• Version:GM:Studio

Posted 11 December 2011 - 11:08 PM

See this example. Hack score, then click a fruit.
• 0

### #8 yourtexthere

yourtexthere

GMC Member

• New Member
• 66 posts

Posted 12 December 2011 - 02:10 AM

Why do you care so much if people cheat in your game?
That's their problem if they get pleasure out of freaking CHEATING on someone's game maker game, I mean seriously...
• -3

### #9 Blue2010

Blue2010

GMC Member

• New Member
• 8 posts

Posted 12 December 2011 - 02:41 AM

YAL: After re-reading that, I understand and it's a pretty good method other than a hacker aware of this could observe the trend between both variables. I like this method though. What about speed? Would the extra memory and math calculations matter much?

Why do you care so much if people cheat in your game?
That's their problem if they get pleasure out of freaking CHEATING on someone's game maker game, I mean seriously...

These comments are beginning to irritate me. Evidently you cannot conceive a possible scenario where cheating would be detrimental to other players; ie online communication. If you are not going to post something useful, please do not post at all.
• 0

### #10 YellowAfterlife

YellowAfterlife

GMC Member

• Global Moderators
• 3496 posts
• Version:GM:Studio

Posted 12 December 2011 - 05:37 AM

YAL: After re-reading that, I understand and it's a pretty good method other than a hacker aware of this could observe the trend between both variables. I like this method though. What about speed? Would the extra memory and math calculations matter much?

GameMaker changes a lot of its own variables every step. If hacker has patience to do step-by-step debugging of your game to track down second variable, figure out it's formulae, and change those at once, anti-hacking protections wouldn't protect your game anyway.
About performance - depends on operations that you perform, but in most cases not significiant (other in-game calculations are likely to take more time than it anyway). I have succesfully used Le Maire's random number generation algorithm (value_ = ((value * const1) + const2) mod const3) for this purpose in few games and it still wasn't noticable behind other calculations. Obviously, a more complex algorithm also makes it harder to track down 'protecting' variable.
• 0

### #11 DZiW

DZiW

GMC Member

• GMC Member
• 727 posts

Posted 12 December 2011 - 01:26 PM

IMO it's too much fuss about nothing: all online apps with sensible protection are server-side only. Do you copy?
Furthermore, all GM EXE are so easily ripped back as GMx/K that I don't think it's a real problem--so now you have also to check CRC/MD5 or something too, right? Go ahead and on

The 'real' protection which I find really cute makes a few indirect checks, but doesn't cry out 'WOLF! WOLF!' or something, it just modifies memory a heap/data so that the app successfully crashes--every cheat is a crash.

But there's no need of it all: if one really wants he can just modify the routine or send his modified data to your server of hi-scores even without running your game. So, the only relevant criterion of hi-score is... game time?
• 0

### #12 NakedPaulToast

NakedPaulToast

GM Studio/Mac/Win

• GMC Member
• 7203 posts
• Version:GM:Studio

Posted 12 December 2011 - 02:52 PM

Why does GM modify the x variable? I really hope you're not meaning all the variables and mistook my meaning of x being co-ordinate variables...

Yes I interpreted your use of the x variable as the co-ordinate. That's what the x variable represents.

And yeah, wow, GM doesn't actually round the decimals except when displaying them, which is a bit weird. Again, why was this done...?

For convenience. Take the default of two decimal points or use string_format if you want to control the number of decimal points.
• 0

### #13 Erik Leppen

Erik Leppen

GMC Member

• GMC Member
• 2035 posts
• Version:GM:Studio

Posted 12 December 2011 - 07:56 PM

Begin step;
x = (((22*x)-7)/4)+.123 (packing)

End step;
x = (((x-.123)*4)+7)/22 (unpacking)
if x is now a decimal, then we've been hacking.

I need to place a word of warning here, because GM cannot exactly represent the number 0.123. The reason is that computers work in binary and the decimal fraction 0.12310 is in fact the binary fraction
0.00011111011111001110110110010001011010000111001010110000001000001100010010011011101001011110001101010012
in binary (the undelined part is the period, should be overlined instead of underlined).
So GM will round this number, it will not be exactly decimal 0.123 anymore. It may only differ for 2-53 (I believe), but a difference that small will make x into a decimal (because 256.000000000000001 is a decimal).

For this reason I'm always cautious with floating point arithmetic and I prefer integer arithmetic for those kinds of things.
• 0

### #14 Blue2010

Blue2010

GMC Member

• New Member
• 8 posts

Posted 13 December 2011 - 01:41 AM

Why does GM modify the x variable? I really hope you're not meaning all the variables and mistook my meaning of x being co-ordinate variables...

Yes I interpreted your use of the x variable as the co-ordinate. That's what the x variable represents.

Recently I saw something like this to protect the valuable variables in a game, replace x with them;

Erik, that's actually really interesting, so you're saying that I should use something 'nice' for binary? I'ma test that out...

• 0

### #15 DZiW

DZiW

GMC Member

• GMC Member
• 727 posts

Posted 18 December 2011 - 07:21 PM

IMO the only modern way to obfuscate something against cheating is custom encoding and dynamic constantly changing address, but some advanced cheat engines (e.g. ArtMoney) have plenty of methods (like search for formula, coded value, unknown, memory damp, structure, pointer, filesearch, with full process session data and control /pause-resume, save-load/ etc) which make even almost any 'protection' futile.

For onstance, in my demo I used hack-revealing method of 'score/time' aspect where time value was encoded with fingeprints (e.g. '24-Hh' and '60-Mm'), so I could check the pseudo-CRC and assess allegedly time spent. The point is when one sees the formula then it's more than trivial to use math-reversal: a friend of mine once showed me how hacked hi-score sending routine without real hacking - just via ol' TCP_VIEW!

Yet I would like to make a compliment to you: if at least someone really wanted to hack your GM game then it must be something really worthy
• 0

### #16 TamoNekiTipo

TamoNekiTipo

Centurion

• Banned Users
• 51 posts
• Version:GM8

Posted 11 January 2012 - 09:28 PM

I just divide the variable by 2, and then multiply it by 2.
It's simple and it sure covers the variable in Cheat Engine.

### #17 loverock125

loverock125

GMC Member

• GMC Member
• 1614 posts
• Version:GM8

Posted 12 January 2012 - 01:07 AM

As 'YellowAfterLife' said:

Cheating is critical only for games where online highscores or achievements are available.

So if you are going to have online highscores, you might as well use a server and have the important variables stored by the server.
Otherwise the safest way in my opinion is encryption but I don't really see the point of having so much protection for simple single-player games.

Also keep in mind that everything can be hacked.

Edit: If Game Maker stores data in RAM at the exact moment when you assign a value to a variable (I'm 99% sure that this is what it does), then I believe that to determine what time Cheat Engine can capture variables you would need to know in what order the CPU executes the commands (GameMaker's first or Cheat Engine's). If Cheat Engine captures data directly from RAM, and Game Maker stores data immediately in RAM then you would need to find out which program's commands are executed first.

Edited by loverock125, 12 January 2012 - 01:16 AM.

• 0

### #18 jonathanz

jonathanz

GMC Member

• GMC Member
• 66 posts
• Version:Unknown

Posted 27 February 2012 - 08:46 PM

Cheat engine has been made to edit variables in games that DO have randomizers
Thus the anti randomizer function which would help for code injections.

What you wanna do is:

-When the game is paused varibles add a random number which is stored and minus off when unpaused (I say this because if the change is constant during the pause it will be very easy, for obvious reasons)

-Have two varible to represent one. Eg, money have coins and cents.. Once cents equals 100, it is sent to 0 and we then have a coin.
If the player doesnt know this is happening since the score will be reprensented visually as something different, we have our solution.

Edited by jonathanz, 27 February 2012 - 08:52 PM.

• 0

### #19 jonathanz

jonathanz

GMC Member

• GMC Member
• 66 posts
• Version:Unknown

Posted 20 March 2012 - 10:40 PM

Packing every step is not needed and wastes cpu. Every 5 steps is fine.. 5 times faster!
• 0

### #20 Primoz128

Primoz128

GMC Member

• GMC Member
• 278 posts
• Version:GM:Studio

Posted 29 April 2012 - 10:29 AM

How about you xor it then use the first post's method, then when unpacking use the anti method and then xor it.