Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to get list of all cheat table, table files?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Tue Jan 09, 2018 5:22 pm    Post subject: How to get list of all cheat table, table files? Reply with quote

How do I get a list of all cheat table, table files?

I want to be able to iterate though "TableFile" class objects in Lua, to make use of the "delete" and "saveToFile" functions. Wanted an easy why to clear a cheat table of all table files, and at this point parsing the "?.CT" XML is the best I've got so far.

EDIT:
Well I also came up with this to get started:
Code:

local function tableFileListTester()
   print('--- Start ---')
   local mainForm = getMainForm()
   if mainForm.Menu == nil then return end
   local menuItems = mainForm.Menu.Items
   local miTable = nil
   local TableFiles = {}
   for i = 0, menuItems.Count - 1 do
      if menuItems[i].Name == 'miTable' then
         miTable = menuItems[i]
         ---- If table menu is never opened, then the table files are never added as menu items.
         miTable.doClick()
         mainForm.bringToFront()
      end
   end
   print('')
   print('- miTable -')
   print(type(miTable))
   print(miTable.Name)
   local startCapture = false
   for i = 0, miTable.Count - 1 do
      print(miTable[i].Name)
      if startCapture then
         print(miTable[i].Caption)
         TableFiles[#TableFiles + 1] = miTable[i].Caption
      end
      if miTable[i].Name == 'miAddFile' then
         startCapture = true
         print('- Start Capture -')
      end
   end
   print('')
   print('- TableFiles -')
   if TableFiles then
      for i, v in ipairs(TableFiles) do
         print(v)
      end
   end
   print('--- End ---')
end


EDIT:

And this is what I ended up with:

Add Table Helpers to Tools Menu.

_________________
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Tue Jan 09, 2018 10:22 pm    Post subject: Reply with quote

I haven't played enough to really know if this is feasible or not, but you can attach CE to itself and scan for the number of table files, 8 bytes (at least for the x64 CE) before that value you'll find a pointer which points to a list of TLuafile objects (same addresses you'd get from print(findTableFile...)



so in theory you could find a pointer to that and use the read*Local functions to find out how many there are and what each of the names are from inside CE itself.

Of course, the pointer would probably change with each version of CE so it's not quite as portable as something that reads the menu items...

One other thing to note is that the TrainerOrigin value is also set for cheat tables, as long as CE was started from the table (not from a shortcut and then the table opened)... not sure if you could find the actual CT filename however....

So what you've managed is probably the best way I can think of right now.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Tue Jan 09, 2018 11:22 pm    Post subject: Reply with quote

That is definitely an interesting approach, I hadn't thought of it. But I wanted to do this for working on tables while attached to a game. I like to use external files then pack them into a table, but there was no easy why to clear the table of all table files with Cheat Engine.
_________________
Back to top
View user's profile Send private message Visit poster's website
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Tue Jan 09, 2018 11:26 pm    Post subject: Reply with quote

Not sure it work for all system, especially not sure file access right thing,
(saveTable function will cause error if some table file name contain space or invalid character, so it cannot use to remove invalid table file name, but menu approach may be capable)
Code:
function listTFNames()
  local base = os.getenv"USERPROFILE"..'\\Documents\\My Cheat Tables\\'
  local ct = base..math.random(1000,9999)..os.clock()
  saveTable(ct)
  local ff = io.open(ct,'rb')
  local ss = ff and ff:read'*a'
  if ff then ff:close(); shellExecute('cmd','/c del /q "'..ct..'"',nil,false) end
  ss = ss and ss:match"<Files>(.-)</Files>"
  local r = {}
  if ss then
    local a,b,file = ss:find"<(%S+)"
    while a do
      a,b = ss:find("</"..file,b+1,true)--true for plain file text
      if a then
        r[1+#r]=file
        a,b,file = ss:find("<(%S+)",b+1)
      end
    end
  end
  return r
end
--test
local r = listTFNames()
print(#r,'\r\n',table.concat(r,'\r\n'))

_________________
- Retarded.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Wed Jan 10, 2018 12:09 am    Post subject: Reply with quote

loadTable() empty ct
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping


Last edited by Dark Byte on Wed Jan 10, 2018 12:13 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Wed Jan 10, 2018 12:13 am    Post subject: Reply with quote

Yeah, creating a temp file then parsing it was what I started with but I wanted to get away from creating a file.
But with the "TrainerOrigin" a temp file may not be needed I just thought that didn't work for ".CT" files.
But there are a million ways to skin a catfish.

_________________
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Wed Jan 10, 2018 11:54 pm    Post subject: Reply with quote

I played around some more with what I mentioned earlier and got this working:

Code:
--to find offsets start 2 instances of CE, in the first add some tablefiles in the second scan for the number of table files there are
-- find what accesses the address, you'll find an instruction with either 0x10 (x64) or 0x8, take the register value (probably in *bx)
-- and scan for it, you should only have a few results, check each to see which is accessed when you click the Tables menu
-- once you've found the one that's actually used, that's the offset from the MainForm
local knownTableFileOffsets = {
  [1688879925040206] = 0x900,
  [1688879925040207] = 0x1058
}

function getTableFileOffset()
  return knownTableFileOffsets[getCheatEngineFileVersion()]
end

local TFPGListOfTLuaFilesOffset = getTableFileOffset()
local pointerSize = cheatEngineIs64Bit() and 8 or 4
local TFPGListOfTLuaFiles = readPointerLocal(userDataToInteger(MainForm)+TFPGListOfTLuaFilesOffset)
local count = readIntegerLocal(TFPGListOfTLuaFiles + pointerSize*2)
local itemsBase = readPointerLocal(TFPGListOfTLuaFiles + pointerSize)

-- https://www.lua.org/pil/7.1.html
function tableFileIterator()
  local i = 0
  local n = count
  return function()
    if i < n then
      local file = integerToUserData(readPointerLocal(itemsBase+pointerSize*i))
      i = i + 1
      return file
    end
  end
end

for file in tableFileIterator() do
  print(file.name)
end


As far down as the list is (0x1058/0x900) it seems guaranteed to change with different versions but CE doesn't update that often so...shouldn't be particularly difficult to keep it up to date, throw in an alert whenever you run a version of CE that doesn't exist in the table and put it all in a lua file in autorun and you'll even be reminded to keep it up to date lol

autorun file on github (updated to work for 6.6, the only other official version of CE I have)
Back to top
View user's profile Send private message
DKing
How do I cheat?
Reputation: 0

Joined: 11 Jan 2018
Posts: 1

PostPosted: Thu Jan 11, 2018 8:10 am    Post subject: Reply with quote

I thought it was just as simple as

Code:

tablestart = tonumber(AOBScan("3C 43 68 65 61 74 54 61 62 6C 65 20")[0],16)
tablestop = tonumber(AOBScan("3C 2F 43 68 65 61 74 54 61 62 6C 65 3E")[0],16) + 15

CheatTableFile = "E:\\savefilename.ct"

writeRegionToFile(CheatTableFile, tablestart , tablestop-tablestart)

ctcontent = createStringlist()
ctcontent.loadFromFile(CheatTableFile)
ctcontent.Text = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"..ctcontent.Text
ctcontent.saveToFile(CheatTableFile)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites