Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to create a Save/Load functon for a Trainer?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Shirabrixx
How do I cheat?
Reputation: 0

Joined: 13 Jul 2017
Posts: 5

PostPosted: Tue Aug 08, 2017 11:02 pm    Post subject: How to create a Save/Load functon for a Trainer? Reply with quote

I wanna add a Save/Load Function for my Trainer. Its for GTA5 a Outfitdesigner.

It should be save/load the Outfitparts of a *.ini file

example for my "Outfits_1.ini" file then...
Code:
[OUTFITS_SAVED_1]
   
TOPS1=0
TEXTURE_1=0

TOPS2=0
TEXTURE_2=0

LEGS=13
TEXTURE_3=0

GLOVES=19
TEXTURE_4=0

SHOES=7
TEXTURE_5=4

HATS=55
TEXTURE_6=7

MASK=9
TEXTURE_7=2

PARACHUTE=41
TEXTURE_8=0

SCARF=55
TEXTURE_9=0

ARMOR=58
TEXTURE_10=0

SCARF=55
TEXTURE_11=0

EARPIECES=2
TEXTURE_12=0

GLASSES=2
TEXTURE_13=0

WATCHES=7
TEXTURE_14=0

BANGLES=2
TEXTURE_14=0


My Trainer -->



GTA5[1.40] SunShineSilver OTD(RB) 1.20.5 [SC]_2017-08-08_14-26-01.png
 Description:
 Filesize:  302.3 KB
 Viewed:  930 Time(s)

GTA5[1.40] SunShineSilver OTD(RB) 1.20.5 [SC]_2017-08-08_14-26-01.png


Back to top
View user's profile Send private message
dl748
Cheater
Reputation: 0

Joined: 05 Mar 2016
Posts: 39

PostPosted: Wed Aug 09, 2017 1:09 am    Post subject: Reply with quote

MY EYES!!! MY EYES!!!
Back to top
View user's profile Send private message
FreeER
Expert Cheater
Reputation: 9

Joined: 09 Aug 2013
Posts: 228

PostPosted: Wed Aug 09, 2017 9:18 am    Post subject: Reply with quote

Have you looked at lua io tutorials? https://www.tutorialspoint.com/lua/lua_file_io.htm

Code:

-- Opens a file in append mode
file = io.open("test.lua", "a")

-- sets the default output file as test.lua
io.output(file)

-- appends a word test to the last line of the file
io.write("-- End of the test.lua file")

-- explicitly writes to file instead of default (from second example)
file:write("--test")

-- closes the open file
io.close(file)


seems pretty simple to understand....
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 26

Joined: 01 Oct 2008
Posts: 652

PostPosted: Wed Aug 09, 2017 9:49 am    Post subject: Reply with quote

May try this module https://github.com/jonstoler/lua-toml
toml seems similar ini.
toml spec : https://github.com/toml-lang/toml

but lua-toml is not completely satisfy toml spec, yet should be enough for simple structure.

eg.
Code:

local db = {
  OUTFITS_SAVED_1 = {
  TOPS1=0,
  TEXTURE_1=0,
  a_path = [[c:\user\user\appdata]],
  multi_line = [[
    hello,
    world
  ]]
  }
}

local toml = require'toml'

local str = toml.encode(db)

print(str)--
[OUTFITS_SAVED_1]
a_path = "c:\\user\\user\\appdata"
TOPS1 = 0
multi_line = """    hello,
    world
  """
TEXTURE_1 = 0


so a lua table structure (statisfy toml spec) can be serialize/save deserilize/load as file.

then your ui can concentrated on manipulating data setup on a lua table .

_________________
- Retarded.
dropbox
Back to top
View user's profile Send private message
Corroder
Master Cheater
Reputation: 8

Joined: 10 Apr 2015
Posts: 414

PostPosted: Wed Aug 09, 2017 4:52 pm    Post subject: Reply with quote

Maybe...

http://forum.cheatengine.org/viewtopic.php?t=603189

_________________
I can't do it now because I don't know yet and because You knew it before me. There is heaven above the sky.
Back to top
View user's profile Send private message
Shirabrixx
How do I cheat?
Reputation: 0

Joined: 13 Jul 2017
Posts: 5

PostPosted: Wed Aug 09, 2017 9:18 pm    Post subject: Reply with quote

FreeER wrote:
Have you looked at lua io tutorials?

Code:

-- Opens a file in append mode
file = io.open("test.lua", "a")

-- sets the default output file as test.lua
io.output(file)

-- appends a word test to the last line of the file
io.write("-- End of the test.lua file")

-- explicitly writes to file instead of default (from second example)
file:write("--test")

-- closes the open file
io.close(file)


seems pretty simple to understand....



Idk what i must do, that confused me so!

Can u help me a bit more I tried these

Code:

function SAVE_A_button()
-- Opens a file in append mode
file = io.open("test.lua", "w+")

-- sets the default output file as test.lua
io.output(file)

-- appends a word test to the last line of the file
--TOPS1
io.write("TOPS1")
file:write("Text")

--TEXTURE_1
io.write("TEXTURE_1")
file:write("Text")

--TOPS2
io.write("TOPS2=")
file:write("Text")

--TEXTURE_2
io.write("TEXTURE_2")
file:write("Text")

-- explicitly writes to file instead of default (from second example)

-- closes the open file
io.close(file)
end


+ how can i read the value of the editbox/address then...
idk must i do something like this:

setProperty(mdAOTD_Edit1,"Text", readBytes("[[[GTA5.exe+02351090]+8]+48]+F0"))

Can u give me a example what i must exactly do (write) to get a putfile with the right values then please.

Like:

TOPS1=?
TEXTURE_1=?
TOPS2=?
TEXTURE_2=?

and that ican load it right!

I am really new in (lua) coding and my english is really bad. Sad
Back to top
View user's profile Send private message
Corroder
Master Cheater
Reputation: 8

Joined: 10 Apr 2015
Posts: 414

PostPosted: Fri Aug 11, 2017 1:34 am    Post subject: Reply with quote

Just a simple sample

Code:
f = createForm()

lb1 = createLabel(f)
lb1.left = 10
lb1.top = 10
lb1.Caption = 'Top 1'

lb2 = createLabel(f)
lb2.left = 10
lb2.top = 30
lb2.Caption = 'Texture'

e1 = createEdit(f)
e1.left = 100
e1.top = 10
e1.width = 100
e1.Text ='0'

e2 = createEdit(f)
e2.left = 100
e2.top = 30
e2.width = 100
e2.Text = '0'

b1 = createButton(f)
b1.left = 10
b1.height = 30
b1.top = 100
b1.width = 60
b1.Caption = 'Save'

b2 = createButton(f)
b2.left = b1.left + b1.width + 10
b2.height = 30
b2.top = 100
b2.width = 60
b2.Caption = 'Load'

b3 = createButton(f)
b3.left = b2.left + b2.width + 10
b3.height = 30
b3.top = 100
b3.width = 60
b3.Caption = 'Close'


function SaveVars()
 get_Top1 = tonumber(e1.text)
 get_Texture1 = tonumber(e2.text)
 local f = assert(io.open("SavedVars.txt", "w"))
 f:write(get_Top1,"\n")
 f:write(get_Texture1,"\n")
 f:close()
 showMessage("Done... Data Saved")
 return
end

function LoadVars()
 local f = assert(io.open("SavedVars.txt", "r"))
 set_Top1 = f:read("*line")
 set_Texture1 = f:read("*line")
 f:close()
 e1.Text = tostring(set_Top1)
 e2.Text = tostring(set_Texture1)
end

function exitTrainer()
 form_hide(f)
 return caFree
end

b1.onClick = SaveVars
b2.onClick = LoadVars
b3.onClick = exitTrainer

f.show()

_________________
I can't do it now because I don't know yet and because You knew it before me. There is heaven above the sky.
Back to top
View user's profile Send private message
Shirabrixx
How do I cheat?
Reputation: 0

Joined: 13 Jul 2017
Posts: 5

PostPosted: Sat Aug 12, 2017 8:22 pm    Post subject: Reply with quote

@Corroder Thank You So Much! I finished and figured out how to to code a "SAVE"/"LOAD" Option for my Outfit Designer! Your Example has helped me alot to understand it! Also Thanks to @FreeER & @panraven ty all Very Happy

Code:
function svOTD_C()
 get_Tops1 = tonumber(control_getCaption(mdAOTD_Edit1))
 get_tex1 = tonumber(control_getCaption(mdAOTD_Edit2))
 get_Tops2 = tonumber(control_getCaption(mdAOTD_Edit3))
 get_tex2 = tonumber(control_getCaption(mdAOTD_Edit4))
 get_Legs = tonumber(control_getCaption(mdAOTD_Edit5))
 get_tex3 = tonumber(control_getCaption(mdAOTD_Edit6))
 get_Gloves = tonumber(control_getCaption(mdAOTD_Edit7))
 get_tex4 = tonumber(control_getCaption(mdAOTD_Edit8))
 get_Shoes = tonumber(control_getCaption(mdAOTD_Edit9))
 get_tex5 = tonumber(control_getCaption(mdAOTD_Edit10))
 get_Hats = tonumber(control_getCaption(mdAOTD_Edit11))
 get_tex6 = tonumber(control_getCaption(mdAOTD_Edit12))
 get_Mask = tonumber(control_getCaption(mdAOTD_Edit13))
 get_tex7 = tonumber(control_getCaption(mdAOTD_Edit14))
 get_Parachute = tonumber(control_getCaption(mdAOTD_Edit15))
 sleep(5)
 get_tex8 = tonumber(control_getCaption(mdAOTD_Edit16))
 get_Scarf = tonumber(control_getCaption(mdAOTD_Edit17))
 get_tex9 = tonumber(control_getCaption(mdAOTD_Edit18))
 get_Armor = tonumber(control_getCaption(mdAOTD_Edit19))
 get_tex10 = tonumber(control_getCaption(mdAOTD_Edit20))
 get_Decals = tonumber(control_getCaption(mdAOTD_Edit21))
 get_tex11 = tonumber(control_getCaption(mdAOTD_Edit22))
 get_Earpieces = tonumber(control_getCaption(mdAOTD_Edit23))
 get_tex12 = tonumber(control_getCaption(mdAOTD_Edit24))
 get_Glasses = tonumber(control_getCaption(mdAOTD_Edit25))
 get_tex13 = tonumber(control_getCaption(mdAOTD_Edit26))
 get_Watches = tonumber(control_getCaption(mdAOTD_Edit27))
 get_tex14 = tonumber(control_getCaption(mdAOTD_Edit28))
 get_Bangles = tonumber(control_getCaption(mdAOTD_Edit29))
 get_tex15 = tonumber(control_getCaption(mdAOTD_Edit30))
 sleep(5)
 local mdAOTD = assert(io.open([[c:\Saved_Outfit_C.txt]], "w"))
 mdAOTD:write(get_Tops1,"\n")
 mdAOTD:write(get_tex1,"\n")
 mdAOTD:write(get_Tops2,"\n")
 mdAOTD:write(get_tex2,"\n")
 mdAOTD:write(get_Legs,"\n")
 mdAOTD:write(get_tex3,"\n")
 mdAOTD:write(get_Gloves,"\n")
 mdAOTD:write(get_tex4,"\n")
 mdAOTD:write(get_Shoes,"\n")
 mdAOTD:write(get_tex5,"\n")
 mdAOTD:write(get_Hats,"\n")
 mdAOTD:write(get_tex6,"\n")
 mdAOTD:write(get_Mask,"\n")
 mdAOTD:write(get_tex7,"\n")
 mdAOTD:write(get_Parachute,"\n")
 sleep(5)
 mdAOTD:write(get_tex8,"\n")
 mdAOTD:write(get_Scarf,"\n")
 mdAOTD:write(get_tex9,"\n")
 mdAOTD:write(get_Armor ,"\n")
 mdAOTD:write(get_tex10,"\n")
 mdAOTD:write(get_Decals,"\n")
 mdAOTD:write(get_tex11,"\n")
 mdAOTD:write(get_Earpieces,"\n")
 mdAOTD:write(get_tex12,"\n")
 mdAOTD:write(get_Glasses,"\n")
 mdAOTD:write(get_tex13,"\n")
 mdAOTD:write(get_Watches,"\n")
 mdAOTD:write(get_tex14,"\n")
 mdAOTD:write(get_Bangles,"\n")
 mdAOTD:write(get_tex15,"\n")
 mdAOTD:close()
 showMessage("mdA Saved Outfit ~> C <~")
 return
end

function ldOTD_C()
 local mdAOTD = assert(io.open([[c:\Saved_Outfit_C.txt]], "r"))
 set_Tops1 = mdAOTD:read("*line")
 set_tex1 = mdAOTD:read("*line")
 set_Tops2 = mdAOTD:read("*line")
 set_tex2 = mdAOTD:read("*line")
 set_Legs = mdAOTD:read("*line")
 set_tex3 = mdAOTD:read("*line")
 set_Gloves = mdAOTD:read("*line")
 set_tex4 = mdAOTD:read("*line")
 set_Shoes = mdAOTD:read("*line")
 set_tex5 = mdAOTD:read("*line")
 set_Hats = mdAOTD:read("*line")
 set_tex6 = mdAOTD:read("*line")
 set_Mask = mdAOTD:read("*line")
 set_tex7 = mdAOTD:read("*line")
 set_Parachute = mdAOTD:read("*line")
 sleep(5)
 set_tex8 = mdAOTD:read("*line")
 set_Scarf = mdAOTD:read("*line")
 set_tex9 = mdAOTD:read("*line")
 set_Armor  = mdAOTD:read("*line")
 set_tex10 = mdAOTD:read("*line")
 set_Decals = mdAOTD:read("*line")
 set_tex11 = mdAOTD:read("*line")
 set_Earpieces = mdAOTD:read("*line")
 set_tex12 = mdAOTD:read("*line")
 set_Glasses = mdAOTD:read("*line")
 set_tex13 = mdAOTD:read("*line")
 set_Watches = mdAOTD:read("*line")
 set_tex14 = mdAOTD:read("*line")
 set_Bangles = mdAOTD:read("*line")
 set_tex15 = mdAOTD:read("*line")
 mdAOTD:close()
 control_setCaption(mdAOTD_Edit1,tostring(set_Tops1))
 control_setCaption(mdAOTD_Edit2,tostring(set_tex1))
 control_setCaption(mdAOTD_Edit3,tostring(set_Tops2))
 control_setCaption(mdAOTD_Edit4,tostring(set_tex2))
 control_setCaption(mdAOTD_Edit5,tostring(set_Legs))
 control_setCaption(mdAOTD_Edit6,tostring(set_tex3))
 control_setCaption(mdAOTD_Edit7,tostring(set_Gloves))
 control_setCaption(mdAOTD_Edit8,tostring(set_tex4))
 control_setCaption(mdAOTD_Edit9,tostring(set_Shoes))
 control_setCaption(mdAOTD_Edit10,tostring(set_tex5))
 control_setCaption(mdAOTD_Edit11,tostring(set_Hats))
 control_setCaption(mdAOTD_Edit12,tostring(set_tex6))
 control_setCaption(mdAOTD_Edit13,tostring(set_Mask))
 control_setCaption(mdAOTD_Edit14,tostring(set_tex7))
 control_setCaption(mdAOTD_Edit15,tostring(set_Parachute))
 sleep(5)
 control_setCaption(mdAOTD_Edit16,tostring(set_tex8))
 control_setCaption(mdAOTD_Edit17,tostring(set_Scarf))
 control_setCaption(mdAOTD_Edit18,tostring(set_tex9))
 control_setCaption(mdAOTD_Edit19,tostring(set_Armor))
 control_setCaption(mdAOTD_Edit20,tostring(set_tex10))
 control_setCaption(mdAOTD_Edit21,tostring(set_Decals))
 control_setCaption(mdAOTD_Edit22,tostring(set_tex11))
 control_setCaption(mdAOTD_Edit23,tostring(set_Earpieces))
 control_setCaption(mdAOTD_Edit24,tostring(set_tex12))
 control_setCaption(mdAOTD_Edit25,tostring(set_Glasses))
 control_setCaption(mdAOTD_Edit26,tostring(set_tex13))
 control_setCaption(mdAOTD_Edit27,tostring(set_Watches))
 control_setCaption(mdAOTD_Edit28,tostring(set_tex14))
 control_setCaption(mdAOTD_Edit29,tostring(set_Bangles))
 control_setCaption(mdAOTD_Edit30,tostring(set_tex15))

 showMessage("mdA Loaded Outfit ~> C <~")
end
Now I am happy and it works great!
Back to top
View user's profile Send private message
Corroder
Master Cheater
Reputation: 8

Joined: 10 Apr 2015
Posts: 414

PostPosted: Sat Aug 12, 2017 10:58 pm    Post subject: Reply with quote

@Shirabrixx ... great..!
_________________
I can't do it now because I don't know yet and because You knew it before me. There is heaven above the sky.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites