If you use the module with other code make sure to remove the
return
else it will stop execution there.
To make a blacklist, you want to add a table, and use a loop to iterate through it and check for the description. Or you could use the description as the table key with a value of
true
, and check for that.
Try this:
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 = '<SEP>',
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.Description:sub(0, #svm) == svm and 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 and mr.Description:sub(0, #svm) == svm 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
-- getAddressList().getMemoryRecordByDescription("max jump everywhere - change value to 60)").active=true
--
---- 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
I move the setup variables to the top of the script and since you never used
controlMainForm
so I removed it. And you can remove the loop in the auto attach timer that iterates through the name list since it's not needed anymore. Plus you don't want to just set
AddressList
because in newer versions of CE it and
MainForm
are constants set by CE. The reason I have it check for nil then set those is to make it compatible with older CE versions. So now it has a black list.
And you can use this at the start of any script you want to blacklist, just put this in the enable section. And it will not effect that script when loading or saving.
Code: Select all
{$lua}
I2CETState.BlackList[memrec.Description] = true
{$asm}
And just to note any script that starts with "Load Table State" or "Save Table State" will be ignored as well.
EDIT: And you can use these to save different states and load them, just paste this to the address list. So long as you keep the "Save/Load Table State" you can rename those scripts and move them where you'd like. If you change the main one ("_[ I2CETState ]_") just make sure you add it to the blacklist, I'd just change that entry in the blacklist of the main code, since it'd likely be what you want to use regularly.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
<CheatEntries>
<CheatEntry>
<ID>53</ID>
<Description>"_[ I2CETState ]_"</Description>
<Options moHideChildren="1"/>
<LastState Value="" Activated="1" RealAddress="00000000"/>
<GroupHeader>1</GroupHeader>
<CheatEntries>
<CheatEntry>
<ID>54</ID>
<Description>"_[ Save Table State ]_"</Description>
<Options moHideChildren="1"/>
<LastState Value="" RealAddress="00000000"/>
<GroupHeader>1</GroupHeader>
<CheatEntries>
<CheatEntry>
<ID>55</ID>
<Description>"Save Table State : None ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.saveTableState('none')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>56</ID>
<Description>"Save Table State : Default ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.saveTableState('default')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>57</ID>
<Description>"Save Table State : Casual ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.saveTableState('casual')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>58</ID>
<Description>"Save Table State : Full ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.saveTableState('full')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>59</ID>
<Description>"Save Table State : Test ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.saveTableState('test')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
</CheatEntries>
</CheatEntry>
<CheatEntry>
<ID>60</ID>
<Description>"_[ Load Table State ]_"</Description>
<Options moHideChildren="1"/>
<LastState Value="" RealAddress="00000000"/>
<GroupHeader>1</GroupHeader>
<CheatEntries>
<CheatEntry>
<ID>61</ID>
<Description>"Load Table State : None ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.loadTableState('none')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>62</ID>
<Description>"Load Table State : Default ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.loadTableState('default')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>63</ID>
<Description>"Load Table State : Casual ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.loadTableState('casual')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>64</ID>
<Description>"Load Table State : Full ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.loadTableState('full')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
<CheatEntry>
<ID>65</ID>
<Description>"Load Table State : Test ()->"</Description>
<LastState/>
<Color>008000</Color>
<VariableType>Auto Assembler Script</VariableType>
<AssemblerScript>{$lua}
------------------------------ ENABLE ------------------------------
[ENABLE]
if syntaxcheck then return end
I2CETState.loadTableState('test')
if type(mrAutoDisable) == 'function' then
mrAutoDisable(memrec.ID)
end
------------------------------ DISABLE ------------------------------
[DISABLE]
</AssemblerScript>
</CheatEntry>
</CheatEntries>
</CheatEntry>
</CheatEntries>
</CheatEntry>
</CheatEntries>
</CheatTable>