last fixes
[iso2ps2.git] / iso2ps2
... / ...
CommitLineData
1#!/bin/bash
2
3PROGNAME="$(basename $0)"
4PWD=$(dirname $0)
5[ "$PWD" ] || PWD=$(pwd)
6PWD=$(cd $PWD; pwd)
7
8# default values
9CACHE=$PWD/cache
10CONFIGS=$PWD/CONFIGS
11KLICENSE="e4e54fd67c16c316f47829a30484d843"
12PS2CLASSIC=$PWD/ps2classic/ps2classic
13PSNPACKAGE=$PWD/psn_package_npdrm/psn_package_npdrm
14# FAT SLIM SUPER ULTRA
15MODEL="ULTRA"
16
17# formating functions
18function title () { echo -e "\033[0;1m$*\033[0;0m"; }
19function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
20function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
21function fail () { echo -e "\033[1;31m$*\033[0;0m"; exit 1; }
22
23# defaut values
24id=0
25
26# get last values
27[ -f .$PROGNAME ] && source .$PROGNAME
28
29# init
30file="$1"
31
32# get serial
33serial=$(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++; }
37
38# store last value
39echo > .$PROGNAME
40echo "id=$id" >> .$PROGNAME
41
42# get name
43function 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
47 awk '/>'$file'</ {
48 getline; gsub(/<[^<]*>/, "")
49 sub(/&nbsp;/, " ")
50 gsub(/^[ \t]*/, "")
51 gsub(/[ \t]*$/, "")
52 print
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
58title=$(awk -F\; '"'$serial'" == $1 {print $2}' PS2-GAMEID-TITLE-MASTER.csv)
59[ "$title" ] || title=$(basename "$file" | sed 's/ *(.*//')
60
61# create CID
62title "create CID"
63cid=2P0001-${serial/-}_00-$(echo ${title}0000111122223333 | \
64 tr '[a-z]' '[A-Z]' | \
65 sed 's/[^A-Z0-9]//g;s/\(................\).*$/\1/')
66
67# main process
68title "description"
69echo "File: '$file'"
70echo "Serial: $serial"
71echo "Title: '$title'"
72echo "CID: $cid"
73
74# install skeleton
75title "install skeleton"
76mkdir $serial
77tar -C $serial -xzf skeleton.tgz
78[ -d "$CACHE" ] || mkdir "$CACHE"
79
80# images:
81# - ICON0.PNG 320x176
82# - PIC0.PNG 1000x560
83# - PIC1.PNG 1920x1080
84
85# get cover image
86title "get cover image"
87if [ -f "$CACHE/$serial-ICON0.PNG" ]; then
88 cp "$CACHE/$serial-ICON0.PNG" $serial/ICON0.PNG
89else
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
97 cp $serial/ICON0.PNG "$CACHE/$serial-ICON0.PNG"
98 else
99 warn "can't find cover"
100 fi
101fi
102
103# get screenshot
104title "get screenshot"
105if [ -f "$CACHE/$serial-PIC0.PNG" ]; then
106 cp "$CACHE/$serial-PIC0.PNG" $serial/PIC0.PNG
107else
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
117 cp $serial/PIC0.PNG "$CACHE/$serial-PIC0.PNG"
118 else
119 warn "can't find screenshot"
120 fi
121fi
122
123# create PARAM.SFO
124title "create PARAM.SFO"
125# parameters
126# - file: PARAM.SFO
127# 0x120: title
128# 0x1a0: ${serial/-}
129# - file: USRDIR/ISO.BIN.EDAT
130# 0x017: ${serial/-}
131echo -n $title | xxd | xxd -r -s 0x120 - $serial/PARAM.SFO
132echo -n ${serial/-} | xxd | xxd -r -s 0x1a0 - $serial/PARAM.SFO
133echo -n ${serial/-} | xxd | xxd -r -s 0x17- $serial/USRDIR/ISO.BIN.EDAT
134
135# generate key
136title "generate key"
137dd bs=1 count=$(expr ${#KLICENSE} / 2) if=/dev/zero of=$serial/ps2.key
138echo "00000000 $KLICENSE" | xxd -r - $serial/ps2.key
139
140# find config file
141title "find config file"
142confname=$(echo $serial.CONFIG | sed 's/-/_/;s/_\(...\)/_\1./')
143case "$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 ;;
150esac
151[ -f "CONFIGS/$config" ] || fail "can't find config"
152cp $CONFIGS/$config $serial/$confname
153
154# create package config
155title "create package config"
156cat > $serial/package.conf << EOF
157Content-ID = $cid
158k_licensee = 0x$KLICENSE
159DRM_Type = Free
160Content_Type = PS2_Classics_Game
161PackageVersion = 01.01
162EOF
163
164# prepare iso
165title "prepare iso"
166$PS2CLASSIC prepare "$file"
167
168# convert iso
169title "convert iso"
170$PS2CLASSIC e cex $serial/ps2.key "$file" $serial/USRDIR/ISO.BIN.ENC ISO.BIN.ENC $cid
171
172# create package
173title "create package"
174( cd $serial; $PSNPACKAGE package.conf . )
175mv $serial/$cid.pkg .
176
177# cleaning
178#title "cleaning"
179#rm -rf $serial