From 93c1f2a9dd8fa423d0c7f3d57f12e68ad6fdcbd5 Mon Sep 17 00:00:00 2001 From: nosoop Date: Sun, 17 Mar 2019 05:02:25 -0700 Subject: [PATCH] Add KV key existence check Bandaid that fixes #1. --- gamedata/tf2.econ_data.txt | 7 +++++++ scripting/tf_econ_data.sp | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gamedata/tf2.econ_data.txt b/gamedata/tf2.econ_data.txt index 45d0ac5..fc8b3f6 100644 --- a/gamedata/tf2.econ_data.txt +++ b/gamedata/tf2.econ_data.txt @@ -31,6 +31,13 @@ "linux" "@_ZN9KeyValues9GetStringEPKcS1_" "windows" "\x55\x8B\xEC\x81\xEC\x40\x02\x00\x00" } + "KeyValues::FindKey()" + { + // first call in KeyValues::GetString() + "library" "server" + "linux" "@_ZN9KeyValues7FindKeyEPKcb" + "windows" "\x55\x8B\xEC\x81\xEC\x04\x01\x00\x00\x56\x8B\x75\x08\x57" + } } "Offsets" diff --git a/scripting/tf_econ_data.sp b/scripting/tf_econ_data.sp index 30fa2b0..aa42da6 100644 --- a/scripting/tf_econ_data.sp +++ b/scripting/tf_econ_data.sp @@ -26,6 +26,7 @@ Handle g_SDKCallGetEconItemSchema; Handle g_SDKCallSchemaGetItemDefinition; Handle g_SDKCallTranslateWeaponEntForClass; Handle g_SDKCallGetKeyValuesString; +Handle g_SDKCallGetKeyValuesFindKey; Address offs_CEconItemDefinition_pKeyValues, offs_CEconItemDefinition_u8MinLevel, @@ -94,6 +95,13 @@ public void OnPluginStart() { PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); g_SDKCallGetKeyValuesString = EndPrepSDKCall(); + StartPrepSDKCall(SDKCall_Raw); + PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "KeyValues::FindKey()"); + PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain); + PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer); + PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain); + g_SDKCallGetKeyValuesFindKey = EndPrepSDKCall(); + offs_CEconItemDefinition_pKeyValues = GameConfGetAddressOffset(hGameConf, "CEconItemDefinition::m_pKeyValues"); offs_CEconItemDefinition_u8MinLevel = @@ -222,7 +230,7 @@ public int Native_GetItemDefinitionString(Handle hPlugin, int nParams) { Address pItemDef = GetEconItemDefinition(defindex); if (pItemDef) { Address pKeyValues = DereferencePointer(pItemDef + offs_CEconItemDefinition_pKeyValues); - if (pKeyValues) { + if (KeyValuesPtrKeyExists(pKeyValues, key)) { SDKCall(g_SDKCallGetKeyValuesString, pKeyValues, buffer, maxlen, key, buffer); } } @@ -320,6 +328,13 @@ static bool LoadEconItemDefinitionString(int defindex, Address offset, char[] bu return true; } +static bool KeyValuesPtrKeyExists(Address pKeyValues, const char[] key) { + if (!pKeyValues) { + return false; + } + return !!SDKCall(g_SDKCallGetKeyValuesFindKey, pKeyValues, key, false); +} + static Address GetEconItemSchema() { return SDKCall(g_SDKCallGetEconItemSchema); }