#!/usr/bin/env bash
tes3cmd=./tes3cmd
previous_esp="Yet Another Better Sounds Patch - Tavern and Town Sounds Expansion.esp"
cs_esp="Yet Another Better Sounds Patch - Tavern Sounds Expansion - CS.esp"
result="Yet Another Better Sounds Patch - Tavern Sounds Expansion.esp"

# Recompile scripts for vanilla engine users
# Resulting esp is a mess. So i have to reconstruct it again.

rm -v "${result}"
# Assemble the patch from many pieces
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type TES3 --type SOUN
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type MGEF
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type SCPT\
  --exact-id "outsidebanner"\
  --exact-id "globalstopsoundsscript"
${tes3cmd} dump "${cs_esp}" --raw "${result}" --type SCPT\
  --exact-id "globaltownsoundscript"
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type SCPT\
  --exact-id "globalweathersoundscript"\
  --exact-id "outsidebanner_2"\
  --exact-id "plains"\
  --exact-id "plains2"\
  --exact-id "plains3"\
  --exact-id "plains4"\
  --exact-id "signrotate_2"\
  --exact-id "sound_blacksmith_ambient"\
  --exact-id "sound_cave_wind_2"\
  --exact-id "sound_daedric_chant_2"\
  --exact-id "sound_forge_ambient"\
  --exact-id "sound_haunted_2"\
  --exact-id "sound_tavern_ambient"\
  --exact-id "sound_tavern_ambient_sp"\
  --exact-id "swampsoundscript"
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type REGN
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type SSCR
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type CONT
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type ACTI
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type SNDG
${tes3cmd} dump "${previous_esp}" --raw "${result}" --type CELL
