Skip to content

Commit

Permalink
Read size of static_attrib_t from gamedata
Browse files Browse the repository at this point in the history
Totally not useless futureproofing.
  • Loading branch information
nosoop committed Feb 5, 2020
1 parent 19acb66 commit 74f50c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions gamedata/tf2.econ_data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@
"linux" "268"
"windows" "268"
}

"sizeof(static_attrib_t)"
{
// used for iterating over the attribute list
"linux" "8"
"windows" "8"
}
}
}
}
4 changes: 3 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.5"
#define PLUGIN_VERSION "0.16.6"
public Plugin myinfo = {
name = "[TF2] Econ Data",
author = "nosoop",
Expand Down Expand Up @@ -275,6 +275,8 @@ public void OnPluginStart() {
GameConfGetAddressOffset(hGameConf,
"CProtoBufScriptObjectDefinitionManager::m_PaintList");

sizeof_static_attrib_t = GameConfGetAddressOffset(hGameConf, "sizeof(static_attrib_t)");

delete hGameConf;

CreateConVar("tfecondata_version", PLUGIN_VERSION,
Expand Down
8 changes: 5 additions & 3 deletions scripting/tf_econ_data/item_definition.sp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Address offs_CEconItemDefinition_pKeyValues,
offs_CEconItemDefinition_bitsEquipRegionConflicts;
Address offs_CEconItemDefinition_aiItemSlot;

Address sizeof_static_attrib_t;

// in CEconItemDefinition, defindex is at 0x08 (we never use this information though)

/**
Expand Down Expand Up @@ -212,11 +214,11 @@ public int Native_GetItemStaticAttributes(Handle hPlugin, int nParams) {
NumberType_Int32);
Address pAttribList = DereferencePointer(pItemDef + offs_CEconItemDefinition_AttributeList);

// struct { attribute_defindex, value }
// struct { attribute_defindex, value } // (TF2)
ArrayList attributeList = new ArrayList(2, nAttribs);
for (int i; i < nAttribs; i++) {
// TODO push attributes to list
Address pStaticAttrib = pAttribList + view_as<Address>(i * 0x08);
Address pStaticAttrib = pAttribList
+ view_as<Address>(i * view_as<int>(sizeof_static_attrib_t));

int attrIndex = LoadFromAddress(pStaticAttrib, NumberType_Int16);
any attrValue = LoadFromAddress(pStaticAttrib + view_as<Address>(0x04),
Expand Down

0 comments on commit 74f50c0

Please sign in to comment.