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 


Passing variable from AA script to Lua script or vise versa

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Tue Feb 23, 2016 4:24 pm    Post subject: Passing variable from AA script to Lua script or vise versa Reply with quote

Please take a look at the following code, basically I want to catch an input and pass it to the AA script:
Code:

number = 0

t =
  {
  {
  '1',
  [[                                                        ------------ Enable AA script
  alloc(newmem,2048)
  label(returnhere)
  label(originalcode)
  label(exit)
  label(addStats1)

  newmem:
  cmp byte ptr [ebx+19],5F
  jl addStats1

  addStats1:
  add byte ptr [ebx+1C],number <----- Failed
  jmp exit

  originalcode:
  movzx eax,byte ptr [ebx+19]
  cmp eax,ecx

  exit:
  jmp returnhere

  "game.exe"+5A234A:
  jmp newmem
  nop
  returnhere:
  ]],
 
  [[                                                   -------------Disable AA script
  dealloc(newmem)
  "game.exe"+5A234A:
  movzx eax,byte ptr [ebx+19]
  cmp eax,ecx
  ]]
  }
  }


function CEButton1Click(sender)
    number = getText(UDF1.CEEdit1) <----- Failed
    autoAssemble(t[1][2])
end


I want to pass variable "number" into the AA script, can I do that?
I also tried the following and it didn't work:
Code:

  alloc(newmem,2048)
  alloc(number,16)
  ...
  label(exit)
  label(addStats1)
  registersymbol(number)

  newmem:
  ...
  jmp addStats1

  addStats1:
  {$lua}
  number = getText(UDF1.CEEdit1)
  writeInteger('number',number)
  {$asm}
  add byte ptr [ebx+19],'number'
  jmp exit
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 Feb 23, 2016 8:26 pm    Post subject: Reply with quote

Code:
  alloc(newmem,2048)
  label(returnhere)
  label(originalcode)
  label(exit)
  label(addStats1)
  label(number)               {ADDED}

  newmem:
  cmp byte ptr [ebx+19],5F
  jl addStats1

  addStats1:
  movzx eax,byte ptr [number] {ADDED}
  add byte ptr [ebx+1C],eax   {FIXED}
  jmp exit

  originalcode:
  movzx eax,byte ptr [ebx+19]
  cmp eax,ecx

  exit:
  jmp returnhere

  number:                     {ADDED}
  db 0                        {ADDED}

  "game.exe"+5A234A:
  jmp newmem
  nop
  returnhere:
  registersymbol(number)      {ADDED}

Code:
function CEButton1Click(sender)
    local number = tonumber(UDF1.CEEdit1.Text) or 0
    writeBytes("number", number)
end
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Tue Feb 23, 2016 9:07 pm    Post subject: Reply with quote

With ce 6.5, a lua global variable of type integer can be referred in AA by prefixing the variable name with a symbol '$'.
The integer number will be in hexadecimal form in AA

Code:
NUMBER = 10000 -- lua global integer variable
print(tostring(autoAssemble([[
globalalloc(cave,1000)
cave:
dq cave,$NUMBER
{$lua}
NUMBER = math.floor(math.random()*1000) -- or tonumber(getText(UDF1.CEEdit1) )
{$asm}
jmp $NUMBER
dq $NUMBER
]])))


Lua block expand before AA command, so both instance of '$NUMBER' will be the same

but, there is some inconsistency.
For example, $NUMBER cannot place on '1000' as globalalloc parameter, but can be parameters (2nd & 3rd) for range of AOBScanRegion .

Alternatively,the number value can be manually forma/gsub into the AA script:
Code:

autoAssemble(string.format([[
...
mov eax,%X
mov ebx,%X
...
]],number,number))



Code:

autoAssemble(string.gsub([[
...
...
mov eax,NUMBER
mov ebx,NUMBER
...
...
]],'NUMBER',string.format("%X",number)))

_________________
- Retarded.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Tue Feb 23, 2016 9:21 pm    Post subject: Reply with quote

Zanzer wrote:
Code:
  alloc(newmem,2048)
  label(returnhere)
  label(originalcode)
  label(exit)
  label(addStats1)
  label(number)               {ADDED}

  newmem:
  cmp byte ptr [ebx+19],5F
  jl addStats1

  addStats1:
  movzx eax,byte ptr [number] {ADDED}
  add byte ptr [ebx+1C],eax   {FIXED}
  jmp exit

  originalcode:
  movzx eax,byte ptr [ebx+19]
  cmp eax,ecx

  exit:
  jmp returnhere

  number:                     {ADDED}
  db 0                        {ADDED}

  "game.exe"+5A234A:
  jmp newmem
  nop
  returnhere:
  registersymbol(number)      {ADDED}

Code:
function CEButton1Click(sender)
    local number = tonumber(UDF1.CEEdit1.Text) or 0
    writeBytes("number", number)
end


Thanks for the detailed answer, Zaner. However, this line is causing a problem:
Code:
add byte ptr [ebx+1C],eax   {FIXED}


If I change "eax" to "1", it works, but that's not what I want, do you know what causes this bug? Thanks a lot. Smile


@panrave, the "$" and global variable worked!! Thanks a lot!
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 Feb 23, 2016 11:00 pm    Post subject: Reply with quote

Code:
add byte ptr [ebx+1C],al
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Tue Feb 23, 2016 11:03 pm    Post subject: Reply with quote

Zanzer wrote:
Code:
add byte ptr [ebx+1C],al


Thanks a lot for the help. Very Happy
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