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 


Automatically execute lua-script on startup

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

Joined: 03 Jul 2016
Posts: 3

PostPosted: Sun Jul 03, 2016 6:37 pm    Post subject: Automatically execute lua-script on startup Reply with quote

Hi

I've tried to get a simple lua script (open a process, write these bytes, read those bytes, execute command line afterwards...) to automatically execute on Cheat Engine start up with no luck.

For example this simple script, which works totally fine if executed with Tools->Lua Engine is doing absolutely nothing if added to main.lua
Code:
...
openProcess("citra.exe")
writeBytes(lOffset1, iValue1)
iValue2 = readBytes(lOffset1, 2)
...

I guess main.lua is beeing called before CE has initialised completely, so I thought how about a timer which will call a function after 5 seconds (should be enough time for CE to get initialised).

Code:
t = createTimer(nil,false)
timer_onTimer(t, MyFunc)
timer_setInterval(t, 5000)
timer_setEnabled(t, true)

function MyFunc()
...
openProcess("citra.exe")
writeBytes(lOffset1, iValue1)
iValue2 = readBytes(lOffset1, 2)
...

which however also does nothing. Is there any way to get some kind of automation like this done or even better, call CE directly from commandline and pass a lua.script as argument which will be executed after (not on) startup?

Trainers are not an option as I tend to manually search/patch something new almost every time. I just want to use vanilla CE with a few commands after the start.
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Sun Jul 03, 2016 7:25 pm    Post subject: Reply with quote

Add it to autorun folder
_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jul 03, 2016 7:41 pm    Post subject: Reply with quote

Code:
getAutoAttachList().add("game.exe")
function onOpenProcess(processId)
  reinitializeSymbolhandler()
  -- enable whatever
end
Back to top
View user's profile Send private message
user669
How do I cheat?
Reputation: 0

Joined: 03 Jul 2016
Posts: 3

PostPosted: Mon Jul 04, 2016 5:35 am    Post subject: Reply with quote

STN wrote:
Add it to autorun folder

...
thats not what I want. CE gets called automatically, however it doesn't load the lua script.

Zanzer wrote:
Code:
getAutoAttachList().add("game.exe")
function onOpenProcess(processId)
  reinitializeSymbolhandler()
  -- enable whatever
end


Wow this actually works, even with openProcess(pid). getAutoAttachList().add() is missing in the documentation...

Just a problem, onOpenProcess gets called multiple (3-4) times.
Code:
getAutoAttachList().add("citra.exe")
function onOpenProcess()
   reinitializeSymbolhandler()
   showMessage("onProcess called")
end


Is there a way to fix this or do I have to rely on toggle-booleans?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4722

PostPosted: Mon Jul 04, 2016 8:54 am    Post subject: Reply with quote

user669 wrote:
getAutoAttachList().add() is missing in the documentation...
main.lua wrote:
getAutoAttachList(): returns the AutoAttach StringList object.
...
Stringlist Class: (Inheritance : Strings->Object)
...
Strings Class: (Inheritance : Object) (Mostly an abstract class)
properties
Text : String - All the strings in one string
Count: Integer - The number of strings in this list
String[]: String - Array to access one specific string in the list
[] = String[]

methods
clear() : Deletes all strings in the list
add(string) : adds a string to the list
delete(index) : Deletes a string from the list
...


user669 wrote:
Just a problem, onOpenProcess gets called multiple (3-4) times... Is there a way to fix this or do I have to rely on toggle-booleans?
main.lua wrote:
function onOpenProcess(processid):
If this function is defined it will be called whenever cheat engine opens a process.
Note: The the same process might be opened multiple times in a row internally
Note 2: This function is called before attachment is fully done. You can call reinitializeSymbolhandler() to force the open to complete, but it will slow down process opens. Alternatively, you could launch a timer which will run when the opening has finished

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
user669
How do I cheat?
Reputation: 0

Joined: 03 Jul 2016
Posts: 3

PostPosted: Mon Jul 04, 2016 10:16 am    Post subject: Reply with quote

ParkourPenguin wrote:
...

Yes I figured it out already, turns out wiki.cheatengine.org/index.php?title=Lua is missing a ton of stuff. May someone updates it.
reinitializeSymbolhandler() does not solve anything though, onOpenProcess(processId) will nontheless get called 3-4 times. However processId will be 0 on every call except the last one. So my approach is a little different:
Code:
--main.lua:
if getProcessIDFromProcessName("citra.exe") == nil then
   --quit if process not found
   return
end
getAutoAttachList().add("citra.exe")

function onOpenProcess(processId)
  if processId ~= getProcessIDFromProcessName("citra.exe") then
     --onOpenProcess() gets called multiple times, but only the very last call should have a valid processId
     return
  end
  --Do all stuff here
end
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 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