BepInEx.IL2CPP: Fix mutex checks

This commit is contained in:
ghorsington committed 2022-08-14 17:18:58 +03:00
1 parent 8dc326c652
commit b80f29784c
2 files changed
+22 -3

No files matched your search

+17
View File
@@ -320,6 +320,23 @@ public static class Utility
return ByteArrayToString(md5.Hash);
}
/// <summary>
/// Hash a list of strings using MD5
/// </summary>
/// <param name="strings">Strings to hash</param>
/// <returns>MD5 of the strings</returns>
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);
}
/// <summary>
/// Convert the given array to a hex string.
/// </summary>
+5 -3
View File
@@ -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();