Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tick = 0.05
- function writeLog(text)
- if not fileName then
- fileName = "undefined"
- end
- f = fs.open(fileName, "a")
- f.writeLine(text)
- f.close()
- end
- debugMode = true
- function console(text, ligne)
- local lx, ly = term.getCursorPos()
- if ligne==nil then ligne=1 end
- if debugMode == true then
- term.setCursorPos(1,ligne)
- term.clearLine()
- term.write(text)
- end
- term.setCursorPos(lx, ly)
- end
- local function compare(data1,data2)
- return data1 > data2
- end
- function tableSort(tToSort)
- local copyToSort = {}
- for i = 1, #tToSort do
- copyToSort[i] = tToSort[i]
- end
- local len = #copyToSort
- for j = 2, len do
- local key = copyToSort[j]
- local i = j - 1
- while i > 0 and compare(copyToSort[i],key) do
- copyToSort[i + 1] = copyToSort[i]
- i = i - 1
- end
- copyToSort[i + 1] = key
- end
- return copyToSort
- end
- function selectionMenu(title, ... )
- tChoices = {}
- if type(arg[1]) == "table" then
- for i=1, #arg do
- tChoices[i] = arg[i]
- -- tChoices[1] = {a,b,c,d,e}
- -- tChoices[2] = {1,2,3,4,5}
- end
- else
- tChoices[1] = arg
- -- tChoices[1] = {a,b,c,d,e}
- end
- local nTermX, nTermY = term.getSize()
- local sSeperator = ("-"):rep(nTermX) -- Create a seperator string with the size of the terminal
- local tSeparatorLength = math.floor((nTermX-string.len(tostring(title)))/2)-1
- local tSeparator = (" "):rep(tSeparatorLength)
- print(tSeparator)
- -- Do the above for the remaining
- local nSelection = 1 -- The current selection defaults at 1
- while true do
- term.setCursorPos(1, 1)
- term.clear()
- print(sSeperator)
- term.write("|"..(" "):rep(tSeparatorLength))
- term.write(tostring(title))
- if tSeparatorLength%2 == 0 then
- print(tSeparator.."|")
- else
- print(tSeparator.." |")
- end
- print(sSeperator)
- for nLine = 1, #tChoices[1] do -- Iterate through the possible potions, and print them, marking the chosen one
- local sLine = " "
- if nSelection == nLine then
- sLine = ">"
- end
- local sLineNum = tostring(nLine)
- if #sLineNum < 2 then
- sLineNum = "0" .. sLineNum -- Prepend a 0 if it's too short
- end
- sLine = sLine .. "[" .. sLineNum .. "] "
- for i=1,#tChoices do
- sLine = sLine .. tostring(tChoices[i][nLine]) .. " "
- -- [0] choix1 choix2 choixN
- end
- print(sLine) -- Print it
- end
- -- os.pullEvent keys: up - 200, down - 208, enter - 28
- local sEvent, nKey = os.pullEvent("key") -- Using the 1.3 filtering; this will mean only "key" events will pass
- if nKey == 200 or nKey == 17 then -- Up/w key: move up the menu
- if tChoices[1][nSelection - 1] then -- Check if we can move up
- nSelection = nSelection - 1
- end
- -- Ignore it otherwise
- elseif nKey == 208 or nKey == 31 then -- Down/s key: move down the menu
- if tChoices[1][nSelection + 1] then -- Check if we can move down
- nSelection = nSelection + 1
- end
- elseif nKey == 28 then -- Enter key: Selecting a choice
- if tChoices[1][nSelection] then
- return nSelection, tChoices[1][nSelection] -- Run the function associated with the action.
- else
- print("Error: Selection out of bounds: ", nSelection)
- return false
- end
- end
- end
- end
- function searchTableFor(t, restrict)
- ret = {}
- for i,v in pairs(t) do
- if string.find(tostring(v), restrict) then
- table.insert(ret, v)
- else
- end
- end
- return ret
- end
- function readLogs()
- files = fs.list("")
- files = searchTableFor(files, ".log")
- _, choice = selectionMenu("Choose a log file", files)
- f = fs.open(choice, "r")
- assert(f)
- line = ""
- j = 0
- k = 0
- values = {}
- while true do
- line = f.readLine()
- if line == nil then
- break
- end
- j = j+1
- values[j] = {}
- for i,v in string.gmatch(line, "%d+") do
- table.insert(values[j], i)
- -- k = k+1
- -- values[j][(k%3)+1] = i
- end
- table.insert(values[j], line)
- end
- if string.find(pType, "tesseract") then
- local freq = {}
- local speed = {}
- for i=1,#values do
- freq[i] = values[i][1].." Hz"
- speed[i] = values[i][2].." RF/t"
- end
- _, choice = selectionMenu("Frequency selection", freq, speed)
- choice = string.reverse(string.sub(string.reverse(choice), 4))
- print(tonumber(choice))
- assert(e.setFrequency(tonumber(choice)), "Error: Couldn't change the tesseract frequency")
- else --assume enderchest/endertank
- term.clear()
- for i=1,#values do
- e.setColors(2^values[i][1], 2^values[i][2], 2^values[i][3])
- console("Apply a redstone signal to cycle through the log file")
- console(values[i][4], 3)
- while rs.getInput("front") == false do
- sleep()
- end
- end
- end
- end
- --[[
- if peripheral.getType(side) = "modem" then
- names = peripheral.getNamesRemote()
- if #names > 0 then
- for i=1,#names do
- types = peripheral.getTypeRemote(names[i])
- end
- if #names > 1 then
- choice = selectionMenu(names)
- if choice then
- pType = types[choice]
- end
- end
- end
- end
- --]]
- names = peripheral.getNames()
- if #names > 0 then
- types = {}
- if #names > 1 then
- for i=1,#names do
- types[i] = peripheral.getType(names[i])
- end
- choice = selectionMenu("First, please select a peripheral", types)
- if choice then
- pType = types[choice]
- assert(pType)
- e = peripheral.wrap(names[choice])
- assert(e)
- end
- end
- end
- _, action = selectionMenu("Action to perform", "Explore logs", "Bruteforce")
- if action == "Explore logs" then
- readLogs(e)
- else
- local i = 1
- fileName = ""
- truncatedPType = string.reverse(string.sub(string.reverse(pType), -10))
- repeat
- fileName = truncatedPType.."_"..i..".log"
- i = i+1
- until fs.exists(fileName) == false
- if pType == "ender_tank" then
- for a=0,15 do
- for b=0,15 do
- for c=0,15 do
- e.setColors(2^a,2^b,2^c)
- tank = e.getTankInfo()[1]
- if tank.contents.amount > 0 then
- writeLog(a..","..b..","..c..","..tank.contents.name)
- end
- end
- sleep(tick)
- end
- end
- elseif pType == "ender_chest" then
- for a=0,15 do
- for b=0,15 do
- for c=0,15 do
- e.setColors(2^a,2^b,2^c)
- inventory = e.getAllStacks()
- if #inventory > 0 then
- if inventory[1] ~= nil then
- writeLog(a..","..b..","..c..","..tostring(inventory[1].all().name))
- else
- writeLog(a..","..b..","..c..",unknown")
- end
- end
- end
- sleep(tick)
- end
- end
- elseif pType == "tile_thermalexpansion_ender_tesseract_name" then
- choice = selectionMenu("Please select an energy cell", types)
- term.clear()
- if choice then
- cell = peripheral.wrap(names[choice])
- if type(cell.getEnergyStored) == "function" then
- function isGettingPower(accuracy)
- if type(accuracy) ~= "number" then
- local accuracy = 5
- end
- local stored = cell.getEnergyStored()
- for i=1,accuracy do
- sleep()
- if cell.getEnergyStored() ~= stored then
- return true
- end
- end
- return false
- end
- function getPowerIncomePerTick(accuracy, debugValue)
- if tonumber(accuracy) > 0 then
- local t0 = os.clock()
- local sum = 0
- local energyAtFirst = cell.getEnergyStored()
- for i=1,accuracy do
- sleep()
- console(debugValue.."/999 = "..(cell.getEnergyStored()-energyAtFirst)/i, 19)
- end
- local gain = cell.getEnergyStored() - energyAtFirst
- local timeSpan = os.clock() - t0
- return (gain/timeSpan) / 20
- else
- return false
- end
- end
- else
- return false
- end
- end
- for i=1,999 do
- e.setFrequency(i)
- console(tostring(i).."/999 = 0", 19)
- if getPowerIncomePerTick(1, i) == 0 then
- else
- local espeed = getPowerIncomePerTick(10, i)
- writeLog(i..","..math.floor(espeed))
- end
- end
- term.setCursorPos(1,1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement