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 work with lua

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

Joined: 28 Jan 2014
Posts: 160

PostPosted: Tue Sep 06, 2016 1:46 pm    Post subject: how to work with lua Reply with quote

hi, i'm sure there is Lua tut in this forum but i couldn't find one which explains about where to write Lua scripts and how to use them and call them in AA.
but i see everyone knows how to do it...
i would appreciate a good help,
thanks

P.S.: something like this:
http://forum.cheatengine.org/viewtopic.php?p=886483#886483
but for lua

_________________
Back to top
View user's profile Send private message
Smellyhobo101
Newbie cheater
Reputation: 0

Joined: 21 Sep 2014
Posts: 23

PostPosted: Tue Sep 06, 2016 2:39 pm    Post subject: Reply with quote

To write lua scripts go to table > show cheat table lua script.

The wiki is a good place to start but has a lot of missing information. Look at main.lua in your cheat engine folder for a complete reference.

http://wiki.cheatengine.org/index.php?title=Lua

Take a look at using timers to set up an execution loop.

You can write lua in auto assembler scripts with the {$lua} tag. Like this:

Code:

[ENABLE]
{$lua}
-- everything below here is LUA
{$asm}
// everything below here is ASM


If you want your assembly code to call a lua function directly it's a bit different. First make a new auto assembler script and use the template "Call CE Lua function". Leave that script as it is and run it. Now you can call your CE lua functions from ASM like so:

Code:

alloc(NAME, 64)

NAME:
db 'functionName()',0

code:
pushad
push eax
push NAME
call LuaFunctionCall
popad


pushad and popad are probably not necessary but I had an issue with registers getting messed up once so I always do it.
Back to top
View user's profile Send private message
Nemexia55
Expert Cheater
Reputation: 0

Joined: 28 Jan 2014
Posts: 160

PostPosted: Sat Sep 10, 2016 1:52 pm    Post subject: Reply with quote

thanks for your useful info!
but i still have problem with this part:
Quote:

Code:

alloc(NAME, 64)

NAME:
db 'functionName()',0

code:
pushad
push eax
push NAME
call LuaFunctionCall
popad


pushad and popad are probably not necessary but I had an issue with registers getting messed up once so I always do it.

_________________
Back to top
View user's profile Send private message
Smellyhobo101
Newbie cheater
Reputation: 0

Joined: 21 Sep 2014
Posts: 23

PostPosted: Sat Sep 10, 2016 3:32 pm    Post subject: Reply with quote

You need to learn how to do code injection first. Plenty of tutorials on the forums on that. Then once you have your injection set up you add that code to call your LUA function.


Here's my full template for LUA hooks:

Code:
aobScanModule(NAME_inject_point,lethalleague.exe,BYTES)

registersymbol(NAME_inject_point)

alloc(code,1024)
alloc(NAME, 64)
label(NAME_code)
label(NAME_return)

NAME:
db 'functionName()',0

code:
NAME_code:
//ORIGINAL CODE

pushad
push eax
push NAME
call LuaFunctionCall
popad

jmp NAME_return

NAME_inject_point:
jmp NAME_code
//nops here
NAME_return:

[DISABLE]

NAME_inject_point:
//ORIGINAL CODE

unregistersymbol(NAME_inject_point)

dealloc(code)


To use:

1. Replace NAME with a name of your choice
2. Replace BYTES with the AOB (array of bytes) of your injection point.
3. Replace //ORIGINAL CODE with the code your jump will overwrite.
4. Make sure you have the correct amount of nops at //nops here. This depends on the amount of instructions you are overwriting. Jumps are 5 bytes, so if you overwrite 8 bytes of instructions you need 3 extra nops to overwrite the left over junk.
5. Replace functionName() with the name of the function you want to call.
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