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 pass a value from LUA script to CE script

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Pirulito
Newbie cheater
Reputation: 0

Joined: 13 May 2017
Posts: 13

PostPosted: Sun Mar 04, 2018 8:07 pm    Post subject: How to pass a value from LUA script to CE script Reply with quote

Please, why is this CE script not working?

Code:

define(address,"GameProcess.exe"+54762B)
define(bytes,8D 4D 08 C6 45 FC 02)

[ENABLE]

assert(address,bytes)
alloc(newmem,$10)
alloc(result,$4)
registersymbol(result)

label(code)
label(return)

{$lua}
if syntaxcheck then return end
   autoAssemble(string.format("result:\ndb CA CA CA CA"))
{$asm}

newmem:

code:
  lea ecx,[ebp+08]
  mov byte ptr [ebp-04],02
  jmp return

address:
  jmp newmem
  nop
  nop
return:

[DISABLE]

address:
  db bytes
  // lea ecx,[ebp+08]
  // mov byte ptr [ebp-04],02

unregistersymbol(result)
dealloc(result)
dealloc(newmem)


All I want (this is a test, for me to learn how to pass a value from the LUA script to the CE script) is that the LUA script write the following in the CE script:

Code:

result:
  db CA CA CA CA


but it does not work. When I go to the injected code in the game, I do not see the bytes CA CA CA CA in the address defined by "result". I see the address "result" but not the bytes that I expected to be there.

How to fix it?
Thank you.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Mar 04, 2018 8:56 pm    Post subject: Reply with quote

lua code like that is run before the script is actually enabled, so "result" doesn't exist.
For something like this you can just use "return ..." instead of "AutoAssemble(...)", which will cause the returned string to be inserted as assembly code in place of the lua block, eg.

Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>0</ID>
      <Description>"Auto Assemble script"</Description>
      <LastState Activated="1"/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[enable]
alloc(result,4)
registersymbol(result)

{$lua}-- doesn't do anything we don't want to happen during a syntax check so let it run
return string.format("result:\ndb CA CA CA CA")
{$asm}
[disable]
unregistersymbol(result)
dealloc(result)
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>1</ID>
          <Description>"No description"</Description>
          <LastState Value="CA CA CA CA" RealAddress="051B0000"/>
          <ShowAsHex>1</ShowAsHex>
          <VariableType>Array of byte</VariableType>
          <ByteLength>4</ByteLength>
          <Address>result</Address>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>


I've used that a few times when I needed a lot of nops or 0 bytes etc. and didn't want to type/copy+paste them out.

Alternatively (if you really wanted to implement it as AutoAssemble) you'd need a separate script with the lua code in it that's run after the first which creates and registers result, or to use a lua timer as a delay to essentially automate the above, or look into the lua template which actually allows lua code to be called from inside the script (probably slow though, haven't really every tried to use it, however the other methods run it just once when the script is enabled, though the timer could be setup to keep looping and run after it detects a change in memory it's not exactly the same).

Oh, I think you can also do this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>2</ID>
      <Description>"Auto Assemble script"</Description>
      <LastState Activated="1"/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[enable]
alloc(result,4)
registersymbol(result)

{$lua}
value = 0xCACACACA
{$asm}
result:
 dd $value
[disable]
unregistersymbol(result)
dealloc(result)
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>3</ID>
          <Description>"No description"</Description>
          <LastState Value="CA CA CA CA" RealAddress="051A0000"/>
          <ShowAsHex>1</ShowAsHex>
          <VariableType>Array of byte</VariableType>
          <ByteLength>4</ByteLength>
          <Address>result</Address>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>


might only be implemented for 4 byte values though...

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Pirulito
Newbie cheater
Reputation: 0

Joined: 13 May 2017
Posts: 13

PostPosted: Tue Mar 06, 2018 5:05 pm    Post subject: Reply with quote

Thank you, FreeER. Your suggestion to use return solved my problem. I had many lines to write to the script so I concatenated the lines and used return on the final big string and it worked perfectly. Smile
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 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