Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Preserve TableFile Names for Older Cheat Engine Versions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
DhaosCollider
How do I cheat?
Reputation: 0

Joined: 12 Mar 2022
Posts: 8

PostPosted: Wed Sep 30, 2026 4:08 am    Post subject: Preserve TableFile Names for Older Cheat Engine Versions Reply with quote

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("&lt;", "<")
    local s4 = s3:gsub("&gt;", ">")
    local s5 = s4:gsub("&amp;", "&")
    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).



hookLegacyTableSave.lua
 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)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites