Advertisement
SuicidalSTDz

EnderOS v2.1

Feb 1st, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.11 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.  
  7.  
  8. os.pullEvent = os.pullEventRaw
  9. term.clear()
  10. term.setCursorPos(1,1)
  11. function sha256(msg)
  12. function band(int1, int2, int3, ...)
  13. local ret =
  14. ((int1%0x00000002>=0x00000001 and int2%0x00000002>=0x00000001 and 0x00000001) or 0)+
  15. ((int1%0x00000004>=0x00000002 and int2%0x00000004>=0x00000002 and 0x00000002) or 0)+
  16. ((int1%0x00000008>=0x00000004 and int2%0x00000008>=0x00000004 and 0x00000004) or 0)+
  17. ((int1%0x00000010>=0x00000008 and int2%0x00000010>=0x00000008 and 0x00000008) or 0)+
  18. ((int1%0x00000020>=0x00000010 and int2%0x00000020>=0x00000010 and 0x00000010) or 0)+
  19. ((int1%0x00000040>=0x00000020 and int2%0x00000040>=0x00000020 and 0x00000020) or 0)+
  20. ((int1%0x00000080>=0x00000040 and int2%0x00000080>=0x00000040 and 0x00000040) or 0)+
  21. ((int1%0x00000100>=0x00000080 and int2%0x00000100>=0x00000080 and 0x00000080) or 0)+
  22. ((int1%0x00000200>=0x00000100 and int2%0x00000200>=0x00000100 and 0x00000100) or 0)+
  23. ((int1%0x00000400>=0x00000200 and int2%0x00000400>=0x00000200 and 0x00000200) or 0)+
  24. ((int1%0x00000800>=0x00000400 and int2%0x00000800>=0x00000400 and 0x00000400) or 0)+
  25. ((int1%0x00001000>=0x00000800 and int2%0x00001000>=0x00000800 and 0x00000800) or 0)+
  26. ((int1%0x00002000>=0x00001000 and int2%0x00002000>=0x00001000 and 0x00001000) or 0)+
  27. ((int1%0x00004000>=0x00002000 and int2%0x00004000>=0x00002000 and 0x00002000) or 0)+
  28. ((int1%0x00008000>=0x00004000 and int2%0x00008000>=0x00004000 and 0x00004000) or 0)+
  29. ((int1%0x00010000>=0x00008000 and int2%0x00010000>=0x00008000 and 0x00008000) or 0)+
  30. ((int1%0x00020000>=0x00010000 and int2%0x00020000>=0x00010000 and 0x00010000) or 0)+
  31. ((int1%0x00040000>=0x00020000 and int2%0x00040000>=0x00020000 and 0x00020000) or 0)+
  32. ((int1%0x00080000>=0x00040000 and int2%0x00080000>=0x00040000 and 0x00040000) or 0)+
  33. ((int1%0x00100000>=0x00080000 and int2%0x00100000>=0x00080000 and 0x00080000) or 0)+
  34. ((int1%0x00200000>=0x00100000 and int2%0x00200000>=0x00100000 and 0x00100000) or 0)+
  35. ((int1%0x00400000>=0x00200000 and int2%0x00400000>=0x00200000 and 0x00200000) or 0)+
  36. ((int1%0x00800000>=0x00400000 and int2%0x00800000>=0x00400000 and 0x00400000) or 0)+
  37. ((int1%0x01000000>=0x00800000 and int2%0x01000000>=0x00800000 and 0x00800000) or 0)+
  38. ((int1%0x02000000>=0x01000000 and int2%0x02000000>=0x01000000 and 0x01000000) or 0)+
  39. ((int1%0x04000000>=0x02000000 and int2%0x04000000>=0x02000000 and 0x02000000) or 0)+
  40. ((int1%0x08000000>=0x04000000 and int2%0x08000000>=0x04000000 and 0x04000000) or 0)+
  41. ((int1%0x10000000>=0x08000000 and int2%0x10000000>=0x08000000 and 0x08000000) or 0)+
  42. ((int1%0x20000000>=0x10000000 and int2%0x20000000>=0x10000000 and 0x10000000) or 0)+
  43. ((int1%0x40000000>=0x20000000 and int2%0x40000000>=0x20000000 and 0x20000000) or 0)+
  44. ((int1%0x80000000>=0x40000000 and int2%0x80000000>=0x40000000 and 0x40000000) or 0)+
  45. ((int1>=0x80000000 and int2>=0x80000000 and 0x80000000) or 0)
  46.  
  47. return (int3 and band(ret, int3, ...)) or ret
  48. end
  49.  
  50. local function bxor(int1, int2, int3, ...)
  51. local ret =
  52. ((int1%0x00000002>=0x00000001 ~= (int2%0x00000002>=0x00000001) and 0x00000001) or 0)+
  53. ((int1%0x00000004>=0x00000002 ~= (int2%0x00000004>=0x00000002) and 0x00000002) or 0)+
  54. ((int1%0x00000008>=0x00000004 ~= (int2%0x00000008>=0x00000004) and 0x00000004) or 0)+
  55. ((int1%0x00000010>=0x00000008 ~= (int2%0x00000010>=0x00000008) and 0x00000008) or 0)+
  56. ((int1%0x00000020>=0x00000010 ~= (int2%0x00000020>=0x00000010) and 0x00000010) or 0)+
  57. ((int1%0x00000040>=0x00000020 ~= (int2%0x00000040>=0x00000020) and 0x00000020) or 0)+
  58. ((int1%0x00000080>=0x00000040 ~= (int2%0x00000080>=0x00000040) and 0x00000040) or 0)+
  59. ((int1%0x00000100>=0x00000080 ~= (int2%0x00000100>=0x00000080) and 0x00000080) or 0)+
  60. ((int1%0x00000200>=0x00000100 ~= (int2%0x00000200>=0x00000100) and 0x00000100) or 0)+
  61. ((int1%0x00000400>=0x00000200 ~= (int2%0x00000400>=0x00000200) and 0x00000200) or 0)+
  62. ((int1%0x00000800>=0x00000400 ~= (int2%0x00000800>=0x00000400) and 0x00000400) or 0)+
  63. ((int1%0x00001000>=0x00000800 ~= (int2%0x00001000>=0x00000800) and 0x00000800) or 0)+
  64. ((int1%0x00002000>=0x00001000 ~= (int2%0x00002000>=0x00001000) and 0x00001000) or 0)+
  65. ((int1%0x00004000>=0x00002000 ~= (int2%0x00004000>=0x00002000) and 0x00002000) or 0)+
  66. ((int1%0x00008000>=0x00004000 ~= (int2%0x00008000>=0x00004000) and 0x00004000) or 0)+
  67. ((int1%0x00010000>=0x00008000 ~= (int2%0x00010000>=0x00008000) and 0x00008000) or 0)+
  68. ((int1%0x00020000>=0x00010000 ~= (int2%0x00020000>=0x00010000) and 0x00010000) or 0)+
  69. ((int1%0x00040000>=0x00020000 ~= (int2%0x00040000>=0x00020000) and 0x00020000) or 0)+
  70. ((int1%0x00080000>=0x00040000 ~= (int2%0x00080000>=0x00040000) and 0x00040000) or 0)+
  71. ((int1%0x00100000>=0x00080000 ~= (int2%0x00100000>=0x00080000) and 0x00080000) or 0)+
  72. ((int1%0x00200000>=0x00100000 ~= (int2%0x00200000>=0x00100000) and 0x00100000) or 0)+
  73. ((int1%0x00400000>=0x00200000 ~= (int2%0x00400000>=0x00200000) and 0x00200000) or 0)+
  74. ((int1%0x00800000>=0x00400000 ~= (int2%0x00800000>=0x00400000) and 0x00400000) or 0)+
  75. ((int1%0x01000000>=0x00800000 ~= (int2%0x01000000>=0x00800000) and 0x00800000) or 0)+
  76. ((int1%0x02000000>=0x01000000 ~= (int2%0x02000000>=0x01000000) and 0x01000000) or 0)+
  77. ((int1%0x04000000>=0x02000000 ~= (int2%0x04000000>=0x02000000) and 0x02000000) or 0)+
  78. ((int1%0x08000000>=0x04000000 ~= (int2%0x08000000>=0x04000000) and 0x04000000) or 0)+
  79. ((int1%0x10000000>=0x08000000 ~= (int2%0x10000000>=0x08000000) and 0x08000000) or 0)+
  80. ((int1%0x20000000>=0x10000000 ~= (int2%0x20000000>=0x10000000) and 0x10000000) or 0)+
  81. ((int1%0x40000000>=0x20000000 ~= (int2%0x40000000>=0x20000000) and 0x20000000) or 0)+
  82. ((int1%0x80000000>=0x40000000 ~= (int2%0x80000000>=0x40000000) and 0x40000000) or 0)+
  83. ((int1>=0x80000000 ~= (int2>=0x80000000) and 0x80000000) or 0)
  84.  
  85. return (int3 and bxor(ret, int3, ...)) or ret
  86. end
  87.  
  88. local function bnot(int)
  89. return 4294967295 - int
  90. end
  91.  
  92. local function rshift(int, by)
  93. local shifted = int / (2 ^ by)
  94. return shifted - shifted % 1
  95. end
  96.  
  97. local function rrotate(int, by)
  98. local shifted = int / (2 ^ by)
  99. local fraction = shifted % 1
  100. return (shifted - fraction) + fraction * (2 ^ 32)
  101. end
  102.  
  103. local k = {
  104. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  105. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  106. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  107. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  108. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  109. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  110. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  111. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  112. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  113. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  114. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  115. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  116. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  117. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  118. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  119. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
  120. }
  121.  
  122. local function str2hexa(s)
  123. local h = string.gsub(s, ".", function(c)
  124. return string.format("%02x", string.byte(c))
  125. end)
  126. return h
  127. end
  128.  
  129. local function num2s(l, n)
  130. local s = ""
  131. for i = 1, n do
  132. local rem = l % 256
  133. s = string.char(rem) .. s
  134. l = (l - rem) / 256
  135. end
  136. return s
  137. end
  138.  
  139. local function s232num(s, i)
  140. local n = 0
  141. for i = i, i + 3 do n = n*256 + string.byte(s, i) end
  142. return n
  143. end
  144.  
  145. local function preproc(msg, len)
  146. local extra = 64 - ((len + 1 + 8) % 64)
  147. len = num2s(8 * len, 8)
  148. msg = msg .. "\128" .. string.rep("\0", extra) .. len
  149. return msg
  150. end
  151.  
  152. local function initH256(H)
  153. H[1] = 0x6a09e667
  154. H[2] = 0xbb67ae85
  155. H[3] = 0x3c6ef372
  156. H[4] = 0xa54ff53a
  157. H[5] = 0x510e527f
  158. H[6] = 0x9b05688c
  159. H[7] = 0x1f83d9ab
  160. H[8] = 0x5be0cd19
  161. return H
  162. end
  163.  
  164. local function digestblock(msg, i, H)
  165. local w = {}
  166. for j = 1, 16 do w[j] = s232num(msg, i + (j - 1) * 4) end
  167. for j = 17, 64 do
  168. local v = w[j - 15]
  169. local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
  170. v = w[j - 2]
  171. local s1 = bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
  172. w[j] = w[j - 16] + s0 + w[j - 7] + s1
  173. end
  174.  
  175. 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]
  176. for i = 1, 64 do
  177. local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
  178. local maj = bxor(band(a, b), band(a, c), band(b, c))
  179. local t2 = s0 + maj
  180. local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
  181. local ch = bxor (band(e, f), band(bnot(e), g))
  182. local t1 = h + s1 + ch + k[i] + w[i]
  183. h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
  184. end
  185.  
  186. H[1] = band(H[1], a)
  187. H[2] = band(H[2], b)
  188. H[3] = band(H[3], c)
  189. H[4] = band(H[4], d)
  190. H[5] = band(H[5], e)
  191. H[6] = band(H[6], f)
  192. H[7] = band(H[7], g)
  193. H[8] = band(H[8], h)
  194. end
  195.  
  196. msg = preproc(msg, #msg)
  197. local H = initH256({})
  198. for i = 1, #msg, 64 do digestblock(msg, i, H) end
  199. return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
  200. num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
  201. end
  202. --Ignore
  203. saltHash = "T01hFg62zY"
  204. --Ignore
  205. function settingsChangeUser()
  206. reset()
  207. term.setTextColor(colors.orange)
  208. local passFile = io.open("/.EnderOS/.passInfo", "r")
  209. local passContents = passFile:read()
  210. passFile:close()
  211. print("Please enter your password: ")
  212. local input = read("*")
  213. if sha256(input) ~= passContents then
  214. print("Invalid password")
  215. sleep(1.5)
  216. settingsChangeUser()
  217. else
  218. local user = ("/.EnderOS/.userInfo")
  219. io.open(user)
  220. local username = io.open(user, "w")
  221. print("Enter new username: ")
  222. writeUser = read()
  223. local hash = sha256(writeUser)
  224. writeN = username:write(hash)
  225. username:close()
  226. print("Your new username is "..writeUser)
  227. sleep(2)
  228. startScreen()
  229. end
  230. term.setTextColor(colors.white)
  231. end
  232. function settingsChangePass()
  233. reset()
  234. term.setTextColor(colors.orange)
  235. local passFile = io.open("/.EnderOS/.passInfo", "r")
  236. local passContents = passFile:read()
  237. passFile:close()
  238. print("Please enter your password: ")
  239. local input = read("*")
  240. if sha256(input) ~= passContents then
  241. print("Invalid password")
  242. sleep(1.5)
  243. settingsChangePass()
  244. else
  245. local pass = ("/.EnderOS/.passInfo")
  246. io.open(pass)
  247. local password = io.open(pass, "w")
  248. print("Enter new password: ")
  249. local writePass = read("*")
  250. local hash = sha256(writePass)
  251. local writeN = password:write(hash)
  252. password:close()
  253. print("Your new password is "..writePass)
  254. sleep(2)
  255. startScreen()
  256. end
  257. term.setTextColor(colors.white)
  258. end
  259. function settingsChangeHint()
  260. reset()
  261. term.setTextColor(colors.orange)
  262. local passFile = io.open("/.EnderOS/.passInfo", "r")
  263. local passContents = passFile:read()
  264. passFile:close()
  265. print("Please enter your password: ")
  266. local input = read("*")
  267. if sha256(input) ~= passContents then
  268. print("Invalid password")
  269. sleep(1.5)
  270. settingsChangeHint()
  271. else
  272. local hint = ("/.EnderOS/.userHint")
  273. io.open(hint)
  274. local uHint = io.open(hint, "w")
  275. print("Enter new hint: ")
  276. local writeHint = read()
  277. local writeN = uHint:write(writeHint)
  278. uHint:close()
  279. print("Your new hint is "..writeHint)
  280. sleep(2)
  281. startScreen()
  282. end
  283. term.setTextColor(colors.white)
  284. end
  285. version = "v2.1"
  286. userfile = shell.getRunningProgram()
  287. local v = ".(Period)"
  288. function reset()
  289. term.clear()
  290. term.setCursorPos(1,1)
  291. end
  292. function userInfo()
  293. reset()
  294. fs.makeDir("/.EnderOS/")
  295. user = ("/.EnderOS/.userInfo")
  296. io.open(user)
  297. username = io.open(user, "w")
  298. print("Please enter your desired Username")
  299. writeUser = read()
  300. local hash = sha256(writeUser)
  301. writeIsFailUser = username:write(hash)
  302. username:close()
  303. pass = ("/.EnderOS/.passInfo")
  304. io.open(pass)
  305. password = io.open(pass, "w")
  306. print("Please enter your desired Password")
  307. writePass = read("*")
  308. local hash = sha256(writePass)
  309. writeIsFailPass = password:write(hash)
  310. password:close()
  311. hint = ("/.EnderOS/.userHint")
  312. io.open(hint)
  313. uHint = io.open(hint, "w")
  314. print("Please enter your desired Password hint")
  315. writeHint = read()
  316. writeIsFailHint = uHint:write(writeHint)
  317. uHint:close()
  318. local installC = fs.open("/.EnderOS/.EnderOSisInstalled", "w")
  319. installC:close()
  320. end
  321. function frame()
  322. print("+-------------------------------------------------+")
  323. for i = 1,17 do
  324. print("| |")
  325. end
  326. term.write("+-------------------------------------------------+")
  327. end
  328. function no()
  329. term.clear()
  330. term.setTextColor(colors.red)
  331. term.setCursorPos(1,1)
  332. print("Sorry, I have not coded this in yet. Please be patient.")
  333. sleep(3)
  334. end
  335. function screen()
  336. reset()
  337. term.setTextColor(colors.lime)
  338. print("+-------------------------------------------------+")
  339. print("| |")
  340. print("| ")
  341. term.setCursorPos(19,3)
  342. term.setTextColor(colors.purple)
  343. write("EnderOS "..version)
  344. term.setTextColor(colors.lime)
  345. term.setCursorPos(31,3)
  346. print(" |")
  347. print("| |")
  348. print("| |")
  349. print("| |")
  350. print("| |")
  351. print("| ")
  352. term.setCursorPos(10,8)
  353. term.setTextColor(colors.orange)
  354. print("Username:")
  355. term.setCursorPos(19,8)
  356. print(" ")
  357. term.setCursorPos(50,8)
  358. term.setTextColor(colors.lime)
  359. print(" |")
  360. print("| |")
  361. print("| ")
  362. term.setTextColor(colors.orange)
  363. term.setCursorPos(10,10)
  364. print("Password:")
  365. term.setCursorPos(19,10)
  366. print(" ")
  367. term.setCursorPos(50,10)
  368. term.setTextColor(colors.lime)
  369. print(" |")
  370. print("| |")
  371. print("| |")
  372. print("| ")
  373. term.setCursorPos(8,13)
  374. term.setTextColor(colors.blue)
  375. print("forgot password ")
  376. term.setCursorPos(50,13)
  377. term.setTextColor(colors.lime)
  378. print(" |")
  379. print("| |")
  380. print("| |")
  381. print("| |")
  382. print("| |")
  383. print("| |")
  384. write("+-------------------------------------------------+")
  385. end
  386. function click()
  387. local userHint = io.open("/.EnderOS/.userHint", "r")
  388. hintContents = userHint:read()
  389. userHint:close()
  390. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  391. if button == 1 then
  392. if (xPos >=8 and xPos <=22 and yPos == 13) then
  393. term.setCursorPos(10,15)
  394. term.setTextColor(colors.lightGray)
  395. print("Hint: "..hintContents)
  396. term.setTextColor(colors.white)
  397. click()
  398. elseif (xPos >=10 and xPos <=18 and yPos == 8) then
  399. term.setCursorPos(20,8)
  400. else
  401. screen()
  402. click()
  403. end
  404. else
  405. click()
  406. end
  407. end
  408. function login()
  409. click()
  410. local userFile = io.open("/.EnderOS/.userInfo", "r")
  411. userContents = userFile:read()
  412. userFile:close()
  413. local passFile = io.open("/.EnderOS/.passInfo", "r")
  414. passContents = passFile:read()
  415. passFile:close()
  416. term.setTextColor(colors.white)
  417. local input = read()
  418. if sha256(input) == userContents then
  419. term.setCursorPos(8,8)
  420. term.setTextColor(colors.lime)
  421. term.write("O")
  422. term.setTextColor(colors.white)
  423. term.setCursorPos(20,10)
  424. local input = read("*")
  425. if sha256(input) == passContents then
  426. term.setCursorPos(8,10)
  427. term.setTextColor(colors.lime)
  428. term.write("O")
  429. term.setTextColor(colors.white)
  430. sleep(0.8)
  431. term.clear()
  432. term.setCursorPos(19,9)
  433. x,y = term.getCursorPos()
  434. print("Logging in")
  435. term.setCursorPos(x+10,9)
  436. sleep(0.7)
  437. print(".")
  438. sleep(0.7)
  439. term.setCursorPos(x+11,9)
  440. print(".")
  441. sleep(0.7)
  442. term.setCursorPos(x+12,9)
  443. print(".")
  444. sleep(0.7)
  445. reset()
  446. startScreen()
  447. else
  448. term.setCursorPos(8,10)
  449. term.setTextColor(colors.red)
  450. term.write("X")
  451. sleep(0.5)
  452. term.setTextColor(colors.white)
  453. screen()
  454. login()
  455. end
  456. else
  457. term.setCursorPos(8,8)
  458. term.setTextColor(colors.red)
  459. term.write("X")
  460. sleep(0.5)
  461. term.setTextColor(colors.white)
  462. screen()
  463. login()
  464. end
  465. end
  466. function settings()
  467. term.setTextColor(colors.purple)
  468. frame()
  469. term.setCursorPos(17,1)
  470. term.setTextColor(colors.lime)
  471. print("[EnderOS Settings]")
  472. term.setCursorPos(7,3)
  473. print("{Change Username} {Change Password}")
  474. term.setCursorPos(15,5)
  475. print("{Change Password Hint}")
  476. term.setCursorPos(3,1)
  477. term.setTextColor(colors.orange)
  478. term.write("[Back]")
  479. term.setTextColor(colors.white)
  480. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  481. if button == 1 then
  482. if (xPos >=7 and xPos <=23 and yPos == 3) then
  483. settingsChangeUser()
  484. elseif (xPos >=27 and xPos <=43 and yPos == 3) then
  485. settingsChangePass()
  486. elseif (xPos >=15 and xPos <=36 and yPos == 5) then
  487. settingsChangeHint()
  488. elseif (xPos >=3 and xPos <=9 and yPos == 1) then
  489. startScreen()
  490. else
  491. settings()
  492. end
  493. else
  494. sleep(1)--This is to prevent spamming, thus "overloading" EnderOS
  495. settings()
  496. end
  497. end
  498. function startScreen()
  499. reset()
  500. term.setTextColor(colors.purple)
  501. frame()
  502. term.setCursorPos(3,19)
  503. term.setTextColor(colors.orange)
  504. term.write("[Log Out]")
  505. term.setCursorPos(17,1)
  506. term.setTextColor(colors.lime)
  507. print("[EnderOS Commands]")
  508. term.setCursorPos(3,3)
  509. print("{Settings} {SkullPong} {Exit}")
  510. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  511. if button == 1 then
  512. if (xPos >=16 and xPos <=26 and yPos == 3) then
  513. SkullPong()
  514. elseif (xPos >=3 and xPos <=12 and yPos == 3) then
  515. settings()
  516. elseif (xPos >=30 and xPos <=35 and yPos == 3) then
  517. reset()
  518. elseif (xPos >=3 and xPos <=11 and yPos == 19) then
  519. reset()
  520. screen()
  521. login()
  522. else
  523. startScreen()
  524. end
  525. else
  526. sleep(1)--This is to prevent spamming, thus "overloading" EnderOS
  527. startScreen()
  528. end
  529. end
  530. function SkullPong()
  531. --Code By SkullBlade(Skullblade213)
  532. --You are allowed to modify and redistribute
  533. --You are not allowed to modify this header
  534. function Draw()
  535. term.setBackgroundColor(counter)
  536. term.clear()
  537. term.setBackgroundColor(colors.white)
  538. term.setCursorPos(Ball[1], Ball[2])
  539. print(" ")
  540. term.setBackgroundColor(colors.lime)
  541. term.setCursorPos(You[1], You[2])
  542. print(" ")
  543. term.setCursorPos(You[1], You[3])
  544. print(" ")
  545. term.setCursorPos(You[1], You[4])
  546. print(" ")
  547. term.setBackgroundColor(colors.red)
  548. term.setCursorPos(Op[1], Op[2])
  549. print(" ")
  550. term.setCursorPos(Op[1], Op[3])
  551. print(" ")
  552. term.setCursorPos(Op[1], Op[4])
  553. print(" ")
  554. end
  555. function Update()
  556. Ball={Ball[1]+Ball[3],Ball[2]+Ball[4],Ball[3],Ball[4]}
  557. if Ball[1]==3 or Ball[1]==49 then
  558. if Ball[1]==3 then
  559. Check="L"
  560. end
  561. if Ball[1]==49 then
  562. Check="R"
  563. end
  564. if (Ball[2]==You[2] and Check=="L") or (Ball[2]==Op[2] and Check=="R") then
  565. Ball[3]=Ball[3]*-1
  566. Ball[4]=-1
  567. rans=math.random(1,5)
  568. end
  569. if (Ball[2]==You[3] and Check=="L") or (Ball[2]==Op[3] and Check=="R") then
  570. Ball[3]=Ball[3]*-1
  571. Ball[4]=Ball[4]*-1
  572. end
  573. if (Ball[2]==You[4] and Check=="L") or (Ball[2]==Op[4] and Check=="R") then
  574. Ball[3]=Ball[3]*-1
  575. Ball[4]=1
  576. end
  577. end
  578. if Ball[2]==1 or Ball[2]==18 or Ball[2]==0 or Ball[2]==19 then
  579. Ball[4]=Ball[4]*-1
  580. end
  581. if Ball[1]==1 then
  582. score2=score2+1
  583. Start()
  584. end
  585. if Ball[1]==51 then
  586. score=score+1
  587. Start()
  588. end
  589. end
  590. function Move()
  591. if key==200 then
  592. You[2]=You[2]-1
  593. end
  594. if key==208 then
  595. You[2]=You[2]+1
  596. end
  597. end
  598. function AI()
  599. if Ball[2]+Ball[4]>Op[2]+2 then
  600. if Op[2]+3~=19 then
  601. Op={Op[1],Op[2]+1,Op[2]+2,Op[2]+3}
  602. end
  603. end
  604. if Ball[2]+Ball[4]<Op[2] then
  605. if Op[2]-1~=0 then
  606. Op={Op[1],Op[2]-1,Op[2],Op[2]+1}
  607. end
  608. end
  609. end
  610. function Start()
  611. You={2,9,10,11}
  612. Op={50,9,10,11}
  613. ran=math.random(-1,1)
  614. ran2=math.random(-1,1)
  615. while ran==0 do
  616. ran=math.random(-1,1)
  617. end
  618. while ran2==0 do
  619. ran2=math.random(-1,1)
  620. end
  621. Ball={25,10,ran,ran2}
  622. term.setCursorPos(20,10)
  623. print(score.." VS "..score2)
  624. if vars=="surv" and score2==1 then
  625. ends="true"
  626. end
  627. sleep(1)
  628. end
  629. function Single(v)
  630. vars=v
  631. ends="false"
  632. score=0
  633. score2=0
  634. if resume~="true" then
  635. Start()
  636. end
  637. counter=1
  638. breaks="false"
  639. while true do
  640. if vars=="surv" then
  641. counter=counter*2
  642. if counter==32 or counter==16384 then
  643. counter=counter*2
  644. end
  645. if counter==32768 then
  646. counter=2
  647. end
  648. term.setBackgroundColor(counter)
  649. end
  650. if vars~="surv" then
  651. counter=32768
  652. end
  653. Draw()
  654. os.startTimer(.1)
  655. while true do
  656. event, key = os.pullEvent()
  657. if event=="key" then
  658. if vars~="Local" then
  659. Move()
  660. end
  661. if key==59 and (vars=="surv" or vars=="norm" or vars=="Local") then
  662. Menu("Paused","Resume","Info/Help","Quit")
  663. breaks="true"
  664. break
  665. end
  666. if vars=="Local" then
  667. if key==17 then
  668. You[2]=You[2]-1
  669. end
  670. if key==31 then
  671. You[2]=You[2]+1
  672. end
  673. if key==200 then
  674. Op[2]=Op[2]-1
  675. end
  676. if key==208 then
  677. Op[2]=Op[2]+1
  678. end
  679. if You[2]==0 then
  680. You[2]=1
  681. end
  682. if You[2]==17 then
  683. You[2]=16
  684. end
  685. if Op[2]==0 then
  686. Op[2]=1
  687. end
  688. if Op[2]==17 then
  689. Op[2]=16
  690. end
  691. You={You[1],You[2],You[2]+1,You[2]+2}
  692. Op={Op[1],Op[2],Op[2]+1,Op[2]+2}
  693. end
  694. if You[2]==0 then
  695. You[2]=1
  696. end
  697. if You[2]==17 then
  698. You[2]=16
  699. end
  700. You={You[1],You[2],You[2]+1,You[2]+2}
  701. end
  702. if event=="timer" then
  703. break
  704. end
  705. end
  706. if breaks=="true" then
  707. break
  708. end
  709. if vars~="Local" then
  710. AI()
  711. end
  712. Update()
  713. if ends=="true" then
  714. ends="false"
  715. Menu("SinglePlayer","Normal","Survival","Back")
  716. break
  717. end
  718. end
  719. end
  720. function Set(x1,y1)
  721. x=x1
  722. y=y1
  723. term.setCursorPos(x1,y1)
  724. end
  725. function PrintCenter(text)
  726. textLen=string.len(text)
  727. x = ((51-textLen)/2)
  728. term.setCursorPos(x,y)
  729. print(text)
  730. y=y+1
  731. end
  732. function Menu(title,opt1,opt2,opt3)
  733. resume="false"
  734. term.setBackgroundColor(colors.black)
  735. select=1
  736. while true do
  737. term.clear()
  738. term.setCursorPos(1,1)
  739. term.setTextColor(colors.lime)
  740. print("SkullPong V1.10")
  741. Set(1,6)
  742. PrintCenter(title)
  743. PrintCenter("------------")
  744. term.setTextColor(colors.white)
  745. PrintCenter(opt1)
  746. PrintCenter(opt2)
  747. PrintCenter(opt3)
  748. if select==1 then
  749. Set(1,8)
  750. term.setTextColor(colors.blue)
  751. PrintCenter(opt1)
  752. term.setTextColor(colors.white)
  753. end
  754. if select==2 then
  755. Set(1,9)
  756. term.setTextColor(colors.blue)
  757. PrintCenter(opt2)
  758. term.setTextColor(colors.white)
  759. end
  760. if select==3 then
  761. Set(1,10)
  762. term.setTextColor(colors.blue)
  763. PrintCenter(opt3)
  764. term.setTextColor(colors.white)
  765. end
  766. event, param1, param2, param3 = os.pullEvent()
  767. if event=="mouse_click" then
  768. if param3==8 or param3==9 or param3==10 then
  769. sel=select
  770. if param3==8 then
  771. text=opt1
  772. select=1
  773. end
  774. if param3==9 then
  775. text=opt2
  776. select=2
  777. end
  778. if param3==10 then
  779. text=opt3
  780. select=3
  781. end
  782. strLen=string.len(text)
  783. start=(51-strLen)/2-1
  784. if param2>start and param2<start+strLen then
  785. if select==1 then
  786. if opt1=="SinglePlayer" then
  787. Menu("SinglePlayer","Normal","Survival","Back")
  788. break
  789. end
  790. if opt1=="Normal" then
  791. Single("norm")
  792. break
  793. end
  794. if opt1=="Resume" then
  795. resume="true"
  796. Single(vars)
  797. break
  798. end
  799. if opt1=="Local" then
  800. Single("Local")
  801. break
  802. end
  803. end
  804. if select==2 then
  805. if opt1=="SinglePlayer" then
  806. Menu("MultiPlayer","Local","Rednet","Back")
  807. break
  808. end
  809. if opt1=="Normal" then
  810. Single("surv")
  811. break
  812. end
  813. if opt1=="Resume" then
  814. if vars~="Local" then
  815. term.clear()
  816. term.setTextColor(colors.lime)
  817. term.setBackgroundColor(colors.black)
  818. term.setCursorPos(1,1)
  819.  
  820. print("SkullPong V1.10")
  821. print("Help")
  822. print("---------------")
  823. term.setTextColor(colors.white)
  824. print("")
  825. print("Controls")
  826. print("UpArrow: Paddle Up")
  827. print("DownArrow: Paddle Down")
  828. print("Objective")
  829. print("Don't let the ball get pass the green paddle{You}")
  830. print("Get the ball pass the red paddle{AI}")
  831. print("")
  832. print("Press any key to continue")
  833. os.pullEvent("key")
  834. end
  835. if vars=="Local" then
  836. term.clear()
  837. term.setTextColor(colors.lime)
  838. term.setBackgroundColor(colors.black)
  839. term.setCursorPos(1,1)
  840. print("SkullPong V1.10")
  841. print("Help")
  842. print("---------------")
  843. term.setTextColor(colors.white)
  844. print("")
  845. print("Controls")
  846. print("UpArrow: Paddle Up-Red")
  847. print("DownArrow: Paddle Down-Red")
  848. print("W: Paddle Up-Green")
  849. print("A: Paddle Down-Green")
  850. print("Objective")
  851. print("Don't let the ball get pass the your paddle")
  852. print("Get the ball pass your opponent's paddle")
  853. print("")
  854. print("Press any key to continue")
  855. os.pullEvent("key")
  856. end
  857. end
  858. if opt1=="Local" then
  859. error("Not Implimented!")
  860. end
  861. end
  862. if select==3 then
  863. if opt1=="SinglePlayer" then
  864. term.clear()
  865. term.setCursorPos(1,1)
  866. break
  867. else
  868. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  869. break
  870. end
  871. end
  872. else
  873. select=sel
  874. end
  875. end
  876. end
  877. if event=="key" then
  878. if param1==200 then
  879. select=select-1
  880. end
  881. if param1==208 then
  882. select=select+1
  883. end
  884. if param1==28 then
  885. if select==1 then
  886. if opt1=="SinglePlayer" then
  887. Menu("SinglePlayer","Normal","Survival","Back")
  888. break
  889. end
  890. if opt1=="Normal" then
  891. Single("norm")
  892. break
  893. end
  894. if opt1=="Resume" then
  895. resume="true"
  896. Single(vars)
  897. break
  898. end
  899. if opt1=="Local" then
  900. Single("Local")
  901. break
  902. end
  903. end
  904. if select==2 then
  905. if opt1=="SinglePlayer" then
  906. Menu("MultiPlayer","Local","Rednet","Back")
  907. break
  908. end
  909. if opt1=="Normal" then
  910. Single("surv")
  911. break
  912. end
  913. if opt1=="Resume" then
  914. if vars~="Local" then
  915. term.clear()
  916. term.setTextColor(colors.lime)
  917. term.setBackgroundColor(colors.black)
  918. term.setCursorPos(1,1)
  919.  
  920. print("SkullPong V1.10")
  921. print("Help")
  922. print("---------------")
  923. term.setTextColor(colors.white)
  924. print("")
  925. print("Controls")
  926. print("UpArrow: Paddle Up")
  927. print("DownArrow: Paddle Down")
  928. print("Objective")
  929. print("Don't let the ball get pass the green paddle{You}")
  930. print("Get the ball pass the red paddle{AI}")
  931. print("")
  932. print("Press any key to continue")
  933. os.pullEvent("key")
  934. end
  935. if vars=="Local" then
  936. term.clear()
  937. term.setTextColor(colors.lime)
  938. term.setBackgroundColor(colors.black)
  939. term.setCursorPos(1,1)
  940. print("SkullPong V1.10")
  941. print("Help")
  942. print("---------------")
  943. term.setTextColor(colors.white)
  944. print("")
  945. print("Controls")
  946. print("UpArrow: Paddle Up-Red")
  947. print("DownArrow: Paddle Down-Red")
  948. print("W: Paddle Up-Green")
  949. print("A: Paddle Down-Green")
  950. print("Objective")
  951. print("Don't let the ball get pass the your paddle")
  952. print("Get the ball pass your opponent's paddle")
  953. print("")
  954. print("Press any key to continue")
  955. os.pullEvent("key")
  956. end
  957. end
  958. if opt1=="Local" then
  959. error("Not Implimented!")
  960. end
  961. end
  962. if select==3 then
  963. if opt1=="SinglePlayer" then
  964. term.clear()
  965. term.setCursorPos(1,1)
  966. break
  967. else
  968. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  969. break
  970. end
  971. end
  972. end
  973. if select==0 then
  974. select=3
  975. end
  976. if select==4 then
  977. select=1
  978. end
  979. end
  980. end
  981. end
  982. Menu("Start","SinglePlayer","MultiPlayer","Quit")
  983. startScreen()
  984. end
  985.  
  986. --EnderOS
  987. local running = shell.getRunningProgram()
  988. if not term.isColor() then
  989. term.clear()
  990. term.setCursorPos(1,1)
  991. print("EnderOS does not support non-color computers!")
  992. sleep(3)
  993. os.shutdown()
  994. end
  995. if running ~= startup then
  996. term.clear()
  997. term.setCursorPos(1,1)
  998. print("It is recommended that this file is named startup!")
  999. sleep(5)
  1000. end
  1001. if not fs.exists("/.EnderOS/.EnderOSisInstalled") then
  1002. userInfo()
  1003. end
  1004. reset()
  1005. term.setTextColor(colors.purple)
  1006. term.setCursorPos(13,7)
  1007. print("EnderOS "..version.." Initializing")
  1008. term.setTextColor(colors.white)
  1009. term.setBackgroundColor(colors.lime)
  1010. for i = 14,36 do
  1011. term.setCursorPos(i,9)
  1012. term.write(" ")
  1013. sleep(0.3)
  1014. end
  1015. term.setBackgroundColor(colors.black)
  1016. sleep(0.5)
  1017. screen()
  1018. login()
  1019. startScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement