mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Add a workaround for MissingMethodException for unityVersion in some rare cases
Rebase of 6bd59af
This commit is contained in:
1 file changed
+16
-1
@@ -3,6 +3,7 @@ using BepInEx.Logging;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using BepInEx.Bootstrap;
|
||||
using BepInEx.Preloader.Core.Logging;
|
||||
@@ -33,6 +34,20 @@ namespace BepInEx.Unity.Bootstrap
|
||||
private string _consoleTitle;
|
||||
protected override string ConsoleTitle => _consoleTitle;
|
||||
|
||||
|
||||
// In some rare cases calling Application.unityVersion seems to cause MissingMethodException
|
||||
// if a preloader patch applies Harmony patch to Chainloader.Initialize.
|
||||
// The issue could be related to BepInEx being compiled against Unity 5.6 version of UnityEngine.dll,
|
||||
// but the issue is apparently present with both official Harmony and HarmonyX
|
||||
// We specifically prevent inlining to prevent early resolving
|
||||
// TODO: Figure out better version obtaining mechanism (e.g. from globalmanagers)
|
||||
private static string UnityVersion
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
get => Application.unityVersion;
|
||||
}
|
||||
|
||||
|
||||
public override void Initialize(string gameExePath = null)
|
||||
{
|
||||
UnityTomlTypeConverters.AddUnityEngineConverters();
|
||||
@@ -56,7 +71,7 @@ namespace BepInEx.Unity.Bootstrap
|
||||
|
||||
if (Utility.CurrentPlatform != Platform.Windows)
|
||||
{
|
||||
Logger.LogInfo($"Detected Unity version: v{Application.unityVersion}");
|
||||
Logger.LogInfo($"Detected Unity version: v{UnityVersion}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user