From bacac929e92221174401f483de0df43a680d6dce Mon Sep 17 00:00:00 2001
From: Sinai <49360850+sinai-dev@users.noreply.github.com>
Date: Fri, 1 Apr 2022 18:14:50 +1100
Subject: [PATCH] Show InputField for exceptions to view/copy full exception
---
src/CacheObject/CacheConstructor.cs | 2 -
src/CacheObject/CacheField.cs | 2 -
src/CacheObject/CacheMethod.cs | 2 -
src/CacheObject/CacheObjectBase.cs | 65 +++++++++++---------
src/CacheObject/CacheProperty.cs | 2 -
src/CacheObject/IValues/InteractiveString.cs | 8 ++-
src/CacheObject/IValues/InteractiveValue.cs | 36 +++++------
src/Tests/TestClass.cs | 2 +
8 files changed, 58 insertions(+), 61 deletions(-)
diff --git a/src/CacheObject/CacheConstructor.cs b/src/CacheObject/CacheConstructor.cs
index 4f33f16..3a2e973 100644
--- a/src/CacheObject/CacheConstructor.cs
+++ b/src/CacheObject/CacheConstructor.cs
@@ -72,13 +72,11 @@ namespace UnityExplorer.CacheObject
else
ret = Activator.CreateInstance(returnType, ArgumentUtility.EmptyArgs);
- HadException = false;
LastException = null;
return ret;
}
catch (Exception ex)
{
- HadException = true;
LastException = ex;
return null;
}
diff --git a/src/CacheObject/CacheField.cs b/src/CacheObject/CacheField.cs
index e8b335c..65ee59a 100644
--- a/src/CacheObject/CacheField.cs
+++ b/src/CacheObject/CacheField.cs
@@ -32,13 +32,11 @@ namespace UnityExplorer.CacheObject
try
{
var ret = FieldInfo.GetValue(DeclaringInstance);
- HadException = false;
LastException = null;
return ret;
}
catch (Exception ex)
{
- HadException = true;
LastException = ex;
return null;
}
diff --git a/src/CacheObject/CacheMethod.cs b/src/CacheObject/CacheMethod.cs
index 77c2165..decae29 100644
--- a/src/CacheObject/CacheMethod.cs
+++ b/src/CacheObject/CacheMethod.cs
@@ -45,13 +45,11 @@ namespace UnityExplorer.CacheObject
ret = methodInfo.Invoke(DeclaringInstance, Evaluator.TryParseArguments());
else
ret = methodInfo.Invoke(DeclaringInstance, ArgumentUtility.EmptyArgs);
- HadException = false;
LastException = null;
return ret;
}
catch (Exception ex)
{
- HadException = true;
LastException = ex;
return null;
}
diff --git a/src/CacheObject/CacheObjectBase.cs b/src/CacheObject/CacheObjectBase.cs
index 1e1e980..764f081 100644
--- a/src/CacheObject/CacheObjectBase.cs
+++ b/src/CacheObject/CacheObjectBase.cs
@@ -57,7 +57,6 @@ namespace UnityExplorer.CacheObject
public abstract bool ShouldAutoEvaluate { get; }
public abstract bool HasArguments { get; }
public abstract bool CanWrite { get; }
- public bool HadException { get; protected set; }
public Exception LastException { get; protected set; }
public virtual void SetFallbackType(Type fallbackType)
@@ -106,8 +105,8 @@ namespace UnityExplorer.CacheObject
if (CellView != null)
SetDataToCell(CellView);
- // If the owner's parent CacheObject is set, we are setting the value of an inspected struct.
- // Set the inspector target as the value back to that parent cacheobject.
+ // If the owner's ParentCacheObject is set, we are setting the value of an inspected struct.
+ // Set the inspector target as the value back to that parent.
if (Owner.ParentCacheObject != null)
Owner.ParentCacheObject.SetUserValue(Owner.Target);
}
@@ -137,7 +136,7 @@ namespace UnityExplorer.CacheObject
{
var prevState = State;
- if (HadException)
+ if (LastException != null)
{
LastValueWasNull = true;
LastValueType = FallbackType;
@@ -158,7 +157,7 @@ namespace UnityExplorer.CacheObject
{
// If we changed states (always needs IValue change)
// or if the value is null, and the fallback type isnt string (we always want to edit strings).
- if (State != prevState || (State != ValueState.String && Value.IsNullOrDestroyed()))
+ if (State != prevState || (State != ValueState.String && State != ValueState.Exception && Value.IsNullOrDestroyed()))
{
// need to return IValue
ReleaseIValue();
@@ -206,7 +205,7 @@ namespace UnityExplorer.CacheObject
return $"{NOT_YET_EVAL} ({SignatureHighlighter.Parse(FallbackType, true)})";
case ValueState.Exception:
- return $"{LastException.ReflectionExToString()}";
+ return $"{LastException.ReflectionExToString()}";
// bool and number dont want the label for the value at all
case ValueState.Boolean:
@@ -291,36 +290,36 @@ namespace UnityExplorer.CacheObject
switch (State)
{
case ValueState.Exception:
- SetValueState(cell, ValueStateArgs.Default);
+ SetValueState(cell, new(true, subContentButtonActive: true));
break;
case ValueState.Boolean:
- SetValueState(cell, new ValueStateArgs(false, toggleActive: true, applyActive: CanWrite));
+ SetValueState(cell, new(false, toggleActive: true, applyActive: CanWrite));
break;
case ValueState.Number:
- SetValueState(cell, new ValueStateArgs(false, typeLabelActive: true, inputActive: true, applyActive: CanWrite));
+ SetValueState(cell, new(false, typeLabelActive: true, inputActive: true, applyActive: CanWrite));
break;
case ValueState.String:
if (LastValueWasNull)
- SetValueState(cell, new ValueStateArgs(true, subContentButtonActive: true));
+ SetValueState(cell, new(true, subContentButtonActive: true));
else
- SetValueState(cell, new ValueStateArgs(true, false, SignatureHighlighter.StringOrange, subContentButtonActive: true));
+ SetValueState(cell, new(true, false, SignatureHighlighter.StringOrange, subContentButtonActive: true));
break;
case ValueState.Enum:
- SetValueState(cell, new ValueStateArgs(true, subContentButtonActive: CanWrite));
+ SetValueState(cell, new(true, subContentButtonActive: CanWrite));
break;
case ValueState.Color:
case ValueState.ValueStruct:
if (ParseUtility.CanParse(LastValueType))
- SetValueState(cell, new ValueStateArgs(false, false, null, true, false, true, CanWrite, true, true));
+ SetValueState(cell, new(false, false, null, true, false, true, CanWrite, true, true));
else
- SetValueState(cell, new ValueStateArgs(true, inspectActive: true, subContentButtonActive: true));
+ SetValueState(cell, new(true, inspectActive: true, subContentButtonActive: true));
break;
case ValueState.Collection:
case ValueState.Dictionary:
- SetValueState(cell, new ValueStateArgs(true, inspectActive: !LastValueWasNull, subContentButtonActive: !LastValueWasNull));
+ SetValueState(cell, new(true, inspectActive: !LastValueWasNull, subContentButtonActive: !LastValueWasNull));
break;
case ValueState.Unsupported:
- SetValueState(cell, new ValueStateArgs(true, inspectActive: !LastValueWasNull));
+ SetValueState(cell, new (true, inspectActive: !LastValueWasNull));
break;
}
@@ -368,8 +367,10 @@ namespace UnityExplorer.CacheObject
if (cell.InspectButton != null)
cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !LastValueWasNull);
- // allow IValue for null strings though
- cell.SubContentButton.Component.gameObject.SetActive(args.subContentButtonActive && (!LastValueWasNull || State == ValueState.String));
+ // set subcontent button if needed, and for null strings and exceptions
+ cell.SubContentButton.Component.gameObject.SetActive(
+ args.subContentButtonActive
+ && (!LastValueWasNull || State == ValueState.String || State == ValueState.Exception));
}
// CacheObjectCell Apply
@@ -401,7 +402,7 @@ namespace UnityExplorer.CacheObject
{
if (this.IValue == null)
{
- var ivalueType = InteractiveValue.GetIValueTypeForState(State);
+ Type ivalueType = InteractiveValue.GetIValueTypeForState(State);
if (ivalueType == null)
return;
@@ -455,6 +456,7 @@ namespace UnityExplorer.CacheObject
{
inactiveIValueHolder = new GameObject("Temp_IValue_Holder");
GameObject.DontDestroyOnLoad(inactiveIValueHolder);
+ inactiveIValueHolder.hideFlags = HideFlags.HideAndDontSave;
inactiveIValueHolder.transform.parent = UniversalUI.PoolHolder.transform;
inactiveIValueHolder.SetActive(false);
}
@@ -467,9 +469,20 @@ namespace UnityExplorer.CacheObject
public struct ValueStateArgs
{
- public ValueStateArgs(bool valueActive = true, bool valueRichText = true, Color? valueColor = null,
- bool typeLabelActive = false, bool toggleActive = false, bool inputActive = false, bool applyActive = false,
- bool inspectActive = false, bool subContentButtonActive = false)
+ public static ValueStateArgs Default { get; } = new(true);
+
+ public Color valueColor;
+ public bool valueActive, valueRichText, typeLabelActive, toggleActive, inputActive, applyActive, inspectActive, subContentButtonActive;
+
+ public ValueStateArgs(bool valueActive = true,
+ bool valueRichText = true,
+ Color? valueColor = null,
+ bool typeLabelActive = false,
+ bool toggleActive = false,
+ bool inputActive = false,
+ bool applyActive = false,
+ bool inspectActive = false,
+ bool subContentButtonActive = false)
{
this.valueActive = valueActive;
this.valueRichText = valueRichText;
@@ -481,14 +494,6 @@ namespace UnityExplorer.CacheObject
this.inspectActive = inspectActive;
this.subContentButtonActive = subContentButtonActive;
}
-
- public static ValueStateArgs Default => _default;
- private static ValueStateArgs _default = new ValueStateArgs(true);
-
- public bool valueActive, valueRichText, typeLabelActive, toggleActive,
- inputActive, applyActive, inspectActive, subContentButtonActive;
-
- public Color valueColor;
}
}
}
diff --git a/src/CacheObject/CacheProperty.cs b/src/CacheObject/CacheProperty.cs
index d4c9569..b15f12d 100644
--- a/src/CacheObject/CacheProperty.cs
+++ b/src/CacheObject/CacheProperty.cs
@@ -40,13 +40,11 @@ namespace UnityExplorer.CacheObject
ret = PropertyInfo.GetValue(DeclaringInstance, this.Evaluator.TryParseArguments());
else
ret = PropertyInfo.GetValue(DeclaringInstance, null);
- HadException = false;
LastException = null;
return ret;
}
catch (Exception ex)
{
- HadException = true;
LastException = ex;
return null;
}
diff --git a/src/CacheObject/IValues/InteractiveString.cs b/src/CacheObject/IValues/InteractiveString.cs
index ee96a6f..7f3f817 100644
--- a/src/CacheObject/IValues/InteractiveString.cs
+++ b/src/CacheObject/IValues/InteractiveString.cs
@@ -31,8 +31,9 @@ namespace UnityExplorer.CacheObject.IValues
{
base.OnBorrowed(owner);
- inputField.Component.readOnly = !owner.CanWrite;
- ApplyButton.Component.gameObject.SetActive(owner.CanWrite);
+ bool canWrite = owner.CanWrite && owner.State != ValueState.Exception;
+ inputField.Component.readOnly = !canWrite;
+ ApplyButton.Component.gameObject.SetActive(canWrite);
SaveFilePath.Text = Path.Combine(ConfigManager.Default_Output_Path.Value, "untitled.txt");
}
@@ -47,6 +48,9 @@ namespace UnityExplorer.CacheObject.IValues
public override void SetValue(object value)
{
+ if (CurrentOwner.State == ValueState.Exception)
+ value = CurrentOwner.LastException.ToString();
+
RealValue = value as string;
SaveFileRow.SetActive(IsStringTooLong(RealValue));
diff --git a/src/CacheObject/IValues/InteractiveValue.cs b/src/CacheObject/IValues/InteractiveValue.cs
index 0b98c8b..334cec1 100644
--- a/src/CacheObject/IValues/InteractiveValue.cs
+++ b/src/CacheObject/IValues/InteractiveValue.cs
@@ -16,22 +16,16 @@ namespace UnityExplorer.CacheObject.IValues
{
public static Type GetIValueTypeForState(ValueState state)
{
- switch (state)
+ return state switch
{
- case ValueState.String:
- return typeof(InteractiveString);
- case ValueState.Enum:
- return typeof(InteractiveEnum);
- case ValueState.Collection:
- return typeof(InteractiveList);
- case ValueState.Dictionary:
- return typeof(InteractiveDictionary);
- case ValueState.ValueStruct:
- return typeof(InteractiveValueStruct);
- case ValueState.Color:
- return typeof(InteractiveColor);
- default: return null;
- }
+ ValueState.Exception or ValueState.String => typeof(InteractiveString),
+ ValueState.Enum => typeof(InteractiveEnum),
+ ValueState.Collection => typeof(InteractiveList),
+ ValueState.Dictionary => typeof(InteractiveDictionary),
+ ValueState.ValueStruct => typeof(InteractiveValueStruct),
+ ValueState.Color => typeof(InteractiveColor),
+ _ => null,
+ };
}
public GameObject UIRoot { get; set; }
@@ -39,28 +33,28 @@ namespace UnityExplorer.CacheObject.IValues
public virtual bool CanWrite => this.CurrentOwner.CanWrite;
- public CacheObjectBase CurrentOwner => m_owner;
- private CacheObjectBase m_owner;
+ public CacheObjectBase CurrentOwner => owner;
+ private CacheObjectBase owner;
public bool PendingValueWanted;
public virtual void OnBorrowed(CacheObjectBase owner)
{
- if (this.m_owner != null)
+ if (this.owner != null)
{
ExplorerCore.LogWarning("Setting an IValue's owner but there is already one set. Maybe it wasn't cleaned up?");
ReleaseFromOwner();
}
- this.m_owner = owner;
+ this.owner = owner;
}
public virtual void ReleaseFromOwner()
{
- if (this.m_owner == null)
+ if (this.owner == null)
return;
- this.m_owner = null;
+ this.owner = null;
}
public abstract void SetValue(object value);
diff --git a/src/Tests/TestClass.cs b/src/Tests/TestClass.cs
index e0dc1b6..776b2e5 100644
--- a/src/Tests/TestClass.cs
+++ b/src/Tests/TestClass.cs
@@ -28,6 +28,8 @@ namespace UnityExplorer.Tests
public static object LiterallyAnything = null;
+ public static string Exception => throw new Exception("This is a test.");
+
// Test enumerables
public static int[,,] MultiDimensionalArray = new int[45, 45, 45];
public static List