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

Commit

Permalink
a few tidy ups
Browse files Browse the repository at this point in the history
  • Loading branch information
sinai-dev committed Sep 7, 2020
1 parent c228d29 commit 4aefe1c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
46 changes: 23 additions & 23 deletions src/CachedObjects/Object/CacheDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ private IDictionary Il2CppDictionaryToMono()
{
// 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);
Expand All @@ -68,27 +64,15 @@ private IDictionary Il2CppDictionaryToMono()
var keyList = new List<object>();
var valueList = new List<object>();

// 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]);
Expand All @@ -97,6 +81,22 @@ private IDictionary Il2CppDictionaryToMono()
return dict;
}

private void EnumerateWithReflection(object collection, List<object> 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)
Expand Down
2 changes: 1 addition & 1 deletion src/CachedObjects/Other/CacheOther.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override void DrawValue(Rect window, float width)
}

GUI.skin.button.alignment = TextAnchor.MiddleLeft;
if (GUILayout.Button("<color=yellow>" + label + "</color>", new GUILayoutOption[] { GUILayout.Width(width) }))
if (GUILayout.Button("<color=yellow>" + label + "</color>", new GUILayoutOption[] { GUILayout.Width(width - 15) }))
{
WindowManager.InspectObject(Value, out bool _);
}
Expand Down
10 changes: 2 additions & 8 deletions src/UnstripFixes/GUIUnstrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ private static GenericStack ScrollStack
}
}
private static PropertyInfo m_scrollViewStatesInfo;

// ======= public methods ======= //


public static Rect GetLastRect()
{
Expand Down Expand Up @@ -73,7 +72,6 @@ public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] o
catch
{
ScrollFailed = true;
return scroll;
}
}

Expand All @@ -86,10 +84,8 @@ public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] o
}
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;
}
}

Expand All @@ -113,8 +109,6 @@ public static void EndScrollView(bool handleScrollWheel = true)
}
}

// ======= private methods ======= //

private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical,
GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options)
{
Expand Down

0 comments on commit 4aefe1c

Please sign in to comment.