mirror of
https://github.com/nh-server/scripts.git
synced 2026-08-15 20:20:22 -07:00
197 lines
7.8 KiB
Plaintext
197 lines
7.8 KiB
Plaintext
# Manual CTRTransfer Script
|
|
# A heavily-tweaked chimera of the original manual transfer script and the Lazarus3DS script.
|
|
# Attempts to revive a damaged NAND with a donor CTRNAND.
|
|
# last changed: 2024-09-28
|
|
# author: AnalogMan, fox8091, StarlitSkies
|
|
|
|
# Tell user what script does and ask for confirmation
|
|
set GM9IN "0:/gm9/in"
|
|
set ERRORMSG "Script aborted by user."
|
|
ask "This script overwrites the entire CTRNAND\nwith a known working copy of that data.\nIt will keep all existing unique files intact\n but everything already missing will stay missing.\n \nOnly use this script on consoles that will not boot.\n \nIf this applies to you, press (A) to continue."
|
|
|
|
# Check that essentials.exefs exists as backup, mount it, and extract uniques
|
|
# If it doesn't, check for backup essentials.exefs in 0:/gm9/out, mount it, and extract uniques
|
|
# If that doesn't exist either, check for already-extracted uniques in 0:/gm9/in instead
|
|
# If any console uniques are missing, immediately end script - this isn't Lazarus, nor should it be
|
|
|
|
if not find S:/essential.exefs ESSENTIAL
|
|
echo "Note: essential.exefs not found.\nUsing backup essential.exefs in 0:/gm9/out instead.\n \nPress (A) to continue."
|
|
if not find $[GM9IN]/essential.exefs ESSENTIAL
|
|
echo "Note: Backup essential.exefs not found.\nUsing extracted files from 0:/gm9/in instead.\n \nPress (A) to continue."
|
|
end
|
|
end
|
|
|
|
set ERRORMSG "Console unique(s) not found.\nThis script will not run unless all console uniques exist."
|
|
|
|
if chk -u $[ESSENTIAL] ""
|
|
# this is if either essential.exefs exists
|
|
imgmount $[ESSENTIAL]
|
|
set BACKUP $[GM9OUT]/backup
|
|
mkdir $[BACKUP]
|
|
cp -n -w -o -s G:/frndseed $[BACKUP]/LocalFriendCodeSeed_B
|
|
cp -n -w -o -s G:/hwcal0 $[BACKUP]/HWCAL0.dat
|
|
cp -n -w -o -s G:/hwcal1 $[BACKUP]/HWCAL1.dat
|
|
cp -n -w -o -s G:/movable $[BACKUP]/movable.sed
|
|
cp -n -w -o -s G:/secinfo $[BACKUP]/SecureInfo_A
|
|
imgumount
|
|
cp -n -w $[ESSENTIAL] $[BACKUP]/essential.exefs
|
|
find $[BACKUP]/LocalFriendCodeSeed_B SEED
|
|
find $[BACKUP]/HWCAL0.dat HWCAL0
|
|
find $[BACKUP]/HWCAL1.dat HWCAL1
|
|
find $[BACKUP]/movable.sed MOVABLE
|
|
find $[BACKUP]/SecureInfo_A SECINFO
|
|
else
|
|
# this is if neither essential.exefs exists. note it still checks gm9/in, not gm9/out
|
|
find 0:/gm9/in/LocalFriendCodeSeed_B SEED
|
|
find 0:/gm9/in/HWCAL0.dat HWCAL0
|
|
find 0:/gm9/in/HWCAL1.dat HWCAL1
|
|
find 0:/gm9/in/movable.sed MOVABLE
|
|
find 0:/gm9/in/SecureInfo_A SECINFO
|
|
end
|
|
|
|
set ERRORMSG "No valid CTRTransfer files found in 0:/gm9/in."
|
|
if chk $[ONTYPE] "N3DS"
|
|
find $[GM9IN]/*_ctrtransfer_n3ds.bin NULL
|
|
else
|
|
find $[GM9IN]/*_ctrtransfer_o3ds.bin NULL
|
|
end
|
|
|
|
set ERRORMSG "No CTRTransfer file was selected."
|
|
if chk $[ONTYPE] "N3DS"
|
|
filesel "Select the CTRTransfer file to use." $[GM9IN]/*_ctrtransfer_n3ds.bin IMAGE
|
|
else
|
|
filesel "Select the CTRTransfer file to use." $[GM9IN]/*_ctrtransfer_o3ds.bin IMAGE
|
|
end
|
|
|
|
set ERRORMSG "The selected CTRNAND image is corrupted.\n \nPower off the console and obtain\na new copy of your CTRTransfer file."
|
|
sha $[IMAGE] $[IMAGE].sha
|
|
imgmount $[IMAGE]
|
|
find 7:/title/000400db/00017?02 NULL
|
|
imgumount
|
|
|
|
if ask "Also restore non-critical data?\nThis includes things like the friends list and activity log,\nwhich would normally be reset.\n \nThis is usually safe, but may carry\na risk of preserving file corruption.\n \n(If you do not restore the data,\nbackups of it will be kept in 0:/pit.)"
|
|
set OPTRESTORE 1
|
|
else
|
|
set OPTRESTORE 0
|
|
end
|
|
|
|
# Prompt for permission
|
|
set ERRORMSG "Script denied permissions by user."
|
|
allow -a S:
|
|
|
|
# Preserve all other important console-unique data, regardless of whether it's restored after transfer
|
|
# Attempt to copy sysdata files to SD
|
|
set ERRORMSG "Backing up data somehow failed...?"
|
|
cp -w -o -s -n 1:/data/$[SYSID0]/sysdata/00010017/00000000 0:/pit/configsave.bin
|
|
cp -w -o -s -n 1:/data/$[SYSID0]/sysdata/00010032/00000000 0:/pit/friendsave.bin
|
|
cp -w -o -s -n 1:/data/$[SYSID0]/sysdata/0001000f/00000000 0:/pit/seedsave.bin
|
|
cp -w -o -s -n 1:/data/$[SYSID0]/sysdata/00010022/00000000 0:/pit/activitylog.bin
|
|
|
|
# Attempt to copy system app sysdata
|
|
find -o -s 1:/data/$[SYSID0]/sysdata/000202?8 MIIPLAZA
|
|
set MIIPLAZA $[MIIPLAZA]/00000000
|
|
cp -w -o -s -n $[MIIPLAZA] 0:/pit/miiplaza.bin
|
|
find -o -s 1:/data/$[SYSID0]/sysdata/000202?d FACERAIDERS
|
|
set FACERAIDERS $[FACERAIDERS]/00000000
|
|
cp -w -o -s -n $[FACERAIDERS] 0:/pit/faceraiders.bin
|
|
find -o -s 1:/data/$[SYSID0]/sysdata/000202?e ARGAMES
|
|
set ARGAMES $[ARGAMES]/00000000
|
|
cp -w -o -s -n $[ARGAMES] 0:/pit/argames.bin
|
|
|
|
# Attempt to copy extdata files to SD
|
|
cp -w -o -s -n 1:/data/$[SYSID0]/extdata/00048000/f0000001 0:/pit/01 # Photos
|
|
cp -w -o -s -n 1:/data/$[SYSID0]/extdata/00048000/f0000002 0:/pit/02 # Sounds
|
|
cp -w -o -s -n 1:/data/$[SYSID0]/extdata/00048000/f000000b 0:/pit/0b # MiiMaker, Game Coins, etc.
|
|
|
|
# Overwrite CTRNAND with CTRTransfer image and then restore system uniques
|
|
set ERRORMSG "Overwriting CTRNAND with image failed."
|
|
cp -n -w $[IMAGE] S:/ctrnand_full.bin
|
|
set ERRORMSG "Restoring LocalFriendCodeSeed_B failed."
|
|
cp -n -w $[SEED] 1:/rw/sys/LocalFriendCodeSeed_B
|
|
set ERRORMSG "Restoring SecureInfo_A failed."
|
|
cp -n -w $[SECINFO] 1:/rw/sys/SecureInfo_A
|
|
set ERRORMSG "Restoring HWCAL0.dat failed."
|
|
cp -n -w $[HWCAL0] 1:/ro/sys/HWCAL0.dat
|
|
set ERRORMSG "Restoring HWCAL1.dat failed."
|
|
cp -n -w $[HWCAL1] 1:/ro/sys/HWCAL1.dat
|
|
set ERRORMSG "Restoring movable.sed failed."
|
|
cp -n -w $[MOVABLE] 1:/private/movable.sed
|
|
|
|
# Create SecureInfo_C if there's a region difference between SecureInfo_A and CVer
|
|
set ERRORMSG ""
|
|
if find 1:/title/000400db/00017202 NULL
|
|
set CVREG 00
|
|
elif find 1:/title/000400db/00017302 NULL
|
|
set CVREG 01
|
|
elif find 1:/title/000400db/00017102 NULL
|
|
set CVREG 02
|
|
elif find 1:/title/000400db/00017402 NULL
|
|
set CVREG 04
|
|
elif find 1:/title/000400db/00017502 NULL
|
|
set CVREG 05
|
|
elif find 1:/title/000400db/00017602 NULL
|
|
set CVREG 06
|
|
else
|
|
echo "The CVer title does not exist.\nYour CTRTransfer image somehow corrupted itself after injection.\n \nPress (A) to shut down, then please ask\nfor help in the Nintendo Homebrew Discord."
|
|
poweroff
|
|
end
|
|
fget 1:/rw/sys/SecureInfo_A@100:1 SIREG
|
|
|
|
if chk -u $[CVREG] $[SIREG]
|
|
cp -w -o -s -n 1:/rw/sys/SecureInfo_A 1:/rw/sys/SecureInfo_C
|
|
fset 1:/rw/sys/SecureInfo_C@100:1 $[CVREG]
|
|
end
|
|
|
|
|
|
# Restore backed-up system data if agreed to earlier
|
|
if chk $[OPTRESTORE] 1
|
|
cp -w -o -s -n 0:/pit/seedsave.bin 1:/data/$[SYSID0]/sysdata/0001000f/00000000
|
|
cp -w -o -s -n 0:/pit/configsave.bin 1:/data/$[SYSID0]/sysdata/00010017/00000000
|
|
cp -w -o -s -n 0:/pit/friendsave.bin 1:/data/$[SYSID0]/sysdata/00010032/00000000
|
|
cp -w -o -s -n 0:/pit/activitylog.bin 1:/data/$[SYSID0]/sysdata/00010022/00000000
|
|
|
|
# Restore system app sysdata
|
|
if chk $[CVREG] 00
|
|
set CHR 0
|
|
elif chk $[CVREG] 01
|
|
set CHR 1
|
|
elif chk $[CVREG] 02
|
|
set CHR 2
|
|
elif chk $[CVREG] 04
|
|
set CHR 6
|
|
elif chk $[CVREG] 05
|
|
set CHR 7
|
|
elif chk $[CVREG] 06
|
|
set CHR 8
|
|
end
|
|
cp -w -o -s -n 0:/pit/miiplaza.bin 1:/data/$[SYSID0]/sysdata/000202$[CHR]8/00000000
|
|
cp -w -o -s -n 0:/pit/faceraiders.bin 1:/data/$[SYSID0]/sysdata/000202$[CHR]d/00000000
|
|
cp -w -o -s -n 0:/pit/argames.bin 1:/data/$[SYSID0]/sysdata/000202$[CHR]e/00000000
|
|
|
|
# Restore shared extdata
|
|
cp -w -o -s -n 0:/pit/01 1:/data/$[SYSID0]/extdata/00048000/f0000001 # Photos
|
|
cp -w -o -s -n 0:/pit/02 1:/data/$[SYSID0]/extdata/00048000/f0000002 # Sounds
|
|
cp -w -o -s -n 0:/pit/0b 1:/data/$[SYSID0]/extdata/00048000/f000000b # MiiMaker, Game Coins, etc.
|
|
end
|
|
|
|
# Fix SYSNAND CTRNAND CMACs
|
|
set ERRORMSG "Failed to fix 1:/dbs CMACs."
|
|
fixcmac 1:/dbs
|
|
set ERRORMSG "Failed to fix 1:/data CMACs."
|
|
fixcmac 1:/data
|
|
set ERRORMSG "Failed to fix 1:/private CMACs."
|
|
fixcmac 1:/private
|
|
|
|
# Wrap up
|
|
set ERRORMSG "Reboot canceled."
|
|
if chk $[OPTRESTORE] 1
|
|
ask "Manual CTRTransfer complete.\n \nPress (A) to remove backup files and reboot now."
|
|
else
|
|
ask "Manual CTRTransfer complete.\n \nPress (A) to reboot now."
|
|
end
|
|
if chk $[OPTRESTORE] 1
|
|
rm -o -s 0:/pit
|
|
end
|
|
rm -o -s 0:/gm9/scripts/manual_transfer.gm9
|
|
reboot
|