Author Topic: Simple Bad Strref Item Property Filter  (Read 9417 times)

Offline 420

  • Hero Member
  • *****
  • Posts: 4087
    • View Profile
    • Email
Simple Bad Strref Item Property Filter
« on: January 18, 2007, 01:43:28 PM »
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
Code: [Select]
//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
« Last Edit: May 20, 2007, 05:20:59 PM by 420 »

Offline 420

  • Hero Member
  • *****
  • Posts: 4087
    • View Profile
    • Email
Simple Bad Strref Item Property Filter
« Reply #1 on: May 20, 2007, 05:19:52 PM »
Ser Red Ronnet Connington brought to my attention that the bad strref filter I posted was getting stuck in an infinite loop. While looking into this I actually decided to test it with a bad strref item and sure enough, the script was completely wrong!

Well, I fixed the infinite loop and the item property sub-type check and even streamlined the code a bit to make it more efficient. I've tested this script with a bad strref item equipped and with one in the inventory and it now properly removes all bad strref properties on items.

Thanks to Ser for bringing my attention to this problem.

Cheers,
420

Ser Red Ronnet Connington

  • Guest
Simple Bad Strref Item Property Filter
« Reply #2 on: May 20, 2007, 05:47:18 PM »
Quote
Ser Red Ronnet Connington brought to my attention that the bad strref filter I posted was getting stuck in an infinite loop. While looking into this I actually decided to test it with a bad strref item and sure enough, the script was completely wrong!

Well, I fixed the infinite loop and the item property sub-type check and even streamlined the code a bit to make it more efficient. I've tested this script with a bad strref item equipped and with one in the inventory and it now properly removes all bad strref properties on items.

Thanks to Ser for bringing my attention to this problem.

Cheers,
420
[snapback]35284[/snapback]

No problem, thanks for the script.