|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Junebug How do I cheat? Reputation: 0
Joined: 19 May 2016 Posts: 2
|
Posted: Thu May 19, 2016 1:26 am Post subject: Auto Reattach after Close |
|
|
So, for example, if I wanted to set the speed of a process when it is opened like this:
Code: | strings_add(getAutoAttachList(), "filename.exe")
function onOpenProcess(processid)
reinitializeSymbolhandler()
speedhack_setSpeed(69.420)
end |
And then, if the process is closed, and opened again, have the trainer open the new process?
It seems that it doesn't try to open the process the second time, and requires closing and opening of the trainer.
I tried some things similar to code posted in this thread viewtopic.php?t=590284 but to no avail, also that code seems to cause extreme lag, at least when executed inside of CE.
Also, I'd also greatly prefer to have no trainer GUI if possible and let it run in the background, closing with task manager is fine.
I feel like this should be easy, but I've never really done much with lua.
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu May 19, 2016 8:51 am Post subject: |
|
|
Code: | function onOpenProcess(processid)
reinitializeSymbolhandler()
speedhack_setSpeed(69.420)
end
function reopenProcessThreadFunc(thread, processName)
thread.name = '"reopenProcessThread"'
while true do
if readInteger(processName)==nil then
if openProcess(processName) then
--synchronize(function () FormName.LabelName.Caption='process opened' end)
else
--synchronize(function () FormName.LabelName.Caption='process not found' end)
end
end
sleep(5000)
end
end
createNativeThread(reopenProcessThreadFunc,"processname.exe")
|
_________________
|
|
Back to top |
|
|
Junebug How do I cheat? Reputation: 0
Joined: 19 May 2016 Posts: 2
|
Posted: Thu May 19, 2016 3:52 pm Post subject: |
|
|
Oh that makes some sense, lua is a little weird but not all that complicated. Sorry if this is unusual, but I'd like to double check my understanding and ask a few questions(I'm trying to learn so I can do things for my self and perhaps help others in the future). Comments below.
Code: | function onOpenProcess(processid) --Makes CE do this when process is hooked (How does this work if it is never called? It works by itself so I don't understand it... Part of CE and not lua? The documentation page exists but is empty.)
reinitializeSymbolhandler() --Reload symbols to avoid running assembly code too early (Not sure how symbols work, haven't touched assembly in years)
speedhack_setSpeed(69.420) --Calls CE includes to set the speedhack
end
function reopenProcessThreadFunc(thread, processName) --Define's a function
thread.name = '"reopenProcessThread"' --Name's thread, not sure why this is needed. Maybe defining this function as a thread is nessecary for some reason.
while true do --Infinite loop
if readInteger(processName)==nil then --If the process is closed the value returns to nil, this checks that to avoid spamming the hook routine over and over I believe. Might not even be needed if it wouldn't hurt to just rehook over and over, could just be there to avoid spamming the console output of the two commented out lines below.
if openProcess(processName) then --Tries to rehook the process
--synchronize(function () FormName.LabelName.Caption='process opened' end) {commented out, would normally output in a console I suppose}
else
--synchronize(function () FormName.LabelName.Caption='process not found' end) {commented out, would normally output in a console I suppose}
end
end
sleep(5000)--Wait 5 seconds before restarting routine
end
end
createNativeThread(reopenProcessThreadFunc,"processname.exe") --Runs the function as a thread.
|
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu May 19, 2016 6:06 pm Post subject: |
|
|
Code: | synchronize(function () FormName.LabelName.Caption='process opened' end) |
If you have a window, with cheat list, images, buttons and etc., you can add additional label.
For example Form name is UDF1, label name is lblStatus, this line will update label caption
Code: | UDF1.lblStatus.Caption='process opened' |
I commented it out because I don't know what your form and components names are, or if you have a Form at all.
Because we are inside a thread function (which is not the main thread) and we want to access GUI components we have to use this:
Code: | synchronize(function () UDF1.lblStatus.Caption='process opened' end) |
Quote: | readInteger(processName)
If the process is closed the value returns to nil, this checks that to avoid spamming the hook routine over and over I believe. Might not even be needed if it wouldn't hurt to just rehook over and over, could just be there to avoid spamming the console output of the two commented out lines below. |
Opening process over and over will result in executing onOpenProcess function over and over.
readInteger in a loop is not a big deal. Doesn't take much CPU time.
Code: | function onOpenProcess(processid) --Makes CE do this when process is hooked (How does this work if it is never called? It works by itself so I don't understand it... Part of CE and not lua? The documentation page exists but is empty.) |
CE checks if onOpenProcess is defined, if yes it executes it.
Code: | 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 |
_________________
|
|
Back to top |
|
|
|
|
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
|
|