update script
authorMazet Laurent <mazet@softndesign.org>
Sat, 9 Dec 2023 08:14:00 +0000 (09:14 +0100)
committerMazet Laurent <mazet@softndesign.org>
Sat, 9 Dec 2023 08:14:00 +0000 (09:14 +0100)
iso2ps2
psn_package_npdrm/psn_package_npdrm
skeleton.tgz

diff --git a/iso2ps2 b/iso2ps2
index fd26b5f89de4288761695e122168520f2e837982..88000348fa98bb9a199de1b006c02ed017cd2aeb 100755 (executable)
--- a/iso2ps2
+++ b/iso2ps2
@@ -1,10 +1,24 @@
 #!/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
@@ -20,7 +34,6 @@ serial=$(isoinfo -f -i "$file" | \
     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
@@ -31,7 +44,7 @@ function getname () {
     [ -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(/&nbsp;/, " ")
         gsub(/^[ \t]*/, "")
@@ -45,67 +58,122 @@ function getname () {
 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
index 42a0e3f6997bb82c40eccf78cd35f1bfc5a8cb54..74b5c8b4884d473cea0002c8f2af1ca0b8d85e14 100755 (executable)
@@ -2,4 +2,4 @@
 
 PWD=$(dirname $0)
 [ "$PWD" ] || PWD=.
-wine $PWD/$0.exe
+wine $PWD/$(basename $0).exe $@
index ee71b16e911088ec211c8e7b608b99709ae1ce72..d958120d79a35f65d367a76d6e5dda446bb1aeac 100644 (file)
Binary files a/skeleton.tgz and b/skeleton.tgz differ