Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Asset Encryption - Text files - How to handle?

Author
Message
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 15th Jan 2021 12:10
Hi All,

Does anyone know how to turn a memblock into a text file without writing that text file to disk? Ie So it can be read normally as if using OpenToRead(FileName$)

I'm looking into asset encryption for my game (it's getting closer!). I have code (thanks to BatVink) that enables my to encrypt and decrypt files. When the game runs, I can decrypt an encrypted image file to a memblock and then use CreateImageFromMemblock and subsequently access the image via the resulting file ID directly in my game (I think - not actually done it yet). Looks like I can do the same for sounds using CreateSoundFromMemblock. But... how do I do the same for text files? Currently my game loads up maps etc by opening a text file that is read line at a time using tokens to get the relevant info out. I don't want to use CreateFileFromMemblock as I don't want the unencrypted data files being written to disk - I just want the file to reside in the game memory (similar to the CreateImageFromMemblock command).

Any clues?

David
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 16th Jan 2021 01:25 Edited at: 16th Jan 2021 03:56
I modified BatVinks functions to encrypt/decrypt a text file
This will ONLY work with a CRLF delimited file
Note that these functions return and use a type rather than an integer to manage the encrypted file;

Functions are as follows,

/*******************************************************************************************************************************
Text Crypt File Functions

filename - The file containing the encrypted image
key - The key used to decrypt the file
CryptFile(source, destination, key)
OpenCryptFile()
CloseCryptFile()
GetCryptFileEOF()
ReadCryptFileLine()

*******************************************************************************************************************************/

PLEASE TEST IT THOUROUGHLY BEFORE YOU USE IT

Attachments

Login to view attachments
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 16th Jan 2021 09:32
Great! Let me take a look!!! Fingers crossed this is going to take away a major headache!
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 16th Jan 2021 10:20
When I test it with a text file generated by my code or a new one created in Notepad, it appears to strip the first character on each line after the first. First line is fine but all others are missing their first character.

Try a file with no spaces at the start of the second onwards lines...
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 16th Jan 2021 19:58 Edited at: 16th Jan 2021 19:58
My bad.
Change line 87 from
if c = 0x0a
to
if c = 0x0d
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 18th Jan 2021 09:25
Thanks! Will give that a whirl! Love looking at other people's code - you can learn so much. From little things like you can use a single / as a remstart to bigger things. Another thing I've learned is.... you're a far more advanced coder than me! Ha ha! Can't even figure out how it's all working yet!!
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 21st Jan 2021 14:34 Edited at: 21st Jan 2021 14:35
Quote: "you can use a single / as a remstart"

No you can't. A single / is a division.
But you can use /* as a remstart and */ as a remend
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 21st Jan 2021 15:29
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Jan 2021 20:57
Did it work?
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 22nd Jan 2021 12:25
Sorry - Yes! Wish I could code like that! I've tried it on one of my map files and it looks to produce identical files. I've not integrated into the game as that requires quite a bit of re-work (I was convinced when I set out that general encryption would be sorted by the time I came to need it!).

Thanks again - really appreciate the help. I feel a key coming on
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 23rd Jan 2021 01:46
Great! and good luck with your excellent game
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th Jan 2021 02:58
DavidAGK,

Quote: "
But... how do I do the same for text files? Currently my game loads up maps etc by opening a text file that is read line at a time using tokens to get the relevant info out. I don't want to use CreateFileFromMemblock as I don't want the unencrypted data files being written to disk - I just want the file to reside in the game memory (similar to the CreateImageFromMemblock command).
"


Just out of curiosity, can you post some examples of what data your trying to hide? If it's just a big tile map array in a text file, then embedding some run length or common parse compression will keep most sticky noses out. A well selected approach can reduce the input file size to a fraction also.



PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 25th Jan 2021 08:09
Hi Kevin,

For the text files, they are all "token" separated files (ie CSV except I use multiple different separators (not just commas) for more dev legibility).

Not sure I understand the rest of your message!



blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 25th Jan 2021 20:26
I think the effort in creating the compression could be better spent elsewhere. Finish that game!!

Login to post a reply

Server time is: 2024-04-16 17:04:56
Your offset time is: 2024-04-16 17:04:56