From f4ba14cd1354f304055a54ad55737999909debdf Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Fri, 30 Oct 2020 19:24:42 +1100 Subject: [PATCH] 2.1.0 * Fix a bug with Il2Cpp reflection causing TargetInvocationException and other weird issues. --- src/ExplorerCore.cs | 2 +- src/Helpers/ReflectionHelpers.cs | 2 +- src/Tests/TestClass.cs | 7 +++++++ src/UI/Inspectors/ReflectionInspector.cs | 17 +++++++++++++++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 633c351..2dc3e96 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -12,7 +12,7 @@ namespace Explorer public class ExplorerCore { public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")"; - public const string VERSION = "2.0.9"; + public const string VERSION = "2.1.0"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.explorer"; diff --git a/src/Helpers/ReflectionHelpers.cs b/src/Helpers/ReflectionHelpers.cs index d1aca8f..793610a 100644 --- a/src/Helpers/ReflectionHelpers.cs +++ b/src/Helpers/ReflectionHelpers.cs @@ -43,7 +43,7 @@ namespace Explorer.Helpers return obj; if (!typeof(Il2CppSystem.Object).IsAssignableFrom(castTo)) - return obj; + return obj as System.Object; IntPtr castToPtr; if (!ClassPointers.ContainsKey(castTo)) diff --git a/src/Tests/TestClass.cs b/src/Tests/TestClass.cs index 94f9212..937a581 100644 --- a/src/Tests/TestClass.cs +++ b/src/Tests/TestClass.cs @@ -49,6 +49,7 @@ namespace Explorer.Tests #if CPP public static Il2CppSystem.Collections.Generic.HashSet ILHashSetTest; + public static Il2CppReferenceArray testRefArray; #endif public TestClass() @@ -64,6 +65,12 @@ namespace Explorer.Tests GameObject.DontDestroyOnLoad(TestTexture); GameObject.DontDestroyOnLoad(TestSprite); + testRefArray = new Il2CppReferenceArray(5); + for (int i = 0; i < 5; i++) + { + testRefArray[i] = "hi " + i; + } + //// test loading a tex from file //var dataToLoad = System.IO.File.ReadAllBytes(@"Mods\Explorer\Tex_Nemundis_Nebula.png"); //ExplorerCore.Log($"Tex load success: {TestTexture.LoadImage(dataToLoad, false)}"); diff --git a/src/UI/Inspectors/ReflectionInspector.cs b/src/UI/Inspectors/ReflectionInspector.cs index 86bc01b..e0445b7 100644 --- a/src/UI/Inspectors/ReflectionInspector.cs +++ b/src/UI/Inspectors/ReflectionInspector.cs @@ -10,6 +10,7 @@ using Explorer.UI.Inspectors; using Explorer.Helpers; #if CPP using UnhollowerBaseLib; +using UnhollowerRuntimeLib; #endif namespace Explorer.UI.Inspectors @@ -141,6 +142,18 @@ namespace Explorer.UI.Inspectors continue; } + var target = Target; +#if CPP + try + { + target = target.Il2CppCast(declaringType); + } + catch //(Exception e) + { + //ExplorerCore.LogWarning("Excepting casting " + target.GetType().FullName + " to " + declaringType.FullName); + } +#endif + foreach (var member in infos) { try @@ -156,7 +169,7 @@ namespace Explorer.UI.Inspectors if (IsStaticInspector) { if (member is FieldInfo fi && !fi.IsStatic) continue; - else if (pi != null && !pi.GetAccessors()[0].IsStatic) continue; + else if (pi != null && !pi.GetAccessors(true)[0].IsStatic) continue; else if (mi != null && !mi.IsStatic) continue; } @@ -196,7 +209,7 @@ namespace Explorer.UI.Inspectors { // ExplorerCore.Log($"Trying to cache member {sig}..."); - var cached = CacheFactory.GetCacheObject(member, Target); + var cached = CacheFactory.GetCacheObject(member, target); if (cached != null) {