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 


Auto-attach

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

Joined: 18 Sep 2010
Posts: 1

PostPosted: Fri Aug 07, 2015 9:45 am    Post subject: Auto-attach Reply with quote

I tried the auto-attach script found in another thread

Code:
aalist=getAutoAttachList()
stringlist_add(aalist,"myprogram.exe")


but it seems it only works once, and then I have to close and re-open CE. Re-executing the script doesn't work.

How can I attach whenever I start myprogram.exe? (there will always be at most one instance of myprogram.exe running)
Back to top
View user's profile Send private message
Smellyhobo101
Newbie cheater
Reputation: 0

Joined: 21 Sep 2014
Posts: 23

PostPosted: Sun Aug 23, 2015 1:54 pm    Post subject: Reply with quote

I just figured out how to do this today.

Code:

function attach() -- this function will be called every 5 seconds

GameID = getProcessIDFromProcessName("game.exe") -- Get the Process ID of the game process

-- If CE is attached to the wrong process AND the game is running
if GameID ~= getOpenedProcessID() and GameID ~= nil then
   openProcess("game.exe") --  Attach to the game process
end

end

t = createTimer(nil, false)  -- create a Timer object and assign it to variable t.
timer_onTimer(t, attach)   -- When the timer ticks, call the function main
timer_setInterval(t, 5000) -- Sets the interval of the timer in milliseconds
timer_setEnabled(t, true) -- Turns the timer on


getOpenedProcessID() returns the process ID of the process CE is currently attached to. It returns 0 if not attached to a process.

getProcessIDFromProcessName() returns the process ID of the process name. Will return a nil value if that process isnt running.

Every 5 seconds it will check if the ID of the process matches the ID of the process CE is currently attached to. If they don't match then it will try to attach to the process again. Be careful not to set the timer interval too high. I've found that getProcessIDFromProcessName() uses a lot of CPU when called frequently. With an interval of 50ms cheat engine was using 25% of my CPU, and I have an i5-4670k.
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