Cleanups, remove redundancy

This commit is contained in:
Sinai 2022-03-29 22:36:17 +11:00
parent c71748d22a
commit 4bee55fb25
4 changed files with 45 additions and 69 deletions

View File

@ -14,7 +14,7 @@ namespace UnityExplorer.CacheObject
{ {
public static class CacheMemberFactory public static class CacheMemberFactory
{ {
public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type type, ReflectionInspector inspector) public static List<CacheMember> GetCacheMembers(Type type, ReflectionInspector inspector)
{ {
//var list = new List<CacheMember>(); //var list = new List<CacheMember>();
HashSet<string> cachedSigs = new(); HashSet<string> cachedSigs = new();
@ -49,10 +49,6 @@ namespace UnityExplorer.CacheObject
foreach (var declaringType in types) foreach (var declaringType in types)
{ {
var target = inspectorTarget;
if (!inspector.StaticOnly)
target = target.TryCast(declaringType);
foreach (var prop in declaringType.GetProperties(flags)) foreach (var prop in declaringType.GetProperties(flags))
if (prop.DeclaringType == declaringType) if (prop.DeclaringType == declaringType)
TryCacheMember(prop, props, cachedSigs, declaringType, inspector); TryCacheMember(prop, props, cachedSigs, declaringType, inspector);
@ -79,13 +75,9 @@ namespace UnityExplorer.CacheObject
return sorted; return sorted;
} }
static void TryCacheMember( static void TryCacheMember<T>(MemberInfo member, List<T> list, HashSet<string> cachedSigs,
MemberInfo member, Type declaringType, ReflectionInspector inspector, bool ignorePropertyMethodInfos = true)
IList list, where T : CacheMember
HashSet<string> cachedSigs,
Type declaringType,
ReflectionInspector inspector,
bool ignorePropertyMethodInfos = true)
{ {
try try
{ {
@ -94,7 +86,9 @@ namespace UnityExplorer.CacheObject
string sig = member switch string sig = member switch
{ {
// method or constructor
MethodBase mb => mb.FullDescription(), MethodBase mb => mb.FullDescription(),
// property or field
PropertyInfo or FieldInfo => $"{member.DeclaringType.FullDescription()}.{member.Name}", PropertyInfo or FieldInfo => $"{member.DeclaringType.FullDescription()}.{member.Name}",
_ => throw new NotImplementedException(), _ => throw new NotImplementedException(),
}; };
@ -164,32 +158,13 @@ namespace UnityExplorer.CacheObject
cached.SetFallbackType(returnType); cached.SetFallbackType(returnType);
cached.SetInspectorOwner(inspector, member); cached.SetInspectorOwner(inspector, member);
list.Add(cached); list.Add((T)cached);
} }
catch (Exception e) catch (Exception e)
{ {
ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!"); ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!");
ExplorerCore.Log(e.ToString()); ExplorerCore.Log(e);
} }
} }
//internal static string GetSig(MemberInfo member) => $"{member.DeclaringType.Name}.{member.Name}";
//
//internal static string GetArgumentString(ParameterInfo[] args)
//{
// var sb = new StringBuilder();
// sb.Append(' ');
// sb.Append('(');
// foreach (var param in args)
// {
// sb.Append(param.ParameterType.Name);
// sb.Append(' ');
// sb.Append(param.Name);
// sb.Append(',');
// sb.Append(' ');
// }
// sb.Append(')');
// return sb.ToString();
//}
} }
} }

View File

@ -1,10 +1,12 @@
using System.IO; using System;
using System.IO;
using UnityEngine; using UnityEngine;
using UnityExplorer.Config; using UnityExplorer.Config;
using UnityExplorer.ObjectExplorer; using UnityExplorer.ObjectExplorer;
using UnityExplorer.Runtime; using UnityExplorer.Runtime;
using UnityExplorer.UI; using UnityExplorer.UI;
using UnityExplorer.UI.Panels; using UnityExplorer.UI.Panels;
using UniverseLib;
using UniverseLib.Input; using UniverseLib.Input;
namespace UnityExplorer namespace UnityExplorer
@ -26,23 +28,20 @@ namespace UnityExplorer
public static void Init(IExplorerLoader loader) public static void Init(IExplorerLoader loader)
{ {
if (Loader != null) if (Loader != null)
{ throw new Exception("UnityExplorer is already loaded.");
LogWarning("UnityExplorer is already loaded!");
return;
}
Loader = loader; Loader = loader;
Log($"{NAME} {VERSION} initializing..."); Log($"{NAME} {VERSION} initializing...");
if (!Directory.Exists(Loader.ExplorerFolder)) Directory.CreateDirectory(Loader.ExplorerFolder);
Directory.CreateDirectory(Loader.ExplorerFolder);
ConfigManager.Init(Loader.ConfigHandler); ConfigManager.Init(Loader.ConfigHandler);
UERuntimeHelper.Init(); UERuntimeHelper.Init();
ExplorerBehaviour.Setup(); ExplorerBehaviour.Setup();
UnityCrashPrevention.Init(); UnityCrashPrevention.Init();
UniverseLib.Universe.Init(ConfigManager.Startup_Delay_Time.Value, LateInit, Log, new() Universe.Init(ConfigManager.Startup_Delay_Time.Value, LateInit, Log, new()
{ {
Disable_EventSystem_Override = ConfigManager.Disable_EventSystem_Override.Value, Disable_EventSystem_Override = ConfigManager.Disable_EventSystem_Override.Value,
Force_Unlock_Mouse = ConfigManager.Force_Unlock_Mouse.Value, Force_Unlock_Mouse = ConfigManager.Force_Unlock_Mouse.Value,
@ -53,7 +52,7 @@ namespace UnityExplorer
// Do a delayed setup so that objects aren't destroyed instantly. // Do a delayed setup so that objects aren't destroyed instantly.
// This can happen for a multitude of reasons. // This can happen for a multitude of reasons.
// Default delay is 1 second which is usually enough. // Default delay is 1 second which is usually enough.
private static void LateInit() static void LateInit()
{ {
Log($"Setting up late core features..."); Log($"Setting up late core features...");
@ -63,21 +62,18 @@ namespace UnityExplorer
UIManager.InitUI(); UIManager.InitUI();
Log($"{NAME} {VERSION} initialized for {UniverseLib.Universe.Context}."); Log($"{NAME} {VERSION} ({Universe.Context}) initialized.");
//InspectorManager.Inspect(typeof(Tests.TestClass)); //InspectorManager.Inspect(typeof(Tests.TestClass));
} }
/// <summary> internal static void Update()
/// Should be called once per frame.
/// </summary>
public static void Update()
{ {
UIManager.Update();
// check master toggle // check master toggle
if (InputManager.GetKeyDown(ConfigManager.Master_Toggle.Value)) if (InputManager.GetKeyDown(ConfigManager.Master_Toggle.Value))
UIManager.ShowMenu = !UIManager.ShowMenu; UIManager.ShowMenu = !UIManager.ShowMenu;
UIManager.Update();
} }
#region LOGGING #region LOGGING

View File

@ -164,7 +164,7 @@ namespace UnityExplorer.Inspectors
// Get cache members // Get cache members
this.members = CacheMemberFactory.GetCacheMembers(Target, TargetType, this); this.members = CacheMemberFactory.GetCacheMembers(TargetType, this);
// reset filters // reset filters

View File

@ -24,6 +24,8 @@ namespace UnityExplorer.Tests
#endif #endif
} }
#region MONO
public static object LiterallyAnything = null; public static object LiterallyAnything = null;
// Test enumerables // Test enumerables
@ -90,12 +92,12 @@ namespace UnityExplorer.Tests
ExplorerCore.Log($"Test3 {typeof(T).FullName}"); ExplorerCore.Log($"Test3 {typeof(T).FullName}");
} }
public static void TestArgumentParse(string _string, public static void TestArgumentParse(string _string,
int integer, int integer,
Color color, Color color,
CameraClearFlags flags, CameraClearFlags flags,
Vector3 vector, Vector3 vector,
Quaternion quaternion, Quaternion quaternion,
object obj, object obj,
Type type, Type type,
GameObject go) GameObject go)
@ -145,6 +147,8 @@ namespace UnityExplorer.Tests
ExplorerCore.Log("Finished TestClass Init_Mono"); ExplorerCore.Log("Finished TestClass Init_Mono");
} }
#endregion
#if CPP #if CPP
public static Il2CppSystem.Collections.Generic.Dictionary<string, string> IL2CPP_Dict; public static Il2CppSystem.Collections.Generic.Dictionary<string, string> IL2CPP_Dict;
public static Il2CppSystem.Collections.Generic.HashSet<string> IL2CPP_HashSet; public static Il2CppSystem.Collections.Generic.HashSet<string> IL2CPP_HashSet;
@ -156,7 +160,7 @@ namespace UnityExplorer.Tests
public static Il2CppSystem.Collections.IDictionary IL2CPP_IDict; public static Il2CppSystem.Collections.IDictionary IL2CPP_IDict;
public static Il2CppSystem.Collections.IList IL2CPP_IList; public static Il2CppSystem.Collections.IList IL2CPP_IList;
public static Dictionary<Il2CppSystem.Object, Il2CppSystem.Object> IL2CPP_BoxedDict; public static Dictionary<Il2CppSystem.Object, Il2CppSystem.Object> IL2CPP_BoxedDict;
public static Il2CppSystem.Object IL2CPP_BoxedInt; public static Il2CppSystem.Object IL2CPP_BoxedInt;
public static Il2CppSystem.Int32 IL2CPP_Int; public static Il2CppSystem.Int32 IL2CPP_Int;
public static Il2CppSystem.Decimal IL2CPP_Decimal; public static Il2CppSystem.Decimal IL2CPP_Decimal;
@ -185,31 +189,31 @@ namespace UnityExplorer.Tests
IL2CPP_HashTable.Add("key1", "value1"); IL2CPP_HashTable.Add("key1", "value1");
IL2CPP_HashTable.Add("key2", "value2"); IL2CPP_HashTable.Add("key2", "value2");
IL2CPP_HashTable.Add("key3", "value3"); IL2CPP_HashTable.Add("key3", "value3");
ExplorerCore.Log($"IL2CPP 3: Il2Cpp IDictionary"); ExplorerCore.Log($"IL2CPP 3: Il2Cpp IDictionary");
var dict2 = new Il2CppSystem.Collections.Generic.Dictionary<string, string>(); var dict2 = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
dict2.Add("key1", "value1"); dict2.Add("key1", "value1");
IL2CPP_IDict = dict2.TryCast<Il2CppSystem.Collections.IDictionary>(); IL2CPP_IDict = dict2.TryCast<Il2CppSystem.Collections.IDictionary>();
ExplorerCore.Log($"IL2CPP 4: Il2Cpp List of Il2Cpp Object"); ExplorerCore.Log($"IL2CPP 4: Il2Cpp List of Il2Cpp Object");
var list = new Il2CppSystem.Collections.Generic.List<Il2CppSystem.Object>(5); var list = new Il2CppSystem.Collections.Generic.List<Il2CppSystem.Object>(5);
list.Add("one"); list.Add("one");
list.Add("two"); list.Add("two");
IL2CPP_IList = list.TryCast<Il2CppSystem.Collections.IList>(); IL2CPP_IList = list.TryCast<Il2CppSystem.Collections.IList>();
ExplorerCore.Log($"IL2CPP 5: Il2Cpp List of strings"); ExplorerCore.Log($"IL2CPP 5: Il2Cpp List of strings");
IL2CPP_ListString = new Il2CppSystem.Collections.Generic.List<string>(); IL2CPP_ListString = new Il2CppSystem.Collections.Generic.List<string>();
IL2CPP_ListString.Add("hello,"); IL2CPP_ListString.Add("hello,");
IL2CPP_ListString.Add("world!"); IL2CPP_ListString.Add("world!");
ExplorerCore.Log($"IL2CPP 7: Dictionary of Il2Cpp String and Il2Cpp Object"); ExplorerCore.Log($"IL2CPP 7: Dictionary of Il2Cpp String and Il2Cpp Object");
IL2CPP_BoxedDict = new(); IL2CPP_BoxedDict = new();
IL2CPP_BoxedDict[(Il2CppSystem.String)"one"] = new Il2CppSystem.Int32 { m_value = 1 }.BoxIl2CppObject(); IL2CPP_BoxedDict[(Il2CppSystem.String)"one"] = new Il2CppSystem.Int32 { m_value = 1 }.BoxIl2CppObject();
IL2CPP_BoxedDict[(Il2CppSystem.String)"two"] = new Il2CppSystem.Int32 { m_value = 2 }.BoxIl2CppObject(); IL2CPP_BoxedDict[(Il2CppSystem.String)"two"] = new Il2CppSystem.Int32 { m_value = 2 }.BoxIl2CppObject();
IL2CPP_BoxedDict[(Il2CppSystem.String)"three"] = new Il2CppSystem.Int32 { m_value = 3 }.BoxIl2CppObject(); IL2CPP_BoxedDict[(Il2CppSystem.String)"three"] = new Il2CppSystem.Int32 { m_value = 3 }.BoxIl2CppObject();
IL2CPP_BoxedDict[(Il2CppSystem.String)"four"] = new Il2CppSystem.Int32 { m_value = 4 }.BoxIl2CppObject(); IL2CPP_BoxedDict[(Il2CppSystem.String)"four"] = new Il2CppSystem.Int32 { m_value = 4 }.BoxIl2CppObject();
ExplorerCore.Log($"IL2CPP 8: List of boxed Il2Cpp Objects"); ExplorerCore.Log($"IL2CPP 8: List of boxed Il2Cpp Objects");
IL2CPP_listOfBoxedObjects = new List<Il2CppSystem.Object>(); IL2CPP_listOfBoxedObjects = new List<Il2CppSystem.Object>();
IL2CPP_listOfBoxedObjects.Add((Il2CppSystem.String)"boxedString"); IL2CPP_listOfBoxedObjects.Add((Il2CppSystem.String)"boxedString");
@ -224,16 +228,16 @@ namespace UnityExplorer.Tests
var boxedEnum = Il2CppSystem.Enum.Parse(cppType, "Color"); var boxedEnum = Il2CppSystem.Enum.Parse(cppType, "Color");
IL2CPP_listOfBoxedObjects.Add(boxedEnum); IL2CPP_listOfBoxedObjects.Add(boxedEnum);
} }
var structBox = Vector3.one.BoxIl2CppObject(); var structBox = Vector3.one.BoxIl2CppObject();
IL2CPP_listOfBoxedObjects.Add(structBox); IL2CPP_listOfBoxedObjects.Add(structBox);
} }
catch (Exception ex) catch (Exception ex)
{ {
ExplorerCore.LogWarning($"Boxed enum test fail: {ex}"); ExplorerCore.LogWarning($"Boxed enum test fail: {ex}");
} }
ExplorerCore.Log($"IL2CPP 9: Il2Cpp struct array of ints"); ExplorerCore.Log($"IL2CPP 9: Il2Cpp struct array of ints");
IL2CPP_structArray = new UnhollowerBaseLib.Il2CppStructArray<int>(5); IL2CPP_structArray = new UnhollowerBaseLib.Il2CppStructArray<int>(5);
IL2CPP_structArray[0] = 0; IL2CPP_structArray[0] = 0;
@ -241,13 +245,13 @@ namespace UnityExplorer.Tests
IL2CPP_structArray[2] = 2; IL2CPP_structArray[2] = 2;
IL2CPP_structArray[3] = 3; IL2CPP_structArray[3] = 3;
IL2CPP_structArray[4] = 4; IL2CPP_structArray[4] = 4;
ExplorerCore.Log($"IL2CPP 10: Il2Cpp reference array of boxed objects"); ExplorerCore.Log($"IL2CPP 10: Il2Cpp reference array of boxed objects");
IL2CPP_ReferenceArray = new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Object>(3); IL2CPP_ReferenceArray = new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Object>(3);
IL2CPP_ReferenceArray[0] = new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject(); IL2CPP_ReferenceArray[0] = new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject();
IL2CPP_ReferenceArray[1] = null; IL2CPP_ReferenceArray[1] = null;
IL2CPP_ReferenceArray[2] = (Il2CppSystem.String)"whats up"; IL2CPP_ReferenceArray[2] = (Il2CppSystem.String)"whats up";
ExplorerCore.Log($"IL2CPP 11: Misc il2cpp members"); ExplorerCore.Log($"IL2CPP 11: Misc il2cpp members");
IL2CPP_BoxedInt = new Il2CppSystem.Int32() { m_value = 5 }.BoxIl2CppObject(); IL2CPP_BoxedInt = new Il2CppSystem.Int32() { m_value = 5 }.BoxIl2CppObject();
IL2CPP_Int = new Il2CppSystem.Int32 { m_value = 420 }; IL2CPP_Int = new Il2CppSystem.Int32 { m_value = 420 };
@ -257,6 +261,7 @@ namespace UnityExplorer.Tests
ExplorerCore.Log($"Finished Init_Il2Cpp"); ExplorerCore.Log($"Finished Init_Il2Cpp");
} }
#endif #endif
} }
} }