mirror of
https://github.com/acidicoala/SmokeAPI.git
synced 2026-01-26 06:22:51 -05:00
Refactored for latest Koalabox
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
#include <steam_impl/steam_inventory.hpp>
|
||||
#include <core/config.hpp>
|
||||
#include <koalabox/logger.hpp>
|
||||
|
||||
namespace steam_inventory {
|
||||
|
||||
EResult GetResultStatus(
|
||||
const String& function_name,
|
||||
const SteamInventoryResult_t resultHandle,
|
||||
const std::function<EResult()>& original_function
|
||||
const Function<EResult()>& original_function
|
||||
) {
|
||||
const auto status = original_function();
|
||||
|
||||
logger->debug("{} -> handle: {}, status: {}", function_name, resultHandle, (int) status);
|
||||
LOG_DEBUG("{} -> handle: {}, status: {}", function_name, resultHandle, (int) status)
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -20,8 +21,8 @@ namespace steam_inventory {
|
||||
const SteamInventoryResult_t resultHandle,
|
||||
SteamItemDetails_t* pOutItemsArray,
|
||||
uint32_t* punOutItemsArraySize,
|
||||
const std::function<bool()>& original_function,
|
||||
const std::function<bool(SteamItemDef_t*, uint32_t*)>& get_item_definition_ids
|
||||
const Function<bool()>& original_function,
|
||||
const Function<bool(SteamItemDef_t*, uint32_t*)>& get_item_definition_ids
|
||||
) {
|
||||
static std::mutex section;
|
||||
const std::lock_guard<std::mutex> guard(section);
|
||||
@@ -29,26 +30,26 @@ namespace steam_inventory {
|
||||
const auto success = original_function();
|
||||
|
||||
auto print_item = [](const String& tag, const SteamItemDetails_t& item) {
|
||||
logger->debug(
|
||||
LOG_DEBUG(
|
||||
" [{}] definitionId: {}, itemId: {}, quantity: {}, flags: {}",
|
||||
tag, item.m_iDefinition, item.m_itemId, item.m_unQuantity, item.m_unFlags
|
||||
);
|
||||
)
|
||||
};
|
||||
|
||||
if (not success) {
|
||||
logger->debug("{} -> original result is false", function_name);
|
||||
LOG_DEBUG("{} -> original result is false", function_name)
|
||||
return success;
|
||||
}
|
||||
|
||||
if (punOutItemsArraySize == nullptr) {
|
||||
logger->error("{} -> arraySize pointer is null", function_name);
|
||||
LOG_ERROR("{} -> arraySize pointer is null", function_name)
|
||||
return success;
|
||||
}
|
||||
|
||||
logger->debug(
|
||||
LOG_DEBUG(
|
||||
"{} -> handle: {}, pOutItemsArray: {}, arraySize: {}",
|
||||
function_name, resultHandle, fmt::ptr(pOutItemsArray), *punOutItemsArraySize
|
||||
);
|
||||
)
|
||||
|
||||
static uint32_t original_count = 0;
|
||||
const auto injected_count = config::instance.extra_inventory_items.size();
|
||||
@@ -56,14 +57,13 @@ namespace steam_inventory {
|
||||
// Automatically get inventory items from steam
|
||||
static Vector<SteamItemDef_t> auto_inventory_items;
|
||||
if (config::instance.auto_inject_inventory) {
|
||||
static std::once_flag flag;
|
||||
std::call_once(flag, [&]() {
|
||||
CALL_ONCE({
|
||||
uint32_t count = 0;
|
||||
if (get_item_definition_ids(nullptr, &count)) {
|
||||
auto_inventory_items.resize(count);
|
||||
get_item_definition_ids(auto_inventory_items.data(), &count);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
const auto auto_injected_count = auto_inventory_items.size();
|
||||
@@ -72,10 +72,10 @@ namespace steam_inventory {
|
||||
// If pOutItemsArray is NULL then we must set the array size.
|
||||
original_count = *punOutItemsArraySize;
|
||||
*punOutItemsArraySize += auto_injected_count + injected_count;
|
||||
logger->debug(
|
||||
LOG_DEBUG(
|
||||
"{} -> Original count: {}, Total count: {}",
|
||||
function_name, original_count, *punOutItemsArraySize
|
||||
);
|
||||
)
|
||||
} else {
|
||||
// Otherwise, we modify the array
|
||||
for (int i = 0; i < original_count; i++) {
|
||||
@@ -120,7 +120,7 @@ namespace steam_inventory {
|
||||
const char* pchPropertyName,
|
||||
char* pchValueBuffer,
|
||||
const uint32_t* punValueBufferSizeOut,
|
||||
const std::function<bool()>& original_function
|
||||
const Function<bool()>& original_function
|
||||
) {
|
||||
const auto common_info = fmt::format(
|
||||
"{} -> Handle: {}, Index: {}, Name: '{}'", function_name, resultHandle, unItemIndex, pchPropertyName
|
||||
@@ -129,11 +129,11 @@ namespace steam_inventory {
|
||||
const auto success = original_function();
|
||||
|
||||
if (!success) {
|
||||
logger->warn("{}, Result is false", common_info);
|
||||
LOG_WARN("{}, Result is false", common_info)
|
||||
return false;
|
||||
}
|
||||
|
||||
logger->debug("{}, Buffer: '{}'", common_info, String(pchValueBuffer, *punValueBufferSizeOut - 1));
|
||||
LOG_DEBUG("{}, Buffer: '{}'", common_info, String(pchValueBuffer, *punValueBufferSizeOut - 1))
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -141,11 +141,11 @@ namespace steam_inventory {
|
||||
bool GetAllItems(
|
||||
const String& function_name,
|
||||
const SteamInventoryResult_t* pResultHandle,
|
||||
const std::function<bool()>& original_function
|
||||
const Function<bool()>& original_function
|
||||
) {
|
||||
const auto success = original_function();
|
||||
|
||||
logger->debug("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle));
|
||||
LOG_DEBUG("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle))
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -156,15 +156,15 @@ namespace steam_inventory {
|
||||
SteamInventoryResult_t* pResultHandle,
|
||||
const SteamItemInstanceID_t* pInstanceIDs,
|
||||
const uint32_t unCountInstanceIDs,
|
||||
const std::function<bool()>& original_function
|
||||
const Function<bool()>& original_function
|
||||
) {
|
||||
const auto success = original_function();
|
||||
|
||||
logger->debug("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle));
|
||||
LOG_DEBUG("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle))
|
||||
|
||||
if (success && pInstanceIDs != nullptr) {
|
||||
for (int i = 0; i < unCountInstanceIDs; i++) {
|
||||
logger->debug(" Index: {}, ItemId: {}", i, pInstanceIDs[i]);
|
||||
LOG_DEBUG(" Index: {}, ItemId: {}", i, pInstanceIDs[i])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,15 +176,15 @@ namespace steam_inventory {
|
||||
SteamInventoryResult_t resultHandle,
|
||||
void* pOutBuffer,
|
||||
uint32_t* punOutBufferSize,
|
||||
const std::function<bool()>& original_function
|
||||
const Function<bool()>& original_function
|
||||
) {
|
||||
const auto success = original_function();
|
||||
|
||||
if (pOutBuffer != nullptr) {
|
||||
String buffer((char*) pOutBuffer, *punOutBufferSize);
|
||||
logger->debug("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
|
||||
LOG_DEBUG("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer)
|
||||
} else {
|
||||
logger->debug("{} -> Handle: {}, Size: '{}'", function_name, resultHandle, *punOutBufferSize);
|
||||
LOG_DEBUG("{} -> Handle: {}, Size: '{}'", function_name, resultHandle, *punOutBufferSize)
|
||||
}
|
||||
|
||||
return success;
|
||||
@@ -194,23 +194,23 @@ namespace steam_inventory {
|
||||
const String& function_name,
|
||||
const SteamItemDef_t* pItemDefIDs,
|
||||
uint32_t* punItemDefIDsArraySize,
|
||||
const std::function<bool()>& original_function
|
||||
const Function<bool()>& original_function
|
||||
) {
|
||||
const auto success = original_function();
|
||||
|
||||
if (!success) {
|
||||
logger->warn("{} -> Result is false", function_name);
|
||||
LOG_WARN("{} -> Result is false", function_name)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (punItemDefIDsArraySize) {
|
||||
logger->debug("{} -> Size: {}", function_name, *punItemDefIDsArraySize);
|
||||
LOG_DEBUG("{} -> Size: {}", function_name, *punItemDefIDsArraySize)
|
||||
}
|
||||
|
||||
if (pItemDefIDs) { // Definitions were copied
|
||||
for (int i = 0; i < *punItemDefIDsArraySize; i++) {
|
||||
const auto& def = pItemDefIDs[i];
|
||||
logger->debug(" Index: {}, ID: {}", i, def);
|
||||
LOG_DEBUG(" Index: {}, ID: {}", i, def)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,14 +221,14 @@ namespace steam_inventory {
|
||||
const String& function_name,
|
||||
SteamInventoryResult_t resultHandle,
|
||||
CSteamID steamIDExpected,
|
||||
const std::function<bool()>& original_function
|
||||
const Function<bool()>& original_function
|
||||
) {
|
||||
const auto result = original_function();
|
||||
|
||||
logger->debug(
|
||||
LOG_DEBUG(
|
||||
"{} -> handle: {}, steamID: {}, original result: {}",
|
||||
function_name, resultHandle, steamIDExpected, result
|
||||
);
|
||||
)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user