| 1 | #!/bin/bash |
| 2 | |
| 3 | PROGNAME="$(basename $0)" |
| 4 | PWD=$(dirname $0) |
| 5 | [ "$PWD" ] || PWD=$(pwd) |
| 6 | PWD=$(cd $PWD; pwd) |
| 7 | |
| 8 | # default values |
| 9 | CACHE=$PWD/cache |
| 10 | CONFIGS=$PWD/CONFIGS |
| 11 | KLICENSE="e4e54fd67c16c316f47829a30484d843" |
| 12 | PS2CLASSIC=$PWD/ps2classic/ps2classic |
| 13 | PSNPACKAGE=$PWD/psn_package_npdrm/psn_package_npdrm |
| 14 | # FAT SLIM SUPER ULTRA |
| 15 | MODEL="ULTRA" |
| 16 | |
| 17 | # formating functions |
| 18 | function title () { echo -e "\033[0;1m$*\033[0;0m"; } |
| 19 | function pass () { echo -e "\033[1;32m$*\033[0;0m"; } |
| 20 | function warn () { echo -e "\033[1;33m$*\033[0;0m"; } |
| 21 | function fail () { echo -e "\033[1;31m$*\033[0;0m"; exit 1; } |
| 22 | |
| 23 | # defaut values |
| 24 | id=0 |
| 25 | |
| 26 | # get last values |
| 27 | [ -f .$PROGNAME ] && source .$PROGNAME |
| 28 | |
| 29 | # init |
| 30 | file="$1" |
| 31 | |
| 32 | # get serial |
| 33 | serial=$(isoinfo -f -i "$file" | \ |
| 34 | grep "^/[A-Z][A-Z][A-Z][A-Z]_[0-9][0-9][0-9]\.[0-9][0-9];" | \ |
| 35 | sed 's,[/.],,g;s,_,-,;s,;.*,,') |
| 36 | [ "$serial" ] || { serial=$(printf "PS2U-1%04d" $id); let id++; } |
| 37 | |
| 38 | # store last value |
| 39 | echo > .$PROGNAME |
| 40 | echo "id=$id" >> .$PROGNAME |
| 41 | |
| 42 | # get name |
| 43 | function getname () { |
| 44 | [ -f jlist2.html ] || wget https://psxdatacenter.com/psx2/jlist2.html |
| 45 | [ -f plist2.html ] || wget https://psxdatacenter.com/psx2/plist2.html |
| 46 | [ -f ulist2.html ] || wget https://psxdatacenter.com/psx2/ulist2.html |
| 47 | awk '/>'$file'</ { |
| 48 | getline; gsub(/<[^<]*>/, "") |
| 49 | sub(/ /, " ") |
| 50 | gsub(/^[ \t]*/, "") |
| 51 | gsub(/[ \t]*$/, "") |
| 52 | print |
| 53 | }' [jpu]list2.html |
| 54 | } |
| 55 | |
| 56 | # get game title |
| 57 | [ -f PS2-GAMEID-TITLE-MASTER.csv ] || wget https://raw.githubusercontent.com/VTSTech/PS2-OPL-CFG/master/test/PS2-GAMEID-TITLE-MASTER.csv |
| 58 | title=$(awk -F\; '"'$serial'" == $1 {print $2}' PS2-GAMEID-TITLE-MASTER.csv) |
| 59 | [ "$title" ] || title=$(basename "$file" | sed 's/ *(.*//') |
| 60 | |
| 61 | # create CID |
| 62 | title "create CID" |
| 63 | cid=2P0001-${serial/-}_00-$(echo ${title}0000111122223333 | \ |
| 64 | tr '[a-z]' '[A-Z]' | \ |
| 65 | sed 's/[^A-Z0-9]//g;s/\(................\).*$/\1/') |
| 66 | |
| 67 | # main process |
| 68 | title "description" |
| 69 | echo "File: '$file'" |
| 70 | echo "Serial: $serial" |
| 71 | echo "Title: '$title'" |
| 72 | echo "CID: $cid" |
| 73 | |
| 74 | # install skeleton |
| 75 | title "install skeleton" |
| 76 | mkdir $serial |
| 77 | tar -C $serial -xzf skeleton.tgz |
| 78 | [ -d "$CACHE" ] || mkdir "$CACHE" |
| 79 | |
| 80 | # images: |
| 81 | # - ICON0.PNG 320x176 |
| 82 | # - PIC0.PNG 1000x560 |
| 83 | # - PIC1.PNG 1920x1080 |
| 84 | |
| 85 | # get cover image |
| 86 | title "get cover image" |
| 87 | if [ -f "$CACHE/$serial-ICON0.PNG" ]; then |
| 88 | cp "$CACHE/$serial-ICON0.PNG" $serial/ICON0.PNG |
| 89 | else |
| 90 | wget https://psxdatacenter.com/psx2/images2/covers/$serial.jpg |
| 91 | if [ -f $serial.jpg ]; then |
| 92 | convert $serial.jpg tmp.png |
| 93 | mogrify -resize 320x176 tmp.png |
| 94 | mogrify -background transparent -gravity center -extent 320x176 tmp.png |
| 95 | mv tmp.png $serial/ICON0.PNG |
| 96 | rm $serial.jpg |
| 97 | cp $serial/ICON0.PNG "$CACHE/$serial-ICON0.PNG" |
| 98 | else |
| 99 | warn "can't find cover" |
| 100 | fi |
| 101 | fi |
| 102 | |
| 103 | # get screenshot |
| 104 | title "get screenshot" |
| 105 | if [ -f "$CACHE/$serial-PIC0.PNG" ]; then |
| 106 | cp "$CACHE/$serial-PIC0.PNG" $serial/PIC0.PNG |
| 107 | else |
| 108 | touch .touch |
| 109 | find $HOME/.config/PCSX2/snaps/ -type f | xargs rm .touch |
| 110 | pcsx2 "$file" |
| 111 | capture=$(find $HOME/.config/PCSX2/snaps/ -type f | sort) |
| 112 | if [ "$capture" ]; then |
| 113 | cp "$capture" tmp.png |
| 114 | mogrify -scale 1000x560 tmp.png |
| 115 | mogrify -background transparent -gravity center -extent 1000x560 tmp.png |
| 116 | mv tmp.png $serial/PIC0.PNG |
| 117 | cp $serial/PIC0.PNG "$CACHE/$serial-PIC0.PNG" |
| 118 | else |
| 119 | warn "can't find screenshot" |
| 120 | fi |
| 121 | fi |
| 122 | |
| 123 | # create PARAM.SFO |
| 124 | title "create PARAM.SFO" |
| 125 | # parameters |
| 126 | # - file: PARAM.SFO |
| 127 | # 0x120: title |
| 128 | # 0x1a0: ${serial/-} |
| 129 | # - file: USRDIR/ISO.BIN.EDAT |
| 130 | # 0x017: ${serial/-} |
| 131 | echo -n $title | xxd | xxd -r -s 0x120 - $serial/PARAM.SFO |
| 132 | echo -n ${serial/-} | xxd | xxd -r -s 0x1a0 - $serial/PARAM.SFO |
| 133 | echo -n ${serial/-} | xxd | xxd -r -s 0x17- $serial/USRDIR/ISO.BIN.EDAT |
| 134 | |
| 135 | # generate key |
| 136 | title "generate key" |
| 137 | dd bs=1 count=$(expr ${#KLICENSE} / 2) if=/dev/zero of=$serial/ps2.key |
| 138 | echo "00000000 $KLICENSE" | xxd -r - $serial/ps2.key |
| 139 | |
| 140 | # find config file |
| 141 | title "find config file" |
| 142 | confname=$(echo $serial.CONFIG | sed 's/-/_/;s/_\(...\)/_\1./') |
| 143 | case "$MODEL" in |
| 144 | FAT) |
| 145 | config=$(cd $CONFIGS; find GX -name $confname | head -1) |
| 146 | ;; |
| 147 | SLIM|SUPER|ULTRA) |
| 148 | config=$(cd $CONFIGS; find CUSTOM SOFT NET -name $confname | head -1) |
| 149 | ;; |
| 150 | esac |
| 151 | [ -f "CONFIGS/$config" ] || fail "can't find config" |
| 152 | cp $CONFIGS/$config $serial/$confname |
| 153 | |
| 154 | # create package config |
| 155 | title "create package config" |
| 156 | cat > $serial/package.conf << EOF |
| 157 | Content-ID = $cid |
| 158 | k_licensee = 0x$KLICENSE |
| 159 | DRM_Type = Free |
| 160 | Content_Type = PS2_Classics_Game |
| 161 | PackageVersion = 01.01 |
| 162 | EOF |
| 163 | |
| 164 | # prepare iso |
| 165 | title "prepare iso" |
| 166 | $PS2CLASSIC prepare "$file" |
| 167 | |
| 168 | # convert iso |
| 169 | title "convert iso" |
| 170 | $PS2CLASSIC e cex $serial/ps2.key "$file" $serial/USRDIR/ISO.BIN.ENC ISO.BIN.ENC $cid |
| 171 | |
| 172 | # create package |
| 173 | title "create package" |
| 174 | ( cd $serial; $PSNPACKAGE package.conf . ) |
| 175 | mv $serial/$cid.pkg . |
| 176 | |
| 177 | # cleaning |
| 178 | #title "cleaning" |
| 179 | #rm -rf $serial |