Advertisement
COOLGAMETUBEorginal

***[ComputerCraft] WicowsTools (API)

Aug 11th, 2015
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.67 KB | None | 0 0
  1. --[[DONT REMOVE THIS NOTICE!!!
  2. Download: pastebin get REaZXV7W WicowsTools || http://www.pastebin.com/REaZXV7W
  3. Copyright ©COOLGAMETUBE
  4. Copyright ©Buschrolle
  5. Copyright ©JcraftxD
  6.  
  7. Release: 11.08.2015
  8. Updated: 10.04.2016
  9.  
  10. EULA:
  11. -I will not share this API whithout this notice!
  12. -I'm able to modify and reupload it, if this notice haven't been removed.
  13. -I will credit COOLGAMETUBE.
  14. -I'm able to set my Credit, if this API has been modified(New Functions)
  15. -This API will be FREE available (no money)--]]
  16.  
  17. function packmanSystem()
  18.     if fs.exists("/usr/bin/packman") then
  19.         return true
  20.     else
  21.         return false
  22.     end
  23. end
  24.  
  25. local tArgs = {...}
  26.  
  27. function GetAuthor()
  28.     return "COOLGAMETUBE"
  29. end
  30.  
  31. function GetVersion()
  32.     return 1.311
  33. end
  34.  
  35. function MagicClear(t)
  36.     if not t then t = 0.5 end
  37.     l = {"[", "-", "]", " ", t}
  38.     x, y = term.getSize()
  39.     lt = ""
  40.     ct = ""
  41.     for i = 1, x do
  42.             le = l[2]
  43.             if i == 1 then le = l[1] end
  44.             if i == x then le = l[3] end
  45.             lt = lt .. le
  46.             ct = ct .. l[4]
  47.     end
  48.     for i = 1, y do
  49.             term.setCursorPos(1, i -1)
  50.             write(ct)
  51.             term.setCursorPos(1, i)
  52.             write(lt)
  53.             sleep(l[5])
  54.     end
  55.     term.setCursorPos(1, 1)
  56.     term.clear()
  57. end
  58.  
  59. function MagicSpam()
  60.     s = 0.1
  61.     x, y = term.getSize()
  62.     lt = ""
  63.     scnd = true
  64.     for i = 1, y do
  65.         for i = 1, x do
  66.             lt = lt .. tostring(math.random(0,9))
  67.         end
  68.         term.setCursorPos(1, i)
  69.         write(lt)
  70.         if scnd then
  71.             sleep(s)
  72.             scnd = false
  73.         else    
  74.             scnd = true
  75.         end
  76.     end
  77.     term.setCursorPos(1,y)
  78. end
  79.  
  80. function toInt(str)
  81.     num = ""
  82.     sp = false
  83.     for a = 1, string.len(str) do
  84.         l = string.sub(str, a,a)
  85.         if l == "0"
  86.         or l == "1"
  87.         or l == "2"
  88.         or l == "3"
  89.         or l == "4"
  90.         or l == "5"
  91.         or l == "6"
  92.         or l == "7"
  93.         or l == "8"
  94.         or l == "9"
  95.         or l == "." then
  96.             if l == "." and not sp then
  97.                 num = num .. l
  98.             elseif l ~= "." then
  99.                 num = num .. l
  100.             end
  101.         end
  102.     end
  103.     if num == "" or num == nil then num = 0 end
  104.     return tonumber(num)
  105. end
  106.  
  107. function digit_sum(num)
  108.     num = toInt(num)
  109.     num = tostring(num)
  110.    
  111.     numlet = {}
  112.     if string.len(num) > 1 then
  113.         for a = 1, string.len(num) do
  114.             numlet[a] = string.sub(num, a,a)
  115.         end
  116.     else
  117.         numlet[1] = num
  118.     end
  119.     local result = nil
  120.     if #numlet > 1 then
  121.         local rn = 0
  122.         for i = 1, #numlet do
  123.                 rn = rn + toInt(numlet[i])
  124.         end
  125.         result = rn
  126.     else
  127.         result = toInt(numlet[1])
  128.     end
  129.     return result
  130. end
  131.  
  132. function invert(num)
  133.     num = toInt(num)
  134.     num = tostring(num)
  135.     numlet = {}
  136.     if string.len(num) > 1 then
  137.         for a = 1, string.len(num) do
  138.             numlet[a] = string.sub(num, a,a)
  139.         end
  140.     else
  141.         numlet[1] = num
  142.     end
  143.  
  144.     local result = nil
  145.     if #numlet > 1 then
  146.         local rn = ""
  147.         for i = 1, (#numlet) do
  148.             rn = rn..numlet[#numlet-i+1]
  149.         end
  150.         result = rn
  151.     else
  152.         result = numlet[1]
  153.     end
  154.     return result
  155. end
  156.  
  157. function SplitStr(inputstr, sep)
  158.     if sep == nil then
  159.         sep = "%s"
  160.     end
  161.     local t={} ; i=1
  162.     if string.gmatch(inputstr, "([^"..sep.."]+)") then
  163.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  164.             t[i] = str
  165.             i = i + 1
  166.         end
  167.     end
  168.     return t
  169. end
  170.  
  171. function ReplaceStr(str, rep, to)  
  172.     if not rep then return nil end
  173.     str = tostring(str)
  174.     local pcs = SplitStr(str, rep)
  175.     str = pcs[1]
  176.     for n=2,#pcs do
  177.         str = str..to..pcs[n]
  178.     end
  179.     return str
  180. end
  181.  
  182. function WriteFile(file, text, append)
  183.     local m = "w"
  184.     if append == true then
  185.         m = "a"
  186.     end
  187.     if not fs.exists(file) then
  188.         if not fs.isReadOnly(file) then
  189.             f = fs.open(file, m)
  190.             f.write(text)
  191.             f.close()
  192.             return true
  193.         else
  194.             return false
  195.         end
  196.     else
  197.         return false
  198.     end
  199. end
  200.  
  201. function ReadFile(file)
  202.     if fs.exists(file) then
  203.         local f = fs.open(file, "r")
  204.         local text = f.readAll()
  205.         f.close()
  206.         if text ~= nil then
  207.             return text
  208.         else
  209.             return "ERROR!"
  210.         end
  211.     else
  212.         return false
  213.     end
  214. end
  215.  
  216. function safeSet(default, with)
  217.     if with then
  218.         ret = with
  219.     else
  220.         ret = default
  221.     end
  222.     return ret
  223. end
  224.  
  225. function SimpleClear()
  226.     term.setBackgroundColor(colors.black)
  227.     term.setTextColor(colors.white)
  228.     term.clear()
  229.     term.setCursorPos(1, 1)
  230. end
  231.  
  232. function CreateBorder(vwx, vwy, vx, vy)
  233.     local letters = {"+","-","|",}
  234.     local wx = safeSet(0, vwx)
  235.     local wy = safeSet(0, vwy)
  236.     local x,y = term.getSize()
  237.     if vy and vx then
  238.         x = vx
  239.         y = vy
  240.     else
  241.         term.clear()
  242.     end
  243.     local cy = 1  
  244.     local lt = ""
  245.     for i = 1, y do
  246.         cy = i
  247.         lt = ""
  248.         for i = 1, x do
  249.             if cy == 1 and i == 1 then
  250.                 lt = lt..letters[1]
  251.             elseif cy == 1 and i == x then
  252.                 lt = lt..letters[1]
  253.             elseif cy == y and i == 1 then
  254.                 lt = lt..letters[1]
  255.             elseif cy == y and i == x then
  256.                 lt = lt..letters[1]
  257.             elseif cy == 1 then
  258.                 lt = lt..letters[2]
  259.             elseif cy == y then
  260.                 lt = lt..letters[2]
  261.             elseif i == 1 then
  262.                 lt = lt..letters[3]
  263.             elseif i == x then
  264.                lt = lt..letters[3]
  265.             else
  266.                 lt = lt.." "
  267.             end
  268.         end
  269.         term.setCursorPos(wx+1, wy+i)
  270.         write(lt)
  271.     end
  272. end
  273.  
  274. function is(var)
  275.     if var then
  276.         return true
  277.     else
  278.         return false
  279.     end
  280. end
  281.  
  282. function Log(msg, terminal, add)
  283.     if terminal then
  284.         if terminal == term or terminal == term.current() then
  285.             if add then
  286.                 term.write(msg)
  287.             else
  288.                 print(msg)
  289.             end
  290.         else
  291.             if add then
  292.                 terminal.write(msg)
  293.             else
  294.                 x, y = terminal.getCursorPos()
  295.                 terminal.write(msg)
  296.                 terminal.setCursorPos(1, y+1)
  297.             end
  298.         end
  299.     end
  300. end
  301.  
  302. function GetRawWebString(url)
  303.     if type(url) ~="string" then
  304.         error("Can't execute function GetRawWebString(string) because parameter[1] is not a string!")
  305.         return false
  306.     end
  307.     local connection = http.get(url)
  308.     if connection then
  309.         local result = connection.readAll()
  310.         connection.close()
  311.         return result
  312.     else
  313.         return false
  314.     end
  315. end
  316. function CheckCompatible(file, returnVersion, outputTerm)
  317.     t = nil
  318.     o = nil
  319.     funcList = nil
  320.     osv = nil
  321.     fo = nil
  322.     f = nil
  323.     foundMv = nil
  324.     -------------
  325.     t = outputTerm
  326.     o = is(returnVersion)
  327.     funcList = textutils.unserialize(GetRawWebString("http://pastebin.com/raw.php?i=tvVjyfHD"))
  328.     osv = toInt(_CC_VERSION)
  329.     fo = fs.open(file, "r")
  330.     f = fo.readAll()
  331.     fo.close()
  332.     foundMv = false
  333.     for i = 1, #funcList["list"] do
  334.         if not foundMv then
  335.             Log("Check Version: "..funcList["list"][i]["vers"].." ...", t)
  336.             sleep(0.01) --yielding!
  337.             for fu = 1, #funcList["list"][i]["funcList"] do
  338.                 sleep(0.01) --yielding!
  339.                 if string.find(f, "turtle.")
  340.                 and trutle
  341.                 or not string.find(f, "turtle.")
  342.                 and not turtle then
  343.                     if string.find(f, funcList["list"][i]["funcList"][fu]) then
  344.                         foundMv = funcList["list"][i]["vers"]
  345.                     end
  346.                 end
  347.             end
  348.         end
  349.     end
  350.     r = nil
  351.     if foundMv then
  352.         if foundMv > osv then
  353.             Log("false, NOT compatible! Min Version: "..foundMv, t)
  354.             r = false
  355.         else
  356.             Log("true, Min Version: "..foundMv, t)
  357.             r = true
  358.         end
  359.     else
  360.         Log("true, Min Version: First Release!", t)
  361.         r = true
  362.     end
  363.     if o then
  364.         return r, foundMv
  365.     else
  366.         return r
  367.     end
  368. end
  369.  
  370. function GetWebHash(HashType, Data)
  371.     return GetRawWebString("http://coolgametube.net/cc/hash.php?mode="..HashType.."&str="..Data)
  372. end
  373.  
  374. function BigChar(char)
  375.         if char == "a" then return "A"
  376.     elseif char == "b" then return "B"
  377.     elseif char == "c" then return "C"
  378.     elseif char == "d" then return "D"
  379.     elseif char == "e" then return "E"
  380.     elseif char == "f" then return "F"
  381.     elseif char == "g" then return "G"
  382.     elseif char == "h" then return "H"
  383.     elseif char == "i" then return "I"
  384.     elseif char == "j" then return "J"
  385.     elseif char == "k" then return "K"
  386.     elseif char == "l" then return "L"
  387.     elseif char == "m" then return "M"
  388.     elseif char == "n" then return "N"
  389.     elseif char == "o" then return "O"
  390.     elseif char == "p" then return "P"
  391.     elseif char == "q" then return "Q"
  392.     elseif char == "r" then return "R"
  393.     elseif char == "s" then return "S"
  394.     elseif char == "t" then return "T"
  395.     elseif char == "u" then return "U"
  396.     elseif char == "v" then return "V"
  397.     elseif char == "w" then return "W"
  398.     elseif char == "x" then return "X"
  399.     elseif char == "y" then return "Y"
  400.     elseif char == "z" then return "Z"
  401.     elseif char == "ä" then return "Ä"
  402.     elseif char == "ö" then return "Ö"
  403.     elseif char == "ü" then return "Ü"
  404.     else return char end
  405. end
  406.  
  407. function BigLetters(text)
  408.     local BStr = ""
  409.     for i = 1, string.len(text) + 1 do
  410.         BStr = BStr..BigChar(string.sub(text, i,i))
  411.     end
  412.     return BStr
  413. end
  414.  
  415. function boolStr(obj)
  416.     res = is(obj)
  417.     if res then
  418.         return "true"
  419.     else
  420.         return "false"
  421.     end
  422. end
  423.  
  424. function getCenterStart(objSize, screenSize)
  425.     return ((screenSize/2)-(objSize/2))
  426. end
  427.  
  428. function compareTables(t1,t2,ignore_mt)
  429.    local ty1 = type(t1)
  430.    local ty2 = type(t2)
  431.    if ty1 ~= ty2 then return false end
  432.    if ty1 ~= 'table' and ty2 ~= 'table' then return t1 == t2 end
  433.    local mt = getmetatable(t1)
  434.    if not ignore_mt and mt and mt.__eq then return t1 == t2 end
  435.    for k1,v1 in pairs(t1) do
  436.       local v2 = t2[k1]
  437.       if v2 == nil or not compareTables(v1,v2) then return false end
  438.    end
  439.    for k2,v2 in pairs(t2) do
  440.       local v1 = t1[k2]
  441.       if v1 == nil or not compareTables(v1,v2) then return false end
  442.    end
  443.    return true
  444. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement