From 0e208181e3359939b580a9aaf951594245bc42fb Mon Sep 17 00:00:00 2001 From: SmileyAG <58108407+SmileyAG@users.noreply.github.com> Date: Fri, 5 Jul 2024 04:00:04 +0400 Subject: [PATCH] helper_functions: allow multiple instances on Windows --- BunnymodXT/helper_functions.hpp | 16 ++++++++++++++++ BunnymodXT/modules/HwDLL.cpp | 10 +--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/BunnymodXT/helper_functions.hpp b/BunnymodXT/helper_functions.hpp index 44961a28..cc2458b3 100644 --- a/BunnymodXT/helper_functions.hpp +++ b/BunnymodXT/helper_functions.hpp @@ -13,4 +13,20 @@ namespace helper_functions void com_fixslashes(std::string &str); std::string swap_lib(const char* current_lib_path, std::string new_lib_path, const char *start); void crash_if_failed(std::string str); + + inline void allow_multiple_instances() // Make it possible to run multiple Half-Life instances. + { + #ifdef _WIN32 + auto mutex = OpenMutexA(SYNCHRONIZE, FALSE, "ValveHalfLifeLauncherMutex"); + if (!mutex) + mutex = OpenMutexA(SYNCHRONIZE, FALSE, "SvenCoopLauncherMutex"); + + if (mutex) + { + EngineMsg("Releasing the launcher mutex.\n"); + ReleaseMutex(mutex); + CloseHandle(mutex); + } + #endif + } } \ No newline at end of file diff --git a/BunnymodXT/modules/HwDLL.cpp b/BunnymodXT/modules/HwDLL.cpp index effbefad..21c5688a 100644 --- a/BunnymodXT/modules/HwDLL.cpp +++ b/BunnymodXT/modules/HwDLL.cpp @@ -386,15 +386,7 @@ void HwDLL::Hook(const std::wstring& moduleName, void* moduleHandle, void* modul } m_HookedNumber = number; -#ifdef _WIN32 - // Make it possible to run multiple Half-Life instances. - auto mutex = OpenMutexA(SYNCHRONIZE, FALSE, "ValveHalfLifeLauncherMutex"); - if (mutex) { - EngineMsg("Releasing the launcher mutex.\n"); - ReleaseMutex(mutex); - CloseHandle(mutex); - } -#endif + helper_functions::allow_multiple_instances(); FindStuff();