diff --git a/src/CachedObjects/CacheObjectBase.cs b/src/CachedObjects/CacheObjectBase.cs index 4bd06c5..1cd88fb 100644 --- a/src/CachedObjects/CacheObjectBase.cs +++ b/src/CachedObjects/CacheObjectBase.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; -using Explorer.CachedObjects; using MelonLoader; using UnhollowerBaseLib; using UnityEngine; diff --git a/src/CachedObjects/Struct/CacheColor.cs b/src/CachedObjects/Struct/CacheColor.cs index 1dec234..0e1525c 100644 --- a/src/CachedObjects/Struct/CacheColor.cs +++ b/src/CachedObjects/Struct/CacheColor.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; -namespace Explorer.CachedObjects +namespace Explorer { public class CacheColor : CacheObjectBase { @@ -79,7 +79,8 @@ namespace Explorer.CachedObjects && float.TryParse(b, out float fB) && float.TryParse(a, out float fA)) { - Value = new Color(fR, fB, fG, fA); + Value = new Color(fR, fB, fG, fA); + SetValue(); } } } diff --git a/src/CachedObjects/Struct/CachePrimitive.cs b/src/CachedObjects/Struct/CachePrimitive.cs index 4789209..374d9b5 100644 --- a/src/CachedObjects/Struct/CachePrimitive.cs +++ b/src/CachedObjects/Struct/CachePrimitive.cs @@ -8,7 +8,7 @@ namespace Explorer { public class CachePrimitive : CacheObjectBase { - public enum PrimitiveTypes + public enum Types { Bool, Double, @@ -20,20 +20,9 @@ namespace Explorer private string m_valueToString; - public PrimitiveTypes PrimitiveType; - - public MethodInfo ParseMethod - { - get - { - if (m_parseMethod == null) - { - m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) }); - } - return m_parseMethod; - } - } + public Types PrimitiveType; + public MethodInfo ParseMethod => m_parseMethod ?? (m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) })); private MethodInfo m_parseMethod; public override void Init() @@ -41,58 +30,39 @@ namespace Explorer if (Value == null) { // this must mean it is a string. No other primitive type should be nullable. - PrimitiveType = PrimitiveTypes.String; + PrimitiveType = Types.String; return; } m_valueToString = Value.ToString(); - var type = Value.GetType(); + var type = Value.GetType(); if (type == typeof(bool)) { - PrimitiveType = PrimitiveTypes.Bool; + PrimitiveType = Types.Bool; } else if (type == typeof(double)) { - PrimitiveType = PrimitiveTypes.Double; + PrimitiveType = Types.Double; } else if (type == typeof(float)) { - PrimitiveType = PrimitiveTypes.Float; - } - else if (IsInteger(type)) - { - PrimitiveType = PrimitiveTypes.Int; + PrimitiveType = Types.Float; } else if (type == typeof(char)) { - PrimitiveType = PrimitiveTypes.Char; + PrimitiveType = Types.Char; + } + else if (typeof(int).IsAssignableFrom(type)) + { + PrimitiveType = Types.Int; } else { - PrimitiveType = PrimitiveTypes.String; + PrimitiveType = Types.String; } } - private static bool IsInteger(Type type) - { - // For our purposes, all types of int can be treated the same, including IntPtr. - return _integerTypes.Contains(type); - } - - private static readonly HashSet _integerTypes = new HashSet - { - typeof(int), - typeof(uint), - typeof(short), - typeof(ushort), - typeof(long), - typeof(ulong), - typeof(byte), - typeof(sbyte), - typeof(IntPtr) - }; - public override void UpdateValue() { base.UpdateValue(); @@ -102,11 +72,10 @@ namespace Explorer public override void DrawValue(Rect window, float width) { - if (PrimitiveType == PrimitiveTypes.Bool) + if (PrimitiveType == Types.Bool) { var b = (bool)Value; - var color = $"" : "red>")}"; - var label = $"{color}{b}"; + var label = $"{b}"; if (CanWrite) { @@ -150,7 +119,7 @@ namespace Explorer } } - public void SetValueFromInput(string value) + public void SetValueFromInput(string valueString) { if (MemInfo == null) { @@ -158,16 +127,15 @@ namespace Explorer return; } - if (PrimitiveType == PrimitiveTypes.String) + if (PrimitiveType == Types.String) { - Value = value; + Value = valueString; } else { try { - var val = ParseMethod.Invoke(null, new object[] { value }); - Value = val; + Value = ParseMethod.Invoke(null, new object[] { valueString }); } catch (Exception e) { diff --git a/src/CachedObjects/Struct/CacheQuaternion.cs b/src/CachedObjects/Struct/CacheQuaternion.cs index 98e2d45..dcfcf75 100644 --- a/src/CachedObjects/Struct/CacheQuaternion.cs +++ b/src/CachedObjects/Struct/CacheQuaternion.cs @@ -9,8 +9,6 @@ namespace Explorer { public class CacheQuaternion : CacheObjectBase { - private Vector3 EulerAngle = Vector3.zero; - private string x = "0"; private string y = "0"; private string z = "0"; @@ -19,11 +17,11 @@ namespace Explorer { base.UpdateValue(); - EulerAngle = ((Quaternion)Value).eulerAngles; + var euler = ((Quaternion)Value).eulerAngles; - x = EulerAngle.x.ToString(); - y = EulerAngle.y.ToString(); - z = EulerAngle.z.ToString(); + x = euler.x.ToString(); + y = euler.y.ToString(); + z = euler.z.ToString(); } public override void DrawValue(Rect window, float width) diff --git a/src/CachedObjects/Struct/CacheRect.cs b/src/CachedObjects/Struct/CacheRect.cs index 6522907..5488432 100644 --- a/src/CachedObjects/Struct/CacheRect.cs +++ b/src/CachedObjects/Struct/CacheRect.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; -namespace Explorer.CachedObjects +namespace Explorer { public class CacheRect : CacheObjectBase {