Skip to content

Commit 653b4fe

Browse files
Merge pull request #60 from ApexNite/master
Bugfix: Missing harmony assembly for unity explorer compatability fix
2 parents bf7a084 + 3c10d5e commit 653b4fe

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

WorldBoxMod.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ public class WorldBoxMod : MonoBehaviour
3131
private bool initialized = false;
3232
private bool initialized_successfully = false;
3333

34-
[HarmonyPatch(typeof(Assembly), nameof(Assembly.LoadFrom), typeof(string))]
35-
[HarmonyReversePatch]
36-
private static Assembly LoadFrom(string path) => throw new NotImplementedException();
34+
private static void UnityExplorerFix() {
35+
Harmony harmony = new Harmony(Others.harmony_id);
36+
MethodInfo original = AccessTools.Method(typeof(Assembly), nameof(Assembly.LoadFrom), new[] { typeof(string) });
37+
MethodInfo standin = AccessTools.Method(typeof(WorldBoxMod), nameof(LoadFrom));
38+
ReversePatcher reversePatcher = harmony.CreateReversePatcher(original, new HarmonyMethod(standin));
39+
40+
reversePatcher.Patch();
41+
}
42+
43+
private static Assembly LoadFrom(string path) => Assembly.LoadFrom(path);
3744

3845
private void Start()
3946
{
@@ -46,7 +53,10 @@ private void Start()
4653

4754
LogService.Init();
4855

49-
Harmony.CreateAndPatchAll(typeof(WorldBoxMod), Others.harmony_id);
56+
if (ReflectionHelper.IsAssemblyLoaded("0Harmony")) {
57+
UnityExplorerFix();
58+
}
59+
5060
fileSystemInitialize();
5161
LogService.LogInfo($"NeoModLoader Version: {InternalResourcesGetter.GetCommit()}");
5262
}

utils/ReflectionHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ namespace NeoModLoader.utils;
77

88
internal static class ReflectionHelper
99
{
10+
internal static bool IsAssemblyLoaded(string assembly_name) {
11+
return AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name.Equals(assembly_name));
12+
}
13+
1014
internal static Delegate GetMethod<T>(string method_name, bool is_static = false)
1115
{
1216
return createMethodDelegate(is_static

0 commit comments

Comments
 (0)