Skip to content

Instantly share code, notes, and snippets.

@shmerl
Last active January 8, 2022 17:40
Show Gist options
  • Save shmerl/ad11145ad4ef018fb2a5133bd5009948 to your computer and use it in GitHub Desktop.
Save shmerl/ad11145ad4ef018fb2a5133bd5009948 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Usage: gog_dex_extract_music.sh <data_dir>
#
# The script relies on these utilities:
# 1. QuickBMS extractor (quickbms)
# See http://aluigi.altervista.org/quickbms.htm
# Source: http://aluigi.altervista.org/papers/quickbms_src.zip
#
# 2. Unity BMS script to be used with QuickBMS (unity.bms)
# Source: http://aluigi.altervista.org/bms/unity.bms
#
# 3. FSB Vorbis extractor (extractor)
# Source: https://github.com/tmiasko/fsb-vorbis-extractor
#
# The script assumes, all these tools are placed in ${HOME}/bin/extractors
# override these three variables when running the script if you placed them elsewhere or they are named differently.
# quickbms=<location> unity_bms=<location> vorbis_extractor=<location> gog_dex_extract_music.sh <data_dir>
quickbms=${quickbms:-"${HOME}/bin/extractors/quickbms"}
unity_bms=${unity_bms:-"${HOME}/bin/extractors/unity.bms"}
vorbis_extractor=${vorbis_extractor:-"${HOME}/bin/extractors/extractor"}
dex_data="$1"
extract_dir="tmp_extract_fsb"
result_dir="result_ogg"
# cleanup
if [ -e "$extract_dir" ]; then
rm -v ${extract_dir}/*.fsb
fi
if [ -e "$result_dir" ]; then
rm -v ${result_dir}/*.ogg
fi
mkdir -p $extract_dir
mkdir -p $result_dir
# passing "r" as an answer to rename potential duplicates instead of skipping them
printf "r\n" | ${quickbms} -F 'level*;main*;*.assets;*.resource' -f '*.fsb' "$unity_bms" "$dex_data" "$extract_dir"
sources_tmp=( $extract_dir/resources~[[:lower:]]*.fsb $extract_dir/resources~GSV_[[:lower:]]*.fsb )
# Excluding some matches which aren't actually music
music_sources=()
for source in ${sources_tmp[@]}; do
if [[ "$source" != "$extract_dir/resources~click.fsb" ]] && \
[[ "$source" != "$extract_dir/resources~hover.fsb" ]] && \
[[ "$source" != "$extract_dir/resources~hello"*".fsb" ]]; then
music_sources+=( $source )
fi
done
# Extracting ogg/vorbis from fsb (fmod archives)
for source in ${music_sources[@]}; do
target=${source##"$extract_dir/"}
target=${target%%.*}.ogg
target=${target##resources~}
$vorbis_extractor $source -d $result_dir
mv -v ${result_dir}/1.sample.ogg ${result_dir}/${target}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment