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
Cheater
Cheater
Posts: 36
Joined: Thu Mar 29, 2018 1:28 am
Reputation: 16

Write value of a lua variable to an address

Post by nihilism »

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: Select all

[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)
Last edited by nihilism on Sat Mar 21, 2020 3:06 pm, edited 1 time in total.

User avatar
koderkrazy
Expert Cheater
Expert Cheater
Posts: 254
Joined: Sun Jun 17, 2018 2:14 pm
Reputation: 190

Write value of a lua variable to an address

Post by koderkrazy »

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
Cheater
Cheater
Posts: 36
Joined: Thu Mar 29, 2018 1:28 am
Reputation: 16

Write value of a lua variable to an address

Post by nihilism »

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
Novice Cheater
Novice Cheater
Posts: 21
Joined: Sun Jun 10, 2018 2:15 pm
Reputation: 20

Write value of a lua variable to an address

Post by tabman »

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

Who is online

Users browsing this forum: No registered users