Archived

This topic is now archived and is closed to further replies.

Enokh

Using text files for variable storage, and an issue

Recommended Posts

Heya all. I'm working on a 2D space shooter project for my senior year in highschool, and I've grown to like using text files for various reasons. I have a ship statistics database (how fast each ship is, how hard it hits, etc) and it's all stored in a text file. So I can change how fast an X-Wing goes without recompliing the game, which to me is awesome since it'll make things alot easier later on for balancing reasons. My problem is that text files are awfully easy to edit, anyone can do it. Sure I can write to a file called ShipsDB.POO and it'll still work fine, but then anyone could just rename the file and change the values around so the Millenium Falcon kills everything in one shot. Is there a way to make it so my text files are not so easily opened and edited from Windows, but still contain readable information for my engine? If you got any solution, fire away, I'm open to try anything. Also, what's the right way to do it? How does Quake3 save information, apart from levels, models, sound effects and such. Real information, like how fast the player runs. Also, an unrelated question: If I'd like in my game to run another exe, but not through the system("AppName.exe") way, any suggestions? The reason I don't like system is that it leaves an ugly console window open. It's dos for god's sakes! [edited by - Enokh on October 7, 2003 3:34:33 PM]

Share this post


Link to post
Share on other sites
Well, you could use a very simple encryption method (like One Layer XOR Based Encryption). Of course, you''ll probably have to write a little tool that will encrypt all your data files for you - probably best to let your game open plaintext, or encrypted files. Develop with plaintext files, and then when you want to release, encrypt all the files with your tool, and switch your code to read encrypted files.

Another option is to package up the files in an archive file. You can use a standard zip file (just use an existing library to open the archive in your game code), and you can get it to encrypt the archive so people can''t just decompress it and start changing things. Again, let your code open either plaintext from the normal directory system, or files from the archive, and only bother building the archive when you want to release.

Or you could just let people mod your game - personally I think that''s the best option, but whatever.

John B

Share this post


Link to post
Share on other sites
How about some encryption? A simple substitution cipher would probably stop most people. Another way would be a checksum comparison (MD5 is an alternative) to detect if someone has changed anything.

Share this post


Link to post
Share on other sites
I, personally, don''t think it matters, as long as its not a network game. I wouldn''t do it because it takes all of the challenge out of the game (and therefore almost anyone who knows how to change it won''t).

Share this post


Link to post
Share on other sites
Thank you for the responses, they are most helpful! And now on to the questions =D

Correct me if I''m wrong but a checksum checks a float in bytes that I give it against the current size of the file, and if it doesn''t match, poop out of the game? That''s very nice, but wouldn''t it mean that I''d have to change the correct checksum value every time that I''d like to change something myself? I''d really love any links or additional information you could give me regarding the checksum route because it sounds the easiest, and practically unbreakable (not that I''m designing HL2 here, harhar).

PS: About modability, this isn''t exactly a commercial game which I expect to be known outside of my close knit of friends, regardless I do intend to make it fully moddable on all accounts though. Graphics, sounds, ship behavior, menus, everything.

Share this post


Link to post
Share on other sites
quote:
Original post by Enokh
How does Quake3 save information, apart from levels, models, sound effects and such. Real information, like how fast the player runs.


I''m not too how Q3 does it, but with Half-Life this stuff is actually coded into the game. The HL SDK contains the source code to the client and server dlls (not the engine itself), and this type of information is in the server dll. At a guess, Quake 3 uses something similar.

Share this post


Link to post
Share on other sites
Sorry for not replying sooner.

From MD5 Homepage (unofficial)
quote:
[The MD5 algorithm] takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA.

I didn''t quite understand what you meant by: "a checksum checks a float in bytes that I give it against the current size of the file". You compare finger prints and if they don''t match, you poop out, as you said. Perhaps thats what you meant? The link above has implementations for various languages and test suits. The "message" is a stream of bytes, in your case, the file. The output (message digest) is a 16 byte array of unsigned chars for a C/C++ implementation. Thats really all there is to it. If you are interested about the details, check the rfc.
quote:
but wouldn''t it mean that I''d have to change the correct checksum value every time that I''d like to change something myself

Yes... perhaps a bit cumbersome, but I don''t know if it would be any easier editing an encrypted file.

Share this post


Link to post
Share on other sites
Why don't you make it a byte code format rather than plain text? You would have to create an editor (easy to do with VB or using resources in C++) that you could use, and then when it saves to a file it saves it as a character representation of the number--ie, if the number was 59 the character in the text would be ';'. Or you could just read in the memory straight and spit it to file. No one would be able to read it except a program, and then you just make a seperate program to edit it. No need to change checksums, and if you want to let people mod it you release the editing tool.

[edited by - Erzengeldeslichtes on October 9, 2003 2:44:21 PM]

Share this post


Link to post
Share on other sites
How bout something like this?
You change your game so that it first looks for .TXT files, and if it can''t find them, it checks for .DAT instead.

You write a little utility that encrypts a TXT file into your own format (even something as simple as single XOR).
Create a batch file that converts all the TXT files into DATs (leaving the TXT files there)

So while you''re working on the game, you leave them in TXT form. Easy to change, no problems. When you want to "ship" the game,
you hit the batch file, it creates a bunch of encrypted versions of the text files, and you include those in the distribution instead of the DAT files.

So your developer version will see the TXT files and open those first, but since there are no TXT files in the distributed version, it loads the DATs, which are encrypted.

Share this post


Link to post
Share on other sites
quote:
Original post by TravisWells
How bout something like this?
You change your game so that it first looks for .TXT files, and if it can''t find them, it checks for .DAT instead.

You write a little utility that encrypts a TXT file into your own format (even something as simple as single XOR).
Create a batch file that converts all the TXT files into DATs (leaving the TXT files there)

So while you''re working on the game, you leave them in TXT form. Easy to change, no problems. When you want to "ship" the game,
you hit the batch file, it creates a bunch of encrypted versions of the text files, and you include those in the distribution instead of the DAT files.

So your developer version will see the TXT files and open those first, but since there are no TXT files in the distributed version, it loads the DATs, which are encrypted.


That is almost exactly what I do. I use regular txt files for my shooter while I''m developing, and when I release, I encrypt them with a little utility I wrote. It 1st looks for the .dat file, and if it doesn''t find it, it then looks for the .txt files. Works great.

You just have to write a little utility to encrypt your files. it''s easy, and kinda fun too. I wrote LoadFile and SaveFiles to encrypt and Decrypt. And, i think it''d be really tough to crack my stuff.

Share this post


Link to post
Share on other sites
quote:
It''s dos for god''s sakes!

If you''re talking about Windows then, no, it''s not DOS. DOS is an operating system, not a user interface. What you''re talking about is called the console or terminal.

Share this post


Link to post
Share on other sites