Advertisement
AssortedBrunoz

Nsp phone

Dec 19th, 2024 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.07 KB | None | 0 0
  1. local basalt = require("basalt")
  2. local DiscoHook = require("DiscoHook")
  3. local webhook = DiscoHook.create("https://discord.com/api/webhooks/1316102809002836059/B_2l6RncV-J8dUwXGSHl7r2v0f0o1K5sXi8ckZO45cK8pczq6_vaL7ELbn8gn3RJLEvE")
  4. local version = 1.003
  5. if tonumber(http.get("https://pastebin.com/raw/L8PN2RTy").readAll()) ~= version then
  6.     fs.delete(shell.getRunningProgram())
  7.     shell.run("pastebin get d6vviWbb startup.lua")
  8.     print("rebooting, update successful")
  9.     shell.run("reboot")
  10. end
  11. require("stringtools")()
  12. local main = basalt.createFrame()
  13.     :setSize(26, 20)
  14.     :setTheme(
  15.         {
  16.             BaseFrameBG = colors.gray,
  17.             BaseFrameText = colors.gray,
  18.             FrameBG = colors.black,
  19.             FrameText = colors.gray,
  20.             ButtonBG = colors.lightBlue,
  21.             ButtonText = colors.gray,
  22.             CheckboxBG = colors.gray,
  23.             CheckboxText = colors.white,
  24.             InputBG = colors.gray,
  25.             InputText = colors.lightGray,
  26.             TextfieldBG = colors.lightGray,
  27.             TextfieldText = colors.gray,
  28.             ListBG = colors.gray,
  29.             ListText = colors.gray,
  30.             MenubarBG = colors.gray,
  31.             MenubarText = colors.gray,
  32.             DropdownBG = colors.gray,
  33.             DropdownText = colors.gray,
  34.             RadioBG = colors.gray,
  35.             RadioText = colors.gray,
  36.             SelectionBG = colors.gray,
  37.             SelectionText = colors.lightGray,
  38.             GraphicBG = colors.blue,
  39.             ImageBG = colors.gray,
  40.             PaneBG = colors.gray,
  41.             ProgramBG = colors.gray,
  42.             ProgressbarBG = colors.gray,
  43.             ProgressbarText = colors.gray,
  44.             ProgressbarActiveBG = colors.gray,
  45.             ScrollbarBG = colors.lightGray,
  46.             ScrollbarText = colors.blue,
  47.             ScrollbarSymbolColor = colors.blue,
  48.             SliderBG = false,
  49.             SliderText = colors.gray,
  50.             SliderSymbolColor = colors.gray,
  51.             SwitchBG = colors.lightGray,
  52.             SwitchText = colors.gray,
  53.             LabelBG = false,
  54.             LabelText = colors.gray,
  55.             GraphBG = colors.gray,
  56.             GraphText = colors.gray
  57.         }
  58.     )
  59. local subFrames = {
  60.     mainMenu = main:addFrame()
  61.         :setSize("parent.w", "parent.h - 1")
  62.         :setPosition(1,2)
  63.         :setBackground(colors.lightGray)
  64.         :hide(),
  65.     checklist = main:addFrame()
  66.         :setSize("parent.w", "parent.h - 1")
  67.         :setPosition(1,2)
  68.         :setBackground(colors.lightGray)
  69.         :hide()
  70. }
  71. local allChars = {}
  72. local id = os.getComputerID()
  73.  
  74. for i = 0, 255 do
  75.     allChars[i] = string.char(i)
  76. end
  77. local function encrypt(message)
  78.     message = string.fracture(textutils.serialise(message))
  79.     local new = ""
  80.     for _, char in pairs(message) do
  81.         for _idx, _char in ipairs(allChars) do
  82.             if char == _char then
  83.                 new = new..allChars[(_idx+id)%#allChars]
  84.             end
  85.         end
  86.     end
  87.     return new.."_"..id
  88. end
  89.  
  90. local function decrypt(message)
  91.     message = string.fracture(message)
  92.     local unlockId = ""
  93.     for i = #message, 1, -1 do
  94.         if message[i] ~= "_" then
  95.             unlockId = unlockId..message[i]
  96.         else
  97.             for j = i, #message do
  98.                 message[j] = nil
  99.             end
  100.             break
  101.         end
  102.     end
  103. ---@diagnostic disable-next-line: cast-local-type
  104.     unlockId = tonumber(string.reverse(unlockId))
  105.     local new = ""
  106.     for _, char in pairs(message) do
  107.         for _idx, _char in ipairs(allChars) do
  108.             if char == _char then
  109.                 new = new..allChars[(_idx-unlockId)%#allChars]
  110.             end
  111.         end
  112.     end
  113.     return textutils.unserialise(new)
  114. end
  115.  
  116.  
  117. --storage
  118. local temp
  119. if not fs.exists("./storage.json") then
  120.     temp = fs.open("./storage.json", "w")
  121.     temp.write(textutils.serialiseJSON({
  122.         personalChecklist = {},
  123.         lastScreen = "mainMenu"
  124.     }))
  125.     temp.close()
  126. end
  127. local storageJson = fs.open("./storage.json", "r")
  128. local storage = textutils.unserialiseJSON(storageJson.readAll())
  129. subFrames[storage.lastScreen]:show()
  130. local function saveStorage()
  131.     temp = fs.open("storage.json", "w")
  132.     temp.write(textutils.serialiseJSON(storage))
  133.     temp.close()
  134. end
  135.  
  136. local function openSubFrame(index)
  137.     for _, frame in pairs(subFrames) do
  138.         frame:hide()
  139.     end
  140.     subFrames[index]:show()
  141.     storage.lastScreen = index
  142.     saveStorage()
  143. end
  144.  
  145.  
  146. --main menu placeholder
  147. subFrames.mainMenu:addLabel()
  148.     :setText("No main menu, have a guide: below is your app bar with a checklist and a return to main menu button, top right is the time, the triangle is the connection status to base, red is disconnected, yellow means no modem is connected and green is connected")
  149.     :setSize(20,15)
  150.  
  151. --checklist
  152. local space_used = 0
  153. local taskObjects = {}
  154. local tasks = subFrames.checklist:addFrame()
  155.     :setSize(25,15)
  156.     :setBackground(colors.lightGray)
  157.  
  158. subFrames.checklist:addScrollbar()
  159.     :setPosition(26,1)
  160.     :setSize(1,15)
  161.     :setScrollAmount(#storage.personalChecklist*3)
  162.     :onChange(function(_, _, value)
  163.         tasks:setOffset(0, value-1)
  164.     end)
  165. local input = subFrames.checklist:addFrame()
  166.     :setSize("parent.w", "parent.h")
  167.     :setBackground(colors.lightGray)
  168.     :hide()
  169.  
  170. input:addLabel()
  171.     :setText("Create task:")
  172. local inText = input:addInput()
  173.     :setPosition(2,2)
  174.     :setSize(24,1)
  175.     :setBackground(colors.gray)
  176.     :setForeground(colors.black)
  177.     :setDefaultText("Clean the dishes")
  178.  
  179. input:addButton()
  180.     :setPosition(1,4)
  181.     :setText("Cancel")
  182.     :setSize(6,1)
  183.     :setBackground(colors.red)
  184.     :setForeground(colors.black)
  185.     :onClick(function()
  186.         input:hide()
  187.         tasks:show()
  188.     end)
  189.  
  190. tasks:setSize(16, space_used+15)
  191. local function updatePersonalTasks()
  192.     tasks:removeChildren()
  193.     for index, task in pairs(storage.personalChecklist) do
  194.         local indent = index * 2 + string.height(table.concat(string.wordWrap(storage.personalChecklist[index-1] and storage.personalChecklist[index-1] or "",16),"\n"))
  195.         local checkBox = tasks:addCheckbox()
  196.             :setSize(1,1)
  197.             :setPosition(2, indent)
  198.             :onChange(function ()
  199.                 table.remove(storage.personalChecklist, index)
  200.                 updatePersonalTasks()
  201.                 saveStorage()
  202.             end)
  203.  
  204.    
  205.         local taskLabel = tasks:addLabel()
  206.         taskLabel:setText(task)
  207.         taskLabel:setPosition(4, indent)
  208.         taskLabel:setSize(16, "parent.h")
  209.         space_used = space_used + indent + string.height(task)
  210.    
  211.         table.insert(taskObjects,{checkBox,taskLabel})
  212.     end
  213.     tasks:addButton()
  214.         :setSize(1,1)
  215.         :setPosition(2, (#storage.personalChecklist+1) * 2 + string.height(table.concat(string.wordWrap(storage.personalChecklist[#storage.personalChecklist-1] and storage.personalChecklist[#storage.personalChecklist-1] or "",25),"\n")))
  216.         :setBackground(colors.green)
  217.         :setForeground(colors.black)
  218.         :setText("+")
  219.         :onClick(function()
  220.             tasks:hide()
  221.             input:show()
  222.         end)
  223. end
  224. input:addButton()
  225.     :setPosition(20,4)
  226.     :setText("Finish")
  227.     :setSize(6,1)
  228.     :setBackground(colors.green)
  229.     :setForeground(colors.black)
  230.     :onClick(function()
  231.         table.insert(storage.personalChecklist, inText:getValue())
  232.         saveStorage()
  233.         input:hide()
  234.         updatePersonalTasks()
  235.         tasks:show()
  236.     end)
  237. updatePersonalTasks()
  238.  
  239.  
  240. -- stuff that stays on top
  241. --topBar
  242. local topBar = main:addFrame():setSize("parent.w",1):setBackground(colors.blue)
  243. local factionLabel = topBar:addLabel()
  244.     :setText("NSPhone")
  245.     :setForeground(colors.black)
  246. local timeLabel = topBar:addLabel()
  247.     :setForeground(colors.black)
  248. local connectionSymbol = topBar:addButton()
  249.     :setText("\31")
  250.     :setForeground(colors.black)
  251.     :setBackground(colors.blue)
  252.     :setSize(1,1)
  253.  
  254. local function awaitMessage(channel, timeOut, condition)
  255.     local toReturn = {}
  256.     parallel.waitForAny(function()
  257.         repeat
  258.             os.sleep(1)
  259.             timeOut = timeOut - 1
  260.         until timeOut <= 0
  261.         toReturn = {false}
  262.     end, function()
  263.         while next(toReturn) == nil do
  264.             local received = table.pack(os.pullEvent("modem_message"))
  265.             if received[3] == channel then
  266.                 received[5] = decrypt(received[5])
  267.                 if condition(received[5]) then
  268.                     toReturn = {true, received}
  269.                 else
  270.                     toReturn = {false}
  271.                 end
  272.             end
  273.         end
  274.     end)
  275.     return table.unpack(toReturn)
  276. end
  277. local modem, _ = peripheral.find("modem")
  278. modem.open(48084)
  279. local function attemptConnection()
  280.     modem, _ = peripheral.find("modem")
  281.     if modem ~= nil then
  282.         --[[
  283.             48084: Receive connection verification
  284.             48184: Send connection verification
  285.         ]]
  286.         modem.transmit(48184, 48084, encrypt({
  287.             operation = "connect",
  288.             connector = "phone",
  289.             lookingFor = "home"
  290.         }))
  291.         local success, _ = awaitMessage(48084, 10, function(message)
  292.             if message.name == "home" and message.operation == "connect" and message.status == true then
  293.                 return true
  294.             else
  295.                 return false
  296.             end
  297.         end)
  298.         return success
  299.     else
  300.         return nil
  301.     end
  302. end
  303. local connectionThread = main:addThread()
  304.     :start(function()
  305.         while true do
  306.             local connectionStatus = attemptConnection()
  307.             if connectionStatus == nil then
  308.                 connectionSymbol:setText("\17")
  309.                     :setForeground(colors.yellow)
  310.             elseif connectionStatus then
  311.                 connectionSymbol:setText("\30")
  312.                     :setForeground(colors.green)
  313.             else
  314.                 connectionSymbol:setText("\31")
  315.                     :setForeground(colors.red)
  316.             end
  317.             os.sleep(1)
  318.         end
  319.     end)
  320.  
  321. --local radarThread = main:addThread()
  322. --    :start(function()
  323. --        modem.open(37073)
  324. --        while true do
  325. --            local _, _, channel, replyChannel, message, _ = os.pullEvent("modem_message")
  326. --            message = decrypt(message)
  327. --            if message.lookingForType == "phone" and message.operation == "radarCheck" and message.connector == "pc" then
  328. --                modem.transmit(replyChannel, channel, encrypt({
  329. --                    operation = "radarResponse",
  330. --                    connector = "phone",
  331. --                    lookingFor = message.sender
  332. --                }))
  333. --            end
  334. --        end
  335. --    end)
  336.  
  337. local clockThread = main:addThread()
  338.     :start(function()
  339.         local time = textutils.formatTime(os.time(),true)
  340.         local position = 26-string.len(time)
  341.         timeLabel:setText(time):setPosition(position)
  342.         while true do
  343.             time = textutils.formatTime(os.time(),true)
  344.             timeLabel:setText(time):setPosition(position)
  345.             connectionSymbol:setPosition(position-2)
  346.             os.sleep(0.5)
  347.         end
  348.     end)
  349.  
  350. --appBar
  351. local appBar = main:addFrame():setSize("parent.w",5):setPosition(1,16):setBackground(colors.gray)
  352.  
  353. --checklist button
  354. appBar:addButton()
  355.     :setText("\140\140\140")
  356.     :setVerticalAlign("top")
  357.     :setBackground(false)
  358.     :setSize(5, 3)
  359.     :setPosition(11,2)
  360.     :onClick(function()
  361.         updatePersonalTasks()
  362.         openSubFrame("checklist")
  363.     end)
  364. appBar:addPane()
  365.     :setPosition(11,2)
  366.     :setSize(5,3)
  367.     :setBackground(colors.white)
  368. appBar:addPane()
  369.     :setPosition(12,1)
  370.     :setSize(3,1)
  371.     :setBackground(false, "\95",colors.lightGray)
  372. appBar:addLabel()
  373.     :setText("\140\140\140\n\140\140\140")
  374.     :setPosition(12,3)
  375.  
  376. --main menu button
  377. appBar:addButton()
  378.     :setText("<")
  379.     :setBackground(colors.white)
  380.     :setSize(5,3)
  381.     :setPosition(2,2)
  382.     :onClick(function()
  383.         openSubFrame("mainMenu")
  384.     end)
  385.  
  386. basalt.autoUpdate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement