diff --git a/WorldBoxMod.cs b/WorldBoxMod.cs index da40172..5e2c6d5 100644 --- a/WorldBoxMod.cs +++ b/WorldBoxMod.cs @@ -31,9 +31,16 @@ public class WorldBoxMod : MonoBehaviour private bool initialized = false; private bool initialized_successfully = false; - [HarmonyPatch(typeof(Assembly), nameof(Assembly.LoadFrom), typeof(string))] - [HarmonyReversePatch] - private static Assembly LoadFrom(string path) => throw new NotImplementedException(); + private static void UnityExplorerFix() { + Harmony harmony = new Harmony(Others.harmony_id); + MethodInfo original = AccessTools.Method(typeof(Assembly), nameof(Assembly.LoadFrom), new[] { typeof(string) }); + MethodInfo standin = AccessTools.Method(typeof(WorldBoxMod), nameof(LoadFrom)); + ReversePatcher reversePatcher = harmony.CreateReversePatcher(original, new HarmonyMethod(standin)); + + reversePatcher.Patch(); + } + + private static Assembly LoadFrom(string path) => Assembly.LoadFrom(path); private void Start() { @@ -46,7 +53,10 @@ private void Start() LogService.Init(); - Harmony.CreateAndPatchAll(typeof(WorldBoxMod), Others.harmony_id); + if (ReflectionHelper.IsAssemblyLoaded("0Harmony")) { + UnityExplorerFix(); + } + fileSystemInitialize(); LogService.LogInfo($"NeoModLoader Version: {InternalResourcesGetter.GetCommit()}"); } diff --git a/utils/ReflectionHelper.cs b/utils/ReflectionHelper.cs index 60d2599..ea07b18 100644 --- a/utils/ReflectionHelper.cs +++ b/utils/ReflectionHelper.cs @@ -7,6 +7,10 @@ namespace NeoModLoader.utils; internal static class ReflectionHelper { + internal static bool IsAssemblyLoaded(string assembly_name) { + return AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name.Equals(assembly_name)); + } + internal static Delegate GetMethod(string method_name, bool is_static = false) { return createMethodDelegate(is_static