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

Commit

Permalink
1.6.1
Browse files Browse the repository at this point in the history
* Fix for when inspected object gets destroyed
* Fix for displaying Dictionaries/Lists nested inside a Dictionary
* Cleanups
  • Loading branch information
sinai-dev committed Sep 7, 2020
1 parent 4e8b84b commit 72d31ea
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 164 deletions.
5 changes: 2 additions & 3 deletions src/CachedObjects/CacheObjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ public abstract class CacheObjectBase
public string ValueTypeName;
public Type ValueType;

// Reflection Inspector only
public MemberInfo MemInfo { get; set; }
public Type DeclaringType { get; set; }
public object DeclaringInstance { get; set; }
public string ReflectionException { get; set; }

public int PropertyIndex { get; private set; }
private string m_propertyIndexInput = "0";

public string ReflectionException { get; set; }

public string RichTextName => m_richTextName ?? GetRichTextName();
private string m_richTextName;

Expand Down
63 changes: 27 additions & 36 deletions src/CachedObjects/Object/CacheDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace Explorer
{
public class CacheDictionary : CacheObjectBase
public class CacheDictionary : CacheObjectBase, IExpandHeight
{
public bool IsExpanded { get; set; }
public PageHelper Pages = new PageHelper();
public float WhiteSpace { get; set; } = 215f;
public float ButtonWidthOffset { get; set; } = 290f;

public float WhiteSpace = 215f;
public float ButtonWidthOffset = 290f;
public PageHelper Pages = new PageHelper();

private CacheObjectBase[] m_cachedKeys;
private CacheObjectBase[] m_cachedValues;
Expand Down Expand Up @@ -48,6 +48,8 @@ public IDictionary IDict
}
private IDictionary m_iDictionary;

// ========== Methods ==========

// This is a bit janky due to Il2Cpp Dictionary not implementing IDictionary.
private IDictionary Il2CppDictionaryToMono()
{
Expand Down Expand Up @@ -94,43 +96,36 @@ private IDictionary Il2CppDictionaryToMono()
return dict;
}

// ========== Methods ==========

private void GetGenericArguments()
{
if (m_keysType == null || m_valuesType == null)
if (this.MemInfo != null)
{
if (this.MemInfo != null)
Type memberType = null;
switch (this.MemInfo.MemberType)
{
Type memberType = null;
switch (this.MemInfo.MemberType)
{
case MemberTypes.Field:
memberType = (MemInfo as FieldInfo).FieldType;
break;
case MemberTypes.Property:
memberType = (MemInfo as PropertyInfo).PropertyType;
break;
}
case MemberTypes.Field:
memberType = (MemInfo as FieldInfo).FieldType;
break;
case MemberTypes.Property:
memberType = (MemInfo as PropertyInfo).PropertyType;
break;
}

if (memberType != null && memberType.IsGenericType)
{
m_keysType = memberType.GetGenericArguments()[0];
m_valuesType = memberType.GetGenericArguments()[1];
}
if (memberType != null && memberType.IsGenericType)
{
m_keysType = memberType.GetGenericArguments()[0];
m_valuesType = memberType.GetGenericArguments()[1];
}
else if (Value != null)
}
else if (Value != null)
{
var type = Value.GetType();
if (type.IsGenericType)
{
var type = Value.GetType();
if (type.IsGenericType)
{
m_keysType = type.GetGenericArguments()[0];
m_valuesType = type.GetGenericArguments()[1];
}
m_keysType = type.GetGenericArguments()[0];
m_valuesType = type.GetGenericArguments()[1];
}
}

return;
}

public override void UpdateValue()
Expand Down Expand Up @@ -258,15 +253,11 @@ public override void DrawValue(Rect window, float width)
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });

GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.MinWidth((window.width / 3) - 60f) });
GUILayout.Label("Key:", new GUILayoutOption[] { GUILayout.Width(40) });
key.DrawValue(window, (window.width / 2) - 30f);
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal(null);
GUILayout.Label("Value:", new GUILayoutOption[] { GUILayout.Width(40) });
val.DrawValue(window, (window.width / 2) - 30f);
GUILayout.EndHorizontal();
}

}
Expand Down
9 changes: 5 additions & 4 deletions src/CachedObjects/Object/CacheList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

namespace Explorer
{
public class CacheList : CacheObjectBase
public class CacheList : CacheObjectBase, IExpandHeight
{
public bool IsExpanded { get; set; }
public PageHelper Pages = new PageHelper();
public float WhiteSpace { get; set; } = 215f;
public float ButtonWidthOffset { get; set; } = 290f;

public float WhiteSpace = 215f;
public float ButtonWidthOffset = 290f;
public PageHelper Pages = new PageHelper();

private CacheObjectBase[] m_cachedEntries;

Expand Down Expand Up @@ -52,6 +52,7 @@ public PropertyInfo ItemProperty
{
get => GetItemProperty();
}

private PropertyInfo m_itemProperty;

// ========== Methods ==========
Expand Down
183 changes: 82 additions & 101 deletions src/CachedObjects/Other/CacheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,17 @@ public class CacheMethod : CacheObjectBase
private ParameterInfo[] m_arguments;
private string[] m_argumentInput;

public bool HasParameters
{
get
{
if (m_hasParams == null)
{
m_hasParams = (MemInfo as MethodInfo).GetParameters().Length > 0;
}
return (bool)m_hasParams;
}
}
private bool? m_hasParams;
public bool HasParameters => m_arguments != null && m_arguments.Length > 0;

public static bool CanEvaluate(MethodInfo mi)
{
// generic type args not supported yet
// TODO generic args
if (mi.GetGenericArguments().Length > 0)
{
return false;
}

// only primitive and string args supported
// primitive and string args supported
foreach (var param in mi.GetParameters())
{
if (!param.ParameterType.IsPrimitive && param.ParameterType != typeof(string))
Expand All @@ -64,7 +53,84 @@ public override void Init()
public override void UpdateValue()
{
//base.UpdateValue();
}
}

private void Evaluate()
{
var mi = MemInfo as MethodInfo;

object ret = null;

if (!HasParameters)
{
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, new object[0]);
m_evaluated = true;
}
else
{
var parsedArgs = new List<object>();
for (int i = 0; i < m_arguments.Length; i++)
{
var input = m_argumentInput[i];
var type = m_arguments[i].ParameterType;

if (type == typeof(string))
{
parsedArgs.Add(input);
}
else
{
try
{
if (type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input }) is object parsed)
{
parsedArgs.Add(parsed);
}
else
{
// try add a null arg i guess
parsedArgs.Add(null);
}

}
catch
{
MelonLogger.Log($"Unable to parse '{input}' to type '{type.Name}'");
break;
}
}
}

try
{
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, parsedArgs.ToArray());
m_evaluated = true;
}
catch (Exception e)
{
MelonLogger.Log($"Exception evaluating: {e.GetType()}, {e.Message}");
}
}

if (ret != null)
{
m_cachedReturnValue = GetCacheObject(ret);

if (m_cachedReturnValue is IExpandHeight expander)
{
expander.WhiteSpace = 0f;
expander.ButtonWidthOffset += 70f;
}

m_cachedReturnValue.UpdateValue();
}
else
{
m_cachedReturnValue = null;
}
}

// ==== GUI DRAW ====

public override void DrawValue(Rect window, float width)
{
Expand Down Expand Up @@ -124,15 +190,7 @@ public override void DrawValue(Rect window, float width)
{
if (m_cachedReturnValue != null)
{
try
{
m_cachedReturnValue.DrawValue(window, width);
}
catch (Exception e)
{
MelonLogger.Log("Exception drawing m_cachedReturnValue!");
MelonLogger.Log(e.ToString());
}
m_cachedReturnValue.DrawValue(window, width);
}
else
{
Expand All @@ -147,82 +205,5 @@ public override void DrawValue(Rect window, float width)

GUILayout.EndVertical();
}

private void Evaluate()
{
var mi = MemInfo as MethodInfo;

object ret = null;

if (!HasParameters)
{
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, new object[0]);
m_evaluated = true;
}
else
{
var arguments = new List<object>();
for (int i = 0; i < m_arguments.Length; i++)
{
var input = m_argumentInput[i];
var type = m_arguments[i].ParameterType;

if (type == typeof(string))
{
arguments.Add(input);
}
else
{
try
{
if (type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input }) is object parsed)
{
arguments.Add(parsed);
}
else
{
throw new Exception();
}

}
catch
{
MelonLogger.Log($"Unable to parse '{input}' to type '{type.Name}'");
break;
}
}
}

if (arguments.Count == m_arguments.Length)
{
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, arguments.ToArray());
m_evaluated = true;
}
else
{
MelonLogger.Log($"Did not invoke because {m_arguments.Length - arguments.Count} arguments could not be parsed!");
}
}

if (ret != null)
{
m_cachedReturnValue = GetCacheObject(ret);
if (m_cachedReturnValue is CacheList cacheList)
{
cacheList.WhiteSpace = 0f;
cacheList.ButtonWidthOffset += 70f;
}
else if (m_cachedReturnValue is CacheDictionary cacheDict)
{
cacheDict.WhiteSpace = 0f;
cacheDict.ButtonWidthOffset += 70f;
}
m_cachedReturnValue.UpdateValue();
}
else
{
m_cachedReturnValue = null;
}
}
}
}
2 changes: 1 addition & 1 deletion src/CppExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Explorer
public class CppExplorer : MelonMod
{
public const string GUID = "com.sinai.cppexplorer";
public const string VERSION = "1.6.0";
public const string VERSION = "1.6.1";
public const string AUTHOR = "Sinai";

public const string NAME = "CppExplorer"
Expand Down
1 change: 1 addition & 0 deletions src/CppExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Helpers\IExpandHeight.cs" />
<Compile Include="CachedObjects\Struct\CacheColor.cs" />
<Compile Include="CachedObjects\Object\CacheDictionary.cs" />
<Compile Include="CachedObjects\Struct\CacheEnum.cs" />
Expand Down
Loading

0 comments on commit 72d31ea

Please sign in to comment.