DaBooda Turbo v1.4 - Tutorial E |
Protect ThySelf (Resource Class) |
Andrew "DaBooda" Stickney |
August 12, 2004 |
Ok, we have worked on a program for hours upon hours, now we will release it to the public for them to enjoy. But wait, out there hiding in the deepest darkest corners of the World Wide Web, are losers, who do not wan't to put the time and effort into making their own resources. So guess what, you notice a game with very similar graphics or music as yours, guess what, yes you have been robbed of your work. This happens alot, I see it all the time, so a fellow contributor pointed it out to me, that this engine was in serious need of a way to put your resources into one file and encrypt them. Well this is how the resource class came to be, with this class, you can compile any file of any type and password protect it. This will keep those pesky lazy programmers away from your work.
You may have noticed there is no program with this tutorial. This is because I could not figure out how to demonstrate this class, but I will break down all the commands and explain them as well as show how one would use them. Lets get into this thing...
A Quick Note On AutoLoading... |
Before getting into this class, I just wanted to let you know that this class does not auto load resources, for it is strictly just for handling files. The reason for this is, when you load a file into the engine, there are alot of specifics that go into it, like format and such. I will work on an auto loading routine for this engine, but as of now you still have to manually load files into the class. This may seem like your files will be open to the public while the engine loads them, but believe it or not it is such a quick process, that the user will not have time to even copy one.
Setting a Folder |
For the resource class to work, it must have a folder to find and add files too. You can ignore this command and use full path names if you wish, but I do warn you that file names can only be 16 characters in length, so therefore setting a folder path is wiser. This is because the compiling of a binary file has to be pretty specific on size, there is no way around this.
Entering a PassWord |
This is probably the most important command in the class, this is what is used to encrypt the file. Just look at this as a key to the Resource File, for it locks and unlocks it... so the same password must be used for both extracting and combining a resource class, otherwise you will not be able to open it. What this one word does is actually encrypt the header information, and without that information the user does not know where the files end or begin, basically rendering the entire file useless. Just remember this can only be 16 characters in length and it has to be entered befor extracting or combining a resource file.
Adding and Removing Files. |
For this class to know what to combine, one must first add a file to it. Just remember the name of the file can only be 16 characters in length. When the ExtractFromResourceFile command is used you will then also have files listed in the resource class.
Extracting and Combining. |
To combine a file is to actually take all the files within the class and combine them into one binary file, and then to encrypt it with the password. To extract does the opposite. Pretty easy, just remember to use the same password for each operation. There really doesn't seem to be anything to this class, and you are right, for a lot of stuff goes on behind the scenes, isn't programming great.
What In The World Is A JunkFile... |
A junk file is simply a file of nothing but random bytes. When your resource file gets encrypted, only the header info is encrypted, for it would take forever to do an entire file. But a clever programmer can do some backwards reading of your file and eventually come to something readable. But you can create junk files with the command, and add those to your resource file, this way the hacker is looking at a bunch of unreadable data, this will throw them off.
A Quick Example... |
Ok, I am going to run down a quick example on how one would use this class within the Engine.
'combine resources With TEngine.DBResource .SetFolderPath Path .EnterPassword Pass .CreateJunkFile JunkFileName, Length .AddFile File1 .AddFile File2 .AddFile JunkFileName .CombineResourceFile ResourceFileName End With |
First before we have to Create a Resource File, like above. This can either be done within the same program or another program. All you need to know that a resource file only has to be created one time, after that you just use the below method to extract all the files.
'Extract resources With TEngine.DBResource .SetFolderPath Path .EnterPassword Pass .ExtractFromResourceFile ResourceFileName End With 'Load in all your resources into the Engine 'Kill the files With TEngine.DBResource .KillFiles End With |
This is how you would set up your program to extract all the files from you resource file. Notice that you can then load all the files into the engine, like you normally would. After you do that you can then use the killFiles comamnd to delete all the files. Note that the kill files command does just that, you cannot even recover them from the recycle bin, this is permanent, so only use when you have a resource file already made, and yes you can choose when to use this. If you only wish to delete some files, then you will have to use a remove command to remove the file from the class before using this command.
This is all there is to saving and protecting your files...
One Fatal Flaw... |
Maybe Fatal is to strong of a word, but there is one file that cannot be put into a resource file and loaded, then killed. This is music files, for some reason when you load music into the music class, then the file is considered copy protected and will not let the engine delete it. This is because the media player reads music from the disk, not memory, so there fore it needs it to stay. There is a work around for this, and it is a little complicated, but you can extract from a resource file, then manually copy the music file, there is a command for this. Then just load the copy, and kill the copy when the program is about to end... this is the only way, as for the rest it will go into memory and you can kill it after loading it. There is no other way around this, sorry.
One Last Note... |
Although the original purpose behind this was to actually just keep textures, and sounds and such. But you can use this class to hold any file you wish, the good thing about this is for game data. For example you are programming a rpg, and the player actually hacks into the data, and changes it. Well the resource class actually checks validity of the file, and if the size changed it will be corrupt and unloadable, this will keep cheaters at bay.
This wraps it up for the resource class, I hope I covered everthing and there are a few commands I left out, but they are there just to retrieve information. This class is really easy, but please be careful with that kill command, make backups or something before using this....
And this wraps up the tutorials for v1.4, believe it or not, after this and the older ones, there is know reason why you shouldn't be able to create a game... lets get it going, I want to see what this engine can do, open it up and turn it on!!
For anymore questions please email me at masterbooda@yahoo.com ... And please ask me anything...