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

Commit 1fce346

Browse files
committed
Fix bug in ForceUnlockCursor, fix mistake in Reflection Inspector, reduced amount casting with Reflection Inspector
1 parent 8949e3d commit 1fce346

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

src/UI/ForceUnlockCursor.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using UnityEngine;
33
using Explorer.Helpers;
4+
using BF = System.Reflection.BindingFlags;
45
#if ML
56
using Harmony;
67
#else
@@ -40,8 +41,17 @@ public static void Init()
4041
}
4142

4243
// Get current cursor state and enable cursor
43-
m_lastLockMode = Cursor.lockState;
44-
m_lastVisibleState = Cursor.visible;
44+
try
45+
{
46+
//m_lastLockMode = Cursor.lockState;
47+
m_lastLockMode = (CursorLockMode?)typeof(Cursor).GetProperty("lockState", BF.Public | BF.Static)?.GetValue(null, null)
48+
?? CursorLockMode.None;
49+
50+
//m_lastVisibleState = Cursor.visible;
51+
m_lastVisibleState = (bool?)typeof(Cursor).GetProperty("visible", BF.Public | BF.Static)?.GetValue(null, null)
52+
?? false;
53+
}
54+
catch { }
4555

4656
// Setup Harmony Patches
4757
TryPatch("lockState", new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_set_lockState))), true);

src/UI/Inspectors/ReflectionInspector.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,19 @@ public virtual bool ShouldProcessMember(CacheMember holder)
9999
if (m_typeFilter != MemberTypes.All && m_typeFilter != holder.MemInfo?.MemberType)
100100
return false;
101101

102+
// hide failed reflection
103+
if (!string.IsNullOrEmpty(holder.ReflectionException) && m_hideFailedReflection)
104+
return false;
105+
102106
// check scope filter
103-
if (m_scopeFilter == MemberScopes.Instance)
107+
if (m_scopeFilter == MemberScopes.Instance && holder.IsStatic)
104108
{
105-
return !holder.IsStatic;
109+
return false;
106110
}
107-
else if (m_scopeFilter == MemberScopes.Static)
111+
else if (m_scopeFilter == MemberScopes.Static && !holder.IsStatic)
108112
{
109-
return holder.IsStatic;
110-
}
111-
112-
// hide failed reflection
113-
if (!string.IsNullOrEmpty(holder.ReflectionException) && m_hideFailedReflection)
114113
return false;
114+
}
115115

116116
// see if we should do name search
117117
if (m_search == "" || holder.MemInfo == null)
@@ -141,22 +141,6 @@ private void CacheMembers(Type[] types)
141141
continue;
142142
}
143143

144-
object target = Target;
145-
string exception = null;
146-
147-
#if CPP
148-
if (!IsStaticInspector && target is Il2CppSystem.Object ilObject)
149-
{
150-
try
151-
{
152-
target = ilObject.Il2CppCast(declaringType);
153-
}
154-
catch (Exception e)
155-
{
156-
exception = ReflectionHelpers.ExceptionToString(e);
157-
}
158-
}
159-
#endif
160144
foreach (var member in infos)
161145
{
162146
try
@@ -211,17 +195,12 @@ void AppendParams(ParameterInfo[] _args)
211195

212196
try
213197
{
214-
var cached = CacheFactory.GetCacheObject(member, target);
198+
var cached = CacheFactory.GetCacheObject(member, Target);
215199

216200
if (cached != null)
217201
{
218202
cachedSigs.Add(sig);
219203
list.Add(cached);
220-
221-
if (string.IsNullOrEmpty(cached.ReflectionException))
222-
{
223-
cached.ReflectionException = exception;
224-
}
225204
}
226205
}
227206
catch (Exception e)

src/UI/WindowBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using UnityEngine;
33
using Explorer.Config;
44
using Explorer.UI.Inspectors;
5+
using Explorer.Helpers;
56

67
namespace Explorer.UI
78
{
@@ -26,7 +27,15 @@ public static WindowBase CreateWindow<T>(object target) where T : WindowBase
2627
{
2728
var window = Activator.CreateInstance<T>();
2829

30+
#if CPP
31+
if (target is Il2CppSystem.Object ilObject)
32+
{
33+
target = ilObject.Il2CppCast(ReflectionHelpers.GetActualType(ilObject));
34+
}
35+
#endif
36+
2937
window.Target = target;
38+
3039
window.windowID = WindowManager.NextWindowID();
3140
window.m_rect = WindowManager.GetNewWindowRect();
3241

0 commit comments

Comments
 (0)