Resource:Compiler: Difference between revisions
Line 71: | Line 71: | ||
<section name="Server" class="server" show="true"> | <section name="Server" class="server" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEventHandler( "onResourceStart", | addEventHandler( "onResourceStart", resourceRoot, function() | ||
local encryptedData = exports.Compiler:fileCompile("yourFile.txt", "YourPassword") | local encryptedData = exports.Compiler:fileCompile("yourFile.txt", "YourPassword") | ||
if encryptedData then | if encryptedData then | ||
Line 88: | Line 88: | ||
<section name="Client" class="client" show="true"> | <section name="Client" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEventHandler( "onClientResourceStart", | addEventHandler( "onClientResourceStart", resourceRoot, function() | ||
local txd = exports.Compiler:fileCompile("banshee.txd", "YourPassword") | local txd = exports.Compiler:fileCompile("banshee.txd", "YourPassword") | ||
local dff = exports.Compiler:fileCompile("banshee.dff", "YourPassword") | local dff = exports.Compiler:fileCompile("banshee.dff", "YourPassword") | ||
Line 110: | Line 110: | ||
<section name="Server" class="server" show="true"> | <section name="Server" class="server" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEventHandler( "onResourceStart", | addEventHandler( "onResourceStart", resourceRoot, function() | ||
local decryptedData = exports.Compiler:fileDecompile("yourFile.txtc", "YourPassword") | local decryptedData = exports.Compiler:fileDecompile("yourFile.txtc", "YourPassword") | ||
if decryptedData then | if decryptedData then | ||
Line 124: | Line 124: | ||
<section name="Client" class="client" show="true"> | <section name="Client" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEventHandler( "onClientResourceStart", | addEventHandler( "onClientResourceStart", resourceRoot, function() | ||
local txd = exports.Compiler:fileDecompile("banshee.txdc", "YourPassword") | local txd = exports.Compiler:fileDecompile("banshee.txdc", "YourPassword") | ||
local dff = exports.Compiler:fileDecompile("banshee.dffc", "YourPassword") | local dff = exports.Compiler:fileDecompile("banshee.dffc", "YourPassword") |
Revision as of 12:44, 1 November 2021
This resource allows you to compile and decompile files of various types.
Overview
A simple-to-use resource that can be exported both on the client side and on the server side. consisting in the encryption/decryption of files
Exported functions
fileCompile
This function encrypts the data of the file
string exports.Compiler:fileCompile(string filePath, var key, [int maxBytes = 1024])
Required Arguments
- string filePath: The filepath of the file in the following format: ":resourceName/path". 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
- For example, if there is a file named 'coolObjects.txt' in the resource 'objectSearch', it can be opened from another resource this way: fileOpen(":objectSearch/coolObjects.txt").
- If the file is in the current resource, only the file path is necessary, e.g. fileOpen("coolObjects.txt").
- var key: The key you want to use as the file encoding key (the first 16 characters of the result are used)
Optional Arguments
- int maxBytes: Maximum interger of bytes to be encoded, default is 1024 bytes. (using less than 1024 bytes is not recommended)
Returns
Returns the encrypted bytes that have been read in the file, if something is unsuccessful, returns false.
fileDecompile
This function decrypted the data of the file
string exports.Compiler:fileDecompile(string filePath, var key)
Required Arguments
- string filePath: The filepath of the file in the following format: ":resourceName/path". 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
- For example, if there is a file named 'coolObjects.txt' in the resource 'objectSearch', it can be opened from another resource this way: fileOpen(":objectSearch/coolObjects.txt").
- If the file is in the current resource, only the file path is necessary, e.g. fileOpen("coolObjects.txt").
- var key: The key you want to use as the file decrypted key (the first 16 characters of the result are used)
Returns
Returns the decrypted bytes that have been read in the file, if something is unsuccessful, returns false.
replaceCompileFile
The function encrypts and overwrites the file or creates a new one at the specified path
boolean exports.Compiler:replaceCompileFile(string filePath, var key, [string newFilePath, int maxBytes])
Required Arguments
- string filePath: The filepath of the file in the following format: ":resourceName/path". 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
- For example, if there is a file named 'coolObjects.txt' in the resource 'objectSearch', it can be opened from another resource this way: fileOpen(":objectSearch/coolObjects.txt").
- If the file is in the current resource, only the file path is necessary, e.g. fileOpen("coolObjects.txt").
- var key: The key you want to use as the file decrypted key (the first 16 characters of the result are used)
Optional Arguments
- string newFilePath: Destination filepath for the specified source file in the same format.
- int maxBytes: Maximum interger of bytes to be encoded, default is 1024 bytes. (using less than 1024 bytes is not recommended)
Returns
Returns true on valid encryption, and returns false if unsuccessful
replaceDecompileFile
The function decrypted and overwrites the file or creates a new one at the specified path
boolean exports.Compiler:replaceDecompileFile(string filePath, var key, [string newFilePath])
Required Arguments
- string filePath: The filepath of the file in the following format: ":resourceName/path". 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
- For example, if there is a file named 'coolObjects.txt' in the resource 'objectSearch', it can be opened from another resource this way: fileOpen(":objectSearch/coolObjects.txt").
- If the file is in the current resource, only the file path is necessary, e.g. fileOpen("coolObjects.txt").
- var key: The key you want to use as the file decrypted key (the first 16 characters of the result are used)
Optional Arguments
- string newFilePath: Destination filepath for the specified source file in the same format.
Returns
Returns true on valid decryption, and returns false if unsuccessful
Examples
fileCompile
addEventHandler( "onResourceStart", resourceRoot, function() local encryptedData = exports.Compiler:fileCompile("yourFile.txt", "YourPassword") if encryptedData then local fileHandler = fileCreate("yourFile.txtc") fileWrite(fileHandler, encryptedData) fileClose(fileHandler) outputChatBox(encryptedData) outputChatBox("Successfully encrypted yourFile.txt") else outputChatBox("Failed to encrypted yourFile.txt") end end)
addEventHandler( "onClientResourceStart", resourceRoot, function() local txd = exports.Compiler:fileCompile("banshee.txd", "YourPassword") local dff = exports.Compiler:fileCompile("banshee.dff", "YourPassword") if txd and dff then local fileHandlerTxd = fileCreate("banshee.txdc") fileWrite(fileHandlerTxd, txd) fileClose(fileHandlerTxd) local fileHandlerDff = fileCreate("banshee.dffc") fileWrite(fileHandlerDff, dff) fileClose(fileHandlerDff) outputChatBox("Successfully encrypted model banshee") else outputChatBox("Failed to encrypted model banshee") end end)
fileDecompile
addEventHandler( "onResourceStart", resourceRoot, function() local decryptedData = exports.Compiler:fileDecompile("yourFile.txtc", "YourPassword") if decryptedData then outputChatBox(decryptedData) outputChatBox("Successfully decrypted yourFile.txtc") else outputChatBox("Failed to decrypted yourFile.txtc") end end)
addEventHandler( "onClientResourceStart", resourceRoot, function() local txd = exports.Compiler:fileDecompile("banshee.txdc", "YourPassword") local dff = exports.Compiler:fileDecompile("banshee.dffc", "YourPassword") if txd and dff then local loadTXD = engineLoadTXD(txd) engineImportTXD(loadTXD, 429) local loadDFF = engineLoadDFF(dff) engineReplaceModel(loadDFF, 429) outputChatBox("Successfully decrypted model banshee and loaded") else outputChatBox("Failed to decrypted model banshee") end end)