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 


Execution order in AA scripts

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

Joined: 02 Oct 2014
Posts: 8

PostPosted: Tue Dec 20, 2016 6:26 am    Post subject: Execution order in AA scripts Reply with quote

Hi everyone.

I have a script in my table that includes ASM and at the end has some lua code.

The ASM works perfectly, and so does the LUA. My problem is that the LUA code seems to always run BEFORE the ASM code, no matter where I place it. I've even resorted to doing a luacall at the end of the ASM and it still runs the LUA function first.

I've attached the code for reference. This is the version where I use luacall. I've tried embedding the LUA below the ASM as well.

All help appreciated Smile

Code:
{ Game   : metro2033.exe
  Version:
  Date   : 2016-12-16
  Author : JasonD

  This script does blah blah blah
}

define(address,"Metro2033.exe"+33A561)
define(bytes,8B EC 83 E4 F8)

{$lua}
  --print("- - - - - - - - - - ")

  function do_aobscan()
    print("Doing AOB Scan")

    addresslist = getAddressList()
    aob_base_desc = [[AOB Root]]
    aob_base_mr = addresslist_getMemoryRecordByDescription(addresslist, aob_base_desc)
    aob_base_mr.Color="0x0000FF"

    -- raspberrypirules
    aob_base = "72 61 73 70 62 65 72 72 79 70 69 72 75 6C 65 73"

    aob_base_mr.Color="0xFF00FF"
    --aob_base_addr = AOBScan("72 61 73 70 62 65 72 72 79 70 69 72 75 6C 65 73")

    aob_base_addr = AOBScan("726173706265727279706972756C6573")
    print("AOB Base Addr: ", aob_base_addr)
    aob_base_scancount = aob_base_scancount + 1

    aob_base_mr.Color="0x000000"



  end

{$asm}

[ENABLE]

assert(address,bytes)
alloc(newmem,$1000)
alloc(testmem,$1000)

label(code)
label(return)

testmem:
  DB 'raspberrypirules',0

newmem:
  jmp code

code:
  mov ebp,esp
  and esp,-08
  jmp return

address:
  jmp newmem
return:

luacall(do_aobscan())

{ ---------------------------------------------------------------}
{$lua}

  print("- - - - - - - - - - ")
  --sleep(1000)

{$asm}



[DISABLE]

address:
  db bytes
  // mov ebp,esp
  // and esp,-08

dealloc(newmem)
dealloc(testmem)

{$lua}
  --
  print("Disabling test.")
  aob_base_mr.Address=""
  aob_base_mr.Color="0x0000FF"
{$asm}


{
// ORIGINAL CODE - INJECTION POINT: "Metro2033.exe"+33A561

"Metro2033.exe"+33A557: CC                       -  int 3
"Metro2033.exe"+33A558: CC                       -  int 3
"Metro2033.exe"+33A559: CC                       -  int 3
"Metro2033.exe"+33A55A: CC                       -  int 3
"Metro2033.exe"+33A55B: CC                       -  int 3
"Metro2033.exe"+33A55C: CC                       -  int 3
"Metro2033.exe"+33A55D: CC                       -  int 3
"Metro2033.exe"+33A55E: CC                       -  int 3
"Metro2033.exe"+33A55F: CC                       -  int 3
"Metro2033.exe"+33A560: 55                       -  push ebp
// ---------- INJECTING HERE ----------
"Metro2033.exe"+33A561: 8B EC                    -  mov ebp,esp
"Metro2033.exe"+33A563: 83 E4 F8                 -  and esp,-08
// ---------- DONE INJECTING  ----------
"Metro2033.exe"+33A566: F3 0F 10 89 24 08 00 00  -  movss xmm1,[ecx+00000824]
"Metro2033.exe"+33A56E: F3 0F 58 89 20 08 00 00  -  addss xmm1,[ecx+00000820]
"Metro2033.exe"+33A576: F3 0F 58 89 1C 08 00 00  -  addss xmm1,[ecx+0000081C]
"Metro2033.exe"+33A57E: A1 A4 82 A1 00           -  mov eax,[Metro2033.exe+6182A4]
"Metro2033.exe"+33A583: F3 0F 59 0D 7C 0A 96 00  -  mulss xmm1,[Metro2033.exe+560A7C]
"Metro2033.exe"+33A58B: F3 0F 59 89 10 0C 00 00  -  mulss xmm1,[ecx+00000C10]
"Metro2033.exe"+33A593: 83 EC 08                 -  sub esp,08
"Metro2033.exe"+33A596: 3B 81 C8 0B 00 00        -  cmp eax,[ecx+00000BC8]
"Metro2033.exe"+33A59C: 53                       -  push ebx
"Metro2033.exe"+33A59D: 57                       -  push edi
}

_________________

Sometimes it's better to just keep quiet. I seem to have trouble identifying those moments.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25788
Location: The netherlands

PostPosted: Tue Dec 20, 2016 6:47 am    Post subject: Reply with quote

correct, the lua code executes before aa. the result of the lua function will be interpreted by the auto assembler as native aa commands

e.g
Code:

00400500:
{$lua}
return 'db 90 90 90'


is equivalent to
Code:

00400500:
db 90 90 90

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
ToxicBunny
How do I cheat?
Reputation: 0

Joined: 02 Oct 2014
Posts: 8

PostPosted: Tue Dec 20, 2016 6:57 am    Post subject: Reply with quote

Thanks for the quick response Smile

Is there any way to get the LUA code to execute after the ASM?

Specifically, I want to do a LUA aobscan after the ASM has run.

(Has to be a LUA aobscan, not an ASM aobscan)

_________________

Sometimes it's better to just keep quiet. I seem to have trouble identifying those moments.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25788
Location: The netherlands

PostPosted: Tue Dec 20, 2016 7:39 am    Post subject: Reply with quote

launch a timer that runs after it has been executed, or try giving it children configured to activate at the same time as their parent
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
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 Dec 20, 2016 10:54 am    Post subject: Reply with quote

Inside AA script we can add Lua script blocks (it's a new feature since CE6.4). You have to treat it more or less as a text preprocessor.

Lua script doesn't know anything about what AA script is doing. And, Lua script blocks are executed before the "AA script analyzing and assembling".


But it would be a bad feature if there was not any way of passing some information from one to another. Lua script can pass some information to the AA script (can be done with "return something" at the end of Lua block).
Communication I was talking about is made only once while enabling/disabling AA script.

AA scripts and Lua scripts can get and set user symbols. We can use it to extend Lua<->AA communication.


If you want to exchange data between assembled code (working in game thread and game memory) and Lua script (working in CE thread and accessing game memory) for a longer time period, you just use user symbols.

In AA something like this: "mov [usersymbol],eax",
in Lua something like this: readInteger("usersymbol")

inside ontimer function of Lua timer object.

_________________
Back to top
View user's profile Send private message MSN Messenger
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