Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit bb8837d

Browse files
committed
1.5.6 hotfix
* Fix for setting CacheColor value * Cleanup
1 parent a236b27 commit bb8837d

File tree

5 files changed

+27
-61
lines changed

5 files changed

+27
-61
lines changed

src/CachedObjects/CacheObjectBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Reflection;
55
using System.Text;
66
using System.Threading.Tasks;
7-
using Explorer.CachedObjects;
87
using MelonLoader;
98
using UnhollowerBaseLib;
109
using UnityEngine;

src/CachedObjects/Struct/CacheColor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading.Tasks;
66
using UnityEngine;
77

8-
namespace Explorer.CachedObjects
8+
namespace Explorer
99
{
1010
public class CacheColor : CacheObjectBase
1111
{
@@ -79,7 +79,8 @@ private void SetValueFromInput()
7979
&& float.TryParse(b, out float fB)
8080
&& float.TryParse(a, out float fA))
8181
{
82-
Value = new Color(fR, fB, fG, fA);
82+
Value = new Color(fR, fB, fG, fA);
83+
SetValue();
8384
}
8485
}
8586
}

src/CachedObjects/Struct/CachePrimitive.cs

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Explorer
88
{
99
public class CachePrimitive : CacheObjectBase
1010
{
11-
public enum PrimitiveTypes
11+
public enum Types
1212
{
1313
Bool,
1414
Double,
@@ -20,79 +20,49 @@ public enum PrimitiveTypes
2020

2121
private string m_valueToString;
2222

23-
public PrimitiveTypes PrimitiveType;
24-
25-
public MethodInfo ParseMethod
26-
{
27-
get
28-
{
29-
if (m_parseMethod == null)
30-
{
31-
m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) });
32-
}
33-
return m_parseMethod;
34-
}
35-
}
23+
public Types PrimitiveType;
3624

25+
public MethodInfo ParseMethod => m_parseMethod ?? (m_parseMethod = Value.GetType().GetMethod("Parse", new Type[] { typeof(string) }));
3726
private MethodInfo m_parseMethod;
3827

3928
public override void Init()
4029
{
4130
if (Value == null)
4231
{
4332
// this must mean it is a string. No other primitive type should be nullable.
44-
PrimitiveType = PrimitiveTypes.String;
33+
PrimitiveType = Types.String;
4534
return;
4635
}
4736

4837
m_valueToString = Value.ToString();
49-
var type = Value.GetType();
5038

39+
var type = Value.GetType();
5140
if (type == typeof(bool))
5241
{
53-
PrimitiveType = PrimitiveTypes.Bool;
42+
PrimitiveType = Types.Bool;
5443
}
5544
else if (type == typeof(double))
5645
{
57-
PrimitiveType = PrimitiveTypes.Double;
46+
PrimitiveType = Types.Double;
5847
}
5948
else if (type == typeof(float))
6049
{
61-
PrimitiveType = PrimitiveTypes.Float;
50+
PrimitiveType = Types.Float;
6251
}
63-
else if (IsInteger(type))
52+
else if (type == typeof(char))
6453
{
65-
PrimitiveType = PrimitiveTypes.Int;
54+
PrimitiveType = Types.Char;
6655
}
67-
else if (type == typeof(char))
56+
else if (typeof(int).IsAssignableFrom(type))
6857
{
69-
PrimitiveType = PrimitiveTypes.Char;
58+
PrimitiveType = Types.Int;
7059
}
7160
else
7261
{
73-
PrimitiveType = PrimitiveTypes.String;
62+
PrimitiveType = Types.String;
7463
}
7564
}
7665

77-
private static bool IsInteger(Type type)
78-
{
79-
// For our purposes, all types of int can be treated the same, including IntPtr.
80-
return _integerTypes.Contains(type);
81-
}
82-
83-
private static readonly HashSet<Type> _integerTypes = new HashSet<Type>
84-
{
85-
typeof(int),
86-
typeof(uint),
87-
typeof(short),
88-
typeof(ushort),
89-
typeof(long),
90-
typeof(ulong),
91-
typeof(byte),
92-
typeof(sbyte),
93-
typeof(IntPtr)
94-
};
95-
9666
public override void UpdateValue()
9767
{
9868
base.UpdateValue();
@@ -102,11 +72,10 @@ public override void UpdateValue()
10272

10373
public override void DrawValue(Rect window, float width)
10474
{
105-
if (PrimitiveType == PrimitiveTypes.Bool)
75+
if (PrimitiveType == Types.Bool)
10676
{
10777
var b = (bool)Value;
108-
var color = $"<color={(b ? "lime>" : "red>")}";
109-
var label = $"{color}{b}</color>";
78+
var label = $"<color={(b ? "lime" : "red")}>{b}</color>";
11079

11180
if (CanWrite)
11281
{
@@ -150,24 +119,23 @@ public override void DrawValue(Rect window, float width)
150119
}
151120
}
152121

153-
public void SetValueFromInput(string value)
122+
public void SetValueFromInput(string valueString)
154123
{
155124
if (MemInfo == null)
156125
{
157126
MelonLogger.Log("Trying to SetValue but the MemberInfo is null!");
158127
return;
159128
}
160129

161-
if (PrimitiveType == PrimitiveTypes.String)
130+
if (PrimitiveType == Types.String)
162131
{
163-
Value = value;
132+
Value = valueString;
164133
}
165134
else
166135
{
167136
try
168137
{
169-
var val = ParseMethod.Invoke(null, new object[] { value });
170-
Value = val;
138+
Value = ParseMethod.Invoke(null, new object[] { valueString });
171139
}
172140
catch (Exception e)
173141
{

src/CachedObjects/Struct/CacheQuaternion.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace Explorer
99
{
1010
public class CacheQuaternion : CacheObjectBase
1111
{
12-
private Vector3 EulerAngle = Vector3.zero;
13-
1412
private string x = "0";
1513
private string y = "0";
1614
private string z = "0";
@@ -19,11 +17,11 @@ public override void UpdateValue()
1917
{
2018
base.UpdateValue();
2119

22-
EulerAngle = ((Quaternion)Value).eulerAngles;
20+
var euler = ((Quaternion)Value).eulerAngles;
2321

24-
x = EulerAngle.x.ToString();
25-
y = EulerAngle.y.ToString();
26-
z = EulerAngle.z.ToString();
22+
x = euler.x.ToString();
23+
y = euler.y.ToString();
24+
z = euler.z.ToString();
2725
}
2826

2927
public override void DrawValue(Rect window, float width)

src/CachedObjects/Struct/CacheRect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading.Tasks;
66
using UnityEngine;
77

8-
namespace Explorer.CachedObjects
8+
namespace Explorer
99
{
1010
public class CacheRect : CacheObjectBase
1111
{

0 commit comments

Comments
 (0)