SuicidalSTDz

EnderOS v2.4

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