Porting TF2IDB and TF2II plugins to TFEconData - nosoop/SM-TFEconData GitHub Wiki

This entry is up-to-date as of version 0.17.1 of the plugin. Newer versions may have added natives that I forgot to add here.

These are the closest available equivalents for both TF2II and TF2IDB. The following terminology is used:

  • "maps directly" indicates the function name can be replaced and everything should work as expected provided there are no additional conditions that need to be met (listed in the same bullet point)
  • "can be done" indicates that a similar native exists, so you should be able to get the same functionality with some rewriting
  • "has no equivalent" indicates that TF2 Econ Data isn't capable of that functionality (yet!)

Additionally, there is now a compatibility shim whose purpose is to accurately respond to TF2II and TF2IDB native calls while using Econ Data as the data source.

TF2ItemsInfo to TFEconData

  • TF2II_IsItemSchemaPrecached() maps directly to true
  • TF2II_IsValidItemID() maps directly to TF2Econ_IsValidItemDefinition()
  • TF2II_GetItemName() maps directly to TF2Econ_GetItemName()
  • TF2II_ItemHasProperty() can be done with calls to TF2Econ_GetItemDefinitionString()
  • TF2II_GetItemClass() maps directly to TF2Econ_GetItemClassName()
  • TF2II_GetListedItemSlot() maps partially to TF2Econ_GetItemLoadoutSlot(), with the following restrictions:
    • The player class must be specified, and -1 is the return value for invalid class / slot combinations. Use TF2Econ_GetItemDefaultLoadoutSlot() if you only care about the default slot.
    • See notes about loadout slots.
    • TF2II_GetItemSlot() maps the tf_weapon_revolver item class to primary instead of secondary.
  • TF2II_GetListedItemSlotName() can be done with TF2Econ_GetItemDefinitionString(int defindex, "item_slot", ...), or calling TF2Econ_TranslateLoadoutSlotIndexToName() on the result of TF2Econ_GetItem*LoadoutSlot()
    • TF2II_GetItemSlotName() maps tf_weapon_revolver entities to primary instead of secondary.
  • TF2II_IsItemUsedByClass() can be done by checking if TF2Econ_GetItemLoadoutSlot() returns -1 for the given player class.
  • TF2II_GetItemMinLevel() and TF2II_GetItemMaxLevel() can be done by passing in integer variables by-ref to TF2Econ_GetItemLevelRange()
  • TF2II_GetItemQuality() maps directly to TF2Econ_GetItemQuality()
  • TF2II_GetItemQualityName() can be done by calling TF2Econ_GetQualityName() on the quality returned from TF2Econ_GetItemQuality().
  • TF2II_GetItemNumAttributes() can be done by getting the length of the ArrayList returned from TF2Econ_GetItemStaticAttributes().
  • TF2II_GetItemAttributeName() can be done by getting the attribute ID from the ArrayList returned from TF2Econ_GetItemStaticAttributes(), calling TF2Econ_GetAttributeName() to get the name.
  • TF2II_GetItemAttributeID() can be done by getting the attribute ID from the ArrayList returned from TF2Econ_GetItemStaticAttributes().
  • TF2II_GetItemAttributeValue() can be done by getting the attribute value from TF2Econ_GetItemStaticAttributes(). This returns a raw 32-bit value; if the attribute is a string / vector you'll probably be better off calling TF2Econ_GetItemDefinitionString(defindex, "static_attrs/${attr}", ...) with the attribute name.
  • TF2II_GetItemAttributes() cab be done with TF2Econ_GetItemStaticAttributes(). I have no idea how their ArrayList is laid out, though.
  • TF2II_GetToolType() can be done with TF2Econ_GetItemDefinitionString(defindex, "tool/type", ...)
  • TF2II_ItemHolidayRestriction() can be done with TF2Econ_GetItemDefinitionString(defindex, "holiday_restriction", ...) and checking the string for your holiday
  • TF2II_GetItemEquipRegions() can be done by extracting the group names from TF2Econ_GetItemEquipRegionGroupBits through TF2Econ_GetEquipRegionGroups.
  • TF2II_IsValidAttribID() maps directly to TF2Econ_IsValidAttributeDefinition()
  • TF2II_GetAttribName() maps directly to TF2Econ_GetAttributeName()
  • TF2II_GetAttribClass() maps directly to TF2Econ_GetAttributeClassName()
  • TF2II_GetAttribDispName() is deprecated — the game doesn't use attribute_name at all.
  • TF2II_GetAttribMinValue() is deprecated — the game doesn't use min_value at all.
  • TF2II_GetAttribMaxValue() is deprecated — the game doesn't use max_value at all.
  • TF2II_GetAttribGroup() is deprecated. I have no idea what it originally was.
  • TF2II_GetAttribDescrString() can be done with TF2Econ_GetAttributeDefinitionString(defindex, "description_string", ...)
  • TF2II_GetAttribDescrFormat() can be done with TF2Econ_GetAttributeDefinitionString(defindex, "description_format", ...)
  • TF2II_HiddenAttrib() maps directly to TF2Econ_IsAttributeHidden()
  • TF2II_GetAttribEffectType() can be done by calling TF2Econ_GetAttributeDefinitionString(defindex, "effect_type", ...) and mapping the results to the appropriate numbers.
  • TF2II_AttribStoredAsInteger() maps directly to TF2Econ_IsAttributeStoredAsInteger()
  • TF2II_GetItemKeyValues() has no equivalent, but if you know the key(s) you're looking for you can use TF2Econ_GetItemDefinitionString()
  • TF2II_GetItemKey() can be done by running StringToInt on the output of TF2Econ_GetItemDefinitionString()
  • TF2II_GetItemKeyFloat() can be done by running StringToFloat on the output of TF2Econ_GetItemDefinitionString()
  • TF2II_GetItemKeyString() maps directly to TF2Econ_GetItemDefinitionString() (with an optional default value as an additional argument)
  • TF2II_GetAttribKeyValues() has no equivalent, but if you know the key(s) you're looking for you can use TF2Econ_GetAttributeDefinitionString()
  • TF2II_GetAttribKey() can be done by running StringToInt on the output of TF2Econ_GetAttributeDefinitionString()
  • TF2II_GetAttribKeyFloat() can be done by running StringToFloat on the output of TF2Econ_GetAttributeDefinitionString()
  • TF2II_GetAttribKeyString() maps directly to TF2Econ_GetAttributeDefinitionString() (with an optional default value as an additional argument)
  • TF2II_IsConflictRegions() can be done by and-ing together bits from the appropriate regions from TF2Econ_GetEquipRegionMask.
  • TF2II_GetQualityByName() maps directly to TF2Econ_TranslateQualityNameToValue()
  • TF2II_GetQualityName() maps directly to TF2Econ_GetQualityName()
  • TF2II_GetAttributeIDByName() maps directly to TF2Econ_TranslateAttributeNameToDefinitionIndex()
  • TF2II_GetAttributeNameByID() maps directly to TF2Econ_GetAttributeName()
  • TF2II_FindItems() can be done with TF2Econ_GetItemList() and a user-defined function to filter the results
  • TF2II_ListAttachableEffects() and TF2II_ListEffects() can be done with TF2Econ_GetParticleAttributeList(). Note that this only seems to exclude non-Unusual cosmetic effects and other_particles; no special handling for killstreak glows and weapon effects are available in Econ Data.
  • TF2II_GetItemLevelByID() can be done by calling GetRandomInt after getting the level range with TF2Econ_GetItemLevelRange()
  • TF2II_GetQualityColor() has no equivalent; it is a stock function with hardcoded color values.
  • TF2II_GetSlotByName() maps directly to TF2Econ_TranslateLoadoutSlotNameToIndex(), though you will need to see notes about loadout slots.

TF2IDB to TFEconData

  • TF2IDB_IsValidItemID() maps directly to TF2Econ_IsValidItemDefinition()
  • TF2IDB_GetItemName() maps directly to TF2Econ_GetItemName()
  • TF2IDB_GetItemClass() maps directly to TF2Econ_GetItemClassName()
  • TF2IDB_GetItemSlotName() can be done with TF2Econ_GetItemDefinitionString(int defindex, "item_slot", ...), or calling TF2Econ_TranslateLoadoutSlotIndexToName() on the result of TF2Econ_GetItem*LoadoutSlot(); this depends on if you want the class-specific or default class slot
  • TF2IDB_GetItemSlot() maps directly to TF2Econ_GetItem*LoadoutSlot(), with the following restrictions.
    • The player class must be specified, and -1 is the return value for invalid class / slot combinations. Use TF2Econ_GetItemDefaultLoadoutSlot() if you only care about the default slot.
    • See notes about loadout slots.
  • TF2IDB_GetItemQuality() maps directly to TF2Econ_GetItemQuality()
  • TF2IDB_GetItemQualityName() can be done by calling TF2Econ_GetQualityName() on the quality returned from TF2Econ_GetItemQuality().
  • TF2IDB_GetItemLevels() maps directly to TF2Econ_GetItemLevelRange()
  • TF2IDB_GetItemAttributes() can be done by translating the output of TF2Econ_GetItemStaticAttributes() from a key / valur pair array into separate keys / values arrays.
  • TF2IDB_GetItemEquipRegions() can be done by extracting the group names from TF2Econ_GetItemEquipRegionGroupBits() through TF2Econ_GetEquipRegionGroups().
  • TF2IDB_DoRegionsConflict() can be done by and-ing together bits from the appropriate regions from TF2Econ_GetEquipRegionMask().
  • TF2IDB_ListParticles() can be done with TF2Econ_GetParticleAttributeList() and removing the values corresponding to stamp_spin and drg_pipe_smoke.
  • TF2IDB_FindItemCustom() can be done with TF2Econ_GetItemList() for items; instead of writing an SQL query you pass in a filter function and use the other available natives to restrict your selection
  • TF2IDB_ItemHasAttribute() can be done by calling TF2Econ_GetItemStaticAttributes() and checking for the attribute ID in the first block
  • TF2IDB_UsedByClasses() can be done by iterating over TFClassType and checking the result of TF2Econ_GetItemLoadoutSlot()
  • TF2IDB_IsValidAttributeID() maps directly to TF2Econ_IsValidAttributeDefinition()
  • TF2IDB_GetAttributeName() maps directly to TF2Econ_GetAttributeName()
  • TF2IDB_GetAttributeClass() maps directly to TF2Econ_GetAttributeClassName()
  • TF2IDB_GetAttributeType() can be done with TF2Econ_GetAttributeDefinitionString(defindex, "attribute_type", ...)
  • TF2IDB_GetAttributeDescString() can be done with TF2Econ_GetAttributeDefinitionString(defindex, "description_string", ...)
  • TF2IDB_GetAttributeDescFormat() can be done with TF2Econ_GetAttributeDefinitionString(defindex, "description_format", ...)
  • TF2IDB_GetAttributeEffectType() can be done with TF2Econ_GetAttributeDefinitionString(defindex, "effect_type", ...)
  • TF2IDB_GetAttributeArmoryDesc() can be done with TF2Econ_GetAttributeDefinitionString(defindex, "armory_desc", ...)
  • TF2IDB_GetAttributeItemTag() can be done with TF2Econ_GetAttributeDefinitionString(defindex, "apply_tag_to_item_definition", ...)
  • TF2IDB_GetAttributeProperties() can be done by parsing out the appropriate data.
  • TF2IDB_GetQualityName() maps directly to TF2Econ_GetQualityName()
  • TF2IDB_GetQualityByName() maps directly to TF2Econ_TranslateQualityNameToValue()
  • TF2IDB_CustomQuery() has no equivalent; determine your use case and use alternative natives.
    • For getting a list of items, use TF2Econ_GetItemList().
    • You may also want to use the compatibility shim, which attempts to generate a compatible SQLite database and subsequently supports arbitrary queries.

Notes about loadout slots

The results of TF2IDB_GetItemSlot() and TF2II_GetItemSlot() are not equivalent to the result of TF2Econ_GetItemLoadoutSlot().

The former matches what the weapon shows up as in GetPlayerWeaponSlot() (which I will refer to as "weapon slots"); this is used to switch weapons during gameplay. The latter uses the TF2-specific slot indices (which are called "loadout slots" internally); this is used in the player inventory system.

You'll have to do one of the following if you're porting a plugin that used TF2IDB_GetItemSlot() / TF2II_GetItemSlot() along with GetPlayerWeaponSlot():

  • Use TF2Util_GetPlayerLoadoutEntity() from TF2 Utils instead of GetPlayerWeaponSlot(). This will require you to consistently use loadout slots.
    • This does not work if the item is normally incompatible with the class (such as Randomizer).
    • This was previously TF2_GetPlayerLoadoutSlot() from the TF2 Wearables API, but TF2 Utils is a more complete package of functions.
  • Use TF2Util_GetWeaponSlot() from TF2 Utils to consistently use weapon slots.
    • This requires an actual spawned entity, and it only works for weapons; it cannot be used for wearables that can be equipped in weapon loadout slots such shields or boots.
  • Use TF2Econ_TranslateLoadoutSlotIndexToName() and TF2Econ_TranslateLoadoutSlotNameToIndex() and maintain your own internal mapping of the slots.