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.Text;
using System.Threading.Tasks;
using Explorer.CachedObjects;
using MelonLoader;
using UnhollowerBaseLib;
using UnityEngine;

View File

@ -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();
}
}
}

View File

@ -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<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()
{
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 = $"<color={(b ? "lime>" : "red>")}";
var label = $"{color}{b}</color>";
var label = $"<color={(b ? "lime" : "red")}>{b}</color>";
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)
{

View File

@ -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)

View File

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