Difference between revisions of "Lua:createTableFile"
(Replaced content with '<span style="font-size:25px;color:red">Sorry! Content not available.</span>') |
m |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | + | [[Category:Lua]] | |
| + | {{CodeBox|'''function''' createTableFile(''fileName'', ''filePath'' OPTIONAL) ''':''' TableFile}} | ||
| + | |||
| + | Creates a new [[Lua:Class:TableFile|TableFile]] object and adds it to the current cheat table. | ||
| + | |||
| + | If filePath is specified, Cheat Engine reads the file from disk and embeds its contents in the table. If filePath is omitted, an empty table file is created. | ||
| + | |||
| + | ===Function Parameters=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Parameter | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |fileName | ||
| + | |String | ||
| + | |The name the file will have inside the cheat table. | ||
| + | |- | ||
| + | |filePath | ||
| + | |String OPTIONAL | ||
| + | |The path to the file on disk. If omitted, a blank table file is created. | ||
| + | |} | ||
| + | |||
| + | ===Returns=== | ||
| + | [[Lua:Class:TableFile|TableFile]] — The created table file object. | ||
| + | |||
| + | ===Description=== | ||
| + | createTableFile adds a file entry to the current cheat table. | ||
| + | |||
| + | This is useful for packaging resources with a table, such as sounds, images, binary data, configuration files, or other files used by Lua scripts. The file can later be retrieved with [[Lua:findTableFile|findTableFile]], saved back to disk, or accessed through its [[Lua:Class:MemoryStream|MemoryStream]]. | ||
| + | |||
| + | ===Examples=== | ||
| + | |||
| + | ====Create a blank table file==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = createTableFile("runtime.dat") | ||
| + | |||
| + | print("Created table file: " .. file.Name) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Create a table file from disk==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = createTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]]) | ||
| + | |||
| + | print("Added table file: " .. file.Name) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Play an embedded sound==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = createTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]]) | ||
| + | |||
| + | playSound(file) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Create the file only if it does not already exist==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("config.json") | ||
| + | |||
| + | if file == nil then | ||
| + | file = createTableFile("config.json", [[C:\\SomeDirectory\\config.json]]) | ||
| + | end | ||
| + | |||
| + | print("Using table file: " .. file.Name) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Replace an existing table file==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local oldFile = findTableFile("config.json") | ||
| + | |||
| + | if oldFile ~= nil then | ||
| + | oldFile.delete() | ||
| + | end | ||
| + | |||
| + | local newFile = createTableFile("config.json", [[C:\\SomeDirectory\\config.json]]) | ||
| + | |||
| + | print("Replaced table file: " .. newFile.Name) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save the created table file to disk==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]]) | ||
| + | |||
| + | file.saveToFile([[C:\\Temp\\data_copy.bin]]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Read the created file as a MemoryStream==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]]) | ||
| + | local stream = file.getData() | ||
| + | |||
| + | print("Stream size: " .. tostring(stream.Size)) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Access the Stream property==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]]) | ||
| + | local stream = file.Stream | ||
| + | |||
| + | stream.Position = 0 | ||
| + | |||
| + | print("Stream size: " .. tostring(stream.Size)) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Create multiple table files==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local files = { | ||
| + | { name = "startup.wav", path = [[C:\\Sounds\\startup.wav]] }, | ||
| + | { name = "success.wav", path = [[C:\\Sounds\\success.wav]] }, | ||
| + | { name = "failed.wav", path = [[C:\\Sounds\\failed.wav]] } | ||
| + | } | ||
| + | |||
| + | for i, entry in ipairs(files) do | ||
| + | if findTableFile(entry.name) == nil then | ||
| + | createTableFile(entry.name, entry.path) | ||
| + | end | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Use a helper function==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local function ensureTableFile(name, path) | ||
| + | local file = findTableFile(name) | ||
| + | |||
| + | if file == nil then | ||
| + | file = createTableFile(name, path) | ||
| + | end | ||
| + | |||
| + | return file | ||
| + | end | ||
| + | |||
| + | local sound = ensureTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]]) | ||
| + | |||
| + | playSound(sound) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Adding a File through the GUI=== | ||
| + | To add a file to your table manually, open the '''Table''' menu and choose '''Add File'''. | ||
| + | |||
| + | [[Image: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. | ||
| + | |||
| + | [[Image:AddedFileMenu.png]] | ||
| + | |||
| + | {{LuaSeeAlso}} | ||
| + | |||
| + | {{CheatTable}} | ||
Latest revision as of 19:05, 25 June 2026
Creates a new TableFile object and adds it to the current cheat table.
If filePath is specified, Cheat Engine reads the file from disk and embeds its contents in the table. If filePath is omitted, an empty table file is created.
Contents
- 1 Function Parameters
- 2 Returns
- 3 Description
- 4 Examples
- 4.1 Create a blank table file
- 4.2 Create a table file from disk
- 4.3 Play an embedded sound
- 4.4 Create the file only if it does not already exist
- 4.5 Replace an existing table file
- 4.6 Save the created table file to disk
- 4.7 Read the created file as a MemoryStream
- 4.8 Access the Stream property
- 4.9 Create multiple table files
- 4.10 Use a helper function
- 5 Adding a File through the GUI
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The name the file will have inside the cheat table. |
| filePath | String OPTIONAL | The path to the file on disk. If omitted, a blank table file is created. |
Returns[edit]
TableFile — The created table file object.
Description[edit]
createTableFile adds a file entry to the current cheat table.
This is useful for packaging resources with a table, such as sounds, images, binary data, configuration files, or other files used by Lua scripts. The file can later be retrieved with findTableFile, saved back to disk, or accessed through its MemoryStream.
Examples[edit]
Create a blank table file[edit]
1 local file = createTableFile("runtime.dat")
2
3 print("Created table file: " .. file.Name)
Create a table file from disk[edit]
1 local file = createTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]])
2
3 print("Added table file: " .. file.Name)
Play an embedded sound[edit]
1 local file = createTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]])
2
3 playSound(file)
Create the file only if it does not already exist[edit]
1 local file = findTableFile("config.json")
2
3 if file == nil then
4 file = createTableFile("config.json", [[C:\\SomeDirectory\\config.json]])
5 end
6
7 print("Using table file: " .. file.Name)
Replace an existing table file[edit]
1 local oldFile = findTableFile("config.json")
2
3 if oldFile ~= nil then
4 oldFile.delete()
5 end
6
7 local newFile = createTableFile("config.json", [[C:\\SomeDirectory\\config.json]])
8
9 print("Replaced table file: " .. newFile.Name)
Save the created table file to disk[edit]
1 local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]])
2
3 file.saveToFile([[C:\\Temp\\data_copy.bin]])
Read the created file as a MemoryStream[edit]
1 local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]])
2 local stream = file.getData()
3
4 print("Stream size: " .. tostring(stream.Size))
Access the Stream property[edit]
1 local file = createTableFile("data.bin", [[C:\\SomeDirectory\\data.bin]])
2 local stream = file.Stream
3
4 stream.Position = 0
5
6 print("Stream size: " .. tostring(stream.Size))
Create multiple table files[edit]
1 local files = {
2 { name = "startup.wav", path = [[C:\\Sounds\\startup.wav]] },
3 { name = "success.wav", path = [[C:\\Sounds\\success.wav]] },
4 { name = "failed.wav", path = [[C:\\Sounds\\failed.wav]] }
5 }
6
7 for i, entry in ipairs(files) do
8 if findTableFile(entry.name) == nil then
9 createTableFile(entry.name, entry.path)
10 end
11 end
Use a helper function[edit]
1 local function ensureTableFile(name, path)
2 local file = findTableFile(name)
3
4 if file == nil then
5 file = createTableFile(name, path)
6 end
7
8 return file
9 end
10
11 local sound = ensureTableFile("protected.wav", [[C:\\SomeDirectory\\protected.wav]])
12
13 playSound(sound)
Adding a File through the GUI[edit]
To add a file to your table manually, open the Table menu and choose Add File.
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.

