Skip to content

Commit

Permalink
helper_functions: allow multiple instances on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG authored and YaLTeR committed Jul 27, 2024
1 parent 2c06fda commit 0e20818
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 16 additions & 0 deletions BunnymodXT/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
10 changes: 1 addition & 9 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 0e20818

Please sign in to comment.