Thought to make this seperate - this is not memblock work
Asset encryption code
Encryption code
// Project: enctest
// Created: 2018-11-17
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "enctest" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#constant size = 128
global encryptionkey as integer[size,size]
package("assets.agm")
do
Print( ScreenFPS() )
Sync()
loop
function generatebitmask(sizex,sizey)
for x=0 to sizex
for y=0 to sizey
encryptionkey[x,y]=random2(200,255)
next
next
endfunction
function package(filename$)
generatebitmask(size,size)
newfile = OpenToWrite(filename$)
fn$=GetFirstFile()
while fn$<>""
if fn$<>"bytecode.byc" and fn$<>filename$ // dont encrypt the bytecode or itself (if ever it finds them)
file = OpenToRead(fn$)
WriteLine(newfile,"AGM!")
writebyte(newfile,size)
WriteLine(newfile,fn$)
WriteInteger(newfile, GetFileSize(file))
enclocx=0
enclocy=0
length=GetFileSize(file)
for a=0 to length
WriteByte(newfile,encryptionkey[enclocx,enclocy])
WriteByte(newfile, (ReadByte(file) ~~ (encryptionkey[enclocx,enclocy]+a)) ~~a)
inc enclocx
if enclocx>size
enclocx=0
inc enclocy
endif
if enclocy>size
enclocx=0
enclocy=0
endif
next
WriteLine(newfile,"AGM!")
CloseFile(file)
endif
fn$=GetNextFile()
endwhile
CloseFile(newfile)
endfunction
Decryption
// Project: enctest
// Created: 2018-11-17
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "enctest" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
type _strings
id
txt
fontsize
x
y
rotate#
angle#
colorred
colorgreen
colorblue
coloralpha
endtype
global strings as _strings[]
unpackage("assets.agm")
// What do we think is inside the Assets.agm
cube = AGM_LoadObject("cube.obj")
cone = AGM_LoadObject("cone.obj")
ico = AGM_LoadObject("ico.obj")
cubepng=AGM_LoadImage("cobe.png")
conepng=AGM_LoadImage("cone.png")
icopng=AGM_LoadImage("ico.png")
music = AGM_LoadMusic(1, "overworld.ogg")
agm_loadstrings("strings.txt")
SetObjectPosition(cube,-10,0,0)
SetObjectPosition(cone,0,0,0)
SetObjectPosition(ico,10,0,0)
SetObjectImage(cube,cubepng,0)
SetObjectImage(cone,conepng,0)
SetObjectImage(ico,icopng,0)
c=CreateObjectBox(2,2,2)
SetObjectImage(c,conepng,0)
SetObjectPosition(c,-10,4,0)
c=CreateObjectBox(2,2,2)
SetObjectImage(c,cubepng,0)
SetObjectPosition(c,0,4,0)
c=CreateObjectBox(2,2,2)
SetObjectImage(c,icopng,0)
SetObjectPosition(c,10,4,0)
PlayMusicOGG(music)
do
for a=0 to strings.length
SetTextPosition(strings[a].id,strings[a].x,strings[a].y)
SetTextAngle(strings[a].id,strings[a].angle#)
inc strings[a].angle#,strings[a].rotate#
next
if GetRawKeyPressed(27) then runexit()
Print( ScreenFPS() )
Sync()
loop
function runexit()
// run some code to delete all files in the media folder (EXCEPT the agm file)
endfunction
function AGM_loadstrings(filename$)
s as _strings
file = OpenToRead(filename$)
while not FileEOF(file)
line$=ReadLine(file)
s.id = CreateText(GetStringToken(line$,",",1))
s.fontsize = val(GetStringToken(line$,",",2))
s.x = val(GetStringToken(line$,",",3))
s.y = val(GetStringToken(line$,",",4))
s.rotate# = ValFloat(GetStringToken(line$,",",5))
s.colorred = val(GetStringToken(line$,",",6))
s.colorgreen = val(GetStringToken(line$,",",7))
s.colorblue = val(GetStringToken(line$,",",8))
s.coloralpha = val(GetStringToken(line$,",",9))
SetTextColor(s.id,s.colorred,s.colorgreen,s.colorblue,s.coloralpha)
SetTextSize(s.id,s.fontsize)
strings.insert(s)
endwhile
CloseFile(file)
DeleteFile(filename$)
endfunction
function AGM_LoadMusic(id, file$)
LoadMusicOGG(id,file$)
DeleteFile(file$)
endfunction id
function AGM_LoadObject(file$)
id = LoadObject(file$)
DeleteFile(file$)
endfunction id
function AGM_LoadImage(file$)
id = LoadImage(file$)
DeleteFile(file$)
endfunction id
function unpackage(filename$)
newfile = OpenToRead(filename$)
while not FileEOF(newfile)
if (readLine(newfile)="AGM!")
size = readbyte(newfile)
Dim encryptionkey [size,size]
fn$ = readLine(newfile)
length = readInteger(newfile)
file = OpenToWrite(fn$)
enclocx=0
enclocy=0
for a=0 to length
encryptionkey[enclocx,enclocy] = ReadByte(newfile)
if (fn$<>filename$)
WriteByte(file, (ReadByte(newfile) ~~ encryptionkey[enclocx,enclocy]+a) ~~a)
else
print("ERROR: Bad " + filename$ + " AGM format")
sync()
sleep(4000)
exitfunction
endif
inc enclocx
if enclocx>size
enclocx=0
inc enclocy
endif
if enclocy>size
enclocx=0
enclocy=0
endif
next
ReadLine(newfile)
CloseFile(file)
else
endif
endwhile
CloseFile(newfile)
encryptionkey.length=-1
endfunction
Ill leave it from the memblock work thread cause its not really memblock work
Hope you find it useful, I know i will