Skip to content

Commit

Permalink
Add TF2Econ_IsItemInBaseSet native (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
FortyTwoFortyTwo authored Oct 26, 2021
1 parent 2b27804 commit c03048a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gamedata/tf2.econ_data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@
"linux" "220"
"windows" "220"
}
"CEconItemDefinition::m_bBaseItem"
{
// x-ref "baseitem" in CEconItemDefinition::BInitFromKV()
"linux" "230"
"windows" "230"
}
"CEconItemDefinition::m_bitsEquipRegionGroups"
{
// result of CEconItemSchema::GetEquipRegionBitMaskByName() call
Expand Down
5 changes: 5 additions & 0 deletions scripting/include/tf_econ_data.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ typedef ItemFilterCriteria = function bool(int itemdef, any data);
*/
native bool TF2Econ_IsValidItemDefinition(int itemdef);

/**
* Returns true if item is in base set (corresponds to the "baseitem" key).
*/
native bool TF2Econ_IsItemInBaseSet(int itemdef);

/**
* Returns the item's name (corresponds to the "name" key).
*/
Expand Down
3 changes: 3 additions & 0 deletions scripting/tf_econ_data.sp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {

// item information
CreateNative("TF2Econ_IsValidItemDefinition", Native_IsValidItemDefinition);
CreateNative("TF2Econ_IsItemInBaseSet", Native_IsItemInBaseSet);
CreateNative("TF2Econ_GetItemName", Native_GetItemName);
CreateNative("TF2Econ_GetLocalizedItemName", Native_GetLocalizedItemName);
CreateNative("TF2Econ_GetItemClassName", Native_GetItemClassName);
Expand Down Expand Up @@ -219,6 +220,8 @@ public void OnPluginStart() {
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_pszItemClassname");
offs_CEconItemDefinition_pszItemName =
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_pszItemName");
offs_CEconItemDefinition_bBaseItem =
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_bBaseItem");
offs_CEconItemDefinition_bitsEquipRegionGroups =
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_bitsEquipRegionGroups");
offs_CEconItemDefinition_bitsEquipRegionConflicts =
Expand Down
16 changes: 16 additions & 0 deletions scripting/tf_econ_data/item_definition.sp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Address offs_CEconItemDefinition_pKeyValues,
offs_CEconItemDefinition_pszLocalizedItemName,
offs_CEconItemDefinition_pszItemClassname,
offs_CEconItemDefinition_pszItemName,
offs_CEconItemDefinition_bBaseItem,
offs_CEconItemDefinition_bitsEquipRegionGroups,
offs_CEconItemDefinition_bitsEquipRegionConflicts;
Address offs_CEconItemDefinition_aiItemSlot,
Expand Down Expand Up @@ -278,6 +279,21 @@ public int Native_GetItemDefinitionString(Handle hPlugin, int nParams) {
return !!buffer[0];
}

/**
* native int(int itemdef);
*
* Returns whenever item is in base set, false if the item definition does not exist.
*/
public int Native_IsItemInBaseSet(Handle hPlugin, int nParams) {
int defindex = GetNativeCell(1);
Address pItemDef = GetEconItemDefinition(defindex);
if (!pItemDef) {
return false;
}
return !!LoadFromAddress(pItemDef + offs_CEconItemDefinition_bBaseItem,
NumberType_Int8);
}

/**
* native bool(int itemdef);
*
Expand Down

0 comments on commit c03048a

Please sign in to comment.