Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# SteamAPIBridge

Read README.md for runtime ownership and ABI boundaries. Build with the x86 Debug
and Release scripts and run CTest. Keep public exports C-compatible and prefixed
SteamBridge_. Do not link steam_api.lib, initialize or shut down the host Steam
session, or expose vendor C++ objects in the public ABI. External SDK trees are
read-only. Preserve historical interface slots and verify callback layouts against
the referenced Valve headers when extending compatibility. Record simulated and
Read README.md for runtime ownership and ABI boundaries. Build with the Windows
x86/x64 and Linux scripts and run CTest on each platform you change. Keep public exports
C-compatible and prefixed SteamBridge_. Do not link steam_api.lib or expose vendor C++
objects in the public ABI. Only host mode (SteamBridge_Host*/Server*) initializes or
shuts down Steam, and only when the host requests it; plugin-mode code never touches
the game's Steam session. External SDK trees are read-only.
Preserve historical interface slots and verify callback layouts against the
referenced Valve headers when extending compatibility. Record simulated and
real-game verification separately. Tests exercise behavior and binary loading,
not documentation or configuration text.

Expand Down
58 changes: 45 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,62 @@ endif()
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
project(SteamAPIBridge VERSION 1.0.0 LANGUAGES CXX)
if(NOT WIN32 OR NOT MSVC OR NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
message(FATAL_ERROR "SteamAPIBridge requires Windows MSVC x86 (-A Win32).")
if(WIN32 AND NOT MSVC)
message(FATAL_ERROR "SteamAPIBridge requires MSVC on Windows.")
elseif(NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(FATAL_ERROR "SteamAPIBridge supports Windows and Linux.")
endif()
get_property(steambridge_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(steambridge_multi_config)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Supported configurations" FORCE)
elseif(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release)$")
message(FATAL_ERROR "Select Debug or Release.")
# A parent project keeps its own configurations.
if(PROJECT_IS_TOP_LEVEL)
get_property(steambridge_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(steambridge_multi_config)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Supported configurations" FORCE)
elseif(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release)$")
message(FATAL_ERROR "Select Debug or Release.")
endif()
endif()
set(STEAMSDK_SOURCE_PATH "$ENV{STEAMSDK_SOURCE_PATH}" CACHE PATH "Read-only SteamSDK source")
include(cmake/Dependencies.cmake)
steambridge_prepare_dependencies()
include(cmake/SourceGroups.cmake)
add_library(SteamAPIBridge SHARED src/SteamAPIBridge.cpp)
add_library(SteamAPIBridge SHARED src/SteamAPIBridge.cpp src/Host.cpp src/Platform.h src/LegacyInterfaces.h)
steambridge_assign_source_groups(SteamAPIBridge)
add_library(SteamAPIBridge::SteamAPIBridge ALIAS SteamAPIBridge)
target_compile_features(SteamAPIBridge PRIVATE cxx_std_20)
target_compile_definitions(SteamAPIBridge PRIVATE STEAMAPIBRIDGE_EXPORTS WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS)
target_include_directories(SteamAPIBridge PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" PRIVATE "${STEAMSDK_SOURCE_PATH}")
target_compile_options(SteamAPIBridge PRIVATE /W4 /permissive- /Zi)
target_link_options(SteamAPIBridge PRIVATE /DEBUG)
set_target_properties(SteamAPIBridge PROPERTIES DEBUG_POSTFIX "")
install(TARGETS SteamAPIBridge RUNTIME DESTINATION svencoop/metahook/dlls)
install(FILES "$<TARGET_PDB_FILE:SteamAPIBridge>" DESTINATION svencoop/metahook/dlls)
if(MSVC)
target_compile_definitions(SteamAPIBridge PRIVATE STEAMAPIBRIDGE_EXPORTS WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS)
target_compile_options(SteamAPIBridge PRIVATE /W4 /permissive- /Zi)
target_link_options(SteamAPIBridge PRIVATE /DEBUG)
else()
target_compile_definitions(SteamAPIBridge PRIVATE STEAMAPIBRIDGE_EXPORTS)
target_compile_options(SteamAPIBridge PRIVATE -Wall -Wextra)
target_link_libraries(SteamAPIBridge PRIVATE ${CMAKE_DL_LIBS})
# Only the SteamBridge_ C ABI is exported; the version script also hides libstdc++ template instances.
set_target_properties(SteamAPIBridge PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/SteamAPIBridge.map")
target_link_options(SteamAPIBridge PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/SteamAPIBridge.map")
endif()
# The steam_api runtime that host mode loads from the bridge's directory.
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(steambridge_runtime "${STEAMSDK_SOURCE_PATH}/bin/steam_api64.dll")
elseif(WIN32)
set(steambridge_runtime "${STEAMSDK_SOURCE_PATH}/bin/steam_api.dll")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(steambridge_runtime "${STEAMSDK_SOURCE_PATH}/bin/linux64/libsteam_api.so")
else()
set(steambridge_runtime "${STEAMSDK_SOURCE_PATH}/bin/linux32/libsteam_api.so")
endif()
set(STEAMAPIBRIDGE_RUNTIME "${steambridge_runtime}" CACHE INTERNAL "steam_api runtime for the target architecture")
set(STEAMAPIBRIDGE_INSTALL_DIR "svencoop/metahook/dlls" CACHE STRING "Install directory of the bridge, relative to the install prefix")
option(STEAMAPIBRIDGE_INSTALL_RUNTIME "Install the steam_api runtime beside the bridge for host mode" OFF)
install(TARGETS SteamAPIBridge RUNTIME DESTINATION "${STEAMAPIBRIDGE_INSTALL_DIR}" LIBRARY DESTINATION "${STEAMAPIBRIDGE_INSTALL_DIR}")
if(MSVC)
install(FILES "$<TARGET_PDB_FILE:SteamAPIBridge>" DESTINATION "${STEAMAPIBRIDGE_INSTALL_DIR}")
endif()
if(STEAMAPIBRIDGE_INSTALL_RUNTIME)
install(FILES "${STEAMAPIBRIDGE_RUNTIME}" DESTINATION "${STEAMAPIBRIDGE_INSTALL_DIR}")
endif()
option(STEAMAPIBRIDGE_BUILD_TESTS "Build bridge regression tests" ${PROJECT_IS_TOP_LEVEL})
if(STEAMAPIBRIDGE_BUILD_TESTS)
enable_testing()
Expand Down
118 changes: 93 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
# SteamAPIBridge

Windows MSVC x86 compatibility DLL for MetaHookSv SteamAPI consumers. Plugins link
`SteamAPIBridge.lib`; the game supplies and initializes its own `steam_api.dll`.
The bridge neither imports SteamAPI functions nor replaces the game's runtime.
C ABI bridge to the Steamworks API for Windows (MSVC x86/x64) and Linux (x86/x64).
It has two modes:

* **Plugin mode** (MetaHookSv consumers): plugins link `SteamAPIBridge.lib`; the game
supplies and initializes its own `steam_api.dll`. The bridge only uses the runtime
that is already loaded and never initializes or shuts Steam down.
* **Host mode** (a game engine without its own Steam session): the host asks the bridge
to load the runtime and own SteamAPI/SteamGameServer initialization, callback pumping
and shutdown, through the `SteamBridge_Host*`, `SteamBridge_User*`,
`SteamBridge_Voice*` and `SteamBridge_Server*` functions.

In both modes the bridge resolves the runtime dynamically and does not link
`steam_api.lib`.

## Runtime contract

The C interface is `include/SteamAPIBridge.h`. It exposes SteamID, screenshot and
HTTP operations, status codes, opaque consumer contexts and function callbacks.
No Steam interface pointer, STL object or allocation ownership crosses the DLL ABI.
`SB_OK` is zero; failed create operations clear their output handles.
The C interface is `include/SteamAPIBridge.h`. It exposes status codes, opaque
consumer contexts, function callbacks and plain event structures. No Steam interface
pointer, STL object or allocation ownership crosses the ABI. `SB_OK` is zero; failed
create or query operations clear their outputs.

### Plugin mode

The runtime is the loaded `steam_api.dll` (Windows x86), `steam_api64.dll` (Windows
x64) or `libsteam_api.so` (Linux). Contexts expose SteamID, screenshot and HTTP
operations.

* Modern runtimes: dynamically request User023, Screenshots003 and HTTP003 using
`SteamInternal_FindOrCreateUserInterface`.
* GoldSrc 8684 runtime: use its **SteamClient012 Windows ABI** with the existing
user/pipe to request the same versions. User016 and Screenshots001 are supported
fallbacks. Private declarations record their historical Valve SDK provenance.
* GoldSrc 8684 runtime (Windows x86 only): use its **SteamClient012 Windows ABI** with
the existing user/pipe to request the same versions. User016 and Screenshots001 are
supported fallbacks. Private declarations record their historical Valve SDK provenance.
* HTTP always requires HTTP003. Older HTTP002 revisions have incompatible method
availability despite sharing a version string; the bridge does not silently
omit cookies or certificate verification settings.
Expand All @@ -27,47 +43,99 @@ bound to its first available module/user/pipe session; create a new context for
new game session. Interface objects are resolved on each operation, not cached
across sessions. An unavailable initial runtime may be retried on the same context.

The game alone runs `SteamAPI_Init`, `SteamAPI_RunCallbacks` and `SteamAPI_Shutdown`.
Callbacks execute synchronously on the host callback thread, outside bridge locks.
Event pointers are borrowed during the call. Callbacks may unsubscribe, release a
request or destroy their context; native callback objects are retired until dispatch
has returned. Do not destroy a context concurrently with calls using that context.
Application callbacks must not throw across the C ABI.
In plugin mode the game alone runs `SteamAPI_Init`, `SteamAPI_RunCallbacks` and
`SteamAPI_Shutdown`. Callbacks execute synchronously on the host callback thread,
outside bridge locks. Event pointers are borrowed during the call. Callbacks may
unsubscribe, release a request or destroy their context; native callback objects are
retired until dispatch has returned. Do not destroy a context concurrently with calls
using that context. Application callbacks must not throw across the C ABI.

Screenshot completion results retain Steam's numeric EResult values. HTTP events
distinguish headers, data and completion. Headers/data are ordinary Steam callbacks
filtered by request handle; completion is a call result dispatched at most once.
Request/response buffers belong to the caller. Read response data before releasing
the request. No successful interface lookup certifies game-engine compatibility.

### Host mode

`SteamBridge_HostInit(runtimePath, initializeClient)` loads `runtimePath`, or the
platform runtime from the bridge's own directory when it is `NULL`. Host mode requires
a modern runtime exporting `SteamAPI_InitFlat`, `SteamInternal_GameServer_Init_V2` and
the `SteamInternal_FindOrCreate*Interface` accessors; Steamworks SDK v1.65 is pinned.
A missing runtime or export returns `SB_UNAVAILABLE`, and a failed client initialization
(`SteamAPI_InitFlat`: Steam not running, application not owned) returns `SB_FAILED`;
both leave the runtime unloaded. A dedicated server passes `initializeClient = 0` and
only uses the game server functions.

* Client: game connection tickets (`InitiateGameConnection_DEPRECATED`), SteamID,
persona name, app subscription and voice (User023, Friends018, Apps009). Missing
interfaces make the corresponding calls return `SB_UNAVAILABLE`.
* Game server (`SteamBridge_ServerInit`): GameServer015 logon, server rules and
heartbeats, ticket authentication (`SendUserConnectAndAuthenticate_DEPRECATED`),
bots and shared-socket master server packets. The interface version list matches
`SteamGameServer_InitEx`.
* Events: ClientGameServerDeny, GameServerChangeRequested and GameOverlayActivated
reach the client callback during `SteamBridge_HostRunCallbacks`; SteamServersConnected,
SteamServerConnectFailure, GSPolicyResponse and GSClientApprove/Deny/Kick reach the
server callback during `SteamBridge_ServerRunCallbacks`. Fields are copied out of
Steam's payloads; IP addresses and ports pass through unchanged.

Host functions are not thread-safe; call them from the host's main thread. A callback
may call `SteamBridge_HostShutdown` or `SteamBridge_ServerShutdown`; the shutdown runs
after the native dispatcher returns. `SteamBridge_HostShutdown` shuts down an active
game server first. Plugin contexts may use the runtime that host mode loaded; destroy
them before `SteamBridge_HostShutdown`.

## Build and install

```bat
scripts\build-SteamAPIBridge-x86-Debug.bat
scripts\build-SteamAPIBridge-x86-Release.bat
scripts\build-SteamAPIBridge-x64-Debug.bat
scripts\build-SteamAPIBridge-x64-Release.bat
```

Requires CMake 3.21+, Visual Studio 2022 Win32 and C++20. Uses the static CRT.
```sh
scripts/build-SteamAPIBridge-linux.sh x64 Release
scripts/build-SteamAPIBridge-linux.sh x86 Release # needs g++-multilib
```

Requires CMake 3.21+ and C++20: Visual Studio 2022 (Win32 or x64, static CRT) on
Windows, GCC or Clang on Linux. Linux builds export only the `SteamBridge_` symbols.
`STEAMSDK_SOURCE_PATH` accepts a read-only local dependency tree; otherwise the
pinned SDK is fetched.
`STEAMAPIBRIDGE_BUILD_TESTS` defaults on for standalone builds, off as a subproject.
As a subproject the bridge keeps the parent's build configurations.

CMake target: `SteamAPIBridge` (alias `SteamAPIBridge::SteamAPIBridge`). Consumers
reuse this target in the aggregate; standalone consumers build a fixed bridge
commit through `STEAMAPIBRIDGE_SOURCE_PATH` or FetchContent. Installation stages
the DLL/PDB under `svencoop/metahook/dlls`; the installer maps the selected game mod.
No `steam_api.dll` is installed. The game must make `metahook/dlls` available before
loading consumers, as the MetaHook loader already does.
the bridge (and PDB on Windows) under `STEAMAPIBRIDGE_INSTALL_DIR`, by default
`svencoop/metahook/dlls`; the installer maps the selected game mod. The game must make
that directory available before loading consumers, as the MetaHook loader already does.
`STEAMAPIBRIDGE_INSTALL_RUNTIME` (default `OFF`) also installs the SDK's `steam_api`
runtime for the target architecture beside the bridge, as host mode expects;
`STEAMAPIBRIDGE_RUNTIME` names that file for consumers that stage it themselves.

## Verification

CTest covers absent/uninitialized Steam, legacy and intermediate-modern exports,
exact-version availability and retry, SteamID/screenshots, cookie/certificate
CTest covers, on every supported platform, absent runtimes and host mode against a
fixture runtime: client initialization failure and retry, connection tickets, voice
capture/decoding and non-OK voice results, client and game server event translation
and dispatcher separation, deferred shutdown from callbacks, game server setters and
authentication, packets, and dedicated (server-only) sessions. On Windows it also
covers plugin mode: absent/uninitialized Steam, legacy (x86) and intermediate-modern
exports, exact-version availability and retry, SteamID/screenshots, cookie/certificate
forwarding, stream events, context isolation, cancellation and reentrant destruction.
Fixtures never initialize the real Steam client or make network requests.
`SteamBridgeLoadSmoke` accepts real Steam DLL and consumer DLL paths for loader-only
checks. These checks do not validate Steam authentication, screenshot submission,
real HTTP traffic, engine hooks or gameplay. Those require running each target game.

Two manual tools are built but not run by CTest. `SteamBridgeLoadSmoke` (Windows)
accepts real Steam DLL and consumer DLL paths for loader-only checks.
`SteamBridgeHostSmoke <runtime> [seconds]` needs a running, logged-in Steam client and
`steam_appid.txt` in the working directory: it initializes the client, logs a game
server on anonymously, authenticates the client's ticket and exits zero on
GSClientApprove. Neither validates screenshot submission, real HTTP traffic, engine
hooks or gameplay; those require running each target game.

The SDK notice is installed with the runtime. Historical ABI declarations derive
from Valve Steamworks headers; see their provenance in `src/LegacyInterfaces.h`.
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function(steambridge_prepare_dependencies)
include(FetchContent)
FetchContent_Declare(steambridge_sdk
GIT_REPOSITORY https://github.com/MetaHookSv/SteamSDK
GIT_TAG 3c1abaf6277f9f99fd16ef40557d6852820b848f
GIT_TAG ba2bfcc008b8aa197aba05e6122a15d6d236b80b
GIT_SUBMODULES "" SOURCE_SUBDIR _source_only)
FetchContent_MakeAvailable(steambridge_sdk)
set(STEAMSDK_SOURCE_PATH "${steambridge_sdk_SOURCE_DIR}")
Expand Down
Loading
Loading