Slib 1.2 - really easy saving!

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Snuux
Prole
Posts: 49
Joined: Sun Dec 15, 2013 10:43 am
Location: Russia, Moskow
Contact:

Slib 1.2 - really easy saving!

Post by Snuux » Thu Feb 20, 2014 9:04 pm

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
Last edited by Snuux on Mon Sep 01, 2014 2:37 pm, edited 10 times in total.
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)

User avatar
Snuux
Prole
Posts: 49
Joined: Sun Dec 15, 2013 10:43 am
Location: Russia, Moskow
Contact:

Re: Slib 0.4.0 - realy easy save!

Post by Snuux » Thu Feb 20, 2014 10:18 pm

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)
Last edited by Snuux on Fri Feb 21, 2014 5:13 pm, edited 1 time in total.
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Slib 0.4.0 - realy easy save!

Post by Robin » Fri Feb 21, 2014 9:23 am

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.
Help us help you: attach a .love.

User avatar
Snuux
Prole
Posts: 49
Joined: Sun Dec 15, 2013 10:43 am
Location: Russia, Moskow
Contact:

Re: Slib 0.4.0 - realy easy save!

Post by Snuux » Fri Feb 21, 2014 1:05 pm

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...
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)

User avatar
Doctory
Party member
Posts: 439
Joined: Fri Dec 27, 2013 4:53 pm

Re: Slib 0.4.0 - realy easy save!

Post by Doctory » Fri Feb 21, 2014 2:19 pm

THIS
IS
AWESOME!
(not sparta)
In many ways!
"This is what videogames should be like; they should have meaning and triple machine guns"
- Jan Willem Nijman, 2013
github

User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Slib 0.4.0 - realy easy save!

Post by Plu » Fri Feb 21, 2014 2:42 pm

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.

User avatar
Snuux
Prole
Posts: 49
Joined: Sun Dec 15, 2013 10:43 am
Location: Russia, Moskow
Contact:

Re: Slib 0.9 - realy easy saving!

Post by Snuux » Fri Feb 21, 2014 3:54 pm

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!
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)

User avatar
Doctory
Party member
Posts: 439
Joined: Fri Dec 27, 2013 4:53 pm

Re: Slib 0.9 - realy easy saving!

Post by Doctory » Fri Feb 21, 2014 4:43 pm

I will try to make a networking program w/ this.
"This is what videogames should be like; they should have meaning and triple machine guns"
- Jan Willem Nijman, 2013
github

User avatar
Snuux
Prole
Posts: 49
Joined: Sun Dec 15, 2013 10:43 am
Location: Russia, Moskow
Contact:

Re: Slib 1.0 - really easy saving!

Post by Snuux » Tue Apr 01, 2014 12:47 pm

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!
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)

User avatar
Ref
Party member
Posts: 679
Joined: Wed May 02, 2012 11:05 pm

Re: Slib 1.0 - really easy saving!

Post by Ref » Wed Apr 02, 2014 2:08 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests