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 


Easy CE Lua calling from aa script

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions
View previous topic :: View next topic  
Author Message
jgoemat
Master Cheater
Reputation: 22

Joined: 25 Sep 2011
Posts: 252

PostPosted: Sat Jun 16, 2018 3:08 am    Post subject: Easy CE Lua calling from aa script This post has 1 review(s) Reply with quote

The purpose of this script is to make it easier to call lua code in the
Cheat Engine process from the game. The following commands will be made
available:

Code:
CELUA_SYNC(functionName, arg1, arg2, ...)
CELUA_ASYNC(functionName, arg1, arg2, ...)


Reference: https://forum.cheatengine.org/viewtopic.php?t=605733

These should work in 32-bit and 64-bit tables. All flags and registers should
be preserved except for eax/rax which will hold the return value of the
function. There are a few caveats with the values you can use:

32-bit - the string you pass for each argument is used as the argument for
the push instruction. So if you call this:
Code:
CELUA_ASYNC(MyFunction, eax, [ebp+08], [pPlayer])

these push instructions will be used (args are pushed in reverse order)
Code:
push [pPlayer]
push [ebp+08]
push eax

So you can't use things like XMM registers, 16-bit values, etc. You'll have
to save those to memory or the stack yourself and load a register with the
address or something. Also since values are pushed onto the stack, a
stack reference like '[esp+28]' would not be what you expect.

64-bit - the string you pass for each argument is loaded into rax and pushed
onto the stack for sending to lua. Since the arguments are 64-bit, you should
load any 32-bit values into 32 bit registers and pass them, or put them
on the stack or in memory and pass a pointer to them. For instance:
Code:
CELUA_ASYNC(MyFunction, rcx, [ebp+10], [globals])

Will use these instructions:
Code:
mov rax,[globals]
push rax
mov rax,[ebp+10]
push rax
mov rax,rcx
push rax

In addition since rax is used you cannot use rax for any but the last argument
or it would be overwritten by earlier instructions. Finally you can't load
far addresses directly in x64 so if the symbol globals isn't in the same
memory space, you would have to load a register with the the address, like:
Code:
mov rdx,globals
CELUA_ASYNC(MyFunction, [rdx], [rax+8]) // rax as final argument is fine



CELUA.lua
 Description:
LUA script with CELUA_SYNC and CELUA_ASYNC AA commands

Download
 Filename:  CELUA.lua
 Filesize:  10.77 KB
 Downloaded:  863 Time(s)

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 Extensions 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