[WIP] Linux support

This commit is contained in:
acidicoala
2025-09-14 14:52:16 +05:00
parent 69e7af6dae
commit 51709b53ad
6 changed files with 24 additions and 24 deletions

View File

@@ -7,8 +7,6 @@ include(KoalaBox/cmake/KoalaBox.cmake)
add_subdirectory(KoalaBox)
add_subdirectory(tools)
configure_build_config(extra_build_config)
set(SMOKE_API_STATIC_SOURCES
static/smoke_api/interfaces/steam_apps.hpp
static/smoke_api/interfaces/steam_apps.cpp
@@ -61,6 +59,8 @@ else()
endif()
set_32_and_64(SMOKE_API_FILENAME smoke_api32 smoke_api64)
configure_build_config(extra_build_config)
### SmokeAPI interface
add_library(SmokeAPI_common INTERFACE)
@@ -109,13 +109,13 @@ if(WIN32)
DLL_FILES_GLOB "C:/Windows/System32/version.dll"
)
else()
configure_linker_exports(
TARGET SmokeAPI
HEADER_NAME "libsteam_api_exports.cpp"
FORWARDED_DLL "${STEAM_API_MODULE}_o.so"
DLL_FILES_GLOB "${CMAKE_CURRENT_SOURCE_DIR}/res/steamworks/*/binaries/${LINUX_DIR}/${STEAM_API_MODULE}.so"
INPUT_SOURCES_DIR ""
)
# configure_linker_exports(
# TARGET SmokeAPI
# HEADER_NAME "libsteam_api_exports.cpp"
# FORWARDED_DLL "${STEAM_API_MODULE}_o.so"
# DLL_FILES_GLOB "${CMAKE_CURRENT_SOURCE_DIR}/res/steamworks/*/binaries/${LINUX_DIR}/${STEAM_API_MODULE}.so"
# INPUT_SOURCES_DIR ""
# )
endif()
## https://github.com/batterycenter/embed

View File

@@ -1,4 +1,4 @@
#pragma once
#define STEAMAPI_DLL "${STEAMAPI_DLL}"
#define STEAM_API_MODULE "${STEAM_API_MODULE}"
#define STEAMCLIENT_DLL "${STEAMCLIENT_DLL}"

View File

@@ -2,11 +2,11 @@
#include "smoke_api/smoke_api.hpp"
extern "C" void __attribute__((constructor)) on_loaded() {
extern "C" void __attribute__((constructor)) init() {
// On linux we don't automatically get current module handle,
// hence we get it manually
// hence we find it manually
Dl_info info;
if(dladdr(reinterpret_cast<void*>(&on_loaded), &info) && info.dli_fname) {
if(dladdr(reinterpret_cast<void*>(&init), &info) && info.dli_fname) {
void* handle = dlopen(info.dli_fname, RTLD_NOW | RTLD_NOLOAD);
smoke_api::init(handle);
} else {
@@ -15,6 +15,6 @@ extern "C" void __attribute__((constructor)) on_loaded() {
}
}
extern "C" void __attribute__((destructor)) on_unloaded() {
extern "C" void __attribute__((destructor)) fini() {
smoke_api::shutdown();
}

View File

@@ -64,9 +64,9 @@ namespace {
bool on_steamclient_loaded(const HMODULE steamclient_handle) {
auto* const steamapi_handle = original_steamapi_handle
? original_steamapi_handle
: kb::module::get_library_handle(TEXT(STEAMAPI_DLL));
: kb::module::get_library_handle(TEXT(STEAM_API_MODULE));
if(!steamapi_handle) {
LOG_ERROR("{} -> {} is not loaded", __func__, STEAMAPI_DLL);
LOG_ERROR("{} -> {} is not loaded", __func__, STEAM_API_MODULE);
return true;
}
@@ -75,7 +75,7 @@ namespace {
const auto steamclient_versions = find_steamclient_versions(steamapi_handle);
for(const auto& steamclient_version : steamclient_versions) {
if(CreateInterface$(steamclient_version.c_str(), nullptr)) {
// TODO: This is not true when running under Proton.
// TODO: This is not true when running under Proton or native Linux.
// Even before initialization, an interface will be returned,
// but GetISteamGenericInterface will still fail.
LOG_WARN("'{}' was already initialized. SmokeAPI might not work as expected.", steamclient_version);
@@ -119,20 +119,20 @@ namespace smoke_api {
// We need to hook functions in either mode
kb::hook::init(true);
if(kb::hook::is_hook_mode(module_handle, STEAMAPI_DLL)) {
if(kb::hook::is_hook_mode(module_handle, STEAM_API_MODULE)) {
LOG_INFO("Detected hook mode");
start_dll_listener();
} else {
LOG_INFO("Detected proxy mode");
start_dll_listener();
const auto self_path = kb::paths::get_self_dir();
original_steamapi_handle = kb::loader::load_original_library(
self_path,
STEAMAPI_DLL
STEAM_API_MODULE
);
start_dll_listener();
}
LOG_INFO("Initialization complete");

View File

@@ -206,10 +206,10 @@ namespace steam_interfaces {
// Remove steam client map since we don't want to hook its methods
virtual_hook_map.erase(STEAM_CLIENT);
// Map remaining virtual hook map to a set of keys
// Map virtual hook map to a set of keys
const auto prefixes = std::views::keys(virtual_hook_map) | std::ranges::to<std::set>();
// Prepare HSteamPipe and HSteamUser
const auto CreateInterface$ = KB_MOD_GET_FUNC(steamclient_handle, CreateInterface);
const auto* const THIS = CreateInterface$(steam_client_interface_version.c_str(), nullptr);
hook_virtuals(THIS, steam_client_interface_version);