Jump to content
  • Advertisement
Sign in to follow this  
Bolthame

A good file type to use?

This topic is 4025 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I was wondering, is there a file type that a simple file I/O line or two could edit, but a use couldn't? I've been using text files for game saves so far but the people who play my games just edit the saves and get ubered in the game. Thanks for your help :D

Share this post


Link to post
Share on other sites
Advertisement
Depending on the technicality of your users, you could just add in a checksum for the file. That way your game can recalculate the checksum and store it, but your users can't - unless they reverse engineer the checksum method. That way you can also leave text files for your own ease-of-use, since you can use your own program to ignore the checksum in debug mode, say.

Share this post


Link to post
Share on other sites
You can roll your own binary format, but be aware that some users will eventually figure out how to edit it anyway by experimenting with the hex values. One really simple (simple to implement, simple to crack) thing you could do is have your program zip up the save game file and store it with some strange extension, like ".dat", but this is security by obscurity, which isn't worth much. You could also opt for one of the binary XML formats, but you'd have to find a parser that supports them. You could also encrypt the save file, either with a full-blown symmetric-key encryption algorithm or with something really simple like XOR.

Share this post


Link to post
Share on other sites
File types are windows type of thing without saving with the .txt extension it is still the same file. As baldurk pointed out a checksum is probably the best and easiest way, although you could:
write in binary mode
write in binary with an offset to the start.
hide it in a bitmap or something similar.
use huffman where your application knows or has access to the frequency table.
use huffman and store the frequency in the file much like a zip.

the strangest way I have seen someone do it is adding the ".exe" extension to the file which was just a plain text file.

Share this post


Link to post
Share on other sites
Heh, I forgot to mention I've only been programming for a few months now..

Also, the I/O will be working with ints, chars, and possibly floats, and will be writing to and from arrays, will this effect any of your suggestions?

I was thinking of using a Steagonos (or however you spell it) Locknote file, but I don't know the file extension nor how to set a password using a program.

Any thoughts on this?

Oh, and I feel embarassed asking this, but what's a checksum?

Share this post


Link to post
Share on other sites
Make sure you're not using a more complex solution than you need to - KISS :). If all you want is to make sure most average gamers can't edit the file very easily, a checksum or writing everything in a binary format might be the way to go. Although it's not complicated per se, reading and writing binary files does come with a whole new set of things to keep track of, and it might be just as easy to ignore that for now.

I'd say that almost certainly trying to figure out or implement some kind of complex encryption or compression is too much for your needs.

Also remember that no matter what you do, someone will figure out how to edit the file - all you can do is make it harder for them.

For the checksum you just do something as simple as summing all the values you store, multiplying by some prime and then taking the modulus vs. some other prime. Say: checksum = (sum_of_data * 102983) % 1879; [note: I don't promise this is a good checksum]

This means that for any given input, you get a single number that represents it. The number might not be unique (ie. two different inputs might give the same checksum), but generally you don't have to worry about that too much.

Then when you're writing you store the correct checksum, and when you're reading you read in the checksum for the file. You then calculate what the checksum *should* be for the data you just read in, and compare it with what you read in. if they are different, the file probably hasn't been modified by someone else. If they are, the file has been tampered with.

The limitation obviously is that someone might figure out the checksumming method, and recalculate it themselves.

Also, if this game isn't to be played online, how much do you really care that people cheat? If it *is* played online then you shouldn't be letting them store any important information :).

Share this post


Link to post
Share on other sites
Quote:
Original post by baldurk
Also, if this game isn't to be played online, how much do you really care that people cheat? If it *is* played online then you shouldn't be letting them store any important information :).


Heh, I'm flattered that you think it could be an online game, but alas, it's just a text based game that runs in DOS, hahaha.

Would saving it without a file extension work? 'Cause then it would just be a File and a user wouldn't be able to open it, but would the program still be able to I/O from it?

Share this post


Link to post
Share on other sites
Bolthame, you seem to be a bit confused about the nature of files. Changing the extension is certainly possible and no problem at all - both the user and the program still won't have any problem whatsoever reading the file. The extension is just there to give a hint about what the file possibly contains.

Share this post


Link to post
Share on other sites
Eh, sorry, I've only been learning to program for a month or so and file I/O is new to me, and so is most knowledge about files. Embarassingly so, I've been taking how files work for granted :(

Also, to save making a new thread, I'll ask some more questions in this one:

1: How can I get cin (or something that works the same) to work with spaces?
2: How can I have a program I/O to the clipboard?

Thanks for your help :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!