[HELP] How to add a LUA script to a table?

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
ctl3d32
Table Makers
Table Makers
Posts: 112
Joined: Sun Nov 24, 2019 7:05 am
Reputation: 198

[HELP] How to add a LUA script to a table?

Post by ctl3d32 »

Greetings,

I'm adding the code below to a script inside a table, so that i can enable and disable it. The code bellow only works if variables "address", "original" and "newmem" are not locals. If another script uses the same variable names, it overwrites the values of these variables. When that happens, if i disable the first script the original bytes are not restored correctly and the process crashes.

Is it possible to add as many lua scripts to a table as i want using only local variables, so that i can enable and disable them?
By using local variables i can reuse this code with minimal chages. Else, i have to rename every global variable throughout the code.

Code: Select all

[ENABLE]
{$lua}
if syntaxcheck then return end
local address_list = AOBScan("F3 0F 10 * * * 00 00 0F 57 C0 0F 2F D0 F3 0F 10 * * * 00 00 0F 97 C0")
local address      = getAddress(address_list[0])
local original     = readBytes(address,8,true)
local edited       = readBytes(address,8,true)
edited[3]          = 0x11
local newmem       = allocateMemory(100,address)

local strOriginal  = "db"
for i, v in next,original do
  strOriginal = strOriginal .. string.format(" %.2X",v)
end
strOriginal = strOriginal .. string.format("\n")

local strEdited    = "db"
for i, v in next,edited do
  strEdited = strEdited .. string.format(" %.2X",v)
end
strEdited = strEdited .. string.format("\n")

local script_enable = [[
label(code)
label(return)
label(value)
newmem:
  movss xmm2,[value]
  ]].. strEdited ..[[
code:
  ]].. strOriginal ..[[
  jmp return
value:
  dd (float)1.0
address:
  jmp newmem
  nop 3
return:
]]
--print(script_enable)

local a, b = autoAssemble(script_enable, false)

[DISABLE]
{$lua}
writeBytes(address,original)
deAlloc(newmem)
Best regards,
ctl3d32
Last edited by ctl3d32 on Fri Jun 21, 2024 9:59 am, edited 7 times in total.

Paul44
RCE Fanatics
RCE Fanatics
Posts: 887
Joined: Thu Jul 27, 2017 9:02 am
Reputation: 566

Re: [HELP] How to add a LUA script to a table?

Post by Paul44 »

^ some suggestions: google...
> "cheat engine aobscan until aob exists"
> "cheat engine AOBScan with variable like registersymbol"

also: you could register symbols per memrecID:

Code: Select all

{$lua}

  -- might not work if script is enabled indirectly via lua; iow one needs to 'click' the script...
  local mrID = getAddressList().getSelectedRecord().ID
  print(mrID)

  local mySymbol = "mySymbol_"..mrID

  unregisterSymbol(string.format('mySymbol_%d',mrID))
  if not getAddressSafe(string.format('mySymbol_%d',mrID)) then
     registerSymbol(string.format('mySymbol_%d',mrID), allocateMemory(8))
  end

  local addr = getAddress( string.format('mySymbol_%d',mrID) )
  print(string.format('%X ~ %s',addr,mySymbol))

  writeQword(addr,0x0102030305050807)  -- <= proof of concept; you can now check that mem_location

Post Reply

Who is online

Users browsing this forum: No registered users