I've had a couple requests recently for a filter that removes "bad strref" item properties,
For those unfamiliar with the term, bad strref is short for "bad string reference" and specifically refers to an invalid value in the corrisponding .2da file. Bad strref items can be used to deal insane amounts of damage, crash mods or clients and all sorts of other nasty stuff.
Here is a quick filter I typed up this morning that should detect and remove all bad strref properties from all the items on a PC:
NOTE: This script should work for both NWN and NWN2
//420's Bad Strref Item Property Filter
//Created: January 18, 2007
//Last Update: May 20, 2007
//Put in OnClientEnter
void main()
{
//Declare variables
object oPC = GetEnteringObject();
object oItem;
itemproperty ipProp;
int iType;
string sType;
string sSubTypeResRef;
int iSubType;
string sSubType;
int iCounter;
//Cycle through all equipped items
for (iCounter = 0; iCounter <= NUM_INVENTORY_SLOTS; iCounter++)
{
oItem = GetItemInSlot(iCounter, oPC);
if(GetIsObjectValid(oItem))
{
//Cycle through item's properties
ipProp = GetFirstItemProperty(oItem);
while(GetIsItemPropertyValid(ipProp))
{
//Check for bad strref property types and remove them
iType = GetItemPropertyType(ipProp);
sType = Get2DAString("itempropdef", "Name", iType);
sSubTypeResRef = Get2DAString("itempropdef", "SubTypeResRef", iType);
if(sType == "")
{
RemoveItemProperty(oItem, ipProp);
}
//Check for valid property subtype if property type is valid
else if(sSubTypeResRef != "")
{
//Check for bad strref property sub types and remove them
iSubType = GetItemPropertySubType(ipProp);
sSubType = Get2DAString(sSubTypeResRef, "Name", iSubType);
if(sSubType == "")
{
RemoveItemProperty(oItem, ipProp);
}
}
ipProp = GetNextItemProperty(oItem);
}
}
}
//Cycle through all inventory items
oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem) == TRUE)
{
//Cycle through item's properties
ipProp = GetFirstItemProperty(oItem);
while(GetIsItemPropertyValid(ipProp))
{
//Check for bad strref property types and remove them
iType = GetItemPropertyType(ipProp);
sType = Get2DAString("itempropdef", "Name", iType);
sSubTypeResRef = Get2DAString("itempropdef", "SubTypeResRef", iType);
if(sType == "")
{
RemoveItemProperty(oItem, ipProp);
}
//Check for valid property subtype if property type is valid
else if(sSubTypeResRef != "")
{
//Check for bad strref property sub types and remove them
iSubType = GetItemPropertySubType(ipProp);
sSubType = Get2DAString(sSubTypeResRef, "Name", iSubType);
if(sSubType == "")
{
RemoveItemProperty(oItem, ipProp);
}
}
ipProp = GetNextItemProperty(oItem);
}
oItem = GetNextItemInInventory(oPC);
}
}
If you have any problems with this filter please tell me and I'll fix it.
Also, notice I used the "Name" column to check for bad strref, this is because some of the "Label" columns in itempropdef.2da contain valid strings but are not valid item properties. Specifically Vorpal and Wounding (68 and 69) were moved to sub properties and EnhancedContainer_BonusSlot (31) was removed entirely.
-420