LiquidFenrir

Luma3DS-updater in lpp-3ds

Apr 23rd, 2016
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.86 KB | None | 0 0
  1. local white = Color.new(255,255,255)
  2. local url = "http://astronautlevel2.github.io/Luma3DS/latest.zip"
  3. local zip_path = "/latest.zip"
  4. local a9lh_path = "/arm9loaderhax.bin" --max length 38 characters including the first slash. if bigger, the path inside the .bin wont be changed
  5. local backup_path = a9lh_path..".bak"
  6.  
  7. function unicodify(str)
  8.     local new_str = ""
  9.     for i = 1, #str,1 do
  10.         new_str = new_str..string.sub(str,i,i)..string.char(00)
  11.     end
  12.     return new_str
  13. end
  14.  
  15. function path_changer()
  16.     local file = io.open(a9lh_path, FREAD)
  17.     local a9lh_data = io.read(file, 0, io.size(file))
  18.     io.close(file)
  19.     local offset = string.find(a9lh_data, "%"..unicodify("arm9loaderhax.bin"))
  20.     local new_path = unicodify(string.sub(a9lh_path,2,-1))
  21.     if #new_path < 74 then
  22.         for i = 1,74-#new_path,1 do
  23.             new_path = new_path..string.char(00)
  24.         end
  25.         local file = io.open(a9lh_path, FWRITE)
  26.         io.write(file, offset-1, new_path, 74)
  27.         io.close(file)
  28.     end
  29. end
  30.  
  31. function main()
  32.     Screen.refresh()
  33.     Screen.debugPrint(5,5, "Welcome to the Luma3DS updater!", white, TOP_SCREEN)
  34.     Screen.debugPrint(5,20, "Press A to update Luma3DS", white, TOP_SCREEN)
  35.     Screen.debugPrint(5,35, "Press B to restore a Luma3DS backup", white, TOP_SCREEN)
  36.     Screen.debugPrint(5,50, "Press START to go back to HBL/Home menu", white, TOP_SCREEN)
  37.     Screen.debugPrint(5,155, "Thanks to:", white, TOP_SCREEN)
  38.     Screen.debugPrint(5,170, "astronautlevel2 for the builds", white, TOP_SCREEN)
  39.     Screen.debugPrint(5,185, "AuroraWright for her amazing CFW", white, TOP_SCREEN)
  40.     Screen.debugPrint(5,200, "Rinnegatamante for lpp-3ds", white, TOP_SCREEN)
  41.     Screen.debugPrint(5,215, "Hamcha for the idea", white, TOP_SCREEN)
  42.     Screen.waitVblankStart()
  43.     Screen.flip()
  44.     while true do
  45.         pad = Controls.read()
  46.         if pad ~= oldPad then
  47.             oldPad = pad
  48.             if Controls.check(pad,KEY_START) then
  49.                 Screen.waitVblankStart()
  50.                 Screen.flip()
  51.                 System.exit()
  52.             elseif Controls.check(pad,KEY_A) then
  53.                 Screen.refresh()
  54.                 Screen.clear(TOP_SCREEN)
  55.                 Screen.waitVblankStart()
  56.                 Screen.flip()
  57.                 if Network.isWifiEnabled() then
  58.                     Screen.debugPrint(5,5, "Downloading latest.zip...", white, TOP_SCREEN)
  59.                     Network.downloadFile(url, zip_path)
  60.                     Screen.debugPrint(5,20, "File downloaded!", white, TOP_SCREEN)
  61.                     Screen.debugPrint(5,35, "Backing up arm9loaderhax.bin...", white, TOP_SCREEN)
  62.                     System.renameFile(a9lh_path, backup_path)
  63.                     Screen.debugPrint(5,50, "Extracting arm9loaderhax.bin from latest.zip", white, TOP_SCREEN)
  64.                     System.extractFromZIP(zip_path, "out/arm9loaderhax.bin", a9lh_path)
  65.                     Screen.debugPrint(5,65, "Deleting latest.zip...", white, TOP_SCREEN)
  66.                     System.deleteFile(zip_path)
  67.                     Screen.debugPrint(5,80, "Changing path for reboot patch", white, TOP_SCREEN)
  68.                     path_changer()
  69.                     Screen.debugPrint(5,95, "Done!", white, TOP_SCREEN)
  70.                     Screen.debugPrint(5,110, "Press START to go back to HBL/Home menu", white, TOP_SCREEN)
  71.                     while true do
  72.                         pad = Controls.read()
  73.                         if pad ~= oldPad then
  74.                             oldPad = pad
  75.                             if Controls.check(pad,KEY_START) then
  76.                                 Screen.waitVblankStart()
  77.                                 Screen.flip()
  78.                                 System.exit()
  79.                             end
  80.                         end
  81.                     end
  82.                 else
  83.                     Screen.debugPrint(5,5, "WiFi is off! Please turn it on and retry!", white, TOP_SCREEN)
  84.                     Screen.debugPrint(5,20, "Press START to go back to HBL/Home menu", white, TOP_SCREEN)
  85.                     while true do
  86.                         pad = Controls.read()
  87.                         if pad ~= oldPad then
  88.                             oldPad = pad
  89.                             if Controls.check(pad,KEY_START) then
  90.                                 Screen.waitVblankStart()
  91.                                 Screen.flip()
  92.                                 System.exit()
  93.                             end
  94.                         end
  95.                     end
  96.                 end
  97.             elseif Controls.check(pad,KEY_B) then
  98.                 Screen.refresh()
  99.                 Screen.clear(TOP_SCREEN)
  100.                 Screen.waitVblankStart()
  101.                 Screen.flip()
  102.                 if System.doesFileExist(backup_path) then
  103.                     Screen.debugPrint(5,5, "Deleting new arm9loaderhax.bin...", white, TOP_SCREEN)
  104.                     System.deleteFile(a9lh_path)
  105.                     Screen.debugPrint(5,20, "Renaming backup to arm9loaderhax.bin...", white, TOP_SCREEN)
  106.                     System.renameFile(backup_path, a9lh_path)
  107.                     Screen.debugPrint(5,35, "Press START to go back to HBL/Home menu", white, TOP_SCREEN)
  108.                     while true do
  109.                         pad = Controls.read()
  110.                         if pad ~= oldPad then
  111.                             oldPad = pad
  112.                             if Controls.check(pad,KEY_START) then
  113.                                 Screen.waitVblankStart()
  114.                                 Screen.flip()
  115.                                 System.exit()
  116.                             end
  117.                         end
  118.                     end
  119.                 else
  120.                     Screen.debugPrint(5,5, "You don't have a backup to restore", white, TOP_SCREEN)
  121.                     Screen.debugPrint(5,20, "Press START to go back to HBL/Home menu", white, TOP_SCREEN)
  122.                     while true do
  123.                         pad = Controls.read()
  124.                         if pad ~= oldPad then
  125.                             oldPad = pad
  126.                             if Controls.check(pad,KEY_START) then
  127.                                 Screen.waitVblankStart()
  128.                                 Screen.flip()
  129.                                 System.exit()
  130.                             end
  131.                         end
  132.                     end
  133.                 end
  134.             end
  135.         end
  136.     end
  137. end
  138.  
  139. main()
Advertisement
Add Comment
Please, Sign In to add comment