mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
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
34 lines
977 B
C#
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;
|
|
}
|
|
}
|