Wondering how to stop errors..
Author |
Message |
TokenHerbz

|
Posted: Tue Apr 11, 2006 6:23 pm Post subject: Wondering how to stop errors.. |
|
|
Hi, i am wondering if it is possible to read a file, and if the values are wrong for the variable, to set a default, without crashing the game.
Perhaps instead of causeing an error, it will call a proc "new game" (in my RPG)
Let me elaberate on what the problem really is.
In my game you can save/load, or new game. When you save the variables are encrypted and stored into a .txt file. When i load, the .txt file is read, then uncrypted, and used for the variables values.
If someone changes the .txt file, then the values used are incorrect, which cause error's etc: Im wondering how i can avoid the errors, and instead call the new_game, with a message of ("Canno't load game")...
I would appriciate only intellegent reply's, nothing like, YOU CANT DO THAT IN TURING, unless Cervantes or another intellegent person says, to which i will believe them.
Thanks for the help to come  |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Cervantes

|
Posted: Tue Apr 11, 2006 6:48 pm Post subject: (No subject) |
|
|
With whatever encryption method you're using, have the decrypt function return a special value if it realizes that the input has been mucked up.
If this special flag is not returned, you should be good. However, there is always the off chance that the input was changed in just the way that it still makes sense but the message is different. This might lead to your party being placed in front of a dragon at level 3. Who's to say if that's a bad thing?  |
|
|
|
|
 |
TokenHerbz

|
Posted: Tue Apr 11, 2006 7:12 pm Post subject: (No subject) |
|
|
me
I just want it so that if the file is modified at all, it will make them start a new game, other wise it will load... I don't need really anthing else more or less, and i don't get what you mean: "have the decrypt function return a special value if it realizes that the input has been mucked up. "
Also, how do i check a faulty variable without useing it? |
|
|
|
|
 |
Cervantes

|
Posted: Tue Apr 11, 2006 7:33 pm Post subject: (No subject) |
|
|
I'm assuming that your encryption is such that as you decrypt it, you can tell if something is wrong. I leave it up to you to figure out how to do that.
For example: if your encryption is to turn everything into binary, then you can very easily tell if something is wrong when you see a "2".
However, a "0" could have been turned into a "1" by some malicious user. This you couldn't catch, until you go through and decode your data file and find that your party's location in the x plane is at "q", "^", or "\t". That's when you have to use things like strintok. |
|
|
|
|
 |
Delos

|
Posted: Tue Apr 11, 2006 7:43 pm Post subject: (No subject) |
|
|
Possibly the best solution would be to use a CRC checksum on the file. This is a little laborious though, and does require a little indepth knowledge into bitwise operators and XOR'ing...(do a wiki search if you're interested).
Your safest bet is to use very strong encryption. There have recently been ideas floating around of sticking in buffer space into your encrypted file so that you bulk it up a bit. This will also confuse any potential cheaters since the values they change may end up being redundant, unused segments.
Other tricks include:
- if you have a series of integers (HP, Mana, etc) simply include a number somewhere in there that has sumed them all up and performed some mathematical operation (e.g., (Sum(X) + 5) * 2)) and have a check to ensure that the values match.
- be tricky. Store your save files in files that are not apparently meant to be for saving...and have dummy files in place of them too. So, put the real data into "dialogue05.dat" and the dummy into "chara1.sav".
There are others, see what you can do with these though. |
|
|
|
|
 |
Bored

|
Posted: Tue Apr 11, 2006 9:15 pm Post subject: (No subject) |
|
|
Rather then looking at this from the programming perspective I'm gonna look at this the simple way. Firstly if values are not going to change such as default settings and such you can allways just open up the file properties and click read only. Then if you want to hide it from the user, regardless of wether the values need to change, you can click the Hidden box. you may be thinking what if I .zip it, well I know for atlest zips (haven't tested rar's, etc.) the file will still be hidden when you extract it. Like the rest of the suggestions this is still not fool proof but is another thing you can do to help. Also if your not already try using read and write as it's much harder to decode a binary file and alter it the way you want. |
|
|
|
|
 |
Delos

|
Posted: Tue Apr 11, 2006 10:03 pm Post subject: (No subject) |
|
|
Bored wrote: you can allways just open up the file properties and click read only. Then if you want to hide it from the user, regardless of wether the values need to change, you can click the Hidden box.
Not a bad idea and in a parallel-thought process sort of way. However, the big problem will be met when people package their programmes into Setup files. Sure there's some great software out there (I use Inno) that allows you to actually set files as hidden/read only etc - but is this really the approach you'd want to take.
Technically, if you have a read-only file, your programme shouldn't be able to change it! So even if these are global settings, there are likely to be instances when the User would like to change some of those.
It's not a bad idea thinking about problems locally and targetting just that issue, but a holistic approach is to think generally and critically. The aim of problem solving is only half to solve the problem at hand, and the other half to gain the insight to solve later problems. There's far more on this topic to be said than I'll say here, so I'll leave it at that. |
|
|
|
|
 |
|
|