From 673cd11e471c08e33da283f6dadaa322b4ef78f1 Mon Sep 17 00:00:00 2001 From: acidicoala <67734819+acidicoala@users.noreply.github.com> Date: Mon, 6 Oct 2025 18:53:22 +0500 Subject: [PATCH] Added init & shutdown checks --- KoalaBox | 2 +- README.md | 53 ++++++++++++++++++++----------------- src/smoke_api/smoke_api.cpp | 15 +++++++++++ 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/KoalaBox b/KoalaBox index 43bd142..365bbb6 160000 --- a/KoalaBox +++ b/KoalaBox @@ -1 +1 @@ -Subproject commit 43bd1420c536e1fa2afbeb4ccd4ac5fa5c4716b3 +Subproject commit 365bbb68583777d9dd13ea46a2eead3169c9d44e diff --git a/README.md b/README.md index 463a477..fccde82 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ SmokeAPI supports **2** installation modes: _Hook mode_ and _Proxy mode_. - **Advantages**: - Guaranteed to load - **Disadvantages**: - - Might need reinstallation aftera game update + - Might need reinstallation after a game update My advice is to try installing the unlocker in hook mode first. If it doesn't work, try installing it in proxy mode instead. @@ -187,26 +187,11 @@ Optional libraries: Just like on Windows, SmokeAPI features 32 and 64-bit Linux builds. In release archive they are named as `libsmoke_api32.so` or `libsmoke_api64.so` respectively. - -### 🪝 Hook mode (🐧 Linux) - -Linux doesn't have the same easily exploitable library injection mechanism that Windows has. -However, it is possible to force any Linux executable to load any library by using the -`LD_PRELOAD` environment variable. -For example: - -1. Extract and paste the `libsmoke_api32.so` or `libsmoke_api64.so` next to the game's executable. -2. In Steam _Library_ open game's _Properties_, switch to the _General_ tab, and set the following _LAUNCH OPTIONS_: - -| Bitness | Launch Options | -|---------|--------------------------------------------------------------------| -| 32-bit | `LD_PRELOAD=./libsmoke_api32.so ./GameExecutable.x86 %command%` | -| 64-bit | `LD_PRELOAD=./libsmoke_api64.so ./GameExecutable.x86_64 %command%` | - -Naturally, the exact options might change depending on how files are located on your filesystem -or depending on other environment variables you might have configured. -If you have other environment variables, and you don't know how to correctly combine them, -then please make heavy use of search engines and LLMs for guidance and examples instead of the official forum topic. +However, unlike Windows, it is recommended to use proxy mode, rather than hook mode. +This is because the current hook mode installation method has to directly launch game +executable. However, by default Steam doesn't do that, instead it launches certain wrappers +that setup game environment with optimal parameters. Hence, launching a game without those +wrappers might cause issues. That is why proxy mode is recommended on Linux for now. ### 🔀 Proxy mode (🐧 Linux) @@ -214,9 +199,29 @@ Same as on Windows: 1. Rename the original `libsteam_api.so` to `libsteam_api.so` 2. Extract and paste the `libsmoke_api32.so` or `libsmoke_api64.so` to the same directory, renaming it to `libsteam_api.so`. -### 🐞 Known issues +### 🪝 Hook mode (🐧 Linux) -- Steam overlay is not working in hook mode +Linux doesn't have the same easily exploitable library injection mechanism that Windows has. +However, it is possible to force any Linux executable to load any library by using the +`LD_PRELOAD` environment variable. In fact, Steam itself already uses that to inject its overlay, +hence we can use it as well. But we have to include that overlay library as well when specifying +`LD_PRELOAD`, otherwise the game will be launched with SmokeAPI, but without Steam overlay. + +For example: + +1. Extract and paste the `libsmoke_api32.so` or `libsmoke_api64.so` next to the game's executable. +2. In Steam _Library_ open game's _Properties_, switch to the _General_ tab, and set the following _LAUNCH OPTIONS_: + +| Bitness | Launch Options | +|---------|----------------------------------------------------------------------------------------------------------------------------------| +| 32-bit | `LD_PRELOAD="./libsmoke_api32.so $HOME/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so" ./GameExecutable.x86 %command%` | +| 64-bit | `LD_PRELOAD="./libsmoke_api64.so $HOME/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so" ./GameExecutable.x86_64 %command%` | + +Naturally, the exact options might change depending on where files are located on your filesystem +and other environment variables you might have specified previously. +If you have other environment variables, and you don't know how to correctly combine them, +then please make extensive use of search engines and LLMs for guidance and examples +before seeking help the official forum topic. ## ⚙ Configuration @@ -413,7 +418,7 @@ This project makes use of the following open source projects: - [bshoshany/thread-pool](https://github.com/bshoshany/thread-pool) - [batterycenter/embed](https://github.com/batterycenter/embed) -r +u ## 📄 License diff --git a/src/smoke_api/smoke_api.cpp b/src/smoke_api/smoke_api.cpp index f112b63..15e4823 100644 --- a/src/smoke_api/smoke_api.cpp +++ b/src/smoke_api/smoke_api.cpp @@ -217,6 +217,14 @@ namespace { namespace smoke_api { void init(void* self_module_handle) { try { + static std::mutex section; + const std::lock_guard lock(section); + + static bool init_complete = false; + if(init_complete) { + LOG_ERROR("{} is already initialized", PROJECT_NAME); + } + kb::globals::init_globals(self_module_handle, PROJECT_NAME); config::instance = kb::config::parse(); @@ -253,6 +261,7 @@ namespace smoke_api { init_lib_monitor(); + init_complete = true; LOG_INFO("Initialization complete"); } catch(const std::exception& e) { kb::util::panic(std::format("Initialization error: {}", e.what())); @@ -261,6 +270,11 @@ namespace smoke_api { void shutdown() { try { + static bool shutdown_complete = false; + if(shutdown_complete) { + LOG_ERROR("{} is already shut down", PROJECT_NAME); + } + if(original_steamapi_handle != nullptr) { kb::lib::unload(original_steamapi_handle); original_steamapi_handle = nullptr; @@ -272,6 +286,7 @@ namespace smoke_api { // TODO: Unhook everything + shutdown_complete = true; LOG_INFO("Shutdown complete"); } catch(const std::exception& e) { LOG_ERROR("Shutdown error: {}", e.what());