I tried a pre-built cheat engine's Lua’s XML Parser. Using a meta-method since on return cheat engine returns only 10 entries, which isn't full print.
Code: Select all
local MAX_DEPTH = 5 -- Set the maximum depth level for printing
local function printTableRecursive(tbl, indent, depth)
indent = indent or ""
depth = depth or 1
for key, value in pairs(tbl) do
if type(value) == "table" and depth < MAX_DEPTH then
print(indent .. key .. ": table")
printTableRecursive(value, indent .. " ", depth + 1)
else
print(indent .. key .. " = " .. tostring(value))
end
end
end
local function read_file(path)
local file = io.open(path, "r") -- r for read
if not file then
return nil
end
local data = file:read("*a") -- *a or *all reads the whole file
file:close()
return data
end
local fileContent = read_file('example.ct') -- CE's installation path
if not fileContent then
error("File not found or unable to read.")
end
local result = { XmlParser:ParseXmlText(fileContent) }
printTableRecursive(result)
This should be assigned to my other thread called "how to find aspect ratio for UE".
This script automatically gets aspect ratio value and insert's as new memory address into cheat engine's address list.
Code: Select all
local x = getScreenHeight()
local y = getScreenWidth()
local a = y/x
print(a)
local allocAddress = allocateMemory(0x1)
if allocAddress ~= nil then
writeFloat(allocAddress, a)
registerSymbol("MyAllocAddress", allocAddress)
if allocAddress ~= nil then
local addressList = getAddressList()
local memoryRecord = addressList.createMemoryRecord()end
if memoryRecord ~= nil then
memoryRecord.Description = "Allocated Address"
memoryRecord.Address = allocAddress
memoryRecord.Type = vtSingle --float
--memoryRecord.Value = a -- uncomment this, incase, if script fails creating an memory record.
print("Address added to the address list: " .. allocAddress)
else print("Failed to create memory record")
end
end
print("Memory allocation created at address: " .. string.format("%X", allocAddress).." "..a)
else print("Failed to allocate memory");print("Symbol not found");
end
found gettickcount() func.
gettickcount is based on, reference
https://learn.microsoft.com/en-us/windo ... ttickcount
what it could be used for: determinating how fast lua script is.
Code: Select all
function printTickCount()
local a = getTickCount(); -- milsec
local b = math.floor(a/1000); -- formating to sec
local c = math.floor(b/60); -- formating to min
local d = math.floor(c/60); -- formating to hr
local e = math.floor(d/24 * 10 ^ 2) / 10 ^ 2; -- formating to dd
print(" ")
print("Time spent since system boot: ");
print(a.." miliseconds| ",b.." seconds| ",c.." minutes| ",d.." hours| ",e.." day's| ");
print(" ")
local f = getTickCount();
local g = f-a
print("To run this script, it took your time of "..g.." miliseconds.")
end
printTickCount()
While working on threads & mono (Unity engine (Cell to sing)) i kept on crashing so, instead of long opening concert, i created (re-launch and) re-attach script.
In overall not perfect -- because need a script termination point -- if program was closed by user will.
UN-properly handled things can lead to Lua’s script error stack overflow.

(Materials for this image taken from creative commons (CC) distribution)
In a nutshell:
1# Timer – loops until process is attached to cheat engine, then self-pause’s and goes to Timer 2
2# Timer – checks if process crashed and if process crashed – timer self-pause’s and goes to Timer 1
Loop.
Code: Select all
-- PRIMARY TIMER
ExpectedProcess = 'gtutorial-x86_64.exe'; -- enter manually process title e.g. 'gtutorial-x86_64.exe' -- case sensitive !
sttimer = createTimer()
sttimer.Interval = 2000
sttimer.OnTimer = function(sttimer)
do
if getProcessIDFromProcessName(ExpectedProcess) ~= nil then
openProcess(ExpectedProcess)
sttimer.Enabled = false
ndtimer.Enabled = true
end
if readInteger(process)==nil
then
else
-- runs once AFTER process is opened.. ..
end
end
end
-- SECONDARY TIMER
ndtimer = createTimer()
ndtimer.Enabled = false -- don't run timer while first timer wasn't run
ndtimer.Interval = 2000
ndtimer.OnTimer = function(ndtimer)
do
if readInteger(process)==nil
then -- process crashed
ndtimer.Enabled = false -- disable II timer, if process crashed, or suddenly exited.
sttimer.Enabled = true -- enable first timer
-- here you can setup launch.. path's.. or other methods in order to launch app..
end
end
end
I've been writing a lot of scripts that prints (error) messages in the output.
This "script" will hide any errors or messages in lua's output.
Code: Select all
print = function() end
error = function() end
*AnyCELUAfunction* = function() end -- in practice should disable;
! Important notes: if you disable print and want to enable it again -- you will have to restart cheat engine's application or lua engine. Otherwise, you can preserve print function with "local OriginalFunction = print" and restore with "print = OriginalFunction"
in earlier thread called "Some things … known earlier" I posted that you can press ctrl+space in celua window to open drop down list to see all available celua/lua functions. Now if you want to print all available variables or functions you can use this code.
Code: Select all
local function print_G()
-- Check if it is lua function.
local function CheckForFunc(value)
return type(value) == "function" -- returns : true or false | (1 or 0) | [boolean]
end
-- Check if it is a native function.
local function CheckForNative(func)
local info = debug.getinfo(func)
return info and info.what == "C" -- lua.org/pil/23.1.html
end
-- Separate functions, native functions and variables from _G
local items = {} --
-- Collects items info from _G before printing.
for key, value in pairs(_G) do
if CheckForFunc(value) then
local label = "Function";
if CheckForNative(value) then
label = "Native Function";
end
table.insert(items, { name = key, label = label })
else table.insert(items, { name = key, label = "Variable", value = value })
end
end
-- Print results
for _, item in ipairs(items) do
local output = item.name .. " (" .. item.label .. ")"
if item.value ~= nil then
output = output .. " = " .. tostring(item.value)
end
print(output)
end
end
print_G()
Since you can disable function. You can as well modify existing functions to your needs. This is my one of my scripts there I use to save celua output to *.txt. Each time you print("Sample text") then into "output.txt" will be saved as "Sample text".
Code: Select all
local originalPrint = print -- preserve original print function
function printOutput(...)
originalPrint(...) -- call the original print function
local output = table.concat({...}, "\t") -- print in a single line
local file = io.open("output.txt", "r+") -- call R/W mode
-- create a file if file is not present in CE's directory
if not file then file = io.open("output.txt", "w+") end
file:seek("end")
file:write(output .. "\n")
file:close()
end
print = printOutput -- replace print with slightly modified print function
-- while keeping originalPrint(Print) function.
My Cheat table's quick save script.
on lua execute:
local_quicksave(true) -- will save cheat table at my document's inside of my cheat tables folder
local_quicksave(false) or local_quicksave() -- will save cheat table at cheat engine's directory
Code: Select all
function local_quicksave(state)
if process==nil then process="nil" end
if state==nil then state="false"; end
local tablename = os.date ("%Y%m%d%H%M%S").."_"..process..".CT";
quicksave, errh = saveTable(tablename);
local moving_state = state;
if(moving_state==true)then
if quicksave then
local getCT = getCheatEngineDir()..tablename
local username = os.getenv('USERNAME')
local destination = 'C:\\users\\' .. username .. '\\Documents\\My Cheat Tables'.."\\"..tablename
os.rename(getCT,destination)
print("Quicksaved at ",destination);
else if not quicksave then print("Saving error:",errh);
end
end
else
if quicksave then
print("Quicksaved at ",getCheatEngineDir()..tablename);
else if not quicksave then print("Saving error:",errh);
end
end
end
end -- closing function
local_quicksave(true)
This script gives to Address list, Color changing borders.
Spoiler

Code: Select all
if syntax_check then return end
function local_color_twist(speed,timelenght,phase)
if (phase==nil) then phase=1000; else if (phase==0) then phase=1000 end end
al = AddressList;c = 1 ;
debug_print = false;
if timelenght then
ticks=0;
local_color_timer = createTimer()
local_color_timer.Interval = 1000
local_color_timer.Enabled = true
local_color_timer.OnTimer = function()
ticks=ticks+1;
if ticks == timelenght then
local_color_timer.destroy();
local_color_timer=nil;
if debug_print then print("sending thread to kill it self. HANG ON.") end
thread:terminate();
end
end
else
if debug_print then print("Timer wasn't set. Infinity run begins. Don't forget to use local_color_twist_destroy() ") end
local_color_timer = 'fake';
end
function threadFunction(thread)
while local_color_timer do
if al.Font.Color < 0 then al.Font.Color = 0 end
c = c+phase
al.Font.Color=c
al.Color=c
border=true;if border==true then al.BorderWidth=3;al.Color=c;end
sleep(speed)
end
thread:terminate();
end
thread = createThread(threadFunction)
end
function local_color_twist_destroy()
if local_color_timer==nil then if (debug_print) then print("function already killed") end;return; end
local_color_timer = nil;
thread:terminate();
end
local_color_twist(512,nil,10054321) -- if you won't use timer then use below function to kill later this function
--local_color_twist_destroy()
-- Options:
-- Speed:
-- 0 or nil fastest , even cegui can't handle this
-- 10 slow , higher than this will be of course slower
-- timelenght
-- specific in seconds how many second's to run this
-- if not specified run "local_color_twist_destroy()" to destroy this.
-- phase:
-- how much change color (by adding)
