Lua:Class:TableFile
Jump to navigation
Jump to search
The TableFile class represents a file embedded in the current cheat table.
Table files can be created with createTableFile or retrieved with findTableFile. Their contents can be accessed through a MemoryStream, saved to disk, or used directly by functions that accept table files.
Contents
- 1 Inheritance
- 2 Related Functions
- 3 Properties
- 4 Methods
- 5 Examples
- 5.1 Find an embedded table file
- 5.2 Play an embedded sound
- 5.3 Create a blank table file
- 5.4 Create a table file from disk
- 5.5 Save a table file to disk
- 5.6 Read table file data as a MemoryStream
- 5.7 Access the Stream property
- 5.8 Copy table file data into another MemoryStream
- 5.9 Delete a table file
- 5.10 Replace an embedded file
Inheritance
| Class | Inherits From | Description |
|---|---|---|
| TableFile | Object | Represents a file stored inside the cheat table. |
Related Functions
| Function | Return Type | Description |
|---|---|---|
| findTableFile(filename) | TableFile | Returns the TableFile object for a file stored in the cheat table. |
| createTableFile(filename, filepath OPTIONAL) | TableFile | Adds a new file to the cheat table. If filepath is not specified, it creates a blank file. If filepath is specified, it reads the contents from disk. |
Properties
| Property | Type | Description |
|---|---|---|
| Name | String | The name of the file stored in the cheat table. |
| Stream | MemoryStream | The stream containing the file data. |
Methods
| Method | Return Type | Description |
|---|---|---|
| delete() | void | Deletes this file from the cheat table. |
| saveToFile(filename) | void | Saves this table file to disk. |
| getData() | MemoryStream | Returns a MemoryStream object containing the file data. |
Examples
Find an embedded table file
1 local file = findTableFile("protected.wav")
2
3 if file ~= nil then
4 print("Found table file: " .. file.Name)
5 end
Play an embedded sound
1 local file = findTableFile("protected.wav")
2
3 if file ~= nil then
4 playSound(file)
5 end
Create a blank table file
1 local file = createTableFile("runtime.dat")
2
3 print("Created table file: " .. file.Name)
Create a table file from disk
1 local file = createTableFile("config.json", [[C:\\Temp\\config.json]])
2
3 print("Added table file: " .. file.Name)
Save a table file to disk
1 local file = findTableFile("config.json")
2
3 if file ~= nil then
4 file.saveToFile([[C:\\Temp\\config_copy.json]])
5 end
Read table file data as a MemoryStream
1 local file = findTableFile("data.bin")
2
3 if file ~= nil then
4 local stream = file.getData()
5
6 print("Stream size: " .. tostring(stream.Size))
7 end
Access the Stream property
1 local file = findTableFile("data.bin")
2
3 if file ~= nil then
4 local stream = file.Stream
5
6 stream.Position = 0
7 print("Stream size: " .. tostring(stream.Size))
8 end
1 local fileStr = nil
2 local tableFile = findTableFile('PlayerBaseHook.CEA')
3 if tableFile ~= nil then
4 local stringStream = createStringStream()
5 stringStream.Position = 0 -- if not set before using 'copyFrom' the 'StringStream' object will be inconsistent.
6 stringStream.copyFrom(tableFile.Stream, tableFile.Stream.Size)
7 fileStr = stringStream.DataString
8 stringStream.destroy()
9 end
Copy table file data into another MemoryStream
1 local file = findTableFile("data.bin")
2
3 if file ~= nil then
4 local source = file.getData()
5 local copy = createMemoryStream()
6
7 source.Position = 0
8 copy.copyFrom(source, source.Size)
9
10 print("Copied bytes: " .. tostring(copy.Size))
11
12 copy.destroy()
13 end
Delete a table file
1 local file = findTableFile("old_data.bin")
2
3 if file ~= nil then
4 file.delete()
5 end
Replace an embedded file
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:\\Temp\\config.json]])
8
9 print("Replaced table file: " .. newFile.Name)