From 06f88d4687e34abb129a4e9ce0a1e233028c4224 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Fri, 12 Jul 2019 22:26:45 +0200 Subject: [PATCH] Added the missing use cases If pchPropertyName == NULL and/or pchValueBuffer == NULL --- dll/steam_inventory.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/dll/steam_inventory.h b/dll/steam_inventory.h index c3e8af49..d25c7b49 100644 --- a/dll/steam_inventory.h +++ b/dll/steam_inventory.h @@ -560,7 +560,7 @@ bool GetItemDefinitionIDs( return false; for (auto& i : items) - * pItemDefIDs++ = i.first; + *pItemDefIDs++ = i.first; return true; } @@ -586,6 +586,7 @@ bool GetItemDefinitionProperty( SteamItemDef_t iDefinition, const char *pchPrope attr_iterator attr; if (pchPropertyName != nullptr) { + // Should I check for punValueBufferSizeOut == nullptr ? // Try to get the property if ((attr = item->second.find(pchPropertyName)) != items[iDefinition].end()) { @@ -604,6 +605,32 @@ bool GetItemDefinitionProperty( SteamItemDef_t iDefinition, const char *pchPrope PRINT_DEBUG("Attr %s not found for item %d", pchPropertyName, iDefinition); } } + else // Pass a NULL pointer for pchPropertyName to get a comma - separated list of available property names. + { + // If pchValueBuffer is NULL, *punValueBufferSize will contain the suggested buffer size + if (pchValueBuffer == nullptr) + { + // Should I check for punValueBufferSizeOut == nullptr ? + *punValueBufferSizeOut = 0; + for (auto& i : item->second) + *punValueBufferSizeOut += i.first.length() + 1; // Size of key + comma, and the last is not a comma but null char + } + else + { + uint32_t len = *punValueBufferSizeOut; + memset(pchValueBuffer, 0, len); + for( auto i = item->second.begin(); i != item->second.end() && len > 0; ++i ) + { + strncat(pchValueBuffer, i->first.c_str(), len); + len -= i->first.length(); + if (len <= 0) // Check if we reached the end of the buffer + break; + + if (std::distance(i, item->second.end()) != 1) // If this is not the last item, add a comma + strncat(pchValueBuffer, ",", len--); + } + } + } } return true; }