-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch_r2modman_valheim_start_game_bepinex.py
More file actions
executable file
·52 lines (42 loc) · 1.21 KB
/
patch_r2modman_valheim_start_game_bepinex.py
File metadata and controls
executable file
·52 lines (42 loc) · 1.21 KB
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
#! /usr/bin/env python3
##
# Patch the file to launch Valheim with mods from r2modman
#
# https://github.com/ebkr/r2modmanPlus/issues/1534
# https://github.com/BepInEx/BepInEx/issues/1032
#
import glob
import os
from pathlib import Path
old_statement = """
# Special case: program is launched via Steam
# In that case rerun the script via their bootstrapper to ensure Steam overlay works
if [ "$2" = "SteamLaunch" ]; then
cmd="$1 $2 $3 $4 $0"
shift 4
exec $cmd $@
exit
fi
"""
replacement = """
# https://github.com/BepInEx/BepInEx/issues/1032#issuecomment-2585547358
if [ "$4" = "SteamLaunch" ]; then
cmd="$1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} $0"
shift 11
exec $cmd $@
exit
fi
"""
home = Path('~').expanduser()
for filename in glob.glob(f"{home}/.config/r2modmanPlus-local/Valheim/profiles/*/start_game_bepinex.sh"):
content = open(filename).read()
if replacement in content:
print(f"File {filename} is already patched")
exit
print(f"Patching {filename}")
# Backup the old one
os.rename(filename, f"{filename}.bak")
new_content = content.replace(old_statement, replacement)
with open(filename, 'w') as f:
f.write(new_content)
print("Done!")