#!/usr/bin/env bash
# vim: nowrap
# Changelog:
# 2023-08-18
#   - Remove "OAAB_Tel Mora - Script Fix" with 2 dialogue script fixes(fixed upstream in v4.0.3)
#
# 2023-04-27
#   - Fix DELE fields in "Patch for Purists - Clean_Mines & Caverns - Mat" patch(remove DATA fields)
#
# 2023-04-21
#   - Add "Patch for Purists - Clean_Mines & Caverns - Mat" patch(floating items in Mat fixed)
#   - Add "OAAB Brother Junipers Twin Lamps - Script Fix" with 1 script fix(tl_invasion didn't compile on OpenMW)
#   - Add "OAAB_Tel Mora - Script Fix" with 2 dialogue script fixes
#
# 2023-04-10
#   - Remove "BTBGI - auto-calc spells" patch for QCVL because no longer auto-calc spells ;-)
#
# 2023-01-04
#   - Update Library of Vivec Overhaul - Full - Dialogue Fix
#
# 2023-01-02
#   - Add "OAAB Brother Junipers Twin Lamps - Camonna Tong Compatibility Patch"(script and npc changes merged)
#   - Add "Magical Missions - Patch for Purists"(port 1 dialogue fix from PFP, non-public)
#
# 2022-12-31
#   - Add "tribunal rebalance - Hunter's Mark"(merge changes for goblins - add rem's arrows, non-public)
#
# 2022-12-23
#   - Update "BTBGI - auto-calc spells" patch for QCVL" with newly added spells
#   - Add "Taskmaster of House Telvanni Part I - Script Fix" with 1 dialogue script fix
#   - Add "Patch for Purists - INFO Override"(non-public)
#
# 2022-12-17
#   - Add "FMI - Alice's Package - Entertainers Expanded"(merge changes for Dorisa Darvel)
#
# 2022-12-16
#   - Add "ABCmod - Dagoth Ur Voice Addon"(remove conflicts by merging changes)
#   - Add "Beware the Sixth House - Dagoth Ur Voice Addon"(remove conflicts by merging changes)
#   - Add "Almalexia_Voicev1 - PFP"(port fix from PFP)
#   - Add "Almalexia_Voicev1 - Sotha Sil Expanded"(combine dialogues to place mods in any order)
#
# 2022-12-14
#   - Remove "Staff Agency_NoModels - Script Fix"(had 1 dialogue script fix - no longer use the mod)
#
# 2022-12-13
#   - Remove "Cyrodiil_Main - Script Fix"(with 6 dialogue script fixes that are no longer needed - everything was fixed in recent release)
#   - Remove "Cyrodiil_Main - Suppress Log - OpenMW" deprecated guard faction change to prevent warning in OpenMW log(non-public)
#
# 2022-12-05
#   - Add AliceL93's Vanilla Quest Tweaks - TR_Factions Compatibility Patch(resolve conflict between mods)
#
# 2022-11-28
#   - Remove "TR_Mainland - Script Fix.esp"(Tamriel Rebuilt was updated to v22.11 and those errors are hopefully fixed now)
#   - Remove "The Minotaurs Ring - Script Fix"(no longer needed - everything's fixed)
#
# 2022-11-21
#   - Remove "SV - Terrors Of The Night Normal - Sirollus Saccus Services Override.esp"(made another patch for LGNPC)
#   - Remove "Improved Inns Expanded - Entertainers" patch for Camonna Tong(made another patch for LGNPC)
#
# 2022-10-28
#   - Remove "abotBoats - Disable Scenic Ship"
#
# 2022-10-09
#   - Remove "lack_stridersnest - No Autocalc spells.esp"(The Strider's Nest - Companions and Quests, fixed upstream)
#
# 2022-09-24
#   - Add "lack_stridersnest - No Autocalc spells.esp"(The Strider's Nest - Companions and Quests, remove autocalc flag)
#   - Add "Bloodmoon Rebalance - BT_Whitewolf_2_0_HOTV.esp"(skeleton nord_2 from BMR override, non-public)
#   - Add "SV - Terrors Of The Night Normal - Sirollus Saccus Services Override.esp"(sirollus saccus services override, non-public)
#   - Add "TeaMod_2.1 - UL_3.5_TR Doily Override.esp"(st_doily misc override, non-public)
#   - Add "Solstheim Tomb of The Snow Prince - Bloodmoon Rebalance"(merge changes of The Swimmer)
#   - Add "SHS - Bloodskal Barrow - Bloodmoon Rebalance"(bloodskal draugrs BMR override, non-public)
#   - Add "Hunter's Mark - A Marksman Mod - TOTSP TD Content Integration"(merge nordictomb cont, non-public)
#   - Add "Morrowind - DA_Sobitur Cont Override"(override sobitur's changes to daed conts, non-public) 
#   - Add and then remove "Ports Of Vvardenfell V1.6 - NPC Only - Hood and Mask - TR_Travels - TOTSP - ShrineOfAzura.esp"(add DODT to shrine, non-public), because she's a monk and doesn't provide travel services :-)
#   - Add "Patch for Purists - Book Typos - Semi-Puris Fixes.esp"(merge 4 books changes from both, non-public)
#
# 2022-11-10
#   - Remove "TeaMod_2.1 - UL_3.5_TR Doily Override.esp"(not needed, teamod should go after UL and patches)
#   - Remove "Fighters_Guild_Questline_Overhaul - Script Fix"
#   - Remove "Fighters_Guild_Questline_Overhaul - Dialogue Script Fix"
#   - Remove "Fighters_Guild_Questline_Overhaul - Enable OpenMW"
#
# 2022-09-18
#   - Add "After the Blight - Disable MWSE scripts"(non-public)
#
# 2022-09-10
#   - Add "FMI_ServiceRefusal_Contraband - After the Blight - Bolrin"(non-public)
#
# 2022-09-09
#   - Add "Master Index Naturalized - Dialogue Script Fix" with 1 dialogue script fix
#   - Add "Siege at Firemoth Naturalized - Dialogue Script Fix" with 7 dialogue script fixes
#   - Add "Siege at Firemoth Naturalized - BTBGI - Ward of Akavir Enchanting"(tone down Naturalized or boost original, resist magicka and weapons 25 -> 5)
#   - Finally merge together leveled lists patch and the main merged patch
#
# 2022-09-08
#   - Add "Camonna Tong - Adamantium Armor Integrated - UL - Anti-Cheese - Raven"(non-public)
#
# 2022-09-07
#   - Add "Missing Snow Armor - BTBGI"(bm wolf shield stats)
#   - Add "Grandfather Frost - BTBGI"(red colovian helm stats)
#   - Add "Entertainers Expanded - BTBGI"(colovian helm stats)
#
# 2022-09-06
#   - Move BTBGI patches to dedicated folder "04 BTBGI"
#
# 2022-08-09
#   - Add "Census and Excise Office Faction - BTBGI - Contraband"(change prices for giving in contraband)
#
# 2022-07-16
#   - Update "Improved Inns Expanded - Entertainers" patch for Camonna Tong(enable Barter for "Darvam Hlaren")
#
# 2022-07-15
#   - Add "RP House Hlaalu - Disable MWSE scripts"(non-public)
#
# 2022-07-09
#   - Add "riders - Your Own Ashlander Tribe" (make rider in Salit camp peaceful)
#
# 2022-06-27
#   - Add "Boys in the Hood - Balmora Waterworks" (merge changes of both mods to Heddvild NPC - both key and script)
#   - Add "FMI_HulStop 1.6 - Balmora Waterworks" (merge changes of both mods to Hul NPC - both key and script)
#
# 2022-05-16
#   - Remove "Vvardenfell Brotherhood - Dialogue Script Fix" with 1 dialogue script fix(fixed upstream)
#   - Remove "The Rise of the House Unmourned - Dialogue Script Fix" with 1 dialogue script fix(fixed upstream)
#
# 2022-05-08
#   - Make (QCVL) "Quests for Clans and Vampire Legends - Morrowind Anti-Cheese" patch(Mastrius gets weaker items)
#
# 2022-05-05
#   - Update "BTBGI - auto-calc spells" patch for QCVL" with newly added spell
#
# 2022-04-13
#   - Add "The Rise of the House Unmourned - Dialogue Script Fix" with 1 dialogue script fix(non-public)
#
# 2022-04-11
#   - Add "Vvardenfell Brotherhood - Dialogue Script Fix" with 1 dialogue script fix(non-public)
#   - Add Ashlander Traders Remastered - Script Fix Backport NoLore(non-public) with NoLore added to script from recent BCOM version
#   - Add (QCVL) "Quests for Clans and Vampire Legends - Dialogue Sotha Sil Expanded Conflict.esp"(non-public)
#
# 2022-04-09
#   - Add "VB_EmynDB_Patch - Dialogue Fix" with 4 dialogues text updated for recent version of Vvardenfell Brotherhood
#
# 2022-02-20
#   - Move "Morag Tong Polished" patch for TR_Factions from Tamriel Rebuilt into separate download
#     - Remove public and from merged. Though keep modified file here just in case
#
# 2022-02-19
#   - Add "Cyrodiil_Main" deprecated guard faction change to prevent warning in OpenMW log(non-public)
#   - Remove "Sky_Main" dialogue script patch. Everything was fixed in v22.02a
#   - Make "Morag Tong Polished" patch for TR_Factions from Tamriel Rebuilt public
#
# 2022-02-12
#   - Update "Sky_Main" dialogue script patch with 2 more dialogues(v22.02)
#
# 2022-02-11
#   - Add "Disable MWSE scripts" patch for Camonna Tong(non-public)
#
# 2022-02-10
#   - Add "Morag Tong Polished" patch for TR_Factions from Tamriel Rebuilt(non-public, wait for Caeris to produce one)
#
# 2022-02-09
#   - Add "Improved Inns Expanded - Entertainers" patch for Camonna Tong
#   - Add "BTBGI - auto-calc spells" patch for QCVL
#   - Add "Vampire Clans - Clutter Monkey Overhaul" patch for QCVL
#
# 2022-01-08
#   - Add "Area Effect Projectiles Integrated" patch for LeFemmArmor
#   - Add "Area Effect Projectiles Integrated" patch for Quill of Feyfolken
#
# 2021-12-31
#   - Add "Sottilde Lure" fixes to both FG dialogue and script fixes
#
# 2021-12-19
#   - Add "Tribunal - Rare Durzogs In Vvardenfell Caves" standalone
#   - Add "Morrowind - Tombs Leveled Lists Flag Fixed" standalone
#
# 2021-12-05
#   - Add "abotBoats - Disable Scenic Ship"
#
# 2021-11-14
#   - Remove Mudcrab Imports Pirate Adventures, fixed upstream
#
# 2021-11-12
#   - Add Wares-base - Adamantium Armor - Rare
#   - Add Library of Vivec Overhaul - Full - Dialogue Fix
#   - Add AliceL93's Vanilla Quest Tweaks - Script Fix
#
# 2021-11-11
#   - Add Mining Pick Requirement - Diamond Rocks
#   - Add Mining Pick Requirement - correctUV Ore Replacer_fixed from GH
#
# 2021-10-30
#   - Add Wyrmhaven
#
# 2021-10-25
#   - Merge script and dialogue scripts in public patches
#
# 2021-10-21
#   - Add a lot of Dialogue Script Fixes until 100% compiled
#
# 2021-10-19
#   - Add a lot of Script Fixes until 100% compiled
#
# 2021-10-18
#   - Add Enable OpenMW for Fighters_Guild_Questline_Overhaul
#   - Add Disable Rebirth for Ebonheart Underworks
# 
# 2021-10-17
#   - Remake the patch completely
#   - Integrate Frostwind patch
#

tes3cmd="./tes3cmd"

d="/tmp/__omw-misc-2"
d1="${d}/01 Merged"
d2="${d}/02 Modular"
d3="${d}/03 Modified"
d4="${d}/04 Default"
d90uni="${d}/90uni"
d5_01="${d}/05 Public/01 Misc"
d5_02="${d}/05 Public/02 Script Fix"
d5_03="${d}/05 Public/03 Creature Leveled Lists"
d5_04="${d}/05 Public/04 BTBGI"                  
o="../.."
r000="${d1}/avp_misc.esp"
s001="Morrowind.esm"
r001="${d2}/${s001%.*} - Gnisis Door Position Fix_m.esp"
r001c="${d3}/${s001%.*}_c.esp"
r001cd="${d4}/${s001%.*}_cd.esp"
p001="${d5_01}/Gnisis Tamnsumiran Door Position Fix.esp"
s002="Patch for Purists.esm"
r002="${d2}/${s002%.*} - Ajira Deflowered_m.esp"
r002n="${d3}/${s002%.*}_n.esp"
r002nd="${d4}/${s002%.*}_nd.esp"
p002="${d5_01}/Ajira Deflowered - Patch for Purists.esp"
s003="Cooking and Eating.ESP"
r003="${d2}/${s003%.*} - Enable Hunger_m.esp"
r003n="${d3}/${s003%.*}_n.esp"
r003nd="${d4}/${s003%.*}_nd.esp"
p003="${d5_01}/${s003%.*} - Enable Hunger.esp"
s004="chuzei_helm_no_neck.esp"
# o004="${o}/mods/Performance/MorrowindOptimizationPatch/0/04 Chuzei Fix/chuzei_helm_no_neck.esp"
o004="${o}/mods/Performance/MorrowindOptimizationPatch/0/03 Chuzei Fix/chuzei_helm_no_neck.esp"
r004="${d2}/${s004%.*} - BTBGI_m.esp"
r004n="${d3}/${s004%.*}_n.esp"
r004nd="${d4}/${s004%.*}_nd.esp"
p004="${d5_04}/${s004%.*} - BTBGI.esp"
s005="Frostwind.ESP"
r005="${d2}/${s005%.*} - Rebalance_m.esp"
r005n="${d3}/${s005%.*}_n.esp"
r005s="${d3}/${s005%.*}_s.esp"
r005sd="${d4}/${s005%.*}_sd.esp"
p005="${d5_01}/${s005%.*} - Rebalance - OpenMW.esp"
s006="DRPV1.9.ESP"
r006="${d2}/${s006%.*} - Script Fix_m.esp"
r006s="${d3}/${s006%.*}_s.esp"
r006sd="${d4}/${s006%.*}_sd.esp"
p006="${d5_02}/${s006%.*} - Script Fix.esp"
s007="Uvirith's Legacy_3.53.esp"
r007="${d2}/${s007%.*} - Script Fix_m.esp"
r007s="${d3}/${s007%.*}_s.esp"
r007sd="${d4}/${s007%.*}_sd.esp"
p007="${d5_02}/${s007%.*} - Script Fix.esp"
# s008="UL_3.5_TR_18.07_Add-on.esp"
# r008="${d2}/${s008%.*} - Script Fix_m.esp"
# r008s="${d3}/${s008%.*}_s.esp"
# r008sd="${d4}/${s008%.*}_sd.esp"
# p008="${d5_02}/${s008%.*} - Script Fix.esp"
s009="DA_Sobitur_Facility_Clean.ESP"
r009="${d2}/${s009%.*} - Script Fix_m.esp"
r009s="${d3}/${s009%.*}_s.esp"
r009sd="${d4}/${s009%.*}_sd.esp"
p009="${d5_02}/${s009%.*} - Script Fix.esp"
s010="DA_Sobitur_Quest_Part_1 Clean.esp"
r010="${d2}/${s010%.*} - Script Fix_m.esp"
r010s="${d3}/${s010%.*}_s.esp"
r010sd="${d4}/${s010%.*}_sd.esp"
p010="${d5_02}/${s010%.*} - Script Fix.esp"
# s011="DA_Sobitur_TRIngred_Compat.ESP"
# r011="${d2}/${s011%.*} - Script Fix_m.esp"
# r011s="${d3}/${s011%.*}_s.esp"
# r011sd="${d4}/${s011%.*}_sd.esp"
# p011="${d5_02}/${s011%.*} - Script Fix.esp"
s012="Sotha Sil Expanded.ESP"
r012="${d2}/${s012%.*} - Script Fix_m.esp"
r012s="${d3}/${s012%.*}_s.esp"
r012sd="${d4}/${s012%.*}_sd.esp"
p012="${d5_02}/${s012%.*} - Script Fix.esp"
s013="Ebonheart_Underworks.esp"
r013="${d2}/${s013%.*} - Disable Rebirth_m.esp"
r013n="${d3}/${s013%.*}_n.esp"
r013nd="${d4}/${s013%.*}_nd.esp"
p013="${d5_01}/${s013%.*} - Disable Rebirth Question.esp"
# s014="Fighters_Guild_Questline_Overhaul.ESP"
# r014="${d2}/${s014%.*} - Enable OpenMW_m.esp"
# r014s="${d3}/${s014%.*}_s_014.esp"
# r014sd="${d4}/${s014%.*}_sd_014.esp"
# p014="${d5_01}/${s014%.*} - Enable OpenMW.esp"
# s015="Fighters_Guild_Questline_Overhaul.ESP"
# r015="${d2}/${s015%.*} - Script Fix_m.esp"
# r015s="${d3}/${s015%.*}_s_015.esp"
# r015sd="${d4}/${s015%.*}_sd_015.esp"
# p015="${d5_02}/${s015%.*} - Script Fix.esp"
s016="Ashlander Traders Remastered.esp"
r016="${d2}/${s016%.*} - Script Fix_m.esp"
r016s="${d3}/${s016%.*}_s.esp"
r016sd="${d4}/${s016%.*}_sd.esp"
# p016="${d5_02}/${s016%.*} - Script Fix.esp"
s017="Clean_Mines & Caverns.esp"
r017="${d2}/${s017%.*} - Script Fix_m.esp"
r017s="${d3}/${s017%.*}_s.esp"
r017sd="${d4}/${s017%.*}_sd.esp"
p017="${d5_02}/${s017%.*} - Script Fix.esp"
s018="MoonlightOnTheOdaiRiver.esp"
r018="${d2}/${s018%.*} - Script Fix_m.esp"
r018s="${d3}/${s018%.*}_s.esp"
r018sd="${d4}/${s018%.*}_sd.esp"
p018="${d5_02}/${s018%.*} - Script Fix.esp"
s019="TeaMod_2.1.esp"
r019="${d2}/${s019%.*} - Script Fix_m.esp"
r019s="${d3}/${s019%.*}_s.esp"
r019sd="${d4}/${s019%.*}_sd.esp"
p019="${d5_02}/${s019%.*} - Script Fix.esp"
s020="The Doors of Oblivion 1.4.esp"
r020="${d2}/${s020%.*} - Script Fix_m.esp"
r020s="${d3}/${s020%.*}_s.esp"
r020sd="${d4}/${s020%.*}_sd.esp"
#p020="${d5_02}/${s020%.*} - Script Fix.esp"
s021="The Redoran Bard.esp"
r021="${d2}/${s021%.*} - Script Fix_m.esp"
r021s="${d3}/${s021%.*}_s.esp"
r021sd="${d4}/${s021%.*}_sd.esp"
#p021="${d5_02}/${s021%.*} - Script Fix.esp"
# 2022.07.10 disable these patches due to being outdated with Vvardenfell Brotherhood v1.17
# s022="VB_EmynDB_Patch.ESP"
# r022="${d2}/${s022%.*} - Script Fix_m.esp"
# r022s="${d3}/${s022%.*}_s.esp"
# r022sd="${d4}/${s022%.*}_sd.esp"
# p022="${d5_02}/${s022%.*} - Script Fix.esp"
s023="Alms and Donations.ESP"
r023="${d2}/${s023%.*} - Dialogue Script Fix_m.esp"
r023d="${d3}/${s023%.*}_d.esp"
r023dd="${d4}/${s023%.*}_dd.esp"
p023="${d5_02}/${s023%.*} - Script Fix.esp"
s024="Balmora Guilds Expanded.ESP"
r024="${d2}/${s024%.*} - Dialogue Script Fix_m.esp"
r024d="${d3}/${s024%.*}_d.esp"
r024dd="${d4}/${s024%.*}_dd.esp"
p024="${d5_02}/${s024%.*} - Script Fix.esp"
s025="The Hammer of Orsinium.esp"
r025="${d2}/${s025%.*} - Dialogue Script Fix_m.esp"
r025d="${d3}/${s025%.*}_d.esp"
r025dd="${d4}/${s025%.*}_dd.esp"
p025="${d5_02}/${s025%.*} - Script Fix.esp"
s026="MoonlightOnTheOdaiRiver.esp"
r026="${d2}/${s026%.*} - Dialogue Script Fix_m.esp"
r026d="${d3}/${s026%.*}_d.esp"
r026dd="${d4}/${s026%.*}_dd.esp"
# s027="The Minotaurs Ring.esp"
# r027="${d2}/${s027%.*} - Dialogue Script Fix_m.esp"
# r027d="${d3}/${s027%.*}_d.esp"
# r027dd="${d4}/${s027%.*}_dd.esp"
# p027="${d5_02}/${s027%.*} - Script Fix.esp"
s028="SHS - Bloodskal Barrow.ESP"
r028="${d2}/${s028%.*} - Dialogue Script Fix_m.esp"
r028d="${d3}/${s028%.*}_d.esp"
r028dd="${d4}/${s028%.*}_dd.esp"
p028="${d5_02}/${s028%.*} - Script Fix.esp"
# s029="Sky_Main.esm"
# r029="${d2}/${s029%.*} - Dialogue Script Fix_m.esp"
# r029d="${d3}/${s029%.*}_d.esp"
# r029dd="${d4}/${s029%.*}_dd.esp"
# p029="${d5_02}/${s029%.*} - Script Fix.esp"
s030="The Great Fantasco.ESP"
r030="${d2}/${s030%.*} - Dialogue Script Fix_m.esp"
r030d="${d3}/${s030%.*}_d.esp"
r030dd="${d4}/${s030%.*}_dd.esp"
p030="${d5_02}/${s030%.*} - Script Fix.esp"
s031="Wanderers of Solstheim-TOTSP.ESP"
r031="${d2}/${s031%.*} - Dialogue Script Fix_m.esp"
r031d="${d3}/${s031%.*}_d.esp"
r031dd="${d4}/${s031%.*}_dd.esp"
p031="${d5_02}/${s031%.*} - Script Fix.esp"
s032="DD_Caldera_Expansion.esp"
r032="${d2}/${s032%.*} - Dialogue Script Fix_m.esp"
r032d="${d3}/${s032%.*}_d.esp"
r032dd="${d4}/${s032%.*}_dd.esp"
p032="${d5_02}/${s032%.*} - Script Fix.esp"
# s033="Staff Agency_NoModels.esp"
# r033="${d2}/${s033%.*} - Dialogue Script Fix_m.esp"
# r033d="${d3}/${s033%.*}_d.esp"
# r033dd="${d4}/${s033%.*}_dd.esp"
# p033="${d5_02}/${s033%.*} - Script Fix.esp"
s034="The Doors of Oblivion 1.4.esp"
r034="${d2}/${s034%.*} - Dialogue Script Fix_m.esp"
r034d="${d3}/${s034%.*}_d.esp"
r034dd="${d4}/${s034%.*}_dd.esp"
p034="${d5_02}/${s034%.*} - Script Fix.esp"
s035="CCM-SecretsofVos-V2-TB.esp"
r035="${d2}/${s035%.*} - Dialogue Script Fix_m.esp"
r035d="${d3}/${s035%.*}_d.esp"
r035dd="${d4}/${s035%.*}_dd.esp"
p035="${d5_02}/${s035%.*} - Script Fix.esp"
# s036="Mudcrab Imports Pirate Adventures.esp"
# r036="${d2}/${s036%.*} - Dialogue Script Fix_m.esp"
# r036d="${d3}/${s036%.*}_d.esp"
# r036dd="${d4}/${s036%.*}_dd.esp"
# p036="${d5_02}/${s036%.*} - Script Fix.esp"
# s037="TR_Mainland.esm"
# r037="${d2}/${s037%.*} - Dialogue Script Fix_m.esp"
# r037d="${d3}/${s037%.*}_d.esp"
# r037dd="${d4}/${s037%.*}_dd.esp"
# p037="${d5_02}/${s037%.*} - Script Fix.esp"
# s038="Cyrodiil_Main.esm"
# r038="${d2}/${s038%.*} - Dialogue Script Fix_m.esp"
# r038d="${d3}/${s038%.*}_d.esp"
# r038dd="${d4}/${s038%.*}_dd.esp"
# p038="${d5_02}/${s038%.*} - Script Fix.esp"
s039="Uvirith's Legacy_3.53.esp"
r039="${d2}/${s039%.*} - Dialogue Script Fix_m.esp"
r039d="${d3}/${s039%.*}_d.esp"
r039dd="${d4}/${s039%.*}_dd.esp"
# s040="Fighters_Guild_Questline_Overhaul.ESP"
# r040="${d2}/${s040%.*} - Dialogue Script Fix_m.esp"
# r040d="${d3}/${s040%.*}_d.esp"
# r040dd="${d4}/${s040%.*}_dd.esp"
s041="Wyrmhaven.esm"
r041="${d2}/${s041%.*} - Script Fix_m.esp"
r041s="${d3}/${s041%.*}_s.esp"
r041sd="${d4}/${s041%.*}_sd.esp"
p041="${d5_02}/${s041%.*} - Script Fix.esp"
s042="Wyrmhaven.esm"
r042="${d2}/${s042%.*} - Hlarvis Dren_m.esp"
r042n="${d3}/${s042%.*}_n.esp"
r042nd="${d4}/${s042%.*}_nd.esp"
p042="${d5_01}/${s042%.*} - Hlarvis Dren - OpenMW.esp"
s043="Morrowind.esm"
r043="${d2}/${s043%.*} - MPR_m.esp"
r043n="${d3}/${s043%.*}_MPR_n.esp"
r043nd="${d4}/${s043%.*}_MPR_nd.esp"
p043="${d5_01}/Mining Pick Requirement - Diamond Rocks.esp"
s044="correctUV Ore Replacer_fixed.esp"
r044="${d2}/${s044%.*} - MPR_m.esp"
r044n="${d3}/${s044%.*}_MPR_n.esp"
r044nd="${d4}/${s044%.*}_MPR_nd.esp"
p044="${d5_01}/Mining Pick Requirement - correctUV Ore Replacer_fixed from GH.esp"
s045="Wares-base.esm"
r045="${d2}/${s045%.*} - Adamantium Armor - Rare_m.esp"
r045n="${d3}/${s045%.*}_Adamantium Armor - Rare_n.esp"
r045nd="${d4}/${s045%.*}_Adamantium Armor - Rare_nd.esp"
p045="${d5_01}/Wares-base - Adamantium Armor - Rare.esp"
s046="Library of Vivec Overhaul - Full.esp"
r046="${d2}/${s046%.*} - Dialogue Fix_m.esp"
r046n="${d3}/${s046%.*}_Dialogue Fix_n.esp"
r046nd="${d4}/${s046%.*}_Dialogue Fix_nd.esp"
p046="${d5_01}/${s046%.*} - Dialogue Fix.esp"
s047="The_Vanilla_Quest_Tweaks_RP_Choices_Consequences_Super_Mega_Package_-_Ultimate_Edition.ESP"
r047="${d2}/AliceL93 Vanilla Quest Tweaks - Dialogue Script Fix_m.esp"
r047d="${d3}/AliceL93 Vanilla Quest Tweaks_d.esp"
r047dd="${d4}/AliceL93 Vanilla Quest Tweaks_dd.esp"
p047="${d5_02}/AliceL93 Vanilla Quest Tweaks - Script Fix.esp"
# s048="abotBoatsTR2101.esp"
# r048="${d2}/${s048%.*} - Disable Scenic Ship_m.esp"
# r048n="${d3}/${s048%.*}_n.esp"
# r048nd="${d4}/${s048%.*}_nd.esp"
# p048="${d5_01}/${s048%.*} - Disable Scenic Ship.esp"
r049l="${d3}/Tribunal - Rare Durzogs In Vvardenfell Caves_l.esp"
p049="${d5_03}/Tribunal - Rare Durzogs In Vvardenfell Caves.esp"
r050l="${d3}/Morrowind - Tombs Leveled Lists Flag Fixed_l.esp"
p050="${d5_03}/Morrowind - Tombs Leveled Lists Flag Fixed.esp"
# 2022-09-09 - Finally merge together leveled lists patch and the main merged patch
# rm050="${d1}/Tombs Leveled Lists Flag Fixed And Rare Durzogs In Caves.esp"
s051="Area Effect Projectiles Integrated.esp"
r051="${d2}/${s051%.*} - LeFemmArmor_m.esp"
r051n="${d3}/${s051%.*}_LeFemmArmor_n.esp"
r051nd="${d4}/${s051%.*}_LeFemmArmor_nd.esp"
p051="${d5_01}/${s051%.*} - LeFemmArmor.esp"
s052="Area Effect Projectiles Integrated.esp"
r052="${d2}/${s052%.*} - Quill of Feyfolken 2.0_m.esp"
r052n="${d3}/${s052%.*}_Quill of Feyfolken 2.0_n.esp"
r052nd="${d4}/${s052%.*}_Quill of Feyfolken 2.0_nd.esp"
p052="${d5_01}/${s052%.*} - Quill of Feyfolken 2.0.esp"
# s053="Camonna Tong.esp"
# r053="${d2}/${s053%.*} - Improved Inns Expanded - Entertainers_m.esp"
# r053n="${d3}/${s053%.*}_Improved Inns Expanded - Entertainers_n.esp"
# r053nd="${d4}/${s053%.*}_Improved Inns Expanded - Entertainers_nd.esp"
# p053="${d5_01}/${s053%.*} - Improved Inns Expanded - Entertainers.esp"
# s054="Quests for Clans and Vampire Legends.ESP"
# r054="${d2}/${s054%.*} - BTBGI - auto-calc spells_m.esp"
# r054n="${d3}/${s054%.*}_BTBGI - auto-calc spells_n.esp"
# r054nd="${d4}/${s054%.*}_BTBGI - auto-calc spells_nd.esp"
# p054="${d5_04}/${s054%.*} - BTBGI - auto-calc spells.esp"
s055="Quests for Clans and Vampire Legends.ESP"
r055="${d2}/${s055%.*} - Vampire Clans - Clutter Monkey Overhaul_m.esp"
r055c="${d3}/${s055%.*}_Vampire Clans - Clutter Monkey Overhaul_c.esp"
r055cd="${d4}/${s055%.*}_Vampire Clans - Clutter Monkey Overhaul_cd.esp"
p055="${d5_01}/${s055%.*} - Vampire Clans - Clutter Monkey Overhaul.esp"
r055uni="${d90uni}/${s055%.*} - Vampire Clans - Clutter Monkey Overhaul_uni.esp"
# s056="TR_Factions.esp"
# r056="${d2}/${s056%.*} - Morag Tong Polished_m.esp"
# r056s="${d3}/${s056%.*}_s.esp"
# r056sd="${d4}/${s056%.*}_sd.esp"
# p056="${d5_01}/${s056%.*} - Morag Tong Polished.esp"
s057="Camonna Tong.esp"
r057="${d2}/${s057%.*} - Disable MWSE-scripts_m.esp"
r057s="${d3}/${s057%.*}_Disable MWSE-scripts_s.esp"
r057sd="${d4}/${s057%.*}_Disable MWSE-scripts_sd.esp"
# p057="${d5_02}/${s057%.*} - Disable MWSE-scripts.esp"
# s058="Cyrodiil_Main.esm"
# r058="${d2}/${s058%.*} - Suppress Log - OpenMW_m.esp"
# r058n="${d3}/${s058%.*}_n.esp"
# r058nd="${d4}/${s058%.*}_nd.esp"
# p058="${d5_02}/${s058%.*} - Suppress Log - OpenMW.esp"
# 2022.07.10 disable these patches due to being outdated with Vvardenfell Brotherhood v1.17
# s059="VB_EmynDB_Patch.ESP"
# r059="${d2}/${s059%.*} - Dialogue Fix_m.esp"
# r059n="${d3}/${s059%.*}_Dialogue Fix_n.esp"
# r059nd="${d4}/${s059%.*}_Dialogue Fix_nd.esp"
# p059="${d5_01}/${s059%.*} - Dialogue Fix.esp"
# s060="Vvardenfell Brotherhood.esp"
# r060="${d2}/${s060%.*} - Dialogue Script Fix_m.esp"
# r060d="${d3}/${s060%.*}_Dialogue Script Fix_n.esp"
# r060dd="${d4}/${s060%.*}_Dialogue Script Fix_nd.esp"
# p060="${d5_02}/${s060%.*} - Dialogue Script Fix.esp"
s061="Ashlander Traders Remastered.esp"
r061="${d2}/${s061%.*} - Script Fix Backport NoLore_m.esp"
r061s="${d3}/${s061%.*}_BackportNoLore_s.esp"
r061sd="${d4}/${s061%.*}_BackportNoLore_sd.esp"
# p061="${d5_01}/${s061%.*} - Script Fix Backport NoLore.esp"
s062="Quests for Clans and Vampire Legends.ESP"
r062="${d2}/${s062%.*} - Dialogue Sotha Sil Expanded Conflict_m.esp"
r062d="${d3}/${s062%.*}_Dialogue Sotha Sil Expanded Conflict_n.esp"
r062dd="${d4}/${s062%.*}_Dialogue Sotha Sil Expanded Conflict_nd.esp"
# p062="${d5_02}/${s062%.*} - Dialogue Sotha Sil Expanded Conflict.esp"
# s063="The Rise of the Tribe Unmourned.esp"
# r063="${d2}/${s063%.*} - Dialogue Script Fix_m.esp"
# r063d="${d3}/${s063%.*}_Dialogue Script Fix_n.esp"
# r063dd="${d4}/${s063%.*}_Dialogue Script Fix_nd.esp"
# p063="${d5_02}/${s063%.*} - Dialogue Script Fix.esp"
s064="Quests for Clans and Vampire Legends.ESP"
r064="${d2}/${s064%.*} - Morrowind Anti-Cheese_m.esp"
r064n="${d3}/${s064%.*}_Morrowind Anti-Cheese_n.esp"
r064nd="${d4}/${s064%.*}_Morrowind Anti-Cheese_nd.esp"
p064="${d5_01}/${s064%.*} - Morrowind Anti-Cheese.esp"
s065="Boys in the Hood.ESP"
r065="${d2}/${s065%.*} - Balmora Waterworks_m.esp"
r065n="${d3}/${s065%.*}_Balmora Waterworks_n.esp"
r065nd="${d4}/${s065%.*}_Balmora Waterworks_nd.esp"
p065="${d5_01}/${s065%.*} - Balmora Waterworks.esp"
s066="FMI_HulStop 1.6.ESP"
r066="${d2}/${s066%.*} - Balmora Waterworks_m.esp"
r066n="${d3}/${s066%.*}_Balmora Waterworks_n.esp"
r066nd="${d4}/${s066%.*}_Balmora Waterworks_nd.esp"
p066="${d5_01}/${s066%.*} - Balmora Waterworks.esp"
s067="riders.esp"
r067="${d2}/${s067%.*} - Your Own Ashlander Tribe_m.esp"
r067n="${d3}/${s067%.*}_Your Own Ashlander Tribe_n.esp"
r067nd="${d4}/${s067%.*}_Your Own Ashlander Tribe_nd.esp"
p067="${d5_01}/${s067%.*} - Your Own Ashlander Tribe.esp"
s068="RP House Hlaalu.esp"
r068="${d2}/${s068%.*} - Disable MWSE-scripts_m.esp"
r068s="${d3}/${s068%.*}_Disable MWSE-scripts_s.esp"
r068sd="${d4}/${s068%.*}_Disable MWSE-scripts_sd.esp"
# p068="${d5_02}/${s068%.*} - Disable MWSE-scripts.esp"
s069="Census_and_Excise_Office_Faction.ESP"
r069="${d2}/${s069%.*} - BTBGI - Contraband_m.esp"
r069s="${d3}/${s069%.*}_BTBGI - Contraband_n.esp"
r069sd="${d4}/${s069%.*}_BTBGI - Contraband_nd.esp"
p069="${d5_04}/${s069%.*} - BTBGI - Contraband.esp"
s070="Missing snow armor.esp"
r070="${d2}/${s070%.*} - BTBGI_m.esp"
r070n="${d3}/${s070%.*}_BTBGI_n.esp"
r070nd="${d4}/${s070%.*}_BTBGI_nd.esp"
p070="${d5_04}/${s070%.*} - BTBGI.esp"
s071="Grandfather Frost - TOTSP.ESP"
r071="${d2}/${s071%.*} - BTBGI_m.esp"
r071n="${d3}/${s071%.*}_BTBGI_n.esp"
r071nd="${d4}/${s071%.*}_BTBGI_nd.esp"
p071="${d5_04}/${s071%.*} - BTBGI.esp"
s072="Entertainers Expanded.esp"
r072="${d2}/${s072%.*} - BTBGI_m.esp"
r072n="${d3}/${s072%.*}_BTBGI_n.esp"
r072nd="${d4}/${s072%.*}_BTBGI_nd.esp"
p072="${d5_04}/${s072%.*} - BTBGI.esp"
s073="Camonna Tong.esp"
r073="${d2}/${s073%.*} - Adamantium Armor Integrated - UL - Anti-Cheese - Raven_m.esp"
r073n="${d3}/${s073%.*}_Adamantium Armor Integrated - UL - Anti-Cheese - Raven_n.esp"
r073nd="${d4}/${s073%.*}_Adamantium Armor Integrated - UL - Anti-Cheese - Raven_nd.esp"
# p073="${d5_04}/${s073%.*} - Adamantium Armor Integrated - UL - Anti-Cheese - Raven.esp"
s074="Siege at Firemoth Naturalized.esp"
r074="${d2}/${s074%.*} - BTBGI - Ward of Akavir Enchanting_m.esp"
r074n="${d3}/${s074%.*}_BTBGI - Ward of Akavir Enchanting_n.esp"
r074nd="${d4}/${s074%.*}_BTBGI - Ward of Akavir Enchanting_nd.esp"
p074="${d5_04}/${s074%.*} - BTBGI - Ward of Akavir Enchanting.esp"
s075="Master Index Naturalized.esp"
r075="${d2}/${s075%.*} - Dialogue Script Fix_m.esp"
r075d="${d3}/${s075%.*}_d.esp"
r075dd="${d4}/${s075%.*}_dd.esp"
p075="${d5_02}/${s075%.*} - Script Fix.esp"
s076="Siege at Firemoth Naturalized.esp"
r076="${d2}/${s076%.*} - Dialogue Script Fix_m.esp"
r076d="${d3}/${s076%.*}_d.esp"
r076dd="${d4}/${s076%.*}_dd.esp"
p076="${d5_02}/${s076%.*} - Script Fix.esp"
s077="FMI_ServiceRefusal_Contraband.ESP"
r077="${d2}/${s077%.*} - After the Blight - Bolrin_m.esp"
r077n="${d3}/${s077%.*}_After the Blight - Bolrin_n.esp"
r077nd="${d4}/${s077%.*}_After the Blight - Bolrin_nd.esp"
# p077="${d5_04}/${s077%.*} - After the Blight - Bolrin.esp"
s078="After the Blight.esp"
r078="${d2}/${s078%.*} - Disable MWSE-scripts_m.esp"
r078s="${d3}/${s078%.*}_Disable MWSE-scripts_s.esp"
r078sd="${d4}/${s078%.*}_Disable MWSE-scripts_sd.esp"
# p078="${d5_02}/${s078%.*} - Disable MWSE-scripts.esp"
# s079="lack_stridersnest.esp"
# r079="${d2}/${s079%.*} - No Autocalc spells_m.esp"
# r079n="${d3}/${s079%.*}_No Autocalc spells_d.esp"
# r079nd="${d4}/${s079%.*}_No Autocalc spells_dd.esp"
# p079="${d5_01}/${s079%.*} - No Autocalc spells.esp"
s080="Bloodmoon Rebalance.esp"
r080="${d2}/${s080%.*} - BT_Whitewolf_2_0_HOTV_m.esp"
r080n="${d3}/${s080%.*}_BT_Whitewolf_2_0_HOTV_d.esp"
r080nd="${d4}/${s080%.*}_BT_Whitewolf_2_0_HOTV_dd.esp"
# p080="${d5_01}/${s080%.*} - BT_Whitewolf_2_0_HOTV.esp"
# s081="SV - Terrors Of The Night Normal.ESP"
# r081="${d2}/${s081%.*} - Sirollus Saccus Override_m.esp"
# r081n="${d3}/${s081%.*}_Sirollus Saccus Override_d.esp"
# r081nd="${d4}/${s081%.*}_Sirollus Saccus Override_dd.esp"
# # p081="${d5_01}/${s081%.*} - Sirollus Saccus Override.esp"
# s082="TeaMod_2.1.esp"
# r082="${d2}/${s082%.*} - UL_3.5_TR Doily Override_m.esp"
# r082n="${d3}/${s082%.*}_UL_3.5_TR Doily Override_d.esp"
# r082nd="${d4}/${s082%.*}_UL_3.5_TR Doily Override_dd.esp"
# # p082="${d5_01}/${s082%.*} - UL_3.5_TR Doily Override.esp"
s083="Solstheim Tomb of The Snow Prince.esm"
r083="${d2}/${s083%.*} - Bloodmoon Rebalance_m.esp"
r083n="${d3}/${s083%.*}_Bloodmoon Rebalance_d.esp"
r083nd="${d4}/${s083%.*}_Bloodmoon Rebalance_dd.esp"
p083="${d5_01}/${s083%.*} - Bloodmoon Rebalance.esp"
s084="SHS - Bloodskal Barrow.ESP"
r084="${d2}/${s084%.*} - Bloodmoon Rebalance_m.esp"
r084n="${d3}/${s084%.*}_Bloodmoon Rebalance_d.esp"
r084nd="${d4}/${s084%.*}_Bloodmoon Rebalance_dd.esp"
# p084="${d5_01}/${s084%.*} - Bloodmoon Rebalance.esp"
s085="Hunter's Mark - A Marksman Mod.ESP"
r085="${d2}/${s085%.*} - TOTSP TD Content Integration_m.esp"
r085n="${d3}/${s085%.*}_TOTSP TD Content Integration_d.esp"
r085nd="${d4}/${s085%.*}_TOTSP TD Content Integration_dd.esp"
# p085="${d5_01}/${s085%.*} - TOTSP TD Content Integration.esp"
s086="Morrowind.esm"
r086="${d2}/${s086%.*} - DA_Sobitur Cont Override_m.esp"
r086n="${d3}/${s086%.*}_DA_Sobitur Cont Override_d.esp"
r086nd="${d4}/${s086%.*}_DA_Sobitur Cont Override_dd.esp"
# p086="${d5_01}/${s086%.*} - DA_Sobitur Cont Override.esp"
s087="Patch for Purists - Book Typos.ESP"
r087="${d2}/${s087%.*} - Semi-Puris Fixes_m.esp"
r087n="${d3}/${s087%.*}_Semi-Puris Fixes_d.esp"
r087nd="${d4}/${s087%.*}_Semi-Puris Fixes_dd.esp"
# p087="${d5_01}/${s087%.*} - Semi-Puris Fixes.esp"
s088="The_Vanilla_Quest_Tweaks_RP_Choices_Consequences_Super_Mega_Package_-_Ultimate_Edition.ESP"
r088="${d2}/AliceL93 Vanilla Quest Tweaks - TR_Factions_m.esp"
r088d="${d3}/AliceL93 Vanilla Quest Tweaks - TR_Factions_d.esp"
r088dd="${d4}/AliceL93 Vanilla Quest Tweaks - TR_Factions_dd.esp"
p088="${d5_01}/AliceL93 Vanilla Quest Tweaks - TR_Factions Compatibility Patch.esp"
s089="ABCmod.ESP"
r089="${d2}/${s089%.*} - Dagoth Ur Voice Addon_m.esp"
r089n="${d3}/${s089%.*}_Dagoth Ur Voice Addon_n.esp"
r089nd="${d4}/${s089%.*}_Dagoth Ur Voice Addon_nd.esp"
p089="${d5_01}/${s089%.*} - Dagoth Ur Voice Addon.esp"
s090="Beware the Sixth House.ESP"
r090="${d2}/${s090%.*} - Dagoth Ur Voice Addon_m.esp"
r090n="${d3}/${s090%.*}_Dagoth Ur Voice Addon_n.esp"
r090nd="${d4}/${s090%.*}_Dagoth Ur Voice Addon_nd.esp"
p090="${d5_01}/${s090%.*} - Dagoth Ur Voice Addon.esp"
s091="Patch for Purists.esm"
r091="${d2}/Almalexia_Voicev1 - PFP_m.esp"
r091d="${d3}/Almalexia_Voicev1 - PFP_d.esp"
r091dd="${d4}/Almalexia_Voicev1 - PFP_dd.esp"
p091="${d5_01}/Almalexia_Voicev1 - PFP.esp"
s092="Almalexia_Voicev1.esp"
r092="${d2}/${s092%.*} - Sotha Sil Expanded_m.esp"
r092d="${d3}/${s092%.*}_Sotha Sil Expanded_d.esp"
r092dd="${d4}/${s092%.*}_Sotha Sil Expanded_dd.esp"
p092="${d5_01}/${s092%.*} - Sotha Sil Expanded.esp"
s093="FMI - Alice's Package.ESP"
r093="${d2}/${s093%.*} - Entertainers Expanded_m.esp"
r093n="${d3}/${s093%.*}_Entertainers Expanded_n.esp"
r093nd="${d4}/${s093%.*}_Entertainers Expanded_nd.esp"
p093="${d5_01}/${s093%.*} - Entertainers Expanded.esp"
s094="Taskmaster of House Telvanni Part I.ESP"
r094="${d2}/${s094%.*} - Dialogue Script Fix_m.esp"
r094d="${d3}/${s094%.*}_d.esp"
r094dd="${d4}/${s094%.*}_dd.esp"
p094="${d5_02}/${s094%.*} - Script Fix.esp"
s095="Patch for Purists.esm"
r095="${d2}/${s095%.*} - INFO Override_m.esp"
r095d="${d3}/${s095%.*}_d.esp"
r095dd="${d4}/${s095%.*}_dd.esp"
# p095="${d5_01}/${s095%.*} - INFO Override.esp"
s096="tribunal rebalance.ESP"
r096="${d2}/${s096%.*} - Hunter's Mark_m.esp"
r096n="${d3}/${s096%.*}_Hunter's Mark_n.esp"
r096nd="${d4}/${s096%.*}_Hunter's Mark_nd.esp"
# p096="${d5_01}/${s096%.*} - Hunter's Mark.esp"
s097="Patch for Purists.esm"
r097="${d2}/Magical Missions - Patch for Purists_m.esp"
r097d="${d3}/Magical Missions_d.esp"
r097dd="${d4}/Magical Missions_dd.esp"
# p097="${d5_02}/${s097%.*} - Patch for Purists.esp"
s098="OAAB Brother Junipers Twin Lamps.esp"
r098="${d2}/${s098%.*} - Camonna Tong Compatibility Patch_m.esp"
r098s="${d3}/${s098%.*}_s.esp"
r098sd="${d4}/${s098%.*}_sd.esp"
p098="${d5_01}/${s098%.*} - Camonna Tong Compatibility Patch.esp"
s099="Patch for Purists.esm"
r099="${d2}/${s099%.*} - Clean_Mines & Caverns - Mat_m.esp"
r099c="${d3}/${s099%.*}_Clean_Mines & Caverns - Mat_c.esp"
r099cd="${d4}/${s099%.*}_Clean_Mines & Caverns - Mat_cd.esp"
p099="${d5_01}/${s099%.*} - Clean_Mines & Caverns - Mat.esp"
s100="OAAB Brother Junipers Twin Lamps.esp"
r100="${d2}/${s100%.*} - Script Fix_m.esp"
r100s="${d3}/${s100%.*}_Script Fix_s.esp"
r100sd="${d4}/${s100%.*}_Script Fix_sd.esp"
p100="${d5_02}/${s100%.*} - Script Fix.esp"
# s101="OAAB_Tel Mora.ESP"
# r101="${d2}/${s101%.*} - Dialogue Script Fix_m.esp"
# r101d="${d3}/${s101%.*}_d.esp"
# r101dd="${d4}/${s101%.*}_dd.esp"
# p101="${d5_02}/${s101%.*} - Script Fix.esp"

if [ -z "${TMPDIR}" ]; then
  tmpdir_infix="misc"
  tmpdir_root="/tmp"
  tmpdir_prefix="tmp.__omw-"
  tmpdir_pattern="${tmpdir_prefix}${tmpdir_infix}-XXXXXXXXXX"
  fd -t d --changed-before 1h "${tmpdir_prefix}" "${tmpdir_root}" -x rm -r {}
  TMPDIR="$(mktemp --directory --tmpdir=${tmpdir_root} "${tmpdir_pattern}")"
  export TMPDIR
fi

tmpd="$(mktemp -d)"

main() {
if [ "${1}" = "install" ]; then

  if [ ! -d "${d1}" ]\
    || [ ! -d "${d2}" ]\
    || [ ! -d "${d3}" ]\
    || [ ! -d "${d4}" ]\
    || [ ! -d "${d90uni}" ]\
    || [ ! -d "${d5_01}" ]\
    || [ ! -d "${d5_02}" ]\
    || [ ! -d "${d5_03}" ]\
    || [ ! -d "${d5_04}" ]; then
      return 1
  fi

# 00. Merged version assembling
tlog="$(mktemp)"
{
if [ -s "${r000}" ]; then mv -v "${r000}" "${r000##*/}.BAK" 2>&1; fi
# $tes3cmd dump "${r001c}" --raw "${r000}" --type TES3 --type CELL 2>&1
$tes3cmd dump "${r099c}" --raw "${r000}" --type TES3 --type CELL 2>&1
# r055uni changes
# $tes3cmd dump "${r055c}" --raw "${r000}" --type CELL 2>&1

# $tes3cmd modify "${r000}" --hide-backups --backup-dir "${tmpd}"\
#   --type TES3\
#   --run "\
#   \$R->append(TES3::MAST->new({'master', '${s055}'})),\
#   \$R->append(TES3::DATA->new({'length', '2929882'}))"\
#   2>&1
# $tes3cmd modify "${r000}" --hide-backups --backup-dir "${tmpd}"\
#   --type CELL\
#   --exact-id "galom daeus, observatory"\
#   --run "\$R->set({i=>[2], f=>'MastIdx'}, '5')"\
#   2>&1 | tee -a "${tlog}"
$tes3cmd header "${r000}" --hide-backups --backup-dir "${tmpd}" --synchronize 2>&1

$tes3cmd dump "${r001c}" --raw "${r000}" --type CELL 2>&1

if [ -s "${r001}" ]; then rm -v "${r001}" 2>&1; fi
$tes3cmd dump "${r001c}" --raw "${r001}" --type TES3 --type CELL 2>&1
if [ -s "${p001}" ]; then rm -v "${p001}" 2>&1; fi
$tes3cmd dump "${r001c}" --raw "${p001}" --type TES3 --type CELL 2>&1

if [ -s "${r055}" ]; then rm -v "${r055}" 2>&1; fi
$tes3cmd dump "${r055c}" --raw "${r055}" --type TES3 --type CELL 2>&1
if [ -s "${p055}" ]; then rm -v "${p055}" 2>&1; fi
$tes3cmd dump "${r055c}" --raw "${p055}" --type TES3 --type CELL 2>&1
if [ -s "${r055uni}" ]; then rm -v "${r055uni}" 2>&1; fi
$tes3cmd dump "${r055c}" --raw "${r055uni}" --type TES3 --type CELL 2>&1

if [ -s "${r099}" ]; then rm -v "${r099}" 2>&1; fi
$tes3cmd dump "${r099c}" --raw "${r099}" --type TES3 --type CELL 2>&1
if [ -s "${p099}" ]; then rm -v "${p099}" 2>&1; fi
$tes3cmd dump "${r099c}" --raw "${p099}" --type TES3 --type CELL 2>&1

$tes3cmd dump "${r002n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r002n}" --raw-with-header "${r002}" --type NPC_ 2>&1
$tes3cmd dump "${r002n}" --raw-with-header "${p002}" --type NPC_ 2>&1
$tes3cmd dump "${r003n}" --raw "${r000}" --type GLOB 2>&1
$tes3cmd dump "${r003n}" --raw-with-header "${r003}" --type GLOB 2>&1
$tes3cmd dump "${r003n}" --raw-with-header "${p003}" --type GLOB 2>&1
$tes3cmd dump "${r004n}" --raw "${r000}" --type ARMO 2>&1
$tes3cmd dump "${r004n}" --raw-with-header "${r004}" --type ARMO 2>&1
$tes3cmd dump "${r004n}" --raw-with-header "${p004}" --type ARMO 2>&1
$tes3cmd dump "${r005n}" --raw "${r000}" --type GLOB 2>&1
$tes3cmd dump "${r005n}" --raw-with-header "${r005}" --type GLOB 2>&1
$tes3cmd dump "${r005n}" --raw-with-header "${p005}" --type GLOB 2>&1
$tes3cmd dump "${r005s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r005s}" --raw "${r005}" --type SCPT 2>&1
$tes3cmd dump "${r005s}" --raw "${p005}" --type SCPT 2>&1
$tes3cmd header "${r005}" --hide-backups --backup-dir "${tmpd}" --update-record-count 2>&1
$tes3cmd header "${p005}" --hide-backups --backup-dir "${tmpd}" --update-record-count 2>&1
$tes3cmd dump "${r006s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r006s}" --raw-with-header "${r006}" --type SCPT 2>&1
$tes3cmd dump "${r006s}" --raw-with-header "${p006}" --type SCPT 2>&1
$tes3cmd dump "${r007s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r007s}" --raw-with-header "${r007}" --type SCPT 2>&1
$tes3cmd dump "${r007s}" --raw-with-header "${p007}" --type SCPT 2>&1
# $tes3cmd dump "${r008s}" --raw "${r000}" --type SCPT 2>&1
# $tes3cmd dump "${r008s}" --raw-with-header "${r008}" --type SCPT 2>&1
# $tes3cmd dump "${r008s}" --raw-with-header "${p008}" --type SCPT 2>&1
$tes3cmd dump "${r009s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r009s}" --raw-with-header "${r009}" --type SCPT 2>&1
$tes3cmd dump "${r009s}" --raw-with-header "${p009}" --type SCPT 2>&1
$tes3cmd dump "${r010s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r010s}" --raw-with-header "${r010}" --type SCPT 2>&1
$tes3cmd dump "${r010s}" --raw-with-header "${p010}" --type SCPT 2>&1
# $tes3cmd dump "${r011s}" --raw "${r000}" --type SCPT 2>&1
# $tes3cmd dump "${r011s}" --raw-with-header "${r011}" --type SCPT 2>&1
# $tes3cmd dump "${r011s}" --raw-with-header "${p011}" --type SCPT 2>&1
$tes3cmd dump "${r012s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r012s}" --raw-with-header "${r012}" --type SCPT 2>&1
$tes3cmd dump "${r012s}" --raw-with-header "${p012}" --type SCPT 2>&1
$tes3cmd dump "${r013n}" --raw "${r000}" --type GLOB 2>&1
$tes3cmd dump "${r013n}" --raw-with-header "${r013}" --type GLOB 2>&1
$tes3cmd dump "${r013n}" --raw-with-header "${p013}" --type GLOB 2>&1
# $tes3cmd dump "${r014s}" --raw "${r000}" --type SCPT 2>&1
# $tes3cmd dump "${r014s}" --raw-with-header "${r014}" --type SCPT 2>&1
# $tes3cmd dump "${r014s}" --raw-with-header "${p014}" --type SCPT 2>&1
# $tes3cmd dump "${r015s}" --raw "${r000}" --type SCPT 2>&1
# $tes3cmd dump "${r015s}" --raw-with-header "${r015}" --type SCPT 2>&1
# $tes3cmd dump "${r015s}" --raw-with-header "${p015}" --type SCPT 2>&1
$tes3cmd dump "${r016s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r016s}" --raw-with-header "${r016}" --type SCPT 2>&1
#$tes3cmd dump "${r016s}" --raw-with-header "${p016}" --type SCPT 2>&1
$tes3cmd dump "${r017s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r017s}" --raw-with-header "${r017}" --type SCPT 2>&1
$tes3cmd dump "${r017s}" --raw-with-header "${p017}" --type SCPT 2>&1
$tes3cmd dump "${r018s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r018s}" --raw-with-header "${r018}" --type SCPT 2>&1
$tes3cmd dump "${r018s}" --raw-with-header "${p018}" --type SCPT 2>&1
$tes3cmd dump "${r019s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r019s}" --raw-with-header "${r019}" --type SCPT 2>&1
$tes3cmd dump "${r019s}" --raw-with-header "${p019}" --type SCPT 2>&1
$tes3cmd dump "${r020s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r020s}" --raw-with-header "${r020}" --type SCPT 2>&1
#$tes3cmd dump "${r020s}" --raw-with-header "${p020}" --type SCPT 2>&1
$tes3cmd dump "${r021s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r021s}" --raw-with-header "${r021}" --type SCPT 2>&1
#$tes3cmd dump "${r021s}" --raw-with-header "${p021}" --type SCPT 2>&1
# 2022.07.10 disable these patches due to being outdated with Vvardenfell Brotherhood v1.17
# $tes3cmd dump "${r022s}" --raw "${r000}" --type SCPT 2>&1
# $tes3cmd dump "${r022s}" --raw-with-header "${r022}" --type SCPT 2>&1
# $tes3cmd dump "${r022s}" --raw-with-header "${p022}" --type SCPT 2>&1
# benefaction
$tes3cmd dump "${r023d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r023d}" --raw-with-header "${r023}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r023d}" --raw-with-header "${p023}" --type DIAL --type INFO 2>&1
# brothes oran
# greeting 5
$tes3cmd dump "${r024d}" --raw "${r000}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r036d}" --raw "${r000}" --type INFO 2>&1
# $tes3cmd dump "${r038d}" --raw "${r000}" --exact-id "19854421204853818" 2>&1
# $tes3cmd dump "${r040d}" --raw "${r000}" --exact-id "8370248291737032661" 2>&1
$tes3cmd dump "${r046n}" --raw "${r000}" --type INFO 2>&1
$tes3cmd dump "${r047d}" --raw "${r000}" --type INFO 2>&1
$tes3cmd dump "${r095d}" --raw "${r000}" --type INFO 2>&1
$tes3cmd dump "${r024d}" --raw-with-header "${r024}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r024d}" --raw-with-header "${p024}" --type DIAL --type INFO 2>&1
# enchanted hammer and amulet
# +tactics
$tes3cmd dump "${r025d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r025d}" --raw-with-header "${r025}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r025d}" --raw-with-header "${p025}" --type DIAL --type INFO 2>&1
# greeting 1
$tes3cmd dump "${r026d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r031d}" --raw "${r000}" --type INFO 2>&1
$tes3cmd dump "${r032d}" --raw "${r000}" --type INFO 2>&1
$tes3cmd dump "${r035d}" --raw "${r000}" --type INFO 2>&1
# $tes3cmd dump "${r037d}" --raw "${r000}" --exact-id "20970177273117028650" 2>&1
$tes3cmd dump "${r039d}" --raw "${r000}"\
  --exact-id "237147941395021679"\
  --exact-id "1450219902413027899"\
  2>&1
# $tes3cmd dump "${r040d}" --raw "${r000}" --exact-id "11582184939177417" --exact-id "23951613945006280" 2>&1
$tes3cmd dump "${r076d}" --raw "${r000}" --type INFO 2>&1
$tes3cmd dump "${r094d}" --raw "${r000}" --type INFO 2>&1
# 2022.07.10 disable these patches due to being outdated with Vvardenfell Brotherhood v1.17
# $tes3cmd dump "${r059n}" --raw "${r000}" --type INFO 2>&1
# $tes3cmd dump "${r060d}" --raw "${r000}" --type INFO 2>&1
$tes3cmd dump "${r026d}" --raw-with-header "${r026}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r026d}" --raw-with-header "${p026}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r026d}" --raw "${p018}" --type DIAL --type INFO 2>&1
$tes3cmd header "${p018}" --hide-backups --backup-dir "${tmpd}" --update-record-count 2>&1
# witch
# $tes3cmd dump "${r027d}" --raw "${r000}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r027d}" --raw-with-header "${r027}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r027d}" --raw-with-header "${p027}" --type DIAL --type INFO 2>&1
# give it to me
$tes3cmd dump "${r028d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r028d}" --raw-with-header "${r028}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r028d}" --raw-with-header "${p028}" --type DIAL --type INFO 2>&1
# # FIXED UPSTREAM
# # marrelaeth
# # diplomatic mission
# $tes3cmd dump "${r029d}" --raw "${r000}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r029d}" --raw-with-header "${r029}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r029d}" --raw-with-header "${p029}" --type DIAL --type INFO 2>&1

# stealing alchemy ingredients
$tes3cmd dump "${r030d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r030d}" --raw-with-header "${r030}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r030d}" --raw-with-header "${p030}" --type DIAL --type INFO 2>&1
# greeting 1 # DUP
# $tes3cmd dump "${r031d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r031d}" --raw-with-header "${r031}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r031d}" --raw-with-header "${p031}" --type DIAL --type INFO 2>&1
# greeting 1 # DUP
# $tes3cmd dump "${r032d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r032d}" --raw-with-header "${r032}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r032d}" --raw-with-header "${p032}" --type DIAL --type INFO 2>&1
# -*-travel
# $tes3cmd dump "${r033d}" --raw "${r000}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r033d}" --raw-with-header "${r033}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r033d}" --raw-with-header "${p033}" --type DIAL --type INFO 2>&1
# some of that sap
$tes3cmd dump "${r034d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r034d}" --raw-with-header "${r034}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r034d}" --raw-with-header "${p034}" --type DIAL --type INFO 2>&1
# greeting 1 # DUP
#$tes3cmd dump "${r035d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r035d}" --raw-with-header "${r035}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r035d}" --raw-with-header "${p035}" --type DIAL --type INFO 2>&1
# greeting 5 # DUP
# $tes3cmd dump "${r036d}" --raw "${r000}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r036d}" --raw-with-header "${r036}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r036d}" --raw-with-header "${p036}" --type DIAL --type INFO 2>&1
# delamus andary
# toxic powder
# greeting 1 # DUP
# $tes3cmd dump "${r037d}" --raw "${r000}"\
#   --exact-id "delamus andary"\
#   --exact-id "297621946163728530"\
#   --exact-id "toxic powder"\
#   --exact-id "63928165782132061"\
#   2>&1
# $tes3cmd dump "${r037d}" --raw-with-header "${r037}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r037d}" --raw-with-header "${p037}" --type DIAL --type INFO 2>&1
# greeting 5 # DUP
# selkies
# $tes3cmd dump "${r038d}" --raw "${r000}"\
#   --exact-id "selkies"\
#   --exact-id "295397289559310058"\
#   --exact-id "24580116661411328176"\
#   --exact-id "578611950188279499"\
#   --exact-id "4280268521140210193"\
#   --exact-id "2360469202464030796"\
#   2>&1
# $tes3cmd dump "${r038d}" --raw-with-header "${r038}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r038d}" --raw-with-header "${p038}" --type DIAL --type INFO 2>&1
# greeting 1 # DUP
# keep out of the way!
# latest rumors
# greeting 0
# phylactery
$tes3cmd dump "${r039d}" --raw "${r000}"\
  --exact-id "keep out of the way!"\
  --exact-id "24071257562452919757"\
  --exact-id "latest rumors"\
  --exact-id "2018354181961315213"\
  --exact-id "greeting 0"\
  --exact-id "1802279642940530140"\
  --exact-id "2988325467330829936"\
  --exact-id "phylactery"\
  --exact-id "10852891934209108"\
  --exact-id "20564277962909127995"\
  2>&1
$tes3cmd dump "${r039d}" --raw-with-header "${r039}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r039d}" --raw-with-header "${p039}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r039d}" --raw "${p007}" --type DIAL --type INFO 2>&1
$tes3cmd header "${p007}" --hide-backups --backup-dir "${tmpd}" --update-record-count 2>&1
# # greeting 1 # DUP
# # greeting 5 # DUP
# # work for sarathram
# # promote the member
# # valenwood wine
# # buy liette
# # lure away sottilde
# $tes3cmd dump "${r040d}" --raw "${r000}"\
#   --exact-id "work for sarathram"\
#   --exact-id "15226218612809825096"\
#   --exact-id "promote the member"\
#   --exact-id "1854430421189973307"\
#   --exact-id "valenwood wine"\
#   --exact-id "921474281978516597"\
#   --exact-id "buy liette"\
#   --exact-id "4953296216025158"\
#   --exact-id "lure away sottilde"\
#   --exact-id "2154523709649316117"\
#   2>&1
# $tes3cmd dump "${r040d}" --raw-with-header "${r040}" --type DIAL --type INFO 2>&1
# # $tes3cmd dump "${r040d}" --raw-with-header "${p040}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r040d}" --raw "${p015}" --type DIAL --type INFO 2>&1
# $tes3cmd header "${p015}" --hide-backups --backup-dir "${tmpd}" --update-record-count 2>&1
$tes3cmd dump "${r041s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r041s}" --raw-with-header "${r041}" --type SCPT 2>&1
$tes3cmd dump "${r041s}" --raw-with-header "${p041}" --type SCPT 2>&1
$tes3cmd dump "${r042n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r042n}" --raw-with-header "${r042}" --type NPC_ 2>&1
$tes3cmd dump "${r042n}" --raw-with-header "${p042}" --type NPC_ 2>&1
$tes3cmd dump "${r043n}" --raw "${r000}" --type CONT 2>&1
$tes3cmd dump "${r043n}" --raw-with-header "${r043}" --type CONT 2>&1
$tes3cmd dump "${r043n}" --raw-with-header "${p043}" --type CONT 2>&1
$tes3cmd dump "${r044n}" --raw "${r000}" --type CONT 2>&1
$tes3cmd dump "${r044n}" --raw-with-header "${r044}" --type CONT 2>&1
$tes3cmd dump "${r044n}" --raw-with-header "${p044}" --type CONT 2>&1
$tes3cmd dump "${r045n}" --raw "${r000}" --type LEVI 2>&1
$tes3cmd dump "${r045n}" --raw-with-header "${r045}" --type LEVI 2>&1
$tes3cmd dump "${r045n}" --raw-with-header "${p045}" --type LEVI 2>&1
# greeting 5 # DUP
# $tes3cmd dump "${r046n}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r046n}" --raw-with-header "${r046}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r046n}" --raw-with-header "${p046}" --type DIAL --type INFO 2>&1
# greeting 5 # DUP
# $tes3cmd dump "${r047d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r047d}" --raw-with-header "${r047}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r047d}" --raw-with-header "${p047}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r048n}" --raw "${r000}" --type GLOB 2>&1
# $tes3cmd dump "${r048n}" --raw-with-header "${r048}" --type GLOB 2>&1
# $tes3cmd dump "${r048n}" --raw-with-header "${p048}" --type GLOB 2>&1
$tes3cmd dump "${r051n}" --raw "${r000}" --type CONT 2>&1
$tes3cmd dump "${r051n}" --raw-with-header "${r051}" --type CONT 2>&1
$tes3cmd dump "${r051n}" --raw-with-header "${p051}" --type CONT 2>&1
$tes3cmd dump "${r052n}" --raw "${r000}" --type CONT 2>&1
$tes3cmd dump "${r052n}" --raw-with-header "${r052}" --type CONT 2>&1
$tes3cmd dump "${r052n}" --raw-with-header "${p052}" --type CONT 2>&1
# $tes3cmd dump "${r053n}" --raw "${r000}" --type NPC_ 2>&1
# $tes3cmd dump "${r053n}" --raw-with-header "${r053}" --type NPC_ 2>&1
# $tes3cmd dump "${r053n}" --raw-with-header "${p053}" --type NPC_ 2>&1
# $tes3cmd dump "${r054n}" --raw "${r000}" --type SPEL 2>&1
# $tes3cmd dump "${r054n}" --raw-with-header "${r054}" --type SPEL 2>&1
# $tes3cmd dump "${r054n}" --raw-with-header "${p054}" --type SPEL 2>&1
# $tes3cmd dump "${r056s}" --raw "${r000}" --type SCPT 2>&1
# $tes3cmd dump "${r056s}" --raw-with-header "${r056}" --type SCPT 2>&1
# $tes3cmd dump "${r056s}" --raw-with-header "${p056}" --type SCPT 2>&1
$tes3cmd dump "${r057s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r057s}" --raw-with-header "${r057}" --type SCPT 2>&1
# $tes3cmd dump "${r058n}" --raw "${r000}" --type NPC_ 2>&1
# $tes3cmd dump "${r058n}" --raw-with-header "${r058}" --type NPC_ 2>&1
# greeting 1 # DUP
# $tes3cmd dump "${r059n}" --raw "${r000}" --type DIAL --type INFO 2>&1
# 2022.07.10 disable these patches due to being outdated with Vvardenfell Brotherhood v1.17
# $tes3cmd dump "${r059n}" --raw-with-header "${r059}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r059n}" --raw-with-header "${p059}" --type DIAL --type INFO 2>&1
# greeting 1 # DUP
## $tes3cmd dump "${r060d}" --raw "${r000}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r060d}" --raw-with-header "${r060}" --type DIAL --type INFO 2>&1
## $tes3cmd dump "${r060d}" --raw-with-header "${p060}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r061s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r061s}" --raw-with-header "${r061}" --type SCPT 2>&1
#$tes3cmd dump "${r061s}" --raw-with-header "${p061}" --type SCPT 2>&1
$tes3cmd dump "${r062d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r062d}" --raw-with-header "${r062}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r062d}" --raw-with-header "${p062}" --type DIAL --type INFO 2>&1
# tear of st. meris
# $tes3cmd dump "${r063d}" --raw "${r000}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r063d}" --raw-with-header "${r063}" --type DIAL --type INFO 2>&1
## $tes3cmd dump "${r063d}" --raw-with-header "${p063}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r064n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r064n}" --raw-with-header "${r064}" --type NPC_ 2>&1
$tes3cmd dump "${r064n}" --raw-with-header "${p064}" --type NPC_ 2>&1
$tes3cmd dump "${r065n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r065n}" --raw-with-header "${r065}" --type NPC_ 2>&1
$tes3cmd dump "${r065n}" --raw-with-header "${p065}" --type NPC_ 2>&1
$tes3cmd dump "${r066n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r066n}" --raw-with-header "${r066}" --type NPC_ 2>&1
$tes3cmd dump "${r066n}" --raw-with-header "${p066}" --type NPC_ 2>&1
$tes3cmd dump "${r067n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r067n}" --raw-with-header "${r067}" --type NPC_ 2>&1
$tes3cmd dump "${r067n}" --raw-with-header "${p067}" --type NPC_ 2>&1
$tes3cmd dump "${r068s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r068s}" --raw-with-header "${r068}" --type SCPT 2>&1
# moon sugar
# raw ebony
$tes3cmd dump "${r069s}" --raw "${r000}" --type BOOK --type DIAL --type INFO 2>&1
$tes3cmd dump "${r069s}" --raw-with-header "${r069}" --type BOOK --type DIAL --type INFO 2>&1
$tes3cmd dump "${r069s}" --raw-with-header "${p069}" --type BOOK --type DIAL --type INFO 2>&1
$tes3cmd dump "${r070n}" --raw "${r000}" --type ARMO 2>&1
$tes3cmd dump "${r070n}" --raw-with-header "${r070}" --type ARMO 2>&1
$tes3cmd dump "${r070n}" --raw-with-header "${p070}" --type ARMO 2>&1
$tes3cmd dump "${r071n}" --raw "${r000}" --type ARMO 2>&1
$tes3cmd dump "${r071n}" --raw-with-header "${r071}" --type ARMO 2>&1
$tes3cmd dump "${r071n}" --raw-with-header "${p071}" --type ARMO 2>&1
$tes3cmd dump "${r072n}" --raw "${r000}" --type ARMO 2>&1
$tes3cmd dump "${r072n}" --raw-with-header "${r072}" --type ARMO 2>&1
$tes3cmd dump "${r072n}" --raw-with-header "${p072}" --type ARMO 2>&1
$tes3cmd dump "${r073n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r073n}" --raw-with-header "${r073}" --type NPC_ 2>&1
# $tes3cmd dump "${r073n}" --raw-with-header "${p073}" --type ARMO 2>&1
$tes3cmd dump "${r074n}" --raw "${r000}" --type ENCH 2>&1
$tes3cmd dump "${r074n}" --raw-with-header "${r074}" --type ENCH 2>&1
$tes3cmd dump "${r074n}" --raw-with-header "${p074}" --type ENCH 2>&1
# master index
$tes3cmd dump "${r075d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r075d}" --raw-with-header "${r075}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r075d}" --raw-with-header "${p075}" --type DIAL --type INFO 2>&1
# greeting 1 # DUP
# $tes3cmd dump "${r075d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r076d}" --raw-with-header "${r076}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r076d}" --raw-with-header "${p076}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r077n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r077n}" --raw-with-header "${r077}" --type NPC_ 2>&1
# $tes3cmd dump "${r077n}" --raw-with-header "${p077}" --type NPC_ 2>&1
$tes3cmd dump "${r078s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r078s}" --raw-with-header "${r078}" --type SCPT 2>&1
# $tes3cmd dump "${r079n}" --raw "${r000}" --type SPEL 2>&1
# $tes3cmd dump "${r079n}" --raw-with-header "${r079}" --type SPEL 2>&1
# $tes3cmd dump "${r079n}" --raw-with-header "${p079}" --type SPEL 2>&1
$tes3cmd dump "${r080n}" --raw "${r000}" --type CREA 2>&1
$tes3cmd dump "${r080n}" --raw-with-header "${r080}" --type CREA 2>&1
# $tes3cmd dump "${r080n}" --raw-with-header "${p080}" --type CREA 2>&1
# $tes3cmd dump "${r081n}" --raw "${r000}" --type NPC_ 2>&1
# $tes3cmd dump "${r081n}" --raw-with-header "${r081}" --type NPC_ 2>&1
# # $tes3cmd dump "${r081n}" --raw-with-header "${p081}" --type NPC_ 2>&1
# $tes3cmd dump "${r082n}" --raw "${r000}" --type MISC 2>&1
# $tes3cmd dump "${r082n}" --raw-with-header "${r082}" --type MISC 2>&1
# # $tes3cmd dump "${r082n}" --raw-with-header "${p082}" --type MISC 2>&1
$tes3cmd dump "${r083n}" --raw "${r000}" --type CREA 2>&1
$tes3cmd dump "${r083n}" --raw-with-header "${r083}" --type CREA 2>&1
$tes3cmd dump "${r083n}" --raw-with-header "${p083}" --type CREA 2>&1
$tes3cmd dump "${r084n}" --raw "${r000}" --type CREA 2>&1
$tes3cmd dump "${r084n}" --raw-with-header "${r084}" --type CREA 2>&1
# $tes3cmd dump "${r084n}" --raw-with-header "${p084}" --type CREA 2>&1
$tes3cmd dump "${r085n}" --raw "${r000}" --type CONT 2>&1
$tes3cmd dump "${r085n}" --raw-with-header "${r085}" --type CONT 2>&1
# $tes3cmd dump "${r085n}" --raw-with-header "${p085}" --type CONT 2>&1
$tes3cmd dump "${r086n}" --raw "${r000}" --type CONT 2>&1
$tes3cmd dump "${r086n}" --raw-with-header "${r086}" --type CONT 2>&1
# $tes3cmd dump "${r086n}" --raw-with-header "${p086}" --type CONT 2>&1
$tes3cmd dump "${r087n}" --raw "${r000}" --type BOOK 2>&1
$tes3cmd dump "${r087n}" --raw-with-header "${r087}" --type BOOK 2>&1
# $tes3cmd dump "${r087n}" --raw-with-header "${p087}" --type BOOK 2>&1
# telvanni bride
$tes3cmd dump "${r088d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r088d}" --raw-with-header "${r088}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r088d}" --raw-with-header "${p088}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r089n}" --raw "${r000}" --type CREA 2>&1
$tes3cmd dump "${r089n}" --raw-with-header "${r089}" --type CREA 2>&1
$tes3cmd dump "${r089n}" --raw-with-header "${p089}" --type CREA 2>&1
$tes3cmd dump "${r090n}" --raw "${r000}" --type CREA 2>&1
$tes3cmd dump "${r090n}" --raw-with-header "${r090}" --type CREA 2>&1
$tes3cmd dump "${r090n}" --raw-with-header "${p090}" --type CREA 2>&1
# task
$tes3cmd dump "${r091d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r091d}" --raw-with-header "${r091}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r091d}" --raw-with-header "${p091}" --type DIAL --type INFO 2>&1
# unstable
# clockwork city
$tes3cmd dump "${r092d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r092d}" --raw-with-header "${r092}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r092d}" --raw-with-header "${p092}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r093n}" --raw "${r000}" --type NPC_ 2>&1
$tes3cmd dump "${r093n}" --raw-with-header "${r093}" --type NPC_ 2>&1
$tes3cmd dump "${r093n}" --raw-with-header "${p093}" --type NPC_ 2>&1
# greeting 1 # DUP
# $tes3cmd dump "${r094d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r094d}" --raw-with-header "${r094}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r094d}" --raw-with-header "${p094}" --type DIAL --type INFO 2>&1
# greeting 5 # DUP
# $tes3cmd dump "${r095d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r095d}" --raw-with-header "${r095}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r095d}" --raw-with-header "${p095}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r096n}" --raw "${r000}" --type CREA 2>&1
$tes3cmd dump "${r096n}" --raw-with-header "${r096}" --type CREA 2>&1
# $tes3cmd dump "${r096n}" --raw-with-header "${p096}" --type CREA 2>&1
# duties
$tes3cmd dump "${r097d}" --raw "${r000}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r097d}" --raw-with-header "${r097}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r097d}" --raw-with-header "${p097}" --type DIAL --type INFO 2>&1
$tes3cmd dump "${r098s}" --raw "${r000}" --type NPC_ --type SCPT 2>&1
$tes3cmd dump "${r098s}" --raw-with-header "${r098}" --type NPC_ --type SCPT 2>&1
$tes3cmd dump "${r098s}" --raw-with-header "${p098}" --type NPC_ --type SCPT 2>&1
$tes3cmd dump "${r100s}" --raw "${r000}" --type SCPT 2>&1
$tes3cmd dump "${r100s}" --raw-with-header "${r100}" --type SCPT 2>&1
$tes3cmd dump "${r100s}" --raw-with-header "${p100}" --type SCPT 2>&1
# vampires attacking tel mora
# $tes3cmd dump "${r101d}" --raw "${r000}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r101d}" --raw-with-header "${r101}" --type DIAL --type INFO 2>&1
# $tes3cmd dump "${r101d}" --raw-with-header "${p101}" --type DIAL --type INFO 2>&1
# 2022-09-09 - Finally merge together leveled lists patch and the main merged patch
# $tes3cmd header "${r000}" --hide-backups --backup-dir "${tmpd}" --synchronize
# $tes3cmd header "${r000}" --hide-backups --backup-dir "${tmpd}" --update-record-count 2>&1
# leveled lists
# $tes3cmd dump "${r049l}" --raw-with-header "${rm050}" --type LEVC 2>&1
# $tes3cmd dump "${r049l}" --raw-with-header "${p049}" --type LEVC 2>&1
# $tes3cmd dump "${r050l}" --raw "${rm050}" --type LEVC 2>&1
# $tes3cmd dump "${r050l}" --raw-with-header "${p050}" --type LEVC 2>&1
# $tes3cmd header "${rm050}" --hide-backups --backup-dir "${tmpd}" --update-record-count 2>&1
$tes3cmd dump "${r049l}" --raw "${r000}" --type LEVC 2>&1
$tes3cmd dump "${r049l}" --raw-with-header "${p049}" --type LEVC 2>&1
$tes3cmd dump "${r050l}" --raw "${r000}" --type LEVC 2>&1
$tes3cmd dump "${r050l}" --raw-with-header "${p050}" --type LEVC 2>&1
$tes3cmd header "${r000}" --hide-backups --backup-dir "${tmpd}" --synchronize
$tes3cmd header "${r000}" --hide-backups --backup-dir "${tmpd}" --update-record-count 2>&1
} | tee "${tlog}"
  rg -v 'SV - Terrors Of The Night Normal.*Sirollus Saccus Override' "${tlog}" |\
    if rg -i 'error|warning|not modified'; then
      echo "error"
      return 1
    fi
  $tes3cmd dump --list "${r000}" | sort | uniq -c | sort -bgr | rg -v '^ *1' > "${tlog}"
  if [ -s "${tlog}" ]; then
    cat "${tlog}"
    echo "error dup"
    return 1
  fi
elif [ "${1}" = "make" ]; then

  if [ ! -d "${d1}" ]; then mkdir -vp "${d1}"; fi
  if [ ! -d "${d2}" ]; then mkdir -vp "${d2}"; fi
  if [ ! -d "${d3}" ]; then mkdir -vp "${d3}"; fi
  if [ ! -d "${d4}" ]; then mkdir -vp "${d4}"; fi
  if [ ! -d "${d90uni}" ]; then mkdir -vp "${d90uni}"; fi
  if [ ! -d "${d5_01}" ]; then mkdir -vp "${d5_01}"; fi
  if [ ! -d "${d5_02}" ]; then mkdir -vp "${d5_02}"; fi
  if [ ! -d "${d5_03}" ]; then mkdir -vp "${d5_03}"; fi

tlog="$(mktemp)"
# 001. Gnisis door fix
s="${s001}"
r="${r001cd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CELL\
  --exact-id "gnisis (-11, 11)"\
  --instance-match "ObjIdx:1934"\
  2>&1 | tee -a "${tlog}"
r="${r001c}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CELL\
  --exact-id "gnisis (-11, 11)"\
  --instance-match "ObjIdx:1934"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type TES3\
  --run "\
  \$R->append(TES3::MAST->new({'master', 'Morrowind.esm'})),\
  \$R->append(TES3::DATA->new({'length', '79837557'}))"\
  2>&1 | tee -a "${tlog}"
$tes3cmd header "${r}" --hide-backups --backup-dir "${tmpd}" --synchronize 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CELL\
  --exact-id "gnisis (-11, 11)"\
  --run "\
  \$R->set({i=>[6], f=>'X'}, '-85825'),\
  \$R->set({i=>[6], f=>'Y'}, '95380'),\
  \$R->set({i=>[6], f=>'Z'}, '1125')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CELL\
  --exact-id "gnisis (-11, 11)"\
  --run "\$R->set({i=>[4], f=>'MastIdx'}, '1')"\
  2>&1 | tee -a "${tlog}"

# 002. Ajira deflowered
s="${s002}"
r="${r002nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "ajira"\
  2>&1 | tee -a "${tlog}"
r="${r002n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "ajira"\
  2>&1 | tee -a "${tlog}"
$tes3cmd delete "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type NPC_\
  --exact-id "ajira"\
  --sub-match "Object:ingred_willow_anther_01"\
  2>&1 | tee -a "${tlog}"
$tes3cmd delete "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type NPC_\
  --exact-id "ajira"\
  --sub-match "Object:ingred_heather_01"\
  2>&1 | tee -a "${tlog}"

# 003. Cooking and eating enable hunger
s="${s003}"
r="${r003nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type GLOB\
  --exact-id "enablehunger"\
  2>&1 | tee -a "${tlog}"
r="${r003n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type GLOB\
  --exact-id "enablehunger"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type GLOB\
  --exact-id "enablehunger"\
  --run "\$R->set({t=>'FLTV', f=>'Float'}, '1')"\
  2>&1 | tee -a "${tlog}"

# 004. Bonemold chuzei helm no neck fix + BTB's stats
s="${s004}"
cp -v "${o004}" "${s004}" || return 1
r="${r004nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ARMO\
  --exact-id "bonemold_chuzei_helm"\
  2>&1 | tee -a "${tlog}"
r="${r004n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ARMO\
  --exact-id "bonemold_chuzei_helm"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type ARMO\
  --exact-id "bonemold_chuzei_helm"\
  --run "\$R->set({t=>'AODT',f=>'Enchantment'}, '140')"\
  2>&1 | tee -a "${tlog}"

# 005. Frostwind balance patche globs
s="${s005}"
r="${r005n}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type GLOB --exact-id "a_temp_level" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type GLOB --exact-id "a_temp_level" --run "\
  \$R->set({t=>'NAME', f=>'ID'}, 'avp_frostwind_warmth_adjust'),\
  \$R->set({t=>'FLTV', f=>'Float'}, '4.4')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type GLOB --exact-id "a_temp_level" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type GLOB --exact-id "a_temp_level" --run "\
  \$R->set({t=>'NAME', f=>'ID'}, 'avp_frostwind_wet_coeff'),\
  \$R->set({t=>'FLTV', f=>'Float'}, '4')"\
  2>&1 | tee -a "${tlog}"
r="${r005sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "a_calculate_warmth"\
  --exact-id "a_frostwind"\
  --exact-id "a_region_check"\
  2>&1 | tee -a "${tlog}"
# add two globals:
#   avp_frostwind_warmth_adjust float (+4.4 in my case: .4 because i don't use frostwind food, 3 because of limit adjust, 1 because i don't use unarmored)
#   avp_frostwind_wet_coeff float (1 to 4)
# a_calculate_warmth (L241-242):
#   add warmth adjust
#   add wet warmth coefficient
# a_frostwind (L241-242):
#   adjust external temperature limit from 5 to 8
# a_region_check:
#   add 5 solstheim regions with -2 temperature:
#     solstheim
#     fort frostmoth
#     raven rock
#     skaal village
#     thirsk

# 006. DRP
s="${s006}"
r="${r006sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "nchuleft_test"\
  --exact-id "Sturdumz_fire_spider"\
  --exact-id "sturdumz_weap_spin"\
  --exact-id "Sturdumz_weld2"\
  2>&1 | tee -a "${tlog}"
# DRP
# "nchuleft_test"
#   L5: Player->Getdistance TO GetDistance Player
# "Sturdumz_fire_spider"
#   L5: Player->Getdistance TO GetDistance Player
# "sturdumz_weap_spin"
#   L5: Remove space between Rotate and World
# "Sturdumz_weld2"
#   L13-L16: Remove lines

# 007. Uvirith's Legacy_3.53.esp
s="${s007}"
r="${r007sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "uvirith_verenarevengetimer"\
  2>&1 | tee -a "${tlog}"
# wrong call to GetHealth

# 008. UL TR
# s="${s008}"
# r="${r008sd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SCPT\
#   --exact-id "uvi_shipment_tr"\
#   2>&1 | tee -a "${tlog}"

# 009. DA_Sobitur_Facility_Clean.ESP recolour scripts
s="${s009}"
r="${r009sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "_df_ebordwrecolourcuirass"\
  --exact-id "_df_recolourcuirass"\
  --exact-id "_df_recolourwarrow"\
  --exact-id "_df_recolourwbattleaxe"\
  --exact-id "_df_recolourwclaymore"\
  --exact-id "_df_recolourwclub"\
  --exact-id "_df_recolourwdagger"\
  --exact-id "_df_recolourwdai-katana"\
  --exact-id "_df_recolourwdart"\
  --exact-id "_df_recolourwkatana"\
  --exact-id "_df_recolourwlongbow"\
  --exact-id "_df_recolourwlongsword"\
  --exact-id "_df_recolourwmace"\
  --exact-id "_df_recolourwshortsword"\
  --exact-id "_df_recolourwspear"\
  --exact-id "_df_recolourwstaff"\
  --exact-id "_df_recolourwtanto"\
  --exact-id "_df_recolourwwakizashi"\
  --exact-id "_df_recolourwwaraxe"\
  --exact-id "_df_recolourwwarhammer"\
  2>&1 | tee -a "${tlog}"


# 010. Sobitur lvl40check
s="${s010}"
r="${r010sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "_da_lvl40check"\
  2>&1 | tee -a "${tlog}"
# "DA_Sobitur_Quest_Part_1 Clean.esp"
# "_da_lvl40check"
#   L7, L8: Remove line (extra endif and useless elseif)
#   L13: Remove line (extra endif)
#   L23: Remove player-> from addtopic

# # 011. Sobitur tringred compat sorter
# s="${s011}"
# r="${r011sd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SCPT\
#   --exact-id "da_tringred_sorter"\
#   2>&1 | tee -a "${tlog}"

# 012. Sotha Sil Expanded
s="${s012}"
r="${r012sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "sotha_famercontain1"\
  --exact-id "sotha_hangspeak"\
  2>&1 | tee -a "${tlog}"

# 013. Enonhear Underworks Disable Rebirth
s="${s013}"
r="${r013nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type GLOB\
  --exact-id "dd19rebirthConfig"\
  2>&1 | tee -a "${tlog}"
r="${r013n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type GLOB\
  --exact-id "dd19rebirthConfig"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type GLOB\
  --exact-id "dd19rebirthConfig"\
  --run "\$R->set({t=>'FLTV', f=>'Float'}, '1')"\
  2>&1 | tee -a "${tlog}"
# to test
# show dd19nothief
# show dd19rebirth

# # 014. Fighters Guild Questline Overhaul Enable OpenMW
# s="${s014}"
# r="${r014sd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SCPT\
#   --exact-id "fg_openmw_ask"\
#   2>&1 | tee -a "${tlog}"
# # Record: SCPT "fg_openmw_ask" Flags:0x0000 ()
# # set OpenMWQuestion to 2
# # set FG_OpenMW to 1

# # 015. Fighters Guild Questline Overhaul Fix Scripts
# s="${s015}"
# r="${r015sd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SCPT\
#   --exact-id "fg_ashurnibibi_inside_friends"\
#   --exact-id "fg_job_given_bounty_lorzub"\
#   --exact-id "fg_job_given_bounty_miles"\
#   --exact-id "fg_orcdeadalarm"\
#   --exact-id "fg_pc_exec_massentertainment"\
#   --exact-id "fg_sondryn_slavepod"\
#   --exact-id "fg_thief_jailed_maar_gan"\
#   --exact-id "fg_sottildelure_script"\
#   2>&1 | tee -a "${tlog}"
# # 1. "fg_ashurnibibi_inside_friends"
# # E: L16: (breaking backslash at the end of line)
# # 		"rolfish gra-dugul"->stopcombat player\
# # 		"rolfish gra-dugul"->stopcombat player
# # W: L13: (extra argument)
# # 		"durgash gro-rushub"->stopcombat player
# # 		"durgash gro-rushub"->stopcombat
# # W: L16: (extra argument)
# # 		"rolfish gra-dugul"->stopcombat player
# # 		"rolfish gra-dugul"->stopcombat
# # 2. "fg_job_given_bounty_lorzub"
# # E: L35, 45, 55, 73: (missing double-quote around region names)
# # W: L10, 18, 27: (same)
# # 3. "fg_job_given_bounty_miles": same as 2.
# # 4. "fg_orcdeadalarm"\
# # E: L9, 21, 33: (wrong getdeadcount call)
# #   '"<name>"->GetDeadCount' should be 'GetDeadCount "<name>"'
# # not used "fg_pc_exec_massentertainment"
# # 5. "fg_sondryn_slavepod"
# # E: L8: (wrong call to unlock)
# # "sondryn irathi"->unlock "FG_Sondryn_SlaveCageDoor"
# # "FG_Sondryn_SlaveCageDoor"->unlock
# # W: L9: (actually this is error i suppose)
# # "sondryn irathi"->Activate "FG_Sondryn_SlaveCageDoor"
# # "FG_Sondryn_SlaveCageDoor"->Activate
# # W: L24: (redundant endif)
# # 6. "fg_thief_jailed_maar_gan"
# # E: L35: (typo, "'" instead of comment ";")
# # 7. "fg_sottildelure_script"
# # L7, 62, 69: x3 wrong variable name fg_sottildelure -> fgsottildelure
# # L98: Playsound should not have target

# 016. Ashlander Traders Remastered.esp
s="${s016}"
r="${r016sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "cv_control1"\
  2>&1 | tee -a "${tlog}"
# not used in game

# 017. Clean_Mines & Caverns.esp
s="${s017}"
r="${r017sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "darkdwemerarmor"\
  2>&1 | tee -a "${tlog}"

# 018. MoonlightOnTheOdaiRiver.esp
s="${s018}"
r="${r018sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "_mor_float"\
  2>&1 | tee -a "${tlog}"

# 019. TeaMod_2.1.esp
s="${s019}"
r="${r019sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "tm_shipment_weekly"\
  --exact-id "tmt_shipment_weekly"\
  2>&1 | tee -a "${tlog}"

# 020. The Doors of Oblivion 1.4.esp
s="${s020}"
r="${r020sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "bs_barbas_defend"\
  --exact-id "bs_clavicus_defend"\
  --exact-id "bs_nervous_scamp_script"\
  2>&1 | tee -a "${tlog}"
# all these scripts are not used, simply commented out

# 021. The Redoran Bard.esp
s="${s021}"
r="${r021sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "companioncombat"\
  2>&1 | tee -a "${tlog}"
# not used in game

# 2022.07.10 disable these patches due to being outdated with Vvardenfell Brotherhood v1.17
# 022. VB_EmynDB_Patch.ESP
# s="${s022}"
# r="${r022sd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SCPT\
#   --exact-id "p_severmagia_teleport"\
#   2>&1 | tee -a "${tlog}"
# # L202: (getdistance wrong call)
# # 		if ( "CS_Cyrse6"->GetDistance < 1000 )
# # 		if ( "CS_Cyrse6"->GetDistance, player < 1000 )

# 023. Alms and Donations.ESP
s="${s023}"
r="${r023dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "benefaction" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "20644265812752419041" 2>&1 | tee -a "${tlog}"
r="${r023d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "benefaction" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "20644265812752419041" 2>&1 | tee -a "${tlog}"
# removeitem lines were joined
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "20644265812752419041"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'player->removeitem gold_001 50000
player->removeitem gold_001 50000
Cast \"AZ_Charity_IV_IC\" Player
Set AZ_Alms_IC to AZ_Alms_IC + 50000
Set AZ_Alms_IC to AZ_Alms_IC + 50000')" 2>&1 | tee -a "${tlog}"

# 024. Balmora Guilds Expanded.ESP
s="${s024}"
r="${r024dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "brothes oran" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "2864925247234605049" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "20797316562522223286" 2>&1 | tee -a "${tlog}"
r="${r024d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "brothes oran" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "2864925247234605049" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "20797316562522223286" 2>&1 | tee -a "${tlog}"
# Error: line 3, column 12 (->): Unexpected special token
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "2864925247234605049"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'player->removeitem \"gold_001\" 1000
moddisposition 10
addtopic \"Aharunartus\"
Journal luce_miobfg_wuleen 32')" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 1 (<newline>): Unexpected special token
# it gets auto-corrected while dumping i suppose # it doesn't
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "20797316562522223286"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Say, \"Vo\\d\\m\\CrAtk_AM003.mp3\", \" \"')" 2>&1 | tee -a "${tlog}"
# '\"luce_mio_bfg_arthes\"->Say \"Vo/d/m/CrAtk_AM003.mp3\"')" 2>&1 | tee -a "${tlog}"

# 025. The Hammer of Orsinium.esp
s="${s025}"
r="${r025dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "enchanted hammer and amulet" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "23745146991978230022" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "30817132642709911999" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "+tactics" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "8089305471293820634" 2>&1 | tee -a "${tlog}"
r="${r025d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "enchanted hammer and amulet" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "23745146991978230022" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "30817132642709911999" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "+tactics" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "8089305471293820634" 2>&1 | tee -a "${tlog}"
# Error: line 3, column 30 (1): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "23745146991978230022"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Player->AddItem \"tec_hraghammerweap\" 1
Player->AddItem \"tech_hragamuletcloth\" 1
tec_hraghammerweap->disable
tech_hragamuletcloth->disable
ModDisposition -50
Goodbye')" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "30817132642709911999"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Player->AddItem \"tec_hraghammerweap\" 1
Player->AddItem \"tech_hragamuletcloth\" 1
tec_hraghammerweap->disable
tech_hragamuletcloth->disable
Player->RemoveItem \"Gold_001\" 5000
Goodbye')" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 11 (setweapUse): Unexpected name
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "8089305471293820634"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'setmarksman 0
set weapUse to 0')" 2>&1 | tee -a "${tlog}"

# 026. MoonlightOnTheOdaiRiver.esp
s="${s026}"
r="${r026dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "31567139452934014964" 2>&1 | tee -a "${tlog}"
r="${r026d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "31567139452934014964" 2>&1 | tee -a "${tlog}"
# Error: line 1, column 11 (->): Unexpected special token
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "31567139452934014964"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'AddTopic \"Favor\"')" 2>&1 | tee -a "${tlog}"

# # 027. The Minotaurs Ring.esp
# s="${s027}"
# r="${r027dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "witch" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1765330571598610233" 2>&1 | tee -a "${tlog}"
# r="${r027d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "witch" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1765330571598610233" 2>&1 | tee -a "${tlog}"
# # Error: line 1, column 9 (.): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "1765330571598610233"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Goodbye')" 2>&1 | tee -a "${tlog}"

# 028. SHS - Bloodskal Barrow.ESP
s="${s028}"
r="${r028dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "give it to me" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1508134931505721410" 2>&1 | tee -a "${tlog}"
r="${r028d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "give it to me" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1508134931505721410" 2>&1 | tee -a "${tlog}"
# Error: line 1, column 9 (.): Unexpected special token
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "1508134931505721410"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Goodbye')" 2>&1 | tee -a "${tlog}"

# # 029. Sky_Main.esm
# s="${s029}"
# r="${r029dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "marrelaeth" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "24411164381667128888" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "diplomatic mission" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "265452965195223133" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "37286486124094465" 2>&1 | tee -a "${tlog}"
# r="${r029d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "marrelaeth" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "24411164381667128888" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "diplomatic mission" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "265452965195223133" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "37286486124094465" 2>&1 | tee -a "${tlog}"
# # Error: line 1, column 9 (.): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "24411164381667128888"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Choice \"Marrelaeth does not exist. The author probably made it up.\" 5 \"The only person who knew is dead. The secret of Marralaeth is lost now.\" 8')" 2>&1 | tee -a "${tlog}"
# # Error: line 4, column 4 (end): Unexpected keyword
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "265452965195223133"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Choice \"I will help you.\" 1 \"Sorry, I\'ve got things to do.\" 2
# if ( player->GetItemCount Sky_qRe_DSW02_LakushSkull > 0 )
#     Choice \"I have Lakush\'s remains.\" 3
# endif
# Journal Sky_qRe_DSW02_Journal 30
# AddTopic \"Lakush\'s remains\"
# AddTopic \"passage through the wall\"')" 2>&1 | tee -a "${tlog}"
# # Error: line 4, column 4 (end): Unexpected keyword
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "37286486124094465"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Choice \"I will help you.\" 1 \"Sorry, I\'ve got things to do.\" 2
# if ( player->GetItemCount Sky_qRe_DSW02_LakushSkull > 0 )
#     Choice \"I have Lakush\'s remains.\" 3
# endif
# Journal Sky_qRe_DSW02_Journal 20
# AddTopic \"Lakush\'s remains\"
# AddTopic \"passage through the wall\"')" 2>&1 | tee -a "${tlog}"

# 030. The Great Fantasco.ESP
s="${s030}"
r="${r030dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "stealing alchemy ingredients" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "27800229783215721412" 2>&1 | tee -a "${tlog}"
r="${r030d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "stealing alchemy ingredients" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "27800229783215721412" 2>&1 | tee -a "${tlog}"
# Error: line 1, column 124 (6): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "27800229783215721412"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Choice \"Sure. What do you need me to do?\" 5 \"Wait I meant help you get ingredients, not erase someone\'s memories!\" 6')" 2>&1 | tee -a "${tlog}"

# 031. Wanderers of Solstheim-TOTSP.ESP
s="${s031}"
r="${r031dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "96892230215854989" 2>&1 | tee -a "${tlog}"
r="${r031d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "96892230215854989" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 13 (PlaySoundb3D): Unexpected name
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "96892230215854989"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Player->AddItem \"ingred_scrib_jerky_01\", 3
PlaySound3D \"greneat\"
ModCurrentFatigue 999
set DoneThing to -1')" 2>&1 | tee -a "${tlog}"

# 032. DD_Caldera_Expansion.esp
s="${s032}"
r="${r032dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "27485184982197318538" 2>&1 | tee -a "${tlog}"
r="${r032d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "27485184982197318538" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 23 (state): Unknown variable
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "27485184982197318538"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'PlayGroup Idle9 1
set state to 1
Goodbye')" 2>&1 | tee -a "${tlog}"

# # 033. Staff Agency_NoModels.esp
# s="${s033}"
# r="${r033dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "-*-travel" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "649532632139124460" 2>&1 | tee -a "${tlog}"
# r="${r033d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "-*-travel" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "649532632139124460" 2>&1 | tee -a "${tlog}"
# # Error: line 2, column 1 (): incomplete string or name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "649532632139124460"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'choice \"No, let\'s explore a bit longer.\" 2 \"Yes, we need to rest and restock our supplies.\" 3')" 2>&1 | tee -a "${tlog}"

# 034. The Doors of Oblivion 1.4.esp
s="${s034}"
r="${r034dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "some of that sap" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1163814153110524187" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "22586275341761910959" 2>&1 | tee -a "${tlog}"
r="${r034d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "some of that sap" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1163814153110524187" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "22586275341761910959" 2>&1 | tee -a "${tlog}"
# Error: line 1, column 2 (j): Unexpected name
$tes3cmd delete "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type INFO\
  --exact-id "1163814153110524187"\
  --exact-id "22586275341761910959"\
  --sub-match "Result:" 2>&1 | tee -a "${tlog}"

# 035. CCM-SecretsofVos-V2-TB.esp
s="${s035}"
r="${r035dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "23994105191438322849" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "20644713321814916" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "301156111928919142" 2>&1 | tee -a "${tlog}"
r="${r035d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "23994105191438322849" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "20644713321814916" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "301156111928919142" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 14 (->): Unexpected special token
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "23994105191438322849"\
  --exact-id "20644713321814916"\
  --exact-id "301156111928919142"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'SetFight 100
StartCombat player')" 2>&1 | tee -a "${tlog}"

# FIXED upstream
# 036. Mudcrab Imports Pirate Adventures.esp
# s="${s036}"
# r="${r036dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO\
#   --exact-id "1384283851673919016"\
#   --exact-id "19014108002075126281"\
#   --exact-id "316958899359220544"\
#   --exact-id "17735144832593222346"\
#   2>&1 | tee -a "${tlog}"
# r="${r036d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO\
#   --exact-id "1384283851673919016"\
#   --exact-id "19014108002075126281"\
#   --exact-id "316958899359220544"\
#   --exact-id "17735144832593222346"\
#   2>&1 | tee -a "${tlog}"
# # Error: line 2, column 1 (): incomplete string or name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "1384283851673919016"\
#   --exact-id "19014108002075126281"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'AddTopic \"Smugglers\' Cross\"')" 2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "316958899359220544"\
#   --exact-id "17735144832593222346"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'AddTopic \"Smugglers\' Cross\"
# SetFight 100
# Goodbye')" 2>&1 | tee -a "${tlog}"

# # 037. TR_Mainland.esm
# s="${s037}"
# r="${r037dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "delamus andary" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "297621946163728530" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "toxic powder" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "63928165782132061" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "20970177273117028650" 2>&1 | tee -a "${tlog}"
# r="${r037d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "delamus andary" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "297621946163728530" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "toxic powder" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "63928165782132061" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "20970177273117028650" 2>&1 | tee -a "${tlog}"
# # Error: line 1, column 84 (.): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "297621946163728530"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Choice \"Have you brought this to the attention of the island guard?\" 2 \"Nevermind.\" 3')" 2>&1 | tee -a "${tlog}"
# # Error: line 2, column 94 (.): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "63928165782132061"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'ModDisposition -10
# Choice \"Admit it... You work for the Hlaalu.\", 3, \"Because of the halberd you bought from him.\", 7, \"I am a sworn member of the Temple. Do not lie to me.\", 4, \"I\'m done talking to you... for now.\", 5')" 2>&1 | tee -a "${tlog}"
# # Error: line 3, column 22 (.): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "20970177273117028650"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'set TR_m3_Dralin_Belvayn.controlQ to GetDisposition
# if ( TR_m3_Dralin_Belvayn.controlQ > 15 )
# TR_m3_Dralin_Belvayn->ModDisposition -15
# endif
# goodbye')" 2>&1 | tee -a "${tlog}"

# # 038. Cyrodiil_Main.esm
# s="${s038}"
# r="${r038dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "19854421204853818" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "selkies" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO\
#   --exact-id "295397289559310058"\
#   --exact-id "24580116661411328176"\
#   --exact-id "578611950188279499"\
#   --exact-id "4280268521140210193"\
#   --exact-id "2360469202464030796"\
#   2>&1 | tee -a "${tlog}"
# r="${r038d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "19854421204853818" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "selkies" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO\
#   --exact-id "295397289559310058"\
#   --exact-id "24580116661411328176"\
#   --exact-id "578611950188279499"\
#   --exact-id "4280268521140210193"\
#   --exact-id "2360469202464030796"\
#   2>&1 | tee -a "${tlog}"
# # Error: line 1, column 16 ("PC_Q1-5_Agent"): Unexpected name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "19854421204853818"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# '\"PC_q1_Str05_Vilter\"->StartCombat Player
# Goodbye')" 2>&1 | tee -a "${tlog}"
# # Error: line 4, column 24 ("PC_Str_Quintus Tragia"): Unexpected name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "295397289559310058"\
#   --exact-id "4280268521140210193"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'moddisposition 50
# Journal PC_q1_Str03_Journal 90
# \"player\"->removeitem \"PC_Q1-3_SelkieSkin\" 1
# \"PC_i1-Str_Quintus\"->additem \"PC_Q1-3_SelkieSkin\" 1
# \"player\"->additem \"gold_001\" 50
# Goodbye')" 2>&1 | tee -a "${tlog}"
# # Error: line 4, column 24 ("PC_Str_Quintus Tragia"): Unexpected name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "24580116661411328176"\
#   --exact-id "2360469202464030796"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'moddisposition 50
# Journal PC_q1_Str03_Journal 95
# \"player\"->removeitem \"PC_Q1-3_SelkieSkin\" 1
# \"PC_i1-Str_Quintus\"->additem \"PC_Q1-3_SelkieSkin\" 1
# Goodbye')" 2>&1 | tee -a "${tlog}"
# # Error: line 4, column 24 ("PC_Str_Quintus Tragia"): Unexpected name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "578611950188279499"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'moddisposition -5
# Journal PC_q1_Str03_Journal 92
# \"player\"->removeitem \"PC_Q1-3_SelkieSkin\" 1
# \"PC_i1-Str_Quintus\"->additem \"PC_Q1-3_SelkieSkin\" 1
# \"player\"->additem \"gold_001\" 10
# Goodbye')" 2>&1 | tee -a "${tlog}"

# 039. Uvirith's Legacy_3.53.esp
s="${s039}"
r="${r039dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --exact-id "greeting 1"\
  --exact-id "237147941395021679"\
  --exact-id "1450219902413027899"\
  --exact-id "keep out of the way!"\
  --exact-id "24071257562452919757"\
  --exact-id "latest rumors"\
  --exact-id "2018354181961315213"\
  --exact-id "greeting 0"\
  --exact-id "1802279642940530140"\
  --exact-id "2988325467330829936"\
  --exact-id "phylactery"\
  --exact-id "10852891934209108"\
  --exact-id "20564277962909127995"\
  2>&1 | tee -a "${tlog}"
r="${r039d}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --exact-id "greeting 1"\
  --exact-id "237147941395021679"\
  --exact-id "1450219902413027899"\
  --exact-id "keep out of the way!"\
  --exact-id "24071257562452919757"\
  --exact-id "latest rumors"\
  --exact-id "2018354181961315213"\
  --exact-id "greeting 0"\
  --exact-id "1802279642940530140"\
  --exact-id "2988325467330829936"\
  --exact-id "phylactery"\
  --exact-id "10852891934209108"\
  --exact-id "20564277962909127995"\
  2>&1 | tee -a "${tlog}"
# Error: line 1, column 2 (%): Syntax error
$tes3cmd delete "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type INFO\
  --exact-id "1450219902413027899"\
  --exact-id "10852891934209108"\
  --exact-id "20564277962909127995"\
  --sub-match "Result:" 2>&1 | tee -a "${tlog}"
# Error: line 1, column 93 (5): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "237147941395021679"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Choice \"I will at least give you money for travel. [Give 10 gold]\" 4 \"It is how it must be.\" 5 \"Then stay, if you must.\" 2')" 2>&1 | tee -a "${tlog}"
# Error: line 1, column 79 (2): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "24071257562452919757"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Choice \"Nevermind.\" 1 \"Just stay in here and don\'t come out until I tell you.\" 2
ClearInfoActor')" 2>&1 | tee -a "${tlog}"
# Error: line 1, column 9 ('): Syntax error
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "2018354181961315213"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Choice \"You wait \'til I get there.\" 3
ClearInfoActor')" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 13 (Uvi_AshF_flw): Unexpected name
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "1802279642940530140"\
  --exact-id "2988325467330829936"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'AIWander 60 5 0 60 20 10 0 0 0 0 0 0
set uvi_AshF_flw to 0
StartScript Uvirith_Ash_Banish
;banished Ash-Kosh to Asharakumuk')" 2>&1 | tee -a "${tlog}"

# # 040. Fighters_Guild_Questline_Overhaul.ESP
# s="${s040}"
# r="${r040dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --exact-id "greeting 1"\
#   --exact-id "11582184939177417"\
#   --exact-id "23951613945006280"\
#   --exact-id "greeting 5"\
#   --exact-id "8370248291737032661"\
#   --exact-id "work for sarathram"\
#   --exact-id "15226218612809825096"\
#   --exact-id "promote the member"\
#   --exact-id "1854430421189973307"\
#   --exact-id "valenwood wine"\
#   --exact-id "921474281978516597"\
#   --exact-id "buy liette"\
#   --exact-id "4953296216025158"\
#   --exact-id "lure away sottilde"\
#   --exact-id "2154523709649316117"\
#   2>&1 | tee -a "${tlog}"
# r="${r040d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --exact-id "greeting 1"\
#   --exact-id "11582184939177417"\
#   --exact-id "23951613945006280"\
#   --exact-id "greeting 5"\
#   --exact-id "8370248291737032661"\
#   --exact-id "work for sarathram"\
#   --exact-id "15226218612809825096"\
#   --exact-id "promote the member"\
#   --exact-id "1854430421189973307"\
#   --exact-id "valenwood wine"\
#   --exact-id "921474281978516597"\
#   --exact-id "buy liette"\
#   --exact-id "4953296216025158"\
#   --exact-id "lure away sottilde"\
#   --exact-id "2154523709649316117"\
#   2>&1 | tee -a "${tlog}"
# # Error: line 4, column 1 (<newline>): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "11582184939177417"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'ModDisposition 1
# AIWander, 0, 0, 20, 30, 60, 10, 0, 0, 0, 0, 0, 0
# ;startscript
# Goodbye')" 2>&1 | tee -a "${tlog}"
# # Error: line 3, column 1 (<newline>): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "23951613945006280"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'ModDisposition 2
# player->removeitem ingred_crab_meat_01 1
# Goodbye')" 2>&1 | tee -a "${tlog}"
# # Error: line 2, column 1 (<newline>): Missing expression
# $tes3cmd delete "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type INFO\
#   --exact-id "1854430421189973307"\
#   --sub-match "Result:" 2>&1 | tee -a "${tlog}"
# # Error: line 1, column 14 (ModDispostion): Unexpected name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "921474281978516597"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'ModDisposition -5
# Goodbye')" 2>&1 | tee -a "${tlog}"
# # Error: line 1, column 7 (Goobye): Unexpected name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "15226218612809825096"\
#   --exact-id "4953296216025158"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Goodbye')" 2>&1 | tee -a "${tlog}"
# # Error: line 5, column 7 (Goobye): Unexpected name
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "8370248291737032661"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'setfight 100
# startcombat player
# \"Daynila Valas\"->setfight 100
# \"Daynila Valas\"->startcombat player
# Goodbye')" 2>&1 | tee -a "${tlog}"
# # Warning: [dialogue script] line 2, column 23 (to): Unknown variable
# # again fg_sottildelure -> fgsottildelure
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "2154523709649316117"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'startscript FG_SottildeLure_Script
# set FGSottildeLure to 2
# Goodbye')" 2>&1 | tee -a "${tlog}"

# 041. Wyrmhaven
s="${s041}"
r="${r041sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "wyrm_daylight"\
  2>&1 | tee -a "${tlog}"
# Error: wyrm_daylight line 19, column 19 (-): Unexpected special token
# Error: script compiling failed: wyrm_daylight
# paranthessis around (z - 8000)

# 042. Wyrmhave Hlarvis position
s="${s042}"
r="${r042nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "_wyrm_hlarvis"\
  2>&1 | tee -a "${tlog}"
r="${r042n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "_wyrm_hlarvis"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type NPC_\
  --exact-id "_wyrm_hlarvis"\
  --run "\$R->set({t=>'SCRI', f=>'Script'}, 'nolore')"\
  2>&1 | tee -a "${tlog}"
# otherwise he drops and dies

# also some works was done but got rid of it - too much to fix
# ./tes3cmd modify "Wyrmhaven.esm" --hide-backups --backup-dir "${tmpd}" --type STAT --exact-id "furn_com_rm_bench_02x" --run "\$R->set({t=>'MODL', f=>'Model'}, 'f\\Furn_Com_Bench_02.NIF')"
# ./tes3cmd modify "Wyrmhaven.esm" --hide-backups --backup-dir "${tmpd}" --type STAT --exact-id "furn_com_rm_chair_03x" --run "\$R->set({t=>'MODL', f=>'Model'}, 'f\\Furn_Com_Chair_03.NIF')"
# ./tes3cmd modify "Wyrmhaven.esm" --hide-backups --backup-dir "${tmpd}" --type STAT --exact-id "furn_com_rm_barstool0" --run "\$R->set({t=>'MODL', f=>'Model'}, 'f\\Furn_Com_Barstool.NIF')"
# ./tes3cmd modify "Wyrmhaven.esm" --hide-backups --backup-dir "${tmpd}" --type NPC_ --exact-id "_wyrm_hlarvis" --run "\$R->set({t=>'SCRI', f=>'Script'}, 'nolore')"
# ./tes3cmd modify "Wyrmhaven.esm" --hide-backups --backup-dir "${tmpd}" --type NPC_\
#   --exact-id "_wyrm_hlarvis"\
#   --exact-id "_wyrm_perry"\
#   --exact-id "_wyrm_solomon"\
#   --exact-id "_wyrm_eriol"\
#   --run "\$R->set({t=>'MODL', f=>'Model'}, 'AM\\AM_Sitting.nif')"
# # _wyrm_sitting_pants_feet
# _wyrm_sitting_pants1

# 043. Mining Pick Requirement - Diamond Rocks
s="${s043}"
r="${r043nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --match "rock_diamond"\
  2>&1 | tee -a "${tlog}"
r="${r043n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --match "rock_diamond"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CONT\
  --match "rock_diamond"\
  --run "\$R->append(CONT::SCRI->new({'script', 'TDM_MiningPicks'}))"\
  2>&1 | tee -a "${tlog}"

# 044. Mining Pick Requirement - correctUV Ore Replacer_fixed from GH
s="${s044}"
r="${r044nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  2>&1 | tee -a "${tlog}"
r="${r044n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CONT\
  --run "\$R->append(CONT::SCRI->new({'script', 'TDM_MiningPicks'}))"\
  2>&1 | tee -a "${tlog}"

# 045. Adamantium Armor - Wares - Rare
s="${s045}"
r="${r045nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type LEVI \
  --exact-id "aa_trader_armour" \
  2>&1 | tee -a "${tlog}"
r="${r045n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type LEVI \
  --exact-id "aa_trader_armour" \
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type LEVI \
  --exact-id "aa_trader_armour" \
  --run "\
  \$R->set({t=>'Name', f=>'ID'}, 'aa_avp_adamantium_random'), \
  \$R->set({t=>'NNAM', f=>'Chance_None'}, '98'), \
  \$R->append(LEVI::INDX->new({'item_count', '7'})), \
  \$R->append(LEVI::INAM->new({'item_id', 'adamantium boots'})), \
  \$R->append(LEVI::INTV->new({'level', '17'})), \
  \$R->append(LEVI::INAM->new({'item_id', 'adamantium_bracer_left'})), \
  \$R->append(LEVI::INTV->new({'level', '17'})), \
  \$R->append(LEVI::INAM->new({'item_id', 'adamantium_bracer_right'})), \
  \$R->append(LEVI::INTV->new({'level', '17'})), \
  \$R->append(LEVI::INAM->new({'item_id', 'adamantium_cuirass'})), \
  \$R->append(LEVI::INTV->new({'level', '17'})), \
  \$R->append(LEVI::INAM->new({'item_id', 'adamantium_greaves'})), \
  \$R->append(LEVI::INTV->new({'level', '17'})), \
  \$R->append(LEVI::INAM->new({'item_id', 'adamantium_pauldron_right'})), \
  \$R->append(LEVI::INTV->new({'level', '17'})), \
  \$R->append(LEVI::INAM->new({'item_id', 'adamantium_pauldron_left'})), \
  \$R->append(LEVI::INTV->new({'level', '17'}))" \
  2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}"\
  --type LEVI \
  --exact-id "aa_trader_armour" \
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type LEVI \
  --exact-id "aa_trader_armour" \
  --run "\
  \$R->append(LEVI::INDX->new({'item_count', '1'})), \
  \$R->append(LEVI::INAM->new({'item_id', 'aa_avp_adamantium_random'})), \
  \$R->append(LEVI::INTV->new({'level', '17'}))" \
  2>&1 | tee -a "${tlog}"

# 046. Library of Vivec Overhaul - Full - Dialogue Fix
s="${s046}"
r="${r046nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO\
  --exact-id "3405282081295215505"\
  --exact-id "3103019949187356597"\
  2>&1 | tee -a "${tlog}"
r="${r046n}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO\
  --exact-id "3405282081295215505"\
  --exact-id "3103019949187356597"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type INFO\
  --exact-id "3405282081295215505"\
  --run "\$R->set({t=>'NNAM',f=>'Next_ID'}, '3103019949187356598')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type INFO\
  --exact-id "3103019949187356597"\
  --run "\$R->set({t=>'INAM',f=>'ID'}, '3103019949187356598')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type INFO\
  --exact-id "3103019949187356598"\
  --run "\$R->set({t=>'NNAM',f=>'Next_ID'}, '3103019949187356597')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd dump "Morrowind.esm" --raw "${r}" --type INFO\
  --exact-id "3103019949187356597"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type INFO\
  --exact-id "3103019949187356597"\
  --run "\$R->set({t=>'PNAM',f=>'Prev_ID'}, '3103019949187356598')"\
  2>&1 | tee -a "${tlog}"

# 047. The_Vanilla_Quest_Tweaks_RP_Choices_Consequences_Super_Mega_Package_-_Ultimate_Edition.ESP - Dialogue fix
s="${s047}"
r="${r047dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "12653199392949220190" 2>&1 | tee -a "${tlog}"
r="${r047d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "12653199392949220190" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 171 (?): Syntax error
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "12653199392949220190"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
';Iulus Truptor
Choice \"No, but I\'m working on it.\" 1 \"I\'m sorry, but I can\'t seem to raise the gold.\" 2 \"Yes, I\'ve reached our goal.\" 3 \"Look, can I just pay the sum from my own pockets?\" 4')"\
  2>&1 | tee -a "${tlog}"

# # 048. abot Boats disable Scenic Ship in Seyda Neen
# s="${s048}"
# r="${r048nd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type GLOB\
#   --exact-id "ab01bonoseydaanchorship"\
#   2>&1 | tee -a "${tlog}"
# r="${r048n}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type GLOB\
#   --exact-id "ab01bonoseydaanchorship"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type GLOB\
#   --exact-id "ab01bonoseydaanchorship"\
#   --run "\$R->set({t=>'FLTV', f=>'Float'}, '1')"\
#   2>&1 | tee -a "${tlog}"

# 049. Rare Durzogs In Caves
# create durzog leveled lists
$tes3cmd dump --type levc --exact-id "in_cave_all_lev+0" Morrowind.esm --raw-with-header "${r049l}"
$tes3cmd delete "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --sub-match "Creature_ID:"
$tes3cmd delete "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --sub-match "Level:"
$tes3cmd modify "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --run "\
  \$R->set({t=>'NAME',f=>'ID'}, 'avp_in_cave_durzog_levc+0'), \
  \$R->set({t=>'INDX',f=>'Item_Count'}, '4'), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_wild_weaker'})), \
  \$R->append(LEVC::INTV->new({'level', '5'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_wild'})), \
  \$R->append(LEVC::INTV->new({'level', '10'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_diseased'})), \
  \$R->append(LEVC::INTV->new({'level', '12'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_war'})), \
  \$R->append(LEVC::INTV->new({'level', '20'}))"
$tes3cmd dump --type levc --exact-id "in_cave_all_lev+0" Morrowind.esm --raw "${r049l}"
$tes3cmd delete "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --sub-match "Creature_ID:"
$tes3cmd delete "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --sub-match "Level:"
$tes3cmd modify "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --run "\
  \$R->set({t=>'NAME',f=>'ID'}, 'avp_in_cave_durzog_levc+2'), \
  \$R->set({t=>'INDX',f=>'Item_Count'}, '4'), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_wild_weaker'})), \
  \$R->append(LEVC::INTV->new({'level', '7'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_wild'})), \
  \$R->append(LEVC::INTV->new({'level', '12'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_diseased'})), \
  \$R->append(LEVC::INTV->new({'level', '14'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_war'})), \
  \$R->append(LEVC::INTV->new({'level', '22'}))"
$tes3cmd dump --type levc --exact-id "in_cave_all_lev+0" Morrowind.esm --raw "${r049l}"
$tes3cmd delete "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --sub-match "Creature_ID:"
$tes3cmd delete "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --sub-match "Level:"
$tes3cmd modify "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --run "\
  \$R->set({t=>'NAME',f=>'ID'}, 'avp_in_cave_durzog_levc-1'), \
  \$R->set({t=>'INDX',f=>'Item_Count'}, '4'), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_wild_weaker'})), \
  \$R->append(LEVC::INTV->new({'level', '4'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_wild'})), \
  \$R->append(LEVC::INTV->new({'level', '9'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_diseased'})), \
  \$R->append(LEVC::INTV->new({'level', '11'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'durzog_war'})), \
  \$R->append(LEVC::INTV->new({'level', '19'}))"
# add durzogs to in_cave leveled lists
$tes3cmd dump --type levc --match in_cave_all_ Morrowind.esm --raw "${r049l}"
$tes3cmd modify "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --match "in_cave_all_lev" --run "\$R->delete({i=>[10..15]})"
$tes3cmd modify "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+0" --run "\
  \$R->set({t=>'INDX',f=>'Item_Count'}, '7'), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'avp_in_cave_durzog_levc+0'})), \
  \$R->append(LEVC::INTV->new({'level', '5'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk_diseased'})), \
  \$R->append(LEVC::INTV->new({'level', '6'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk'})), \
  \$R->append(LEVC::INTV->new({'level', '6'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk_blighted'})), \
  \$R->append(LEVC::INTV->new({'level', '8'}))"
$tes3cmd modify "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev+2" --run "\
  \$R->set({t=>'INDX',f=>'Item_Count'}, '7'), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'avp_in_cave_durzog_levc+2'})), \
  \$R->append(LEVC::INTV->new({'level', '7'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk_diseased'})), \
  \$R->append(LEVC::INTV->new({'level', '8'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk'})), \
  \$R->append(LEVC::INTV->new({'level', '8'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk_blighted'})), \
  \$R->append(LEVC::INTV->new({'level', '10'}))"
$tes3cmd modify "${r049l}" --hide-backups --backup-dir "${tmpd}" --type LEVC --exact-id "in_cave_all_lev-1" --run "\
  \$R->set({t=>'INDX',f=>'Item_Count'}, '7'), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'avp_in_cave_durzog_levc-1'})), \
  \$R->append(LEVC::INTV->new({'level', '4'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk_diseased'})), \
  \$R->append(LEVC::INTV->new({'level', '5'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk'})), \
  \$R->append(LEVC::INTV->new({'level', '5'})), \
  \$R->append(LEVC::CNAM->new({'creature_id', 'shalk_blighted'})), \
  \$R->append(LEVC::INTV->new({'level', '7'}))"

# 050. Tombs Leveled Lists Flag Fixed
# change in_tomb_ leveled lists flag to '1' for increasing variety
$tes3cmd dump --type levc --match in_tomb_all_ Morrowind.esm --raw-with-header "${r050l}"
$tes3cmd dump --type levc --match in_tomb_skele_ Morrowind.esm --raw "${r050l}"
$tes3cmd dump --type levc --match in_tomb_bone_ Morrowind.esm --raw "${r050l}"
$tes3cmd modify "${r050l}" --hide-backups --backup-dir "${tmpd}" --type levc --run "\$R->set({t=>'DATA', f=>'List_Flags'}, '1')"

# 051. Area Effect Projectiles Integrated - LeFemmArmor
s="${s051}"
r="${r051nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --exact-id "de_p_chest_02_aryne"\
  2>&1 | tee -a "${tlog}"
r="${r051n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --exact-id "de_p_chest_02_aryne"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CONT\
  --exact-id "de_p_chest_02_aryne"\
  --run "\
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'Domina_gauntlet_R'})), \
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'Domina_gauntlet_L'})), \
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'Domina_boots'})), \
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'Domina_greaves'})), \
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'Domina_pauldron_R'})), \
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'Domina_pauldron_L'})), \
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'Domina_cuirass'})), \
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'Domina_Helm'}))"\
  2>&1 | tee -a "${tlog}"

# 052. Area Effect Projectiles Integrated - Quill of Feyfolken 2.0
s="${s052}"
r="${r052nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --exact-id "de_r_closet_01_vari"\
  2>&1 | tee -a "${tlog}"
r="${r052n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --exact-id "de_r_closet_01_vari"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CONT\
  --exact-id "de_r_closet_01_vari"\
  --run "\
\$R->append(CONT::NPCO->new({'count', '-5', 'object', 'scrolls_blank1'})), \
\$R->append(CONT::NPCO->new({'count', '-5', 'object', 'scrolls_blank2'})), \
\$R->append(CONT::NPCO->new({'count', '-2', 'object', 'scrolls_blank3'})), \
\$R->append(CONT::NPCO->new({'count', '-2', 'object', 'scrolls_blank4'})), \
\$R->append(CONT::NPCO->new({'count', '-2', 'object', 'scrolls_blank5'})), \
\$R->append(CONT::NPCO->new({'count', '-1', 'object', 'scrolls_blank6'}))"\
  2>&1 | tee -a "${tlog}"

# # 053. Improved Inns Expanded - Entertainers - Camonna Tong
# s="${s053}"
# r="${r053nd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type NPC_\
#   --exact-id "darvam hlaren"\
#   2>&1 | tee -a "${tlog}"
# r="${r053n}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type NPC_\
#   --exact-id "darvam hlaren"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type NPC_\
#   --exact-id "darvam hlaren"\
#   --run "\
# \$R->set({t=>'CNAM', f=>'Class'}, 'Publican'), \
# \$R->set({t=>'SCRI', f=>'Script'}, 'Pub_Aldruhn_Council'), \
# \$R->set({t=>'AIDT', f=>'Services'}, '8208')"\
#   2>&1 | tee -a "${tlog}"

# # 054. BTBGI - auto-calc spells - QCVL
# s="${s054}"
# r="${r054nd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SPEL\
#   --exact-id "fireball_lich_elayne_u"\
#   --exact-id "dread_curse_hp_lich_elayne_u"\
#   --exact-id "barrierdrn_ferver_elayne_u"\
#   --exact-id "cavd_anduscovenspell01"\
#   --exact-id "cavd_tharencovenspell01"\
#   --exact-id "cavd_selarocovenspell01"\
#   --exact-id "cavd_ververcovenspell01"\
#   --exact-id "cavd_darethicovenspell01"\
#   --exact-id "summon_undead_nring_elayne_u"\
#   --exact-id "summon_01felara_elayne_u"\
#   --exact-id "summon_02felara_elayne_u"\
#   2>&1 | tee -a "${tlog}"
# r="${r054n}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SPEL\
#   --exact-id "fireball_lich_elayne_u"\
#   --exact-id "dread_curse_hp_lich_elayne_u"\
#   --exact-id "barrierdrn_ferver_elayne_u"\
#   --exact-id "cavd_anduscovenspell01"\
#   --exact-id "cavd_tharencovenspell01"\
#   --exact-id "cavd_selarocovenspell01"\
#   --exact-id "cavd_ververcovenspell01"\
#   --exact-id "cavd_darethicovenspell01"\
#   --exact-id "summon_undead_nring_elayne_u"\
#   --exact-id "summon_01felara_elayne_u"\
#   --exact-id "summon_02felara_elayne_u"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "fireball_lich_elayne_u" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "dread_curse_hp_lich_elayne_u" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "barrierdrn_ferver_elayne_u" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '48')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "cavd_anduscovenspell01" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '72'), \$R->set({t=>'ENAM', f=>'Duration'}, '30')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "cavd_tharencovenspell01" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '72')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "cavd_selarocovenspell01" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '48')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "cavd_ververcovenspell01" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '48')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "cavd_darethicovenspell01" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '48')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "summon_undead_nring_elayne_u" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '48')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "summon_01felara_elayne_u" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '192')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type SPEL\
#   --exact-id "summon_02felara_elayne_u" --run "\$R->set({t=>'SPDT', f=>'Flags'}, '0'), \$R->set({t=>'SPDT', f=>'Spell_Cost'}, '288')"\
#   2>&1 | tee -a "${tlog}"

# 055. Vampire Clans - Clutter Monkey Overhaul - QCVL
s="${s055}"
r="${r055cd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CELL\
  --exact-id "galom daeus, observatory"\
  --instance-match "Name:Moricius_BER"\
  2>&1 | tee -a "${tlog}"
r="${r055c}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CELL\
  --exact-id "galom daeus, observatory"\
  --instance-match "Name:Moricius_BER"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type TES3\
  --run "\
  \$R->append(TES3::MAST->new({'master', 'Morrowind.esm'})),\
  \$R->append(TES3::DATA->new({'length', '79837557'})),\
  \$R->append(TES3::MAST->new({'master', '${s055}'})),\
  \$R->append(TES3::DATA->new({'length', '2929882'}))"\
  2>&1 | tee -a "${tlog}"
$tes3cmd header "${r}" --hide-backups --backup-dir "${tmpd}" --synchronize 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CELL\
  --exact-id "galom daeus, observatory"\
  --run "\
  \$R->set({i=>[4], f=>'X'}, '3600'),\
  \$R->set({i=>[4], f=>'Y'}, '3300')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CELL\
  --exact-id "galom daeus, observatory"\
  --run "\$R->set({i=>[2], f=>'MastIdx'}, '2')"\
  2>&1 | tee -a "${tlog}"

## 056. TR_Factions - Morag Tong Polished
#s="${s056}"
#r="${r056sd}"
#$tes3cmd dump "${s}" --raw-with-header "${r}"\
#  --type SCPT\
#  --exact-id "counttelvannihortator"\
#  2>&1 | tee -a "${tlog}"
## Line 35
## if ( GetDeadCount Neloth >= 1 )
## ->
## if ( GetJournalIndex "CS_Neloth" >= 20 )
## actually inserted at L37
##	else
##		if ( GetJournalIndex "CS_Neloth" >= 20 )
##			set HortatorVotes to ( HortatorVotes + 1 )
##		endif

# 057. Camonna Tong - Disable MWSE-scripts
s="${s057}"
r="${r057sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "cs_ctlumt"\
  --exact-id "cs_ctlusc"\
  2>&1 | tee -a "${tlog}"

# # 058. Cyrodiil_Main - Change deprecated NPC faction to suppress OpenMW warning
# s="${s058}"
# r="${r058nd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type NPC_\
#   --exact-id "pc_gc_guard"\
#   2>&1 | tee -a "${tlog}"
# r="${r058n}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type NPC_\
#   --exact-id "pc_gc_guard"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type NPC_\
#   --exact-id "pc_gc_guard"\
#   --replace '/T_Cyr_ImperialWatch/T_Cyr_ImperialLegion/'\
#   2>&1 | tee -a "${tlog}"

# 2022.07.10 disable these patches due to being outdated with Vvardenfell Brotherhood v1.17
# 059. VB_EmynDB_Patch - Dialogue Fix
# s="${s059}"
# r="${r059nd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO\
#   --exact-id "14552225132801142"\
#   --exact-id "1951228827310408144"\
#   --exact-id "284922073883066542"\
#   --exact-id "31558240422026212789"\
#   2>&1 | tee -a "${tlog}"
# r="${r059n}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO\
#   --exact-id "14552225132801142"\
#   --exact-id "1951228827310408144"\
#   --exact-id "284922073883066542"\
#   --exact-id "31558240422026212789"\
#   2>&1 | tee -a "${tlog}"
# # delete "nefarious"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type INFO\
#   --exact-id "14552225132801142"\
#   --run "\$R->set({t=>'NAME',f=>'Response'}, \
# 'You look like the sort of person I need. May I interest you in some work?')"\
#   2>&1 | tee -a "${tlog}"
# # delete "the"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type INFO\
#   --exact-id "1951228827310408144"\
#   --run "\$R->set({t=>'NAME',f=>'Response'}, \
# 'Come back to me once Drelis Ondyn is dead.')"\
#   2>&1 | tee -a "${tlog}"
# # add one more choice 1 response
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type INFO\
#   --exact-id "284922073883066542"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Choice \"You smell foul.\" 1 \"To never raise a child like you.\" 1 \"Don\'t look at me with that disgusting look.\" 1 \"[Attack him.]\" 6 \"Nothing.\" 2')"\
#   2>&1 | tee -a "${tlog}"
# # formerly -> formally
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type INFO\
#   --exact-id "31558240422026212789"\
#   --run "\$R->set({t=>'NAME',f=>'Response'}, \
# 'The Altmer at the very top of the Mythic Dawn wishes for the Vvardenfell Brotherhood to be formally recognised as the eastern denomination of the Mythic Dawn. Expansion is imperative to the success of our mission, which if you accept this offer, you will soon learn all about. Please, %PCName, do not see your newfound leadership as a means of continuing a dying vision of Sithis, but instead see it as the beginning of something new. What do you say, friend? Will you lead the Mythic Dawn in the east?')"\
#   2>&1 | tee -a "${tlog}"

# fixed upstream
# 060. Vvardenfell Brotherhood - Dialogue Script Fix
# s="${s060}"
# r="${r060dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1119916988305838000" 2>&1 | tee -a "${tlog}"
# r="${r060d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1119916988305838000" 2>&1 | tee -a "${tlog}"
# # Error: line 1, column 98 (4): Unexpected numeric value
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "1119916988305838000"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Choice \"[Spit at him.]\" 4 \"I curse you and your kin. You ought to get what is coming to you.\" 4 \"Do you actually think you contribute anything to society? Your existence challenges the will to live of those around you.\" 4')"\
#   2>&1 | tee -a "${tlog}"

# 061. Ashlander Traders Remastered - Backport NoLore
s="${s061}"
r="${r061sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "cv_enable"\
  2>&1 | tee -a "${tlog}"

# 062. QCVL - fix conflict with Sotha Sil Expanded
s="${s062}"
r="${r062dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "hello" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1709302711210241" 2>&1 | tee -a "${tlog}"
r="${r062d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "hello" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1709302711210241" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "1709302711210241"\
  --run "\$R->set({t=>'PNAM',f=>'Prev_ID'}, '1499199543096224590')"\
  2>&1 | tee -a "${tlog}"

# fixed in v1.01
# # 063. The Rise of the Tribe Unmourned - Dialogue Script Fix
# s="${s063}"
# r="${r063dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "tear of st. meris" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "208842575813514869" 2>&1 | tee -a "${tlog}"
# r="${r063d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "tear of st. meris" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "208842575813514869" 2>&1 | tee -a "${tlog}"
# # Error: line 3, column 7 (FadeTo): Unexpected keyword
# # extra " in the end
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "208842575813514869"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Journal CS_Blades07 10
# \"Vedran Balen\"->Disable
# FadeTo 100 0.5
# FadeTo 0 2.0
# Goodbye')"\
#   2>&1 | tee -a "${tlog}"

# 064. Quests for Clans and Vampire Legends - Morrowind Anti-Cheese(Mastrius weaker items)
s="${s064}"
r="${r064nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "mastrius_elayne_u" \
  --exact-id "mastrius"\
  2>&1 | tee -a "${tlog}"
r="${r064n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "mastrius_elayne_u" \
  --exact-id "mastrius"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --replace '/^ebony_cuirass$/bonemold_cuirass/' 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --replace '/^ebony_shield$/steel_towershield/' 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --replace '/^ebony_pauldron_right$/steel_pauldron_right/' 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --replace '/^ebony_pauldron_left$/steel_pauldron_left/' 2>&1 | tee -a "${tlog}"

# 065. "Boys in the Hood - Balmora Waterworks" (merge changes of both mods to Heddvild NPC - both key and script)
s="${s065}"
r="${r065nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "heddvild" \
  2>&1 | tee -a "${tlog}"
r="${r065n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "heddvild" \
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --exact-id "heddvild" --run "\$R->append(NPC_::NPCO->new({'count', '1', 'object', 'key_heddvild'}))"\
  2>&1 | tee -a "${tlog}"

# 066. "FMI_HulStop 1.6 - Balmora Waterworks" (merge changes of both mods to Hul NPC - both key and script)
s="${s066}"
r="${r066nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "hul" \
  2>&1 | tee -a "${tlog}"
r="${r066n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "hul" \
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --exact-id "hul" --run "\$R->append(NPC_::NPCO->new({'count', '1', 'object', 'key_hul'}))"\
  2>&1 | tee -a "${tlog}"

# 067. "riders - Your Own Ashlander Tribe" (make rider in Salit camp peaceful)
s="${s067}"
r="${r067nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "rot_rider_ashlander2" \
  2>&1 | tee -a "${tlog}"
r="${r067n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "rot_rider_ashlander2" \
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --exact-id "rot_rider_ashlander2" --run "\$R->set({t=>'AIDT', f=>'Hello'}, '20'), \$R->set({t=>'AIDT', f=>'Fight'}, '40'), \$R->set({t=>'AIDT', f=>'Alarm'}, '90')"\
  2>&1 | tee -a "${tlog}"

# 068. RP House Hlaalu - Disable MWSE-scripts
s="${s068}"
r="${r068sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "cs_hhlumt"\
  --exact-id "cs_hhlusc"\
  2>&1 | tee -a "${tlog}"

# 069. "Census and Excise Office Faction - BTBGI - Contraband"(change prices for giving in contraband)
s="${s069}"
r="${r069sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "moon sugar" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "2119322897186808461" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "raw ebony" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "733413085308724908" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type BOOK --exact-id "aa_censuslist" 2>&1 | tee -a "${tlog}"
r="${r069s}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "moon sugar" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "2119322897186808461" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "raw ebony" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "733413085308724908" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type BOOK --exact-id "aa_censuslist" 2>&1 | tee -a "${tlog}"

$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO --exact-id "2119322897186808461" --replace "/gold_001\" 50/gold_001\" 25/" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO --exact-id "733413085308724908" --replace "/gold_001\" 200/gold_001\" 100/" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type BOOK --exact-id "aa_censuslist" --replace\
 "/We give 50 gold for a portion of Moon Sugar, 200 gold for a piece of Raw Ebony,/We give 25 gold for a portion of Moon Sugar, 100 gold for a piece of Raw Ebony,/"\
 2>&1 | tee -a "${tlog}"

# 070. Missing Snow Armor - "bm wolf shield" stats
s="${s070}"
r="${r070nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ARMO\
  --exact-id "bm wolf shield"\
  2>&1 | tee -a "${tlog}"
r="${r070n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ARMO\
  --exact-id "bm wolf shield"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type ARMO\
  --exact-id "bm wolf shield"\
  --run "\
\$R->set({t=>'AODT',f=>'Enchantment'}, '80'),\
\$R->set({t=>'AODT',f=>'AR'}, '20')"\
  2>&1 | tee -a "${tlog}"

# 071. Grandfather Frost - "fur_colovian_helm_red" stats
s="${s071}"
r="${r071nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ARMO\
  --exact-id "fur_colovian_helm_red"\
  2>&1 | tee -a "${tlog}"
r="${r071n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ARMO\
  --exact-id "fur_colovian_helm_red"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type ARMO\
  --exact-id "fur_colovian_helm_red"\
  --run "\
\$R->set({t=>'AODT',f=>'Weight'}, '0.5'),\
\$R->set({t=>'AODT',f=>'Enchantment'}, '35'),\
\$R->set({t=>'AODT',f=>'AR'}, '1')"\
  2>&1 | tee -a "${tlog}"

# 072. Entertainers Expanded - "fur_colovian_helm" stats
s="${s072}"
r="${r072nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ARMO\
  --exact-id "fur_colovian_helm"\
  2>&1 | tee -a "${tlog}"
r="${r072n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ARMO\
  --exact-id "fur_colovian_helm"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type ARMO\
  --exact-id "fur_colovian_helm"\
  --run "\
\$R->set({t=>'AODT',f=>'Weight'}, '0.5'),\
\$R->set({t=>'AODT',f=>'Enchantment'}, '35'),\
\$R->set({t=>'AODT',f=>'AR'}, '1')"\
  2>&1 | tee -a "${tlog}"

# 073. Camonna Tong - Adamantium Armor Integrated - UL - Anti-Cheese - Raven
s="${s073}"
r="${r073nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "sorkvild the raven"\
  2>&1 | tee -a "${tlog}"
r="${r073n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "sorkvild the raven"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type NPC_\
  --exact-id "sorkvild the raven"\
  --run "\
\$R->set({t=>'NPDT',f=>'Level'}, '26'),\
\$R->set({t=>'NPDT',f=>'Health'}, '230'),\
\$R->set({t=>'NPDT',f=>'Magicka'}, '210'),\
\$R->set({t=>'NPDT',f=>'Fatigue'}, '350'),\
\$R->append(NPC_::NPCO->new({'count', '1', 'object', 'bk_DaedricSummoning_2c'})),\
\$R->append(NPC_::NPCS->new({'spell', 'summon greater bonewalker'}))"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --exact-id "sorkvild the raven" --replace\
 "/bonemold_boots/adamantium boots/"\
 2>&1 | tee -a "${tlog}"

# 074. Siege at Firemoth Naturalized - BTBGI - Ward of Akavir Enchanting
# tone down Naturalized or boost original, resist magicka and weapons 25 -> 5
s="${s074}"
r="${r074nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ENCH\
  --exact-id "ward of akavir_en"\
  2>&1 | tee -a "${tlog}"
r="${r074n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type ENCH\
  --exact-id "ward of akavir_en"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type ENCH\
  --exact-id "ward of akavir_en"\
  --run "\
\$R->set({i=>[3], f=>'Mag_Min'}, '5'),\
\$R->set({i=>[3], f=>'Mag_Max'}, '5'),\
\$R->set({i=>[4], f=>'Mag_Min'}, '5'),\
\$R->set({i=>[4], f=>'Mag_Max'}, '5')"\
  2>&1 | tee -a "${tlog}"

# 075. Master Index Naturalized - Dialogue Script Fix
s="${s075}"
r="${r075dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "master index" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "11326105111042521817" 2>&1 | tee -a "${tlog}"
r="${r075d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "master index" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "11326105111042521817" 2>&1 | tee -a "${tlog}"
# Error: line 3, column 1 (<newline>): Missing expression
# missing "count" after additem
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "11326105111042521817"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Player->RemoveItem \"Gold_001\" 2500
Player->AddItem \"index_master\" 1')" 2>&1 | tee -a "${tlog}"

# 076. Siege at Firemoth Naturalized - Dialogue Script Fix
s="${s076}"
r="${r076dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO\
  --exact-id "282577121279469046"\
  --exact-id "216664319542320611"\
  --exact-id "231346222013627146"\
  --exact-id "388526397617818011"\
  --exact-id "32477187732497926178"\
  --exact-id "21192284342333425021"\
  --exact-id "168224964735621032"\
  2>&1 | tee -a "${tlog}"
r="${r076d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO\
  --exact-id "216664319542320611"\
  --exact-id "231346222013627146"\
  --exact-id "282577121279469046"\
  --exact-id "21192284342333425021"\
  --exact-id "32477187732497926178"\
  --exact-id "388526397617818011"\
  --exact-id "168224964735621032"\
  2>&1 | tee -a "${tlog}"
# All of the following have the same problem, aifollow's first argument should be target, i.e. player
# Error: line 1, column 11 (0): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "216664319542320611"\
  --exact-id "231346222013627146"\
  --exact-id "282577121279469046"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'AiFollow Player 0 0 0 0 0
Goodbye')" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 35 (0): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "21192284342333425021"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'if ( GetDeadCount \"firemoth_warrior\" == 0 )
    \"firemoth_warrior\"->AiFollow Player 0 0 0 0 0
endif

if ( GetDeadCount \"firemoth_archer\" == 0 )
    \"firemoth_archer\"->AiFollow Player 0 0 0 0 0
endif
		
if ( \"firemoth_sailor\".state == 25 )
    if ( GetDeadCount \"firemoth_cat\" == 0 )
        \"firemoth_cat\"->AiFollow Player 0 0 0 0 0
    endif
endif

AiFollow Player 0 0 0 0 0
Goodbye')" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 35 (0): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "32477187732497926178"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'if ( GetDeadCount \"firemoth_archer\" == 0 )
    \"firemoth_archer\"->AiFollow Player 0 0 0 0 0
endif

if ( GetDeadCount \"firemoth_mage\" == 0 )
    \"firemoth_mage\"->AiFollow Player 0 0 0 0 0
endif
		
if ( \"firemoth_sailor\".state == 25 )
    if ( GetDeadCount \"firemoth_cat\" == 0 )
        \"firemoth_cat\"->AiFollow Player 0 0 0 0 0
    endif
endif

AiFollow Player 0 0 0 0 0
Goodbye')" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 35 (0): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "388526397617818011"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'if ( GetDeadCount \"firemoth_warrior\" == 0 )
    \"firemoth_warrior\"->AiFollow Player 0 0 0 0 0
endif

if ( GetDeadCount \"firemoth_mage\" == 0 )
    \"firemoth_mage\"->AiFollow Player 0 0 0 0 0
endif
		
if ( \"firemoth_sailor\".state == 25 )
    if ( GetDeadCount \"firemoth_cat\" == 0 )
        \"firemoth_cat\"->AiFollow Player 0 0 0 0 0
    endif
endif

AiFollow Player 0 0 0 0 0
Goodbye')" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 34 (0): Unexpected numeric value
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "168224964735621032"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'if ( GetDeadCount \"firemoth_warrior\" == 0 )
    \"firemoth_warrior\"->AiFollow Player 0 0 0 0 0
endif

if ( GetDeadCount \"firemoth_archer\" == 0 )
    \"firemoth_archer\"->AiFollow Player 0 0 0 0 0
endif

if ( GetDeadCount \"firemoth_mage\" == 0 )
    \"firemoth_mage\"->AiFollow Player 0 0 0 0 0
endif

AiFollow Player 0 0 0 0 0
Goodbye')" 2>&1 | tee -a "${tlog}"


# 075. FMI_ServiceRefusal_Contraband - After the Blight - Bolrin
s="${s077}"
r="${r077nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "bolrin"\
  2>&1 | tee -a "${tlog}"
r="${r077n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type NPC_\
  --exact-id "bolrin"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type NPC_\
  --exact-id "bolrin"\
  --run "\
\$R->set({t=>'SCRI', f=>'Script'}, 'CS_BolrinScript1')"\
  2>&1 | tee -a "${tlog}"

# 078. After the Blight - Disable MWSE scripts
s="${s078}"
r="${r078sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "cs_atblumt"\
  --exact-id "cs_atblusc"\
  2>&1 | tee -a "${tlog}"

# # 079. "lack_stridersnest - No Autocalc spells.esp"(The Strider's Nest - Companions and Quests, remove autocalc flag)
# s="${s079}"
# r="${r079nd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SPEL\
#   --match "Flags:\[0x000[15]"\
#   2>&1 | tee -a "${tlog}"
# r="${r079n}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type SPEL\
#   --match "Flags:\[0x000[15]"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type SPEL\
#   --match "Flags:\[0x0001"\
#   --run "\
# \$R->set({t=>'SPDT', f=>'Flags'}, '0')"\
#   2>&1 | tee -a "${tlog}"
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type SPEL\
#   --match "Flags:\[0x0005"\
#   --run "\
# \$R->set({t=>'SPDT', f=>'Flags'}, '4')"\
#   2>&1 | tee -a "${tlog}"

# 080. "BT_Whitewolf_2_0_HOTV - Bloodmoon Rebalance.esp"(skeleton nord_2 from BMR, non-public)
s="${s080}"
r="${r080nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "skeleton nord_2"\
  2>&1 | tee -a "${tlog}"
r="${r080n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "skeleton nord_2"\
  2>&1 | tee -a "${tlog}"

# # 081."SV - Terrors Of The Night Normal - Sirollus Saccus Services Override.esp"(sirollus saccus services override, non-public)
# s="${s081}"
# r="${r081nd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type NPC_\
#   --exact-id "sirollus saccus"\
#   2>&1 | tee -a "${tlog}"
# r="${r081n}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type NPC_\
#   --exact-id "sirollus saccus"\
#   2>&1 | tee -a "${tlog}"
# # 0x24203
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
#   --type NPC_\
#   --exact-id "sirollus saccus"\
#   --run "\
# \$R->set({t=>'AIDT', f=>'Services'}, '147971')"\
#   2>&1 | tee -a "${tlog}"

# # 082. "TeaMod_2.1 - UL_3.5_TR Doily Override.esp"(st_doily misc override, non-public)
# s="${s082}"
# r="${r082nd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type MISC\
#   --exact-id "st_doily_03"\
#   --exact-id "st_doily_04"\
#   2>&1 | tee -a "${tlog}"
# r="${r082n}"
# $tes3cmd dump "${s}" --raw-with-header "${r}"\
#   --type MISC\
#   --exact-id "st_doily_03"\
#   --exact-id "st_doily_04"\
#   2>&1 | tee -a "${tlog}"

# 083. "Solstheim Tomb of The Snow Prince - Bloodmoon Rebalance"(merge changes of The Swimmer)
s="${s083}"
r="${r083nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "bm_horker_swim_unique"\
  2>&1 | tee -a "${tlog}"
r="${r083n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "bm_horker_swim_unique"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CREA\
  --exact-id "bm_horker_swim_unique"\
  --run "\
\$R->set({t=>'NPDT',f=>'Health'}, '200'),\
\$R->set({t=>'NPDT',f=>'Attack_Min_1'}, '15'),\
\$R->set({t=>'NPDT',f=>'Attack_Min_2'}, '15'),\
\$R->set({t=>'NPDT',f=>'Attack_Min_3'}, '15'),\
\$R->set({t=>'NPDT',f=>'Attack_Max_1'}, '20'),\
\$R->set({t=>'NPDT',f=>'Attack_Max_2'}, '20'),\
\$R->set({t=>'NPDT',f=>'Attack_Max_3'}, '20')"\
  2>&1 | tee -a "${tlog}"

# 084. "SHS - Bloodskal Barrow - Bloodmoon Rebalance"(bloodskal draugr BMR override)
s="${s084}"
r="${r084nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "bm_draugr_bloodskal"\
  --exact-id "bm_sk_champ_bloodskal01"\
  --exact-id "bm_sk_champ_bloodskal02"\
  2>&1 | tee -a "${tlog}"
r="${r084n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "bm_draugr_bloodskal"\
  --exact-id "bm_sk_champ_bloodskal01"\
  --exact-id "bm_sk_champ_bloodskal02"\
  2>&1 | tee -a "${tlog}"

# 085. "Hunter's Mark - A Marksman Mod - TOTSP TD Content Integration"(merge nordictomb cont, non-public)
s="${s085}"
r="${r085nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --exact-id "bm_nordictomb_01"\
  2>&1 | tee -a "${tlog}"
r="${r085n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --exact-id "bm_nordictomb_01"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type CONT --exact-id "bm_nordictomb_01" --replace\
 "/random_ingredient/wl_bm_random_ingredient/"\
 2>&1 | tee -a "${tlog}"

# 086. "Morrowind - DA_Sobitur Cont Override"(override sobitur's changes to daed conts, non-public) 
s="${s086}"
r="${r086nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --exact-id "com_chest_daed_ruin_01"\
  --exact-id "com_chest_daed_cursed"\
  2>&1 | tee -a "${tlog}"
r="${r086n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CONT\
  --exact-id "com_chest_daed_ruin_01"\
  --exact-id "com_chest_daed_cursed"\
  2>&1 | tee -a "${tlog}"

# 087. "Patch for Purists - Book Typos - Semi-Puris Fixes.esp"(merge 4 books changes from both, non-public)
s="${s087}"
r="${r087nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type BOOK\
  --exact-id "bk_ilhermit_page"\
  --exact-id "bk_notetoamaya"\
  --exact-id "sc_chappy_sniper_test"\
  --exact-id "sc_hiddenkiller"\
  2>&1 | tee -a "${tlog}"
r="${r087n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type BOOK\
  --exact-id "bk_ilhermit_page"\
  --exact-id "bk_notetoamaya"\
  --exact-id "sc_chappy_sniper_test"\
  --exact-id "sc_hiddenkiller"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type BOOK\
  --exact-id "bk_ilhermit_page"\
  --run "\
\$R->set({t=>'BKDT',f=>'Weight'}, '0.1')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type BOOK\
  --exact-id "bk_notetoamaya"\
  --run "\
\$R->set({t=>'BKDT',f=>'Weight'}, '0.1')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type BOOK\
  --exact-id "sc_chappy_sniper_test"\
  --run "\
\$R->set({t=>'BKDT',f=>'Weight'}, '0.2'),\
\$R->set({t=>'ITEX',f=>'Icon'}, 'm\\Tx_scroll_open_01.tga')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type BOOK\
  --exact-id "sc_hiddenkiller"\
  --run "\
\$R->set({t=>'BKDT',f=>'Weight'}, '0.2'),\
\$R->set({t=>'ITEX',f=>'Icon'}, 'm\\Tx_scroll_open_01.tga')"\
  2>&1 | tee -a "${tlog}"

# 088. AliceL93's Vanilla Quest Tweaks - TR_Factions(resolve conflict between mods)
s="${s088}"
r="${r088dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "telvanni bride" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1772430844181427661" 2>&1 | tee -a "${tlog}"
r="${r088d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "telvanni bride" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1772430844181427661" 2>&1 | tee -a "${tlog}"
# Both mods add lines, there should be merge between them, also change condition to TR's
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "1772430844181427661"\
  --run "\$R->set({t=>'SCVR',f=>'Comparison'}, '3')" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "1772430844181427661"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
';Ashkhan Kaushad; Journal \"B3_ZainabBride\" >= 47;
Journal \"B3_ZainabBride\" 50
ModDisposition 20
Player->ModReputation 1
Player->additem \"Thong\" 1
;line from TR_Factions
set TR_Fac_NerevarineCount to ( TR_Fac_NerevarineCount + 1 )
;line from AliceL93 mod
Choice \"Thank you, Ashkhan.\" 1 \"Thank you, Ashkhan. But I have to confess: This Dunmer is not a Telvanni, but a mere slave. I hope that you will forgive me, and accept her, because no Telvanni would marry an Ashlander.\" 2')" 2>&1 | tee -a "${tlog}"

# 089. ABCmod - Dagoth Ur Voice Addon
s="${s089}"
r="${r089nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "heart_akulakhan"\
  2>&1 | tee -a "${tlog}"
r="${r089n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "heart_akulakhan"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CREA\
  --exact-id "heart_akulakhan"\
  --run "\$R->set({t=>'SCRI', f=>'Script'}, 'MrTSLorkhanHeart')"\
  2>&1 | tee -a "${tlog}"

# 090. Beware the Sixth House - Dagoth Ur Voice Addon
s="${s090}"
r="${r090nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "dagoth_ur_1"\
  --exact-id "dagoth_ur_2"\
  2>&1 | tee -a "${tlog}"
r="${r090n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "dagoth_ur_1"\
  --exact-id "dagoth_ur_2"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CREA\
  --exact-id "dagoth_ur_1"\
  --run "\$R->set({t=>'SCRI', f=>'Script'}, 'MrTSDagothUrCreature1')"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CREA\
  --exact-id "dagoth_ur_2"\
  --run "\$R->set({t=>'SCRI', f=>'Script'}, 'MrTSDagothUrCreature2')"\
  2>&1 | tee -a "${tlog}"

# 091. Almalexia_Voicev1 - PFP
s="${s091}"
r="${r091dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "task" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO\
  --exact-id "1406841961381683"\
  2>&1 | tee -a "${tlog}"
r="${r091d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "task" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO\
  --exact-id "1406841961381683"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "1406841961381683"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'Set AlmaVoiceID to 76
StartScript AlmaSpeak
Journal TR_ShowPower 10')" 2>&1 | tee -a "${tlog}"

# 092. Almalexia_Voicev1 - Sotha Sil Expanded
s="${s092}"
r="${r092dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "unstable" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1453930628980165" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "clockwork city" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "23739682074468576" 2>&1 | tee -a "${tlog}"
r="${r092d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "unstable" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1453930628980165" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type DIAL --exact-id "clockwork city" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "23739682074468576" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "1453930628980165"\
  --run "\$R->set({t=>'PNAM',f=>'Prev_ID'}, '19666144551355921308')" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "23739682074468576"\
  --run "\$R->set({t=>'PNAM',f=>'Prev_ID'}, '785337941841419837')" 2>&1 | tee -a "${tlog}"

# 093. FMI - Alice's Package - Entertainers Expanded
s="${s093}"
r="${r093nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type NPC_ --exact-id "dorisa darvel" 2>&1 | tee -a "${tlog}"
r="${r093n}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type NPC_ --exact-id "dorisa darvel" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type NPC_ --exact-id "dorisa darvel"\
  --run "\$R->append(NPC_::NPCO->new({'count', '1', 'object', 'bk_Balladeers_Fakebook'}))" 2>&1 | tee -a "${tlog}"

# 094. Taskmaster of House Telvanni Part I - Script Fix
s="${s094}"
r="${r094dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "100181125124417843" 2>&1 | tee -a "${tlog}"
r="${r094d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 1" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "100181125124417843" 2>&1 | tee -a "${tlog}"
# Error: line 2, column 17 (Swims-in-Shadows): Unexpected name
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "100181125124417843"\
  --run "\$R->set({t=>'BNAM',f=>'Result'}, \
'addtopic \"Dwemer device\"
addtopic \"Swims-in-Shadows\"')" 2>&1 | tee -a "${tlog}"

# 095. Patch for Purists - INFO Override
s="${s095}"
r="${r095dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1288227500790714973" 2>&1 | tee -a "${tlog}"
r="${r095d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "greeting 5" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "1288227500790714973" 2>&1 | tee -a "${tlog}"

# 096. tribunal rebalance - Hunter's Mark(merge changes for goblins - add rem's arrows)
s="${s096}"
r="${r096nd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "goblin_grunt"\
  --exact-id "goblin_handler"\
  2>&1 | tee -a "${tlog}"
r="${r096n}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CREA\
  --exact-id "goblin_grunt"\
  --exact-id "goblin_handler"\
  2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type CREA --exact-id "goblin_grunt"\
  --run "\$R->append(NPC_::NPCO->new({'count', '5', 'object', 'rem_goblin_arrow'}))" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type CREA --exact-id "goblin_handler"\
  --run "\$R->append(NPC_::NPCO->new({'count', '10', 'object', 'rem_goblin_arrow'}))" 2>&1 | tee -a "${tlog}"

# 097. Magical Missions - Patch for Purists
s="${s097}"
r="${r097dd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "duties" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "252869918238779866" 2>&1 | tee -a "${tlog}"
r="${r097d}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "duties" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type INFO --exact-id "252869918238779866" 2>&1 | tee -a "${tlog}"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
  --exact-id "252869918238779866"\
  --run "\$R->set({t=>'NNAM',f=>'Next_ID'}, '2567018606192071310')" 2>&1 | tee -a "${tlog}"

# 098. OAAB Brother Junipers Twin Lamps - Camonna Tong Compatibility Patch(script and npc changes merged)
s="${s098}"
r="${r098sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}" --type NPC_ --exact-id "galyn arvel" 2>&1 | tee -a "${tlog}"
$tes3cmd dump "${s}" --raw "${r}" --type SCPT --exact-id "TL_GalynScript" 2>&1 | tee -a "${tlog}"
# merge 2 scripts together in CS to let Morrowind.exe users also be able to use it
# tes3cmd modify x.esp --type NPC_ --exact-id "galyn arvel" --run "\$R->append(NPC_::NPCO->new({'count', '1', 'object', 'CS_FairKey'}))"
# tes3cmd modify x.esp --type NPC_ --exact-id "galyn arvel" --run "\$R->set({t=>'AIDT', f=>'Unknown_2'}, '0')"
# tes3cmd modify x.esp --type NPC_ --exact-id "galyn arvel" --run "\$R->set({t=>'FLAG', f=>'Flags'}, '25')"

# 099. Patch for Purists - Clean_Mines & Caverns - Mat(floating items in Mat fixed)
s="${s099}"
r="${r099cd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CELL\
  --exact-id "Mat"\
  --instance-match "ObjIdx:11(4|5|6|7) "\
  2>&1 | tee -a "${tlog}"
r="${r099c}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type CELL\
  --exact-id "Mat"\
  --instance-match "ObjIdx:11(4|5|6|7) "\
  2>&1 | tee -a "${tlog}"
$tes3cmd delete "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CELL\
  --exact-id "Mat"\
  --instance-match "ObjIdx:11(4|5|6|7) "
# \$R->append(CELL::DATA->new({'x', '4881.097', 'y', '6733.234', 'z', '7613.222', 'x_angle', '0.0000', 'y_angle', '0.0000', 'z_angle', '1.5292'})), \
# \$R->append(CELL::DATA->new({'x', '4882.347', 'y', '6803.812', 'z', '7611.763', 'x_angle', '0.0000', 'y_angle', '0.0000', 'z_angle', '2.1000'})), \
# \$R->append(CELL::DATA->new({'x', '4934.200', 'y', '6834.688', 'z', '7613.875', 'x_angle', '0.0000', 'y_angle', '0.0000', 'z_angle', '5.7416'})), \
# \$R->append(CELL::DATA->new({'x', '4921.743', 'y', '6690.090', 'z', '7626.595', 'x_angle', '0.0000', 'y_angle', '0.0000', 'z_angle', '0.0000'})), \
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type CELL\
  --exact-id "Mat"\
  --run "\
  \$R->append(CELL::FRMR->new({'objidx', '114', 'mastidx', '4'})), \
  \$R->append(CELL::NAME->new({'name', 'furn_de_pathspear_04'})), \
  \$R->append(CELL::XSCL->new({'scale', '0.50'})), \
  \$R->append(CELL::DELE->new({'deleted', '4729956'})), \
  \$R->append(CELL::FRMR->new({'objidx', '115', 'mastidx', '4'})), \
  \$R->append(CELL::NAME->new({'name', 'furn_de_pathspear_03'})), \
  \$R->append(CELL::XSCL->new({'scale', '0.50'})), \
  \$R->append(CELL::DELE->new({'deleted', '4729956'})), \
  \$R->append(CELL::FRMR->new({'objidx', '116', 'mastidx', '4'})), \
  \$R->append(CELL::NAME->new({'name', 'furn_de_pathspear_04'})), \
  \$R->append(CELL::XSCL->new({'scale', '0.50'})), \
  \$R->append(CELL::DELE->new({'deleted', '4729956'})), \
  \$R->append(CELL::FRMR->new({'objidx', '117', 'mastidx', '4'})), \
  \$R->append(CELL::NAME->new({'name', 'barrel_02_CheapFood5'})), \
  \$R->append(CELL::DELE->new({'deleted', '4729956'}))"
$tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}"\
  --type TES3\
  --run "\
  \$R->append(TES3::MAST->new({'master', 'Morrowind.esm'})),\
  \$R->append(TES3::DATA->new({'length', '79837557'})),\
  \$R->append(TES3::MAST->new({'master', 'Tribunal.esm'})), \
  \$R->append(TES3::DATA->new({'length', '4565686'})), \
  \$R->append(TES3::MAST->new({'master', 'Bloodmoon.esm'})), \
  \$R->append(TES3::DATA->new({'length', '9631798'})), \
  \$R->append(TES3::MAST->new({'master', '${s}'})), \
  \$R->append(TES3::DATA->new({'length', '2994440'}))"\
  2>&1 | tee -a "${tlog}"
$tes3cmd header "${r}" --hide-backups --backup-dir "${tmpd}" --synchronize 2>&1 | tee -a "${tlog}"

# 100. OAAB Brother Junipers Twin Lamps - Script Fix(tl_invasion didn't compile on OpenMW due to wrong commands)
s="${s100}"
r="${r100sd}"
$tes3cmd dump "${s}" --raw-with-header "${r}"\
  --type SCPT\
  --exact-id "tl_invasion"\
  2>&1 | tee -a "${tlog}"

# 101. OAAB_Tel Mora - Script Fix(2 dialogue fixes)
# s="${s101}"
# r="${r101dd}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "vampires attacking tel mora" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO\
#   --exact-id "993331968210417576"\
#   --exact-id "17903147822645032645"\
#   2>&1 | tee -a "${tlog}"
# r="${r101d}"
# $tes3cmd dump "${s}" --raw-with-header "${r}" --type DIAL --exact-id "vampires attacking tel mora" 2>&1 | tee -a "${tlog}"
# $tes3cmd dump "${s}" --raw "${r}" --type INFO\
#   --exact-id "993331968210417576"\
#   --exact-id "17903147822645032645"\
#   2>&1 | tee -a "${tlog}"
# # Error: line 5, column 1 (<newline>): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "993331968210417576"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Player->RemoveItem \"ingred_corprus_weepings_01\" 1
# Player->RemoveItem \"ingred_vampire_dust_01\" 1
# MessageBox \"[Endar Drenim takes the ingredients and recites an incantation over a scroll in his hand.]\"
# Say \"Vo\d\m\Idl_DM004.wav\" \"\"
# Choice \"[Wait.]\" 100')" 2>&1 | tee -a "${tlog}"
# # Error: line 5, column 1 (<newline>): Unexpected special token
# $tes3cmd modify "${r}" --hide-backups --backup-dir "${tmpd}" --type INFO\
#   --exact-id "17903147822645032645"\
#   --run "\$R->set({t=>'BNAM',f=>'Result'}, \
# 'Player->RemoveItem \"ingred_corprus_weepings_01\" 1
# Player->RemoveItem \"ingred_vampire_dust_01\" 1
# MessageBox \"[Endar Drenim takes the ingredients and recites an incantation over a scroll in his hand.]\"
# Say \"Vo\d\m\Idl_DM004.wav\" \"\"
# Choice \"[Wait.]\" 100')" 2>&1 | tee -a "${tlog}"

  rg -v 'SV - Terrors Of The Night Normal.*Sirollus Saccus Override' "${tlog}" |\
    if rg -i 'error|warning|not modified'; then
      echo "error"
      return 1
    fi
else
  echo "wrong argument"
  return 1
fi
}
main "$@" || { echo "error"; exit 1; }
