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 


AutoAttachList Save and Load questions

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

Joined: 30 Aug 2016
Posts: 5

PostPosted: Mon Jan 01, 2018 8:37 am    Post subject: AutoAttachList Save and Load questions Reply with quote

I am making a standalone exe for personal use with speed hack functionality, editable hotkeys, saving settings to the registry and all that jazz. Before I started I had never seen LUA code before, now everything is pretty much up and running.

But I also have an edit box, where I can enter a process name and then add it to the AutoAttachList. Now I wanted to save said list in the registry, which did not work, the key was always empty. Figured out, that a stringlist can apparently not be saved that way. Used the following code now:

Code:
aalist = getAutoAttachList()
aalist.loadFromFile('AutoAttach.cfg')

-- DO SOME STUFF --

function btnOpenProcessClick(sender)
  stringlist_add(aalist,speedHackForm_edtProcessname.Text)
end

-- DO SOME OTHER STUFF --

function FormClose(sender)
  aalist.saveToFile('AutoAttach.cfg')
  closeCE();
  return caFree --Possible options: caHide, caFree, caMinimize, caNone
end


This works fine when executing the script in cheat engine, it creates the file 'AutoAttach.cfg' it reads from it, everything good.

Now as soon as I convert that into a "Gigantic" exe file (I tried to enable all the features, tried it with only speedhack) it does not work. It will neither read an existing 'AutoAttach.cfg', nor write to one, nor make a new one. Otherwise the code does what it is supposed to do.

I really need help with that, searching has not born fruit yet. What gives? xD


Edit: I thought if someone really wants to see the whole code or use it for his own standalone speedhack, I might as well attach it.

Credit for the code goes to DarkByte for some snippets I honestly have no idea anymore what I copied and what I wrote myself (copy-pasting is life) and mgr.inz.Player for the first ~150 lines of code with his ChangeHotKeys code. Big Thanks to both of you. If I copied code from someone else and forgot about it: I am truly sorry, this was ever only intended for personal use, so I didn't take extensive notes.

Also: The code is not malicious (of course), it DOES add a registry key in "\HKEY_CURRENT_USER\Software\Cheat Engine\overload\Speedhack v4\" to store hotkeys and "\HKEY_CURRENT_USER\Software\Cheat Engine\overload\Speedhack v4\Values" to store your last speed and step settings. And it also should but doesn't currently (hence the post) create a file in its working directory called 'AutoAttach.cfg' containing the process names it should auto attach to.

Critique on my code is welcome, I am an absolute beginner at coding.

File was too big for upload and I can't add a URL... guess no file then for now.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 7

Joined: 24 Feb 2017
Posts: 194
Location: Right Here Buddy.

PostPosted: Mon Jan 01, 2018 12:42 pm    Post subject: Reply with quote

Have you tried Lua's File IO

http://www.lua.org/pil/21.2.html

https://www.tutorialspoint.com/lua/lua_file_io.htm

I could also be your anti-virus software blocking the executable. Say if it doesn't like the way you check for hot keys, it might think it's some kind of key logger.

_________________
A: What manner of man are you that can summon up fire without flint or tinder?
T: I... am an enchanter.
Back to top
View user's profile Send private message
overload86
How do I cheat?
Reputation: 0

Joined: 30 Aug 2016
Posts: 5

PostPosted: Mon Jan 01, 2018 4:15 pm    Post subject: Reply with quote

Big Edit: Thanks to h**p://forum.cheatengine.org/viewtopic.php?t=544107
and h**p://forum.cheatengine.org/viewtopic.php?t=545361
It came to my attention, that CE created executables extract all the files to a temp folder, which is also where my created file was put and afterwards deleted.

Using
Code:
local FILENAME = TrainerOrigin .. 'AutoAttach.cfg'


was all it took to get the code to work how I wanted it to.

Thread can be closed, thank you for your help again.


-- Original Thread --
Thank you for your suggestions. I am not using anti virus software, since it never detected the rare virus I did pick up in 30 years of using PCs and it flagged many many many things I wanted to open and knew were virus free.

It would have been a valid argument though, but also notice that I said the exe works flawlessly, it just doesn't read or write to files. So the read and write part to the registry is no problem, hotkeys are working, it speeds up what it is supposed to speed up.

Now I have modified the code to use Lua's own file io like you suggested.

--- This is only a snippet of the code, obviously, but everything that should be relevant ---
Code:

-- Constant for the filename (yes not really constant... but good enough)
local FILENAME = 'AutoAttach.cfg'

-- new Autoattachlist
aalist = getAutoAttachList()

-- Open file for reading
file = io.open(FILENAME,'r')

-- Catch nonexisting file
if file ~= nil then
-- Read file line by line, append it to aalist and close the filehandle
  for line in file:lines() do
    stringlist_add(aalist,line)
  end
else
  -- Create file if it didn't exist
  file = io.open(FILENAME,'w')
  file:close()
end

-- This is a button in my trainer next to a edit field for the executable name
function btnOpenProcessClick(sender)
  -- Append what is inside the edit field to aalist
  stringlist_add(aalist, speedHackForm_edtProcessname.Text)
  -- open file for appending, this time throw an error, if it can't be opened
  file = assert(io.open(FILENAME,'a'))
  -- Write the content of the edit field to the file, including a new line and close the handle
  file:write(speedHackForm_edtProcessname.Text .. '\n')
  file:close()
end

-- When the program gets closed properly, save values in registry, then close CE
function FormClose(sender)
  values = getSettings(SETTINGS_PATH_VALUES)
  values.Value['Speed'] = tostring(speed)
  values.Value['Step'] = tostring(step)
  closeCE();
  return caFree --Possible options: caHide, caFree, caMinimize, caNone
end


Once again working as intended when I open the .ct file with Cheat Engine and execute the script.

Does not open a file, create a new file if there is none, write to a file after being compiled to an exe (is it compilation? Not really, right?)

Rest of the code still works.[/code]


Last edited by overload86 on Mon Jan 01, 2018 4:30 pm; edited 1 time in total
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 7

Joined: 24 Feb 2017
Posts: 194
Location: Right Here Buddy.

PostPosted: Mon Jan 01, 2018 4:27 pm    Post subject: Reply with quote

Try to see if there is an error.
Code:
-- Open file for reading
file, err = io.open(FILENAME,'r')

-- check for errors in opening file.
if file ~= nil and err then
   print(err)
end
-- Catch nonexisting file
if file ~= nil then
-- Read file line by line, append it to aalist and close the filehandle
for line in file:lines() do
  stringlist_add(aalist,line)
end
else
-- Create file if it didn't exist
file = io.open(FILENAME,'w')
file:close()
end

_________________
A: What manner of man are you that can summon up fire without flint or tinder?
T: I... am an enchanter.
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