CE Table Manager

Anything Cheat Engine related, bugs, suggestions, helping others, etc..
Post Reply
jonplumb
Noobzor
Noobzor
Posts: 10
Joined: Wed Apr 18, 2018 6:26 pm
Reputation: 1

CE Table Manager

Post by jonplumb » Wed Sep 05, 2018 10:46 pm

It would be cool to see a cheat table manager that can keep our cheat tables updated. I'm picturing something like the old Curse client (I think it's Twitch now, or something like that) that I used to keep my World of Warcraft add-ons up-to-date.

Just a thought. It wouldn't be too hard, but might be more work than anyone wants to put into it...

User avatar
TheyCallMeTim13
Administration
Administration
Posts: 984
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 154
Contact:

Re: CE Table Manager

Post by TheyCallMeTim13 » Thu Sep 06, 2018 2:20 am

jonplumb wrote:
Wed Sep 05, 2018 10:46 pm
It would be cool to see a cheat table manager that can keep our cheat tables updated. I'm picturing something like the old Curse client (I think it's Twitch now, or something like that) that I used to keep my World of Warcraft add-ons up-to-date.

Just a thought. It wouldn't be too hard, but might be more work than anyone wants to put into it...

Here's one with Lua:
Here's the file:
I2CETUpdater.lua.7z
I2CETUpdater.lua v: 1.1.3
(3.78 KiB) Downloaded 18 times
And the code:

Code: Select all

--[====================================================================================================================[

	I2 Cheat Engine Table Updater

	Version: 1.1.3
		1.0.1:
			* Initial setup.
		1.0.5:
			* Added auto save ("AutoSave") setting and functionality (default: true).
				- Auto saves loaded table after download, 
					using the name generated with "FileNameFormat".
			* Added force update ("ForceUpdate") setting and functionality (default: false).
				- Forces table 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".
		1.1.3:
			* Fixed Error with wring version number being used.

	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 update by closing CE if user selects no.
		AutoSave (default: true): Auto saves loaded table 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.'
			CETUpdater.DownloadQuestion = 'Would you like to download it now?'
			CETUpdater.SavedMessage = 'New table saved.'
			CETUpdater.ForcedMessage = 'Sorry but the table 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!'
			CETUpdater.checkTableVersion(url, '3.0.8', 'mgsvtpp')


]====================================================================================================================]--


local NAME = 'I2 Cheat Engine Table Updater'
local CLASS_NAME = 'I2CETUpdater'
local VERSION = '1.1.3'
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 = '0.0.0', 
	FileNameFormat = '${TableName}.[v${Version}].${FileExtension}', 
	ForceUpdate = false, 
	AutoSave = true, 
	NewLine = defaultNewLine, 
	ExecuteNewFile = false, 
	--
	---- Messages
	NewVersionMessage = 'There is a newer version of this table.', 
	DownloadQuestion = 'Would you like to download it now?', 
	SavedMessage = 'New table saved.', 
	UserSaveMessage = 'Be sure to save the new table!', 
	ForcedMessage = 'Sorry but the table creator thinks it\'s best to use the latest version!', 
	ClosingMessage = 'Now Closing Cheat Engine', 
	HasLatestMessage = 'You currently have the latest version of the table!', 
}

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%04X', verStr, tonumber(vers[i] or '0'))
	end
	return tonumber(verStr, 16)
end


function CETUpdater.getTableFileName(versionStr, tableUrl, tableName, isSave)
	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 versionStr = args[1]
		local version = CETUpdater.getVersionNumber(versionStr)
		local url = args[2]
		return (version > tableVersion), versionStr, 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)
	iNet.destroy()
	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 downloaded; from: "%s", to: "%s"', tableUrl, newTablePath)
			loadTable(newTablePath)
			sleep(0)
			os.remove(newTablePath)
			sleep(0)
		else
			Logger.errorf('Unable to create file for new table; at: "%s"', newTablePath)
		end
	else
		Logger.errorf('Unable to download latest table file; at: "%s"', tableUrl)
	end
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

function CETUpdater.checkTableVersionSilent(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
		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)
		end
	end
end

return CETUpdater


Version File Example:

Code: Select all

3.0.9
http://fearlessrevolution.com/index.php?attachments/mgsvtpp-v3-0-9-ct.9549/
Lua useage:

Code: Select all

require('I2CETUpdater')
---- or 
--doFile('I2CETUpdater.lua')

---- CETUpdater.checkTableVersion(versionFileUrl, tableVersion, tableName)
CETUpdater.checkTableVersion('https://docs.google.com/document/d/1pPgHNGV1-EmIpfxxXp0vnoeoZxlCg11ofdV1x78bJEw/export?format=txt', '3.0.8', 'mgsvtpp')
Or

Code: Select all

CETUpdater.TableVersion = '3.0.8'
CETUpdater.TableName = 'mgsvtpp'
CETUpdater.VersionFileUrl = 'https://docs.google.com/document/d/1pPgHNGV1-EmIpfxxXp0vnoeoZxlCg11ofdV1x78bJEw/export?format=txt'
CETUpdater.checkTableVersion()
But you also have to distribute this with tables.

jonplumb
Noobzor
Noobzor
Posts: 10
Joined: Wed Apr 18, 2018 6:26 pm
Reputation: 1

Re: CE Table Manager

Post by jonplumb » Thu Sep 06, 2018 4:37 am

Cool! I'll toy around with this. Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users