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 can I encode closing an open program with CE Close?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Aylin
Expert Cheater
Reputation: 2

Joined: 16 Feb 2017
Posts: 154

PostPosted: Sat Feb 17, 2018 12:51 pm    Post subject: How can I encode closing an open program with CE Close? Reply with quote

Here is a code for getting started.
When the Trainer is turned on, simultaneously .exe file is opened.
When I close the Trainer, it is shutting down .exe file.
This functionality works well

Code:
function CEImage4Click(sender)
shellExecute([[C:\Program Files (x86)\Cheat Engine 6.7\autorun\Close.bat]]);
  closeCE()
end
--------------------------------------------
shellExecute([[C:\Windows\System32\StikyNot.exe]]);
form_onClose(UDF1, CloseTrainer)
form_show(UDF1)


(I will describe the .bat file and its functionality in a separate forum.)
How can I do this opening and closing with Cheat Engine? Rolling Eyes
Without the trainer, only with the Cheat engine. Rolling Eyes
but I closed the file with "shellExecute" on the trainer,
(Game.exe, etc.) How do I relate to Cheat Engine Close?

thanks in advance for your valuable ideas.

_________________
See Hitler ! This Trainer is for you!
http://forum.cheatengine.org/viewtopic.php?t=606786
Enthusiastic people: Always one step ahead!
Do not underestimate me Master: You were a beginner in the past!
Back to top
View user's profile Send private message MSN Messenger
FreeER
Grandmaster Cheater
Reputation: 31

Joined: 09 Aug 2013
Posts: 760

PostPosted: Sat Feb 17, 2018 1:59 pm    Post subject: Reply with quote

Code:
function openExe(...)
  local before = getProcesslist()
  shellExecute(...)
  local after = getProcesslist()
  for k,v in pairs(after) do
    if not before[k] then return k,v end
  end
end
local openedPID = openExe('notepad')

local MainOnClose = MainForm.OnClose
MainForm.OnClose = function(...)
  shellExecute('taskkill', '/PID ' .. openedPID)
  return MainOnClose(...)
end


mostly seems to work, though for whatever reason CE is left running as a background process... Would probably work fine for a trainer that had it's own form rather than the MainForm used in tables (which is how I tested it).

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Aylin
Expert Cheater
Reputation: 2

Joined: 16 Feb 2017
Posts: 154

PostPosted: Sat Feb 17, 2018 3:05 pm    Post subject: Reply with quote

FreeER wrote:
Code:
function openExe(...)
  local before = getProcesslist()
  shellExecute(...)
  local after = getProcesslist()
  for k,v in pairs(after) do
    if not before[k] then return k,v end
  end
end
local openedPID = openExe('notepad')

local MainOnClose = MainForm.OnClose
MainForm.OnClose = function(...)
  shellExecute('taskkill', '/PID ' .. openedPID)
  return MainOnClose(...)
end


mostly seems to work, though for whatever reason CE is left running as a background process... Would probably work fine for a trainer that had it's own form rather than the MainForm used in tables (which is how I tested it).


Your method is used in a form (Trainer)!
Is it correct?
If so, I am looking for a method that is used with Cheat Engine.
For example; When Cheat Engine is opened, Game.exe will be opened.
And when Cheat Engine is shut down, Game.exe will close!
I'm looking for an encoding to do this.
I have this solution, I will present it with a CT and Video.
How to turn on and off Game.exe in Trainer.
I already have this encoding.
I tried and worked successfully.
But I need it with Cheat Engine.
Opening-closing, coding and path are required. Rolling Eyes

I should use this command as an LUA or DLL. etc.
What kind of coding will get me closer to the target, Master? Sad

_________________
See Hitler ! This Trainer is for you!
http://forum.cheatengine.org/viewtopic.php?t=606786
Enthusiastic people: Always one step ahead!
Do not underestimate me Master: You were a beginner in the past!
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 353

Joined: 09 May 2003
Posts: 20601
Location: The netherlands

PostPosted: Sat Feb 17, 2018 5:46 pm    Post subject: This post has 1 review(s) Reply with quote

in the OnClose method of CE have this code:
Code:

executeCode('Exit')

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater
Reputation: 17

Joined: 10 Apr 2015
Posts: 619

PostPosted: Sat Feb 17, 2018 6:50 pm    Post subject: Reply with quote

Script provide by @FreeER already gave an answer and solution, just save this script as Lua file and save to CE autorun folder.

Code:
function openExe(...)
  local before = getProcesslist()
  shellExecute(...)
  local after = getProcesslist()
  for k,v in pairs(after) do
    if not before[k] then return k,v end
  end
end
local openedPID = openExe('notepad')

local MainOnClose = MainForm.OnClose
MainForm.OnClose = function(...)
  shellExecute('taskkill', '/PID ' .. openedPID)
  return MainOnClose(...)
end



Or another version to do same process as above :

Code:
getLuaEngine().cbShowOnPrint.Checked=false
getLuaEngine().hide()

game_check_list = createStringlist()

function game_check()
getProcesslist(game_check_list)
local count = 0
for i=0,game_check_list.count-1 do
if game_check_list[i]:find("notepad") then
count = count + 1
end
end
if count > 1 then
showMessage("Can not identify game process. Use manual attach")
else
local path = 'C:\\Windows\\notepad.exe'
shellExecute(path)   ---  change to process name you wish to open
openProcess('notepad')
showMessage("Process found and opened")
return
end
game_check_list.clear()
end

function onCloseCE()
 local id = getOpenedProcessID()
 os.execute("taskkill -im "..id)
 closeCE()
 return caFree
end

game_check()
MainForm.OnClose = onCloseCE


save as a Lua file and place to CE autorun folder

_________________
Singapore Sling + Johnnie Walker + Some Peanuts....
Back to top
View user's profile Send private message
Aylin
Expert Cheater
Reputation: 2

Joined: 16 Feb 2017
Posts: 154

PostPosted: Sat Feb 17, 2018 8:19 pm    Post subject: Reply with quote

Corroder wrote:
Script provide by @FreeER already gave an answer and solution, just save this script as Lua file and save to CE autorun folder.

Code:
function openExe(...)
  local before = getProcesslist()
  shellExecute(...)
  local after = getProcesslist()
  for k,v in pairs(after) do
    if not before[k] then return k,v end
  end
end
local openedPID = openExe('notepad')

local MainOnClose = MainForm.OnClose
MainForm.OnClose = function(...)
  shellExecute('taskkill', '/PID ' .. openedPID)
  return MainOnClose(...)
end



Or another version to do same process as above :

Code:
getLuaEngine().cbShowOnPrint.Checked=false
getLuaEngine().hide()

game_check_list = createStringlist()

function game_check()
getProcesslist(game_check_list)
local count = 0
for i=0,game_check_list.count-1 do
if game_check_list[i]:find("notepad") then
count = count + 1
end
end
if count > 1 then
showMessage("Can not identify game process. Use manual attach")
else
local path = 'C:\\Windows\\notepad.exe'
shellExecute(path)   ---  change to process name you wish to open
openProcess('notepad')
showMessage("Process found and opened")
return
end
game_check_list.clear()
end

function onCloseCE()
 local id = getOpenedProcessID()
 os.execute("taskkill -im "..id)
 closeCE()
 return caFree
end

game_check()
MainForm.OnClose = onCloseCE


save as a Lua file and place to CE autorun folder



FreeER always skips these details Smile
Giving a code and questions remain in the air!
The idea of throwing in the CE Autorun Folder makes sense.
Throughout the night, I tried other options for this detail.
I used the .bat script with the Trainer in the video.

Thanks for the explanation.
Everything I learned, I'm trying to move further.
I have more ways and it is an honor to be with you again.
Code:
FreeER: Thanks again for the code.
Thanks Corroder and DB..


https://www.youtube.com/watch?v=gvds9uFcHTw&t=0s&index=70&list=PL1yPHiegVpRoWx7jy6ecTqmbejos75O37

_________________
See Hitler ! This Trainer is for you!
http://forum.cheatengine.org/viewtopic.php?t=606786
Enthusiastic people: Always one step ahead!
Do not underestimate me Master: You were a beginner in the past!
Back to top
View user's profile Send private message MSN Messenger
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