--[====================================================================================================================[ I2 Cheat Engine Table Updater Version: 1.1.2 1.0.1: * Initial setup. 1.0.5: * Added auto save ("AutoSave") setting and functionality (default: true). - Auto saves loaded table/trainer after download, using the name generated with "FileNameFormat". * Added force update ("ForceUpdate") setting and functionality (default: false). - Forces table/trainer update by closing CE if user selects no. 1.1.1: * Changed some file name format keys. * Changed setting "VersionUrl" to "VersionFileUrl". 1.1.2: * Fixed "ForceSaveMessage" setting name, changed to "ForcedMessage". Author: Matt - TheyCallMeTim13 - MattI2.com Features: - Auto updates table (".CT") or trainer (".CETRAINER") files from a URL. - Settings: TableVersion: TableName: TableUrl: VersionFileUrl: FileExtension: DefaultVersion: FileNameFormat: ForceUpdate (default: false): Forces table/trainer update by closing CE if user selects no. AutoSave (default: true): Auto saves loaded table/trainer after download, using the name generated with "FileNameFormat". NewLine: Messages: NewVersionMessage: DownloadQuestion: SavedMessage: UserSaveMessage: ForcedMessage: ClosingMessage: HasLatestMessage: Keys: TrainerOrigin Process UserDir HomeDir AppData Temp CheatEngineDir HomeDir CheatTablesDir UserName FileName TableName Version VersionNumer FileExtension TableTitle GameTitle Examples: Version File: 3.0.9 http://fearlessrevolution.com/index.php?attachments/mgsvtpp-v3-0-9-ct.9549/ Code: require('I2CETUpdater') CETUpdater.checkTableVersion(versionFileUrl, tableVersion, tableName) Code: require('I2CETUpdater') CETUpdater.TableVersion = '3.0.8' CETUpdater.TableName = 'mgsvtpp' CETUpdater.VersionFileUrl = 'https://docs.google.com/document/d/1pPgHNGV1-EmIpfxxXp0vnoeoZxlCg11ofdV1x78bJEw/export?format=txt' CETUpdater.FileNameFormat = '${TableName}.[v${Version}].${FileExtension}' CETUpdater.checkTableVersion() Code: local url = 'https://docs.google.com/document/d/1pPgHNGV1-EmIpfxxXp0vnoeoZxlCg11ofdV1x78bJEw/export?format=txt' require('I2CETUpdater') CETUpdater.FileNameFormat = '${Process}.${FileExtension}' CETUpdater.checkTableVersion(url, '3.0.8', 'mgsvtpp') Code: local url = 'https://docs.google.com/document/d/1pPgHNGV1-EmIpfxxXp0vnoeoZxlCg11ofdV1x78bJEw/export?format=txt' require('I2CETUpdater') CETUpdater.ForceUpdate = true CETUpdater.AutoSave = true CETUpdater.NewLine = '\n' CETUpdater.FileNameFormat = '${TrainerOrigin}' CETUpdater.NewVersionMessage = 'There is a newer version of this table/trainer.' CETUpdater.DownloadQuestion = 'Would you like to download it now?' CETUpdater.SavedMessage = 'New table/trainer saved.' CETUpdater.ForcedMessage = 'Sorry but the table/trainer creator thinks it\'s best to use the latest version!' CETUpdater.ClosingMessage = 'Now Closing Cheat Engine' CETUpdater.HasLatestMessage = 'You currently have the latest version!' CETUpdater.checkTableVersion(url, '3.0.8', 'mgsvtpp') Code: local url = 'https://docs.google.com/document/d/1pPgHNGV1-EmIpfxxXp0vnoeoZxlCg11ofdV1x78bJEw/export?format=txt' require('I2CETUpdater') CETUpdater.ForceUpdate = false CETUpdater.AutoSave = true CETUpdater.FileNameFormat = '${Process}.${FileExtension}' CETUpdater.UserSaveMessage = 'Be sure to save the new table/trainer!' CETUpdater.checkTableVersion(url, '3.0.8', 'mgsvtpp') ]====================================================================================================================]-- local NAME = 'I2 Cheat Engine Table Updater' local CLASS_NAME = 'I2CETUpdater' local VERSION = '1.1.2' local AUTHOR = 'Matt Irwin; Matt.Irwin.US@Gmail.com' local LICENSE = [=[MIT License Copyright (c) 2018 Matt Irwin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]=] local format = string.format local strE = string.empty or STRING_EMPTY or '' local t = translate -- ---- Logger -- local Logger = { -- LEVELS = { -- OFF = 0, -- FATAL = 1, -- ERROR = 2, -- WARN = 3, -- INFO = 4, -- DEBUG = 5, -- TRACE = 6 -- }, -- } -- for k, v in pairs(Logger.LEVELS) do -- -- Logger[k:lower()] = function( ... ) return end -- -- Logger[k:lower() .. 'f'] = function( ... ) return end -- Logger[k:lower()] = function(msg, ex) return print(msg, ex) end -- Logger[k:lower() .. 'f'] = function(msg, ... ) return print(string.format(msg, ... )) end -- end local Logger = Logger if Logger == nil then if type(CETrequire) == 'function' then Logger = CETrequire('I2CETLogger') else Logger = require('I2CETLogger') end Logger.LogName = 'CETupdater' end -- ---- Helpers if type(CETrequire) == 'function' then I2CEHelpers = CETrequire('I2CEHelpers') else I2CEHelpers = require('I2CEHelpers') end -- local function split(s, delimiter) -- result = {} -- for match in (s .. delimiter):gmatch('(.-)' .. delimiter) do -- table.insert(result, match) -- end -- return result -- end local function split(s, delimiter) return I2CEHelpers.split(s, delimiter) end -- local function interp(s, tbl) -- if s == nil then return end -- return (s:gsub('($%b{})', function(w) return tbl[w:sub(3, -2)] or w end)) -- end local function interp(s, tbl) return I2CEHelpers.interp(s, tbl) end -- ---- local defaultFileExtension = 'CT' local defaultNewLine = '\n' local sep = package.config:sub(1,1) -- ---- CETUpdater CETUpdater = { Name = NAME, ClassName = CLASS_NAME, Version = VERSION, Author = AUTHOR, License = LICENSE, -- ---- Settings TableVersion = TABLE_VERSION, TableName = TABLE_TITLE, TableUrl = TABLE_URL, VersionFileUrl = VERSION_FILE_URL, FileExtension = defaultFileExtension, DefaultVersion = '1.0.1', FileNameFormat = '${TableName}.[v${Version}].${FileExtension}', ForceUpdate = false, AutoSave = true, NewLine = defaultNewLine, -- ---- Messages NewVersionMessage = 'There is a newer version of this table/trainer.', DownloadQuestion = 'Would you like to download it now?', SavedMessage = 'New table/trainer saved.', UserSaveMessage = 'Be sure to save the new table/trainer!', ForcedMessage = 'Sorry but the table/trainer creator thinks it\'s best to use the latest version!', ClosingMessage = 'Now Closing Cheat Engine', HasLatestMessage = 'You currently have the latest version!', } function CETUpdater.getVersionNumber(versionString) if type(versionString) ~= 'string' then local msg = format('"versionString" must be a string: %s', type(versionString)) Logger.error(msg) error(msg) return end local vers = { string.match(versionString, '(%d+)%.(%d+)%.(%d+)') } local verStr = '' for i = 1, #vers do verStr = format('%s%08X', verStr, tonumber(vers[i] or '0')) end return tonumber(verStr, 16) end function CETUpdater.getTableFileName(versionStr, tableUrl, tableName) if type(versionStr) ~= 'string' then local msg = format('"versionStr" must be a string: %s', type(versionStr)) Logger.error(msg) error(msg) return end if type(tableUrl) ~= 'string' then local msg = format('"tableUrl" must be a string: %s', type(tableUrl)) Logger.error(msg) error(msg) return end if type(tableName) ~= 'string' then local msg = format('"tableName" must be a string: %s', type(tableName)) Logger.error(msg) error(msg) return end local tbl = { TrainerOrigin = TrainerOrigin, Process = process, UserDir = (os.getenv('USERPROFILE') or '~') .. sep, HomeDir = (os.getenv('HOMEPATH') or os.getenv('HOME')) .. sep, AppData = os.getenv('APPDATA') .. sep, Temp = os.getenv('TEMP') .. sep, CheatEngineDir = getCheatEngineDir() .. sep, HomeDir = os.getenv('HOME') or strE, CheatTablesDir = os.getenv('CE_CHEATTABLES') or strE, UserName = os.getenv('CE_USERNAME') or os.getenv('USERNAME') or strE, TableName = tableName, Version = versionStr, VersionNumer = CETUpdater.getVersionNumber(versionStr), FileExtension = CETUpdater.FileExtension or defaultFileExtension, TableTitle = TABLE_TITLE or strE, GameTitle = GAME_TITLE or strE, } return interp(CETUpdater.FileNameFormat, tbl) end function CETUpdater.isTableToDownLoad(versionFileUrl, tableVersion) local nl = CETUpdater.NewLine or defaultNewLine versionFileUrl = versionFileUrl or CETUpdater.VersionFileUrl local tableVersionStr = tableVersion or CETUpdater.TableVersion tableVersion = CETUpdater.getVersionNumber(tableVersionStr) if type(versionFileUrl) ~= 'string' then local msg = format('"versionFileUrl" must be a string: %s', type(versionFileUrl)) Logger.error(msg) error(msg) return end if type(tableVersionStr) ~= 'string' then local msg = format('"tableVersion" must be a string: %s', type(tableVersionStr)) Logger.error(msg) error(msg) return end if type(tableVersion) ~= 'number' then local msg = format('Unable to convert "tableVersion" to number: %s', type(tableVersion)) Logger.error(msg) error(msg) return end local iNet = getInternet() local text = iNet.getURL(versionFileUrl) iNet.destroy() if text then local args = split(text:gsub('\r\n', nl), nl) local version = CETUpdater.getVersionNumber(args[1]) local url = args[2] return (version > tableVersion), tableVersionStr, url else Logger.errorf('Unable to download version file; at: "%s"', versionFileUrl) return nil end end function CETUpdater.getNewTable(versionStr, tableUrl, tableName) local nl = CETUpdater.NewLine or defaultNewLine versionStr = versionStr or CETUpdater.DefaultVersion tableUrl = tableUrl or CETUpdater.TableUrl tableName = tableName or CETUpdater.TableName or CETUpdater.ClassName if type(versionStr) ~= 'string' then local msg = format('"versionStr" must be a string: %s', type(versionStr)) Logger.error(msg) error(msg) return end if type(tableUrl) ~= 'string' then local msg = format('"tableUrl" must be a string: %s', type(tableUrl)) Logger.error(msg) error(msg) return end if type(tableName) ~= 'string' then local msg = format('"tableName" must be a string: %s', type(tableName)) Logger.error(msg) error(msg) return end local iNet = getInternet() local newTableStr = iNet.getURL(tableUrl) if newTableStr ~= nil then newTableStr = newTableStr:gsub('\r\n', nl) local newTablePath = CETUpdater.getTableFileName(versionStr, tableUrl, tableName) local f, err = io.open(newTablePath, 'w') if f and not err then f:write(newTableStr) f:close() Logger.infof('New table/trainer downloaded; from: "%s", to: "%s"', tableUrl, newTablePath) loadTable(newTablePath) else Logger.errorf('Unable to create temp file for new table/trainer; at: "%s"', newTablePath) end else Logger.errorf('Unable to download latest table/trainer file; at: "%s"', tableUrl) end iNet.destroy() end function CETUpdater.checkTableVersion(versionFileUrl, tableVersion, tableName) versionFileUrl = versionFileUrl or CETUpdater.VersionFileUrl tableVersion = tableVersion or CETUpdater.TableVersion tableName = tableName or CETUpdater.TableName or CETUpdater.ClassName local nl = CETUpdater.NewLine or defaultNewLine local downloadTable, versionStr, url = CETUpdater.isTableToDownLoad(versionFileUrl, tableVersion) if downloadTable then local answer = messageDialog(t(CETUpdater.NewVersionMessage) .. nl .. format(t('At') .. ': "%s"', url) .. nl .. t(CETUpdater.DownloadQuestion), mtWarning, mbYes, mbNo) if answer == mrYes then CETUpdater.getNewTable(versionStr, url, tableName) if CETUpdater.AutoSave then local newTablePath = CETUpdater.getTableFileName(versionStr, url, tableName) saveTable(newTablePath) messageDialog(t(CETUpdater.SavedMessage) .. nl .. format(t('To') .. ': "%s"', newTablePath), mtInformation, mbOK) else messageDialog('* ' .. t(CETUpdater.UserSaveMessage), mtInformation, mbOK) end else if CETUpdater.ForceUpdate then messageDialog('* ' .. t(CETUpdater.ForcedMessage) .. nl .. t(CETUpdater.ClosingMessage), mtInformation, mbOK) closeCE() end end else messageDialog(format(t(CETUpdater.HasLatestMessage) .. ', "%s"', versionStr), mtInformation, mbOK) end end return CETUpdater