Grammarsalad / Proficiencies

This is a mod that adds proficiencies and skills to the Enhanced Edition IE games (BGEE, BG2EE, and IWDEE).
https://Grammarsalad.github.io/Proficiencies/
Creative Commons Zero v1.0 Universal
1 stars 2 forks source link

Save Bonuses for exceptional attributes #42

Open Grammarsalad opened 5 years ago

Grammarsalad commented 5 years ago

 COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 BEGIN   //wiz spells
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 6  OR  //If invoker school (I think)
                      school = 7  OR  //necromancy
                      school = 4  OR  //enchanter
                      school = 5  BEGIN  //illusionist
         READ_STRREF 0x50 ~sv_des~  //save description
               PATCH_IF ("%sv_des%" STRING_CONTAINS_REGEXP "Saving Throw: None" != 0)  BEGIN   //if spell text does NOT contain this phrase:  Saving Throw: None
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN
         END
         INNER_PATCH_SAVE cus1 ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_M~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_A~  //what are these? 'prefix'
         END
PATCH_IF school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END
        END  //%cus2%A.SPL not in game

    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END
        END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add =  1          //
             END      //
           END
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END
         END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END
         END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END
         END //%cus2%G.SPL not in game
      END   //save not 0
      END   //opcode 12
      //other opcodes?  111 doesn't seem to apply (any require saves???)
/*
      PATCH_IF fx_type = 111 BEGIN
        PATCH_PRINT "%item%"  //test
      END
*/
    END   //pnp_each
        END //pnp_each
        END //evocation check
PATCH_IF school = 4  OR //enchanter --vs A LOT of different kind of effects...  
         school = 5  OR //illusionist (fear, ...)
         school = 9  BEGIN //another check for just necromancer --wis vs fear
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF 
      fx_type = 5  OR       // opcode 5 (Charm)
      //NEXT
      fx_type = 24 BEGIN    //opcode 24 (Horror)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0

          END //save not 0
      END //opcode check (fear, sleep, 
    END//PHP
  END//PHP
  END// Mind affecting schools (enchant/illusion/necromancy)
             END //end description no save
            END //(nec, illusionist, enchant, evocation) school check

        END  //wiz spells
      END   //source size
    BUT_ONLY
Grammarsalad commented 5 years ago

 COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 BEGIN   //wiz spells
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 6  OR  //If invoker school (I think)
                      school = 7  OR  //necromancy
                      school = 4  OR  //enchanter
                      school = 5  BEGIN  //illusionist
         READ_STRREF 0x50 ~sv_des~  //save description
               PATCH_IF ("%sv_des%" STRING_CONTAINS_REGEXP "Saving Throw: None" != 0)  BEGIN   //if spell text does NOT contain this phrase:  Saving Throw: None
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN
         END
         INNER_PATCH_SAVE cus1 ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_M~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_A~  //what are these? 'prefix'
         END
PATCH_IF school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END
        END  //%cus2%A.SPL not in game

    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END
        END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add =  1          //
             END      //
           END
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END
         END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END
         END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END
         END //%cus2%G.SPL not in game
      END   //save not 0
      END   //opcode 12
      //other opcodes?  111 doesn't seem to apply (any require saves???)
/*
      PATCH_IF fx_type = 111 BEGIN
        PATCH_PRINT "%item%"  //test
      END
*/
    END   //pnp_each
        END //pnp_each
        END //evocation check
PATCH_IF school = 4  OR //enchanter --vs A LOT of different kind of effects...  
//             school = 9  BEGIN //another check for just necromancer --wis vs fear, but do separately (i.e. with con based death saves)
                school = 5  BEGIN //illusionist (fear, blindness, deafness ...)
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF 
      fx_type = 2 OR       // opcode 2 (Sleep)
      fx_type = 3 OR       // opcode 3 (Berserking)
      fx_type = 5 OR       // opcode 5 (Charm)
      fx_type = 24 OR       // opcode 24 (Horror)
      fx_type = 39 OR       // opcode 39 (Unconsciousness)
      fx_type = 45 OR       // opcode 45 (Stun)
      fx_type = 74 OR       // opcode 74 (Blindness)
      fx_type = 76 OR       // opcode 76 (Feeblemind)
      fx_type = 80 OR       // opcode 80 (Deafness)
      fx_type = 109 OR       // opcode 109 (Hold)
      fx_type = 128 OR       // opcode 128 (Confusion)
      fx_type = 175 OR       // opcode 175 (Hold)
      fx_type = 241 OR       // opcode 241 (Charm)
      fx_type = 246 OR       // opcode 246 (Berserking)
      fx_type = 247 BEGIN // opcode 247 (Attack nearest creature)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
//CONTINUE          
          END //save not 0
      END //opcode check (fear, sleep, 
    END//PHP
  END//PHP
  END// Mind affecting schools (enchant/illusion/necromancy)
             END //end description no save
            END //(nec, illusionist, enchant, evocation) school check

        END  //wiz spells
      END   //source size
    BUT_ONLY
Grammarsalad commented 5 years ago
 COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 BEGIN   //wiz spells
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 6  OR  //If invoker school (I think)
                      school = 7  OR  //necromancy
                      school = 4  OR  //enchanter
                      school = 5  BEGIN  //illusionist
         READ_STRREF 0x50 ~sv_des~  //save description
               PATCH_IF ("%sv_des%" STRING_CONTAINS_REGEXP "Saving Throw: None" != 0)  BEGIN   //if spell text does NOT contain this phrase:  Saving Throw: None
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN
         END
         INNER_PATCH_SAVE cus1 ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_M~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_A~  //what are these? 'prefix'
         END
PATCH_IF school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END
        END  //%cus2%A.SPL not in game

    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END
        END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add =  1          //
             END      //
           END
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END
         END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END
         END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END
         END //%cus2%G.SPL not in game
      END   //save not 0
      END   //opcode 12
      //other opcodes?  111 doesn't seem to apply (any require saves???)
/*
      PATCH_IF fx_type = 111 BEGIN
        PATCH_PRINT "%item%"  //test
      END
*/
    END   //pnp_each
        END //pnp_each
        END //evocation check
PATCH_IF school = 4  OR //enchanter --vs A LOT of different kind of effects...  
         school = 5  OR //illusionist (fear, ...)
         school = 9  BEGIN //another check for just necromancer --wis vs fear
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF 
      fx_type = 5  OR       // opcode 5 (Charm)
      //NEXT
      fx_type = 24 BEGIN    //opcode 24 (Horror)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END
            END //not %cus2%A.SPL in game
          END //save not 0
      END //opcode check (fear, sleep, 
    END//PHP
  END//PHP
  END// Mind affecting schools (enchant/illusion/necromancy)
             END //end description no save
            END //(nec, illusionist, enchant, evocation) school check

        END  //wiz spells
      END   //source size
    BUT_ONLY
Grammarsalad commented 5 years ago
 COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 BEGIN   //wiz spells
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 6  OR  //If invoker school (I think)
                      school = 7  OR  //necromancy
                      school = 4  OR  //enchanter
                      school = 5  BEGIN  //illusionist
         READ_STRREF 0x50 ~sv_des~  //save description
               PATCH_IF ("%sv_des%" STRING_CONTAINS_REGEXP "Saving Throw: None" != 0)  BEGIN   //if spell text does NOT contain this phrase:  Saving Throw: None
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN
         END
         INNER_PATCH_SAVE cus1 ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_M~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_A~  //what are these? 'prefix'
         END
PATCH_IF school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END
        END  //%cus2%A.SPL not in game

    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END
        END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add =  1          //
             END      //
           END
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END
         END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END
         END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END
         END //%cus2%G.SPL not in game
      END   //save not 0
      END   //opcode 12
      //other opcodes?  111 doesn't seem to apply (any require saves???)
/*
      PATCH_IF fx_type = 111 BEGIN
        PATCH_PRINT "%item%"  //test
      END
*/
    END   //pnp_each
        END //pnp_each
        END //evocation check
PATCH_IF school = 4  OR //enchanter --vs A LOT of different kind of effects...  
//             school = 9  BEGIN //another check for just necromancer --wis vs fear, but do separately (i.e. with con based death saves)
                school = 5  BEGIN //illusionist (fear, blindness, deafness ...)
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF 
      fx_type = 2 OR       // opcode 2 (Sleep)
      fx_type = 3 OR       // opcode 3 (Berserking)
      fx_type = 5 OR       // opcode 5 (Charm)
      fx_type = 24 OR       // opcode 24 (Horror)
      fx_type = 39 OR       // opcode 39 (Unconsciousness)
      fx_type = 45 OR       // opcode 45 (Stun)
      fx_type = 74 OR       // opcode 74 (Blindness)
      fx_type = 76 OR       // opcode 76 (Feeblemind)
      fx_type = 80 OR       // opcode 80 (Deafness)
      fx_type = 109 OR       // opcode 109 (Hold)
      fx_type = 128 OR       // opcode 128 (Confusion)
      fx_type = 175 OR       // opcode 175 (Hold)
      fx_type = 241 OR       // opcode 241 (Charm)
      fx_type = 246 OR       // opcode 246 (Berserking)
      fx_type = 247 BEGIN // opcode 247 (Attack nearest creature)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END        
          END //save not 0
      END //opcode check (fear, sleep, 
    END//PHP
  END//PHP
  END// Mind affecting schools (enchant/illusion/necromancy)
             END //end description no save
            END //(nec, illusionist, enchant, evocation) school check

        END  //wiz spells
      END   //source size
    BUT_ONLY
Grammarsalad commented 5 years ago
 COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 BEGIN   //wiz spells
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 6  OR  //If invoker school (I think)
                      school = 7  OR  //necromancy
                      school = 4  OR  //enchanter
                      school = 5  BEGIN  //illusionist
         READ_STRREF 0x50 ~sv_des~  //save description
               PATCH_IF ("%sv_des%" STRING_CONTAINS_REGEXP "Saving Throw: None" != 0)  BEGIN   //if spell text does NOT contain this phrase:  Saving Throw: None
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN
         END
         INNER_PATCH_SAVE cus1 ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_M~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_A~  //what are these? 'prefix'
         END
PATCH_IF school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END
        END  //%cus2%A.SPL not in game

    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END
        END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add =  1          //
             END      //
           END
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END
         END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END
         END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END
         END //%cus2%G.SPL not in game
      END   //save not 0
      END   //opcode 12
      //other opcodes?  111 doesn't seem to apply (any require saves???)
/*
      PATCH_IF fx_type = 111 BEGIN
        PATCH_PRINT "%item%"  //test
      END
*/
    END   //pnp_each
        END //pnp_each
        END //evocation check
PATCH_IF school = 4  OR //enchanter --vs A LOT of different kind of effects...  
//             school = 9  BEGIN //another check for just necromancer --wis vs fear, but do separately (i.e. with con based death saves)
                school = 5  BEGIN //illusionist (fear, blindness, deafness ...)
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF 
      fx_type = 2 OR       // opcode 2 (Sleep)
      fx_type = 3 OR       // opcode 3 (Berserking)
      fx_type = 5 OR       // opcode 5 (Charm)
      fx_type = 24 OR       // opcode 24 (Horror)
      fx_type = 39 OR       // opcode 39 (Unconsciousness)
      fx_type = 45 OR       // opcode 45 (Stun)
      fx_type = 74 OR       // opcode 74 (Blindness)
      fx_type = 76 OR       // opcode 76 (Feeblemind)
      fx_type = 80 OR       // opcode 80 (Deafness)
      fx_type = 109 OR       // opcode 109 (Hold)
      fx_type = 128 OR       // opcode 128 (Confusion)
      fx_type = 175 OR       // opcode 175 (Hold)
      fx_type = 241 OR       // opcode 241 (Charm)
      fx_type = 246 OR       // opcode 246 (Berserking)
      fx_type = 247 BEGIN // opcode 247 (Attack nearest creature)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF cd_apply_batch STR_VAR array_name = b_wis_charm_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
             WRITE_LONG 0x0008 ~%name%~
             WRITE_LONG 0x0034 level //spell level
             WRITE_LONG 0x000c ~%name%~
             WRITE_LONG 0x0054 ~%desc%~
             WRITE_SHORT 0x007E target //Target-check
             WRITE_SHORT 0x0080 range //range-check
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END        
          END //save not 0
      END //opcode check (fear, sleep,
    END//PHP
  END//PHP
  END// Mind affecting schools (enchant/illusion/necromancy)
             END //end description no save
            END //(nec, illusionist, enchant, evocation) school check

        END  //wiz spells
      END   //source size
    BUT_ONLY
Grammarsalad commented 5 years ago
 COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 BEGIN   //wiz spells
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 6  OR  //If invoker school (I think)
                      school = 7  OR  //necromancy
                      school = 4  OR  //enchanter
                      school = 5  BEGIN  //illusionist
         READ_STRREF 0x50 ~sv_des~  //save description
               PATCH_IF ("%sv_des%" STRING_CONTAINS_REGEXP "Saving Throw: None" != 0)  BEGIN   //if spell text does NOT contain this phrase:  Saving Throw: None
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN
         END
         INNER_PATCH_SAVE cus1 ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_M~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_A~  //what are these? 'prefix'
         END
PATCH_IF school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END
        END  //%cus2%A.SPL not in game

    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END
        END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add =  1          //
             END      //
           END
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END
         END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END
         END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END
         END //%cus2%G.SPL not in game
      END   //save not 0
      END   //opcode 12
      //other opcodes?  111 doesn't seem to apply (any require saves???)
/*
      PATCH_IF fx_type = 111 BEGIN
        PATCH_PRINT "%item%"  //test
      END
*/
    END   //pnp_each
        END //pnp_each
        END //evocation check
PATCH_IF school = 4  OR //enchanter --vs A LOT of different kind of effects...  
//             school = 9  BEGIN //another check for just necromancer --wis vs fear, but do separately (i.e. with con based death saves)
                school = 5  BEGIN //illusionist (fear, blindness, deafness ...)
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF 
      fx_type = 2 BEGIN // opcode 2 (Sleep)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_sleep_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // not %cus2%A.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game
          END //save not 0
      END //opcode check (fear, sleep,
PATCH_IF 
      fx_type = 39 BEGIN // opcode 39 (Unconsciousness)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_uncon_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // not %cus2%A.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game
          END //save not 0
      END //opcode check (fear, sleep,    END//PHP
PATCH_IF 
      fx_type = 45 OR      // opcode 45 (Stun) 
      fx_type = 109 OR     // opcode 109 (Hold)
      fx_type = 175 BEGIN  // opcode 175 (Hold)
      /*
      fx_type = 3 OR       // opcode 3 (Berserking) (enchant)
      fx_type = 246 OR     // opcode 246 (Berserking) (enchant)
      fx_type = 247 OR     // opcode 247 (Attack nearest creature)
      fx_type = 24 OR      // opcode 24 (Horror) (illusion, nec, enchant)
      fx_type = 74 OR      // opcode 74 (Blindness) (illusion)
      fx_type = 80 OR      // opcode 80 (Deafness) (illusion)
      fx_type = 76 OR      // opcode 76 (Feeblemind) (enchant)
      fx_type = 128 OR     // opcode 128 (Confusion) (enchant)
      fx_type = 5 OR       // opcode 5 (Charm)
      fx_type = 241 BEGIN */        // opcode 241 (Charm)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_stun_arrays_sr END  //wis apply spl
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold1_arrays_sr END //wis apply spl
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold2_arrays_sr END //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // not %cus2%A.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game
          END //save not 0
      END //opcode check (fear, sleep,    END//PHP
  END//PHP
  END// Mind affecting schools (enchant/illusion/necromancy)
             END //end description no save
            END //(nec, illusionist, enchant, evocation) school check

        END  //wiz spells
      END   //source size
    BUT_ONLY
Grammarsalad commented 5 years ago
COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 OR //wiz spells
                    type = 2 OR //cleric
                    type = 4 BEGIN   //Innate
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 6  OR  //If invoker school (I think)
                      school = 7  OR  //necromancy
                      school = 4  OR  //enchanter
                      school = 5  BEGIN  //illusionist
         READ_STRREF 0x50 ~sv_des~  //save description
               PATCH_IF ("%sv_des%" STRING_CONTAINS_REGEXP "Saving Throw: None" != 0)  BEGIN   //if spell text does NOT contain this phrase:  Saving Throw: None
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN
         END
         INNER_PATCH_SAVE cusz ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPPR~ ~B_P~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cusy ~%cusz%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPRA~ ~B_R~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cusx ~%cusy%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_R~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cus1 ~%cusx%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPIN~ ~B_M~  //standard mage 'prefix'
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_A~  //what are these? 'prefix'
         END
PATCH_IF school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END
        END  //%cus2%A.SPL not in game

    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END
        END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add =  1          //
             END      //
           END
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END
         END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END
         END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END
         END //%cus2%G.SPL not in game
      END   //save not 0
      END   //opcode 12
      //other opcodes?  111 doesn't seem to apply (any require saves???)
/*
      PATCH_IF fx_type = 111 BEGIN
        PATCH_PRINT "%item%"  //test
      END
*/
    END   //pnp_each
        END //pnp_each
        END //evocation check
PATCH_IF school = 4  OR //enchanter --vs A LOT of different kind of effects...
         school = 5  BEGIN //illusionist (fear, blindness, deafness ...)
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF 
      fx_type = 2 BEGIN // opcode 2 (Sleep)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_sleep_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // not %cus2%A.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game
          END //save not 0
      END //opcode check (fear, sleep,
PATCH_IF 
      fx_type = 39 BEGIN // opcode 39 (Unconsciousness)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_uncon_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // not %cus2%A.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game
          END //save not 0
      END //opcode check (fear, sleep,
PATCH_IF
      fx_type = 45 OR      // opcode 45 (Stun)
      fx_type = 109 OR     // opcode 109 (Hold)
      fx_type = 175 BEGIN  // opcode 175 (Hold)
      /*
      fx_type = 3 OR       // opcode 3 (Berserking) (enchant)
      fx_type = 246 OR     // opcode 246 (Berserking) (enchant)
      fx_type = 247 OR     // opcode 247 (Attack nearest creature)
      fx_type = 24 OR      // opcode 24 (Horror) (illusion, nec, enchant)
      fx_type = 74 OR      // opcode 74 (Blindness) (illusion)
      fx_type = 80 OR      // opcode 80 (Deafness) (illusion)
      fx_type = 76 OR      // opcode 76 (Feeblemind) (enchant)
      fx_type = 128 OR     // opcode 128 (Confusion) (enchant)
      fx_type = 5 OR       // opcode 5 (Charm)
      fx_type = 241 BEGIN */        // opcode 241 (Charm)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_stun_arrays_sr END  //wis apply spl
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold1_arrays_sr END //wis apply spl
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold2_arrays_sr END //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // not %cus2%A.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game
          END //save not 0
      END //opcode check (stun or hold)
PATCH_IF
      fx_type = 5 OR       // opcode 5 (Charm)
      fx_type = 241 BEGIN  // opcode 241 (Charm)
/*
      fx_type = 24 OR      // opcode 24 (Horror) (illusion, nec, enchant)
      fx_type = 76 OR      // opcode 76 (Feeblemind) (enchant)
      fx_type = 128 OR     // opcode 128 (Confusion) (enchant)
*/
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_charm1_arrays_sr END  //wis apply spl
             LPF cd_apply_batch STR_VAR array_name = b_wis_charm2_arrays_sr END //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // not %cus2%A.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game
        END //saves >0
END //charm opcode
  END  //PHP
  END  //PHP
             END    // Mind affecting schools (enchant/illusion)
PATCH_IF school = 7  BEGIN //just necromancer --wis vs fear, Con vs paralysis and death
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF
      fx_type = 13 OR      // opcode 13  (Death)
      fx_type = 45 OR      // opcode 45  (Stun)
      fx_type = 55 OR      // opcode 55  (Kill creature type)
      fx_type = 109 OR     // opcode 109 (Hold)
//      fx_type = 111 OR     // opcode 111 (Create magical weapon)
      fx_type = 209 OR      // opcode 209  (death 60hp)
      fx_type = 175 BEGIN  // opcode 175 (Hold)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_stun_arrays_sr END  //wis apply spl (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold1_arrays_sr END //wis apply spl (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold2_arrays_sr END //wis apply spl  (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_con_death1_arrays_sr END //con apply spl  
             LPF cd_apply_batch STR_VAR array_name = b_con_death2_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_death3_arrays_sr END //con apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // con less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // con greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // con less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // con = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // con = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // con = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // con = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // con = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // con = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // con = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // con = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // con greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // splA
           PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game
        END //save >0
      END//opcode paralysis/death
    END //php
  END //php
END //necromancer

PATCH_IF school = 7  OR     //necromancy
         school = 4  OR     //enchanter
         school = 5  BEGIN  //illusionist
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      PATCH_IF
      fx_type = 24 BEGIN     // opcode 24  (Fear)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_fear_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // splA
           PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game

          END //save not 0
      END //opcode 24

    END//PHP
  END //PHP
END //necromancy/illusion/charm
END //end description not no save
END   //(nec, illusionist, enchant, evocation) school check
END //spell type (wiz/cleric/innate)
END //source size
BUT_ONLY
Grammarsalad commented 5 years ago
COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 OR //wiz spells
                    type = 2 OR //cleric
                    type = 4 BEGIN   //Innate
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 0  OR  //If None school
                      school = 2  OR  //If Conjurer school
                      school = 4  OR  //enchanter
                      school = 5  OR  //illusionist
                      school = 6  OR  // invoker school
                      school = 7 BEGIN //necromancy
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN  //cus0 = sourc_res
         END
         INNER_PATCH_SAVE cusz ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPPR~ ~B_P~  //Priest SPPR --> B_P (cusz)
         END
         INNER_PATCH_SAVE cusy ~%cusz%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPRA~ ~B_R~  //SPRA -->B_R (cusy) Some ranger? spells
         END
         INNER_PATCH_SAVE cusx ~%cusy%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_W~  //standard mage 'prefix' SPWI-->B_W
         END
         INNER_PATCH_SAVE cus1 ~%cusx%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPIN~ ~B_I~  //innate SPIN--> B_I
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_M~  //what are these? SPWM--> B_M
         END
PATCH_IF school = 0 OR
         school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
               INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = (0 -2)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%A.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
                 LPF ALTER_EFFECT_ADD
                   INT_VAR savebonus_add = (0 -1)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add =  1          //
                  END      // Alter_effect
               END //Inner_Action
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 2          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 3          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 4          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 5          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%G.SPL not in game
          END  //save >0
      END //opcode 12
    END //PHP2
  END //PHP1
END //School (evocation only)
PATCH_IF school = 0  OR  //If None school
         school = 2  OR  //If Conjurer school
         school = 4  OR  //enchanter
         school = 5  OR  //illusionist
         school = 7 BEGIN //necromancy  Vs. Fear
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 24 BEGIN    //opcode 24 (fear)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_fear_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
               INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = (0 -2)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%A.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
                 LPF ALTER_EFFECT_ADD
                   INT_VAR savebonus_add = (0 -1)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add =  1          //
                  END      // Alter_effect
               END //Inner_Action
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 2          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 3          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 4          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 5          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%G.SPL not in game
          END //save >0
      END //opcode 24 (fear)
    END //PHP2
  END //PHP1
END//end nec, enchant, illusion, conjurer
PATCH_IF school = 0  OR  //If None school
         school = 2  OR  //If Conjurer school
         school = 4  OR  //enchanter
         school = 5 BEGIN//illusionist  Vs. mind
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 2 OR          // opcode 2 (Sleep)
               fx_type = 3 OR          // opcode 3 (Berserking) (enchant)
               fx_type = 5 OR          // opcode 5 (Charm)
               fx_type = 39 OR         // opcode 39 (Unconsciousness)
               fx_type = 45 OR         // opcode 45  (Stun)
               fx_type = 76 OR         // opcode 76 (Feeblemind) (enchant)
               fx_type = 109 OR        // opcode 109 (Hold)
               fx_type = 128 OR        // opcode 128 (Confusion) (enchant)
               fx_type = 175 OR        // opcode 175 (Hold)
               fx_type = 241 OR        // opcode 241 (Charm)
               fx_type = 246 OR        // opcode 246 (Berserking) (enchant)
               fx_type = 247 BEGIN     // opcode 247 (Attack nearest creature)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
              LPF cd_apply_batch STR_VAR array_name = b_wis_sleep_arrays_sr END  //wis apply sleep
              LPF cd_apply_batch STR_VAR array_name = b_wis_uncon_arrays_sr END  //wis apply unconsciousness
              LPF cd_apply_batch STR_VAR array_name = b_wis_stun_arrays_sr END  //wis apply stun
              LPF cd_apply_batch STR_VAR array_name = b_wis_hold1_arrays_sr END //wis apply hold1
              LPF cd_apply_batch STR_VAR array_name = b_wis_hold2_arrays_sr END //wis apply hold2
              LPF cd_apply_batch STR_VAR array_name = b_wis_charm1_arrays_sr END  //wis apply charm1
              LPF cd_apply_batch STR_VAR array_name = b_wis_charm2_arrays_sr END //wis apply charm2
              LPF cd_apply_batch STR_VAR array_name = b_wis_bersk1_arrays_sr END //wis apply berserk1
              LPF cd_apply_batch STR_VAR array_name = b_wis_bersk2_arrays_sr END //wis apply berserk2
              LPF cd_apply_batch STR_VAR array_name = b_wis_bersk3_arrays_sr END //wis apply berserk3
              LPF cd_apply_batch STR_VAR array_name = b_wis_feeble_arrays_sr END //wis apply feeblemind
              LPF cd_apply_batch STR_VAR array_name = b_wis_confuse_arrays_sr END //wis apply confusion
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
               INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = (0 -2)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%A.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
                 LPF ALTER_EFFECT_ADD
                   INT_VAR savebonus_add = (0 -1)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add =  1          //
                  END      // Alter_effect
               END //Inner_Action
        END //%cus2%C.SPL not in game
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 2          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%D.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 3          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%E.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 4          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%F.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 5          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%G.SPL not in game
          END//save >0
      END//opcodes
    END //PHP2
  END //PHP1
END//conjuration, enchant, illusion (rest of will saves)
PATCH_IF school = 0  OR  //If None school
         school = 2  OR  //If Conjurer school
         school = 7 BEGIN //necromancy  con Vs. death (and hold/stun for nec--other non nec *should* be skipped)
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 13 OR      // opcode 13  (Death)
               fx_type = 25 OR      // opcode 25  (poison)
               fx_type = 45 OR      // opcode 45  (Stun)
               fx_type = 55 OR      // opcode 55  (Kill creature type)
               fx_type = 78 OR      // opcode 78  (Disease)
               fx_type = 109 OR     // opcode 109 (Hold)
               fx_type = 209 OR      // opcode 209  (death 60hp)
               fx_type = 175 BEGIN  // opcode 175 (Hold)
     PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_stun_arrays_sr END  //wis apply spl (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold1_arrays_sr END //wis apply spl (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold2_arrays_sr END //wis apply spl  (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_con_death1_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_death2_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_death3_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_poison_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_disease_arrays_sr END //con apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // con less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // con greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // con less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // con = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // con = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // con = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // con = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // con = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // con = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // con = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // con = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // con greater than 19, cast splG (+5)
               INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = (0 -2)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%A.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
                 LPF ALTER_EFFECT_ADD
                   INT_VAR savebonus_add = (0 -1)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add =  1          //
                  END      // Alter_effect
               END //Inner_Action
        END //%cus2%C.SPL not in game
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 2          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%D.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 3          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%E.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 4          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%F.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 5          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%G.SPL not in game
      END //opcodes
    END //PHP2
  END //PHP1
END //nec/conjuration for death effects
//the end end
             END//School (none, conjuration, enchant, illusion, invoc, necromancy)
           END //Spell type (wiz/cleric/innate)
         END //source size

/*
      PATCH_IF
      fx_type = 111 BEGIN  // opcode 111 (Create magical weapon)
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                 COPY_EXISTING ~%item%.itm~ ~override~  //need to read and copy over effects to subspells
             PATCH_PRINT "%item%"  //test
               END//Inner action
      END//type create weapon
    END //php
  END //php
END //necromancer

PATCH_IF school = 7  OR     //necromancy
         school = 4  OR     //enchanter
         school = 5  BEGIN  //illusionist
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      PATCH_IF
      fx_type = 24 BEGIN     // opcode 24  (Fear)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_fear_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // splA
           PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game

          END //save not 0
      END //opcode 24

    END//PHP
  END //PHP
END //necromancy/illusion/charm
END //end description not no save
END   //(nec, illusionist, enchant, evocation) school check
END //spell type (wiz/cleric/innate)
END //source size
END //??
BUT_ONLY
*/
Grammarsalad commented 5 years ago
COPY_EXISTING_REGEXP GLOB ~.[^abcde]*\.SPL~ ~override~
     PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
      READ_BYTE 0x001C type //Spell type
       PATCH_IF type = 1 OR //wiz spells
                    type = 2 OR //cleric
                    type = 4 BEGIN   //Innate
            READ_BYTE 0x0025 school //school type
         PATCH_IF school = 0  OR  //If None school
                      school = 2  OR  //If Conjurer school
                      school = 4  OR  //enchanter
                      school = 5  OR  //illusionist
                      school = 6  OR  // invoker school
                      school = 7 BEGIN //necromancy
                READ_LONG  0x0034 level //spell level
            READ_LONG 0x0008 name //spell name
            READ_LONG 0x0050 desc //description
            READ_SHORT 0x007E target //Target-check
            READ_SHORT 0x0080 range //range-check
                READ_LONG  0x64 abil_off ELSE 0
                READ_SHORT 0x68 abil_num ELSE 0
         INNER_PATCH_SAVE cus0 ~%SOURCE_RES%~ BEGIN  //cus0 = sourc_res
         END
         INNER_PATCH_SAVE cusz ~%cus0%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPPR~ ~B_P~  //Priest SPPR --> B_P (cusz)
         END
         INNER_PATCH_SAVE cusy ~%cusz%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPRA~ ~B_R~  //SPRA -->B_R (cusy) Some ranger? spells
         END
         INNER_PATCH_SAVE cusx ~%cusy%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWI~ ~B_W~  //standard mage 'prefix' SPWI-->B_W
         END
         INNER_PATCH_SAVE cus1 ~%cusx%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPIN~ ~B_I~  //innate SPIN--> B_I
         END
         INNER_PATCH_SAVE cus2 ~%cus1%~ BEGIN
          REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~SPWM~ ~B_M~  //what are these? SPWM--> B_M
         END
PATCH_IF school = 0 OR
         school = 6  BEGIN //another check for just evocation --dex vs damaging schools
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 12 BEGIN    //opcode 12
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_dex_evoc_arrays_sr END  //dex apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // dex less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // dex greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // dex less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // dex = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // dex = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // dex = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // dex = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // dex = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // dex = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // dex = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // dex = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %dex_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // dex greater than 19, cast splG (+5)
               INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = (0 -2)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%A.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
                 LPF ALTER_EFFECT_ADD
                   INT_VAR savebonus_add = (0 -1)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add =  1          //
                  END      // Alter_effect
               END //Inner_Action
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 2          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 3          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 4          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 5          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%G.SPL not in game
          END  //save >0
      END //opcode 12
    END //PHP2
  END //PHP1
END //School (evocation only)
PATCH_IF school = 0  OR  //If None school
         school = 2  OR  //If Conjurer school
         school = 4  OR  //enchanter
         school = 5  OR  //illusionist
         school = 7 BEGIN //necromancy  Vs. Fear
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 24 BEGIN    //opcode 24 (fear)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_fear_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
               INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = (0 -2)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%A.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
                 LPF ALTER_EFFECT_ADD
                   INT_VAR savebonus_add = (0 -1)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add =  1          //
                  END      // Alter_effect
               END //Inner_Action
        END //%cus2%C.SPL not in game

        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 2          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%D.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 3          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%E.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 4          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%F.SPL not in game

         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 5          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%G.SPL not in game
          END //save >0
      END //opcode 24 (fear)
    END //PHP2
  END //PHP1
END//end nec, enchant, illusion, conjurer
PATCH_IF school = 0  OR  //If None school
         school = 2  OR  //If Conjurer school
         school = 4  OR  //enchanter
         school = 5 BEGIN//illusionist  Vs. mind
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 2 OR          // opcode 2 (Sleep)
               fx_type = 3 OR          // opcode 3 (Berserking) (enchant)
               fx_type = 5 OR          // opcode 5 (Charm)
               fx_type = 39 OR         // opcode 39 (Unconsciousness)
               fx_type = 45 OR         // opcode 45  (Stun)
               fx_type = 76 OR         // opcode 76 (Feeblemind) (enchant)
               fx_type = 109 OR        // opcode 109 (Hold)
               fx_type = 128 OR        // opcode 128 (Confusion) (enchant)
               fx_type = 175 OR        // opcode 175 (Hold)
               fx_type = 241 OR        // opcode 241 (Charm)
               fx_type = 246 OR        // opcode 246 (Berserking) (enchant)
               fx_type = 247 BEGIN     // opcode 247 (Attack nearest creature)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
              LPF cd_apply_batch STR_VAR array_name = b_wis_sleep_arrays_sr END  //wis apply sleep
              LPF cd_apply_batch STR_VAR array_name = b_wis_uncon_arrays_sr END  //wis apply unconsciousness
              LPF cd_apply_batch STR_VAR array_name = b_wis_stun_arrays_sr END  //wis apply stun
              LPF cd_apply_batch STR_VAR array_name = b_wis_hold1_arrays_sr END //wis apply hold1
              LPF cd_apply_batch STR_VAR array_name = b_wis_hold2_arrays_sr END //wis apply hold2
              LPF cd_apply_batch STR_VAR array_name = b_wis_charm1_arrays_sr END  //wis apply charm1
              LPF cd_apply_batch STR_VAR array_name = b_wis_charm2_arrays_sr END //wis apply charm2
              LPF cd_apply_batch STR_VAR array_name = b_wis_bersk1_arrays_sr END //wis apply berserk1
              LPF cd_apply_batch STR_VAR array_name = b_wis_bersk2_arrays_sr END //wis apply berserk2
              LPF cd_apply_batch STR_VAR array_name = b_wis_bersk3_arrays_sr END //wis apply berserk3
              LPF cd_apply_batch STR_VAR array_name = b_wis_feeble_arrays_sr END //wis apply feeblemind
              LPF cd_apply_batch STR_VAR array_name = b_wis_confuse_arrays_sr END //wis apply confusion
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
               INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = (0 -2)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%A.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
                 LPF ALTER_EFFECT_ADD
                   INT_VAR savebonus_add = (0 -1)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add =  1          //
                  END      // Alter_effect
               END //Inner_Action
        END //%cus2%C.SPL not in game
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 2          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%D.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 3          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%E.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 4          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%F.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 5          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%G.SPL not in game
          END//save >0
      END//opcodes
    END //PHP2
  END //PHP1
END//conjuration, enchant, illusion (rest of will saves)
PATCH_IF school = 0  OR  //If None school
         school = 2  OR  //If Conjurer school
         school = 7 BEGIN //necromancy  con Vs. death (and hold/stun for nec--other non nec *should* be skipped)
  GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      READ_SHORT fx_off fx_type
      READ_ASCII fx_off + 0x14 item
      PATCH_IF fx_type = 13 OR      // opcode 13  (Death)
               fx_type = 25 OR      // opcode 25  (poison)
               fx_type = 45 OR      // opcode 45  (Stun)
               fx_type = 55 OR      // opcode 55  (Kill creature type)
               fx_type = 78 OR      // opcode 78  (Disease)
               fx_type = 109 OR     // opcode 109 (Hold)
               fx_type = 209 OR      // opcode 209  (death 60hp)
               fx_type = 175 BEGIN  // opcode 175 (Hold)
     PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_stun_arrays_sr END  //wis apply spl (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold1_arrays_sr END //wis apply spl (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_wis_hold2_arrays_sr END //wis apply spl  (but here con)
             LPF cd_apply_batch STR_VAR array_name = b_con_death1_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_death2_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_death3_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_poison_arrays_sr END //con apply spl
             LPF cd_apply_batch STR_VAR array_name = b_con_disease_arrays_sr END //con apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // con less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // con greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // con less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // con = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // con = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // con = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // con = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // con = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // con = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // con = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // con = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %con_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // con greater than 19, cast splG (+5)
               INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = (0 -2)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%A.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
                 LPF ALTER_EFFECT_ADD
                   INT_VAR savebonus_add = (0 -1)          //
                  END      // Alter_effect
               END //Inner_Action
            END  //%cus2%B.SPL not in game
    PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add =  1          //
                  END      // Alter_effect
               END //Inner_Action
        END //%cus2%C.SPL not in game
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 2          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%D.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 3          //
                  END      // Alter_effect
               END //Inner_Action
             END //%cus2%E.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 4          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%F.SPL not in game
         PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
                  LPF ALTER_EFFECT_ADD
                    INT_VAR savebonus_add = 5          //
                  END      // Alter_effect
               END //Inner_Action
         END //%cus2%G.SPL not in game
      END //opcodes
    END //PHP2
  END //PHP1
END //nec/conjuration for death effects
//the end end
             END//School (none, conjuration, enchant, illusion, invoc, necromancy)
           END //Spell type (wiz/cleric/innate)
         END //source size

/*
      PATCH_IF
      fx_type = 111 BEGIN  // opcode 111 (Create magical weapon)
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
           INNER_ACTION BEGIN
                 COPY_EXISTING ~%item%.itm~ ~override~  //need to read and copy over effects to subspells
             PATCH_PRINT "%item%"  //test
               END//Inner action
      END//type create weapon
    END //php
  END //php
END //necromancer

PATCH_IF school = 7  OR     //necromancy
         school = 4  OR     //enchanter
         school = 5  BEGIN  //illusionist
 GET_OFFSET_ARRAY ab_array 0x64 4 0x68 2 0 0 0x28
  PHP_EACH ab_array AS int => ab_off BEGIN
    GET_OFFSET_ARRAY2 fx_array ab_off ITM_V10_HEAD_EFFECTS
    PHP_EACH fx_array AS int => fx_off BEGIN
      PATCH_IF
      fx_type = 24 BEGIN     // opcode 24  (Fear)
        READ_LONG fx_off + 0x24 save
          PATCH_IF save > 0 BEGIN   //save not 0
        PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%A.SPL~ BEGIN  //
             LPF cd_apply_batch STR_VAR array_name = b_wis_fear_arrays_sr END  //wis apply spl
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_9~ resource = EVAL ~%cus0%~  END     // wis less than 9, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_14~ resource = EVAL ~%cus0%~  END     // wis greater than 14, immune to base spell
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_ls% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~ls_6~ resource = EVAL ~%cus2%A~  END     // wis less than 6, cast splA (-2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_6~ resource = EVAL ~%cus2%B~  END     // wis = 6, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_7~ resource = EVAL ~%cus2%B~  END     // wis = 7, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_8~ resource = EVAL ~%cus2%B~  END     // wis = 8, cast splB (-1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_15~ resource = EVAL ~%cus2%C~  END     // wis = 15, cast splC (+1)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_16~ resource = EVAL ~%cus2%D~  END     // wis = 16, cast splD (+2)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_17~ resource = EVAL ~%cus2%E~  END     // wis = 17, cast splE (+3)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_18~ resource = EVAL ~%cus2%F~  END     // wis = 18, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_eq% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~eq_19~ resource = EVAL ~%cus2%F~  END     // wis = 19, cast splF (+4)
             LPF ALTER_EFFECT INT_VAR  multi_match = 1 parameter2 = %wis_gr% probability1 = 100 probability2 = 0 STR_VAR match_resource = ~gr_19~ resource = EVAL ~%cus2%G~  END     // wis greater than 19, cast splG (+5)
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%A.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -2)          //
             END      //
           END  //inner action
           END // splA
           PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%B.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%B.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = (0 -1)          //
             END      //
           END //inner action
           END // not %cus2%B.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%C.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%C.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 1          //
             END      //
           END //inner action
           END // not %cus2%C.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%D.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%D.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 2          //
             END      //
           END //inner action
           END // not %cus2%D.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%E.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%E.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 3          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%F.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%F.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 4          //
             END      //
           END //inner action
           END // not %cus2%E.SPL exists in game
       PATCH_IF !FILE_EXISTS_IN_GAME ~%cus2%G.SPL~ BEGIN  //
            //Do Stuff to original spell
           INNER_ACTION BEGIN
           COPY_EXISTING ~%cus0%.SPL~ ~override/%cus2%G.SPL~
             LPF ALTER_EFFECT_ADD
               INT_VAR savebonus_add = 5          //
             END      //
           END //inner action
           END // not %cus2%G.SPL exists in game

          END //save not 0
      END //opcode 24

    END//PHP
  END //PHP
END //necromancy/illusion/charm
END //end description not no save
END   //(nec, illusionist, enchant, evocation) school check
END //spell type (wiz/cleric/innate)
END //source size
END //??
BUT_ONLY
*/