-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattila-forge
More file actions
executable file
·106 lines (94 loc) · 3.25 KB
/
attila-forge
File metadata and controls
executable file
·106 lines (94 loc) · 3.25 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
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
#!/bin/bash
steam_dir="${HOME}/.steam/steam/"
workshop_dir="${steam_dir}/steamapps/workshop/content/325610"
gamedata_dir="${steam_dir}/steamapps/common/Total War Attila/data"
scripts_dir="${HOME}/.Creative Assembly/Attila/scripts"
preferences_script_path="${scripts_dir}/preferences.script.txt"
packfile_prefix="mod."
default_save_name="modded_preferences.script.txt"
e_missing_arg=2
e_file_not_found=3
error_exit() {
echo "Error: $2" >&2
exit $1
}
# Help message
if [ $# -eq 0 -o "$1" = "-h" -o "$1" = "--help" ]; then
echo "Welcome to AttilaForge by Vulcan. Usage:"
echo "$0 [OPTIONS] [<packfile> ...]"
echo
echo "Options:"
echo -e " -r, --run"
echo " Runs the game at the end of execution. Must be the first option, otherwise ignored."
echo -e " -o, --output[=filename]"
echo " The game overwrites the preferences script on exit by default. Save the script after appending mods. If filename is not included, defaults to ${default_save_name}."
echo -e " -l, --load [filename]"
echo " Copies the specified filename to the preferences script file. Asks for permission to overwrite. If filename is not included, defaults to ${default_save_name}."
echo -e " -h, --help"
echo " Displays this help message."
exit 0
fi
# Run game executable
# TODO: Support launch options for the game
if [ "$1" = "-r" -o "$1" = "--run" ]; then
program_path=$0
shift 1
"$program_path" $*
steam steam://run/325610
exit 0
fi
# Load saved preferences script
if [ "$1" = "-l" -o "$1" = "--load" ]; then
save_path=$default_save_name
if [ $# -gt 1 ]; then
save_path=$2
fi
save_path="$scripts_dir/$save_path"
if [ ! -f "$save_path" ]; then
error_exit 3 "preferences script not found at $save_path"
fi
cp -bf "$save_path" "$preferences_script_path"
echo "Loaded preferences script."
exit 0
fi
# Save preferences script
if [[ "$1" == -o* || "$1" == --output* ]]; then
if grep -Eq "=.+$" <<< "$1"; then
save_name=${1#*=}
else
save_name=$default_save_name
fi
shift
fi
# Remove existing mods from preferences script. Can't remove lines directly because the file is written with ^M control chars (made for Windows I guess)
sed -i 's/mod .*//g' "$preferences_script_path"
sed -i '/^$/d' "$preferences_script_path"
# Copy .pack files and update preferences script
for arg in "$@"; do
packfile_path=$(find "$workshop_dir" -maxdepth 2 \( -name "$arg" -o -name "${arg}.pack" \) -print -quit 2> /dev/null )
if [ -z "$packfile_path" ]; then
echo "Mod '$arg' not found. Skipping."
continue
fi
packfile_basename=$(basename "$packfile_path")
echo -n "$packfile_basename : Found"
packfile_basename="${packfile_prefix}${packfile_basename}"
if [ -f "${gamedata_dir}/${packfile_basename}" ]; then
echo -n ", Already Copied"
else
cp "$packfile_path" "$gamedata_dir/${packfile_basename}"
echo -n ", Copied"
fi
if grep -q "$packfile_basename" "$preferences_script_path"; then
echo ", Already in Script"
else
echo "mod ${packfile_basename};" >> "$preferences_script_path"
echo ", Script Updated"
fi
done
# Save backup if option was set
if [ -n "$save_name" ]; then
cp -i "$preferences_script_path" "${scripts_dir}/${save_name}"
echo "Saved the preference script."
fi
exit 0