COPY_EXISTING_REGEXP GLOB ~^anomen[0-9]*\.cre~ ~override~
                          ~^imoen[0-9]*\.cre~  ~override~
                          ~^mazzy[0-9]*\.cre~  ~override~
 READ_LONG 0x244 "current_kit_value"
 PATCH_IF ("%current_kit_value%" = 0x00000000) BEGIN
   WRITE_LONG 0x244 0x40000000
 END
 BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING_REGEXP GLOB ~^haer[0-9]*\.cre~ ~override~
 READ_LONG 0x244 "current_kit_value"
 PATCH_IF ("%current_kit_value%" = 0x00000020) BEGIN
   WRITE_LONG 0x244 0x400d0000
 END
 BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING_REGEXP GLOB ~^korgan[0-9]*\.cre~ ~override~
 READ_LONG 0x244 "current_kit_value"
 PATCH_IF ("%current_kit_value%" = 0x00010000) BEGIN
   WRITE_LONG 0x244 0x40010000
 END
 BUT_ONLY_IF_IT_CHANGES

/*
 * Situations that need to be handled:
 * Let # denote any character that constitutes a word boundary
 * KITNAME1 - i.e., numbers (on either side); do not want to replace
 * FOO#KITNAME - do not want to replace
 * KITNAME#FOO - do not want to replace
 * KITNAME - the one we want to replace
 * \b is not suitable because it replaces the second and third example
 */
COPY_EXISTING ~kit.ids~ ~override~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(TRUECLASS[ %TAB%%WNL%]+\)~              ~0x4000 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(BERSERKER[ %TAB%%WNL%]+\)~              ~0x4001 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(WIZARDSLAYER[ %TAB%%WNL%]+\)~           ~0x4002 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(KENSAI[ %TAB%%WNL%]+\)~                 ~0x4003 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(CAVALIER[ %TAB%%WNL%]+\)~               ~0x4004 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(INQUISITOR[ %TAB%%WNL%]+\)~             ~0x4005 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(UNDEADHUNTER[ %TAB%%WNL%]+\)~           ~0x4006 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_ABJURER[ %TAB%%WNL%]+\)~     ~0x0040 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_CONJURER[ %TAB%%WNL%]+\)~    ~0x0080 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_DIVINER[ %TAB%%WNL%]+\)~     ~0x0100 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_ENCHANTER[ %TAB%%WNL%]+\)~   ~0x0200 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_ILLUSIONIST[ %TAB%%WNL%]+\)~ ~0x0400 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_INVOKER[ %TAB%%WNL%]+\)~     ~0x0800 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_NECROMANCER[ %TAB%%WNL%]+\)~ ~0x1000 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_TRANSMUTER[ %TAB%%WNL%]+\)~  ~0x2000 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(MAGESCHOOL_GENERALIST[ %TAB%%WNL%]+\)~  ~0x4000 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(FERALAN[ %TAB%%WNL%]+\)~                ~0x4007 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(STALKER[ %TAB%%WNL%]+\)~                ~0x4008 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(BEASTMASTER[ %TAB%%WNL%]+\)~            ~0x4009 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(ASSASIN[ %TAB%%WNL%]+\)~                ~0x400A \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(BOUNTYHUNTER[ %TAB%%WNL%]+\)~           ~0x400B \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(SWASHBUCKLER[ %TAB%%WNL%]+\)~           ~0x400C \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(BLADE[ %TAB%%WNL%]+\)~                  ~0x400D \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(JESTER[ %TAB%%WNL%]+\)~                 ~0x400E \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(SKALD[ %TAB%%WNL%]+\)~                  ~0x400F \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(GODTALOS[ %TAB%%WNL%]+\)~               ~0x4013 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(GODHELM[ %TAB%%WNL%]+\)~                ~0x4014 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(GODLATHANDER[ %TAB%%WNL%]+\)~           ~0x4015 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(TOTEMIC[ %TAB%%WNL%]+\)~                ~0x4010 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(SHAPESHIFTER[ %TAB%%WNL%]+\)~           ~0x4011 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(BEASTFRIEND[ %TAB%%WNL%]+\)~            ~0x4012 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(BARBARIAN[ %TAB%%WNL%]+\)~              ~0x40000000 \1~
  REPLACE_TEXTUALLY ~.+[ %TAB%]\(WILDMAGE[ %TAB%%WNL%]+\)~               ~0x80000000 \1~
BUT_ONLY

APPEND ~kit.ids~ ~0x4000 TRUECLASS~ UNLESS ~[ %TAB%]TRUECLASS[ %TAB%%WNL%]+~
APPEND ~kit.ids~ ~0x40000000 BARBARIAN~ UNLESS ~[ %TAB%]BARBARIAN[ %TAB%%WNL%]+~
APPEND ~kit.ids~ ~0x80000000 WILDMAGE~ UNLESS ~[ %TAB%]WILDMAGE[ %TAB%%WNL%]+~

COPY_EXISTING ~race.ids~ ~override~
  REPLACE_TEXTUALLY ~^149[ %TAB%]+SHADOW\([ %TAB%%WNL%]+\)~ ~149 STATUE\1~
BUT_ONLY_IF_IT_CHANGES

APPEND ~ACTION.IDS~ ~31 SpellRES(S:RES*,O:Target*)~
UNLESS ~31[ %TAB%]+SpellRES~
APPEND ~ACTION.IDS~ ~95 SpellPointRES(S:RES*,P:Target*)~
UNLESS ~95[ %TAB%]+SpellPointRES~
APPEND ~ACTION.IDS~ ~113 ForceSpellRES(S:RES*,O:Target)~
UNLESS ~113[ %TAB%]+ForceSpellRES~
APPEND ~ACTION.IDS~ ~114 ForceSpellPointRES(S:RES*,P:Target)~
UNLESS ~114[ %TAB%]+ForceSpellPointRES~
APPEND ~ACTION.IDS~ ~160 ApplySpellRES(S:RES*,O:Target)~
UNLESS ~160[ %TAB%]+ApplySpellRES~
APPEND ~ACTION.IDS~ ~181 ReallyForceSpellRES(S:RES*,O:Target)~
UNLESS ~181[ %TAB%]+ReallyForceSpellRES~
APPEND ~ACTION.IDS~ ~191 SpellNoDecRES(S:RES*,O:Target*)~
UNLESS ~191[ %TAB%]+SpellNoDecRES~
APPEND ~ACTION.IDS~ ~192 SpellPointNoDecRES(S:RES*,P:Target*)~
UNLESS ~192[ %TAB%]+SpellPointNoDecRES~
APPEND ~ACTION.IDS~ ~240 ReallyForceSpellDeadRES(S:RES*,O:Target)~
UNLESS ~240[ %TAB%]+ReallyForceSpellDeadRES~
APPEND ~ACTION.IDS~ ~318 ForceSpellRangeRES(S:RES*,O:Target)~
UNLESS ~318[ %TAB%]+ForceSpellRangeRES~
APPEND ~ACTION.IDS~ ~319 ForceSpellPointRangeRES(S:RES*,P:Target)~
UNLESS ~319[ %TAB%]+ForceSpellPointRangeRES~
APPEND ~ACTION.IDS~ ~337 ReallyForceSpellPointRES(S:RES*,P:Target*)~
UNLESS ~337[ %TAB%]+ReallyForceSpellPointRES~
APPEND ~ACTION.IDS~ ~336 MakeGlobal()~
UNLESS ~MakeGlobal~
APPEND ~ACTION.IDS~ ~339 SwingOnce()~
UNLESS ~339[ %TAB%]+SwingOnce~
APPEND ~ACTION.IDS~ ~338 SetCutSceneLite(I:BOOL*BOOLEAN)~
UNLESS ~338[ %TAB%]+SetCutSceneLite~
APPEND ~ACTION.IDS~ ~345 SetSequence(I:Sequence*SEQ)~
UNLESS ~345[ %TAB%]+SetSequence~

APPEND ~TRIGGER.IDS~ ~0x4031 HaveSpellRES(S:Spell*)~
UNLESS ~0x4031[ %TAB%]+HaveSpellRES~
APPEND ~TRIGGER.IDS~ ~0x40DA HaveSpellParty(I:Spell*Spell)~
UNLESS ~0x40DA[ %TAB%]+HaveSpellParty~
APPEND ~TRIGGER.IDS~ ~0x40D5 ActuallyInCombat()~
UNLESS ~0x40D5[ %TAB%]+ActuallyInCombat()~

APPEND ~CLASS.IDS~ ~202 LONG_BOW~
UNLESS ~202[ %TAB%]+LONG_BOW~
APPEND ~CLASS.IDS~ ~202 MAGE_ALL~
UNLESS ~202[ %TAB%]+MAGE_ALL~

APPEND ~STATE.IDS~ ~0x00000FC0 STATE_REALLY_DEAD~
UNLESS ~0x00000FC0[ %TAB%]+STATE_REALLY_DEAD~
APPEND ~STATE.IDS~ ~0x80101FEF CD_STATE_NOTVALID~
UNLESS ~CD_STATE_NOTVALID~
APPEND ~STATE.IDS~ ~0x00000029 D0_STATE_DISABLED~ // STUNNED, HELPLESS, SLEEP
UNLESS ~D0_STATE_DISABLED~

CLEAR_IDS_MAP
