Added steamworks sdk v1.62,

This commit is contained in:
acidicoala
2025-08-13 22:38:48 +05:00
parent 4b337a981e
commit 81dd00195c
19 changed files with 3624 additions and 624 deletions

View File

@@ -44,12 +44,16 @@
#define DLL_EXPORT(TYPE) extern "C" [[maybe_unused]] __declspec( dllexport ) TYPE __cdecl
#define VIRTUAL(TYPE) __declspec(noinline) TYPE __fastcall
// TODO: Replace with direct call
#define GET_ORIGINAL_HOOKED_FUNCTION(FUNC) \
static const auto FUNC##_o = koalabox::hook::get_original_hooked_function(#FUNC, FUNC);
#define GET_ORIGINAL_FUNCTION_STEAMAPI(FUNC) \
static const auto FUNC##_o = koalabox::hook::get_original_function(globals::steamapi_module, #FUNC, FUNC);
#define ORIGINAL_FUNCTION_STEAMAPI(FUNC) \
koalabox::hook::get_original_function(globals::steamapi_module, #FUNC, FUNC)
// TODO: Rename to DEFINE_ORIGINAL_FUNCTION_STEAMAPI
#define GET_ORIGINAL_FUNCTION_STEAMAPI(FUNC) \
static const auto FUNC##_o = ORIGINAL_FUNCTION_STEAMAPI(FUNC);
#define DETOUR_ADDRESS(FUNC, ADDRESS) \
koalabox::hook::detour_or_warn(ADDRESS, #FUNC, reinterpret_cast<uintptr_t>(FUNC));
@@ -90,9 +94,10 @@ struct SteamItemDetails_t {
// results from UserHasLicenseForApp
enum EUserHasLicenseForAppResult {
k_EUserHasLicenseResultHasLicense = 0, // User has a license for specified app
k_EUserHasLicenseResultDoesNotHaveLicense = 1, // User does not have a license for the specified app
k_EUserHasLicenseResultNoAuth = 2, // User has not been authenticated
k_EUserHasLicenseResultHasLicense = 0, // User has a license for specified app
k_EUserHasLicenseResultDoesNotHaveLicense = 1,
// User does not have a license for the specified app
k_EUserHasLicenseResultNoAuth = 2, // User has not been authenticated
};
// These aliases exist solely to increase code readability
@@ -115,10 +120,12 @@ private:
// These 2 names must match the property names from Steam API
String appid;
String name;
public:
explicit DLC() = default;
explicit DLC(String appid, String name) : appid{std::move(appid)}, name{std::move(name)} {}
explicit DLC(String appid, String name) : appid{std::move(appid)}, name{std::move(name)} {
}
[[nodiscard]] String get_id_str() const {
return appid;
@@ -134,7 +141,7 @@ public:
NLOHMANN_DEFINE_TYPE_INTRUSIVE(DLC, appid, name)
static Vector<DLC> get_dlcs_from_apps(const AppDlcNameMap& apps, AppId_t app_id);
static Vector<DLC> get_dlcs_from_apps(const AppDlcNameMap &apps, AppId_t app_id);
static DlcNameMap get_dlc_map_from_vector(const Vector<DLC>& vector);
};
static DlcNameMap get_dlc_map_from_vector(const Vector<DLC> &vector);
};

View File

@@ -0,0 +1,19 @@
#include <smoke_api/config.hpp>
// TODO: Detour in hook mode
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(
[[maybe_unused]] const uint32_t unOwnAppID
) {
if (smoke_api::config::instance.override_app_id != 0) {
LOG_DEBUG("{} -> Preventing app restart", __func__)
return false;
}
return ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_RestartAppIfNecessary)(unOwnAppID);
}
DLL_EXPORT(void) SteamAPI_Shutdown() {
LOG_INFO("{} -> Game requested shutdown", __func__)
ORIGINAL_FUNCTION_STEAMAPI(SteamAPI_Shutdown)();
}

View File

@@ -23,6 +23,7 @@ namespace smoke_api::config {
bool logging = false;
bool unlock_family_sharing = true;
AppStatus default_app_status = AppStatus::UNLOCKED;
uint32_t override_app_id = 0;
Map<String, AppStatus> override_app_status;
Map<String, AppStatus> override_dlc_status;
AppDlcNameMap extra_dlcs;
@@ -37,6 +38,7 @@ namespace smoke_api::config {
logging,
unlock_family_sharing,
default_app_status,
override_app_id,
override_app_status,
override_dlc_status,
extra_dlcs,

View File

@@ -34,17 +34,39 @@
// Given that hooking steam_api has no apparent benefits, but has inherent flaws,
// the support for it has been dropped from this project.
void override_app_id() {
const auto override_app_id = smoke_api::config::instance.override_app_id;
if (override_app_id == 0)
return;
LOG_DEBUG("Overriding app id to {}", override_app_id);
SetEnvironmentVariable(
TEXT("SteamAppId"),
std::to_wstring(override_app_id).c_str()
);
}
void init_proxy_mode() {
LOG_INFO("🔀 Detected proxy mode")
globals::steamapi_module = koalabox::loader::load_original_library(paths::get_self_path(), STEAMAPI_DLL);
override_app_id();
globals::steamapi_module = koalabox::loader::load_original_library(
paths::get_self_path(),
STEAMAPI_DLL
);
}
void init_hook_mode() {
LOG_INFO("🪝 Detected hook mode")
override_app_id();
koalabox::dll_monitor::init_listener(
STEAMCLIENT_DLL, [](const HMODULE& library) {
STEAMCLIENT_DLL,
[](const HMODULE &library) {
globals::steamclient_module = library;
DETOUR_STEAMCLIENT(CreateInterface)
@@ -54,7 +76,7 @@ void init_hook_mode() {
);
}
bool is_valve_steam(const String& exe_name) noexcept {
bool is_valve_steam(const String &exe_name) noexcept {
try {
if (exe_name < not_equals > "steam.exe") {
return false;
@@ -63,11 +85,12 @@ bool is_valve_steam(const String& exe_name) noexcept {
// Verify that it's steam from valve, and not some other executable coincidentally named steam
const HMODULE steam_handle = koalabox::win_util::get_module_handle_or_throw(nullptr);
const auto manifest = koalabox::win_util::get_module_manifest(steam_handle);
const auto manifest = koalabox::win_util::get_module_manifest(
steam_handle);
// Steam.exe manifest is expected to contain this string
return manifest < contains > "valvesoftware.steam.steam";
} catch (const Exception& e) {
} catch (const Exception &e) {
LOG_ERROR("{} -> {}", __func__, e.what())
return false;
@@ -75,8 +98,8 @@ bool is_valve_steam(const String& exe_name) noexcept {
}
namespace smoke_api {
void init(HMODULE module_handle) {
void init(const HMODULE module_handle) {
// FIXME: IMPORTANT! Non ascii paths in directories will result in init errors
try {
DisableThreadLibraryCalls(module_handle);
@@ -87,19 +110,28 @@ namespace smoke_api {
config::init_config();
if (config::instance.logging) {
koalabox::logger::init_file_logger(paths::get_log_path());
koalabox::logger::init_file_logger();
}
// This kind of timestamp is reliable only for CI builds, as it will reflect the compilation
// time stamp only when this file gets recompiled.
LOG_INFO("🐨 {} v{} | Compiled at '{}'", PROJECT_NAME, PROJECT_VERSION, __TIMESTAMP__)
LOG_INFO(
"🐨 {} v{} | Compiled at '{}'", PROJECT_NAME,
PROJECT_VERSION,
__TIMESTAMP__
)
const auto exe_path = Path(koalabox::win_util::get_module_file_name_or_throw(nullptr));
const Path exe_path = koalabox::win_util::get_module_file_name_or_throw(nullptr);
const auto exe_name = exe_path.filename().string();
LOG_DEBUG("Process name: '{}' [{}-bit]", exe_name, BITNESS)
if (koalabox::hook::is_hook_mode(globals::smokeapi_handle, STEAMAPI_DLL)) {
const bool is_hook_mode = koalabox::hook::is_hook_mode(
globals::smokeapi_handle,
STEAMAPI_DLL
);
if (is_hook_mode) {
koalabox::hook::init(true);
if (is_valve_steam(exe_name)) {
@@ -115,8 +147,10 @@ namespace smoke_api {
}
LOG_INFO("🚀 Initialization complete")
} catch (const Exception& ex) {
koalabox::util::panic(fmt::format("Initialization error: {}", ex.what()));
} catch (const Exception &ex) {
koalabox::util::panic(
fmt::format("Initialization error: {}", ex.what())
);
}
}
@@ -127,9 +161,8 @@ namespace smoke_api {
}
LOG_INFO("💀 Shutdown complete")
} catch (const Exception& ex) {
} catch (const Exception &ex) {
LOG_ERROR("Shutdown error: {}", ex.what())
}
}
}
}

View File

@@ -16,56 +16,58 @@ namespace steam_impl {
typedef Map<String, Map<int, int>> FunctionOrdinalMap;
FunctionOrdinalMap steam_client_ordinal_map = { // NOLINT(cert-err58-cpp)
{"ISteamClient_GetISteamApps",
{
{6, 16},
{7, 18},
{8, 15},
{9, 16},
{12, 15},
}
},
FunctionOrdinalMap steam_client_ordinal_map = { // NOLINT(cert-err58-cpp)
{"ISteamClient_GetISteamUser",
{
{6, 6},
{7, 5},
}
{
{6, 6},
{7, 5},
}
},
{"ISteamClient_GetISteamUtils",
{
{6, 12},
{7, 9},
}
{
{6, 12},
{7, 9},
}
},
{"ISteamClient_GetISteamGenericInterface",
{
{7, 14},
{8, 13},
{12, 12},
}
{
{7, 14},
{8, 13},
{12, 12},
}
},
{"ISteamClient_GetISteamApps",
{
{6, 16},
{7, 18},
{8, 15},
{9, 16},
{12, 15},
}
},
{"ISteamClient_GetISteamInventory",
{
{17, 34},
{18, 35},
}
{
{17, 34},
{18, 35},
{21, 33},
}
}
};
FunctionOrdinalMap steam_apps_ordinal_map = { // NOLINT(cert-err58-cpp)
{"ISteamApps_BIsSubscribedApp", {{2, 6}}},
{"ISteamApps_BIsDlcInstalled", {{2, 7}}},
{"ISteamApps_GetDLCCount", {{2, 10}}},
{"ISteamApps_BIsSubscribedApp", {{2, 6}}},
{"ISteamApps_BIsDlcInstalled", {{2, 7}}},
{"ISteamApps_GetDLCCount", {{2, 10}}},
{"ISteamApps_BGetDLCDataByIndex", {{2, 11}}},
};
FunctionOrdinalMap steam_user_ordinal_map = { // NOLINT(cert-err58-cpp)
{"ISteamUser_UserHasLicenseForApp", {
{12, 15},
{13, 16},
{15, 17},
}}
{12, 15},
{13, 16},
{15, 17},
{23, 18},
}}
};
FunctionOrdinalMap steam_utils_ordinal_map = { // NOLINT(cert-err58-cpp)
@@ -73,21 +75,21 @@ namespace steam_impl {
};
FunctionOrdinalMap steam_inventory_ordinal_map = { // NOLINT(cert-err58-cpp)
{"ISteamInventory_GetResultStatus", {{1, 0}}},
{"ISteamInventory_GetResultItems", {{1, 1}}},
{"ISteamInventory_GetResultStatus", {{1, 0}}},
{"ISteamInventory_GetResultItems", {{1, 1}}},
{"ISteamInventory_GetResultItemProperty", {{2, 2}}},
{"ISteamInventory_CheckResultSteamID", {{1, 3}, {2, 4}}},
{"ISteamInventory_GetAllItems", {{1, 5}, {2, 6}}},
{"ISteamInventory_GetItemsByID", {{1, 6}, {2, 7}}},
{"ISteamInventory_SerializeResult", {{1, 7}, {2, 8}}},
{"ISteamInventory_GetItemDefinitionIDs", {{1, 20}, {2, 21}}},
{"ISteamInventory_CheckResultSteamID", {{1, 3}, {2, 4}}},
{"ISteamInventory_GetAllItems", {{1, 5}, {2, 6}}},
{"ISteamInventory_GetItemsByID", {{1, 6}, {2, 7}}},
{"ISteamInventory_SerializeResult", {{1, 7}, {2, 8}}},
{"ISteamInventory_GetItemDefinitionIDs", {{1, 20}, {2, 21}}},
};
int extract_version_number(
const String& version_string,
const String& prefix,
int min_version,
int max_version
const int min_version,
const int max_version
) {
LOG_DEBUG("Hooking interface '{}'", version_string)
@@ -106,21 +108,31 @@ namespace steam_impl {
}
return version_number;
} catch (const std::exception& ex) {
koalabox::util::panic("Failed to extract version number from: '{}'", version_string);
} catch ([[maybe_unused]] const std::exception& ex) {
koalabox::util::panic(
"Failed to extract version number from: '{}'. Reason: {}",
version_string, ex.what()
);
}
}
int get_ordinal(const FunctionOrdinalMap& ordinal_map, const String& function_name, int interface_version) {
int get_ordinal(
const FunctionOrdinalMap& ordinal_map,
const String& function_name,
int interface_version
) {
const auto& map = ordinal_map.at(function_name);
for (auto [version, ordinal]: std::ranges::reverse_view(map)) {
for (auto [version, ordinal] : std::ranges::reverse_view(map)) {
if (interface_version >= version) {
return ordinal;
}
}
koalabox::util::panic("Invalid interface version ({}) for function {}", interface_version, function_name);
koalabox::util::panic(
"Invalid interface version ({}) for function {}",
interface_version, function_name
);
}
#define HOOK_VIRTUALS(MAP, FUNC) \
@@ -152,7 +164,7 @@ namespace steam_impl {
const MutexLockGuard guard(section);
if (version_string.starts_with(STEAM_CLIENT)) {
const auto version_number = extract_version_number(version_string, STEAM_CLIENT, 6, 20);
const auto version_number = extract_version_number(version_string, STEAM_CLIENT, 6, 21);
HOOK_STEAM_CLIENT(ISteamClient_GetISteamApps)
HOOK_STEAM_CLIENT(ISteamClient_GetISteamUser)
@@ -176,13 +188,15 @@ namespace steam_impl {
HOOK_STEAM_APPS(ISteamApps_BGetDLCDataByIndex)
}
} else if (version_string.starts_with(STEAM_USER)) {
const auto version_number = extract_version_number(version_string, STEAM_USER, 9, 21);
const auto version_number = extract_version_number(version_string, STEAM_USER, 9, 23);
if (version_number >= 12) {
HOOK_STEAM_USER(ISteamUser_UserHasLicenseForApp)
}
} else if (version_string.starts_with(STEAM_INVENTORY)) {
const auto version_number = extract_version_number(version_string, STEAM_INVENTORY, 1, 3);
const auto version_number = extract_version_number(
version_string, STEAM_INVENTORY, 1, 3
);
HOOK_STEAM_INVENTORY(ISteamInventory_GetResultStatus)
HOOK_STEAM_INVENTORY(ISteamInventory_GetResultItems)
@@ -195,7 +209,10 @@ namespace steam_impl {
if (version_number >= 2) {
HOOK_STEAM_INVENTORY(ISteamInventory_GetResultItemProperty)
}
} else if (version_string.starts_with(CLIENT_ENGINE) && !hooked_interfaces.contains(interface)) {
} else if (
version_string.starts_with(CLIENT_ENGINE) &&
!hooked_interfaces.contains(interface)
) {
#if COMPILE_STORE_MODE
store::steamclient::process_client_engine(reinterpret_cast<uintptr_t>(interface));
#endif
@@ -210,26 +227,26 @@ namespace steam_impl {
const auto& steam_api_module = koalabox::win_util::get_module_handle_or_throw(STEAMAPI_DLL);
void* GetHSteamPipe_address;
try {
GetHSteamPipe_address = (void*) koalabox::win_util::get_proc_address_or_throw(
GetHSteamPipe_address = (void*)koalabox::win_util::get_proc_address_or_throw(
steam_api_module, "SteamAPI_GetHSteamPipe"
);
} catch (const Exception& ex) {
GetHSteamPipe_address = (void*) koalabox::win_util::get_proc_address_or_throw(
GetHSteamPipe_address = (void*)koalabox::win_util::get_proc_address_or_throw(
steam_api_module, "GetHSteamPipe"
);
}
typedef HSteamPipe (__cdecl* GetHSteamPipe_t)();
const auto GetHSteamPipe_o = (GetHSteamPipe_t) GetHSteamPipe_address;
typedef HSteamPipe (__cdecl*GetHSteamPipe_t)();
const auto GetHSteamPipe_o = (GetHSteamPipe_t)GetHSteamPipe_address;
return GetHSteamPipe_o();
}
template<typename F>
template <typename F>
F get_virtual_function(void* interface, int ordinal) {
auto* v_table = (void***) interface;
return (F) (*v_table)[ordinal];
auto* v_table = (void***)interface;
return (F)(*v_table)[ordinal];
}
template<typename F, typename... Args>
template <typename F, typename... Args>
auto call_virtual_function(void* interface, F function, Args... args) {
#ifdef _WIN64
void* RCX = interface;
@@ -243,8 +260,9 @@ namespace steam_impl {
AppId_t get_app_id_or_throw() {
// Get CreateInterface
const auto& steam_client_module = koalabox::win_util::get_module_handle_or_throw(STEAMCLIENT_DLL);
auto* CreateInterface_address = (void*) koalabox::win_util::get_proc_address_or_throw(
const auto& steam_client_module =
koalabox::win_util::get_module_handle_or_throw(STEAMCLIENT_DLL);
auto* CreateInterface_address = (void*)koalabox::win_util::get_proc_address_or_throw(
steam_client_module, "CreateInterface"
);
auto* CreateInterface_o = PLH::FnCast(CreateInterface_address, CreateInterface);
@@ -253,23 +271,31 @@ namespace steam_impl {
int result;
auto* i_steam_client = CreateInterface_o("SteamClient006", &result);
if (i_steam_client == nullptr) {
throw koalabox::util::exception("Failed to obtain SteamClient006 interface. Result: {}", result);
throw koalabox::util::exception(
"Failed to obtain SteamClient006 interface. Result: {}",
result
);
}
// Get GetISteamUtils
typedef void*** (__fastcall* GetISteamUtils_t)(PARAMS(HSteamPipe hSteamPipe, const char* version));
typedef void*** (__fastcall*GetISteamUtils_t)(
PARAMS(HSteamPipe hSteamPipe, const char* version)
);
const auto steam_utils_ordinal = steam_client_ordinal_map["ISteamClient_GetISteamUtils"][6];
const auto GetISteamUtils_o = get_virtual_function<GetISteamUtils_t>(i_steam_client, steam_utils_ordinal);
const auto GetISteamUtils_o = get_virtual_function<GetISteamUtils_t>(
i_steam_client, steam_utils_ordinal);
// Get ISteamUtils
const auto steam_pipe = get_steam_pipe_or_throw();
auto* i_steam_utils = call_virtual_function(i_steam_client, GetISteamUtils_o, steam_pipe, "SteamUtils002");
auto* i_steam_utils = call_virtual_function(
i_steam_client, GetISteamUtils_o, steam_pipe, "SteamUtils002"
);
// Get GetAppID
typedef uint32_t (__fastcall* GetAppID_t)(PARAMS());
typedef uint32_t (__fastcall*GetAppID_t)(PARAMS());
const auto get_app_id_ordinal = steam_utils_ordinal_map["ISteamUtils_GetAppID"][2];
const auto GetAppID_o = get_virtual_function<GetAppID_t>(i_steam_utils, get_app_id_ordinal);
return call_virtual_function(i_steam_utils, GetAppID_o);
}
}
}