Page 1 of 2

Slib 1.2 - really easy saving!

Posted: Thu Feb 20, 2014 9:04 pm
by Snuux
Hi! My name is Vadim, and I create new library for easy save and load tables in your game.

Slib can encrypt your save file! And if player don't have special key, and alghoritm for decryption, he can't change save file.
If you need, Slib can create more than one files. And in Slib you can manage encryption specal key yourself.
In benchmark I use not single table. I use table in table (for example).

View on GitHub:
https://github.com/Snuux/Slib
Download Slib (in .zip):
https://github.com/Snuux/Slib/archive/master.zip

Documentation:
  • Function:
    slib.init(name)
  • Description:
    Initialize Slib.
  • Parameters:
    name - name of Slib, that you use.
    filename (optional) - your default save file name
    enc (optional) - default key for encription
  • Return:
    nothing
  • Function:
    slib.isFirst(filename)
  • Description:
    Check, that save file is in folder. Use for first saving.
  • Parameters:
    filename (optional) - your save file name
  • Return:
    boolean - true, if it is first save
  • Function:
    slib.save(table, filename, drop, enc)
  • Description:
    Save table without encryption (example: maps, names...). It's much faster.
  • Parameters:
    table - table to save
    filename (optional) - your save file name
    drop (optional) - if you have custom userdata (like Image) in table
    enc (optional) - key for encription
  • Return:
    boolean - true while end saving
  • Function:
    slib.save(table, filename, drop, enc)
  • Description:
    Save table with encryption (example: stats, money...). It's slow.
  • Parameters:
    table - table to save
    filename (optional) - your save file name
    drop (optional) - if you have custom userdata (like Image) in table
    enc (optional) - key for encription
  • Return:
    boolean - true while end saving
  • Function:
    slib.load(filename, enc)
  • Description:
    Load your table from file (can be encrypted, or not).
  • Parameters:
    filename (optional) - your save file name
    enc (optional) - key for encription
  • Return:
    table - table that you save
    boolean - true while end loading
  • Function:
    slib.clear(filename)
  • Description:
    Delete save file.
  • Parameters:
    filename (optional) - your save file name
  • Return:
    boolean - true, if clear succsess
You can see, where file save on disk there link.

Simple example:

Code: Select all

--While you exit from app, data save. And while you will open this, data load
Slib = require "slib"

function love.load()
  Slib.init("Slib") -- initialize slib

  if Slib.isFirst() then --if there is no save
    g = {} --char stats
    g.hp = 50
    g.dmg = 100
    g.def = 10
  else --if there is save file
    g = Slib.load() 
  end
end

function love.update(dt)
  if love.keyboard.isDown('g') then
    g.hp = math.random(10, 5000) --generate new stats
    g.dmg = math.random(10, 5000)
    g.def = math.random(10, 5000)
    Slib.saveE(g) --save stats
  end
end

function love.draw()
  --draw our stats:
  love.graphics.print("HP: " .. g.hp .. " Dmg: " .. g.dmg .. " Def: " .. g.def, 10, 10)
  
  love.graphics.print("Press G to generate random HP, Dmg, Def, and save them!", 10, 30)
end
And it is example's save file: Vf-Zq3SI?k$Zm6PNfb"$w0RUXla-xlDk&`Rk&PbT)]&2l`~_n}BB



Be careful! Slib can't save custom userdata. And if your table have some this:

Code: Select all

  g = {} --char stats
  g.hp = 50
  g.dmg = 100
  g.def = 10
  g.img = love.graphics.newImage("Player.png")
  g.body = love.physics.newBody(world, 10, 10, "Shape")
For save this table, you must write "image" and "body" in "drop" parameter. Like this:

Code: Select all

  --Parametes: table to save, save file, drop parameter
  slib.saveE(g, "save", {"image", "body"})
And g.img, g.body don't save. When you load table, you must call function again!


It's very easy!

P.S. Please give me some advice with code, and may be new features.
1.2 Changelog:
- Add cute comments
- Add clear function
- Add default file name and encription code
- Add two parameters in init function
- Rename function isFirstSave to isFirst
- Fix small bug in pack function
- Fix saving non table values

Re: Slib 0.4.0 - realy easy save!

Posted: Thu Feb 20, 2014 10:18 pm
by Snuux
Create new version! And I discover about that userdata serialization impossible((
It's add some new restrictions((



I will update documentation tomorrow.

(Sorry for my bad english)

Re: Slib 0.4.0 - realy easy save!

Posted: Fri Feb 21, 2014 9:23 am
by Robin
Snuux wrote:And if player don't have special key, and alghoritm for decryption, he can't change save file.
The player always has those, though.

Re: Slib 0.4.0 - realy easy save!

Posted: Fri Feb 21, 2014 1:05 pm
by Snuux
Robin wrote:The player always has those, though.
Why? If you compile in .exe (in windows) file, sources won't avaliable?

But, this is better than nothing...

Re: Slib 0.4.0 - realy easy save!

Posted: Fri Feb 21, 2014 2:19 pm
by Doctory
THIS
IS
AWESOME!
(not sparta)
In many ways!

Re: Slib 0.4.0 - realy easy save!

Posted: Fri Feb 21, 2014 2:42 pm
by Plu
Snuux wrote:
Robin wrote:The player always has those, though.
Why? If you compile in .exe (in windows) file, sources won't avaliable?

But, this is better than nothing...
You can reverse engineer the .exe file quite easily; it's literally just the love.exe with the game.love taped to the end. Just cut away the .exe part, open it with winzip, and there ya go.

Re: Slib 0.9 - realy easy saving!

Posted: Fri Feb 21, 2014 3:54 pm
by Snuux
Plu wrote:You can reverse engineer the .exe file quite easily; it's literally just the love.exe with the game.love taped to the end. Just cut away the .exe part, open it with winzip, and there ya go.
What I can say? I try to implement some defense. If people want to hack, they hack commercial and very expensive products. I create this, to protect you games from "first glance" ("first see"). I don't guarantee, that it's super-omega-ultra alghoritm...
(Sorry for my bad English)
Doctory wrote:THIS
IS
AWESOME!
(not sparta)
In many ways!
Thanks! I very happy!

New version 0.9!

Some changelog:
  • New functions "slib.saveE", "slib.save" - for encrypt and usual save
  • Performance is much faster (>x2 times)
  • Now functions return true, while end loading/saving
  • Fix some bugs
You can download if from main post!

Re: Slib 0.9 - realy easy saving!

Posted: Fri Feb 21, 2014 4:43 pm
by Doctory
I will try to make a networking program w/ this.

Re: Slib 1.0 - really easy saving!

Posted: Tue Apr 01, 2014 12:47 pm
by Snuux
Update lib to next version. Now it's 1.0 version.
This version is ready to use. It's more fast, more comfortable, and availible on GitHub!

Changelog:
  • Add slib.init() function
  • Now you can set name of "slib"
  • More fast
It's my first expereance in Git. Please tell me my mistakes.

Download it!

Re: Slib 1.0 - really easy saving!

Posted: Wed Apr 02, 2014 2:08 pm
by Ref
Not really into obfuscation but if you are - why not change slib.crypt to:

Code: Select all

function slib.crypt( text, key, mode )   	-- simple substitution encryption
	local count, m, n
	assert( type( key ) == 'string', "Key must be a string!" )
	count = 1
	m = ""
	n = mode and 1 or -1	                     -- true = encrypt, false = decrypt
	for i = 1, #text do
		m = m..string.char( text:sub(i,i):byte( ) + n * key:sub(count,count):byte())
		count = count < #key and count + 1 or 1
		end
	return m
	end
Then you could use an alpha-numeric key like "TheKey 12345" - something more like a typical key.