#!/usr/bin/env bash
# vim:nowrap
# Changelog:
# 2021-10-16
#   - Bloodmoon Rebalance patch now contains Patch for Purists fixes
#
# 2022-04-17
#   - Revert back to using original Bloodmoon Rebalance
#
# 2022-11-28
#   - Update Tamriel_Data patch to v9, add Land Dreugh
#   - Remove TR_Mainland patch(it should not be created)
#
tes3cmd="./tes3cmd"

# 01 Base game and Patch for Purists
result="YANDL - Base.esp"
$tes3cmd dump "Morrowind.esm" --raw-with-header "${result}" --type CREA\
 --exact-id "kwama worker diseased"\
 --exact-id "scrib diseased"\
 --exact-id "alit_blighted"\
 --exact-id "alit_diseased"\
 --exact-id "cliff racer_blighted"\
 --exact-id "cliff racer_diseased"\
 --exact-id "kagouti_blighted"\
 --exact-id "kagouti_diseased"\
 --exact-id "mudcrab-diseased"\
 --exact-id "nix-hound blighted"\
 --exact-id "rat_blighted"\
 --exact-id "scrib blighted"\
 --exact-id "shalk_blighted"\
 --exact-id "shalk_diseased"
# --exact-id "rat_diseased"\
$tes3cmd dump "Tribunal.esm" --raw "${result}" --type CREA\
 --exact-id "rat_plague"\
 --exact-id "rat_diseased"\
 --exact-id "durzog_diseased"
# YANDL - Bloodmoon.esp
# $tes3cmd dump "Bloodmoon.esm" --raw "${result}" --type CREA\
#  --exact-id "bm_bear_brown"\
#  --exact-id "bm_wolf_red"
$tes3cmd dump "Patch for Purists.esm" --raw "${result}" --type CREA\
 --exact-id "kwama warrior blighted"\
 --exact-id "kwama worker blighted"\
 --exact-id "kwama forager blighted"\
 --exact-id "bm_bear_brown"\
 --exact-id "bm_wolf_red"
$tes3cmd header "${result}" --hide-backups --update-record-count
# now modify
# YANDL - Morrowind.esp
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "shalk_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Shalk')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "shalk_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Shalk')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "cliff racer_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Cliff Racer')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "cliff racer_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Cliff Racer')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "alit_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Alit')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "alit_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Alit')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kagouti_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kagouti')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kagouti_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kagouti')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kwama worker diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kwama Worker')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "nix-hound blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Nix-Hound')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "scrib diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Scrib')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "scrib blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Scrib')"
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "rat_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Rat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "rat_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Rat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "mudcrab-diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Mudcrab')"
# YANDL - Tribunal.esp
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "rat_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Rat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "rat_plague" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Rat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "durzog_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Durzog')"
# YANDL - Bloodmoon.esp
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_bear_brown" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bear')"
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_wolf_red" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Wolf')"
# YANDL - Patch for Purists.esp
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kwama warrior blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kwama Warrior')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kwama worker blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kwama Worker')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kwama forager blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kwama Forager')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_bear_brown" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_wolf_red" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Wolf')"

# 02 Blighted Animals Retextured
result="YANDL - BlightedAnimalsRetextured.esp"
$tes3cmd dump "BlightedAnimalsRetextured.esp" --raw-with-header "${result}" --type CREA\
 --exact-id "shalk_blighted"\
 --exact-id "cliff racer_blighted"\
 --exact-id "alit_blighted"\
 --exact-id "kagouti_blighted"\
 --exact-id "kwama forager blighted"\
 --exact-id "nix-hound blighted"\
 --exact-id "scrib blighted"\
 --exact-id "rat_blighted"
$tes3cmd header "${result}" --hide-backups --update-record-count
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "shalk_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Shalk')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "cliff racer_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Cliff Racer')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "alit_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Alit')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kagouti_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kagouti')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kwama forager blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kwama Forager')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "nix-hound blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Nix-Hound')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "scrib blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Scrib')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "rat_blighted" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Rat')"

# 03 Tribunal Rebalance
result="YANDL - tribunal rebalance.esp"
$tes3cmd dump "tribunal rebalance.ESP" --raw-with-header "${result}" --type CREA\
 --exact-id "durzog_diseased"
$tes3cmd header "${result}" --hide-backups --update-record-count
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "durzog_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Durzog')"

# 04 Bloodmoon Rebalance
result="YANDL - Bloodmoon Rebalance.esp"
# $tes3cmd dump "Bloodmoon Rebalance - PFP.esp" --raw-with-header "${result}" --type CREA\
$tes3cmd dump "Bloodmoon Rebalance.esp" --raw-with-header "${result}" --type CREA\
 --exact-id "bm_bear_brown"\
 --exact-id "bm_wolf_red"
$tes3cmd header "${result}" --hide-backups --update-record-count
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_bear_brown" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_wolf_red" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Wolf')"

# 05 Tamriel Data
result="YANDL - Tamriel_Data.esp"
$tes3cmd dump "Tamriel_Data.esm" --raw-with-header "${result}" --type CREA\
 --exact-id "t_cyr_fau_bearcolds_01"\
 --exact-id "t_cyr_fau_goatdis_01"\
 --exact-id "t_cyr_fau_mooncdis_01"\
 --exact-id "t_cyr_fau_muskratds_01"\
 --exact-id "t_cyr_fau_ratds_01"\
 --exact-id "t_cyr_fau_wolfcolds_01"\
 --exact-id "t_cyr_fau_wolfcolds_02"\
 --exact-id "t_dwe_und_ghstgrpl_01"\
 --exact-id "t_dwe_und_ghstpl_01"\
 --exact-id "t_glb_cre_dreuds_01"\
 --exact-id "t_glb_cre_landdreuds_01"\
 --exact-id "t_glb_cre_trollcaved_03"\
 --exact-id "t_glb_fau_fishslds_01"\
 --exact-id "t_glb_fau_fishslsmds_01"\
 --exact-id "t_glb_fau_ratcvds_01"\
 --exact-id "t_glb_fau_ratds_01"\
 --exact-id "t_glb_fau_seacrds_01"\
 --exact-id "t_glb_und_lichpl_01"\
 --exact-id "t_glb_und_skelcmppl_01"\
 --exact-id "t_glb_und_skelpl_01"\
 --exact-id "t_glb_und_skelwlorpl_01"\
 --exact-id "t_ham_fau_spkwormds_01"\
 --exact-id "t_mw_fau_beetleblds_01"\
 --exact-id "t_mw_fau_beetlebrds_01"\
 --exact-id "t_mw_fau_beetlegrds_01"\
 --exact-id "t_mw_fau_beetlehrds_01"\
 --exact-id "t_mw_fau_cephbgds_01"\
 --exact-id "t_mw_fau_cephds_01"\
 --exact-id "t_mw_fau_eyestds_01"\
 --exact-id "t_mw_fau_guards_01"\
 --exact-id "t_mw_fau_guarfrds_01"\
 --exact-id "t_mw_fau_kwafrgds_01"\
 --exact-id "t_mw_fau_kwaqnds_01"\
 --exact-id "t_mw_fau_kwawrds_01"\
 --exact-id "t_mw_fau_mucklchds_01"\
 --exact-id "t_mw_fau_muskfds_01"\
 --exact-id "t_mw_fau_netblds_01"\
 --exact-id "t_mw_fau_netblrcds_01"\
 --exact-id "t_mw_fau_netbtyds_01"\
 --exact-id "t_mw_fau_netbtyrcds_01"\
 --exact-id "t_mw_fau_nixhds_01"\
 --exact-id "t_mw_fau_ornds_01"\
 --exact-id "t_mw_fau_ornqnds_01"\
 --exact-id "t_mw_fau_parads_01"\
 --exact-id "t_mw_fau_paravnds_01"\
 --exact-id "t_mw_fau_skrendds_01"\
 --exact-id "t_mw_fau_trllswds_01"\
 --exact-id "t_mw_fau_tullcfds_01"\
 --exact-id "t_mw_fau_tullds_01"\
 --exact-id "t_mw_und_boneldpl_01"\
 --exact-id "t_mw_und_bonewkgrpl_01"\
 --exact-id "t_mw_und_bonewkpl_01"\
 --exact-id "t_mw_und_mumpl_01"\
 --exact-id "t_sky_cre_minods_01"\
 --exact-id "t_sky_fau_bearbkds_01"\
 --exact-id "t_sky_fau_bearbrds_01"\
 --exact-id "t_sky_fau_beargrds_01"\
 --exact-id "t_sky_fau_bearredds_01"\
 --exact-id "t_sky_fau_boards_01"\
 --exact-id "t_sky_fau_goatmnds_01"\
 --exact-id "t_sky_fau_horkerds_01"\
 --exact-id "t_sky_fau_rakids_01"\
 --exact-id "t_sky_fau_sabcatds_01"\
 --exact-id "t_sky_fau_sabcatds_02"\
 --exact-id "t_sky_fau_snowrayds_01"\
 --exact-id "t_sky_fau_wolfblads_01"\
 --exact-id "t_sky_fau_wolfgr_dis_01"\
 --exact-id "t_sky_fau_wolfredds_01"
$tes3cmd header "${result}" --hide-backups --update-record-count
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_cyr_fau_bearcolds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Colovian Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_cyr_fau_goatdis_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Weald Goat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_cyr_fau_mooncdis_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Mooncrab')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_cyr_fau_muskratds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Muskrat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_cyr_fau_ratds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Rat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_cyr_fau_wolfcolds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Colovian Wolf')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_cyr_fau_wolfcolds_02" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Highlands Wolf')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_dwe_und_ghstgrpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Greater Ghost')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_dwe_und_ghstpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Ghost')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_cre_dreuds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Dreugh')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_cre_landdreuds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Land Dreugh')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_cre_trollcaved_03" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Cave Troll')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_fau_fishslds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Slaughterfish')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_fau_fishslsmds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Small Slaughterfish')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_fau_ratcvds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Cave Rat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_fau_ratds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Rat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_fau_seacrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Sea Crab')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_und_lichpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Lich')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_und_skelcmppl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Skeleton Champion')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_und_skelpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Skeleton')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_glb_und_skelwlorpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Skeleton Warlord')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_ham_fau_spkwormds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Spikeworm')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_beetleblds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Blue Beetle')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_beetlebrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Brown Beetle')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_beetlegrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Green Beetle')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_beetlehrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Horned Beetle')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_cephbgds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Giant Cephalopod')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_cephds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Cephalopod')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_eyestds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Eyestar')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_guards_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Guar')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_guarfrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Wild Guar')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_kwafrgds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kwama Forager')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_kwaqnds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kwama Queen')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_kwawrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kwama Warrior')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_mucklchds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Muck Leech')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_muskfds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Muskfly')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_netblds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bull Netch')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_netblrcds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bull Netch')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_netbtyds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Betty Netch')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_netbtyrcds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Betty Netch')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_nixhds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Nix-Hound')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_ornds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Ornada')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_ornqnds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Ornada Queen')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_parads_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Parastylus')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_paravnds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Venomous Parastylus')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_skrendds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Sky Render')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_trllswds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Swamp Troll')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_tullcfds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Tully Calf')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_tullds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Tully')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_und_boneldpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bonelord')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_und_bonewkgrpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Greater Bonewalker')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_und_bonewkpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bonewalker')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_und_mumpl_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Mummy')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_cre_minods_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kreathi Minotaur')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_bearbkds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Black Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_bearbrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Grizzly Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_beargrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Cave Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_bearredds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Brown Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_boards_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Wild Boar')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_goatmnds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Mountain Goat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_horkerds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Horker')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_rakids_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Raki')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_sabcatds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Sabre Cat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_sabcatds_02" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Sabre Cat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_snowrayds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Snow Ray')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_wolfblads_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Black Wolf')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_wolfgr_dis_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Grey Wolf')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_sky_fau_wolfredds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Red Wolf')"

# # 06 Tamriel Rebuilt
# result="YANDL - TR_Mainland.esp"
# $tes3cmd dump "TR_Mainland.esm" --raw-with-header "${result}" --type CREA\
#  --exact-id "tr_m3_skeleton_plague"\
#  --exact-id "tr_m3_zan_lich"\
#  --exact-id "tr_m3_q_a7_bosskelp"\
#  --exact-id "tr_m1_aran_skeleton"\
#  --exact-id "tr_m1_aran_skel_ch_pla"\
#  --exact-id "tr_m1_aran_bonew_g_pla"\
#  --exact-id "tr_m1_aran_bonew_plague"
# $tes3cmd header "${result}" --hide-backups --update-record-count
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "tr_m3_skeleton_plague" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Skeleton Warrior')"
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "tr_m3_zan_lich" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Lich')"
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "tr_m3_q_a7_bosskelp" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Skeleton Warrior')"
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "tr_m1_aran_skeleton" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Skeleton')"
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "tr_m1_aran_skel_ch_pla" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Skeleton Champion')"
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "tr_m1_aran_bonew_g_pla" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Greater Bonewalker')"
# $tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "tr_m1_aran_bonew_plague" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bonewalker')"

# 07 TriangleTooth's Ecology Mod 
result="YANDL - Ttooth Ecology.esp"
$tes3cmd dump "Ttooth Ecology.esp" --raw-with-header "${result}" --type CREA\
 --exact-id "shalk_diseased"\
 --exact-id "cliff racer_diseased"\
 --exact-id "alit_diseased"\
 --exact-id "kagouti_diseased"\
 --exact-id "rat_diseased"\
 --exact-id "mudcrab-diseased"\
 --exact-id "ttooth_wolf_red_pup"\
 --exact-id "ttooth_bear_brown_cub"\
 --exact-id "bm_bear_brown"\
 --exact-id "bm_wolf_red"
$tes3cmd header "${result}" --hide-backups --update-record-count
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "shalk_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Shalk')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "cliff racer_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Cliff Racer')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "alit_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Alit')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "kagouti_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Kagouti')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "rat_diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Rat')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "mudcrab-diseased" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Mudcrab')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_bear_brown" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_wolf_red" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Wolf')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "ttooth_wolf_red_pup" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Wolf Pup')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "ttooth_bear_brown_cub" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bear Cub')"

# 08 TriangleTooth's Ecology Mod - Bloodmoon Rebalance
result="YANDL - Ttooth Ecology - BMR Patch.esp"
$tes3cmd dump "Ttooth Ecology - BMR Patch.ESP" --raw-with-header "${result}" --type CREA\
 --exact-id "bm_bear_brown"\
 --exact-id "bm_wolf_red"
$tes3cmd header "${result}" --hide-backups --update-record-count
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_bear_brown" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Bear')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "bm_wolf_red" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Wolf')"

# 09 TriangleTooth's Ecology Mod - Tamriel Rebuilt
result="YANDL - Ttooth Ecology - TR Patch.esp"
$tes3cmd dump "Ttooth Ecology - TR Patch.ESP" --raw-with-header "${result}" --type CREA\
 --exact-id "t_mw_fau_muskfds_01"\
 --exact-id "t_mw_fau_guards_01"\
 --exact-id "t_mw_fau_guarfrds_01"
$tes3cmd header "${result}" --hide-backups --update-record-count
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_muskfds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Muskfly')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_guards_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Guar')"
$tes3cmd modify "${result}" --hide-backups --type CREA --exact-id "t_mw_fau_guarfrds_01" --run "\$R->set({t=>'FNAM', f=>'Name'}, 'Feral Guar')"
