Difference between revisions of "Lua:Class:TableFile"
Jump to navigation
Jump to search
(Major overhaul of the post.) |
|||
| (4 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | + | {{Class|'''class''' TableFile ''':''' Object}} | |
| − | + | The TableFile class represents a file embedded in the current cheat table. | |
| − | Table files can be | + | Table files can be created with [[Lua:createTableFile|createTableFile]] or retrieved with [[Lua:findTableFile|findTableFile]]. Their contents can be accessed through a [[Lua:Class:MemoryStream|MemoryStream]], saved to disk, or used directly by functions that accept table files. |
| − | |||
| − | == | + | ===Inheritance=== |
| − | ; [[ | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
| − | + | !align="left"|Class | |
| + | !align="left"|Inherits From | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |TableFile | ||
| + | |[[Lua:Class:Object|Object]] | ||
| + | |Represents a file stored inside the cheat table. | ||
| + | |} | ||
| − | ; [[createTableFile]]( | + | ===Related Functions=== |
| − | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | |
| − | + | !align="left"|Function | |
| + | !align="left"|Return Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |[[Lua:findTableFile|findTableFile]](filename) | ||
| + | |TableFile | ||
| + | |Returns the TableFile object for a file stored in the cheat table. | ||
| + | |- | ||
| + | |[[Lua:createTableFile|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 == | + | ===Properties=== |
| − | ; Name | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
| − | : The | + | !align="left"|Property |
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |Name | ||
| + | |String | ||
| + | |The name of the file stored in the cheat table. | ||
| + | |- | ||
| + | |Stream | ||
| + | |[[Lua:Class:MemoryStream|MemoryStream]] | ||
| + | |The stream containing the file data. | ||
| + | |} | ||
| − | ; | + | ===Methods=== |
| − | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | |
| + | !align="left"|Method | ||
| + | !align="left"|Return Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |delete() | ||
| + | |void | ||
| + | |Deletes this file from the cheat table. | ||
| + | |- | ||
| + | |saveToFile(filename) | ||
| + | |void | ||
| + | |Saves this table file to disk. | ||
| + | |- | ||
| + | |getData() | ||
| + | |[[Lua:Class:MemoryStream|MemoryStream]] | ||
| + | |Returns a MemoryStream object containing the file data. | ||
| + | |} | ||
| − | == | + | ===Examples=== |
| − | |||
| − | |||
| − | + | ====Find an embedded table file==== | |
| − | + | <syntaxhighlight lang="lua" line> | |
| + | local file = findTableFile("protected.wav") | ||
| − | + | if file ~= nil then | |
| − | + | print("Found table file: " .. file.Name) | |
| − | + | end | |
| − | + | </syntaxhighlight> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | ====Play an embedded sound==== | |
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("protected.wav") | ||
| + | |||
| + | if file ~= nil then | ||
| + | playSound(file) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====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("config.json", [[C:\\Temp\\config.json]]) | ||
| + | |||
| + | print("Added table file: " .. file.Name) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save a table file to disk==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("config.json") | ||
| + | |||
| + | if file ~= nil then | ||
| + | file.saveToFile([[C:\\Temp\\config_copy.json]]) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Read table file data as a MemoryStream==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("data.bin") | ||
| + | |||
| + | if file ~= nil then | ||
| + | local stream = file.getData() | ||
| + | |||
| + | print("Stream size: " .. tostring(stream.Size)) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Access the Stream property==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("data.bin") | ||
| + | |||
| + | if file ~= nil then | ||
| + | local stream = file.Stream | ||
| + | |||
| + | stream.Position = 0 | ||
| + | print("Stream size: " .. tostring(stream.Size)) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local fileStr = nil | ||
| + | local tableFile = findTableFile('PlayerBaseHook.CEA') | ||
| + | if tableFile ~= nil then | ||
| + | local stringStream = createStringStream() | ||
| + | stringStream.Position = 0 -- if not set before using 'copyFrom' the 'StringStream' object will be inconsistent. | ||
| + | stringStream.copyFrom(tableFile.Stream, tableFile.Stream.Size) | ||
| + | fileStr = stringStream.DataString | ||
| + | stringStream.destroy() | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Copy table file data into another MemoryStream==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("data.bin") | ||
| + | |||
| + | if file ~= nil then | ||
| + | local source = file.getData() | ||
| + | local copy = createMemoryStream() | ||
| + | |||
| + | source.Position = 0 | ||
| + | copy.copyFrom(source, source.Size) | ||
| + | |||
| + | print("Copied bytes: " .. tostring(copy.Size)) | ||
| + | |||
| + | copy.destroy() | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Delete a table file==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local file = findTableFile("old_data.bin") | ||
| + | |||
| + | if file ~= nil then | ||
| + | file.delete() | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Replace an embedded file==== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local oldFile = findTableFile("config.json") | ||
| + | |||
| + | if oldFile ~= nil then | ||
| + | oldFile.delete() | ||
| + | end | ||
| + | |||
| + | local newFile = createTableFile("config.json", [[C:\\Temp\\config.json]]) | ||
| − | + | print("Replaced table file: " .. newFile.Name) | |
| − | + | </syntaxhighlight> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | {{LuaSeeAlso}} | |
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 18:55, 25 June 2026
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[edit]
| Class | Inherits From | Description |
|---|---|---|
| TableFile | Object | Represents a file stored inside the cheat table. |
Related Functions[edit]
| 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[edit]
| Property | Type | Description |
|---|---|---|
| Name | String | The name of the file stored in the cheat table. |
| Stream | MemoryStream | The stream containing the file data. |
Methods[edit]
| 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[edit]
Find an embedded table file[edit]
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[edit]
1 local file = findTableFile("protected.wav")
2
3 if file ~= nil then
4 playSound(file)
5 end
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("config.json", [[C:\\Temp\\config.json]])
2
3 print("Added table file: " .. file.Name)
Save a table file to disk[edit]
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[edit]
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[edit]
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[edit]
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[edit]
1 local file = findTableFile("old_data.bin")
2
3 if file ~= nil then
4 file.delete()
5 end
Replace an embedded 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:\\Temp\\config.json]])
8
9 print("Replaced table file: " .. newFile.Name)