Destruction Productions
Destruction Productions
Destruction Productions
Would you like to react to this message? Create an account in a few clicks or log in to continue.


Make Games. Make Money. Make Friends.
 
HomeLatest imagesRegisterLog in

 

 Saving multiple encrypted files as one

Go down 
3 posters
AuthorMessage
gullesnuffs

gullesnuffs


Number of posts : 252
Registration date : 2009-05-06
Age : 30
Location : Stockholm, Sweden

Saving multiple encrypted files as one Empty
PostSubject: Saving multiple encrypted files as one   Saving multiple encrypted files as one EmptySun Jan 03, 2010 1:23 am

Alright, I'm done with the updated encryption/decryption scripts, now it's possible to save several strings into one file.

scr_save_game();
Code:
{
 var str, string_number, filename, i, file, j, k;
 //Remember that the str-variables have to be strings
 str[0]="The string that previously was in save_file.txt";
 str[1]="The string that previously was in save_file2.txt";
 str[2]="The string that previously was in save_file3.txt";
 str[3]="The string that previously was in save_file4.txt";
 str[4]="The string that previously was in save_file5.txt";
 str[5]="The string that previously was in save_file6.txt";
 str[6]="The string that previously was in save_file7.txt";
 str[7]="The string that previously was in save_file8.txt";
 string_number=8;
 filename="savegame.b4s";
 file=file_bin_open(filename, 1);
 for(i=0; i < string_number; i += 1)
 {
    str[i] += " ";
    //I have no idea why I have to add the above line, but it works ;)
    k=string_length(str[0]);
    if(k < 256)
    {
    file_bin_write_byte(file, 0);
    file_bin_write_byte(file, k);
    }
    else if(k < 65536)
    {
    file_bin_write_byte(file, 1);
    file_bin_write_byte(file, floor(k/256));
    file_bin_write_byte(file, k mod 256);
    }
    else if(k < 16777216)
    {
    file_bin_write_byte(file, 2);
    file_bin_write_byte(file, floor(k/65536));
    file_bin_write_byte(file, floor((k mod 65536)/256));
    file_bin_write_byte(file, k mod 256);
    }
    else show_error("String number " + string(i) + " is to large to be saved, please make it smaller. (below 16 Mb)", 0);
    for(j=1; j <= k; j += 1)
    {
        file_bin_write_byte(file, ord(string_char_at(str[i], j))^(((5*i+17)*i*i+33*i+92) mod 256));
    }
 }
 file_bin_close(file);
}

scr_load_game();

Code:
{
 var str, string_number, filename, i, file, j, k, length;
 string_number=8;
 filename="savegame.b4s";
 file=file_bin_open(filename, 0);
 for(i=0; i < string_number; i += 1)
 {
    k=file_bin_read_byte(file);
    if(k == 0)length=file_bin_read_byte(file);
    else if(k == 1)
    {
    length=file_bin_read_byte(file)*256;
    length += file_bin_read_byte(file);
    }
    else if(k == 2)
    {
    length=file_bin_read_byte(file)*65536;
    length += file_bin_read_byte(file)*256;
    length += file_bin_read_byte(file);
    }
    else show_error("String number " + string(i) + " seems to be corrupted...", 0);
    k="";
    for(j=1; j <= length; j += 1)
    {
        k += chr(file_bin_read_byte(file)^(((5*i+17)*i*i+33*i+92) mod 256));
    }
    //k now contains string number i
    //Example of how the following code can look:
    /*
    if(i == 0)
    {
        score=real(k);
        //Remember to use real when necessary
    }
    else if(i == 1)
    {
        global.kills=real(k);
        //Remember to use real when necessary
    }
    else if(i == 2)
    {
        global.player_name=k;
    }
    else if(i == 3)
    {
        player.x=real(k);
    }
    else if(i == 4)
    {
        player.y=real(k);
    }
    else if(i == 5)
    {
        player.ammo=real(k);
    }
    */
 }
 file_bin_close(file);
}

Feel free to ask if anything is unclear. Wink
Back to top Go down
http://gullesnuffs.deviantart.com/
Hegemege
Moderator
Hegemege


Number of posts : 919
Registration date : 2009-02-21
Age : 31
Location : Helsinki, Finland

Saving multiple encrypted files as one Empty
PostSubject: Re: Saving multiple encrypted files as one   Saving multiple encrypted files as one EmptySun Jan 03, 2010 1:53 am

Looks like it will be very easy to use and add stuff. Thank you gullesnuffs!

But hey, couldnt one use a switch statement when checking the variables in load game script?

And it looks like we already have some kind of anti cheat system, I am not sure what would happen if someone edited anything after saving and then loads, maybe the value gets too high.

How fast are these scripts btw? it looks like theres a for loop inside a for loop in the loading process...

and, in "k now holds string number i" do you mean that it holds the string IN number i?
Back to top Go down
Commander~DEST
Admin
Commander~DEST


Number of posts : 1499
Registration date : 2009-01-16
Age : 29
Location : Quispamsis, New Brunswick, Canada

Saving multiple encrypted files as one Empty
PostSubject: Re: Saving multiple encrypted files as one   Saving multiple encrypted files as one EmptySun Jan 03, 2010 3:27 am

Looks great Gullesnuffs! Good job! Hey, Hegemege, since you are currently the one with the engine, do you mind importing it into the game?
Back to top Go down
https://dest.forumotion.com
Hegemege
Moderator
Hegemege


Number of posts : 919
Registration date : 2009-02-21
Age : 31
Location : Helsinki, Finland

Saving multiple encrypted files as one Empty
PostSubject: Re: Saving multiple encrypted files as one   Saving multiple encrypted files as one EmptySun Jan 03, 2010 3:35 am

Sure, no big deal.
Back to top Go down
Commander~DEST
Admin
Commander~DEST


Number of posts : 1499
Registration date : 2009-01-16
Age : 29
Location : Quispamsis, New Brunswick, Canada

Saving multiple encrypted files as one Empty
PostSubject: Re: Saving multiple encrypted files as one   Saving multiple encrypted files as one EmptySun Jan 03, 2010 3:44 am

Thanks, it will hardly take anytime anyway.
Back to top Go down
https://dest.forumotion.com
Hegemege
Moderator
Hegemege


Number of posts : 919
Registration date : 2009-02-21
Age : 31
Location : Helsinki, Finland

Saving multiple encrypted files as one Empty
PostSubject: Re: Saving multiple encrypted files as one   Saving multiple encrypted files as one EmptySun Jan 03, 2010 4:25 am

Well, I don't have enough time now to merge it... maybe someone else?

Firstly, we need to make the curent shooting variables which have anything to do with weapon stats into arrays. We could also load weapon stats from a file...

Also, we should make clear tables of any used arrays so we know what kind of info every slot holds and what its used for, eg.
weapon[0,0] = "Name of the weapon"
weapon[0,1] = damage
etc.
Into a separate textfile so we avoid tens of rows of comments.

Another thing, when you declare global variables you can use this format:
globalvar ammo, health, level; //now you dont need to put global. as a prefix
you can now handle these variables like this normal variables but without global. prefix. just make sure you give them values after globalvar
Back to top Go down
Sponsored content





Saving multiple encrypted files as one Empty
PostSubject: Re: Saving multiple encrypted files as one   Saving multiple encrypted files as one Empty

Back to top Go down
 
Saving multiple encrypted files as one
Back to top 
Page 1 of 1
 Similar topics
-
» Encryption/Decryption of files

Permissions in this forum:You cannot reply to topics in this forum
Destruction Productions :: Archives-
Jump to: