Skip to content

Commit 51709b5

Browse files
committed
[WIP] Linux support
1 parent 69e7af6 commit 51709b5

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ include(KoalaBox/cmake/KoalaBox.cmake)
77
add_subdirectory(KoalaBox)
88
add_subdirectory(tools)
99

10-
configure_build_config(extra_build_config)
11-
1210
set(SMOKE_API_STATIC_SOURCES
1311
static/smoke_api/interfaces/steam_apps.hpp
1412
static/smoke_api/interfaces/steam_apps.cpp
@@ -61,6 +59,8 @@ else()
6159
endif()
6260
set_32_and_64(SMOKE_API_FILENAME smoke_api32 smoke_api64)
6361

62+
configure_build_config(extra_build_config)
63+
6464
### SmokeAPI interface
6565

6666
add_library(SmokeAPI_common INTERFACE)
@@ -109,13 +109,13 @@ if(WIN32)
109109
DLL_FILES_GLOB "C:/Windows/System32/version.dll"
110110
)
111111
else()
112-
configure_linker_exports(
113-
TARGET SmokeAPI
114-
HEADER_NAME "libsteam_api_exports.cpp"
115-
FORWARDED_DLL "${STEAM_API_MODULE}_o.so"
116-
DLL_FILES_GLOB "${CMAKE_CURRENT_SOURCE_DIR}/res/steamworks/*/binaries/${LINUX_DIR}/${STEAM_API_MODULE}.so"
117-
INPUT_SOURCES_DIR ""
118-
)
112+
# configure_linker_exports(
113+
# TARGET SmokeAPI
114+
# HEADER_NAME "libsteam_api_exports.cpp"
115+
# FORWARDED_DLL "${STEAM_API_MODULE}_o.so"
116+
# DLL_FILES_GLOB "${CMAKE_CURRENT_SOURCE_DIR}/res/steamworks/*/binaries/${LINUX_DIR}/${STEAM_API_MODULE}.so"
117+
# INPUT_SOURCES_DIR ""
118+
# )
119119
endif()
120120

121121
## https://github.com/batterycenter/embed

res/extra_build_config.gen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#pragma once
22

3-
#define STEAMAPI_DLL "${STEAMAPI_DLL}"
3+
#define STEAM_API_MODULE "${STEAM_API_MODULE}"
44
#define STEAMCLIENT_DLL "${STEAMCLIENT_DLL}"

src/main_linux.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
#include "smoke_api/smoke_api.hpp"
44

5-
extern "C" void __attribute__((constructor)) on_loaded() {
5+
extern "C" void __attribute__((constructor)) init() {
66
// On linux we don't automatically get current module handle,
7-
// hence we get it manually
7+
// hence we find it manually
88
Dl_info info;
9-
if(dladdr(reinterpret_cast<void*>(&on_loaded), &info) && info.dli_fname) {
9+
if(dladdr(reinterpret_cast<void*>(&init), &info) && info.dli_fname) {
1010
void* handle = dlopen(info.dli_fname, RTLD_NOW | RTLD_NOLOAD);
1111
smoke_api::init(handle);
1212
} else {
@@ -15,6 +15,6 @@ extern "C" void __attribute__((constructor)) on_loaded() {
1515
}
1616
}
1717

18-
extern "C" void __attribute__((destructor)) on_unloaded() {
18+
extern "C" void __attribute__((destructor)) fini() {
1919
smoke_api::shutdown();
2020
}

src/smoke_api/smoke_api.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ namespace {
6464
bool on_steamclient_loaded(const HMODULE steamclient_handle) {
6565
auto* const steamapi_handle = original_steamapi_handle
6666
? original_steamapi_handle
67-
: kb::module::get_library_handle(TEXT(STEAMAPI_DLL));
67+
: kb::module::get_library_handle(TEXT(STEAM_API_MODULE));
6868
if(!steamapi_handle) {
69-
LOG_ERROR("{} -> {} is not loaded", __func__, STEAMAPI_DLL);
69+
LOG_ERROR("{} -> {} is not loaded", __func__, STEAM_API_MODULE);
7070
return true;
7171
}
7272

@@ -75,7 +75,7 @@ namespace {
7575
const auto steamclient_versions = find_steamclient_versions(steamapi_handle);
7676
for(const auto& steamclient_version : steamclient_versions) {
7777
if(CreateInterface$(steamclient_version.c_str(), nullptr)) {
78-
// TODO: This is not true when running under Proton.
78+
// TODO: This is not true when running under Proton or native Linux.
7979
// Even before initialization, an interface will be returned,
8080
// but GetISteamGenericInterface will still fail.
8181
LOG_WARN("'{}' was already initialized. SmokeAPI might not work as expected.", steamclient_version);
@@ -119,20 +119,20 @@ namespace smoke_api {
119119
// We need to hook functions in either mode
120120
kb::hook::init(true);
121121

122-
if(kb::hook::is_hook_mode(module_handle, STEAMAPI_DLL)) {
122+
if(kb::hook::is_hook_mode(module_handle, STEAM_API_MODULE)) {
123123
LOG_INFO("Detected hook mode");
124124

125125
start_dll_listener();
126126
} else {
127127
LOG_INFO("Detected proxy mode");
128128

129+
start_dll_listener();
130+
129131
const auto self_path = kb::paths::get_self_dir();
130132
original_steamapi_handle = kb::loader::load_original_library(
131133
self_path,
132-
STEAMAPI_DLL
134+
STEAM_API_MODULE
133135
);
134-
135-
start_dll_listener();
136136
}
137137

138138
LOG_INFO("Initialization complete");

src/steam_api/steam_interfaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ namespace steam_interfaces {
206206
// Remove steam client map since we don't want to hook its methods
207207
virtual_hook_map.erase(STEAM_CLIENT);
208208

209-
// Map remaining virtual hook map to a set of keys
209+
// Map virtual hook map to a set of keys
210210
const auto prefixes = std::views::keys(virtual_hook_map) | std::ranges::to<std::set>();
211211

212-
// Prepare HSteamPipe and HSteamUser
212+
213213
const auto CreateInterface$ = KB_MOD_GET_FUNC(steamclient_handle, CreateInterface);
214214
const auto* const THIS = CreateInterface$(steam_client_interface_version.c_str(), nullptr);
215215
hook_virtuals(THIS, steam_client_interface_version);

0 commit comments

Comments
 (0)