Cam's Function Library

In the course of writing the IWD Fixpack, I wrote a series of macros to assist in patching spells and items. These macros can quickly and easily patch a wide variety of items, areas, and spells, but their targeting may be a bit crude for some applications. Note that these are primarily for patching existing effects/triggers/etc., not necessarily for adding or deleting them. The best place to find working examples of these is the IWD Fixpack, though these macros will work just fine in both BG and BG2. This tutorial assumes familiarity with using macros.

Area Patching

AREA_ALTER_ENTRANCE

This is a simple macro for changing the coordinates and orientation of the party entrance points in an area file.

  INT_VAR x_coord = "-1" // new x coordinate at 0x20, negative values not written
y_coord = "-1" // new y coordinate at 0x22, negative values not written
orient = "-1" // new orientation at 0x24, negative values not written
STR_VAR entry_name = "" // required, needs to match name at 0x00

entry_name is required to make any changes, as that's what the macro will look for to patch. This is set at 0x00 in an entrance point. Set x_coord, y_coord, or orient to the value you wish to patch them to. If you do not specify a value for a variable or set it to a negative value that field will not be patched. Some examples:

  LPF AREA_ALTER_ENTRANCE INT_VAR orient = 12 STR_VAR entry_name = "FR5104" END

This will change the orientation of the party when using the FR5104 entrance point. The location of the entry is not changed. If we wanted to change the coordinates of the entry point we could use

  LPF AREA_ALTER_ENTRANCE INT_VAR orient = 12 x_coord = 100 y_coord = 150 STR_VAR entry_name = "FR5104" END

This would change the entry location to [100.150] and change the orientation. To simply change the coordinates, we would drop orient = 12.

AREA_ALTER_REGION

A simple macro for altering regions, also known as triggers, in area files.

  INT_VAR type        = "-1" // region type at 0x20; negative values mean no change
cursor = "-1" // cursor type at 0x34; negative values mean no change
trap_detect = "-1" // difficulty of trap detection at 0x68; negative values mean no change
trap_remove = "-1" // difficulty of trap removal at 0x6a; negative values mean no change
trapped = "-1" // is trapped? at 0x6c; negative values mean no change
detected = "-1" // is detected? at 0x6e; negative values mean no change
// flag_ vars affect flags starting at 0x60; 0 means remove flag, 1 means add flag, -1 no change
flag_locked = "-1" // locked, bit0
flag_resets = "-1" // trap resets, bit1
flag_party_required = "-1" // party required, bit2
flag_trap_detectable = "-1" // trap can be detected, bit3
flag_trap_enemies = "-1" // trap can be set off by enemies, bit4
flag_tutorial = "-1" // tutorial trigger, bit5
flag_trap_npcs = "-1" // trap can be set off by npcs, bit6
flag_silent = "-1" // silent trigger, bit7
flag_deactivated = "-1" // deactivated, bit8
flag_impassable_npc = "-1" // can not be passed by npcs, bit9
flag_activation_point = "-1" // use activation point, bit10
flag_connect_to_door = "-1" // connected to door, bit11
STR_VAR trig_name = "" // required, used to match region
dest_area = "same" // changes destination area at 0x38; "same" means no change
ent_name = "same" // changes entrance name at 0x40; "same" means no change
door_key = "same" // resref of key to unlock at 0x74; "same" means no change
door_script = "same" // resref of region script at 0x7c; "same" means no change

trig_name is required and is what the macro will use to target its patch. For the integer variables, any negative value means to leave a field unchanged and they all default to -1. For the strings, "same" is the default and means no change; "" can be used to remove a script or other field. Some examples:

  LPF AREA_ALTER_REGION INT_VAR cursor = 30 STR_VAR trig_name = "To1200" END

This will find and patch the To1200 region and change its cursor to 30.

  LPF AREA_ALTER_REGION INT_VAR flag_party_required = 1 STR_VAR trig_name = "To2109" END

This will set the flag to make To2109 a party-required transition (you must gather your party to venture forth).

AREA_ALTER_ACTOR

This macro targets and patches information about actors in the area file.

  INT_VAR x_coord = "-1" // new x coordinate at 0x20 and 0x24; negative values mean no change
y_coord = "-1" // new y coordinate at 0x22 and 0x26; negative values mean no change
orient = "-1" // facing direction for actor at 0x34; negative values mean no change
STR_VAR actor_name = "" // required, at 0x00, used to match actor
dlg_file = "same" // changes dialog file at 0x48; "same" means no change
script_override = "same" // changes override script at 0x50; "same" means no change
script_general = "same" // changes general script at 0x58; "same" means no change
script_class = "same" // changes class script at 0x60; "same" means no change
script_race = "same" // changes race script at 0x68; "same" means no change
script_default = "same" // changes default script at 0x70; "same" means no change
script_specifics = "same" // changes specifics script at 0x78; "same" means no change
cre_file = "same" // changes creature file at 0x80; "same" means no change

actor_name is required and is what the macro will use to patch. For the integer variables, any negative value means to leave a field unchanged and they all default to -1. For the strings, "same" is the default and means no change; "" can be used to remove a script or other field. The x and y coordinates will patch both the current and destination area of the specificed creature. Some examples:

  FOR (index = 1 ; index < 10 ; ++index) BEGIN
LPF AREA_ALTER_ACTOR STR_VAR actor_name = EVAL "Townsperson %index%" script_default = "kutowng" END
END

This loop will patch ten creatures in the area file, Townsperson 1 through Townsperson 10 to use kutowng.bcs as their default script.

  LPF AREA_ALTER_ACTOR INT_VAR x_coord = 2194 y_coord = 1264 STR_VAR actor_name = "Neo Orog 8" END

This will move Neo Orog 8 out of a wall and to the coordinates [2194.1264].

AREA_ALTER_CONTAINER

This macro will alter containers in an area file, but not their contents.

  INT_VAR cont_icon     = "-1" // icon displayed when opened at 0x24; negative values mean no change
trapped = "-1" // is trapped? at 0x30; negative values mean no change
detected = "-1" // is detected? at 0x32; negative values mean no change
string = "-1" // lockpick string at 0x84; negative values mean no change
lock_diff = "-1" // difficulty to pick lock at 0x26; negative values mean no change
trap_det_diff = "-1" // difficulty to detect trap at 0x2c; negative values mean no change
trap_rem_diff = "-1" // difficulty to remove tap at 0x2e; negative values mean no change
// flag_ vars affect flags starting at 0x28; 0 means remove flag, 1 means add flag, -1 no change
flag_locked = "-1" // locked, bit0
flag_mlocked = "-1" // magical lock, bit2
flag_resets = "-1" // trap resets, bit3
flag_disabled = "-1" // disabled, bit5
STR_VAR cont_name = "" // required, at 0x00, used to match container
cont_script = "same" // changes container script at 0x48; "same" means no change
cont_key = "same" // changes container key 0x78; "same" means no change

cont_name is required and is what the macro will use to patch. For the integer variables, any negative value means to leave a field unchanged and they all default to -1. For the strings, "same" is the default and means no change; "" can be used to remove a script or other field. Some examples:

  LPF AREA_ALTER_CONTAINER INT_VAR cont_icon =  7 STR_VAR cont_name = "Sarcophagus" END

This will change the icon of all containers in the area named "Sarcpohagus".

  LPF AREA_ALTER_CONTAINER STR_VAR cont_script = "" cont_name = "Cushions" END

This patch will remove the script from the container named "Cushions".

AREA_ALTER_DOOR

This macro will alter doors in an area file.

  INT_VAR door_icon   = "-1" // changes cursor at 0x68; negative values mean no change
trap_detect = "-1" // difficulty of trap detection at 0x6c; negative values mean no change
trap_remove = "-1" // difficulty of trap removal at 0x6e; negative values mean no change
trapped = "-1" // is trapped? at 0x70; negative values mean no change
detected = "-1" // is detected? at 0x72; negative values mean no change
door_detect = "-1" // difficulty of detection at 0x88; negative values mean no change
lock_diff = "-1" // difficulty of lock at 0x8c; negative values mean no change
STR_VAR door_name = "" // required, at 0x00, used to match door
door_key = "same" // changes door key at 0x78; "same" means no change
door_script = "same" // changes door script at 0x80; "same" means no change; "same" means no change

door_name is required and is what the macro will use to patch. For the integer variables, any negative value means to leave a field unchanged and they all default to -1. For the strings, "same" is the default and means no change; "" can be used to remove a script or other field. Some examples:

  LPF AREA_ALTER_DOOR INT_VAR lock_diff = 100 STR_VAR door_name = "AR6006Door11" END

This sets the lock on AR6006Door11 to have difficulty 100, meaning that it cannot be picked.

  LPF AREA_ALTER_DOOR INT_VAR door_icon = 8 STR_VAR door_name = "AR3502Switch1" END

This will change the door named AR3502Switch1 to use a different cursor.

Item Patches

CONVERT_BG_IWD_DURATION

Icewind Dale uses the basis of one round lasting seven real seconds, whereas Baldur's Gate uses six seconds as a round. This macro was written to help convert effects on spells and items from one system to the other.

  STR_VAR changeto = "iwd" // iwd changes effects to use round = 7; otherwise use round = 6

This macro only has one variable as input, changeto. If it's set to the default of "iwd" then effects will use rounds of seven seconds; any other value will convert rounds to six seconds.

  LPF CONVERT_BG_IWD_DURATION END

A BG spell which lasts two rounds (12 seconds) would be converted to last two IWD rounds (14 seconds) if this macro was applied.

  LPF CONVERT_BG_IWD_DURATION STR_VAR changeto = "bg" END

The inverse could also be applied--by using a different value of changeto effects under this patch would go from IWD rounds to BG. For example, a spell that lasted three rounds (21 seconds) in IWD would be converted to 18 seconds (three BG rounds).

This macro will ignore effects that last less than one round, as these are typically cosmetic or instant effects which shouldn't have their durations changed.

ITEM_ALTER_EFFECT

This macro can alter effects on items, including both global (equipping) effects and/or effects on extended headers.

  INT_VAR equipped      = 0  // check global effects: 0 for no, 1 for yes
headers = 0 // check effects on headers; 0 for no, 1 for yes
type = "-1" // -1 to check all headers, otherwise use type specified
opcode = "-1" // opcode at 0x00 to match, use -1 for all
opcode_new = "-1" // if opcode matches, change to this value
target = "-1" // change target at 0x02; negative values mean no change
timing = "-1" // change timing at 0x0c; negative values mean no change
power = "-1" // change power level at 0x03; negative values mean no change
parameter1 = "-1" // change parameter at 0x04; negative values mean no change
parameter2 = "-1" // change parameter at 0x08; negative values mean no change
resist_dispel = "-1" // change resist/dispel at 0x0d; negative values mean no change
duration = "-1" // change duration at 0x0e; negative values mean no change
duration_high = "-1" // same as duration, but only if existing duration > 5
probability1 = "-1" // change high probability at 0x12; negative values mean no change
probability2 = "-1" // change low probability at 0x13; negative values mean no change
dicenumber = "-1" // change number of dice at 0x1c; negative values mean no change
dicesize = "-1" // change size of dice at 0x20; negative values mean no change
savingthrow = "-1" // changing type of saving throw at 0x24; negative values mean no change
savebonus = "-11" // change save bonus/penalty; values -11 or lower are ignored
STR_VAR resource = "same" // resref at 0x14; same means no change, otherwise use this value

For the integer variables, any negative value means to leave a field unchanged (except for savebonus, noted below) and they all default to -1. For the resource, "same" is the default and means no change; "" can be used to remove the resource reference outright.

Note that both equipped and headers are 0 by default, so you need to change one or both of these to 1 to perform any patching at all. If you patch headers, you can further target by using type to target melee, ranged, or magical headers. Opcode can be left at -1 to match all effects on your targeted range or targeted to a specific opcode. If the opcode itself needs to be changed, you can use opcode to target the existing effect and opcode_new as the new opcode to use. duration_high is an alternative to duration, mainly for changing the overall duration of an item's effects. The idea is to allow you to mass patch effects to new durations while leaving the one-time only cosmetics and visuals--which are usual instant or only run for a few seconds--unchanged. One example would be:

  LPF ITEM_ALTER_EFFECT INT_VAR headers = 1 power = 0 duration_high = 70 END

This was used to change the overall duration on a potion without affecting the short-term effects. By using headers = 1 and no opcode, this patches all of the effects on the extended headers but ignores any effect with a duration of less than one round, such as a string saying 'gulp' or the one-time cosmetic visuals. Using duration would have altered all of these effects. duration_high really shines in the spell effect patching.

  LPF ITEM_ALTER_EFFECT INT_VAR headers = 1 opcode = 174 STR_VAR resource = "eff_m22a" END

This was used to correct an item using the wrong sound file on hits.

  LPF ITEM_ALTER_EFFECT INT_VAR headers = 1 power = 4 savingthrow = BIT0 savebonus = 2 END

This was used to correct an item which had the wrong power levels and lacked a saving throw. Note that the WeiDU BITx variables can be used in place of integers. Unlike other integer variables, the savebonus can take negative numbers up to -10.

  LPF ITEM_ALTER_EFFECT INT_VAR headers = 1 opcode = 45 dicesize = 0 END

Note that dicesize and dicenumber also double as minimum and maximum hit dice for some opcodes. This was used to remove an incorrect minimum hit dice for a stun effect.

  LPF ITEM_ALTER_EFFECT INT_VAR opcode = 109 opcode_new = 185 END

This was used to change an item using the paralyzation opcode (109) to use the hold opcode (185) instead.

ITEM_ALTER_HEADER

This macro can alter ability headers on items.

  INT_VAR type          = "-1" // -1 is all headers, >4 forces icon match, otherwise use value here
header = 0 // 0 matches all headers, otherwise just modify specified header - use with type = -1
type_new = "-1" // change the type at 0x00 to this value; negative values mean no change
identify = "-1" // identify to use? at 0x01; negative values mean no change
location = "-1" // ability location at 0x02; negative values mean no change
target = "-1" // target at 0x0c; negative values mean no change
range = "-1" // range at 0x0e; negative values mean no change
launcher = "-1" // launcher required at 0x10; negative values mean no change
speed = "-1" // speed at 0x12; negative values mean no change
thac0_bonus = "-1" // to-hit bonus at 0x14; negative values mean no change
dicesize = "-1" // dice size at 0x16; negative values mean no change
primary = "-1" // primary school at 0x17; negative values mean no change
dicenum = "-1" // number of dice at 0x18; negative values mean no change
secondary = "-1" // seoncdary type at 0x19; negative values mean no change
damage_bonus = "-1" // +damage bonus at 0x1a; negative values mean no change
damage_type = "-1" // damage type at 0x1c; negative values mean no change
effects_num = "-1" // number of effects at 0x1e; negative values mean no change
effects_index = "-1" // effects index at 0x20; negative values mean no change
charges = "-1" // number of charges at 0x22; negative values mean no change
drained = "-1" // when drained? at 0x24; negative values mean no change
projectile = "-1" // projectile at 0x2a; negative values mean no change
anim_overhead = "-1" // % of overhead attacks at 0x2c; negative values mean no change
anim_backhand = "-1" // % of bakhand attacks at 0x2e; negative values mean no change
anim_thrust = "-1" // % of thirsuting attacks at 0x30; negative values mean no change
arrow = "-1" // is arrow? at 0x32; negative values mean no change
bolt = "-1" // is bolt? at 0x34; negative values mean no change
bullet = "-1" // is bullet? at 0x36; negative values mean no change
// flag_ vars affect flags starting at 0x26; 0 means remove flag, 1 means add flag, -1 no change
flag_strength = "-1" // add strength bonus, bit0
flag_break = "-1" // breakable, bit1
flag_hostile = "-1" // hostile, bit10
flag_recharge = "-1" // recharge after resting, bit11
flag_bypass = "-1" // bypass armor, bit16
flag_keenedge = "-1" // keen edge, bit17
flag_backstab = "-1" // tobex only, can backstab, bit25
flag_noinvis = "-1" // tobex only, cannot target invisible, bit26
STR_VAR icon = "same" // ability icon at 0x04; used to match if type > 4; same means no change otherwise use this value

type is used to limit the scope of matching. The default value of -1 will match all types of headers while values of 0-4 will match headers with those values. Values of type greater than 4 will force a match using the ability icon at 0x04, which is useful for items which have multiple magic abilities. header can also be used to limit patching to the Nth header, counting from 1 as the first header. The default is 0, which will match all headers.

Note that while effects_num and effects_index are exposed, arbitrarily changing them is probably a really bad idea.

Outside of type and header, for the integer variables, any negative value means to leave a field unchanged and they all default to -1. For the icon, "same" is the default and means no change; "" can be used to remove the icon reference outright. Some examples:

  LPF ITEM_ALTER_HEADER INT_VAR identify = 1 type = 3 END

This is a simple patch that changed all magical abilities on an item to require the item being identified prior to use.

  LPF ITEM_ALTER_HEADER INT_VAR type = 1 anim_overhead = 65 anim_backhand = 35 anim_thrust = 0 END

This patch targeted melee headers and changed the balance of the attack animations.

  LPF ITEM_ALTER_HEADER STR_VAR icon = EVAL ~i%SOURCE_RES%~ END

This was used in a mass item patch to correct their icons on the quick bar. It used the WeiDU variable SOURCE_RES in conjunction with a leading "i" to set the correct icon for the ability headers. Note that this patch would patch all headers, melee, magical, or otherwise since it's not bound.

    LPF ITEM_ALTER_HEADER INT_VAR header = 3 range = 100 END

This was used to change the range of a magical ability to 100 without affecting the melee header.

  LPF ITEM_ALTER_HEADER INT_VAR type = 1 damage_type = 3 END

This was used to change an item's melee ability to use slashing damage.

ITEM_DELETE_HEADER

This can be used to delete an ability (aka extended header) from an item, along with all of its associated effects, and properly re-index the file.

  INT_VAR type = 0 // -1 for all headers, otherwise match type

This was written mainly to purge old BG items of their extraneous type (0) effects. These were needed in BG to allow these items to stack but are no longer needed in BG2 or more modern variants of the engine.

Spell Patches

CONVERT_BG_IWD_DURATION

Icewind Dale uses the basis of one round lasting seven real seconds, whereas Baldur's Gate uses six seconds as a round. This macro was written to help convert effects on spells and items from one system to the other.

  STR_VAR changeto = "iwd" // iwd changes effects to use round = 7; otherwise use round = 6

This macro only has one variable as input, changeto. If it's set to the default of "iwd" then effects will use rounds of seven seconds; any other value will convert rounds to six seconds.

  LPF CONVERT_BG_IWD_DURATION END

A BG spell which lasts two rounds (12 seconds) would be converted to last two IWD rounds (14 seconds) if this macro was applied.

  LPF CONVERT_BG_IWD_DURATION STR_VAR changeto = "bg" END

The inverse could also be applied--by using a different value of changeto effects under this patch would go from IWD rounds to BG. For example, a spell that lasted three rounds (21 seconds) in IWD would be converted to 18 seconds (three BG rounds).

This macro will ignore effects that last less than one round, as these are typically cosmetic or instant effects which shouldn't have their durations changed.

SPELL_ALTER_EFFECT

This macro can alter effects on spells.

  INT_VAR header        = 0  // 0 for all, otherwise use number
type = "-1" // -1 to check all headers, otherwise use type specified
opcode = "-1" // opcode at 0x00 to match, use -1 for all
opcode_new = "-1" // if opcode matches, change to this value
target = "-1" // change target at 0x02; negative values mean no change
timing = "-1" // change timing at 0x0c; negative values mean no change
power = "-1" // change power level at 0x03; negative values mean no change
parameter1 = "-1" // change parameter at 0x04; negative values mean no change
parameter2 = "-1" // change parameter at 0x08; negative values mean no change
resist_dispel = "-1" // change resist/dispel at 0x0d; negative values mean no change
duration = "-1" // change duration at 0x0e; negative values mean no change
duration_high = "-1" // same as duration, but only if existing duration > 5
probability1 = "-1" // change high probability at 0x12; negative values mean no change
probability2 = "-1" // change low probability at 0x13; negative values mean no change
dicenumber = "-1" // change number of dice at 0x1c; negative values mean no change
dicesize = "-1" // change size of dice at 0x20; negative values mean no change
savingthrow = "-1" // changing type of saving throw at 0x24; negative values mean no change
savebonus = "-11" // change save bonus/penalty; values -11 or lower are ignored
STR_VAR resource = "same" // resref at 0x14; same means no change, otherwise use this value

This is more or less identical to ITEM_ALTER_EFFECT except for the tergeting of effects. type can be used to target specific header types, but this is of limited use on spells since most are magical (3). header can be set to 0 to match effects on all headers, or can be used with a value to target a specific header (first header is 1 and counts up).

For the integer variables, any negative value means to leave a field unchanged (except for savebonus, noted below) and they all default to -1. For the resource, "same" is the default and means no change; "" can be used to remove the resource reference outright.

Opcode can be left at -1 to match all effects on your targeted range or targeted to a specific opcode. If the opcode itself needs to be changed, you can use opcode to target the existing effect and opcode_new as the new opcode to use. duration_high is an alternative to duration, mainly for changing the overall duration of a spell's effects. The idea is to allow you to mass patch effects to new durations while leaving the one-time only cosmetics and visuals--which are usual instant or only run for a few seconds--unchanged. One example would be:

  READ_SHORT  0x68 abil_num
FOR (index = 1 ; index < (abil_num + 1) ; ++index) BEGIN
LPF SPELL_ALTER_EFFECT INT_VAR header = index duration_high = ((index * 14) + 28) resist_dispel = 1 END
END

This was used to correct a spell's duration on Icewind Dale. It was a second level spell that was supposed to last two rounds per level so a simple loop, based on the number of abilities, walks through each header and adjusts the duration. Since it's a third level spell, the first header is actually for a level three caster, hence the bit of extra math for duration_high. duration_high, unlike duration, ignores all of the short-term cosmetic visuals and permanent effects with 0 duration.

  LPF SPELL_ALTER_EFFECT INT_VAR opcode = 12 target = 2 END

This was used to correct a trap spell that was causing damage to itself rather than its target. Note that since this isn't bound with a header variable, this would patch any opcode 12 it finds on every header of the spell.

  LPF SPELL_ALTER_EFFECT INT_VAR opcode = 174 savingthrow = BIT0 savebonus = "-2" END

This was used to correct a spell with a sound effect that lacked a save. Note that the WeiDU BITx variables can be used in place of integers. Unlike other integer variables, the savebonus can take negative numbers up to -10.

  LPF SPELL_ALTER_EFFECT INT_VAR dicenumber = 4 END

Note that dicesize and dicenumber also double as minimum and maximum hit dice for some opcodes. This was used to correct an incorrect maximum hit dice on a spell.

  LPF SPELL_ALTER_EFFECT INT_VAR opcode = 54 opcode_new = 133 END

This was used to change a spell using the thac0 bonus opcode (54) to use the luck opcode (133) instead.

SPELL_ALTER_HEADER

This macro can alter ability headers on spells.

  INT_VAR type          = "-1" // -1 is all headers, >4 forces icon match, otherwise use value here
header = 0 // 0 matches all headers, otherwise just modify specified header - use with type = -1
type_new = "-1" // change the type at 0x00 to this value; negative values mean no change
location = "-1" // ability location at 0x02; negative values mean no change
target = "-1" // target at 0x0c; negative values mean no change
range = "-1" // range at 0x0e; negative values mean no change
min_level = "-1" // minimum level at 0x10; negative values mean no change
speed = "-1" // speed at 0x12; negative values mean no change
thac0_bonus = "-1" // to-hit bonus at 0x14; negative values mean no change
dicesize = "-1" // dice size at 0x16; negative values mean no change
dicenum = "-1" // number of dice at 0x18; negative values mean no change
damage_bonus = "-1" // +damage bonus at 0x1a; negative values mean no change
damage_type = "-1" // damage type at 0x1c; negative values mean no change
effects_num = "-1" // number of effects at 0x1e; negative values mean no change
effects_index = "-1" // effects index at 0x20; negative values mean no change
charges = "-1" // number of charges at 0x22; negative values mean no change
projectile = "-1" // projectile at 0x26; negative values mean no change
STR_VAR icon = "same" // ability icon at 0x04; used to match if type > 4; same means no change otherwise use this value

type is used to limit the scope of matching, though since most spells use type magical (3) it's of limited use. The default value of -1 will match all types of headers while values of 0-4 will match headers with those values. Values of type greater than 4 will force a match using the ability icon at 0x04, which is useful for items which have multiple magic abilities. header can also be used to limit patching to the Nth header, counting from 1 as the first header. The default is 0, which will match all headers.

Note that while effects_num and effects_index are exposed, arbitrarily changing them is probably a really bad idea.

Outside of type and header, for the integer variables, any negative value means to leave a field unchanged and they all default to -1. For the icon, "same" is the default and means no change; "" can be used to remove the icon reference outright. Some examples:

  LPF SPELL_ALTER_HEADER INT_VAR range = 30 END

This is a simple patch that corrects the range of a spell. Since neither type nor header were specified, this will adjust all abilities on the spell.

  LPF SPELL_ALTER_HEADER INT_VAR speed = 1 END

This is another simple patch; this one corrects the casting speed of a spell. Since neither type nor header were specified, this will adjust all abilities on the spell.

SPELL_DELETE_HEADER

This can be used to delete an ability header from a spell, along with all of its associated effects, and properly re-index the file.

  INT_VAR type      = 0    // -1 for all headers, otherwise match type
min_level = "-1" // -1 for all headers, otherwise match

This was written mainly to purge old BG items of their extraneous type (0) effects and was ported to allow the same functionality for spells. This can be targeted against specific types of headers or against headers of a certain minimum levels.