Skip to content

Commit

Permalink
Support statically-defined rarities
Browse files Browse the repository at this point in the history
  • Loading branch information
nosoop committed Sep 21, 2019
1 parent 8c117ad commit 77e42df
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions gamedata/tf2.econ_data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
"linux" "18"
"windows" "18"
}
"CEconItemDefinition::m_si8ItemRarity"
{
// byte read in IEconItemInterface::GetRarity()
"linux" "21"
"windows" "21"
}
"CEconItemDefinition::m_AttributeList"
{
"linux" "28"
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 @@ -74,6 +74,11 @@ native int TF2Econ_GetItemEquipRegionGroupBits(int defindex);
*/
native bool TF2Econ_GetItemLevelRange(int defindex, int &iMinLevel, int &iMaxLevel);

/**
* Returns the given item's rarity, or -1 if the item does not have a statically defined rarity.
*/
native int TF2Econ_GetItemRarity(int defindex);

/**
* Returns an `ArrayList` containing attribute defindex / value pairs corresponding to the given
* item definition, or `null` if not a valid item definition.
Expand Down
5 changes: 4 additions & 1 deletion scripting/tf_econ_data.sp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <stocksoup/handles>
#include <stocksoup/memory>

#define PLUGIN_VERSION "0.16.0"
#define PLUGIN_VERSION "0.16.1"
public Plugin myinfo = {
name = "[TF2] Econ Data",
author = "nosoop",
Expand Down Expand Up @@ -56,6 +56,7 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
CreateNative("TF2Econ_GetItemEquipRegionMask", Native_GetItemEquipRegionMask);
CreateNative("TF2Econ_GetItemEquipRegionGroupBits", Native_GetItemEquipRegionGroupBits);
CreateNative("TF2Econ_GetItemLevelRange", Native_GetItemLevelRange);
CreateNative("TF2Econ_GetItemRarity", Native_GetItemRarity);
CreateNative("TF2Econ_GetItemStaticAttributes", Native_GetItemStaticAttributes);
CreateNative("TF2Econ_GetItemDefinitionString", Native_GetItemDefinitionString);

Expand Down Expand Up @@ -188,6 +189,8 @@ public void OnPluginStart() {
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_u8MinLevel");
offs_CEconItemDefinition_u8MaxLevel =
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_u8MaxLevel");
offs_CEconItemDefinition_si8ItemRarity =
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_si8ItemRarity");
offs_CEconItemDefinition_AttributeList =
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_AttributeList");
offs_CEconItemDefinition_pszLocalizedItemName =
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
@@ -1,6 +1,7 @@
Address offs_CEconItemDefinition_pKeyValues,
offs_CEconItemDefinition_u8MinLevel,
offs_CEconItemDefinition_u8MaxLevel,
offs_CEconItemDefinition_si8ItemRarity,
offs_CEconItemDefinition_AttributeList,
offs_CEconItemDefinition_pszLocalizedItemName,
offs_CEconItemDefinition_pszItemClassname,
Expand Down Expand Up @@ -106,6 +107,21 @@ public int Native_GetItemLevelRange(Handle hPlugin, int nParams) {
return false;
}

public int Native_GetItemRarity(Handle hPlugin, int nParams) {
int defindex = GetNativeCell(1);
Address pItemDef = GetEconItemDefinition(defindex);

if (!pItemDef) {
ThrowNativeError(1, "Item definition index %d is not valid", defindex);
}

int rarity = LoadFromAddress(pItemDef + offs_CEconItemDefinition_si8ItemRarity,
NumberType_Int8);

// sign extension on byte -- items that don't have rarities assigned are -1
return (rarity >> 7)? 0xFFFFFF00 | rarity : rarity;
}

bool GetItemLevelRange(int defindex, int &iMinLevel, int &iMaxLevel) {
Address pItemDef = GetEconItemDefinition(defindex);
if (!pItemDef) {
Expand Down

0 comments on commit 77e42df

Please sign in to comment.