Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper_functions: allow multiple instances on Windows #541

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -376,15 +376,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