Files
BepInEx/BepInEx.Preloader.UnityMono/RuntimeFixes/UnityPatches.cs
T
ghorsington 828ef20996 UnityMono: Resolve assemblies into memory using mono API
This fixes several issues with loading assemblies. In turn, this commit also removes old Location/CodeBase fixes since now assemblies are resolved automatically correctly.

Additionally, integrate the mono loader into preloading which fixes assembly location resolving
2022-08-14 17:19:08 +03:00

34 lines
977 B
C#

using System.IO;
using System.Reflection;
using BepInEx.Preloader.UnityMono.Utils;
using HarmonyLib;
namespace BepInEx.Preloader.UnityMono.RuntimeFixes;
internal static class UnityPatches
{
private static Harmony HarmonyInstance { get; set; }
public static void Apply()
{
HarmonyInstance = Harmony.CreateAndPatchAll(typeof(UnityPatches));
try
{
TraceFix.ApplyFix();
}
catch { } //ignore everything, if it's thrown an exception, we're using an assembly that has already fixed this
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Assembly), nameof(Assembly.LoadFile), typeof(string))]
[HarmonyPatch(typeof(Assembly), nameof(Assembly.LoadFrom), typeof(string))]
public static bool LoadFilePrefix(string __0, ref Assembly __result)
{
if (!File.Exists(__0))
throw new FileNotFoundException(__0);
__result = MonoAssemblyHelper.Load(__0);
return false;
}
}