Added init functions and hook fallback

This commit is contained in:
acidicoala
2025-08-31 03:56:27 +05:00
parent eac7e87880
commit c376b793c1
15 changed files with 168 additions and 76 deletions

View File

@@ -10,17 +10,13 @@ namespace smoke_api::config {
LOCKED,
};
NLOHMANN_JSON_SERIALIZE_ENUM(
AppStatus,
// @formatter:off
{
{ AppStatus::UNDEFINED, nullptr },
{ AppStatus::ORIGINAL, "original" },
{ AppStatus::UNLOCKED, "unlocked" },
{ AppStatus::LOCKED, "locked" },
}
// @formatter:on
)
// @formatter:off
NLOHMANN_JSON_SERIALIZE_ENUM(AppStatus, {
{ AppStatus::UNDEFINED, nullptr },
{ AppStatus::ORIGINAL, "original" },
{ AppStatus::UNLOCKED, "unlocked" },
{ AppStatus::LOCKED, "locked" },
}) // @formatter:on
struct Config {
uint32_t $version = 4;

View File

@@ -30,7 +30,7 @@ namespace {
const std::lock_guard lock(section);
if(app_id == 0) {
LOG_ERROR("'{}' -> App ID is 0", __func__);
LOG_ERROR("{} -> App ID is 0", __func__);
app_dlcs[app_id] = {}; // Dummy value to avoid checking for presence on each access
return;
}
@@ -94,7 +94,7 @@ namespace smoke_api::steam_apps {
);
LOG_INFO(
"'{}' -> {}DLC ID: {:>8}, Unlocked: {}",
"{} -> {}DLC ID: {:>8}, Unlocked: {}",
function_name,
get_app_id_log(app_id),
dlc_id,
@@ -103,7 +103,7 @@ namespace smoke_api::steam_apps {
return unlocked;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Uncaught exception: {}", function_name, e.what());
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
return false;
}
}
@@ -115,16 +115,16 @@ namespace smoke_api::steam_apps {
) noexcept {
try {
const auto total_count = [&](int count) {
LOG_INFO("'{}' -> Responding with DLC count: {}", function_name, count);
LOG_INFO("{} -> Responding with DLC count: {}", function_name, count);
return count;
};
if(app_id != 0) {
LOG_DEBUG("'{}' -> App ID: {}", function_name, app_id);
LOG_DEBUG("{} -> App ID: {}", function_name, app_id);
}
const auto original_count = original_function();
LOG_DEBUG("'{}' -> Original DLC count: {}", function_name, original_count);
LOG_DEBUG("{} -> Original DLC count: {}", function_name, original_count);
if(original_count < MAX_DLC) {
return total_count(original_count);
@@ -156,11 +156,11 @@ namespace smoke_api::steam_apps {
const std::function<bool()>& is_originally_unlocked
) noexcept {
try {
LOG_DEBUG("'{}' -> {}index: {:>3}", function_name, get_app_id_log(app_id), iDLC);
LOG_DEBUG("{} -> {}index: {:>3}", function_name, get_app_id_log(app_id), iDLC);
const auto print_dlc_info = [&](const std::string& tag) {
LOG_INFO(
R"('{}' -> [{:^12}] {}index: {:>3}, DLC ID: {:>8}, available: {:5}, name: "{}")",
R"({} -> [{:^12}] {}index: {:>3}, DLC ID: {:>8}, available: {:5}, name: "{}")",
function_name,
tag,
get_app_id_log(app_id),
@@ -190,7 +190,7 @@ namespace smoke_api::steam_apps {
return true;
}
LOG_WARN("'{}' -> Out of bounds DLC index: {}", function_name, iDLC);
LOG_WARN("{} -> Out of bounds DLC index: {}", function_name, iDLC);
return false;
}
@@ -206,12 +206,12 @@ namespace smoke_api::steam_apps {
);
print_dlc_info("original");
} else {
LOG_WARN("'{}' -> original call failed for index: {}", function_name, iDLC);
LOG_WARN("{} -> original call failed for index: {}", function_name, iDLC);
}
return success;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Uncaught exception: {}", function_name, e.what());
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
return false;
}
}

View File

@@ -2,8 +2,6 @@
#include "smoke_api/types.hpp"
// TODO: Make them all noexcept
namespace smoke_api::steam_apps {
bool IsDlcUnlocked(
const std::string& function_name,

View File

@@ -24,7 +24,7 @@ namespace smoke_api::steam_http {
: "";
LOG_INFO(
"'{}' -> handle: {}, size: {}, buffer:\n{}",
"{} -> handle: {}, size: {}, buffer:\n{}",
function_name,
hRequest,
unBufferSize,
@@ -34,7 +34,7 @@ namespace smoke_api::steam_http {
return result;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", __func__, e.what());
LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false;
}
}
@@ -60,7 +60,7 @@ namespace smoke_api::steam_http {
: "";
LOG_INFO(
"'{}' -> handle: {}, offset: {}, size: {}, buffer:\n{}",
"{} -> handle: {}, offset: {}, size: {}, buffer:\n{}",
function_name,
hRequest,
cOffset,
@@ -71,7 +71,7 @@ namespace smoke_api::steam_http {
return result;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", __func__, e.what());
LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false;
}
}
@@ -97,7 +97,7 @@ namespace smoke_api::steam_http {
: "";
LOG_INFO(
"'{}' -> handle: {}, content-type: {}, size: {}, buffer:\n{}",
"{} -> handle: {}, content-type: {}, size: {}, buffer:\n{}",
function_name,
hRequest,
content_type,
@@ -108,7 +108,7 @@ namespace smoke_api::steam_http {
return result;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", __func__, e.what());
LOG_ERROR("{} -> Error: {}", __func__, e.what());
return false;
}
}

View File

@@ -13,7 +13,7 @@ namespace smoke_api::steam_inventory {
const auto status = original_function();
LOG_DEBUG(
"'{}' -> handle: {}, status: {}",
"{} -> handle: {}, status: {}",
function_name,
resultHandle,
static_cast<int>(status)
@@ -21,7 +21,7 @@ namespace smoke_api::steam_inventory {
return status;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return EResult::k_EResultFail;
}
}
@@ -52,17 +52,17 @@ namespace smoke_api::steam_inventory {
};
if(not success) {
LOG_DEBUG("'{}' -> original result is false", function_name);
LOG_DEBUG("{} -> original result is false", function_name);
return success;
}
if(punOutItemsArraySize == nullptr) {
LOG_ERROR("'{}' -> arraySize pointer is null", function_name);
LOG_ERROR("{} -> arraySize pointer is null", function_name);
return success;
}
LOG_DEBUG(
"'{}' -> handle: {}, pOutItemsArray: {}, arraySize: {}",
"{} -> handle: {}, pOutItemsArray: {}, arraySize: {}",
function_name,
resultHandle,
reinterpret_cast<void*>(pOutItemsArray),
@@ -95,7 +95,7 @@ namespace smoke_api::steam_inventory {
original_count = *punOutItemsArraySize;
*punOutItemsArraySize += auto_injected_count + injected_count;
LOG_DEBUG(
"'{}' -> Original count: {}, Total count: {}",
"{} -> Original count: {}, Total count: {}",
function_name,
original_count,
*punOutItemsArraySize
@@ -136,7 +136,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return false;
}
}
@@ -152,7 +152,7 @@ namespace smoke_api::steam_inventory {
) noexcept {
try {
LOG_DEBUG(
"'{}' -> Handle: {}, Index: {}, Name: '{}'",
"{} -> Handle: {}, Index: {}, Name: '{}'",
function_name,
resultHandle,
unItemIndex,
@@ -163,7 +163,7 @@ namespace smoke_api::steam_inventory {
const auto success = original_function();
if(!success) {
LOG_WARN("'{}' -> Result is false", function_name);
LOG_WARN("{} -> Result is false", function_name);
return false;
}
@@ -180,7 +180,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return false;
}
}
@@ -194,14 +194,14 @@ namespace smoke_api::steam_inventory {
const auto success = original_function();
LOG_DEBUG(
"'{}' -> Handle: {}",
"{} -> Handle: {}",
function_name,
reinterpret_cast<const void*>(pResultHandle)
);
return success;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return false;
}
}
@@ -216,7 +216,7 @@ namespace smoke_api::steam_inventory {
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++) {
@@ -226,7 +226,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return false;
}
}
@@ -243,10 +243,10 @@ namespace smoke_api::steam_inventory {
if(pOutBuffer != nullptr) {
std::string buffer(static_cast<char*>(pOutBuffer), *punOutBufferSize);
LOG_DEBUG("'{}' -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
LOG_DEBUG("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
} else {
LOG_DEBUG(
"'{}' -> Handle: {}, Size: '{}'",
"{} -> Handle: {}, Size: '{}'",
function_name,
resultHandle,
*punOutBufferSize
@@ -255,7 +255,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return false;
}
}
@@ -270,12 +270,12 @@ namespace smoke_api::steam_inventory {
const auto success = original_function();
if(!success) {
LOG_WARN("'{}' -> Result is false", function_name);
LOG_WARN("{} -> Result is false", function_name);
return false;
}
if(punItemDefIDsArraySize) {
LOG_DEBUG("'{}' -> Size: {}", function_name, *punItemDefIDsArraySize);
LOG_DEBUG("{} -> Size: {}", function_name, *punItemDefIDsArraySize);
} else {
return success;
}
@@ -289,7 +289,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return false;
}
}
@@ -304,7 +304,7 @@ namespace smoke_api::steam_inventory {
const auto result = original_function();
LOG_DEBUG(
"'{}' -> handle: {}, steamID: {}, original result: {}",
"{} -> handle: {}, steamID: {}, original result: {}",
function_name,
resultHandle,
steamIDExpected,
@@ -313,7 +313,7 @@ namespace smoke_api::steam_inventory {
return true;
} catch(const std::exception& e) {
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return false;
}
}

View File

@@ -14,7 +14,7 @@ namespace smoke_api::steam_user {
const auto result = original_function();
if(result == k_EUserHasLicenseResultNoAuth) {
LOG_WARN("'{}' -> App ID: {:>8}, Result: NoAuth", function_name, dlcId);
LOG_WARN("{} -> App ID: {:>8}, Result: NoAuth", function_name, dlcId);
return result;
}
@@ -26,13 +26,13 @@ namespace smoke_api::steam_user {
}
);
LOG_INFO("'{}' -> App ID: {:>8}, HasLicense: {}", function_name, dlcId, has_license);
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());
LOG_ERROR("{} -> Error: {}", function_name, e.what());
return k_EUserHasLicenseResultDoesNotHaveLicense;
}
}

View File

@@ -44,11 +44,11 @@
* The macros below implement the above-mentioned considerations.
*/
#ifdef _WIN64
#define PARAMS(...) const void *RCX, __VA_ARGS__
#define PARAMS(...) const void* RCX, __VA_ARGS__
#define ARGS(...) RCX, __VA_ARGS__
#define THIS RCX
#else
#define PARAMS(...) const void *ECX, const void *EDX, __VA_ARGS__
#define PARAMS(...) const void* ECX, const void* EDX, __VA_ARGS__
#define ARGS(...) ECX, EDX, __VA_ARGS__
#define THIS ECX
#endif