Skip to content

Instantly share code, notes, and snippets.

@swarzesherz
Last active August 29, 2015 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swarzesherz/cccc328d6718e9e1f896 to your computer and use it in GitHub Desktop.
Save swarzesherz/cccc328d6718e9e1f896 to your computer and use it in GitHub Desktop.
3ds to cia Batch by Katsu 2.00
#!/bin/bash
default='\033[0m'
green='\033[32m' #color a
blue='\033[34m' #color b
red='\033[91m' #color c
yellow='\033[33m' #color e
function quit {
echo -e "${default}"
exit
}
function fail {
echo -e "${yellow}
#######################################################
# #
# Drag n drop .3ds on batch file to start conversion! #
# #
#######################################################
"
quit
}
function notools {
echo -e "${red}
############################################################
# #
# Missing Tools - Please re-install 3ds_to_cia to fix it #
# XORPADS and .3ds needs to be inside 3ds_to_cia's folder! #
# #
############################################################
"
quit
}
function noxorpad {
cd for_sd
python ctrKeyGen.py "../${GameName}.3ds" &> /dev/null
echo -e "${yellow}
#######################################################################
# #
# Missing XORPADS, pleasy copy your files into 3ds_to_cia's directory #
# #
#######################################################################
"
quit
}
function no3ds {
echo -e "${yellow}
#################################################################
# #
# Missing 3ds, pleasy copy the game into 3ds_to_cia's directory #
# #
#################################################################
"
quit
}
function duplicate {
echo -e "${red}
#######################################################
# #
# GameFolder already exists, please check your files! #
# #
#######################################################
"
quit
}
function checkcia {
if [ ! -f "./${GameName}/cia/${GameName}.cia" ]
then
echo -e "${red}Failed to create \"${GameName}.cia\""
mv "./${GameName}/xorpads/"*.xorpad .
mv "./${GameName}/decrypted/"*.3ds .
rm -rf "./${GameName}"
quit
else
mkdir -p "./${GameName}/3ds"
mv "./${GameName}/decrypted/"*.3ds "./${GameName}/3ds"
rm -rf "./${GameName}/decrypted"
clear
echo -e "${green}
!!! Success to create \"${GameName}.cia\" !!!
STATUS:
Remove Region Lock : ${RRL}
Use own RSF : ${uor}
Use auto RSF : ${uar}
Use Original EXHEADER : ${uoe}
Firmware Spoof to 4.x : ${fst4}
Includes Manual : ${manual}
Includes Download Play : ${dlp}
Your file is ready in ${GameName}/cia
"
quit
fi
}
function reset {
export RRL=no
export uor=no
export uar=yes
export uoe=no
export fst4=no
export manual=no
export dlp=no
}
function start {
clear
echo -e "${green}
##################################################
# #
# 3ds to cia #
# Batch by Katsu 2.00 #
# #
##################################################
"
if [ $(find ./ -maxdepth 1 -name "*Manual.romfs.xorpad" 2>/dev/null | wc -l) -eq 0 ];then echo " (1) Remove Region Lock : ${RRL}";fi
if [ $(find ./ -maxdepth 1 -name "*Manual.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ];then export manual=yes; echo " (1) Remove Region Lock : ${RRL} *Manual detected*";fi
if [ $(find ./ -maxdepth 1 -name "*DownloadPlay.romfs.xorpad" 2>/dev/null | wc -l) -eq 0 ];then echo " (2) Use own RSF : ${uor}";fi
if [ $(find ./ -maxdepth 1 -name "*DownloadPlay.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ];then export dlp=yes; echo " (2) Use own RSF : ${uor} *DLP detected*";fi
echo " (3) Use auto RSF : ${uar}"
echo " (4) Use Original EXHEADER : ${uoe}"
echo " (5) Firmware Spoof to 4.x : ${fst4}"
if [ $(find ./ -maxdepth 1 -name "*exefs_7x.xorpad" 2>/dev/null | wc -l) -gt 0 ];then echo " 7.x";else echo "";fi
echo " (r) Reset all Values (q) Quit (s) Start"
echo "
Game: ${GameName}
##################################################
# #
# Thanks to everyone who #
# helped creating this #
# #
##################################################
"
echo -n "Make your choice and press s to start [1,2,3,4,5,s,r,q]?"
read option
case ${option} in
1)
export RRL=yes; start;;
2)
export uor=yes; export uar=no; export uoe=no; export fst4=no; start;;
3)
export uar=yes;export uor=no; export uoe=no; start;;
4)
export uoe=yes; export uar=yes; export uor=no; start;;
5)
export fst4=yes; export uor=no; export uar=yes; start;;
s)
letsgo;;
r)
reset; start;;
q)
quit;;
*)
start;;
esac
}
function letsgo {
echo -e "${blue}"
if [ $(find ./ -maxdepth 1 -name "*UpdateData.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ];then echo "Removing Update Data"; rm -rf *UpdateData.romfs.xorpad;fi
createproject
}
function createproject {
mkdir -p "${GameName}"/{xorpads,encrypted,decrypted,cia}
renameprojectfiles
}
function renameprojectfiles {
if [[ ( $(ls -1 exefs.xorpad 2>/dev/null | wc -l) -gt 0 || ( $(ls -1 exefs_norm.xorpad 2>/dev/null | wc -l) -gt 0 && $(ls -1 exefs_7x.xorpad 2>/dev/null | wc -l) -gt 0 ) ) && $(ls -1 exheader.xorpad 2>/dev/null | wc -l) -gt 0 && $(ls -1 romfs.xorpad 2>/dev/null | wc -l) -gt 0 ]]
then
movexorpad3ds
else
if [ $(find ./ -maxdepth 1 -name "*exefs_7x.xorpad" 2>/dev/null | wc -l) -eq 0 ];then mv *Main.exefs_norm.xorpad exefs.xorpad;fi
if [ $(find ./ -maxdepth 1 -name "*exefs_7x.xorpad" 2>/dev/null | wc -l) -gt 0 ];then mv *Main.exefs_7x.xorpad exefs_7x.xorpad;fi
if [ $(ls -1 exefs_7x.xorpad 2>/dev/null | wc -l) -gt 0 ];then mv -f *Main.exefs_norm.xorpad exefs_norm.xorpad;fi
if [ $(find ./ -maxdepth 1 -name "*Main.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ];then mv *Main.romfs.xorpad romfs.xorpad;fi
if [ $(find ./ -maxdepth 1 -name "*Main.exheader.xorpad" 2>/dev/null | wc -l) -gt 0 ];then mv *Main.exheader.xorpad exheader.xorpad;fi
movexorpad3ds
fi
}
function movexorpad3ds {
mv *.xorpad "./${GameName}/xorpads"
mv "./${GameName}.3ds" "./${GameName}/decrypted"
getencryptedbin
}
function getencryptedbin {
./tools/ctrtool -p --exheader="./${GameName}/encrypted/exheaderEncrypted.bin" --romfs="./${GameName}/encrypted/romfsEncrypted.bin" --exefs="./${GameName}/encrypted/exefsEncrypted.bin" --logo="./${GameName}/encrypted/logo.bin" "./${GameName}/decrypted/${GameName}.3ds"
if [ $(ls -1 "./${GameName}/xorpads/exefs_7x.xorpad" 2>/dev/null | wc -l) -gt 0 ]
then
python tools/MEX.py "./${GameName}/encrypted/exefsEncrypted.bin" "./${GameName}/xorpads/exefs_norm.xorpad" "./${GameName}/xorpads/exefs_7x.xorpad" "./${GameName}/xorpads/exefs.xorpad"
echo "7.x EXEFS present"
fi
echo "Created Encrypted bins"
xor
}
function xor {
./tools/padxorer "./${GameName}/encrypted/romfsEncrypted.bin" "./${GameName}/xorpads/romfs.xorpad"
./tools/padxorer "./${GameName}/encrypted/exheaderEncrypted.bin" "./${GameName}/xorpads/exheader.xorpad"
./tools/padxorer "./${GameName}/encrypted/exefsEncrypted.bin" "./${GameName}/xorpads/exefs.xorpad"
export xor=false
if [[ $(ls -1 "./${GameName}/encrypted/exefsEncrypted.bin.out" 2>/dev/null | wc -l) -gt 0 && $(ls -1 "./${GameName}/encrypted/exheaderEncrypted.bin.out" 2>/dev/null | wc -l) -gt 0 && $(ls -1 "./${GameName}/encrypted/romfsEncrypted.bin.out" 2>/dev/null | wc -l) -gt 0 ]]
then
echo "xorpads xored"
mv "./${GameName}/encrypted/"*.out "./${GameName}/decrypted"
mv "./${GameName}/encrypted/logo.bin" "./${GameName}/decrypted"
mv "./${GameName}/decrypted/romfsEncrypted.bin.out" "./${GameName}/decrypted/romfs.bin"
mv "./${GameName}/decrypted/exefsEncrypted.bin.out" "./${GameName}/decrypted/exefs.bin"
mv "./${GameName}/decrypted/exheaderEncrypted.bin.out" "./${GameName}/decrypted/exheader.bin"
removeencrypted
else
echo -e "${red}xorpads failed"
checkcia
fi
}
function removeencrypted {
rm -rf "./${GameName}/encrypted"
echo "Encrypted bin removed"
createexheader
}
function createexheader {
./tools/ctrtool -t exheader "./${GameName}/decrypted/exheader.bin" > "./${GameName}/decrypted/exheader.txt"
extractexefs
}
function extractexefs {
echo -e "${blue}"
./tools/ctrtool -t exefs --exefsdir="./${GameName}/decrypted" "./${GameName}/decrypted/exefs.bin" --decompresscode
echo "
Created code / banner / icon
If Secion Name is unreadable, something went wrong!
It should be something like - .code banner icon logo
"
regionpatch
}
function regionpatch {
if [[ "$RRL" == "yes" ]]
then
cd "./${GameName}/decrypted"
python "../../tools/region.py"
cd ../..
echo "Region patched"
fi
checkmanual
}
function checkmanual {
echo -e "${blue}\n\n"
if [[ $(find "./${GameName}/xorpads" -maxdepth 1 -name "*Manual.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 || $(find "./${GameName}/xorpads" -maxdepth 1 -name "*DownloadPlay.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ]]
then
./tools/rom_tool --extract="./${GameName}/decrypted" "./${GameName}/decrypted/${GameName}.3ds"
fi
if [ $(find "./${GameName}/xorpads" -maxdepth 1 -name "*Manual.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ]; then mv "./${GameName}/decrypted/"*MANUAL*.cfa "./${GameName}/decrypted/manual.cfa";fi
if [ $(find "./${GameName}/xorpads" -maxdepth 1 -name "*DownloadPlay.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ]; then mv "./${GameName}/decrypted/"*DLP.cfa "./${GameName}/decrypted/dlp.cfa";fi
rm -f "./${GameName}/decrypted/"*APPDATA.cxi
rm -f "./${GameName}/decrypted/"*UPDATEDATA.cfa
echo "Removed unneeded Data"
creatersf
useautorsf
}
function creatersf {
if [[ "${uor}" == "yes" ]]
then
echo -e "${green}"
cp tools/sample-rsf.txt "./${GameName}/decrypted/${GameName}.rsf"
infoexheader
fi
}
function infoexheader {
echo "
###########################################################
# #
# Please edit your .rsf now or creating cia might fail! #
# #
# As reference you can open exheader.txt to fill .rsf #
# #
# or copy now a premade .rsf into 3ds to cia's direcory #
# #
# Press \"d\" to display EXHEADER.TXT #
# Press \"r\" to display Rom Tool Info #
# #
###########################################################
Edit \"${GameName}/decrypted/${GameName}.rsf!!!\"
"
echo -n "Is your .rsf ready (y)es (r)om_tool (d)isplay?"
read option
case ${option} in
y)
build;;
r)
clear; ./tools/rom_tool -i "./${GameName}/decrypted/${GameName}.3ds"; echo "\nScroll up to check!\n"; infoexheader;;
d)
clear; cat "./${GameName}/decrypted/exheader.txt"; echo "\nScroll up to check!\n"; infoexheader;;
*)
infoexheader
esac
}
function useautorsf {
if [[ "${uar}" == "yes" ]]
then
echo -e "${blue}"
cp tools/rom.rsf "./${GameName}/decrypted/${GameName}.rsf"
cd "./${GameName}/decrypted"
if [[ "${fst4}" == "yes" ]];then python ../../tools/rsfgen.py "./${GameName}" -spoof;else python ../../tools/rsfgen.py "./${GameName}";fi
cd ../..
if [[ "${uoe}" == "yes" ]];then exinjector;fi
build
fi
}
function exinjector {
if [[ "${uoe}" == "yes" ]]
then
echo "Creating \"${GameName}\".cxi"
echo "Please wait..."
./tools/makerom -f cxi -o "./${GameName}/decrypted/${GameName}.cxi" -rsf "./${GameName}/decrypted/${GameName}.rsf" -target t -desc ecapp:3 -exheader "./${GameName}/decrypted/exheader.bin" -exefslogo -code "./${GameName}/decrypted/code.bin" -romfs "./${GameName}/decrypted/romfs.bin" -icon "./${GameName}/decrypted/icon.bin" -banner "./${GameName}/decrypted/banner.bin"
echo "Inserting original exheader"
python tools/ExInjector.py -rom "./${GameName}/decrypted/${GameName}.cxi" -exheader "./${GameName}/decrypted/exheader.bin" -sd
echo "\nAlmost ready\n"
echo "Creating \"${GameName}\".cia"
echo "Please wait..."
if [ $(find "./${GameName}/xorpads" -maxdepth 1 -name "*DownloadPlay.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ]; then dlpex;fi
if [ $(ls -1 "./${GameName}/decrypted/manual.cfa" 2>/dev/null | wc -l) -gt 0 ]
then
echo "Manual will be included"
./tools/makerom -f cia -target t -content "./${GameName}/decrypted/${GameName}.cxi":0:0 -content "./${GameName}/decrypted/manual.cfa":1:1 -o "./${GameName}/cia/${GameName}.cia"
else
./tools/makerom -f cia -target t -content "./${GameName}/decrypted/${GameName}.cxi":0:0 -o "./${GameName}/cia/${GameName}.cia"
fi
echo -e "${yellow}"
echo "\nYou can ignore \" CIA will not be encrypted \" message!\n"
echo -e "${blue}"
checkcia
fi
}
function dlpex {
echo "DownloadPlay will be included"
if [ $(ls -1 "./${GameName}/decrypted/manual.cfa" 2>/dev/null | wc -l) -gt 0 ]
then
echo "Manual will be included"
./tools/makerom -f cia -target t -content "./${GameName}/decrypted/${GameName}.cxi":0:0 -content "./${GameName}/decrypted/manual.cfa":1:1 -content "./${GameName}/decrypted/dlp.cfa":2:2 -o "./${GameName}/cia/${GameName}.cia"
else
./tools/makerom -f cia -target t -content "./${GameName}/decrypted/${GameName}.cxi":0:0 -content "./${GameName}/decrypted/dlp.cfa":2:2 -o "./${GameName}/cia/${GameName}.cia"
fi
echo -e "${yellow}"
echo "\nYou can ignore \" CIA will not be encrypted \" message!\n"
echo -e "${blue}"
checkcia
}
function build {
echo "Creating \"${GameName}\".cia"
echo "Please wait..."
if [ $(find "./${GameName}/xorpads" -maxdepth 1 -name "*DownloadPlay.romfs.xorpad" 2>/dev/null | wc -l) -gt 0 ];then dlpbuild; fi
if [ $(ls -1 "./${GameName}/decrypted/manual.cfa" 2>/dev/null | wc -l) -gt 0 ]
then
echo "Manual will be included"
./tools/makerom -f cia -rsf "./${GameName}/decrypted/${GameName}.rsf" -target t -desc app:4 -o "./${GameName}/cia/${GameName}.cia" -icon "./${GameName}/decrypted/icon.bin" -banner "./${GameName}/decrypted/banner.bin" -exefslogo -code "./${GameName}/decrypted/code.bin" -exheader "./${GameName}/decrypted/exheader.bin" -romfs "./${GameName}/decrypted/romfs.bin" -content "./${GameName}/decrypted/manual.cfa":1:1
else
./tools/makerom -f cia -rsf "./${GameName}/decrypted/${GameName}.rsf" -target t -desc app:4 -o "./${GameName}/cia/${GameName}.cia" -icon "./${GameName}/decrypted/icon.bin" -banner "./${GameName}/decrypted/banner.bin" -exefslogo -code "./${GameName}/decrypted/code.bin" -exheader "./${GameName}/decrypted/exheader.bin" -romfs "./${GameName}/decrypted/romfs.bin"
fi
echo -e "${yellow}"
echo "\nYou can ignore \" CIA will not be encrypted \" message!\n"
echo -e "${blue}"
checkcia
}
function dlpbuild {
echo "DownloadPlay will be included"
if [ $(ls -1 "./${GameName}/decrypted/manual.cfa" 2>/dev/null | wc -l) -gt 0 ]
then
echo "Manual will be included"
./tools/makerom -f cia -rsf "./${GameName}/decrypted/${GameName}.rsf" -target t -desc app:4 -o "./${GameName}/cia/${GameName}.cia" -icon "./${GameName}/decrypted/icon.bin" -banner "./${GameName}/decrypted/banner.bin" -exefslogo -code "./${GameName}/decrypted/code.bin" -exheader "./${GameName}/decrypted/exheader.bin" -romfs "./${GameName}/decrypted/romfs.bin" -content "./${GameName}/decrypted/manual.cfa":1:1 -content "./${GameName}/decrypted/dlp.cfa":2:2
else
./tools/makerom -f cia -rsf "./${GameName}/decrypted/${GameName}.rsf" -target t -desc app:4 -o "./${GameName}/cia/${GameName}.cia" -icon "./${GameName}/decrypted/icon.bin" -banner "./${GameName}/decrypted/banner.bin" -exefslogo -code "./${GameName}/decrypted/code.bin" -exheader "./${GameName}/decrypted/exheader.bin" -romfs "./${GameName}/decrypted/romfs.bin" -content "./${GameName}/decrypted/dlp.cfa":2:2
fi
echo -e "${yellow}"
echo "\nYou can ignore \" CIA will not be encrypted \" message!\n"
echo -e "${blue}"
checkcia
}
GameName=${1%%.*}
if [ "${GameName}" = "" ];then fail;fi
if [ ! -d "./tools" ];then notools;fi
if [ ! -f "./tools/rsfgen.py" ];then notools;fi
if [ ! -f "./tools/ctrtool" ];then notools;fi
if [ ! -f "./tools/rom_tool" ];then notools;fi
if [ ! -f "./tools/makerom" ];then notools;fi
if [ ! -f "./tools/padxorer" ];then notools;fi
if [ ! -f "./tools/MEX.py" ];then notools;fi
if [ ! -f "./tools/ExInjector.py" ];then notools;fi
if [ ! -f "./tools/sample-rsf.txt" ];then notools;fi
if [ ! -f "./tools/rom.rsf" ];then notools;fi
if [ -f "./${GameName}.3dz" ];then mv "./${GameName}.3dz" "./${GameName}.3ds";fi
if [ ! -f "./${GameName}.3ds" ];then no3ds;fi
if [ $(find ./ -maxdepth 1 -name "*.xorpad" 2>/dev/null | wc -l) -eq 0 ];then noxorpad;fi
if [ -d "./${GameName}" ];then duplicate;fi
reset
start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment