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

Commit 4bee55f

Browse files
committed
Cleanups, remove redundancy
1 parent c71748d commit 4bee55f

File tree

4 files changed

+45
-69
lines changed

4 files changed

+45
-69
lines changed

src/CacheObject/CacheMemberFactory.cs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace UnityExplorer.CacheObject
1414
{
1515
public static class CacheMemberFactory
1616
{
17-
public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type type, ReflectionInspector inspector)
17+
public static List<CacheMember> GetCacheMembers(Type type, ReflectionInspector inspector)
1818
{
1919
//var list = new List<CacheMember>();
2020
HashSet<string> cachedSigs = new();
@@ -49,10 +49,6 @@ public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type typ
4949

5050
foreach (var declaringType in types)
5151
{
52-
var target = inspectorTarget;
53-
if (!inspector.StaticOnly)
54-
target = target.TryCast(declaringType);
55-
5652
foreach (var prop in declaringType.GetProperties(flags))
5753
if (prop.DeclaringType == declaringType)
5854
TryCacheMember(prop, props, cachedSigs, declaringType, inspector);
@@ -79,13 +75,9 @@ public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type typ
7975
return sorted;
8076
}
8177

82-
static void TryCacheMember(
83-
MemberInfo member,
84-
IList list,
85-
HashSet<string> cachedSigs,
86-
Type declaringType,
87-
ReflectionInspector inspector,
88-
bool ignorePropertyMethodInfos = true)
78+
static void TryCacheMember<T>(MemberInfo member, List<T> list, HashSet<string> cachedSigs,
79+
Type declaringType, ReflectionInspector inspector, bool ignorePropertyMethodInfos = true)
80+
where T : CacheMember
8981
{
9082
try
9183
{
@@ -94,7 +86,9 @@ static void TryCacheMember(
9486

9587
string sig = member switch
9688
{
89+
// method or constructor
9790
MethodBase mb => mb.FullDescription(),
91+
// property or field
9892
PropertyInfo or FieldInfo => $"{member.DeclaringType.FullDescription()}.{member.Name}",
9993
_ => throw new NotImplementedException(),
10094
};
@@ -164,32 +158,13 @@ static void TryCacheMember(
164158
cached.SetFallbackType(returnType);
165159
cached.SetInspectorOwner(inspector, member);
166160

167-
list.Add(cached);
161+
list.Add((T)cached);
168162
}
169163
catch (Exception e)
170164
{
171165
ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!");
172-
ExplorerCore.Log(e.ToString());
166+
ExplorerCore.Log(e);
173167
}
174168
}
175-
176-
//internal static string GetSig(MemberInfo member) => $"{member.DeclaringType.Name}.{member.Name}";
177-
//
178-
//internal static string GetArgumentString(ParameterInfo[] args)
179-
//{
180-
// var sb = new StringBuilder();
181-
// sb.Append(' ');
182-
// sb.Append('(');
183-
// foreach (var param in args)
184-
// {
185-
// sb.Append(param.ParameterType.Name);
186-
// sb.Append(' ');
187-
// sb.Append(param.Name);
188-
// sb.Append(',');
189-
// sb.Append(' ');
190-
// }
191-
// sb.Append(')');
192-
// return sb.ToString();
193-
//}
194169
}
195170
}

src/ExplorerCore.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using UnityEngine;
34
using UnityExplorer.Config;
45
using UnityExplorer.ObjectExplorer;
56
using UnityExplorer.Runtime;
67
using UnityExplorer.UI;
78
using UnityExplorer.UI.Panels;
9+
using UniverseLib;
810
using UniverseLib.Input;
911

1012
namespace UnityExplorer
@@ -26,23 +28,20 @@ public static class ExplorerCore
2628
public static void Init(IExplorerLoader loader)
2729
{
2830
if (Loader != null)
29-
{
30-
LogWarning("UnityExplorer is already loaded!");
31-
return;
32-
}
31+
throw new Exception("UnityExplorer is already loaded.");
32+
3333
Loader = loader;
3434

3535
Log($"{NAME} {VERSION} initializing...");
3636

37-
if (!Directory.Exists(Loader.ExplorerFolder))
38-
Directory.CreateDirectory(Loader.ExplorerFolder);
39-
37+
Directory.CreateDirectory(Loader.ExplorerFolder);
4038
ConfigManager.Init(Loader.ConfigHandler);
39+
4140
UERuntimeHelper.Init();
4241
ExplorerBehaviour.Setup();
4342
UnityCrashPrevention.Init();
4443

45-
UniverseLib.Universe.Init(ConfigManager.Startup_Delay_Time.Value, LateInit, Log, new()
44+
Universe.Init(ConfigManager.Startup_Delay_Time.Value, LateInit, Log, new()
4645
{
4746
Disable_EventSystem_Override = ConfigManager.Disable_EventSystem_Override.Value,
4847
Force_Unlock_Mouse = ConfigManager.Force_Unlock_Mouse.Value,
@@ -53,7 +52,7 @@ public static void Init(IExplorerLoader loader)
5352
// Do a delayed setup so that objects aren't destroyed instantly.
5453
// This can happen for a multitude of reasons.
5554
// Default delay is 1 second which is usually enough.
56-
private static void LateInit()
55+
static void LateInit()
5756
{
5857
Log($"Setting up late core features...");
5958

@@ -63,21 +62,18 @@ private static void LateInit()
6362

6463
UIManager.InitUI();
6564

66-
Log($"{NAME} {VERSION} initialized for {UniverseLib.Universe.Context}.");
65+
Log($"{NAME} {VERSION} ({Universe.Context}) initialized.");
6766

6867
//InspectorManager.Inspect(typeof(Tests.TestClass));
6968
}
7069

71-
/// <summary>
72-
/// Should be called once per frame.
73-
/// </summary>
74-
public static void Update()
70+
internal static void Update()
7571
{
76-
UIManager.Update();
77-
7872
// check master toggle
7973
if (InputManager.GetKeyDown(ConfigManager.Master_Toggle.Value))
8074
UIManager.ShowMenu = !UIManager.ShowMenu;
75+
76+
UIManager.Update();
8177
}
8278

8379
#region LOGGING

src/Inspectors/ReflectionInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void SetTarget(object target)
164164

165165
// Get cache members
166166

167-
this.members = CacheMemberFactory.GetCacheMembers(Target, TargetType, this);
167+
this.members = CacheMemberFactory.GetCacheMembers(TargetType, this);
168168

169169
// reset filters
170170

src/Tests/TestClass.cs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ static TestClass()
2424
#endif
2525
}
2626

27+
#region MONO
28+
2729
public static object LiterallyAnything = null;
2830

2931
// Test enumerables
@@ -90,12 +92,12 @@ public static void TestComponent<T>() where T : Component
9092
ExplorerCore.Log($"Test3 {typeof(T).FullName}");
9193
}
9294

93-
public static void TestArgumentParse(string _string,
94-
int integer,
95-
Color color,
96-
CameraClearFlags flags,
97-
Vector3 vector,
98-
Quaternion quaternion,
95+
public static void TestArgumentParse(string _string,
96+
int integer,
97+
Color color,
98+
CameraClearFlags flags,
99+
Vector3 vector,
100+
Quaternion quaternion,
99101
object obj,
100102
Type type,
101103
GameObject go)
@@ -145,6 +147,8 @@ private static void Init_Mono()
145147
ExplorerCore.Log("Finished TestClass Init_Mono");
146148
}
147149

150+
#endregion
151+
148152
#if CPP
149153
public static Il2CppSystem.Collections.Generic.Dictionary<string, string> IL2CPP_Dict;
150154
public static Il2CppSystem.Collections.Generic.HashSet<string> IL2CPP_HashSet;
@@ -156,7 +160,7 @@ private static void Init_Mono()
156160
public static Il2CppSystem.Collections.IDictionary IL2CPP_IDict;
157161
public static Il2CppSystem.Collections.IList IL2CPP_IList;
158162
public static Dictionary<Il2CppSystem.Object, Il2CppSystem.Object> IL2CPP_BoxedDict;
159-
163+
160164
public static Il2CppSystem.Object IL2CPP_BoxedInt;
161165
public static Il2CppSystem.Int32 IL2CPP_Int;
162166
public static Il2CppSystem.Decimal IL2CPP_Decimal;
@@ -185,31 +189,31 @@ private static void Init_IL2CPP()
185189
IL2CPP_HashTable.Add("key1", "value1");
186190
IL2CPP_HashTable.Add("key2", "value2");
187191
IL2CPP_HashTable.Add("key3", "value3");
188-
192+
189193
ExplorerCore.Log($"IL2CPP 3: Il2Cpp IDictionary");
190194
var dict2 = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
191195
dict2.Add("key1", "value1");
192196
IL2CPP_IDict = dict2.TryCast<Il2CppSystem.Collections.IDictionary>();
193-
197+
194198
ExplorerCore.Log($"IL2CPP 4: Il2Cpp List of Il2Cpp Object");
195199
var list = new Il2CppSystem.Collections.Generic.List<Il2CppSystem.Object>(5);
196200
list.Add("one");
197201
list.Add("two");
198202
IL2CPP_IList = list.TryCast<Il2CppSystem.Collections.IList>();
199-
203+
200204
ExplorerCore.Log($"IL2CPP 5: Il2Cpp List of strings");
201205
IL2CPP_ListString = new Il2CppSystem.Collections.Generic.List<string>();
202206
IL2CPP_ListString.Add("hello,");
203207
IL2CPP_ListString.Add("world!");
204-
205-
208+
209+
206210
ExplorerCore.Log($"IL2CPP 7: Dictionary of Il2Cpp String and Il2Cpp Object");
207211
IL2CPP_BoxedDict = new();
208212
IL2CPP_BoxedDict[(Il2CppSystem.String)"one"] = new Il2CppSystem.Int32 { m_value = 1 }.BoxIl2CppObject();
209213
IL2CPP_BoxedDict[(Il2CppSystem.String)"two"] = new Il2CppSystem.Int32 { m_value = 2 }.BoxIl2CppObject();
210214
IL2CPP_BoxedDict[(Il2CppSystem.String)"three"] = new Il2CppSystem.Int32 { m_value = 3 }.BoxIl2CppObject();
211215
IL2CPP_BoxedDict[(Il2CppSystem.String)"four"] = new Il2CppSystem.Int32 { m_value = 4 }.BoxIl2CppObject();
212-
216+
213217
ExplorerCore.Log($"IL2CPP 8: List of boxed Il2Cpp Objects");
214218
IL2CPP_listOfBoxedObjects = new List<Il2CppSystem.Object>();
215219
IL2CPP_listOfBoxedObjects.Add((Il2CppSystem.String)"boxedString");
@@ -224,30 +228,30 @@ private static void Init_IL2CPP()
224228
var boxedEnum = Il2CppSystem.Enum.Parse(cppType, "Color");
225229
IL2CPP_listOfBoxedObjects.Add(boxedEnum);
226230
}
227-
231+
228232
var structBox = Vector3.one.BoxIl2CppObject();
229233
IL2CPP_listOfBoxedObjects.Add(structBox);
230-
234+
231235
}
232236
catch (Exception ex)
233237
{
234238
ExplorerCore.LogWarning($"Boxed enum test fail: {ex}");
235239
}
236-
240+
237241
ExplorerCore.Log($"IL2CPP 9: Il2Cpp struct array of ints");
238242
IL2CPP_structArray = new UnhollowerBaseLib.Il2CppStructArray<int>(5);
239243
IL2CPP_structArray[0] = 0;
240244
IL2CPP_structArray[1] = 1;
241245
IL2CPP_structArray[2] = 2;
242246
IL2CPP_structArray[3] = 3;
243247
IL2CPP_structArray[4] = 4;
244-
248+
245249
ExplorerCore.Log($"IL2CPP 10: Il2Cpp reference array of boxed objects");
246250
IL2CPP_ReferenceArray = new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Object>(3);
247251
IL2CPP_ReferenceArray[0] = new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject();
248252
IL2CPP_ReferenceArray[1] = null;
249253
IL2CPP_ReferenceArray[2] = (Il2CppSystem.String)"whats up";
250-
254+
251255
ExplorerCore.Log($"IL2CPP 11: Misc il2cpp members");
252256
IL2CPP_BoxedInt = new Il2CppSystem.Int32() { m_value = 5 }.BoxIl2CppObject();
253257
IL2CPP_Int = new Il2CppSystem.Int32 { m_value = 420 };
@@ -257,6 +261,7 @@ private static void Init_IL2CPP()
257261

258262
ExplorerCore.Log($"Finished Init_Il2Cpp");
259263
}
264+
260265
#endif
261266
}
262267
}

0 commit comments

Comments
 (0)