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 


Creating a Lua Trainer to open an exe and close when the exe

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

Joined: 20 Jul 2020
Posts: 9

PostPosted: Fri Jun 11, 2021 3:50 pm    Post subject: Creating a Lua Trainer to open an exe and close when the exe Reply with quote

Hello everybody

Super Noob here ,

i managed to create a lua EXE trainer with a one button toggle to apply an AOB replacement on a game that works very well ( toggle the game between 30 and 60 fps).

i would like to create a new Trainer that when started:

1 - open the game (i know the code for that : shellExecute([[c:\program files\blabla\mygame\mygamesexe.exe]]); )
2 - wait 5 secondes that game is launched to then:
3 - apply the AOB replacement automatically by itself (without any button toggle needed)
4 - close the trainer and kill all the Trainer process (i see 3 trainer process in task manager ) when/if the game is closed first by user (me haha)

all this by being hidden in the back when running in order to not losing focus on the full screen game (i know how to do this as i applied it to my first trainer i explained about in the start (add "--" in front of CETrainer.show in the lua scipt)

well i know it is a lot but i need help after 22 hours of search haha)

thanks a lot for any help
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Fri Jun 11, 2021 5:33 pm    Post subject: Reply with quote

Code:
shellExecute([[c:\program files\blabla\mygame\mygamesexe.exe]])
while not openProcess("process.exe") do
   sleep(100);
   if os.clock() > 300 then closeCE() end -- if the process has not been opened after 5 minutes terminate the trainer
end
sleep(5000) -- pause for 5 seconds
-- do your script/aobscan/etc
-- you can do in lua aobscan or just toggle a script
addressList.getMemoryRecordByDescription('myAAscript').active = true

closeCE()

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
Gorimaa
How do I cheat?
Reputation: 0

Joined: 20 Jul 2020
Posts: 9

PostPosted: Sat Jun 12, 2021 2:10 am    Post subject: Reply with quote

hi again , i just tried, well i already wrote a reply but idk it has disapeared Sad

so i will write it again as things dont work out yet.

first let me present you my original AA script to toggle 60hz in my actual trainer and its LUA script attached :



edit : **ARGHH I AM NOT ALLOWED TO POST CODE (SAYING URL YET (?))


this one has to be modified i think in order to make the LUA trainer aplly directly and automatically the AOB replcement when launched, or maybe it has to be done in the LUA script ?

here it how it is for amnually toggle over 30 and 60hz, being invisible ("--" commented in front of "CETrainer.show()"


**ARGHH I AM NOT ALLOWED TO POST CODE (SAYING URL YET (?))


i dont know how is embeded the AA script inside ... anyway here is the modfied script with your recommandations:


edit : ***ARGHH I AM NOT ALLOWED TO POST CODE (SAYING URL YET (?))

So, so far the game is launching (if you look of the path, it directs to a shortcut, this is because the game is crashing if i dont go through a shotcut, same if launched with a .bat file)


but:
- FRAPS fps displayer mysteriously doesnt show any overlay display of FPS anymore
- the AOB replacement is not applied automatically (maybe logic as there is no code to automatically enable it , but also no button toggling works anymore
- when i quit the game, i am not sure maybe the CE process is killed, but not the 3 process of the trainer ( .EXE, and 2 times a .EXE32)

as a reminder the trainer windows is made invisble in order to not lose full screen game focus when trainer is launched 5 secondes later of the game

well i hope we ll find a way

i really would like to thank you again and anybody than can contribute

edit : HOW COULD I SHOW YOU MY SCRIPTS ?
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Sat Jun 12, 2021 5:07 am    Post subject: Reply with quote

Try uploading the script to pastebin or any other alternative.

Copy pasting the script, modifying the "myAAscript" (in line 9) to your corresponding script in cheat engine address list, the 'active' property is toggling (enabling) the script.

Don't forget to modify the process.exe (in line 2) to your game process name.

There is no GUI or any thing so any other lua script is not mandatory (e.g CETrainer).

The script should close cheat engine right after activation including the other sub processes, save the cheat engine table as an executable and try running it.

You could increase the delay (line 6) from 5000 to any other amount of time (in milliseconds)

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
Gorimaa
How do I cheat?
Reputation: 0

Joined: 20 Jul 2020
Posts: 9

PostPosted: Sun Jun 13, 2021 12:05 pm    Post subject: Reply with quote

shellExecute([[E:\Games\Castle of Illusion\shortcut pour batch.lnk]])
while not openProcess("coi.exe") do
sleep(100);
if os.clock() > 300 then closeCE() end -- if the process has not been opened after 5 minutes terminate the trainer
end
sleep(5000) -- pause for 5 seconds
-- do your script/aobscan/etc
-- you can do in lua aobscan or just toggle a script
openProcess("coi.exe")
local pattern = "00 00 00 40 60 E5 A0 3F 02 2B 07 3D"
local replace = "7B 14 AE 47 E1 7A 84 3F 0A D7 23 3C"
-- edit the name of the cheat
-- edit the pattern to search
-- edit the replacement bytes
-- use ?? to ignore the bytes
-- do not edit the code below
local scans = AOBScan(pattern)
if scans == nil then
showMessage("Unable to find pattern:\n"..pattern)
else
local saved = {}
local length = (#replace + 1) / 3
for i = 0, scans.Count - 1 do
local backup = readBytes(scans[i], length, true)
local bytes = {}
for hex in string.gmatch(replace, "%S+") do
local size = #bytes + 1
if hex == "??" then
bytes[size] = backup[size]
else
bytes[size] = tonumber(hex, 16)
end
end
saved[i] = backup
writeBytes(scans[i], bytes)
end
_G[cheat_name] = {
["scans"] = scans,
["saved"] = saved
}
end

closeCE()


here is my lua script


it does work but i receive an error i think because of the shortcut i use to launch the game :
Error:[string "shellExecute([[E:\Games\Castle of Illusion\sh..."]:39: table index is nil
Error:[string "shellExecute([[E:\Games\Castle of Illusion\sh..."]:40: table index is nil
Error:[string "shellExecute([[E:\Games\Castle of Illusion\sh..."]:40: table index is nil
Error:[string "shellExecute([[E:\Games\Castle of Illusion\sh..."]:40: table index is nil
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun Jun 13, 2021 12:58 pm    Post subject: Reply with quote

You don't set "cheat_name" in the script. So it's likely nil thus "table index is nil".
_________________
Back to top
View user's profile Send private message Visit poster's website
Gorimaa
How do I cheat?
Reputation: 0

Joined: 20 Jul 2020
Posts: 9

PostPosted: Sun Jun 13, 2021 11:25 pm    Post subject: Reply with quote

thanks for reply!
i was thinking as i past the AA script to the LUA script, cheat table wasnt needed...

i just tried another way like this:


shellExecute([[E:\Games\Castle of Illusion\shortcut pour batch.lnk]])
while not openProcess("coi.exe") do
sleep(100);
if os.clock() > 300 then closeCE() end -- if the process has not been opened after 5 minutes terminate the trainer
end
sleep(5000) -- pause for 5 seconds
-- do your script/aobscan/etc
-- you can do in lua aobscan or just toggle a script
addressList.getMemoryRecordByDescription('le60').active = true

closeCE()

with the "le60" being the name of my aa script listed in the cheat table as "le60"

but here are the error return:

Error:[string "--TRAINERGENERATORSTART--
..."]:27: attempt to index a nil value (global 'addressList')
Error:[string "--TRAINERGENERATORSTART--
..."]:27: attempt to index a nil value (global 'addressList')
Error:[string "shellExecute([[E:\Games\Castle of Illusion\sh..."]:39: table index is nil
Error:[string "
..."]:10: attempt to index a nil value (global 'addressList')



for info here is the AA script :

{$lua}
if syntaxcheck then return end
cheat_name = "MyCheat"
[ENABLE]
local pattern = "00 00 00 40 60 E5 A0 3F 02 2B 07 3D"
local replace = "7B 14 AE 47 E1 7A 84 3F 0A D7 23 3C"
-- edit the name of the cheat
-- edit the pattern to search
-- edit the replacement bytes
-- use ?? to ignore the bytes
-- do not edit the code below
local scans = AOBScan(pattern)
if scans == nil then
showMessage("Unable to find pattern:\n"..pattern)
else
local saved = {}
local length = (#replace + 1) / 3
for i = 0, scans.Count - 1 do
local backup = readBytes(scans[i], length, true)
local bytes = {}
for hex in string.gmatch(replace, "%S+") do
local size = #bytes + 1
if hex == "??" then
bytes[size] = backup[size]
else
bytes[size] = tonumber(hex, 16)
end
end
saved[i] = backup
writeBytes(scans[i], bytes)
end
_G[cheat_name] = {
["scans"] = scans,
["saved"] = saved
}
end
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Jun 14, 2021 4:33 am    Post subject: Reply with quote

You don't set "addressList" so it's nil, you probable want "AddressList" it's set by CE.
_________________
Back to top
View user's profile Send private message Visit poster's website
Gorimaa
How do I cheat?
Reputation: 0

Joined: 20 Jul 2020
Posts: 9

PostPosted: Mon Jun 14, 2021 10:27 pm    Post subject: Reply with quote

i really dont know how to do that . i dont even undertsand why it needs an adress list as it is a AOB scan and replacement Smile...

Is somebody could help to correct my script ? i am still too noob to do it, very sorry but would be happy it we could figure out jow to make it works

Massive thanks to one and all
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Tue Jun 15, 2021 5:29 am    Post subject: Reply with quote

Where it tells you at line 27 "attempt to index a nil value (global 'addressList')". That's where you're using the address list to activate a memory record. There you're using "addressList" which is nil like the error message says. You either need to set "addressList" to the address list object or use the global variable CE provides which is "AddressList". Thus all you need to do at this point is change "addressList" to "AddressList". If that's going over your head you should probably forgo the trainer at this point and just focus on the table and use it in that way, then do some lua tutorials and come back to the trainer later. Else you'll be asking for someone to fix it for you with every error you have.
_________________
Back to top
View user's profile Send private message Visit poster's website
Gorimaa
How do I cheat?
Reputation: 0

Joined: 20 Jul 2020
Posts: 9

PostPosted: Thu Jun 17, 2021 12:44 am    Post subject: Reply with quote

Mannn,

THAT'S IT, it's working !... and perfectly, wow only changing to "Adresslist" made it,

i would like to deeply thank you and of course Daspammer!

You both rock !

massive thanks again and again

Have a great day 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 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