Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Enhanced Portals 3
- -- Address Hacker
- --
- -- Author: Sharidan
- -- www.sharidan.dk
- --
- local app = {
- name = "ephack",
- version = "1.0-c"
- }
- local fileConfig = "/etc/ephack.cfg"
- local fileResults = "/etc/addresses.eph"
- local components = require("component")
- local term = require("term")
- local event = require("event")
- local ser = require("serialization")
- local fs = require("filesystem")
- local running = true
- local function getComponent(compType)
- for addr, ct in components.list(compType, false) do
- return components.proxy(addr)
- end
- return nil
- end
- local controller = getComponent("ep_controller")
- local dialer = getComponent("dialling_device")
- local config = {
- symbols = 0,
- glyphs = { -1, -1, -1, -1, -1, -1, -1, -1, -1 },
- }
- local function showUsage()
- print("Usage: ephack [-c/-r] symbols")
- print(" symbols = how many symbols to start with.")
- print(" valid: 1-9")
- print(" -c = continue. symbols can be skipped.")
- print(" -r = reset with new symbols.")
- end
- local function checkArgs(args)
- local opts, syms = table.unpack(args)
- if (opts) then
- local opt = tonumber(opts)
- if (opt) then
- if (opt >= 1 and opt <= 9) then
- return 1, opt
- end
- else
- local o = string.lower(opts)
- local s = tonumber(syms) or -1
- if (o == "-c") then
- return 3, 0
- elseif (o == "-r") then
- if (s >= 1 and s <= 9) then
- return 2, s
- end
- end
- end
- end
- return nil, nil
- end
- local function killFile(fn)
- if (fs.exists(fn)) then
- fs.remove(fn)
- end
- end
- local function loadConfig()
- local success
- if (fs.exists(fileConfig)) then
- local f = io.open(fileConfig, "r")
- if (f) then
- local data = f:read()
- f:close()
- if (data) then
- config = ser.unserialize(data)
- success = true
- end
- end
- f = nil
- end
- return success
- end
- local function saveConfig()
- killFile(fileConfig)
- if (not fs.exists(fileConfig)) then
- local f = io.open(fileConfig, "w")
- if (f) then
- f:write(ser.serialize(config))
- f:close()
- end
- f = nil
- end
- end
- local function appendResult(address)
- local f
- if (not fs.exists(fileResults)) then
- f = io.open(fileResults, "w")
- else
- f = io.open(fileResults, "a")
- end
- if (f) then
- f:write(address.."\n")
- f:close()
- end
- f = nil
- end
- local function setupGlyphs(syms)
- config.symbols = tonumber(syms)
- for g = 1, 9 do
- if (g <= syms) then
- config.glyphs[g] = 0
- else
- config.glyphs[g] = -1
- end
- end
- end
- local function getCurrentPortalAddress()
- local address = string.gsub(table.concat(config.glyphs, " "), "-1", "")
- address = string.gsub(address, " ", "-")
- return address
- end
- local function nextGlyph()
- for g = 1, 9 do
- config.glyphs[g] = config.glyphs[g] + 1
- if (config.glyphs[g] == 27) then
- config.glyphs[g] = 0
- else
- break
- end
- end
- end
- local function tryDial()
- local address = getCurrentPortalAddress()
- if (controller and dialer) then
- dialer.dial(address)
- if (controller.isPortalActive()) then
- local cx, cy = term.getCursor()
- term.setCursor(1, cy)
- term.write(string.rep(" ", 40))
- term.setCursor(1, cy)
- print("Address found: "..address)
- appendResult(address)
- dialer.terminate()
- end
- end
- nextGlyph()
- end
- local function showAddy()
- local address = getCurrentPortalAddress()
- local cx, cy = term.getCursor()
- term.setCursor(1, cy)
- term.write(string.rep(" ", 40))
- term.setCursor(1, cy)
- term.write(address)
- end
- local function runHack(mode, syms)
- if (mode == 1 or mode == 2) then -- New / Reset
- killFile(fileResults)
- setupGlyphs(syms)
- elseif (mode == 3) then -- Continue
- loadConfig()
- end
- print("ephack is running!")
- print("Press \"Q\" to quit.")
- local dtid = event.timer(0.1, tryDial, math.huge)
- local stid = event.timer(1, showAddy, math.huge)
- while running do
- local e, p1, p2, p3, p4, p5 = event.pull()
- if (e == "key_down" and p3 == 16) then
- running = nil
- end
- end
- event.cancel(stid)
- event.cancel(dtid)
- saveConfig()
- print("")
- print("Any found addresses were saved in:")
- print(fileResults)
- end
- if (controller and dialer) then
- local opt, syms = checkArgs({...})
- if (opt) then
- runHack(opt, syms)
- else
- showUsage()
- end
- else
- print(app.name.." "..app.version)
- if (not controller) then
- print("No portal controller found!")
- elseif (not dialer) then
- print("No dialing device found!")
- end
- end
- dialer = nil
- controller = nil
- components = nil
- event = nil
- term = nil
- ser = nil
- fs = nil
Add Comment
Please, Sign In to add comment