View previous topic :: View next topic |
Author |
Message |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Apr 04, 2016 10:49 am Post subject: How to check if CE is attached to the game? |
|
|
How to check if CE is attached to the game.exe whenever the user want to use any option on my trainer?
Without the check, if the users close the game while using my trainer, the trainer won't work properly if they start the game again and do not restart the trainer.
I suppose there are some Lua functions for such purpose?
Thanks. |
|
Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Mon Apr 04, 2016 5:38 pm Post subject: |
|
|
Code: | t=createTimer(nil, false)
t.Interval=1000
t.OnTimer=function(t)
if getOpenedProcessID() ~= 0 and readInteger("kernel32.dll") == nil then
closeCE()
end
end
t.Enabled=true |
|
|
Back to top |
|
 |
Daijobu Master Cheater
Reputation: 13
Joined: 05 Feb 2013 Posts: 301 Location: the Netherlands
|
Posted: Mon Apr 04, 2016 6:34 pm Post subject: |
|
|
To add to the above, an option as a function you can use with/in your timer function. Assuming there is only one process.
I'm not a whiz with LUA but I've used this code for my own stuff. Also, assumed is that getAutoAttachList().add("MyExecutable.exe") is configured or you executed openProcess("MyExecutable.exe") beforehand.
Code: | function pCheckProcess(module)
local pModule = tostring(module) --use input as string "executable.exe"
local pCurrentPID = getProcessIDFromProcessName(pModule)
if pCurrentPID == getOpenedProcessID() then
return true
else
if pCurrentPID and pCurrentPID ~= getOpenedProcessID() then --this one is implied above, double checking anyway.
openProcess(pCurrentPID) --attach to new PID
return true
end
return false
end
end
|
Returns true if PID from module equals attached PID.
Returns true if PID mismatches but reattaches through PID.
Returns false if both conditions mismatch (as in, there is no process that matches).
Run pCheckProcess(MyExecutable.exe). e.g.:
Code: | if pCheckProcess(MyExecutable.exe) then
print("true")
else
print("false")
end |
_________________
|
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Apr 04, 2016 9:39 pm Post subject: |
|
|
Thanks a lot, Zaner and Daijobu!
@Daijobu
So in order to use your code, I need to openProcess("game.exe") first somewhere in my Lua script? I have never done that with my trainer, but the trainer is still attached to the game.exe, it seems that it is attached to the game automatically upon start. Do I still need to use "openProcess()" in advance?
Thanks.
Edit: @Daijobu Oh, is it in the code automatically generated by CE? |
|
Back to top |
|
 |
Daijobu Master Cheater
Reputation: 13
Joined: 05 Feb 2013 Posts: 301 Location: the Netherlands
|
Posted: Tue Apr 05, 2016 6:01 am Post subject: |
|
|
It should be once you generate a trainer form. If you're creating a trainer from scratch you need to add it yourself.
Check Rydian's well written tuorial: http://forum.cheatengine.org/viewtopic.php?t=579440 _________________
|
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Tue Apr 05, 2016 11:49 am Post subject: |
|
|
Thanks for the info.  |
|
Back to top |
|
 |
|