From b80f29784c0d40f3778a3a4cc5c090b0bb92ea40 Mon Sep 17 00:00:00 2001 From: ghorsington Date: Sat, 14 May 2022 23:33:32 +0300 Subject: [PATCH] BepInEx.IL2CPP: Fix mutex checks --- BepInEx.Core/Utility.cs | 17 +++++++++++++++++ BepInEx.IL2CPP/DoorstopEntrypoint.cs | 8 +++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/BepInEx.Core/Utility.cs b/BepInEx.Core/Utility.cs index a71f731..a4252d2 100644 --- a/BepInEx.Core/Utility.cs +++ b/BepInEx.Core/Utility.cs @@ -320,6 +320,23 @@ public static class Utility return ByteArrayToString(md5.Hash); } + /// + /// Hash a list of strings using MD5 + /// + /// Strings to hash + /// MD5 of the strings + public static string HashStrings(params string[] strings) + { + using var md5 = MD5.Create(); + + foreach (var str in strings) + md5.TransformBlock(Encoding.UTF8.GetBytes(str), 0, str.Length, null, 0); + + md5.TransformFinalBlock(new byte[0], 0, 0); + + return ByteArrayToString(md5.Hash); + } + /// /// Convert the given array to a hex string. /// diff --git a/BepInEx.IL2CPP/DoorstopEntrypoint.cs b/BepInEx.IL2CPP/DoorstopEntrypoint.cs index 18b2d93..5f9902e 100644 --- a/BepInEx.IL2CPP/DoorstopEntrypoint.cs +++ b/BepInEx.IL2CPP/DoorstopEntrypoint.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics; using System.IO; using System.Threading; +using BepInEx; using BepInEx.IL2CPP; using BepInEx.Preloader.Core; @@ -25,9 +26,10 @@ internal static class Entrypoint silentExceptionLog = Path.Combine(Path.GetDirectoryName(EnvVars.DOORSTOP_PROCESS_PATH), silentExceptionLog); - mutex = new Mutex(false, - Process.GetCurrentProcess().ProcessName + EnvVars.DOORSTOP_PROCESS_PATH + - typeof(Doorstop.Entrypoint).FullName); + var mutexId = Utility.HashStrings(Process.GetCurrentProcess().ProcessName, EnvVars.DOORSTOP_PROCESS_PATH, + typeof(Entrypoint).FullName); + + mutex = new Mutex(false, $"Global\\{mutexId}"); mutex.WaitOne(); UnityPreloaderRunner.PreloaderMain();