Posted: 20th Jun 2007 8:41
The game I'm working on at the moment has a lot of media with it. I've painstakingly endeavoured to design all of it from scratch (particularly MP3s and .x's) and I want to make sure it doesn't get stolen. Thus, I want to encrypt it.

Now, I already know that DBPro comes with a feature that allows you to encrypt attached media and I would gladly use it. The problem is that I want to be able to provide extensions and add-ons to the game as well. If I encrypt the attached media and leave the game as an exe, how am I supposed to "add-on" to the game? Alternatively, if the media is left out of the exe (which makes add-ons easy), how can I keep it safe?

If you have an answer to these questions, or you can think of a different method of encryption, I'd really like to hear it.

PS, Please do not use the word "patch" in your answer
Posted: 20th Jun 2007 12:27
This is the code I use for protecting folders:
+ Code Snippet
if file exist("Data") then delete file "Data" `<---name of file to place your media folder into 
open to write 1,"Data"  
write dirblock 1,"Media" `<---folder you want to protect
close file 1


Then use this code open files within the protected file:
+ Code Snippet
open to read 1,"Data"
read dirblock 1,"Media"
close file 1

`````loading commands here!``````

if path exist("Media") then delete directory "Media"


To add new files or replace files within the protected file, I guess you should make a program to extract the protected folder then add or replace files within then protect it again.

Edit: Made some changes.
Posted: 20th Jun 2007 12:44
Yeah, but that will prevent ordinary users from accessing your media files. Well that's the simplest thing I can think of.
Posted: 20th Jun 2007 13:08
Yeah it's not encryption but it's better than leaving a folder full of .x files. I probably be happy with making the files not loadable into their native design app as my experience of encryption is that it is sloooooow.
Posted: 20th Jun 2007 15:16
You could try the attached dba program. It won't deter serious code crackers but will deter the vast majority of people.

Just place your media file in the same directory as the program. Then run the program and enter the filename (including extension) and press another key to exit. When the program has finished, you should have two new files: the encrypted file and the new un-encrypted file (which should be the same as the original un-encrypted file, of course).

I've just tested this and it took 70 secs to encrypt a 12.5 megabyte .bmp file.

I'm sure the code could be re-written to make it faster - but this should be fast enough for most purposes.

Edit

Oops! Sorry - forgot to save the latest dba file before posting. Here's the correct version attached (I hope).
Posted: 20th Jun 2007 16:48
Take a look at this:
http://www.molebox.com/
Well, it does cost money, but i think it's worth as an additional protection to your media...
Posted: 22nd Jun 2007 9:54
Thankx for all your ideas guys, I didn't know about the dirblock cammand and my friend tells me that it is "seriously cool". As for encryption programs, thats all well and good but your forgetting that DBP has to be able to read the file in-game, which means that it has to have a plug-in or something similar to de-crypt the media and read it. I know I won't be able to stop everyone from getting at my media but I want some sort of deterant (like yaarj suggested) to stop people stealing the media without a fight. Any other ideas besides these?

P.S, Don't suggest encryption algorithms for saves and other txt files, those are easy to encrypt.
Posted: 1st Aug 2007 12:49
There is an excellent project in the WIP board called "GameCrypt" it opens files in DBP and encrypts them. I heard you can use it to encrypt media but maybe I am wrong. If you want to try it out search "GameCrypt" or look through the WIP board.

Cheers,
Kieran Wood
Posted: 1st Aug 2007 19:05
I believe that the expansion pack (http://darkbasicpro.thegamecreators.com/?f=enhancementpack) has zip (fileblock) commands that can incorporate password-encrypted zip files. Then you should be able to use 'LOAD OBJECT FROM BLOCK' or a similar command to load media directly from the encrypted zip file without ever extracting it onto the hard drive.

-Xol
Posted: 1st Aug 2007 22:25
How about using load array to load a file, decrypt it, and then using the make memblock from array command (I think that's what it's called) to turn it into a memblock, and then using make image from memblock to turn the media into an image.

Probably slow, but just an idea.
Posted: 2nd Aug 2007 3:32
At the moment I'm working on an application for FPSC that automatically handles decryption without modifying the source. What I'm doing is taking control of file I/O at a low level to allow me to implement automatic decryption and caching (both operations in memory). In my experimentation I have image loading working fine, but before I get other types of media loading working I'm doing more research into less fiddly ways of attaching my 'virtual file system' as I call it.

Although it's being designed for FPSC it'll work fine with DBP EXEs, so when it gets done it's another tool in the box that you can use. We'll have to wait to see how it turns out...