mirror of
https://github.com/acidicoala/SmokeAPI.git
synced 2025-12-05 21:15:39 -05:00
Added ISteamHTTP
This commit is contained in:
@@ -23,8 +23,9 @@ namespace smoke_api::config {
|
||||
)
|
||||
|
||||
struct Config {
|
||||
uint32_t $version = 3;
|
||||
uint32_t $version = 4;
|
||||
bool logging = false;
|
||||
bool log_steam_http = false;
|
||||
AppStatus default_app_status = AppStatus::UNLOCKED;
|
||||
std::map<std::string, AppStatus> override_app_status;
|
||||
std::map<std::string, AppStatus> override_dlc_status;
|
||||
@@ -32,7 +33,7 @@ namespace smoke_api::config {
|
||||
bool auto_inject_inventory = true;
|
||||
std::vector<uint32_t> extra_inventory_items;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(
|
||||
Config,
|
||||
$version,
|
||||
logging,
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace smoke_api::steam_apps {
|
||||
const AppId_t app_id,
|
||||
const AppId_t dlc_id,
|
||||
const std::function<bool()>& original_function
|
||||
) {
|
||||
) noexcept {
|
||||
try {
|
||||
const auto unlocked = config::is_dlc_unlocked(
|
||||
app_id,
|
||||
@@ -103,7 +103,7 @@ namespace smoke_api::steam_apps {
|
||||
|
||||
return unlocked;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("Uncaught exception: {}", e.what());
|
||||
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ namespace smoke_api::steam_apps {
|
||||
const std::string& function_name,
|
||||
const AppId_t app_id,
|
||||
const std::function<int()>& original_function
|
||||
) {
|
||||
) noexcept {
|
||||
try {
|
||||
const auto total_count = [&](int count) {
|
||||
LOG_INFO("{} -> Responding with DLC count: {}", function_name, count);
|
||||
@@ -139,7 +139,7 @@ namespace smoke_api::steam_apps {
|
||||
|
||||
return total_count(static_cast<int>(app_dlcs[app_id].size()));
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("Uncaught exception: {}", function_name, e.what());
|
||||
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -153,8 +153,8 @@ namespace smoke_api::steam_apps {
|
||||
char* pchName,
|
||||
const int cchNameBufferSize,
|
||||
const std::function<bool()>& original_function,
|
||||
const std::function<bool(AppId_t)>& is_originally_unlocked
|
||||
) {
|
||||
const std::function<bool()>& is_originally_unlocked
|
||||
) noexcept {
|
||||
try {
|
||||
LOG_DEBUG("{} -> {}index: {:>3}", function_name, get_app_id_log(app_id), iDLC);
|
||||
|
||||
@@ -174,13 +174,7 @@ namespace smoke_api::steam_apps {
|
||||
const auto output_dlc = [&](const DLC& dlc) {
|
||||
// Fill the output pointers
|
||||
*pDlcId = dlc.get_id();
|
||||
*pbAvailable = config::is_dlc_unlocked(
|
||||
app_id,
|
||||
*pDlcId,
|
||||
[&] {
|
||||
return is_originally_unlocked(*pDlcId);
|
||||
}
|
||||
);
|
||||
*pbAvailable = config::is_dlc_unlocked(app_id, *pDlcId, is_originally_unlocked);
|
||||
|
||||
auto name = dlc.get_name();
|
||||
name = name.substr(0, cchNameBufferSize + 1);
|
||||
|
||||
@@ -2,19 +2,21 @@
|
||||
|
||||
#include "smoke_api/types.hpp"
|
||||
|
||||
// TODO: Make them all noexcept
|
||||
|
||||
namespace smoke_api::steam_apps {
|
||||
bool IsDlcUnlocked(
|
||||
const std::string& function_name,
|
||||
AppId_t app_id,
|
||||
AppId_t dlc_id,
|
||||
const std::function<bool()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
int GetDLCCount(
|
||||
const std::string& function_name,
|
||||
AppId_t app_id,
|
||||
const std::function<int()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
bool GetDLCDataByIndex(
|
||||
const std::string& function_name,
|
||||
@@ -25,6 +27,6 @@ namespace smoke_api::steam_apps {
|
||||
char* pchName,
|
||||
int cchNameBufferSize,
|
||||
const std::function<bool()>& original_function,
|
||||
const std::function<bool(AppId_t)>& is_originally_unlocked
|
||||
);
|
||||
const std::function<bool()>& is_originally_unlocked
|
||||
) noexcept;
|
||||
}
|
||||
|
||||
115
static/smoke_api/interfaces/steam_http.cpp
Normal file
115
static/smoke_api/interfaces/steam_http.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
#include <koalabox/logger.hpp>
|
||||
|
||||
#include "smoke_api/interfaces/steam_http.hpp"
|
||||
#include "smoke_api/config.hpp"
|
||||
|
||||
namespace smoke_api::steam_http {
|
||||
bool GetHTTPResponseBodyData(
|
||||
const std::string& function_name,
|
||||
const HTTPRequestHandle hRequest,
|
||||
const uint8_t* pBodyDataBuffer,
|
||||
const uint32_t unBufferSize,
|
||||
const std::function<bool()>& original_function
|
||||
) noexcept {
|
||||
try {
|
||||
const auto result = original_function();
|
||||
|
||||
if(config::instance.log_steam_http) {
|
||||
const std::string_view buffer =
|
||||
pBodyDataBuffer && unBufferSize
|
||||
? std::string_view(
|
||||
reinterpret_cast<const char*>(pBodyDataBuffer),
|
||||
unBufferSize
|
||||
)
|
||||
: "";
|
||||
|
||||
LOG_INFO(
|
||||
"{} -> handle: {}, size: {}, buffer:\n{}",
|
||||
function_name,
|
||||
hRequest,
|
||||
unBufferSize,
|
||||
buffer
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", __func__, e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool GetHTTPStreamingResponseBodyData(
|
||||
const std::string& function_name,
|
||||
const HTTPRequestHandle hRequest,
|
||||
const uint32_t cOffset,
|
||||
const uint8_t* pBodyDataBuffer,
|
||||
const uint32_t unBufferSize,
|
||||
const std::function<bool()>& original_function
|
||||
) noexcept {
|
||||
try {
|
||||
const auto result = original_function();
|
||||
|
||||
if(config::instance.log_steam_http) {
|
||||
const std::string_view buffer =
|
||||
pBodyDataBuffer && unBufferSize
|
||||
? std::string_view(
|
||||
reinterpret_cast<const char*>(pBodyDataBuffer),
|
||||
unBufferSize
|
||||
)
|
||||
: "";
|
||||
|
||||
LOG_INFO(
|
||||
"{} -> handle: {}, offset: {}, size: {}, buffer:\n{}",
|
||||
function_name,
|
||||
hRequest,
|
||||
cOffset,
|
||||
unBufferSize,
|
||||
buffer
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", __func__, e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SetHTTPRequestRawPostBody(
|
||||
const std::string& function_name,
|
||||
const HTTPRequestHandle hRequest,
|
||||
const char* pchContentType,
|
||||
const uint8_t* pubBody,
|
||||
const uint32_t unBodyLen,
|
||||
const std::function<bool()>& original_function
|
||||
) noexcept {
|
||||
try {
|
||||
const auto result = original_function();
|
||||
|
||||
if(config::instance.log_steam_http) {
|
||||
const std::string_view content_type =
|
||||
pchContentType ? pchContentType : "smoke_api::N/A";
|
||||
|
||||
const std::string_view buffer =
|
||||
pubBody && unBodyLen
|
||||
? std::string_view(reinterpret_cast<const char*>(pubBody), unBodyLen)
|
||||
: "";
|
||||
|
||||
LOG_INFO(
|
||||
"{} -> handle: {}, content-type: {}, size: {}, buffer:\n{}",
|
||||
function_name,
|
||||
hRequest,
|
||||
content_type,
|
||||
unBodyLen,
|
||||
buffer
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", __func__, e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
static/smoke_api/interfaces/steam_http.hpp
Normal file
31
static/smoke_api/interfaces/steam_http.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "smoke_api/types.hpp"
|
||||
|
||||
namespace smoke_api::steam_http {
|
||||
bool GetHTTPResponseBodyData(
|
||||
const std::string& function_name,
|
||||
HTTPRequestHandle hRequest,
|
||||
const uint8_t* pBodyDataBuffer,
|
||||
uint32_t unBufferSize,
|
||||
const std::function<bool()>& original_function
|
||||
) noexcept;
|
||||
|
||||
bool GetHTTPStreamingResponseBodyData(
|
||||
const std::string& function_name,
|
||||
HTTPRequestHandle hRequest,
|
||||
uint32_t cOffset,
|
||||
const uint8_t* pBodyDataBuffer,
|
||||
uint32_t unBufferSize,
|
||||
const std::function<bool()>& original_function
|
||||
) noexcept;
|
||||
|
||||
bool SetHTTPRequestRawPostBody(
|
||||
const std::string& function_name,
|
||||
HTTPRequestHandle hRequest,
|
||||
const char* pchContentType,
|
||||
const uint8_t* pubBody,
|
||||
uint32_t unBodyLen,
|
||||
const std::function<bool()>& original_function
|
||||
) noexcept;
|
||||
}
|
||||
@@ -8,17 +8,22 @@ namespace smoke_api::steam_inventory {
|
||||
const std::string& function_name,
|
||||
const SteamInventoryResult_t resultHandle,
|
||||
const std::function<EResult()>& original_function
|
||||
) {
|
||||
const auto status = original_function();
|
||||
) noexcept {
|
||||
try {
|
||||
const auto status = original_function();
|
||||
|
||||
LOG_DEBUG(
|
||||
"{} -> handle: {}, status: {}",
|
||||
function_name,
|
||||
resultHandle,
|
||||
static_cast<int>(status)
|
||||
);
|
||||
LOG_DEBUG(
|
||||
"{} -> handle: {}, status: {}",
|
||||
function_name,
|
||||
resultHandle,
|
||||
static_cast<int>(status)
|
||||
);
|
||||
|
||||
return status;
|
||||
return status;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return EResult::k_EResultFail;
|
||||
}
|
||||
}
|
||||
|
||||
bool GetResultItems(
|
||||
@@ -28,107 +33,112 @@ namespace smoke_api::steam_inventory {
|
||||
uint32_t* punOutItemsArraySize,
|
||||
const std::function<bool()>& original_function,
|
||||
const std::function<bool(SteamItemDef_t*, uint32_t*)>& get_item_definition_ids
|
||||
) {
|
||||
static std::mutex section;
|
||||
const std::lock_guard guard(section);
|
||||
) noexcept {
|
||||
try {
|
||||
static std::mutex section;
|
||||
const std::lock_guard guard(section);
|
||||
|
||||
const auto success = original_function();
|
||||
const auto success = original_function();
|
||||
|
||||
auto print_item = [](const std::string& tag, const SteamItemDetails_t& item) {
|
||||
LOG_DEBUG(
|
||||
" [{}] definitionId: {}, itemId: {}, quantity: {}, flags: {}",
|
||||
tag,
|
||||
item.m_iDefinition,
|
||||
item.m_itemId,
|
||||
item.m_unQuantity,
|
||||
item.m_unFlags
|
||||
);
|
||||
};
|
||||
|
||||
if(not success) {
|
||||
LOG_DEBUG("{} -> original result is false", function_name);
|
||||
return success;
|
||||
}
|
||||
|
||||
if(punOutItemsArraySize == nullptr) {
|
||||
LOG_ERROR("{} -> arraySize pointer is null", function_name);
|
||||
return success;
|
||||
}
|
||||
|
||||
LOG_DEBUG(
|
||||
"{} -> handle: {}, pOutItemsArray: {}, arraySize: {}",
|
||||
function_name,
|
||||
resultHandle,
|
||||
reinterpret_cast<void*>(pOutItemsArray),
|
||||
*punOutItemsArraySize
|
||||
);
|
||||
|
||||
static uint32_t original_count = 0;
|
||||
const auto injected_count = config::instance.extra_inventory_items.size();
|
||||
|
||||
// Automatically get inventory items from steam
|
||||
static std::vector<SteamItemDef_t> auto_inventory_items;
|
||||
if(config::instance.auto_inject_inventory) {
|
||||
static std::once_flag inventory_inject_flag;
|
||||
std::call_once(
|
||||
inventory_inject_flag,
|
||||
[&] {
|
||||
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();
|
||||
|
||||
if(not pOutItemsArray) {
|
||||
// If pOutItemsArray is NULL then we must set the array size.
|
||||
original_count = *punOutItemsArraySize;
|
||||
*punOutItemsArraySize += auto_injected_count + injected_count;
|
||||
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++) {
|
||||
print_item("original", pOutItemsArray[i]);
|
||||
}
|
||||
|
||||
static auto new_item = [](SteamItemDef_t id) {
|
||||
return SteamItemDetails_t{
|
||||
.m_itemId = id,
|
||||
.m_iDefinition = id,
|
||||
.m_unQuantity = 1,
|
||||
.m_unFlags = 0,
|
||||
};
|
||||
auto print_item = [](const std::string& tag, const SteamItemDetails_t& item) {
|
||||
LOG_DEBUG(
|
||||
" [{}] definitionId: {}, itemId: {}, quantity: {}, flags: {}",
|
||||
tag,
|
||||
item.m_iDefinition,
|
||||
item.m_itemId,
|
||||
item.m_unQuantity,
|
||||
item.m_unFlags
|
||||
);
|
||||
};
|
||||
|
||||
for(int i = 0; i < auto_injected_count; i++) {
|
||||
auto& item = pOutItemsArray[original_count + i];
|
||||
const auto item_def_id = auto_inventory_items[i];
|
||||
|
||||
item = new_item(item_def_id);
|
||||
|
||||
print_item("auto-injected", item);
|
||||
if(not success) {
|
||||
LOG_DEBUG("{} -> original result is false", function_name);
|
||||
return success;
|
||||
}
|
||||
|
||||
for(int i = 0; i < injected_count; i++) {
|
||||
auto& item = pOutItemsArray[original_count + auto_injected_count + i];
|
||||
const auto item_def_id = config::instance.extra_inventory_items[i];
|
||||
|
||||
item = new_item(item_def_id);
|
||||
|
||||
print_item("injected", item);
|
||||
if(punOutItemsArraySize == nullptr) {
|
||||
LOG_ERROR("{} -> arraySize pointer is null", function_name);
|
||||
return success;
|
||||
}
|
||||
|
||||
LOG_DEBUG(
|
||||
"{} -> handle: {}, pOutItemsArray: {}, arraySize: {}",
|
||||
function_name,
|
||||
resultHandle,
|
||||
reinterpret_cast<void*>(pOutItemsArray),
|
||||
*punOutItemsArraySize
|
||||
);
|
||||
|
||||
static uint32_t original_count = 0;
|
||||
const auto injected_count = config::instance.extra_inventory_items.size();
|
||||
|
||||
// Automatically get inventory items from steam
|
||||
static std::vector<SteamItemDef_t> auto_inventory_items;
|
||||
if(config::instance.auto_inject_inventory) {
|
||||
static std::once_flag inventory_inject_flag;
|
||||
std::call_once(
|
||||
inventory_inject_flag,
|
||||
[&] {
|
||||
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();
|
||||
|
||||
if(not pOutItemsArray) {
|
||||
// If pOutItemsArray is NULL then we must set the array size.
|
||||
original_count = *punOutItemsArraySize;
|
||||
*punOutItemsArraySize += auto_injected_count + injected_count;
|
||||
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++) {
|
||||
print_item("original", pOutItemsArray[i]);
|
||||
}
|
||||
|
||||
static auto new_item = [](SteamItemDef_t id) {
|
||||
return SteamItemDetails_t{
|
||||
.m_itemId = id,
|
||||
.m_iDefinition = id,
|
||||
.m_unQuantity = 1,
|
||||
.m_unFlags = 0,
|
||||
};
|
||||
};
|
||||
|
||||
for(int i = 0; i < auto_injected_count; i++) {
|
||||
auto& item = pOutItemsArray[original_count + i];
|
||||
const auto item_def_id = auto_inventory_items[i];
|
||||
|
||||
item = new_item(item_def_id);
|
||||
|
||||
print_item("auto-injected", item);
|
||||
}
|
||||
|
||||
for(int i = 0; i < injected_count; i++) {
|
||||
auto& item = pOutItemsArray[original_count + auto_injected_count + i];
|
||||
const auto item_def_id = config::instance.extra_inventory_items[i];
|
||||
|
||||
item = new_item(item_def_id);
|
||||
|
||||
print_item("injected", item);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool GetResultItemProperty(
|
||||
@@ -139,47 +149,61 @@ namespace smoke_api::steam_inventory {
|
||||
const char* pchValueBuffer,
|
||||
const uint32_t* punValueBufferSizeOut,
|
||||
const std::function<bool()>& original_function
|
||||
) {
|
||||
LOG_DEBUG(
|
||||
"{} -> Handle: {}, Index: {}, Name: '{}'",
|
||||
function_name,
|
||||
resultHandle,
|
||||
unItemIndex,
|
||||
// can be empty, in which case steam responds with property list in csv format
|
||||
pchPropertyName ? pchPropertyName : "nullptr"
|
||||
);
|
||||
) noexcept {
|
||||
try {
|
||||
LOG_DEBUG(
|
||||
"{} -> Handle: {}, Index: {}, Name: '{}'",
|
||||
function_name,
|
||||
resultHandle,
|
||||
unItemIndex,
|
||||
// can be empty, in which case steam responds with property list in csv format
|
||||
pchPropertyName ? pchPropertyName : "nullptr"
|
||||
);
|
||||
|
||||
const auto success = original_function();
|
||||
const auto success = original_function();
|
||||
|
||||
if(!success) {
|
||||
LOG_WARN("{} -> Result is false", function_name);
|
||||
if(!success) {
|
||||
LOG_WARN("{} -> Result is false", function_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(
|
||||
pchValueBuffer && *pchValueBuffer &&
|
||||
punValueBufferSizeOut && *punValueBufferSizeOut > 0
|
||||
) {
|
||||
LOG_DEBUG(
|
||||
R"({} -> Buffer: "{}")",
|
||||
function_name,
|
||||
std::string(pchValueBuffer, *punValueBufferSizeOut - 1)
|
||||
);
|
||||
}
|
||||
|
||||
return success;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(
|
||||
pchValueBuffer && *pchValueBuffer &&
|
||||
punValueBufferSizeOut && *punValueBufferSizeOut > 0
|
||||
) {
|
||||
LOG_DEBUG(
|
||||
R"({} -> Buffer: "{}")",
|
||||
function_name,
|
||||
std::string(pchValueBuffer, *punValueBufferSizeOut - 1)
|
||||
);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool GetAllItems(
|
||||
const std::string& function_name,
|
||||
const SteamInventoryResult_t* pResultHandle,
|
||||
const std::function<bool()>& original_function
|
||||
) {
|
||||
const auto success = original_function();
|
||||
) noexcept {
|
||||
try {
|
||||
const auto success = original_function();
|
||||
|
||||
LOG_DEBUG("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle));
|
||||
LOG_DEBUG(
|
||||
"{} -> Handle: {}",
|
||||
function_name,
|
||||
reinterpret_cast<const void*>(pResultHandle)
|
||||
);
|
||||
|
||||
return success;
|
||||
return success;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool GetItemsByID(
|
||||
@@ -188,18 +212,23 @@ namespace smoke_api::steam_inventory {
|
||||
const SteamItemInstanceID_t* pInstanceIDs,
|
||||
const uint32_t unCountInstanceIDs,
|
||||
const std::function<bool()>& original_function
|
||||
) {
|
||||
const auto success = original_function();
|
||||
) noexcept {
|
||||
try {
|
||||
const auto success = original_function();
|
||||
|
||||
LOG_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++) {
|
||||
LOG_DEBUG(" Index: {}, ItemId: {}", i, pInstanceIDs[i]);
|
||||
if(success && pInstanceIDs != nullptr) {
|
||||
for(int i = 0; i < unCountInstanceIDs; i++) {
|
||||
LOG_DEBUG(" Index: {}, ItemId: {}", i, pInstanceIDs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
return success;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SerializeResult(
|
||||
@@ -208,22 +237,27 @@ namespace smoke_api::steam_inventory {
|
||||
void* pOutBuffer,
|
||||
uint32_t* punOutBufferSize,
|
||||
const std::function<bool()>& original_function
|
||||
) {
|
||||
const auto success = original_function();
|
||||
) noexcept {
|
||||
try {
|
||||
const auto success = original_function();
|
||||
|
||||
if(pOutBuffer != nullptr) {
|
||||
std::string buffer(static_cast<char*>(pOutBuffer), *punOutBufferSize);
|
||||
LOG_DEBUG("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
|
||||
} else {
|
||||
LOG_DEBUG(
|
||||
"{} -> Handle: {}, Size: '{}'",
|
||||
function_name,
|
||||
resultHandle,
|
||||
*punOutBufferSize
|
||||
);
|
||||
if(pOutBuffer != nullptr) {
|
||||
std::string buffer(static_cast<char*>(pOutBuffer), *punOutBufferSize);
|
||||
LOG_DEBUG("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
|
||||
} else {
|
||||
LOG_DEBUG(
|
||||
"{} -> Handle: {}, Size: '{}'",
|
||||
function_name,
|
||||
resultHandle,
|
||||
*punOutBufferSize
|
||||
);
|
||||
}
|
||||
|
||||
return success;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool GetItemDefinitionIDs(
|
||||
@@ -231,28 +265,33 @@ namespace smoke_api::steam_inventory {
|
||||
const SteamItemDef_t* pItemDefIDs,
|
||||
uint32_t* punItemDefIDsArraySize,
|
||||
const std::function<bool()>& original_function
|
||||
) {
|
||||
const auto success = original_function();
|
||||
) noexcept {
|
||||
try {
|
||||
const auto success = original_function();
|
||||
|
||||
if(!success) {
|
||||
LOG_WARN("{} -> Result is false", function_name);
|
||||
if(!success) {
|
||||
LOG_WARN("{} -> Result is false", function_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(punItemDefIDsArraySize) {
|
||||
LOG_DEBUG("{} -> Size: {}", function_name, *punItemDefIDsArraySize);
|
||||
} else {
|
||||
return success;
|
||||
}
|
||||
|
||||
if(pItemDefIDs) { // Definitions were copied
|
||||
for(int i = 0; i < *punItemDefIDsArraySize; i++) {
|
||||
const auto& def = pItemDefIDs[i];
|
||||
LOG_DEBUG(" Index: {}, ID: {}", i, def);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(punItemDefIDsArraySize) {
|
||||
LOG_DEBUG("{} -> Size: {}", function_name, *punItemDefIDsArraySize);
|
||||
} else {
|
||||
return success;
|
||||
}
|
||||
|
||||
if(pItemDefIDs) { // Definitions were copied
|
||||
for(int i = 0; i < *punItemDefIDsArraySize; i++) {
|
||||
const auto& def = pItemDefIDs[i];
|
||||
LOG_DEBUG(" Index: {}, ID: {}", i, def);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CheckResultSteamID(
|
||||
@@ -260,17 +299,22 @@ namespace smoke_api::steam_inventory {
|
||||
SteamInventoryResult_t resultHandle,
|
||||
CSteamID steamIDExpected,
|
||||
const std::function<bool()>& original_function
|
||||
) {
|
||||
const auto result = original_function();
|
||||
) noexcept {
|
||||
try {
|
||||
const auto result = original_function();
|
||||
|
||||
LOG_DEBUG(
|
||||
"{} -> handle: {}, steamID: {}, original result: {}",
|
||||
function_name,
|
||||
resultHandle,
|
||||
steamIDExpected,
|
||||
result
|
||||
);
|
||||
LOG_DEBUG(
|
||||
"{} -> handle: {}, steamID: {}, original result: {}",
|
||||
function_name,
|
||||
resultHandle,
|
||||
steamIDExpected,
|
||||
result
|
||||
);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace smoke_api::steam_inventory {
|
||||
const std::string& function_name,
|
||||
SteamInventoryResult_t resultHandle,
|
||||
const std::function<EResult()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
bool GetResultItems(
|
||||
const std::string& function_name,
|
||||
@@ -16,7 +16,7 @@ namespace smoke_api::steam_inventory {
|
||||
uint32_t* punOutItemsArraySize,
|
||||
const std::function<bool()>& original_function,
|
||||
const std::function<bool(SteamItemDef_t*, uint32_t*)>& get_item_definition_ids
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
bool GetResultItemProperty(
|
||||
const std::string& function_name,
|
||||
@@ -26,13 +26,13 @@ namespace smoke_api::steam_inventory {
|
||||
const char* pchValueBuffer,
|
||||
const uint32_t* punValueBufferSizeOut,
|
||||
const std::function<bool()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
bool GetAllItems(
|
||||
const std::string& function_name,
|
||||
const SteamInventoryResult_t* pResultHandle,
|
||||
const std::function<bool()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
bool GetItemsByID(
|
||||
const std::string& function_name,
|
||||
@@ -40,7 +40,7 @@ namespace smoke_api::steam_inventory {
|
||||
const SteamItemInstanceID_t* pInstanceIDs,
|
||||
uint32_t unCountInstanceIDs,
|
||||
const std::function<bool()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
bool SerializeResult(
|
||||
const std::string& function_name,
|
||||
@@ -48,19 +48,19 @@ namespace smoke_api::steam_inventory {
|
||||
void* pOutBuffer,
|
||||
uint32_t* punOutBufferSize,
|
||||
const std::function<bool()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
bool GetItemDefinitionIDs(
|
||||
const std::string& function_name,
|
||||
const SteamItemDef_t* pItemDefIDs,
|
||||
uint32_t* punItemDefIDsArraySize,
|
||||
const std::function<bool()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
|
||||
bool CheckResultSteamID(
|
||||
const std::string& function_name,
|
||||
SteamInventoryResult_t resultHandle,
|
||||
CSteamID steamIDExpected,
|
||||
const std::function<bool()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
}
|
||||
|
||||
@@ -9,26 +9,31 @@ namespace smoke_api::steam_user {
|
||||
const AppId_t appId,
|
||||
const AppId_t dlcId,
|
||||
const std::function<EUserHasLicenseForAppResult()>& original_function
|
||||
) {
|
||||
const auto result = original_function();
|
||||
) noexcept {
|
||||
try {
|
||||
const auto result = original_function();
|
||||
|
||||
if(result == k_EUserHasLicenseResultNoAuth) {
|
||||
LOG_WARN("{} -> App ID: {:>8}, Result: NoAuth", function_name, dlcId);
|
||||
return result;
|
||||
}
|
||||
|
||||
const auto has_license = config::is_dlc_unlocked(
|
||||
appId,
|
||||
dlcId,
|
||||
[&] {
|
||||
return result == k_EUserHasLicenseResultHasLicense;
|
||||
if(result == k_EUserHasLicenseResultNoAuth) {
|
||||
LOG_WARN("{} -> App ID: {:>8}, Result: NoAuth", function_name, dlcId);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
|
||||
LOG_INFO("{} -> App ID: {:>8}, HasLicense: {}", function_name, dlcId, has_license);
|
||||
const auto has_license = config::is_dlc_unlocked(
|
||||
appId,
|
||||
dlcId,
|
||||
[&] {
|
||||
return result == k_EUserHasLicenseResultHasLicense;
|
||||
}
|
||||
);
|
||||
|
||||
return has_license
|
||||
? k_EUserHasLicenseResultHasLicense
|
||||
: k_EUserHasLicenseResultDoesNotHaveLicense;
|
||||
LOG_INFO("{} -> App ID: {:>8}, HasLicense: {}", function_name, dlcId, has_license);
|
||||
|
||||
return has_license
|
||||
? k_EUserHasLicenseResultHasLicense
|
||||
: k_EUserHasLicenseResultDoesNotHaveLicense;
|
||||
} catch(const std::exception& e) {
|
||||
LOG_ERROR("{} -> Error: {}", function_name, e.what());
|
||||
return k_EUserHasLicenseResultDoesNotHaveLicense;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,5 @@ namespace smoke_api::steam_user {
|
||||
AppId_t appId,
|
||||
AppId_t dlcId,
|
||||
const std::function<EUserHasLicenseForAppResult()>& original_function
|
||||
);
|
||||
) noexcept;
|
||||
}
|
||||
|
||||
@@ -14,11 +14,15 @@
|
||||
// These macros are meant to be used for callbacks that should return original result
|
||||
|
||||
#define HOOKED_CALL(FUNC, ...) \
|
||||
static const auto _##FUNC = KB_HOOK_GET_HOOKED_FN(FUNC); \
|
||||
return _##FUNC(__VA_ARGS__)
|
||||
static const auto _##FUNC = KB_HOOK_GET_HOOKED_FN(FUNC); \
|
||||
return _##FUNC(__VA_ARGS__)
|
||||
|
||||
#define HOOKED_CALL_CLOSURE(FUNC, ...) \
|
||||
[&] { HOOKED_CALL(FUNC, __VA_ARGS__); }
|
||||
[&] { HOOKED_CALL(FUNC, __VA_ARGS__); }
|
||||
|
||||
#define HOOKED_CALL_RESULT(FUNC, ...) \
|
||||
static const auto _##FUNC = KB_HOOK_GET_HOOKED_FN(FUNC); \
|
||||
const auto result = _##FUNC(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* By default, virtual functions are declared with __thiscall
|
||||
@@ -55,12 +59,19 @@ return _##FUNC(__VA_ARGS__)
|
||||
|
||||
using AppId_t = uint32_t;
|
||||
using HSteamPipe = uint32_t;
|
||||
using EResult = uint32_t;
|
||||
using HSteamUser = uint32_t;
|
||||
using SteamInventoryResult_t = uint32_t;
|
||||
using SteamItemInstanceID_t = uint64_t;
|
||||
using SteamItemDef_t = uint32_t;
|
||||
using CSteamID = uint64_t;
|
||||
using HTTPRequestHandle = uint32_t;
|
||||
|
||||
enum class EResult {
|
||||
k_EResultNone = 0,
|
||||
k_EResultOK = 1,
|
||||
k_EResultFail = 2,
|
||||
// See all at steamclientpublic.h
|
||||
};
|
||||
|
||||
struct SteamItemDetails_t {
|
||||
SteamItemInstanceID_t m_itemId;
|
||||
@@ -71,10 +82,12 @@ struct SteamItemDetails_t {
|
||||
|
||||
// results from UserHasLicenseForApp
|
||||
enum EUserHasLicenseForAppResult {
|
||||
k_EUserHasLicenseResultHasLicense = 0, // User has a license for specified app
|
||||
k_EUserHasLicenseResultDoesNotHaveLicense = 1,
|
||||
// User has a license for specified app
|
||||
k_EUserHasLicenseResultHasLicense = 0,
|
||||
// User does not have a license for the specified app
|
||||
k_EUserHasLicenseResultNoAuth = 2, // User has not been authenticated
|
||||
k_EUserHasLicenseResultDoesNotHaveLicense = 1,
|
||||
// User has not been authenticated
|
||||
k_EUserHasLicenseResultNoAuth = 2,
|
||||
};
|
||||
|
||||
// These aliases exist solely to increase code readability
|
||||
@@ -87,7 +100,7 @@ using DlcNameMap = std::map<DlcIdKey, DlcNameValue>;
|
||||
struct App {
|
||||
DlcNameMap dlcs;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(App, dlcs) // NOLINT(misc-const-correctness)
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(App, dlcs)
|
||||
};
|
||||
|
||||
using AppDlcNameMap = std::map<AppIdKey, App>;
|
||||
@@ -98,6 +111,8 @@ class DLC {
|
||||
std::string name;
|
||||
|
||||
public:
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(DLC, appid, name)
|
||||
|
||||
explicit DLC() = default;
|
||||
|
||||
explicit DLC(std::string appid, std::string name) : appid{std::move(appid)},
|
||||
@@ -115,8 +130,6 @@ public:
|
||||
return name;
|
||||
}
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(DLC, appid, name)
|
||||
|
||||
static std::vector<DLC> get_dlcs_from_apps(const AppDlcNameMap& apps, AppId_t app_id);
|
||||
|
||||
static DlcNameMap get_dlc_map_from_vector(const std::vector<DLC>& dlcs);
|
||||
|
||||
Reference in New Issue
Block a user