fb:porticula NoPaste
Savegame - Lib
Uploader: | AndT |
Datum/Zeit: | 10.12.2007 19:36:25 |
' Programmed by AndT
Const Cryptkey = 1234
sub create_savegamefolder
mkdir "savegames"
end sub
sub open_savegame (file as string)
open ".\savegames\"&file for binary as #1
end sub
sub kill_savegame (file as string)
close #1
kill ".\savegames\"&file
end sub
sub close_savegame
close #1
end sub
sub save_savegame(datastring as string)
dim as integer dlen=len(datastring)
put #1,1,"SAV"
put #1,,dlen
put #1,,datastring
end sub
function get_savegamestring(startpos as integer,endpos as integer) as string
dim as string tmpstr
dim as ubyte tchar
for i as integer = startpos to endpos
get #1,i,tchar
tmpstr+=chr(tchar)
next
function = tmpstr
end function
function load_savegame as string
IF LOF(1)=0 then FUNCTION = "SAVEGAME NOT LOADED!":EXIT FUNCTION
IF get_savegamestring(lof(1)-2,lof(1))="ENC" THEN FUNCTION = "NO SAVEGAME - ERR 2":EXIT FUNCTION
IF get_savegamestring(1,3)="SAV" THEN ELSE FUNCTION = "NO SAVEGAME - ERR 1":EXIT FUNCTION
dim as integer strlen
get #1,,strlen
if strlen=0 then FUNCTION ="NO SAVEGAME":EXIT FUNCTION ELSE IF strlen > 102400000 THEN FUNCTION = "SAVEGAME ERROR":EXIT FUNCTION
function = get_savegamestring(8,7+strlen)
end function
sub cryptsave
RANDOMIZE Cryptkey
dim as ubyte char,gchar
for i as integer = 1 to lof(1)
get #1,i,char
char = char xor 64 + INT(RND*1024)
put #1,i,char
next
put #1,,"ENC"
end sub
sub decryptsave
RANDOMIZE Cryptkey
IF get_savegamestring(lof(1)-2,lof(1))<> "ENC" then exit sub
dim as ubyte char,gchar
for i as integer = 1 to lof(1)-2
get #1,i,char
char = char xor 64 + INT(RND*1024)
put #1,i,char
next
put #1,,"DEC"
end sub
function secload_savegame as string
decryptsave
function = load_savegame
cryptsave
end function
'Programmcode hier!
const Dateiname = "Das_ist_ein_Testsavegame.sav"
' Speicehrn und verschlüsseln - Beispiel
Print "Speichern.."
create_savegamefolder
kill_savegame Dateiname
open_savegame Dateiname
save_savegame "gold=12300,hp=100,scrres=1024x768 usw.."
cryptsave
close_savegame
' Laden und entschlüsseln - Beispiel
Print "Laden.."
open_savegame Dateiname
decryptsave
print load_savegame
cryptsave
close_savegame
print "Auf Taste warten.."
sleep