diff --git a/src/CachedObjects/Object/CacheDictionary.cs b/src/CachedObjects/Object/CacheDictionary.cs index 868e090..7623d89 100644 --- a/src/CachedObjects/Object/CacheDictionary.cs +++ b/src/CachedObjects/Object/CacheDictionary.cs @@ -56,10 +56,6 @@ namespace Explorer { // note: "ValueType" is the Dictionary itself, TypeOfValues is the 'Dictionary.Values' type. - // make generic dictionary from key and value type - var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>) - .MakeGenericType(TypeOfKeys, TypeOfValues)); - // get keys and values var keys = ValueType.GetProperty("Keys") .GetValue(Value); var values = ValueType.GetProperty("Values").GetValue(Value); @@ -68,27 +64,15 @@ namespace Explorer var keyList = new List(); var valueList = new List(); - // get keys enumerator and store keys - var keyEnumerator = keys.GetType().GetMethod("GetEnumerator").Invoke(keys, null); - var keyCollectionType = keyEnumerator.GetType(); - var keyMoveNext = keyCollectionType.GetMethod("MoveNext"); - var keyCurrent = keyCollectionType.GetProperty("Current"); - while ((bool)keyMoveNext.Invoke(keyEnumerator, null)) - { - keyList.Add(keyCurrent.GetValue(keyEnumerator)); - } + // store entries with reflection + EnumerateWithReflection(keys, keyList); + EnumerateWithReflection(values, valueList); - // get values enumerator and store values - var valueEnumerator = values.GetType().GetMethod("GetEnumerator").Invoke(values, null); - var valueCollectionType = valueEnumerator.GetType(); - var valueMoveNext = valueCollectionType.GetMethod("MoveNext"); - var valueCurrent = valueCollectionType.GetProperty("Current"); - while ((bool)valueMoveNext.Invoke(valueEnumerator, null)) - { - valueList.Add(valueCurrent.GetValue(valueEnumerator)); - } + // make actual mono dictionary + var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>) + .MakeGenericType(TypeOfKeys, TypeOfValues)); - // finally iterate into actual dictionary + // finally iterate into dictionary for (int i = 0; i < keyList.Count; i++) { dict.Add(keyList[i], valueList[i]); @@ -97,6 +81,22 @@ namespace Explorer return dict; } + private void EnumerateWithReflection(object collection, List list) + { + // invoke GetEnumerator + var enumerator = collection.GetType().GetMethod("GetEnumerator").Invoke(collection, null); + // get the type of it + var enumeratorType = enumerator.GetType(); + // reflect MoveNext and Current + var moveNext = enumeratorType.GetMethod("MoveNext"); + var current = enumeratorType.GetProperty("Current"); + // iterate + while ((bool)moveNext.Invoke(enumerator, null)) + { + list.Add(current.GetValue(enumerator)); + } + } + private void GetGenericArguments() { if (this.MemInfo != null) diff --git a/src/CachedObjects/Other/CacheOther.cs b/src/CachedObjects/Other/CacheOther.cs index b77981b..58aceb9 100644 --- a/src/CachedObjects/Other/CacheOther.cs +++ b/src/CachedObjects/Other/CacheOther.cs @@ -50,7 +50,7 @@ namespace Explorer } GUI.skin.button.alignment = TextAnchor.MiddleLeft; - if (GUILayout.Button("" + label + "", new GUILayoutOption[] { GUILayout.Width(width) })) + if (GUILayout.Button("" + label + "", new GUILayoutOption[] { GUILayout.Width(width - 15) })) { WindowManager.InspectObject(Value, out bool _); } diff --git a/src/UnstripFixes/GUIUnstrip.cs b/src/UnstripFixes/GUIUnstrip.cs index 6067a11..84fac68 100644 --- a/src/UnstripFixes/GUIUnstrip.cs +++ b/src/UnstripFixes/GUIUnstrip.cs @@ -41,8 +41,7 @@ namespace Explorer } } private static PropertyInfo m_scrollViewStatesInfo; - - // ======= public methods ======= // + public static Rect GetLastRect() { @@ -73,7 +72,6 @@ namespace Explorer catch { ScrollFailed = true; - return scroll; } } @@ -86,10 +84,8 @@ namespace Explorer } catch (Exception e) { - MelonLogger.Log("Exception on GUIUnstrip.BeginScrollView_ImplLayout: " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace); - + MelonLogger.Log("Exception on manual BeginScrollView: " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace); ManualUnstripFailed = true; - return scroll; } } @@ -113,8 +109,6 @@ namespace Explorer } } - // ======= private methods ======= // - private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options) {