Skip to content

Instantly share code, notes, and snippets.

@GermaniumSystem
Created June 10, 2017 06:30
Show Gist options
  • Save GermaniumSystem/0c76d4c8871a7be7005b5631081e7854 to your computer and use it in GitHub Desktop.
Save GermaniumSystem/0c76d4c8871a7be7005b5631081e7854 to your computer and use it in GitHub Desktop.
1.3 Mech & Captain's Chair Patcher
#!/bin/bash
[ -d tmp ] || mkdir tmp
INITDIR="$(pwd)"
WSDIR='../steamcmd/tmp/Starbound/steamapps/workshop/content/211820/'
SBDIR="../steamcmd/tmp/Starbound/"
MODSDIR="mods/"
UPDIR="unpack/"
MODBASE="modBase/"
[ -e "${UPDIR}" ] && rm -r "${UPDIR}"
mkdir "${UPDIR}"
[ -e 'speciesFixes' ] && rm -r 'speciesFixes'
cp -a "$MODBASE" 'speciesFixes'
printf '' > 'tmp/fixCinematic.log'
printf '' > 'tmp/patchChairs.log'
function logAction {
if [ -z "$1" ] || [ -z "$2" ] || [ -n "$3" ] ; then
echo 'Malformed call to `logAction`!'
exit 1
fi
MODID="$2"
METAFILE="$(find "${UPDIR}/${MODID}" -maxdepth 1 -type f -iregex '.*/\(\.\|_\)metadata$' | head -n 1)"
NAME="Unknown"
if [ -n "$METAFILE" ] ; then
if grep -qE '"name" *: *"' "$METAFILE" ; then
NAME="$(grep -E '"name" *: *"' "$METAFILE" | sed 's/.*"name" *: *"//' | sed 's/"[^\\]*$//')"
elif grep -qE '"friendlyName" *: *"' "$METAFILE" ; then
NAME="$(grep -E '"friendlyName" *: *"' "$METAFILE" | sed 's/.*"friendlyName" *: *"//' | sed 's/"[^\\]*$//')"
fi
fi
if [[ "$1" == "fixCinematic" ]] ; then
echo "Fixed cinematic in mod '$MODID'"
echo "$MODID $NAME" >> 'tmp/fixCinematic.log'
else
echo "Patched chair in mod '$MODID'"
echo "$MODID $NAME" >> 'tmp/patchChairs.log'
fi
}
function fixCinematics {
if [ -z "$1" ] || [ -n "$2" ] ; then
echo 'Malformed call to `fixCinematics`!'
exit 1
fi
MODID="$1"
SPECIESLIST="$(
find "${UPDIR}/${MODID}" -type f -name "*.species" | while read FILE ; do
grep -E '"kind" *: *"' "$FILE" | sed 's/.*"kind" *: *"//' | sed 's/".*//'
done | sort -u
)"
SKIPSPECIES="$(
find "${UPDIR}/${MODID}" -type f -name "deploy_*.cinematic" | while read FILE ; do
echo "$FILE" | sed 's/.*deploy_//' | sed 's/\.cinematic//'
done | sort -u
)"
CINSPECIES="$(comm -23 <(echo "$SPECIESLIST") <(echo "$SKIPSPECIES"))"
if [ -n "$CINSPECIES" ] ; then
echo "$CINSPECIES" | while read SPECIES ; do
cp -a 'deploy_SPECIES.cinematic' "speciesFixes/cinematics/teleport/deploy_${SPECIES}.cinematic"
echo "Built cinematic for species '$SPECIES'"
done
logAction "fixCinematic" "$MODID"
fi
}
function patchChairs {
if [ -z "$1" ] || [ -n "$2" ] ; then
echo 'Malformed call to `fixCinematics`!'
exit 1
fi
MODID="$1"
CAPCHAIRLIST="$(
find "${UPDIR}/${MODID}" -type f -name "*.object" | while read FILE ; do
if grep -q 'openCockpitInterface' "$FILE" ; then
echo "$FILE" | sed "s:.*${MODID}/::"
fi
done
)"
if [ -n "$CAPCHAIRLIST" ] ; then
echo "$CAPCHAIRLIST" | while read FILE ; do
mkdir -p "speciesFixes/$(dirname "$FILE")"
cp -a 'captainChair.patch' "speciesFixes/${FILE}.patch"
echo "Patched outdated captain's chair '$FILE'"
done
logAction "patchChairs" "$MODID"
fi
}
if [[ "$1" == "local" ]] ; then
echo "Using local mods directory $MODSDIR as source. NOTE: Must use proper naming convention!"
ls "$MODSDIR" | while read FILE ; do
MODID="$(echo "$FILE" | sed 's/_.*//')"
if [ -f "${MODSDIR}/${FILE}" ] ; then
"${SBDIR}/linux/asset_unpacker" "${MODSDIR}/${FILE}" "${UPDIR}/${MODID}"
else
echo "File '${MODSDIR}/${FILE}' is not unpackable. Copying to '${UPDIR}/${MODID}"
cp -a "${MODSDIR}/${FILE}" "${UPDIR}/${MODID}"
fi
echo "Processing mod '$MODID'..."
fixCinematics "$MODID"
patchChairs "$MODID"
rm -r "${UPDIR}/${MODID}"
done
else
echo "Using workshop directory '$WSDIR' as source."
ls "$WSDIR" | while read MODID ; do
ls "${WSDIR}/${MODID}/" | while read FILE ; do
if [ -f "${WSDIR}/${MODID}/${FILE}" ] ; then
"${SBDIR}/linux/asset_unpacker" "${WSDIR}/${MODID}/${FILE}" "${UPDIR}/${MODID}"
else
echo "File '${WSDIR}/${MODID}/${FILE}' is not unpackable. Copying to '${UPDIR}/${MODID}'..."
cp -a "${WSDIR}/${MODID}/${FILE}" "${UPDIR}/${MODID}"
fi
echo "Processing mod '$MODID'..."
fixCinematics "$MODID"
patchChairs "$MODID"
rm -r "${UPDIR}/${MODID}"
done
done
fi
"${SBDIR}/linux/asset_packer" 'speciesFixes' 'speciesFixes.pak'
BOTH="$(comm -12 <(cat 'tmp/fixCinematic.log' | sort) <(cat 'tmp/patchChairs.log' | sort) | sort -nk1 | sed 's/\t/ - /')"
CINEMATIC="$(comm -23 <(cat 'tmp/fixCinematic.log' | sort) <(cat 'tmp/patchChairs.log' | sort) | sort -nk1 | sed 's/\t/ - /')"
CHAIR="$(comm -13 <(cat 'tmp/fixCinematic.log' | sort) <(cat 'tmp/patchChairs.log' | sort) | sort -nk1 | sed 's/\t/ - /')"
echo "--- Mods with fixed mech cinematics and captain's chairs ---" > 'tmp/report_both.txt'
echo "$BOTH" >> 'tmp/report_both.txt'
echo '' >> 'tmp/report_both.txt'
echo "--- Mods with only fixed mech cinematics ---" > 'tmp/report_cinematic.txt'
echo "$CINEMATIC" >> 'tmp/report_cinematic.txt'
echo '' >> 'tmp/report_cinematic.txt'
echo "--- Mods with only fixed captain's chairs ---" > 'tmp/report_chair.txt'
echo "$CHAIR" >> 'tmp/report_chair.txt'
echo '' >> 'tmp/report_chair.txt'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment