2014-11-20 06:31:51

Hi all,
I'm just wondering if it is possible to do this? The Encryption functions themselves in BGT only allow for files, but I'd just love to encrypt my whole directory so that people can't get at sounds, music etc. Although, I know some people have decrypted stuff made with BGT sadly. I lost it when I formatted my Mac but the Parilous Hearts music and sounds were floating around.

2014-11-20 07:06:34 (edited by CAE_Jones 2014-11-20 07:07:13)

Sure.
One could encrypt each file individually, or could encrypt them after packing them.
(IIRC, the encryption scheme changed after the Perilous Hearts demo, but I'm not sure about that. I think it changed at one point to something more secure.)


Here's an example. I'm literally just adding one line to my pack_all example:

// Pack all files in a certain directory, recursive.
// This probably needs to be in its own script; pack everything separately from the game, otherwise it will do weird things when someone tries to play it.

// Both parameters here have a default value, so you can just call pack_all().close() and that's everything. You might try pack_all("sounds") if you only want the sounds folder, for example.

pack_file@ pack_all(string top="", pack_file@ ret=null) {
 if(@ret==null) {
  pack_file temp;
  @ret=temp;
  ret.create("sounds.dat");
 }

// Formatting:
if((top!="")&&(string_right(top, 1)!="/")&&(string_right(top, 1)!="\\")) {
 top += "/";
 }
string[] dirs=find_directories(top + "*");
string[] files=find_files(top + "*");

for(uint i=0; i<files.length(); i++) {
ret.add_file(top + files[i], top + files[i]); // The filename in the pack matches the filename on the system.
}

 for(uint i=0; i<dirs.length(); i++) {
 @ret=pack_all(top + dirs[i], ret); // Since ret is a handle, we shouldn't need to save it, but if this doesn't work, try adding @ret= to the start of this line.
}

return ret;
}


void main() {
// Example, packing everything in ./sounds
pack_all("sounds/").close();
file_encrypt("sounds.dat", "sounds2.dat", "best encryption key ever!");
}

If you wanted to encrypt something other than sounds, and use a file other than sounds.dat, you might do something like this:

pack_file temp;
pack_file@ pack=temp; // Just because we'll be passing it around to functions.
pack.create("data.temp"); // It's a temp because we're going to encrypt it.
pack_all("", pack);
pack.close();
file_encrypt("data.temp", "data.dat", "super awesome key of safety+4");


To use the pack later, you'd need to decrypt it first, though, which could be a problem.
An alternative would be to encrypt all your files separately, then pack the encrypted files. You'd need something like the pack_all function to do this, just encrypting instead of packing. The advantage to changing it to work that way would be that you could access the files more easily without the security risk of unpacking everything where a cheater might find it.
That, and the sound engine allows you to use a pack and set an encryption key, but IIUC it only works if the files are encrypted separately.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.