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

Commit 56d1507

Browse files
committed
1.6.2
* Fix for a crash that can occur when inspecting unsupported Dictionaries * Added a scroll bar to the REPL console input area, fixes the issue of the code just being cut off when it goes too long.
1 parent 72d31ea commit 56d1507

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

src/CachedObjects/Object/CacheDictionary.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using MelonLoader;
88
using UnityEngine;
99
using System.Reflection;
10+
using UnhollowerBaseLib;
1011

1112
namespace Explorer
1213
{
@@ -130,6 +131,13 @@ private void GetGenericArguments()
130131

131132
public override void UpdateValue()
132133
{
134+
// first make sure we won't run into a TypeInitializationException.
135+
if (!EnsureDictionaryIsSupported())
136+
{
137+
ReflectionException = "Dictionary Type not supported with Reflection!";
138+
return;
139+
}
140+
133141
base.UpdateValue();
134142

135143
// reset
@@ -160,6 +168,86 @@ public override void UpdateValue()
160168
m_cachedValues = values.ToArray();
161169
}
162170

171+
private bool EnsureDictionaryIsSupported()
172+
{
173+
try
174+
{
175+
//var ilTypes = new List<Il2CppSystem.Type>();
176+
var monoTypes = new Type[] { TypeOfKeys, TypeOfValues };
177+
178+
foreach (var type in monoTypes)
179+
{
180+
var generic = typeof(Il2CppClassPointerStore<>).MakeGenericType(type);
181+
if (generic == null) return false;
182+
183+
var genericPtr = (IntPtr)generic.GetField("NativeClassPtr").GetValue(null);
184+
if (genericPtr == null) return false;
185+
186+
var classPtr = IL2CPP.il2cpp_class_get_type(genericPtr);
187+
if (classPtr == null) return false;
188+
189+
var internalType = Il2CppSystem.Type.internal_from_handle(classPtr);
190+
if (internalType == null) return false;
191+
192+
//ilTypes.Add(internalType);
193+
}
194+
}
195+
catch
196+
{
197+
return false;
198+
}
199+
200+
// Should be fine if we got this far, but I'll leave the rest below commented out just in case.
201+
return true;
202+
203+
//MelonLogger.Log("Got both generic types, continuing...");
204+
205+
//var dictIlClass = IL2CPP.GetIl2CppClass("mscorlib.dll", "System.Collections.Generic", "Dictionary`2");
206+
//if (dictIlClass == null) return;
207+
208+
//MelonLogger.Log("Got base dictionary Il2Cpp type");
209+
210+
//var ilClassFromType = IL2CPP.il2cpp_class_get_type(dictIlClass);
211+
//if (ilClassFromType == null) return;
212+
213+
//MelonLogger.Log("got IntPtr from base dictionary type");
214+
215+
//var internalHandle = Il2CppSystem.Type.internal_from_handle(ilClassFromType);
216+
//if (internalHandle == null) return;
217+
218+
//var generic = internalHandle.MakeGenericType(new Il2CppReferenceArray<Il2CppSystem.Type>(new Il2CppSystem.Type[]
219+
//{
220+
// ilTypes[0], ilTypes[1]
221+
//}));
222+
//if (generic == null) return;
223+
224+
//MelonLogger.Log("Made generic handle for our entry types");
225+
226+
//var nativeClassPtr = generic.TypeHandle.value;
227+
//if (nativeClassPtr == null) return;
228+
229+
//MelonLogger.Log("Got the actual nativeClassPtr for the handle");
230+
231+
//var dictType = typeof(Il2CppSystem.Collections.Generic.Dictionary<,>).MakeGenericType(TypeOfKeys, TypeOfValues);
232+
//if (dictType == null) return;
233+
234+
//MelonLogger.Log("Made the generic type for the dictionary");
235+
236+
//var pointerStoreType = typeof(Il2CppClassPointerStore<>).MakeGenericType(dictType);
237+
//if (pointerStoreType == null) return;
238+
239+
//MelonLogger.Log("Made the generic PointerStoreType for our dict");
240+
241+
//var ptrToSet = IL2CPP.il2cpp_class_from_type(nativeClassPtr);
242+
//if (ptrToSet == null) return;
243+
244+
//MelonLogger.Log("Got class from nativeClassPtr, setting value...");
245+
246+
//pointerStoreType.GetField("NativeClassPtr").SetValue(null, ptrToSet);
247+
248+
//MelonLogger.Log("Ok");
249+
}
250+
163251
// ============= GUI Draw =============
164252

165253
public override void DrawValue(Rect window, float width)

src/MainMenu/Pages/ConsolePage.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class ConsolePage : WindowPage
1919
private ScriptEvaluator _evaluator;
2020
private readonly StringBuilder _sb = new StringBuilder();
2121

22+
private Vector2 inputAreaScroll;
23+
2224
private string MethodInput = "";
2325
private string UsingInput = "";
2426

@@ -124,7 +126,12 @@ public override void DrawWindow()
124126
GUI.skin.label.alignment = TextAnchor.UpperLeft;
125127

126128
GUILayout.Label("Enter code here as though it is a method body:", null);
127-
MethodInput = GUILayout.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.Height(250) });
129+
130+
inputAreaScroll = GUIUnstrip.BeginScrollView(inputAreaScroll, new GUILayoutOption[] { GUILayout.Height(250) });
131+
132+
MethodInput = GUILayout.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.ExpandHeight(true) });
133+
134+
GUIUnstrip.EndScrollView();
128135

129136
if (GUILayout.Button("<color=cyan><b>Execute</b></color>", null))
130137
{

0 commit comments

Comments
 (0)