Commit | Line | Data |
---|---|---|
1de93811 ML |
1 | #!/bin/bash |
2 | ||
a8671a5d ML |
3 | PROGNAME="$(basename $0)" |
4 | PWD=$(dirname $0) | |
5 | [ "$PWD" ] || PWD=$(pwd) | |
6 | PWD=$(cd $PWD; pwd) | |
7 | ||
1de93811 | 8 | # default values |
a8671a5d ML |
9 | CACHE=$PWD/cache |
10 | CONFIGS=$PWD/CONFIGS | |
4ed64574 | 11 | KLICENSE="e4e54fd67c16c316f47829a30484d843" |
a8671a5d ML |
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; } | |
1de93811 ML |
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++; } | |
1de93811 ML |
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 | |
a8671a5d | 47 | awk '/>'$file'</ { |
1de93811 ML |
48 | getline; gsub(/<[^<]*>/, "") |
49 | sub(/ /, " ") | |
50 | gsub(/^[ \t]*/, "") | |
51 | gsub(/[ \t]*$/, "") | |
52 | ||
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 | ||
a8671a5d ML |
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 | ||
1de93811 | 67 | # main process |
a8671a5d | 68 | title "description" |
1de93811 ML |
69 | echo "File: '$file'" |
70 | echo "Serial: $serial" | |
71 | echo "Title: '$title'" | |
a8671a5d | 72 | echo "CID: $cid" |
1de93811 | 73 | |
a8671a5d ML |
74 | # install skeleton |
75 | title "install skeleton" | |
1de93811 ML |
76 | mkdir $serial |
77 | tar -C $serial -xzf skeleton.tgz | |
8ae7c948 | 78 | [ -d "$CACHE" ] || mkdir "$CACHE" |
1de93811 | 79 | |
1de93811 ML |
80 | # images: |
81 | # - ICON0.PNG 320x176 | |
82 | # - PIC0.PNG 1000x560 | |
83 | # - PIC1.PNG 1920x1080 | |
84 | ||
a8671a5d ML |
85 | # get cover image |
86 | title "get cover image" | |
8ae7c948 ML |
87 | if [ -f "$CACHE/$serial-ICON0.PNG" ]; then |
88 | cp "$CACHE/$serial-ICON0.PNG" $serial/ICON0.PNG | |
a8671a5d ML |
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 | |
8ae7c948 | 97 | cp $serial/ICON0.PNG "$CACHE/$serial-ICON0.PNG" |
a8671a5d ML |
98 | else |
99 | warn "can't find cover" | |
100 | fi | |
1de93811 ML |
101 | fi |
102 | ||
a8671a5d ML |
103 | # get screenshot |
104 | title "get screenshot" | |
8ae7c948 ML |
105 | if [ -f "$CACHE/$serial-PIC0.PNG" ]; then |
106 | cp "$CACHE/$serial-PIC0.PNG" $serial/PIC0.PNG | |
a8671a5d ML |
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 | |
8ae7c948 | 117 | cp $serial/PIC0.PNG "$CACHE/$serial-PIC0.PNG" |
a8671a5d ML |
118 | else |
119 | warn "can't find screenshot" | |
120 | fi | |
1de93811 ML |
121 | fi |
122 | ||
a8671a5d ML |
123 | # create PARAM.SFO |
124 | title "create PARAM.SFO" | |
1de93811 ML |
125 | # parameters |
126 | # - file: PARAM.SFO | |
a8671a5d ML |
127 | # 0x120: title |
128 | # 0x1a0: ${serial/-} | |
1de93811 | 129 | # - file: USRDIR/ISO.BIN.EDAT |
a8671a5d ML |
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 | |
1de93811 | 134 | |
2484479b | 135 | # generate key |
a8671a5d | 136 | title "generate key" |
4ed64574 | 137 | dd bs=1 count=$(expr ${#KLICENSE} / 2) if=/dev/zero of=$serial/ps2.key |
a8671a5d ML |
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 | |
2484479b ML |
158 | k_licensee = 0x$KLICENSE |
159 | DRM_Type = Free | |
a8671a5d | 160 | Content_Type = PS2_Classics_Game |
2484479b ML |
161 | PackageVersion = 01.01 |
162 | EOF | |
163 | ||
a8671a5d ML |
164 | # prepare iso |
165 | title "prepare iso" | |
166 | $PS2CLASSIC prepare "$file" | |
167 | ||
2484479b | 168 | # convert iso |
a8671a5d ML |
169 | title "convert iso" |
170 | $PS2CLASSIC e cex $serial/ps2.key "$file" $serial/USRDIR/ISO.BIN.ENC ISO.BIN.ENC $cid | |
2484479b ML |
171 | |
172 | # create package | |
a8671a5d | 173 | title "create package" |
8ae7c948 | 174 | ( cd $serial; $PSNPACKAGE package.conf . ) |
a8671a5d ML |
175 | mv $serial/$cid.pkg . |
176 | ||
177 | # cleaning | |
8ae7c948 ML |
178 | #title "cleaning" |
179 | #rm -rf $serial |