Advertisement
DOGGYWOOF

Untitled

Aug 6th, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. -- Define the key elements to check for in the startup scripts
  2. local requiredElements = {
  3. "local requiredFiles = {", -- Definition of the requiredFiles table
  4. "/disk/bootloader/VA11-ILLA.lua", -- Specific file path
  5. "/disk/os/home.lua", -- Specific file path
  6. "/disk/os/lock.lua", -- Specific file path
  7. "/disk/boot/boot-animation", -- Specific file path
  8. "/disk/error/BSOD.lua", -- Specific file path
  9. "os.pullEvent = os.pullEventRaw", -- Overriding os.pullEvent
  10. "local function checkFiles()", -- Definition of checkFiles function
  11. "local missingFiles = {}", -- Initialization of missingFiles table
  12. "for _, fileName in ipairs(requiredFiles) do", -- Loop through requiredFiles
  13. "if not fs.exists(fileName) then", -- Check for file existence
  14. "table.insert(missingFiles, fileName)", -- Inserting missing files
  15. "return missingFiles", -- Return missing files
  16. "local function main()", -- Definition of main function
  17. "local missing = checkFiles()", -- Call checkFiles function
  18. "if #missing > 0 then", -- Check if any files are missing
  19. "shell.run(\"no-os\")", -- Run no-os script
  20. "else", -- Else branch for file existence
  21. "shell.run(\"/disk/boot/CFW-check.lua\")", -- Run start-check.lua
  22. "end", -- End of if-else block
  23. "main()" -- Call the main function
  24. }
  25.  
  26. -- Function to read a file's content
  27. local function readFile(path)
  28. if not fs.exists(path) then
  29. return nil
  30. end
  31.  
  32. local file = fs.open(path, "r")
  33. local content = file.readAll()
  34. file.close()
  35. return content
  36. end
  37.  
  38. -- Function to check for the presence of key elements in a script
  39. local function checkForElements(content, elements)
  40. if not content then
  41. return false
  42. end
  43.  
  44. for _, element in ipairs(elements) do
  45. if not string.find(content, element, 1, true) then
  46. return false
  47. end
  48. end
  49.  
  50. return true
  51. end
  52.  
  53. -- Function to check if dev.cfg exists and show a message if necessary
  54. local function checkDevMode()
  55. if fs.exists("/dev.cfg") then
  56. term.clear()
  57. term.setBackgroundColor(colors.black)
  58. term.setTextColor(colors.white)
  59. term.setCursorPos(1, 1)
  60. term.write("IGNORE MODIFIED BOOTLOADER WHEN DEV MODE ON: YES")
  61. sleep(2) -- Show the message for 2 seconds
  62. return true -- Indicate that dev mode is active
  63. end
  64. return false -- Indicate that dev mode is not active
  65. end
  66.  
  67. -- Function to clear the screen and display a fixed error message
  68. local function showFatalError()
  69. term.clear()
  70. term.setBackgroundColor(colors.black)
  71. term.setTextColor(colors.white)
  72. term.clear()
  73.  
  74. local width, height = term.getSize()
  75.  
  76. local function centerText(y, text, textColor)
  77. local x = math.floor((width - #text) / 2)
  78. term.setCursorPos(x, y)
  79. term.setTextColor(textColor)
  80. term.write(text)
  81. end
  82.  
  83. local fatalArt = {
  84. " |\\_/| ",
  85. " | X X ",
  86. " | <> _ ",
  87. " | _/\\------____ ((| |))",
  88. " | `--' | ",
  89. " _____|_ ___| |___. ",
  90. "/_/_____/____/_______| "
  91. }
  92.  
  93. term.setTextColor(colors.red)
  94. local startLine = math.floor((height - #fatalArt - 4) / 2) -- Adjust start line for ASCII art
  95.  
  96. for i, line in ipairs(fatalArt) do
  97. centerText(startLine + i, line, colors.red)
  98. end
  99.  
  100. term.setTextColor(colors.white)
  101. centerText(startLine + #fatalArt + 2, "Error:", colors.white) -- Position adjusted
  102. centerText(startLine + #fatalArt + 3, "CFW Verification Error", colors.white) -- Position adjusted
  103. centerText(height - 2, "Please contact support.", colors.white) -- Added back at the bottom
  104.  
  105. while true do
  106. sleep(1)
  107. end
  108. end
  109.  
  110. -- Modified compareStartupFiles function with dev.cfg check
  111. local function compareStartupFiles()
  112. local startupContent = readFile("/startup")
  113. local startupLuaContent = readFile("/startup.lua")
  114.  
  115. if checkForElements(startupContent, requiredElements) or checkForElements(startupLuaContent, requiredElements) then
  116. -- All required elements are present; run the start-check.lua script
  117. shell.run("/disk/boot/start-check.lua")
  118. else
  119. -- Required elements are missing
  120. local devMode = checkDevMode() -- Check for dev mode before showing the fatal error
  121.  
  122. if not devMode then
  123. -- If not in dev mode, show fatal error
  124. print("Error: The startup script does not contain all required elements.")
  125. showFatalError()
  126. else
  127. -- In dev mode, run a fallback script instead of showing the fatal error
  128. shell.run("/disk/boot/next-program.lua") -- Replace with the actual fallback script
  129. end
  130. end
  131. end
  132.  
  133. -- Run the comparison function with error handling
  134. local success, _ = pcall(compareStartupFiles)
  135. if not success then
  136. local devMode = checkDevMode() -- Check for dev mode before showing the fatal error
  137.  
  138. if not devMode then
  139. -- If not in dev mode, show fatal error
  140. showFatalError()
  141. else
  142. -- In dev mode, run a fallback script instead of showing the fatal error
  143. shell.run("/disk/boot/next-program.lua") -- Replace with the actual fallback script
  144. end
  145. end
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement