|
7 | 7 | using MelonLoader;
|
8 | 8 | using UnityEngine;
|
9 | 9 | using System.Reflection;
|
| 10 | +using UnhollowerBaseLib; |
10 | 11 |
|
11 | 12 | namespace Explorer
|
12 | 13 | {
|
@@ -130,6 +131,13 @@ private void GetGenericArguments()
|
130 | 131 |
|
131 | 132 | public override void UpdateValue()
|
132 | 133 | {
|
| 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 | + |
133 | 141 | base.UpdateValue();
|
134 | 142 |
|
135 | 143 | // reset
|
@@ -160,6 +168,86 @@ public override void UpdateValue()
|
160 | 168 | m_cachedValues = values.ToArray();
|
161 | 169 | }
|
162 | 170 |
|
| 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 | + |
163 | 251 | // ============= GUI Draw =============
|
164 | 252 |
|
165 | 253 | public override void DrawValue(Rect window, float width)
|
|
0 commit comments