This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
leagueoflegends
executable file
·677 lines (586 loc) · 18.2 KB
/
leagueoflegends
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#!/bin/bash
set -euo pipefail
msg() {
echo -e "[+] ${1-}" >&2
}
warn() {
echo -e "[!] ${1-}" >&2
}
die() {
echo -e "[!] ${1-}" >&2
exit 1
}
version_le() {
lesser_version="$(echo -e "$1\n$2" | sort -V | head -n1)"
[ "$1" = "$lesser_version" ]
}
join_array() {
local IFS="$1"
shift
echo "$*"
}
askQ() {
count=1
echo
echo " $1"
shift
for region in "$@"; do
echo " #$count - $region"
((count++))
done
echo
}
parse_args() {
VERBOSE=0
CONFIG_FILE=
PATCHLINE=live
REGION=
LOCALE=
while :; do
case "${1-}" in
-h | --help)
usage
exit
;;
-v | --verbose)
VERBOSE=1
set -x
;;
-f | --config)
CONFIG_FILE="${2-}"
shift
;;
--pbe)
PATCHLINE=pbe
;;
--region)
REGION="${2-}"
shift
;;
--locale)
LOCALE="${2-}"
shift
;;
--)
shift
break
;;
-?*) die "Unknown option: ${1-}\n$(usage)" ;;
*) break ;;
esac
shift
done
CMD=("$@")
export VERBOSE
export CONFIG_FILE
export PATCHLINE
export REGION
export LOCALE
export CMD
}
read_configs() {
if [[ -z "$CONFIG_FILE" ]]; then
if [ -n "${XDG_CONFIG_HOME+x}" ]; then
CONFIG_FILE="$XDG_CONFIG_HOME/league.sh"
else
CONFIG_FILE="$HOME/.config/league.sh"
fi
elif [[ ! -e "$CONFIG_FILE" ]]; then
die "File not found: $CONFIG_FILE"
fi
# Load the config file.
if [[ -e "$CONFIG_FILE" ]]; then
# shellcheck source=/dev/null
source "$CONFIG_FILE"
fi
if [ -z "${DATA_HOME+x}" ]; then
if [ -n "${XDG_DATA_HOME+x}" ]; then
DATA_HOME="$XDG_DATA_HOME"
else
DATA_HOME="$HOME/.local/share"
fi
fi
if [ -z "${CACHE_HOME+x}" ]; then
if [ -n "${XDG_CACHE_HOME+x}" ]; then
CACHE_HOME="$XDG_CACHE_HOME"
else
CACHE_HOME="$HOME/.cache"
fi
fi
export DATA_HOME
export CACHE_HOME
}
export_env_variables() {
# Note that in this order, wine-lol-staging will take precedence over
# wine-lol if they both exist. Consider adding a configuration option in the
# future.
if [[ -d "/opt/wine-lol/bin" ]]; then
PATH="/opt/wine-lol/bin:$PATH"
fi
if [[ -d "/opt/wine-lol-staging/bin" ]]; then
PATH="/opt/wine-lol-staging/bin:$PATH"
fi
export PATH
export REGFILE="/usr/share/doc/leagueoflegends/leagueoflegends.reg"
export ICON="/usr/share/icons/hicolor/256x256/apps/leagueoflegends.png"
export CACHE_DIR="$CACHE_HOME/leagueoflegends"
export WINEARCH="${WINEARCH:-win64}"
export WINEDLLOVERRIDES="mscoree,mshtml=;winemenubuilder.exe=d"
export WINE_REQ_MOD=(win10)
export WINEPREFIX="${WINEPREFIX:-$DATA_HOME/leagueoflegends}"
export INSTALL_DIR="$WINEPREFIX/drive_c/Riot Games"
export RIOT_CLIENT="$INSTALL_DIR/Riot Client/RiotClientServices.exe"
export LEAGUE_CLIENT="$INSTALL_DIR/League of Legends/LeagueClient.exe"
export GAME_EXE_DIR="$INSTALL_DIR/League of Legends/Game"
export GAME_EXE="$GAME_EXE_DIR/League of Legends.exe"
export RUNES_FILE="$INSTALL_DIR/League of Legends/Config/PerksPreferences.yaml"
if [ "$VERBOSE" -ne 0 ]; then
export WINEDEBUG="${WINEDEBUG:-}"
export VK_LOADER_DEBUG="${VK_LOADER_DEBUG:-error,warn,driver}"
else
export WINEDEBUG="${WINEDEBUG:-fixme-all}"
fi
export DXVK_DLLS=(d3d9 d3d10core d3d11 dxgi)
export DXVK_LOG_LEVEL=none
export DXVK_STATE_CACHE=0
DXVKDLLOVERRIDES="$(join_array , "${DXVK_DLLS[@]}")=n,b"
WINEDLLOVERRIDES="${WINEDLLOVERRIDES};${DXVKDLLOVERRIDES}"
# Prevents the zombie processes from remaining upon crashes.
# https://github.com/kyechou/leagueoflegends/issues/106
LOLDLLOVERRIDES="RiotClientCrashHandler.exe=d;LeagueCrashHandler64.exe=d"
WINEDLLOVERRIDES="${WINEDLLOVERRIDES};${LOLDLLOVERRIDES}"
export MESA_GLTHREAD=true
export STAGING_SHARED_MEMORY=1
export WINE_LARGE_ADDRESS_AWARE=1
export __GL_SHADER_DISK_CACHE=1
export __GL_SHADER_DISK_CACHE_PATH="$WINEPREFIX"
export __GL_THREADED_OPTIMIZATIONS=1
}
check_depends() {
depends=(wine wineboot winetricks winecfg wineserver winepath curl glxinfo)
for dep in "${depends[@]}"; do
if ! command -v "$dep" >/dev/null 2>&1; then
die "Missing $dep"
fi
done
optdepends=()
for dep in "${optdepends[@]}"; do
if command -v "$dep" >/dev/null 2>&1; then
export "HAS_$(echo "$dep" | awk '{ print toupper($0) }')"=1
fi
done
}
check_vulkan() {
if [ -z "${VK_DRIVER_FILES+x}" ]; then
# VK_DRIVER_FILES has not been set
# Get the active graphic card vendor
local vk_icd_files=()
local vendor_string
vendor_string="$(glxinfo -B | grep 'OpenGL vendor string' | cut -d: -f2)"
if echo "$vendor_string" | grep -iqF amd; then
mapfile -t vk_icd_files < <(
find /usr/share/vulkan/icd.d/{radeon,amd}* -type f 2>/dev/null
)
elif echo "$vendor_string" | grep -iqF nvidia; then
mapfile -t vk_icd_files < <(
find /usr/share/vulkan/icd.d/nvidia* -type f 2>/dev/null
)
elif echo "$vendor_string" | grep -iqF intel; then
mapfile -t vk_icd_files < <(
find /usr/share/vulkan/icd.d/intel* -type f 2>/dev/null
)
fi
if [[ "${#vk_icd_files[@]}" -eq 0 ]]; then
die "Vulkan ICD files not found\n Please install the correct Vulkan driver"
fi
VK_DRIVER_FILES="$(
IFS=:
echo "${vk_icd_files[*]}"
)"
fi
export VK_DRIVER_FILES
}
check_wine_lol() {
wine_path="$(command -v wine)"
if [[ "$wine_path" != *"wine-lol"* ]]; then
die "$wine_path doesn't seem to be wine-lol or wine-lol-staging"
fi
}
_create_wineprefix() {
if [ -e "$WINEPREFIX" ]; then
die "Wineprefix $WINEPREFIX already exists"
fi
msg "Creating wineprefix: $WINEPREFIX"
mkdir -p "$WINEPREFIX"
wineboot --init
msg "Installing winetricks verbs: ${WINE_REQ_MOD[*]}"
winetricks -q --optout --force "${WINE_REQ_MOD[@]}"
for link in "$WINEPREFIX/dosdevices"/*; do
[[ "$link" =~ 'c:' ]] && continue # for drive_c
[[ "$link" =~ 'z:' ]] && continue # for /
msg "Removing unnecessary device $(basename "$link")"
unlink "$link"
done
msg "Modifying WINE registry with $REGFILE"
regedit "$REGFILE"
msg "Waiting for wine processes..."
wineserver --wait
add_dxvk
msg "Wineprefix created: $WINEPREFIX"
}
install_LoL() {
if [ ! -e "$WINEPREFIX" ]; then
_create_wineprefix
elif [ -f "$RIOT_CLIENT" ]; then
while :; do
echo -n "[!] The game has been installed. Install anyway? [Y/n] "
read -r force
force="$(echo "$force" | tr '[:upper:]' '[:lower:]')"
if [ -z "${force##y*}" ]; then
break
elif [ -z "${force##n*}" ]; then
exit 1
fi
done
fi
askQ "Select your region" \
"North America" "EU West" "EU Nordic & East" "Latin America North" \
"Latin America South" "Brazil" "Turkey" "Russia" "Japan" "Oceania" \
"Republic of Korea" "Taiwan" "Philippines" "Singapore" "Vietnam" \
"Thailand"
read -r -p " #: " answer
case "${answer}" in
1) # North America
LANG_CODE="na" ;;
2) # EU West
LANG_CODE="euw" ;;
3) # EU Nordic & East
LANG_CODE="eune" ;;
4) # Latin America North
LANG_CODE="la1" ;;
5) # Latin America South
LANG_CODE="la2" ;;
6) # Brazil
LANG_CODE="br" ;;
7) # Turkey
LANG_CODE="tr" ;;
8) # Russia
LANG_CODE="ru" ;;
9) # Japan
LANG_CODE="jp" ;;
10) # Oceania
LANG_CODE="oc1" ;;
11) # Republic of Korea
LANG_CODE="kr" ;;
12) # Taiwan
LANG_CODE="tw2" ;;
13) # Philippines
LANG_CODE="ph2" ;;
14) # Singapore
LANG_CODE="sg2" ;;
15) # Vietnam
LANG_CODE="vn2" ;;
16) # Thailand
LANG_CODE="th2" ;;
*)
die "Unknown region number: $answer"
;;
esac
INSTALLER="$CACHE_DIR/installer.$LANG_CODE.exe"
INSTALLER_URL="https://lol.secure.dyn.riotcdn.net/channels/public/x/installer/current/live.$LANG_CODE.exe"
if [ ! -e "$INSTALLER" ]; then
msg "Downloading installer..."
mkdir -p "$CACHE_DIR"
curl --silent --show-error -Lo "$INSTALLER" "$INSTALLER_URL"
fi
msg "Installing League of Legends..."
wine "$(winepath -w "$INSTALLER")"
msg "Waiting for wine processes..."
wineserver --wait
msg "The game is installed at $INSTALL_DIR"
}
uninstall_LoL() {
msg "Uninstalling league of legends..."
set +e
{
rm -rf "$CACHE_DIR" "$WINEPREFIX"
rm -rf \
~/.config/menus/applications-merged/*-League\ of\ Legends* \
~/.local/share/applications/wine/Programs/Riot\ Games \
~/.local/share/desktop-directories/*-League\ of\ Legends.directory \
~/.local/share/desktop-directories/*-Riot\ Games.directory
find -H ~/.config/menus/applications-merged -empty -delete
find -H ~/.config/menus -empty -delete
find -H ~/.local/share/applications/wine/Programs -empty -delete
find -H ~/.local/share/applications/wine -empty -delete
find -H ~/.local/share/applications -empty -delete
find -H ~/.local/share/desktop-directories -empty -delete
} 2>/dev/null
set -e
}
reinstall_LoL() {
if [ -e "$INSTALL_DIR" ]; then
while :; do
echo -n "[!] Besides reinstalling the wine prefix, do you also want to reinstall the game? [Y/n] "
read -r rm_game
rm_game="$(echo "$rm_game" | tr '[:upper:]' '[:lower:]')"
if [ -z "${rm_game##y*}" ]; then
break
elif [ -z "${rm_game##n*}" ]; then
# Only reset the wine prefix
reset_wineprefix
return
fi
done
fi
# Reinstall the entire game
uninstall_LoL
_32_to_64_transition_guard
install_LoL
}
reset_wineprefix() {
if [ ! -e "$WINEPREFIX" ]; then
die "Wine prefix $WINEPREFIX does not exist. No need to reset"
fi
local saved_game_dir
saved_game_dir="$(realpath "$WINEPREFIX"/../league_save_dir)"
if [ -e "$saved_game_dir" ]; then
die "$saved_game_dir already exists"
fi
if [ -e "$INSTALL_DIR" ]; then
msg "Saving $INSTALL_DIR to $saved_game_dir"
mv "$INSTALL_DIR" "$saved_game_dir"
fi
uninstall_LoL
_create_wineprefix
if [ -e "$saved_game_dir" ]; then
msg "Moving $saved_game_dir back to $INSTALL_DIR"
mv "$saved_game_dir" "$INSTALL_DIR"
fi
}
_save_runes() {
# Temporary workaround to prevent the rune pages getting overwritten when
# the League client launches
# (https://github.com/kyechou/leagueoflegends/issues/38)
if [ -f "$RUNES_FILE" ]; then
chmod a-w "$RUNES_FILE"
fi
}
start_LoL() {
if [ ! -f "$RIOT_CLIENT" ]; then
while :; do
echo -n "[!] The game is not installed. Install it? [Y/n] "
read -r install
install="$(echo "$install" | tr '[:upper:]' '[:lower:]')"
if [ -z "${install##y*}" ]; then
install_LoL
break
elif [ -z "${install##n*}" ]; then
exit 1
fi
done
fi
local launch_flags=(
"--launch-product=league_of_legends"
"--launch-patchline=$PATCHLINE"
)
if [[ -n "$REGION" ]]; then
launch_flags+=("--region=$REGION")
fi
if [[ -n "$LOCALE" ]]; then
launch_flags+=("--locale=$LOCALE")
fi
msg "Starting..."
_save_runes
wine "$(winepath -w "$LEAGUE_CLIENT")" "${launch_flags[@]}"
wineserver --wait
wait
}
replay_match() {
if [ ! -f "$GAME_EXE" ]; then
die "The game is not installed. Please install it first"
fi
if [ ! -f "$1" ]; then
die "File not found: $1"
fi
msg "Replaying $1"
replay_path="$(winepath -w "$1")"
(cd "$GAME_EXE_DIR" && wine "$(winepath -w "$GAME_EXE")" "$replay_path")
wineserver --wait
wait
}
_download_dxvk() {
DXVK_VERSION="$(curl -s https://api.github.com/repos/doitsujin/dxvk/releases/latest | grep 'tag_name' | cut -d\" -f4 | tr -d v)"
DXVK_URL="https://github.com/doitsujin/dxvk/releases/download/v$DXVK_VERSION/dxvk-$DXVK_VERSION.tar.gz"
DXVK_TARBALL="$CACHE_DIR/dxvk-$DXVK_VERSION.tar.gz"
if [ ! -f "$DXVK_TARBALL" ]; then
msg "Downloading DXVK tarball"
mkdir -p "$CACHE_DIR"
curl --silent --show-error -Lo "$DXVK_TARBALL" "$DXVK_URL"
fi
msg "Extracting DXVK tarball..."
tar xzf "$DXVK_TARBALL" -C "$CACHE_DIR"
}
add_dxvk() {
if [ ! -d "$WINEPREFIX" ]; then
die "The game is not installed. Please install it first"
fi
_download_dxvk
msg "Installing DXVK to $WINEPREFIX"
# Install 64-bit libraries
for dll in "${DXVK_DLLS[@]}"; do
local src_file="$CACHE_DIR/dxvk-$DXVK_VERSION/x64/$dll.dll"
local dst_file="$WINEPREFIX/drive_c/windows/system32/$dll.dll"
if [ ! -f "$src_file" ]; then
die "File not found: $src_file"
fi
if [ -f "$dst_file" ] && [ ! -f "$dst_file.old" ]; then
mv -v "$dst_file" "$dst_file.old"
fi
cp -v --reflink=auto "$src_file" "$dst_file"
done
# Install 32-bit libraries
for dll in "${DXVK_DLLS[@]}"; do
local src_file="$CACHE_DIR/dxvk-$DXVK_VERSION/x32/$dll.dll"
local dst_file="$WINEPREFIX/drive_c/windows/syswow64/$dll.dll"
if [ ! -f "$src_file" ]; then
die "File not found: $src_file"
fi
if [ -f "$dst_file" ] && [ ! -f "$dst_file.old" ]; then
mv -v "$dst_file" "$dst_file.old"
fi
cp -v --reflink=auto "$src_file" "$dst_file"
done
msg "DXVK is installed"
}
del_dxvk() {
if [ ! -d "$WINEPREFIX" ]; then
die "The game is not installed. Please install it first"
fi
_download_dxvk
msg "Uninstalling DXVK from $WINEPREFIX"
# Remove 64-bit libraries
for dll in "${DXVK_DLLS[@]}"; do
local src_file="$CACHE_DIR/dxvk-$DXVK_VERSION/x64/$dll.dll"
local dst_file="$WINEPREFIX/drive_c/windows/system32/$dll.dll"
if [ ! -f "$src_file" ]; then
die "File not found: $src_file"
fi
if [ -f "$dst_file.old" ]; then
mv -v "$dst_file.old" "$dst_file"
fi
done
# Remove 32-bit libraries
for dll in "${DXVK_DLLS[@]}"; do
local src_file="$CACHE_DIR/dxvk-$DXVK_VERSION/x32/$dll.dll"
local dst_file="$WINEPREFIX/drive_c/windows/syswow64/$dll.dll"
if [ ! -f "$src_file" ]; then
die "File not found: $src_file"
fi
if [ -f "$dst_file.old" ]; then
mv -v "$dst_file.old" "$dst_file"
fi
done
msg "DXVK is removed"
}
rm_dxvk_cache() {
if [ -d "$CACHE_DIR" ]; then
find "$CACHE_DIR" -type f -name '*.dxvk-cache' -exec rm {} +
fi
}
cleanup_logs() {
msg "Cleaning up log files..."
if [ -d "$INSTALL_DIR" ]; then
find -H "$INSTALL_DIR" -name "*.log" -delete -print
if [ -d "$INSTALL_DIR/League of Legends/Logs" ]; then
find -H "$INSTALL_DIR/League of Legends/Logs" -type f -delete -print
find -H "$INSTALL_DIR/League of Legends/Logs" -empty -delete -print
fi
fi
}
usage() {
cat <<EOF
[!] Usage: $(basename "${BASH_SOURCE[0]}") [options] <command>
League of Legends - helper program
Options:
-h, --help Show help message
-v, --verbose Enable verbose output
-f, --config Specify the configuration file
--pbe Launch the PBE patchline
--region <region> Set region
--locale <locale> Set locale (if different from the region)
Commands:
start Start LoL
stop Same as kill
install Install LoL
uninstall Uninstall LoL
reinstall Reinstall LoL
reset-wineprefix Reset wine prefix
replay <path> Replay match (.rofl file)
add-dxvk Install DXVK to the LoL wineprefix
del-dxvk Remove DXVK from the LoL wineprefix
rm-dxvk-cache Remove DXVK cache
cleanup-logs Remove log files
kill Kill the wine processes of the wineprefix
run <cmd> Run shell command with environment variables
EOF
}
_32_to_64_transition_guard() {
local SYSTEM32="$WINEPREFIX/drive_c/windows/system32"
local SYSWOW64="$WINEPREFIX/drive_c/windows/syswow64"
if [[ -e "$SYSTEM32" ]] && [[ ! -e "$SYSWOW64" ]]; then
cat <<EOF
[!] The current installation is 32-bit.
Please run 'leagueoflegends reinstall' to switch to a 64-bit installation.
EOF
exit
fi
}
run_command() {
case "${1-}" in
start)
_32_to_64_transition_guard
start_LoL
;;
stop) wineserver --kill ;;
install)
_32_to_64_transition_guard
install_LoL
;;
uninstall) uninstall_LoL ;;
reinstall) reinstall_LoL ;;
reset-wineprefix) reset_wineprefix ;;
replay)
shift
_32_to_64_transition_guard
replay_match "${1-}"
;;
add-dxvk)
_32_to_64_transition_guard
add_dxvk
;;
del-dxvk)
_32_to_64_transition_guard
del_dxvk
;;
rm-dxvk-cache) rm_dxvk_cache ;;
cleanup-logs) cleanup_logs ;;
kill) wineserver --kill ;;
run)
shift
_32_to_64_transition_guard && "$@"
;;
*) die "Unknown command: ${1-}\n$(usage)" ;;
esac
}
main() {
parse_args "$@"
read_configs
export_env_variables
check_depends
check_vulkan
check_wine_lol
run_command "${CMD[@]}"
}
main "$@"
# vim: set ts=4 sw=4 et: