Skip to content

Commit

Permalink
Add TF2Econ_GetItemDefaultLoadoutSlot
Browse files Browse the repository at this point in the history
  • Loading branch information
nosoop committed Aug 31, 2020
1 parent b9034c4 commit e1fcc49
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
16 changes: 14 additions & 2 deletions gamedata/tf2.econ_data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@
"windows" "308"
}

// wait, shoot, this is CTFItemDefinition -- rename this once the next revision is out?
"CEconItemDefinition::m_aiItemSlot"
"CTFItemDefinition::m_iDefaultItemSlot"
{
"linux" "400"
"windows" "400"
}
"CTFItemDefinition::m_aiItemSlot"
{
// array mapping class indices to item slots (-1 if not valid for class)
// x-ref "used_by_classes" in CTFItemDefinition::BInitFromKV()
Expand All @@ -157,6 +161,14 @@
"windows" "512"
}

// DEPRECATED: this is present as a transitional period for backwards compatibility.
// this will be removed at some point
"CEconItemDefinition::m_aiItemSlot"
{
"linux" "512"
"windows" "512"
}

"CEconItemAttributeDefinition::m_pKeyValues"
{
// set in CEconItemAttributeDefinition::BInitFromKV() after KeyValues::MakeCopy()
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 @@ -70,6 +70,11 @@ native bool TF2Econ_GetItemClassName(int itemdef, char[] buffer, int maxlen);
*/
native int TF2Econ_GetItemLoadoutSlot(int itemdef, TFClassType playerClass);

/**
* Returns the item's default loadout slot.
*/
native int TF2Econ_GetItemDefaultLoadoutSlot(int itemdef);

/**
* Returns the given item's equipment region mask. This mask can be and-tested with another
* mask to determine if items conflict.
Expand Down
8 changes: 6 additions & 2 deletions 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.7"
#define PLUGIN_VERSION "0.17.0"
public Plugin myinfo = {
name = "[TF2] Econ Data",
author = "nosoop",
Expand Down Expand Up @@ -55,6 +55,7 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
CreateNative("TF2Econ_GetLocalizedItemName", Native_GetLocalizedItemName);
CreateNative("TF2Econ_GetItemClassName", Native_GetItemClassName);
CreateNative("TF2Econ_GetItemLoadoutSlot", Native_GetItemSlot);
CreateNative("TF2Econ_GetItemDefaultLoadoutSlot", Native_GetItemDefaultSlot);
CreateNative("TF2Econ_GetItemEquipRegionMask", Native_GetItemEquipRegionMask);
CreateNative("TF2Econ_GetItemEquipRegionGroupBits", Native_GetItemEquipRegionGroupBits);
CreateNative("TF2Econ_GetItemLevelRange", Native_GetItemLevelRange);
Expand Down Expand Up @@ -211,8 +212,11 @@ public void OnPluginStart() {
offs_CEconItemDefinition_bitsEquipRegionConflicts =
GameConfGetAddressOffset(hGameConf,
"CEconItemDefinition::m_bitsEquipRegionConflicts");

offs_CTFItemDefinition_iDefaultItemSlot =
GameConfGetAddressOffset(hGameConf, "CTFItemDefinition::m_iDefaultItemSlot");
offs_CEconItemDefinition_aiItemSlot =
GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_aiItemSlot");
GameConfGetAddressOffset(hGameConf, "CTFItemDefinition::m_aiItemSlot");

offs_CEconItemSchema_ItemRarities =
GameConfGetAddressOffset(hGameConf, "CEconItemSchema::m_ItemRarities");
Expand Down
18 changes: 17 additions & 1 deletion scripting/tf_econ_data/item_definition.sp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Address offs_CEconItemDefinition_pKeyValues,
offs_CEconItemDefinition_pszItemName,
offs_CEconItemDefinition_bitsEquipRegionGroups,
offs_CEconItemDefinition_bitsEquipRegionConflicts;
Address offs_CEconItemDefinition_aiItemSlot;
Address offs_CEconItemDefinition_aiItemSlot,
offs_CTFItemDefinition_iDefaultItemSlot;

Address sizeof_static_attrib_t;

Expand Down Expand Up @@ -96,6 +97,21 @@ public int Native_GetItemSlot(Handle hPlugin, int nParams) {
view_as<Address>(playerClass * 4), NumberType_Int32);
}

/**
* native int();
*
* Returns the default assigned item loadout slot, or -1 if the item definition does not exist.
*/
public int Native_GetItemDefaultSlot(Handle hPlugin, int nParams) {
int defindex = GetNativeCell(1);
Address pItemDef = GetEconItemDefinition(defindex);
if (!pItemDef) {
return -1;
}
return LoadFromAddress(pItemDef + offs_CTFItemDefinition_iDefaultItemSlot,
NumberType_Int32);
}

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

0 comments on commit e1fcc49

Please sign in to comment.