Lua:findTableFile

From Cheat Engine
Jump to navigation Jump to search

<> Lua API Reference

function findTableFile(filename) : TableFile

Returns a TableFile object for a file stored inside the current cheat table.

A table file is embedded in the cheat table itself. It can be used directly by functions that accept table files, such as playSound, or accessed as a stream through the TableFile object.

Function Parameters[edit]

Parameter Type Description
filename String The name of the file stored in the cheat table.

Returns[edit]

TableFile — The table file object with the given name.

If no table file with that name exists, the function returns nil.

Description[edit]

findTableFile searches the files embedded in the current cheat table and returns the matching TableFile object.

This is useful when a script needs to access resources that were packaged with the cheat table, such as sounds, images, binary data, or other support files.

Examples[edit]

Play an embedded sound[edit]

1 local file = findTableFile("protected.wav")
2 
3 if file ~= nil then
4   playSound(file)
5 end

Check if a table file exists[edit]

1 local file = findTableFile("data.bin")
2 
3 if file == nil then
4   print("The table file was not found")
5 else
6   print("The table file exists")
7 end

Save an embedded file to disk[edit]

1 local file = findTableFile("data.bin")
2 
3 if file ~= nil then
4   file.saveToFile([[C:\\Temp\\data.bin]])
5 end

Load a table file into a MemoryStream[edit]

 1 local file = findTableFile("data.bin")
 2 
 3 if file ~= nil then
 4   local stream = createMemoryStream()
 5 
 6   file.Stream.Position = 0
 7   stream.copyFrom(file.Stream, file.Stream.Size)
 8 
 9   print("Loaded bytes: " .. tostring(stream.Size))
10 
11   stream.destroy()
12 end

Use a table file as script resource[edit]

 1 local function requireTableFile(filename)
 2   local file = findTableFile(filename)
 3 
 4   if file == nil then
 5     error("Missing table file: " .. filename)
 6   end
 7 
 8   return file
 9 end
10 
11 local sound = requireTableFile("protected.wav")
12 
13 playSound(sound)

Adding a File to the Table[edit]

To add a file to your table, open the Table menu and choose Add File.

AddFile.png

Select the file you want to embed. Cheat Engine adds it to the table using the original filename.

After the file has been added, it appears as a separate entry below Add file in the Table menu. From there, you can rename it, save it to disk, or delete it.

AddedFileMenu.png

Common Uses[edit]

Use Case Description
Sounds Store sound files in the table and play them with playSound.
Images Store image resources that can be loaded by GUI scripts.
Binary resources Store binary data that a Lua script can read or extract.
Support files Package helper files with the table instead of requiring separate files on disk.

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Cheat Table Related Functions