Advertisement
JayRain

Ini Parser

Jun 1st, 2020
1,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. --Credits to LIP for older version coded for vanilla Lua, I ported + added some adjustments specifically for Roblox Exploit Lua.
  2. local LIP = {}
  3. LIP.__index = LIP
  4. function LIP:load(fileName)
  5.     assert(type(fileName) == "string", string.format("Expected string as argument #1, got %s", type(fileName)))
  6.     assert(pcall(readfile, fileName), string.format("The Ini file with the name '%s' doesn't exist in workspace folder", fileName or "empty"))
  7.     local data = {}
  8.     local section
  9.     local file = readfile(fileName)
  10.     for index, line in pairs(file:split("\n")) do
  11.         local tempSection = line:match("^%[([^%[%]]+)%]$")
  12.         if(tempSection)then
  13.             section = tonumber(tempSection) and tonumber(tempSection) or tempSection
  14.             data[section] = data[section] or {}
  15.         end
  16.         local param, value = line:match("^([%w|_]+)%s-=%s-(.+)$")
  17.         if(param and value ~= nil)then
  18.             if(tonumber(value))then
  19.                 value = tonumber(value)
  20.             elseif(value == "true")then
  21.                 value = true
  22.             elseif(value == "false")then
  23.                 value = false
  24.             end
  25.             if(tonumber(param))then
  26.                 param = tonumber(param)
  27.             end
  28.             data[section][param] = value
  29.         end
  30.     end
  31.     return data
  32. end
  33.  
  34. function LIP:save(fileName, data)
  35.     assert(writefile, "Your exploit doesn't support writefile.")
  36.     assert(type(fileName) == "string", string.format("Expected string as argument #1, got %s", type(fileName)))
  37.     assert(type(data) == "table", string.format("Expected table as argument #2, got %s", type(data)))
  38.     local contents = ""
  39.     for section, param in pairs(data) do
  40.         contents = contents .. ("[%s]\n"):format(section)
  41.         for key, value in pairs(param) do
  42.             contents = contents .. ("%s=%s\n"):format(key, tostring(value))
  43.         end
  44.         contents = contents .. "\n"
  45.     end
  46.     writefile(fileName, contents)
  47. end
  48.  
  49. function LIP:delete(fileName)
  50.     assert(delfile, "Your exploit doesn't support delfile.")
  51.     assert(type(fileName) == "string", string.format("Expected string as argument #1, got %s", type(fileName)))
  52.     assert(pcall(delfile, fileName), string.format("Failed to delete ini file named '%s'", fileName or "empty"))
  53.     return true
  54. end
  55. return LIP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement