| 1 | #!/bin/bash |
| 2 | |
| 3 | # default values |
| 4 | PROGNAME=$(basename $0) |
| 5 | KLICENSE="e4e54fd67c16c316f47829a30484d843" |
| 6 | PS2CLASSIC=ps2classic/ps2classic |
| 7 | PSNPACKAGE=psn_package_npdrm/psn_package_npdrm |
| 8 | |
| 9 | # defaut values |
| 10 | id=0 |
| 11 | |
| 12 | # get last values |
| 13 | [ -f .$PROGNAME ] && source .$PROGNAME |
| 14 | |
| 15 | # init |
| 16 | file="$1" |
| 17 | |
| 18 | # get serial |
| 19 | serial=$(isoinfo -f -i "$file" | \ |
| 20 | grep "^/[A-Z][A-Z][A-Z][A-Z]_[0-9][0-9][0-9]\.[0-9][0-9];" | \ |
| 21 | sed 's,[/.],,g;s,_,-,;s,;.*,,') |
| 22 | [ "$serial" ] || { serial=$(printf "PS2U-1%04d" $id); let id++; } |
| 23 | CID=${serial/-} |
| 24 | |
| 25 | # store last value |
| 26 | echo > .$PROGNAME |
| 27 | echo "id=$id" >> .$PROGNAME |
| 28 | |
| 29 | # get name |
| 30 | function getname () { |
| 31 | [ -f jlist2.html ] || wget https://psxdatacenter.com/psx2/jlist2.html |
| 32 | [ -f plist2.html ] || wget https://psxdatacenter.com/psx2/plist2.html |
| 33 | [ -f ulist2.html ] || wget https://psxdatacenter.com/psx2/ulist2.html |
| 34 | awk '/>'$1'</ { |
| 35 | getline; gsub(/<[^<]*>/, "") |
| 36 | sub(/ /, " ") |
| 37 | gsub(/^[ \t]*/, "") |
| 38 | gsub(/[ \t]*$/, "") |
| 39 | print |
| 40 | }' [jpu]list2.html |
| 41 | } |
| 42 | |
| 43 | # get game title |
| 44 | [ -f PS2-GAMEID-TITLE-MASTER.csv ] || wget https://raw.githubusercontent.com/VTSTech/PS2-OPL-CFG/master/test/PS2-GAMEID-TITLE-MASTER.csv |
| 45 | title=$(awk -F\; '"'$serial'" == $1 {print $2}' PS2-GAMEID-TITLE-MASTER.csv) |
| 46 | [ "$title" ] || title=$(basename "$file" | sed 's/ *(.*//') |
| 47 | |
| 48 | # main process |
| 49 | echo "File: '$file'" |
| 50 | echo "Serial: $serial" |
| 51 | echo "Title: '$title'" |
| 52 | |
| 53 | # skeleton |
| 54 | mkdir $serial |
| 55 | tar -C $serial -xzf skeleton.tgz |
| 56 | |
| 57 | # images: |
| 58 | # - ICON0.PNG 320x176 |
| 59 | # - PIC0.PNG 1000x560 |
| 60 | # - PIC1.PNG 1920x1080 |
| 61 | |
| 62 | # cover |
| 63 | wget https://psxdatacenter.com/psx2/images2/covers/$serial.jpg |
| 64 | if [ -f $serial.jpg ]; then |
| 65 | convert $serial.jpg tmp.png |
| 66 | mogrify -resize 320x176 tmp.png |
| 67 | mogrify -background transparent -gravity center -extent 320x176 tmp.png |
| 68 | mv tmp.png $serial/ICON0.PNG |
| 69 | rm $serial.jpg |
| 70 | fi |
| 71 | |
| 72 | # screenshot |
| 73 | touch .touch |
| 74 | find $HOME/.config/PCSX2/snaps/ -type f | xargs rm .touch |
| 75 | pcsx2 "$file" |
| 76 | capture=$(find $HOME/.config/PCSX2/snaps/ -type f | sort) |
| 77 | if [ "$capture" ]; then |
| 78 | cp "$capture" tmp.png |
| 79 | mogrify -scale 1000x560 tmp.png |
| 80 | mogrify -background transparent -gravity center -extent 1000x560 tmp.png |
| 81 | mv tmp.png $serial/PIC0.PNG |
| 82 | fi |
| 83 | |
| 84 | # parameters |
| 85 | # - file: PARAM.SFO |
| 86 | # 0x108: title |
| 87 | # 0x188: CID |
| 88 | # - file: USRDIR/ISO.BIN.EDAT |
| 89 | # 0x017: CID |
| 90 | echo -n $title | xxd | xxd -r -s 0x108 - $serial/PARAM.SFO |
| 91 | echo -n $CID | xxd | xxd -r -s 0x188 - $serial/PARAM.SFO |
| 92 | echo -n $CID | xxd | xxd -r -s 0x17- $serial/USRDIR/ISO.BIN.EDAT |
| 93 | |
| 94 | # generate key |
| 95 | dd bs=1 count=$(expr ${#KLICENSE} / 2) if=/dev/zero of=$serial/ps2.key |
| 96 | echo "00000000 $KLICENSE" | xdd -r - > $serial/ps2.key |
| 97 | |
| 98 | # package config |
| 99 | echo > $serial/package.conf << EOF |
| 100 | Content-ID = $CID |
| 101 | k_licensee = 0x$KLICENSE |
| 102 | DRM_Type = Free |
| 103 | Content_Type = Game_Data |
| 104 | PackageVersion = 01.01 |
| 105 | EOF |
| 106 | |
| 107 | # convert iso |
| 108 | $PS2CLASSIC e cex $serial/ps2.key "$1" $serial/USRDIR/ISO.BIN.ENC ISO.BIN.ENC 2P0001-${CID}_00-0000111122223333 |
| 109 | |
| 110 | # create package |
| 111 | $PSNPACKAGE $serial |