diff --git a/MonkeyLoader.Resonite.Integration/MonkeyLoader.Resonite.Integration.csproj b/MonkeyLoader.Resonite.Integration/MonkeyLoader.Resonite.Integration.csproj index 9c5a9a3..149383e 100644 --- a/MonkeyLoader.Resonite.Integration/MonkeyLoader.Resonite.Integration.csproj +++ b/MonkeyLoader.Resonite.Integration/MonkeyLoader.Resonite.Integration.csproj @@ -58,13 +58,14 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + + diff --git a/MonkeyLoader.Resonite.Integration/PluginLoadingFix.cs b/MonkeyLoader.Resonite.Integration/PluginLoadingFix.cs new file mode 100644 index 0000000..c8494b2 --- /dev/null +++ b/MonkeyLoader.Resonite.Integration/PluginLoadingFix.cs @@ -0,0 +1,37 @@ +using HarmonyLib; +using MonkeyLoader.Patching; +using FrooxEngine.Weaver; +using System; +using System.Collections.Generic; +using System.Text; +using Mono.Cecil; +using System.Reflection.Emit; + +namespace MonkeyLoader.Resonite +{ + [HarmonyPatchCategory(nameof(PluginLoadingFix))] + [HarmonyPatch(typeof(AssemblyPostProcessor), nameof(AssemblyPostProcessor.Process), + [typeof(string), typeof(string), typeof(string)], [ArgumentType.Normal, ArgumentType.Out, ArgumentType.Normal])] + internal sealed class PluginLoadingFix : Monkey + { + private static void HandleAssemblyResolver(ReaderParameters readerParameters, DefaultAssemblyResolver assemblyResolver) + { + assemblyResolver.AddSearchDirectory(MonkeyLoader.GameAssemblyPath); + readerParameters.AssemblyResolver = assemblyResolver; + } + + private static IEnumerable Transpiler(IEnumerable instructions) + { + var handleAssemblyResolverMethod = AccessTools.Method(typeof(PluginLoadingFix), nameof(HandleAssemblyResolver)); + var setAssemblyResolverMethod = AccessTools.PropertySetter(typeof(ReaderParameters), nameof(ReaderParameters.AssemblyResolver)); + + foreach (var instruction in instructions) + { + if (instruction.Calls(setAssemblyResolverMethod)) + yield return new CodeInstruction(OpCodes.Call, handleAssemblyResolverMethod); + else + yield return instruction; + } + } + } +} \ No newline at end of file