#!/bin/bash
+PROGNAME="$(basename $0)"
+PWD=$(dirname $0)
+[ "$PWD" ] || PWD=$(pwd)
+PWD=$(cd $PWD; pwd)
+
# default values
-PROGNAME=$(basename $0)
+CACHE=$PWD/cache
+CONFIGS=$PWD/CONFIGS
KLICENSE="e4e54fd67c16c316f47829a30484d843"
-PS2CLASSIC=ps2classic/ps2classic
-PSNPACKAGE=psn_package_npdrm/psn_package_npdrm
+PS2CLASSIC=$PWD/ps2classic/ps2classic
+PSNPACKAGE=$PWD/psn_package_npdrm/psn_package_npdrm
+# FAT SLIM SUPER ULTRA
+MODEL="ULTRA"
+
+# formating functions
+function title () { echo -e "\033[0;1m$*\033[0;0m"; }
+function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
+function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
+function fail () { echo -e "\033[1;31m$*\033[0;0m"; exit 1; }
# defaut values
id=0
grep "^/[A-Z][A-Z][A-Z][A-Z]_[0-9][0-9][0-9]\.[0-9][0-9];" | \
sed 's,[/.],,g;s,_,-,;s,;.*,,')
[ "$serial" ] || { serial=$(printf "PS2U-1%04d" $id); let id++; }
-CID=${serial/-}
# store last value
echo > .$PROGNAME
[ -f jlist2.html ] || wget https://psxdatacenter.com/psx2/jlist2.html
[ -f plist2.html ] || wget https://psxdatacenter.com/psx2/plist2.html
[ -f ulist2.html ] || wget https://psxdatacenter.com/psx2/ulist2.html
- awk '/>'$1'</ {
+ awk '/>'$file'</ {
getline; gsub(/<[^<]*>/, "")
sub(/ /, " ")
gsub(/^[ \t]*/, "")
title=$(awk -F\; '"'$serial'" == $1 {print $2}' PS2-GAMEID-TITLE-MASTER.csv)
[ "$title" ] || title=$(basename "$file" | sed 's/ *(.*//')
+# create CID
+title "create CID"
+cid=2P0001-${serial/-}_00-$(echo ${title}0000111122223333 | \
+ tr '[a-z]' '[A-Z]' | \
+ sed 's/[^A-Z0-9]//g;s/\(................\).*$/\1/')
+
# main process
+title "description"
echo "File: '$file'"
echo "Serial: $serial"
echo "Title: '$title'"
+echo "CID: $cid"
-# skeleton
+# install skeleton
+title "install skeleton"
mkdir $serial
tar -C $serial -xzf skeleton.tgz
+[ -d $CACHE ] || mkdir $CACHE
# images:
# - ICON0.PNG 320x176
# - PIC0.PNG 1000x560
# - PIC1.PNG 1920x1080
-# cover
-wget https://psxdatacenter.com/psx2/images2/covers/$serial.jpg
-if [ -f $serial.jpg ]; then
- convert $serial.jpg tmp.png
- mogrify -resize 320x176 tmp.png
- mogrify -background transparent -gravity center -extent 320x176 tmp.png
- mv tmp.png $serial/ICON0.PNG
- rm $serial.jpg
+# get cover image
+title "get cover image"
+if [ -f $CACHE/$serial-ICON0.PNG ]; then
+ cp $CACHE/$serial-ICON0.PNG $serial/ICON0.PNG
+else
+ wget https://psxdatacenter.com/psx2/images2/covers/$serial.jpg
+ if [ -f $serial.jpg ]; then
+ convert $serial.jpg tmp.png
+ mogrify -resize 320x176 tmp.png
+ mogrify -background transparent -gravity center -extent 320x176 tmp.png
+ mv tmp.png $serial/ICON0.PNG
+ rm $serial.jpg
+ cp $serial/ICON0.PNG $CACHE/$serial-ICON0.PNG
+ else
+ warn "can't find cover"
+ fi
fi
-# screenshot
-touch .touch
-find $HOME/.config/PCSX2/snaps/ -type f | xargs rm .touch
-pcsx2 "$file"
-capture=$(find $HOME/.config/PCSX2/snaps/ -type f | sort)
-if [ "$capture" ]; then
- cp "$capture" tmp.png
- mogrify -scale 1000x560 tmp.png
- mogrify -background transparent -gravity center -extent 1000x560 tmp.png
- mv tmp.png $serial/PIC0.PNG
+# get screenshot
+title "get screenshot"
+if [ $CACHE/$serial-PIC0.PNG ]; then
+ cp $CACHE/$serial-PIC0.PNG $serial/PIC0.PNG
+else
+ touch .touch
+ find $HOME/.config/PCSX2/snaps/ -type f | xargs rm .touch
+ pcsx2 "$file"
+ capture=$(find $HOME/.config/PCSX2/snaps/ -type f | sort)
+ if [ "$capture" ]; then
+ cp "$capture" tmp.png
+ mogrify -scale 1000x560 tmp.png
+ mogrify -background transparent -gravity center -extent 1000x560 tmp.png
+ mv tmp.png $serial/PIC0.PNG
+ cp $serial/PIC0.PNG $CACHE/$serial-PIC0.PNG
+ else
+ warn "can't find screenshot"
+ fi
fi
+# create PARAM.SFO
+title "create PARAM.SFO"
# parameters
# - file: PARAM.SFO
-# 0x108: title
-# 0x188: CID
+# 0x120: title
+# 0x1a0: ${serial/-}
# - file: USRDIR/ISO.BIN.EDAT
-# 0x017: CID
-echo -n $title | xxd | xxd -r -s 0x108 - $serial/PARAM.SFO
-echo -n $CID | xxd | xxd -r -s 0x188 - $serial/PARAM.SFO
-echo -n $CID | xxd | xxd -r -s 0x17- $serial/USRDIR/ISO.BIN.EDAT
+# 0x017: ${serial/-}
+echo -n $title | xxd | xxd -r -s 0x120 - $serial/PARAM.SFO
+echo -n ${serial/-} | xxd | xxd -r -s 0x1a0 - $serial/PARAM.SFO
+echo -n ${serial/-} | xxd | xxd -r -s 0x17- $serial/USRDIR/ISO.BIN.EDAT
# generate key
+title "generate key"
dd bs=1 count=$(expr ${#KLICENSE} / 2) if=/dev/zero of=$serial/ps2.key
-echo "00000000 $KLICENSE" | xdd -r - > $serial/ps2.key
-
-# package config
-echo > $serial/package.conf << EOF
-Content-ID = $CID
+echo "00000000 $KLICENSE" | xxd -r - $serial/ps2.key
+
+# find config file
+title "find config file"
+confname=$(echo $serial.CONFIG | sed 's/-/_/;s/_\(...\)/_\1./')
+case "$MODEL" in
+ FAT)
+ config=$(cd $CONFIGS; find GX -name $confname | head -1)
+ ;;
+ SLIM|SUPER|ULTRA)
+ config=$(cd $CONFIGS; find CUSTOM SOFT NET -name $confname | head -1)
+ ;;
+esac
+[ -f "CONFIGS/$config" ] || fail "can't find config"
+cp $CONFIGS/$config $serial/$confname
+
+# create package config
+title "create package config"
+cat > $serial/package.conf << EOF
+Content-ID = $cid
k_licensee = 0x$KLICENSE
DRM_Type = Free
-Content_Type = Game_Data
+Content_Type = PS2_Classics_Game
PackageVersion = 01.01
EOF
+# prepare iso
+title "prepare iso"
+$PS2CLASSIC prepare "$file"
+
# convert iso
-$PS2CLASSIC e cex $serial/ps2.key "$1" $serial/USRDIR/ISO.BIN.ENC ISO.BIN.ENC 2P0001-${CID}_00-0000111122223333
+title "convert iso"
+$PS2CLASSIC e cex $serial/ps2.key "$file" $serial/USRDIR/ISO.BIN.ENC ISO.BIN.ENC $cid
# create package
-$PSNPACKAGE $serial
+title "create package"
+( cd $serial; $PSNPACKAGE $confname package.conf . )
+mv $serial/$cid.pkg .
+
+# cleaning
+title "cleaning"
+rm -rf $serial