Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions WorldBoxMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@
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()
{
Expand All @@ -46,7 +53,10 @@

LogService.Init();

Harmony.CreateAndPatchAll(typeof(WorldBoxMod), Others.harmony_id);
if (ReflectionHelper.IsAssemblyLoaded("0Harmony")) {
UnityExplorerFix();
}

fileSystemInitialize();
LogService.LogInfo($"NeoModLoader Version: {InternalResourcesGetter.GetCommit()}");
}
Expand Down Expand Up @@ -321,7 +331,7 @@
LogService.LogInfo($"NeoModLoader.dll is newer than AutoUpdate.dll, " +
$"re-extract AutoUpdate.dll from NeoModLoader.dll");
}
catch (Exception e)

Check warning on line 334 in WorldBoxMod.cs

View workflow job for this annotation

GitHub Actions / Windows

The variable 'e' is declared but never used
{
// ignored
}
Expand Down
4 changes: 4 additions & 0 deletions utils/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(string method_name, bool is_static = false)
{
return createMethodDelegate(is_static
Expand Down
Loading