Advertisement
Guest User

Cheat Engine - dropdown list string to bytes

a guest
Jun 21st, 2019
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. -- Cheat Engine Lua script snippet
  2. -- formats string drop down list values to AoBs and writes 0s to unused bytes
  3. for i = 0, AddressList.count - 1 do
  4.   local mr = AddressList[i]
  5.  
  6.   -- identify memory records to change
  7.   if mr.Type == vtString
  8.      and not mr.IsGroupHeader
  9.      and mr.DropDownCount > 0
  10.      and not mr.DropDownLinked then    -- possibly undesirable; I haven't experimented w/ linking
  11.    
  12.     local size = mr.String.Size
  13.     -- sanity check
  14.     for j = 0, mr.DropDownCount - 1 do
  15.       assert(#mr.DropDownValue[j] <= size,
  16.              ('Error: memory record "%s" (#%d, ID %d): drop down value "%s" longer than size "%d".'):format(
  17.              mr.Description, i, mr.ID, mr.DropDownValue[j], size))
  18.     end
  19.  
  20.     mr.Type = vtByteArray
  21.     mr.Aob.Size = size
  22.    
  23.     mr.DropDownList.beginUpdate()
  24.     for j = 0, mr.DropDownCount - 1 do
  25.       local val_str = mr.DropDownValue[j]
  26.       local bt = stringToByteTable(val_str)
  27.       for k = #val_str + 1, size, 1 do
  28.         bt[#bt+1] = 0
  29.       end
  30.       if bt[#bt] ~= 0 then
  31.         print(('Warning: memory record "%s" (#%d, ID %d): value of drop down description "%s" has no null terminator.'):format(
  32.              mr.Description, i, mr.ID, mr.DropDownDescription[j]))
  33.       end
  34.       for k,v in ipairs(bt) do
  35.         bt[k] = ('%02X'):format(v)
  36.       end
  37.       mr.DropDownList.setString(j, ('%s:%s'):format(table.concat(bt), mr.DropDownDescription[j]))
  38.     end
  39.     mr.DropDownList.endUpdate()
  40.   end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement