From d54d52651d76f81d7624bf1dee166e6295b5a15b Mon Sep 17 00:00:00 2001 From: ApexNite <128202315+ApexNite@users.noreply.github.com> Date: Thu, 11 Sep 2025 12:36:23 -0500 Subject: [PATCH 1/3] Bugfix: Missing harmony assembly for unity explorer compatability fix --- WorldBoxMod.cs | 24 ++++++++++++++++++------ utils/ReflectionHelper.cs | 4 ++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/WorldBoxMod.cs b/WorldBoxMod.cs index da40172..49029b0 100644 --- a/WorldBoxMod.cs +++ b/WorldBoxMod.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.InteropServices; using HarmonyLib; using NeoModLoader.api; using NeoModLoader.constants; @@ -31,9 +32,17 @@ 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 +55,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()}"); } @@ -294,8 +306,8 @@ void extractAssemblies() try { LoadFrom(file_full_path); - } - catch (BadImageFormatException) + + } catch (BadImageFormatException) { LogService.LogError($"" + $"BadImageFormatException: " + 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 From e7c663cbb224eacc4a3de588bc41188878a36077 Mon Sep 17 00:00:00 2001 From: ApexNite <128202315+ApexNite@users.noreply.github.com> Date: Thu, 11 Sep 2025 12:37:50 -0500 Subject: [PATCH 2/3] Revert "Bugfix: Missing harmony assembly for unity explorer compatability fix" This reverts commit d54d52651d76f81d7624bf1dee166e6295b5a15b. --- WorldBoxMod.cs | 24 ++++++------------------ utils/ReflectionHelper.cs | 4 ---- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/WorldBoxMod.cs b/WorldBoxMod.cs index 49029b0..da40172 100644 --- a/WorldBoxMod.cs +++ b/WorldBoxMod.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.InteropServices; using HarmonyLib; using NeoModLoader.api; using NeoModLoader.constants; @@ -32,17 +31,9 @@ public class WorldBoxMod : MonoBehaviour private bool initialized = false; private bool initialized_successfully = false; - 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); - + [HarmonyPatch(typeof(Assembly), nameof(Assembly.LoadFrom), typeof(string))] + [HarmonyReversePatch] + private static Assembly LoadFrom(string path) => throw new NotImplementedException(); private void Start() { @@ -55,10 +46,7 @@ private void Start() LogService.Init(); - if (ReflectionHelper.IsAssemblyLoaded("0Harmony")) { - UnityExplorerFix(); - } - + Harmony.CreateAndPatchAll(typeof(WorldBoxMod), Others.harmony_id); fileSystemInitialize(); LogService.LogInfo($"NeoModLoader Version: {InternalResourcesGetter.GetCommit()}"); } @@ -306,8 +294,8 @@ void extractAssemblies() try { LoadFrom(file_full_path); - - } catch (BadImageFormatException) + } + catch (BadImageFormatException) { LogService.LogError($"" + $"BadImageFormatException: " + diff --git a/utils/ReflectionHelper.cs b/utils/ReflectionHelper.cs index ea07b18..60d2599 100644 --- a/utils/ReflectionHelper.cs +++ b/utils/ReflectionHelper.cs @@ -7,10 +7,6 @@ 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 From 3c10d5e804a8997ea953b7a89c040d169c33bd1a Mon Sep 17 00:00:00 2001 From: ApexNite <128202315+ApexNite@users.noreply.github.com> Date: Thu, 11 Sep 2025 12:39:19 -0500 Subject: [PATCH 3/3] Bugfix: Missing harmony assembly for unity explorer compatability fix --- WorldBoxMod.cs | 18 ++++++++++++++---- utils/ReflectionHelper.cs | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) 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