Save dll_listener context

This commit is contained in:
acidicoala
2025-09-18 06:36:17 +05:00
parent d80fd562ca
commit 3544436df7
2 changed files with 12 additions and 5 deletions

View File

@@ -42,6 +42,7 @@ namespace {
namespace kb = koalabox; namespace kb = koalabox;
void* steamapi_handle = nullptr; void* steamapi_handle = nullptr;
const kb::dll_monitor::callback_context_t* dll_monitor_context = nullptr;
std::set<std::string> find_steamclient_versions() { std::set<std::string> find_steamclient_versions() {
if(!steamapi_handle) { if(!steamapi_handle) {
@@ -93,11 +94,18 @@ namespace {
KB_HOOK_DETOUR_MODULE(CreateInterface, steamclient_handle); KB_HOOK_DETOUR_MODULE(CreateInterface, steamclient_handle);
// TODO: There is an implicit lifetime dependency here and potential for leaks.
// This mechanism requires rework.
// DLL monitor will have destroyed it.
dll_monitor_context = nullptr;
return true; return true;
} }
void start_dll_listener() { void start_dll_listener() {
kb::dll_monitor::init_listener({{STEAMCLIENT_DLL, on_steamclient_loaded}}); dll_monitor_context = kb::dll_monitor::init_listener(
{{STEAMCLIENT_DLL, on_steamclient_loaded}}
);
} }
} }
@@ -153,14 +161,13 @@ namespace smoke_api {
steamapi_handle = nullptr; steamapi_handle = nullptr;
} }
kb::dll_monitor::shutdown_listener(nullptr); kb::dll_monitor::shutdown_listener(dll_monitor_context);
// TODO: Unhook everything // TODO: Unhook everything
LOG_INFO("Shutdown complete"); LOG_INFO("Shutdown complete");
} catch(const std::exception& e) { } catch(const std::exception& e) {
const auto msg = std::format("Shutdown error: {}", e.what()); LOG_ERROR("Shutdown error: {}", e.what());
LOG_ERROR(msg);
} }
kb::logger::shutdown(); kb::logger::shutdown();