/*
 * "The BG1 NPC Project"
 * Combined Tutu/BGT installer
 * authored and coded by tons of dedicated people from all walks of life
 * Version 21 pre-release, "Liam's Fabulous Fortuitous Friendly Folly - Factualized and Franchised"
*/

/* Backup folder */
BACKUP ~bg1npc/backup~

/* Author */
AUTHOR ~The BG1 NPC Project Team: forums.gibberlings3.net/index.php?showforum=45~

/* Enable all error messages; nothing suppressed. comment this out for release version - cmorgan */
/* MODDER */

/* WeiDU versions newer than v203 allow tp2 level version listing in the .log for troubleshooting  */
VERSION ~v21_PRERELEASE_20140816~
/* Launch the readme file immediately. */
/* Isaya : display in native selected language if available, otherwise english */
README ~bg1npc/readme-bg1npc-%LANGUAGE%.html~ ~bg1npc/readme-bg1npc.html~

/* ALWAYS = Before each and any component, do this. */
ALWAYS

ACTION_IF GAME_IS ~bgee~ THEN BEGIN
  /*Tell the player it is using BG:EE stuff */
  PRINT ~BG:EE Detected. Installation based on those resources.~
  INCLUDE ~bg1npc\lib\liam_bgee_vars.tpa~
  OUTER_SPRINT ~bgee~ ~bgee/~
  LOAD_TRA ~bg1npc/tra/%LANGUAGE%/bgee.tra~ /* Strings from BG2 not in BGEE */

  /* BG:EE tra conversion : Character encoding for BG II for various languages: ensure the name matches the menu choices */
  ACTION_DEFINE_ASSOCIATIVE_ARRAY languageencoding BEGIN
	"english" => "CP1252"
	"french" => "CP1252"
	"spanish" => "CP1252"
	"polish" => "CP1250"
  END
  OUTER_SPRINT initialencoding ~~
  ACTION_PHP_EACH languageencoding AS lang => encoding BEGIN
    ACTION_IF ("%LANGUAGE%" STRING_EQUAL_CASE ~%lang%~ = 1) THEN BEGIN
      OUTER_SPRINT initialencoding ~%encoding%~
    END
  END
  /* 
   * Isaya: check for existence of BG1NPC/TRA/%LANGUAGE%/BG1NPC.tra as a marker that the mod
   * has already installed at least one component, so conversion is already done, in order
   * to avoid repeating for each component (as a backup of all tra files is then done in each
   * subdirectory of backup)
   * This is a handy trick with BG1 NPC, since BG1NPC.tra is created when the mod is installed
   * and removed with the mod. But it cannot be used as a generic trick for other mods.
  */
  ACTION_IF NOT (FILE_EXISTS_IN_GAME ~bg1npc/tra/%LANGUAGE%/BG1NPC.tra~) AND
            (STRING_LENGTH ~%initialencoding%~ != 0) THEN BEGIN
    ACTION_IF ("%WEIDU_OS%" STRING_EQUAL_CASE ~WIN32~ = 1) THEN BEGIN
      /* Only convert for the language selected by passing the directory as parameter */
      PRINT ~Windows conversion with %initialencoding%~
      AT_NOW ~bg1npc/conv_tra.bat %LANGUAGE% %initialencoding%~
    END
    ACTION_IF ("%WEIDU_OS%" STRING_EQUAL_CASE ~OSX~ = 1) OR ("%WEIDU_OS%" STRING_EQUAL_CASE ~UNIX~ = 1) THEN BEGIN
      /* Only convert for the language selected by passing the directory as parameter */
      PRINT ~Linux and Mac conversion with %initialencoding%~
      AT_NOW ~bg1npc/conv_tra.sh %LANGUAGE% %initialencoding%~
    END
    /* Isaya: all tra files have to be replaced with their counterpart from the utf8 directory */
    /* Otherwise the tra files for dialogs are still with the Windows 1252 / 1250 encoding */
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/bg1npc_tmp.tra~ ~bg1npc/tra/%LANGUAGE%/bg1npc_tmp.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#brlt.tra~ ~bg1npc/tra/%LANGUAGE%/p#brlt.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#centeo.tra~ ~bg1npc/tra/%LANGUAGE%/p#centeo.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#ciflirt.tra~ ~bg1npc/tra/%LANGUAGE%/p#ciflirt.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#corlt.tra~ ~bg1npc/tra/%LANGUAGE%/p#corlt.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#crnpc.tra~ ~bg1npc/tra/%LANGUAGE%/p#crnpc.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#fw2700.tra~ ~bg1npc/tra/%LANGUAGE%/p#fw2700.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#imanel.tra~ ~bg1npc/tra/%LANGUAGE%/p#imanel.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#imanl2.tra~ ~bg1npc/tra/%LANGUAGE%/p#imanl2.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/p#wolf.tra~ ~bg1npc/tra/%LANGUAGE%/p#wolf.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/setup.tra~ ~bg1npc/tra/%LANGUAGE%/setup.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#addial_tmp.tra~ ~bg1npc/tra/%LANGUAGE%/x#addial_tmp.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajantis.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajantis.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajantisaddlts_pr.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajantisaddlts_pr.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajantisaddlts_pr_notosc.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajantisaddlts_pr_notosc.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajantisbhaallts.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajantisbhaallts.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajantisdreamlts.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajantisdreamlts.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajantisiniflirts_pr.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajantisiniflirts_pr.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajantislts_pr.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajantislts_pr.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajantisnpc_talks_pr.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajantisnpc_talks_pr.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajint.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajpcfl_tmp.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajpcfl_tmp.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ajroadd_pr.tra~ ~bg1npc/tra/%LANGUAGE%/x#ajroadd_pr.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#alint.tra~ ~bg1npc/tra/%LANGUAGE%/x#alint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#alora.tra~ ~bg1npc/tra/%LANGUAGE%/x#alora.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#aloran.tra~ ~bg1npc/tra/%LANGUAGE%/x#aloran.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#alorepl.tra~ ~bg1npc/tra/%LANGUAGE%/x#alorepl.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ar6001.tra~ ~bg1npc/tra/%LANGUAGE%/x#ar6001.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#assist.tra~ ~bg1npc/tra/%LANGUAGE%/x#assist.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#branw.tra~ ~bg1npc/tra/%LANGUAGE%/x#branw.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#bri.tra~ ~bg1npc/tra/%LANGUAGE%/x#bri.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#brint.tra~ ~bg1npc/tra/%LANGUAGE%/x#brint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#challenge.tra~ ~bg1npc/tra/%LANGUAGE%/x#challenge.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#chop.tra~ ~bg1npc/tra/%LANGUAGE%/x#chop.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#coint.tra~ ~bg1npc/tra/%LANGUAGE%/x#coint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#coran.tra~ ~bg1npc/tra/%LANGUAGE%/x#coran.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#coran1.tra~ ~bg1npc/tra/%LANGUAGE%/x#coran1.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#cosqu.tra~ ~bg1npc/tra/%LANGUAGE%/x#cosqu.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#cru11.tra~ ~bg1npc/tra/%LANGUAGE%/x#cru11.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#da0125.tra~ ~bg1npc/tra/%LANGUAGE%/x#da0125.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dav01.tra~ ~bg1npc/tra/%LANGUAGE%/x#dav01.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dav02.tra~ ~bg1npc/tra/%LANGUAGE%/x#dav02.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#davi.tra~ ~bg1npc/tra/%LANGUAGE%/x#davi.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dybha.tra~ ~bg1npc/tra/%LANGUAGE%/x#dybha.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dyint.tra~ ~bg1npc/tra/%LANGUAGE%/x#dyint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dylast.tra~ ~bg1npc/tra/%LANGUAGE%/x#dylast.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dynah.tra~ ~bg1npc/tra/%LANGUAGE%/x#dynah.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dynaquest.tra~ ~bg1npc/tra/%LANGUAGE%/x#dynaquest.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dyro.tra~ ~bg1npc/tra/%LANGUAGE%/x#dyro.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#dyronpc.tra~ ~bg1npc/tra/%LANGUAGE%/x#dyronpc.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#edint.tra~ ~bg1npc/tra/%LANGUAGE%/x#edint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#edwin.tra~ ~bg1npc/tra/%LANGUAGE%/x#edwin.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#eldoth.tra~ ~bg1npc/tra/%LANGUAGE%/x#eldoth.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#eldothn.tra~ ~bg1npc/tra/%LANGUAGE%/x#eldothn.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#elint.tra~ ~bg1npc/tra/%LANGUAGE%/x#elint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#faint.tra~ ~bg1npc/tra/%LANGUAGE%/x#faint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#faldorn.tra~ ~bg1npc/tra/%LANGUAGE%/x#faldorn.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#gaint.tra~ ~bg1npc/tra/%LANGUAGE%/x#gaint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#garar.tra~ ~bg1npc/tra/%LANGUAGE%/x#garar.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#garri.tra~ ~bg1npc/tra/%LANGUAGE%/x#garri.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#garwyl.tra~ ~bg1npc/tra/%LANGUAGE%/x#garwyl.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#gorlet.tra~ ~bg1npc/tra/%LANGUAGE%/x#gorlet.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#halbaz.tra~ ~bg1npc/tra/%LANGUAGE%/x#halbaz.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#ict3.tra~ ~bg1npc/tra/%LANGUAGE%/x#ict3.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#imint.tra~ ~bg1npc/tra/%LANGUAGE%/x#imint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#imoen.tra~ ~bg1npc/tra/%LANGUAGE%/x#imoen.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#impspl.tra~ ~bg1npc/tra/%LANGUAGE%/x#impspl.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#jaheira.tra~ ~bg1npc/tra/%LANGUAGE%/x#jaheira.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#jaint.tra~ ~bg1npc/tra/%LANGUAGE%/x#jaint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#jaqu.tra~ ~bg1npc/tra/%LANGUAGE%/x#jaqu.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#kagain.tra~ ~bg1npc/tra/%LANGUAGE%/x#kagain.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#kaint.tra~ ~bg1npc/tra/%LANGUAGE%/x#kaint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#kaqst.tra~ ~bg1npc/tra/%LANGUAGE%/x#kaqst.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#khalid.tra~ ~bg1npc/tra/%LANGUAGE%/x#khalid.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#khint.tra~ ~bg1npc/tra/%LANGUAGE%/x#khint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#kiint.tra~ ~bg1npc/tra/%LANGUAGE%/x#kiint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#kiint_new.tra~ ~bg1npc/tra/%LANGUAGE%/x#kiint_new.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#kisequ.tra~ ~bg1npc/tra/%LANGUAGE%/x#kisequ.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#kivan.tra~ ~bg1npc/tra/%LANGUAGE%/x#kivan.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#lake.tra~ ~bg1npc/tra/%LANGUAGE%/x#lake.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#lp1r.tra~ ~bg1npc/tra/%LANGUAGE%/x#lp1r.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#lp1rep.tra~ ~bg1npc/tra/%LANGUAGE%/x#lp1rep.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#lp2r.tra~ ~bg1npc/tra/%LANGUAGE%/x#lp2r.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#lp2rep.tra~ ~bg1npc/tra/%LANGUAGE%/x#lp2rep.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#lp3r.tra~ ~bg1npc/tra/%LANGUAGE%/x#lp3r.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#lp3rep.tra~ ~bg1npc/tra/%LANGUAGE%/x#lp3rep.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#lprcad.tra~ ~bg1npc/tra/%LANGUAGE%/x#lprcad.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#miint.tra~ ~bg1npc/tra/%LANGUAGE%/x#miint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#minsc.tra~ ~bg1npc/tra/%LANGUAGE%/x#minsc.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#mirc.tra~ ~bg1npc/tra/%LANGUAGE%/x#mirc.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#moint.tra~ ~bg1npc/tra/%LANGUAGE%/x#moint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#montaron.tra~ ~bg1npc/tra/%LANGUAGE%/x#montaron.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#newmerch2.tra~ ~bg1npc/tra/%LANGUAGE%/x#newmerch2.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#npcwait.tra~ ~bg1npc/tra/%LANGUAGE%/x#npcwait.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#pcbury.tra~ ~bg1npc/tra/%LANGUAGE%/x#pcbury.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#pcbury1.tra~ ~bg1npc/tra/%LANGUAGE%/x#pcbury1.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#pcinit_tmp.tra~ ~bg1npc/tra/%LANGUAGE%/x#pcinit_tmp.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#quayl.tra~ ~bg1npc/tra/%LANGUAGE%/x#quayl.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#quint.tra~ ~bg1npc/tra/%LANGUAGE%/x#quint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#rumor.tra~ ~bg1npc/tra/%LANGUAGE%/x#rumor.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#safana.tra~ ~bg1npc/tra/%LANGUAGE%/x#safana.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#saint.tra~ ~bg1npc/tra/%LANGUAGE%/x#saint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#sharteel.tra~ ~bg1npc/tra/%LANGUAGE%/x#sharteel.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#shint.tra~ ~bg1npc/tra/%LANGUAGE%/x#shint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#shrom.tra~ ~bg1npc/tra/%LANGUAGE%/x#shrom.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#skie.tra~ ~bg1npc/tra/%LANGUAGE%/x#skie.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#skint.tra~ ~bg1npc/tra/%LANGUAGE%/x#skint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#tiax.tra~ ~bg1npc/tra/%LANGUAGE%/x#tiax.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#tiaxquest.tra~ ~bg1npc/tra/%LANGUAGE%/x#tiaxquest.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#tiint.tra~ ~bg1npc/tra/%LANGUAGE%/x#tiint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#totsc.tra~ ~bg1npc/tra/%LANGUAGE%/x#totsc.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#viconia.tra~ ~bg1npc/tra/%LANGUAGE%/x#viconia.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#viint.tra~ ~bg1npc/tra/%LANGUAGE%/x#viint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xaint.tra~ ~bg1npc/tra/%LANGUAGE%/x#xaint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xan.tra~ ~bg1npc/tra/%LANGUAGE%/x#xan.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xanlt.tra~ ~bg1npc/tra/%LANGUAGE%/x#xanlt.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xanq.tra~ ~bg1npc/tra/%LANGUAGE%/x#xanq.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xqxan.tra~ ~bg1npc/tra/%LANGUAGE%/x#xqxan.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xzar.tra~ ~bg1npc/tra/%LANGUAGE%/x#xzar.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xzdqu.tra~ ~bg1npc/tra/%LANGUAGE%/x#xzdqu.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xzdr2.tra~ ~bg1npc/tra/%LANGUAGE%/x#xzdr2.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xzdr3.tra~ ~bg1npc/tra/%LANGUAGE%/x#xzdr3.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xzint.tra~ ~bg1npc/tra/%LANGUAGE%/x#xzint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#xzqu.tra~ ~bg1npc/tra/%LANGUAGE%/x#xzqu.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#yeint.tra~ ~bg1npc/tra/%LANGUAGE%/x#yeint.tra~
    MOVE ~bg1npc/tra/%LANGUAGE%/utf8/x#yeslick.tra~ ~bg1npc/tra/%LANGUAGE%/x#yeslick.tra~

    LOAD_TRA ~bg1npc/tra/%LANGUAGE%/setup.tra~
    PRINT ~re-loaded %LANGUAGE% TRA files with UTF-8(no BOM) encoding for use on BG:EE~
  END

END ELSE BEGIN
  ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
    /* Tell the player it is using Tutu stuff */
    PRINT @1000
    INCLUDE ~bg1npc\lib\g3_tutu_cpmvars.tpa~
  END ELSE BEGIN
    ACTION_IF GAME_IS ~bgt~ THEN BEGIN
        /* Tell the player it is using BGT stuff */
        PRINT @1001
        INCLUDE ~bg1npc\lib\g3_bgt_cpmvars.tpa~
        /* Tell the player it is not Tutu or BGT */
    END ELSE BEGIN FAIL ~Please install on BG:EE, Tutu or BGT.~
    END
  END
END

  /*  alter fluid states */
  INCLUDE ~BG1NPC\lib\g3_fluid_cpmvars.tpa~

  /* prep tras for sound references */
  COPY ~BG1NPC/TRA/%LANGUAGE%/BG1NPC_tmp.tra~ ~BG1NPC/TRA/%LANGUAGE%/BG1NPC.tra~
     EVALUATE_BUFFER
  LOAD_TRA ~BG1NPC/TRA/%LANGUAGE%/BG1NPC.tra~

  INCLUDE ~bg1npc\lib\extra_regexp_vars.tpa~   /* allows us to regexp match tabs and newlines */
  INCLUDE ~bg1npc\lib\cmorgan_project_macros.tpa~   /* adds macros callable by each component */
END

/* Language Settings */
AUTO_TRA ~bg1npc/tra/%s~
LANGUAGE ~English~ ~english~ ~bg1npc/tra/english/setup.tra~
LANGUAGE ~Espanol (traducido por Clan DLAN)~ ~spanish~ ~bg1npc/tra/spanish/setup.tra~
LANGUAGE ~Francais (traduit par les d'Oghmatiques)~ ~french~ ~bg1npc/tra/french/setup.tra~
LANGUAGE ~Polski~ ~polish~ ~bg1npc/tra/polish/setup.tra~

/* BEGIN The BG1 NPC Project: Required Modifications  */
BEGIN @1005 DESIGNATED 0
  /* Tells other mods BG1NPC Core is installed */
  COPY ~BG1NPC/Core/X#component.xx~ ~override/X#BG1NPCCore.G3~

  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

    /* allows us to regexp match tabs and newlines */
  INCLUDE ~BG1NPC/LIB/extra_regexp_vars.tpa~

  /* Defines regexp whitespaces */
  OUTER_SPRINT "whitespace" "[%tab% %lnl%%mnl%%wnl%]+"
  
  ACTION_IF GAME_IS ~tutu tutu_totsc bgt~ THEN BEGIN
  /* Ascension64's Bere"gost" Fix - very cool!  AR3300, FW3300, AR6700 (BG1, BGTutu, BGT) */
	ACTION_FOR_EACH ~filetofix~ IN ~fw3300.are~ ~ar6700.are~ BEGIN
		ACTION_IF FILE_EXISTS_IN_GAME ~%filetofix%~ THEN BEGIN
			COPY_EXISTING ~%filetofix%~ ~override~
			READ_LONG 0xA4 nDoors
			READ_LONG 0xA8 offDoors
			READ_LONG 0x7C offPoints
			READ_LONG 0x80 nPoints
			SET i = 0
			FOR (i = 0; i < nDoors; i += 1) BEGIN
				READ_ASCII ( %offDoors% + %i% * 0xC8 + 0x20 ) DoorId
				PATCH_IF ( "%DoorId%" STRING_EQUAL "DOOR3304" ) BEGIN
				  READ_LONG ( %offDoors% + %i% * 0xC8 + 0x48 ) idxPointsImpededOpen
				  READ_SHORT ( %offDoors% + %i% * 0xC8 + 0x4C ) nPointsImpededOpen
				  SET j = 0
				  FOR (j = %idxPointsImpededOpen%; j < %idxPointsImpededOpen% + %nPointsImpededOpen%; j += 1) BEGIN
					READ_SHORT ( %offPoints% + %j% * 0x4) x
					READ_SHORT ( %offPoints% + %j% * 0x4 + 0x2) y
					PATCH_IF ( x = 243 && y = 326 ) BEGIN
					  WRITE_SHORT ( %offPoints% + %j% * 0x4) 233
					  WRITE_SHORT ( %offPoints% + %j% * 0x4 + 0x2) 302
					END
					PATCH_IF ( x = 243 && y = 327 ) BEGIN
					  WRITE_SHORT ( %offPoints% + %j% * 0x4) 233
					  WRITE_SHORT ( %offPoints% + %j% * 0x4 + 0x2) 304
					END
					PATCH_IF ( x = 242 && y = 325 ) BEGIN
					  WRITE_SHORT ( %offPoints% + %j% * 0x4) 232
					  WRITE_SHORT ( %offPoints% + %j% * 0x4 + 0x2) 304
					END
					PATCH_IF ( x = 233 && y = 303 ) BEGIN
					END
				  END
				END
			END
		END
	END
END // of A_I G_I Tutu, BGT

  /*  Nythrun's Broken CRE Order and Effects Macros are depreciated - her Fix is now part of WeiDU, with troubleshooting/extension by Miloch */
  /* Miloch's and older fixes combined here using PATCH_IF - less touching of the file = good thing */
  /* As far as I can tell the fixes are from Nythrun, Dudleyville, Miloch (especially Gnome fixes), and Tutu v4 conversion hiccups, and BGT vs Tutu script assignments - cmorgan, March 26, 2011 */
  /* Apply Nythrun's Fixes to creatures we use */
	ACTION_FOR_EACH ~crefile~ IN ~%tutu_scripta%varicem.cre~
                               ~%tutu_scriptb%ullrush.cre~
                               ~%tutu_scriptbg%neb.cre~
                               ~%tutu_scriptd%ursword.cre~
                               ~%tutu_scriptf%twbax_a.cre~
                               ~%tutu_scripti%ronelit.cre~
                               ~%tutu_scriptm%oorlock.cre~
                               ~%tutu_scripto%grema03.cre~
                               ~%tutu_scripts%handal2.cre~
                               ~%tutu_var%alatos.cre~
                               ~%tutu_var%albert.cre~
                               ~%tutu_var%alvanh.cre~
                               ~%tutu_var%alyth.cre~
                               ~%tutu_var%amaran.cre~
                               ~%tutu_var%angelo.cre~
                               ~%tutu_var%ankheg.cre~
                               ~%tutu_var%arkush.cre~
                               ~%tutu_var%avarice.cre~
                               ~%tutu_var%bandit.cre~
                               ~%tutu_var%baresh.cre~
                               ~%tutu_var%bassil.cre~
                               ~%tutu_var%bayard.cre~
                               ~%tutu_var%bearbl.cre~
                               ~%tutu_var%bearbr.cre~
                               ~%tutu_var%bearca.cre~
                               ~%tutu_var%bearpo.cre~
                               ~%tutu_var%belt.cre~
                               ~%tutu_var%bently.cre~
                               ~%tutu_var%bjorni.cre~
                               ~%tutu_var%brage.cre~
                               ~%tutu_var%brielb.cre~
                               ~%tutu_var%brilla.cre~
                               ~%tutu_var%cadder.cre~
                               ~%tutu_var%calaha.cre~
                               ~%tutu_var%chase.cre~
                               ~%tutu_var%claird.cre~
                               ~%tutu_var%coksmth.cre~
                               ~%tutu_var%daitel.cre~
                               ~%tutu_var%dalton.cre~
                               ~%tutu_var%davaeo.cre~
                               ~%tutu_var%deathk.cre~
                               ~%tutu_var%delain.cre~
                               ~%tutu_var%delsvir.cre~
                               ~%tutu_var%deltan.cre~
                               ~%tutu_var%dopdur1.cre~
                               ~%tutu_var%drienn.cre~
                               ~%tutu_var%drizzt.cre~
                               ~%tutu_var%dryad.cre~
                               ~%tutu_var%durlagt.cre~
                               ~%tutu_var%durlyl.cre~
                               ~%tutu_var%dushai.cre~
                               ~%tutu_var%elmin2.cre~
                               ~%tutu_var%elmin5.cre~
                               ~%tutu_var%ender.cre~
                               ~%tutu_var%entill.cre~
                               ~%tutu_var%erdane.cre~
                               ~%tutu_var%faldor.cre~
                               ~%tutu_var%farmbr.cre~
                               ~%tutu_var%fear.cre~
                               ~%tutu_var%fearm.cre~
                               ~%tutu_var%fenrus.cre~
                               ~%tutu_var%fireb1.cre~
                               ~%tutu_var%flame.cre~
                               ~%tutu_var%galken.cre~
                               ~%tutu_var%galtok.cre~
                               ~%tutu_var%gatewa.cre~
                               ~%tutu_var%gellan.cre~
                               ~%tutu_var%gerde.cre~
                               ~%tutu_var%girba2.cre~
                               ~%tutu_var%gnoll.cre~
                               ~%tutu_var%gorion.cre~
                               ~%tutu_var%grael.cre~
                               ~%tutu_var%greywo.cre~
                               ~%tutu_var%hack.cre~
                               ~%tutu_var%hafiz.cre~
                               ~%tutu_var%halaca.cre~
                               ~%tutu_var%halbaz.cre~
                               ~%tutu_var%hurgan.cre~
                               ~%tutu_var%ike.cre~
                               ~%tutu_var%iron11.cre~
                               ~%tutu_var%isla.cre~
                               ~%tutu_var%jessup.cre~
                               ~%tutu_var%joia.cre~
                               ~%tutu_var%kaisha.cre~
                               ~%tutu_var%karoug.cre~
                               ~%tutu_var%keeper.cre~
                               ~%tutu_var%keldda.cre~
                               ~%tutu_var%kirinh.cre~
                               ~%tutu_var%korax.cre~
                               ~%tutu_var%krumm.cre~
                               ~%tutu_var%landri.cre~
                               ~%tutu_var%larze.cre~
                               ~%tutu_var%liia.cre~
                               ~%tutu_var%love.cre~
                               ~%tutu_var%lovem.cre~
                               ~%tutu_var%madarc.cre~
                               ~%tutu_var%marl.cre~
                               ~%tutu_var%meiala.cre~
                               ~%tutu_var%mendas.cre~
                               ~%tutu_var%mulahe.cre~
                               ~%tutu_var%mutami.cre~
                               ~%tutu_var%narlen.cre~
                               ~%tutu_var%niemai.cre~
                               ~%tutu_var%nobw2.cre~
                               ~%tutu_var%perdue.cre~
                               ~%tutu_var%petrin.cre~
                               ~%tutu_var%pheirk.cre~
                               ~%tutu_var%phlydi3.cre~
                               ~%tutu_var%poe.cre~
                               ~%tutu_var%pride.cre~
                               ~%tutu_var%pridem.cre~
                               ~%tutu_var%prost5.cre~
                               ~%tutu_var%pumberl.cre~
                               ~%tutu_var%rielta.cre~
                               ~%tutu_var%riggilo.cre~
                               ~%tutu_var%sarev1.cre~
                               ~%tutu_var%sarevo.cre~
                               ~%tutu_var%sarhed.cre~
                               ~%tutu_var%scar.cre~
                               ~%tutu_var%seniya.cre~
                               ~%tutu_var%serva2.cre~
                               ~%tutu_var%shoal.cre~
                               ~%tutu_var%silke.cre~
                               ~%tutu_var%skie.cre~
                               ~%tutu_var%slave.cre~
                               ~%tutu_var%taerom.cre~
                               ~%tutu_var%takiyah.cre~
                               ~%tutu_var%tamoko.cre~
                               ~%tutu_var%tarnes.cre~
                               ~%tutu_var%tarnor.cre~
                               ~%tutu_scriptbg%tazok.cre~
                               ~%tutu_var%tazok2.cre~
                               ~%tutu_var%tellan.cre~
                               ~%tutu_var%tenya.cre~
                               ~%tutu_var%thalan.cre~
                               ~%tutu_var%therel.cre~
                               ~%tutu_var%ulraun.cre~
                               ~%tutu_var%unshey.cre~
                               ~%tutu_var%vai.cre~
                               ~%tutu_var%vail.cre~
                               ~%tutu_var%volo.cre~
                               ~%tutu_var%winski.cre~
                               ~%tutu_var%winski2.cre~
                               ~%tutu_var%winthr2.cre~
                               ~%tutu_var%yago.cre~
                               ~%tutu_var%zombie.cre~
                               ~%tutu_var%zombiew.cre~
                               ~%tutu_var%ajanti.cre~
                               ~%tutu_var%ajanti4.cre~
                               ~%tutu_var%ajanti6.cre~
                               ~%tutu_var%alora.cre~
                               ~%tutu_var%alora6.cre~
                               ~%tutu_var%branwe.cre~
                               ~%tutu_var%branwe5.cre~
                               ~%tutu_var%coran.cre~
                               ~%tutu_var%coran5.cre~
                               ~%tutu_var%dynahe.cre~
                               ~%tutu_var%dynahe2.cre~
                               ~%tutu_var%dynahe4.cre~
                               ~%tutu_var%dynahe6.cre~
                               ~%tutu_var%edwin.cre~
                               ~%tutu_var%edwin2.cre~
                               ~%tutu_var%edwin4.cre~
                               ~%tutu_var%edwin6.cre~
                               ~%tutu_var%faldor.cre~
                               ~%tutu_var%faldor5.cre~
                               ~%tutu_var%garric.cre~
                               ~%tutu_var%garric2.cre~
                               ~%tutu_var%garric4.cre~
                               ~%tutu_var%garric6.cre~
                               ~%tutu_var%imoen1.cre~
                               ~%tutu_var%imoen2.cre~
                               ~%tutu_var%imoen4.cre~
                               ~%tutu_var%imoen6.cre~
                               ~%tutu_var%jaheir.cre~
                               ~%tutu_var%jaheir2.cre~
                               ~%tutu_var%jaheir4.cre~
                               ~%tutu_var%jaheir6.cre~
                               ~%tutu_var%kagain.cre~
                               ~%tutu_var%kagain2.cre~
                               ~%tutu_var%kagain4.cre~
                               ~%tutu_var%kagain6.cre~
                               ~%tutu_var%khalid.cre~
                               ~%tutu_var%khalid2.cre~
                               ~%tutu_var%khalid4.cre~
                               ~%tutu_var%khalid6.cre~
                               ~%tutu_var%kivan.cre~
                               ~%tutu_var%kivan4.cre~
                               ~%tutu_var%kivan6.cre~
                               ~%tutu_var%minsc.cre~
                               ~%tutu_var%minsc2.cre~
                               ~%tutu_var%minsc4.cre~
                               ~%tutu_var%minsc6.cre~
                               ~%tutu_var%montar.cre~
                               ~%tutu_var%montar2.cre~
                               ~%tutu_var%montar4.cre~
                               ~%tutu_var%montar6.cre~
                               ~%tutu_scriptbg%quayle.cre~
                               ~%tutu_var%quayle4.cre~
                               ~%tutu_var%quayle6.cre~
                               ~%tutu_var%safana.cre~
                               ~%tutu_var%safana4.cre~
                               ~%tutu_var%safana6.cre~
                               ~%tutu_var%sharte.cre~
                               ~%tutu_var%sharte4.cre~
                               ~%tutu_var%sharte6.cre~
                               ~%tutu_var%skie.cre~
                               ~%tutu_var%skie6.cre~
                               ~%tutu_var%tiax.cre~
                               ~%tutu_var%tiax4.cre~
                               ~%tutu_var%tiax6.cre~
                               ~%tutu_var%viconi.cre~
                               ~%tutu_var%viconi4.cre~
                               ~%tutu_var%viconi6.cre~
                               ~%tutu_scriptbg%xan.cre~
                               ~%tutu_var%xan4.cre~
                               ~%tutu_var%xan6.cre~
                               ~%tutu_var%xzar.cre~
                               ~%tutu_var%xzar2.cre~
                               ~%tutu_var%xzar4.cre~
                               ~%tutu_var%xzar6.cre~
                               ~%tutu_var%yeslic.cre~
                               ~%tutu_var%yeslic5.cre~
                               ~idemon02.cre~
                               ~imp01.cre~
                               ~mepsmo01.cre~ 
	BEGIN
		ACTION_IF FILE_EXISTS_IN_GAME ~%crefile%~ THEN BEGIN
			COPY_EXISTING ~%crefile%~ ~override~
				LAUNCH_PATCH_FUNCTION FJ_CRE_VALIDITY
					INT_VAR do_message = 1
				END
				/* do all the stuff we do to .cres in one tower of P_I */
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%ajanti.cre~ = 0) BEGIN
					WRITE_BYTE 0x54 12 // Save vs. Death
					WRITE_BYTE 0x55 14 // Save vs. Wand
					WRITE_BYTE 0x56 13 // Save vs. Polymorph
					WRITE_BYTE 0x57 15 // Save vs. Breath
					WRITE_BYTE 0x58 15 // Save vs. Spells
				END	
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%ajanti4.cre~ = 0) BEGIN
					WRITE_BYTE 0x54 11 // Save vs. Death
					WRITE_BYTE 0x55 13 // Save vs. Wand
					WRITE_BYTE 0x56 12 // Save vs. Polymorph
					WRITE_BYTE 0x57 14 // Save vs. Breath
					WRITE_BYTE 0x58 14 // Save vs. Spells
				END	
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%ajanti6.cre~ = 0) BEGIN
					WRITE_BYTE 0x54 9  // Save vs. Death
					WRITE_BYTE 0x55 11 // Save vs. Wand
					WRITE_BYTE 0x56 10 // Save vs. Polymorph
					WRITE_BYTE 0x57 11 // Save vs. Breath
					WRITE_BYTE 0x58 12 // Save vs. Spells
				END		
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%alora.cre~ = 0) BEGIN
					WRITE_ASCIIE 0x248 ~%tutu_var%ALORA~ #8 //  override script
					WRITE_ASCIIE 0x2CC ~%tutu_var%ALORA~ #8 //  dialog
					WRITE_BYTE 0x54 10 // Save vs. Death
					WRITE_BYTE 0x55 11 // Save vs. Wand
					WRITE_BYTE 0x56 12 // Save vs. Polymorph
					WRITE_BYTE 0x57 16 // Save vs. Breath
					WRITE_BYTE 0x58 12 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%alora6.cre~ = 0) BEGIN
					WRITE_ASCIIE 0x248 ~%tutu_var%ALORA~ #8 //  override script
					WRITE_ASCIIE 0x2CC ~%tutu_var%ALORA~ #8 //  dialog
					WRITE_BYTE 0x54 9  // Save vs. Death
					WRITE_BYTE 0x55 9  // Save vs. Wand
					WRITE_BYTE 0x56 11 // Save vs. Polymorph
					WRITE_BYTE 0x57 15 // Save vs. Breath
					WRITE_BYTE 0x58 10 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%bently.cre~ = 0) BEGIN /* Bentley Mirrorshade (in FAI L1) */
					WRITE_SHORT 0x24 50 // Current HP (was 41)
					WRITE_SHORT 0x26 50 // Max HP (was 41)
					WRITE_SHORT 0x28 0x6204 // Animation (mage_male_gnome, was 0x6202 dwarf)
					WRITE_BYTE 0x52 15 // THAC0 (was 16)
					WRITE_BYTE 0x55 7 // Save vs. wands (was 9)
					WRITE_BYTE 0x58 8 // Save vs. spells (was 10)
					WRITE_BYTE 0x6f 1 // Small swords (was 3)
					WRITE_BYTE 0x235 11 // Level 2 (was 10)
					WRITE_BYTE 0x236 1 // Level 3 (was 6)
					WRITE_BYTE 0x23a 17 // Intelligence (was 16)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_ASCII 0x250 ~x#mag10b~ #8 // Class script
					REMOVE_MEMORIZED_SPELL ~spwi211~ ~spwi303~ ~spwi401~
					ADD_MEMORIZED_SPELL ~spwi112~ #0 ~wizard~ (4) // Magic Missile
					ADD_MEMORIZED_SPELL ~spwi118~ #0 ~wizard~ // Chromatic Orb
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ (4) // Melf's Acid Arrow
					ADD_MEMORIZED_SPELL ~spwi212~ #1 ~wizard~ // Mirror Image
					ADD_MEMORIZED_SPELL ~spwi302~ #2 ~wizard~ // Dispel Magic
					ADD_MEMORIZED_SPELL ~spwi303~ #2 ~wizard~ // Flame Arrow
					ADD_MEMORIZED_SPELL ~spwi306~ #2 ~wizard~ // Hold Person
					ADD_MEMORIZED_SPELL ~spwi311~ #2 ~wizard~ // Protection From Normal Missiles
					ADD_MEMORIZED_SPELL ~spwi401~ #3 ~wizard~ // Confusion
					ADD_MEMORIZED_SPELL ~spwi407~ #3 ~wizard~ // Monster Summoning 2
					ADD_MEMORIZED_SPELL ~spwi423~ #3 ~wizard~ // Spider Spawn
					ADD_MEMORIZED_SPELL ~spwi506~ #4 ~wizard~ // Domination
					ADD_MEMORIZED_SPELL ~spwi521~ #4 ~wizard~ // Conjure Lesser Earth Elemental
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_branwe.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_BRANWE~ #8 //  override script
				END	 
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_branwe5.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_BRANWE~ #8 //  override script
					WRITE_BYTE 0x66 5 // Lore
				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~branwe.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGBRANW~ #8 //  override script
      				END	 
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~branwe5.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGBRANW~ #8 //  override script
      					WRITE_BYTE 0x66 5 // Lore
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~branwe.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~BRANWEN~ #8 //  override script
      				END	 
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~branwe5.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~BRANWEN~ #8 //  override script
      					WRITE_BYTE 0x66 5 // Lore
      				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%coran.cre~ = 0) BEGIN
					WRITE_BYTE 0x24 24 // Current Hit Points
					WRITE_BYTE 0x26 24 // Maximum Hit Points
					WRITE_BYTE 0x66 9  // Lore
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%coran5.cre~ = 0) BEGIN
					WRITE_BYTE 0x66 15 // Lore
					WRITE_BYTE 0x52 16 // THAC0
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%delsvir.cre~ = 0) BEGIN /* Delsvirtanyon (in Ulgoth's Beard) */
					WRITE_LONG 0x14 976 // XP Value (was 801)
					WRITE_SHORT 0x28 0x6304 // Animation (thief_male_gnome, was 0x5302 dwarf_low)
					WRITE_BYTE 0x52 17 // THAC0 (was 16)
					WRITE_BYTE 0x54 12 // Save vs. death (was 11)
					WRITE_BYTE 0x55 7 // Save vs. wands (was 9)
					WRITE_BYTE 0x56 11 // Save vs. polymorph (was 10)
					WRITE_BYTE 0x58 8 // Save vs. spells (was 10)
					WRITE_BYTE 0x6f 1 // Small swords (was 3)
					WRITE_BYTE 0x235 7 // Level 2 (was 1)
					WRITE_BYTE 0x236 1 // Level 3 (was 6)
					WRITE_BYTE 0x237 1 // Sex (male, was 158)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_EVALUATED_ASCII 0x258 ~%tutu_var%mage6~ #8 // Race script
					WRITE_BYTE 0x275 1 // Gender (male, was 158)
					REMOVE_MEMORIZED_SPELL ~spwi211~ ~spwi303~ ~spwi401~ ~spwi505~
					REMOVE_KNOWN_SPELL ~spwi505~ // Shadow Door
					ADD_MEMORIZED_SPELL ~spwi112~ #0 ~wizard~ (4) // Magic Missile
					ADD_MEMORIZED_SPELL ~spwi118~ #0 ~wizard~ // Chromatic Orb
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ (3) // Melf's Acid Arrow
					ADD_MEMORIZED_SPELL ~spwi217~ #1 ~wizard~ // Agannazar's Scorcher
					ADD_MEMORIZED_SPELL ~spwi303~ #2 ~wizard~ (2) // Flame Arrow
					ADD_MEMORIZED_SPELL ~spwi304~ #2 ~wizard~ // Fireball
					ADD_MEMORIZED_SPELL ~spwi401~ #2 ~wizard~ (2) // Confusion
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%dushai.cre~ = 0) BEGIN // Dushai (in Ulgoth's Beard)
					WRITE_LONG 0x14 2001 // XP Value (was 11)
					WRITE_SHORT 0x24 55 // Current HP (was 25)
					WRITE_SHORT 0x26 55 // Max HP (was 25)
					WRITE_SHORT 0x28 0x6014 // Animation (cleric_female_gnome, was 0x6013 halfling)
					WRITE_BYTE 0x52 16 // THAC0 (was 5)
					WRITE_BYTE 0x54 7 // Save vs. death (was 5)
					WRITE_BYTE 0x55 6 // Save vs. wands (was 5)
					WRITE_BYTE 0x56 10 // Save vs. polymorph (was 5)
					WRITE_BYTE 0x57 13 // Save vs. breath (was 5)
					WRITE_BYTE 0x58 7 // Save vs. spells (was 5)
					WRITE_BYTE 0x59 100 // Resist fire
					WRITE_BYTE 0x5e 80 // Resist magic fire
					WRITE_BYTE 0x72 1 // Blunt weapons
					WRITE_BYTE 0x75 1 // Missile weapons
					WRITE_BYTE 0x234 9 // Level 1 (was 10)
					WRITE_BYTE 0x23c 16 // Dexterity (was 12)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist, was 0x40000000 trueclass)
					WRITE_ASCII 0x258 ~x#mag10c~ #8 // Race script
					WRITE_ASCII 0x260 ~x#prs10b~ #8 // General script
					WRITE_BYTE 0x273 0x9b // Class (innocent, was 0xe cleric_mage)
					ADD_CRE_ITEM ~clck19~ #0 #0 #0 ~IDENTIFIED~ ~ARMOR~ // Robe of the Good Archmagi (Undroppable)
					ADD_CRE_ITEM ~%tutu_var%blun04~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ // Mace
					REMOVE_MEMORIZED_SPELL ~spwi215~ // Web
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ (6) // Command
					ADD_MEMORIZED_SPELL ~sppr208~ #1 ~priest~ (4) // Hold Person
					ADD_MEMORIZED_SPELL ~sppr211~ #1 ~priest~ (2) // Silence 15' Radius
					ADD_MEMORIZED_SPELL ~sppr306~ #2 ~priest~ // Protection From Fire
					ADD_MEMORIZED_SPELL ~sppr312~ #2 ~priest~ // Strength of One
					ADD_MEMORIZED_SPELL ~sppr313~ #2 ~priest~ // Holy Smite
					ADD_MEMORIZED_SPELL ~sppr315~ #2 ~priest~ // Cure Medium Wounds
					ADD_MEMORIZED_SPELL ~sppr401~ #3 ~priest~ (2) // Cure Serious Wounds
					ADD_MEMORIZED_SPELL ~sppr406~ #3 ~priest~ // Defensive Harmony
					ADD_MEMORIZED_SPELL ~sppr503~ #4 ~priest~ // Flame Strike
					ADD_MEMORIZED_SPELL ~spwi118~ #0 ~wizard~ (6) // Chromatic Orb
					ADD_MEMORIZED_SPELL ~spwi212~ #1 ~wizard~ // Mirror Image
					ADD_MEMORIZED_SPELL ~spwi215~ #1 ~wizard~ (2) // Web
					ADD_MEMORIZED_SPELL ~spwi219~ #1 ~wizard~ // Vocalize
					ADD_MEMORIZED_SPELL ~spwi306~ #2 ~wizard~ (2) // Hold Person
					ADD_MEMORIZED_SPELL ~spwi308~ #2 ~wizard~ (2) // Lightning Bolt
					ADD_MEMORIZED_SPELL ~spwi408~ #3 ~wizard~ // Stoneskin
					ADD_MEMORIZED_SPELL ~spwi418~ #3 ~wizard~ // Fire Shield (Red)
					ADD_MEMORIZED_SPELL ~spwi421~ #3 ~wizard~ // Teleport Field
					ADD_MEMORIZED_SPELL ~spwi508~ #4 ~wizard~ (3) // Chaos
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_faldor.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_FALDO~ #8 //  override script
				END	 
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_faldor5.cre~ = 0) BEGIN
      					WRITE_ASCII 0x248 ~_FALDO~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE  ~faldor.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGFALDRN~ #8 //  override script
      				END	 
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~faldor5.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGFALDRN~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE  ~faldor.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~FALDORN~ #8 //  override script
      				END	 
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~faldor5.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~FALDORN~ #8 //  override script
      				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%galtok.cre~ = 0) BEGIN // Galtok (in Nashkel Mines)
				  WRITE_LONG 0x14 176 // XP Value (was 151)
					WRITE_SHORT 0x24 25 // Current HP (was 2)
					WRITE_BYTE 0x273 0x9b // Class (innocent, was fighter/mage)
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~scrl70~ ~scrl12~ // Scroll of Foolishness
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~scrl07~ ~scrl11~ // Scroll of Clumsiness
					WRITE_SHORT 0x26 35 // Max HP
					WRITE_SHORT 0x28 0x6204 // Animation (mage_male_gnome, was 0x6202 dwarf)
					WRITE_BYTE 0x55 5 // Save vs. wands (was 13)
					WRITE_BYTE 0x56 11 // Save vs. polymorph (was 12)
					WRITE_BYTE 0x58 6 // Save vs. spells (was 14)
					WRITE_BYTE 0x234 6 // Level 1 (was 4)
					WRITE_BYTE 0x235 6 // Level 2 (was 4)
					WRITE_BYTE 0x236 1 // Level 3 (was 5)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_EVALUATED_ASCII 0x258 ~%tutu_var%mage3~ #8 // Race script
					WRITE_EVALUATED_ASCII 0x260 ~%tutu_var%mage2~ #8 // General script (was %tutu_scriptw%tasight)
					WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%tasight~ #8 // Default script
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~chan01~ ~dagg05~ // Throwing Dagger
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~chan04~ ~shld13~ // Medium Shield
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~scrl81~ ~scrl14~ // Cursed Scroll of Summon Monster
					READ_LONG 0x2b8 ix // Item slots offset
					READ_LONG 0x2bc iy // Item offset
					READ_LONG 0x2c0 iz // Item count
					FOR (i1 = 0; i1 < iz; i1 += 1) BEGIN
						READ_ASCII (iy + (0x14 * i1)) ~itm~
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%helm01~ = 0) BEGIN
						  READ_SHORT ix hs // Helmet slot
						  PATCH_IF (hs = 0xffff) BEGIN // If slot open
							WRITE_SHORT ix i1 // Assign helmet
						  END
						END ELSE
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%shld13~ = 0) BEGIN
						  READ_SHORT (ix + 0x4) ss // Shield slot
						  PATCH_IF (ss = 0xffff) BEGIN // If slot open
							WRITE_SHORT (ix + 0x4) i1 // Assign shield
						  END
						END ELSE
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%dagg05~ = 0) BEGIN
						  WRITE_SHORT (iy + (0x14 * i1) + 0xa) 20 // Charges 1
						  READ_SHORT (ix + 0x14) w2 // Weapon2 slot
						  PATCH_IF (w2 = 0xffff) BEGIN // If slot open
							WRITE_SHORT (ix + 0x14) i1 // Assign dagger to weapon2
						  END
						END ELSE
						PATCH_IF ((~%itm%~ STRING_COMPARE_CASE ~%tutu_var%scrl14~ = 0) OR (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%scrl12~ = 0) OR (~%itm%~ STRING_EQUAL_CASE ~%tutu_var%scrl11~ = 0)) BEGIN
							FOR (i2 = 18; i2 < 36; i2 += 1) BEGIN // Find first open slot
								READ_SHORT (ix + (i2 * 0x2)) sr
								PATCH_IF (sr = 0xffff) BEGIN // If open
									WRITE_SHORT (ix + (i2 * 0x2)) i1 // Assign scroll to slot
									i2 = 36 // Kills loop
								END
							END
						END
					END
					REMOVE_MEMORIZED_SPELL ~spwi205~ ~spwi212~ // Horror & Mirror Image
					REMOVE_KNOWN_SPELL ~spwi205~ ~spwi212~
					ADD_MEMORIZED_SPELL ~spwi308~ #2 ~wizard~ // Lightning Bolt
				END				
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_garric.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_GARRI~ #8 //  override script
				END	 
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_garric2.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_GARRI~ #8 //  override script
				END	 
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_garric4.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_GARRI~ #8 //  override script
				END	 
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_garric6.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_GARRI~ #8 //  override script
				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~garric.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGGARRIK~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~garric2.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGGARRIK~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~garric4.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGGARRIK~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~garric6.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGGARRIK~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~garric.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~GARRICK~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~garric2.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~GARRICK~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~garric4.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~GARRICK~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~garric6.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~GARRICK~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%gellan.cre~ = 0) BEGIN // Gellana Mirrorshade (in FAI Temple of Wisdom)
					WRITE_SHORT 0x24 65 // Current HP (was 55)
					WRITE_SHORT 0x26 65 // Max HP (was 55)
					WRITE_SHORT 0x28 0x6014 // Animation (cleric_female_gnome, was 0x6012 dwarf)
					WRITE_BYTE 0x2c 115 // Metal color (sunkissed, was 27 gray)
					WRITE_BYTE 0x2d 35 // Minor color (light:yellow/dark:purple, was 61 lavender)
					WRITE_BYTE 0x2e 50 // Major color (dark yellow, was 46 red)
					WRITE_BYTE 0x30 80 // Leather color (saturated bronze, was 21 dark iron gray)
					WRITE_BYTE 0x31 67 // Armor color (shiny gold, was 24 dark gold)
					WRITE_BYTE 0x54 6 // Save vs. death (was 7)
					WRITE_BYTE 0x55 6 // Save vs. wands (was 11)
					WRITE_BYTE 0x56 9 // Save vs. polymorph (was 10)
					WRITE_BYTE 0x57 12 // Save vs. breath (was 13)
					WRITE_BYTE 0x58 7 // Save vs. spells (was 12)
					WRITE_BYTE 0x72 1 // Blunt weapons (was 3)
					WRITE_BYTE 0x75 1 // Missile weapons
					WRITE_BYTE 0x234 10 // Level 1 (was 9)
					WRITE_BYTE 0x235 1 // Level 2 (was 3)
					WRITE_BYTE 0x236 1 // Level 3 (was 6)
					WRITE_BYTE 0x23b 18 // Wisdom (was 16)
					REMOVE_MEMORIZED_SPELL ~sppr105~ ~sppr301~ ~sppr304~
					REMOVE_KNOWN_SPELL ~sppr105~ ~sppr301~ // Entangle & Animate Dead
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ (4) // Command
					ADD_MEMORIZED_SPELL ~sppr103~ #0 ~priest~ (2) // Cure Light Wounds
					ADD_MEMORIZED_SPELL ~sppr107~ #0 ~priest~ // Protection From Evil
					ADD_MEMORIZED_SPELL ~sppr208~ #1 ~priest~ (2) // Hold Person
					ADD_MEMORIZED_SPELL ~sppr211~ #1 ~priest~ // Silence 15' Radius
					ADD_MEMORIZED_SPELL ~sppr303~ #2 ~priest~ // Dispel Magic
					ADD_MEMORIZED_SPELL ~sppr304~ #2 ~priest~ // Glyph of Warding
					ADD_MEMORIZED_SPELL ~sppr306~ #2 ~priest~ // Protection From Fire
					ADD_MEMORIZED_SPELL ~sppr309~ #2 ~priest~ // Invisibility Purge
					ADD_MEMORIZED_SPELL ~sppr401~ #3 ~priest~ (2) // Cure Serious Wounds
					ADD_MEMORIZED_SPELL ~sppr502~ #4 ~priest~ // Cure Critical Wounds
					ADD_MEMORIZED_SPELL ~sppr503~ #4 ~priest~ // Flame Strike
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%hafiz.cre~ = 0) BEGIN // Hafiz (in Gibberling Mountains)
				    WRITE_LONG 0x14 176 // XP Value (was 151)
					WRITE_SHORT 0x24 35 // Current HP (was 29)
					WRITE_SHORT 0x26 35 // Max HP
					WRITE_SHORT 0x28 0x6204 // Animation (mage_male_gnome, was 0x6202 dwarf)
					WRITE_BYTE 0x55 5 // Save vs. wands (was 13)
					WRITE_BYTE 0x56 11 // Save vs. polymorph (was 12)
					WRITE_BYTE 0x58 6 // Save vs. spells (was 14)
					WRITE_BYTE 0x234 6 // Level 1 (was 4)
					WRITE_BYTE 0x235 6 // Level 2 (was 4)
					WRITE_BYTE 0x236 1 // Level 3 (was 5)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_EVALUATED_ASCII 0x258 ~%tutu_var%mage3~ #8 // Race script
					WRITE_EVALUATED_ASCII 0x260 ~%tutu_var%mage2~ #8 // General script (was %tutu_scriptw%tasight)
					WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%tasight~ #8 // Default script
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~chan01~ ~dagg05~ // Throwing Dagger
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~chan04~ ~shld13~ // Medium Shield
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~scrl81~ ~scrl14~ // Cursed Scroll of Summon Monster
					READ_LONG 0x2b8 ix // Item slots offset
					READ_LONG 0x2bc iy // Item offset
					READ_LONG 0x2c0 iz // Item count
					FOR (i1 = 0; i1 < iz; i1 += 1) BEGIN
						READ_ASCII (iy + (0x14 * i1)) ~itm~
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%helm01~) BEGIN
						  READ_SHORT ix hs // Helmet slot
						  PATCH_IF (hs = 0xffff) BEGIN // If slot open
						    WRITE_SHORT ix i1 // Assign helmet
						  END
						END ELSE
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%shld13~) BEGIN
						  READ_SHORT (ix + 0x4) ss // Shield slot
						  PATCH_IF (ss = 0xffff) BEGIN // If slot open
							WRITE_SHORT (ix + 0x4) i1 // Assign shield
						  END
						END ELSE
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%dagg05~) BEGIN
						  WRITE_SHORT (iy + (0x14 * i1) + 0xa) 20 // Charges 1
						  READ_SHORT (ix + 0x14) w2 // Weapon2 slot
						  PATCH_IF (w2 = 0xffff) BEGIN // If slot open
						    WRITE_SHORT (ix + 0x14) i1 // Assign dagger to weapon2
						  END
						END ELSE
						PATCH_IF ((~%itm%~ STRING_COMPARE_CASE ~%tutu_var%scrl14~ = 0) OR (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%scrl12~ = 0) OR (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%scrl11~ = 0 )) BEGIN
							FOR (i2 = 18; i2 < 36; i2 += 1) BEGIN // Find first open slot
								READ_SHORT (ix + (i2 * 0x2)) sr
								PATCH_IF (sr = 0xffff) BEGIN // If open
									WRITE_SHORT (ix + (i2 * 0x2)) i1 // Assign scroll to slot
									i2 = 36 // Kills loop
								END
							END
						END
					END
					REMOVE_MEMORIZED_SPELL ~spwi205~ ~spwi212~ // Horror & Mirror Image
					REMOVE_KNOWN_SPELL ~spwi205~ ~spwi212~
					ADD_MEMORIZED_SPELL ~spwi308~ #2 ~wizard~ // Lightning Bolt
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%halaca.cre~ = 0) BEGIN // Halacan (in Gullykin)
					WRITE_LONG 0x14 176 // XP Value (was 651)
					WRITE_SHORT 0x28 0x6104 // Animation (fighter_male_gnome, was 0x5102 dwarf_low)
					WRITE_BYTE 0x55 5 // Save vs. wands (was 13)
					WRITE_BYTE 0x56 11 // Save vs. polymorph (was 12)
					WRITE_BYTE 0x58 6 // Save vs. spells (was 14)
					WRITE_BYTE 0x6f 1 // Small swords
					WRITE_BYTE 0x234 6 // Level 1 (was 4)
					WRITE_BYTE 0x235 6 // Level 2 (was 4)
					WRITE_BYTE 0x236 1 // Level 3 (was 5)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_BYTE 0x23c 16 // Dexterity (was 13)
					WRITE_EVALUATED_ASCII 0x250 ~%tutu_var%mage3~ #8 // Class script (was ~%tutu_var%mage2~)
					REMOVE_MEMORIZED_SPELL ~spwi205~ ~spwi212~ // Horror & Mirror Image
					REMOVE_KNOWN_SPELL ~spwi205~ ~spwi212~
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ // Melf's Acid Arrow
					ADD_MEMORIZED_SPELL ~spwi213~ #1 ~wizard~ // Stinking Cloud
					ADD_MEMORIZED_SPELL ~spwi217~ #1 ~wizard~ // Agannazar's Scorcher
					ADD_MEMORIZED_SPELL ~spwi308~ #2 ~wizard~ (2) // Lightning Bolt
					ADD_MEMORIZED_SPELL ~spwi317~ #2 ~wizard~ // Ghost Armor
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_imoen1.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_IMOEN2~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_imoen2.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_IMOEN2~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_imoen4.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_IMOEN2~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~_imoen6.cre~ = 0) BEGIN
					WRITE_ASCII 0x248 ~_IMOEN2~ #8 //  override script
				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~imoen1.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGIMOEN~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~imoen2.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGIMOEN~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~imoen4.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGIMOEN~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~imoen61.cre~ = 0) AND (GAME_IS ~bgt~) BEGIN
      					WRITE_ASCII 0x248 ~BGIMOEN~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~imoen1.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~IMOEN~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~imoen2.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~IMOEN~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~imoen4.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~IMOEN~ #8 //  override script
      				END
      				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~imoen6.cre~ = 0) AND (GAME_IS ~bgee~) BEGIN
      					WRITE_ASCII 0x248 ~IMOEN~ #8 //  override script
      				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%jaheir.cre~ = 0) BEGIN
					WRITE_BYTE 0x66 1 // Lore
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%jaheir2.cre~ = 0) BEGIN
					WRITE_BYTE 0x66 2  // Lore
					WRITE_BYTE 0x24 11 // Current Hit Points
					WRITE_BYTE 0x26 11 // Maximum Hit Points
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%jaheir4.cre~ = 0) BEGIN
					WRITE_BYTE 0x66 4 // Lore
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%jaheir6.cre~ = 0) BEGIN
					WRITE_BYTE 0x66 6  // Lore
					WRITE_BYTE 0x52 16 // THAC0
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%kagain.cre~ = 0) BEGIN
					WRITE_BYTE 0x54 9  // Save vs. Death
					WRITE_BYTE 0x55 11 // Save vs. Wand
					WRITE_BYTE 0x56 15 // Save vs. Polymorph
					WRITE_BYTE 0x57 17 // Save vs. Breath
					WRITE_BYTE 0x58 12 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%kagain2.cre~ = 0) BEGIN
					WRITE_BYTE 0x54 9  // Save vs. Death
					WRITE_BYTE 0x55 11 // Save vs. Wand
					WRITE_BYTE 0x56 15 // Save vs. Polymorph
					WRITE_BYTE 0x57 17 // Save vs. Breath
					WRITE_BYTE 0x58 12 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%kagain4.cre~ = 0) BEGIN
					WRITE_BYTE 0x54 8  // Save vs. Death
					WRITE_BYTE 0x55 10 // Save vs. Wand
					WRITE_BYTE 0x56 14 // Save vs. Polymorph
					WRITE_BYTE 0x57 16 // Save vs. Breath
					WRITE_BYTE 0x58 11 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%kagain6.cre~ = 0) BEGIN
					WRITE_BYTE 0x54 6  // Save vs. Death
					WRITE_BYTE 0x55 8  // Save vs. Wand
					WRITE_BYTE 0x56 12 // Save vs. Polymorph
					WRITE_BYTE 0x57 13 // Save vs. Breath
					WRITE_BYTE 0x58 9  // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%khalid.cre~ = 0) BEGIN
					WRITE_BYTE 0x23a 15 // intelligence
					WRITE_BYTE 0x66 1  // Lore
					WRITE_BYTE 0x54 14 // Save vs. Death
					WRITE_BYTE 0x55 16 // Save vs. Wand
					WRITE_BYTE 0x56 15 // Save vs. Polymorph
					WRITE_BYTE 0x57 17 // Save vs. Breath
					WRITE_BYTE 0x58 17 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%khalid2.cre~ = 0) BEGIN
					WRITE_BYTE 0x23a 15 // intelligence
					WRITE_BYTE 0x66 2  // Lore
					WRITE_BYTE 0x54 14 // Save vs. Death
					WRITE_BYTE 0x55 16 // Save vs. Wand
					WRITE_BYTE 0x56 15 // Save vs. Polymorph
					WRITE_BYTE 0x57 17 // Save vs. Breath
					WRITE_BYTE 0x58 17 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%khalid4.cre~ = 0) BEGIN
					WRITE_BYTE 0x23a 15 // intelligence
					WRITE_BYTE 0x66 4  // Lore
					WRITE_BYTE 0x54 13 // Save vs. Death
					WRITE_BYTE 0x55 15 // Save vs. Wand
					WRITE_BYTE 0x56 14 // Save vs. Polymorph
					WRITE_BYTE 0x57 16 // Save vs. Breath
					WRITE_BYTE 0x58 16 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%khalid6.cre~ = 0) BEGIN
					WRITE_BYTE 0x23a 15 // intelligence				
					WRITE_BYTE 0x66 6  // Lore
					WRITE_BYTE 0x54 11 // Save vs. Death
					WRITE_BYTE 0x55 13 // Save vs. Wand
					WRITE_BYTE 0x56 12 // Save vs. Polymorph
					WRITE_BYTE 0x57 13 // Save vs. Breath
					WRITE_BYTE 0x58 14 // Save vs. Spells
				END					
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%landri.cre~ = 0) BEGIN // Landrin (in FAI L3)
					WRITE_SHORT 0x28 0x6314 // Animation (thief_female_gnome, was 0x6212 mage_female_dwarf)
					WRITE_BYTE 0x55 9 // Save vs. wands (was 11)
					WRITE_BYTE 0x58 10 // Save vs. spells (was 12)
					WRITE_BYTE 0x236 1 // Level 3 (was 5)
					WRITE_BYTE 0x23c 16 // Dexterity (was 11)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_EVALUATED_ASCII 0x258 ~%tutu_var%mage3~ #8 // Race script (was ~%tutu_var%mage1~)
					REMOVE_MEMORIZED_SPELL ~spwi102~ ~spwi105~ // Armor & Color Spray
					REMOVE_KNOWN_SPELL ~spwi102~ ~spwi105~
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ // Melf's Acid Arrow
					ADD_MEMORIZED_SPELL ~spwi213~ #1 ~wizard~ // Stinking Cloud
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%madarc.cre~ = 0) BEGIN // Mad Arcand (in Shipwreck's Coast)
					WRITE_SHORT 0x28 0x6004 // Animation (cleric_male_gnome, was 0x6002 dwarf)
					WRITE_BYTE 0x55 4 // Save vs. wands (was 7)
					WRITE_BYTE 0x58 5 // Save vs. spells (was 8)
					WRITE_BYTE 0x72 1 // Blunt weapons (was 3)
					WRITE_BYTE 0x75 1 // Missile weapons
					WRITE_BYTE 0x236 1 // Level 3 (was 5)
					WRITE_BYTE 0x23c 16 // Dexterity (was 11)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_EVALUATED_ASCII 0x250 ~%tutu_var%mage7~ #8 // Class script (was ~%tutu_var%priest5~)
					WRITE_EVALUATED_ASCII 0x258 ~%tutu_var%priest4~ #8 // Race script
					ADD_CRE_ITEM ~%tutu_var%mage05~ #0 #0 #0 ~NONE~ ~LRING RRING~ // Free Action
					REMOVE_MEMORIZED_SPELL ~sppr214~ ~sppr301~ // Draw Upon Holy Might & Animate Dead
					REMOVE_KNOWN_SPELL ~sppr214~
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ (3) // Command
					ADD_MEMORIZED_SPELL ~sppr103~ #0 ~priest~ (3) // Cure Light Wounds
					ADD_MEMORIZED_SPELL ~sppr107~ #0 ~priest~ // Protection From Evil
					ADD_MEMORIZED_SPELL ~sppr208~ #1 ~priest~ // Hold Person
					ADD_MEMORIZED_SPELL ~sppr211~ #1 ~priest~ // Silence 15' Radius
					ADD_MEMORIZED_SPELL ~sppr301~ #2 ~priest~ // Animate Dead
					ADD_MEMORIZED_SPELL ~sppr303~ #2 ~priest~ // Dispel Magic
					ADD_MEMORIZED_SPELL ~sppr304~ #2 ~priest~ // Glyph of Warding
					ADD_MEMORIZED_SPELL ~sppr306~ #2 ~priest~ // Protection From Fire
					ADD_MEMORIZED_SPELL ~sppr309~ #2 ~priest~ // Invisibility Purge
					ADD_MEMORIZED_SPELL ~sppr401~ #3 ~priest~ (2) // Cure Serious Wounds
					ADD_MEMORIZED_SPELL ~sppr402~ #3 ~priest~ (2) // Animal Summoning 1
					ADD_MEMORIZED_SPELL ~sppr502~ #4 ~priest~ // Cure Critical Wounds
					ADD_MEMORIZED_SPELL ~sppr503~ #4 ~priest~ // Flame Strike
					ADD_MEMORIZED_SPELL ~spwi112~ #0 ~wizard~ (5) // Magic Missile
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ (4) // Melf's Acid Arrow
					ADD_MEMORIZED_SPELL ~spwi212~ #1 ~wizard~ // Mirror Image
					ADD_MEMORIZED_SPELL ~spwi302~ #2 ~wizard~ (2) // Dispel Magic
					ADD_MEMORIZED_SPELL ~spwi308~ #2 ~wizard~ (3) // Lightning Bolt
					ADD_MEMORIZED_SPELL ~spwi401~ #3 ~wizard~ (3) // Confusion
					ADD_MEMORIZED_SPELL ~spwi406~ #3 ~wizard~ // Minor Globe of Invulnerability
					ADD_MEMORIZED_SPELL ~spwi502~ #4 ~wizard~ (4) // Cloudkill
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%minsc6.cre~ = 0) BEGIN
					WRITE_LONG 0x18 36293 // Current XP
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%montar.cre~ = 0) BEGIN
					WRITE_BYTE 0x66 3  // Lore
					WRITE_BYTE 0x54 9  // Save vs. Death
					WRITE_BYTE 0x55 10 // Save vs. Wand
					WRITE_BYTE 0x56 12 // Save vs. Polymorph
					WRITE_BYTE 0x57 16 // Save vs. Breath
					WRITE_BYTE 0x58 11 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%montar2.cre~ = 0) BEGIN
					WRITE_BYTE 0x24 11 // Current Hit Points
					WRITE_BYTE 0x26 11 // Maximum Hit Points
					WRITE_BYTE 0x66 6  // Lore
					WRITE_BYTE 0x54 9  // Save vs. Death
					WRITE_BYTE 0x55 10 // Save vs. Wand
					WRITE_BYTE 0x56 12 // Save vs. Polymorph
					WRITE_BYTE 0x57 16 // Save vs. Breath
					WRITE_BYTE 0x58 11 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%montar4.cre~ = 0) BEGIN
					WRITE_BYTE 0x24 27 // Current Hit Points
					WRITE_BYTE 0x26 27 // Maximum Hit Points
					WRITE_BYTE 0x66 12 // Lore
					WRITE_BYTE 0x54 9  // Save vs. Death
					WRITE_BYTE 0x55 10 // Save vs. Wand
					WRITE_BYTE 0x56 12 // Save vs. Polymorph
					WRITE_BYTE 0x57 16 // Save vs. Breath
					WRITE_BYTE 0x58 11 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%montar6.cre~ = 0) BEGIN
					WRITE_BYTE 0x24 43 // Current Hit Points
					WRITE_BYTE 0x26 43 // Maximum Hit Points
					WRITE_BYTE 0x66 18 // Lore
					WRITE_BYTE 0x54 7  // Save vs. Death
					WRITE_BYTE 0x55 8  // Save vs. Wand
					WRITE_BYTE 0x56 11 // Save vs. Polymorph
					WRITE_BYTE 0x57 13 // Save vs. Breath
					WRITE_BYTE 0x58 9  // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%mutami.cre~ = 0) BEGIN // Mutamin (in Mutamin's Garden)
					WRITE_LONG 0x14 976 // XP Value (was 1201)
					WRITE_SHORT 0x24 24 // Current HP (was 19)
					WRITE_SHORT 0x26 24 // Max HP (was 19)
					WRITE_SHORT 0x28 0x6204 // Animation (mage_male_gnome, was 0x6202 dwarf)
					WRITE_SHORT 0x46 10 // Base AC (was 6)
					WRITE_SHORT 0x48 10 // Effective AC (was 6)
					WRITE_BYTE 0x55 5 // Save vs. wands (was 9)
					WRITE_BYTE 0x58 6 // Save vs. spells (was 3)
					WRITE_BYTE 0x23c 18 // Dexterity (was 16)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_EVALUATED_ASCII 0x258 ~%tutu_var%mage7~ #8 // Race script (was %tutu_var%mage5)
					WRITE_BYTE 0x272 6 // Race (gnome, was human)
					READ_LONG 0x2b8 ix // Item slots offset
					READ_LONG 0x2bc iy // Item offset
					READ_LONG 0x2c0 iz // Item count
					FOR (i1 = 0; i1 < iz; i1 += 1) BEGIN
					READ_ASCII (iy + (0x14 * i1)) ~itm~
					PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%dart01~ = 0) BEGIN
					  READ_SHORT (ix + 0x14) w2 // Weapon2 slot
					  PATCH_IF (w2 = 0xffff) BEGIN // If open
						WRITE_SHORT (ix + 0x14) i1 // Assign darts to weapon2
					  END
					END ELSE
					PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%potn08~ = 0) BEGIN
					  READ_SHORT (ix + 0x24) q1 // Qitem1 slot
					  READ_SHORT (ix + 0x26) q2 // Qitem1 slot
					  PATCH_IF (q1 = q2) BEGIN // If duplicate
						WRITE_SHORT (ix + 0x24) i1 // Assign potn08 to qitem1
					  END
					END
					END
					ADD_CRE_ITEM ~%tutu_var%brac01~ #0 #0 #0 ~NONE~ ~GLOVES~ // Bracers AC8
					ADD_CRE_ITEM ~%tutu_var%mage06~ #0 #0 #0 ~NONE~ ~LRING RRING~ // Haste
					REMOVE_MEMORIZED_SPELL ~spwi119~ ~spwi205~ ~spwi211~ ~spwi305~
					REMOVE_KNOWN_SPELL ~spwi119~ ~spwi205~ // Larloch's Minor Drain & Horror
					ADD_MEMORIZED_SPELL ~spwi112~ #0 ~wizard~ (5) // Magic Missile
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ (2) // Melf's Acid Arrow
					ADD_MEMORIZED_SPELL ~spwi308~ #2 ~wizard~ (2) // Lightning Bolt
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_scriptbg%neb.cre~ = 0) BEGIN // Neb (in SW Baldur's Gate FF HQ L1)
					WRITE_SHORT 0x24 70 // Current HP (was 85)
					WRITE_SHORT 0x26 70 // Max HP (was 85)
					WRITE_SHORT 0x46 10 // Base AC (was 0)
					WRITE_SHORT 0x48 10 // Effective AC (was 0)
					WRITE_BYTE 0x52 13 // THAC0 (was 19)
					WRITE_BYTE 0x54 6 // Save vs. death (was 13)
					WRITE_BYTE 0x55 4 // Save vs. wands (was 14)
					WRITE_BYTE 0x56 9 // Save vs. polymorph (was 12)
					WRITE_BYTE 0x57 13 // Save vs. breath (was 16)
					WRITE_BYTE 0x58 5 // Save vs. spells (was 15)
					WRITE_BYTE 0x75 1 // Missile weapons
					WRITE_BYTE 0x234 15 // Level 1 (was 3)
					WRITE_BYTE 0x235 1 // Level 2 (was 4)
					WRITE_BYTE 0x23c 17 // Dexterity (was 14)
					WRITE_BYTE 0x23d 15 // Constitution (was 6)
					WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%trunsgt~ #8 // Default script
					WRITE_BYTE 0x272 4 // Race (dwarf, was gnome)
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%pheirk.cre~ = 0) BEGIN // Pheirkas (in NW Baldur's Gate)
					WRITE_SHORT 0x24 54 // Current HP (was 32)
					WRITE_SHORT 0x26 54 // Max HP (was 32)
					WRITE_SHORT 0x28 0x6114 // Animation (fighter_female_gnome, was 0x6112 dwarf)
					WRITE_BYTE 0x54 7 // Save vs. death (was 11)
					WRITE_BYTE 0x55 9 // Save vs. wands (was 13)
					WRITE_BYTE 0x58 10 // Save vs. spells (was 14)
					WRITE_BYTE 0x73 0 // Spiked weapons (was 2)
					WRITE_BYTE 0x74 5 // Axes (was 3)
					WRITE_BYTE 0x236 1 // Level 3 (was 5)
					WRITE_BYTE 0x27b 0x22 // Alignment (neutral)
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_scriptbg%quayle.cre~ = 0) BEGIN 
					WRITE_SHORT 0x28 0x6004 // Animation (cleric_male_gnome, was 0x6002 dwarf)
					WRITE_BYTE 0x55 8 // Save vs. wands (was 11)
					WRITE_BYTE 0x58 9 // Save vs. spells (was 12)
					WRITE_BYTE 0x236 1 // Level 3 (was 0)
					WRITE_BYTE 0x23c 16 // Dexterity (was 15)
					WRITE_LONG 0x18 5001 // XP (was 4001)
					WRITE_SHORT 0x24 12 // Current HP (was 11)
					WRITE_SHORT 0x26 12 // Max HP (was 11)
					WRITE_BYTE 0x66 13 // Lore (was 8)
					REMOVE_MEMORIZED_SPELL ~sppr105~ // Entangle
					REMOVE_KNOWN_SPELL ~sppr105~
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ // Command
					ADD_MEMORIZED_SPELL ~spwi112~ #0 ~wizard~ // Magic Missile
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_script%quayle4.cre~ = 0) BEGIN
					WRITE_SHORT 0x28 0x6004 // Animation (cleric_male_gnome, was 0x6002 dwarf)
					WRITE_BYTE 0x55 8 // Save vs. wands (was 11)
					WRITE_BYTE 0x58 9 // Save vs. spells (was 12)
					WRITE_BYTE 0x236 1 // Level 3 (was 0)
					WRITE_BYTE 0x23c 16 // Dexterity (was 15)
					REMOVE_MEMORIZED_SPELL ~sppr105~ // Entangle
					REMOVE_KNOWN_SPELL ~sppr105~
					REMOVE_MEMORIZED_SPELL ~spwi205~ // Horror
					REMOVE_KNOWN_SPELL ~spwi205~
					WRITE_SHORT 0x24 22 // Current HP (was 18)
					WRITE_SHORT 0x26 22 // Max HP (was 18)
					WRITE_BYTE 0x66 19 // Lore (was 13)
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ (2) // Command
					ADD_MEMORIZED_SPELL ~spwi112~ #0 ~wizard~ // Magic Missile
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ (2) // Melf's Acid Arrow
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_script%quayle6.cre~ = 0) BEGIN
					WRITE_SHORT 0x28 0x6004 // Animation (cleric_male_gnome, was 0x6002 dwarf)
					WRITE_BYTE 0x55 8 // Save vs. wands (was 11)
					WRITE_BYTE 0x58 9 // Save vs. spells (was 12)
					WRITE_BYTE 0x236 1 // Level 3 (was 0)
					WRITE_BYTE 0x23c 16 // Dexterity (was 15)  				
					WRITE_SHORT 0x24 34 // Current HP (was 24)
					WRITE_SHORT 0x26 34 // Max HP (was 24)
					WRITE_BYTE 0x66 25 // Lore (was 21)
					REMOVE_MEMORIZED_SPELL ~sppr105~ // Entangle
					REMOVE_KNOWN_SPELL ~sppr105~ 
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ (2) // Command
					ADD_MEMORIZED_SPELL ~spwi118~ #0 ~wizard~ // Chromatic Orb
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ // Melf's Acid Arrow
					ADD_MEMORIZED_SPELL ~spwi309~ #2 ~wizard~ // Monster Summoning 1
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%sarhed.cre~ = 0) BEGIN // Sarhedra (in Lonely Peaks)
					WRITE_SHORT 0x24 45 // Current HP (was 28)
					WRITE_SHORT 0x26 45 // Max HP (was 28)
					WRITE_SHORT 0x28 0x6114 // Animation (fighter_female_gnome, was 0x6112 dwarf)
					WRITE_BYTE 0x54 7 // Save vs. death (was 11)
					WRITE_BYTE 0x55 9 // Save vs. wands (was 13)
					WRITE_BYTE 0x58 10 // Save vs. spells (was 14)
					WRITE_BYTE 0x73 0 // Spiked weapons (was 2)
					WRITE_BYTE 0x74 5 // Axes (was 3)
					WRITE_BYTE 0x236 1 // Level 3 (was 5)
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%skie.cre~ = 0) BEGIN
					WRITE_ASCIIE 0x248 ~%tutu_scriptbg%skie~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%skie6.cre~ = 0) BEGIN
					WRITE_ASCIIE 0x248 ~%tutu_scriptbg%skie~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%tellan.cre~ = 0) BEGIN // Tellan (in Ice Island L1)
					WRITE_LONG 0x14 2001 // XP Value (was 11)
					WRITE_SHORT 0x24 64 // Current HP (was 54)
					WRITE_SHORT 0x26 64 // Max HP (was 54)
					WRITE_SHORT 0x28 0x6204 // Animation (mage_male_gnome, was 0x6202 dwarf)
					WRITE_SHORT 0x46 10 // Base AC (was 0)
					WRITE_SHORT 0x48 10 // Effective AC (was 0)
					WRITE_BYTE 0x54 10 // Save vs. death (was 6)
					WRITE_BYTE 0x55 3 // Save vs. wands (was 6)
					WRITE_BYTE 0x56 9 // Save vs. polymorph (was 6)
					WRITE_BYTE 0x57 11 // Save vs. breath (was 10)
					WRITE_BYTE 0x58 4 // Save vs. spells (was 7)
					WRITE_BYTE 0x6f 1 // Small swords (was 3)
					WRITE_BYTE 0x236 1 // Level 3 (was 13)
					WRITE_LONG 0x244 0x04000000 // Kit (illusionist)
					WRITE_ASCIIE 0x250 ~%tutu_var%follow~ #8
					WRITE_ASCII 0x258 ~x#mag14d~ #8 // Race script (was ~%tutu_var%mage7~)
					WRITE_ASCII 0x260 ~~ #8
					WRITE_BYTE 0x270 0x80 // Reaction (neutral, was enemy)
					WRITE_BYTE 0x272 6 // Race (gnome, was human)
					WRITE_BYTE 0x273 0xd //  Class (mage/thief, was thief)
					SAY INITIAL_MEETING #4931
					SAY SELECT_COMMON1 #4930
					SAY DAMAGE #12582
					SAY DYING #12583
					SAY DIALOGUE_DEFAULT #4929
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~dagg04~ ~dagg02~ // Dagger +1
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~leat02~ ~clck17~ // Robe of the Evil Archmagi
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~slng02~ ~mage02~ // Protection from Normal Missiles
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~_bull02~ ~_ageamul~ (8) // Minor Globe of Invulnerability
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~bull02~ ~mageamul~ (8)
					REPLACE_TEXTUALLY CASE_INSENSITIVE ~bull03~ ~potn08~ // Potion of Healing
					READ_LONG 0x2b8 ix // Item slots offset
					READ_LONG 0x2bc iy // Item offset
					READ_LONG 0x2c0 iz // Item count
					FOR (i1 = 0; i1 < iz; i1 += 1) BEGIN
						READ_ASCII (iy + (0x14 * i1)) ~itm~
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%clck17~ = 0) BEGIN
							READ_SHORT (ix + 0x2) rs // Armor slot
								PATCH_IF (rs = 0xffff) BEGIN // If slot open
									WRITE_SHORT (ix + 0x2) i1 // Assign robe to armor
								END
						END ELSE
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%mage02~ = 0) BEGIN
							READ_SHORT (ix + 0x8) lr // Lring slot
							READ_SHORT (ix + 0xa) rr // Rring slot
							PATCH_IF (lr = 0xffff) BEGIN // If slot open
								WRITE_SHORT (ix + 0x8) i1 // Assign mage02 to lring
							END ELSE
							PATCH_IF (rr = 0xffff) BEGIN // If slot open
								WRITE_SHORT (ix + 0xa) i1 // Assign mage02 to rring
							END
						END ELSE
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_scriptm%ageamul~ = 0) BEGIN
							READ_SHORT (ix + 0xc) rs // Amulet slot
							PATCH_IF (rs = 0xffff) BEGIN // If slot open
								WRITE_SHORT (ix + 0xc) i1 // Assign mageamul to amulet
							END
						END ELSE
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%dagg02~ = 0) BEGIN
							READ_SHORT (ix + 0x12) w1 // Weapon1 slot
							READ_SHORT (ix + 0x14) w2 // Weapon2 slot
							PATCH_IF (w1 = w2) BEGIN // If duplicate weapon reference
								WRITE_SHORT (ix + 0x14) i1 // Assign dagger to weapon2
							END
						END ELSE
						PATCH_IF (~%itm%~ STRING_COMPARE_CASE ~%tutu_var%potn08~ = 0) BEGIN
							FOR (i2 = 18; i2 < 36; i2 += 1) BEGIN // Find first open slot
								READ_SHORT (ix + (i2 * 0x2)) sr
								PATCH_IF (sr = 0xffff) BEGIN // If open
									WRITE_SHORT (ix + (i2 * 0x2)) i1 // Assign potn08 to slot
									i2 = 36 // Kills loop
								END
							END
						END
					END
					REMOVE_MEMORIZED_SPELL ~spwi205~ ~spwi308~ ~spwi313~ ~spwi401~
					REMOVE_KNOWN_SPELL ~spwi205~ ~spwi313~ // Horror, Skull Trap
					ADD_MEMORIZED_SPELL ~spwi203~ #1 ~wizard~ // Detect Invisibility
					ADD_MEMORIZED_SPELL ~spwi211~ #1 ~wizard~ (2) // Melf's Acid Arrow
					ADD_MEMORIZED_SPELL ~spwi219~ #1 ~wizard~ // Vocalize
					ADD_MEMORIZED_SPELL ~spwi305~ #2 ~wizard~ // Haste
					ADD_MEMORIZED_SPELL ~spwi311~ #2 ~wizard~ // Protection From Normal Missiles
					ADD_MEMORIZED_SPELL ~spwi312~ #2 ~wizard~ // Slow
					ADD_MEMORIZED_SPELL ~spwi318~ #2 ~wizard~ // Minor Spell Deflection
					ADD_MEMORIZED_SPELL ~spwi325~ #2 ~wizard~ // Melf's Minute Meteors
					ADD_MEMORIZED_SPELL ~spwi405~ #3 ~wizard~ // Improved Invisibility
					ADD_MEMORIZED_SPELL ~spwi408~ #3 ~wizard~ // Stoneskin
					ADD_MEMORIZED_SPELL ~spwi418~ #3 ~wizard~ // Fire Shield (Red)
					ADD_MEMORIZED_SPELL ~spwi419~ #3 ~wizard~ // Secret Word
					ADD_MEMORIZED_SPELL ~spwi408~ #3 ~wizard~ // Stoneskin
					ADD_MEMORIZED_SPELL ~spwi503~ #4 ~wizard~ // Cone of Cold
					ADD_MEMORIZED_SPELL ~spwi504~ #4 ~wizard~ // Monster Summoning 3
					ADD_MEMORIZED_SPELL ~spwi505~ #4 ~wizard~ // Shadow Door
					ADD_MEMORIZED_SPELL ~spwi513~ #4 ~wizard~ // Breach
					ADD_MEMORIZED_SPELL ~spwi522~ #4 ~wizard~ // Minor Spell Turning
					ADD_MEMORIZED_SPELL ~spwi605~ #5 ~wizard~ // Death Spell
					ADD_MEMORIZED_SPELL ~spwi609~ #5 ~wizard~ // True Sight
					ADD_MEMORIZED_SPELL ~spwi624~ #5 ~wizard~ // Summon Nishruu
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%tiax.cre~ = 0) BEGIN
					WRITE_SHORT 0x28 0x6004 // Animation (cleric_male_gnome, was 0x6002 dwarf)
					WRITE_BYTE 0x236 1 // Level 3 (was 0)
					READ_LONG 0x244 tkt
					PATCH_IF (tkt = 0x40000000) BEGIN
						WRITE_LONG 0x244 0x00000000 // Kit (none, was 0x40000000 trueclass)
					END
					READ_LONG 0x2b8 st // Item slots offset
					READ_SHORT (st + 0x2a) sx
					READ_SHORT (st + 0x2c) sz
					PATCH_IF ((sx = 1) AND (sz = 2)) BEGIN // Equip sling and bullets
						WRITE_SHORT (st + 0x2a) `0x0
						WRITE_SHORT (st + 0x2c) `0x0
						WRITE_SHORT (st + 0x14) 1
						WRITE_SHORT (st + 0x1a) 2
						WRITE_SHORT (st + 0x4c) 1
					END
					REMOVE_MEMORIZED_SPELL ~sppr105~ // Entangle
					REMOVE_KNOWN_SPELL ~sppr105~
					WRITE_SHORT 0x24 14 // Current HP (was 17)
					WRITE_SHORT 0x26 14 // Max HP (was 17)
					WRITE_BYTE 0x55 10 // Save vs. wands (was 14)
					WRITE_BYTE 0x58 11 // Save vs. spells (was 15)
					WRITE_BYTE 0x45 25 // Hide in shadows
					WRITE_BYTE 0x64 10 // Detect illusions
					WRITE_BYTE 0x65 5 // Set traps
					WRITE_BYTE 0x66 6 // Lore (was 8)
					WRITE_BYTE 0x67 25 // Open locks (was 15)
					WRITE_BYTE 0x68 25 // Move silently (was 10)
					WRITE_BYTE 0x69 30 // Find traps (was 15)
					WRITE_BYTE 0x6a 35 // Pick pockets (was 10)
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ // Command
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%tiax4.cre~ = 0) BEGIN
					WRITE_SHORT 0x28 0x6004 // Animation (cleric_male_gnome, was 0x6002 dwarf)
					WRITE_BYTE 0x236 1 // Level 3 (was 0)
					READ_LONG 0x244 tkt
					PATCH_IF (tkt = 0x40000000) BEGIN
						WRITE_LONG 0x244 0x00000000 // Kit (none, was 0x40000000 trueclass)
					END
					READ_LONG 0x2b8 st // Item slots offset
					READ_SHORT (st + 0x2a) sx
					READ_SHORT (st + 0x2c) sz
					PATCH_IF ((sx = 1) AND (sz = 2)) BEGIN // Equip sling and bullets
						WRITE_SHORT (st + 0x2a) `0x0
						WRITE_SHORT (st + 0x2c) `0x0
						WRITE_SHORT (st + 0x14) 1
						WRITE_SHORT (st + 0x1a) 2
						WRITE_SHORT (st + 0x4c) 1
					END
					REMOVE_MEMORIZED_SPELL ~sppr105~ // Entangle
					REMOVE_KNOWN_SPELL ~sppr105~
					WRITE_SHORT 0x24 26 // Current HP (was 28)
					WRITE_SHORT 0x26 26 // Max HP (was 28)
					WRITE_BYTE 0x55 9 // Save vs. wands (was 13)
					WRITE_BYTE 0x58 10 // Save vs. spells (was 14)
					WRITE_BYTE 0x45 35 // Hide in shadows
					WRITE_BYTE 0x64 10 // Detect illusions
					WRITE_BYTE 0x65 5 // Set traps
					WRITE_BYTE 0x66 12 // Lore (was 16)
					WRITE_BYTE 0x67 35 // Open locks (was 25)
					WRITE_BYTE 0x68 35 // Move silently (was 20)
					WRITE_BYTE 0x69 40 // Find traps (was 25)
					WRITE_BYTE 0x6a 45 // Pick pockets (was 20)
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ (2) // Command
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%tiax6.cre~ = 0) BEGIN
					WRITE_SHORT 0x28 0x6004 // Animation (cleric_male_gnome, was 0x6002 dwarf)
					WRITE_BYTE 0x236 1 // Level 3 (was 0)
					READ_LONG 0x244 tkt
					PATCH_IF (tkt = 0x40000000) BEGIN
						WRITE_LONG 0x244 0x00000000 // Kit (none, was 0x40000000 trueclass)
					END
					READ_LONG 0x2b8 st // Item slots offset
					READ_SHORT (st + 0x2a) sx
					READ_SHORT (st + 0x2c) sz
					PATCH_IF ((sx = 1) AND (sz = 2)) BEGIN // Equip sling and bullets
						WRITE_SHORT (st + 0x2a) `0x0
						WRITE_SHORT (st + 0x2c) `0x0
						WRITE_SHORT (st + 0x14) 1
						WRITE_SHORT (st + 0x1a) 2
						WRITE_SHORT (st + 0x4c) 1
					END
					REMOVE_MEMORIZED_SPELL ~sppr105~ // Entangle
					REMOVE_KNOWN_SPELL ~sppr105~
					WRITE_SHORT 0x24 36 // Current HP (was 38)
					WRITE_SHORT 0x26 36 // Max HP (was 38)
					WRITE_BYTE 0x55 8 // Save vs. wands (was 12)
					WRITE_BYTE 0x58 9 // Save vs. spells (was 13)
					WRITE_BYTE 0x45 45 // Hide in shadows
					WRITE_BYTE 0x64 10 // Detect illusions
					WRITE_BYTE 0x65 5 // Set traps
					WRITE_BYTE 0x66 18 // Lore (was 23)
					WRITE_BYTE 0x67 45 // Open locks (was 35)
					WRITE_BYTE 0x68 45 // Move silently (was 30)
					WRITE_BYTE 0x69 50 // Find traps (was 35)
					WRITE_BYTE 0x6a 55 // Pick pockets (was 30)
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ // Command
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%unshey.cre~ = 0) BEGIN // Unshey (in Friendly Arm Inn L2)
					WRITE_SHORT 0x24 42 // Current HP (was 23)
					WRITE_SHORT 0x26 42 // Max HP (was 23)
					WRITE_SHORT 0x28 0x6014 // Animation (cleric_female_gnome, was 0x6012 dwarf)
					WRITE_BYTE 0x54 5 // Save vs. death (was 9)
					WRITE_BYTE 0x55 9 // Save vs. wands (was 13)
					WRITE_BYTE 0x58 10 // Save vs. spells (was 14)
					WRITE_BYTE 0x236 1 // Level 3 (was 5)
					WRITE_EVALUATED_ASCII 0x250 ~%tutu_var%priest4~ #8 // Class script (was %tutu_var%priest3)
					REMOVE_MEMORIZED_SPELL ~sppr105~ ~sppr213~ // Entangle & Spiritual Hammer
					REMOVE_KNOWN_SPELL ~sppr105~
					ADD_MEMORIZED_SPELL ~sppr102~ #0 ~priest~ (2) // Command
					ADD_MEMORIZED_SPELL ~sppr103~ #0 ~priest~ (2) // Cure Light Wounds
					ADD_MEMORIZED_SPELL ~sppr107~ #0 ~priest~ // Protection From Evil
					ADD_MEMORIZED_SPELL ~sppr208~ #1 ~priest~ // Hold Person
					ADD_MEMORIZED_SPELL ~sppr211~ #1 ~priest~ // Silence 15' Radius
					ADD_MEMORIZED_SPELL ~sppr303~ #2 ~priest~ // Dispel Magic
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_scriptbg%xan.cre~ = 0) BEGIN
					WRITE_ASCIIE 0x248 ~%tutu_var%xan~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%xan4.cre~ = 0) BEGIN
					WRITE_ASCIIE 0x248 ~%tutu_var%xan~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%xan6.cre~ = 0) BEGIN
					WRITE_ASCIIE 0x248 ~%tutu_var%xan~ #8 //  override script
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%yeslic.cre~ = 0) BEGIN
					WRITE_BYTE 0x24 23 // Current Hit Points
					WRITE_BYTE 0x26 23 // Maximum Hit Points
					WRITE_BYTE 0x54 5  // Save vs. Death
					WRITE_BYTE 0x55 9  // Save vs. Wand
					WRITE_BYTE 0x56 13 // Save vs. Polymorph
					WRITE_BYTE 0x57 16 // Save vs. Breath
					WRITE_BYTE 0x58 10 // Save vs. Spells
				END
				PATCH_IF (~%crefile%~ STRING_COMPARE_CASE ~%tutu_var%yeslic5.cre~ = 0) BEGIN
					WRITE_BYTE 0x24 42 // Current Hit Points
					WRITE_BYTE 0x26 42 // Maximum Hit Points
					WRITE_BYTE 0x54 4  // Save vs. Death
					WRITE_BYTE 0x55 8  // Save vs. Wand
					WRITE_BYTE 0x56 12 // Save vs. Polymorph
					WRITE_BYTE 0x57 15 // Save vs. Breath
					WRITE_BYTE 0x58 9  // Save vs. Spells
				END
			BUT_ONLY_IF_IT_CHANGES /*indent of C_E */
		END /* of A_I */
	END /*of F_E IN */

  /* Scripts */
	COMPILE ~bg1npc/core/baf/x#mag10b.baf~  /* For Bently */
    COMPILE ~bg1npc/core/baf/x#mag10c.baf~  /* For Dushai */
    COMPILE ~bg1npc/core/baf/x#mag14d.baf~  /* For Tellan */
    COMPILE ~bg1npc/core/baf/x#prs10b.baf~  /* For Dushai */


  /* .2da patching */
	
  /* pdialog.2da preparation - not needed for BGEE */
  ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
    COPY_EXISTING ~pdialog.2da~ ~override~ 
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^JOIN_DIALOG_FILE\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~JOIN_DIALOG_FILE\1DREAM_SCRIPT_FILE~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_MINSCJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_MINSCJ\1_MINSCD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_FALDOJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_FALDOJ\1_FALDOD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_JAHEIJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_JAHEIJ\1_JAHEID~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_CORANJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_CORANJ\1_CORAND~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_DYNAHJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_DYNAHJ\1_DYNAHD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_XANJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_XANJ\1_XAND~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_YESLIJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_YESLIJ\1_YESLID~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_ELDOTJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_ELDOTJ\1_ELDOTD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_VICONJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_VICONJ\1_VICOND~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_SHARTJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_SHARTJ\1_SHARTD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_SKIEJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_SKIEJ\1_SKIED~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_KIVANJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_KIVANJ\1_KIVAND~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_XZARJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_XZARJ\1_XZARD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_SAFANJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_SAFANJ\1_SAFAND~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_QUAYLJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_QUAYLJ\1_QUAYLD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_KHALIJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_KHALIJ\1_KHALID~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_TIAXJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_TIAXJ\1_TIAXD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_EDWINJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_EDWINJ\1_EDWIND~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_AJANTJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_AJANTJ\1_AJANTD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_KAGAIJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_KAGAIJ\1_KAGAID~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_MONTAJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_MONTAJ\1_MONTAD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_IMOEN2\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_IMOEN2\1_IMOEND~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_GARRIJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_GARRIJ\1_GARRID~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_BRANWJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_BRANWJ\1_BRANWD~
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~^_ALORAJ\( +[^ ]+ +[^ ]+ +\)[^ ]+~ ~_ALORAJ\1_ALORAD~
    BUT_ONLY_IF_IT_CHANGES
  END
  
  /* BGT Versions */
  ACTION_IF GAME_IS ~bgt~ THEN BEGIN
    COPY_EXISTING ~pdialog.2da~ ~override~
      COUNT_2DA_ROWS 8 "cnt_row"
      FOR ( cnt=0; cnt<"%cnt_row%"; cnt=cnt+1 ) BEGIN
        READ_2DA_ENTRY "%cnt%" 0 8 "pd_name"
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "MONTARON")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "MONTAD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "KAGAIN")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "KAGAID"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "KIVAN")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "KIVAND"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "SHARTEEL")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "SHARTD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "YESLICK")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "YESLID"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "XZAR")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "XZARD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "ALORA")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "ALORAD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "AJANTIS")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "AJANTD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "KHALID")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "KHALID"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "GARRICK")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "GARRID"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "SAFANA")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "SAFAND"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "FALDORN")=0) BEGIN
        SET_2DA_ENTRY "%cnt%" 3 8 "FALDOD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "BRANWEN")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "BRANWD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "QUAYLE")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "QUAYLD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "XAN")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "XAND"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "SKIE")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "SKIED"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "ELDOTH")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "ELDOTD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "TIAX")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "TIAXD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "DYNAHEIR")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "DYNAHD"
        END
        PATCH_IF (("%pd_name%" STRING_COMPARE_CASE "CORAN")=0) BEGIN
         SET_2DA_ENTRY "%cnt%" 3 8 "CORAND"
        END
      END
    BUT_ONLY_IF_IT_CHANGES
  END

  COPY_EXISTING ~pdialog.2da~ ~override~
    PRETTY_PRINT_2DA

  /* Tutu: Giving Imoen a banter file entry in the interdi.2da */
  ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
    APPEND ~interdia.2da~ ~IMOEN _BIMOEN~ UNLESS ~_BIMOEN~
  END
  /* BGT and BG:EE : Checking for Imoen's banter file if the Fixpack isn't installed */
  ACTION_IF NOT (FILE_EXISTS_IN_GAME ~cdbehbla.pro~) AND (GAME_IS ~bgt bgee~) THEN BEGIN
    ACTION_IF FILE_EXISTS_IN_GAME ~saradush.mve~ THEN BEGIN
      COPY_EXISTING ~interdia.2da~ ~override~
        SET_2DA_ENTRY 17 1 2 ~BIMOEN2~ // fixes ToB version
      BUT_ONLY_IF_IT_CHANGES
    END ELSE BEGIN
        APPEND ~interdia.2da~ ~IMOEN BIMOEN2~ // fixes SoA version
        UNLESS ~BIMOEN2~
    END
  END
  
  COPY_EXISTING ~interdia.2da~ ~override~
      PRETTY_PRINT_2DA

  /* Imoen BIMOEN.DLG check for Tutu */
  ACTION_IF NOT (FILE_EXISTS_IN_GAME ~_bimoen.dlg~) AND (GAME_IS ~tutu tutu_totsc~) THEN BEGIN
    COMPILE ~BG1NPC/Core/dlg/X#BIMOEN_TUTU.D~
  END
  
  /* Imoen BIMOEN.DLG check for BGT */
  ACTION_IF NOT (FILE_EXISTS_IN_GAME ~bimoen2.dlg~) AND (GAME_IS ~bgt~) THEN BEGIN
      COMPILE ~BG1NPC/Core/dlg/X#BIMOEN_BGT.D~
  END 
  
  /* give Imoen a J file in BG:EE */
  ACTION_IF NOT (FILE_EXISTS_IN_GAME ~imoenj.dlg~) AND (GAME_IS ~bgee~) THEN BEGIN
    COMPILE ~BG1NPC/Core/dlg/x#imoenj_bgee.d~
  END

  /* give CHARNAME a dialogue file in BG:EE */
  ACTION_IF NOT (FILE_EXISTS_IN_GAME ~player1.dlg~) AND (GAME_IS ~bgee~) THEN BEGIN
    COMPILE ~BG1NPC/Core/dlg/x#player1_bgee.d~
  END

  /* Cam's 2DA Neutral/Happy interjection restoration : Tutu|BGT only (BG:EE has already modified happy.2da) */
  ACTION_IF GAME_IS ~tutu tutu_totsc bgt~ THEN BEGIN
  	COPY_EXISTING ~happy.2da~ ~override~
    		FOR (row = 8; row < 14; row = row + 1) BEGIN
      			SET_2DA_ENTRY "%row%" 2 4 ~80~
    		END
  	BUT_ONLY_IF_IT_CHANGES
  END
  
    /* CamDawg's Temple Healing Fix */
    /* give all stores the normal suite of cures available */
    COPY_EXISTING_REGEXP GLOB ~^.+\.sto$~ ~override~
      READ_BYTE 0x10 "flags" ELSE 0
      PATCH_IF (("%flags%" BAND 0b00010000) = 0b00010000) BEGIN //  if sures available; also filters out invalid files
        READ_LONG 0x2c "buy_off"   ELSE 0
        READ_LONG 0x34 "sale_off"  ELSE 0
        READ_LONG 0x4c "drink_off" ELSE 0
        READ_LONG 0x70 "cure_off"  ELSE 0
        READ_LONG 0x74 "cure_num"  ELSE 0
        SET "new_cure" = 0
        SET "sppr103" = 0 //  cure light wounds
        SET "sppr212" = 0 //  slow poison
        SET "sppr303" = 0 //  dispel magic
        SET "sppr307" = 0 //  remove curse
        SET "sppr401" = 0 //  cure serious wounds
        SET "sppr502" = 0 //  cure critical wounds
        SET "sppr504" = 0 //  raise dead
        SET "sppr607" = 0 //  heal
        SET "sppr712" = 0 //  resurrection
        SET "sppr713" = 0 //  greater restoration
        //  check if cures already available
        FOR (index = 0; index < cure_num; index = index + 1) BEGIN
          READ_ASCII ("%cure_off%" + ("%index%" * 0x0c)) "resref"
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr103" = 0) BEGIN
            SET "sppr103" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr212" = 0) BEGIN
            SET "sppr212" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr303" = 0) BEGIN
            SET "sppr303" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr307" = 0) BEGIN
            SET "sppr307" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr401" = 0) BEGIN
            SET "sppr401" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr502" = 0) BEGIN
            SET "sppr502" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr504" = 0) BEGIN
            SET "sppr504" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr607" = 0) BEGIN
            SET "sppr607" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr712" = 0) BEGIN
            SET "sppr712" = 1
          END ELSE
          PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr713" = 0) BEGIN
            SET "sppr713" = 1
          END
        END
        //  add cures if not already present
        PATCH_IF ("%sppr103%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr103~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 50        //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr212%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr212~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 150       //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr303%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr303~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 200       //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr307%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr307~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 500       //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr401%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr401~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 100       //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr502%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr502~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 200       //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr504%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr504~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 750       //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr607%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr607~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 750       //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr712%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr712~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 1000      //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        PATCH_IF ("%sppr713%" = 0) BEGIN //  if cure not already available
          INSERT_BYTES  ("%cure_off%" +        ("%cure_num%" * 0x0c)) 0x0c
            WRITE_ASCII ("%cure_off%" +        ("%cure_num%" * 0x0c)) ~sppr713~ //  resref
            WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 750       //  price
          SET "cure_num" = "%cure_num%" + 1
          SET "new_cure" = "%new_cure%" + 1
        END
        //  adjust offsets and counts if cures inserted
        PATCH_IF ("%new_cure%" > 0) BEGIN
          WRITE_LONG 0x74 "%cure_num%"
          PATCH_IF ("%buy_off%" > "%cure_off%") BEGIN
            WRITE_LONG 0x2c ("%buy_off%" + ("%new_cure%" * 0x0c))
          END
          PATCH_IF ("%sale_off%" > "%cure_off%") BEGIN
            WRITE_LONG 0x34 ("%sale_off%" + ("%new_cure%" * 0x0c))
          END
          PATCH_IF ("%drink_off%" > "%cure_off%") BEGIN
            WRITE_LONG 0x4c ("%drink_off%" + ("%new_cure%" * 0x0c))
          END
        END
      END
      BUT_ONLY_IF_IT_CHANGES

  /* Update SPELDESC.2DA for Temple Fix in BGEE */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
  	COPY_EXISTING ~speldesc.2da~ ~override~
  		COUNT_2DA_ROWS 2 "cnt_row"
  		FOR (cnt = 0; cnt < %cnt_row%; cnt = cnt + 1) BEGIN
  			READ_2DA_ENTRY "%cnt%" 0 2 "spl_name"
  			PATCH_IF (("%spl_name%" STRING_COMPARE_CASE "sppr502")=0) BEGIN
  				SET_2DA_ENTRY "%cnt%" 1 2 "25357"
  			END
  			PATCH_IF (("%spl_name%" STRING_COMPARE_CASE "sppr607")=0) BEGIN
  				SET_2DA_ENTRY "%cnt%" 1 2 "25358"
  			END
  			PATCH_IF (("%spl_name%" STRING_COMPARE_CASE "sppr712")=0) BEGIN
  				SET_2DA_ENTRY "%cnt%" 1 2 "25359"
  			END
  			PATCH_IF (("%spl_name%" STRING_COMPARE_CASE "sppr713")=0) BEGIN
  				SET_2DA_ENTRY "%cnt%" 1 2 "25360"
  			END
    	END
  	BUT_ONLY_IF_IT_CHANGES
  END


  ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
    /* Music File .2da patching, Tutu only */
    COPY ~BG1NPC/Core/MUS/x#blank.mus~ ~music~
    COPY_EXISTING ~songlist.2da~ ~override~
      SET_2DA_ENTRY 0 2 3 ~X#BLANK.MUS~
    BUT_ONLY_IF_IT_CHANGES
  END
  
  /* Tutu repeating dialogues block other talks */
  ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
    /* Stop Bioware dialogues repeating, fixes DLG matching BreakingPoint DPLAYER2.bcs changes */
    COMPILE EVALUATE_BUFFER ~BG1NPC/Core/dlg/X#BGREPLACE_TUTU.D~
  END
  
  /* BGT repeating dialogues block other talks */
  ACTION_IF GAME_IS ~bgt~ THEN BEGIN
    /* Stop Bioware dialogues repeating, fixes DLG */
    COMPILE EVALUATE_BUFFER ~BG1NPC/Core/dlg/X#BGREPLACE_BGT.D~
  END

  /* BG:EE repeating dialogues block other talks */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
    /* Stop Bioware dialogues repeating, fixes DLG */
    COMPILE EVALUATE_BUFFER ~BG1NPC/Core/dlg/x#bgreplace_bgee.D~
  END

  /* custom cutspy.cre for BG1NPC code */
  COPY ~BG1NPC/Core/CRE/x#cutspy.cre~ ~override/x#cutspy.cre~
   WRITE_LONG NAME1 (BNOT 0x0)
   WRITE_LONG NAME2 (BNOT 0x0)
   LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
   WRITE_LONG DAMAGE (BNOT 0x0)
   WRITE_LONG DYING (BNOT 0x0)
   PATCH_IF (SOURCE_SIZE > 0x2d4) BEGIN
     WRITE_ASCIIE 0x280 ~%DEST_RES%~ #32 //  death variable
   END
   ADD_CRE_ITEM ~%tutu_var%mage01~ #0 #0 #0 ~identified&unstealable&undroppable~ ~LRING~
   ADD_CRE_ITEM ~%tutu_var%minhp1~ #0 #0 #0 ~identified&unstealable&undroppable~ ~AMULET~


  /* X#GorionTalkingLetter Variable: Gorion's Letter creature */
  COPY ~BG1NPC/Core/cre/x#gorlet.cre~ ~override/x#gorlet.cre~
    SAY NAME1 @5
    SAY NAME2 @5
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~ 

  /* add Gorion's Talking Letter Area Script */
  EXTEND_BOTTOM ~%CK_LibL5_BCS%.bcs~ ~BG1NPC/CORE/baf/X#FW2612.baf~
    EVALUATE_BUFFER

  /* add Gorion's Talking Letter dialog, no need for EVAL */
  COMPILE        ~BG1NPC/Core/dlg/X#GORLET.D~
  COMPILE        ~BG1NPC/Core/baf/X#GORLET.BAF~

  /* berelinde's Statue Naming Fixes */
  COPY_EXISTING ~%tutu_var%achen.cre~  ~override~
    SAY NAME2 @1118 //  ~Achen Dell~
  BUT_ONLY_IF_IT_CHANGES
  
  COPY_EXISTING ~%tutu_var%cailan.cre~  ~override~
    SAY NAME2 @1119 //  ~Cailan~
  BUT_ONLY_IF_IT_CHANGES
  
  COPY_EXISTING ~%tutu_var%faizah.cre~  ~override~
    SAY NAME2 @1120 //  ~Faizah Tin~
  BUT_ONLY_IF_IT_CHANGES
  
  COPY_EXISTING ~%tutu_var%rance.cre~  ~override~
    SAY NAME2 @1121 //  ~Rance~
  BUT_ONLY_IF_IT_CHANGES
  
  COPY_EXISTING ~%tutu_var%vail.cre~  ~override~
    SAY NAME2 @1122 //  ~Vail~
  BUT_ONLY_IF_IT_CHANGES
  
  /* Kivan and Tazok Dialogue File Assignment */
  COPY_EXISTING ~%tutu_var%tazok2.cre~  ~override~
    WRITE_EVALUATED_ASCII 0x2CC ~%tutu_var%tazok2~ #8 //  dialog
  BUT_ONLY_IF_IT_CHANGES
  
  /* STATE.IDS patching to ToB - thanks, Cam, if you read it */
  /* adds custom IsValidForPartyDialogue state */
  APPEND ~STATE.IDS~ ~0x80101FEF CD_STATE_NOTVALID~ UNLESS ~CD_STATE_NOTVALID~

  /* ACTION.IDS and TRIGGER.IDS patching to ToB - thanks, Cam, if you read it */
  /* and GTIMES.IDS, ANIMATE.IDS patching to ToB, courtesy of the BG2 Fix Pack */
  INCLUDE ~BG1NPC/LIB/ids_entries_cleanup.tph~

/* Tutu J File junk States, DPLAYER2.BCS */
ACTION_IF (GAME_IS ~tutu tutu_totsc~) THEN BEGIN
	/* Cleaning J files from junk states */
	COMPILE EVALUATE_BUFFER ~BG1NPC/Core/dlg/X#JFIX_TUTU.D~
	
	/* Changing DPLAYER2.bcs to stop BreakingPoint SDNS from hanging Tutu Only */
	COPY_EXISTING ~DPLAYER2.bcs~ ~override~
		DECOMPILE_AND_PATCH BEGIN
			REPLACE_TEXTUALLY CASE_INSENSITIVE ~!InParty(Myself)~ ~False()~
			REPLACE_TEXTUALLY CASE_INSENSITIVE ~ChangeAIScript("",DEFAULT)~ ~~
			REPLACE_TEXTUALLY CASE_INSENSITIVE ~SetGlobal("IHATEYOUALL","LOCALS",0)~ ~~
		END
	BUT_ONLY_IF_IT_CHANGES

	EXTEND_TOP ~DPLAYER2.bcs~ ~BG1NPC/Core/baf/X#DPLYR2.BAF~
END 

/* BGT J File junk States, DPLAYER2.BCS */
ACTION_IF GAME_IS ~bgt~ THEN BEGIN
	/* Cleaning J files from junk states */
	COMPILE EVALUATE_BUFFER ~BG1NPC/Core/dlg/X#JFIX_BGT.D~
	/* Changing DPLAYER2.bcs to stop BreakingPoint SDNS from hanging is unnessesary in BGT */     
END


/* Tutu, BGT, BG:EE Dialogue Correction in X#JFIX.D */
  COPY_EXISTING ~%UC_TofB_BCS%.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY CASE_INSENSITIVE
      ~Global("DeathOfSarevok","GLOBAL",0)~
      ~Global("DeathOfSarevok","GLOBAL",0) OR(4) Global("X#DynaheirRomanceInactive","GLOBAL",1) Global("X#DynaheirRomanceActive","GLOBAL",0) Dead("dynaheir") !InParty("dynaheir")~
      REPLACE_TEXTUALLY CASE_INSENSITIVE
      ~GlobalTimerExpired("DeathOfSarevok","GLOBAL")~
      ~GlobalTimerExpired("DeathOfSarevok","GLOBAL") OR(4) Global("X#DynaheirRomanceInactive","GLOBAL",1) Global("X#DynaheirRomanceActive","GLOBAL",0) Dead("dynaheir") !InParty("dynaheir")~
      REPLACE_TEXTUALLY CASE_INSENSITIVE
      ~Global("D0FinalSave","GLOBAL",0)~
      ~Global("D0FinalSave","GLOBAL",0) OR(4) Global("X#DynaheirRomanceInactive","GLOBAL",1) Global("X#DynaheirRomanceActive","GLOBAL",0) Dead("dynaheir") !InParty("dynaheir")~
    END
  BUT_ONLY_IF_IT_CHANGES

/* Trying to prevent Alora from Stuttering. */
  COPY_EXISTING ~%tutu_var%ALORA.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
    REPLACE_TEXTUALLY CASE_INSENSITIVE
      ~TimeOfDay(DAY)~ ~AreaCheck("%WBaldursGate_HallofWonders%") NumberOfTimesTalkedTo(0) TimeOfDay(DAY) !InParty(Myself)~
    END
  BUT_ONLY_IF_IT_CHANGES

  /* WizWom's Prevent Alora Area Script from Crashing. */
  COPY_EXISTING ~%HallofWonders_BCS%.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~Exists("Alora")~ ~Exists("Alora") InMyArea("Alora")~
    END
  BUT_ONLY_IF_IT_CHANGES
  
  /* Stop Viconia's Potential Script Stutter on Tutu - fix already in BGEE */
  /* scripts */
  ACTION_IF !(GAME_IS ~bgee~) THEN BEGIN
	  COPY_EXISTING ~%tutu_var%VICONIA.bcs~ ~override~
    	DECOMPILE_AND_PATCH BEGIN
    		REPLACE_TEXTUALLY CASE_INSENSITIVE ~See("flamingfist2")~ ~See("flamingfist2") !Dead("flamingfist2")~
	    END
  	  BUT_ONLY_IF_IT_CHANGES
  END
  
  /* Make Tazok Killable */
  /* scripts */
  COPY_EXISTING ~%tutu_var%TAZOK.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
    	REPLACE_TEXTUALLY CASE_INSENSITIVE ~HPPercentLT(Myself,50)~ ~HPPercentLT(Myself,50) !InParty("kivan")~
    	REPLACE_TEXTUALLY CASE_INSENSITIVE ~Global("MACTazokBelt","LOCALS",0)~ ~Global("X#MACDisableTazokInv","GLOBAL",1)~
    	REPLACE_TEXTUALLY CASE_INSENSITIVE ~SetGlobal("MACTazokBelt","LOCALS",1)~ ~SetGlobal("X#MACDisableTazokInv","GLOBAL",2)~
    END
  BUT_ONLY_IF_IT_CHANGES
  
  /* scripts extension */
  EXTEND_TOP ~%tutu_var%TAZOK.bcs~ ~BG1NPC/Core/baf/X#TAKILL.BAF~
    EVALUATE_BUFFER
	
  /* Set Tazok sprite back to living before last chapter, and move triggers to another variable other than Dead() */
  EXTEND_BOTTOM ~%Undercity_BCS%.bcs~ ~bg1npc/core/baf/x#tazokarea.baf~
    EVALUATE_BUFFER
    
  /* Create Coran's Wyverns */
  COPY_EXISTING ~%tutu_var%WYVERN.CRE~ ~override/X#CORWYV.CRE~
    WRITE_ASCII 0x280 ~X#CoranWyvern~ #32
  BUT_ONLY_IF_IT_CHANGES

  /* put them in the Cave */
  COPY_EXISTING ~%CloakwoodWyverns_WyvernCave%.ARE~ ~override~
    READ_LONG 0x54 actors_off
    READ_SHORT 0x58 actors_num
    FOR (i = 0; i < %actors_num%; i += 1) BEGIN
      READ_ASCII (%actors_off% + %i% * 0x110 + 0x80) actor_resref
      PATCH_IF !("%actor_resref%" STRING_COMPARE_CASE "%tutu_var%WYVERN") BEGIN
        WRITE_ASCII (%actors_off% + %i% * 0x110 + 0x80) X#CORWYV #8
      END
    END
  BUT_ONLY_IF_IT_CHANGES
  
  /* False() out blocks from Coran's default script 
     All platforms: Default timer expired block
     BGEE only: Wyvern killed block */
  COPY_EXISTING ~%CORAN_BCS%.bcs~ ~override~
  	DECOMPILE_AND_PATCH BEGIN
  	  REPLACE_TEXTUALLY CASE_INSENSITIVE ~GlobalTimerExpired("Coran","GLOBAL")~ ~False()~
      PATCH_IF (GAME_IS ~bgee~) BEGIN 
      	REPLACE_TEXTUALLY CASE_INSENSITIVE ~Global("coranreward","global",0)~ ~False()~
	  END
    END
  BUT_ONLY_IF_IT_CHANGES

  /* Fixing Coran's Wyvern script */
  EXTEND_TOP ~%CORAN_BCS%.bcs~ ~BG1NPC/Core/baf/X#CORWYV.BAF~
     EVALUATE_BUFFER

  /* Fix Coran's dialog files */
  ACTION_IF GAME_IS ~tutu tutu_totsc bgee~ THEN BEGIN
  	COMPILE EVALUATE_BUFFER ~BG1NPC/Core/dlg/x#corwyv_tutubgee.d~
  END ELSE ACTION_IF GAME_IS ~bgt~ THEN BEGIN
  	COMPILE EVALUATE_BUFFER ~BG1NPC/Core/dlg/x#corwyv_bgt.d~
  END
  
  /* removing Kivan's timer to leave party */
  COPY_EXISTING ~%KIVAN_BCS%.bcs~ ~override~
  	DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~GlobalTimerExpired("Kivan","GLOBAL")~ ~False()~
    END
  BUT_ONLY_IF_IT_CHANGES

  /* removing Minsc's timer to leave party */
  COPY_EXISTING ~%MINSC_BCS%.bcs~ ~override~
  	DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~GlobalTimerExpired("Minsc","GLOBAL")~ ~False()~
    END
  BUT_ONLY_IF_IT_CHANGES

  /* Area Script Assignment Patching: All Areas Script ID'd */
  /* Tutu */
  ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
    INCLUDE ~BG1NPC\LIB\tutu_area_script_assign.tph~
  END ELSE ACTION_IF GAME_IS ~bgee~ THEN BEGIN 
  /* BGEE */
    INCLUDE ~BG1NPC\LIB\bgee_area_script_assign.tph~
  END

	/* Area Type Flagging */
    /* TotSC only */
    ACTION_IF GAME_IS ~tutu_totsc bgt bgee~ THEN BEGIN //  if TotSC is installed
      COPY_EXISTING ~%IsleofBalduranN%.are~ ~override~
                    ~%IsleofBalduranS%.are~ ~override~
                    ~%DurlagsTower%.are~ ~override~
                    ~%Farmlands%.are~ ~override~ //  is this correct? area reference is... FW0400
        READ_BYTE  "0x48" "flags"
        WRITE_BYTE "0x48" ("%flags%" BOR "0b00010001")
      BUT_ONLY_IF_IT_CHANGES
    END
  
    /* FOREST and OUTDOOR */
    COPY_EXISTING ~%FishingVillage%.are~ ~override~
                  ~%Peldvale%.are~ ~override~
                  ~%LionsWay%.are~ ~override~
                  ~%CoastWay%.are~ ~override~
                  ~%Larswood%.are~ ~override~
                  ~%ShipwrecksCoast%.are~ ~override~
                  ~%HighHedge%.are~ ~override~
                  ~%MutaminsGarden%.are~ ~override~
                  ~%Lighthouse%.are~ ~override~
                  ~%RedCanyons%.are~ ~override~
                  ~%SouthBeregostRoad%.are~ ~override~
                  ~%Ulcaster%.are~ ~override~
                  ~%ArchaeologicalSite%.are~ ~override~
                  ~%FishermansLake%.are~ ~override~
                  ~%NorthNashkelRoad%.are~ ~override~
                  ~%LonelyPeaks%.are~ ~override~
                  ~%FirewineBridge%.are~ ~override~
                  ~%BearRiver%.are~ ~override~
                  ~%ValleyoftheTombs%.are~ ~override~
                  ~%DryadFalls%.are~ ~override~
                  ~%FireLeafForest%.are~ ~override~
                  ~%GibberlingMountains%.are~ ~override~
      READ_BYTE  "0x48" "flags"
      WRITE_BYTE "0x48" ("%flags%" BOR "0b00010001")
    BUT_ONLY_IF_IT_CHANGES
  
    /* OUTDOOR ONLY */
    COPY_EXISTING ~%GnollStronghold%.are~ ~override~
                  ~%NashkelMines%.are~ ~override~
                  ~%FriendlyArmInn%.are~ ~override~
                  ~%Temple%.are~ ~override~
                  ~%NashkelCarnival%.are~ ~override~
      READ_BYTE  "0x48" "flags"
      WRITE_BYTE "0x48" ("%flags%" BOR "0b00000001")
    BUT_ONLY_IF_IT_CHANGES
  
    /* CITY and OUTDOOR */
    COPY_EXISTING ~%WyrmsCrossing%.are~ ~override~
                  ~%Candlekeep_Ch6%.are~ ~override~
                  ~%Gullykin%.are~ ~override~
      READ_BYTE  "0x48" "flags"
      WRITE_BYTE "0x48" ("%flags%" BOR "0b00001001")
    BUT_ONLY_IF_IT_CHANGES
  
    /* WizWom's Tutu NPC Battle fix: TUTU only, not compatible with BGT scripts */
    ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
      COPY_EXISTING ~%EDWIN_BCS%.bcs~ ~override~
                    ~%ELDOTH_BCS%.bcs~ ~override~
                    ~%SHARTEEL_BCS%.bcs~ ~override~
                    ~%JAHEIRA_BCS%.bcs~ ~override~
                    ~%KAGAIN_BCS%.bcs~ ~override~
                    ~%KHALID_BCS%.bcs~ ~override~
                    ~%KIVAN_BCS%.bcs~ ~override~
                    ~%MINSC_BCS%.bcs~ ~override~
                    ~%MONTARON_BCS%.bcs~ ~override~
                    ~%QUAYLE_BCS%.bcs~ ~override~
                    ~%TIAX_BCS%.bcs~ ~override~
                    ~%VICONIA_BCS%.bcs~ ~override~
                    ~%DYNAHEIR_BCS%.bcs~ ~override~
        DECOMPILE_AND_PATCH BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE ~MakeUnselectable(5000)~ ~MakeUnselectable(6) Continue()~
        END
      BUT_ONLY_IF_IT_CHANGES
    END


    /* Miloch's bugged spell/script fixes (required for Gnomes) */
    ACTION_IF GAME_IS ~tutu tutu_totsc bgt~ THEN BEGIN
      COPY_EXISTING ~mage14d.bcs~ ~override~ // Fix script syntax error
        DECOMPILE_AND_PATCH BEGIN
          REPLACE_TEXTUALLY EXACT_MATCH ~!Dead("yself)")~ ~!StateCheck(Myself,4032)~
        END
      BUT_ONLY_IF_IT_CHANGES
    END


  ACTION_IF NOT(MOD_IS_INSTALLED setup-scs.tp2 32) THEN BEGIN // Non-SCS Smarter Priests
    EXTEND_TOP ~%tutu_var%priest4.bcs~ ~BG1NPC/phase2/baf/x#pries4.baf~ // Add a few spells
  END

  COPY_EXISTING ~%tutu_var%ghoult.itm~ ~override~ // Fix droppable Ghoul Touch
    PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
      READ_BYTE 0x18 fl // Flags
      PATCH_IF ((fl BAND 0b00000100) = 0b00000100) BEGIN // If movable
        WRITE_BYTE 0x18 (fl BAND 0b11110011) // Make unmovable
      END
    END
  BUT_ONLY_IF_IT_CHANGES


/* BEGIN PHASE I BG1NPC PROJECT */
BEGIN @1007
  GROUP @1006
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
   COPY ~BG1NPC/Core/X#component.xx~ ~override/X#BG1NPCPhase1.G3~
   COPY ~BG1NPC/Core/X#component.xx~ ~override/X#BG1NPCPhase2.G3~ //legacy file, leave in

  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

/* set up .tra files for Tutu vs BGT sound resources, create platform files */
  COPY ~BG1NPC/TRA/%LANGUAGE%/X#ADDIAL_tmp.tra~ ~BG1NPC/TRA/%LANGUAGE%/X#ADDIAL.tra~
      EVALUATE_BUFFER

  /* Patching _ELDOTH.bcs */
  COPY_EXISTING ~%ELDOTH_BCS%.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
    	REPLACE_TEXTUALLY CASE_INSENSITIVE ~GlobalTimerExpired("RescueSkie","GLOBAL")~ ~!Global("X#SkieLeftEldoth","GLOBAL",1) GlobalTimerExpired("RescueSkie","GLOBAL")~
    END
  BUT_ONLY_IF_IT_CHANGES

  /* Death variable assignments for Yeslick dialogue X#YESLI1.BAF */
  COPY_EXISTING ~%tutu_var%iron11.cre~ ~override~
    WRITE_ASCII 0x280 ~iron11~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_var%poe.cre~ ~override~
    WRITE_ASCII 0x280 ~poe~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  /* items */
  /* Ring of Human Influence */
  COPY_EXISTING ~BG1NPC/Phase1/ITM/X#RINGRO.itm~ ~override/X#RINGRO.itm~
    SAY NAME1 @10
    SAY NAME2 @11
    SAY UNIDENTIFIED_DESC @12
    SAY DESC @13

  /* Ajantis shield */
  COPY ~BG1NPC/Phase1/ITM/X#ISHAJ.BAM~ ~override~
  COPY ~BG1NPC/Phase1/ITM/X#CSHAJ.BAM~ ~override~
  COPY ~BG1NPC/Phase1/ITM/X#AJSHLD.itm~ ~override~
    SAY NAME1 @6
    SAY NAME2 @7
    SAY UNIDENTIFIED_DESC @8
    SAY DESC @9
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x44 ~GSHLD03~ #8  //  ground icon8
      END

  /* BGEE: Add Ajantis' shield to item_use.2da */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN 
  	APPEND ~item_use.2da~ ~x#ajshld AJANTIS 9382 2~ 
  	  UNLESS ~x#ajshld~
  	COPY_EXISTING ~item_use.2da~ ~override~
	  PRETTY_PRINT_2DA
  END
  
  /* Give Ajantis his shield and a bastard sword (no proficiency) */
  COPY_EXISTING ~%tutu_var%ajanti.cre~  ~override~
                ~%tutu_var%ajanti4.cre~ ~override~
                ~%tutu_var%ajanti6.cre~ ~override~
    ADD_CRE_ITEM ~%tutu_var%SW1H01~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ EQUIP
    ADD_CRE_ITEM ~X#AJSHLD~ #0 #0 #0 ~IDENTIFIED~ ~SHIELD~

  /* Imoen - Pink Xan */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN 
	COPY ~BG1NPC/Phase1/cre/pinkxans_ee.bmp~ ~override/pinkxans.bmp~
	COPY ~BG1NPC/Phase1/cre/pinkxanl_ee.bmp~ ~override/pinkxanl.bmp~
  END ELSE BEGIN /* Tutu or BGT */
	COPY ~BG1NPC/Phase1/cre/pinkxans.bmp~ ~override~
  	COPY ~BG1NPC/Phase1/cre/pinkxanl.bmp~ ~override~
  END
  
  COPY ~BG1NPC/Phase1/ITM/PINKXAN.SPL~ ~override~
    SAY 8 @14
    WRITE_ASCII 0xde ~pinkxans~
    WRITE_ASCII 0xae ~pinkxanl~

  COPY ~BG1NPC/Phase1/ITM/PINKXAN.SPL~ ~override/pinkback.spl~
    SAY 8 @14
    PATCH_IF (GAME_IS ~bgee~) BEGIN  /* BGEE */
        WRITE_ASCII 0xde ~xans~
		WRITE_ASCII 0xae ~xanl~
    END ELSE PATCH_IF (GAME_IS ~bgt~) BEGIN /* BGT */
        WRITE_ASCII 0xde ~xans~
		WRITE_ASCII 0xae ~xanm~
    END ELSE BEGIN /* Tutu */
        WRITE_ASCII 0xde ~_ans~
		WRITE_ASCII 0xae ~_anl~
	END

  /* Imoen - Lockpick */
  COPY ~BG1NPC/Phase1/ITM/X#IMSAF.SPL~ ~override/x#imsaf.spl~
    SAY 8 @15

  COPY ~BG1NPC/Phase1/ITM/NUTKIN.EFF~ ~override~

  /* AstroBryGuy's and Mike1072's BG:EE strref fix */
  COPY ~BG1NPC/Phase1/ITM/X#DEX.SPL~ ~override~
    PATCH_IF (GAME_IS ~bgee~) BEGIN
        WRITE_LONG 0x08 25989  // spell name "Dexterity Increase"
    END
    ELSE BEGIN
        WRITE_LONG 0x08 2688  // spell name "Dexterity Increase"
    END
    WRITE_ASCII 0x10 ~CAS_M08~ #8   // casting sound
    WRITE_ASCII 0x3a ~SPWI415C~ #8   // spell icon
    WRITE_ASCII 0x76 ~SPWI415B~ #8   // ability #0 icon
    WRITE_ASCII 0xDE ~EFF_P07~ #8   // resource
	
  COPY ~BG1NPC/Phase1/ITM/X#POLY.SPL~ ~override~
    WRITE_ASCII 0x10 ~CAS_M08~ #8    // casting sound
    WRITE_ASCII 0x3a ~SPWI415C~ #8   // spell icon
    WRITE_ASCII 0x76 ~SPWI415B~ #8   // ability #0 icon
    WRITE_ASCII 0xDE ~EFF_P07~ #8    // resource
	
  COPY ~BG1NPC/Phase1/ITM/X#TOME.itm~ ~override~
    SAY NAME1 @16
    SAY NAME2 @16
    SAY UNIDENTIFIED_DESC @17
    SAY DESC @18

  COPY ~BG1NPC/Phase1/ITM/X#IAMUL.itm~ ~override/x#iamul.itm~
    SAY NAME1 @19
    SAY NAME2 @19
    SAY UNIDENTIFIED_DESC @20
    SAY DESC @20

  /* Safana's Item: */
  COPY ~BG1NPC/Phase1/ITM/X#SABOX.itm~ ~override/x#sabox.itm~
    SAY NAME1 @21
    SAY NAME2 @21
    SAY UNIDENTIFIED_DESC @22
    SAY DESC @22

  /* Imoen - Tarnesh Spell scene */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/baf/X#CANTRP.BAF~

  /* Phase 1 - Dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#AJANTIS.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#ALORA.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#ALOREPL.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#BRANW.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#CORAN.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#DYNAH.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#EDWIN.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#ELDOTH.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#FALDORN.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#GARRI.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#IMOEN.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#JAHEIRA.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#KAGAIN.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#KHALID.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#KIVAN.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#MINSC.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#MONTARON.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#QUAYL.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#SAFANA.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#SHARTEEL.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#SKIE.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#TIAX.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#VICONIA.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#XAN.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#XZAR.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#YESLICK.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#ADDIAL.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#RUMOR.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase1/dlg/X#PCBURY.D~

  /* Dream script compilation */
  EXTEND_TOP ~%tutu_var%EDWIND.bcs~   ~BG1NPC/Phase1/baf/P#EDWIND.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%ELDOTD.bcs~   ~BG1NPC/Phase1/baf/P#ELDOTD.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%IMOEND.bcs~   ~BG1NPC/Phase1/baf/P#IMOEND.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%KAGAID.bcs~   ~BG1NPC/Phase1/baf/P#KAGAID.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%KIVAND.bcs~   ~BG1NPC/Phase1/baf/P#KIVAND.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%MINSCD.bcs~   ~BG1NPC/Phase1/baf/P#MINSCD.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%MONTAD.bcs~   ~BG1NPC/Phase1/baf/P#MONTAD.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%SHARTD.bcs~   ~BG1NPC/Phase1/baf/P#SHARTD.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%SKIED.bcs~    ~BG1NPC/Phase1/baf/P#SKIED.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%VICOND.bcs~   ~BG1NPC/Phase1/baf/P#VICOND.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%XZARD.bcs~    ~BG1NPC/Phase1/baf/P#XZARD.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%YESLID.bcs~   ~BG1NPC/Phase1/baf/P#YESLID.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%tutu_var%GARRID.bcs~   ~BG1NPC/Phase1/baf/P#GARRID.BAF~
    EVALUATE_BUFFER

  /* NPC override script compilation */
  EXTEND_TOP ~%ALORA_BCS%.bcs~   ~BG1NPC/Phase1/baf/X#ALORA1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%AJANTIS_BCS%.bcs~ ~BG1NPC/Phase1/baf/X#AJANTIS1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%BRANWEN_BCS%.bcs~  ~BG1NPC/Phase1/baf/X#BRANWEN1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%CORAN_BCS%.bcs~   ~BG1NPC/Phase1/baf/X#CORAN1.BAF~
      EVALUATE_BUFFER
      USING ~BG1NPC/TRA/%LANGUAGE%/X#CORAN1.TRA~
  EXTEND_TOP ~%DYNAHEIR_BCS%.bcs~ ~BG1NPC/Phase1/baf/X#DYNAHEIR1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%EDWIN_BCS%.bcs~   ~BG1NPC/Phase1/baf/X#EDWIN1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%ELDOTH_BCS%.bcs~  ~BG1NPC/Phase1/baf/X#ELDOT1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%FALDORN_BCS%.bcs~   ~BG1NPC/Phase1/baf/X#FALDO1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%GARRICK_BCS%.bcs~   ~BG1NPC/Phase1/baf/X#GARRI1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%IMOEN_BCS%.bcs~  ~BG1NPC/Phase1/baf/X#IMOEN1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%JAHEIRA_BCS%.bcs~ ~BG1NPC/Phase1/baf/X#JAHEIRA1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%KAGAIN_BCS%.bcs~  ~BG1NPC/Phase1/baf/X#KAGAIN1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%KHALID_BCS%.bcs~  ~BG1NPC/Phase1/baf/X#KHALID1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%KIVAN_BCS%.bcs~   ~BG1NPC/Phase1/baf/X#KIVAN1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%MINSC_BCS%.bcs~   ~BG1NPC/Phase1/baf/X#MINSC1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%MONTARON_BCS%.bcs~ ~BG1NPC/Phase1/baf/X#MONTA1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%QUAYLE_BCS%.bcs~  ~BG1NPC/Phase1/baf/X#QUAYLE1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%SAFANA_BCS%.bcs~  ~BG1NPC/Phase1/baf/X#SAFANA1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%SHARTEEL_BCS%.bcs~ ~BG1NPC/Phase1/baf/X#SHAR1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%SKIE_BCS%.bcs~    ~BG1NPC/Phase1/baf/X#SKIE1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%TIAX_BCS%.bcs~    ~BG1NPC/Phase1/baf/X#TIAX1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%VICONIA_BCS%.bcs~ ~BG1NPC/Phase1/baf/X#VICON1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%XAN_BCS%.bcs~     ~BG1NPC/Phase1/baf/X#XAN1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%XZAR_BCS%.bcs~    ~BG1NPC/Phase1/baf/X#XZAR1.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%YESLICK_BCS%.bcs~ ~BG1NPC/Phase1/baf/X#YESLI1.BAF~
      EVALUATE_BUFFER

  /* Firewine */
  EXTEND_BOTTOM ~%FirewineBridge_BCS%.bcs~ ~BG1NPC/Phase1/baf/P#FW4500.baf~
    EVALUATE_BUFFER

  COPY_EXISTING ~%tutu_scriptf%twbax_a.cre~ ~override~
                ~%tutu_scriptf%twbax_b.cre~ ~override~
                ~%tutu_scriptf%twbax_c.cre~ ~override~
                ~%tutu_scriptf%twbax_d.cre~ ~override~
                ~%tutu_scriptf%twbax_e.cre~ ~override~
    WRITE_EVALUATED_ASCII 0x2CC ~X#RUMOR~ #8 //  dialog
  BUT_ONLY_IF_IT_CHANGES


  /* BEGIN PHASE II BG1NPC PROJECT */

  /* DV assignments */
  COPY_EXISTING  ~%tutu_var%alvanh.cre~ ~override~
    WRITE_ASCII 0x280 ~alvahe~ #32 //  death variable X#MOINT2.BAF
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING  ~%tutu_var%slave.cre~ ~override~
    WRITE_ASCII 0x280 ~cmslave~ #32 //  death variable unused
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING  ~%tutu_var%korax.cre~ ~override~
    WRITE_ASCII 0x280 ~korax~ #32 //  death variable X#JAINT2.BAF
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING  ~%tutu_var%coksmth.cre~ ~override~
    WRITE_ASCII 0x280 ~peter~ #32 //  death variable X#FAINT.D
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING  ~%tutu_var%entill.cre~ ~override~
    WRITE_ASCII 0x280 ~entill~ #32 //  death variable X#JAINT.D
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING  ~%tutu_var%phlydi3.cre~ ~override~
    WRITE_ASCII 0x280 ~phlydia~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_var%bearbl.cre~ ~override~
    WRITE_ASCII 0x280 ~bearbl~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_var%bearbr.cre~ ~override~
    WRITE_ASCII 0x280 ~bearbr~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_var%bearca.cre~ ~override~
    WRITE_ASCII 0x280 ~bearca~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_var%bearpo.cre~ ~override~
    WRITE_ASCII 0x280 ~bearpo~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_var%elmin5.cre~ ~override~
    WRITE_ASCII 0x280 ~elminster5~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  /* ToSC death Variables */
  ACTION_IF GAME_IS ~tutu_totsc bgt bgee~ THEN BEGIN
    COPY_EXISTING  ~%tutu_var%pridem.cre~ ~override~
      WRITE_ASCII 0x280 ~pridem~ #32 //  death variable X#BRINT2.BAF
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING  ~%tutu_scripta%varicem.cre~ ~override~
      WRITE_ASCII 0x280 ~avaricem~ #32 //  death variable X#BRINT2.BAF
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%fearm.cre~ ~override~
      WRITE_ASCII 0x280 ~fearm~ #32 //  death variable X#BRINT2.BAF
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%lovem.cre~ ~override~
      WRITE_ASCII 0x280 ~lovem~ #32 //  death variable X#BRINT2.BAF
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING  ~%tutu_scripto%grema03.cre~ ~override~
      WRITE_ASCII 0x280 ~cmogremage~ #32 //  death variable X#XZINT2.BAF
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING  ~%tutu_var%zombiew.cre~ ~override~
      WRITE_BYTE 0x272 0x94 // Race (zombie, was skeleton)
      WRITE_ASCII 0x280 ~zombiew~ #32 //  death variable X#XZINT2.BAF
    BUT_ONLY_IF_IT_CHANGES
  END

  /* ToSC Interjections, ToSC only: */
  ACTION_IF GAME_IS ~tutu_totsc bgt bgee~ THEN BEGIN //  if TotSC is installed
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#TOTSC.d~
  END

  /* Interjections */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#BRINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#JAINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#FAINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#SKINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#KIINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#XZINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#MOINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#ELINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#SAINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#TIINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#YEINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#KAINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#KHINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#AJINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#DYINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#XAINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#SHINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#MIINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#EDINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#GAINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#ALINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#IMINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#COINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#VIINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#QUINT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/x#kiint_new.d~

  /* Area Script additions */
  EXTEND_BOTTOM ~%SilvershieldEstate_L2_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW0102.BAF~
      EVALUATE_BUFFER
  EXTEND_BOTTOM ~%FishingVillage_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW1400.BAF~
      EVALUATE_BUFFER
  EXTEND_BOTTOM ~%Undercellars_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW0112.BAF~
      EVALUATE_BUFFER
  EXTEND_BOTTOM ~%SorcerousSundries_L2_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW0704.BAF~
      EVALUATE_BUFFER
  EXTEND_BOTTOM ~%LionsWay_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW2700.BAF~
      EVALUATE_BUFFER
      USING ~BG1NPC/TRA/%LANGUAGE%/P#FW2700.tra~

  /* General use scripts */
  COMPILE EVALUATE_BUFFER ~bg1npc/phase2/baf/x#gpsht.baf~ 
  COMPILE ~bg1npc/phase2/baf/x#shout6.baf~
  COMPILE ~bg1npc/phase2/baf/x#fight2.baf~ 

	  
 /* -JW-'s Edwin vs Denak fix */ 
 /* http:// forums.gibberlings3.net/index.php?s=&showtopic=15516&view=findpost&p=133308 */
 
  EXTEND_BOTTOM ~%SpiderWood_BCS%.bcs~ ~BG1NPC/Phase2/baf/JW#FW3000.BAF~

  /* Interjection scripting changes, added creatures */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#KRUMM.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#JESSUP.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#DORAA.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#MOMUR1.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#ZIZI1.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#ZIZI2.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#ZIZI3.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#ZIZI4.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#XZSLIM.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#XZJELL.BAF~

  /* Interjection scripting changes, BG1 NPCs */
  EXTEND_TOP  ~%BRANWEN_BCS%.bcs~  ~BG1NPC/Phase2/baf/X#BRINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_scriptr%EDDEATH.bcs~ ~BG1NPC/Phase2/baf/X#BRDWI.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%JAHEIRA_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#JAINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%FALDORN_BCS%.bcs~   ~BG1NPC/Phase2/baf/X#FAINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%SKIE_BCS%.bcs~    ~BG1NPC/Phase2/baf/X#SKINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%KIVAN_BCS%.bcs~   ~BG1NPC/Phase2/baf/X#KIINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%MONTARON_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#MOINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%XZAR_BCS%.bcs~    ~BG1NPC/Phase2/baf/X#XZINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_var%NIEMAIN.bcs~ ~BG1NPC/Phase2/baf/X#NIEMAIN.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%ELDOTH_BCS%.bcs~  ~BG1NPC/Phase2/baf/X#ELINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%SAFANA_BCS%.bcs~  ~BG1NPC/Phase2/baf/X#SAINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%TIAX_BCS%.bcs~    ~BG1NPC/Phase2/baf/X#TIINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_var%RIELTAR.bcs~ ~BG1NPC/Phase2/baf/X#RIYE.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%YESLICK_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#YEINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%KAGAIN_BCS%.bcs~  ~BG1NPC/Phase2/baf/X#KAINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%KHALID_BCS%.bcs~  ~BG1NPC/Phase2/baf/X#KHINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%AJANTIS_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#AJINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%DYNAHEIR_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#DYINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%EDWIN_BCS%.bcs~   ~BG1NPC/Phase2/baf/X#EDINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%MINSC_BCS%.bcs~   ~BG1NPC/Phase2/baf/X#MIINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%CORAN_BCS%.bcs~   ~BG1NPC/Phase2/baf/X#COINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%IMOEN_BCS%.bcs~  ~BG1NPC/Phase2/baf/X#IMINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%GARRICK_BCS%.bcs~   ~BG1NPC/Phase2/baf/X#GAINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%SHARTEEL_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#SHINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%XAN_BCS%.bcs~     ~BG1NPC/Phase2/baf/X#XAINT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_var%DRIZZT.bcs~  ~BG1NPC/Phase2/baf/X#DRIZZT2.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%KIVAN_BCS%.bcs~  ~BG1NPC/Phase2/baf/x#kiint_new.baf~
      EVALUATE_BUFFER

  /* Added Quests */
  /* Edwin */
  /* Tiax Quest */
  /* creatures */
  /* Belgin */
  COPY ~bg1npc/phase2/cre/x#belgin.cre~ ~override/x#belgin.cre~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 ~Belgin~
    SAY NAME2 ~Belgin~
    SAY INITIAL_MEETING @557
    SAY BATTLE_CRY1 @558
    SAY BATTLE_CRY2 @558
    SAY BATTLE_CRY3 @558
    SAY BATTLE_CRY4 @558
    SAY BATTLE_CRY5 @558
    SAY DAMAGE @559
    SAY DYING @560
    SAY SELECT_COMMON1 @561
    SAY DIALOGUE_DEFAULT @561
    WRITE_ASCIIE 0x250 ~%tutu_var%priest3~ #8 /* Class script */
    ADD_CRE_ITEM ~hamm01~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ EQUIP
    ADD_CRE_ITEM ~shld04~ #0 #0 #0 ~IDENTIFIED~ ~SHIELD~
    ADD_CRE_ITEM ~chan02~ #0 #0 #0 ~IDENTIFIED~ ~ARMOR~
    ADD_CRE_ITEM ~helm06~ #0 #0 #0 ~IDENTIFIED~ ~HELMET~
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~ 

  /* Karris */
  COPY ~bg1npc/phase2/cre/x#karris.cre~ ~override/x#karris.cre~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 ~Karris~
    SAY NAME2 ~Karris~
    SAY INITIAL_MEETING @476
    SAY BATTLE_CRY1 @488
    SAY BATTLE_CRY2 @488
    SAY BATTLE_CRY3 @488
    SAY BATTLE_CRY4 @488
    SAY BATTLE_CRY5 @488
    SAY DAMAGE @555
    SAY DYING @556
    SAY SELECT_COMMON1 @476
    SAY DIALOGUE_DEFAULT @476
    WRITE_ASCII 0x248 ~x#karris~ #8  // override
    WRITE_ASCIIE 0x250 ~%tutu_var%thief4~ #8  // Class script
    WRITE_ASCII 0x2cc ~x#karris~ #8  // dialogue
    WRITE_ASCII 0x280 ~x#karris~ #32 // DV
    ADD_CRE_ITEM ~sw1h05~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ EQUIP
    ADD_CRE_ITEM ~leat11~ #0 #0 #0 ~IDENTIFIED~ ~ARMOR~

  /* Assorted bounty hunters */
  COPY ~bg1npc/phase2/cre/x#tqbh1.cre~ ~override/x#tqbh1.cre~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 ~Alvo~
    SAY NAME2 ~Alvo~
    SAY INITIAL_MEETING @474
    SAY BATTLE_CRY1 @354
    SAY BATTLE_CRY2 @354
    SAY BATTLE_CRY3 @354
    SAY BATTLE_CRY4 @354
    SAY BATTLE_CRY5 @354
    SAY DAMAGE @473
    SAY DYING @472
    SAY SELECT_COMMON1 @474
    SAY DIALOGUE_DEFAULT @474
	WRITE_ASCII 0x250 ~x#fight2~ #8 //  class script
    WRITE_ASCII 0x2cc ~x#tqbh~ #8 //  dialogue
    WRITE_ASCII 0x280 ~x#tqbh1~ #32 // DV
    WRITE_ASCIIE 0x248 ~x#tqbh~ #8 //  override script
    ADD_CRE_ITEM ~ax1h01~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ EQUIP
    ADD_CRE_ITEM ~ax1h01~ #0 #0 #0 ~IDENTIFIED~ ~SHIELD~
    ADD_CRE_ITEM ~chan01~ #0 #0 #0 ~IDENTIFIED~ ~ARMOR~

  COPY ~bg1npc/phase2/cre/x#tqbh2.cre~ ~override/x#tqbh2.cre~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 ~Leti~
    SAY NAME2 ~Leti~
    SAY INITIAL_MEETING @25
    SAY BATTLE_CRY1 @25
    SAY BATTLE_CRY2 @25
    SAY BATTLE_CRY3 @25
    SAY BATTLE_CRY4 @25
    SAY BATTLE_CRY5 @25
    SAY DAMAGE @3
    SAY DYING @4
    SAY SELECT_COMMON1 @25
    SAY DIALOGUE_DEFAULT @25
    WRITE_ASCII 0x250 ~x#fight2~ #8 //  class script
    WRITE_ASCII 0x2cc ~x#tqbh~ #8 //  dialogue
    WRITE_ASCII 0x280 ~x#tqbh2~ #32 // DV
    WRITE_ASCIIE 0x248 ~x#tqbh~ #8 //  override script
    ADD_CRE_ITEM ~sw1h43~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ EQUIP
    ADD_CRE_ITEM ~sw1h43~ #0 #0 #0 ~IDENTIFIED~ ~SHIELD~
    ADD_CRE_ITEM ~leat01~ #0 #0 #0 ~IDENTIFIED~ ~ARMOR~

  COPY ~bg1npc/phase2/cre/x#tqbh3.cre~ ~override/x#tqbh3.cre~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 ~Zed~
    SAY NAME2 ~Zed~
    SAY INITIAL_MEETING @285
    SAY BATTLE_CRY1 @285
    SAY BATTLE_CRY2 @285
    SAY BATTLE_CRY3 @285
    SAY BATTLE_CRY4 @285
    SAY BATTLE_CRY5 @285
    SAY DAMAGE @23
    SAY DYING @387
    SAY SELECT_COMMON1 @285
    SAY DIALOGUE_DEFAULT @285
    WRITE_ASCII 0x250 ~x#fight2~ #8 //  class script
    WRITE_ASCII 0x2cc ~x#tqbh~ #8 //  dialogue
    WRITE_ASCII 0x280 ~x#tqbh3~ #32 // DV
    WRITE_ASCIIE 0x248 ~x#tqbh~ #8 //  override script
    ADD_CRE_ITEM ~sw1h01~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ EQUIP
    ADD_CRE_ITEM ~sw1h01~ #0 #0 #0 ~IDENTIFIED~ ~SHIELD~
    ADD_CRE_ITEM ~leat01~ #0 #0 #0 ~IDENTIFIED~ ~ARMOR~

  COPY ~bg1npc/phase2/cre/x#tqbh4.cre~ ~override/x#tqbh4.cre~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 ~Mati~
    SAY NAME2 ~Mati~
    SAY INITIAL_MEETING @455
    SAY BATTLE_CRY1 @455
    SAY BATTLE_CRY2 @455
    SAY BATTLE_CRY3 @455
    SAY BATTLE_CRY4 @455
    SAY BATTLE_CRY5 @455
    SAY DAMAGE @388
    SAY DYING @399
    SAY SELECT_COMMON1 @455
    SAY DIALOGUE_DEFAULT @455
    WRITE_ASCII 0x250 ~x#fight2~ #8 //  class script
    WRITE_ASCII 0x2cc ~x#tqbh~ #8 //  dialogue
    WRITE_ASCII 0x280 ~x#tqbh4~ #32 // DV
    WRITE_ASCIIE 0x248 ~x#tqbh~ #8 //  override script
    ADD_CRE_ITEM ~ax1h01~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ EQUIP
    ADD_CRE_ITEM ~hamm01~ #0 #0 #0 ~IDENTIFIED~ ~SHIELD~
    ADD_CRE_ITEM ~chan01~ #0 #0 #0 ~IDENTIFIED~ ~ARMOR~

  /* scripts */
  EXTEND_BOTTOM ~%TIAX_BCS%.bcs~ ~BG1NPC/Phase2/baf/x#tqtiax.baf~
    EVALUATE_BUFFER
  EXTEND_BOTTOM ~X#BELGIN.bcs~ ~BG1NPC/Phase2/baf/x#tqbelgin.baf~
    EVALUATE_BUFFER
  EXTEND_BOTTOM ~X#KARRIS.bcs~ ~BG1NPC/Phase2/baf/x#tqkarris.baf~
    EVALUATE_BUFFER
  COMPILE ~BG1NPC/Phase2/baf/x#tqbh.baf~
  
  /* area scripts */
  EXTEND_BOTTOM ~%SEBGBStarsL2_BCS%.bcs~ ~BG1NPC/Phase2/baf/x#tqfw0106.baf~
     EVALUATE_BUFFER

  EXTEND_BOTTOM ~%BGDocks_BCS%.bcs~ ~BG1NPC/Phase2/baf/x#tqfw1200.baf~
     EVALUATE_BUFFER

  /* dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/x#tiaxquest.d~

  /* Kagain's Caravan */
  /* Kagain Caravan quest rebuild */
  /* area patching */
  COPY_EXISTING ~%CoastWay_BCS%.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~GlobalLT("KagainCaravan","GLOBAL",2)~ ~False()~
    END
  BUT_ONLY_IF_IT_CHANGES
  EXTEND_BOTTOM ~%CoastWay_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW2800.baf~
     EVALUATE_BUFFER

  /* Overriding old Kagain Quest interaction triggers */
  COPY_EXISTING ~%KAGAIN_BCS%.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~GlobalTimerExpired("Kagain","GLOBAL")~ ~False()~
    END
  BUT_ONLY_IF_IT_CHANGES
  EXTEND_BOTTOM ~%KAGAIN_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#KGQUST.BAF~
     EVALUATE_BUFFER

  /* items */
  COPY ~BG1NPC/phase2/itm/x#silsh.itm~ ~override~
    SAY NAME1 @34
    SAY NAME2 @34
    SAY UNIDENTIFIED_DESC @35
    SAY DESC @35

  /* creatures */

  COPY_EXISTING ~%tutu_scripti%ronelit.cre~ ~override/x#kaband.cre~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~ 
    SAY NAME1 @24
    SAY NAME2 @24
    SAY INITIAL_MEETING @25
    SAY BATTLE_CRY1 @26
    SAY BATTLE_CRY2 @27
    SAY BATTLE_CRY3 @25
    SAY BATTLE_CRY4 @26
    SAY BATTLE_CRY5 @27
    SAY ATTACK1 @25
    SAY ATTACK2 @26
    SAY DAMAGE @28
    SAY DYING @29
    SAY SELECT_COMMON1 @27
    SAY SELECT_COMMON2 @27
    SAY SELECT_COMMON3 @27
    SAY SELECT_COMMON4 @27
    SAY SELECT_COMMON5 @27
    SAY SELECT_COMMON6 @27
    WRITE_SHORT 0x0028 0x6110 // animation ID fighter_female_human
    WRITE_BYTE 0x0237 0x02//  gender: female
    WRITE_ASCII 0x0250 ~~ #8 //  Creature script - Class
    WRITE_ASCII 0x0258 ~~ #8 //  Creature script - Race
    WRITE_ASCII 0x0260 ~~ #8 //  Creature script - General
    WRITE_BYTE 0x270 ~128~ // Allegiance = Neutral
    WRITE_EVALUATED_ASCII 0x0268 ~%tutu_scriptw%TASIGHT~ #8 //  Creature script - Default
    WRITE_BYTE 0x0275 0x02//  gender: female
    ADD_CRE_ITEM ~X#SILSH~ #0 #0 #0 ~IDENTIFIED~ ~INV5~
    ADD_CRE_ITEM ~%tutu_var%misc86~ #0 #0 #0 ~IDENTIFIED~ ~GLOVES~

  COPY_EXISTING  ~%tutu_var%bandit.cre~ ~override/x#bandk1.cre~
                 ~%tutu_var%bandit.cre~ ~override/x#bandk2.cre~
                 ~%tutu_var%bandit.cre~ ~override/x#bandk3.cre~
	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
	LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~ 
    SAY NAME1 @30
    SAY NAME2 @30
    SAY INITIAL_MEETING @31
    SAY BATTLE_CRY1 @31
    SAY BATTLE_CRY2 @31
    SAY BATTLE_CRY3 @31
    SAY BATTLE_CRY4 @31
    SAY BATTLE_CRY5 @31
    SAY DAMAGE @32
    SAY DYING @33
    SAY SELECT_COMMON1 @31
    SAY SELECT_COMMON2 @31
    SAY SELECT_COMMON3 @31
    SAY SELECT_COMMON4 @31
    SAY SELECT_COMMON5 @31
    SAY SELECT_COMMON6 @31
    WRITE_ASCII 0x0258 ~~ #8 //  Creature script - Race
    WRITE_ASCII 0x0260 ~~ #8 //  Creature script - General
    WRITE_EVALUATED_ASCII 0x0268 ~%tutu_scriptw%TARSGT~ #8 //  Creature script - Default
    WRITE_BYTE 0x270 ~128~ // Allegiance = Neutral

  /* Burned corpse */
  COPY ~bg1npc/phase2/cre/x#burn01.cre~ ~override~
  	PATCH_IF GAME_IS ~bgee~ BEGIN
  		SAY NAME1 #17309  // Male body
  		SAY NAME2 #17309  // Male body
  	END ELSE BEGIN	/* Tutu, BGT */
  		SAY NAME1 #20323  // Body
  		SAY NAME2 #20323  // Body
    END		

  /* Adding Brilla's DV */
  COPY_EXISTING ~%tutu_var%brilla.cre~ ~override~
    WRITE_EVALUATED_ASCII 0x2CC ~%SOURCE_RES%~ #8 //  dialog
    WRITE_ASCII 0x280 ~brilla~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#KABAND.BAF~

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#KAQST.D~

  /* Eldoth's Bently Quarrel */
  COPY ~BG1NPC/phase2/itm/x#fai1.itm~ ~override~
    SAY NAME1 @56
    SAY NAME2 @57
    SAY UNIDENTIFIED_DESC @58
    SAY DESC @59

  COPY ~BG1NPC/phase2/itm/x#fai2.itm~ ~override~
    SAY NAME1 @60
    SAY NAME2 @61
    SAY UNIDENTIFIED_DESC @62
    SAY DESC @63

  COPY ~BG1NPC/phase2/itm/x#fai3.itm~ ~override~
    SAY NAME1 @64
    SAY NAME2 @64
    SAY UNIDENTIFIED_DESC @65
    SAY DESC @66

  COPY ~BG1NPC/phase2/itm/x#fai4.itm~ ~override~
    SAY NAME1 @67
    SAY NAME2 @67
    SAY UNIDENTIFIED_DESC @68
    SAY DESC @69

  COPY ~BG1NPC/phase2/itm/X#FAI5.itm~ ~override~
    SAY NAME1 @70
    SAY NAME2 @71
    SAY UNIDENTIFIED_DESC @72
    SAY DESC @73

  /* Eldoth FAI */
  COPY ~BG1NPC/phase2/itm/X#FRIED2.STO~ ~override~
    SAY STORE_NAME @624
    SAY 0xA4 @52
    SAY 0xb8 @53
    SAY 0xcc @54
    SAY 0xe0 @55
	PATCH_IF GAME_IS ~bgee bgt~ BEGIN
		WRITE_ASCII 0x44 ~RFRIED2~ #8   // rumors dialog
    END

  /* Xzar's Quest */

  /* items */
  COPY ~BG1NPC/phase2/itm/X#XZSLIM.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#XZSLIM.itm~ ~override~
    SAY NAME1 @48
    SAY NAME2 @49
    SAY UNIDENTIFIED_DESC @50
    SAY DESC @51

  /* creatures */
  COPY ~BG1NPC/Phase2/cre/x#harl1.cre~ ~override/x#zizi1.cre~
       ~BG1NPC/Phase2/cre/x#harl1.cre~ ~override/x#zizi2.cre~
       ~BG1NPC/Phase2/cre/x#harl1.cre~ ~override/x#zizi3.cre~
       ~BG1NPC/Phase2/cre/x#harl1.cre~ ~override/x#zizi4.cre~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @36
    SAY NAME2 @36
    SAY DAMAGE @37
    SAY DYING @38
    SAY SELECT_COMMON1 @37
    SAY SELECT_COMMON2 @37
    SAY SELECT_COMMON3 @37
    SAY SELECT_COMMON3 @37
    SAY SELECT_COMMON4 @37
    SAY SELECT_COMMON5 @37
    SAY SELECT_COMMON6 @37
    WRITE_EVALUATED_ASCII 0x248 ~%DEST_RES%~ #8 //  Creature script - Override
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32 //  death variable
      PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#zizi1~) BEGIN
        WRITE_ASCII 0x2CC ~ZIZIZI1~ #8 //  dialog
      END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#zizi2~) BEGIN
        WRITE_ASCII 0x2CC ~ZIZIZI2~ #8 //  dialog
      END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#zizi3~) BEGIN
        WRITE_ASCII 0x2CC ~ZIZIZI3~ #8 //  dialog
      END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#zizi4~) BEGIN
        WRITE_ASCII 0x2CC ~ZIZIZI4~ #8 //  dialog
      END

  COPY_EXISTING ~%tutu_var%prost5.cre~ ~override~
                ~%tutu_var%prost6.cre~ ~override~
                ~%tutu_var%prost7.cre~ ~override~
                ~%tutu_var%prost4.cre~ ~override~
                ~%tutu_var%prost8.cre~ ~override~
                ~%tutu_var%prost2.cre~ ~override~
                ~%tutu_var%prost3.cre~ ~override~
    WRITE_ASCII 0x280 ~harlot~ #32 //  death variable


  COPY ~BG1NPC/Phase2/cre/x#jelly.cre~ ~override/x#jelly.cre~
      SAY NAME1 @39
      SAY NAME2 @39
      SAY BATTLE_CRY1 @40
      SAY BATTLE_CRY2 @41
      SAY BATTLE_CRY3 @40
      SAY BATTLE_CRY4 @41
      SAY BATTLE_CRY5 @40
      SAY ATTACK1 @42
      SAY ATTACK2 @43
      SAY DAMAGE @44
      SAY DYING @45
      SAY SELECT_COMMON1 @46
      SAY SELECT_COMMON2 @47
      WRITE_ASCII 0x248 ~X#XZJELL~ #8//  override script
      WRITE_ASCII 0x280 ~xzjelly~ #32//  death variable
	  WRITE_EVALUATED_ASCII 0x0268 ~%tutu_scriptw%TASIGHT~ #8 //  Creature script - Default

  COPY ~BG1NPC/Phase2/cre/x#slime.cre~ ~override/x#slime.cre~
    SAY NAME1 @39
    SAY NAME2 @39
    SAY BATTLE_CRY1 @40
    SAY BATTLE_CRY2 @41
    SAY BATTLE_CRY3 @40
    SAY BATTLE_CRY4 @41
    SAY BATTLE_CRY5 @40
    SAY ATTACK1 @42
    SAY ATTACK2 @43
    SAY DAMAGE @44
    SAY DYING @45
    SAY SELECT_COMMON1 @46
    SAY SELECT_COMMON2 @47
    WRITE_ASCII 0x248 ~X#XZSLIM~ #8//  override script
    WRITE_ASCII 0x280 ~xzslime~ #32//  death variable
	WRITE_EVALUATED_ASCII 0x0268 ~%tutu_scriptw%TASIGHT~ #8 //  Creature script - Default

  /* Kivan's spear */
  COPY ~BG1NPC/phase2/itm/X#KISPEA.itm~ ~override~
    SAY NAME1 @74
    SAY NAME2 @75
    SAY UNIDENTIFIED_DESC @76
    SAY DESC @77
    WRITE_LONG 0x34 0

  /* Great Shield - White Oak */
  COPY ~BG1NPC/phase2/itm/X#FASH01.itm~ ~override~
    SAY NAME1 @78
    SAY NAME2 @78
    SAY UNIDENTIFIED_DESC @79
    SAY DESC @80

  /* DVs */
  COPY_EXISTING  ~%tutu_var%krumm.cre~ ~override~
    WRITE_ASCII 0x248 ~X#KRUMM~ #8 //  override script
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING  ~%tutu_var%ankheg.cre~  ~override~
                 ~%tutu_var%ankhegg.cre~ ~override~
                 ~%tutu_var%ankhegq.cre~ ~override~
    WRITE_ASCII 0x280 ~ankheg~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING  ~%tutu_var%ender.cre~ ~override~
    WRITE_ASCII 0x280 ~ender~ #8 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_var%serva2.cre~ ~override/x#jessup.cre~
    SAY NAME1 @81
    SAY NAME2 @81
    WRITE_EVALUATED_ASCII 0x248 ~%DEST_RES%~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x2CC ~%DEST_RES%~ #8 //  dialog
    WRITE_ASCII 0x280 ~jessup~ #32 //  death variable

  COPY_EXISTING ~%tutu_var%nobw2.cre~ ~override/x#dora.cre~
    SAY NAME1 @82
    SAY NAME2 @82
    WRITE_ASCII 0x248 ~X#DORAA~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x2CC ~%tutu_var%DORAA~ #8 //  dialog
    WRITE_ASCII 0x280 ~doraa~ #32 //  death variable

  /* Xan's Encounter 1  */

    /* items */
  COPY ~BG1NPC/phase2/itm/X#CTURN.BAM~ ~override~
       ~BG1NPC/phase2/itm/X#ITURN.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/P#BAG01.itm~ ~override~
    SAY NAME1 @163
    SAY NAME2 @163
    WRITE_ASCII 0x3a ~X#ITURN~ #8
    WRITE_ASCII 0x44 ~GSACK01~ #8
    WRITE_ASCII 0x58 ~X#CTURN~ #8
    SAY UNIDENTIFIED_DESC @164
    SAY DESC @165

  COPY ~BG1NPC/phase2/itm/P#BAG02.itm~ ~override~
    SAY NAME1 @166
    SAY NAME2 @166
    WRITE_ASCII 0x44 ~GSACK01~ #8
    SAY UNIDENTIFIED_DESC @167
    SAY DESC @168

  COPY_EXISTING ~%tutu_var%STO4901.sto~ ~override~
    ADD_STORE_ITEM ~P#BAG02~  AFTER  ~SHLD16~  #0 #0 #0 ~IDENTIFIED~ #5
    ADD_STORE_ITEM ~P#BAG01~  AFTER  ~SHLD16~  #0 #0 #0 ~IDENTIFIED~ #5

  /* creatures */
  COPY ~BG1NPC/Phase2/cre/x#david.cre~ ~override~
    SAY NAME1 @83
    SAY NAME2 @83
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    PATCH_IF GAME_IS ~bgee~ BEGIN /* Jan Jansen soundset not present in BGEE, use default gnome instead */
    	SAY INITIAL_MEETING @557
    	SAY DAMAGE @559
    	SAY DYING @560
    	SAY SELECT_COMMON1 @557
    	SAY SELECT_COMMON2 @558
    	SAY SELECT_COMMON3 @561
    END ELSE BEGIN /* Tutu and BGT */
	    SAY MORALE @84
    	SAY HAPPY @85
    	SAY UNHAPPY_ANNOYED @86
    	SAY UNHAPPY_SERIOUS @87
    	SAY UNHAPPY_BREAKING @88
    	SAY LEADER @89
    	SAY TIRED @90
    	SAY BORED @91
    	SAY BATTLE_CRY1 @92
    	SAY BATTLE_CRY2 @93
    	SAY BATTLE_CRY3 @94
    	SAY DAMAGE @95
    	SAY DYING @96
    	SAY HURT @97
    	SAY AREA_FOREST @98
    	SAY AREA_CITY @99
    	SAY AREA_DUNGEON @100
    	SAY AREA_DAY @101
    	SAY AREA_NIGHT @102
    	SAY SELECT_COMMON1 @103
    	SAY SELECT_COMMON3 @104
    	SAY SELECT_COMMON4 @105
    	SAY SELECT_COMMON5 @106
    	SAY SELECT_COMMON6 @107
    	SAY SELECT_ACTION1 @108
    	SAY SELECT_ACTION2 @109
    	SAY SELECT_ACTION3 @110
    	SAY SELECT_ACTION4 @111
    	SAY SELECT_ACTION5 @112
    	SAY SELECT_ACTION6 @113
    	SAY SELECT_ACTION7 @114
    	SAY SELECT_RARE1 @115
    	SAY SELECT_RARE2 @116
    	SAY CRITICAL_HIT @117
    	SAY CRITICAL_MISS @118
    	SAY TARGET_IMMUNE @119
    	SAY INVENTORY_FULL @120
    	SAY PICKED_POCKET @121
    	SAY HIDDEN_IN_SHADOWS @122
    	SAY SPELL_DISRUPTED @123
    	SAY SET_A_TRAP @124
    END
    WRITE_LONG BIO (BNOT 0x0)
    WRITE_EVALUATED_ASCII 0x248 ~%SOURCE_RES%~ #8 //  override script
    WRITE_ASCII SCRIPT_CLASS ~x#gpsht~ #8 // class script
    WRITE_ASCII SCRIPT_DEFAULT ~x#davidx~ #8 // default script
    WRITE_ASCII 0x34 ~~ #8 // small portrait
    WRITE_ASCII 0x2CC ~X#DAVI~ #8 //  dialog
    WRITE_EVALUATED_ASCII 0x280 ~%SOURCE_RES%~ #32 //  death variable

  COPY ~BG1NPC/Phase2/cre/x#cru11.cre~ ~override~
    SAY NAME1 @125
    SAY NAME2 @125
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    PATCH_IF GAME_IS ~bgee~ BEGIN /* BG2 sounds not in BGEE */
    	SAY INITIAL_MEETING @702 // x#ogref3
    	SAY BATTLE_CRY1 @700 // x#ogref1
    	SAY BATTLE_CRY2 @702 // x#ogref3
    	SAY DAMAGE @704 // x#ogref5
    	SAY DYING @705 // x#ogref6
    	SAY SELECT_COMMON1 @701 // x#ogref2
    	SAY SELECT_COMMON2 @703 // x#ogref4
    END ELSE BEGIN /* Tutu, BGT */    	
	    SAY INITIAL_MEETING @126
    	SAY UNHAPPY_BREAKING @127
   		SAY BATTLE_CRY1 @128
    	SAY BATTLE_CRY2 @129
    	SAY DAMAGE @130
    	SAY DYING @131
    	SAY SELECT_COMMON1 @126
    	SAY SELECT_COMMON2 @132
    	SAY SELECT_COMMON3 @133
    	SAY SELECT_COMMON4 @134
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~ 

  COPY ~BG1NPC/Phase2/cre/x#chop.cre~ ~override~
    SAY NAME1 @135
    SAY NAME2 @135
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    PATCH_IF GAME_IS ~bgee~ BEGIN /* BG2 sounds not in BGEE */
    	SAY INITIAL_MEETING @702 // x#ogref3
    	SAY BATTLE_CRY1 @700 // x#ogref1
    	SAY BATTLE_CRY2 @702 // x#ogref3
    	SAY DAMAGE @704 // x#ogref5
    	SAY DYING @705 // x#ogref6
    	SAY SELECT_COMMON1 @701 // x#ogref2
    	SAY SELECT_COMMON2 @703 // x#ogref4
    END ELSE BEGIN /* Tutu, BGT */    	
	    SAY INITIAL_MEETING @126
    	SAY UNHAPPY_BREAKING @127
   		SAY BATTLE_CRY1 @128
    	SAY BATTLE_CRY2 @129
    	SAY DAMAGE @130
    	SAY DYING @131
    	SAY SELECT_COMMON1 @126
    	SAY SELECT_COMMON2 @132
    	SAY SELECT_COMMON3 @133
    	SAY SELECT_COMMON4 @134
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase2/cre/x#assi01.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi02.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi03.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi04.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi05.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi06.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi07.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi08.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi09.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi10.cre~ ~override~
       ~BG1NPC/Phase2/cre/x#assi11.cre~ ~override~
    SAY NAME1 @136
    SAY NAME2 @136
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    PATCH_IF GAME_IS ~bgee~ BEGIN /* BG2 sounds not in BGEE */
    /* x#assi01-11 are illusions created by x#david that don't speak */
    	WRITE_LONG DAMAGE BNOT (0x0)
    	WRITE_LONG DYING BNOT (0x0)
    END ELSE BEGIN /* Tutu, BGT */    	
    	SAY LEADER @137
    	SAY TIRED @138
    	SAY BORED @139
    	SAY BATTLE_CRY1 @140
    	SAY BATTLE_CRY2 @141
    	SAY BATTLE_CRY3 @142
    	SAY DAMAGE @143
    	SAY DYING @144
    	SAY HURT @145
    	SAY SELECT_COMMON1 @146
    	SAY SELECT_COMMON2 @147
    	SAY SELECT_COMMON3 @148
    	SAY SELECT_ACTION1 @149
    	SAY SELECT_ACTION2 @150
    	SAY SELECT_ACTION3 @151
    	SAY SELECT_RARE1 @152
    	SAY SELECT_RARE2 @153
    	SAY CRITICAL_HIT @154
    	SAY CRITICAL_MISS @155
    	SAY TARGET_IMMUNE @156
    	SAY INVENTORY_FULL @157
    	SAY PICKED_POCKET @158
    	SAY HIDDEN_IN_SHADOWS @159
    	SAY SPELL_DISRUPTED @160
    	SAY SET_A_TRAP @161
	END
    SAY BIO @162
    WRITE_ASCII 0x2CC ~X#ASSIST~ #8 //  dialog
    WRITE_ASCII 0x3c ~~ #8 // large portrait
    WRITE_ASCII 0x34 ~~ #8 // small portrait
    WRITE_EVALUATED_ASCII 0x280 ~%SOURCE_RES%~ #32 //  death variable

  /* dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#DAVI.D~
                          ~BG1NPC/Phase2/dlg/X#CRU11.D~
                          ~BG1NPC/Phase2/dlg/X#CHOP.D~
                          ~BG1NPC/Phase2/dlg/X#XANQ.D~
                          ~BG1NPC/Phase2/dlg/X#ASSIST.D~
                          ~BG1NPC/Phase2/dlg/X#NEWMERCH2.D~

  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#DAV01.BAF~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#DAV01.TRA~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#DAVID.BAF~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#DAVID.TRA~
  COMPILE ~bg1npc/phase2/baf/x#davidx.baf~  /* Combat script for David Jansen */

  ACTION_IF GAME_IS ~bgee~ THEN BEGIN  /* Add sound files for x#cru11 and x#chop */
	COPY ~bg1npc/bgee/wav/x#ogref1.wav~ ~override~
	COPY ~bg1npc/bgee/wav/x#ogref2.wav~ ~override~
	COPY ~bg1npc/bgee/wav/x#ogref3.wav~ ~override~
	COPY ~bg1npc/bgee/wav/x#ogref4.wav~ ~override~
	COPY ~bg1npc/bgee/wav/x#ogref5.wav~ ~override~
	COPY ~bg1npc/bgee/wav/x#ogref6.wav~ ~override~
  END
  
  /* patching Xan's script */
  EXTEND_TOP  ~%XAN_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#XACUT.BAF~
      EVALUATE_BUFFER

  /* Xan's Encounter 1  */
  EXTEND_BOTTOM ~%NNashkelRoad_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#FW4300.BAF~
      EVALUATE_BUFFER

  /* Xan Centeol */
  COPY_EXISTING ~%CloakwoodNest%.are~ ~override~
    WRITE_LONG 0x4a 100

  /* D/BAF Centeol */
  EXTEND_BOTTOM ~%CloakwoodNest_BCS%.bcs~  ~BG1NPC/Phase2/baf/P#FW2100.BAF~
      EVALUATE_BUFFER

  /* D/BAF Centeol */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/P#CENTEO.d~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/P#CECUT.BAF~
  EXTEND_TOP  ~%tutu_var%CENTEOL.bcs~ ~BG1NPC/Phase2/baf/P#CENTEO.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_var%XAN.bcs~  ~BG1NPC/Phase2/baf/P#XANCE.BAF~
    EVALUATE_BUFFER

  /* Xan's Quest */

  /* creatures */
  COPY ~BG1NPC/Phase2/cre/x#skodd.cre~ ~override~
	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @633
    SAY NAME2 @633
    SAY INITIAL_MEETING @474
    SAY DAMAGE @473
    SAY DYING @472   
    SAY SELECT_COMMON1 @474
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
    WRITE_ASCII SCRIPT_GENERAL ~x#xqmerx~ #8
    
  COPY ~BG1NPC/Phase2/cre/x#mazuri.cre~ ~override~
	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @634
    SAY NAME2 @634
    SAY INITIAL_MEETING @177
    SAY DAMAGE @562
    SAY DYING @563 
    SAY SELECT_COMMON1 @177
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
    WRITE_ASCII SCRIPT_GENERAL ~x#xqmerx~ #8

  COPY ~BG1NPC/Phase2/cre/x#gael.cre~ ~override~
	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @635
    SAY NAME2 @635
    SAY INITIAL_MEETING @177
    SAY DAMAGE @562
    SAY DYING @563 
    SAY SELECT_COMMON1 @177
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
    WRITE_ASCII SCRIPT_GENERAL ~x#xqmerx~ #8

  COPY ~BG1NPC/Phase2/cre/x#siene.cre~ ~override~
	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @636
    SAY NAME2 @636
    SAY DAMAGE #11075 // [ELF FEMALE 5]
    SAY DYING #11076 // [ELF FEMALE 6]
    SAY SELECT_COMMON1 @720
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
    WRITE_ASCIIE SCRIPT_GENERAL ~%tutu_var%wtrunsgt~ #8

  COPY ~BG1NPC/Phase2/cre/x#minuw.cre~ ~override~
	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @637
    SAY NAME2 @637
    SAY DAMAGE #11075 // [ELF FEMALE 5]
    SAY DYING #11076 // [ELF FEMALE 6]
    SAY SELECT_COMMON1 @720
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
    WRITE_ASCIIE SCRIPT_GENERAL ~%tutu_var%wtrunsgt~ #8
	
  COPY ~BG1NPC/Phase2/cre/x#diala.cre~ ~override~
  	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @638
    SAY NAME2 @638
    SAY DAMAGE #11075 // [ELF FEMALE 5]
    SAY DYING #11076 // [ELF FEMALE 6]
    SAY SELECT_COMMON1 @720
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
    WRITE_ASCIIE SCRIPT_GENERAL ~%tutu_var%wtrunsgt~ #8

  COPY ~BG1NPC/Phase2/cre/x#wdoe.cre~ ~override~
  	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @639
    SAY NAME2 @639
    SAY INITIAL_MEETING @706 // [MOOSE01]
    SAY SELECT_COMMON1 @706 // [MOOSE01]
    SAY DAMAGE @707 // [MOOSE06]
    SAY DYING @708 // [MOOSE07]
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~


  COPY ~BG1NPC/Phase2/cre/x#xqmer1.cre~ ~override~
  	   ~BG1NPC/Phase2/cre/x#xqmer2.cre~ ~override~
  	   ~BG1NPC/Phase2/cre/x#xqmer3.cre~ ~override~
  	   ~BG1NPC/Phase2/cre/x#xqmer4.cre~ ~override~
  	   ~BG1NPC/Phase2/cre/x#xqmer5.cre~ ~override~
  	   ~BG1NPC/Phase2/cre/x#xqmer6.cre~ ~override~
	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY NAME1 @640
    SAY NAME2 @640
    SAY DAMAGE @562
    SAY DYING @563
    WRITE_ASCII SCRIPT_GENERAL ~x#xqmerx~ #8
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  /* scripts */
  EXTEND_BOTTOM ~%SpiderWood_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#FW3000XQ.BAF~
      EVALUATE_BUFFER
  EXTEND_BOTTOM ~%MutaminsGarden_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#FW3500XQ.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP ~%XAN_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#XQXAN.BAF~
      EVALUATE_BUFFER

  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#XQCUT.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#SKODD.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#XQXAN.D~
  COMPILE ~BG1NPC/phase2/baf/x#xqmerx.baf~
     
 /* Garrick's Quest */

  /* items */
  COPY ~BG1NPC/phase2/itm/X#CGBK.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#CGCN.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#ICBABN.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#ICRFN.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#IGBK.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#IGCN.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#XAQUGN.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#CGBK.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#BLITM.itm~ ~override~
    SAY NAME1 @169

  COPY ~BG1NPC/phase2/itm/X#GARBK.itm~ ~override~
    SAY NAME1 @170
    SAY NAME2 @170
	SAY UNIDENTIFIED_DESC @171
    SAY DESC @171

  COPY ~BG1NPC/phase2/itm/X#GARCH.itm~ ~override~
    SAY NAME1 @172
    SAY NAME2 @172
    SAY UNIDENTIFIED_DESC @173
    SAY DESC @174

  COPY ~BG1NPC/phase2/itm/X#GARCH2.itm~ ~override~
    SAY NAME1 @172
    SAY NAME2 @172
    SAY UNIDENTIFIED_DESC @173
    SAY DESC @175

  /* creatures */
  COPY ~BG1NPC/phase2/cre/x#garar.cre~ ~override~
    SAY NAME1 @176
    SAY NAME2 @176
    SAY INITIAL_MEETING @177
    SAY DAMAGE @178
    SAY DYING @179
    SAY SELECT_COMMON1 @177
    WRITE_EVALUATED_ASCII 0x248 ~%SOURCE_RES%~ #8  //  override script
    WRITE_ASCII 0x280 ~archibald~ #32 //  death variable

  COPY ~BG1NPC/phase2/cre/x#garwyl.cre~ ~override~
    SAY NAME1 @180
    SAY NAME2 @180
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @709 // [GHAST01]
    SAY DAMAGE @710 // [GHAST05]
    SAY DYING @711 // [GHAST06]
    SAY SELECT_COMMON1 @709 // [GHAST01]
    SAY EXISTANCE1 @709 // [GHAST01]

  COPY_EXISTING ~%tutu_var%zombie.cre~  ~override~
                ~%tutu_var%zombieb.cre~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
      WRITE_BYTE 0x272 0x94 // Race (zombie, was skeleton)
    END
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_var%zombie.cre~ ~override/x#garz01.cre~
                ~%tutu_var%zombie.cre~ ~override/x#garz02.cre~
                ~%tutu_var%zombie.cre~ ~override/x#garz03.cre~
                ~%tutu_var%zombie.cre~ ~override/x#garz04.cre~
    SAY NAME1 @203
    SAY NAME2 @203
    SAY BATTLE_CRY1 @204
    SAY BATTLE_CRY2 @204
    SAY BATTLE_CRY3 @204
    SAY BATTLE_CRY4 @204
    SAY BATTLE_CRY5 @204
    SAY ATTACK1 @205
    SAY ATTACK2 @206
    SAY DAMAGE @207
    SAY DYING @208
    SAY SELECT_COMMON1 @209
    SAY SELECT_COMMON2 @210
    WRITE_BYTE 0x270 0x80 // Reaction (neutral, was enemy)
    WRITE_EVALUATED_ASCII 0x2cc ~%DEST_RES%~ #8 // Dialog
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32 // Death variable

  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#GARAR.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#GARWYL.BAF~

  /* dialog */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#GARAR.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#GARWYL.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#HALBAZ.D~

  /* Coran's Quest */
  /* items */
  COPY ~BG1NPC/phase2/itm/X#CBOOK.itm~ ~override~
    SAY NAME1 @211
    SAY NAME2 @211
    SAY UNIDENTIFIED_DESC @212
    SAY DESC @212

  COPY ~BG1NPC/phase2/itm/X#CMILK.itm~ ~override~
    SAY NAME1 @213
    SAY NAME2 @213
    SAY UNIDENTIFIED_DESC @214
    SAY DESC @214

  COPY ~BG1NPC/phase2/itm/X#CBABY.itm~ ~override~
    SAY NAME1 @215
    SAY NAME2 @216
    SAY UNIDENTIFIED_DESC @217
    SAY DESC @217

  COPY ~BG1NPC/phase2/itm/X#COBAG.itm~ ~override~
    SAY NAME1 @218
    SAY NAME2 @219
    SAY UNIDENTIFIED_DESC @220
    SAY DESC @220

  COPY ~BG1NPC/phase2/itm/X#COBAG.STO~ ~override~

  /* pro5's Coran Dragon Skeleton Fix */
  ACTION_IF GAME_IS ~tutu_totsc bgt bgee~ THEN BEGIN
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/P5ARD013.BAF~
    COPY_EXISTING ~%DurlagsTower_D3%.ARE~ ~override~
         LAUNCH_PATCH_MACRO ~DRAGON_TRIGGER~
  END

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#BRI.D~
  /*scipts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#GOBRI.BAF~
  /* appended scripts */
  EXTEND_BOTTOM ~%tutu_var%CORAN.bcs~ ~BG1NPC/Phase2/baf/X#RUNCOR.BAF~
      EVALUATE_BUFFER

  /* appended scripts */
  EXTEND_BOTTOM ~%NEBG_SSL1_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW0103.baf~
      EVALUATE_BUFFER

  /* override script to Brielbara */
  COPY_EXISTING ~%tutu_var%brielb.cre~ ~override~
    WRITE_ASCII 0x248 ~X#GOBRI~ #8 // override script
  BUT_ONLY_IF_IT_CHANGES

  /* Coran Succubus Quest */

  /* items */
  COPY ~BG1NPC/phase2/itm/X#CDYEI.BAM~ ~override~
		~BG1NPC/phase2/itm/X#COAMUL.BAM~ ~override~
		~BG1NPC/phase2/itm/X#CORINC.BAM~ ~override~
		~BG1NPC/phase2/itm/X#CORINI.BAM~ ~override~	   
		~BG1NPC/phase2/itm/X#COFRRO.BAM~ ~override~
		~BG1NPC/phase2/itm/X#COWIRO.BAM~ ~override~
		   
  COPY ~BG1NPC/phase2/itm/X#COAMUL.itm~  ~override~
    SAY NAME1 @221
    SAY NAME2 @222
    SAY UNIDENTIFIED_DESC @223
    SAY IDENTIFIED_DESC @224
    WRITE_ASCII 0x3a ~X#COAMUL~ #8 // BAM
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x44 ~GAMUL02~ #8
        WRITE_ASCII 0x58 ~CAMUL01~ #8
      END

  COPY ~BG1NPC/phase2/itm/X#SUCRIN.itm~  ~override~
    SAY NAME1 @225
    SAY NAME2 @226
    SAY UNIDENTIFIED_DESC @12
    SAY IDENTIFIED_DESC @227
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x3a ~IRING17~ #8
        WRITE_ASCII 0x58 ~CRING11~ #8
      END

  COPY ~BG1NPC/phase2/itm/X#COWIRO.itm~ ~override~
    SAY NAME1 @228
    SAY NAME2 @228
    WRITE_LONG 0x34 1
    SAY UNIDENTIFIED_DESC @229
    SAY DESC @229
	WRITE_ASCII 0x76 ~X#COWIRO~ #8   // icon
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x44 ~GSACK01~ #8
        WRITE_ASCII 0x58 ~CMISC1I~ #8
      END

  COPY ~BG1NPC/phase2/itm/X#COFRRO.itm~ ~override~
    SAY NAME1 @230
    SAY NAME2 @230
    WRITE_LONG 0x34 5
    SAY UNIDENTIFIED_DESC @231
    SAY DESC @232
	WRITE_ASCII 0x76 ~X#COFRRO~ #8   // icon
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x44 ~GSACK01~ #8
        WRITE_ASCII 0x58 ~CMISC1I~ #8
      END

  COPY ~BG1NPC/phase2/itm/X#CODYE1.itm~ ~override~
    SAY NAME1 @233
    SAY NAME2 @233
    SAY UNIDENTIFIED_DESC @234
    SAY DESC @234

  COPY ~BG1NPC/phase2/itm/X#CODYE2.itm~ ~override~
    SAY NAME1 @235
    SAY NAME2 @235
    SAY UNIDENTIFIED_DESC @236
    SAY DESC @236


  /* creatures */
  /* Amelia */
  COPY ~BG1NPC/Phase2/cre/CAMW3G1.BAM~ ~override~
  COPY ~BG1NPC/Phase2/cre/x#amelia.cre~ ~override~
    SAY NAME1 @237
    SAY NAME2 @237
    SAY BATTLE_CRY1 @738 // [VAMPF02]
    SAY DAMAGE @742 // [VAMPF06]
    SAY DYING @743 // [VAMPF07]
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
    ADD_CRE_ITEM ~X#SUCRIN~ #0 #0 #0 ~IDENTIFIED&UNSTEALABLE~ ~LRING~
    ADD_CRE_ITEM ~%tutu_var%CLCK12~ #0 #0 #0 ~IDENTIFIED~ ~CLOAK~

  /* Natan */
  COPY ~BG1NPC/Phase2/cre/x#natan.cre~ ~override~
      LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
      LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
      SAY NAME1 @238
      SAY NAME2 @238
      SAY DAMAGE @712 // [VOIC1L]
      SAY DYING @713 // [VOIC1M]
      WRITE_ASCII 0x280 ~natan~ #32 //  death variable
      ADD_CRE_ITEM ~%tutu_var%POTN42~ #0 #0 #0 ~IDENTIFIED~ ~INV7~
      ADD_CRE_ITEM ~%tutu_var%POTN36~ #0 #0 #0 ~IDENTIFIED~ ~INV8~
      ADD_CRE_ITEM ~%tutu_var%POTN37~ #0 #0 #0 ~IDENTIFIED~ ~INV9~
      ADD_CRE_ITEM ~%tutu_var%POTN07~ #0 #0 #0 ~IDENTIFIED~ ~INV6~
      ADD_CRE_ITEM ~X#CODYE1~ #0 #0 #0 ~IDENTIFIED&UNSTEALABLE~ ~INV1~
      WRITE_ASCII 0x258 ~%tutu_var%thief4~ #8 // Race script
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x268 ~WTARSGT~ #8
        WRITE_ASCII 0x250 ~INITDLG~ #8
      END

  /* Rashel */
  COPY ~BG1NPC/Phase2/cre/x#rashel.cre~ ~override~
    SAY NAME1 @239
    SAY NAME2 @239
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* GPRIF soundset not present in BGEE, use other general female sounds */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY INITIAL_MEETING #11117 // [FEMALE GREETING 10] Salutations.
    	SAY BATTLE_CRY1 #11123 // [FEMALE THREAT 1] It may be a touch unladylike, but I'm gonna slit your throat, I am!
    	SAY DAMAGE #12487 // [ABELA 3]
		SAY DYING #12488 // [ABELA 4]
     	SAY SELECT_COMMON1 #11120 // [FEMALE GREETING 13] How are you?
     	SAY SELECT_COMMON2 #11121 // [FEMALE GREETING 14] What's your tale?
    END ELSE BEGIN /* Tutu, BGT */
    	SAY INITIAL_MEETING @240
    	SAY UNHAPPY_BREAKING @241
    	SAY BATTLE_CRY1 @242
    	SAY DAMAGE @243
    	SAY DYING @244
    	SAY SELECT_COMMON1 @245
    	SAY SELECT_COMMON2 @240
    	SAY SELECT_COMMON3 @246
    	SAY SELECT_COMMON4 @247
    	SAY INTERACTION1 @248
    	SAY INTERACTION2 @248
    	SAY INTERACTION3 @248
    	SAY INTERACTION4 @248
    	SAY INTERACTION5 @248
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  /*area scripts */
  EXTEND_BOTTOM ~%FirewineBridge_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#CQ4500.BAF~
      EVALUATE_BUFFER
  EXTEND_BOTTOM ~%Temple_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW3400.BAF~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%FirewineRuins_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW5201.BAF~
      EVALUATE_BUFFER

  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#AMELIA.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#RASHEL.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#NATAN.BAF~

  /* dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#COSQU.D~

  /* scripts */
  EXTEND_TOP  ~%tutu_var%CORAN.bcs~ ~BG1NPC/Phase2/baf/X#COSQU.BAF~
    EVALUATE_BUFFER

  /* Kivan's Quest */

  /* items */
  COPY ~BG1NPC/phase2/itm/P#BOW.itm~ ~override~
    SAY NAME1 @249
    SAY NAME2 @249
    SAY DESC @250
    
  /* BGEE: Add Kivan's bow to item_use.2da */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
  	APPEND ~item_use.2da~ ~P#BOW KIVAN 9382 2~ 
  	  UNLESS ~P#BOW~  	
  	COPY_EXISTING ~item_use.2da~ ~override~
	  PRETTY_PRINT_2DA
  END

  /* creatures */
  COPY ~BG1NPC/Phase2/cre/p#imanel.cre~ ~override~
    SAY NAME1 @251
    SAY NAME2 @251
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* BG2 soundset not present in BGEE, use SIRINE sounds instead */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY INITIAL_MEETING #5176	// [SIRINE 01] Fools to cross my path.
    	SAY BATTLE_CRY1 #6018		// [SIRINE 03]
    	SAY DAMAGE #6023			// [SIRINE 08]
	    SAY DYING #6024				// [SIRINE 09]
    	SAY SELECT_COMMON1 #5176	// [SIRINE 01] Fools to cross my path.
    	SAY SELECT_COMMON2 #6022	// [SIRINE 06]
    	SAY SELECT_COMMON2 #5178	// [SIRINE 07] Think as you act, fool.
	END ELSE BEGIN /* Tutu, BGT */
    	SAY INITIAL_MEETING @141
    	SAY LEADER @137
    	SAY TIRED @138
    	SAY BORED @139
    	SAY BATTLE_CRY1 @142
    	SAY BATTLE_CRY2 @141
    	SAY BATTLE_CRY3 @142
    	SAY ATTACK1 @142
    	SAY DAMAGE @143
    	SAY DYING @144
    	SAY HURT @145
    	SAY SELECT_COMMON1 @146
    	SAY SELECT_COMMON2 @147
    	SAY SELECT_COMMON3 @148
    	SAY SELECT_ACTION1 @149
    	SAY SELECT_ACTION2 @150
    	SAY SELECT_ACTION3 @151
    	SAY SELECT_RARE1 @152
    	SAY SELECT_RARE2 @153
    	SAY CRITICAL_HIT @154
    	SAY CRITICAL_MISS @155
    	SAY TARGET_IMMUNE @156
    	SAY INVENTORY_FULL @157
    	SAY PICKED_POCKET @158
    	SAY HIDDEN_IN_SHADOWS @159
    	SAY SPELL_DISRUPTED @160
    	SAY SET_A_TRAP @161
    END
    SAY BIO @162
    WRITE_ASCII 0x248 ~P#IMANL2~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x2CC ~%SOURCE_RES%~ #8 //  dialog
    WRITE_EVALUATED_ASCII 0x280 ~%SOURCE_RES%~ #32 //  death variable

  COPY ~BG1NPC/Phase2/cre/p#wolf01.cre~ ~override~
       ~BG1NPC/Phase2/cre/p#wolf02.cre~ ~override~
       ~BG1NPC/Phase2/cre/p#wolf03.cre~ ~override~
       ~BG1NPC/Phase2/cre/p#wolf04.cre~ ~override~
       ~BG1NPC/Phase2/cre/p#wolf05.cre~ ~override~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY BATTLE_CRY1 @253
    SAY BATTLE_CRY2 @253
    SAY BATTLE_CRY3 @253
    SAY BATTLE_CRY4 @253
    SAY BATTLE_CRY5 @253
    SAY ATTACK1 @254
    SAY ATTACK2 @255
    SAY DAMAGE @256
    SAY DYING @257
    SAY SELECT_COMMON1 @258
    SAY SELECT_COMMON2 @259
    WRITE_ASCII 0x248 ~P#WOLFA~ #8 //  override script
    WRITE_ASCII 0x2CC ~P#WOLF~ #8 //  dialog
    WRITE_EVALUATED_ASCII 0x280 ~%SOURCE_RES%~ #32 //  death variable
      PATCH_IF (~%SOURCE_RES%~ STRING_EQUAL ~P#WOLF01~) BEGIN
        SAY NAME1 @252
        SAY NAME2 @252
      END ELSE PATCH_IF (~%SOURCE_RES%~ STRING_EQUAL ~P#WOLF02~) BEGIN
        SAY NAME1 @260
        SAY NAME2 @260
      END ELSE PATCH_IF (~%SOURCE_RES%~ STRING_EQUAL ~P#WOLF03~) BEGIN
        SAY NAME1 @261
        SAY NAME2 @261
      END ELSE PATCH_IF (~%SOURCE_RES%~ STRING_EQUAL ~P#WOLF04~) BEGIN
        SAY NAME1 @262
        SAY NAME2 @262
      END ELSE PATCH_IF (~%SOURCE_RES%~ STRING_EQUAL ~P#WOLF05~) BEGIN
        SAY NAME1 @263
        SAY NAME2 @263
      END

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/P#IMANEL.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/P#WOLF.D~

  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/P#IMANL2.BAF~// Compile script
    USING ~BG1NPC/TRA/%LANGUAGE%/P#IMANL2.TRA~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/P#WOLFA.BAF~// Compile script

  /* area script extension */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
  /* BGEE needs different location for Imanel Silversword, as Simmeon from Dorn's quest spawns in Imanel's original BG1NPC location. */
    EXTEND_BOTTOM ~%WyrmsCross_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#AR0900.BAF~
      EVALUATE_BUFFER
  END ELSE BEGIN
  /* For TuTu and BGT */ 
    EXTEND_BOTTOM ~%WyrmsCross_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW0900.BAF~
      EVALUATE_BUFFER
  END

  /* Kivan and Sea Elf interlude */
  /* creatures */

  /* Jozzi Seasnake */
  COPY ~BG1NPC/Phase2/cre/x#seasn.cre~ ~override~
    SAY NAME1 @264
    SAY NAME2 @265
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
	SAY INITIAL_MEETING @714 // [NEREID 01]
    SAY BATTLE_CRY1 @716 // [NEREID 03]
    SAY DAMAGE @718 // [NEREID 08]
    SAY DYING @719 // [NEREID 09]
    SAY SELECT_COMMON1 @714 // [NEREID 01]
    SAY SELECT_COMMON2 @715 // [NEREID 02]
    SAY SELECT_COMMON3 @717 // [NEREID 04]
    WRITE_ASCII 0x248 ~X#IHTIA~ #8 //  override script
    WRITE_ASCII SCRIPT_CLASS ~x#gpsht~ #8 // class script
    WRITE_ASCII 0x2CC ~X#IHTIA~ #8 //  dialog
    WRITE_ASCII 0x280 ~seasnake~ #32 //  death variable
    ADD_CRE_ITEM ~SW2H01~ #0 #0 #0 ~IDENTIFIED~ ~WEAPON1~ EQUIP

  /* Keth'sim Dwin'anea */
  COPY ~BG1NPC/Phase2/cre/x#keth.cre~ ~override~
    SAY NAME1 @272
    SAY NAME2 @273
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* ELSOL1 soundset not present in BGEE, use ELFFF soundset instead */
    PATCH_IF GAME_IS ~bgee~ BEGIN
	    SAY INITIAL_MEETING #4941	// [ELF 1] The Fair Folk rarely have time for small talk.
    	SAY BATTLE_CRY1 #4943		// [ELF 3] Soon we shall all be together upon Evermeet.
    	SAY DAMAGE #12586			// [ELF 5]
    	SAY DYING #12587			// [ELF 6]
    	SAY SELECT_COMMON1 #4941	// [ELF 1]
    	SAY SELECT_COMMON2 #4942	// [ELF 2] Troubled times are upon us.
    END ELSE BEGIN /* Tutu and BGT */
     	SAY INITIAL_MEETING @266
    	SAY BATTLE_CRY1 @267
	    SAY DAMAGE @268
    	SAY DYING @269
    	SAY SELECT_COMMON1 @266
    	SAY SELECT_COMMON2 @266
    	SAY SELECT_COMMON3 @270
    	SAY SELECT_COMMON4 @271
    END
	WRITE_ASCII SCRIPT_CLASS ~x#gpsht~ #8 // class script
	LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  /* Sahuagin */
  COPY ~BG1NPC/Phase2/cre/x#saha01.cre~ ~override~
    SAY NAME1 @720  /* Sahuagin Chieftain */
    SAY NAME2 @720  /* Sahuagin Chieftain */
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
	SAY INITIAL_MEETING @722 // [SAHAU01]
    SAY BATTLE_CRY1 @723 // [SAHAU02]
    SAY DAMAGE @727 // [SAHAU06]
    SAY DYING @728 // [SAHAU07]
    SAY SELECT_COMMON1 @724 // [SAHAU03]
    SAY SELECT_COMMON2 @725 // [SAHAU04]
    SAY SELECT_COMMON3 @726 // [SAHAU05]
    SAY SELECT_COMMON4 @722 // [SAHAU01]
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
      
  COPY ~BG1NPC/Phase2/cre/x#saha02.cre~ ~override~
    SAY NAME1 @721  /* Sahuagin */
    SAY NAME2 @721  /* Sahuagin */
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
	SAY INITIAL_MEETING @722 // [SAHAU01]
    SAY BATTLE_CRY1 @723 // [SAHAU02]
    SAY DAMAGE @727 // [SAHAU06]
    SAY DYING @728 // [SAHAU07]
    SAY SELECT_COMMON1 @724 // [SAHAU03]
    SAY SELECT_COMMON2 @725 // [SAHAU04]
    SAY SELECT_COMMON3 @726 // [SAHAU05]
    SAY SELECT_COMMON4 @722 // [SAHAU01]
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
      
  /* Add BG2 Items missing from BGEE */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
	/* Boomerang Dagger */
	COPY ~bg1npc/bgee/itm/dagg11.itm~ ~override~ 
  		SAY NAME2 @6002
  		SAY DESC @6003
  		
	/* Sahuagin Paralytic Bolt */
	COPY ~bg1npc/bgee/itm/sahbolt.itm~ ~override~ 
		SAY NAME2 @6011
  		SAY DESC @6012
  END
  
  /* area patching */
  EXTEND_BOTTOM ~%ShipwrecksCoast_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW3100.BAF~
      EVALUATE_BUFFER

  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#IHTIA.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#KETH.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#KISE1.BAF~
  
  /* dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#KISEQU.D~

  /* Dynaheir's Quest */

    /* items */
  COPY_EXISTING ~%tutu_var%SCRL2J.itm~ ~override/X#DYJOR1.itm~ // page
    SAY NAME1 @274
    SAY NAME2 @274
    SAY UNIDENTIFIED_DESC @275
    SAY DESC @275

  COPY_EXISTING ~%tutu_var%BOOK40.itm~ ~override/X#DYJOR2.itm~ // journal
    SAY NAME1 @276
    SAY NAME2 @276
    SAY UNIDENTIFIED_DESC @277
    SAY DESC @277

  COPY ~BG1NPC/phase2/itm/X#WINAMU.itm~ ~override~
    SAY NAME1 @629
    SAY NAME2 @629
    SAY UNIDENTIFIED_DESC @630
    SAY DESC @630

  /* Add BG2 Items missing from BGEE */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
	/* Scrolls of Cacofiend and Maze */
	COPY ~bg1npc/bgee/itm/scrl8i.itm~ ~override~ 
	COPY ~bg1npc/bgee/itm/scrl9h.itm~ ~override~ 
	
	/* Demon See Invisibility ring */
	COPY ~bg1npc/bgee/itm/seeinvis.itm~ ~override~
  END

  /* Working spell for Prot Evil 10' radius that protects vs Demons 
     Note: BGEE version of SPPR408 already protects vs demons. */
  ACTION_IF !(GAME_IS ~bgee~) THEN BEGIN
  	COPY ~BG1NPC/phase2/itm/SPPR408.SPL~ ~override~
  END
 
  /* Compile spell for Imp */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#IMPSPL.BAF~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#IMPSPL.TRA~
  
  /* X#IMPSPL.BCS uses the sound file IMPPP04.wav, which is not found in BGEE. */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
  	COPY ~bg1npc/bgee/wav/imppp04.wav~ ~override~
  END
  
  /* creatures */
  /* new Drizzt for cutscenes */
  COPY_EXISTING ~%tutu_var%drizzt.cre~ ~override/x#drizzt.cre~
    SAY NAME1 @564
    SAY NAME2 @564
    SAY 0xA4 @565
    SAY 0xB8 @566
    SAY 0xC8 @567
    SAY 0xCC @567
    SAY 0xD0 @567
    SAY 0xD4 @567
    SAY 0xD8 @567
    SAY 0xEC @568
    SAY 0xF0 @569
    SAY 0x10C @570
    SAY 0x110 @571
    SAY 0x114 @572
    SAY 0x118 @573
    SAY 0x198 @574
    SAY 0x19C @570
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~

  COPY_EXISTING ~%tutu_var%winski2.cre~ ~override~
    WRITE_EVALUATED_ASCII 0x2cc ~%tutu_var%WINSKI~ #8
    WRITE_ASCII 0x280 ~winski2~ #32

  COPY_EXISTING ~%tutu_var%winski.cre~ ~override/x#winski.cre~
    SAY NAME1 @284
    SAY NAME2 @284
    SAY BATTLE_CRY1 @285
    SAY BATTLE_CRY2 @285
    SAY BATTLE_CRY3 @285
    SAY BATTLE_CRY4 @285
    SAY BATTLE_CRY5 @285
    SAY ATTACK1 @285
    SAY ATTACK2 @285
    SAY DAMAGE @286
    SAY DYING @287
    SAY SELECT_COMMON1 @285
    SAY SELECT_COMMON2 @285
    WRITE_ASCII 0x2cc ~X#WINSKI~ #8// Dialogue file
    WRITE_BYTE 0x270 ~128~ // Allegiance = Neutral no combat scripts assigned to cre, so should remain neutral
    WRITE_ASCII 0x268 ~X#DYQWIN~ #8 // Default Script
    WRITE_ASCII 0x248 ~X#DYQWIN~ #8 //  override script no combat scripting assigned in bcs, so should not respond
    WRITE_ASCII 0x280 ~X#WINSKI~ #32 //  death variable, unused by current scripting; "winski" used on copied uncalled _WINSKI.cre

  COPY_EXISTING ~%tutu_var%GNOLL.cre~ ~override/x#dgnle1.cre~ // Evil Gnoll #1
                ~%tutu_var%GNOLL.cre~ ~override/x#dgnle2.cre~ // Evil Gnoll #2
                ~%tutu_var%GNOLL.cre~ ~override/x#dgnle3.cre~ // Evil Gnoll #3
                ~%tutu_var%GNOLL.cre~ ~override/x#dgnle4.cre~ // Evil Gnoll #4
                ~%tutu_var%GNOLL.cre~ ~override/x#dgnlg1.cre~ // Good Gnoll #1
                ~%tutu_var%GNOLL.cre~ ~override/x#dgnlg2.cre~ // Good Gnoll #2
                ~%tutu_var%GNOLL.cre~ ~override/x#dgnlg3.cre~ // Good Gnoll #3
                ~%tutu_var%GNOLL.cre~ ~override/x#dgnlg4.cre~ // Good Gnoll #4
    SAY NAME1 @278
    SAY NAME2 @278
    SAY BATTLE_CRY1 @279
    SAY BATTLE_CRY2 @279
    SAY BATTLE_CRY3 @279
    SAY BATTLE_CRY4 @279
    SAY BATTLE_CRY5 @279
    SAY ATTACK1 @279
    SAY ATTACK2 @279
    SAY DAMAGE @280
    SAY DYING @281
    SAY SELECT_COMMON1 @282
    SAY SELECT_COMMON2 @283
    WRITE_LONG 0x14 ~100~ // XP Value
    WRITE_BYTE 0x270 ~128~ // Allegiance = Neutral
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32 //  death variable
      PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE ~x#dgnle1~ = 0) BEGIN
        WRITE_ASCII 0x2cc ~X#DGNLE~ #8 // Dialogue file: Evil Gnoll #1
        ADD_CRE_ITEM ~X#DYJOR2~ #0 #0 #0 ~IDENTIFIED~ ~INV5~
      END ELSE PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE ~x#dgnlg1~ = 0) BEGIN
        WRITE_ASCII 0x2cc ~X#DGNLG~ #8// Dialogue file: Good Gnoll #1
        ADD_CRE_ITEM ~X#DYJOR1~ #0 #0 #0 ~IDENTIFIED~ ~INV5~
      END
      

ACTION_IF FILE_EXISTS_IN_GAME ~imp01.cre~ THEN BEGIN
  COPY_EXISTING ~IMP01.cre~ ~override/x#dyqimp.cre~
    SAY NAME1 @288
    SAY NAME2 @288
    SAY DAMAGE @289
    SAY DYING @290
    WRITE_LONG 0x14 ~2000~ // XP Value
    WRITE_SHORT 0x24 ~25~ // Current HP (usually 18)
    WRITE_SHORT 0x26 ~25~ // Maximum HP (usually 18)
    WRITE_ASCII 0x268 ~X#IMPSPL~ #8 // Default Script
    WRITE_ASCII 0x248 ~none~ #8 //  override script no combat scripting assigned in bcs, so should not respond
    WRITE_ASCII 0x280 ~ichthraa~ #32 //  death variable
    
  COPY_EXISTING ~MEPSMO01.cre~ ~override/x#mepht1.cre~
                ~MEPSMO01.cre~ ~override/x#mepht2.cre~
                ~MEPSMO01.cre~ ~override/x#mepht3.cre~
                ~MEPSMO01.cre~ ~override/x#mepht4.cre~
                ~MEPSMO01.cre~ ~override/x#mepht5.cre~
  	WRITE_ASCII SCRIPT_DEFAULT ~x#mepsmo~ #8

  COPY_EXISTING ~IDEMON02.cre~ ~override/x#tanari.cre~
    SAY NAME1 @291
    SAY NAME2 @291
    WRITE_BYTE 0x5b 50  /* Electrical Resistance */
    WRITE_ASCII 0x248 ~X#DYTANR~ #8  /* Override script */
    WRITE_EVALUATED_ASCII 0x2CC ~%DEST_RES%~ #8   /* Dialog */
    WRITE_BYTE 0x270 ~128~  /* Allegiance = Neutral */
    WRITE_ASCII 0x280 ~aravaata~ #32  /* death variable */

END ELSE BEGIN
  COPY ~bg1npc/phase2/cre/x#dyqimp.cre~ ~override~
    SAY NAME1 @288
    SAY NAME2 @288
    SAY DAMAGE @289
    SAY DYING @290
    WRITE_LONG 0x14 ~2000~ // XP Value
    WRITE_SHORT 0x24 ~25~ // Current HP (usually 18)
    WRITE_SHORT 0x26 ~25~ // Maximum HP (usually 18)
    WRITE_ASCII 0x268 ~X#IMPSPL~ #8 // Default Script
    WRITE_ASCII 0x248 ~none~ #8 //  override script no combat scripting assigned in bcs, so should not respond
    WRITE_ASCII 0x280 ~ichthraa~ #32 //  death variable
    
  COPY ~bg1npc/phase2/cre/x#mepht1.cre~ ~override~
       ~bg1npc/phase2/cre/x#mepht1.cre~ ~override/x#mepht2.cre~
       ~bg1npc/phase2/cre/x#mepht1.cre~ ~override/x#mepht3.cre~
       ~bg1npc/phase2/cre/x#mepht1.cre~ ~override/x#mepht4.cre~
       ~bg1npc/phase2/cre/x#mepht1.cre~ ~override/x#mepht5.cre~
        SAY NAME1 @729  /* Smoke Mephit */
        SAY NAME2 @729  /* Smoke Mephit */
        WRITE_ASCII SCRIPT_DEFAULT ~x#mepsmo~ #8

  COPY ~bg1npc/phase2/cre/x#tanari.cre~ ~override~
    SAY NAME1 @291
    SAY NAME2 @291
    WRITE_BYTE 0x5b 50 //  replace # with percentage electrical resistance you want
    WRITE_ASCII 0x248 ~X#DYTANR~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x2CC ~%DEST_RES%~ #8 //  dialog
    WRITE_BYTE 0x270 ~128~ // Allegiance = Neutral
    WRITE_ASCII 0x280 ~aravaata~ #32 //  death variable
END


  /* Compile .bcs for X#WINSKI and X#TANARI and x#mepht1-5 */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#DYQWIN.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#DYTANR.BAF~
  COMPILE ~bg1npc/phase2/baf/x#mepsmo.baf~

  /* dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/x#dynaquest.d~

  /* Extend Dynaheir's override scripts */
  EXTEND_TOP  ~%DYNAHEIR_BCS%.bcs~ ~BG1NPC/Phase2/baf/x#dynaquest.baf~
      EVALUATE_BUFFER

  /* Lake Poets "Quest"; Bard in party encounter */
  /* creatures */
  COPY_EXISTING ~%tutu_var%VOLO.cre~ ~override/x#lakep1.cre~
                ~%tutu_var%VOLO.cre~ ~override/x#lakep2.cre~
                ~%tutu_var%VOLO.cre~ ~override/x#lakep3.cre~
    SAY INITIAL_MEETING @294
    SAY UNHAPPY_BREAKING @295
    SAY BATTLE_CRY1 @296
    SAY BATTLE_CRY2 @296
    SAY BATTLE_CRY3 @296
    SAY BATTLE_CRY4 @296
    SAY BATTLE_CRY5 @296
    SAY DAMAGE @297
    SAY DYING @298
    SAY SELECT_COMMON1 @299
    SAY SELECT_COMMON2 @300
    SAY SELECT_COMMON3 @301
    SAY SELECT_COMMON4 @302
    SAY DIALOGUE_DEFAULT @299
    WRITE_EVALUATED_ASCII 0x2CC ~%DEST_RES%~ #8 //  dialog
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32 //  death variable
      PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#lakep1~) BEGIN
        SAY NAME1 @292
        SAY NAME2 @293
        WRITE_ASCII 0x248 ~X#LP1R~ #8 //  override script
      END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#lakep2~) BEGIN
        SAY NAME1 @303
        SAY NAME2 @304
        WRITE_ASCII 0x248 ~X#LP2R~ #8 //  override script
      END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#lakep3~) BEGIN
        SAY NAME1 @305
        SAY NAME2 @306
        WRITE_ASCII 0x248 ~X#LP3R~ #8 //  override script
      END

  /* area script changes */
  EXTEND_BOTTOM ~%Peldvale_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#LAKEP.BAF~
      EVALUATE_BUFFER

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#LAKE.D~

  /* Add BG2 items missing from BGEE */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
	COPY ~bg1npc/bgee/wav/itemharp.wav~ ~override~
  	/* Harp of Discord */
	COPY ~bg1npc/bgee/itm/misc3m.itm~ ~override~ 
  		SAY NAME2 @6004
  		SAY UNIDENTIFIED_DESC @6005
  		SAY DESC @6006
	/* Azlaer's Harp */
	COPY ~bg1npc/bgee/itm/misc3n.itm~ ~override~ 
  		SAY NAME2 @6007
  		SAY UNIDENTIFIED_DESC @6005
  		SAY DESC @6008
	/* Methlid's Harp */
	COPY ~bg1npc/bgee/itm/misc3o.itm~ ~override~ 
  		SAY NAME2 @6009
  		SAY UNIDENTIFIED_DESC @6005
  		SAY DESC @6010
  END
	
  /* Xzar's Dryad Quest */
  /* items */
  COPY ~BG1NPC/phase2/itm/X#XZSPL.SPL~ ~override~
    SAY NAME1 @307
    SAY NAME2 @307
	WRITE_ASCII 0x10 ~CAS_M05~ #8    // casting sound
	WRITE_ASCII 0x3a ~SPWI509C~ #8   // spell icon
	WRITE_ASCII 0x76 ~SPWI509B~ #8   // ability #0 icon

  COPY ~BG1NPC/phase2/itm/X#XZDRIA.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#XZDRIA.itm~ ~override~
    SAY NAME1 @308
    SAY NAME2 @309
    SAY UNIDENTIFIED_DESC @310
    SAY DESC @311

  /* The Dryad Ring */
  COPY ~BG1NPC/phase2/itm/X#XZRINC.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#XZRINI.BAM~ ~override~
  COPY ~BG1NPC/phase2/itm/X#XZRING.itm~ ~override~
    SAY NAME1 @10
    SAY NAME2 @314
    SAY UNIDENTIFIED_DESC @12
    SAY DESC @315

  /* inventory icon bam for mithril ring */
  COPY ~BG1NPC/phase2/itm/X#XZMIRI.bam~ ~override~

/* Mithril Ring adding to Containers in FW5001,4701, 1401, 1603, 3601 */
  COPY_EXISTING ~%tutu_var%RING11.itm~ ~override/X#XZMIRI.itm~
    SAY NAME1 @312
    SAY NAME2 @312
    SAY UNIDENTIFIED_DESC @313
    SAY DESC @313
    WRITE_LONG 0x34 750
    WRITE_ASCII 0x58 ~cring05~ #8
    WRITE_ASCII 0x3a ~x#xzmiri~

  /* creatures */
  /* Forest Spirit 1 */
  COPY ~BG1NPC/Phase2/cre/x#xzfsp1.cre~ ~override~
    SAY NAME1 @316
    SAY NAME2 @316
    SAY INITIAL_MEETING @317
    SAY DAMAGE @318
    SAY DYING @319
    SAY SELECT_COMMON1 @320
    SAY SELECT_COMMON2 @317
    WRITE_ASCII SCRIPT_CLASS ~x#shoutp~ #8 // class script
    WRITE_ASCII 0x2CC ~X#XZFSP1~ #8 //  dialog
    WRITE_ASCII 0x280 ~xzfspirit1~ #32 //  death variable

  /* Forest Spirit 2,3 */
  COPY ~BG1NPC/Phase2/cre/x#xzfsp2.cre~ ~override/x#xzfsp2.cre~
       ~BG1NPC/Phase2/cre/x#xzfsp2.cre~ ~override/x#xzfsp3.cre~
    SAY NAME1 @316
    SAY NAME2 @316
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* SAUVAT soundset not present in BGEE, use EARTH soundset instead */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY BATTLE_CRY1 @731 // [EARTH02]
    	SAY BATTLE_CRY2 @732 // [EARTH03]
    	SAY DAMAGE @733 // [EARTH06]
    	SAY DYING @734 // [EARTH07]
    	SAY SELECT_COMMON1 @730 // [EARTH01]
	END ELSE BEGIN /* Tutu, BGT */
		SAY BATTLE_CRY1 @321
    	SAY BATTLE_CRY2 @322
    	SAY DAMAGE @323
    	SAY DYING @324
    	SAY SELECT_COMMON1 @325
    END
    WRITE_ASCII 0x248 ~X#XZFSP2~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x2CC ~%DEST_RES%~ #8 //  dialog
    WRITE_EVALUATED_ASCII 0x282 ~%DEST_RES%~ #30 //  death variable
    WRITE_ASCII 0x280 ~xzfspirit~ #9 //  death variable

  /* Blackberry */
  COPY ~BG1NPC/Phase2/cre/x#black.cre~ ~override~
    SAY NAME1 @326
    SAY NAME2 @326
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* EPRIM soundset not present in BGEE, use DRUID soundset instead */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	    SAY INITIAL_MEETING @341
    	SAY BATTLE_CRY1 @341
    	SAY DAMAGE @342
    	SAY DYING @343
    	SAY SELECT_COMMON1 @344
    	SAY SELECT_COMMON2 @345
	END ELSE BEGIN /* Tutu, BGT: BG2 EPRIM soundset */
    	SAY INITIAL_MEETING @327
   		SAY UNHAPPY_BREAKING @328
    	SAY BATTLE_CRY1 @329
    	SAY DAMAGE @330
    	SAY DYING @331
    	SAY SELECT_COMMON1 @327
    	SAY SELECT_COMMON2 @332
    END
	WRITE_EVALUATED_ASCII 0x248 ~%SOURCE_RES%~ #8 //  override script
	WRITE_ASCII SCRIPT_CLASS ~x#druid6~ #8 // class script
    WRITE_ASCII SCRIPT_GENERAL ~x#drdsht~ #8 // general script
    WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%tasight~ #8 // Default script
    WRITE_EVALUATED_ASCII 0x2CC ~%SOURCE_RES%~ #8 //  dialog
    WRITE_ASCII 0x280 ~blackberry~ #32 //  death variable

  /* Storm */
  COPY ~BG1NPC/Phase2/cre/x#storm.cre~ ~override~
    SAY NAME1 @333
    SAY NAME2 @333
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* HVILLM soundset not present in BGEE, use DRUID soundset instead */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY INITIAL_MEETING @341
    	SAY BATTLE_CRY1 @341
    	SAY DAMAGE @342
    	SAY DYING @343
    	SAY SELECT_COMMON1 @344
    	SAY SELECT_COMMON2 @345
	END ELSE BEGIN /* Tutu, BGT: BG2 HVILLM soundset */
    	SAY INITIAL_MEETING @334
    	SAY UNHAPPY_BREAKING @335
    	SAY BATTLE_CRY1 @336
    	SAY DAMAGE @337
    	SAY DYING @338
    	SAY SELECT_COMMON1 @339
    	SAY SELECT_COMMON2 @334
    END
    WRITE_EVALUATED_ASCII 0x248 ~%SOURCE_RES%~ #8 //  override script
    WRITE_ASCII SCRIPT_CLASS ~x#druid8~ #8 // class script
    WRITE_ASCII SCRIPT_GENERAL ~x#drdsht~ #8 // general script
    WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%tasight~ #8 // Default script
    WRITE_EVALUATED_ASCII 0x2CC ~%SOURCE_RES%~ #8 //  dialog
    WRITE_ASCII 0x280 ~storm~ #32 //  death variable

  /* Zosya */
  COPY ~BG1NPC/Phase2/cre/x#zosya.cre~ ~override~
    SAY NAME1 @340
    SAY NAME2 @340
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* DRYAD soundset */
    SAY INITIAL_MEETING @373
    SAY BATTLE_CRY1 @367
    SAY DAMAGE @371
    SAY DYING @372
    SAY SELECT_COMMON1 @366
    SAY SELECT_COMMON2 @373
    WRITE_EVALUATED_ASCII 0x248 ~%SOURCE_RES%~ #8 //  override script
    WRITE_ASCII SCRIPT_CLASS ~x#drui12~ #8 // class script
    WRITE_ASCII SCRIPT_RACE ~~ #8 // race script
    WRITE_ASCII SCRIPT_GENERAL ~x#drdsht~ #8 // general script
    WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%tasight~ #8 // Default script
    WRITE_EVALUATED_ASCII 0x2CC ~%SOURCE_RES%~ #8 //  dialog
    WRITE_ASCII 0x280 ~zosya~ #32 //  death variable

  /* Flaming Fist Officer */
  COPY ~BG1NPC/Phase2/cre/x#xzgu01.cre~ ~override~
    SAY NAME1 @346
    SAY NAME2 @346
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @350
    SAY BATTLE_CRY1 @348
    SAY BATTLE_CRY2 @349
    SAY BATTLE_CRY3 @350
    SAY BATTLE_CRY4 @349
    SAY BATTLE_CRY5 @348
    SAY ATTACK1 @349
    SAY ATTACK2 @348
    SAY DAMAGE @351
    SAY DYING @352
    SAY SELECT_COMMON1 @353
    SAY SELECT_COMMON2 @349
    SAY DIALOGUE_HOSTILE @354
    WRITE_ASCII 0x248 ~X#XZGU01~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%dasight~ #8 // Default script
    WRITE_ASCII 0x2CC ~X#XZGU01~ #8 //  dialog
    WRITE_ASCII 0x280 ~X#XZGU01~ #32 //  death variable
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x258 ~SEEENEMY~ #8
        WRITE_ASCII 0x250 ~INITMAIN~ #8
      END

  /* Flaming Fist Mercenary 1 */
  COPY_EXISTING ~%tutu_var%FLAME.cre~ ~override/x#xzgu02.cre~
    SAY NAME1 @355
    SAY NAME2 @355
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @350
    SAY BATTLE_CRY1 @348
    SAY BATTLE_CRY2 @349
    SAY BATTLE_CRY3 @350
    SAY BATTLE_CRY4 @349
    SAY BATTLE_CRY5 @348
    SAY ATTACK1 @348
    SAY ATTACK2 @349
    SAY DAMAGE @351
    SAY DYING @352
    SAY SELECT_COMMON1 @350
    SAY SELECT_COMMON2 @353
    SAY DIALOGUE_HOSTILE @356
    SAY DIALOGUE_DEFAULT @350
    WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%tasight~ #8 // Default script
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32 //  death variable

  /* Flaming Fist Mercenary 2 */
  COPY ~BG1NPC/Phase2/cre/x#xzgu03.cre~ ~override~
    SAY NAME1 @357
    SAY NAME2 @357
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @350
    SAY BATTLE_CRY1 @353
    SAY BATTLE_CRY2 @349
    SAY BATTLE_CRY3 @350
    SAY BATTLE_CRY4 @349
    SAY BATTLE_CRY5 @348
    SAY ATTACK1 @348
    SAY ATTACK2 @349
    SAY DAMAGE @351
    SAY DYING @352
    SAY SELECT_COMMON1 @350
    SAY SELECT_COMMON2 @349
    SAY DIALOGUE_HOSTILE @353
    SAY SELECT_RARE1 @349
    WRITE_EVALUATED_ASCII 0x268 ~%tutu_scriptw%tasight~ #8 // Default script
    WRITE_ASCII 0x280 ~X#XZGU03~ #32 //  death variable
	WRITE_ASCII 0x3C ~~ #8      // large portrait
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x260 ~FLAMSPEL~ #8
        WRITE_ASCII 0x258 ~FLAMPUN~ #8
        WRITE_ASCII 0x250 ~SHOUT~ #8
        WRITE_ASCII 0x248 ~GUARDS~ #8
      END

  /* extending area scripts */
  EXTEND_BOTTOM ~%FV_AnkhegPit_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW1401.BAF~
    EVALUATE_BUFFER
  EXTEND_BOTTOM ~%CloakwoodDr_PetersCave_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW1603.BAF~
    EVALUATE_BUFFER
  EXTEND_BOTTOM ~%Lighthouse_BAsCave_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW3601.BAF~
    EVALUATE_BUFFER
  EXTEND_BOTTOM ~%XvartVillageCave_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW4701.BAF~
    EVALUATE_BUFFER
  EXTEND_BOTTOM ~%ValleyoftheTombsTomb_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW5001.BAF~
    EVALUATE_BUFFER

  /* dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#XZQU.D~
  
  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#BLACK.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#STORM.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#ZOSYA.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#XZDR1.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#XZDR2.BAF~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#XZDR2.TRA~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#XZDR3.BAF~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#XZDR3.TRA~
  EXTEND_TOP ~%XZAR_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#XZDQU.BAF~
    EVALUATE_BUFFER
    USING ~BG1NPC/TRA/%LANGUAGE%/X#XZDQU.TRA~
  COMPILE ~bg1npc/phase2/baf/x#shoutp.baf~  /* For x#xzfsp1 */
  COMPILE ~bg1npc/phase2/baf/x#druid6.baf~  /* For x#black */
  COMPILE ~bg1npc/phase2/baf/x#druid8.baf~  /* For x#storm */
  COMPILE ~bg1npc/phase2/baf/x#drui12.baf~  /* For x#zosya */
  COMPILE ~bg1npc/phase2/baf/x#drdsht.baf~  /* Druid shout script */
   
  /* Jaheira Shadow Druids Quest */

  /* Club */
  COPY ~BG1NPC/phase2/itm/X#JACLUB.itm~ ~override~
    SAY NAME1 @359
    SAY NAME2 @360
    SAY UNIDENTIFIED_DESC @361
    SAY DESC @362
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x3a ~IBLUN01~ #8 //  main item bam
        WRITE_ASCII 0x44 ~GBLUN01~ #8
        WRITE_ASCII 0x58 ~CBLUN01~ #8
      END

  /* Andarthe's Spear */
  COPY ~BG1NPC/phase2/itm/x#anspri.bam~ ~override~
  COPY ~BG1NPC/phase2/itm/x#ansprd.bam~ ~override~
  COPY ~BG1NPC/phase2/itm/x#ansper.itm~ ~override~
    SAY NAME2 @378
    SAY DESC @379
	WRITE_ASCII 0x10 ~MISC56~ #8 // used-up item
   PATCH_IF GAME_IS ~bgee bgt~ BEGIN
      WRITE_ASCII 0x44 ~gsper01~ #8
    END

  /* creatures */

  COPY_EXISTING ~%tutu_var%takiyah.cre~ ~override~
    WRITE_ASCII 0x280 ~takiyah~ #32 //  death variable
  BUT_ONLY_IF_IT_CHANGES

  /* Andarthe */
  COPY ~BG1NPC/Phase2/cre/x#andart.cre~ ~override~
    SAY NAME1 @363
    SAY NAME2 @363
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @341
    SAY BATTLE_CRY1 @341
    SAY DAMAGE @342
    SAY DYING @343
    SAY SELECT_COMMON1 @345
    WRITE_ASCII 0x280 ~andarthe~ #32 //  death variable
    
  /* Beador */
  COPY ~BG1NPC/phase2/cre/x#beador.cre~ ~override~
    SAY NAME1 @364
    SAY NAME2 @364
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @341
    SAY BATTLE_CRY1 @341
    SAY ATTACK1 @341
    SAY ATTACK2 @341
    SAY DAMAGE @342
    SAY DYING @343
    SAY SELECT_COMMON1 @344
    SAY SELECT_COMMON2 @345

  COPY ~BG1NPC/phase2/cre/x#beado1.cre~ ~override~
    SAY NAME1 @364
    SAY NAME2 @364
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @341
    SAY BATTLE_CRY1 @341
    SAY ATTACK1 @341
    SAY ATTACK2 @341
    SAY DAMAGE @342
    SAY DYING @343
    SAY SELECT_COMMON1 @344
    SAY SELECT_COMMON2 @345

  /* Maretha */
  COPY ~BG1NPC/Phase2/cre/x#mareth.cre~ ~override~
    SAY NAME1 @365
    SAY NAME2 @365
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @366
    SAY BATTLE_CRY1 @367
    SAY BATTLE_CRY2 @367
    SAY BATTLE_CRY3 @367
    SAY BATTLE_CRY4 @367
    SAY BATTLE_CRY5 @367
    SAY ATTACK1 @368
    SAY ATTACK2 @369
    SAY ATTACK3 @370
    SAY DAMAGE @371
    SAY DYING @372
    SAY SELECT_COMMON1 @373
    SAY SELECT_COMMON2 @366

  /* Stock Druids */ 
  COPY ~BG1NPC/phase2/cre/x#shdr6.cre~  ~override/x#shdr6.cre~
       ~BG1NPC/phase2/cre/x#shdr6.cre~  ~override/x#shdr6a.cre~
       ~BG1NPC/phase2/cre/x#shdr6.cre~  ~override/x#shdr6b.cre~
    SAY NAME1 @374
    SAY NAME2 @375
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    PATCH_IF GAME_IS ~bgee~ BEGIN /* BGEE: Use VILLM soundset */
    	SAY INITIAL_MEETING #23945	// [VILLAGER, MALE 01b]
    	SAY BATTLE_CRY1 #23882		// [VILLAGER, MALE 03]
    	SAY DAMAGE #23884			// [VILLAGER, MALE 05]
    	SAY DYING #23885			// [VILLAGER, MALE 06]
    	SAY SELECT_COMMON1 #23946 	// [VILLAGER, MALE 01c]
    	SAY SELECT_COMMON2 #23949   // [VILLAGER, MALE 01f]
    	SAY SELECT_COMMON3 #23945	// [VILLAGER, MALE 01b]
    END ELSE BEGIN /* Tutu, BGT: EPRIM soundset from BG2 */	
    	SAY INITIAL_MEETING @327
    	SAY UNHAPPY_BREAKING @328
    	SAY BATTLE_CRY1 @329
    	SAY DAMAGE @330
    	SAY DYING @331
    	SAY SELECT_COMMON1 @327
    	SAY SELECT_COMMON2 @332
    END
    WRITE_ASCII SCRIPT_OVERRIDE ~x#gpsht~ #8 // override script
    PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#shdr6~) BEGIN
      WRITE_ASCII 0x280 ~jadruid6~ #32 //  death variable
    END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#shdr6a~) BEGIN
      WRITE_ASCII 0x280 ~jadruid6a~ #32 //  death variable
    END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#shdr6b~) BEGIN
      WRITE_ASCII 0x280 ~jadruid6b~ #32 //  death variable
    END

  COPY ~BG1NPC/phase2/cre/x#shdr8a.cre~ ~override/x#shdr8a.cre~
       ~BG1NPC/phase2/cre/x#shdr8b.cre~ ~override/x#shdr8b.cre~
    SAY NAME1 @374
    SAY NAME2 @375
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    PATCH_IF GAME_IS ~bgee~ BEGIN /* BGEE: Use VILLM soundset */
    	SAY INITIAL_MEETING #23945	// [VILLAGER, MALE 01b]
    	SAY BATTLE_CRY1 #23882		// [VILLAGER, MALE 03]
    	SAY DAMAGE #23884			// [VILLAGER, MALE 05]
    	SAY DYING #23885			// [VILLAGER, MALE 06]
    	SAY SELECT_COMMON1 #23946 	// [VILLAGER, MALE 01c]
    	SAY SELECT_COMMON2 #23949   // [VILLAGER, MALE 01f]
    	SAY SELECT_COMMON3 #23945	// [VILLAGER, MALE 01b]
    END ELSE BEGIN /* Tutu, BGT: HVILLM soundset from BG2 */	
    	SAY INITIAL_MEETING @334
    	SAY UNHAPPY_BREAKING @335
    	SAY BATTLE_CRY1 @336
    	SAY DAMAGE @337
    	SAY DYING @338
    	SAY SELECT_COMMON1 @339
    	SAY SELECT_COMMON2 @334
    	SAY SELECT_COMMON3 @376
    	SAY SELECT_COMMON4 @377
    END
    WRITE_ASCII SCRIPT_OVERRIDE ~x#gpsht~ #8 // override script
    PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#shdr8a~) BEGIN
      WRITE_ASCII 0x280 ~jadruid8a~ #32 //  death variable
    END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE ~x#shdr8b~) BEGIN
      WRITE_ASCII 0x280 ~jadruid8b~ #32 //  death variable
    END

  /* dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#JAQU.D~

  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#BEADOR.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#JABE1.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#ANDART.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#MARETH.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#SHDR6.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#SHDR8.BAF~
  EXTEND_TOP ~%JAHEIRA_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#JAQU.BAF~
    EVALUATE_BUFFER

    /* Patching Area Scripts */
  EXTEND_BOTTOM ~%CloakwoodWyverns_BCS%.bcs~ ~BG1NPC/Phase2/baf/P#FW1700JQ.BAF~
      EVALUATE_BUFFER

  /* Patching all creatures in component for Tutu > BGT items */
  ACTION_IF GAME_IS ~bgt bgee~ THEN BEGIN
    COPY_EXISTING_REGEXP GLOB ~^[XxPp]#.*\.cre~ ~override~
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
       LAUNCH_PATCH_MACRO ~convert_tutu_items_bgt_bgee~
      END
    BUT_ONLY_IF_IT_CHANGES
  END
  
  /* Make sure this is last in Quest additions for Phase 2 */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#ICT3.D~

/* END OF BANTERS, QUESTS, INTERJECTIONS */

/* Portrait Changes */
/* Edwin */
BEGIN @1022 /* The BG1 NPC Project: Give Edwin his BG2 portrait. */
  GROUP @1008  /* The BG1 NPC Project: Portrait Changes and Additions */
//  REQUIRE_PREDICATE (!GAME_IS ~bgee~) @5001 /* You must have BGT or TuTu installed for this component. */  
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
ACTION_FOR_EACH edwin IN edwin edwin2 edwin4 edwin6 _edwin _edwin2 _edwin4 _edwin6 BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME "%edwin%.cre" BEGIN
    COPY_EXISTING "%edwin%.cre" ~override~ // Edwin
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN // protects against invalid files
        WRITE_ASCII 0x34 ~NEDWINS~ #8 // small portrait
        WRITE_ASCII 0x3c ~NEDWINM~ #8 // medium portrait
      END
    BUT_ONLY_IF_IT_CHANGES
  END
END

/* Imoen */
BEGIN @1023 /* The BG1 NPC Project: Give Imoen her BG2 portrait. */
  GROUP @1008  /* The BG1 NPC Project: Portrait Changes and Additions */
//  REQUIRE_PREDICATE (!GAME_IS ~bgee~) @5001 /* You must have BGT or TuTu installed for this component. */  
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
ACTION_FOR_EACH imoen IN imoen imoen1 imoen2 imoen4 imoen6 _imoen _imoen1 _imoen2 _imoen4 _imoen6 BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME "%imoen%.cre" BEGIN
    COPY_EXISTING "%imoen%.cre" ~override~
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN // protects against invalid files
        WRITE_ASCII 0x34 ~NIMOENS~ #8 // small portrait
        WRITE_ASCII 0x3c ~NIMOENM~ #8 // medium portrait
      END
    BUT_ONLY_IF_IT_CHANGES
  END
END

/* Jaheira */
BEGIN @1024  /* The BG1 NPC Project: Give Jaheira her BG2 portrait. */
  GROUP @1008  /* The BG1 NPC Project: Portrait Changes and Additions */
//  REQUIRE_PREDICATE (!GAME_IS ~bgee~) @5001 /* You must have BGT or TuTu installed for this component. */  
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
ACTION_FOR_EACH jaheira IN jaheir jaheir2 jaheir4 jaheir6 _jaheir _jaheir2 _jaheir4 _jaheir6 BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME "%jaheira%.cre" BEGIN
    COPY_EXISTING "%jaheira%.cre" ~override~ // Jaheira
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN // protects against invalid files
        WRITE_ASCII 0x34 ~NJAHEIRS~ #8 // small portrait
        WRITE_ASCII 0x3c ~NJAHEIRM~ #8 // medium portrait
      END
    BUT_ONLY_IF_IT_CHANGES
  END
END

/* Minsc */
BEGIN @1025 /* The BG1 NPC Project: Give Minsc his BG2 portrait. */
  GROUP @1008  /* The BG1 NPC Project: Portrait Changes and Additions */
//  REQUIRE_PREDICATE (!GAME_IS ~bgee~) @5001 /* You must have BGT or TuTu installed for this component. */  
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
ACTION_FOR_EACH minsc IN minsc minsc2 minsc4 minsc6 _minsc _minsc2 _minsc4 _minsc6 BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME "%minsc%.cre" BEGIN
    COPY_EXISTING "%minsc%.cre" ~override~ // Minsc
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN // protects against invalid files
        WRITE_ASCII 0x34 ~NMINSCS~ #8 // small portrait
        WRITE_ASCII 0x3c ~NMINSCM~ #8 // medium portrait
      END
    BUT_ONLY_IF_IT_CHANGES
  END
END

/* Viconia */
BEGIN @1026  /* The BG1 NPC Project: Give Viconia her BG2 portrait. */
  GROUP @1008  /* The BG1 NPC Project: Portrait Changes and Additions */
//  REQUIRE_PREDICATE (!GAME_IS ~bgee~) @5001 /* You must have BGT or TuTu installed for this component. */  
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
ACTION_FOR_EACH viconia IN viconi viconi4 viconi61 _viconi _viconi4 _viconi6 BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME "%viconia%.cre" BEGIN
    COPY_EXISTING "%viconia%.cre" ~override~ // Viconia
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN // protects against invalid files
        WRITE_ASCII 0x34 "NVICONS" #8 // small portrait
        WRITE_ASCII 0x3c "NVICONM" #8 // medium portrait
      END
    BUT_ONLY_IF_IT_CHANGES
  END
END
  
/* Kivan */
BEGIN @1027  /* The BG1 NPC Project: Kivan's "Kivan and Deheriana Companions" portrait */
GROUP @1008  /* The BG1 NPC Project: Portrait Changes and Additions */
REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  COPY ~BG1NPC/Phase2/Portraits/%bgee%P#KI2L.bmp~ ~override~
  COPY ~BG1NPC/Phase2/Portraits/%bgee%P#KI2M.bmp~ ~override~
  COPY ~BG1NPC/Phase2/Portraits/%bgee%P#KI2S.bmp~ ~override~
ACTION_FOR_EACH kivan IN kivan kivan4 kivan6 _kivan _kivan4 _kivan6 BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME "%kivan%.cre" BEGIN
    COPY_EXISTING "%kivan%.cre" ~override~ // Kivan
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN // protects against invalid files
        WRITE_ASCII 0x34 ~P#KI2S~ #8 // small portrait
        WRITE_ASCII 0x3c ~P#KI2M~ #8 // medium portrait
      END
    BUT_ONLY_IF_IT_CHANGES
  END
END

/* Non-Joinable Characters */
BEGIN @1009 /* The BG1 NPC Project: Add Non-Joinable NPC portraits to quests and dialogues */
GROUP @1008  /* The BG1 NPC Project: Portrait Changes and Additions */
REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  COPY ~BG1NPC/Core/X#component.xx~ ~override/X#NJNPCPortrait.G3~
  
  ACTION_IF GAME_IS ~tutu tutu_totsc bgt~ THEN BEGIN
    COPY ~BG1NPC/Phase2/Portraits~ ~override~
  END ELSE BEGIN
    COPY ~BG1NPC/Phase2/Portraits/bgee~ ~override~
  END

  /* Standard Non-Joinable Actors */
  COPY_EXISTING ~%tutu_var%alatos.cre~ ~override~
    WRITE_ASCII 0x34 ~alatos~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%albert.cre~ ~override~
    WRITE_ASCII 0x34 ~albers~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%alyth.cre~ ~override~
    WRITE_ASCII 0x34 ~alyths~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%amaran.cre~ ~override~
    WRITE_ASCII 0x34 ~amarans~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%sarev1.cre~ ~override~
    WRITE_ASCII 0x34 ~armoreds~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%bjorni.cre~ ~override~
    WRITE_ASCII 0x34 ~bjorns~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%bassil.cre~ ~override~
    WRITE_ASCII 0x34 ~bass~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%belt.cre~ ~override~
    WRITE_ASCII 0x34 ~belts~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%brage.cre~  ~override~
                ~%tutu_var%brage2.cre~ ~override~
    WRITE_ASCII 0x34 ~brages~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%brilla.cre~ ~override~
    WRITE_ASCII 0x34 ~brilles~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%farmbr.cre~ ~override~
    WRITE_ASCII 0x34 ~bruns~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%cadder.cre~ ~override~
    WRITE_ASCII 0x34 ~cadds~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%coksmth.cre~ ~override~
    WRITE_ASCII 0x34 ~peters~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%davaeo.cre~ ~override~
    WRITE_ASCII 0x34 ~daverons~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%drizzt.cre~ ~override~
    WRITE_ASCII 0x34 ~drizzts~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%drienn.cre~ ~override~
    WRITE_ASCII 0x34 ~driens~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%elmin2.cre~  ~override~
                ~%tutu_var%elmin3.cre~  ~override~
                ~%tutu_var%elmin5.cre~  ~override~
                ~%tutu_var%elmins4.cre~ ~override~
    WRITE_ASCII 0x34 ~elmins~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%gerde.cre~ ~override~
    WRITE_ASCII 0x34 ~gerdes~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%greywo.cre~ ~override~
    WRITE_ASCII 0x34 ~greyws~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%jessup.cre~ ~override~
    WRITE_ASCII 0x34 ~jessups~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%halbaz.cre~ ~override~
    WRITE_ASCII 0x34 ~halbazs~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%liia.cre~ ~override~
    WRITE_ASCII 0x34 ~liias~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%larze.cre~ ~override~
    WRITE_ASCII 0x34 ~larzes~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%keldda.cre~ ~override~
    WRITE_ASCII 0x34 ~keldaths~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%korax.cre~ ~override~
    WRITE_ASCII 0x34 ~koraxs~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%mulahe.cre~ ~override~
    WRITE_ASCII 0x34 ~mulahs~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%narlen.cre~ ~override~
    WRITE_ASCII 0x34 ~narlens~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%niemai.cre~ ~override~
    WRITE_ASCII 0x34 ~niemais~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%petrin.cre~ ~override~
    WRITE_ASCII 0x34 ~petrins~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%rielta.cre~ ~override~
    WRITE_ASCII 0x34 ~rieltars~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%seniya.cre~ ~override~
    WRITE_ASCII 0x34 ~seniyas~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%thalan.cre~ ~override~
    WRITE_ASCII 0x34 ~thalas~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%vai.cre~ ~override~
    WRITE_ASCII 0x34 ~ofvais~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%shoal.cre~ ~override~
    WRITE_ASCII 0x34 ~shoals~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%tamoko.cre~ ~override~
    WRITE_ASCII 0x34 ~tamokos~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%tenya.cre~  ~override~
                ~%tutu_var%tenya2.cre~ ~override~
    WRITE_ASCII 0x34 ~tenyas~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%pumberl.cre~ ~override~
                ~%tutu_var%pumber2.cre~ ~override~
    WRITE_ASCII 0x34 ~umbprs~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%winthr2.cre~ ~override~
                ~%tutu_var%winthr3.cre~ ~override~
                ~%tutu_var%innke2.cre~ ~override~
    WRITE_ASCII 0x34 ~winthrs~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%yago.cre~ ~override~
    WRITE_ASCII 0x34 ~yagos~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%angelo.cre~ ~override~
    WRITE_ASCII 0x34 ~angelos~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%arkush.cre~ ~override~
    SAY NAME1 @385
    SAY NAME2 @385
    WRITE_ASCII 0x34 ~arkushs~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%brielb.cre~ ~override~
    SAY NAME1 @386
    SAY NAME2 @386
    WRITE_ASCII 0x34 ~briels~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%deltan.cre~  ~override~
                ~%tutu_var%deltan2.cre~ ~override~
    WRITE_ASCII 0x34 ~eltans~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%gorion.cre~  ~override~
                ~%tutu_var%gorion3.cre~ ~override~
    WRITE_ASCII 0x34 ~gorions~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%sarevo.cre~  ~override~
                ~%tutu_var%sarevo2.cre~ ~override~
    WRITE_ASCII 0x34 ~sarevoks~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%scar.cre~ ~override~
    WRITE_ASCII 0x34 ~scars~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%vail.cre~ ~override~
    WRITE_ASCII 0x34 ~vails~//  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%volo.cre~ ~override~
    WRITE_ASCII 0x34 ~volos~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%tazok.cre~  ~override~
                ~%tutu_var%tazok2.cre~ ~override~
    WRITE_ASCII 0x34 ~tazoks~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%chase.cre~  ~override~
    WRITE_ASCII 0x34 ~chases~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%dryad.cre~  ~override~
    WRITE_ASCII 0x34 ~dryadcps~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%fireb1.cre~ ~override~
                ~%tutu_var%firebe.cre~ ~override~
    WRITE_ASCII 0x34 ~fbehs~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%keeper.cre~ ~override~
    WRITE_ASCII 0x34 ~keepers~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%silke.cre~ ~override~
    WRITE_ASCII 0x34 ~silkes~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%gatewa.cre~ ~override~
                ~%tutu_var%gatewa2.cre~ ~override~
    WRITE_ASCII 0x34 ~gatewars~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%joia.cre~ ~override~
    WRITE_ASCII 0x34 ~joias~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%marl.cre~ ~override~
    WRITE_ASCII 0x34 ~marls~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%perdue.cre~ ~override~
    WRITE_ASCII 0x34 ~perdues~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%winski.cre~ ~override~
    WRITE_ASCII 0x34 ~winskis~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%winski2.cre~ ~override~
    WRITE_ASCII 0x34 ~winskis~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%taerom.cre~ ~override~
    WRITE_ASCII 0x34 ~taeroms~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%tarnes.cre~ ~override~
    WRITE_ASCII 0x34 ~tarness~ #8 //  small portrait
  BUT_ONLY_IF_IT_CHANGES

  /* Miloch's Gnome Portraits */
  COPY_EXISTING ~%tutu_var%bently.cre~ ~override~ // Bentley Mirrorshade
    WRITE_ASCII 0x34 ~bentlys~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%galtok.cre~ ~override~ // Galtok (in Nashkel Mines)
    WRITE_ASCII 0x34 ~galtoks~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%gellan.cre~ ~override~ // Gellana Mirrorshade (in FAI Temple of Wisdom)
    WRITE_ASCII 0x34 ~gellans~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%hafiz.cre~ ~override~ // Hafiz (in Gibberling Mountains)
    WRITE_ASCII 0x34 ~hafizs~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%landri.cre~ ~override~ // Landrin (in FAI L3)
    WRITE_ASCII 0x34 ~landris~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%madarc.cre~ ~override~ // Mad Arcand (in Shipwreck's Coast)
    WRITE_ASCII 0x34 ~madarcs~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%mutami.cre~ ~override~ // Mutamin (in Mutamin's Garden)
    WRITE_ASCII 0x34 ~mutamis~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_scriptbg%neb.cre~ ~override~ // Neb (in SW Baldur's Gate FF HQ L1)
    WRITE_ASCII 0x34 ~nebs~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%pheirk.cre~ ~override~ // Pheirkas (in NW Baldur's Gate)
    WRITE_ASCII 0x34 ~pheirks~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%sarhed.cre~ ~override~ // Sarhedra (in Lonely Peaks)
    WRITE_ASCII 0x34 ~sarheds~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES
  COPY_EXISTING ~%tutu_var%unshey.cre~ ~override~ // Unshey (in Friendly Arm Inn L2)
    WRITE_ASCII 0x34 ~unsheys~ #8 // Small portrait
  BUT_ONLY_IF_IT_CHANGES

  ACTION_IF (FILE_EXISTS_IN_GAME ~X#BG1NPCPhase1.G3~) THEN BEGIN
  /* Phase2 Quest NPCs */
    COPY_EXISTING ~x#drizzt.cre~ ~override~
      WRITE_ASCII 0x34 ~drizzts~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#kaband.cre~ ~override~
      WRITE_ASCII 0x34 ~kabands~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#david.cre~ ~override~
      WRITE_ASCII 0x34 ~davids~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#cru11.cre~ ~override~
                  ~x#chop.cre~ ~override~
      WRITE_ASCII 0x34 ~ladyogs~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#assi01.cre~ ~override~
                  ~x#assi02.cre~ ~override~
                  ~x#assi03.cre~ ~override~
                  ~x#assi04.cre~ ~override~
                  ~x#assi05.cre~ ~override~
                  ~x#assi06.cre~ ~override~
                  ~x#assi07.cre~ ~override~
                  ~x#assi08.cre~ ~override~
                  ~x#assi09.cre~ ~override~
                  ~x#assi10.cre~ ~override~
                  ~x#assi11.cre~ ~override~
      WRITE_ASCII 0x34 ~asststs~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#garar.cre~ ~override~
      WRITE_ASCII 0x34 ~garars~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#amelia.cre~ ~override~
      WRITE_ASCII 0x34 ~amelias~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#natan.cre~ ~override~
      WRITE_ASCII 0x34 ~natans~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#rashel.cre~ ~override~
      WRITE_ASCII 0x34 ~rashels~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~p#imanel.cre~ ~override~
      WRITE_ASCII 0x34 ~XIMANS~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#seasn.cre~ ~override~
      WRITE_ASCII 0x34 ~seas~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#keth.cre~ ~override~
      WRITE_ASCII 0x34 ~keths~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#dgnlg1.cre~ ~override~
                  ~x#dgnle1.cre~ ~override~
      WRITE_ASCII 0x34 ~gnolls~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#lakep1.cre~ ~override~
      WRITE_ASCII 0x34 ~lpb1s~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#lakep2.cre~ ~override~
      WRITE_ASCII 0x34 ~lpb2s~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#lakep3.cre~ ~override~
      WRITE_ASCII 0x34 ~lpb3s~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#xzfsp1.cre~ ~override~
      WRITE_ASCII 0x34 ~fspirits~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#xzfsp2.cre~ ~override~
                  ~x#xzfsp3.cre~ ~override~
      WRITE_ASCII 0x34 ~greens~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#black.cre~ ~override~
      WRITE_ASCII 0x34 ~blacks~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#storm.cre~ ~override~
      WRITE_ASCII 0x34 ~storms~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#zosya.cre~ ~override~
      WRITE_ASCII 0x34 ~zosyas~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#xzgu01.cre~ ~override~
      WRITE_ASCII 0x34 ~capffs~ #8 // small portrait
    COPY_EXISTING ~x#xzgu02.cre~ ~override~
      WRITE_ASCII 0x34 ~xzgus~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#xzgu03.cre~ ~override~
      WRITE_ASCII 0x34 ~xzgus~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#garwyl.cre~ ~override~
      WRITE_ASCII 0x34 ~mercuts~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#garz01.cre~ ~override~
      WRITE_ASCII 0x34 ~garzoms~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#garz02.cre~ ~override~
      WRITE_ASCII 0x34 ~garzom2s~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#garz03.cre~ ~override~
      WRITE_ASCII 0x34 ~garzom3s~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#garz04.cre~ ~override~
      WRITE_ASCII 0x34 ~garzom4s~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#andart.cre~ ~override~
      WRITE_ASCII 0x34 ~andars~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#beador.cre~ ~override~
                  ~x#beado1.cre~ ~override~
      WRITE_ASCII 0x34 ~beadors~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#mareth.cre~ ~override~
      WRITE_ASCII 0x34 ~marethas~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~x#shdr8a.cre~ ~override~
      WRITE_ASCII 0x34 ~shdr8as~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
  END

  /*ToSC only portraits: */
  ACTION_IF GAME_IS ~tutu_totsc bgt bgee~ THEN BEGIN //  if TotSC is installed
    COPY_EXISTING ~%tutu_var%hurgan.cre~ ~override~
      WRITE_ASCII 0x34 ~hurgans~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%ulraun.cre~ ~override~
      WRITE_ASCII 0x34 ~ulraunts~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%delain.cre~  ~override~
                  ~%tutu_var%delain2.cre~ ~override~
      WRITE_ASCII 0x34 ~delas~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%durlyl.cre~  ~override~
                  ~%tutu_var%durlyl2.cre~ ~override~
      WRITE_ASCII 0x34 ~durls~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%karoug.cre~ ~override~
      WRITE_ASCII 0x34 ~karougs~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%kaisha.cre~ ~override~
                  ~%tutu_var%kaish2.cre~ ~override~
      WRITE_ASCII 0x34 ~kashias~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%mendas.cre~  ~override~
                  ~%tutu_var%mendas2.cre~ ~override~
                  ~%tutu_var%mendas3.cre~ ~override~
      WRITE_ASCII 0x34 ~mendas~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_scripts%handal2.cre~ ~override~
      WRITE_ASCII 0x34 ~shands~ #8 //  small portrait
    BUT_ONLY_IF_IT_CHANGES

    // Miloch's TotSC additions
    COPY_EXISTING ~%tutu_var%avarice.cre~ ~override~ // Avarice (in Durlag's Tower D1)
      WRITE_ASCII 0x34 ~avarices~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%baresh.cre~ ~override~ // Baresh (in Ulgoth's Beard)
      WRITE_ASCII 0x34 ~bareshs~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%bayard.cre~ ~override~ // Bayard (in Durlag's Cellar)
      WRITE_ASCII 0x34 ~bayards~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_scriptb%ullrush.cre~ ~override~ // Bullrush (in Durlag's Tower D3)
      WRITE_ASCII 0x34 ~bullruss~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%calaha.cre~ ~override~ // Calahan (in Ulgoth's Beard)
      WRITE_ASCII 0x34 ~calahas~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%claird.cre~ ~override~ // Clair De'Lain (in Durlag's Tower D4)
      WRITE_ASCII 0x34 ~clairds~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%daitel.cre~ ~override~ // Daitel (Ghost - in Durlag's Tower L3)
      WRITE_ASCII 0x34 ~daitels~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%dalton.cre~ ~override~ // Dalton (Ghost - in Durlag's Tower L4)
      WRITE_ASCII 0x34 ~daltons~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%deathk.cre~  ~override~ // Demonknight (in Durlag's Tower)
                  ~%tutu_var%deathk1.cre~ ~override~
      WRITE_ASCII 0x34 ~deathks~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%delsvir.cre~ ~override~ // Delsvirtanyon (in Ulgoth's Beard)
      WRITE_ASCII 0x34 ~delsvirs~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%dopdur1.cre~ ~override~ // Durlag (Doppleganger - in Durlag's Tower D2)
                  ~%tutu_var%dopdur2.cre~ ~override~
                  ~%tutu_var%dopdur3.cre~ ~override~
      WRITE_ASCII 0x34 ~dopdurs~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%durlagt.cre~ ~override~ // Durlag (Ghost - in Durlag's Tower D4)
      WRITE_ASCII 0x34 ~durlags~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_scriptd%ursword.cre~ ~override~ // Durlag's Pride (in Durlag's Tower D1)
      WRITE_ASCII 0x34 ~durswors~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%dushai.cre~ ~override~ // Dushai (in Ulgoth's Beard)
      WRITE_ASCII 0x34 ~dushais~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%erdane.cre~ ~override~ // Erdane (in Durlag's Tower)
      WRITE_ASCII 0x34 ~erdanes~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%fear.cre~ ~override~ // Fear (in Durlag's Tower D1)
      WRITE_ASCII 0x34 ~fears~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%fenrus.cre~ ~override~ // Fenrus Boulon (in Ulgoth's Beard)
      WRITE_ASCII 0x34 ~fenruss~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%galken.cre~ ~override~ // Galkin (in Ulgoth's Beard)
      WRITE_ASCII 0x34 ~galkens~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%grael.cre~ ~override~ // Grael (in Durlag's Tower D4)
      WRITE_ASCII 0x34 ~graels~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%hack.cre~ ~override~ // Hack (in Durlag's Tower D3)
      WRITE_ASCII 0x34 ~hacks~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%ike.cre~  ~override~ // Ike (in Ulgoth's Beard)
                  ~%tutu_var%ike2.cre~ ~override~ // Ike (in Durlag's Tower)
      WRITE_ASCII 0x34 ~ikes~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%isla.cre~ ~override~ // Islanne (in Durlag's Tower D4)
      WRITE_ASCII 0x34 ~islanns~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%kirinh.cre~ ~override~ // Kirinhale (in Durlag's Tower L4)
      WRITE_ASCII 0x34 ~kirinhs~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%love.cre~ ~override~ // Love (in Durlag's Tower D1)
      WRITE_ASCII 0x34 ~loves~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%meiala.cre~ ~override~ // Meiala (in Durlag's Tower D3)
      WRITE_ASCII 0x34 ~meialas~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_scriptm%oorlock.cre~ ~override~ // Moorlock (in Durlag's Tower D3)
      WRITE_ASCII 0x34 ~moorlocs~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%pride.cre~ ~override~ // Pride (in Durlag's Tower D1)
      WRITE_ASCII 0x34 ~prides~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%riggilo.cre~ ~override~ // Riggilo (in Durlag's Tower L3)
      WRITE_ASCII 0x34 ~riggilos~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%tarnor.cre~ ~override~ // Tarnor (in Durlag's Tower D3)
      WRITE_ASCII 0x34 ~tarnors~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%tellan.cre~ ~override~ // Tellan (in Ice Island L1)
      WRITE_ASCII 0x34 ~tellans~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
    COPY_EXISTING ~%tutu_var%therel.cre~ ~override~ // Therella (in Ulgoth's Beard)
      WRITE_ASCII 0x34 ~therels~ #8 // small portrait
    BUT_ONLY_IF_IT_CHANGES
  END

/* BEGIN PHASE III BG1NPC PROJECT */

/* AJANTIS ROMANCE */
BEGIN @1016 /* The BG1 NPC Project: Ajantis Romance Core (teen content) */
  GROUP @1010  /* The BG1 NPC Project: Romances */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  COPY ~BG1NPC/Core/X#component.xx~ ~override/X#AjantisRomance.G3~
  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

  /* items */
  COPY ~BG1NPC/Phase3/AJROM/ITM/X#AJRONE.itm~ ~override~
    SAY NAME1 @477
    SAY NAME2 @477
    SAY UNIDENTIFIED_DESC @478
    SAY DESC @478

  COPY ~BG1NPC/Phase3/AJROM/BAM~ ~override~
  COPY ~BG1NPC/Phase3/AJROM/ITM/X#AJRORI.itm~ ~override~
    SAY NAME1 @479
    SAY NAME2 @479
    SAY UNIDENTIFIED_DESC @480
    SAY DESC @480

  /* creatures */
  COPY ~BG1NPC/Phase3/AJROM/cre/x#ajdoug.cre~ ~override~ // Douglas
    SAY NAME1 @481
    SAY NAME2 @481
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    PATCH_IF GAME_IS ~bgee~ BEGIN /* BGEE: Use HELMP soundset */
    	SAY INITIAL_MEETING #4976 // HELMP01
    	SAY BATTLE_CRY1 #4976 // HELMP01
    	SAY DAMAGE #5469 // HELMP05
    	SAY DYING #5470 // HELMP06
    	SAY SELECT_COMMON1 #4977 // HELMP02
    	SAY SELECT_COMMON2 #4976 // HELMP01
	END ELSE BEGIN /* Tutu, BGT */
    	SAY INITIAL_MEETING @482
    	SAY BATTLE_CRY1 @483
    	SAY DAMAGE @484
    	SAY DYING @485
    	SAY SELECT_COMMON1 @486
    	SAY SELECT_COMMON2 @482
    	SAY SELECT_ACTION4 @487
    END

  /* Ajantis' romance timer */
  PRINT @1117

  PRINT @1102

  OUTER_SPRINT ~ajantimer~ ~placeholder_value~
  OUTER_WHILE (!(IS_AN_INT ~ajantimer~) OR (~ajantimer~ > 0x5) OR (~ajantimer~ < 0x1)) BEGIN
    PRINT @1108
    ACTION_READLN ~ajantimer~
  END
        ACTION_IF ("ajantimer" = 1) THEN BEGIN
        APPEND ~gtimes.ids~ ~3600 AJROM_TIMER~
        PRINT @1109
        END
        ACTION_IF ("ajantimer" = 2) THEN BEGIN
        APPEND ~gtimes.ids~ ~2700 AJROM_TIMER~
        PRINT @1110
        END
        ACTION_IF ("ajantimer" = 3) THEN BEGIN
        APPEND ~gtimes.ids~ ~1800 AJROM_TIMER~
        PRINT @1111
        END
        ACTION_IF ("ajantimer" = 4) THEN BEGIN
        APPEND ~gtimes.ids~ ~900 AJROM_TIMER~
        PRINT @1112
        END
        ACTION_IF ("ajantimer" = 5) THEN BEGIN
        APPEND ~gtimes.ids~ ~5400 AJROM_TIMER~
        PRINT @1113
        END

  /* cutscenes */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCUT.BAF~

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/X#AJROADD_PR.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/x#ajantisLTs_PR.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/x#ajantisIniFlirts_PR.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/x#ajantisNPC_talks_PR.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/x#ajantisBhaalLTs.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/x#ajantisDreamLTs.D~

  ACTION_IF GAME_IS ~tutu~ BEGIN  // Tutu without TotSC
  	COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/x#ajantisAddLTs_PR_noToSC.D~
  END ELSE ACTION_IF GAME_IS ~bgee~ BEGIN  // BGEE
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/x#ajantisAddLTs_PR_BGEE.D~
      USING ~BG1NPC/TRA/%LANGUAGE%/x#ajantisAddLTs_PR.tra~
  END ELSE BEGIN   // Tutu+TotSC or BGT
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/dlg/x#ajantisAddLTs_PR.D~
  END
  
  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/AJROM/baf/X#AJDOUG.BAF~

  EXTEND_TOP  ~%AJANTIS_BCS%.BCS~ ~BG1NPC/Phase3/AJROM/baf/X#AJROM.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_var%AJANTD.BCS~ ~BG1NPC/Phase3/AJROM/baf/X#AJROD.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%AJANTIS_BCS%.BCS~ ~BG1NPC/Phase3/AJROM/baf/X#AjantisRomNPC.baf~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%AJANTIS_BCS%.BCS~ ~BG1NPC/Phase3/AJROM/baf/X#AjantisIniFlirts.baf~
    EVALUATE_BUFFER

  /* BGT, BGEE compatability macro */
  ACTION_IF GAME_IS ~bgt bgee~ THEN BEGIN
  	COPY_EXISTING ~x#ajdoug.cre~ ~override~
        PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
        	/* LAUNCH_PATCH_MACRO ~tutu_items_to_bgt~ */
			LAUNCH_PATCH_MACRO ~convert_tutu_items_bgt_bgee~
        END
  END

  /* Add Portraits if NJNPC Portraits was chosen */
  ACTION_IF FILE_EXISTS_IN_GAME ~X#NJNPCPortrait.G3~ THEN BEGIN
    COPY_EXISTING ~x#ajdoug.cre~ ~override~
      WRITE_ASCII 0x34 ~ajdougs~ #8 // small portrait
	  BUT_ONLY_IF_IT_CHANGES
  END

/* BRANWEN ROMANCE */
BEGIN @1014  /* The BG1 NPC Project: Branwen's Romance Core (teen content) */
  GROUP @1010  /* The BG1 NPC Project: Romances */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  COPY ~BG1NPC/Core/X#component.xx~ ~override/X#BranwenRomance.G3~
  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

  /* Branwen romance timer */
  PRINT @1106

  PRINT @1102

  OUTER_SPRINT ~brantimer~ ~placeholder_value~
  OUTER_WHILE (!(IS_AN_INT ~brantimer~) OR (~brantimer~ > 0x5) OR (~brantimer~ < 0x1)) BEGIN
    PRINT @1108
    ACTION_READLN ~brantimer~
  END
        ACTION_IF ("brantimer" = 1) THEN BEGIN
        APPEND ~gtimes.ids~ ~3600 BRROM_TIMER~
        PRINT @1109
        END
        ACTION_IF ("brantimer" = 2) THEN BEGIN
        APPEND ~gtimes.ids~ ~2700 BRROM_TIMER~
        PRINT @1110
        END
        ACTION_IF ("brantimer" = 3) THEN BEGIN
        APPEND ~gtimes.ids~ ~1800 BRROM_TIMER~
        PRINT @1111
        END
        ACTION_IF ("brantimer" = 4) THEN BEGIN
        APPEND ~gtimes.ids~ ~900 BRROM_TIMER~
        PRINT @1112
        END
        ACTION_IF ("brantimer" = 5) THEN BEGIN
        APPEND ~gtimes.ids~ ~5400 BRROM_TIMER~
        PRINT @1113
        END

  /* script */
    EXTEND_TOP  ~%BRANWEN_BCS%.BCS~ ~BG1NPC/Phase3/BRROM/baf/P#BRROM.baf~
      EVALUATE_BUFFER
    EXTEND_TOP   ~%tutu_var%BRANWD.BCS~ ~BG1NPC/Phase3/BRROM/baf/P#BRROD.baf~
      EVALUATE_BUFFER

  /* dialogue */
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/BRROM/dlg/P#BRLT.D~

/* CORAN ROMANCE */
BEGIN @1011  /* The BG1 NPC Project: Coran's Romance Core (adult content) */
  GROUP @1010  /* The BG1 NPC Project: Romances */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  COPY ~BG1NPC/Core/X#component.xx~ ~override/X#CoranRomance.G3~
  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200
  /* items */
  COPY ~BG1NPC/Phase3/COROM/ITM/X#CFLOW.itm~ ~override~
    SAY NAME1 @389
    SAY NAME2 @390
    SAY UNIDENTIFIED_DESC @391
    SAY DESC @392

  COPY_EXISTING ~AMUL04.itm~ ~override/X#CMOON.itm~
    SAY NAME1 @393
    SAY NAME2 @393
    SAY UNIDENTIFIED_DESC @394
    SAY DESC @394

  /* creatures */
  COPY_EXISTING ~%tutu_var%girba2.cre~ ~override/x#namara.cre~
    SAY NAME1 @216
    SAY NAME2 @216
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @395
    SAY DAMAGE @396
    SAY DYING @397
    SAY SELECT_COMMON1 @395
    SAY DIALOGUE_HOSTILE @398
    SAY DIALOGUE_DEFAULT @395
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32 //  death variable

  /* Coran's romance timer */
  PRINT @1103

  PRINT @1102

  OUTER_SPRINT ~corantimer~ ~placeholder_value~
  OUTER_WHILE (!(IS_AN_INT ~corantimer~) OR (~corantimer~ > 0x5) OR (~corantimer~ < 0x1)) BEGIN
    PRINT @1108
    ACTION_READLN ~corantimer~
  END
        ACTION_IF ("corantimer" = 1) THEN BEGIN
        APPEND ~gtimes.ids~ ~3600 COROM_TIMER~
        PRINT @1109
        END
        ACTION_IF ("corantimer" = 2) THEN BEGIN
        APPEND ~gtimes.ids~ ~2700 COROM_TIMER~
        PRINT @1110
        END
        ACTION_IF ("corantimer" = 3) THEN BEGIN
        APPEND ~gtimes.ids~ ~1800 COROM_TIMER~
        PRINT @1111
        END
        ACTION_IF ("corantimer" = 4) THEN BEGIN
        APPEND ~gtimes.ids~ ~900 COROM_TIMER~
        PRINT @1112
        END
        ACTION_IF ("corantimer" = 5) THEN BEGIN
        APPEND ~gtimes.ids~ ~5400 COROM_TIMER~
        PRINT @1113
        END

  /* Flirt dialogue compilation */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/COROM/dlg/P#CIFLIRT.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/COROM/dlg/P#CRNPC.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/COROM/dlg/P#CORLT.D~

  /* Flirt scripts */
  EXTEND_TOP  ~%tutu_var%CORAND.BCS~ ~BG1NPC/Phase3/COROM/baf/P#CORAND.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%CORAN_BCS%.BCS~   ~BG1NPC/Phase3/COROM/baf/P#COROM.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%CORAN_BCS%.BCS~   ~BG1NPC/Phase3/COROM/baf/P#COFLIRT.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%ALORA_BCS%.BCS~   ~BG1NPC/Phase3/COROM/baf/P#CRAL.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%ELDOTH_BCS%.BCS~  ~BG1NPC/Phase3/COROM/baf/P#CREL.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%FALDORN_BCS%.BCS~   ~BG1NPC/Phase3/COROM/baf/P#CRFA.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%IMOEN_BCS%.BCS~  ~BG1NPC/Phase3/COROM/baf/P#CRIM.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%SHARTEEL_BCS%.BCS~ ~BG1NPC/Phase3/COROM/baf/P#CRSH.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%VICONIA_BCS%.BCS~ ~BG1NPC/Phase3/COROM/baf/P#CRVI.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP ~%XZAR_BCS%.BCS~    ~BG1NPC/Phase3/COROM/baf/P#CRXZ.BAF~
    EVALUATE_BUFFER

/* DYNAHEIR ROMANCE */
BEGIN @1012  /* The BG1 NPC Project: Dynaheir's Romance Core (teen content) */
GROUP @1010  /* The BG1 NPC Project: Romances */
REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  COPY ~BG1NPC/Core/X#component.xx~ ~override/X#DynaheirRomance.G3~
  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

    /* creatures */
    ACTION_IF NOT FILE_EXISTS_IN_GAME ~x#winski.cre~ THEN BEGIN
      COPY_EXISTING ~%tutu_var%winski2.cre~ ~override~
        WRITE_EVALUATED_ASCII 0x2cc ~%tutu_var%WINSKI~ #8
        WRITE_ASCII 0x280 ~winski2~ #32
      COPY_EXISTING ~%tutu_var%winski.cre~ ~override/x#winski.cre~
    END

  COPY ~BG1NPC/Phase3/DYROM/cre/x#joni.cre~ ~override~
    SAY NAME1 @400
    SAY NAME2 @400
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY BATTLE_CRY1 @401
    SAY BATTLE_CRY2 @402
    SAY DAMAGE @403
    SAY DYING @404
    SAY SELECT_COMMON1 @405
    SAY SELECT_ACTION4 @406
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#bodhi.cre~ ~override~
    SAY NAME1 @407
    SAY NAME2 @407
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* Use VAMPF soundset for BGEE */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY BATTLE_CRY1 @738 // [VAMPF02]
    	SAY ATTACK1 @739 // [VAMPF03]
    	SAY ATTACK2 @740 // [VAMPF04]
    	SAY DAMAGE @742 // [VAMPF06]
    	SAY DYING @743 // [VAMPF07]
    	SAY SELECT_COMMON1 @737 // [VAMPF01]
    	SAY SELECT_COMMON2 @741 // [VAMPF05]
	END ELSE BEGIN /* For Tutu, BGT */
    	SAY BATTLE_CRY1 @408
    	SAY BATTLE_CRY2 @409
    	SAY DAMAGE @410
   		SAY DYING @411
   		SAY SELECT_COMMON1 @412
   	END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#lassa.cre~ ~override~
    SAY NAME1 @413
    SAY NAME2 @413
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* Use VAMPP soundset for BGEE */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY BATTLE_CRY1 @745 // [VAMPP02]
    	SAY ATTACK1 @746 // [VAMPP03]
    	SAY ATTACK2 @747 // [VAMPP04]
    	SAY DAMAGE @749 // [VAMPP06]
    	SAY DYING @750 // [VAMPP07]
    	SAY SELECT_COMMON1 @744 // [VAMPP01]
    	SAY SELECT_COMMON2 @748 // [VAMPP05]
	END ELSE BEGIN /* For Tutu, BGT */
    	SAY INITIAL_MEETING @414
    	SAY UNHAPPY_BREAKING @415
    	SAY BATTLE_CRY1 @416
    	SAY BATTLE_CRY2 @417
    	SAY DAMAGE @418
    	SAY DYING @419
    	SAY SELECT_COMMON1 @414
    	SAY SELECT_COMMON2 @420
    	SAY SELECT_COMMON3 @421
    	SAY SELECT_COMMON4 @422
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#tanov.cre~ ~override~
    SAY NAME1 @423
    SAY NAME2 @423
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* Use VAMPF soundset for BGEE */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY BATTLE_CRY1 @738 // [VAMPF02]
    	SAY ATTACK1 @739 // [VAMPF03]
    	SAY ATTACK2 @740 // [VAMPF04]
    	SAY DAMAGE @742 // [VAMPF06]
    	SAY DYING @743 // [VAMPF07]
    	SAY SELECT_COMMON1 @737 // [VAMPF01]
    	SAY SELECT_COMMON2 @741 // [VAMPF05]
	END ELSE BEGIN /* For Tutu, BGT */
	    SAY INITIAL_MEETING @424
    	SAY UNHAPPY_BREAKING @425
    	SAY BATTLE_CRY1 @426
    	SAY BATTLE_CRY2 @427
    	SAY DAMAGE @428
    	SAY DYING @419
    	SAY SELECT_COMMON1 @424
    	SAY SELECT_COMMON2 @429
    	SAY SELECT_COMMON3 @430
    	SAY SELECT_COMMON4 @422
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#valen.cre~ ~override~
    SAY NAME1 @432
    SAY NAME2 @432
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* Use VAMPF soundset for BGEE */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY BATTLE_CRY1 @738 // [VAMPF02]
    	SAY ATTACK1 @739 // [VAMPF03]
    	SAY ATTACK2 @740 // [VAMPF04]
    	SAY DAMAGE @742 // [VAMPF06]
    	SAY DYING @743 // [VAMPF07]
    	SAY SELECT_COMMON1 @737 // [VAMPF01]
    	SAY SELECT_COMMON2 @741 // [VAMPF05]
	END ELSE BEGIN /* For Tutu, BGT */
    	SAY BATTLE_CRY1 @433
    	SAY DAMAGE @434
    	SAY DYING @435
    	SAY SELECT_COMMON1 @436
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#ulvar.cre~ ~override~
    SAY NAME1 @437
    SAY NAME2 @437
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~

  COPY_EXISTING ~BG1NPC/Phase3/DYROM/cre/x#ulvar.cre~ ~override/x#cutva1.cre~
                ~BG1NPC/Phase3/DYROM/cre/x#ulvar.cre~ ~override/x#cutva2.cre~
                ~BG1NPC/Phase3/DYROM/cre/x#ulvar.cre~ ~override/x#cutva3.cre~
                ~BG1NPC/Phase3/DYROM/cre/x#ulvar.cre~ ~override/x#cutva4.cre~
    SAY NAME1 @438
    SAY NAME2 @438
    WRITE_ASCII 0x248 ~X#CUTVAM~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32 //  death variable

  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYMEN.SPL~ ~override~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#nell.cre~ ~override~
    SAY NAME1 @439
    SAY NAME2 @439
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @440
    SAY BATTLE_CRY1 @441
    SAY BATTLE_CRY2 @441
    SAY BATTLE_CRY3 @441
    SAY BATTLE_CRY4 @441
    SAY BATTLE_CRY5 @441
    SAY ATTACK1 @441
    SAY ATTACK2 @441
    SAY DAMAGE @37
    SAY DYING @38
    SAY SELECT_COMMON1 @442
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#madr.cre~ ~override~
    SAY NAME1 @443
    SAY NAME2 @443
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY BATTLE_CRY1 @444
    SAY BATTLE_CRY2 @444
    SAY BATTLE_CRY3 @444
    SAY BATTLE_CRY4 @444
    SAY BATTLE_CRY5 @441
    SAY ATTACK1 @444
    SAY ATTACK2 @444
    SAY DAMAGE @445
    SAY DYING @446
    SAY SELECT_COMMON1 @447
    SAY SELECT_COMMON2 @447
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#bhet.cre~ ~override~
    SAY NAME1 @448
    SAY NAME2 @448
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY BATTLE_CRY1 @449
    SAY BATTLE_CRY2 @449
    SAY BATTLE_CRY3 @449
    SAY BATTLE_CRY4 @449
    SAY BATTLE_CRY5 @449
    SAY ATTACK1 @449
    SAY ATTACK2 @449
    SAY DAMAGE @450
    SAY DYING @451
    SAY SELECT_COMMON1 @452
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#sveet.cre~ ~override~
    SAY NAME1 @453
    SAY NAME2 @453
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @454
    SAY BATTLE_CRY1 @449
    SAY BATTLE_CRY2 @449
    SAY BATTLE_CRY3 @449
    SAY BATTLE_CRY4 @449
    SAY BATTLE_CRY5 @449
    SAY ATTACK1 @449
    SAY ATTACK2 @449
    SAY DAMAGE @450
    SAY DYING @451
    SAY SELECT_COMMON1 @452
    LAUNCH_PATCH_MACRO ~bg1npc_cre_source_res~

  COPY ~BG1NPC/Phase3/DYROM/cre/x#dfake1.cre~ ~override~
    SAY NAME1 @456
    SAY NAME2 @456
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @457
    SAY BATTLE_CRY1 @458
    SAY BATTLE_CRY2 @458
    SAY BATTLE_CRY3 @458
    SAY BATTLE_CRY4 @458
    SAY BATTLE_CRY5 @458
    SAY ATTACK1 @458
    SAY ATTACK2 @458
    SAY DAMAGE @459
    SAY DYING @460
    SAY SELECT_COMMON1 @461
    SAY SELECT_COMMON2 @461
    SAY SELECT_COMMON3 @461
    SAY SELECT_COMMON4 @461
    SAY SELECT_COMMON5 @461
    SAY SELECT_COMMON6 @461
    SAY SELECT_ACTION1 @461
    SAY SELECT_ACTION2 @461
    SAY SELECT_ACTION3 @461
    SAY SELECT_ACTION4 @461
    SAY SELECT_ACTION5 @461
    SAY SELECT_ACTION6 @461
    SAY SELECT_ACTION7 @461
    WRITE_LONG BIO (BNOT 0x0)
    WRITE_ASCII 0x248 ~X#DYNA~ #8 //  override script
    WRITE_ASCII 0x280 ~dynacutscene~ #32 //  death variable
    WRITE_ASCII 0x2CC ~X#DYNA~ #8 //  dialog
    PATCH_IF GAME_IS ~bgee bgt~ BEGIN
		WRITE_ASCII 0x34 ~DYNAHEIS~ #8  // small portrait
		WRITE_ASCII 0x3C ~DYNAHEIL~ #8  // large portrait
        WRITE_ASCII 0x268 ~DPLAYER~ #8
        WRITE_ASCII 0x260 ~WTRUNSGT~ #8
    END

  COPY ~BG1NPC/Phase3/DYROM/cre/x#setta.cre~ ~override~
    SAY NAME1 @462
    SAY NAME2 @462
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* FEMER soundset not in BGEE.  Use other general female sounds */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY INITIAL_MEETING @442
    	SAY DAMAGE @445
    	SAY DYING @446
    	SAY SELECT_COMMON1 @447
    	SAY SELECT_COMMON2 @442
	END ELSE BEGIN /* Tutu, BGT */
    	SAY INITIAL_MEETING @463
    	SAY DAMAGE @464
    	SAY DYING @465
    	SAY SELECT_COMMON1 @466
    	SAY SELECT_COMMON2 @467
    END
    WRITE_EVALUATED_ASCII 0x280 ~%SOURCE_RES%~ #32 //  death variable
    WRITE_EVALUATED_ASCII 0x2CC ~%SOURCE_RES%~ #8 //  dialog
      PATCH_IF GAME_IS ~bgee bgt~ BEGIN
        WRITE_ASCII 0x268 ~WTRUNSGT~ #8
        WRITE_ASCII 0x258 ~RUNENEMY~ #8
        WRITE_ASCII 0x250 ~MERCH2~ #8
        WRITE_ASCII 0x248 ~SHOUT~ #8
      END

  /* items */
  COPY_EXISTING ~%tutu_var%ghoult.itm~ ~override~ // Fix droppable Ghoul Touch
    PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
      READ_BYTE 0x18 fl // Flags
      PATCH_IF ((fl BAND 0b00000100) = 0b00000100) BEGIN // If movable
        WRITE_BYTE 0x18 (fl BAND 0b11110011) // Make unmovable
      END
    END
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~%tutu_scriptbg%SCRL3I.itm~ ~override/X#DYOATH.itm~
    SAY NAME1 @468
    SAY NAME2 @468
    SAY UNIDENTIFIED_DESC @469
    SAY DESC @469

  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYPORE.BAM~ ~override~
  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYPORE.itm~ ~override~
    SAY NAME1 @470
    SAY NAME2 @470
    SAY UNIDENTIFIED_DESC @471
    SAY DESC @471

  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYPORF.BAM~ ~override~
  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYPORF.itm~ ~override~
    SAY NAME1 @470
    SAY NAME2 @470
    SAY UNIDENTIFIED_DESC @471
    SAY DESC @471

  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYPORO.BAM~ ~override~
  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYPORO.itm~ ~override~
    SAY NAME1 @470
    SAY NAME2 @470
    SAY UNIDENTIFIED_DESC @471
    SAY DESC @471

  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYPORR.BAM~ ~override~
  COPY ~BG1NPC/Phase3/DYROM/ITM/X#DYPORR.itm~ ~override~
    SAY NAME1 @470
    SAY NAME2 @470
    SAY UNIDENTIFIED_DESC @471
    SAY DESC @471

  /* Add BG2 items missing from BGEE */
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN  
  /* Wondrous Gauntlets */
	COPY ~bg1npc/bgee/itm/brac25.itm~ ~override~ 
  		SAY NAME2 @6000
  		SAY DESC @6001

  /* Items for Dynaheir romance endgame cutscene */
  	COPY ~bg1npc/bgee/itm/minhp20.itm~ ~override~   /* For x#bodhi */
	COPY ~bg1npc/bgee/itm/vamp.itm~ ~override~      /* For x#cutva[1-4], x#lassa, x#ulvar */
	COPY ~bg1npc/bgee/itm/vamp1.itm~ ~override~     /* For x#valen */
	COPY ~bg1npc/bgee/itm/vamp2.itm~ ~override~     /* For x#tanov */
	COPY ~bg1npc/bgee/itm/vamp3.itm~ ~override~     /* For x#bodhi */
	COPY ~bg1npc/bgee/itm/vampreg2.itm~ ~override~  /* For x#bodhi */
	
	/* Soundset for x#joni */
	COPY ~bg1npc/bgee/wav/%LANGUAGE%/IRENIC01.wav~ ~override~
	COPY ~bg1npc/bgee/wav/%LANGUAGE%/IRENIC03.wav~ ~override~
	COPY ~bg1npc/bgee/wav/%LANGUAGE%/IRENIC04.wav~ ~override~
	COPY ~bg1npc/bgee/wav/%LANGUAGE%/IRENIC05.wav~ ~override~
	COPY ~bg1npc/bgee/wav/%LANGUAGE%/IRENIC06.wav~ ~override~
  END
  
  /* Dynaheir's romance timer */
  PRINT @1104

  PRINT @1102

  OUTER_SPRINT ~dynatimer~ ~placeholder_value~
  OUTER_WHILE (!(IS_AN_INT ~dynatimer~) OR (~dynatimer~ > 0x5) OR (~dynatimer~ < 0x1)) BEGIN
    PRINT @1108
    ACTION_READLN ~dynatimer~
  END
        ACTION_IF ("dynatimer" = 1) THEN BEGIN
        APPEND ~gtimes.ids~ ~3600 DYROM_TIMER~
        PRINT @1109
        END
        ACTION_IF ("dynatimer" = 2) THEN BEGIN
        APPEND ~gtimes.ids~ ~2700 DYROM_TIMER~
        PRINT @1110
        END
        ACTION_IF ("dynatimer" = 3) THEN BEGIN
        APPEND ~gtimes.ids~ ~1800 DYROM_TIMER~
        PRINT @1111
        END
        ACTION_IF ("dynatimer" = 4) THEN BEGIN
        APPEND ~gtimes.ids~ ~900 DYROM_TIMER~
        PRINT @1112
        END
        ACTION_IF ("dynatimer" = 5) THEN BEGIN
        APPEND ~gtimes.ids~ ~5400 DYROM_TIMER~
        PRINT @1113
        END

  ACTION_IF GAME_IS ~tutu tutu_totsc bgee~ THEN BEGIN
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#DYDEAD.BAF~
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#DYLSTA.BAF~
      USING ~BG1NPC/TRA/%LANGUAGE%/X#DYLAST.TRA~
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#DYLSTB.BAF~
      USING ~BG1NPC/TRA/%LANGUAGE%/X#DYLAST.TRA~
    /* Area Script Extensions */
    EXTEND_BOTTOM ~%tutu_var%AR0112.BCS~ ~BG1NPC/Phase3/DYROM/baf/P#RO0112.baf~
    EVALUATE_BUFFER
    EXTEND_BOTTOM ~%tutu_var%AR2700.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DA2700.baf~
    EVALUATE_BUFFER
    EXTEND_BOTTOM ~%tutu_var%AR0125.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DA0125.baf~
    EVALUATE_BUFFER
      USING ~BG1NPC/TRA/%LANGUAGE%/X#DA0125.TRA~
  END ELSE ACTION_IF GAME_IS ~bgt~ BEGIN /* BGT Versions */
  //   COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#DYDEAD.BAF~// Dynaheir's End Cutscene disabled, no BGT file
  //   COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#DYLSTA.BAF~// Dynaheir's End Cutscene disabled, no BGT file
  //     USING ~BG1NPC/TRA/%LANGUAGE%/X#DYLAST.TRA~// Dynaheir's End Cutscene disabled, no BGT file
  //   COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#DYLSTB.BAF~// Dynaheir's End Cutscene disabled, no BGT file
  //     USING ~BG1NPC/TRA/%LANGUAGE%/X#DYLAST.TRA~// Dynaheir's End Cutscene disabled, no BGT file
    /* Area Script Extensions */
    EXTEND_BOTTOM ~AR7212.BCS~ ~BG1NPC/Phase3/DYROM/baf/P#RO0112.baf~
      EVALUATE_BUFFER
    // NOT FOR BGT EXTEND_BOTTOM ~AR6600.BCS~ ~BG1NPC/BGT/baf/X#DA2700.baf~ // Dynaheir's End Cutscene disabled, no BGT file
    // NOT FOR BGT EXTEND_BOTTOM ~AR7225.BCS~ ~BG1NPC/BGT/baf/X#DA0125.baf~ // Dynaheir's End Cutscene disabled, no BGT file
    // NOT FOR BGT   USING ~BG1NPC/TRA/%LANGUAGE%/X#DA0125.TRA~ // Dynaheir's End Cutscene disabled, no BGT file
  END

  /* dialogues */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/dlg/X#DYRO.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/dlg/X#DYBHA.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/dlg/X#DYRONPC.D~

  /* scripts */
  EXTEND_TOP  ~%tutu_var%DYNAHD.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYNAHD.baf~
  EVALUATE_BUFFER
  EXTEND_TOP  ~%DYNAHEIR_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/P#DYROM.baf~
  EVALUATE_BUFFER

  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#EDCUT1.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#EDCUT2.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#EDCUT3.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/DYROM/baf/X#EDCUT4.BAF~

  /* NPC Reactions Scripts */
  EXTEND_TOP  ~%CORAN_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYCORE.baf~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%EDWIN_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYEDRE.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%GARRICK_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYGARE.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%IMOEN_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYIMRE.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%KHALID_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYKHRE.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%MINSC_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYMIRE.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%TIAX_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYTIRE.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%YESLICK_BCS%.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYERE.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_var%YESLID.BCS~ ~BG1NPC/Phase3/DYROM/baf/X#DYERED.BAF~
    EVALUATE_BUFFER

  /* Add Portraits if NJNPC Portraits was chosen */
  ACTION_IF FILE_EXISTS_IN_GAME ~X#NJNPCPortrait.G3~ THEN BEGIN
    COPY_EXISTING ~x#nell.cre~ ~override~
      WRITE_ASCII 0x34 ~madams~ #8 // small portrait
    COPY_EXISTING ~x#madr.cre~ ~override~
      WRITE_ASCII 0x34 ~madrinas~ #8 // small portrait
    COPY_EXISTING ~x#bhet.cre~ ~override~
      WRITE_ASCII 0x34 ~bhetels~ #8 // small portrait
    COPY_EXISTING ~x#sveet.cre~ ~override~
      WRITE_ASCII 0x34 ~sveetlas~ #8 // small portrait
    COPY_EXISTING ~x#winski.cre~ ~override~
      WRITE_ASCII 0x34 ~winskis~ #8 // small portrait
    COPY_EXISTING ~x#setta.cre~ ~override~
      WRITE_ASCII 0x34 ~settas~ #8 // small portrait
  END
  
  /* Patching all creatures in component for leftover/missed Tutu > BGT items */
  ACTION_IF GAME_IS ~bgt bgee~ THEN BEGIN
    COPY_EXISTING_REGEXP GLOB ~^[XxPp]#.*\.cre~ ~override~
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
       LAUNCH_PATCH_MACRO ~convert_tutu_items_bgt_bgee~
      END
    BUT_ONLY_IF_IT_CHANGES
  END


/* SHAR-TEEL ROMANCE */
BEGIN @1013 /* The BG1 NPC Project: Shar-Teel Relationship Core (adult content) */
  GROUP @1010  /* The BG1 NPC Project: Romances */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  COPY ~BG1NPC/Core/X#component.xx~ ~override/X#SharTeelRomance.G3~
  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

  /* Shar-Teel's romance timer */
  PRINT @1105

  PRINT @1102

  OUTER_SPRINT ~shartimer~ ~placeholder_value~
  OUTER_WHILE (!(IS_AN_INT ~shartimer~) OR (~shartimer~ > 0x5) OR (~shartimer~ < 0x1)) BEGIN
    PRINT @1108
    ACTION_READLN ~shartimer~
  END
        ACTION_IF ("shartimer" = 1) THEN BEGIN
        APPEND ~gtimes.ids~ ~3600 SHROM_TIMER~
        PRINT @1109
        END
        ACTION_IF ("shartimer" = 2) THEN BEGIN
        APPEND ~gtimes.ids~ ~2700 SHROM_TIMER~
        PRINT @1110
        END
        ACTION_IF ("shartimer" = 3) THEN BEGIN
        APPEND ~gtimes.ids~ ~1800 SHROM_TIMER~
        PRINT @1111
        END
        ACTION_IF ("shartimer" = 4) THEN BEGIN
        APPEND ~gtimes.ids~ ~900 SHROM_TIMER~
        PRINT @1112
        END
        ACTION_IF ("shartimer" = 5) THEN BEGIN
        APPEND ~gtimes.ids~ ~5400 SHROM_TIMER~
        PRINT @1113
        END

  /* script */
  EXTEND_TOP  ~%SHARTEEL_BCS%.BCS~   ~BG1NPC/Phase3/SHROM/baf/X#SHROM.baf~
      EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_var%SHARTD.BCS~   ~BG1NPC/Phase3/SHROM/baf/X#SHROMD.baf~
      EVALUATE_BUFFER

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/SHROM/dlg/X#SHROM.D~

/* XAN ROMANCE */
BEGIN @1015 /* The BG1 NPC Project: Xan's Romance Core (teen content) */
  GROUP @1010  /* The BG1 NPC Project: Romances */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  COPY ~BG1NPC/Core/X#component.xx~ ~override/X#XanRomance.G3~
  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

  APPEND ~trigger.ids~ ~0x40da HaveSpellParty(I:Spell*Spell)~ UNLESS ~HaveSpellParty~
  
  /* Xan romance timer */
  PRINT @1107

  PRINT @1102

  OUTER_SPRINT ~xantimer~ ~placeholder_value~
  OUTER_WHILE (!(IS_AN_INT ~xantimer~) OR (~xantimer~ > 0x5) OR (~xantimer~ < 0x1)) BEGIN
    PRINT @1108
    ACTION_READLN ~xantimer~
  END

        ACTION_IF ("xantimer" = 1) THEN BEGIN
        APPEND ~gtimes.ids~ ~3600 XAROM_TIMER~
        PRINT @1109
        END
        ACTION_IF ("xantimer" = 2) THEN BEGIN
        APPEND ~gtimes.ids~ ~2700 XAROM_TIMER~
        PRINT @1110
        END
        ACTION_IF ("xantimer" = 3) THEN BEGIN
        APPEND ~gtimes.ids~ ~1800 XAROM_TIMER~
        PRINT @1111
        END
        ACTION_IF ("xantimer" = 4) THEN BEGIN
        APPEND ~gtimes.ids~ ~900 XAROM_TIMER~
        PRINT @1112
        END
        ACTION_IF ("xantimer" = 5) THEN BEGIN
        APPEND ~gtimes.ids~ ~5400 XAROM_TIMER~
        PRINT @1113
        END
        
        
  /* sound */
  COPY ~BG1NPC/Phase3/XAROM/Sound/X#BLANK.WAV~ ~override~

  /* Xan's Dream 2DA set up */
  COPY ~BG1NPC/Phase3/XAROM/MOS/XANDREAM.MOS~ ~override~
  COPY ~BG1NPC/Phase3/XAROM/MOS/X#BLANK.2da~ ~override/XANDREAM.2da~
         REPLACE_TEXTUALLY ~IMAGE~ ~XANDREAM~
         REPLACE 99999 @475

  /* Script */
  EXTEND_TOP  ~%tutu_var%XAND.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XAROD.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%XAN_BCS%.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XAROM.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%SHARTEEL_BCS%.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XASTRE.baf~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%JAHEIRA_BCS%.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XAJARE.baf~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%MONTARON_BCS%.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XAMORE.baf~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%TIAX_BCS%.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XATIRE.baf~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%MINSC_BCS%.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XAMIRE.baf~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%QUAYLE_BCS%.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XAQURE.baf~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%EDWIN_BCS%.BCS~ ~BG1NPC/Phase3/XAROM/baf/X#XAEDRE.baf~
    EVALUATE_BUFFER

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/XAROM/dlg/X#XANLT.D~
  

/* FEMALE CHARACTER ROMANCE CHALLENGES */
BEGIN @1017  /* The BG1 NPC Project: Female Romance Challenges, Ajantis vs Xan vs Coran */
  GROUP @1010  /* The BG1 NPC Project: Romances */
//  REQUIRE_PREDICATE (!GAME_IS ~bgee~) @5001 /* You must have BGT or TuTu installed for this component. */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    COPY ~BG1NPC/Core/X#component.xx~ ~override/X#FemaleRomChal.G3~

  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

  COPY ~BG1NPC/Phase3/CHALLENGE/bam~ ~override~

  /* Areas for the Challenges */
  /* fireworks area (FW6001) */
  ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
    COPY ~BG1NPC/Phase3/CHALLENGE/itm/x#ajr1.are~ ~override/x#ajr1.are~
  END ELSE BEGIN
    ACTION_IF GAME_IS ~bgee~ THEN BEGIN
  	  COPY ~BG1NPC/Phase3/CHALLENGE/bgee/x#ajr1_bgee.are~ ~override/x#ajr1.are~
    END ELSE BEGIN
      COPY ~BG1NPC/Phase3/CHALLENGE/itm/x#ajr1_bgt.are~ ~override/x#ajr1.are~
    END
  END
  /* Fighting Area */
  ACTION_IF GAME_IS ~tutu tutu_totsc~ THEN BEGIN
    COPY ~BG1NPC/Phase3/CHALLENGE/itm/x#ajr1.ARE~ ~override/x#ch11.are~
      WRITE_ASCII 0x94 ~X#AR6001~ #8
  END ELSE BEGIN
    ACTION_IF GAME_IS ~bgee~ THEN BEGIN
  	  COPY ~BG1NPC/Phase3/CHALLENGE/bgee/x#ajr1_bgee.are~ ~override/x#ch11.are~
  	  WRITE_ASCII 0x94 ~X#AR6001~ #8
    END ELSE BEGIN
      COPY ~BG1NPC/Phase3/CHALLENGE/itm/x#ch11_bgt.are~ ~override/x#ch11.are~
      WRITE_ASCII 0x94 ~X#AR6001~ #8
    END
  END
  
  /* Dragon Area 1 */
  /* BGEE does not have BG2's AR1402 area resources available */ 
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12.MOS~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12.TIS~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12.WED~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12AM.WAV~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12an.wav~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12ht.bmp~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12lm.bmp~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12sr.bmp~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH12_bgee.are~ ~override/x#ch12.are~
		WRITE_ASCII 0x94 ~X#ARCH12~
  END ELSE BEGIN   
  /* For Tutu, BGT */
  	COPY ~BG1NPC/Phase3/CHALLENGE/itm/X#CH12.are~ ~override~
    	WRITE_ASCII 0x94 ~X#ARCH12~
  END
  
  /* Dragon Area 2 */
  COPY_EXISTING ~X#CH12.are~ ~override/X#CH14.are~
    WRITE_ASCII 0x94 ~X#CH14~ #8

  /* Suldanessellar Area */
  /* BGEE does not have BG2's AR2805 area resources available */ 
  ACTION_IF GAME_IS ~bgee~ THEN BEGIN
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13.MOS~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13.TIS~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13.WED~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13AM.WAV~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13c1.WAV~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13c2.WAV~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13c3.WAV~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13c4.WAV~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13c5.WAV~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13ab.wav~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13ht.bmp~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13lm.bmp~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13sr.bmp~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13a.bam~ ~override~
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/X#CH13_bgee.are~ ~override/x#ch13.are~
    	WRITE_ASCII 0x94 ~X#CH13~ #8
  END ELSE BEGIN
  /* For Tutu, BGT */
  	COPY ~BG1NPC/Phase3/CHALLENGE/itm/X#CH13.are~ ~override~
    	WRITE_ASCII 0x94 ~X#CH13~ #8
  END

  /* items */
  COPY ~BG1NPC/Phase3/CHALLENGE/itm/X#MIRC.itm~ ~override~
    SAY NAME1 @489
    SAY NAME2 @489
    SAY UNIDENTIFIED_DESC @490
    SAY DESC @490

  /* 2DA patching */
  APPEND ~ITEMDIAL.2da~ ~X#MIRC 5689 X#MIRC~

  COPY_EXISTING ~itemdial.2da~ ~override~
    PRETTY_PRINT_2DA
    
  /* creatures */
  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#maste.cre~ ~override/x#maste.cre~
    SAY NAME1 @491
    SAY NAME2 @492
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @493
    SAY UNHAPPY_BREAKING @494
    SAY BATTLE_CRY1 @495
    SAY DAMAGE @496
    SAY DYING @497
    SAY SELECT_COMMON1 @498
    SAY SELECT_COMMON2 @493
    SAY SELECT_COMMON3 @499
    SAY SELECT_COMMON4 @500
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	REPLACE_CRE_ITEM ~DAGG04~ #0 #0 #0 ~unstealable&undroppable~ ~WEAPON1~ EQUIP
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~

  /* Coran and Ajantis creatures for Fighting */
  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#xvart.cre~ ~override/x#xvart1.cre~
       ~BG1NPC/Phase3/CHALLENGE/cre/x#xvart.cre~ ~override/x#xvart2.cre~
    SAY NAME1 @501
    SAY NAME2 @501
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY BATTLE_CRY1 @502
    SAY BATTLE_CRY2 @502
    SAY BATTLE_CRY3 @502
    SAY BATTLE_CRY4 @502
    SAY BATTLE_CRY5 @502
    SAY ATTACK1 @503
    SAY ATTACK2 @504
    SAY DAMAGE @505
    SAY DYING @506
    SAY SELECT_COMMON1 @507
    SAY SELECT_COMMON2 @508
    WRITE_ASCIIE 0x248 ~%tutu_scriptw%TASIGHT~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32//  death variable
    WRITE_EVALUATED_ASCII 0x258 ~%tutu_var%xvart~ #8 // Race script

  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#corafi.cre~ ~override~
    SAY NAME1 @509
    SAY NAME2 @509
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY INITIAL_MEETING @510
    SAY MORALE @511
    SAY UNHAPPY_BREAKING @511
    SAY BATTLE_CRY1 @510
    SAY BATTLE_CRY2 @512
    SAY BATTLE_CRY3 @512
    SAY BATTLE_CRY4 @512
    SAY BATTLE_CRY5 @512
    SAY ATTACK1 @510
    SAY ATTACK2 @512
    SAY DAMAGE @513
    SAY DYING @514
    SAY HURT @515
    SAY SELECT_COMMON1 @516
    SAY SELECT_COMMON2 @517
    SAY SELECT_COMMON3 @518
    SAY SELECT_COMMON4 @516
    SAY SELECT_COMMON5 @516
    SAY SELECT_ACTION1 @510
    SAY SELECT_ACTION2 @510
    SAY SELECT_ACTION3 @510
    SAY SELECT_ACTION4 @510
    SAY SELECT_ACTION5 @510
    SAY SELECT_ACTION6 @510
    SAY SELECT_ACTION7 @510
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	REPLACE_CRE_ITEM ~BOW08~ #0 #0 #0 ~unstealable&undroppable~ ~WEAPON1~ EQUIP
    	REPLACE_CRE_ITEM ~QUIVER01~ #0 #0 #0 ~unstealable&undroppable~ ~QUIVER1~ EQUIP
    END
    WRITE_LONG BIO (BNOT 0x0)
    WRITE_EVALUATED_ASCII 0x280 ~%SOURCE_RES%~ #32 //  death variable
    WRITE_EVALUATED_ASCII 0x2CC ~%SOURCE_RES%~ #8 //  dialog
    WRITE_ASCIIE 0x248 ~%tutu_scriptw%TASIGHT~ #8 //  override script
	PATCH_IF GAME_IS ~bgee bgt~ BEGIN
	    WRITE_ASCII 0x34 ~CORANS~ #8    // small portrait
        WRITE_ASCII 0x3C ~CORANL~ #8    // large portrait
    END

  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#ajanfi.cre~ ~override/x#ajanfi.cre~
    SAY NAME1 @519
    SAY NAME2 @519
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    SAY MORALE @520
    SAY BATTLE_CRY1 @521
    SAY BATTLE_CRY2 @522
    SAY BATTLE_CRY3 @522
    SAY BATTLE_CRY4 @522
    SAY BATTLE_CRY5 @522
    SAY ATTACK1 @523
    SAY ATTACK2 @523
    SAY DAMAGE @525
    SAY DYING @526
    SAY HURT @527
    SAY SELECT_COMMON1 @528
    SAY SELECT_COMMON2 @529
    SAY SELECT_COMMON3 @530
    SAY SELECT_COMMON4 @531
    SAY SELECT_COMMON5 @523
    SAY SELECT_COMMON6 @523
    SAY SELECT_ACTION1 @528
    SAY SELECT_ACTION2 @532
    WRITE_LONG BIO (BNOT 0x0)
    WRITE_EVALUATED_ASCII 0x280 ~%SOURCE_RES%~ #32 //  death variable
    WRITE_ASCII 0x2CC ~~ #8 //  dialog
    WRITE_EVALUATED_ASCII 0x248 ~%tutu_scriptw%TASIGHT~ #8 //  override script
    WRITE_EVALUATED_ASCII 0x268 ~%tutu_var%DPLAYER~ #8
	PATCH_IF GAME_IS ~bgee bgt~ BEGIN
		WRITE_ASCII 0x34 ~AJANTISS~ #8  // small portrait
		WRITE_ASCII 0x3C ~AJANTISL~ #8  // large portrait
	END

  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#elhan.cre~ ~override/x#elhan.cre~
    SAY NAME1 @533
    SAY NAME2 @533
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* ELHAN soundset not in BGEE.  Use ELFFF soundset */
    PATCH_IF GAME_IS ~bgee~ BEGIN
	    SAY INITIAL_MEETING #4941	// [ELF 1] The Fair Folk rarely have time for small talk.
    	SAY DAMAGE #12586			// [ELF 5]
    	SAY DYING #12587			// [ELF 6]
    	SAY SELECT_COMMON1 #4941	// [ELF 1]
    	SAY SELECT_COMMON2 #4942	// [ELF 2] Troubled times are upon us.
    	SAY SELECT_COMMON3 #4943	// [ELF 3] Soon we shall all be together upon Evermeet.
    	REPLACE_CRE_ITEM ~CHAN12~ #0 #0 #0 ~unstealable&undroppable~ ~ARMOR~
    	REPLACE_CRE_ITEM ~SW1H22~ #0 #0 #0 ~unstealable&undroppable~ ~WEAPON1~ EQUIP
     	REPLACE_CRE_ITEM ~SW1H22~ #0 #0 #0 ~unstealable&undroppable~ ~SHIELD~    	
	END ELSE BEGIN /* Tutu, BGT */
    	SAY BATTLE_CRY1 @534
    	SAY BATTLE_CRY2 @535
    	SAY DAMAGE @536
    	SAY DYING @537
    	SAY SELECT_COMMON1 @538
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~

  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#elles.cre~ ~override/x#elles.cre~
    SAY NAME1 @539
    SAY NAME2 @539
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* ELLESI soundset not in BGEE.  Use FELFF soundset */
    PATCH_IF GAME_IS ~bgee~ BEGIN
    	SAY INITIAL_MEETING #11063 // [ELF FEMALE 1] Good day and hello to you.
    	SAY DAMAGE #11075 // [ELF FEMALE 5]
    	SAY DYING #11076 // [ELF FEMALE 6]
    	SAY SELECT_COMMON1 #11063 // [ELF FEMALE 1] Good day and hello to you.
	END ELSE BEGIN /* Tutu, BGT */
    	SAY BATTLE_CRY1 @540
    	SAY BATTLE_CRY2 @541
    	SAY DAMAGE @542
    	SAY DYING @543
    	SAY SELECT_COMMON1 @544
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~


  /* Various Dragons */
  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#ajdrsi.cre~ ~override/x#ajdrsi.cre~
    SAY NAME1 @545
    SAY NAME2 @545
	LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
	SAY BATTLE_CRY1 @753 // [WYVER03]
	SAY BATTLE_CRY2 @754 // [WYVER04]
	SAY ATTACK1 @755 // [WYVER05]
	SAY ATTACK2 @756 // [WYVER06]
	SAY ATTACK3 @757 // [WYVER07]
    SAY DAMAGE @758 // [WYVER08]
    SAY DYING @759 // [WYVER09]
    SAY SELECT_COMMON1 @751 // [WYVER01]
    SAY SELECT_COMMON2 @752 // [WYVER02]
    SAY PICKED_POCKET @760 // [WYVER10]
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~


  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#ajdrre.cre~ ~override/x#ajdrre.cre~
    SAY NAME1 @546
    SAY NAME2 @546
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
	SAY BATTLE_CRY1 @753 // [WYVER03]
	SAY BATTLE_CRY2 @754 // [WYVER04]
	SAY ATTACK1 @755 // [WYVER05]
	SAY ATTACK2 @756 // [WYVER06]
	SAY ATTACK3 @757 // [WYVER07]
    SAY DAMAGE @758 // [WYVER08]
    SAY DYING @759 // [WYVER09]
    SAY SELECT_COMMON1 @751 // [WYVER01]
    SAY SELECT_COMMON2 @752 // [WYVER02]
    SAY PICKED_POCKET @760 // [WYVER10]
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~


  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#dragon.cre~ ~override/x#cautz.cre~
    SAY NAME1 @547
    SAY NAME2 @547
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* FIRKAAG soundset not in BGEE.  Use WYVERN soundset */
    PATCH_IF GAME_IS ~bgee~ BEGIN
		SAY BATTLE_CRY1 @753 // [WYVER03]
		SAY BATTLE_CRY2 @754 // [WYVER04]
		SAY ATTACK1 @755 // [WYVER05]
		SAY ATTACK2 @756 // [WYVER06]
		SAY ATTACK3 @757 // [WYVER07]
    	SAY DAMAGE @758 // [WYVER08]
    	SAY DYING @759 // [WYVER09]
    	SAY SELECT_COMMON1 @751 // [WYVER01]
    	SAY SELECT_COMMON2 @752 // [WYVER02]
    	SAY PICKED_POCKET @760 // [WYVER10]
    END ELSE BEGIN /* Tutu, BGT */
    	SAY BATTLE_CRY1 @548
    	SAY BATTLE_CRY2 @549
    	SAY DAMAGE @549
    	SAY DYING @551
    	SAY SELECT_COMMON1 @552
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~


  COPY ~BG1NPC/Phase3/CHALLENGE/cre/x#dragon.cre~ ~override/x#drag2.cre~
    SAY NAME1 @553
    SAY NAME2 @553
    LAUNCH_PATCH_MACRO ~source_cre_sound_cleanup~
    /* FIRKAAG soundset not in BGEE.  Use WYVERN soundset */
    PATCH_IF GAME_IS ~bgee~ BEGIN
		SAY BATTLE_CRY1 @753 // [WYVER03]
		SAY BATTLE_CRY2 @754 // [WYVER04]
		SAY ATTACK1 @755 // [WYVER05]
		SAY ATTACK2 @756 // [WYVER06]
		SAY ATTACK3 @757 // [WYVER07]
    	SAY DAMAGE @758 // [WYVER08]
    	SAY DYING @759 // [WYVER09]
    	SAY SELECT_COMMON1 @751 // [WYVER01]
    	SAY SELECT_COMMON2 @752 // [WYVER02]
    	SAY PICKED_POCKET @760 // [WYVER10]
    END ELSE BEGIN /* Tutu, BGT */
    	SAY BATTLE_CRY1 @548
    	SAY BATTLE_CRY2 @549
    	SAY DAMAGE @549
    	SAY DYING @551
    	SAY SELECT_COMMON1 @552
    END
    LAUNCH_PATCH_MACRO ~bg1npc_cre_dest_res~

  /* Replace Dragon Items missing from BGEE */
  ACTION_IF GAME_IS ~bgee~ BEGIN
	/* Dragon Claws */
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/dragred1.itm~ ~override~
	     ~BG1NPC/Phase3/CHALLENGE/bgee/dragsil1.itm~ ~override~
    	WRITE_LONG NAME1 (BNOT 0x0)
    	WRITE_LONG NAME2 (BNOT 0x0)
    	WRITE_LONG UNIDENTIFIED_DESC (BNOT 0x0)
    	WRITE_LONG DESC (BNOT 0x0)

	/* Dragon Ring - for various immunities */
	COPY ~BG1NPC/Phase3/CHALLENGE/bgee/dragring.itm~ ~override~
    	WRITE_LONG NAME1 6348
    	WRITE_LONG NAME2 6348
    	WRITE_LONG UNIDENTIFIED_DESC 17054
    	WRITE_LONG DESC (BNOT 0x0)

    /* Skull - In dragon inventories */
    COPY_EXISTING ~misc50.itm~ ~override/plot05d.itm~
  END

  /* NPC scripts */
  EXTEND_TOP  ~%AJANTIS_BCS%.BCS~ ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL0.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%tutu_var%AJANTD.BCS~ ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL1.BAF~
    EVALUATE_BUFFER
  EXTEND_TOP  ~%CORAN_BCS%.BCS~ ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL8.BAF~
    EVALUATE_BUFFER

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/dlg/X#CHALLENGE.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/dlg/X#MIRC.D~

  /* additional character scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#MASTE.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AR6001.BAF~
      USING ~BG1NPC/TRA/%LANGUAGE%/X#AR6001.TRA~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#ELHAN.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#ELLES.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CH13.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL2.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL3.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL4.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL5.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL6.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL7.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL8.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHALL9.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHAL10.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHAL11.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHAL12.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#CHAL13.BAF~

  /* cutscene scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCUT.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCU2.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCU3.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCU4.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCU5.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCU6.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCU7.BAF~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/CHALLENGE/baf/X#AJRCU8.BAF~

  /* Add Portraits if NJNPC Portraits was chosen */
  ACTION_IF FILE_EXISTS_IN_GAME ~X#NJNPCPortrait.G3~ THEN BEGIN
    COPY_EXISTING ~x#maste.cre~ ~override/x#maste.cre~
      WRITE_ASCII 0x34 ~mastrchs~ #8 // small portrait
  END

  /* Patching all creatures in component for Tutu > BGT items */
  ACTION_IF GAME_IS ~bgt bgee~ THEN BEGIN
    COPY_EXISTING_REGEXP GLOB ~^[XxPp]#.*\.cre~ ~override~
      PATCH_IF (SOURCE_SIZE > 0x2d3) BEGIN
       LAUNCH_PATCH_MACRO ~convert_tutu_items_bgt_bgee~
      END
    BUT_ONLY_IF_IT_CHANGES
  END

/* BG1 NPC Final Modifications (Wait at an Inn, Change NPC Starting Locations, Jason Compton's Accelerated Banter Script, Walking Speeds Component, Player-Initiated Dialogues */
/* NPCs Wait at Inn */
BEGIN @1064  /* The BG1 NPC Project: NPCs can be sent to wait in an inn. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (!FILE_EXISTS_IN_GAME ~dw#12.xxx~) @1066 /* This component is already handled by Sword Coast Strategems. To use the BG1 NPC version, please uninstall the SCS version first. */
  REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc~) @5003 /* Incompatible with BGT & BGEE: please use the equivalent component in SwordCoastStrategems for BGT and BGEE */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    COPY ~BG1NPC/Core/X#component.xx~ ~override/X#WaitAtInn.G3~

  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

  /* dialog Tutu Only */
  COMPILE ~BG1NPC/Phase3/WAIT/dlg/X#NPCWAIT.D~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#NPCWAIT.TRA~

  /* scripts Tutu Only */
  COPY_EXISTING ~_AR2301.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
    	REPLACE_TEXTUALLY ~GlobalGT("Chapter","GLOBAL",2)~ ~GlobalGT("Chapter","GLOBAL",2) GlobalLT("X#Kh_Jae","GLOBAL",1)~
    END
  BUT_ONLY_IF_IT_CHANGES

  EXTEND_BOTTOM ~_JAHEIRA.bcs~   ~BG1NPC/Phase3/wait/baf/_jaheira_bot.baf~
  EXTEND_BOTTOM ~_KHALID.bcs~   ~BG1NPC/Phase3/wait/baf/_khalid_bot.baf~

/* Move Alora, Eldoth, Quayle and Tiax */
/* patching location code */
/* Alora Starts in the Hall of Wonders */
BEGIN @1067 /* Alora Starts in the Hall of Wonders. */
  SUBCOMPONENT @1068  /* The BG1 NPC Project: Alora's Starting Location. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    PRINT @1069  /* Alora will start in the Hall of Wonders as in the original game. */

/* Alora Starts in Gullykin */
BEGIN @1070  /* Alora Starts in Gullykin. */
  SUBCOMPONENT @1068  /* The BG1 NPC Project: Alora's Starting Location. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    COPY ~BG1NPC/Core/X#component.xx~ ~override/X#AloraMove.G3~

  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/MOVELOC/dlg/x#aloramoves.d~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#ALORAN.TRA~

  ACTION_IF GAME_IS ~tutu tutu_totsc bgee~ THEN BEGIN
    /* Trying to prevent Alora's CTD */
    COPY_EXISTING ~%HallofWonders_BCS%.bcs~ ~override~
      DECOMPILE_AND_PATCH BEGIN
    	REPLACE_TEXTUALLY ~!InParty("alora")~ ~!InParty("alora") Global("X#AloraDontBeDifficult","GLOBAL",1)~
      END
      BUT_ONLY_IF_IT_CHANGES

    /* patching Alora's location */
    COPY_EXISTING ~baldur.gam~ ~override~
      READ_LONG 0x30 non_joined_npcs_off
      READ_LONG 0x34 non_joined_npcs_count
      FOR (i = 0; i < non_joined_npcs_count; i+=1) BEGIN
        SET cre_offset = non_joined_npcs_off + i * 0x160
        READ_ASCII 0xc + cre_offset ~CREName~
        PATCH_IF !(~%CREName%~ STRING_COMPARE_CASE ~%ALORA_BCS%~) BEGIN
          WRITE_ASCIIE cre_offset + 0x18 ~%Gullykin%~ #8
          WRITE_SHORT cre_offset + 0x20 553
          WRITE_SHORT cre_offset + 0x22 506
        END
      END
      BUT_ONLY_IF_IT_CHANGES
    
    PRINT @1071  /* Remember to start a new game for Alora to start in Gullykin near the door to the winery. */
  END ELSE BEGIN
    ACTION_IF GAME_IS ~bgt~ THEN BEGIN
    /* Patching Alora's location BGT */
      COPY_EXISTING ~%HallofWonders_BCS%.bcs~ ~override~
        DECOMPILE_AND_PATCH BEGIN
          REPLACE_TEXTUALLY ~Global("BGTNPC7230","GLOBAL",0)~ ~False()~
          REPLACE_TEXTUALLY ~Exists("Alora")~ ~False()~
        END
      BUT_ONLY_IF_IT_CHANGES
      EXTEND_BOTTOM ~AR9900.bcs~ ~BG1NPC/Phase3/MOVELOC/baf/X#ALORASPA.baf~
        EVALUATE_BUFFER
      PRINT @1071  /* Remember to start a new game for Alora to start in Gullykin near the door to the winery. */
    END
  END

/* Eldoth Starts in the Cloakwood Forest */
BEGIN @1072 /* Eldoth Starts in the Cloakwood Forest. */
  SUBCOMPONENT @1073 /* The BG1 NPC Project: Eldoth's Starting Location. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc bgee~) @1095 /* Incompatible with BGT: please use the equivalent component in SwordCoastStrategems for BGT */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    PRINT @1074 /* Eldoth will start in the Cloakwood as in the original game. */

/* Eldoth Starts on the Coastal Way */
BEGIN @1075 /* Eldoth Starts on the Coast Way. */
  SUBCOMPONENT @1073 /* The BG1 NPC Project: Eldoth's Starting Location. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc bgee~) @1095 /* Incompatible with BGT: please use the equivalent component in SwordCoastStrategems for BGT */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    COPY ~BG1NPC/Core/X#component.xx~ ~override/X#EldothMove.G3~

  /*Patching _ELDOTH.bcs */
  COPY_EXISTING ~%ELDOTH_BCS%.bcs~ ~override~
    DECOMPILE_AND_PATCH BEGIN
    	REPLACE_TEXTUALLY ~!Global("X#SkieLeftEldoth","GLOBAL",1)~ ~OR(2) !Global("X#SkieLeftEldoth","GLOBAL",1) !Global("EldothMove","GLOBAL",0)~
    END
    BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING ~baldur.gam~ ~override~
    READ_LONG 0x30 non_joined_npcs_off
    READ_LONG 0x34 non_joined_npcs_count
    FOR (i = 0; i < non_joined_npcs_count; i+=1) BEGIN
      SET cre_offset = non_joined_npcs_off + i * 0x160
      READ_ASCII 0xc + cre_offset ~CREName~
      PATCH_IF !(~%CREName%~ STRING_COMPARE_CASE ~%ELDOTH_BCS%~) BEGIN
        WRITE_ASCIIE cre_offset + 0x18 ~%CoastWay%~ #8
        WRITE_SHORT cre_offset + 0x20 1064
        WRITE_SHORT cre_offset + 0x22 2086
      END
    END
    BUT_ONLY_IF_IT_CHANGES
  PRINT @1076 /* ~Remember to start a new game for Eldoth to start on the Coast Way near the Obelisk. */

/* Quayle Starts at the Wyrm's Crossing. */
BEGIN @1077  /* Quayle Starts at the Wyrm's Crossing. */
  SUBCOMPONENT @1078  /* The BG1 NPC Project: Quayle's Starting Location. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc bgee~) @1095 /* Incompatible with BGT: please use the equivalent component in SwordCoastStrategems for BGT */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    PRINT @1079  /* Quayle will start at the Wyrm's Crossing as in the original game. */

/* Quayle Starts at the Nashkel Carnival */
BEGIN @1081 /* Quayle Starts at the Nashkel Carnival. */
  SUBCOMPONENT @1078  /* The BG1 NPC Project: Quayle's Starting Location. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc bgee~) @1095 /* Incompatible with BGT: please use the equivalent component in SwordCoastStrategems for BGT */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    COPY ~BG1NPC/Core/X#component.xx~ ~override/X#QuayleMove.G3~

  COPY_EXISTING ~baldur.gam~ ~override~
    READ_LONG 0x30 non_joined_npcs_off
    READ_LONG 0x34 non_joined_npcs_count
    FOR (i = 0; i < non_joined_npcs_count; i+=1) BEGIN
      SET cre_offset = non_joined_npcs_off + i * 0x160
      READ_ASCII 0xc + cre_offset ~CREName~
      PATCH_IF !(~%CREName%~ STRING_COMPARE_CASE ~%QUAYLE_BCS%~) BEGIN
        WRITE_ASCIIE cre_offset + 0x18 ~%NashkelCarnival%~ #8
        WRITE_SHORT cre_offset + 0x20 1067
        WRITE_SHORT cre_offset + 0x22 3784
      END
    END
    BUT_ONLY_IF_IT_CHANGES
  PRINT @1082  /* Remember to start a new game for Quayle to start at the Nashkel Carnival near Great Gazib's show. */

/* Tiax Starts in Baldur's Gate */
BEGIN @1083 /* Tiax Starts in Baldur's Gate. */
  SUBCOMPONENT @1084 /* The BG1 NPC Project: Tiax's Starting Location. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc bgee~) @1095 /* Incompatible with BGT: please use the equivalent component in SwordCoastStrategems for BGT */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    PRINT @1085 /* Tiax will start in Baldur's Gate as in the original game. */

/* Tiax Starts in Beregost */
BEGIN @1086  /* Tiax Starts in Beregost. */
  SUBCOMPONENT @1084 /* The BG1 NPC Project: Tiax's Starting Location. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc bgee~) @1095 /* Incompatible with BGT: please use the equivalent component in SwordCoastStrategems for BGT */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    COPY ~BG1NPC/Core/X#component.xx~ ~override/X#TiaxMove.G3~

  COPY_EXISTING ~baldur.gam~ ~override~
    READ_LONG 0x30 non_joined_npcs_off
    READ_LONG 0x34 non_joined_npcs_count
    FOR (i = 0; i < non_joined_npcs_count; i+=1) BEGIN
      SET cre_offset = non_joined_npcs_off + i * 0x160
      READ_ASCII 0xc + cre_offset ~CREName~
      PATCH_IF !(~%CREName%~ STRING_COMPARE_CASE ~%TIAX_BCS%~) BEGIN
        WRITE_ASCIIE cre_offset + 0x18 ~%Beregost_FeldepostsInn_L1%~ #8
        WRITE_SHORT cre_offset + 0x20 500
        WRITE_SHORT cre_offset + 0x22 630
      END
    END
    BUT_ONLY_IF_IT_CHANGES
  PRINT @1087  /* Remember to start a new game for Tiax to start in Beregost on the first floor of Feldepost's Inn. */

/* Jason Compton's Accelerated Banter Script "bantergoose" */
BEGIN @1088 /* Jason Compton's Accelerated Banter Script. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (!GAME_IS ~bgee~) @5001 /* You must have BGT or TuTu installed for this component. */
  FORBID_FILE ~override/bantergoose.xxx~ @1089  /* You already have the Banter Accelerator installed. */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    COPY ~BG1NPC/Bantergoose/bantergoose.xxx~ ~override/bantergoose.xxx~
    EXTEND_TOP ~baldur.bcs~ ~BG1NPC/bantergoose/bantergoose.baf~

/* BGEE Banter Timing Tweak: Utilizes new BANTTIMG.2DA available in BGEE to 
   adjust banter dialog timings.  Replaces Compton's "bantergoose" script for BGEE - AstroBryGuy */
BEGIN @1123 /* BGEE Banter Timing Tweak */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (GAME_IS ~bgee~) @5002 /* You must have BGEE installed for this component. */
  FORBID_FILE ~override/AYBanterTimingTweak.xxx~ @1124  /* You already have the Banter Timing Tweak installed. */

  COPY ~BG1NPC/Core/X#component.xx~ ~override/AYBanterTimingTweak.xxx~
  
  PRINT @1125
  OUTER_SPRINT ~bantertimer~ ~placeholder_value~
  OUTER_WHILE (!(IS_AN_INT %bantertimer%) OR (%bantertimer% < 1) OR (%bantertimer% > 5)) BEGIN
    PRINT @1108
    ACTION_READLN ~bantertimer~
  END

  ACTION_IF (~%bantertimer%~ = 1) THEN BEGIN
  	COPY_EXISTING ~banttimg.2da~ ~override~
  		SET_2DA_ENTRY 3 1 1 ~600~
  		SET_2DA_ENTRY 4 1 1 ~10~
  		SET_2DA_ENTRY 6 1 1 ~25~
  		BUT_ONLY_IF_IT_CHANGES
  	PRINT @1126
  END
  ACTION_IF (~%bantertimer%~ = 2) THEN BEGIN
   	COPY_EXISTING ~banttimg.2da~ ~override~
  		SET_2DA_ENTRY 3 1 1 ~550~
  		SET_2DA_ENTRY 4 1 1 ~10~
  		SET_2DA_ENTRY 6 1 1 ~30~
  		BUT_ONLY_IF_IT_CHANGES
  	PRINT @1127
  END
  ACTION_IF (~%bantertimer%~ = 3) THEN BEGIN
  	COPY_EXISTING ~banttimg.2da~ ~override~
  		SET_2DA_ENTRY 3 1 1 ~480~
  		SET_2DA_ENTRY 4 1 1 ~10~
  		SET_2DA_ENTRY 6 1 1 ~40~
  		BUT_ONLY_IF_IT_CHANGES
  	PRINT @1128
  END
  ACTION_IF (~%bantertimer%~ = 4) THEN BEGIN
  	COPY_EXISTING ~banttimg.2da~ ~override~
  		SET_2DA_ENTRY 3 1 1 ~650~
  		SET_2DA_ENTRY 4 1 1 ~10~
  		SET_2DA_ENTRY 6 1 1 ~18~
  		BUT_ONLY_IF_IT_CHANGES
	PRINT @1129
  END
  ACTION_IF (~%bantertimer%~ = 5) THEN BEGIN
  	COPY_EXISTING ~banttimg.2da~ ~override~
  		SET_2DA_ENTRY 3 1 1 ~700~
  		SET_2DA_ENTRY 4 1 1 ~10~
  		SET_2DA_ENTRY 6 1 1 ~14~
  		BUT_ONLY_IF_IT_CHANGES
	PRINT @1130
  END
 

BEGIN @1092 /* The BG1 NPC Project: Make Shar-Teel Unkillable until In Party */
GROUP @1065 /* The BG1 NPC Project: Tweaks */
	REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc~) @1093 /* This component is only useful for Tutu installs. */
	REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
	/* Stop Shar-Teel's Premature Death */
    	ACTION_FOR_EACH ~file~ IN ~_sharte~ ~_sharte4~ ~_sharte6~ BEGIN
		ACTION_IF FILE_EXISTS_IN_GAME ~%file%.cre~ BEGIN
			COPY_EXISTING ~%file%.cre~ override
				ADD_CRE_ITEM ~monhp1~ #0 #0 #0 ~unstealable&undroppable~ ~AMULET~ //  either adds it new, or forces into inventory (and unequipped)
      			BUT_ONLY_IF_IT_CHANGES
  		END
  	END

	EXTEND_TOP ~%SHARTEEL_BCS%.bcs~ ~BG1NPC/Core/baf/X#SHARFIX.BAF~
		EVALUATE_BUFFER

BEGIN @1094  /* The BG1 NPC Project: Bardic Reputation Adjustment */
GROUP @1065 /* The BG1 NPC Project: Tweaks */
REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */

  /* makes sure PIDs go last */
  UNINSTALL ~bg1npc.tp2~ 200

  COPY_EXISTING ~%tutu_var%volo.cre~ ~override/x#lp1rep.cre~
                ~%tutu_var%volo.cre~ ~override/x#lp2rep.cre~
                ~%tutu_var%volo.cre~ ~override/x#lp3rep.cre~
    SAY INITIAL_MEETING @294
    SAY UNHAPPY_BREAKING @295
    SAY BATTLE_CRY1 @296
    SAY BATTLE_CRY2 @296
    SAY BATTLE_CRY3 @296
    SAY BATTLE_CRY4 @296
    SAY BATTLE_CRY5 @296
    SAY DAMAGE @297
    SAY DYING @298
    SAY SELECT_COMMON1 @299
    SAY SELECT_COMMON2 @300
    SAY SELECT_COMMON3 @301
    SAY SELECT_COMMON4 @302
    SAY DIALOGUE_DEFAULT @299
    WRITE_EVALUATED_ASCII 0x2CC ~%DEST_RES%~ #8 //  dialog
    WRITE_EVALUATED_ASCII 0x280 ~%DEST_RES%~ #32 //  death variable
    PATCH_IF (~%DEST_RES%~ STRING_EQUAL ~x#lp1rep~) BEGIN
      SAY NAME1 @292
      SAY NAME2 @293
      WRITE_ASCII 0x248 ~X#LP1R~ #8 //  override script
    END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL ~x#lp2rep~) BEGIN
      SAY NAME1 @303
      SAY NAME2 @304
      WRITE_ASCII 0x248 ~X#LP2R~ #8 //  override script
    END ELSE PATCH_IF (~%DEST_RES%~ STRING_EQUAL ~x#lp3rep~) BEGIN
      SAY NAME1 @305
      SAY NAME2 @306
      WRITE_ASCII 0x248 ~X#LP3R~ #8 //  override script
    END

  /* scripts */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#LP1R.BAF~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#LP1R.TRA~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#LP2R.BAF~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#LP2R.TRA~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/baf/X#LP3R.BAF~
    USING ~BG1NPC/TRA/%LANGUAGE%/X#LP3R.TRA~

  /* dialogue */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#LP1REP.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#LP2REP.D~
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#LP3REP.D~

  /* Area Scripts for spawning */
  EXTEND_BOTTOM ~%FriendlyArmInn_L1_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#LP1REPAS.BAF~ // The Friendly Arm Inn
    EVALUATE_BUFFER
  EXTEND_BOTTOM ~%BelchingDragonTavern_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#LP2REPAS.BAF~ // The Belching Dragon
    EVALUATE_BUFFER
  EXTEND_BOTTOM ~%ElfsongTavern_L1_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#LP3REPAS.BAF~ // The Elfsong
    EVALUATE_BUFFER

  /* Ajantis Reputation Seller Reactions */
  COMPILE EVALUATE_BUFFER ~BG1NPC/Phase2/dlg/X#LPRCAD.D~
  EXTEND_BOTTOM ~%AJANTIS_BCS%.bcs~ ~BG1NPC/Phase2/baf/X#LPRCAJR.BAF~
      EVALUATE_BUFFER

  /* Tutu/BGT Portrait Assignment */
  /* Add Portraits if NJNPC Portraits was chosen */
  ACTION_IF FILE_EXISTS_IN_GAME ~X#NJNPCPortrait.G3~ THEN BEGIN
  COPY_EXISTING ~x#lp1rep.cre~ ~override~
    WRITE_ASCII 0x34 ~lpb1s~ #8 // small portrait

  COPY_EXISTING ~x#lp2rep.cre~ ~override~
    WRITE_ASCII 0x34 ~lpb2s~ #8 // small portrait

  COPY_EXISTING ~x#lp3rep.cre~ ~override~
    WRITE_ASCII 0x34 ~lpb3s~ #8 // small portrait
  END

BEGIN @1020  /* Open Cloakwood Lodge (first Cloakwood area only) */
  SUBCOMPONENT @1019  /* The BG1 NPC Project: Cloakwood areas availability in Chapter One */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE ((NOT FILE_EXISTS_IN_GAME ~cdt01035.g3~) AND (NOT FILE_EXISTS_IN_GAME ~cdt01036.g3~)) @1101 /* ~The functionality of this component is either already included or superceded by one of your already installed mods.~ */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* ~BG1 NPC Required Changes component is not installed.~ */
    COPY ~BG1NPC/Core/X#component.xx~ ~override/X#BG1NPCCloakLodge.G3~
  COPY_EXISTING ~worldmap.wmp~ ~override~
    READ_LONG  0x30 "area_num"
    READ_LONG  0x34 "area_off"
    FOR (index = 0; index < area_num; index = index + 1) BEGIN
      READ_ASCII ("%area_off%" + 0x08 + (0xf0 * "%index%")) "area_res"
      PATCH_IF (("%area_res%" STRING_COMPARE_CASE "fw2200" = 0) OR     //  cloakwood 1 (tutu)
                ("%area_res%" STRING_COMPARE_CASE "ar7000" = 0) OR     //  cloakwood 1 (bgt)
                ("%area_res%" STRING_COMPARE_CASE "ar2200" = 0)) BEGIN //  cloakwood 1 (bgee)
        READ_BYTE  ("%area_off%" + 0x30 + (0xf0 * "%index%")) "flags"
        WRITE_BYTE ("%area_off%" + 0x30 + (0xf0 * "%index%")) ("%flags%" BOR 0b00000010) //  adds 'reveal thru linked area' flag
      END ELSE
      PATCH_IF (("%area_res%" STRING_COMPARE_CASE "fw2100" = 0) OR     //  cloakwood 2 (tutu)
                ("%area_res%" STRING_COMPARE_CASE "ar8800" = 0) OR     //  cloakwood 2 (bgt)
                ("%area_res%" STRING_COMPARE_CASE "ar2100" = 0)) BEGIN //  cloakwood 2 (bgee)
        READ_BYTE  ("%area_off%" + 0x30 + (0xf0 * "%index%")) "flags"
        WRITE_BYTE ("%area_off%" + 0x30 + (0xf0 * "%index%")) ("%flags%" BAND 0b11111101) //  removes 'reveal thru linked area' flag
      END
    END
    BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING_REGEXP GLOB ~^\(_ar1901\|ar8701\|ar1901\)\.bcs$~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~RevealAreaOnMap("FW2200")~ ~RevealAreaOnMap("FW2200") RevealAreaOnMap("FW2100")~
      REPLACE_TEXTUALLY ~RevealAreaOnMap("AR7000")~ ~RevealAreaOnMap("AR7000") RevealAreaOnMap("AR8800")~
      REPLACE_TEXTUALLY ~RevealAreaOnMap("AR2200")~ ~RevealAreaOnMap("AR2200") RevealAreaOnMap("AR2100")~
    END
  BUT_ONLY_IF_IT_CHANGES

  PRINT @1003  /* Please remember to start a new game to access the contents of this component. */

BEGIN @1021   /* Open four Cloakwood areas (everything but the Mines) */
  SUBCOMPONENT @1019  /* The BG1 NPC Project: Cloakwood areas availability in Chapter One */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE ((NOT FILE_EXISTS_IN_GAME ~cdt01035.g3~) AND (NOT FILE_EXISTS_IN_GAME ~cdt01036.g3~)) @1101 /* ~The functionality of this component is either already included or superceded by one of your already installed mods.~ */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* ~BG1 NPC Required Changes component is not installed.~ */
    COPY ~BG1NPC/Core/X#component.xx~ ~override/X#BG1NPCCloakwood.G3~
    COPY_EXISTING ~worldmap.wmp~ ~override~
  READ_LONG  0x30 "area_num"
  READ_LONG  0x34 "area_off"
  FOR (index = 0; index < area_num; index = index + 1) BEGIN
    READ_ASCII ("%area_off%" + 0x08 + (0xf0 * "%index%")) "area_res"
    PATCH_IF (("%area_res%" STRING_COMPARE_CASE "fw2200" = 0) OR     //  cloakwood 1 (tutu)
              ("%area_res%" STRING_COMPARE_CASE "ar7000" = 0) OR     //  cloakwood 1 (bgt)
              ("%area_res%" STRING_COMPARE_CASE "ar2200" = 0)) BEGIN //  cloakwood 1 (bgee)
      READ_BYTE  ("%area_off%" + 0x30 + (0xf0 * "%index%")) "flags"
      WRITE_BYTE ("%area_off%" + 0x30 + (0xf0 * "%index%")) ("%flags%" BOR 0b00000010) //  adds 'reveal thru linked area' flag
    END ELSE
    PATCH_IF (("%area_res%" STRING_COMPARE_CASE "fw1800" = 0) OR     //  cloakwood mines (tutu)
              ("%area_res%" STRING_COMPARE_CASE "ar8600" = 0) OR     //  cloakwood mines (bgt)
              ("%area_res%" STRING_COMPARE_CASE "AR1800" = 0)) BEGIN //  cloakwood mines (bgee)
      READ_BYTE  ("%area_off%" + 0x30 + (0xf0 * "%index%")) "flags"
      WRITE_BYTE ("%area_off%" + 0x30 + (0xf0 * "%index%")) ("%flags%" BAND 0b11111101) //  removes 'reveal thru linked area' flag
    END
  END
  BUT_ONLY_IF_IT_CHANGES

  COPY_EXISTING_REGEXP GLOB ~^\(_ar1901\|ar8701\|ar1901\)\.bcs$~ ~override~
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY ~RevealAreaOnMap("FW2200")~ ~RevealAreaOnMap("FW2200") RevealAreaOnMap("FW1800")~
      REPLACE_TEXTUALLY ~RevealAreaOnMap("AR7000")~ ~RevealAreaOnMap("AR7000") RevealAreaOnMap("AR8600")~
      REPLACE_TEXTUALLY ~RevealAreaOnMap("AR2200")~ ~RevealAreaOnMap("AR2200") RevealAreaOnMap("AR1800")~
    END
  BUT_ONLY_IF_IT_CHANGES

  PRINT @1003 /* Please remember to start a new game to access the contents of this component. */

BEGIN @1114 /* The BG1 NPC Project: SixofSpades Extended Sarevok's Diary */
  SUBCOMPONENT @1115  /* The BG1 NPC Project: Sarevok's Diary Adjustments. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  /* SixofSpades Sarevok's Diary changes, Tutu/BGT */
  COPY_EXISTING ~%tutu_var%SCRL3F.itm~ ~override~
    SAY UNIDENTIFIED_DESC @575
    SAY DESC @575
    WRITE_SHORT 0x1c 0x25 //  Sets item category from Scrolls to Books
    WRITE_BYTE 0x4c 0x08 //  Sets weight to 8 lbs
    BUT_ONLY_IF_IT_CHANGES

BEGIN @1116 /* The BG1 NPC Project: Sarevok's Diary Date Changes only */
  SUBCOMPONENT @1115  /* The BG1 NPC Project: Sarevok's Diary Adjustments. */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
  /* Fixing Sarevok's Diary dates changed only, Tutu/BGT */
  COPY_EXISTING ~%tutu_var%SCRL3F.itm~ ~override~
    SAY UNIDENTIFIED_DESC @2
    SAY DESC @2
    WRITE_SHORT 0x1c 0x25 //  Sets item category from Scrolls to Books
    WRITE_BYTE 0x4c 0x08 //  Sets weight to 8 lbs
    BUT_ONLY_IF_IT_CHANGES

/* TutuFix Walking Speeds Component Check -- keep next-to-last to compile */
BEGIN @1090 /* The BG1 NPC Project: Check for TutuFix Walking Speeds */
  GROUP @1065 /* The BG1 NPC Project: Tweaks */
  REQUIRE_PREDICATE (GAME_IS ~tutu tutu_totsc~) @1093 /* This component is only useful for Tutu installs. */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    /* Detect Walking Speeds install */
    COPY_EXISTING ~_montar.cre~ ~override~
      READ_BYTE  0x33 "eff_version"
      READ_LONG  0x2c4 "effects_offset"
      READ_LONG  0x2c8 "fx_num"
      SET "adjust_speed" = 0
      PATCH_IF ("%eff_version%" = 0) BEGIN
        FOR (loops = 0 ; loops < fx_num ; loops = loops + 1) BEGIN
          READ_SHORT ("%effects_offset%" + ("%loops%" * 0x30)) "type"
          PATCH_IF (("%type%" = 176) OR ("%type%" = 126)) BEGIN
            SET "loops" = "%fx_num%"
            SET "adjust_speed" = 1
          END
        END
      END ELSE BEGIN
        FOR (loops = 0 ; loops < fx_num ; loops = loops + 1) BEGIN
          READ_LONG ("%effects_offset%" + 8 + ("%loops%" * 264)) "type"
          PATCH_IF (("%type%" = 176) OR ("%type%" = 126)) BEGIN
            SET "loops" = "%fx_num%"
            SET "adjust_speed" = 1
          END
        END
      END
    BUT_ONLY_IF_IT_CHANGES

  /* Patching BG1NPC added creatures for Walking Speeds */
  COPY_EXISTING_REGEXP GLOB  ~^[XP]#.*\.cre$~ ~override~
    READ_BYTE  0x33  "eff_version" ELSE 2
    PATCH_IF (("%adjust_speed%" = 1) AND ("%eff_version%" < 2)) BEGIN
      READ_LONG  0x2b0 "known_offset"
      READ_LONG  0x2b8 "slots_offset"
      READ_LONG  0x2bc "items_offset"
      READ_LONG  0x2c4 "effects_offset"
      READ_LONG  0x2c8 "num_effects"
      WRITE_LONG 0x2c8 ("%num_effects%" + 1)
        PATCH_IF ("%eff_version%" = 0) BEGIN
          PATCH_IF ("%known_offset%" >= "%effects_offset%") BEGIN
            WRITE_LONG 0x2b0 ("%known_offset%" + 48)
          END
          PATCH_IF ("%slots_offset%" >= "%effects_offset%") BEGIN
            WRITE_LONG 0x2b8 ("%slots_offset%" + 48)
          END
          PATCH_IF ("%items_offset%" >= "%effects_offset%") BEGIN
            WRITE_LONG 0x2bc ("%items_offset%" + 48)
          END
          INSERT_BYTES  ("%effects_offset%"     ) 48
          WRITE_SHORT ("%effects_offset%"     ) 176
          WRITE_BYTE  ("%effects_offset%" +  2) 1 //  target=self
          WRITE_LONG  ("%effects_offset%" +  4) 0xfffffffd //  walking speed
          WRITE_LONG  ("%effects_offset%" +  8) 0 //  modifier type inc/dec
          WRITE_BYTE  ("%effects_offset%" + 12) 9 //  timing mode permanent
          WRITE_BYTE  ("%effects_offset%" + 18) 100
        END ELSE BEGIN
          PATCH_IF ("%known_offset%" >= "%effects_offset%") BEGIN
            WRITE_LONG 0x2b0 ("%known_offset%" + 264)
          END
          PATCH_IF ("%slots_offset%" >= "%effects_offset%") BEGIN
            WRITE_LONG 0x2b8 ("%slots_offset%" + 264)
          END
          PATCH_IF ("%items_offset%" >= "%effects_offset%") BEGIN
            WRITE_LONG 0x2bc ("%items_offset%" + 264)
          END
          INSERT_BYTES  ("%effects_offset%"     ) 264
          WRITE_LONG  ("%effects_offset%" +  8) 176
          WRITE_LONG  ("%effects_offset%" + 12) 1
          WRITE_LONG  ("%effects_offset%" + 20) 0xfffffffd
          WRITE_LONG  ("%effects_offset%" + 24) 0
          WRITE_LONG  ("%effects_offset%" + 28) 9
          WRITE_SHORT ("%effects_offset%" + 36) 100
        END
    END
  BUT_ONLY_IF_IT_CHANGES

/* Player-Initiated Dialogues  -always keep the VERY last of BG1NPC to compile! */
BEGIN @1091 DESIGNATED 200    /* The BG1 NPC Project: Player-Initiated Dialogues */
  REQUIRE_FILE ~override/X#BG1NPCCore.G3~ @1004 /* BG1 NPC Required Changes component is not installed. */
    /* set up .tra files for Tutu vs BGT sound resources, create platform files */
    COPY ~BG1NPC/TRA/%LANGUAGE%/X#PCINIT_tmp.tra~ ~BG1NPC/TRA/%LANGUAGE%/X#PCINIT.tra~
        EVALUATE_BUFFER
    COPY ~BG1NPC/TRA/%LANGUAGE%/X#AJPCFL_tmp.tra~ ~BG1NPC/TRA/%LANGUAGE%/X#AJPCFL.tra~
        EVALUATE_BUFFER
    /* install PIDs */
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/PID/X#PCINIT.D~
    COMPILE EVALUATE_BUFFER ~BG1NPC/Phase3/PID/X#AJPCFL.D~

/* End of File. Enjoy! */
