33set -e
44
55NGDP_BIN=$( realpath keg/bin/ngdp)
6- GREEN=' \e[32m'
76RED=' \e[31m'
7+ GREEN=' \e[32m'
8+ YELLOW=' \e[33m'
89WHITE=' \e[37m'
910
11+ print () {
12+ printf " $1$2 \n${WHITE} "
13+ }
14+
15+ info () {
16+ print $GREEN " $1 "
17+ }
18+
19+ warn () {
20+ print $YELLOW " $1 "
21+ }
22+
23+ error () {
24+ print $RED " $1 "
25+ }
26+
1027ensure_keg () {
1128 if [ ! -d venv ]; then
29+ info " Creating python venv for keg ..."
1230 python -m venv venv
1331 source venv/bin/activate
1432 pushd keg
1533 pip install .
1634 popd
1735 fi
1836 source venv/bin/activate
19- $NGDP_BIN --help || echo " keg is not working" ; exit -1
37+ $NGDP_BIN --help > /dev/null || (error " keg is not working" && exit 1)
2038}
2139
2240set_region () {
@@ -27,7 +45,7 @@ set_region() {
2745
2846 read -p " Which region do you wish to install? [eu/us/kr/cn]: " REGION
2947 if [ " ${REGION} " != " eu" ] && [ " ${REGION} " != " us" ] && [ " ${REGION} " != " kr" ] && [ " ${REGION} " != " cn" ]; then
30- echo -e " ${RED} Invalid Region. Exiting."
48+ error " Invalid Region. Exiting."
3149 exit 1
3250 fi
3351 echo $REGION > .region
@@ -44,7 +62,7 @@ set_locale() {
4462 && [ " ${LOCALE} " != " esMX" ] && [ " ${LOCALE} " != " frFR" ] && [ " ${LOCALE} " != " itIT" ] && [ " ${LOCALE} " != " jaJP" ] \
4563 && [ " ${LOCALE} " != " koKR" ] && [ " ${LOCALE} " != " plPL" ] && [ " ${LOCALE} " != " ptBR" ] && [ " ${LOCALE} " != " ruRU" ] \
4664 && [ " ${LOCALE} " != " thTH" ] && [ " ${LOCALE} " != " zhCN" ] && [ " ${LOCALE} " != " zhTW" ]; then
47- echo -e " ${RED} Invalid Locale. Exiting."
65+ error " Invalid Locale. Exiting."
4866 exit 1
4967 fi
5068 echo $LOCALE > .locale
@@ -69,29 +87,39 @@ check_version() {
6987 INSTALLED=$( cat .version)
7088 fi
7189
72- echo -e " ${GREEN} Region: ${WHITE} $REGION "
73- echo -e " ${GREEN} Online version: ${WHITE} $VERSION "
74- echo -e " ${GREEN} Downloaded version: ${WHITE} $INSTALLED "
90+ info " Region: $REGION "
91+ info " Online version: $VERSION "
92+ info " Installed version: $INSTALLED "
7593}
7694
7795download_hearthstone () {
78- echo -e " ${GREEN} Downloading Hearthstone via keg ...${WHITE} \n "
96+ info " Downloading Hearthstone via keg ..."
7997 $NGDP_BIN --cdn " http://level3.blizzard.com/tpr/hs" fetch http://${REGION} .patch.battle.net:1119/hsb --tags OSX --tags ${LOCALE} --tags Production
8098 $NGDP_BIN install http://${REGION} .patch.battle.net:1119/hsb $VERSION --tags OSX --tags ${LOCALE} --tags Production
8199 echo $VERSION > .version
82100}
83101
84102UNITY_ENGINE=Editor/Data/PlaybackEngines/LinuxStandaloneSupport/Variations/linux64_player_nondevelopment_mono
85- UNITY_VER=2021.3.25f1
86- UNITY_INSTALLER_URL=https://download.unity3d.com/download_unity/68ef2c4f8861/LinuxEditorInstaller/Unity.tar.xz
87- UNITY_HUB=/Hub/Editor/$UNITY_VER /$UNITY_ENGINE
88103
89104check_unity () {
90- if [ -f " $TARGET_PATH /Bin/Hearthstone.x86_64" ]; then
105+ UNITY_VER=` strings " Hearthstone.app/Contents/Resources/Data/level0" | head -n 1`
106+ [ -z " $UNITY_VER " ] && error " Can not determine required Unity version!" && exit 1
107+ UNITY_INSTALLED=" Not installed"
108+ if [ -f " .unity" ]; then
109+ UNITY_INSTALLED=$( cat .unity)
110+ fi
111+
112+ info " Required Unity version: $UNITY_VER "
113+ info " Installed Unity version: $UNITY_INSTALLED "
114+
115+ if [[ " $UNITY_VER " = " $UNITY_INSTALLED " ]]; then
91116 # Unity files are present already in case of updating
92117 return
93118 fi
94119
120+ warn " Update required."
121+ rm -rf MonoBleedingEdge
122+ UNITY_HUB=/Hub/Editor/$UNITY_VER /$UNITY_ENGINE
95123 if [ $1 ]; then
96124 # Unity files supplied via second argument
97125 UNITY_PATH=$1 $UNITY_HUB
@@ -107,41 +135,47 @@ check_unity() {
107135}
108136
109137download_unity () {
110- echo -e " ${RED} Unity files not found.\n${GREEN} Downloading Unity ${UNITY_VER} (This version is required for the game to run).${WHITE} \n"
111138 mkdir -p tmp
112- [ ! -f " tmp/Unity.tar.xz" ] && wget -P tmp $UNITY_INSTALLER_URL
139+ pushd tmp
140+
141+ info " Fetching Unity archive ..."
142+ curl -s https://unity.com/releases/editor/archive -o archive
143+ res=` cat archive | grep unityhub://$UNITY_VER ` || (error " Unity version not found in archive" && exit 1)
113144
114- echo -e " ${GREEN} Extracting Unity files.... ${WHITE} \n "
115- tar -xf tmp/Unity.tar.xz -C tmp $UNITY_ENGINE /LinuxPlayer $UNITY_ENGINE /UnityPlayer.so $UNITY_ENGINE /Data/MonoBleedingEdge/
116- UNITY_PATH=tmp/ $UNITY_ENGINE
117- echo -e " ${GREEN} Done!\n ${WHITE} "
145+ info " Downloading Unity files ..."
146+ HASH= ${res ##* $UNITY_VER / }
147+ HASH= ${HASH %% \" * }
148+ curl https://download.unity3d.com/download_unity/ $HASH /LinuxEditorInstaller/Unity.tar.xz -o Unity.tar.xz || (error " Could not fetch Unity archive " && exit 1)
118149
150+ info " Extracting Unity files ..."
151+ tar -xf Unity.tar.xz $UNITY_ENGINE /LinuxPlayer $UNITY_ENGINE /UnityPlayer.so $UNITY_ENGINE /Data/MonoBleedingEdge/
152+ UNITY_PATH=$PWD /$UNITY_ENGINE
153+
154+ popd
119155 copy_unity_files
120156 rm -rf tmp
121157}
122158
123159copy_unity_files () {
124- echo -e " ${GREEN} Copy Unity files.... ${WHITE} \n "
125- mkdir -p $TARGET_PATH / Bin
126- cp $UNITY_PATH /LinuxPlayer $TARGET_PATH / Bin/Hearthstone.x86_64
127- cp $UNITY_PATH /UnityPlayer.so $TARGET_PATH / Bin/
128- cp -r $UNITY_PATH /Data/MonoBleedingEdge $TARGET_PATH
129- echo -e " ${GREEN} Done!\n ${WHITE} "
160+ info " Copy Unity files ..."
161+ mkdir -p Bin
162+ cp $UNITY_PATH /LinuxPlayer Bin/Hearthstone.x86_64
163+ cp $UNITY_PATH /UnityPlayer.so Bin/
164+ cp -r $UNITY_PATH /Data/MonoBleedingEdge .
165+ echo $UNITY_VER > .unity
130166}
131167
132168move_files_and_cleanup () {
133- echo -e " ${GREEN} Moving files & running cleanup ...\n ${WHITE} "
169+ info " Moving files & running cleanup ..."
134170
135- mv $TARGET_PATH / Hearthstone.app/Contents/Resources/Data $TARGET_PATH / Bin/Hearthstone_Data
136- mv $TARGET_PATH / Hearthstone.app/Contents/Resources/' unity default resources' $TARGET_PATH / Bin/Hearthstone_Data/Resources
137- mv $TARGET_PATH / Hearthstone.app/Contents/Resources/PlayerIcon.icns $TARGET_PATH / Bin/Hearthstone_Data/Resources
138- mv $TARGET_PATH / MonoBleedingEdge $TARGET_PATH / Bin/Hearthstone_Data
171+ mv Hearthstone.app/Contents/Resources/Data Bin/Hearthstone_Data
172+ mv Hearthstone.app/Contents/Resources/' unity default resources' Bin/Hearthstone_Data/Resources
173+ mv Hearthstone.app/Contents/Resources/PlayerIcon.icns Bin/Hearthstone_Data/Resources
174+ mv MonoBleedingEdge Bin/Hearthstone_Data
139175
140- echo -e " ${GREEN} Done!\n${WHITE} "
141-
142- echo -e " ${GREEN} Cleaning up unecessary files.${WHITE} \n"
143- rm -rf $TARGET_PATH /Hearthstone.app
144- rm -rf $TARGET_PATH /' Hearthstone Beta Launcher.app'
176+ info " Cleaning up unecessary files ..."
177+ rm -rf Hearthstone.app
178+ rm -rf ' Hearthstone Beta Launcher.app'
145179}
146180
147181gen_token_login () {
@@ -162,15 +196,16 @@ check_directory() {
162196 if [ $1 ]; then
163197 # User-specified Hearthstone installation
164198 set_region
165- TARGET_PATH=$( realpath $1 )
199+ pushd $1
200+ TARGET_PATH=$PWD
166201 return
167202 fi
168203
169204 ensure_keg
170205
171206 # Managed Hearthstone installation via keg
172207 if [ ! -d hearthstone ]; then
173- echo -e " ${RED} Hearthstone installation not found${WHITE} \n "
208+ warn " Hearthstone installation not found"
174209 init_hearthstone
175210 else
176211 pushd hearthstone
@@ -179,7 +214,7 @@ check_directory() {
179214 # Update procedure
180215 check_version
181216 if [[ ! " $VERSION " = " $INSTALLED " ]]; then
182- echo -e " ${RED} Update required.${WHITE} \n "
217+ warn " Update required."
183218 [ -d " Bin/Hearthstone_Data/MonoBleedingEdge" ] && mv Bin/Hearthstone_Data/MonoBleedingEdge .
184219 rm -rf Bin/Hearthstone_Data
185220 rm -rf Data
@@ -190,13 +225,13 @@ check_directory() {
190225 download_hearthstone
191226 fi
192227
193- popd
194- TARGET_PATH=$( realpath hearthstone)
228+ TARGET_PATH=$PWD
195229}
196230
197231check_directory $1
198232check_unity $2
199233move_files_and_cleanup
234+ popd
200235gen_token_login
201236create_stubs
202237
@@ -210,6 +245,5 @@ Categories=Game;
210245StartupWMClass=Hearthstone.x86_64
211246EOF
212247
213- chmod +x $TARGET_PATH /login
214- chmod +x $TARGET_PATH /Bin/Hearthstone.x86_64
215- echo -e " \n${GREEN} Done. Now generate your web token, before launching the game!${WHITE} "
248+ info " Done."
249+ [ -f " $TARGET_PATH /token" ] || (warn " Please create your login token before launching the game!" && $TARGET_PATH /login)
0 commit comments