Write value of a lua variable to an address

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
User avatar
nihilism
Novice Cheater
Novice Cheater
Posts: 24
Joined: Thu Mar 29, 2018 1:28 am
Reputation: 1

Write value of a lua variable to an address

Post by nihilism » Sat Jun 30, 2018 5:40 am

Just messing around with different mono hacking methods, but stuck at this part. I was able to use the mono lua commands to consistently get the base address that I want to use for pointers/other codes. But not able to get that to write to the symbol I made for it.



Thought at first maybe value is not in the correct format but no dice with conversions.



Think I am missing an obvious step. Please point me in the right direction!



[CODE=lua][ENABLE]

registersymbol(baseaddress)

alloc(baseaddress,64)



baseaddress:

dd 0



{$lua}

images={}

for i=1, #a1 do

images[i]=mono_getImageFromAssembly(a1[i])



if mono_image_get_name(images[i])=="Assembly-CSharp" then

classes=mono_image_enumClasses(images[i])



for j=1, #classes do

if classes[j].classname=="GameManager" then

baseaddress=mono_class_findInstancesOfClassListOnly(d[1],classes[j].class)

--print(string.format("%.8x",baseaddress[1]))

end

end

end

end



--[[addy=readStringLocal(baseaddy,8)

temp=stringToByteTable(addy)

addy1=byteTableToDword(temp)

--]]

{$asm}



[DISABLE]



unregistersymbol(baseaddress)

dealloc(baseaddress)[/CODE]

User avatar
koderkrazy
Fearless Donors
Fearless Donors
Posts: 174
Joined: Sun Jun 17, 2018 2:14 pm
Reputation: 1

Write value of a lua variable to an address

Post by koderkrazy » Sat Jun 30, 2018 10:00 am

Hey try this:

[CODE=lua]local myLuaAddr = mono_class_findInstancesOfClassListOnly(d[1],classes[j].class)

writeQword('baseaddress', myLuaAddr) --if it is 64bit address

--or writePointer('[baseaddress]', myLuaAddr) if you want to write to address pointed by baseaddress directly[/CODE]



See attached table for example:

1. connect to any process. May be connect to Cheat Engine itself.

2. Load the example table.

3. Run [B]CreateASMVariable [/B]script

4. Keep hitting '[B]Add 5 in Lua[/B]' script.

User avatar
nihilism
Novice Cheater
Novice Cheater
Posts: 24
Joined: Thu Mar 29, 2018 1:28 am
Reputation: 1

Write value of a lua variable to an address

Post by nihilism » Sat Jun 30, 2018 2:31 pm

Thanks a lot that helped me find what was wrong.



My main problem though is that my lua variable was a table so I needed to add [1] to get the value I wanted.



Knew it was something obvious. Thanks again.

tabman
Noobzor
Noobzor
Posts: 7
Joined: Sun Jun 10, 2018 2:15 pm
Reputation: 0

Write value of a lua variable to an address

Post by tabman » Fri Aug 03, 2018 1:42 pm

You can also allocate memory and register symbols by means of lua:

[CODE=lua]{$Lua}

[ENABLE]



local size = 4

addr = allocateMemory(size)



--unlike autoassembler, registerered symbol must be unregistered first

unregisterSymbol("var")

registerSymbol("var",addr)



local val = 10

writeInteger("var",val)

--or

--writeInteger(addr,val)



[DISABLE]



unregisterSymbol("var")

deAlloc(addr)[/CODE]

Post Reply