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