From 9acab0626ac7ec5e0db5060fe688e4c8b700a6b1 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 21 Dec 2023 20:18:42 -0500 Subject: [PATCH] Add initial files --- .gitignore | 3 +++ CMakeLists.txt | 16 ++++++++++++++++ LICENSE | 19 +++++++++++++++++++ README.md | 18 ++++++++++++++++++ main.cpp | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 README.md create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee027e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.clang-format +/*build* +/sdk diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c20cb59 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.10) +project(steamwrap) + +set(CMAKE_CXX_STANDARD 17) + +add_library(Steamworks IMPORTED SHARED) +set_target_properties(Steamworks PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${STEAMWORKS_INCLUDE_DIR} + IMPORTED_LOCATION ${STEAMWORKS_LIBRARIES}) + +add_executable(steamwrap main.cpp) +target_link_libraries(steamwrap PRIVATE Steamworks) +set_target_properties(steamwrap + PROPERTIES + BUILD_RPATH "$ORIGIN" +) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5d05984 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2023 Joshua Goins + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0febff9 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# steamwrap + +Used for [Astra](https://git.sr.ht/~redstrate/astra) to initialize and communicate with the Steam API. + +Due to restrictions on how the Steamworks SDK is distributed, I have to build it locally. Astra downloads a binary version of steamwrap from a distribution server during Flatpak build alongside the redistributable. + +## Building + +Remember that newer glibc/++ won't work when it's inside the Steam Linux Runtime, so I recommend using distrobox to build steamwrap: + +```shell +$ distrobox create --name test --init --image debian:10 --additional-packages "systemd libpam-systemd" # Debian 10 is the base of Steam Linux Runtime 2.0 +$ distrobox enter test +$ mkdir build +$ cd build +$ cmake -DSTEAMWORKS_LIBRARIES=/redistributable_bin/linux64/libsteam_api.so -DSTEAMWORKS_INCLUDE_DIR=/public/ .. +$ make +``` diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..80fa9b5 --- /dev/null +++ b/main.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + putenv("SteamAppId=39210"); + putenv("SteamGameId=39210"); + + std::cout << "Previous LD_LIBRARY_PATH:" << getenv("LD_LIBRARY_PATH") << std::endl; + + std::string newEnv = std::string("PREVIOUS_LD_LIBRARY_PATH=") + getenv("LD_LIBRARY_PATH"); + + putenv(const_cast(newEnv.c_str())); + + putenv("LD_LIBRARY_PATH="); + + if (!SteamAPI_Init()) { + throw std::runtime_error("Failed to initialize steam api!"); + } + + std::cout << "Initialized Steam API..." << std::endl; + + std::string args; + for (int i = 1; i < argc; i++) { + args += std::string(argv[i]) + " "; + } + + std::cout << args.c_str() << std::endl; + system(args.c_str()); + + SteamAPI_Shutdown(); + + std::cout << "Shutdown!" << std::endl; + + return 0; +}