Qbasicnews.com

Full Version: Question about saving/loading binary files.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it binary? I don't know.

Anyway, I came up with a system for my adventure game which basicly loads a file according to scene, and from that file it reads : how many click boxes scene got, click boxes boundaries, what messages should be printed when you click on each click box, where the message should be printed and how long should it stay on the screen. I can also make more text message for the same
click box and within the code flag it for a specific situation(if
an object was picked up or similar).
It can all be done with a nice for loop and basicly one set of routines for all scenes minus the specifications for each scene related to object being picked up and similar.

Currently, I do all that within my programm and it's very memory consuming during compiling. My code is like 70 Kb long and I already need to split it.

Now, I can mask my files that hold all these information and messages with bogus names and extensions but I still don't want for people to be able to read the entire game messages or even alter them with the simple text editor.

So I'm wondering, can I save those files as binary or something like that and read all those variables and strings from them when the files are saved like that?

How do I do that?
Binary files don't actually output binary code (like 100110) so people could still easily modify the game, your best bet would be to make a simple encryption routine to encrypt the files, but why are you so worried about people modifying the game anyway? expecially if it's a QB project.
I don't know anything about encrypting.

Hmmm...maybe you are right. I just don't want for people who won't be able to finish the game to get nosey about the game files and start checking them out with text editors.
Encrypting? Easy.

Here's an easy one:
Code:
FUNCTION Encrypt$(char$)
   Encrypt$ = CHR$((ASC(char$) + 1) AND &HFF)
END FUNCTION

Here's a some harder one:
Code:
FUNCTION Encrypt$(char$)
   val = 0
   val1 = ASC(char$)
   FOR I = 7 TO 0 STEP -1
      IF val1 AND (2 ^ I) THEN val = val + 2 ^ (7 - I)
   NEXT I
   Encrypt$ = CHR$(val)
END FUNCTION

It's just messing around with the ASCII table or the binary structure
here's another encryption routine that will encrypt using a password
making it more secure, you can also use the same routine to decrypt a string, just run the encrypted string back thru the routine using the same password.

FUNCTION Enc$ (S$, Pass$)

FOR I = 1 TO LEN(S$)
J = J + 1
IF J = LEN(Pass$) + 1 THEN J = 1
Fin$ = Fin$ + CHR$(ASC(MID$(S$, I, 1)) XOR ASC(MID$(Pass$, J, 1)))
NEXT

Enc$ = Fin$

END FUNCTION
Uhm....right.

Lachie feels stupid
well here's a code sample using my function

Strng$ = "Hello"
PassWord$ = "10a10"

EncryptedString$ = Enc$(Strng$, PassWord$)
Print EncryptedString$

DecryptedString$ = Enc$(EncryptedString$, PassWord$)
Print DecryptedString$