I made it back to a computer.
I looked over the code and in theory I removed the check for the AUTO SET in front of memory records. I don't actually have time to fully debug it right now as it is still technically Monday night in USA.
I can see where one might need something like this functionality especially for large tables like some of mine are. I'm probably not allowed to use this code, so will have to code something a little different if I want to add this functionality to some of trainer apps if it works there at all.
Code: Select all
local format = string.format
local strE = string.empty or STRING_EMPTY or ''
local t = translate
if AddressList == nil then
AddressList = getAddressList()
end
if MainForm == nil then
MainForm = getMainForm()
end
if getCEVersion == nil or getCEVersion() < 6.5 then
messageDialog('It is recommended to use at least Cheat Engine 6.7! (Your Version: '..getCEVersion()..')', mtError, mbOK)
end
errorOnLookupFailure(false)
setGlobalDelayBetweenHotkeyActivation(200)
DefaultProccessName = "pcsx2.exe"
strings_add(getAutoAttachList(), DefaultProccessName)
PRIVATETABLE, SWITCHSUPPORT = true, false
function cycleFullCompact(sender,force)
local state = not(compactmenuitem.Caption == 'Compact View Mode')
if force~=nil then state = not force end
compactmenuitem.Caption = state and 'Compact View Mode' or 'Full View Mode'
getMainForm().Splitter1.Visible = state
getMainForm().Panel4.Visible = state
getMainForm().Panel5.Visible = state
end
function addCompactMenu()
if compactmenualreadyexists then return end
local parent = getMainForm().Menu.Items
compactmenuitem = createMenuItem(parent); parent.add(compactmenuitem)
compactmenuitem.Caption = 'Compact View Mode'
compactmenuitem.OnClick = cycleFullCompact
compactmenualreadyexists = 'yes'
end
addCompactMenu()
cycleFullCompact(nil, true)
----
--
---- Logger
local Logger = {
LEVELS = {
OFF = 0,
FATAL = 1,
ERROR = 2,
WARN = 3,
INFO = 4,
DEBUG = 5,
TRACE = 6
},
Level = 0,
}
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
--
---- Helpers
local function split(s, delimiter)
result = {}
for match in (s .. delimiter):gmatch('(.-)' .. delimiter) do
table.insert(result, match)
end
return result
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
--
---- I2CETState
I2CETState = {
--
---- Settings
DefaultState = 'default',
SaveFileName = 'I2CETState.${StateName}.txt',
UseMemoryRecordDescriptions = false,
LineEnd = '\n',
DisableBeforeLoad = true,
PrintStatus = false, --true,
SaveValueMatch = 'AUTO SET:',
LineDelimiter = '',
ScriptID = 'I2CETStateSCRIPTID',
BlackList = {
['_[ I2CETState ]_'] = true,
['_[ Save Table State ]_'] = true,
['_[ Load Table State ]_'] = true,
},
}
function I2CETState.saveTableState(stateName)
if not inMainThread() then
synchronize(function(thread)
I2CETState.saveTableState(stateName)
end)
return
end
Logger.trace()
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
getLuaEngine().show()
end
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
print(format('Saving Table State: %s', stateName))
end
local le = I2CETState.LineEnd
local ld = I2CETState.LineDelimiter
local sid = I2CETState.ScriptID
local svm = I2CETState.SaveValueMatch
if stateName == nil then
stateName = I2CETState.DefaultState
end
local fileName = interp(I2CETState.SaveFileName, { StateName = stateName } )
Logger.debugf('Using state file name: "%s"', fileName)
local fileStr = strE
for i = 0, AddressList.Count - 1 do
local mr = AddressList.getMemoryRecord(i)
if I2CETState.BlackList[mr.Description] ~= true
and mr.Description:sub(0, 16) ~= 'Load Table State'
and mr.Description:sub(0, 16) ~= 'Save Table State' then
local id = tostring(mr.ID)
if I2CETState.UseMemoryRecordDescriptions then
id = mr.Description
end
if mr.Type == vtAutoAssembler and mr.Active then
Logger.debugf('Saving script state: %d, %d, "%s"', mr.Index, mr.ID, mr.Description)
fileStr = fileStr..id..ld..sid..ld..tostring(mr.Active)..le
elseif mr.Value ~= '??' then
Logger.debugf('Saving value: %d, %d, "%s", %s', mr.Index, mr.ID, mr.Description, mr.Value)
fileStr = fileStr..id..ld..mr.Value..ld..tostring(mr.Active)..le
end
end
end
local f, err = io.open(fileName, 'w')
if err then
Logger.errorf('The file could not be opened, "%s", %s', fileName, err)
elseif f and not err then
f:write(fileStr)
f:close()
end
end
saveTableState = I2CETState.saveTableState
function I2CETState.loadTableState(stateName)
if not inMainThread() then
synchronize(function(thread)
I2CETState.loadTableState(stateName)
end)
return
end
Logger.trace()
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
getLuaEngine().show()
end
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
print(format('Setting Table State: %s', stateName))
end
local le = I2CETState.LineEnd
local ld = I2CETState.LineDelimiter
local sid = I2CETState.ScriptID
local svm = I2CETState.SaveValueMatch
if stateName == nil then
stateName = I2CETState.DefaultState
end
local fileName = interp(I2CETState.SaveFileName, { StateName = stateName } )
Logger.debugf('Using state file name: "%s"', fileName)
local fileStr = nil
local f, err = io.open(fileName, 'r')
if err then
Logger.infof('The local file could not be opened, "%s", %s', fileName, err)
local tableFile = findTableFile(fileName)
if tableFile == nil then
Logger.warnf('file not found, "%s"', fileName)
return
end
local stream = tableFile.getData()
local bytes = stream.read(stream.Size)
for i = 1, #bytes do
if fileStr == nil then
fileStr = strE
end
fileStr = fileStr .. string.char(bytes[i])
end
elseif f and not err then
fileStr = f:read('*all')
f:close()
else
Logger.errorf('The file could not be opened, "%s"', fileName)
end
if I2CETState.DisableBeforeLoad then
for i = AddressList.Count - 1, 0, -1 do
local mr = AddressList.getMemoryRecord(i)
if I2CETState.BlackList[mr.Description] ~= true
and mr.Description:sub(0, 16) ~= 'Load Table State'
and mr.Description:sub(0, 16) ~= 'Save Table State' then
if mr.Active then
Logger.infof('Disabling memory record: %d, %d, "%s"', mr.Index, mr.ID, mr.Description)
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
print(format('Disabling: %s', mr.Description))
end
mr.Active = false
while mr.Async and mr.AsyncProcessing do
checkSynchronize()
end
sleep(0)
end
end
end
sleep(0)
end
if fileStr == nil then
Logger.info('File string was nil')
return
end
local lines = split(fileStr, I2CETState.LineEnd)
for i, v in ipairs(lines) do
if v ~= nil and v ~= strE then
local data = split(v, I2CETState.LineDelimiter)
local mr = nil
if I2CETState.UseMemoryRecordDescriptions then
mr = AddressList.getMemoryRecordByDescription(data[1])
else
mr = AddressList.getMemoryRecordByID(tonumber(data[1]))
end
if mr ~= nil then
if mr.Type == vtAutoAssembler and mr.Active == false
and data[2] == sid and data[3] == tostring(true) then
Logger.infof('Enabling memory record: %d, %d, "%s"', mr.Index, mr.ID, mr.Description)
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
print(format('Enabling: "%s"', mr.Description))
end
mr.Active = true
while mr.Async and mr.AsyncProcessing do
checkSynchronize()
end
sleep(0)
elseif mr.Type ~= vtAutoAssembler then
if mr.Value == '??' then
Logger.warnf('Memory record value not set: %d, %d, "%s", "%s"', mr.Index, mr.ID, mr.Description, mr.Value)
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
print(format('Memory record value not set: "%s", "%s"', mr.Description, mr.Value))
end
else
Logger.infof('Setting memory record: %d, %d, "%s", %s, %s', mr.Index, mr.ID, mr.Description, data[1], data[2])
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
print(format('Setting: "%s", %s', mr.Description, data[2]))
end
mr.Value = data[2]
if data[3] == tostring(true) then
mr.Active = true
end
end
end
else
Logger.errorf('Memory record not found: "%s", "%s", "%s"', data[1], data[2], v)
end
end
end
if I2CETState.PrintStatus and Logger.Level <= Logger.LEVELS.WARN then
print(format('Table State Set: %s', stateName))
getLuaEngine().hide()
end
end
loadTableState = I2CETState.loadTableState
----
PROCESS_NAME = 'pcsx2.exe'
--------
-------- Auto Attach
--------
local autoAttachTimer = nil ---- variable to hold timer object
local autoAttachTimerInterval = 100 ---- Timer intervals are in milliseconds
local autoAttachTimerTicks = 0 ---- variable to count number of times the timer has run
local autoAttachTimerTickMax = 5000 ---- Set to zero to disable ticks max
local function autoAttachTimer_tick(timer) ---- Timer tick call back
---- Destroy timer if max ticks is reached
if autoAttachTimerTickMax > 0 and autoAttachTimerTicks >= autoAttachTimerTickMax then
timer.destroy()
end
---- Check if process is running
if getProcessIDFromProcessName(PROCESS_NAME) ~= nil then
timer.destroy() ---- Destroy timer
openProcess(PROCESS_NAME) ---- Open the process
--
--
---- Just a way to do this with the NameList,
---- thus you can just add to the list to make it work with other memory records.
end
autoAttachTimerTicks = autoAttachTimerTicks + 1 ---- Increase ticks
end
autoAttachTimer = createTimer(getMainForm()) ---- Create timer with the main form as it's parent
autoAttachTimer.Interval = autoAttachTimerInterval ---- Set timer interval
autoAttachTimer.OnTimer = autoAttachTimer_tick ---- Set timer tick call back
If this don't work I will actually test it myself tomorrow.