Pieds-Nus_custom-scripts/factorimods
2023-06-17 18:01:20 +00:00

81 lines
3.5 KiB
Bash

#!/bin/bash
#mod-settings.dat
# Dependencies : you'll need a dmenu-like to run this script.
# On debian and debian-like distros (ubuntu, mint...), simply run:
# sudo apt install dmenu
# If you use something else than dmenu, edit the following line accordingly:
dmenu=dmenu
#Verbosity log
verb=true
# Edit this line to meet your installation
factorio_dir="$HOME/Games/factorio"
test "$verb" && echo "Directory: $factorio_dir"
# If you have installed new mods, this script will revert to previously saved
# mods before launching factorio. To update the modlist for a save, select the
# appropriate mods (via the GUI menu in factorio), then exit, call
# factorimods -r
# and select that save. This will replace the previously saved mods for that
# save with the active list from factorio.
cd "$factorio_dir/saves"
#Ask the user to select a save
save=$(ls -t *.zip | rev | cut -d "." -f 2- | rev | $dmenu -l 5 -p "Chose a save file: ") || ( echo "No save selected" ; exit 1)
test "$verb" && echo "Save selected : $save"
# If -r option is passed, replace the modlist of the save with the latest modlist from factorio
if test "$1" = "-r" ; then
cp ../mods/mod-list.json "mod-list.json_$save"
cp ../mods/mod-list.json "mod-settings.dat_$save"
modlist="$save"
test "$verb" && echo "Modlist updated"
# Check if a modlist exists for that save
elif test -s "mod-list.json_$save" ; then
modlist="$save"
test "$verb" && echo "Modilist found: mod-list.json_$save"
else
# Otherwise, prompt to load another modlist
modlist=$(ls -t mod-list.json_* | cut -d "_" -f 2- | $dmenu -p "No mod list found for savegame \"$save\". Select mod list from available: ")
if test $? -ne 0 ; then
echo "No modlist selected"
# And prompt to save it for later
elif echo -e "yes\nno" | $dmenu -p "Save selected modlist for savegame $save ?" | grep -q "yes" ; then
test "$verb" && echo "Modlist selected: $modlist"
cp "mod-list.json_$modlist" "mod-list.json_$save"
cp "mod-settings.dat_$modlist" "mod-settings.dat_$save"
modlist="$save"
fi
fi
# Link that modlist to the file read by factorio
ln -fs "../saves/mod-list.json_$modlist" ../mods/mod-list.json
test -s "../saves/mod-settings.dat_$modlist" && ln -fs "../saves/mod-settings.dat_$modlist" ../mods/mod-settings.dat
# Launch the game and the requested save
cd ..
echo "LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libhugetlbfs-2.23.so HUGETLB_MORECORE=thp HUGETLB_RESTRICT_EXE=factorio"
echo "$factorio_dir/bin/x64/factorio --load-game $factorio_dir/saves/$save.zip"
# hugepage memory allocation
# source : https://www.reddit.com/r/factorio/comments/dr72zx/8_ups_gain_on_linux_with_huge_pages/
# comment that "LD_PRELOAD..." line to prevent hugepage and go back to normal glibc allocating
#LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libhugetlbfs-2.23.so HUGETLB_MORECORE=thp HUGETLB_RESTRICT_EXE=factorio "$factorio_dir/bin/x64/factorio" --load-game "$factorio_dir/saves/$save.zip"
# Factorio launcher that does some memory alloc optimisations and shit : [ $HOME/Games/factorio/launchers.sh ]
"$factorio_dir/launcher.sh" --load-game \"$factorio_dir/saves/$save.zip\"
# $factorio_dir/bin/x64/factorio --load-game $factorio_dir/saves/$save.zip
diff -q "saves/mod-list.json_$save" mods/mod-list.json && echo -e "save\nforget" | dmenu -p "Mod list updated." | grep -q "save" && cp mods/mod-list.json "saves/mod-list.json_$save"
diff -q "saves/mod-settings.dat_$save" mods/mod-settings.dat && echo -e "save\nforget" | dmenu -p "Mod settings updated." | grep -q "save" && cp mods/mod-settings.dat "saves/mod-settings.dat_$save"