AS3 Score Protection System
// December 7th, 2009 // Flash - AS3
In the past few weeks I’ve been working on a small game engine for flash. Well…I can’t say it is an actual game engine, but more like a collection of classes that make game development a lot easier. One of the first classes I made was a score system that protects the score from game hackers. I decided to release this for anyone that may want to use it.
If you are a flash game developer you may know that that there are a lot of gamers that simply hack the game and this way they can submit a very big score. This is done while the game is player just by modifying the value of the variable where the score is stored. That is why it is very important to protect it.
That is exactly why I made a small class that does exactly that. The “Score” class does not store the actual score, but it stores another value that is calculated every time the score is updated. This way the “hacker” does not know exactly for what value to search. Ok…but how does this make the score so that it can;t be modified from outside? The script has another security layer. This one more secure.
The score is also kept in another variable, end if the script detects that the actual score and the security variable don;t match, it detects that the score has been hacked. The trick is that the security variable is an array, and not an actual number. I won;t discuss how this is calculated or anything like that…
OK! But how do you use it? First of all download the script and extract them in the same folder as your game. After that import the score class:
import zone.Score;
Next you need to make a new variable that holds the score:
var score:Score = new Score(0); //0 is the initial score
To retrieve the score all you need to do is this:
score.getScore()
This returns the correct score IF the script does not detect any outside modifications. Otherwise it returns -9999. This is where you should verify the return value, and if it is -9999, make sure your game stops playing or something.
If you want to set a new score, just call this:
score.setScore(10) //10 is the new score. it can be any int value
I attached a FLA file that you should look over. It is really easy to keep the score in a secure way.
This small SWF file increments the score by 1 every time you press the button. If it detects that the score was modified from an outside source, it goes to the next frame where “Score hacked” is displayed.
[kml_flashembed publishmethod="static" fversion="9.0.0" movie="http://sf-zone.net/wp-content/uploads/2009/12/demo_score.swf" width="200" height="200" targetclass="flashmovie"]
[/kml_flashembed]
So,What are you waiting for? Download the class. Don’t forget to post a “thank you” if you find it useful. Also, this can be used to store any int variable that need to be protected (like ammo).
Leave a Reply
You must be logged in to post a comment.





