Jump to content

STRING_CONTAINS_REGEXP... localized


subtledoctor

Recommended Posts

Anyone know if something like this is possible? (Pseudocode, as usual, posting from a phone.)

 

.tra:

@10  = ~plate~
.tp2:

OUTER_SPRINT plate_tra @10

COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~
  READ_STRREF 0x0c id_name
  PATCH_IF (~%id_name%~ STRING_CONTAINS_REGEXP ~%plate_tra%~) BEGIN
    [do stuff]
  END
BUT_ONLY
?
Link to comment

Now having problems... I am getting this:

In state 931, I expected one of these tokens:
  [0] EOF
Parse error (state 931) at END

[scales_of_balance/components/100_IWO_YARAS.tpa] PARSE ERROR at line 538 column 8-12
Near Text: END
    GLR parse error

It's toward the end of a large patch function. That part of the code looks like this:

COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
      READ_SHORT 0x1c type
      PATCH_IF (type = 2) BEGIN
...
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%plate_dr%%%WNL%%new_dex%%plate_dex%%WNL%%new_cast%%plate_cast%%WNL%%thief_stealth%%plate_stealth%%WNL%%thief_mech%%plate_mech%%WNL%%thief_detect%%plate_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
        END
      END  //  <--- this is line 538
    END
BUT_ONLY

I've gone through to make sure all of the PATCH_IFs get their ENDs, etc. I don't know what "state 931" is, and I don't know what "EOF" means. So I can't figure out that the parse error is about... :(

 

Any help?

 

EDIT: full code below if anyone wants to try it out

 

 

//__________________________________________________________________________________
COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
    READ_SHORT 0x1c type
    PATCH_IF (type = 2) BEGIN
      READ_LONG 0x0c id_name_strref
      PATCH_IF (id_name_strref >= 0 && id_name_strref < 2147483646) BEGIN
        READ_STRREF 0x0c ~id_name~
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+1~) BEGIN
          WRITE_LONG 0x60 1
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+2~) BEGIN
          WRITE_LONG 0x60 2
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+3~) BEGIN
          WRITE_LONG 0x60 3
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+4~) BEGIN
          WRITE_LONG 0x60 4
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+5~) BEGIN
          WRITE_LONG 0x60 5
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+6~) BEGIN
          WRITE_LONG 0x60 6
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%dragon_tra%~) BEGIN
          WRITE_LONG 0x60 4
        END
      END
    END
  END
BUT_ONLY

COPY ~scales_of_balance/misc/d5_cstp1.eff~ ~override~
COPY ~scales_of_balance/misc/d5_cstp2.eff~ ~override~
COPY ~scales_of_balance/misc/d5_cstp3.eff~ ~override~
COPY ~scales_of_balance/misc/d5_cstp4.eff~ ~override~
COPY ~scales_of_balance/misc/d5_cstp5.eff~ ~override~
COPY ~scales_of_balance/misc/dexmo2.2da~ ~override/dexmod.2da~
COPY ~scales_of_balance/misc/skilldex.2da~ ~override~

COPY_EXISTING ~leat01.itm~ ~override~
    READ_LONG 0x08 leather_strref
COPY_EXISTING ~leat04.itm~ ~override~
    READ_LONG 0x08 studded_strref
COPY_EXISTING ~leat10.itm~ ~override~
    READ_LONG 0x08 hide_strref
COPY_EXISTING ~chan01.itm~ ~override~
    READ_LONG 0x08 chain_strref
COPY_EXISTING ~chan04.itm~ ~override~
    READ_LONG 0x08 splint_strref
COPY_EXISTING ~plat01.itm~ ~override~
    READ_LONG 0x08 plate_strref
COPY_EXISTING ~plat05.itm~ ~override~
    READ_LONG 0x08 fullplate_strref
ACTION_IF FILE_EXISTS_IN_GAME ~plat18.itm~ BEGIN
    COPY_EXISTING ~plat18.itm~ ~override~
      READ_LONG 0x08 scale_strref
END

ACTION_FOR_EACH leather_armor IN ~bdleat06~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%leather_armor%.itm~ BEGIN
    COPY_EXISTING ~%leather_armor%.itm~ ~override~
      WRITE_LONG 0x08 %leather_strref%
    BUT_ONLY
  END
END
ACTION_FOR_EACH studded_armor IN ~bdchan01~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%studded_armor%.itm~ BEGIN
    COPY_EXISTING ~%studded_armor%.itm~ ~override~
      WRITE_LONG 0x08 %studded_strref%
    BUT_ONLY
  END
END
ACTION_FOR_EACH chain_armor IN ~bdcha05~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%chain_armor%.itm~ BEGIN
    COPY_EXISTING ~%chain_armor%.itm~ ~override~
      WRITE_LONG 0x08 %chain_strref%
    BUT_ONLY
  END
END
ACTION_FOR_EACH plate_armor IN ~plat06~ ~plat06_~ ~bdplat04~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%plate_armor%.itm~ BEGIN
    COPY_EXISTING ~%plate_armor%.itm~ ~override~
      WRITE_LONG 0x08 %plate_strref%
    BUT_ONLY
  END
END
ACTION_FOR_EACH fullplate_armor IN ~npplat~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%fullplate_armor%.itm~ BEGIN
    COPY_EXISTING ~%fullplate_armor%.itm~ ~override~
      WRITE_LONG 0x08 %fullplate_strref%
    BUT_ONLY
  END
END

    OUTER_SPRINT catch_ac @10001
    OUTER_SPRINT new_ac @10002
    OUTER_SPRINT new_dr @10003
    OUTER_SPRINT new_dex @10004
    OUTER_SPRINT new_cast @10005

    OUTER_SPRINT dragon_tra @10011
    OUTER_SPRINT elven_tra @10012
    OUTER_SPRINT elvish_tra @10013
    OUTER_SPRINT sylvan_tra @10014
    OUTER_SPRINT bladesinger_tra @10015
    OUTER_SPRINT robe_tra @10018
    OUTER_SPRINT cloak_tra @10019

    OUTER_SPRINT thief_stealth @10021
    OUTER_SPRINT thief_mech @10022
    OUTER_SPRINT thief_detect @10023

COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
      READ_SHORT 0x1c type
      PATCH_IF (type = 2) BEGIN
      
        PATCH_IF FILE_EXISTS_IN_GAME ~d5_fnp_usability.d5~ BEGIN
          READ_BYTE    ~0x1f~ ~fight~ //reads the byte containing the fighter usability flag
          PATCH_IF ((~%fight%~ BAND ~0b00100000~) = ~0b00000000~) BEGIN // if *usable* by fighter/mages (excluding scrolls and wands for now)
            READ_BYTE    ~0x1e~ ~class1~
            READ_BYTE    ~0x1f~ ~class2~
            READ_BYTE    ~0x20~ ~class3~
            READ_BYTE    ~0x21~ ~class4~
            WRITE_BYTE    ~0x1e~ (~%class1%~ BAND ~0b00111111~) // cleric & bard
            WRITE_BYTE    ~0x1f~ (~%class2%~ BAND ~0b11010111~) // multiclasses
            WRITE_BYTE    ~0x20~ (~%class3%~ BAND ~0b10000000~) // others
          END
        END
        PATCH_IF NOT FILE_EXISTS_IN_GAME ~d5_fnp_usability.d5~ BEGIN
          READ_BYTE    ~0x1f~ ~fight~ //reads the byte containing the fighter usability flag
          PATCH_IF ((~%fight%~ BAND ~0b00100000~) = ~0b00000000~) BEGIN // if *usable* by fighter/mages (excluding scrolls and wands for now)
            READ_BYTE    ~0x1e~ ~class1~
            READ_BYTE    ~0x1f~ ~class2~
            READ_BYTE    ~0x20~ ~class3~
            READ_BYTE    ~0x21~ ~class4~
            WRITE_BYTE    ~0x1e~ (~%class1%~ BAND ~0b00111111~) // cleric & bard
            WRITE_BYTE    ~0x1f~ (~%class2%~ BAND ~0b00000000~) // multiclasses
            WRITE_BYTE    ~0x20~ (~%class3%~ BAND ~0b10000000~) // others
          END
        END

        READ_LONG 0x08 gen_name_strref
        READ_LONG 0x0c id_name_strref
        READ_LONG 0x22 appearance
        PATCH_IF (gen_name_strref >= 0 && gen_name_strref < 2147483646) BEGIN
          READ_STRREF 0x08 ~gen_name~
        END
        PATCH_IF (id_name_strref >= 0 && id_name_strref < 2147483646) BEGIN
          READ_STRREF 0x0c ~id_name~
        END

        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%elven_tra%~) BEGIN
          SET elven = 1
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%elvish_tra%~) BEGIN
          SET elven = 1
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%sylvan_tra%~) BEGIN
          SET elven = 1
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%bladesinger_tra%~) BEGIN
          SET elven = 1
        END

        PATCH_INCLUDE ~scales_of_balance/lib/YARAS.ini~
        
        PATCH_IF (appearance = 16690) BEGIN // leather appearance
          READ_LONG 0x08 gen_name_strref
//    leather armor
          PATCH_IF (gen_name_strref = %leather_strref%) BEGIN
//            SPRINT armor_type ~leather~
            PATCH_PRINT ~%SOURCE_RES% = leather armor~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %leather_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %leather_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %leather_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %leather_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %leather_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %leather_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%leather_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%leather_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
                INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                  REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%leather_ac%%WNL%%new_dr%%leather_dr%%%WNL%%new_dex%%leather_dex%%WNL%%new_cast%%leather_cast%%WNL%~
                END
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
                INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                  REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%leather_ac%%WNL%%new_dr%%leather_dr%%%WNL%%new_dex%%leather_dex%%WNL%%new_cast%%leather_cast%%WNL%~
                END
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    hide armor
          ELSE PATCH_IF (gen_name_strref = %hide_strref%) BEGIN
//            SPRINT armor_type ~hide~
            PATCH_PRINT ~%SOURCE_RES% = hide armor~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %studded_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %chain_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%chain_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%chain_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%studded_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%chain_dex%%WNL%%new_cast%%chain_cast%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%studded_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%chain_dex%%WNL%%new_cast%%chain_cast%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    studded leather is default
          ELSE BEGIN         
//            SPRINT armor_type ~studded~
               PATCH_PRINT ~%SOURCE_RES% = studded leather~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %studded_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %studded_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %studded_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %studded_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %studded_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %studded_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%studded_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%studded_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%studded_ac%%WNL%%new_dr%%studded_dr%%%WNL%%new_dex%%studded_dex%%WNL%%new_cast%%studded_cast%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%studded_ac%%WNL%%new_dr%%studded_dr%%%WNL%%new_dex%%studded_dex%%WNL%%new_cast%%studded_cast%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
        END
        PATCH_IF (appearance = 16691) BEGIN // chain appearance
          READ_LONG 0x08 gen_name_strref
//    splint armor
          PATCH_IF (gen_name_strref = splint_strref) BEGIN
//            SPRINT armor_type ~splint~
            PATCH_PRINT ~%SOURCE_RES% = splint armor~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %splint_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %splint_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %splint_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %splint_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %splint_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %splint_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%splint_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%splint_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%splint_ac%%WNL%%new_dr%%splint_dr%%%WNL%%new_dex%%splint_dex%%WNL%%new_cast%%splint_cast%%WNL%%thief_stealth%%splint_stealth%%WNL%%thief_mech%%splint_mech%%WNL%%thief_detect%%splint_detect%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%splint_ac%%WNL%%new_dr%%splint_dr%%%WNL%%new_dex%%splint_dex%%WNL%%new_cast%%splint_cast%%WNL%%thief_stealth%%splint_stealth%%WNL%%thief_mech%%splint_mech%%WNL%%thief_detect%%splint_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    chain is default
          ELSE BEGIN
//            SPRINT armor_type ~chain~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %chain_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            PATCH_IF (elven = 1) BEGIN
                PATCH_PRINT ~%SOURCE_RES% = elven chain~
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %leather_dex%) parameter2 = 0 timing = 2 END
                LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%leather_cast%~ END
                PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
                  LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%leather_cast%~ END
                END
                READ_LONG 0x54 valid
                PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
                  READ_STRREF 0x54 "desc"
                  INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                    REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%chain_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%leather_dex%%WNL%%new_cast%%leather_cast%%WNL%~
                  END
                  SAY_EVALUATED 0x54 ~%new_desc%~
                END
                ELSE BEGIN
                  READ_STRREF 0x50 "desc"
                  INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                    REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%chain_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%leather_dex%%WNL%%new_cast%%leather_cast%%WNL%~
                  END
                  SAY_EVALUATED 0x50 ~%new_desc%~
                END
            END
            ELSE BEGIN
                PATCH_PRINT ~%SOURCE_RES% = chain mail~
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %chain_stealth%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %chain_stealth%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %chain_stealth%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %chain_mech%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %chain_mech%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %chain_detect%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %chain_detect%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %chain_dex%) parameter2 = 0 timing = 2 END
                LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%chain_cast%~ END
                PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
                  LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%chain_cast%~ END
                END
                READ_LONG 0x54 valid
                PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
                  READ_STRREF 0x54 "desc"
                  INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                    REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%chain_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%chain_dex%%WNL%%new_cast%%chain_cast%%WNL%%thief_stealth%%chain_stealth%%WNL%%thief_mech%%chain_mech%%WNL%%thief_detect%%chain_detect%%WNL%~
                  END
                  SAY_EVALUATED 0x54 ~%new_desc%~
                END
                ELSE BEGIN
                  READ_STRREF 0x50 "desc"
                  INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                    REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%chain_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%chain_dex%%WNL%%new_cast%%chain_cast%%WNL%%thief_stealth%%chain_stealth%%WNL%%thief_mech%%chain_mech%%WNL%%thief_detect%%chain_detect%%WNL%~
                  END
                  SAY_EVALUATED 0x50 ~%new_desc%~
                END
            END
          END
        END
        ELSE PATCH_IF (appearance = 16692) BEGIN // plate appearance
          READ_LONG 0x08 gen_name_strref
//    full plate armor
          PATCH_IF (gen_name_strref = fullplate_strref) BEGIN
//            SPRINT armor_type ~fullplate~
            PATCH_PRINT ~%SOURCE_RES% = full plate~
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %fullplate_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %fullplate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %fullplate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %fullplate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %fullplate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %fullplate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %fullplate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %fullplate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %fullplate_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %fullplate_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %fullplate_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %fullplate_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %fullplate_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%fullplate_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%fullplate_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%fullplate_ac%%WNL%%new_dr%%fullplate_dr%%%WNL%%new_dex%%fullplate_dex%%WNL%%new_cast%%fullplate_cast%%WNL%%thief_stealth%%fullplate_stealth%%WNL%%thief_mech%%fullplate_mech%%WNL%%thief_detect%%fullplate_detect%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%fullplate_ac%%WNL%%new_dr%%fullplate_dr%%%WNL%%new_dex%%fullplate_dex%%WNL%%new_cast%%fullplate_cast%%WNL%%thief_stealth%%fullplate_stealth%%WNL%%thief_mech%%fullplate_mech%%WNL%%thief_detect%%fullplate_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    scale armor
          PATCH_IF (gen_name_strref = scale_strref) BEGIN
//            SPRINT armor_type ~scale~
            PATCH_PRINT ~%SOURCE_RES% = scale armor~
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %plate_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %splint_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %splint_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %splint_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %splint_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %splint_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%chain_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%chain_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%splint_dr%%%WNL%%new_dex%%splint_dex%%WNL%%new_cast%%chain_cast%%WNL%%thief_stealth%%splint_stealth%%WNL%%thief_mech%%splint_mech%%WNL%%thief_detect%%splint_detect%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%splint_dr%%%WNL%%new_dex%%splint_dex%%WNL%%new_cast%%chain_cast%%WNL%%thief_stealth%%splint_stealth%%WNL%%thief_mech%%splint_mech%%WNL%%thief_detect%%splint_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    plate is default
          ELSE BEGIN
//            SPRINT armor_type ~plate~
            PATCH_PRINT ~%SOURCE_RES% = plate mail~
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %plate_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %plate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %plate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %plate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %plate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %plate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %plate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %plate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %plate_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %plate_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %plate_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %plate_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %plate_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%plate_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%plate_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%plate_dr%%%WNL%%new_dex%%plate_dex%%WNL%%new_cast%%plate_cast%%WNL%%thief_stealth%%plate_stealth%%WNL%%thief_mech%%plate_mech%%WNL%%thief_detect%%plate_detect%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%plate_dr%%%WNL%%new_dex%%plate_dex%%WNL%%new_cast%%plate_cast%%WNL%%thief_stealth%%plate_stealth%%WNL%%thief_mech%%plate_mech%%WNL%%thief_detect%%plate_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
        END
        SET elven = 0
      END
    END
BUT_ONLY
//__________________________________________________________________________________



Link to comment

Hmm, I can't edit that post. Weird.

 

Forget the above spoilered code, here is a better version:

 

 

 

//__________________________________________________________________________________
COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
    READ_SHORT 0x1c type
    PATCH_IF (type = 2) BEGIN
      READ_LONG 0x0c id_name_strref
      PATCH_IF (id_name_strref >= 0 && id_name_strref < 2147483646) BEGIN
        READ_STRREF 0x0c ~id_name~
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+1~) BEGIN
          WRITE_LONG 0x60 1
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+2~) BEGIN
          WRITE_LONG 0x60 2
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+3~) BEGIN
          WRITE_LONG 0x60 3
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+4~) BEGIN
          WRITE_LONG 0x60 4
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+5~) BEGIN
          WRITE_LONG 0x60 5
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~+6~) BEGIN
          WRITE_LONG 0x60 6
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%dragon_tra%~) BEGIN
          WRITE_LONG 0x60 4
        END
      END
    END
  END
BUT_ONLY

COPY_EXISTING ~leat01.itm~ ~override~
    READ_LONG 0x08 leather_strref
COPY_EXISTING ~leat04.itm~ ~override~
    READ_LONG 0x08 studded_strref
COPY_EXISTING ~leat10.itm~ ~override~
    READ_LONG 0x08 hide_strref
COPY_EXISTING ~chan01.itm~ ~override~
    READ_LONG 0x08 chain_strref
COPY_EXISTING ~chan04.itm~ ~override~
    READ_LONG 0x08 splint_strref
COPY_EXISTING ~plat01.itm~ ~override~
    READ_LONG 0x08 plate_strref
COPY_EXISTING ~plat05.itm~ ~override~
    READ_LONG 0x08 fullplate_strref
ACTION_IF FILE_EXISTS_IN_GAME ~plat18.itm~ BEGIN
    COPY_EXISTING ~plat18.itm~ ~override~
      READ_LONG 0x08 scale_strref
END

ACTION_FOR_EACH leather_armor IN ~bdleat06~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%leather_armor%.itm~ BEGIN
    COPY_EXISTING ~%leather_armor%.itm~ ~override~
      WRITE_LONG 0x08 %leather_strref%
    BUT_ONLY
  END
END
ACTION_FOR_EACH studded_armor IN ~bdchan01~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%studded_armor%.itm~ BEGIN
    COPY_EXISTING ~%studded_armor%.itm~ ~override~
      WRITE_LONG 0x08 %studded_strref%
    BUT_ONLY
  END
END
ACTION_FOR_EACH chain_armor IN ~bdcha05~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%chain_armor%.itm~ BEGIN
    COPY_EXISTING ~%chain_armor%.itm~ ~override~
      WRITE_LONG 0x08 %chain_strref%
    BUT_ONLY
  END
END
ACTION_FOR_EACH plate_armor IN ~plat06~ ~plat06_~ ~bdplat04~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%plate_armor%.itm~ BEGIN
    COPY_EXISTING ~%plate_armor%.itm~ ~override~
      WRITE_LONG 0x08 %plate_strref%
    BUT_ONLY
  END
END
ACTION_FOR_EACH fullplate_armor IN ~npplat~ BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%fullplate_armor%.itm~ BEGIN
    COPY_EXISTING ~%fullplate_armor%.itm~ ~override~
      WRITE_LONG 0x08 %fullplate_strref%
    BUT_ONLY
  END
END

    OUTER_SPRINT catch_ac @10001
    OUTER_SPRINT new_ac @10002
    OUTER_SPRINT new_dr @10003
    OUTER_SPRINT new_dex @10004
    OUTER_SPRINT new_cast @10005

    OUTER_SPRINT dragon_tra @10011
    OUTER_SPRINT elven_tra @10012
    OUTER_SPRINT elvish_tra @10013
    OUTER_SPRINT sylvan_tra @10014
    OUTER_SPRINT bladesinger_tra @10015
    OUTER_SPRINT robe_tra @10018
    OUTER_SPRINT cloak_tra @10019

    OUTER_SPRINT thief_stealth @10021
    OUTER_SPRINT thief_mech @10022
    OUTER_SPRINT thief_detect @10023

COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
      READ_SHORT 0x1c type
      PATCH_IF (type = 2) BEGIN
      
        PATCH_IF FILE_EXISTS_IN_GAME ~d5_fnp_usability.d5~ BEGIN
          READ_BYTE    ~0x1f~ ~fight~ //reads the byte containing the fighter usability flag
          PATCH_IF ((~%fight%~ BAND ~0b00100000~) = ~0b00000000~) BEGIN // if *usable* by fighter/mages (excluding scrolls and wands for now)
            READ_BYTE    ~0x1e~ ~class1~
            READ_BYTE    ~0x1f~ ~class2~
            READ_BYTE    ~0x20~ ~class3~
            READ_BYTE    ~0x21~ ~class4~
            WRITE_BYTE    ~0x1e~ (~%class1%~ BAND ~0b00111111~) // cleric & bard
            WRITE_BYTE    ~0x1f~ (~%class2%~ BAND ~0b11010111~) // multiclasses
            WRITE_BYTE    ~0x20~ (~%class3%~ BAND ~0b10000000~) // others
          END
        END
        PATCH_IF NOT FILE_EXISTS_IN_GAME ~d5_fnp_usability.d5~ BEGIN
          READ_BYTE    ~0x1f~ ~fight~ //reads the byte containing the fighter usability flag
          PATCH_IF ((~%fight%~ BAND ~0b00100000~) = ~0b00000000~) BEGIN // if *usable* by fighter/mages (excluding scrolls and wands for now)
            READ_BYTE    ~0x1e~ ~class1~
            READ_BYTE    ~0x1f~ ~class2~
            READ_BYTE    ~0x20~ ~class3~
            READ_BYTE    ~0x21~ ~class4~
            WRITE_BYTE    ~0x1e~ (~%class1%~ BAND ~0b00111111~) // cleric & bard
            WRITE_BYTE    ~0x1f~ (~%class2%~ BAND ~0b00000000~) // multiclasses
            WRITE_BYTE    ~0x20~ (~%class3%~ BAND ~0b10000000~) // others
          END
        END

        READ_LONG 0x08 gen_name_strref
        READ_LONG 0x0c id_name_strref
        READ_LONG 0x22 appearance
        PATCH_IF (gen_name_strref >= 0 && gen_name_strref < 2147483646) BEGIN
          READ_STRREF 0x08 ~gen_name~
        END
        PATCH_IF (id_name_strref >= 0 && id_name_strref < 2147483646) BEGIN
          READ_STRREF 0x0c ~id_name~
        END

        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%elven_tra%~) BEGIN
          SET elven = 1
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%elvish_tra%~) BEGIN
          SET elven = 1
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%sylvan_tra%~) BEGIN
          SET elven = 1
        END
        PATCH_IF NOT (~%id_name%~ STRING_CONTAINS_REGEXP ~%bladesinger_tra%~) BEGIN
          SET elven = 1
        END

        READ_LONG 0x60 enchantment
//
//    BASE AC:
//
        SET leather_ac =     (7 - %enchantment%)
        SET studded_ac =     (6 - %enchantment%)
        SET chain_ac =         (5 - %enchantment%)
        SET splint_ac =     (4 - %enchantment%)
        SET plate_ac =         (3 - %enchantment%)
        SET fullplate_ac =     (2 - %enchantment%)
//
//    DAMAGE RESISTANCE:
//
        SET leather_dr =     (5 + %enchantment%)
        SET studded_dr =     (10 + %enchantment%)
        SET chain_dr =         (18 + %enchantment%)
        SET splint_dr =     (22 + %enchantment%)
        SET plate_dr =         (27 + %enchantment%)
        SET fullplate_dr =     (33 + %enchantment%)
//
//    CASTING SPEED PENALTY:
//
        SET leather_cast =        1
        SET studded_cast =        2
        SET chain_cast =         3
        SET splint_cast =         4
        SET plate_cast =         4
        SET fullplate_cast =     5
//
//    DEX MODIFIERS:
//
        PATCH_IF (%enchantment% = 0) BEGIN
          SET leather_dex =        1
          SET studded_dex =        2
          SET chain_dex =         3
          SET splint_dex =         4
          SET plate_dex =         5
          SET fullplate_dex =     4
        END
        PATCH_IF (%enchantment% = 1) BEGIN
          SET leather_dex =        0
          SET studded_dex =        1
          SET chain_dex =         2
          SET splint_dex =         3
          SET plate_dex =         4
          SET fullplate_dex =     3
        END
        PATCH_IF (%enchantment% >= 2) BEGIN
          SET leather_dex =        0
          SET studded_dex =        0
          SET chain_dex =         1
          SET splint_dex =         2
          SET plate_dex =         3
          SET fullplate_dex =     3
        END
//
//    THIEF SKILL PENALTIES:
//
        SET chain_stealth =     30
        SET chain_mech =         20
        SET chain_detect =         10
        SET splint_stealth =     45
        SET splint_mech =         20
        SET splint_detect =     10
        SET plate_stealth =     60
        SET plate_mech =         30
        SET plate_detect =         30
        SET fullplate_stealth = 90
        SET fullplate_mech =     60
        SET fullplate_detect =     40
       
        PATCH_IF (appearance = 16690) BEGIN // leather appearance
          READ_LONG 0x08 gen_name_strref
//    leather armor
          PATCH_IF (gen_name_strref = %leather_strref%) BEGIN
//            SPRINT armor_type ~leather~
            PATCH_PRINT ~%SOURCE_RES% = leather armor~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %leather_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %leather_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %leather_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %leather_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %leather_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %leather_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%leather_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%leather_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
                INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                  REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%leather_ac%%WNL%%new_dr%%leather_dr%%%WNL%%new_dex%%leather_dex%%WNL%%new_cast%%leather_cast%%WNL%~
                END
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
                INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                  REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%leather_ac%%WNL%%new_dr%%leather_dr%%%WNL%%new_dex%%leather_dex%%WNL%%new_cast%%leather_cast%%WNL%~
                END
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    hide armor
          ELSE PATCH_IF (gen_name_strref = %hide_strref%) BEGIN
//            SPRINT armor_type ~hide~
            PATCH_PRINT ~%SOURCE_RES% = hide armor~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %studded_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %chain_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%chain_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%chain_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%studded_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%chain_dex%%WNL%%new_cast%%chain_cast%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%studded_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%chain_dex%%WNL%%new_cast%%chain_cast%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    studded leather is default
          ELSE BEGIN         
//            SPRINT armor_type ~studded~
               PATCH_PRINT ~%SOURCE_RES% = studded leather~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %studded_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %studded_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %studded_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %studded_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %studded_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %studded_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%studded_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%studded_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%studded_ac%%WNL%%new_dr%%studded_dr%%%WNL%%new_dex%%studded_dex%%WNL%%new_cast%%studded_cast%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%studded_ac%%WNL%%new_dr%%studded_dr%%%WNL%%new_dex%%studded_dex%%WNL%%new_cast%%studded_cast%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
        END
        PATCH_IF (appearance = 16691) BEGIN // chain appearance
          READ_LONG 0x08 gen_name_strref
//    splint armor
          PATCH_IF (gen_name_strref = splint_strref) BEGIN
//            SPRINT armor_type ~splint~
            PATCH_PRINT ~%SOURCE_RES% = splint armor~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %splint_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %splint_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %splint_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %splint_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %splint_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %splint_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%splint_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%splint_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%splint_ac%%WNL%%new_dr%%splint_dr%%%WNL%%new_dex%%splint_dex%%WNL%%new_cast%%splint_cast%%WNL%%thief_stealth%%splint_stealth%%WNL%%thief_mech%%splint_mech%%WNL%%thief_detect%%splint_detect%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%splint_ac%%WNL%%new_dr%%splint_dr%%%WNL%%new_dex%%splint_dex%%WNL%%new_cast%%splint_cast%%WNL%%thief_stealth%%splint_stealth%%WNL%%thief_mech%%splint_mech%%WNL%%thief_detect%%splint_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    chain is default
          ELSE BEGIN
//            SPRINT armor_type ~chain~
            LPF DELETE_EFFECT INT_VAR match_opcode = 0 END
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %chain_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %chain_dr% parameter2 = 1 timing = 2 END
            PATCH_IF (elven = 1) BEGIN
                PATCH_PRINT ~%SOURCE_RES% = elven chain~
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %leather_dex%) parameter2 = 0 timing = 2 END
                LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%leather_cast%~ END
                PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
                  LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%leather_cast%~ END
                END
                READ_LONG 0x54 valid
                PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
                  READ_STRREF 0x54 "desc"
                  INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                    REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%chain_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%leather_dex%%WNL%%new_cast%%leather_cast%%WNL%~
                  END
                  SAY_EVALUATED 0x54 ~%new_desc%~
                END
                ELSE BEGIN
                  READ_STRREF 0x50 "desc"
                  INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                    REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%chain_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%leather_dex%%WNL%%new_cast%%leather_cast%%WNL%~
                  END
                  SAY_EVALUATED 0x50 ~%new_desc%~
                END
            END
            ELSE BEGIN
                PATCH_PRINT ~%SOURCE_RES% = chain mail~
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %chain_stealth%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %chain_stealth%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %chain_stealth%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %chain_mech%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %chain_mech%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %chain_detect%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %chain_detect%) parameter2 = 0 timing = 2 END
                LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %chain_dex%) parameter2 = 0 timing = 2 END
                LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%chain_cast%~ END
                PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
                  LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%chain_cast%~ END
                END
                READ_LONG 0x54 valid
                PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
                  READ_STRREF 0x54 "desc"
                  INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                    REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%chain_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%chain_dex%%WNL%%new_cast%%chain_cast%%WNL%%thief_stealth%%chain_stealth%%WNL%%thief_mech%%chain_mech%%WNL%%thief_detect%%chain_detect%%WNL%~
                  END
                  SAY_EVALUATED 0x54 ~%new_desc%~
                END
                ELSE BEGIN
                  READ_STRREF 0x50 "desc"
                  INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                    REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%chain_ac%%WNL%%new_dr%%chain_dr%%%WNL%%new_dex%%chain_dex%%WNL%%new_cast%%chain_cast%%WNL%%thief_stealth%%chain_stealth%%WNL%%thief_mech%%chain_mech%%WNL%%thief_detect%%chain_detect%%WNL%~
                  END
                  SAY_EVALUATED 0x50 ~%new_desc%~
                END
            END
          END
        END
        ELSE PATCH_IF (appearance = 16692) BEGIN // plate appearance
          READ_LONG 0x08 gen_name_strref
//    full plate armor
          PATCH_IF (gen_name_strref = fullplate_strref) BEGIN
//            SPRINT armor_type ~fullplate~
            PATCH_PRINT ~%SOURCE_RES% = full plate~
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %fullplate_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %fullplate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %fullplate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %fullplate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %fullplate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %fullplate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %fullplate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %fullplate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %fullplate_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %fullplate_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %fullplate_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %fullplate_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %fullplate_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%fullplate_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%fullplate_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%fullplate_ac%%WNL%%new_dr%%fullplate_dr%%%WNL%%new_dex%%fullplate_dex%%WNL%%new_cast%%fullplate_cast%%WNL%%thief_stealth%%fullplate_stealth%%WNL%%thief_mech%%fullplate_mech%%WNL%%thief_detect%%fullplate_detect%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%fullplate_ac%%WNL%%new_dr%%fullplate_dr%%%WNL%%new_dex%%fullplate_dex%%WNL%%new_cast%%fullplate_cast%%WNL%%thief_stealth%%fullplate_stealth%%WNL%%thief_mech%%fullplate_mech%%WNL%%thief_detect%%fullplate_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    scale armor
          PATCH_IF (gen_name_strref = scale_strref) BEGIN
//            SPRINT armor_type ~scale~
            PATCH_PRINT ~%SOURCE_RES% = scale armor~
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %plate_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %splint_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %splint_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %splint_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %splint_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %splint_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %splint_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %splint_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%chain_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%chain_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%splint_dr%%%WNL%%new_dex%%splint_dex%%WNL%%new_cast%%chain_cast%%WNL%%thief_stealth%%splint_stealth%%WNL%%thief_mech%%splint_mech%%WNL%%thief_detect%%splint_detect%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%splint_dr%%%WNL%%new_dex%%splint_dex%%WNL%%new_cast%%chain_cast%%WNL%%thief_stealth%%splint_stealth%%WNL%%thief_mech%%splint_mech%%WNL%%thief_detect%%splint_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
//    plate is default
          ELSE BEGIN
//            SPRINT armor_type ~plate~
            PATCH_PRINT ~%SOURCE_RES% = plate mail~
            LPF DELETE_EFFECT INT_VAR match_opcode = 59 END     // MS
            LPF DELETE_EFFECT INT_VAR match_opcode = 275 END     // HiS
            LPF DELETE_EFFECT INT_VAR match_opcode = 92 END     // PP
            LPF DELETE_EFFECT INT_VAR match_opcode = 90 END     // OL
            LPF DELETE_EFFECT INT_VAR match_opcode = 277 END     // ST
            LPF DELETE_EFFECT INT_VAR match_opcode = 91 END     // FT
            LPF DELETE_EFFECT INT_VAR match_opcode = 276 END     // DI
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 0 target = 1 parameter1 = %plate_ac% parameter2 = 16 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 86 target = 1 parameter1 = %plate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 87 target = 1 parameter1 = %plate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 88 target = 1 parameter1 = %plate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 89 target = 1 parameter1 = %plate_dr% parameter2 = 1 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 59 target = 1 parameter1 = (0 - %plate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 275 target = 1 parameter1 = (0 - %plate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 92 target = 1 parameter1 = (0 - %plate_stealth%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 90 target = 1 parameter1 = (0 - %plate_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 277 target = 1 parameter1 = (0 - %plate_mech%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 91 target = 1 parameter1 = (0 - %plate_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 276 target = 1 parameter1 = (0 - %plate_detect%) parameter2 = 0 timing = 2 END
            LPF ADD_ITEM_EQEFFECT INT_VAR opcode = 15 target = 1 parameter1 = (0 - %plate_dex%) parameter2 = 0 timing = 2 END
            LPF ALTER_EFFECT INT_VAR match_opcode = 145  opcode = 177 target = 1 parameter1 = 1 parameter2 = 5 timing = 2 STR_VAR resource = EVAL ~d5_cstp%plate_cast%~ END
            PATCH_FOR_EACH class IN 5 7 10 13 14 17 BEGIN
              LPF CLONE_EFFECT INT_VAR match_opcode = 177 parameter1 = %class% STR_VAR match_resource = EVAL ~d5_cstp%plate_cast%~ END
            END
            READ_LONG 0x54 valid
            PATCH_IF (%valid% >= 0) BEGIN // verify name is valid
              READ_STRREF 0x54 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%plate_dr%%%WNL%%new_dex%%plate_dex%%WNL%%new_cast%%plate_cast%%WNL%%thief_stealth%%plate_stealth%%WNL%%thief_mech%%plate_mech%%WNL%%thief_detect%%plate_detect%%WNL%~
              END
              SAY_EVALUATED 0x54 ~%new_desc%~
            END
            ELSE BEGIN
              READ_STRREF 0x50 "desc"
              INNER_PATCH_SAVE new_desc ~%desc%~ BEGIN
                REPLACE_TEXTUALLY ~%catch_ac%~  ~%new_ac%%plate_ac%%WNL%%new_dr%%plate_dr%%%WNL%%new_dex%%plate_dex%%WNL%%new_cast%%plate_cast%%WNL%%thief_stealth%%plate_stealth%%WNL%%thief_mech%%plate_mech%%WNL%%thief_detect%%plate_detect%%WNL%~
              END
              SAY_EVALUATED 0x50 ~%new_desc%~
            END
          END
        END
        SET elven = 0
      END
    END
BUT_ONLY
//__________________________________________________________________________________

 

And here the .tra refs:

 

 

@10001  = ~^Armor Class:.+$~
@10002  = ~Armor Class: ~
@10003  = ~Damage Resistance: ~
@10004  = ~Dexterity Penalty: -~
@10005  = ~Arcane Casting Speed Penalty: +~
@10006  = ~Weapon Attack Speed Penalty: +~

@10011  = ~dragon~
@10012  = ~elven~
@10013  = ~elvish~
@10014  = ~sylvan~
@10015  = ~bladesinger~
@10018  = ~robe~
@10019  = ~cloak~

@10021  = ~Stealth, Pick Pockets: -~
@10022  = ~Open Locks, Set Traps: -~
@10023  = ~Find Traps, Detect Illusion: -~

Link to comment

Thx - I had spotted that (there used to be a string validity check there), and gone through to remove them all, but I must have missed those two. Lack of sleep and proofreading don't mix...

 

Next question: can this sort of thing be done in .d files? I'm not used to working with dialogues and scripts, so I'm not sure how to localize them. In my other mod I have clauses like this:

 

IF ~~ THEN BEGIN d5makit_22
 SAY ~ABJURER: A Mage who specializes in protective magics.

Advantages:
– May cast one additional spell per level.
– Receives a +15% bonus when scribing scrolls from the Abjuration school.
– Receives a +2 bonus when making Saving Throws against spells from the Abjuration school.
– Targets suffer a -2 penalty when making Saving Throws against spells from the Abjuration school.

Disadvantages:
– May not learn or cast any spells of the Alteration school.
– Receives a -15% penalty when scribing scrolls from other schools.

Requires at least 15 Wisdom.~
 IF ~~ THEN REPLY ~Adopt this kit~ DO ~AddKit(MAGESCHOOL_ABJURER)~ EXIT
 IF ~~ THEN REPLY ~Choose a different kit~ GOTO d5makit
 END

 

For various reasons, this stuff exists in a .txt file, which I APPEND with various other .txt files to build the final .d file, which gets compiled at install-time. Ideally, I could split that text as follows:

 

.tra file:

@10  = ~Adopt this kit~
@11  = ~Choose a different kit~

 

.tp2 file:

[get the strref of the Abjurer description from kitlist.2da, and put in variable %abjurer_desc%]

 

.txt file:

IF ~~ THEN BEGIN d5makit_22
 SAY ~%abjurer_dec%~
 IF ~~ THEN REPLY @10 DO ~AddKit(MAGESCHOOL_ABJURER)~ EXIT
 IF ~~ THEN REPLY @11 GOTO d5makit
 END

 

I've made two changes there: first, using a variable for some text (%abjurer_desc%), and second, using .tra references (@10 and @11). I don't know if either/both of those things can work in a .d file.

 

(If the former works, but the latter doesn't that's fine, I can just convert those .tra references into variables in the .tp2. So I guess the big question is whether using a variable works.)

Link to comment

Cool! Even easier.

I assume that the patch function APPEND_FILE can take EVAL just as the action function APPEND can? The EVAL will be applied to the contents of the .txt file?

 

 

EDIT - silly me, I just looked at the mod and most of that is already taken care of in the .tp2! All I need to localize are those two short lines: "Adopt this kit" and "Choose another kit." That's what happens when you haven't looked at your mod's code for 6 months - you have a great idea for how to improve it, only to realize that your past self was smarter than you realize and already implemented that idea! :)

Link to comment

You can use tra and dialog.tlk references (@ and #) in .d and .baf files. For the .tra references to work properly, you need to have loaded the relevant .tra file somehow (COMPILE ... USING, AUTO_TRA, WITH_TRA, LOAD_TRA, or by specifying it as one of the defaults in the LANGUAGE section).

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...