Skip to content

Instantly share code, notes, and snippets.

@willfaust
Last active April 16, 2024 11:46
Show Gist options
  • Save willfaust/fb90dec409b8918290012031f09a78ef to your computer and use it in GitHub Desktop.
Save willfaust/fb90dec409b8918290012031f09a78ef to your computer and use it in GitHub Desktop.

NSP Update Patcher

Instructions:

  1. Place your base NSP, update NSP, and prod.keys into a new folder
  2. Open a terminal and cd into this folder
  3. Download and run script:
curl -o nsp_update_patcher.sh https://gist.githubusercontent.com/willfaust/fb90dec409b8918290012031f09a78ef/raw/9abf2e1b020203aec0051fad99524f8269cb1edd/nsp_update_patcher.sh && chmod +x nsp_update_patcher.sh && ./nsp_update_patcher.sh

Notice:

  • This script assumes that the larger NSP is the base, and the smaller NSP is the update
  • Your free drive space should be at least three times the size of your base and update NSPs combined
  • You must have your product keys dumped from your switch

Credit to hactool and hacPack

# find base and update NSPs
basensp=$(ls -S *.nsp | head -1)
updatensp=$(ls -Sr *.nsp | head -1)
# clone and build hactool and hacpack
git clone https://github.com/SciresM/hactool
mv hactool hactoolsrc
cd hactoolsrc
mv config.mk.template config.mk
make
mv hactool ..
cd ..
rm -rf hactoolsrc
git clone https://github.com/The-4n/hacPack
mv hacPack hacpacksrc
cd hacpacksrc
mv config.mk.template config.mk
make
mv hacpack ..
cd ..
rm -rf hacpacksrc
mkdir -p ~/.switch
cp prod.keys ~/.switch
touch ~/.switch/title.keys
mkdir temp hactool_out
cd hactool_out
# derive title keys from base and update NSPs
derivekey () {
title=$(xxd *.tik | grep -oP -m 1 "(?<=2a0: ).{39}" | sed 's/ //g')
key=$(xxd *.tik | grep -oP -m 1 "(?<=180: ).{39}" | sed 's/ //g')
sed -i "/$title=$key/d" ~/.switch/title.keys
echo $title=$key >> ~/.switch/title.keys
}
../hactool -t pfs0 "../$basensp" --outdir .
derivekey
rm *
../hactool -t pfs0 "../$updatensp" --outdir .
derivekey
rm *
# extract base NSP and move program NCA to temp dir
../hactool -t pfs0 "../$basensp" --outdir .
for i in *.nca
do
type=$(../hactool $i | grep -oP "(?<=Content Type:\s{23}).*")
if [ $type == "Program" ]; then
basenca=$i
mv $i ../temp
fi
done
rm *
# extract update NSP and move program & control NCAs to temp dir
../hactool -t pfs0 "../$updatensp" --outdir .
for i in *.nca
do
type=$(../hactool $i | grep -oP "(?<=Content Type:\s{23}).*")
if [ $type == "Program" ]; then
updatenca=$i
mv $i ../temp
elif [ $type == "Control" ]; then
controlnca=$i
mv $i ../temp
fi
done
rm *
cd ..
rm -rf hactool_out
mv hactool temp/
mv hacpack temp/
cd temp
# parse Title ID from base program NCA
titleid=$(./hactool $basenca | grep -oP "(?<=Title ID:\s{27}).*")
# extract base and update NCAs into romfs end exefs
mkdir exefs romfs
./hactool --basenca="$basenca" $updatenca --romfsdir="romfs" --exefsdir="exefs"
rm $basenca $updatenca
# pack romfs and exefs into one NCA
mkdir nca
./hacpack --type="nca" --ncatype="program" --plaintext --exefsdir="exefs" --romfsdir="romfs" --titleid="$titleid" --outdir="nca"
patchednca=$(ls nca)
mv $controlnca nca
rm -rf exefs romfs
# generate meta NCA from patched NCA and control NCA
./hacpack --type="nca" --ncatype="meta" --titletype="application" --programnca="nca/$patchednca" --controlnca="nca/$controlnca" --titleid="$titleid" --outdir="nca"
# pack all three NCAs into an NSP
mkdir nsp
./hacpack --type="nsp" --ncadir="nca" --titleid="$titleid" --outdir="nsp"
cd ..
mv temp/nsp/$titleid.nsp ./$titleid[patched].nsp
rm -rf temp
@mamichini
Copy link

Error when running it, appears to be working, but then it starts displaying "Saving romfs..." "Failed to open romfs!" in a loop one behind the other, never ending, and it makes me terminate it with "Ctrl + C". I tried runing it with Sudo, using "Bash" instead of "./" and giving the .sh permission with "chmod +x". Any suggestion??

Pd: The game is South Park: The stick of truth, and the update is smaller than the base game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment