Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Hideously Smashed Together by Compilr, a Hideous Smash-Stuff-Togetherer, (c) 2014 oeed --
- -- This file REALLLLLLLY isn't suitable to be used for anything other than being executed --
- -- To extract all the files, run: "<filename> --extract" in the Shell --
- local files = {
- sha256 = "\
- -- \
- -- Adaptation of the Secure Hashing Algorithm (SHA-244/256)\
- -- Found Here: http://lua-users.org/wiki/SecureHashAlgorithm\
- -- \
- -- Using an adapted version of the bit library\
- -- Found Here: https://bitbucket.org/Boolsheet/bslf/src/1ee664885805/bit.lua\
- -- \
- \
- local MOD = 2^32\
- local MODM = MOD-1\
- \
- local function memoize(f)\
- local mt = {}\
- local t = setmetatable({}, mt)\
- function mt:__index(k)\
- local v = f(k)\
- t[k] = v\
- return v\
- end\
- return t\
- end\
- \
- local function make_bitop_uncached(t, m)\
- local function bitop(a, b)\
- local res,p = 0,1\
- while a ~= 0 and b ~= 0 do\
- local am, bm = a % m, b % m\
- res = res + t[am][bm] * p\
- a = (a - am) / m\
- b = (b - bm) / m\
- p = p*m\
- end\
- res = res + (a + b) * p\
- return res\
- end\
- return bitop\
- end\
- \
- local function make_bitop(t)\
- local op1 = make_bitop_uncached(t,2^1)\
- local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)\
- return make_bitop_uncached(op2, 2 ^ (t.n or 1))\
- end\
- \
- local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})\
- \
- local function bxor(a, b, c, ...)\
- local z = nil\
- if b then\
- a = a % MOD\
- b = b % MOD\
- z = bxor1(a, b)\
- if c then z = bxor(z, c, ...) end\
- return z\
- elseif a then return a % MOD\
- else return 0 end\
- end\
- \
- local function band(a, b, c, ...)\
- local z\
- if b then\
- a = a % MOD\
- b = b % MOD\
- z = ((a + b) - bxor1(a,b)) / 2\
- if c then z = bit32_band(z, c, ...) end\
- return z\
- elseif a then return a % MOD\
- else return MODM end\
- end\
- \
- local function bnot(x) return (-1 - x) % MOD end\
- \
- local function rshift1(a, disp)\
- if disp < 0 then return lshift(a,-disp) end\
- return math.floor(a % 2 ^ 32 / 2 ^ disp)\
- end\
- \
- local function rshift(x, disp)\
- if disp > 31 or disp < -31 then return 0 end\
- return rshift1(x % MOD, disp)\
- end\
- \
- local function lshift(a, disp)\
- if disp < 0 then return rshift(a,-disp) end \
- return (a * 2 ^ disp) % 2 ^ 32\
- end\
- \
- local function rrotate(x, disp)\
- x = x % MOD\
- disp = disp % 32\
- local low = band(x, 2 ^ disp - 1)\
- return rshift(x, disp) + lshift(low, 32 - disp)\
- end\
- \
- local k = {\
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\
- }\
- \
- local function str2hexa(s)\
- return (string.gsub(s, \".\", function(c) return string.format(\"%02x\", string.byte(c)) end))\
- end\
- \
- local function num2s(l, n)\
- local s = \"\"\
- for i = 1, n do\
- local rem = l % 256\
- s = string.char(rem) .. s\
- l = (l - rem) / 256\
- end\
- return s\
- end\
- \
- local function s232num(s, i)\
- local n = 0\
- for i = i, i + 3 do n = n*256 + string.byte(s, i) end\
- return n\
- end\
- \
- local function preproc(msg, len)\
- local extra = 64 - ((len + 9) % 64)\
- len = num2s(8 * len, 8)\
- msg = msg .. \"\\128\" .. string.rep(\"\\0\", extra) .. len\
- assert(#msg % 64 == 0)\
- return msg\
- end\
- \
- local function initH256(H)\
- H[1] = 0x6a09e667\
- H[2] = 0xbb67ae85\
- H[3] = 0x3c6ef372\
- H[4] = 0xa54ff53a\
- H[5] = 0x510e527f\
- H[6] = 0x9b05688c\
- H[7] = 0x1f83d9ab\
- H[8] = 0x5be0cd19\
- return H\
- end\
- \
- local function digestblock(msg, i, H)\
- local w = {}\
- for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end\
- for j = 17, 64 do\
- local v = w[j - 15]\
- local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))\
- v = w[j - 2]\
- w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))\
- end\
- \
- local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]\
- for i = 1, 64 do\
- local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))\
- local maj = bxor(band(a, b), band(a, c), band(b, c))\
- local t2 = s0 + maj\
- local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))\
- local ch = bxor (band(e, f), band(bnot(e), g))\
- local t1 = h + s1 + ch + k[i] + w[i]\
- h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2\
- end\
- \
- H[1] = band(H[1] + a)\
- H[2] = band(H[2] + b)\
- H[3] = band(H[3] + c)\
- H[4] = band(H[4] + d)\
- H[5] = band(H[5] + e)\
- H[6] = band(H[6] + f)\
- H[7] = band(H[7] + g)\
- H[8] = band(H[8] + h)\
- end\
- \
- function sha256(msg)\
- msg = preproc(msg, #msg)\
- local H = initH256({})\
- for i = 1, #msg, 64 do digestblock(msg, i, H) end\
- return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..\
- num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))\
- end",
- cst = "function getBalance(usr)\
- local stream = http.get(\"http://crystalcoins.site88.net/user.php?action=getBalance&user=\"..usr)\
- local bal = tonumber(stream.readLine())\
- stream.close()\
- return bal\
- end\
- function transact(usr,pw,to,amt)\
- local stream = http.get(\"http://crystalcoins.site88.net/user.php?action=transaction&user=\"..usr..\"&pass=\"..pw..\"&to=\"..to..\"&amt=\"..amt)\
- local suc = stream.readLine()\
- stream.close()\
- return suc\
- end",
- krist = "local KristAPI = {}\
- local nodeURL = \"https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/syncNode\"\
- \
- local function getNode()\
- local node = http.get(nodeURL).readAll()\
- if node then\
- if node:match(\"http\") then\
- return node\
- end\
- error(\"Error: Invalid response from node\", 2)\
- end\
- error(\"Error: Node Offline\", 2)\
- end\
- \
- -- SHA256 By GravityScore\
- \
- local MOD = 2^32\
- local MODM = MOD-1\
- \
- local function memoize(f)\
- local mt = {}\
- local t = setmetatable({}, mt)\
- function mt:__index(k)\
- local v = f(k)\
- t[k] = v\
- return v\
- end\
- return t\
- end\
- \
- local function make_bitop_uncached(t, m)\
- local function bitop(a, b)\
- local res,p = 0,1\
- while a ~= 0 and b ~= 0 do\
- local am, bm = a % m, b % m\
- res = res + t[am][bm] * p\
- a = (a - am) / m\
- b = (b - bm) / m\
- p = p*m\
- end\
- res = res + (a + b) * p\
- return res\
- end\
- return bitop\
- end\
- \
- local function make_bitop(t)\
- local op1 = make_bitop_uncached(t,2^1)\
- local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)\
- return make_bitop_uncached(op2, 2 ^ (t.n or 1))\
- end\
- \
- local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})\
- \
- local function bxor(a, b, c, ...)\
- local z = nil\
- if b then\
- a = a % MOD\
- b = b % MOD\
- z = bxor1(a, b)\
- if c then z = bxor(z, c, ...) end\
- return z\
- elseif a then return a % MOD\
- else return 0 end\
- end\
- \
- local function band(a, b, c, ...)\
- local z\
- if b then\
- a = a % MOD\
- b = b % MOD\
- z = ((a + b) - bxor1(a,b)) / 2\
- if c then z = bit32_band(z, c, ...) end\
- return z\
- elseif a then return a % MOD\
- else return MODM end\
- end\
- \
- local function bnot(x) return (-1 - x) % MOD end\
- \
- local function rshift1(a, disp)\
- if disp < 0 then return lshift(a,-disp) end\
- return math.floor(a % 2 ^ 32 / 2 ^ disp)\
- end\
- \
- local function rshift(x, disp)\
- if disp > 31 or disp < -31 then return 0 end\
- return rshift1(x % MOD, disp)\
- end\
- \
- local function lshift(a, disp)\
- if disp < 0 then return rshift(a,-disp) end \
- return (a * 2 ^ disp) % 2 ^ 32\
- end\
- \
- local function rrotate(x, disp)\
- x = x % MOD\
- disp = disp % 32\
- local low = band(x, 2 ^ disp - 1)\
- return rshift(x, disp) + lshift(low, 32 - disp)\
- end\
- \
- local k = {\
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\
- }\
- \
- local function str2hexa(s)\
- return (string.gsub(s, \".\", function(c) return string.format(\"%02x\", string.byte(c)) end))\
- end\
- \
- local function num2s(l, n)\
- local s = \"\"\
- for i = 1, n do\
- local rem = l % 256\
- s = string.char(rem) .. s\
- l = (l - rem) / 256\
- end\
- return s\
- end\
- \
- local function s232num(s, i)\
- local n = 0\
- for i = i, i + 3 do n = n*256 + string.byte(s, i) end\
- return n\
- end\
- \
- local function preproc(msg, len)\
- local extra = 64 - ((len + 9) % 64)\
- len = num2s(8 * len, 8)\
- msg = msg .. \"\\128\" .. string.rep(\"\\0\", extra) .. len\
- assert(#msg % 64 == 0)\
- return msg\
- end\
- \
- local function initH256(H)\
- H[1] = 0x6a09e667\
- H[2] = 0xbb67ae85\
- H[3] = 0x3c6ef372\
- H[4] = 0xa54ff53a\
- H[5] = 0x510e527f\
- H[6] = 0x9b05688c\
- H[7] = 0x1f83d9ab\
- H[8] = 0x5be0cd19\
- return H\
- end\
- \
- local function digestblock(msg, i, H)\
- local w = {}\
- for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end\
- for j = 17, 64 do\
- local v = w[j - 15]\
- local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))\
- v = w[j - 2]\
- w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))\
- end\
- \
- local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]\
- for i = 1, 64 do\
- local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))\
- local maj = bxor(band(a, b), band(a, c), band(b, c))\
- local t2 = s0 + maj\
- local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))\
- local ch = bxor (band(e, f), band(bnot(e), g))\
- local t1 = h + s1 + ch + k[i] + w[i]\
- h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2\
- end\
- \
- H[1] = band(H[1] + a)\
- H[2] = band(H[2] + b)\
- H[3] = band(H[3] + c)\
- H[4] = band(H[4] + d)\
- H[5] = band(H[5] + e)\
- H[6] = band(H[6] + f)\
- H[7] = band(H[7] + g)\
- H[8] = band(H[8] + h)\
- end\
- \
- local function sha256(msg)\
- msg = preproc(msg, #msg)\
- local H = initH256({})\
- for i = 1, #msg, 64 do digestblock(msg, i, H) end\
- return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..\
- num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))\
- end\
- \
- --\
- \
- function hextobase36(j)\
- for i = 6, 251, 7 do\
- if j <= i then\
- if i <= 69 then\
- return string.char(48+(i-6)/7)\
- end\
- return string.char(97+(i-76)/7)\
- end\
- end\
- return \"e\"\
- end\
- \
- function makev2address(key)\
- local protein = {}\
- local stick = sha256(sha256(key))\
- local n = 0\
- local link = 0\
- local v2 = \"k\"\
- repeat\
- if n < 9 then protein[n] = string.sub(stick,0,2)\
- stick = sha256(sha256(stick)) end\
- n = n + 1\
- until n == 9\
- n = 0\
- repeat\
- link = tonumber(string.sub(stick,1+(2*n),2+(2*n)),16) % 9\
- if string.len(protein[link]) ~= 0 then\
- v2 = v2 .. hextobase36(tonumber(protein[link],16))\
- protein[link] = ''\
- n = n + 1\
- else\
- stick = sha256(stick)\
- end\
- until n == 9\
- return v2\
- end\
- \
- local function parse(url, options)\
- local res = http.get(url..options)\
- if not res then error(\"Error: Node Offline\", 2) end\
- return res.readAll()\
- end\
- \
- function new(password)\
- local Krist = {}\
- Krist.node = getNode()\
- Krist.key = sha256(\"KRISTWALLET\"..password)..\"-000\"\
- Krist.address = makev2address(Krist.key)\
- return setmetatable(Krist, {[\"__index\"] = KristAPI})\
- end\
- \
- function KristAPI:getBalance(address)\
- address = address or self.address\
- return parse(self.node, \"?getbalance=\"..\"kfcal0gxme\")\
- end\
- \
- function KristAPI:getTransaction(address)\
- address = address or self.address\
- local ret = {}\
- local res = parse(self.node, \"?listtx=\"..address)\
- res = res:sub(0, #res-3):gsub(\"\\n\", \"\"):gsub(\"\\r\", \"\")\
- if #res == 0 then return {}\
- elseif #res % 31 == 0 then\
- for i = 0, (#res/31)-1, 1 do\
- local temp = res:sub(i*31+1, (i+1)*31)\
- table.insert(ret, {date = temp:sub(1, 12), recipient = temp:sub(13, 22), amount = tonumber(temp:sub(23))})\
- end\
- return ret\
- end\
- end\
- \
- function KristAPI:getRichList()\
- error(\"TODO, probably won't do\")\
- end\
- \
- function KristAPI:sendKrist(amount, recipient)\
- --if self.address == recipient then error(\"Error: Cannot send to yourself\") end\
- local res = parse(self.node, \"?pushtx2&q=\"..\"recipient\"..\"&pkey=\"..self.key..\"&amt=\"..\"amount\")\
- if res == \"Success\" then return \"Success\"\
- elseif res == \"Error1\" then return \"InsufficientFunds\"\
- elseif res == \"Error2\" then return \"NotEnoughKST\"\
- elseif res == \"Error3\" then return \"BadValue\"\
- elseif res == \"Error4\" then return \"InvalidRecipient\"\
- else return \"Unknown\"\
- end\
- end",
- [ ".shop" ] = "{\
- {name=\"Knight's tour\", code=\"G5FqHanB\", price=5},\
- {name=\"MMTP (mailing)\", code=\"gLuggWkq\", price=10},\
- }",
- [ ".tmp" ] = "{}",
- [ ".cmds" ] = {
- help = "shell.run(\"dir /.cmds\")",
- clr = "term.clear()\
- term.setCursorPos(1,1)",
- pay = "file = fs.open(\".tmp\", \"r\")\
- tBasket = textutils.unserialize(file.readAll())\
- file.close()\
- fs.delete(\".tmp\")\
- \
- file = fs.open(\".tmp\", \"w\")\
- file.write(\"{}\")\
- file.close()\
- \
- shop = fs.open(\".shop\", \"r\")\
- tShop = textutils.unserialize(shop.readAll())\
- shop.close()\
- \
- tItems = {}\
- \
- --for k, v in pairs(tShop) do\
- --print(k)\
- --print(v.name)\
- --print(v.price)\
- --end\
- \
- for k, v in pairs(tShop) do\
- for k1, v1 in pairs(tBasket) do\
- --print(\"T:\"..v1)\
- if v1 == k then\
- tItems[#tItems+1] = {v.name, v.price}\
- end\
- end\
- end\
- --print(#tItems)\
- print(\"Basket:\")\
- total = 0\
- for k, v in pairs(tItems) do\
- print(\"Product: \"..v[1]..\", Price: \"..v[2])\
- --print()\
- total = total + v[2]\
- end\
- val = total\
- print(\"Total: \"..val)\
- \
- print(\"Pay in KST or CST? (k/c)\")\
- \
- while true do\
- ev, k = os.pullEvent(\"char\")\
- if k == \"k\" or k == \"c\" then\
- break\
- end\
- end\
- \
- if k == \"k\" then\
- shell.run(\".pay_krist\")\
- else\
- shell.run(\".pay_crystal\")\
- end\
- ",
- add = "file = fs.open(\".tmp\", \"r\")\
- tBasket = textutils.unserialize(file.readAll())\
- file.close()\
- \
- inp = read()\
- inp = tonumber(inp)\
- if type(inp) ~= \"number\" then\
- print(\"ID MUST BE NUMBER\")\
- return\
- end\
- table.insert(tBasket, inp)\
- \
- file = fs.open(\".tmp\", \"w\")\
- file.write(textutils.serialize(tBasket))\
- file.close()\
- \
- print(\"Current basket:\")\
- \
- tItems = {}\
- \
- shop = fs.open(\".shop\", \"r\")\
- tShop = textutils.unserialize(shop.readAll())\
- shop.close()\
- \
- for k, v in pairs(tShop) do\
- for k1, v1 in pairs(tBasket) do\
- --print(\"T:\"..v1)\
- if v1 == k then\
- tItems[#tItems+1] = {v.name, v.price}\
- print(\"ID: \"..k..\", Name: \"..v.name..\", Price: \"..v.price)\
- end\
- end\
- end",
- ls = "print(\"Available products: \")\
- \
- shop = fs.open(\".shop\", \"r\")\
- tShop = textutils.unserialize(shop.readAll())\
- shop.close()\
- \
- for k, v in pairs(tShop) do\
- print(\"ID: \"..tostring(k)..\", Name: \"..v.name..\", Price: \"..v.price)\
- end",
- },
- startup = "",
- [ ".pay_crystal" ] = "os.loadAPI(\"sha256\")\
- os.loadAPI(\"cst\")\
- bought = false\
- print(\"PAYING IN: CRYSTAL\")\
- print(\"Enter username:\")\
- us = read()\
- print(\"Enter password:\")\
- pw = read(\"*\")\
- balance = tonumber(cst.getBalance(us))\
- print(\"Account:\"..us..\", Balance: \"..balance)\
- if balance >= val then\
- print(\"Price $\"..val..\" CST. Confirm? (y/n)\")\
- k = nil\
- while true do\
- ev, k = os.pullEvent(\"char\")\
- if k == \"y\" then\
- res = cst.transact(us, sha256.sha256(pw), \"rodsn\", val)\
- print(\"Transaction response code: \"..res)\
- return\
- elseif k == \"n\" then\
- print(\"Operation canceled\")\
- return\
- end\
- end\
- else\
- print(\"Not enough money.\")\
- end",
- cmd = "url = \"http://pastebin.com/raw.php?i=2wNetKf4\"\
- \
- r = http.get(url)\
- c = r.readAll()\
- r.close()\
- \
- fs.delete(\".shop\")\
- \
- file = fs.open(\".shop\", \"w\")\
- file.write(c)\
- file.close()\
- \
- path = \".cmds/\"\
- fs.delete(\".tmp\")\
- file = fs.open(\".tmp\", \"w\")\
- file.write(\"{}\")\
- file.close()\
- \
- while true do\
- term.write(\"> \")\
- inp = read()\
- if fs.exists(path..inp) then\
- shell.run(path..inp)\
- end\
- end",
- [ ".pay_krist" ] = "os.loadAPI(\"krist\")\
- bought = false\
- print(\"PAYING IN: KRIST\")\
- print(\"Enter password:\")\
- acc = krist.new(read(\"*\"))\
- print(\"Logged in\")\
- name = acc.address\
- balance = tonumber(acc:getBalance())\
- print(\"Account:\"..name..\", Balance: \"..balance)\
- if balance >= val then\
- print(\"Price $\"..val..\" KST. Confirm? (y/n)\")\
- k = nil\
- while true do\
- ev, k = os.pullEvent(\"char\")\
- if k == \"y\" then\
- res = acc:sendKrist(val, \"kfcal0gxme\")\
- print(\"Transaction response code: \"..res)\
- return\
- elseif k == \"n\" then\
- print(\"Operation canceled\")\
- return\
- end\
- end\
- else\
- print(\"Not enough money.\")\
- end",
- }
- local function run(tArgs)
- local fnFile, err = loadstring(files['startup'], 'startup')
- if err then
- error(err)
- end
- local function split(str, pat)
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- local function resolveTreeForPath(path, single)
- local _files = files
- local parts = split(path, '/')
- if parts then
- for i, v in ipairs(parts) do
- if #v > 0 then
- if _files[v] then
- _files = _files[v]
- else
- _files = nil
- break
- end
- end
- end
- elseif #path > 0 and path ~= '/' then
- _files = _files[path]
- end
- if not single or type(_files) == 'string' then
- return _files
- end
- end
- local oldFs = fs
- local env
- env = {
- fs = {
- list = function(path)
- local list = {}
- if fs.exists(path) then
- list = fs.list(path)
- end
- for k, v in pairs(resolveTreeForPath(path)) do
- if not fs.exists(path .. '/' ..k) then
- table.insert(list, k)
- end
- end
- return list
- end,
- exists = function(path)
- if fs.exists(path) then
- return true
- elseif resolveTreeForPath(path) then
- return true
- else
- return false
- end
- end,
- isDir = function(path)
- if fs.isDir(path) then
- return true
- else
- local tree = resolveTreeForPath(path)
- if tree and type(tree) == 'table' then
- return true
- else
- return false
- end
- end
- end,
- isReadOnly = function(path)
- if not fs.isReadOnly(path) then
- return false
- else
- return true
- end
- end,
- getName = fs.getName,
- getSize = fs.getSize,
- getFreespace = fs.getFreespace,
- makeDir = fs.makeDir,
- move = fs.move,
- copy = fs.copy,
- delete = fs.delete,
- combine = fs.combine,
- open = function(path, mode)
- if fs.exists(path) then
- return fs.open(path, mode)
- elseif type(resolveTreeForPath(path)) == 'string' then
- local handle = {close = function()end}
- if mode == 'r' then
- local content = resolveTreeForPath(path)
- handle.readAll = function()
- return content
- end
- local line = 1
- local lines = split(content, '\n')
- handle.readLine = function()
- if line > #lines then
- return nil
- else
- return lines[line]
- end
- line = line + 1
- end
- return handle
- else
- error('Cannot write to read-only file (compilr archived).')
- end
- else
- return fs.open(path, mode)
- end
- end
- },
- io = {
- input = io.input,
- output = io.output,
- type = io.type,
- close = io.close,
- write = io.write,
- flush = io.flush,
- lines = io.lines,
- read = io.read,
- open = function(path, mode)
- if fs.exists(path) then
- return io.open(path, mode)
- elseif type(resolveTreeForPath(path)) == 'string' then
- local content = resolveTreeForPath(path)
- local f = fs.open(path, 'w')
- f.write(content)
- f.close()
- if mode == 'r' then
- return io.open(path, mode)
- else
- error('Cannot write to read-only file (compilr archived).')
- end
- else
- return io.open(path, mode)
- end
- end
- },
- loadfile = function( _sFile )
- local file = env.fs.open( _sFile, "r" )
- if file then
- local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
- file.close()
- return func, err
- end
- return nil, "File not found: ".._sFile
- end,
- dofile = function( _sFile )
- local fnFile, e = env.loadfile( _sFile )
- if fnFile then
- setfenv( fnFile, getfenv(2) )
- return fnFile()
- else
- error( e, 2 )
- end
- end
- }
- setmetatable( env, { __index = _G } )
- local tAPIsLoading = {}
- env.os.loadAPI = function( _sPath )
- local sName = fs.getName( _sPath )
- if tAPIsLoading[sName] == true then
- printError( "API "..sName.." is already being loaded" )
- return false
- end
- tAPIsLoading[sName] = true
- local tEnv = {}
- setmetatable( tEnv, { __index = env } )
- local fnAPI, err = env.loadfile( _sPath )
- if fnAPI then
- setfenv( fnAPI, tEnv )
- fnAPI()
- else
- printError( err )
- tAPIsLoading[sName] = nil
- return false
- end
- local tAPI = {}
- for k,v in pairs( tEnv ) do
- tAPI[k] = v
- end
- env[sName] = tAPI
- tAPIsLoading[sName] = nil
- return true
- end
- env.shell = shell
- setfenv( fnFile, env )
- fnFile(unpack(tArgs))
- end
- local function extract()
- local function node(path, tree)
- if type(tree) == 'table' then
- fs.makeDir(path)
- for k, v in pairs(tree) do
- node(path .. '/' .. k, v)
- end
- else
- local f = fs.open(path, 'w')
- if f then
- f.write(tree)
- f.close()
- end
- end
- end
- node('', files)
- end
- local tArgs = {...}
- if #tArgs == 1 and tArgs[1] == '--extract' then
- extract()
- else
- run(tArgs)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement