2020-08-29 21:15:54 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using MelonLoader;
|
|
|
|
|
|
|
|
|
|
namespace Explorer
|
|
|
|
|
{
|
|
|
|
|
public class CacheMethod : CacheObjectBase
|
|
|
|
|
{
|
|
|
|
|
private CacheObjectBase m_cachedReturnValue;
|
|
|
|
|
|
|
|
|
|
public static bool CanEvaluate(MethodInfo mi)
|
|
|
|
|
{
|
2020-09-07 17:05:37 +10:00
|
|
|
|
// TODO generic args
|
2020-08-30 01:08:48 +10:00
|
|
|
|
if (mi.GetGenericArguments().Length > 0)
|
2020-08-29 21:15:54 +10:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 17:05:37 +10:00
|
|
|
|
// primitive and string args supported
|
2020-09-09 19:15:47 +10:00
|
|
|
|
return CanProcessArgs(mi.GetParameters());
|
2020-08-29 21:15:54 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UpdateValue()
|
|
|
|
|
{
|
2020-08-31 18:23:19 +10:00
|
|
|
|
//base.UpdateValue();
|
2020-09-07 17:05:37 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-09 19:15:47 +10:00
|
|
|
|
public void Evaluate()
|
2020-09-07 17:05:37 +10:00
|
|
|
|
{
|
2020-09-09 19:15:47 +10:00
|
|
|
|
m_isEvaluating = false;
|
2020-09-07 17:05:37 +10:00
|
|
|
|
|
2020-09-09 19:15:47 +10:00
|
|
|
|
var mi = MemInfo as MethodInfo;
|
2020-09-07 17:05:37 +10:00
|
|
|
|
object ret = null;
|
|
|
|
|
|
|
|
|
|
if (!HasParameters)
|
|
|
|
|
{
|
|
|
|
|
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, new object[0]);
|
|
|
|
|
m_evaluated = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-09-10 18:02:41 +10:00
|
|
|
|
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, ParseArguments());
|
2020-09-07 17:05:37 +10:00
|
|
|
|
m_evaluated = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
MelonLogger.Log($"Exception evaluating: {e.GetType()}, {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret != null)
|
|
|
|
|
{
|
|
|
|
|
m_cachedReturnValue = GetCacheObject(ret);
|
|
|
|
|
m_cachedReturnValue.UpdateValue();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_cachedReturnValue = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==== GUI DRAW ====
|
2020-08-30 01:08:48 +10:00
|
|
|
|
|
2020-08-30 07:01:13 +10:00
|
|
|
|
public override void DrawValue(Rect window, float width)
|
2020-08-29 21:15:54 +10:00
|
|
|
|
{
|
|
|
|
|
if (m_evaluated)
|
|
|
|
|
{
|
|
|
|
|
if (m_cachedReturnValue != null)
|
|
|
|
|
{
|
2020-09-07 17:05:37 +10:00
|
|
|
|
m_cachedReturnValue.DrawValue(window, width);
|
2020-08-29 21:15:54 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-14 20:25:38 +10:00
|
|
|
|
GUILayout.Label($"null (<color=#2df7b2>{ValueTypeName}</color>)", null);
|
2020-08-29 21:15:54 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-14 20:25:38 +10:00
|
|
|
|
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color=#2df7b2>{ValueTypeName}</color>)", null);
|
2020-08-29 21:15:54 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|