DhaosCollider How do I cheat?
Reputation: 0
Joined: 12 Mar 2022 Posts: 8
|
Posted: Wed Sep 30, 2026 4:08 am Post subject: Preserve TableFile Names for Older Cheat Engine Versions |
|
|
| Quote: | from 7.5 to 7.5.1:
c compiler: header files are used as table files. And tablefiles can have any name now |
As a result, if a CT file saved with CE 7.5.1 or later is opened in an older version of CE, all "TableFiles" entries may be renamed to "File0".
hookLegacyTableSave(currentCEVersion) saves the table using the legacy format, allowing findTableFile(filename) to work reliably with older versions of CE as well.
| Code: | ----------------------------------------------------------------------------------------------------
-- Preserve TableFile Names for Older Cheat Engine Versions
----------------------------------------------------------------------------------------------------
local function readFile(path)
local file = assert(io.open(path, "rb"))
local data = file:read("*a")
file:close()
return assert(data)
end
local function writeFile(path, data)
local file = assert(io.open(path, "wb"))
local result = file:write(data)
file:close()
return assert(result)
end
local function getBackupPath(path)
local base = assert(path:match("^(.*)%.[^%.\\/:]+$"))
return base..".xml"
end
local function decodeXmlAttribute(str)
local s1 = str:gsub(""", '"')
local s2 = s1:gsub("'", "'")
local s3 = s2:gsub("<", "<")
local s4 = s3:gsub(">", ">")
local s5 = s4:gsub("&", "&")
return s5
end
local function isLegacyTableFileName(name)
return not (name:match("^[%a_][%w_%.%-]*$") == nil)
end
local function convertTableFile(attributes, data)
local encodedName = assert(attributes:match('Name="(.-)"'))
local name = decodeXmlAttribute(encodedName)
assert(isLegacyTableFileName(name))
local legacyAttributes = attributes:gsub('%s+Name=".-"', "", 1)
return "<"..name..legacyAttributes..">"
..data
.."</"..name..">"
end
local function convertTableFiles(files)
return files:gsub("<File(.-)>([%s%S]-)</File>", convertTableFile)
end
local function convertLegacyTableXml(xml)
local func = function(openTag, files, closeTag)
return openTag..convertTableFiles(files)..closeTag
end
return xml:gsub("(<Files>)([%s%S]-)(</Files>)", func)
end
local function saveLegacyTable(path)
local xml = readFile(path)
writeFile(getBackupPath(path), xml)
writeFile(path, convertLegacyTableXml(xml))
end
local function hookLegacyTableSave(ver)
if (ver < 7.51) then return end
local mf = getMainForm()
local oriSave = mf.miSave.OnClick
local oriSaveAs = mf.SaveButton.Action.OnExecute
local saveAs = function(sender) oriSaveAs(sender); saveLegacyTable(mf.SaveDialog1.FileName) end
local save = function(sender) oriSave(sender); saveLegacyTable(mf.SaveDialog1.FileName) end
mf.SaveButton.Action, mf.Save1.Action = nil, nil
mf.SaveButton.OnClick, mf.Save1.OnClick = saveAs, saveAs
mf.miSave.OnClick = save
end
----------------------------------------------------------------------------------------------------
-- Execute
----------------------------------------------------------------------------------------------------
return hookLegacyTableSave(getCEVersion())
---------------------------------------------------------------------------------------------------- |
If you don't need backups, comment out or remove writeFile(getBackupPath(path), xml).
| Description: |
| It will also work if you place the Lua file in the autorun folder. |
|
 Download |
| Filename: |
hookLegacyTableSave.lua |
| Filesize: |
2.82 KB |
| Downloaded: |
5 Time(s) |
|
|