| jgoemat Master Cheater
 
 ![]() Reputation: 23 
 Joined: 25 Sep 2011
 Posts: 264
 
 
 | 
			
				|  Posted: Sat Jun 16, 2018 3:08 am    Post subject: Easy CE Lua calling from aa script |     |  
				| 
 |  
				| 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
 | 
 
 
 
 
	
		
	 
		| Description: | 
			
				| LUA script with CELUA_SYNC and CELUA_ASYNC AA commands |  |  Download
 |  
		| Filename: | CELUA.lua |  
		| Filesize: | 10.77 KB |  
		| Downloaded: | 1755 Time(s) |  
 |  |