
// Here's where we fix Neera's repeating dialogue

COPY_EXISTING ~neeraj.dlg~ ~override~
  DECOMPILE_AND_PATCH BEGIN
    REPLACE_TEXTUALLY
  ~SetGlobal("OHN_POLY_TRAP","LOCALS",2)
ClearAllActions()~
  ~SetGlobal("OHN_POLY_TRAP","LOCALS",3)
ClearAllActions()~
  END

// Here's where we fix the tweakpack multiple stronghold bug

ACTION_IF FILE_EXISTS ~Override/cdt01160.g3~ THEN BEGIN

COPY_EXISTING ~ar0900.bcs~ ~override~
  DECOMPILE_AND_PATCH BEGIN
    REPLACE_TEXTUALLY
 ~OR(6)
    Class(Player1,CLERIC)
    Class(Player1,FIGHTER_CLERIC)
    Class(Player1,CLERIC_MAGE)
    Class(Player1,CLERIC_THIEF)
    Class(Player1,FIGHTER_MAGE_CLERIC)
    Class(Player1,CLERIC_RANGER)~
  ~True()~
  END

END

// Here's where we ensure we can own the deArnise keep regardless of the PC's class

// If multiple strongholds has not been installed

ACTION_IF !FILE_EXISTS ~Override/cdt01160.g3~ THEN BEGIN

  COPY_EXISTING ~Nalia.dlg~ ~override~
                ~NaliaJ.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY
        ~Global("PlayerHasStronghold","GLOBAL",0)
OR(2)
Class(Player1,FIGHTER_ALL)
Kit(Player1,Blackguard)~
        ~~
      REPLACE_TEXTUALLY
        ~!Kit(Player1,Blackguard)
OR(2)
!Class(Player1,FIGHTER_ALL)
Global("PlayerHasStronghold","GLOBAL",1)~
        ~False()~
      REPLACE_TEXTUALLY
        ~OR(8)
Class(Player1,FIGHTER)
Class(Player1,FIGHTER_MAGE)
Class(Player1,FIGHTER_CLERIC)
Class(Player1,FIGHTER_THIEF)
Class(Player1,FIGHTER_MAGE_THIEF)
Class(Player1,FIGHTER_DRUID)
Class(Player1,FIGHTER_MAGE_CLERIC)
Kit(Player1,Blackguard)~
        ~True()~
      REPLACE_TEXTUALLY
        ~!Kit(Player1,Blackguard)
!Class(Player1,FIGHTER)
!Class(Player1,FIGHTER_MAGE)
!Class(Player1,FIGHTER_CLERIC)
!Class(Player1,FIGHTER_THIEF)
!Class(Player1,FIGHTER_MAGE_THIEF)
!Class(Player1,FIGHTER_DRUID)
!Class(Player1,FIGHTER_MAGE_CLERIC)~
        ~False()~
    END

END

// Here's where we Fix Skie bugs

ACTION_IF MOD_IS_INSTALLED ~Skie/Setup-Skie.tp2~ "0" THEN BEGIN

  COPY_EXISTING ~SkiEp.2da~ ~override~
                ~SkiEp2.2da~ ~override~
                ~SkiEp3.2da~ ~override~
    REPLACE_TEXTUALLY ~1SkieG~ ~1xSkieG~

END

// If Nalia Romance has been installed

ACTION_IF MOD_IS_INSTALLED ~deArnise/setup-deArnise.tp2~ "0" THEN BEGIN

  COPY_EXISTING ~NaliaJ.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY
        ~OR(7)
Class(Player1,FIGHTER)
Class(Player1,FIGHTER_MAGE)
Class(Player1,FIGHTER_CLERIC)
Class(Player1,FIGHTER_THIEF)
Class(Player1,FIGHTER_MAGE_THIEF)
Class(Player1,FIGHTER_DRUID)
Class(Player1,FIGHTER_MAGE_CLERIC)~
        ~True()~
    END

END

// Here's where we speed up Aerie's marriage and birthing

EXTEND_BOTTOM ~aeri25.bcs~ ~Rjali/Scripts/TOB/aeri25.baf~

// Here's where we Fix Isra bugs

ACTION_IF MOD_IS_INSTALLED ~setup-Isra_bg2.tp2~ "0" THEN BEGIN

  COPY_EXISTING ~SCQAR.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~GiveItemCreate("rh#docu2",Player1,1,0,0)~
~GiveItemCreate("rh#docu2",Player1,1,0,0) SetGlobal("rh#QarTalks","GLOBAL",2)~
    END

END

// Here's where we Fix Tashia bugs

ACTION_IF MOD_IS_INSTALLED ~tashia/setup-tashia.tp2~ "0" THEN BEGIN

  COPY_EXISTING ~tashia.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~"Imoen"~ ~"Imoen2"~
    END

END

// Here's where we Fix Dace bugs

ACTION_IF MOD_IS_INSTALLED ~Dace/dace.tp2~ "0" THEN BEGIN

  COPY_EXISTING ~T#DACE.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~AreaCheck("AR0700")~
                        ~OR(2) AreaCheck("AR0700") AreaCheck("AR0702")~
    END

  COPY_EXISTING ~GORODR1.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~Global("T#DWATCHERS","GLOBAL",0)~
                        ~Global("T#DWATCHERS","GLOBAL",0) GLT("Chapter",%bg2_chapter_8%)~
      REPLACE_TEXTUALLY ~Global("T#DWATCHERSToB","GLOBAL",0)~
                        ~Global("T#DWATCHERSToB","GLOBAL",0) GGT("Chapter",%bg2_chapter_7%)~
      REPLACE_TEXTUALLY ~Global("T#DODREN","GLOBAL",0)~
                        ~Global("T#DODREN","GLOBAL",0) GLT("Chapter",%bg2_chapter_8%)~
      REPLACE_TEXTUALLY ~Global("T#DODRENToB","GLOBAL",0)~
                        ~Global("T#DODRENToB","GLOBAL",0) GGT("Chapter",%bg2_chapter_7%)~
      EVALUATE_BUFFER
    END

  COPY_EXISTING ~GORPRI1.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~Global("T#DSLIPPERS","GLOBAL",0)~
                        ~Global("T#DSLIPPERS","GLOBAL",0) GLT("Chapter",%bg2_chapter_8%)~
      REPLACE_TEXTUALLY ~Global("T#DSLIPPERSToB","GLOBAL",0)~
                        ~Global("T#DSLIPPERSToB","GLOBAL",0) GGT("Chapter",%bg2_chapter_7%)~
      EVALUATE_BUFFER
    END

  COPY_EXISTING ~GORMAD1.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~Global("T#DYAKMAN","GLOBAL",0)~
                        ~Global("T#DYAKMAN","GLOBAL",0) GLT("Chapter",%bg2_chapter_8%)~
      REPLACE_TEXTUALLY ~Global("T#DYAKMANToB","GLOBAL",0)~
                        ~Global("T#DYAKMANToB","GLOBAL",0) GGT("Chapter",%bg2_chapter_7%)~
      EVALUATE_BUFFER
    END

  COPY_EXISTING ~GORCAMB.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~Global("T#DDECK","GLOBAL",0)~
                        ~Global("T#DDECK","GLOBAL",0) GLT("Chapter",%bg2_chapter_8%)~
      REPLACE_TEXTUALLY ~Global("T#DDECKToB","GLOBAL",0)~
                        ~Global("T#DDECKToB","GLOBAL",0) GGT("Chapter",%bg2_chapter_7%)~
      EVALUATE_BUFFER
    END

  COPY_EXISTING ~GORCAR.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~Global("T#DMACHINE","GLOBAL",0)~
                        ~Global("T#DMACHINE","GLOBAL",0) GLT("Chapter",%bg2_chapter_8%)~
      REPLACE_TEXTUALLY ~Global("T#DMACHINEToB","GLOBAL",0)~
                        ~Global("T#DMACHINEToB","GLOBAL",0) GGT("Chapter",%bg2_chapter_7%)~
      EVALUATE_BUFFER
    END

  COPY_EXISTING ~FSDRAGON.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~Global("T#DWKDRAGONS","GLOBAL",0)~
                        ~Global("T#DWKDRAGONS","GLOBAL",0) GLT("Chapter",%bg2_chapter_8%)~
      REPLACE_TEXTUALLY ~Global("T#DWKDRAGONSToB","GLOBAL",0)~ 
                        ~Global("T#DWKDRAGONSToB","GLOBAL",0) GGT("Chapter",%bg2_chapter_7%)~
      EVALUATE_BUFFER
    END

ACTION_IF NOT FILE_CONTAINS ~dace/dace.tp2~ "VERSION ~v2 BWP Fix~" THEN BEGIN

  COPY_EXISTING ~AR2000.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~ Global("T#DaceExistsTrademeet","GLOBAL",0)~
                        ~ False()~
    END
    
END

  STRING_SET ~Awww, for cryin' out loud, Ducky... what in the blue blazes d'ya want from me?  I told you I like you pretty damn well, and that I don't see that changin'.  Don't try any of that "undying love" nonsense on me, bucko... I'm too damn old and burnt-out to believe in it anymore, and I don't care if that's a cliché.~
             ~Awww, for cryin' out loud, Ducky... what in the blue blazes d'ya want from me?  I told you I like you pretty damn well, and that I don't see that changin'.  Don't try any of that "undying love" nonsense on me, bucko... I'm too damn old and burnt-out to believe in it anymore, and I don't care if that's a cliche.~

END

// Here's where we Fix Amber bugs

ACTION_IF MOD_IS_INSTALLED ~setup-amber.tp2~ "0" THEN BEGIN

  STRING_SET ~Her niece seems nice enough, even if she's a bit naïve, but this lady certainly gets on my nerves.~
             ~Her niece seems nice enough, even if she's a bit naive, but this lady certainly gets on my nerves.~

  STRING_SET ~<GABBER>, the best diplomat in the world. Just could not break me the news that a tiefling girl might not have been something you were expecting to make an entrée into your life?~
             ~<GABBER>, the best diplomat in the world. Just could not break me the news that a tiefling girl might not have been something you were expecting to make an entree into your life?~

END

// Here's where we Fix Tyris bugs

ACTION_IF MOD_IS_INSTALLED ~tyrisflare/setup-tyrisflare.tp2~ "0" THEN BEGIN

  STRING_SET ~Come now, don't tell me you are that naïve.  This world is no different to your own.  The Drow are hated by surfacers because we are feared by them.~
             ~Come now, don't tell me you are that naive.  This world is no different to your own.  The Drow are hated by surfacers because we are feared by them.~

END

// Here's where we Fix Ninde bugs

ACTION_IF MOD_IS_INSTALLED ~ninde/ninde.tp2~ "0" THEN BEGIN

  STRING_SET ~He had fled from Mulmaster, where all spellcasters of a certain power are recquired to join the Cloaks, a militaristic organisation.  He had been tortured, a sure aphrodisiac to the naïve young girl.  His hands shook when he grasped the stem of a goblet.  I was drunk on wine, he on the joy of surviving to hold another woman in his arms, before a window outside which snow fell.  He laughed at everything I said, had a teasing foreign lilt on his lips and a fierceness to his movements.  I fell asleep and he packed me into a coach back to the Amblecrown manor.  I had only the name to remember him by; Sykre D'Alysoss.~
             ~He had fled from Mulmaster, where all spellcasters of a certain power are recquired to join the Cloaks, a militaristic organisation.  He had been tortured, a sure aphrodisiac to the naive young girl.  His hands shook when he grasped the stem of a goblet.  I was drunk on wine, he on the joy of surviving to hold another woman in his arms, before a window outside which snow fell.  He laughed at everything I said, had a teasing foreign lilt on his lips and a fierceness to his movements.  I fell asleep and he packed me into a coach back to the Amblecrown manor.  I had only the name to remember him by; Sykre D'Alysoss.~

  COPY_EXISTING ~LK#NINDJ.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~"Imoen"~ ~"Imoen2"~
    END

END

// Here's where we Fix Fade bugs

ACTION_IF MOD_IS_INSTALLED ~Fade/setup-Fade.tp2~ "0" THEN BEGIN

  COPY_EXISTING ~GORODR1.dlg~ ~override~
                ~GORCHR.dlg~ ~override~
                ~GORMAD1.dlg~ ~override~
                ~GORSUC01.dlg~ ~override~
                ~GORAPR.dlg~ ~override~
                ~GORDEMO.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~InParty("E3FADE")~ ~InParty("E3FADE") GGT("Chapter",%bg2_chapter_7%)~
      EVALUATE_BUFFER
    END

  COMPILE EVALUATE_BUFFER ~Rjali/Dialogue/SOA/RJFADE.d~

  ACTION_IF MOD_IS_INSTALLED ~imoenRomance/Setup-ImoenRomance.tp2~ "0" THEN BEGIN

    COMPILE ~imoenRomance/scripts/SOA/Quests/ar1203.baf~
    EXTEND_TOP ~ar1203.bcs~ ~Fade/Scripts/E3AR1203.baf~

  END

END

// Here's where we Fix Petsy bugs

ACTION_IF MOD_IS_INSTALLED ~Petsy/Petsy.tp2~ "0" THEN BEGIN

  COPY_EXISTING ~FFBART.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~RibaldTanel~ ~PetsySamuel~
  END

  COPY_EXISTING ~L3PetsyJ.dlg~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~Global("L3PetsyQuest2","GLOBAL",0)~
                        ~
Global("L3PetsyQuest2","GLOBAL",0)
OR(8)
AreaCheck("AR0020")
AreaCheck("AR0300")
AreaCheck("AR0400")
AreaCheck("AR0500")
AreaCheck("AR0700")
AreaCheck("AR0800")
AreaCheck("AR0900")
AreaCheck("AR1000")~
  END

  COPY_EXISTING ~CLEANSE.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~Contains("l3corp",Myself)
  Contains("MISCBP",Myself)~
                        ~Contains("l3corp",Myself)~
      REPLACE_TEXTUALLY ~DestroyItem("L3Corp")
    DestroyItem("MISCBP")~
                        ~DestroyItem("L3Corp")~
  END

  STRING_SET ~That's why we are a marvelous couple, my fiancé!~
             ~That's why we are a marvelous couple, my fiance!~
  STRING_SET ~As you wish, my fiancé!~
             ~As you wish, my fiance!~
  STRING_SET ~No worries, my fiancée. Everything's going to be alright.~
             ~No worries, my fiancee. Everything's going to be alright.~

END

// Here's where we Fix Imoen bugs

ACTION_IF MOD_IS_INSTALLED ~imoenRomance/Setup-ImoenRomance.tp2~ "0" THEN BEGIN

  EXTEND_BOTTOM ~ar6200.bcs~ ~Rjali/Scripts/TOB/imoenbug1.baf~ EVALUATE_BUFFER

END
