<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="42">
  <CheatEntries>
    <CheatEntry>
      <ID>27191</ID>
      <Description>"Theme selector"</Description>
      <Options moHideChildren="1"/>
      <Color>55996A</Color>
      <GroupHeader>1</GroupHeader>
      <CheatEntries>
        <CheatEntry>
          <ID>27192</ID>
          <Description>"OneDark-Pro"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27193</ID>
          <Description>"solarized-light"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27194</ID>
          <Description>"tomorrow-night-blue"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27195</ID>
          <Description>"dimmed-monokai"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27196</ID>
          <Description>"dark_plus"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27197</ID>
          <Description>"solarized-dark"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27198</ID>
          <Description>"kimbie-dark"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27199</ID>
          <Description>"hc_black"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27200</ID>
          <Description>"OneLight"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27201</ID>
          <Description>"abyss"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27202</ID>
          <Description>"Red"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27203</ID>
          <Description>"light_plus"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
        <CheatEntry>
          <ID>27204</ID>
          <Description>"monokai"</Description>
          <Color>55996A</Color>
          <GroupHeader>1</GroupHeader>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>660</ID>
      <Description>"███████████ Group with address"</Description>
      <ShowAsHex>1</ShowAsHex>
      <ShowAsSigned>0</ShowAsSigned>
      <Color>D69C56</Color>
      <GroupHeader>1</GroupHeader>
      <Address>test</Address>
      <Offsets>
        <Offset>0</Offset>
      </Offsets>
    </CheatEntry>
    <CheatEntry>
      <ID>27189</ID>
      <Description>"███████████ Group without address"</Description>
      <Color>55996A</Color>
      <GroupHeader>1</GroupHeader>
    </CheatEntry>
    <CheatEntry>
      <ID>27190</ID>
      <Description>"███████████ User value"</Description>
      <ShowAsSigned>0</ShowAsSigned>
      <Color>FEDC9C</Color>
      <VariableType>4 Bytes</VariableType>
      <Address>ptrGameState</Address>
    </CheatEntry>
    <CheatEntry>
      <ID>27109</ID>
      <Description>"███████████ Float value"</Description>
      <ShowAsSigned>0</ShowAsSigned>
      <Color>A8CEB5</Color>
      <VariableType>Float</VariableType>
      <Address>ptrGameState</Address>
      <Offsets>
        <Offset>0</Offset>
      </Offsets>
    </CheatEntry>
    <CheatEntry>
      <ID>665</ID>
      <Description>"███████████ Integer value"</Description>
      <ShowAsSigned>0</ShowAsSigned>
      <Color>B0C94E</Color>
      <VariableType>4 Bytes</VariableType>
      <Address>ptrGameState</Address>
      <Offsets>
        <Offset>0</Offset>
      </Offsets>
    </CheatEntry>
    <CheatEntry>
      <ID>671</ID>
      <Description>"███████████ Hexedecimal value"</Description>
      <ShowAsHex>1</ShowAsHex>
      <ShowAsSigned>0</ShowAsSigned>
      <Color>B0C94E</Color>
      <VariableType>8 Bytes</VariableType>
      <Address>ptrGameState</Address>
      <Offsets>
        <Offset>6CA</Offset>
      </Offsets>
    </CheatEntry>
    <CheatEntry>
      <ID>668</ID>
      <Description>"███████████ String value"</Description>
      <ShowAsSigned>0</ShowAsSigned>
      <Color>7891CE</Color>
      <VariableType>String</VariableType>
      <Length>10</Length>
      <Unicode>0</Unicode>
      <CodePage>0</CodePage>
      <ZeroTerminate>1</ZeroTerminate>
      <Address>ptrGameState</Address>
      <Offsets>
        <Offset>6C9</Offset>
      </Offsets>
    </CheatEntry>
    <CheatEntry>
      <ID>26721</ID>
      <Description>"███████████ Script"</Description>
      <Color>AADCDC</Color>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
{$lua}
function CECompactMode(state)
  local f = getMainForm()
  local controls = {f.Splitter1, f.Panel4, f.Panel5, AddressList.panelOCTFooter, AddressList.splitterOCTFooter}
  for k,c in ipairs(controls) do c.Visible = not state end
end
CECompactMode(true)
{$asm}
[DISABLE]
{$lua}
CECompactMode(false)
</AssemblerScript>
    </CheatEntry>
    <CheatEntry>
      <ID>664</ID>
      <Description>"███████████ Other value"</Description>
      <ShowAsSigned>0</ShowAsSigned>
      <Color>D4D4D4</Color>
      <VariableType>Binary</VariableType>
      <BitStart>0</BitStart>
      <BitLength>1</BitLength>
      <ShowAsBinary>0</ShowAsBinary>
      <Address>ptrGameState</Address>
      <Offsets>
        <Offset>6C9</Offset>
      </Offsets>
    </CheatEntry>
  </CheatEntries>
  <UserdefinedSymbols/>
  <LuaScript>GetLuaEngine().MenuItem5.doClick() -- crear lua output
function CECompactMode(state)
  local f = getMainForm()
  local controls = {f.Splitter1, f.Panel4, f.Panel5, AddressList.panelOCTFooter, AddressList.splitterOCTFooter}
  for k,c in ipairs(controls) do c.Visible = not state end
end
CECompactMode(true)
--------------------------------------------------------------------------------
function hex(value)
  if value == nil then return "nil" end
  return string.format("%X",value)
end
--------------------------------------------------------------------------------
local pathsep = getOperatingSystem() and [[\]] or [[/]]
local themesPath = getAutoRunPath()..'themes'..pathsep
--------------------------------------------------------------------------------
if package.loaded.json==nil then
  package.path=package.path..';'.. themesPath ..'?.lua'
else
  package.loaded.json=nil
end
local json = require "json"
--------------------------------------------------------------------------------
local function readAll(file)
  local f = assert(io.open(file, "rb"))
  local content = f:read("*all")
  f:close()
  return content
end
--------------------------------------------------------------------------------
function string:split(sep)
  sep = sep or '%s'
  local elements = {}
  for element in string.gmatch(self, "([^"..sep.."]+)") do
    if element then elements[element]=element end
  end
  return elements
end
--------------------------------------------------------------------------------
local function tokenSearch(scope, token)
  if type(scope)=="table" then
    if scope[token] == token then return true end
    for _,item in ipairs(scope) do
      if item == token then return true end
    end
  end
  if type(scope)=="string" and (scope == token or scope:split(", ")[token]) then
    return true
  end
  return false
end
--------------------------------------------------------------------------------
local function tokenColor(raw, token)
  local rawColors = raw["colors"]
  if rawColors and rawColors[token] then return rawColors[token]:bgr() end
  local tokenColors = raw["tokenColors"]
  for _,item in ipairs(tokenColors) do
    if item["scope"] and tokenSearch(item["scope"], token)
      and item["settings"] and item["settings"]["foreground"] then
      return item["settings"]["foreground"]:bgr()
    end
  end
  return nil
end
--------------------------------------------------------------------------------
local function RGB2BGR(RGB)
  local r = RGB // 0x10000
  local g = (( RGB % 0x10000 ) // 0x100 ) &lt;&lt; 8
  local b = ( RGB % 0x100 ) &lt;&lt; 16
  return r+g+b
end
--------------------------------------------------------------------------------
-- get bgr color integer from "#RRGGBB" string
function string:bgr()
  local hexColorString = self:sub(2,7)
  local RGB = tonumber(hexColorString,16)
  return RGB2BGR(RGB)
end
--------------------------------------------------------------------------------
local themes = {}
local function loadThemes()
  -- lists *.json files from themesPath assuming they are valid theme files
  for filePath in io.popen('dir "'..themesPath..'*.json'..'" /b /s'):lines() do
    local raw = json.decode(readAll(filePath))
    local themeName = extractFileNameWithoutExt(extractFileName(filePath))
    local tokens = {
      "editor.background",
      "editor.foreground",
      "comment",
      "string",
      "keyword",
      "variable",
      "variable.parameter",
      "keyword.control",
      "constant.numeric",
      "entity.name.function",
      "entity.name.class",
      "editor.selectionHighlightBackground",
      "editor.inactiveSelectionBackground",
      "activityBarBadge.background",
      "support.class",
      "invalid",
      "keyword.operator",
      "constant.other.color",
    }
    themes[themeName] = {}
    for _,token in ipairs(tokens) do
      local dbg = false
      if dbg and not tokenColor(raw, token) then
        print("Error: '"..token.."' token not found within '"..themeName.."' theme!")
      end
      themes[themeName][token] = tokenColor(raw, token)
    end
  end
end
--------------------------------------------------------------------------------
local function delete_subrecords(record)
  while record ~= nil and record.Count &gt; 0 do
    memoryrecord_delete(record.Child[0])
  end
end
--------------------------------------------------------------------------------
local function deactivate_subrecords(sender, record)
  for i=0,record.Count-1 do
    record.Child[i].Active = false
  end
end
--------------------------------------------------------------------------------
local function ToggleTrigger(record, before, currentstate)
  -- activation begin
  if before == true and currentstate == false then
    deactivate_subrecords(record, record.Parent)
    applyTheme(record.Description)
  end
  -- activation finish
  if before == false and currentstate == true then
  end
  -- deactivation begin
  if before == true and currentstate == true then
  end
  -- deactivation finish
  if before == false and currentstate == false then
  end
  return true
end
--------------------------------------------------------------------------------
local function updateThemeSelector()
  local al = getAddressList()
  local root = al.getMemoryRecordByDescription("Theme selector")
  delete_subrecords(root)
  for themeName,_ in pairs(themes) do
    local mr = al.createMemoryRecord()
    mr.Description = themeName
    mr.IsGroupHeader = true
    mr.Parent = root
    mr.OnActivate = ToggleTrigger
    mr.OnDeactivate = ToggleTrigger
  end
end
--------------------------------------------------------------------------------
function applyTheme(themeName)
  local theme = themes[themeName]
  local al = getAddressList()
  local treeView = al.Control[0]
  treeView.Color = theme["editor.background"] or treeView.Color
  local font = createFont()
  font.Name = "Consolas"
  font.Color = theme["editor.foreground"] or font.Color
  font.Size = 9
  treeView.Font = font

  -- colorize memory records

  al.CheckboxColor = theme["keyword"] or al.CheckboxColor
  al.CheckboxActiveColor = theme["editor.foreground"] or CheckboxActiveColor

  al.CheckboxSelectedColor = theme["keyword"] or CheckboxSelectedColor
  al.CheckboxActiveSelectedColor = theme["editor.foreground"] or addrList.CheckboxActiveSelectedColor

  al.SelectedBackgroundColor = theme["editor.selectionHighlightBackground"] or al.SelectedBackgroundColor
  al.SelectedSecondaryBackgroundColor = theme["editor.inactiveSelectionBackground"] or al.SelectedSecondaryBackgroundColor

  -- colorize memory records

  local stringTypes = {
    [vtString] = true,
    [vtUnicodeString] = true,
  }

  local integerTypes = {
    [vtByte] = true,
    [vtWord] = true,
    [vtDword] = true,
    [vtQword] = true,
  }

  local floatTypes = {
    [vtSingle] = true,
    [vtDouble] = true,
  }

  for i=0,al.Count-1 do
    local mr = al[i]
    mr.Color = theme["editor.foreground"] or mr.Color -- other
    if mr.Type == vtAutoAssembler then
      mr.Color = theme["entity.name.function"] or mr.Color -- script
    elseif mr.IsAddressGroupHeader then
      mr.Color = theme["keyword"] or mr.Color -- group with address
    elseif mr.IsGroupHeader then
      mr.Color = theme["comment"] or mr.Color -- group without address
    elseif mr.OffsetCount==0 and not tonumber(mr.AddressString,16) then
      mr.Color = theme["variable.parameter"] or theme["variable"] or mr.Color -- user defined values
    elseif mr.ShowAsHex then
      mr.Color = theme["support.class"] or theme["keyword.control"] or mr.Color -- pointers and hex values
    elseif stringTypes[mr.Type] then
      mr.Color = theme["string"] or mr.Color  -- string values
    elseif integerTypes[mr.Type] then
      mr.Color = theme["entity.name.class"] or mr.Color -- integer values
    elseif floatTypes[mr.Type] then
      mr.Color = theme["constant.other.color"] or theme["constant.numeric"] or mr.Color -- float values
    else
      mr.Color = theme["editor.foreground"] or mr.Color -- other
    end
  end

end
--------------------------------------------------------------------------------
loadThemes()
updateThemeSelector()
applyTheme("dark_plus")

</LuaScript>
</CheatTable>
