1.5.6 hotfix

* Fix for setting CacheColor value
* Cleanup
This commit is contained in:
sinaioutlander 2020-09-05 23:10:50 +10:00
parent a236b272c1
commit bb8837d58c
5 changed files with 28 additions and 62 deletions

View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Explorer.CachedObjects;
using MelonLoader; using MelonLoader;
using UnhollowerBaseLib; using UnhollowerBaseLib;
using UnityEngine; using UnityEngine;

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
namespace Explorer.CachedObjects namespace Explorer
{ {
public class CacheColor : CacheObjectBase public class CacheColor : CacheObjectBase
{ {
@ -79,7 +79,8 @@ namespace Explorer.CachedObjects
&& float.TryParse(b, out float fB) && float.TryParse(b, out float fB)
&& float.TryParse(a, out float fA)) && float.TryParse(a, out float fA))
{ {
Value = new Color(fR, fB, fG, fA); Value = new Color(fR, fB, fG, fA);
SetValue();
} }
} }
} }

View File

@ -8,7 +8,7 @@ namespace Explorer
{ {
public class CachePrimitive : CacheObjectBase public class CachePrimitive : CacheObjectBase
{ {
public enum PrimitiveTypes public enum Types
{ {
Bool, Bool,
Double, Double,
@ -20,20 +20,9 @@ namespace Explorer
private string m_valueToString; private string m_valueToString;
public PrimitiveTypes PrimitiveType; public Types PrimitiveType;
public MethodInfo ParseMethod
{
get
{
if (m_parseMethod == null)
{
m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) });
}
return m_parseMethod;
}
}
public MethodInfo ParseMethod => m_parseMethod ?? (m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) }));
private MethodInfo m_parseMethod; private MethodInfo m_parseMethod;
public override void Init() public override void Init()
@ -41,58 +30,39 @@ namespace Explorer
if (Value == null) if (Value == null)
{ {
// this must mean it is a string. No other primitive type should be nullable. // this must mean it is a string. No other primitive type should be nullable.
PrimitiveType = PrimitiveTypes.String; PrimitiveType = Types.String;
return; return;
} }
m_valueToString = Value.ToString(); m_valueToString = Value.ToString();
var type = Value.GetType();
var type = Value.GetType();
if (type == typeof(bool)) if (type == typeof(bool))
{ {
PrimitiveType = PrimitiveTypes.Bool; PrimitiveType = Types.Bool;
} }
else if (type == typeof(double)) else if (type == typeof(double))
{ {
PrimitiveType = PrimitiveTypes.Double; PrimitiveType = Types.Double;
} }
else if (type == typeof(float)) else if (type == typeof(float))
{ {
PrimitiveType = PrimitiveTypes.Float; PrimitiveType = Types.Float;
}
else if (IsInteger(type))
{
PrimitiveType = PrimitiveTypes.Int;
} }
else if (type == typeof(char)) else if (type == typeof(char))
{ {
PrimitiveType = PrimitiveTypes.Char; PrimitiveType = Types.Char;
}
else if (typeof(int).IsAssignableFrom(type))
{
PrimitiveType = Types.Int;
} }
else 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<Type> _integerTypes = new HashSet<Type>
{
typeof(int),
typeof(uint),
typeof(short),
typeof(ushort),
typeof(long),
typeof(ulong),
typeof(byte),
typeof(sbyte),
typeof(IntPtr)
};
public override void UpdateValue() public override void UpdateValue()
{ {
base.UpdateValue(); base.UpdateValue();
@ -102,11 +72,10 @@ namespace Explorer
public override void DrawValue(Rect window, float width) public override void DrawValue(Rect window, float width)
{ {
if (PrimitiveType == PrimitiveTypes.Bool) if (PrimitiveType == Types.Bool)
{ {
var b = (bool)Value; var b = (bool)Value;
var color = $"<color={(b ? "lime>" : "red>")}"; var label = $"<color={(b ? "lime" : "red")}>{b}</color>";
var label = $"{color}{b}</color>";
if (CanWrite) if (CanWrite)
{ {
@ -150,7 +119,7 @@ namespace Explorer
} }
} }
public void SetValueFromInput(string value) public void SetValueFromInput(string valueString)
{ {
if (MemInfo == null) if (MemInfo == null)
{ {
@ -158,16 +127,15 @@ namespace Explorer
return; return;
} }
if (PrimitiveType == PrimitiveTypes.String) if (PrimitiveType == Types.String)
{ {
Value = value; Value = valueString;
} }
else else
{ {
try try
{ {
var val = ParseMethod.Invoke(null, new object[] { value }); Value = ParseMethod.Invoke(null, new object[] { valueString });
Value = val;
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -9,8 +9,6 @@ namespace Explorer
{ {
public class CacheQuaternion : CacheObjectBase public class CacheQuaternion : CacheObjectBase
{ {
private Vector3 EulerAngle = Vector3.zero;
private string x = "0"; private string x = "0";
private string y = "0"; private string y = "0";
private string z = "0"; private string z = "0";
@ -19,11 +17,11 @@ namespace Explorer
{ {
base.UpdateValue(); base.UpdateValue();
EulerAngle = ((Quaternion)Value).eulerAngles; var euler = ((Quaternion)Value).eulerAngles;
x = EulerAngle.x.ToString(); x = euler.x.ToString();
y = EulerAngle.y.ToString(); y = euler.y.ToString();
z = EulerAngle.z.ToString(); z = euler.z.ToString();
} }
public override void DrawValue(Rect window, float width) public override void DrawValue(Rect window, float width)

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
namespace Explorer.CachedObjects namespace Explorer
{ {
public class CacheRect : CacheObjectBase public class CacheRect : CacheObjectBase
{ {