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 


How to check if CE is attached to the game?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Apr 04, 2016 10:49 am    Post subject: How to check if CE is attached to the game? Reply with quote

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
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Apr 04, 2016 5:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
Daijobu
Master Cheater
Reputation: 13

Joined: 05 Feb 2013
Posts: 301
Location: the Netherlands

PostPosted: Mon Apr 04, 2016 6:34 pm    Post subject: Reply with quote

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

_________________
Scripts/tables from scratch. Relation to other scripts is coincidental. Use of posted code is credited properly.
Euro Truck Simulator 2 Backwards Compatible Cheat
American Truck Simulator Backwards Compatible Cheat
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Apr 04, 2016 9:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
Daijobu
Master Cheater
Reputation: 13

Joined: 05 Feb 2013
Posts: 301
Location: the Netherlands

PostPosted: Tue Apr 05, 2016 6:01 am    Post subject: Reply with quote

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

_________________
Scripts/tables from scratch. Relation to other scripts is coincidental. Use of posted code is credited properly.
Euro Truck Simulator 2 Backwards Compatible Cheat
American Truck Simulator Backwards Compatible Cheat
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Tue Apr 05, 2016 11:49 am    Post subject: Reply with quote

Daijobu wrote:
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


Thanks for the info. Smile
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