From 46d9dd4f62bd6fecc426867967c30dd0a37f9b95 Mon Sep 17 00:00:00 2001 From: ghorsington Date: Sat, 9 Jul 2022 21:25:49 +0300 Subject: [PATCH] Fix Wine check not working on UnityMono version DynDll relies on PlatformHelper in net35 version which can cause early loading --- BepInEx.Preloader.Core/PlatformUtils.cs | 20 ++++++++++++++----- BepInEx.Preloader.Unity/DoorstopEntrypoint.cs | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/BepInEx.Preloader.Core/PlatformUtils.cs b/BepInEx.Preloader.Core/PlatformUtils.cs index 04453aa..0222114 100644 --- a/BepInEx.Preloader.Core/PlatformUtils.cs +++ b/BepInEx.Preloader.Core/PlatformUtils.cs @@ -26,6 +26,12 @@ internal static class PlatformUtils [DllImport("ntdll.dll", SetLastError = true)] private static extern bool RtlGetVersion(ref WindowsOSVersionInfoExW versionInfo); + [DllImport("kernel32.dll", SetLastError = true)] + private static extern IntPtr LoadLibrary(string libraryName); + + [DllImport("kernel32.dll", SetLastError = true)] + private static extern IntPtr GetProcAddress(IntPtr hModule, string procName); + private static bool Is(this Platform current, Platform expected) => (current & expected) == expected; /// @@ -67,12 +73,16 @@ internal static class PlatformUtils (int) windowsVersionInfo.dwMinorVersion, 0, (int) windowsVersionInfo.dwBuildNumber); - if (DynDll.TryOpenLibrary("ntdll.dll", out var ntdll) && - ntdll.TryGetFunction("wine_get_version", out var wineGetVersion)) + var ntDll = LoadLibrary("ntdll.dll"); + if (ntDll != IntPtr.Zero) { - current |= Platform.Wine; - var getVersion = wineGetVersion.AsDelegate(); - WineVersion = new Version(getVersion()); + var wineGetVersion = GetProcAddress(ntDll, "wine_get_version"); + if (wineGetVersion != IntPtr.Zero) + { + current |= Platform.Wine; + var getVersion = wineGetVersion.AsDelegate(); + WineVersion = new Version(getVersion()); + } } } diff --git a/BepInEx.Preloader.Unity/DoorstopEntrypoint.cs b/BepInEx.Preloader.Unity/DoorstopEntrypoint.cs index 57b96e5..89d0e94 100644 --- a/BepInEx.Preloader.Unity/DoorstopEntrypoint.cs +++ b/BepInEx.Preloader.Unity/DoorstopEntrypoint.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using BepInEx.Preloader.Core; using BepInEx.Preloader.Unity;