Problems with TeraPak

Blitz3D Forums/Blitz3D Beginners Area/Problems with TeraPak

GrayKnight2k(Posted 2007) [#1]
Hello,

I was finding TeraPak (located in the Toolbox) to be very useful for packing my data and then I ran into a bug when I wanted to pak images I've loaded using "LoadAnimImage." It says "too many parameters." Does this mean TeraPak won't support the LoadAnimImage function?

Thanks. -Gk2k


JazzieB(Posted 2007) [#2]
Should work just fine. Here's an example line of code from one of my own projects.

Global cast=LoadAnimImage(pak("gfx\cast.png"),32,32,0,char_fr)

Maybe you've just got too many parameters in your LoadAnimImage call, or a bracket in the wrong place.


GrayKnight2k(Posted 2007) [#3]
This is great, thanks JazzieB. I remember you from another site I used to utilize back in the day. Good to see you again.

Do you (or anyone else) happen to know how to effectively protect text files holding player data? I want to Pak those as well, of course I am running into some big errors when I try and there doesn't seem to be any examples in the Pak program folder.


JazzieB(Posted 2007) [#4]
I didn't think that you could pack files from within your running app/game, which may explain why you can't find any examples of how to do this. I could be wrong though, as I don't use Blitz3D nor TeraPak these days at all ... moved on to BlitzMax.

In terms of protecting player profiles, etc, I generally come up with a way of generating a random key for encrypting the parts of the file that you don't want people altering. This key is used in SeedRnd() before starting to encrypt the file. I then XOR a randomised value to encrypt the data and the next value is also random (so that I'm not using the same number to encrypt all the data). You could generate a key from the ASCII values of their name for example. Just remember never to store the key in the file itself. If a player then decides to alter some portion of the file in NotePad, a different key is generated at load time and they've currupted their profile.

Obviously you will also need to have some way of checking that they have done this, otherwise your game will probably crash. The way I've done this in my current project is to store a random value for each level passed. When a profile is loaded the program goes through each of the values in the profile and compares these with a newly calculated one. As soon as one doesn't match it limits the level selection to any up to this point, even if those following are valid! Serves them right to mess with the file.

As a side note, I only use text files for player profiles and configuration settings. Level files are always stored as binary files in order to keep the size down. I'm guessing you probably already do something similar anyway, but thought I'd mention it.

Hope that sort of helps.


IPete2(Posted 2007) [#5]
Jazzie,
Im sure you are correct - Gray - you will have to create your own encrypt proggie, or find one in the archives.

IPete2


GrayKnight2k(Posted 2007) [#6]
Thanks for your responses, Jazzie & IPete2. One more question for good measure regarding a recent problem: Any idea why I get an error when I try to "Midhandle" an image I just unpak'd? And is there a way around this? Thanks again.


JazzieB(Posted 2007) [#7]
What's the error?

There shouldn't be anything specific to unpacking it, so I would just check if the file has loaded before setting a mid handle or doing anything other with the image before starting the game proper.


GrayKnight2k(Posted 2007) [#8]
The Runtime Error: Image does not exist

Code sample:

Graphics 640, 480, 0, 0
SetBuffer BackBuffer()

Include "include/bones.bb"

Global Splash = LoadImage(Pak("graphics/field/splash.png"))

While Not KeyHit(1)

DrawBlock Splash, 0,0

Flip
Cls
Wend
End


GrayKnight2k(Posted 2007) [#9]
New development: Is this the error?---

I just did a test with only one sub-folder: graphics/splash.png instead of the extra sub-folder...It works. Can terapak only go one sub-folder deep?


GrayKnight2k(Posted 2007) [#10]
Another subtlety: (this is going to make me feel really stupid if this was it): I've been loading with a forward slash instead of a backslash...Is that it?

Example: "graphics/field/splash.png" OR "graphics\field\splash.png" ????


GrayKnight2k(Posted 2007) [#11]
Wow...I think that was it.... O.o


GrayKnight2k(Posted 2007) [#12]
Ok, I have in fact confirmed this was the problem - the simple difference of using the "\" instead of "/". It seems as though while blitz3d allows you to do either, TeraPak only recognizes "\" - let that be a warning to other n00bs like myself.

All of my extra-post ranting aside -- JazzieB: you mind sending me an example of your data file protection? Implementing my own encryption method for text file player data handling is beyond my ability.

e-mail: arenzjoh@...


JazzieB(Posted 2007) [#13]
Hi, I won't be able to send you anything for a few days, as I will be away from my PC. My text file protection is actually in BlitzMax, but the principle will be the same. I might be able to come up with something, but it would be useful to know what type of information you want to protect.


GrayKnight2k(Posted 2007) [#14]
Hi JazzieB,

I would like to protect my "player.dat" file. The values consist of "name", <score> (which can be more than one integer), and a list of 1's and 0's in the following format:
1
0
0
1
0
0
...and so forth

The 1's and 0's indicate whether a player has an item or not. As you can see, it would be extremely easy to hack into the file and give the player everything. I need to protect this data. I have terapak set up to only unpak and then remove these files at certain points in the game, but any user can alt-tab out at certain times to copy the file. So this method is better than nothing, but still makes it far too vulnerable. Any suggestions are appreciated. Thanks for your time and interest in helping me.

Thanks,
-Gk2k


JazzieB(Posted 2007) [#15]
OK, here's very simple example of how to stop someone adding items they don't have to their inventory.



Basically, it generates a seed (key) for use with the random number generator, which is based on the ASCII values of each of the charatcers in the player's name. This is then multiplied by 1000 so that similar names don't generate similar keys.

When the program goes to save the profile it generates a random number for each item in the profile, regardless of whether the player has it or not. If the player does have the item, then this random number is stored instead of a simple 1. 0 is still used to say when an item is not in the player's inventory.

When the profile is loaded again, it gets the player's name from the profile and generates the same seed for the random number generator. When loading the items a check code is randomly generated for each item. If the value from the file is 0, the player doesn't have the item, so there's no problem. However, if the two values don't match, then the player has tried to add the item in NotePad (or similar) by guessing a random number and changing one of the 0's. The player is then not given the item and a flag is set to say that an attempt to cheat has been made. Otherwise, the player is given the item.

Things to note are that the cheating player could guess the correct value to put into the profile, so it's best to use a wide a range of randum numbers as possible to make this more unlikely (values between 1000 and 2000 were used above).

Also, this method will not prevent someone from removing items from a profile, which they might do with a friend's profile, for example. Something a little more complicated would be required, as you couldn't just XOR the encryption value with the item flag as a player would easily figure out that they would only need to change the value in the file by 1 to add or remove items from their inventory.

You might also want to include a player's score or other value that changes as they play when generating the key, so that the key itself changes over time, rather then remain static as this example does. If a player then tries to alter their score, they will end up with no items in their inventory as none of the values will match when it's loaded back in!

Hope that sort of points you in the right direction.


GrayKnight2k(Posted 2007) [#16]
JazzieB,

Thanks so much for the code and detailed explanation. This helps me a lot. Much appreciated.

Gk2k