Example:
function string_padding_dword(s)
local l = 4 - string.len(s) % 4
return s .. string.rep(string.char(l), l)
end
function string_unpadding_dword(s)
return string.sub(s, 0, string.len(s) - string.byte(s, string.len(s)))
end
function FileProtection(path, key)
local file = fileOpen(path)
local size = fileGetSize(file)
local FirstPart = fileRead(file, 65536)
fileSetPos(file, 65536)
local SecondPart = fileRead(file, size - 65536)
fileClose(file)
file = fileCreate(path..'rw')
fileWrite(file, encodeString('tea', string_padding_dword(FirstPart), { key = key })..SecondPart)
fileClose(file)
return true
end
function FileUnProtection(path, key)
local file = fileOpen(path)
local size = fileGetSize(file)
local FirstPart = fileRead(file, 65536 + 4)
fileSetPos(file, 65536 + 4)
local SecondPart = fileRead(file, size - (65536 + 4))
fileClose(file)
-- file = fileCreate(path..'rw')
-- fileWrite(file, string_padding_dword( decodeString('tea', FirstPart, { key = key }) )..SecondPart)
-- fileClose(file)
return string_padding_dword( decodeString('tea', FirstPart, { key = key }) )..SecondPart
end
-- example
FileProtection('infernus.dff', 'GT4BAE')
-- FileUnProtection(path, key)
local txd = engineLoadTXD('infernus.txd')
engineImportTXD(txd, 401)
local dff = engineLoadDFF( FileUnProtection('infernus.dff', 'GT4BAE') )
engineReplaceModel(dff, 401)