patchimage/script.d/common.sh

482 lines
10 KiB
Bash
Raw Normal View History

2013-06-15 19:33:43 +02:00
#!/bin/bash
setup_tools () {
if [[ $(uname -m) == "x86_64" ]]; then
SUFFIX=64
2013-06-15 19:33:43 +02:00
else
SUFFIX=32
fi
#if [[ $(which wit) ]]; then
2014-05-13 17:49:00 +02:00
# WIT=$(which wit)
#else
# WIT=${PATCHIMAGE_TOOLS_DIR}/wit.${SUFFIX}
#fi
WIT=${PATCHIMAGE_TOOLS_DIR}/wit.next
if [[ $(which applyppf3) ]]; then
PPF=$(which applyppf3)
else
PPF=${PATCHIMAGE_TOOLS_DIR}/applyppf3.${SUFFIX}
fi
if [[ $(which uips) ]]; then
IPS=$(which uips)
else
IPS=${PATCHIMAGE_TOOLS_DIR}/uips.${SUFFIX}
fi
if [[ $(which unp) ]]; then
UNP=$(which unp)
else
UNP=${PATCHIMAGE_TOOLS_DIR}/unp
2013-06-15 19:33:43 +02:00
fi
}
ask_game () {
2013-06-20 21:30:26 +02:00
echo -e \
"************************************************
2013-06-20 18:39:11 +02:00
patchimage.sh
2013-06-15 19:33:43 +02:00
Enter Letter for the Game you want to create:
A NewerSMB
2013-06-20 21:03:40 +02:00
B Newer Summer Sun
C AnotherSMB
D Newer: Holiday Special
E Cannon Super Mario Bros.
2013-07-02 20:20:20 +02:00
F Epic Super Bowser World
G Koopa Country
H New Super Mario Bros. 4
2013-07-07 09:42:41 +02:00
I New Super Mario Bros. Wii Retro Remix
J Super Mario: Mushroom Adventure PLUS - Winter Moon
K NSMBW3: The Final Levels
L Super Mario Vacation
2013-10-12 10:37:29 +02:00
M Awesomer Super Luigi Mini
2013-06-22 19:30:30 +02:00
2014-05-13 17:49:00 +02:00
N Wiimfi Patcher. Patch Mario Kart to use Wiimm's server
O Wiimfi Patcher. Patch WFC games to use Wiimm's server (exp)
2014-05-11 19:26:58 +02:00
1 The Legend of Zelda: Parallel Worlds
2013-06-20 21:03:40 +02:00
"
2013-06-15 19:33:43 +02:00
read GAME
}
download_soundtrack () {
2014-05-11 21:57:19 +02:00
if [[ ${SOUNDTRACK_LINK} ]]; then
[[ ! -d ${PATCHIMAGE_AUDIO_DIR} ]] && mkdir -p ${PATCHIMAGE_AUDIO_DIR}
wget --no-check-certificate "${SOUNDTRACK_LINK}" -O "${PATCHIMAGE_AUDIO_DIR}"/${SOUNDTRACK_ZIP} || exit 57
echo -e "\n >>> soundtrack saved to\n >>> ${PATCHIMAGE_AUDIO_DIR}/${SOUNDTRACK_ZIP}"
else
echo -e "no soundtrack for ${GAME} available."
fi
}
download_banner () {
if [[ ${PATCHIMAGE_BANNER_DOWNLOAD} == "TRUE" ]]; then
if [[ ${CUSTOM_BANNER} ]]; then
if [[ ! -f "${PATCHIMAGE_RIIVOLUTION_DIR}"/${GAMEID}-custom-banner.bnr ]]; then
2013-10-12 10:37:29 +02:00
wget --no-check-certificate "${CUSTOM_BANNER}" -O "${PATCHIMAGE_RIIVOLUTION_DIR}"/${GAMEID}-custom-banner.bnr__tmp || exit 57
mv "${PATCHIMAGE_RIIVOLUTION_DIR}"/${GAMEID}-custom-banner.bnr__tmp "${PATCHIMAGE_RIIVOLUTION_DIR}"/${GAMEID}-custom-banner.bnr
fi
BANNER="${PATCHIMAGE_RIIVOLUTION_DIR}"/${GAMEID}-custom-banner.bnr
else
2013-10-12 10:37:29 +02:00
echo "*** >> no custom banner available"
fi
fi
}
nsmbw_version () {
if [[ -f ${WORKDIR}/files/COPYDATE_LAST_2009-10-03_232911 ]]; then
VERSION=EURv1
REG_LETTER=P
elif [[ -f ${WORKDIR}/files/COPYDATE_LAST_2010-01-05_152101 ]]; then
VERSION=EURv2
REG_LETTER=P
elif [[ -f ${WORKDIR}/files/COPYDATE_LAST_2009-10-03_232303 ]]; then
VERSION=USAv1
REG_LETTER=E
elif [[ -f ${WORKDIR}/files/COPYDATE_LAST_2010-01-05_143554 ]]; then
VERSION=USAv2
REG_LETTER=E
elif [[ -f ${WORKDIR}/files/COPYDATE_LAST_2009-10-03_231655 ]]; then
VERSION=JPNv1
REG_LETTER=J
elif [[ ! ${VERSION} ]]; then
echo -e "please specify your games version using --version={EURv1,EURv2,USAv1,USAv2,JPNv1}"
2013-10-12 10:37:29 +02:00
exit 27
fi
2013-10-12 10:37:29 +02:00
echo "*** >> status: ${VERSION}"
}
apply_banner () {
if [[ ${BANNER} != "" ]]; then
if [[ -e ${BANNER} ]]; then
cp "${BANNER}" "${BANNER_LOCATION}"
else
echo "specified banner ${BANNER} does not exist, not modifying"
fi
fi
}
2013-10-12 10:37:29 +02:00
check_directories () {
if [[ ! -d ${PATCHIMAGE_RIIVOLUTION_DIR} ]]; then
mkdir -p ${PATCHIMAGE_RIIVOLUTION_DIR}
fi
if [[ ! -d ${PATCHIMAGE_WBFS_DIR} ]]; then
mkdir -p ${PATCHIMAGE_WBFS_DIR}
fi
if [[ ! -d ${PATCHIMAGE_GAME_DIR} ]]; then
mkdir -p ${PATCHIMAGE_GAME_DIR}
fi
if [[ ! -d ${PATCHIMAGE_AUDIO_DIR} ]]; then
mkdir -p ${PATCHIMAGE_AUDIO_DIR}
fi
2014-05-13 17:49:00 +02:00
if [[ ! -d ${PATCHIMAGE_COVER_DIR} ]]; then
mkdir -p ${PATCHIMAGE_COVER_DIR}
fi
2013-10-12 10:37:29 +02:00
}
2013-06-15 19:33:43 +02:00
check_input_image () {
2013-10-12 10:37:29 +02:00
x=0
2013-06-15 19:33:43 +02:00
if [[ ! ${IMAGE} ]]; then
if [[ -f BASE.wbfs ]]; then
2013-10-12 10:37:29 +02:00
x=1
IMAGE=BASE.wbfs
elif [[ -f BASE.iso ]]; then
2013-10-12 10:37:29 +02:00
x=1
IMAGE=BASE.iso
2013-06-15 19:33:43 +02:00
fi
fi
2013-10-12 10:37:29 +02:00
echo "*** >> status: ${x}"
2013-06-15 19:33:43 +02:00
}
check_input_image_nsmb () {
2013-10-12 10:37:29 +02:00
x=0
if [[ ! ${IMAGE} ]]; then
if test -f SMN?01.wbfs; then
2013-10-12 10:37:29 +02:00
x=1
IMAGE=SMN?01.wbfs
elif test -f SMN?01.iso; then
2013-10-12 10:37:29 +02:00
x=2
IMAGE=SMN?01.iso
elif test -f ${PATCHIMAGE_WBFS_DIR}/SMN?01.iso; then
2013-10-12 10:37:29 +02:00
x=3
IMAGE=${PATCHIMAGE_WBFS_DIR}/SMN?01.iso
elif test -f ${PATCHIMAGE_WBFS_DIR}/SMN?01.wbfs; then
2013-10-12 10:37:29 +02:00
x=4
IMAGE=${PATCHIMAGE_WBFS_DIR}/SMN?01.wbfs
else
echo -e "please specify image to use with --iso=<path>"
2013-10-12 10:37:29 +02:00
exit 15
fi
fi
2013-10-12 10:37:29 +02:00
echo "*** >> status: ${x}"
}
2014-05-11 19:26:58 +02:00
check_input_image_mkwiimm () {
x=0
if [[ ! ${IMAGE} ]]; then
if test -f RMC?01.wbfs; then
x=1
IMAGE=RMC?01.wbfs
elif test -f RMC?01.iso; then
x=2
IMAGE=RMC?01.iso
elif test -f ${PATCHIMAGE_WBFS_DIR}/RMC?01.iso; then
x=3
IMAGE=${PATCHIMAGE_WBFS_DIR}/RMC?01.iso
elif test -f ${PATCHIMAGE_WBFS_DIR}/RMC?01.wbfs; then
x=4
IMAGE=${PATCHIMAGE_WBFS_DIR}/RMC?01.wbfs
else
echo -e "please specify image to use with --iso=<path>"
exit 15
fi
fi
echo "*** >> status: ${x}"
}
2014-05-11 21:57:19 +02:00
show_mkwiimm_db () {
ID=${1:4:2}
[[ ${ID} == [0-9][0-9] ]] && gawk -F \: "/^${ID}/"'{print $2}' \
< ${PATCHIMAGE_SCRIPT_DIR}/mkwiimm.db || echo "** Unknown **"
}
ask_input_image_mkwiimm () {
echo "Choose Mario Kart Wii Image to wiimmfi
ALL patch all images"
for image in ${1}/RMC???.{iso,wbfs}; do
if [[ -e ${image} ]]; then
echo " ${image##*/} $(show_mkwiimm_db ${image##*/})"
fi
done
echo ""
}
show_titles_db () {
ID=${1/.*}
gawk -F \: "/^${ID}/"'{print $2}' \
< ${PATCHIMAGE_SCRIPT_DIR}/titles.db || echo "** Unknown **"
}
2014-05-13 17:49:00 +02:00
ask_input_image_wiimmfi () {
echo "Choose Wii Game Image to wiimmfi"
2014-05-13 18:20:28 +02:00
for image in ${1}/*.{iso,wbfs}; do
2014-05-13 17:49:00 +02:00
if [[ -e ${image} && ! ${image} == "*/RMC*" ]]; then
echo " ${image##*/} $(show_titles_db ${image##*/})"
2014-05-13 17:49:00 +02:00
fi
done
echo ""
}
2013-06-15 19:33:43 +02:00
check_riivolution_patch () {
2013-10-12 10:37:29 +02:00
x=0
if [[ ! -d ${RIIVOLUTION_DIR} ]]; then
2013-10-12 10:37:29 +02:00
x=1
if [[ -f "${PWD}/${RIIVOLUTION_DIR}" ]]; then
echo "*** >> unpacking"
x=2
${UNP} "${PWD}/${RIIVOLUTION_ZIP}" >/dev/null || exit 63
elif [[ -f "${PATCHIMAGE_RIIVOLUTION_DIR}/${RIIVOLUTION_ZIP}" ]]; then
echo "*** >> unpacking"
x=3
${UNP} "${PATCHIMAGE_RIIVOLUTION_DIR}/${RIIVOLUTION_ZIP}" >/dev/null || exit 63
elif [[ ${PATCHIMAGE_RIIVOLUTION_DOWNLOAD} == "TRUE" ]]; then
2013-10-12 10:37:29 +02:00
x=4
if [[ ${DOWNLOAD_LINK} ]]; then
2013-10-12 10:37:29 +02:00
if [[ ! -f "${PATCHIMAGE_RIIVOLUTION_DIR}/${RIIVOLUTION_ZIP}" ]]; then
x=5
echo "*** >> downloading"
wget --no-check-certificate ${DOWNLOAD_LINK} -O "${PATCHIMAGE_RIIVOLUTION_DIR}/${RIIVOLUTION_ZIP}"__tmp >/dev/null || exit 57
mv "${PATCHIMAGE_RIIVOLUTION_DIR}/${RIIVOLUTION_ZIP}"__tmp "${PATCHIMAGE_RIIVOLUTION_DIR}/${RIIVOLUTION_ZIP}"
echo "*** >> unpacking"
${UNP} "${PATCHIMAGE_RIIVOLUTION_DIR}/${RIIVOLUTION_ZIP}" >/dev/null || exit 63
fi
else
echo "no download link for ${GAMENAME} available."
2013-10-12 10:37:29 +02:00
exit 21
fi
else
echo -e "please specify zip/rar to use with --riivolution=<path>"
2013-10-12 10:37:29 +02:00
exit 21
fi
2013-06-15 19:33:43 +02:00
fi
2013-10-12 10:37:29 +02:00
echo "*** >> status: ${x}"
2013-06-15 19:33:43 +02:00
}
2014-05-11 20:43:49 +02:00
download_covers () {
for path in cover cover3D coverfull disc disccustom; do
2014-05-11 21:57:19 +02:00
wget -O ${PATCHIMAGE_COVER_DIR}/${1}_${path}.png \
http://art.gametdb.com/wii/${path}/EN/${1}.png &>/dev/null \
|| ( echo "Cover (${path}) does not exists for gameid ${1}." && \
rm ${PATCHIMAGE_COVER_DIR}/${1}_${path}.png )
2014-05-11 20:43:49 +02:00
done
}
2013-06-15 19:33:43 +02:00
optparse () {
xcount=0
pcount=$#
while [[ $xcount -lt $pcount ]]; do
case $1 in
--iso* )
ISO_PATH=${1/*=}
ISO_EXT=${ISO_PATH//*./}
if [[ -e "${ISO_PATH}" ]]; then
ln -sf "${ISO_PATH}" BASE.${ISO_EXT}
IMAGE=BASE.${ISO_EXT}
2013-06-15 19:33:43 +02:00
else
echo -e "ISO not found"
2013-10-12 10:37:29 +02:00
exit 15
2013-06-15 19:33:43 +02:00
fi
;;
--rom* )
ROM_PATH=${1/*=}
ROM_EXT=${ROM_PATH//*./}
if [[ -e "${ROM_PATH}" ]]; then
ln -sf "${ROM_PATH}" BASE.${ROM_EXT}
IMAGE=BASE.${ROM_EXT}
else
echo -e "ROM not found"
2013-10-12 10:37:29 +02:00
exit 15
fi
;;
2013-06-20 18:50:02 +02:00
--riivolution* )
2013-06-15 19:33:43 +02:00
RIIVOLUTION=${1/*=}
if [[ -e "${RIIVOLUTION}" ]]; then
${UNP} "${RIIVOLUTION}" >/dev/null
2013-06-15 19:33:43 +02:00
else
echo -e "Riivolution patch ${RIIVOLUTION} not found."
2013-10-12 10:37:29 +02:00
exit 21
2013-06-15 19:33:43 +02:00
fi
;;
--patch* )
PATCH=${1/*=}
if [[ -e "${PATCH}" ]]; then
${UNP} "${PATCH}" >/dev/null
else
echo -e "PATCH patch ${PATCH} not found."
2013-10-12 10:37:29 +02:00
exit 21
fi
;;
2013-06-15 19:33:43 +02:00
--customid* )
CUSTOMID=${1/*=}
if [[ ${#CUSTOMID} != 6 ]]; then
echo -e "CustomID ${CUSTOMID} needs to have 6 digits"
2013-10-12 10:37:29 +02:00
exit 39
2013-06-15 19:33:43 +02:00
fi
;;
--download )
PATCHIMAGE_RIIVOLUTION_DOWNLOAD=TRUE
;;
--soundtrack )
2014-05-11 21:57:19 +02:00
PATCHIMAGE_SOUNDTRACK_DOWNLOAD=TRUE
;;
--only-soundtrack )
PATCHIMAGE_SOUNDTRACK_DOWNLOAD=TRUE
ONLY_SOUNDTRACK=TRUE
;;
2013-06-15 19:33:43 +02:00
--version=* )
VERSION=${1/*=}
case ${VERSION} in
EURv1 )
REG_LETTER=P
;;
EURv2 )
REG_LETTER=P
;;
USAv1 )
REG_LETTER=E
;;
USAv2 )
REG_LETTER=E
;;
JPNv1 )
REG_LETTER=J
;;
* )
echo -e "unrecognized game version: ${VERSION}"
2013-10-12 10:37:29 +02:00
exit 27
2013-06-15 19:33:43 +02:00
;;
esac
;;
--sharesave )
PATCHIMAGE_SHARE_SAVE=TRUE
2013-06-15 19:33:43 +02:00
;;
--game* )
GAME=${1/*=}
;;
2014-05-11 21:57:19 +02:00
--covers* )
PATCHIMAGE_COVER_DOWNLOAD=TRUE
;;
--only-covers* )
PATCHIMAGE_COVER_DOWNLOAD=TRUE
download_covers ${1/*=}
exit 0
;;
--banner=* )
BANNER=${1/*=}
BANNER_EXT=${BANNER//*./}
if [[ ${BANNER_EXT} != "bnr" ]]; then
echo "given banner (${BANNER}) is not a .bnr file!"
2013-10-12 10:37:29 +02:00
exit 33
fi
;;
--download-banner )
PATCHIMAGE_BANNER_DOWNLOAD=TRUE
;;
2013-06-15 19:33:43 +02:00
"" | --help )
2014-05-11 21:57:19 +02:00
echo -e "patchimage 4.91 (2014-05-10)
2013-10-12 10:37:29 +02:00
2014-05-11 21:57:19 +02:00
(c) 2013-2014 Christopher Roy Bratusek <nano@jpberlin.de>
2013-10-12 10:37:29 +02:00
patchimage creates wbfs images from riivolution patches.
--game=<gamename/gameletter> | specify game you want to create
--iso/--rom=/home/test/<Image> | specify which ISO/ROM to use for building
--riivolution/--patch=<Patch> | specify path to Riivolution/Patch files
2013-06-15 19:33:43 +02:00
--version=EURv1,EURv2,USAv1,USAv2,JPNv1 | specify your game version
--customdid=SMNP02 | specify a custom ID to use for the game
--sharesave | let modified game share savegame with original game
2013-06-20 18:15:42 +02:00
--download | download riivolution patchfiles
2014-05-11 21:57:19 +02:00
--soundtrack | download soundtrack (if available)
--only-soundtrack | download soundtrack only (if available) and exit
--covers | download covers (if available)
--only-covers=SMNP02 | download covers only (if available)
--banner=<banner.bnr> | use a custom banner (riivolution games)
--download-banner | download a custom banner (if available)"
2013-06-15 19:33:43 +02:00
exit 0
;;
esac
shift
xcount=$(($xcount+1))
done
}