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 


Using lua variables in autoassemble

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

Joined: 19 Aug 2014
Posts: 4

PostPosted: Tue Aug 19, 2014 8:45 am    Post subject: Using lua variables in autoassemble Reply with quote

I'm totally new to lua and assembler and I didn't find any solution in the internet.

I want to print an item list into the lua output, but I'm having trouble using variables right.

For example this function which shall print pointers to items with the ID of 0 to 16 (I know the print is not in the loop, but atm I'd just like to know how to use those variables right).
Code:
itemid = 0 //item ID
item = 0 //a pointer to the item data

autoAssemble([[
alloc(mem,128)
label(.Break)
label(.While)
CreateThread(mem)


mem:
//mov itemid, 0
.While:
cmp itemid, 0x10
jae .Break

mov edx, 1 //count
mov eax, itemid //Item ID
push edx
push eax
mov ecx, [GameInternAddress] //Player
call GameInternFunction
mov pointer, eax

inc itemid

.Break:
ret

dealloc(mem)
]])

print(pointer)
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Tue Aug 19, 2014 10:19 am    Post subject: Re: Using lua variables in autoassemble Reply with quote

Nere wrote:
Your previous post


In the autoassembler,numbers are in hex by default,no need to write 0x10,write one of the following: 10 , (int)16 , #16 .
2- Labels don't start with a dot,the dot is used in structure members and library functions,like Kernel32.lstrcmpiA .
3- Wait a bit before using dealloc,here is what I'd write:
Code:

itemid = 0 //item ID
item = 0 //a pointer to the item data

autoAssemble([[
alloc(mem,128)
alloc(itemid,16)// Should be enough
alloc(pointer,16)
registersymbol(pointer)
registersymbol(itemid)
label(Break)
label(While)
CreateThread(mem)
{$lua}
writeInteger('itemid',itemid)
{$asm}
mem:
//mov itemid, 0
While:
cmp [itemid], 0x10
jae Break

mov edx, 1 //count
mov eax, [itemid] //Item ID
push edx // Is this one of the function arguments?
push eax // Is this one of the function arguments?
mov ecx, [GameInternAddress] //Player
call GameInternFunction
mov [pointer], eax
inc itemid
jmp while // return to the top
Break:
ret
{$lua}
sleep(3000) -- Should be enough
{$asm}
dealloc(mem)
unregistersymbol(itemid)
dealloc(itemid)
]])


print(('%08x'):format(readInteger'pointer'))
Back to top
View user's profile Send private message
Nere
How do I cheat?
Reputation: 0

Joined: 19 Aug 2014
Posts: 4

PostPosted: Wed Aug 20, 2014 4:12 am    Post subject: Re: Using lua variables in autoassemble Reply with quote

Redone wrote:
Nere wrote:
Your previous post


In the autoassembler,numbers are in hex by default,no need to write 0x10,write one of the following: 10 , (int)16 , #16 .
2- Labels don't start with a dot,the dot is used in structure members and library functions,like Kernel32.lstrcmpiA .
3- Wait a bit before using dealloc,here is what I'd write:

Thanks, your code helped me a lot already. Smile

But I still don't know how to connect the lua variables with assembler variables. For example, if I want to print the output:
Code:
alloc(id,4)
registersymbol(id)

...

mov [id], 10
{$lua}
print(id)
{$asm}

...
$lua and $asm seem to have different variables.
in $lua, "id" is nil and in $asm it's 10
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Wed Aug 20, 2014 4:26 am    Post subject: Re: Using lua variables in autoassemble Reply with quote

Nere wrote:
Redone wrote:
Nere wrote:
Your previous post


In the autoassembler,numbers are in hex by default,no need to write 0x10,write one of the following: 10 , (int)16 , #16 .
2- Labels don't start with a dot,the dot is used in structure members and library functions,like Kernel32.lstrcmpiA .
3- Wait a bit before using dealloc,here is what I'd write:

Thanks, your code helped me a lot already. Smile

But I still don't know how to connect the lua variables with assembler variables. For example, if I want to print the output:
Code:
alloc(id,4)
registersymbol(id)

...

mov [id], 10
{$lua}
print(id)
{$asm}

...
$lua and $asm seem to have different variables.
in $lua, "id" is nil and in $asm it's 10


id is a pointer to the variable,so it's just an address that points to your value,you used registersymbol in order to access it from Lua:
Code:
alloc(id,4)
registersymbol(id)

...

mov [id], 10
{$lua}
print(readInteger'id') -- Read a 4-bytes value stored at the symbol 'id'.
-- You can find all the functions in main.lua
{$asm}

...
Back to top
View user's profile Send private message
Nere
How do I cheat?
Reputation: 0

Joined: 19 Aug 2014
Posts: 4

PostPosted: Wed Aug 20, 2014 7:36 am    Post subject: Reply with quote

But if I use this code:

Code:
alloc(main,256)         //main thread
alloc(id,4)             //item id
registerSymbol(id)
label(Loop)
label(Break)

createThread(main)

main:
mov [id], 0

Loop:
cmp [id], A
jae Break

{$lua}
print(readInteger'id')
{$asm}
inc [id]
jmp Loop

Break:
ret

//Exit:
{$lua}
sleep(1000)
{$asm}
unregistersymbol(id)
dealloc(id)
dealloc(main)
I just get "10" printed in the output, even BEFORE the code is injected, instead of 0,1,2,...,10 o.O

Also, if I assign my script to the cheat table and enable/disable it from there, I get no output at all.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Wed Aug 20, 2014 8:40 am    Post subject: Reply with quote

The lua sections are 'preprocessors" their result is what gets assembled into aa code.
If you wish to call lua functions from inside the target process check the lua template in the aa. (Using the luapipe)

Anyhow, i recommend just doing what you need in assembler

_________________
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
Nere
How do I cheat?
Reputation: 0

Joined: 19 Aug 2014
Posts: 4

PostPosted: Wed Aug 20, 2014 8:47 am    Post subject: Reply with quote

Dark Byte wrote:
The lua sections are 'preprocessors" their result is what gets assembled into aa code.
If you wish to call lua functions from inside the target process check the lua template in the aa. (Using the luapipe)

Anyhow, i recommend just doing what you need in assembler
Any idea how to get an easy output then?
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