diff --git a/src/Core/Reflection/Patches.cs b/src/Core/Reflection/Patches.cs new file mode 100644 index 0000000..b06c7ef --- /dev/null +++ b/src/Core/Reflection/Patches.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using HarmonyLib; + +namespace UnityExplorer +{ + public static class ReflectionPatches + { + public static void Init() + { + try + { + var method = typeof(Assembly).GetMethod(nameof(Assembly.GetTypes), new Type[0]); + var processor = ExplorerCore.Harmony.CreateProcessor(method); + processor.AddPrefix(typeof(ReflectionPatches).GetMethod(nameof(ReflectionPatches.Assembly_GetTypes))); + processor.Patch(); + } + catch (Exception ex) + { + ExplorerCore.LogWarning($"Exception setting up Reflection patch: {ex}"); + } + } + + public static bool Assembly_GetTypes(Assembly __instance, ref Type[] __result) + { + __result = __instance.TryGetTypes().ToArray(); + return false; + } + } +} diff --git a/src/Core/Reflection/ReflectionUtility.cs b/src/Core/Reflection/ReflectionUtility.cs index 053b616..d766b95 100644 --- a/src/Core/Reflection/ReflectionUtility.cs +++ b/src/Core/Reflection/ReflectionUtility.cs @@ -27,6 +27,8 @@ namespace UnityExplorer new ReflectionUtility(); #endif Instance.Initialize(); + + ReflectionPatches.Init(); } protected virtual void Initialize() diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index ef05e3b..be675ce 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -218,6 +218,7 @@ +