* Fix a bug with Il2Cpp reflection causing TargetInvocationException and other weird issues.
This commit is contained in:
sinaioutlander 2020-10-30 19:24:42 +11:00
parent 4263cef26a
commit f4ba14cd13
4 changed files with 24 additions and 4 deletions

View File

@ -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";

View File

@ -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))

View File

@ -49,6 +49,7 @@ namespace Explorer.Tests
#if CPP
public static Il2CppSystem.Collections.Generic.HashSet<string> ILHashSetTest;
public static Il2CppReferenceArray<Il2CppSystem.Object> testRefArray;
#endif
public TestClass()
@ -64,6 +65,12 @@ namespace Explorer.Tests
GameObject.DontDestroyOnLoad(TestTexture);
GameObject.DontDestroyOnLoad(TestSprite);
testRefArray = new Il2CppReferenceArray<Il2CppSystem.Object>(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)}");

View File

@ -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)
{