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 


Saving trainer state to a .txt/.ini file?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Thu Oct 13, 2016 2:53 pm    Post subject: Saving trainer state to a .txt/.ini file? Reply with quote

Okay so I read a few older threads on this and sort of getting the idea, but am still far off from my goal.

What I want to do is have OnClick events for saving/loading settings profiles in my table to a simple text file, so whenever it's loaded all checkboxes/editboxes/etc. will go back to whatever state they were saved as.

I'm using OpenDialog to open files and SaveDialog to save, but not sure what to do in between. Also using this thread as a reference for settings function in CE: http://forum.cheatengine.org/viewtopic.php?p=5650759 (no idea how to use that in this situation though)

Code:

function LoadSettingsClick()
   LoadSettings = UDF1.OpenDialog.execute()
   -- something that reads a file and loads the settings values?
end

function SaveSettingsClick()
   SaveSettings = UDF1.SaveDialog.execute()
   -- something that writes the settings value to a text file?
end
Back to top
View user's profile Send private message
predprey
Master Cheater
Reputation: 24

Joined: 08 Oct 2015
Posts: 486

PostPosted: Thu Oct 13, 2016 4:11 pm    Post subject: Reply with quote

the way I save to a file is to createStringlist() first then use the saveToFile() method of string lists.

Autoloading of Lua script would probably not be possible unless the user sets loading of Lua scripts to be auto, else he/she would have to reply yes to the load Lua script prompt.

The first part of the script would of course be to loadFromFile(), also a string list method, and parse the .txt/.ini file for flags.

Then, you want to implement a save function bound to the OnClose event handler of the main form, getMainForm().

You can optionally implement a InputQuery() prompt to the save function to ask the user if he/she wants to save.

Thereafter, parse the address list, getAddressList(), for the enabled/disabled status of all the memory records which should be stored as a boolean in the Active property, i.e. getAddressList()[Index].Active == true?

Finally, store the active records index in the .txt/.ini files using the stringlist, with each index on a newline, i.e. newStringList[LineIndex]. On loading the cheat table, the script would parse the text files for all the indexes and set the memory records at those indexes to active. Alternatively, you can use the Description of the memory records instead, or maybe even both.
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Thu Oct 13, 2016 4:43 pm    Post subject: Reply with quote

Thank you for the suggestions, I'm still a noobie to Lua so I'll have to play around with those methods you mentioned.

Also just to clarify better what I'm trying to do, instead of reading from one text file and auto loading those settings, I'd want the user to be able to choose from different profiles. So when the trainer is loaded it will be unchecked/unedited and the user can select the OnClick object to open a text file containing the settings values (example, UDF1.Checkbox.Checked = true or something like that) and another object to click for saving those values to a new or existing text file.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Oct 13, 2016 4:53 pm    Post subject: Reply with quote

So the file you save should just have a single number in it that you read.
And your Lua would be hardcoded with all options to enable for each profile.
Code:
if value == 1 then
  --load profile 1 settings
elseif value == 2 then
  --load profile 2 settings
end

edit: Unless you still want them to be able to choose which options are enabled in each profile themselves...
Then you'd use predprey's method except hook it to your Save Profile button instead of OnClose.
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Thu Oct 13, 2016 7:34 pm    Post subject: Reply with quote

I'm probably on the wrong track here, not familiar with stringlists or dialog objects unfortunately Sad

Code:

function SaveSettingsClick(sender)

SettingsList = createStringlist()
local SV = getSettings('TrainerState')

if UDF1.Checkbox.Checked then
  SV.Value['CheckboxState'] = '1'
else
  SV.Value['CheckboxState'] = '0'
end

SettingsList.add(SV.Value)
 
SaveSettings = createSaveDialog(sender)
if SaveSettings.execute() then
  SettingsList.saveToFile(SaveSettings.Profile)
end

SaveSettings.destroy()
SettingsList.destroy()
end
Back to top
View user's profile Send private message
predprey
Master Cheater
Reputation: 24

Joined: 08 Oct 2015
Posts: 486

PostPosted: Thu Oct 13, 2016 7:46 pm    Post subject: Reply with quote

looks fine.....i presume SaveSettings.Profile is the filepath for the .txt file?
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Fri Oct 14, 2016 1:37 pm    Post subject: Reply with quote

Sadly it didn't work for me, no errors are thrown and the SaveDialog comes up fine but nothing is actually saved to a file, and likewise for loading
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Oct 14, 2016 6:33 pm    Post subject: Reply with quote

Profile isn't a valid member. You probably wanted:
Code:
SaveSettings.FileName
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Fri Oct 14, 2016 6:58 pm    Post subject: Reply with quote

Zanzer wrote:
Profile isn't a valid member. You probably wanted:
Code:
SaveSettings.FileName


Thanks, silly mistake on my part.

So now saving works and creates a text file, and if I do something like SettingsList.add('1') it will write to the file, but how would I go about storing my settings values and also reading from them in the load function? Sort of like how I'm trying to do in the sloppy example above with getSettings
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Oct 14, 2016 7:43 pm    Post subject: Reply with quote

Code:
local records = getAddressList()
local strings = createStringlist()
for i = 0, records.Count - 1 do
  local record = records.MemoryRecord[i]
  if record.Active then
    strings.add(record.Description)
  end
end
-- save strings
strings.Destroy()

Code:
-- load strings
local records = getAddressList()
for i = 0, strings.Count - 1 do
  records.getMemoryRecordByDescription(strings[i]).Active = true
end
strings.Destroy()
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Sat Oct 15, 2016 3:06 pm    Post subject: Reply with quote

Thanks Zanzer! I don't actually use AA scripts through the CE records I do it all through the Lua script, but I can probably work out the rest with that example.

Appreciate all the help guys! Cheers~
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