Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit f4ba14c

Browse files
committed
2.1.0
* Fix a bug with Il2Cpp reflection causing TargetInvocationException and other weird issues.
1 parent 4263cef commit f4ba14c

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Explorer
1212
public class ExplorerCore
1313
{
1414
public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")";
15-
public const string VERSION = "2.0.9";
15+
public const string VERSION = "2.1.0";
1616
public const string AUTHOR = "Sinai";
1717
public const string GUID = "com.sinai.explorer";
1818

src/Helpers/ReflectionHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static object Il2CppCast(object obj, Type castTo)
4343
return obj;
4444

4545
if (!typeof(Il2CppSystem.Object).IsAssignableFrom(castTo))
46-
return obj;
46+
return obj as System.Object;
4747

4848
IntPtr castToPtr;
4949
if (!ClassPointers.ContainsKey(castTo))

src/Tests/TestClass.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static bool SetOnlyProperty
4949

5050
#if CPP
5151
public static Il2CppSystem.Collections.Generic.HashSet<string> ILHashSetTest;
52+
public static Il2CppReferenceArray<Il2CppSystem.Object> testRefArray;
5253
#endif
5354

5455
public TestClass()
@@ -64,6 +65,12 @@ public TestClass()
6465
GameObject.DontDestroyOnLoad(TestTexture);
6566
GameObject.DontDestroyOnLoad(TestSprite);
6667

68+
testRefArray = new Il2CppReferenceArray<Il2CppSystem.Object>(5);
69+
for (int i = 0; i < 5; i++)
70+
{
71+
testRefArray[i] = "hi " + i;
72+
}
73+
6774
//// test loading a tex from file
6875
//var dataToLoad = System.IO.File.ReadAllBytes(@"Mods\Explorer\Tex_Nemundis_Nebula.png");
6976
//ExplorerCore.Log($"Tex load success: {TestTexture.LoadImage(dataToLoad, false)}");

src/UI/Inspectors/ReflectionInspector.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Explorer.Helpers;
1111
#if CPP
1212
using UnhollowerBaseLib;
13+
using UnhollowerRuntimeLib;
1314
#endif
1415

1516
namespace Explorer.UI.Inspectors
@@ -141,6 +142,18 @@ private void CacheMembers(Type[] types)
141142
continue;
142143
}
143144

145+
var target = Target;
146+
#if CPP
147+
try
148+
{
149+
target = target.Il2CppCast(declaringType);
150+
}
151+
catch //(Exception e)
152+
{
153+
//ExplorerCore.LogWarning("Excepting casting " + target.GetType().FullName + " to " + declaringType.FullName);
154+
}
155+
#endif
156+
144157
foreach (var member in infos)
145158
{
146159
try
@@ -156,7 +169,7 @@ private void CacheMembers(Type[] types)
156169
if (IsStaticInspector)
157170
{
158171
if (member is FieldInfo fi && !fi.IsStatic) continue;
159-
else if (pi != null && !pi.GetAccessors()[0].IsStatic) continue;
172+
else if (pi != null && !pi.GetAccessors(true)[0].IsStatic) continue;
160173
else if (mi != null && !mi.IsStatic) continue;
161174
}
162175

@@ -196,7 +209,7 @@ void AppendParams(ParameterInfo[] _args)
196209
{
197210
// ExplorerCore.Log($"Trying to cache member {sig}...");
198211

199-
var cached = CacheFactory.GetCacheObject(member, Target);
212+
var cached = CacheFactory.GetCacheObject(member, target);
200213

201214
if (cached != null)
202215
{

0 commit comments

Comments
 (0)