mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Make Assembly.GetTypes patch a finalizer instead of prefix
This commit is contained in:
parent
a411ce2dba
commit
4e3203a91b
@ -15,7 +15,7 @@ namespace UnityExplorer
|
|||||||
{
|
{
|
||||||
var method = typeof(Assembly).GetMethod(nameof(Assembly.GetTypes), new Type[0]);
|
var method = typeof(Assembly).GetMethod(nameof(Assembly.GetTypes), new Type[0]);
|
||||||
var processor = ExplorerCore.Harmony.CreateProcessor(method);
|
var processor = ExplorerCore.Harmony.CreateProcessor(method);
|
||||||
processor.AddPrefix(typeof(ReflectionPatches).GetMethod(nameof(ReflectionPatches.Assembly_GetTypes)));
|
processor.AddFinalizer(typeof(ReflectionPatches).GetMethod(nameof(ReflectionPatches.Assembly_GetTypes)));
|
||||||
processor.Patch();
|
processor.Patch();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -24,10 +24,34 @@ namespace UnityExplorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Assembly_GetTypes(Assembly __instance, ref Type[] __result)
|
private static readonly Type[] emptyTypes = new Type[0];
|
||||||
|
|
||||||
|
public static Exception Assembly_GetTypes(Assembly __instance, Exception __exception, ref Type[] __result)
|
||||||
{
|
{
|
||||||
__result = __instance.TryGetTypes().ToArray();
|
if (__exception != null)
|
||||||
return false;
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
__result = __instance.GetExportedTypes();
|
||||||
|
}
|
||||||
|
catch (ReflectionTypeLoadException e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
__result = e.Types.Where(it => it != null).ToArray();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
__result = emptyTypes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
__result = emptyTypes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user