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