SuicidalSTDz

EnderOS v2.4

Feb 3rd, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 68.09 KB | None | 0 0
  1. --License:
  2. --The code of "EnderOS" in any form is intellectual
  3. --property of SuicidalSTDz. You may not reproduce,
  4. --redistribute, or modify it in any way!
  5.  
  6. --This OS stores User information in a hashed form. Making "hackers" tremble in fear >:) Not really...
  7. --The hash that EnderOS uses is Sha-256 and makes storage safer :)
  8. --If you find any bugs(I know there are a few) please report them on the CC Forums on the EnderOS thread!
  9. --Thank you for using EnderOS and enjoy!
  10.  
  11. --Games
  12. --EnderOS includes SkullPong by Skullblade and AdventureCraft by Mikee251 and soon FireWolf by GravityScore
  13.  
  14. os.pullEvent = os.pullEventRaw
  15. if fs.exists("/.Installer/.installer") then
  16. local open = io.open("/.Installer/.installer", "r")
  17. file = open:read()
  18. open:close()
  19. if shell.run("delete",file) == true then
  20. shell.run("delete",file)
  21. else
  22. print("Expected file not found! Ignoring...")
  23. sleep(1.5)
  24. end
  25. end
  26. term.clear()
  27. term.setCursorPos(1,1)
  28. function sha256(msg)
  29. function band(int1, int2, int3, ...)
  30. local ret =
  31. ((int1%0x00000002>=0x00000001 and int2%0x00000002>=0x00000001 and 0x00000001) or 0)+
  32. ((int1%0x00000004>=0x00000002 and int2%0x00000004>=0x00000002 and 0x00000002) or 0)+
  33. ((int1%0x00000008>=0x00000004 and int2%0x00000008>=0x00000004 and 0x00000004) or 0)+
  34. ((int1%0x00000010>=0x00000008 and int2%0x00000010>=0x00000008 and 0x00000008) or 0)+
  35. ((int1%0x00000020>=0x00000010 and int2%0x00000020>=0x00000010 and 0x00000010) or 0)+
  36. ((int1%0x00000040>=0x00000020 and int2%0x00000040>=0x00000020 and 0x00000020) or 0)+
  37. ((int1%0x00000080>=0x00000040 and int2%0x00000080>=0x00000040 and 0x00000040) or 0)+
  38. ((int1%0x00000100>=0x00000080 and int2%0x00000100>=0x00000080 and 0x00000080) or 0)+
  39. ((int1%0x00000200>=0x00000100 and int2%0x00000200>=0x00000100 and 0x00000100) or 0)+
  40. ((int1%0x00000400>=0x00000200 and int2%0x00000400>=0x00000200 and 0x00000200) or 0)+
  41. ((int1%0x00000800>=0x00000400 and int2%0x00000800>=0x00000400 and 0x00000400) or 0)+
  42. ((int1%0x00001000>=0x00000800 and int2%0x00001000>=0x00000800 and 0x00000800) or 0)+
  43. ((int1%0x00002000>=0x00001000 and int2%0x00002000>=0x00001000 and 0x00001000) or 0)+
  44. ((int1%0x00004000>=0x00002000 and int2%0x00004000>=0x00002000 and 0x00002000) or 0)+
  45. ((int1%0x00008000>=0x00004000 and int2%0x00008000>=0x00004000 and 0x00004000) or 0)+
  46. ((int1%0x00010000>=0x00008000 and int2%0x00010000>=0x00008000 and 0x00008000) or 0)+
  47. ((int1%0x00020000>=0x00010000 and int2%0x00020000>=0x00010000 and 0x00010000) or 0)+
  48. ((int1%0x00040000>=0x00020000 and int2%0x00040000>=0x00020000 and 0x00020000) or 0)+
  49. ((int1%0x00080000>=0x00040000 and int2%0x00080000>=0x00040000 and 0x00040000) or 0)+
  50. ((int1%0x00100000>=0x00080000 and int2%0x00100000>=0x00080000 and 0x00080000) or 0)+
  51. ((int1%0x00200000>=0x00100000 and int2%0x00200000>=0x00100000 and 0x00100000) or 0)+
  52. ((int1%0x00400000>=0x00200000 and int2%0x00400000>=0x00200000 and 0x00200000) or 0)+
  53. ((int1%0x00800000>=0x00400000 and int2%0x00800000>=0x00400000 and 0x00400000) or 0)+
  54. ((int1%0x01000000>=0x00800000 and int2%0x01000000>=0x00800000 and 0x00800000) or 0)+
  55. ((int1%0x02000000>=0x01000000 and int2%0x02000000>=0x01000000 and 0x01000000) or 0)+
  56. ((int1%0x04000000>=0x02000000 and int2%0x04000000>=0x02000000 and 0x02000000) or 0)+
  57. ((int1%0x08000000>=0x04000000 and int2%0x08000000>=0x04000000 and 0x04000000) or 0)+
  58. ((int1%0x10000000>=0x08000000 and int2%0x10000000>=0x08000000 and 0x08000000) or 0)+
  59. ((int1%0x20000000>=0x10000000 and int2%0x20000000>=0x10000000 and 0x10000000) or 0)+
  60. ((int1%0x40000000>=0x20000000 and int2%0x40000000>=0x20000000 and 0x20000000) or 0)+
  61. ((int1%0x80000000>=0x40000000 and int2%0x80000000>=0x40000000 and 0x40000000) or 0)+
  62. ((int1>=0x80000000 and int2>=0x80000000 and 0x80000000) or 0)
  63.  
  64. return (int3 and band(ret, int3, ...)) or ret
  65. end
  66.  
  67. local function bxor(int1, int2, int3, ...)
  68. local ret =
  69. ((int1%0x00000002>=0x00000001 ~= (int2%0x00000002>=0x00000001) and 0x00000001) or 0)+
  70. ((int1%0x00000004>=0x00000002 ~= (int2%0x00000004>=0x00000002) and 0x00000002) or 0)+
  71. ((int1%0x00000008>=0x00000004 ~= (int2%0x00000008>=0x00000004) and 0x00000004) or 0)+
  72. ((int1%0x00000010>=0x00000008 ~= (int2%0x00000010>=0x00000008) and 0x00000008) or 0)+
  73. ((int1%0x00000020>=0x00000010 ~= (int2%0x00000020>=0x00000010) and 0x00000010) or 0)+
  74. ((int1%0x00000040>=0x00000020 ~= (int2%0x00000040>=0x00000020) and 0x00000020) or 0)+
  75. ((int1%0x00000080>=0x00000040 ~= (int2%0x00000080>=0x00000040) and 0x00000040) or 0)+
  76. ((int1%0x00000100>=0x00000080 ~= (int2%0x00000100>=0x00000080) and 0x00000080) or 0)+
  77. ((int1%0x00000200>=0x00000100 ~= (int2%0x00000200>=0x00000100) and 0x00000100) or 0)+
  78. ((int1%0x00000400>=0x00000200 ~= (int2%0x00000400>=0x00000200) and 0x00000200) or 0)+
  79. ((int1%0x00000800>=0x00000400 ~= (int2%0x00000800>=0x00000400) and 0x00000400) or 0)+
  80. ((int1%0x00001000>=0x00000800 ~= (int2%0x00001000>=0x00000800) and 0x00000800) or 0)+
  81. ((int1%0x00002000>=0x00001000 ~= (int2%0x00002000>=0x00001000) and 0x00001000) or 0)+
  82. ((int1%0x00004000>=0x00002000 ~= (int2%0x00004000>=0x00002000) and 0x00002000) or 0)+
  83. ((int1%0x00008000>=0x00004000 ~= (int2%0x00008000>=0x00004000) and 0x00004000) or 0)+
  84. ((int1%0x00010000>=0x00008000 ~= (int2%0x00010000>=0x00008000) and 0x00008000) or 0)+
  85. ((int1%0x00020000>=0x00010000 ~= (int2%0x00020000>=0x00010000) and 0x00010000) or 0)+
  86. ((int1%0x00040000>=0x00020000 ~= (int2%0x00040000>=0x00020000) and 0x00020000) or 0)+
  87. ((int1%0x00080000>=0x00040000 ~= (int2%0x00080000>=0x00040000) and 0x00040000) or 0)+
  88. ((int1%0x00100000>=0x00080000 ~= (int2%0x00100000>=0x00080000) and 0x00080000) or 0)+
  89. ((int1%0x00200000>=0x00100000 ~= (int2%0x00200000>=0x00100000) and 0x00100000) or 0)+
  90. ((int1%0x00400000>=0x00200000 ~= (int2%0x00400000>=0x00200000) and 0x00200000) or 0)+
  91. ((int1%0x00800000>=0x00400000 ~= (int2%0x00800000>=0x00400000) and 0x00400000) or 0)+
  92. ((int1%0x01000000>=0x00800000 ~= (int2%0x01000000>=0x00800000) and 0x00800000) or 0)+
  93. ((int1%0x02000000>=0x01000000 ~= (int2%0x02000000>=0x01000000) and 0x01000000) or 0)+
  94. ((int1%0x04000000>=0x02000000 ~= (int2%0x04000000>=0x02000000) and 0x02000000) or 0)+
  95. ((int1%0x08000000>=0x04000000 ~= (int2%0x08000000>=0x04000000) and 0x04000000) or 0)+
  96. ((int1%0x10000000>=0x08000000 ~= (int2%0x10000000>=0x08000000) and 0x08000000) or 0)+
  97. ((int1%0x20000000>=0x10000000 ~= (int2%0x20000000>=0x10000000) and 0x10000000) or 0)+
  98. ((int1%0x40000000>=0x20000000 ~= (int2%0x40000000>=0x20000000) and 0x20000000) or 0)+
  99. ((int1%0x80000000>=0x40000000 ~= (int2%0x80000000>=0x40000000) and 0x40000000) or 0)+
  100. ((int1>=0x80000000 ~= (int2>=0x80000000) and 0x80000000) or 0)
  101.  
  102. return (int3 and bxor(ret, int3, ...)) or ret
  103. end
  104.  
  105. local function bnot(int)
  106. return 4294967295 - int
  107. end
  108.  
  109. local function rshift(int, by)
  110. local shifted = int / (2 ^ by)
  111. return shifted - shifted % 1
  112. end
  113.  
  114. local function rrotate(int, by)
  115. local shifted = int / (2 ^ by)
  116. local fraction = shifted % 1
  117. return (shifted - fraction) + fraction * (2 ^ 32)
  118. end
  119.  
  120. local k = {
  121. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  122. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  123. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  124. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  125. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  126. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  127. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  128. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  129. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  130. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  131. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  132. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  133. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  134. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  135. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  136. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
  137. }
  138.  
  139. local function str2hexa(s)
  140. local h = string.gsub(s, ".", function(c)
  141. return string.format("%02x", string.byte(c))
  142. end)
  143. return h
  144. end
  145.  
  146. local function num2s(l, n)
  147. local s = ""
  148. for i = 1, n do
  149. local rem = l % 256
  150. s = string.char(rem) .. s
  151. l = (l - rem) / 256
  152. end
  153. return s
  154. end
  155.  
  156. local function s232num(s, i)
  157. local n = 0
  158. for i = i, i + 3 do n = n*256 + string.byte(s, i) end
  159. return n
  160. end
  161.  
  162. local function preproc(msg, len)
  163. local extra = 64 - ((len + 1 + 8) % 64)
  164. len = num2s(8 * len, 8)
  165. msg = msg .. "\128" .. string.rep("\0", extra) .. len
  166. return msg
  167. end
  168.  
  169. local function initH256(H)
  170. H[1] = 0x6a09e667
  171. H[2] = 0xbb67ae85
  172. H[3] = 0x3c6ef372
  173. H[4] = 0xa54ff53a
  174. H[5] = 0x510e527f
  175. H[6] = 0x9b05688c
  176. H[7] = 0x1f83d9ab
  177. H[8] = 0x5be0cd19
  178. return H
  179. end
  180.  
  181. local function digestblock(msg, i, H)
  182. local w = {}
  183. for j = 1, 16 do w[j] = s232num(msg, i + (j - 1) * 4) end
  184. for j = 17, 64 do
  185. local v = w[j - 15]
  186. local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
  187. v = w[j - 2]
  188. local s1 = bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
  189. w[j] = w[j - 16] + s0 + w[j - 7] + s1
  190. end
  191.  
  192. 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]
  193. for i = 1, 64 do
  194. local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
  195. local maj = bxor(band(a, b), band(a, c), band(b, c))
  196. local t2 = s0 + maj
  197. local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
  198. local ch = bxor (band(e, f), band(bnot(e), g))
  199. local t1 = h + s1 + ch + k[i] + w[i]
  200. h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
  201. end
  202.  
  203. H[1] = band(H[1], a)
  204. H[2] = band(H[2], b)
  205. H[3] = band(H[3], c)
  206. H[4] = band(H[4], d)
  207. H[5] = band(H[5], e)
  208. H[6] = band(H[6], f)
  209. H[7] = band(H[7], g)
  210. H[8] = band(H[8], h)
  211. end
  212.  
  213. msg = preproc(msg, #msg)
  214. local H = initH256({})
  215. for i = 1, #msg, 64 do digestblock(msg, i, H) end
  216. return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
  217. num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
  218. end
  219. saltHash = "T01hFg62zY"
  220. function settingsChangeUser()
  221. reset()
  222. term.setTextColor(colors.orange)
  223. local passFile = io.open("/.EnderOS/.passInfo", "r")
  224. local passContents = passFile:read()
  225. passFile:close()
  226. print("Please enter your password: ")
  227. term.setTextColor(colors.white)
  228. local input = read("*")
  229. local hash = sha256(input)
  230. if hash..saltHash ~= passContents then
  231. term.setTextColor(colors.red)
  232. print("Invalid password")
  233. sleep(1.5)
  234. settingsChangeUser()
  235. else
  236. local user = ("/.EnderOS/.userInfo")
  237. local username = io.open(user, "w")
  238. term.setTextColor(colors.orange)
  239. print("Enter new username: ")
  240. term.setTextColor(colors.white)
  241. writeUser = read()
  242. local hash = sha256(writeUser)
  243. writeN = username:write(hash..saltHash)
  244. username:close()
  245. term.setTextColor(colors.lightBlue)
  246. print("Your new username is "..writeUser)
  247. sleep(2)
  248. startScreen()
  249. end
  250. term.setTextColor(colors.white)
  251. end
  252. function settingsChangePass()
  253. reset()
  254. term.setTextColor(colors.orange)
  255. local passFile = io.open("/.EnderOS/.passInfo", "r")
  256. local passContents = passFile:read()
  257. passFile:close()
  258. print("Please enter your password: ")
  259. term.setTextColor(colors.white)
  260. local input = read("*")
  261. local hash = sha256(input)
  262. if hash..saltHash ~= passContents then
  263. term.setTextColor(colors.red)
  264. print("Invalid password")
  265. sleep(1.5)
  266. settingsChangePass()
  267. else
  268. local pass = ("/.EnderOS/.passInfo")
  269. local password = io.open(pass, "w")
  270. term.setTextColor(colors.orange)
  271. print("Enter new password: ")
  272. term.setTextColor(colors.white)
  273. local writePass = read("*")
  274. local hash = sha256(writePass)
  275. local writeN = password:write(hash..saltHash)
  276. password:close()
  277. term.setTextColor(colors.lightBlue)
  278. print("Your new password is "..writePass)
  279. sleep(2)
  280. startScreen()
  281. end
  282. term.setTextColor(colors.white)
  283. end
  284. function settingsChangeHint()
  285. reset()
  286. term.setTextColor(colors.orange)
  287. local passFile = io.open("/.EnderOS/.passInfo", "r")
  288. local passContents = passFile:read()
  289. passFile:close()
  290. print("Please enter your password: ")
  291. term.setTextColor(colors.white)
  292. local input = read("*")
  293. local hash = sha256(input)
  294. if hash..saltHash ~= passContents then
  295. term.setTextColor(colors.red)
  296. print("Invalid password")
  297. sleep(1.5)
  298. settingsChangeHint()
  299. else
  300. local hint = ("/.EnderOS/.userHint")
  301. local uHint = io.open(hint, "w")
  302. term.setTextColor(colors.orange)
  303. print("Enter new hint: ")
  304. term.setTextColor(colors.white)
  305. local writeHint = read()
  306. if #writeHint >30 then
  307. term.setTextColor(colors.red)
  308. print("This Hint exceeds the max hint length of 30!")
  309. sleep(3)
  310. uHint:close()
  311. settingsChangeHint()
  312. else
  313. local writeN = uHint:write(writeHint)
  314. uHint:close()
  315. term.setTextColor(colors.lightBlue)
  316. print("Your new hint is "..writeHint)
  317. sleep(2)
  318. startScreen()
  319. end
  320. end
  321. term.setTextColor(colors.white)
  322. end
  323. version = "v2.4"
  324. function calculator()
  325. term.clear()
  326. term.setCursorPos(1,1)
  327. term.setTextColor(colors.orange)
  328. print("Please type your first number")
  329. term.setTextColor(colors.white)
  330. firstNum = read()
  331. numOneIsValid = tonumber(firstNum)
  332. if type(numOneIsValid) == "number" then
  333. term.setTextColor(colors.orange)
  334. print("Please type your second number")
  335. term.setTextColor(colors.white)
  336. secondNum = read()
  337. numTwoIsValid = tonumber(secondNum)
  338. if type(numTwoIsValid) == "number" then
  339. term.clear()
  340. term.setCursorPos(1,1)
  341. term.setTextColor(colors.orange)
  342. print("What would you like to do with these numbers?")
  343. term.setCursorPos(1,3)
  344. term.setTextColor(colors.lime)
  345. print("{Add} {Subtract} {Multiply} {Divide}")
  346. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  347. if button == 1 then
  348. if (xPos >=1 and xPos <=5 and yPos == 3) then
  349. term.clear()
  350. term.setCursorPos(1,1)
  351. local sum = (firstNum+secondNum)
  352. term.setTextColor(colors.lightBlue)
  353. print("The sum of your numbers is "..sum)
  354. term.setCursorPos(1,3)
  355. term.setTextColor(colors.lime)
  356. print("{Clear} {Exit}")
  357. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  358. if button == 1 then
  359. if (xPos >=1 and xPos <=7 and yPos == 3) then
  360. calculator()
  361. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  362. startScreen()
  363. else
  364. calculator()
  365. end
  366. else
  367. calculator()
  368. end
  369. sleep(3.5)
  370. startScreen()
  371. elseif (xPos >=7 and xPos <=16 and yPos == 3) then
  372. term.clear()
  373. term.setCursorPos(1,1)
  374. local diff = (firstNum-secondNum)
  375. term.setTextColor(colors.lightBlue)
  376. term.write("The difference of your numbers is "..diff)
  377. term.setCursorPos(1,3)
  378. term.setTextColor(colors.lime)
  379. print("{Clear} {Exit}")
  380. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  381. if button == 1 then
  382. if (xPos >=1 and xPos <=7 and yPos == 3) then
  383. calculator()
  384. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  385. startScreen()
  386. else
  387. calculator()
  388. end
  389. else
  390. calculator()
  391. end
  392. elseif (xPos >=18 and xPos <=27 and yPos == 3) then
  393. term.clear()
  394. term.setCursorPos(1,1)
  395. local product = (firstNum*secondNum)
  396. term.setTextColor(colors.lightBlue)
  397. term.write("The product of your two numbers is "..product)
  398. term.setCursorPos(1,3)
  399. term.setTextColor(colors.lime)
  400. print("{Clear} {Exit}")
  401. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  402. if button == 1 then
  403. if (xPos >=1 and xPos <=7 and yPos == 3) then
  404. calculator()
  405. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  406. startScreen()
  407. else
  408. calculator()
  409. end
  410. else
  411. calculator()
  412. end
  413. elseif (xPos >=29 and xPos <=36 and yPos == 3) then
  414. term.clear()
  415. term.setCursorPos(1,1)
  416. local quotient = (firstNum/secondNum)
  417. term.setTextColor(colors.lightBlue)
  418. term.write("The quotient of your two numbers is "..quotient)
  419. term.setCursorPos(1,3)
  420. term.setTextColor(colors.lime)
  421. print("{Clear} {Exit}")
  422. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  423. if button == 1 then
  424. if (xPos >=1 and xPos <=7 and yPos == 3) then
  425. calculator()
  426. elseif (xPos >=9 and xPos <=14 and yPos == 3) then
  427. startScreen()
  428. else
  429. calculator()
  430. end
  431. else
  432. calculator()
  433. end
  434. else
  435. startScreen()
  436. end
  437. else
  438. startScreen()
  439. end
  440. else
  441. term.clear()
  442. term.setCursorPos(1,1)
  443. term.setTextColor(colors.red)
  444. print("The Endermen are not amused!")
  445. sleep(3)
  446. startScreen()
  447. end
  448. else
  449. term.clear()
  450. term.setCursorPos(1,1)
  451. term.setTextColor(colors.red)
  452. print("The Endermen are not amused!")
  453. sleep(3)
  454. startScreen()
  455. end
  456. end
  457. function Edit()
  458. reset()
  459. term.setTextColor(colors.orange)
  460. print("What file do you wish to edit?")
  461. -- Get file to edit
  462. term.setTextColor(colors.white)
  463. local input = read()
  464. if #input == 0 then
  465. term.setTextColor(colors.red)
  466. print( "Usage: edit <path>" )
  467. term.setTextColor(colors.white)
  468. startScreen()
  469. end
  470. reset()
  471.  
  472. -- Error checking
  473. local sPath = shell.resolve(input)
  474. local bReadOnly = fs.isReadOnly( sPath )
  475. if fs.exists( sPath ) and fs.isDir( sPath ) then
  476. term.setTextColor(colors.red)
  477. print( "Cannot edit a directory." )
  478. term.setTextColor(colors.white)
  479. sleep(3)
  480. Edit()
  481. end
  482.  
  483. if fs.exists( sPath ) and sPath == shell.getRunningProgram() then
  484. term.setTextColor(colors.red)
  485. print( "Cannot edit the file EnderOS is contained in!" )
  486. term.setTextColor(colors.white)
  487. sleep(3)
  488. Edit()
  489. end
  490.  
  491. local x,y = 1,1
  492. local w,h = term.getSize()
  493. local scrollX, scrollY = 0,0
  494.  
  495. local tLines = {}
  496. local bRunning = true
  497.  
  498. -- Colours
  499. local highlightColour, keywordColour, commentColour, textColour, bgColour
  500. if term.isColour() then
  501. bgColour = colours.black
  502. textColour = colours.white
  503. highlightColour = colours.orange
  504. keywordColour = colours.lightBlue
  505. commentColour = colours.lime
  506. stringColour = colours.red
  507. else
  508. bgColour = colours.black
  509. textColour = colours.white
  510. highlightColour = colours.white
  511. keywordColour = colours.white
  512. commentColour = colours.white
  513. stringColour = colours.white
  514. end
  515.  
  516. -- Menus
  517. local bMenu = false
  518. local nMenuItem = 1
  519. local tMenuItems = {"Save", "Exit", "Print"}
  520. local sStatus = "Press Ctrl to access menu"
  521.  
  522. local function load(_sPath)
  523. tLines = {}
  524. if fs.exists( _sPath ) then
  525. local file = io.open( _sPath, "r" )
  526. local sLine = file:read()
  527. while sLine do
  528. table.insert( tLines, sLine )
  529. sLine = file:read()
  530. end
  531. file:close()
  532. end
  533.  
  534. if #tLines == 0 then
  535. table.insert( tLines, "" )
  536. end
  537. end
  538.  
  539. local function save( _sPath )
  540. -- Create intervening folder
  541. local sDir = sPath:sub(1, sPath:len() - fs.getName(sPath):len() )
  542. if not fs.exists( sDir ) then
  543. fs.makeDir( sDir )
  544. end
  545.  
  546. -- Save
  547. local file = nil
  548. local function innerSave()
  549. file = fs.open( _sPath, "w" )
  550. if file then
  551. for n, sLine in ipairs( tLines ) do
  552. file.write( sLine .. "\n" )
  553. end
  554. else
  555. term.setTextColor(colors.red)
  556. error( "EnderOS failed to open ".._sPath )
  557. term.setTextColor(colors.white)
  558. end
  559. end
  560.  
  561. local ok = pcall( innerSave )
  562. if file then
  563. file.close()
  564. end
  565. return ok
  566. end
  567.  
  568. local tKeywords = {
  569. ["and"] = true,
  570. ["break"] = true,
  571. ["do"] = true,
  572. ["else"] = true,
  573. ["elseif"] = true,
  574. ["end"] = true,
  575. ["false"] = true,
  576. ["for"] = true,
  577. ["function"] = true,
  578. ["if"] = true,
  579. ["in"] = true,
  580. ["local"] = true,
  581. ["nil"] = true,
  582. ["not"] = true,
  583. ["or"] = true,
  584. ["repeat"] = true,
  585. ["return"] = true,
  586. ["then"] = true,
  587. ["true"] = true,
  588. ["until"]= true,
  589. ["while"] = true,
  590. }
  591.  
  592. local function tryWrite( sLine, regex, colour )
  593. local match = string.match( sLine, regex )
  594. if match then
  595. if type(colour) == "number" then
  596. term.setTextColour( colour )
  597. else
  598. term.setTextColour( colour(match) )
  599. end
  600. term.write( match )
  601. term.setTextColour( textColour )
  602. return string.sub( sLine, string.len(match) + 1 )
  603. end
  604. return nil
  605. end
  606.  
  607. local function writeHighlighted( sLine )
  608. while string.len(sLine) > 0 do
  609. sLine =
  610. tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or
  611. tryWrite( sLine, "^%-%-.*", commentColour ) or
  612. tryWrite( sLine, "^\".-[^\\]\"", stringColour ) or
  613. tryWrite( sLine, "^\'.-[^\\]\'", stringColour ) or
  614. tryWrite( sLine, "^%[%[.-%]%]", stringColour ) or
  615. tryWrite( sLine, "^[%w_]+", function( match )
  616. if tKeywords[ match ] then
  617. return keywordColour
  618. end
  619. return textColour
  620. end ) or
  621. tryWrite( sLine, "^[^%w_]", textColour )
  622. end
  623. end
  624.  
  625. local function redrawText()
  626. for y=1,h-1 do
  627. term.setCursorPos( 1 - scrollX, y )
  628. term.clearLine()
  629.  
  630. local sLine = tLines[ y + scrollY ]
  631. if sLine ~= nil then
  632. writeHighlighted( sLine )
  633. end
  634. end
  635. term.setCursorPos( x - scrollX, y - scrollY )
  636. end
  637.  
  638. local function redrawLine(_nY)
  639. local sLine = tLines[_nY]
  640. term.setCursorPos( 1 - scrollX, _nY - scrollY )
  641. term.clearLine()
  642. writeHighlighted( sLine )
  643. term.setCursorPos( x - scrollX, _nY - scrollY )
  644. end
  645.  
  646. local function setLeftStatus()
  647. end
  648.  
  649. local function redrawMenu()
  650. term.setCursorPos( 1, h )
  651. term.clearLine()
  652.  
  653. local sLeft, sRight
  654. local nLeftColour, nLeftHighlight1, nLeftHighlight2
  655. if bMenu then
  656. local sMenu = ""
  657. for n,sItem in ipairs( tMenuItems ) do
  658. if n == nMenuItem then
  659. nLeftHighlight1 = sMenu:len() + 1
  660. nLeftHighlight2 = sMenu:len() + sItem:len() + 2
  661. end
  662. sMenu = sMenu.." "..sItem.." "
  663. end
  664. sLeft = sMenu
  665. nLeftColour = textColour
  666. else
  667. sLeft = sStatus
  668. nLeftColour = highlightColour
  669. end
  670.  
  671. -- Left goes last so that it can overwrite the line numbers.
  672. sRight = "Ln "..y
  673. term.setTextColour( highlightColour )
  674. term.setCursorPos( w-sRight:len() + 1, h )
  675. term.write(sRight)
  676.  
  677. sRight = tostring(y)
  678. term.setTextColour( textColour )
  679. term.setCursorPos( w-sRight:len() + 1, h )
  680. term.write(sRight)
  681.  
  682. if sLeft then
  683. term.setCursorPos( 1, h )
  684. term.setTextColour( nLeftColour )
  685. term.write(sLeft)
  686. if nLeftHighlight1 then
  687. term.setTextColour( highlightColour )
  688. term.setCursorPos( nLeftHighlight1, h )
  689. term.write( "[" )
  690. term.setCursorPos( nLeftHighlight2, h )
  691. term.write( "]" )
  692. end
  693. term.setTextColour( textColour )
  694. end
  695.  
  696. -- Cursor highlights selection
  697. term.setCursorPos( x - scrollX, y - scrollY )
  698. end
  699.  
  700. local tMenuFuncs = {
  701. Save=function()
  702. if bReadOnly then
  703. sStatus = "You cannot access this file!"
  704. else
  705. local ok, err = save( sPath )
  706. if ok then
  707. sStatus="EnderOS saved this file to "..sPath
  708. else
  709. sStatus="EnderOS could not save this file to "..sPath
  710. end
  711. end
  712. redrawMenu()
  713. end,
  714. Print=function()
  715. local sPrinterSide = nil
  716. for n,sSide in ipairs(rs.getSides()) do
  717. if peripheral.isPresent(sSide) and peripheral.getType(sSide) == "printer" then
  718. sPrinterSide = sSide
  719. break
  720. end
  721. end
  722.  
  723. if not sPrinterSide then
  724. sStatus = "EnderOS could not find any printers!"
  725. return
  726. end
  727.  
  728. local nPage = 0
  729. local sName = fs.getName( sPath )
  730. local printer = peripheral.wrap(sPrinterSide)
  731. if printer.getInkLevel() < 1 then
  732. sStatus = "EnderOS detected no ink!"
  733. return
  734. elseif printer.getPaperLevel() < 1 then
  735. sStatus = "EnderOS detected no paper!"
  736. return
  737. end
  738.  
  739. local terminal = {
  740. getCursorPos = printer.getCursorPos,
  741. setCursorPos = printer.setCursorPos,
  742. getSize = printer.getPageSize,
  743. write = printer.write,
  744. }
  745. terminal.scroll = function()
  746. if nPage == 1 then
  747. printer.setPageTitle( sName.." (page "..nPage..")" )
  748. end
  749.  
  750. while not printer.newPage() do
  751. if printer.getInkLevel() < 1 then
  752. sStatus = "EnderOS has detected low ink levels, please refill"
  753. elseif printer.getPaperLevel() < 1 then
  754. sStatus = "EnderOS has detected low paper levels, please refill"
  755. else
  756. sStatus = "EnderOS has detected a full output tray, please empty"
  757. end
  758.  
  759. term.restore()
  760. redrawMenu()
  761. term.redirect( terminal )
  762.  
  763. local timer = os.startTimer(0.5)
  764. sleep(0.5)
  765. end
  766.  
  767. nPage = nPage + 1
  768. if nPage == 1 then
  769. printer.setPageTitle( sName )
  770. else
  771. printer.setPageTitle( sName.." (page "..nPage..")" )
  772. end
  773. end
  774.  
  775. bMenu = false
  776. term.redirect( terminal )
  777. local ok, error = pcall( function()
  778. term.scroll()
  779. for n, sLine in ipairs( tLines ) do
  780. print( sLine )
  781. end
  782. end )
  783. term.restore()
  784. if not ok then
  785. print( error )
  786. end
  787.  
  788. while not printer.endPage() do
  789. sStatus = "EnderOS has detected a full output tray, please empty"
  790. redrawMenu()
  791. sleep( 0.5 )
  792. end
  793. bMenu = true
  794.  
  795. if nPage > 1 then
  796. sStatus = "EnderOS printed "..nPage.." Pages"
  797. else
  798. sStatus = "EnderOS printed 1 Page"
  799. end
  800. redrawMenu()
  801. end,
  802. Exit=function()
  803. bRunning = false
  804. end
  805. }
  806.  
  807. local function doMenuItem( _n )
  808. tMenuFuncs[tMenuItems[_n]]()
  809. if bMenu then
  810. bMenu = false
  811. term.setCursorBlink( true )
  812. end
  813. redrawMenu()
  814. end
  815.  
  816. local function setCursor( x, y )
  817. local screenX = x - scrollX
  818. local screenY = y - scrollY
  819.  
  820. local bRedraw = false
  821. if screenX < 1 then
  822. scrollX = x - 1
  823. screenX = 1
  824. bRedraw = true
  825. elseif screenX > w then
  826. scrollX = x - w
  827. screenX = w
  828. bRedraw = true
  829. end
  830.  
  831. if screenY < 1 then
  832. scrollY = y - 1
  833. screenY = 1
  834. bRedraw = true
  835. elseif screenY > h-1 then
  836. scrollY = y - (h-1)
  837. screenY = h-1
  838. bRedraw = true
  839. end
  840.  
  841. if bRedraw then
  842. redrawText()
  843. end
  844. term.setCursorPos( screenX, screenY )
  845.  
  846. -- Statusbar now pertains to menu, it would probably be safe to redraw the menu on every key event.
  847. redrawMenu()
  848. end
  849.  
  850. -- Actual program functionality begins
  851. load(sPath)
  852.  
  853. term.setBackgroundColour( bgColour )
  854. term.clear()
  855. term.setCursorPos(x,y)
  856. term.setCursorBlink( true )
  857.  
  858. redrawText()
  859. redrawMenu()
  860.  
  861. -- Handle input
  862. while bRunning do
  863. local sEvent, param, param2, param3 = os.pullEvent()
  864. if sEvent == "key" then
  865. if param == keys.up then
  866. -- Up
  867. if not bMenu then
  868. if y > 1 then
  869. -- Move cursor up
  870. y = y - 1
  871. x = math.min( x, string.len( tLines[y] ) + 1 )
  872. setCursor( x, y )
  873. end
  874. end
  875. elseif param == keys.down then
  876. -- Down
  877. if not bMenu then
  878. -- Move cursor down
  879. if y < #tLines then
  880. y = y + 1
  881. x = math.min( x, string.len( tLines[y] ) + 1 )
  882. setCursor( x, y )
  883. end
  884. end
  885. elseif param == keys.tab then
  886. -- Tab
  887. if not bMenu then
  888. local sLine = tLines[y]
  889.  
  890. -- Indent line
  891. -- IN CASE OF INSERT TAB IN PLACE:
  892. -- tLines[y] = string.sub(sLine,1,x-1) .. " " .. string.sub(sLine,x)
  893. tLines[y]=" "..tLines[y]
  894. x = x + 2
  895. setCursor( x, y )
  896. redrawLine(y)
  897. end
  898. elseif param == keys.pageUp then
  899. -- Page Up
  900. if not bMenu then
  901. -- Move up a page
  902. local sx,sy=term.getSize()
  903. y=y-sy-1
  904. if y<1 then y=1 end
  905. x = math.min( x, string.len( tLines[y] ) + 1 )
  906. setCursor( x, y )
  907. end
  908. elseif param == keys.pageDown then
  909. -- Page Down
  910. if not bMenu then
  911. -- Move down a page
  912. local sx,sy=term.getSize()
  913. if y<#tLines-sy-1 then
  914. y = y+sy-1
  915. else
  916. y = #tLines
  917. end
  918. x = math.min( x, string.len( tLines[y] ) + 1 )
  919. setCursor( x, y )
  920. end
  921. elseif param == keys.home then
  922. -- Home
  923. if not bMenu then
  924. -- Move cursor to the beginning
  925. x=1
  926. setCursor(x,y)
  927. end
  928. elseif param == keys["end"] then
  929. -- End
  930. if not bMenu then
  931. -- Move cursor to the end
  932. x = string.len( tLines[y] ) + 1
  933. setCursor(x,y)
  934. end
  935. elseif param == keys.left then
  936. -- Left
  937. if not bMenu then
  938. if x > 1 then
  939. -- Move cursor left
  940. x = x - 1
  941. elseif x==1 and y>1 then
  942. x = string.len( tLines[y-1] ) + 1
  943. y = y - 1
  944. end
  945. setCursor( x, y )
  946. else
  947. -- Move menu left
  948. nMenuItem = nMenuItem - 1
  949. if nMenuItem < 1 then
  950. nMenuItem = #tMenuItems
  951. end
  952. redrawMenu()
  953. end
  954. elseif param == keys.right then
  955. -- Right
  956. if not bMenu then
  957. if x < string.len( tLines[y] ) + 1 then
  958. -- Move cursor right
  959. x = x + 1
  960. elseif x==string.len( tLines[y] ) + 1 and y<#tLines then
  961. x = 1
  962. y = y + 1
  963. end
  964. setCursor( x, y )
  965. else
  966. -- Move menu right
  967. nMenuItem = nMenuItem + 1
  968. if nMenuItem > #tMenuItems then
  969. nMenuItem = 1
  970. end
  971. redrawMenu()
  972. end
  973. elseif param == keys.delete then
  974. -- Delete
  975. if not bMenu then
  976. if x < string.len( tLines[y] ) + 1 then
  977. local sLine = tLines[y]
  978. tLines[y] = string.sub(sLine,1,x-1) .. string.sub(sLine,x+1)
  979. redrawLine(y)
  980. elseif y<#tLines then
  981. tLines[y] = tLines[y] .. tLines[y+1]
  982. table.remove( tLines, y+1 )
  983. redrawText()
  984. redrawMenu()
  985. end
  986. end
  987. elseif param == keys.backspace then
  988. -- Backspace
  989. if not bMenu then
  990. if x > 1 then
  991. -- Remove character
  992. local sLine = tLines[y]
  993. tLines[y] = string.sub(sLine,1,x-2) .. string.sub(sLine,x)
  994. redrawLine(y)
  995.  
  996. x = x - 1
  997. setCursor( x, y )
  998. elseif y > 1 then
  999. -- Remove newline
  1000. local sPrevLen = string.len( tLines[y-1] )
  1001. tLines[y-1] = tLines[y-1] .. tLines[y]
  1002. table.remove( tLines, y )
  1003. redrawText()
  1004.  
  1005. x = sPrevLen + 1
  1006. y = y - 1
  1007. setCursor( x, y )
  1008. end
  1009. end
  1010. elseif param == keys.enter then
  1011. -- Enter
  1012. if not bMenu then
  1013. -- Newline
  1014. local sLine = tLines[y]
  1015. local _,spaces=string.find(sLine,"^[ ]+")
  1016. if not spaces then
  1017. spaces=0
  1018. end
  1019. tLines[y] = string.sub(sLine,1,x-1)
  1020. table.insert( tLines, y+1, string.rep(' ',spaces)..string.sub(sLine,x) )
  1021. redrawText()
  1022.  
  1023. x = spaces+1
  1024. y = y + 1
  1025. setCursor( x, y )
  1026. else
  1027. -- Menu selection
  1028. doMenuItem( nMenuItem )
  1029. end
  1030. elseif param == keys.leftCtrl or param == keys.rightCtrl then
  1031. -- Menu toggle
  1032. bMenu = not bMenu
  1033. if bMenu then
  1034. term.setCursorBlink( false )
  1035. nMenuItem = 1
  1036. else
  1037. term.setCursorBlink( true )
  1038. end
  1039. redrawMenu()
  1040. end
  1041.  
  1042. elseif sEvent == "char" then
  1043. if not bMenu then
  1044. -- Input text
  1045. local sLine = tLines[y]
  1046. tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)
  1047. redrawLine(y)
  1048.  
  1049. x = x + string.len( param )
  1050. setCursor( x, y )
  1051. else
  1052. -- Select menu items
  1053. for n,sMenuItem in ipairs( tMenuItems ) do
  1054. if string.lower(string.sub(sMenuItem,1,1)) == string.lower(param) then
  1055. doMenuItem( n )
  1056. break
  1057. end
  1058. end
  1059. end
  1060.  
  1061. elseif sEvent == "mouse_click" then
  1062. if not bMenu then
  1063. if param == 1 then
  1064. -- Left click
  1065. local cx,cy = param2, param3
  1066. if cy < h then
  1067. y = math.min( math.max( scrollY + cy, 1 ), #tLines )
  1068. x = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[y] ) + 1 )
  1069. setCursor( x, y )
  1070. end
  1071. end
  1072. end
  1073.  
  1074. elseif sEvent == "mouse_scroll" then
  1075. if not bMenu then
  1076. if param == -1 then
  1077. -- Scroll up
  1078. if scrollY > 0 then
  1079. -- Move cursor up
  1080. scrollY = scrollY - 1
  1081. redrawText()
  1082. end
  1083.  
  1084. elseif param == 1 then
  1085. -- Scroll down
  1086. local nMaxScroll = #tLines - (h-1)
  1087. if scrollY < nMaxScroll then
  1088. -- Move cursor down
  1089. scrollY = scrollY + 1
  1090. redrawText()
  1091. end
  1092.  
  1093. end
  1094. end
  1095. end
  1096. end
  1097.  
  1098. -- Cleanup
  1099. term.clear()
  1100. term.setCursorBlink( false )
  1101. term.setCursorPos( 1, 1 )
  1102. startScreen()
  1103. end
  1104. function programs()
  1105. term.setTextColor(colors.purple)
  1106. frame()
  1107. term.setCursorPos(17,1)
  1108. term.setTextColor(colors.lime)
  1109. print("[User Programs]")
  1110. term.setCursorPos(3,1)
  1111. term.setTextColor(colors.orange)
  1112. term.write("[Back]")
  1113. term.setTextColor(colors.white)
  1114. local programs = shell.programs()
  1115. term.setCursorPos(3,3)
  1116. local pTable = textutils.pagedTabulate(programs)
  1117. term.setCursorPos(3,3)
  1118. print(pTable)
  1119. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1120. if button == 1 then
  1121. if (xPos >=3 and xPos <=8 and yPos == 1) then
  1122. startScreen()
  1123. else
  1124. programs()
  1125. end
  1126. else
  1127. programs()
  1128. end
  1129. end
  1130. function reset()
  1131. term.clear()
  1132. term.setCursorPos(1,1)
  1133. end
  1134. function userInfo()
  1135. reset()
  1136. fs.makeDir("/.EnderOS/")
  1137. user = ("/.EnderOS/.userInfo")
  1138. username = io.open(user, "w")
  1139. term.setTextColor(colors.orange)
  1140. print("Please enter your desired Username")
  1141. term.setTextColor(colors.white)
  1142. writeUser = read()
  1143. if #writeUser <2 then
  1144. term.setTextColor(colors.red)
  1145. print("The Endermen hack you in their sleep!")
  1146. sleep(3)
  1147. userInfo()
  1148. end
  1149. local hash = sha256(writeUser)
  1150. writeIsFailUser = username:write(hash..saltHash)
  1151. username:close()
  1152. pass = ("/.EnderOS/.passInfo")
  1153. password = io.open(pass, "w")
  1154. term.setTextColor(colors.orange)
  1155. print("Please enter your desired Password")
  1156. term.setTextColor(colors.white)
  1157. writePass = read("*")
  1158. if #writePass <2 then
  1159. term.setTextColor(colors.red)
  1160. print("The Endermen hack you in their sleep!")
  1161. sleep(3)
  1162. userInfo()
  1163. end
  1164. local hash = sha256(writePass)
  1165. writeIsFailPass = password:write(hash..saltHash)
  1166. password:close()
  1167. hint = ("/.EnderOS/.userHint")
  1168. uHint = io.open(hint, "w")
  1169. term.setTextColor(colors.orange)
  1170. print("Please enter your desired Password hint")
  1171. term.setTextColor(colors.white)
  1172. writeHint = read()
  1173. if #writeHint >30 then
  1174. term.setTextColor(colors.red)
  1175. print("The Endermen revoke any hint greater then 30 characters!")
  1176. shell.run("delete","/.EnderOS/.userInfo")
  1177. shell.run("delete","/.EnderOS/.passInfo")
  1178. uHint:close()
  1179. sleep(2)
  1180. userInfo()
  1181. else
  1182. writeIsFailHint = uHint:write(writeHint)
  1183. uHint:close()
  1184. local installC = fs.open("/.EnderOS/.EnderOSisInstalled", "w")
  1185. installC:close()
  1186. end
  1187. end
  1188. function frame()
  1189. print("+-------------------------------------------------+")
  1190. for i = 1,17 do
  1191. print("| |")
  1192. end
  1193. term.write("+-------------------------------------------------+")
  1194. end
  1195. function no()
  1196. term.clear()
  1197. term.setTextColor(colors.red)
  1198. term.setCursorPos(1,1)
  1199. print("Sorry, I have not coded this in yet. Please be patient.")
  1200. sleep(3)
  1201. end
  1202. function screen()
  1203. reset()
  1204. term.setTextColor(colors.lime)
  1205. print("+-------------------------------------------------+")
  1206. print("| |")
  1207. print("| ")
  1208. term.setCursorPos(19,3)
  1209. term.setTextColor(colors.purple)
  1210. write("EnderOS "..version)
  1211. term.setTextColor(colors.lime)
  1212. term.setCursorPos(31,3)
  1213. print(" |")
  1214. print("| |")
  1215. print("| |")
  1216. print("| |")
  1217. print("| |")
  1218. print("| ")
  1219. term.setCursorPos(10,8)
  1220. term.setTextColor(colors.orange)
  1221. print("Username:")
  1222. term.setCursorPos(19,8)
  1223. print(" ")
  1224. term.setCursorPos(50,8)
  1225. term.setTextColor(colors.lime)
  1226. print(" |")
  1227. print("| |")
  1228. print("| ")
  1229. term.setTextColor(colors.orange)
  1230. term.setCursorPos(10,10)
  1231. print("Password:")
  1232. term.setCursorPos(19,10)
  1233. print(" ")
  1234. term.setCursorPos(50,10)
  1235. term.setTextColor(colors.lime)
  1236. print(" |")
  1237. print("| |")
  1238. print("| |")
  1239. print("| ")
  1240. term.setCursorPos(8,13)
  1241. term.setTextColor(colors.blue)
  1242. print("forgot password ")
  1243. term.setCursorPos(50,13)
  1244. term.setTextColor(colors.lime)
  1245. print(" |")
  1246. print("| |")
  1247. print("| |")
  1248. print("| |")
  1249. print("| |")
  1250. print("| |")
  1251. write("+-------------------------------------------------+")
  1252. end
  1253. function click()
  1254. local userHint = io.open("/.EnderOS/.userHint", "r")
  1255. hintContents = userHint:read()
  1256. userHint:close()
  1257. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1258. if button == 1 then
  1259. if (xPos >=8 and xPos <=22 and yPos == 13) then
  1260. term.setCursorPos(10,15)
  1261. term.setTextColor(colors.lightGray)
  1262. print("Hint: "..hintContents)
  1263. term.setTextColor(colors.white)
  1264. click()
  1265. elseif (xPos >=10 and xPos <=18 and yPos == 8) then
  1266. term.setCursorPos(20,8)
  1267. else
  1268. screen()
  1269. click()
  1270. end
  1271. else
  1272. click()
  1273. end
  1274. end
  1275. function login()
  1276. click()
  1277. local userFile = io.open("/.EnderOS/.userInfo", "r")
  1278. userContents = userFile:read()
  1279. userFile:close()
  1280. local passFile = io.open("/.EnderOS/.passInfo", "r")
  1281. passContents = passFile:read()
  1282. passFile:close()
  1283. term.setTextColor(colors.white)
  1284. local input = read()
  1285. local hash = sha256(input)
  1286. if hash..saltHash == userContents then
  1287. term.setCursorPos(8,8)
  1288. term.setTextColor(colors.lime)
  1289. term.write("O")
  1290. term.setTextColor(colors.white)
  1291. term.setCursorPos(20,10)
  1292. local input = read("*")
  1293. local hash = sha256(input)
  1294. if hash..saltHash == passContents then
  1295. term.setCursorPos(8,10)
  1296. term.setTextColor(colors.lime)
  1297. term.write("O")
  1298. term.setTextColor(colors.white)
  1299. sleep(0.8)
  1300. term.clear()
  1301. term.setCursorPos(19,9)
  1302. x,y = term.getCursorPos()
  1303. print("Logging in")
  1304. term.setCursorPos(x+10,9)
  1305. sleep(0.7)
  1306. print(".")
  1307. sleep(0.7)
  1308. term.setCursorPos(x+11,9)
  1309. print(".")
  1310. sleep(0.7)
  1311. term.setCursorPos(x+12,9)
  1312. print(".")
  1313. sleep(0.7)
  1314. reset()
  1315. startScreen()
  1316. else
  1317. term.setCursorPos(8,10)
  1318. term.setTextColor(colors.red)
  1319. term.write("X")
  1320. sleep(0.5)
  1321. term.setTextColor(colors.white)
  1322. screen()
  1323. login()
  1324. end
  1325. else
  1326. term.setCursorPos(8,8)
  1327. term.setTextColor(colors.red)
  1328. term.write("X")
  1329. sleep(0.5)
  1330. term.setTextColor(colors.white)
  1331. screen()
  1332. login()
  1333. end
  1334. end
  1335. function run()
  1336. reset()
  1337. term.setTextColor(colors.orange)
  1338. print("What program do you wish to run?")
  1339. term.setTextColor(colors.white)
  1340. input = read()
  1341. if not fs.exists(input) then
  1342. term.setTextColor(colors.red)
  1343. print("File doesn't exist!")
  1344. sleep(3)
  1345. startScreen()
  1346. end
  1347. if input == shell.getRunningProgram() then
  1348. term.setTextColor(colors.red)
  1349. print("The Endermen are not fond of your jokes!")
  1350. sleep(3)
  1351. startScreen()
  1352. else
  1353. shell.run(input)
  1354. sleep(1.5)
  1355. startScreen()
  1356. end
  1357. end
  1358. function settings()
  1359. term.setTextColor(colors.purple)
  1360. frame()
  1361. term.setCursorPos(17,1)
  1362. term.setTextColor(colors.lime)
  1363. print("[EnderOS Settings]")
  1364. term.setCursorPos(7,3)
  1365. print("{Change Username} {Change Password}")
  1366. term.setCursorPos(15,5)
  1367. print("{Change Password Hint}")
  1368. term.setCursorPos(3,1)
  1369. term.setTextColor(colors.orange)
  1370. term.write("[Back]")
  1371. term.setTextColor(colors.white)
  1372. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1373. if button == 1 then
  1374. if (xPos >=7 and xPos <=23 and yPos == 3) then
  1375. settingsChangeUser()
  1376. elseif (xPos >=27 and xPos <=43 and yPos == 3) then
  1377. settingsChangePass()
  1378. elseif (xPos >=15 and xPos <=36 and yPos == 5) then
  1379. settingsChangeHint()
  1380. elseif (xPos >=3 and xPos <=9 and yPos == 1) then
  1381. startScreen()
  1382. else
  1383. settings()
  1384. end
  1385. else
  1386. settings()
  1387. end
  1388. end
  1389. function games()
  1390. term.setTextColor(colors.purple)
  1391. frame()
  1392. term.setCursorPos(18,1)
  1393. term.setTextColor(colors.lime)
  1394. print("[EnderOS Games]")
  1395. term.setCursorPos(3,3)
  1396. print("{SkullPong} {AdventureCraft}")
  1397. term.setCursorPos(3,1)
  1398. term.setTextColor(colors.orange)
  1399. term.write("[Back]")
  1400. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1401. if button == 1 then
  1402. if (xPos >=3 and xPos <=13 and yPos == 3) then
  1403. SkullPong()
  1404. elseif (xPos >=3 and xPos <=9 and yPos == 1) then
  1405. startScreen()
  1406. elseif (xPos >=17 and xPos <=32 and yPos == 3) then
  1407. AdventureCraft()
  1408. else
  1409. games()
  1410. end
  1411. else
  1412. games()
  1413. end
  1414. end
  1415. function delete()
  1416. reset()
  1417. term.setTextColor(colors.orange)
  1418. print("What file do you wish to delete?")
  1419. term.setTextColor(colors.white)
  1420. file = read()
  1421. if not fs.exists(file) then
  1422. term.setTextColor(colors.red)
  1423. print("File doesn't exist!")
  1424. sleep(2)
  1425. startScreen()
  1426. end
  1427. if file == shell.getRunningProgram() or file == "/.EnderOS/.userInfo" or file == "/.EnderOS/.passInfo" or file == "startup" or file == shell.getRunningProgram() then
  1428. term.setTextColor(colors.red)
  1429. print("Cannot delete the file: "..file)
  1430. sleep(3)
  1431. startScreen()
  1432. else
  1433. reset()
  1434. term.setTextColor(colors.orange)
  1435. print("Are you sure you want to delete the file: "..file)
  1436. term.setCursorPos(1,2)
  1437. term.setTextColor(colors.white)
  1438. input = read()
  1439. if input == "Yes" or input == "yes" then
  1440. shell.run("delete",file)
  1441. reset()
  1442. term.setTextColor(colors.lightBlue)
  1443. print(file.." deleted!")
  1444. sleep(2)
  1445. startScreen()
  1446. else
  1447. startScreen()
  1448. end
  1449. end
  1450. end
  1451. function startScreen()
  1452. reset()
  1453. term.setTextColor(colors.purple)
  1454. frame()
  1455. term.setCursorPos(3,19)
  1456. term.setTextColor(colors.orange)
  1457. term.write("[Log Out]")
  1458. term.setCursorPos(17,1)
  1459. term.setTextColor(colors.lime)
  1460. print("[EnderOS Commands]")
  1461. term.setCursorPos(3,3)
  1462. print("{Settings} {Games} {Edit} {Programs}")
  1463. term.setCursorPos(3,5)
  1464. print("{Delete} {Run} {Calculator}")
  1465. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  1466. if button == 1 then
  1467. if (xPos >=3 and xPos <=12 and yPos == 3) then --SETTINGS
  1468. settings()
  1469. elseif (xPos >=16 and xPos <=22 and yPos == 3) then --GAMES
  1470. games()
  1471. elseif (xPos >=26 and xPos <=31 and yPos == 3) then --EDIT
  1472. Edit()
  1473. elseif (xPos >=35 and xPos <=44 and yPos == 3) then --PROGRAMS
  1474. programs()
  1475. elseif (xPos >=3 and xPos <=10 and yPos == 5) then --DELETE
  1476. delete()
  1477. elseif (xPos >=14 and xPos <=18 and yPos == 5) then --RUN
  1478. run()
  1479. elseif (xPos >=22 and xPos <=33 and yPos == 5) then --CALCULATOR
  1480. calculator()
  1481. elseif (xPos >=3 and xPos <=11 and yPos == 19) then --LOG OFF
  1482. reset()
  1483. screen()
  1484. login()
  1485. else
  1486. startScreen()
  1487. end
  1488. else
  1489. startScreen()
  1490. end
  1491. end
  1492. function SkullPong()
  1493. --Code By SkullBlade(Skullblade213)
  1494. --You are allowed to modify and redistribute
  1495. --You are not allowed to modify this header
  1496. function Draw()
  1497. term.setBackgroundColor(counter)
  1498. term.clear()
  1499. term.setBackgroundColor(colors.white)
  1500. term.setCursorPos(Ball[1], Ball[2])
  1501. print(" ")
  1502. term.setBackgroundColor(colors.lime)
  1503. term.setCursorPos(You[1], You[2])
  1504. print(" ")
  1505. term.setCursorPos(You[1], You[3])
  1506. print(" ")
  1507. term.setCursorPos(You[1], You[4])
  1508. print(" ")
  1509. term.setBackgroundColor(colors.red)
  1510. term.setCursorPos(Op[1], Op[2])
  1511. print(" ")
  1512. term.setCursorPos(Op[1], Op[3])
  1513. print(" ")
  1514. term.setCursorPos(Op[1], Op[4])
  1515. print(" ")
  1516. end
  1517. function Update()
  1518. Ball={Ball[1]+Ball[3],Ball[2]+Ball[4],Ball[3],Ball[4]}
  1519. if Ball[1]==3 or Ball[1]==49 then
  1520. if Ball[1]==3 then
  1521. Check="L"
  1522. end
  1523. if Ball[1]==49 then
  1524. Check="R"
  1525. end
  1526. if (Ball[2]==You[2] and Check=="L") or (Ball[2]==Op[2] and Check=="R") then
  1527. Ball[3]=Ball[3]*-1
  1528. Ball[4]=-1
  1529. rans=math.random(1,5)
  1530. end
  1531. if (Ball[2]==You[3] and Check=="L") or (Ball[2]==Op[3] and Check=="R") then
  1532. Ball[3]=Ball[3]*-1
  1533. Ball[4]=Ball[4]*-1
  1534. end
  1535. if (Ball[2]==You[4] and Check=="L") or (Ball[2]==Op[4] and Check=="R") then
  1536. Ball[3]=Ball[3]*-1
  1537. Ball[4]=1
  1538. end
  1539. end
  1540. if Ball[2]==1 or Ball[2]==18 or Ball[2]==0 or Ball[2]==19 then
  1541. Ball[4]=Ball[4]*-1
  1542. end
  1543. if Ball[1]==1 then
  1544. score2=score2+1
  1545. Start()
  1546. end
  1547. if Ball[1]==51 then
  1548. score=score+1
  1549. Start()
  1550. end
  1551. end
  1552. function Move()
  1553. if key==200 then
  1554. You[2]=You[2]-1
  1555. end
  1556. if key==208 then
  1557. You[2]=You[2]+1
  1558. end
  1559. end
  1560. function AI()
  1561. if Ball[2]+Ball[4]>Op[2]+2 then
  1562. if Op[2]+3~=19 then
  1563. Op={Op[1],Op[2]+1,Op[2]+2,Op[2]+3}
  1564. end
  1565. end
  1566. if Ball[2]+Ball[4]<Op[2] then
  1567. if Op[2]-1~=0 then
  1568. Op={Op[1],Op[2]-1,Op[2],Op[2]+1}
  1569. end
  1570. end
  1571. end
  1572. function Start()
  1573. You={2,9,10,11}
  1574. Op={50,9,10,11}
  1575. ran=math.random(-1,1)
  1576. ran2=math.random(-1,1)
  1577. while ran==0 do
  1578. ran=math.random(-1,1)
  1579. end
  1580. while ran2==0 do
  1581. ran2=math.random(-1,1)
  1582. end
  1583. Ball={25,10,ran,ran2}
  1584. term.setCursorPos(20,10)
  1585. print(score.." VS "..score2)
  1586. if vars=="surv" and score2==1 then
  1587. ends="true"
  1588. end
  1589. sleep(1)
  1590. end
  1591. function Single(v)
  1592. vars=v
  1593. ends="false"
  1594. score=0
  1595. score2=0
  1596. if resume~="true" then
  1597. Start()
  1598. end
  1599. counter=1
  1600. breaks="false"
  1601. while true do
  1602. if vars=="surv" then
  1603. counter=counter*2
  1604. if counter==32 or counter==16384 then
  1605. counter=counter*2
  1606. end
  1607. if counter==32768 then
  1608. counter=2
  1609. end
  1610. term.setBackgroundColor(counter)
  1611. end
  1612. if vars~="surv" then
  1613. counter=32768
  1614. end
  1615. Draw()
  1616. os.startTimer(.1)
  1617. while true do
  1618. event, key = os.pullEvent()
  1619. if event=="key" then
  1620. if vars~="Local" then
  1621. Move()
  1622. end
  1623. if key==59 and (vars=="surv" or vars=="norm" or vars=="Local") then
  1624. Menu("Paused","Resume","Info/Help","Quit")
  1625. breaks="true"
  1626. break
  1627. end
  1628. if vars=="Local" then
  1629. if key==17 then
  1630. You[2]=You[2]-1
  1631. end
  1632. if key==31 then
  1633. You[2]=You[2]+1
  1634. end
  1635. if key==200 then
  1636. Op[2]=Op[2]-1
  1637. end
  1638. if key==208 then
  1639. Op[2]=Op[2]+1
  1640. end
  1641. if You[2]==0 then
  1642. You[2]=1
  1643. end
  1644. if You[2]==17 then
  1645. You[2]=16
  1646. end
  1647. if Op[2]==0 then
  1648. Op[2]=1
  1649. end
  1650. if Op[2]==17 then
  1651. Op[2]=16
  1652. end
  1653. You={You[1],You[2],You[2]+1,You[2]+2}
  1654. Op={Op[1],Op[2],Op[2]+1,Op[2]+2}
  1655. end
  1656. if You[2]==0 then
  1657. You[2]=1
  1658. end
  1659. if You[2]==17 then
  1660. You[2]=16
  1661. end
  1662. You={You[1],You[2],You[2]+1,You[2]+2}
  1663. end
  1664. if event=="timer" then
  1665. break
  1666. end
  1667. end
  1668. if breaks=="true" then
  1669. break
  1670. end
  1671. if vars~="Local" then
  1672. AI()
  1673. end
  1674. Update()
  1675. if ends=="true" then
  1676. ends="false"
  1677. Menu("SinglePlayer","Normal","Survival","Back")
  1678. break
  1679. end
  1680. end
  1681. end
  1682. function Set(x1,y1)
  1683. x=x1
  1684. y=y1
  1685. term.setCursorPos(x1,y1)
  1686. end
  1687. function PrintCenter(text)
  1688. textLen=string.len(text)
  1689. x = ((51-textLen)/2)
  1690. term.setCursorPos(x,y)
  1691. print(text)
  1692. y=y+1
  1693. end
  1694. function Menu(title,opt1,opt2,opt3)
  1695. resume="false"
  1696. term.setBackgroundColor(colors.black)
  1697. select=1
  1698. while true do
  1699. term.clear()
  1700. term.setCursorPos(1,1)
  1701. term.setTextColor(colors.lime)
  1702. print("SkullPong V1.10")
  1703. Set(1,6)
  1704. PrintCenter(title)
  1705. PrintCenter("------------")
  1706. term.setTextColor(colors.white)
  1707. PrintCenter(opt1)
  1708. PrintCenter(opt2)
  1709. PrintCenter(opt3)
  1710. if select==1 then
  1711. Set(1,8)
  1712. term.setTextColor(colors.blue)
  1713. PrintCenter(opt1)
  1714. term.setTextColor(colors.white)
  1715. end
  1716. if select==2 then
  1717. Set(1,9)
  1718. term.setTextColor(colors.blue)
  1719. PrintCenter(opt2)
  1720. term.setTextColor(colors.white)
  1721. end
  1722. if select==3 then
  1723. Set(1,10)
  1724. term.setTextColor(colors.blue)
  1725. PrintCenter(opt3)
  1726. term.setTextColor(colors.white)
  1727. end
  1728. event, param1, param2, param3 = os.pullEvent()
  1729. if event=="mouse_click" then
  1730. if param3==8 or param3==9 or param3==10 then
  1731. sel=select
  1732. if param3==8 then
  1733. text=opt1
  1734. select=1
  1735. end
  1736. if param3==9 then
  1737. text=opt2
  1738. select=2
  1739. end
  1740. if param3==10 then
  1741. text=opt3
  1742. select=3
  1743. end
  1744. strLen=string.len(text)
  1745. start=(51-strLen)/2-1
  1746. if param2>start and param2<start+strLen then
  1747. if select==1 then
  1748. if opt1=="SinglePlayer" then
  1749. Menu("SinglePlayer","Normal","Survival","Back")
  1750. break
  1751. end
  1752. if opt1=="Normal" then
  1753. Single("norm")
  1754. break
  1755. end
  1756. if opt1=="Resume" then
  1757. resume="true"
  1758. Single(vars)
  1759. break
  1760. end
  1761. if opt1=="Local" then
  1762. Single("Local")
  1763. break
  1764. end
  1765. end
  1766. if select==2 then
  1767. if opt1=="SinglePlayer" then
  1768. Menu("MultiPlayer","Local","Rednet","Back")
  1769. break
  1770. end
  1771. if opt1=="Normal" then
  1772. Single("surv")
  1773. break
  1774. end
  1775. if opt1=="Resume" then
  1776. if vars~="Local" then
  1777. term.clear()
  1778. term.setTextColor(colors.lime)
  1779. term.setBackgroundColor(colors.black)
  1780. term.setCursorPos(1,1)
  1781.  
  1782. print("SkullPong V1.10")
  1783. print("Help")
  1784. print("---------------")
  1785. term.setTextColor(colors.white)
  1786. print("")
  1787. print("Controls")
  1788. print("UpArrow: Paddle Up")
  1789. print("DownArrow: Paddle Down")
  1790. print("Objective")
  1791. print("Don't let the ball get pass the green paddle{You}")
  1792. print("Get the ball pass the red paddle{AI}")
  1793. print("")
  1794. print("Press any key to continue")
  1795. os.pullEvent("key")
  1796. end
  1797. if vars=="Local" then
  1798. term.clear()
  1799. term.setTextColor(colors.lime)
  1800. term.setBackgroundColor(colors.black)
  1801. term.setCursorPos(1,1)
  1802. print("SkullPong V1.10")
  1803. print("Help")
  1804. print("---------------")
  1805. term.setTextColor(colors.white)
  1806. print("")
  1807. print("Controls")
  1808. print("UpArrow: Paddle Up-Red")
  1809. print("DownArrow: Paddle Down-Red")
  1810. print("W: Paddle Up-Green")
  1811. print("A: Paddle Down-Green")
  1812. print("Objective")
  1813. print("Don't let the ball get pass the your paddle")
  1814. print("Get the ball pass your opponent's paddle")
  1815. print("")
  1816. print("Press any key to continue")
  1817. os.pullEvent("key")
  1818. end
  1819. end
  1820. if opt1=="Local" then
  1821. error("Not Implimented!")
  1822. end
  1823. end
  1824. if select==3 then
  1825. if opt1=="SinglePlayer" then
  1826. term.clear()
  1827. term.setCursorPos(1,1)
  1828. break
  1829. else
  1830. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  1831. break
  1832. end
  1833. end
  1834. else
  1835. select=sel
  1836. end
  1837. end
  1838. end
  1839. if event=="key" then
  1840. if param1==200 then
  1841. select=select-1
  1842. end
  1843. if param1==208 then
  1844. select=select+1
  1845. end
  1846. if param1==28 then
  1847. if select==1 then
  1848. if opt1=="SinglePlayer" then
  1849. Menu("SinglePlayer","Normal","Survival","Back")
  1850. break
  1851. end
  1852. if opt1=="Normal" then
  1853. Single("norm")
  1854. break
  1855. end
  1856. if opt1=="Resume" then
  1857. resume="true"
  1858. Single(vars)
  1859. break
  1860. end
  1861. if opt1=="Local" then
  1862. Single("Local")
  1863. break
  1864. end
  1865. end
  1866. if select==2 then
  1867. if opt1=="SinglePlayer" then
  1868. Menu("MultiPlayer","Local","Rednet","Back")
  1869. break
  1870. end
  1871. if opt1=="Normal" then
  1872. Single("surv")
  1873. break
  1874. end
  1875. if opt1=="Resume" then
  1876. if vars~="Local" then
  1877. term.clear()
  1878. term.setTextColor(colors.lime)
  1879. term.setBackgroundColor(colors.black)
  1880. term.setCursorPos(1,1)
  1881.  
  1882. print("SkullPong V1.10")
  1883. print("Help")
  1884. print("---------------")
  1885. term.setTextColor(colors.white)
  1886. print("")
  1887. print("Controls")
  1888. print("UpArrow: Paddle Up")
  1889. print("DownArrow: Paddle Down")
  1890. print("Objective")
  1891. print("Don't let the ball get pass the green paddle{You}")
  1892. print("Get the ball pass the red paddle{AI}")
  1893. print("")
  1894. print("Press any key to continue")
  1895. os.pullEvent("key")
  1896. end
  1897. if vars=="Local" then
  1898. term.clear()
  1899. term.setTextColor(colors.lime)
  1900. term.setBackgroundColor(colors.black)
  1901. term.setCursorPos(1,1)
  1902. print("SkullPong V1.10")
  1903. print("Help")
  1904. print("---------------")
  1905. term.setTextColor(colors.white)
  1906. print("")
  1907. print("Controls")
  1908. print("UpArrow: Paddle Up-Red")
  1909. print("DownArrow: Paddle Down-Red")
  1910. print("W: Paddle Up-Green")
  1911. print("A: Paddle Down-Green")
  1912. print("Objective")
  1913. print("Don't let the ball get pass the your paddle")
  1914. print("Get the ball pass your opponent's paddle")
  1915. print("")
  1916. print("Press any key to continue")
  1917. os.pullEvent("key")
  1918. end
  1919. end
  1920. if opt1=="Local" then
  1921. error("Not Implimented!")
  1922. end
  1923. end
  1924. if select==3 then
  1925. if opt1=="SinglePlayer" then
  1926. term.clear()
  1927. term.setCursorPos(1,1)
  1928. break
  1929. else
  1930. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  1931. break
  1932. end
  1933. end
  1934. end
  1935. if select==0 then
  1936. select=3
  1937. end
  1938. if select==4 then
  1939. select=1
  1940. end
  1941. end
  1942. end
  1943. end
  1944. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  1945. games()
  1946. end
  1947. function AdventureCraft()
  1948. term.setTextColor(colors.white)
  1949. --Misc stats
  1950. numbertext = 0
  1951. --Player stats
  1952. PlayerGold = 0
  1953. PlayerName = ("Player")
  1954. PlayerArmor = 0
  1955. PlayerSword = 0
  1956. PlayerHealth = 100
  1957. PlayerDamage = 5
  1958. PlayerWeapon = ("Fists")
  1959. PlayerArmorType = ("None")
  1960. Block = 0
  1961.  
  1962. rouge = {
  1963. }
  1964.  
  1965.  
  1966.  
  1967. playerokaya = {
  1968. " (o o) ",
  1969. "()||[=]|| ",
  1970. " | | "
  1971. }
  1972. playerhappy = {
  1973. " (o o) /",
  1974. "()||[=]||/ ",
  1975. " | | "
  1976. }
  1977. playerokay = {
  1978. " (o o) /",
  1979. " ||( )||/ ",
  1980. " | | "
  1981. }
  1982. playersad = {
  1983. " (o o) ",
  1984. " ||( )|| ",
  1985. " | | "
  1986. }
  1987.  
  1988. --Npcs
  1989. shopkeeper = {
  1990. " _____ ",
  1991. " |O O| ",
  1992. " | U | ",
  1993. " |_____| ",
  1994. " Shopkeeper"
  1995. }
  1996. --items
  1997. sword = {
  1998. " ___ ",
  1999. "| /|",
  2000. "|-/-|",
  2001. "|/ |",
  2002. "|---|"
  2003. }
  2004. armor = {
  2005. " ___ ",
  2006. "| _ |",
  2007. "|/ \\|",
  2008. "||_||",
  2009. "|---|"
  2010. }
  2011. potion = {
  2012. " ___ ",
  2013. "|/^\\|",
  2014. "|| ||",
  2015. "||_||",
  2016. "|---|"
  2017. }
  2018. bow = {
  2019. " ___ ",
  2020. "||\\ |",
  2021. "|==>|",
  2022. "||/ |",
  2023. "|---|"
  2024. }
  2025. nextpage = {
  2026. " ___ ",
  2027. "| |",
  2028. "|==>|",
  2029. "| |",
  2030. "|---|"
  2031. }
  2032. prevpage = {
  2033. " ___ ",
  2034. "| |",
  2035. "|<==|",
  2036. "| |",
  2037. "|---|"
  2038. }
  2039. --Creature Features
  2040.  
  2041. CurrentCreatureGold = 0
  2042. CurrentCreatureHealth = 0
  2043. CurrentCreatureAttack = 0
  2044.  
  2045. spider = {
  2046. ". (o-o) .",
  2047. ". // \\\\ .",
  2048. ". / \\ .",
  2049. ". .",
  2050. ". Spider .",
  2051. "Spider"
  2052. }
  2053.  
  2054. slime = {
  2055. " ___ ",
  2056. " [o.o] ",
  2057. " [ _ ] ",
  2058. " ",
  2059. " Slime ",
  2060. "Slime"
  2061. }
  2062. magmacube = {
  2063. " ^___^ ",
  2064. " ^[o.o]^ ",
  2065. " ^[___]^ ",
  2066. " ^ ^ ",
  2067. " magmacube ",
  2068. "Magmacube"
  2069. }
  2070. ghast = {
  2071. " ___ ",
  2072. " [-.-] ",
  2073. " [_O_] ",
  2074. " \\\\\\\\ ",
  2075. " Ghast ",
  2076. "Ghast"
  2077. }
  2078. enderdragon = {
  2079. " ^_^ ",
  2080. "- [=.=] --",
  2081. "X- [ - ]-XX",
  2082. "XX--||--XXX",
  2083. "EnderDragon",
  2084. "EnderDragon"
  2085. }
  2086. spiderhp = 20
  2087. slimehp = 15
  2088. spiderattack = 5
  2089. slimeattack = 10
  2090.  
  2091. --drawing functions
  2092.  
  2093. function drawClasses()
  2094. term.setCursorPos(1,4)
  2095. print(string.rep("X",w-13))
  2096. term.setCursorPos(1,h-4)
  2097. print(string.rep("X",w-13))
  2098. for i = 1,3 do
  2099. end
  2100. end
  2101.  
  2102.  
  2103.  
  2104. function drawShopItems(name,name2,type,num,num2,gold)
  2105. -- in each
  2106. --37total
  2107. for i = 1, 5 do
  2108. term.setCursorPos(1 + ((num-1)*5),3+num2 + i)
  2109. print(type[i])
  2110. end
  2111. term.setCursorPos(1 + ((num-1)*5),3+num2 + 6)
  2112. print(name)
  2113. term.setCursorPos(1 + ((num-1)*5),3+num2 + 7)
  2114. print(name2)
  2115. term.setCursorPos(1 + ((num-1)*5),3+num2)
  2116. print(" " .. gold .. "G")
  2117. resetCursor()
  2118.  
  2119. end
  2120.  
  2121.  
  2122. function drawShopOutline()
  2123. term.setCursorPos(1,2)
  2124. print(string.rep("-",w-13))
  2125. term.setCursorPos(1,(h-5))
  2126. print(string.rep("-",w-13))
  2127. end
  2128.  
  2129.  
  2130. w,h = term.getSize()
  2131.  
  2132. function drawscreen()
  2133. term.clear()
  2134. end
  2135.  
  2136. function resetCursor()
  2137. term.setCursorPos(1,h)
  2138. end
  2139.  
  2140. function text(input)
  2141. if numbertext > 6 then
  2142. draw()
  2143. numbertext = 0
  2144. term.setCursorPos(1,(numbertext + 1))
  2145. print(input)
  2146. numbertext = numbertext + 1
  2147. else
  2148. term.setCursorPos(1,(numbertext + 1))
  2149. print(input)
  2150. numbertext = numbertext + 1
  2151. end
  2152. term.setCursorPos(1,h)
  2153. end
  2154.  
  2155. function draw()
  2156. term.clear()
  2157. term.setCursorPos(1,1)
  2158. print(string.rep("=",w))
  2159. term.setCursorPos(1,(h-1))
  2160. print(string.rep("=",w))
  2161. for i = 1,h do
  2162. term.setCursorPos(w-12,i)
  2163. print("|")
  2164. end
  2165. term.setCursorPos(1,(h-4))
  2166. print("attack,block")
  2167. resetCursor()
  2168. end
  2169.  
  2170. function drawBlank()
  2171. term.clear()
  2172. term.setCursorPos(1,1)
  2173. print(string.rep("=",w))
  2174. term.setCursorPos(1,(h-1))
  2175. print(string.rep("=",w))
  2176. for i = 1,h do
  2177. term.setCursorPos(w-12,i)
  2178. print("|")
  2179. end
  2180. term.setCursorPos(1,(h-4))
  2181. print(" ")
  2182. resetCursor()
  2183. end
  2184.  
  2185. function drawWalk()
  2186. term.clear()
  2187. term.setCursorPos(1,1)
  2188. print(string.rep("=",w))
  2189. term.setCursorPos(1,(h-1))
  2190. print(string.rep("=",w))
  2191. for i = 1,h do
  2192. term.setCursorPos(w-12,i)
  2193. print("|")
  2194. end
  2195. term.setCursorPos(1,(h-3))
  2196. print("forward,left,right")
  2197. resetCursor()
  2198. end
  2199.  
  2200. function drawShop(page)
  2201. term.clear()
  2202. term.setCursorPos(1,1)
  2203. print(string.rep("=",w))
  2204. term.setCursorPos(1,(h-1))
  2205. print(string.rep("=",w-13))
  2206. for i = 1,h do
  2207. term.setCursorPos(w-12,i)
  2208. print("|")
  2209. end
  2210. term.setCursorPos(1,(h-3))
  2211. print("purchase,leave,page " .. page)
  2212. resetCursor()
  2213. end
  2214.  
  2215. function displayFunctions(func)
  2216. for i = 1, 5 do
  2217. term.setCursorPos((w-11), i)
  2218. local textdisplay = func[i]
  2219. print(textdisplay)
  2220. end
  2221. resetCursor()
  2222. displayPlayerStats()
  2223. end
  2224.  
  2225. function Reset(C)
  2226. draw()
  2227. displayFunctions(C)
  2228. displayStats(CurrentCreatureHealth)
  2229. displayPlayerStats()
  2230. resetCursor()
  2231. numbertext = 0
  2232. end
  2233.  
  2234. function reset()
  2235. draw()
  2236. displayPlayerStats()
  2237. numbertext = 0
  2238. end
  2239.  
  2240. function resetWalk()
  2241. drawWalk()
  2242. displayPlayerStats()
  2243. numbertext = 0
  2244. end
  2245.  
  2246. function displayStats(func)
  2247. --for i = 1, #func do
  2248. term.setCursorPos((w-11), 6)
  2249. --local textdisplay = func[i]
  2250. print("Health:" .. func .. " ")
  2251. --end
  2252. resetCursor()
  2253. end
  2254.  
  2255. function displayPlayerStats()
  2256.  
  2257. if PlayerSword == 1 and PlayerArmor > 0 then
  2258. for i = 1, 3 do
  2259. term.setCursorPos((w-11), 7+i-1)
  2260. local textdisplay = playerhappy[i]
  2261. print(textdisplay)
  2262. end
  2263. else if PlayerSword == 1 then
  2264. for i = 1, 3 do
  2265. term.setCursorPos((w-11), 7+i-1)
  2266. local textdisplay = playerokay[i]
  2267. print(textdisplay)
  2268. end
  2269. else if PlayerArmor > 0 then
  2270. for i = 1, 3 do
  2271. term.setCursorPos((w-11), 7+i-1)
  2272. local textdisplay = playerokaya[i]
  2273. print(textdisplay)
  2274. end
  2275. else
  2276. for i = 1, 3 do
  2277. term.setCursorPos((w-11), 7+i-1)
  2278. local textdisplay = playersad[i]
  2279. print(textdisplay)
  2280. end
  2281. end end end
  2282. term.setCursorPos((w-11), 10)
  2283. print(PlayerName)
  2284. term.setCursorPos((w-11), 11)
  2285. print("Health: " .. PlayerHealth .. " ")
  2286. term.setCursorPos((w-11), 12)
  2287. print("Dmg/Hit: " .. PlayerDamage)
  2288. term.setCursorPos((w-11), 13)
  2289. print("Weapon: ")
  2290. term.setCursorPos((w-11), 14)
  2291. print(PlayerWeapon)
  2292. term.setCursorPos((w-11), 15)
  2293. print("Gold:" .. PlayerGold)
  2294. term.setCursorPos((w-11), 16)
  2295. print("Armor:")
  2296. term.setCursorPos((w-11), 17)
  2297. print(PlayerArmorType)
  2298.  
  2299. resetCursor()
  2300. end
  2301. --^^ Uses table of monster created upon start of fight
  2302. --{health: {name:
  2303.  
  2304.  
  2305. --game reloads
  2306.  
  2307. function Walk()
  2308. text("Action:")
  2309. command = io.read()
  2310. resetCursor()
  2311. if command == ("forward") then
  2312. resetWalk()
  2313. text("You walk forward through some brush")
  2314. else if command == ("left") then
  2315. resetWalk()
  2316. text("You turn left and continue on")
  2317. else if command == ("right") then
  2318. resetWalk()
  2319. text("You turn right and continue")
  2320. else
  2321. resetWalk()
  2322. Walk()
  2323. end end end
  2324. resetCursor()
  2325. sleep(2)
  2326. random()
  2327. end
  2328. function WalkShop()
  2329. text("Action:")
  2330. command = io.read()
  2331. resetCursor()
  2332. if command == ("forward") then
  2333. resetWalk()
  2334. text("You walk forward through some brush")
  2335. else if command == ("left") then
  2336. resetWalk()
  2337. text("You turn left and enter the shop")
  2338. sleep(1)
  2339. shop()
  2340. else if command == ("right") then
  2341. resetWalk()
  2342. text("You turn right and continue")
  2343. else
  2344. resetWalk()
  2345. Walk()
  2346. end end end
  2347. resetCursor()
  2348. sleep(2)
  2349. random()
  2350.  
  2351. end
  2352. function pageone()
  2353. term.clear()
  2354. drawShop("two")
  2355. drawShopOutline()
  2356. displayFunctions(shopkeeper)
  2357. term.setCursorPos(1,1)
  2358. text("Welcome to my store!")
  2359. drawShopItems("Wood","Sword",sword,1,1,15)
  2360. drawShopItems("Leath.","Armor",armor,2,1,15)
  2361. drawShopItems("Iron","Sword",sword,3,1,60)
  2362. drawShopItems("Iron","Armor",armor,4,1,60)
  2363. drawShopItems("Gold","Sword",sword,5,1,85)
  2364. drawShopItems("Gold","Armor",armor,6,1,85)
  2365. drawShopItems("Next","Page",nextpage,7,1,0)
  2366. end
  2367.  
  2368. function pagetwo()
  2369. drawShop("one")
  2370. drawShopOutline()
  2371. displayFunctions(shopkeeper)
  2372. term.setCursorPos(1,1)
  2373. text("Welcome to my store!")
  2374. drawShopItems("Dia.","Sword",sword,1,1,120)
  2375. drawShopItems("Dia.","Armor",armor,2,1,120)
  2376. drawShopItems("Health","Potion",potion,3,1,10)
  2377. drawShopItems("Prev.","Page",prevpage,4,1,0)
  2378. end
  2379.  
  2380. function bought(name,page)
  2381. if page == 1 then
  2382. term.clear()
  2383. drawShop("two")
  2384. drawShopOutline()
  2385. displayFunctions(shopkeeper)
  2386. term.setCursorPos(1,1)
  2387. text("You bought a " .. name)
  2388. drawShopItems("Wood","Sword",sword,1,1,15)
  2389. drawShopItems("Leath.","Armor",armor,2,1,15)
  2390. drawShopItems("Iron","Sword",sword,3,1,60)
  2391. drawShopItems("Iron","Armor",armor,4,1,60)
  2392. drawShopItems("Gold","Sword",sword,5,1,85)
  2393. drawShopItems("Gold","Armor",armor,6,1,85)
  2394. drawShopItems("Next","Page",nextpage,7,1,0)
  2395. else if page == 2 then
  2396. drawShop("one")
  2397. drawShopOutline()
  2398. displayFunctions(shopkeeper)
  2399. term.setCursorPos(1,1)
  2400. text("You bought a " .. name)
  2401. drawShopItems("Dia.","Sword",sword,1,1,120)
  2402. drawShopItems("Dia.","Armor",armor,2,1,120)
  2403. drawShopItems("Health","Potion",potion,3,1,10)
  2404. drawShopItems("Prev.","Page",prevpage,4,1,0)
  2405. else
  2406. end end
  2407. end
  2408.  
  2409.  
  2410. function shop()
  2411. pageone()
  2412. while true do
  2413. numbertext = 0
  2414. command = io.read()
  2415. if command == ("leave") then
  2416. drawBlank()
  2417. text("Leaving Shop")
  2418. numbertext = 0
  2419. sleep(2)
  2420. random()
  2421. else if command == ("page one") then
  2422. pageone()
  2423. else if command == ("page two") then
  2424. pagetwo()
  2425. else if command == ("purchase wood sword") then
  2426. if PlayerGold >= 15 then
  2427. PlayerGold = PlayerGold - 15
  2428. PlayerDamage = PBD + 8
  2429. PlayerWeapon = ("Wooden Sword")
  2430. PlayerSword = 1
  2431. bought("Wooden Sword", 1)
  2432. displayPlayerStats()
  2433. else end
  2434. else if command == ("purchase iron sword") then
  2435. if PlayerGold >= 60 then
  2436. PlayerGold = PlayerGold - 60
  2437. PlayerDamage = PBD + 12
  2438. bought("Iron Sword", 1)
  2439. PlayerWeapon = ("Iron Sword")
  2440. PlayerSword = 1
  2441. displayPlayerStats()
  2442. else end
  2443. else if command == ("purchase gold sword") then
  2444. if PlayerGold >= 85 then
  2445. PlayerGold = PlayerGold - 85
  2446. PlayerDamage = PBD + 16
  2447. bought("Gold Sword", 1)
  2448. PlayerWeapon = ("Gold Sword")
  2449. PlayerSword = 1
  2450. displayPlayerStats()
  2451. else end
  2452. else if command == ("purchase diamond sword") then
  2453. if PlayerGold >= 120 then
  2454. PlayerGold = PlayerGold - 120
  2455. PlayerDamage = PBD + 20
  2456. bought("Diamond Sword", 2)
  2457. PlayerWeapon = ("Dia. Sword")
  2458. PlayerSword = 1
  2459. displayPlayerStats()
  2460. else end
  2461. else if command == ("purchase leather armor") then
  2462. if PlayerGold >= 15 then
  2463. PlayerGold = PlayerGold - 15
  2464. bought("Leather Armor", 1)
  2465. PlayerArmor = 1
  2466. PlayerArmorType = ("Leather")
  2467. displayPlayerStats()
  2468. else end
  2469. else if command == ("purchase iron armor") then
  2470. if PlayerGold >= 60 then
  2471. PlayerGold = PlayerGold - 60
  2472. bought("Iron Armor", 1)
  2473. PlayerArmor = 3
  2474. PlayerArmorType = ("Iron")
  2475. displayPlayerStats()
  2476. else end
  2477. else if command == ("purchase gold armor") then
  2478. if PlayerGold >= 85 then
  2479. PlayerGold = PlayerGold - 85
  2480. bought("Gold Armor", 1)
  2481. PlayerArmor = 5
  2482. PlayerArmorType = ("Gold")
  2483. displayPlayerStats()
  2484. else end
  2485. else if command == ("purchase diamond armor") then
  2486. if PlayerGold >= 120 then
  2487. PlayerGold = PlayerGold - 120
  2488. bought("Diamond Armor", 2)
  2489. PlayerArmorType = ("Diamond")
  2490. PlayerArmor = 7
  2491. displayPlayerStats()
  2492. else end
  2493. else if command == ("purchase health potion") then
  2494. if PlayerGold >= 10 then
  2495. PlayerGold = PlayerGold - 10
  2496. bought("Health Potion", 2)
  2497. PlayerHealth = PHM
  2498. displayPlayerStats()
  2499. else end
  2500. else
  2501. pageone()
  2502. end end end
  2503. end end end end end end end end end
  2504.  
  2505. end
  2506. end
  2507.  
  2508. function gameOver()
  2509. drawBlank()
  2510. term.setCursorPos((w/2)-7,(h/2))
  2511. print("YOU HAVE DIED")
  2512. term.setCursorPos((w/2)-5,(h/2)+1)
  2513. print("GAME OVER")
  2514. sleep(3)
  2515. shell.run("AdventureCraft")
  2516. end
  2517.  
  2518.  
  2519. --fighting
  2520.  
  2521. function battle(creature)
  2522. draw()
  2523. while true do
  2524. displayFunctions(creature)
  2525. displayStats(CurrentCreatureHealth)
  2526. if PlayerHealth <= 0 then
  2527. gameOver()
  2528. else
  2529. end
  2530. if CurrentCreatureHealth < 1 then
  2531. text("You have slain the " .. creature[6])
  2532. PlayerGold = PlayerGold + CurrentCreatureGold
  2533. sleep(3)
  2534. CurrentCreatureGold = 0
  2535. reset()
  2536. random()
  2537. else
  2538. Block = 0
  2539. term.setCursorPos(1,1)
  2540. text("Action:")
  2541. reaction = io.read()
  2542. if reaction == ("attack") then
  2543. Reset(creature)
  2544. text("You swing your " .. PlayerWeapon .. " at the " .. creature[6])
  2545. randomvar = math.random(1,2)
  2546. if randomvar == 1 then
  2547. randomvar = math.random(-1 * (PBD/3), PBD/3)
  2548. if randomvar == PBD/3 then print("Critical hit!") else end
  2549. CurrentCreatureHealth = CurrentCreatureHealth - PlayerDamage - randomvar
  2550. CPD = PlayerDamage + randomvar
  2551. text("You hit the " .. creature[6] .. " for " .. CPD .. " damage")
  2552. else text("It dodges your attack!")
  2553. end
  2554. else if reaction == ("block") then
  2555. Reset(creature)
  2556. text("Using your " .. PlayerWeapon .. " you block")
  2557. randomvar = math.random(1,3)
  2558. if randomvar < 2 then
  2559. Block = 2
  2560. else
  2561. Block = 1
  2562. end
  2563. else
  2564. resetCursor()
  2565. text("That is not a valid action!")
  2566. draw()
  2567. Reset(creature)
  2568. end end
  2569. sleep(2)
  2570. --creature attacks player
  2571. if Block == 0 then
  2572. randomvar = math.random(1, 3)
  2573. if randomvar > 1 then
  2574. text("The " .. creature[6] .. " missed its attack!")
  2575. else if randomvar < 2 then
  2576. randomvar = math.random(-2,2)
  2577. PlayerHealth = PlayerHealth - CurrentCreatureAttack - randomvar + PlayerArmor
  2578. text("The " .. creature[6] .. " hit you for " .. (CurrentCreatureAttack + randomvar - PlayerArmor) .. " damage")
  2579. else
  2580.  
  2581. end end
  2582. else if Block == 1 then
  2583. randomvar = math.random(1, 7)
  2584. if randomvar > 1 then
  2585. text("You successfully blocked the " .. creature[6] .. "'s attack!")
  2586. else if randomvar < 2 then
  2587. randomvar = math.random(-2,2)
  2588. PlayerHealth = PlayerHealth - CurrentCreatureAttack - randomvar + PlayerArmor
  2589. text("Your block failed, you received " .. (CurrentCreatureAttack + randomvar - PlayerArmor) .. " dmg")
  2590. end end
  2591. else
  2592. end end
  2593.  
  2594. end
  2595. end
  2596. end
  2597. --random events
  2598. count = 0
  2599. function random()
  2600. count = count + 1
  2601. randomevent = math.random(1,7)
  2602. if count == 5 or count == 15 or count == 25 or count == 35 or count == 45 or count == 55 or count == 65 or count == 75 or count == 85 then
  2603. shop()
  2604. elseif randomevent == 1 then
  2605. CurrentCreatureGold = 5
  2606. CurrentCreatureHealth = 15
  2607. CurrentCreatureAttack = 10
  2608. battle(slime)
  2609. elseif randomevent == 2 then
  2610. CurrentCreatureGold = 7
  2611. CurrentCreatureHealth = 25
  2612. CurrentCreatureAttack = 5
  2613. battle(spider)
  2614. elseif randomevent == 3 then
  2615. resetWalk()
  2616. text("You are in the middle of a meadow")
  2617. RandomShop = math.random(1,2)
  2618. if RandomShop == 2 then
  2619. text("There is a shop to the left")
  2620. WalkShop()
  2621. else
  2622. text("There is nothing around you")
  2623. Walk()
  2624. end
  2625. elseif randomevent == 4 then
  2626. shop()
  2627. elseif randomevent == 5 and count > 20 then
  2628. CurrentCreatureGold = 15
  2629. CurrentCreatureHealth = 50
  2630. CurrentCreatureAttack = 15
  2631. battle(magmacube)
  2632. elseif randomevent == 6 and count > 40 then
  2633. CurrentCreatureGold = 40
  2634. CurrentCreatureHealth = 40
  2635. CurrentCreatureAttack = 35
  2636. battle(ghast)
  2637. elseif randomevent == 7 and count > 60 then
  2638. CurrentCreatureGold = 100
  2639. CurrentCreatureHealth = 100
  2640. CurrentCreatureAttack = 25
  2641. battle(enderdragon)
  2642.  
  2643.  
  2644. else
  2645. random()
  2646. end
  2647. end
  2648.  
  2649.  
  2650. --mastercontrol
  2651. --start
  2652. numbertext = 0
  2653. drawBlank()
  2654. text("Hello adventurer!")
  2655. text("Choose a class to continue!")
  2656. text("Barbarian,Rouge,RoyalGuard")
  2657. class = io.read()
  2658. if class == ("Barbarian") then
  2659. PHM = 85
  2660. PBD = 13
  2661. PlayerHealth = 85
  2662. PlayerDamage = 13
  2663. elseif class == ("Rouge") then
  2664. PHM = 60
  2665. PBD = 20
  2666. PlayerHealth = 60
  2667. PlayerDamage = 20
  2668. elseif class == ("RoyalGuard") then
  2669. PHM = 120
  2670. PBD = 7
  2671. PlayerHealth = 120
  2672. PlayerDamage = 7
  2673. else
  2674. end
  2675. random()
  2676. startScreen()
  2677. end
  2678.  
  2679. --EnderOS
  2680. if not term.isColor() then
  2681. term.clear()
  2682. term.setCursorPos(1,1)
  2683. print("EnderOS does not currently support non-color computers!")
  2684. sleep(3)
  2685. os.shutdown()
  2686. end
  2687. file = shell.getRunningProgram()
  2688. if not file == "startup" then
  2689. print("EnderOS MUST be in a file named startup!")
  2690. sleep(3)
  2691. term.clear()
  2692. term.setCursorPos(1,1)
  2693. return
  2694. end
  2695. if not fs.exists("/.EnderOS/.EnderOSisInstalled") then
  2696. userInfo()
  2697. end
  2698. reset()
  2699. term.setTextColor(colors.purple)
  2700. term.setCursorPos(13,7)
  2701. print("EnderOS "..version.." Initializing")
  2702. term.setTextColor(colors.white)
  2703. term.setBackgroundColor(colors.lime)
  2704. for i = 14,36 do
  2705. term.setCursorPos(i,9)
  2706. term.write(" ")
  2707. sleep(0.2)
  2708. end
  2709. term.setBackgroundColor(colors.black)
  2710. sleep(0.5)
  2711. screen()
  2712. login()
  2713. startScreen()
Advertisement
Add Comment
Please, Sign In to add comment