In Part 1 we looked at the main methods of saving data onto the hard drive. However, these methods can be easily hacked into. Look at our INI file from earlier:

[Details]
XPos = 323
YPos = 67
PlayerName = "Bill"
Score = 2301

[Items]
MagicGobletFound = 0
ExplodingCowFound = 1
CrystalsHeld = 7

[Story]
TalkedToSusan = 1
AcceptedFrog = 0

It wouldn't be difficult for someone to edit the file and change the Score to 99999, or change the X and Y positions to avoid getting lost in a maze. So, if you want a successful saving system, you have to protect the data. This article focuses on the easy method of data protection - you just have to use your brain.

Name Randomization

Right. Before you do anything, launch Notepad or Word or get a pen and paper, because you're going to have to write a lot of stuff down. This is the easiest method of data protection to pull off, and can also be the most effective.

Above is a neat, tidy, and well-organized INI file. Perfect for hackers. So open Notepad, and change the names into whatever you want them to be! Lets look at the Details group before and after:

[Details]
XPos = 323
YPos = 67
PlayerName = "Bill"
Score = 2301

[Group1]
Item1 = 323
Item2 = 67
Item3 = "Bill"
Item4 = 2301

Which is more secure? Group1, of course. Looking at it now you wouldn't tell if Item2 was the Y Position, the Score, the number of CrystalsHeld, or whatever. Now, go into Notepad, and write a conversion table:

Item1 = XPos
Item2 = YPos
Item3 = PlayerName
Item4 = Score

This is only an example of what to do - you could do it in Excel for easy sorting, for example.

Another idea is to do away with the groups:

[MyGame]
Item1 = 323
Item2 = 67
Item3 = "Bill"
Item4 = 2301
Item5 = 0
Item6 = 1
Item7 = 7
Item8 = 1
Item9 = 0

What the hell does that mean!? If you didn't have the conversion table, you wouldn't know. It's also a good idea to mix the items up a bit - Score could go in between the X and Y positions, for example, and the AcceptedFrog flag could go at the top.

More Randomization

The ExplodingCowFound flag, or Item6 as we'll call it now, is either 0 or 1. But what if it was 37 or 614 instead? You can create further garbage with this. Lets see our conversion table:

Item1 = AcceptedFrog (46 is no, 6 is yes)
Item2 = TalkedToSusan (2 is no, 55 is yes)
Item3 = YPos
Item4 = PlayerName
Item5 = ExplodingCowFound (37 is no, 614 is yes)
Item6 = Score
Item7 = XPos
Item8 = MagicGobletFound (789 is no, 82 is yes)
Item9 = CrystalsHeld

To this, you might say "But how will I ever remember all that?" Remember - you have the conversion table. If you find Item2 is suddenly set to 55 in your game, you can do a search for Item2, and find out this is set when you meed Susan.

Creating dummy values

So, until now, all the values have pointed to something. Our INI looks like

Item1 = 46
Item2 = 55
Item3 = 67
Item4 = "Bill"
Item5 = 614
Item6 = 2301
Item7 = 323
Item8 = 789
Item9 = 7

And the conversion table is above. Why not add some dummy values in?

Item1 = 46
Item2 = 87
Item3 = 55
Item4 = 67
Item5 = "Bill"
Item6 = 614
Item7 = 2301
Item8 = "Name"
Item9 = 323
Item10 = 789
Item11 = 23
Item12 = 7

Which is now completely garbled. Item2, Item8 and Item11 are all dummy values that do nothing. The hacker may think he's changed a good value, when it actually does nothing. Remember to update the conversion table!

Catchig hackers out

Right, now for some coding! Add a 'Loading' level at the start of your game, and in it check whether any of the values have been tampered with. Just do a:

* If Item 2 is different from 87:
- End the application

Or, if you want to check if any flags have been changed:

* If Item8 is different from 789
If Item8 is different from 82
- End the application.

One more method

Don't make it a .ini file. Call it something like game234.dll. It won't do anything as a .dll, but it still holds your game's data OK.


Well, that took me ages to write. You don't have to follow everything in this article, just enough to make you feel safe. Now, be good and remember to do your conversion tables, while I go and write part 3 about Encryption.

Shen



Before:
[Details]
XPos = 323
YPos = 67
PlayerName = "Bill"
Score = 2301

[Items]
MagicGobletFound = 0
ExplodingCowFound = 1
CrystalsHeld = 7

[Story]
TalkedToSusan = 1
AcceptedFrog = 0

After:
Item1 = 46
Item2 = 87
Item3 = 55
Item4 = 67
Item5 = "Bill"
Item6 = 614
Item7 = 2301
Item8 = "Name"
Item9 = 323
Item10 = 789
Item11 = 23
Item12 = 7