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 


Autorunning a lua script in a saved .exe Trainer

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
tdr2012
Cheater
Reputation: 0

Joined: 02 Nov 2014
Posts: 26

PostPosted: Mon Nov 02, 2015 11:25 am    Post subject: Autorunning a lua script in a saved .exe Trainer Reply with quote

Is there a way to run a LUA table script (not in the Cheat Table) that's part of the trainer when the trainer.exe file is launched?
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Mon Nov 02, 2015 8:31 pm    Post subject: Reply with quote

Use notepad to writing your code (as a function).
Save it as a Lua fle (example : code.lua)
Next, add that file code.lua to your trainer with Table > Add file in CE.

in your trainer script add this function (** Credit to Panraven **)

Code:

function loadTableCode(n)
 local t = findTableFile(n)
 if t ~= nil then
 local s = t.Stream
 local c = readStringLocal(s.Memory,s.Size)
 return c ~= nil and loadstring(c) -- return a function
 end
end
--
local f = loadTableCode('code.lua')
print(type(f))
if type(f) == 'function' then f() else print('not loaded') end


Sample of code.lua file
Code:

function load_myCode()
..
..
..
your script here...
end    ----- end of function load_myCode()


Next on your trainer script should be like this :

Code:

f = createForm(false)
b = cerateButton(f)
..
...
.. your other trainer script
..
if bla bla bla  then
..
..
end

load_myCode()   ------ load your code from code.lua file
..
..


After you did all, try run your trainer and if everything you think is okay, then save tour trainer as stand alone exe file.
Back to top
View user's profile Send private message
tdr2012
Cheater
Reputation: 0

Joined: 02 Nov 2014
Posts: 26

PostPosted: Mon Nov 02, 2015 11:43 pm    Post subject: Reply with quote

Corroder wrote:
Use notepad to writing your code (as a function).
Save it as a Lua fle (example : code.lua)
Next, add that file code.lua to your trainer with Table > Add file in CE.

in your trainer script add this function (** Credit to Panraven **)

Code:

function loadTableCode(n)
 local t = findTableFile(n)
 if t ~= nil then
 local s = t.Stream
 local c = readStringLocal(s.Memory,s.Size)
 return c ~= nil and loadstring(c) -- return a function
 end
end
--
local f = loadTableCode('code.lua')
print(type(f))
if type(f) == 'function' then f() else print('not loaded') end


Sample of code.lua file
Code:

function load_myCode()
..
..
..
your script here...
end    ----- end of function load_myCode()


Next on your trainer script should be like this :

Code:

f = createForm(false)
b = cerateButton(f)
..
...
.. your other trainer script
..
if bla bla bla  then
..
..
end

load_myCode()   ------ load your code from code.lua file
..
..


After you did all, try run your trainer and if everything you think is okay, then save tour trainer as stand alone exe file.

Awesome.

I was able to do all of the above steps, and yes, it does autorun the script when I launch the standalone .exe trainer file now. I do have one other question though.

When the trainer .exe file runs with the call to load_myCode() function (after doing all the steps above), a Lua Engine window appears each time. Is there a way to make it so this windows doesn't appear on launch each time?

Thanks so much, again.
Back to top
View user's profile Send private message
lolAnonymous
Expert Cheater
Reputation: 1

Joined: 19 Jul 2015
Posts: 154

PostPosted: Tue Nov 03, 2015 1:05 am    Post subject: Reply with quote

Put This In The Starting Of Your Trainer Script Wink

Code:
getLuaEngine().cbShowOnPrint.Checked=false
getLuaEngine().hide()
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Tue Nov 03, 2015 7:12 am    Post subject: Reply with quote

Question solved by MasterHacking...

Regard
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Nov 03, 2015 8:16 am    Post subject: Reply with quote

"Lua Engine window appears each time"
because of a print line, one before last, in Corroder post. just remove this line.



Better do not hide "Lua Engine". If something goes wrong, you won't get any feedback. Just write a script the proper way.

An example, my script which adds Redo (undo) functionality into CE's "Disassembler View":
http://forum.cheatengine.org/viewtopic.php?t=585076

Script looks and works pretty good. Today I found out that I forgot to handle some "unexpected" situations. The problem occurs when AA script tries to alter some bytes on non-writable memory page.

I got feedback in Lua Engine window. I updated my script to version 1.04 today, now my script is even better than before.

_________________
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Tue Nov 03, 2015 7:33 pm    Post subject: Reply with quote

mgr.inz.Player,

Is this "Undo" function should work only in AA or for whole we changed in CE?. I mean, example : We do manually scan for an AOB and replace it with our code. Can we "undo" the AOB return back to their original with the function ?. Sorry, I am not try it yet.

Thank you and regard
Back to top
View user's profile Send private message
lolAnonymous
Expert Cheater
Reputation: 1

Joined: 19 Jul 2015
Posts: 154

PostPosted: Tue Nov 03, 2015 7:42 pm    Post subject: Reply with quote

Hey Corroder,

Yes Corroder I think we can undo the Aob we change but remember u should know the place of that aob in memory viewer I mean when u scan a aob click on it and press Ctrl+D then do the change what u want... It will help u to know from where this aob came...

Thanks[/list]
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Tue Nov 03, 2015 8:23 pm    Post subject: Reply with quote

Here is an AOB scan and replace with disable logic.
http://forum.cheatengine.org/viewtopic.php?p=5620925
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Wed Nov 04, 2015 10:28 am    Post subject: Reply with quote

Thank Zanzer,

So if I am not wrong,

this :
local pattern = "48 83 EC 28 E8 ?? ?? ?? ?? 48 83 C4 28"
local replace = "?? ?? ?? ?? 90 90 90 90 90 ?? ?? ?? ??"

will replace "E8 ?? ?? ?? ??" with "90 90 90 90 90" for every match pattern found in whole process memory get opened ignoring the addresses too.

Then it should work too if I am use same function to return back the AOB pattern as their original AOB (Like toggle on/off function), right ?.

Regard
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Wed Nov 04, 2015 6:01 pm    Post subject: Reply with quote

That is correct.
Back to top
View user's profile Send private message
tdr2012
Cheater
Reputation: 0

Joined: 02 Nov 2014
Posts: 26

PostPosted: Fri Nov 06, 2015 11:21 am    Post subject: Reply with quote

mgr.inz.Player wrote:
"Lua Engine window appears each time"
because of a print line, one before last, in Corroder post. just remove this line.



Better do not hide "Lua Engine". If something goes wrong, you won't get any feedback. Just write a script the proper way.

An example, my script which adds Redo (undo) functionality into CE's "Disassembler View":
h?ttp://forum.cheatengine.org/viewtopic.php?t=585076

Script looks and works pretty good. Today I found out that I forgot to handle some "unexpected" situations. The problem occurs when AA script tries to alter some bytes on non-writable memory page.

I got feedback in Lua Engine window. I updated my script to version 1.04 today, now my script is even better than before.


Thanks for the share. This is pretty good! And yes, you're right, it probably is better to leave the lua engine window to open. I just found that one of my scripts was stuck in an endless loop, but was still performing what I wanted it to do. If I didn't leave the Lua engine window open, I wouldn't have seen the repeated call to one of my functions.
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