Advertisement
PlatinKinggg

start.lua

May 29th, 2025 (edited)
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 KB | Gaming | 0 0
  1. -- Datei: start.lua
  2. -- Lädt die modabhängige Turbinensteuerung + GUI für CC: Tweaked mit effizientem Auto-Update
  3.  
  4. -- Mod-Erkennung über Peripherie
  5. local function getModType()
  6.   for _, name in ipairs(peripheral.getNames()) do
  7.     local ptype = peripheral.getType(name)
  8.     if ptype == "BigReactors-Turbine" then
  9.       return "BigReactors"
  10.     elseif ptype == "ExtremeReactors2-Turbine" then
  11.       return "ExtremeReactors"
  12.     elseif ptype == "BiggerReactors-Turbine" then
  13.       return "BiggerReactors"
  14.     end
  15.   end
  16.  
  17.   term.setTextColor(colors.red)
  18.   print("Kein unterstützter Reaktor-Mod gefunden!")
  19.   print("Programm wird gestoppt und der CC-Computer in 15 Sekunden heruntergefahren")
  20.   print("Bitte Fehler beheben und CC-Computer neustarten!")
  21.   sleep(15)
  22.   os.shutdown()
  23. end
  24.  
  25. -- Pastebin-Links
  26. local pastebinLinks = {
  27.  
  28.   BigReactors = {
  29.     turbine = "8xx3Ns3u" -- turbine_br.lua
  30.   },
  31.   ExtremeReactors = {
  32.     turbine = "<PASTEBIN_KEY_ER>"
  33.   },
  34.   BiggerReactors = {
  35.     turbine = "<PASTEBIN_KEY_BGR>"
  36.   },
  37.   common = {
  38.     startup = "bHCyJny5",
  39.     gui = "edBzYTzi",
  40.     main = "dqaeHStp",
  41.     config = "ZEx1hwKf",
  42.     language = "Z48wKpjG",
  43.     state = "UuMV4vQz",
  44.     settingsmodel = "HqkrbCxb",
  45.     userConfig = "crF6ViY5",
  46.   }
  47. }
  48.  
  49. -- Lädt Datei einmal herunter und gibt Inhalt zurück
  50. local function downloadToMemory(pasteKey, targetTmp)
  51.     shell.run("pastebin get " .. pasteKey .. " " .. targetTmp)
  52.     if not fs.exists(targetTmp) then
  53.         error("Fehler beim Herunterladen von " .. pasteKey)
  54.     end
  55.     local f = fs.open(targetTmp, "r")
  56.     local content = f.readAll() or ""
  57.     f.close()
  58.     return content
  59. end
  60.  
  61. -- Datei ggf. aktualisieren (aber lädt Paste nur einmal)
  62. local function updateFileIfNeeded(pasteKey, filename)
  63.     local dummy = {
  64.         write = function() end,
  65.         blit = function() end,
  66.         clear = function() end,
  67.         clearLine = function() end,
  68.         getCursorPos = function() return 1, 1 end,
  69.         setCursorPos = function() end,
  70.         getSize = function() return 1, 1 end,
  71.         getTextColour = function() end,
  72.         setTextColour = function() end,
  73.         setBackgroundColour = function() end,
  74.         scroll = function() end,
  75.         isColour = function() return true end
  76.     }
  77.  
  78.     local contentUpdate = false
  79.    
  80.     local nativ = term.redirect(dummy)
  81.  
  82.     os.sleep(0.3)
  83.    
  84.     if filename == "userConfig" and fs.exists(filename) then
  85.         term.redirect(nativ)
  86.         term.setTextColor(colors.green)
  87.         print("Datei \"" .. filename .. "\" ist vorhanden")
  88.     else
  89.         local tmpFile = ".tmp"
  90.         if fs.exists(tmpFile) then fs.delete(tmpFile) end
  91.         local newContent = downloadToMemory(pasteKey, tmpFile)
  92.         local oldContent = ""
  93.        
  94.         if fs.exists(filename) then
  95.             local f = fs.open(filename, "r")
  96.             oldContent = f.readAll() or ""
  97.             f.close()
  98.         end
  99.        
  100.         if oldContent ~= newContent then
  101.             contentUpdate = true
  102.            
  103.             if fs.exists(filename) then fs.delete(filename) end
  104.             fs.copy(tmpFile, filename)
  105.         end
  106.    
  107.         fs.delete(tmpFile)
  108.         term.redirect(nativ)
  109.        
  110.         if contentUpdate == true then
  111.             term.setTextColor(colors.yellow)
  112.             print("Datei \"" .. filename .. "\" wird aktualisiert...")
  113.            
  114.             if filename == "startup" then
  115.                 print("\nStartup Datei wurde aktualisiert.\nStarte CC Computer in 5 Sekunden neu...")
  116.                 os.sleep(5)
  117.                 os.reboot()
  118.             end
  119.         else
  120.             term.setTextColor(colors.green)
  121.             print("Datei \"" .. filename .. "\" ist aktuell")
  122.         end
  123.     end
  124.     term.setTextColor(colors.white)
  125. end
  126.  
  127. -- Hauptlogik
  128. term.clear()
  129. term.setCursorPos(1,1)
  130. term.setTextColor(colors.red)
  131. print("Prüfe auf vorhandene Reaktor- oder Turbinenversion...\n")
  132. os.sleep(0.3)
  133. term.setTextColor(colors.purple)
  134. local modType = getModType()
  135. print("Mod erkannt: " .. modType .. "\n")
  136. local links = pastebinLinks[modType]
  137. os.sleep(0.5)
  138. if not links or not links.turbine then
  139.   term.setTextColor(colors.red)
  140.   print("Fehlender Pastebin-Link für den erkannten Modtyp: " .. (modType or "Unbekannt"))
  141.   print("Bitte Startdatei erneut herunterladen")
  142.   sleep(10)
  143.   os.shutdown()
  144. end
  145.  
  146. local common = pastebinLinks.common
  147.  
  148. -- Gemeinsame Dateien prüfen und ggf. updaten
  149. updateFileIfNeeded(common.startup, "startup")
  150. updateFileIfNeeded(links.turbine, "turbine")
  151. updateFileIfNeeded(common.gui, "gui")
  152. updateFileIfNeeded(common.main, "orchestrator")
  153. updateFileIfNeeded(common.config, "config")
  154. updateFileIfNeeded(common.language, "language")
  155. updateFileIfNeeded(common.state, "state")
  156. updateFileIfNeeded(common.settingsmodel, "settingsmodel")
  157. updateFileIfNeeded(common.userConfig, "userConfig")
  158.  
  159. -- Starte Programm
  160. term.setTextColor(colors.yellow)
  161. os.sleep(0.5)
  162. print("\nSteuerung wird gestartet...")
  163. sleep(3)
  164. shell.run("orchestrator")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement