From f6e76f60009beb0f5d57ef22a396876a761485ee Mon Sep 17 00:00:00 2001 From: nosoop Date: Tue, 9 Apr 2019 03:47:51 -0700 Subject: [PATCH] Add native to get an attribute index from a name --- gamedata/tf2.econ_data.txt | 11 ++++++ scripting/include/tf_econ_data.inc | 6 +++ scripting/tf_econ_data.sp | 37 ++++++++++++++++++- .../tf_econ_data/attribute_definition.sp | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/gamedata/tf2.econ_data.txt b/gamedata/tf2.econ_data.txt index 410fec9..695a1f8 100644 --- a/gamedata/tf2.econ_data.txt +++ b/gamedata/tf2.econ_data.txt @@ -22,6 +22,12 @@ "linux" "@_ZN15CEconItemSchema22GetAttributeDefinitionEi" "windows" "\x55\x8B\xEC\x83\xEC\x2A\x53\x56\x8B\xD9\x8D\x2A\x2A\x57" } + "CEconItemSchema::GetAttributeDefinitionByName()" + { + "library" "server" + "linux" "@_ZN15CEconItemSchema28GetAttributeDefinitionByNameEPKc" + "windows" "\x55\x8B\xEC\x83\xEC\x14\x53\x8B\x5D\x08\x56\x57\x8B\xF9\x85\xDB" + } "TranslateWeaponEntForClass()" { // get x-ref to structure containing string "saxxy" @@ -105,6 +111,11 @@ "linux" "0" "windows" "0" } + "CEconItemAttributeDefinition::m_iAttributeDefinitionIndex" + { + "linux" "4" + "windows" "4" + } "CEconItemAttributeDefinition::m_bHidden" { "linux" "12" diff --git a/scripting/include/tf_econ_data.inc b/scripting/include/tf_econ_data.inc index 14c3181..f7ccbaf 100644 --- a/scripting/include/tf_econ_data.inc +++ b/scripting/include/tf_econ_data.inc @@ -140,6 +140,12 @@ native bool TF2Econ_GetAttributeClassName(int defindex, char[] buffer, int maxle native void TF2Econ_GetAttributeDefinitionString(int defindex, const char[] key, char[] buffer, int maxlen, const char[] defaultValue = ""); +/** + * Returns the attribute definition index for a given name, or -1 if the name does not + * correspond to an attribute. + */ +native int TF2Econ_TranslateAttributeNameToDefinitionIndex(const char[] name); + /** * Returns the address of the singleton CTFItemSchema (subclass of CEconItemSchema). * diff --git a/scripting/tf_econ_data.sp b/scripting/tf_econ_data.sp index b7f78e1..e348689 100644 --- a/scripting/tf_econ_data.sp +++ b/scripting/tf_econ_data.sp @@ -13,7 +13,7 @@ #include #include -#define PLUGIN_VERSION "0.10.0" +#define PLUGIN_VERSION "0.11.0" public Plugin myinfo = { name = "[TF2] Econ Data", author = "nosoop", @@ -30,6 +30,7 @@ public Plugin myinfo = { Handle g_SDKCallGetEconItemSchema; Handle g_SDKCallSchemaGetItemDefinition; Handle g_SDKCallSchemaGetAttributeDefinition; +Handle g_SDKCallSchemaGetAttributeDefinitionByName; Handle g_SDKCallTranslateWeaponEntForClass; Address offs_CEconItemSchema_ItemList, @@ -68,6 +69,8 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) { CreateNative("TF2Econ_GetAttributeName", Native_GetAttributeName); CreateNative("TF2Econ_GetAttributeClassName", Native_GetAttributeClassName); CreateNative("TF2Econ_GetAttributeDefinitionString", Native_GetAttributeDefinitionString); + CreateNative("TF2Econ_TranslateAttributeNameToDefinitionIndex", + Native_TranslateAttributeNameToDefinitionIndex); // low-level stuff CreateNative("TF2Econ_GetItemSchemaAddress", Native_GetItemSchemaAddress); @@ -105,6 +108,13 @@ public void OnPluginStart() { PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); g_SDKCallSchemaGetAttributeDefinition = EndPrepSDKCall(); + StartPrepSDKCall(SDKCall_Raw); + PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, + "CEconItemSchema::GetAttributeDefinitionByName()"); + PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain); + PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer); + g_SDKCallSchemaGetAttributeDefinitionByName = EndPrepSDKCall(); + StartPrepSDKCall(SDKCall_Static); PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "TranslateWeaponEntForClass()"); PrepSDKCall_SetReturnInfo(SDKType_String, SDKPass_Pointer); @@ -151,6 +161,9 @@ public void OnPluginStart() { offs_CEconItemAttributeDefinition_pKeyValues = GameConfGetAddressOffset(hGameConf, "CEconItemAttributeDefinition::m_pKeyValues"); + offs_CEconItemAttributeDefinition_iAttributeDefinitionIndex = + GameConfGetAddressOffset(hGameConf, + "CEconItemAttributeDefinition::m_iAttributeDefinitionIndex"); offs_CEconItemAttributeDefinition_bHidden = GameConfGetAddressOffset(hGameConf, "CEconItemAttributeDefinition::m_bHidden"); offs_CEconItemAttributeDefinition_bIsInteger = @@ -255,6 +268,28 @@ Address GetEconAttributeDefinition(int defindex) { SDKCall(g_SDKCallSchemaGetAttributeDefinition, pSchema, defindex) : Address_Null; } +public int Native_TranslateAttributeNameToDefinitionIndex(Handle hPlugin, int nParams) { + int maxlen; + GetNativeStringLength(1, maxlen); + maxlen++; + char[] attrName = new char[maxlen]; + GetNativeString(1, attrName, maxlen); + + Address pAttribute = GetEconAttributeDefinitionByName(attrName); + if (pAttribute) { + Address pOffs = + pAttribute + offs_CEconItemAttributeDefinition_iAttributeDefinitionIndex; + return LoadFromAddress(pOffs, NumberType_Int32); + } + return -1; +} + +Address GetEconAttributeDefinitionByName(const char[] name) { + Address pSchema = GetEconItemSchema(); + return pSchema? + SDKCall(g_SDKCallSchemaGetAttributeDefinitionByName, pSchema, name) : Address_Null; +} + Address GetEconItemSchema() { return SDKCall(g_SDKCallGetEconItemSchema); } diff --git a/scripting/tf_econ_data/attribute_definition.sp b/scripting/tf_econ_data/attribute_definition.sp index 5982e48..acc418e 100644 --- a/scripting/tf_econ_data/attribute_definition.sp +++ b/scripting/tf_econ_data/attribute_definition.sp @@ -1,4 +1,5 @@ Address offs_CEconItemAttributeDefinition_pKeyValues, + offs_CEconItemAttributeDefinition_iAttributeDefinitionIndex, offs_CEconItemAttributeDefinition_bHidden, offs_CEconItemAttributeDefinition_bIsInteger, offs_CEconItemAttributeDefinition_pszAttributeName,