Implemented ISteamGameServer

This commit is contained in:
acidicoala
2025-08-26 05:07:17 +05:00
parent 902476cb3e
commit 9f84425e4e
59 changed files with 151 additions and 123 deletions

View File

@@ -37,19 +37,6 @@
namespace {
namespace kb = koalabox;
namespace fs = std::filesystem;
void override_app_id() {
const auto override_app_id = smoke_api::config::instance.override_app_id;
if(override_app_id == 0) {
return;
}
spdlog::default_logger_raw();
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");
@@ -61,27 +48,14 @@ namespace {
void init_hook_mode() {
LOG_INFO("Detected hook mode");
kb::hook::init(true);
const std::vector<std::string> target_libraries{STEAMCLIENT_DLL, STEAMAPI_DLL};
kb::dll_monitor::init_listener(
target_libraries,
{STEAMCLIENT_DLL, STEAMAPI_DLL},
[&](const HMODULE& module_handle, const std::string& library_name) {
static auto hook_count = 0U;
if(kb::str::eq(library_name, STEAMCLIENT_DLL)) {
KB_HOOK_DETOUR_MODULE(CreateInterface, module_handle);
hook_count++;
} else if(kb::str::eq(library_name, STEAMAPI_DLL)) {
KB_HOOK_DETOUR_MODULE(SteamAPI_RestartAppIfNecessary, module_handle);
KB_HOOK_DETOUR_MODULE(SteamAPI_Shutdown, module_handle);
hook_count++;
}
if(hook_count == target_libraries.size()) {
kb::dll_monitor::shutdown_listener();
}
}
);
@@ -111,7 +85,8 @@ namespace smoke_api {
LOG_DEBUG("Process name: '{}' [{}-bit]", exe_name, kb::util::BITNESS);
override_app_id();
// We need to hook functions in either mode
kb::hook::init(true);
if(kb::hook::is_hook_mode(module_handle, STEAMAPI_DLL)) {
hook_mode = true;

View File

@@ -6,6 +6,7 @@ constexpr auto STEAM_APPS = "STEAMAPPS_INTERFACE_VERSION";
constexpr auto STEAM_CLIENT = "SteamClient";
constexpr auto STEAM_USER = "SteamUser";
constexpr auto STEAM_INVENTORY = "STEAMINVENTORY_INTERFACE_V";
constexpr auto STEAM_GAME_SERVER = "SteamGameServer";
// IMPORTANT: DLL_EXPORT is hardcoded in exports_generator.cpp,
// so any name changes here must be reflected there as well.

View File

@@ -5,10 +5,9 @@
#include "smoke_api/config.hpp"
DLL_EXPORT(bool) SteamAPI_RestartAppIfNecessary(const AppId_t unOwnAppID) {
if(smoke_api::config::instance.override_app_id != 0) {
LOG_DEBUG("{} -> {}. Preventing app restart", unOwnAppID, __func__);
return false;
}
LOG_INFO("{} -> unOwnAppID: {}", __func__, unOwnAppID);
// Restart can be suppressed if needed
AUTO_CALL(SteamAPI_RestartAppIfNecessary, unOwnAppID);
}

View File

@@ -9,7 +9,7 @@
// ISteamApps
DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsSubscribedApp(void* self, AppId_t dlcID) {
DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsSubscribedApp(void* self, const AppId_t dlcID) {
try {
return smoke_api::steam_apps::IsDlcUnlocked(
__func__,
@@ -23,7 +23,7 @@ DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsSubscribedApp(void* self, AppId_t dlcID)
}
}
DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsDlcInstalled(void* self, AppId_t dlcID) {
DLL_EXPORT(bool) SteamAPI_ISteamApps_BIsDlcInstalled(void* self, const AppId_t dlcID) {
try {
return smoke_api::steam_apps::IsDlcUnlocked(
__func__,
@@ -294,3 +294,28 @@ DLL_EXPORT(EUserHasLicenseForAppResult) SteamAPI_ISteamUser_UserHasLicenseForApp
return k_EUserHasLicenseResultDoesNotHaveLicense;
}
}
// ISteamGameServer
DLL_EXPORT(EUserHasLicenseForAppResult) SteamAPI_ISteamGameServer_UserHasLicenseForApp(
void* self,
const CSteamID steamID,
const AppId_t dlcID
) {
try {
return smoke_api::steam_user::UserHasLicenseForApp(
__func__,
steam_interface::get_app_id(),
dlcID,
MODULE_CALL_CLOSURE(
SteamAPI_ISteamGameServer_UserHasLicenseForApp,
self,
steamID,
dlcID
)
);
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what());
return k_EUserHasLicenseResultDoesNotHaveLicense;
}
}

View File

@@ -2,7 +2,6 @@
#include <map>
#include <koalabox/logger.hpp>
#include <koalabox/util.hpp>
#include <koalabox/win.hpp>
#include "smoke_api.hpp"
@@ -34,7 +33,7 @@ namespace {
return version_map[version_prefix];
}
throw kb::util::exception("No match found for '{}'", version_prefix);
throw std::runtime_error(std::format("No match found for '{}'", version_prefix));
} catch(const std::exception& ex) {
LOG_ERROR(
"Failed to get versioned interface: {}."

View File

@@ -5,7 +5,6 @@
#include <koalabox/hook.hpp>
#include <koalabox/logger.hpp>
#include <koalabox/util.hpp>
#include <koalabox/win.hpp>
#include "smoke_api.hpp"
@@ -67,17 +66,11 @@ namespace {
}
},
{
STEAM_INVENTORY,
STEAM_GAME_SERVER,
interface_data{
.fallback_version = "STEAMINVENTORY_INTERFACE_V003",
.fallback_version = "SteamGameServer015",
.entry_map = {
ENTRY(ISteamInventory, GetResultStatus),
ENTRY(ISteamInventory, GetResultItems),
ENTRY(ISteamInventory, CheckResultSteamID),
ENTRY(ISteamInventory, GetAllItems),
ENTRY(ISteamInventory, GetItemsByID),
ENTRY(ISteamInventory, SerializeResult),
ENTRY(ISteamInventory, GetItemDefinitionIDs),
ENTRY(ISteamGameServer, UserHasLicenseForApp),
}
}
},

View File

@@ -1,6 +1,5 @@
#include <koalabox/logger.hpp>
#include "smoke_api.hpp"
#include "smoke_api/interfaces/steam_apps.hpp"
#include "steam_api/steam_interface.hpp"
#include "steam_api/virtuals/steam_api_virtuals.hpp"

View File

@@ -1,6 +1,5 @@
#include <koalabox/logger.hpp>
#include "smoke_api.hpp"
#include "steam_api/steam_client.hpp"
#include "steam_api/virtuals/steam_api_virtuals.hpp"

View File

@@ -0,0 +1,21 @@
#include <koalabox/logger.hpp>
#include "smoke_api/interfaces/steam_user.hpp"
#include "steam_api/steam_interface.hpp"
#include "steam_api/virtuals/steam_api_virtuals.hpp"
VIRTUAL(EUserHasLicenseForAppResult) ISteamGameServer_UserHasLicenseForApp(
PARAMS(const CSteamID steamID, const AppId_t dlc_id)
) {
try {
return smoke_api::steam_user::UserHasLicenseForApp(
__func__,
steam_interface::get_app_id(),
dlc_id,
HOOKED_CALL_CLOSURE(ISteamGameServer_UserHasLicenseForApp, ARGS(steamID, dlc_id))
);
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what());
return k_EUserHasLicenseResultDoesNotHaveLicense;
}
}

View File

@@ -1,4 +1,3 @@
#include "smoke_api.hpp"
#include "smoke_api/interfaces/steam_inventory.hpp"
#include "steam_api/virtuals/steam_api_virtuals.hpp"
@@ -130,7 +129,7 @@ VIRTUAL(bool) ISteamInventory_GetItemDefinitionIDs(
}
VIRTUAL(bool) ISteamInventory_CheckResultSteamID(
PARAMS(SteamInventoryResult_t resultHandle, CSteamID steamIDExpected)
PARAMS(const SteamInventoryResult_t resultHandle, CSteamID steamIDExpected)
) {
return smoke_api::steam_inventory::CheckResultSteamID(
__func__,

View File

@@ -1,6 +1,5 @@
#include <koalabox/logger.hpp>
#include "smoke_api.hpp"
#include "smoke_api/interfaces/steam_user.hpp"
#include "steam_api/steam_interface.hpp"
#include "steam_api/virtuals/steam_api_virtuals.hpp"

View File

@@ -33,3 +33,8 @@ VIRTUAL(bool) ISteamInventory_CheckResultSteamID(PARAMS(SteamInventoryResult_t,
// ISteamUser
VIRTUAL(EUserHasLicenseForAppResult) ISteamUser_UserHasLicenseForApp(PARAMS(CSteamID, AppId_t));
// ISteamGameServer
VIRTUAL(EUserHasLicenseForAppResult) ISteamGameServer_UserHasLicenseForApp(
PARAMS(CSteamID, AppId_t)
);