-
Notifications
You must be signed in to change notification settings - Fork 0
/
blt4l.sh
executable file
·133 lines (117 loc) · 4.66 KB
/
blt4l.sh
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
#!/usr/bin/env bash
## BLT4L Launcher Script
## Copyright (C) Zach Mertes 2017. GPL3
## Basic description of current implementation:
## 1. Check if we're in the Steam runtime and set the correct binary
## 2. Check if mods/ exists, if it doesn't copy in the default mods folder.
## 3. Check if mods/base exists, if not copy in the default one.
## 4. LD_PRELOAD
## 5. Launch game
# Folder for the two binaries and for the base lua folder (eventually)
BLT4L_LIB_PATH="/usr/lib/blt4l"
DISTDIR_MODS="$BLT4L_LIB_PATH/mods"
DISTDIR_MODS_BASE="$DISTDIR_MODS/base"
# Game directory, which Steam automatically launches us in
GAMEDIR="$PWD"
GAMEDIR_MODS="$PWD/mods"
GAMEDIR_MODS_BASE="$GAMEDIR_MODS/base"
# Where we spit out debugging information
LOGFILE="$GAMEDIR/blt4l_launcher.log"
## Check if we're even being run by Steam
if [ $# -eq 0 ]; then
echo -e "blt4l isn't meant to be run directly
You should go into Steam->\e[4mPAYDAY 2\e[0m->Right click->\e[4mProperies\e[0m->\e[4mSet Launch Options...\e[0m and set:
\e[1mblt4l %command%\e[0m
(feel free to pass any options to Payday 2 after %command%, like -skip_intro)
Then run Payday 2 from Steam normally."
exit 1
fi
## Utility Functions
log() {
local msg
msg="[$(date --iso=s)] $1"
echo "$msg" >> "$LOGFILE"
echo "$msg" >&2
}
popup_err() {
if hash zenity 2>/dev/null; then
zenity --error --ellipsize --text="$*"
else
log "zenity not found, the error that would've popped up would've been:"
log "$*"
fi
}
is_number() {
re='^[0-9]+$'
[[ $1 =~ $re ]]
}
## Detect if we're in the Steam runtime
## and set the binary accordingly
BLT4L_BINARY_NAME=""
if is_number "$STEAM_RUNTIME"; then
log "Steam runtime not detected"
BLT4L_BINARY_NAME="libblt_loader.so"
else
log "Steam runtime detected"
BLT4L_BINARY_NAME="libblt_loader_steamrt.so"
fi
## If there's a libblt_loader in the game dir, load that
## Otherwise, load the system binary
BLT4L_BINARY_PATH=""
if [[ -e "$GAMEDIR/$BLT4L_BINARY_NAME" ]]; then
log "Loading gamedir binary '$GAMEDIR/$BLT4L_BINARY_NAME'"
BLT4L_BINARY_PATH="$GAMEDIR/$BLT4L_BINARY_NAME"
else
log "Loading system binary '$BLT4L_LIB_PATH/$BLT4L_BINARY_NAME'"
BLT4L_BINARY_PATH="$BLT4L_LIB_PATH/$BLT4L_BINARY_NAME"
fi
if ! [[ -e "$BLT4L_BINARY_PATH" ]]; then
log "WARNING: BLT4L binary doesn't appear to exist; BLT probably isn't going to work."
popup_err "The BLT4L binary doesn't appear to exist, so your game is probably going to load without BLT."
fi
## Detect if the mods folder exists
if [[ -d "$GAMEDIR_MODS" ]]; then
log "Mods directory exists"
else
## Load the mods folder in from the distributed version
log "Mods directory not found, copying in distributed copy"
if ! [[ -e "$DISTDIR_MODS" ]]; then
# Mods directory doesn't exist and we don't have one to install, display err to user and exit
log "WARNING: distribution mods folder '$DISTDIR_MODS' not found."
popup_err "WARNING: no mods folder found and distribution mods folder '$DISTDIR_MODS' not found.
You'll need to manually install the mods directory.
See https://github.com/blt4linux/blt4l for more information.
If you installed blt4l from a distributed package, please complain at whoever provided it to you.
If you're trying to uninstall blt4l, clear PAYDAY 2's launch options in Steam."
exit 1
else
mkdir -p "$GAMEDIR_MODS"
cp -r -t "$GAMEDIR_MODS" "$DISTDIR_MODS/"*
log "Mods directory copied from '$DISTDIR_MODS'"
fi
fi
## Detect if the mods/base folder exists
if [[ -d "$GAMEDIR_MODS_BASE" ]]; then
log "Base mod directory exists"
else
## Load the mods folder in from the distributed version
log "Base mod directory not found, copying in distributed copy"
if ! [[ -e "$DISTDIR_MODS_BASE" ]]; then
# Mods directory doesn't exist and we don't have one to install, display err to user and exit
log "WARNING: distribution mods folder '$DISTDIR_MODS_BASE' not found."
popup_err "WARNING: no mods/base folder found and distribution mods/base folder '$DISTDIR_MODS_BASE' not found.
You'll need to manually install the mods directory.
See https://github.com/blt4linux/blt4l for more information.
If you installed blt4l from a distributed package, please complain at whoever provided it to you.
If you're trying to uninstall blt4l, clear PAYDAY 2's launch options in Steam."
exit 1
else
mkdir -p "$GAMEDIR_MODS_BASE"
cp -r -t "$GAMEDIR_MODS_BASE" "$DISTDIR_MODS_BASE/"*
log "Mods directory copied from '$DISTDIR_MODS_BASE'"
fi
fi
## Launch the game
log "Starting game with provided command '$*'"
export LD_PRELOAD="$LD_PRELOAD:$BLT4L_BINARY_PATH"
exec "$@"