mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-14 13:37:46 +08:00
Cleanup runtime-specific
This commit is contained in:
parent
c2d9b9b59e
commit
2cc403ad17
@ -6,7 +6,7 @@
|
||||
An in-game explorer and a suite of debugging tools for <a href="https://docs.unity3d.com/Manual/IL2CPP.html">IL2CPP</a> and <b>Mono</b> Unity games, to aid with modding development.
|
||||
</p>
|
||||
|
||||
## Releases [](../../releases/latest) [](../../releases) [](../../releases/latest)
|
||||
## Releases [](../../releases/latest) [](../../releases) [](../../releases/latest)
|
||||
|
||||
| Mod Loader | IL2CPP | Mono |
|
||||
| ----------- | ------ | ---- |
|
||||
|
@ -20,7 +20,7 @@ namespace UnityExplorer.Core.CSharp
|
||||
|
||||
public static void StartCoroutine(IEnumerator ienumerator)
|
||||
{
|
||||
RuntimeProvider.Instance.StartConsoleCoroutine(ienumerator);
|
||||
RuntimeProvider.Instance.StartCoroutine(ienumerator);
|
||||
}
|
||||
|
||||
public static void AddUsing(string directive)
|
||||
|
@ -189,4 +189,4 @@ namespace UnityExplorer.Core.Input
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -18,4 +18,4 @@ namespace UnityExplorer.Core.Input
|
||||
void AddUIInputModule();
|
||||
void ActivateModule();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,6 @@ using UnityEngine.EventSystems;
|
||||
using UnityExplorer.UI;
|
||||
using System.Collections.Generic;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
#if CPP
|
||||
using UnhollowerRuntimeLib;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
@ -152,13 +149,9 @@ namespace UnityExplorer.Core.Input
|
||||
}
|
||||
|
||||
var assetType = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionAsset");
|
||||
#if CPP
|
||||
m_newInputModule = UIManager.CanvasRoot.AddComponent(Il2CppType.From(TInputSystemUIInputModule)).TryCast<BaseInputModule>();
|
||||
var asset = ScriptableObject.CreateInstance(Il2CppType.From(assetType));
|
||||
#else
|
||||
m_newInputModule = (BaseInputModule)UIManager.CanvasRoot.AddComponent(TInputSystemUIInputModule);
|
||||
var asset = ScriptableObject.CreateInstance(assetType);
|
||||
#endif
|
||||
m_newInputModule = RuntimeProvider.Instance.AddComponent<BaseInputModule>(UIManager.CanvasRoot, TInputSystemUIInputModule);
|
||||
var asset = RuntimeProvider.Instance.CreateScriptable(assetType);
|
||||
|
||||
inputExtensions = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionSetupExtensions");
|
||||
|
||||
var addMap = inputExtensions.GetMethod("AddActionMap", new Type[] { assetType, typeof(string) });
|
||||
@ -205,4 +198,4 @@ namespace UnityExplorer.Core.Input
|
||||
UI_Enable.Invoke(UI_ActionMap, new object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -54,4 +54,4 @@ namespace UnityExplorer.Core.Input
|
||||
m_inputModule.ActivateModule();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -19,4 +19,4 @@ namespace UnityExplorer.Core.Input
|
||||
public void ActivateModule() { }
|
||||
public void AddUIInputModule() { }
|
||||
}
|
||||
}
|
||||
}
|
@ -43,6 +43,9 @@ namespace UnityExplorer
|
||||
public static object Cast(this object obj, Type castTo)
|
||||
=> ReflectionProvider.Instance.Cast(obj, castTo);
|
||||
|
||||
public static T TryCast<T>(this object obj)
|
||||
=> ReflectionProvider.Instance.TryCast<T>(obj);
|
||||
|
||||
/// <summary>
|
||||
/// Check if the provided Type is assignable to IEnumerable.
|
||||
/// </summary>
|
||||
@ -201,10 +204,9 @@ namespace UnityExplorer
|
||||
{
|
||||
while (e.InnerException != null)
|
||||
{
|
||||
#if CPP
|
||||
if (e.InnerException is System.Runtime.CompilerServices.RuntimeWrappedException)
|
||||
break;
|
||||
#endif
|
||||
|
||||
e = e.InnerException;
|
||||
}
|
||||
}
|
||||
|
@ -50,12 +50,47 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
ExplorerCore.Log(condition, type, true);
|
||||
}
|
||||
|
||||
public override void StartConsoleCoroutine(IEnumerator routine)
|
||||
public override void StartCoroutine(IEnumerator routine)
|
||||
{
|
||||
Il2CppCoroutine.Start(routine);
|
||||
}
|
||||
|
||||
// Unity API Handlers
|
||||
public override void Update()
|
||||
{
|
||||
Il2CppCoroutine.Process();
|
||||
}
|
||||
|
||||
public override T AddComponent<T>(GameObject obj, Type type)
|
||||
{
|
||||
return obj.AddComponent(Il2CppType.From(type)).TryCast<T>();
|
||||
}
|
||||
|
||||
public override ScriptableObject CreateScriptable(Type type)
|
||||
{
|
||||
return ScriptableObject.CreateInstance(Il2CppType.From(type));
|
||||
}
|
||||
|
||||
public override void GraphicRaycast(GraphicRaycaster raycaster, PointerEventData data, List<RaycastResult> list)
|
||||
{
|
||||
var il2cppList = new Il2CppSystem.Collections.Generic.List<RaycastResult>();
|
||||
|
||||
raycaster.Raycast(data, il2cppList);
|
||||
|
||||
if (il2cppList.Count > 0)
|
||||
list.AddRange(il2cppList.ToArray());
|
||||
}
|
||||
|
||||
public override bool IsReferenceEqual(object a, object b)
|
||||
{
|
||||
if (a.TryCast<UnityEngine.Object>() is UnityEngine.Object ua)
|
||||
{
|
||||
var ub = b.TryCast<UnityEngine.Object>();
|
||||
if (ub && ua.m_CachedPtr == ub.m_CachedPtr)
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.IsReferenceEqual(a, b);
|
||||
}
|
||||
|
||||
// LayerMask.LayerToName
|
||||
|
||||
@ -162,6 +197,26 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
public override void FindSingleton(string[] possibleNames, Type type, BF flags, List<object> instances)
|
||||
{
|
||||
PropertyInfo pi;
|
||||
foreach (var name in possibleNames)
|
||||
{
|
||||
pi = type.GetProperty(name, flags);
|
||||
if (pi != null)
|
||||
{
|
||||
var instance = pi.GetValue(null, null);
|
||||
if (instance != null)
|
||||
{
|
||||
instances.Add(instance);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base.FindSingleton(possibleNames, type, flags, instances);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,18 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
return Il2CppCast(obj, castTo);
|
||||
}
|
||||
|
||||
public override T TryCast<T>(object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T)Il2CppCast(obj, typeof(T));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ProcessTypeNameInString(Type type, string theString, ref string typeName)
|
||||
{
|
||||
if (!Il2CppTypeNotNull(type))
|
||||
@ -367,6 +379,124 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
|
||||
return s_unboxMethods[name].Invoke(obj, new object[0]);
|
||||
}
|
||||
|
||||
public override string UnboxString(object value)
|
||||
{
|
||||
string s = null;
|
||||
// strings boxed as Il2CppSystem.Objects can behave weirdly.
|
||||
// GetActualType will find they are a string, but if its boxed
|
||||
// then we need to unbox it like this...
|
||||
if (!(value is string) && value is Il2CppSystem.Object cppobj)
|
||||
s = cppobj.ToString();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
internal static readonly Dictionary<Type, MethodInfo> s_getEnumeratorMethods = new Dictionary<Type, MethodInfo>();
|
||||
|
||||
internal static readonly Dictionary<Type, EnumeratorInfo> s_enumeratorInfos = new Dictionary<Type, EnumeratorInfo>();
|
||||
|
||||
internal class EnumeratorInfo
|
||||
{
|
||||
internal MethodInfo moveNext;
|
||||
internal PropertyInfo current;
|
||||
}
|
||||
|
||||
public override IEnumerable EnumerateEnumerable(object value)
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
var cppEnumerable = (value as Il2CppSystem.Object)?.TryCast<Il2CppSystem.Collections.IEnumerable>();
|
||||
if (cppEnumerable != null)
|
||||
{
|
||||
var type = value.GetType();
|
||||
if (!s_getEnumeratorMethods.ContainsKey(type))
|
||||
s_getEnumeratorMethods.Add(type, type.GetMethod("GetEnumerator"));
|
||||
|
||||
var enumerator = s_getEnumeratorMethods[type].Invoke(value, null);
|
||||
var enumeratorType = enumerator.GetType();
|
||||
|
||||
if (!s_enumeratorInfos.ContainsKey(enumeratorType))
|
||||
{
|
||||
s_enumeratorInfos.Add(enumeratorType, new EnumeratorInfo
|
||||
{
|
||||
current = enumeratorType.GetProperty("Current"),
|
||||
moveNext = enumeratorType.GetMethod("MoveNext"),
|
||||
});
|
||||
}
|
||||
var info = s_enumeratorInfos[enumeratorType];
|
||||
|
||||
// iterate
|
||||
var list = new List<object>();
|
||||
while ((bool)info.moveNext.Invoke(enumerator, null))
|
||||
list.Add(info.current.GetValue(enumerator));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override IDictionary EnumerateDictionary(object value, Type typeOfKeys, Type typeOfValues)
|
||||
{
|
||||
var valueType = ReflectionUtility.GetActualType(value);
|
||||
|
||||
var keyList = new List<object>();
|
||||
var valueList = new List<object>();
|
||||
|
||||
var hashtable = value.Cast(typeof(Il2CppSystem.Collections.Hashtable)) as Il2CppSystem.Collections.Hashtable;
|
||||
|
||||
if (hashtable != null)
|
||||
{
|
||||
EnumerateCppHashtable(hashtable, keyList, valueList);
|
||||
}
|
||||
else
|
||||
{
|
||||
var keys = valueType.GetProperty("Keys").GetValue(value, null);
|
||||
var values = valueType.GetProperty("Values").GetValue(value, null);
|
||||
|
||||
EnumerateCppIDictionary(keys, keyList);
|
||||
EnumerateCppIDictionary(values, valueList);
|
||||
}
|
||||
|
||||
var dict = Activator.CreateInstance(typeof(Dictionary<,>)
|
||||
.MakeGenericType(typeOfKeys, typeOfValues))
|
||||
as IDictionary;
|
||||
|
||||
for (int i = 0; i < keyList.Count; i++)
|
||||
dict.Add(keyList[i], valueList[i]);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private void EnumerateCppIDictionary(object collection, List<object> list)
|
||||
{
|
||||
// invoke GetEnumerator
|
||||
var enumerator = collection.GetType().GetMethod("GetEnumerator").Invoke(collection, null);
|
||||
// get the type of it
|
||||
var enumeratorType = enumerator.GetType();
|
||||
// reflect MoveNext and Current
|
||||
var moveNext = enumeratorType.GetMethod("MoveNext");
|
||||
var current = enumeratorType.GetProperty("Current");
|
||||
// iterate
|
||||
while ((bool)moveNext.Invoke(enumerator, null))
|
||||
{
|
||||
list.Add(current.GetValue(enumerator, null));
|
||||
}
|
||||
}
|
||||
|
||||
private void EnumerateCppHashtable(Il2CppSystem.Collections.Hashtable hashtable, List<object> keys, List<object> values)
|
||||
{
|
||||
for (int i = 0; i < hashtable.buckets.Count; i++)
|
||||
{
|
||||
var bucket = hashtable.buckets[i];
|
||||
if (bucket == null || bucket.key == null)
|
||||
continue;
|
||||
keys.Add(bucket.key);
|
||||
values.Add(bucket.val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
namespace UnityExplorer.Core.Runtime.Mono
|
||||
{
|
||||
public class DummyBehaviour : MonoBehaviour
|
||||
{
|
@ -7,6 +7,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core;
|
||||
@ -20,6 +21,8 @@ namespace UnityExplorer.Core.Runtime.Mono
|
||||
{
|
||||
Reflection = new MonoReflection();
|
||||
TextureUtil = new MonoTextureUtil();
|
||||
|
||||
DummyBehaviour.Setup();
|
||||
}
|
||||
|
||||
public override void SetupEvents()
|
||||
@ -32,11 +35,31 @@ namespace UnityExplorer.Core.Runtime.Mono
|
||||
ExplorerCore.Log(condition, type, true);
|
||||
}
|
||||
|
||||
public override void StartConsoleCoroutine(IEnumerator routine)
|
||||
public override void StartCoroutine(IEnumerator routine)
|
||||
{
|
||||
DummyBehaviour.Instance.StartCoroutine(routine);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override T AddComponent<T>(GameObject obj, Type type)
|
||||
{
|
||||
return (T)obj.AddComponent(type);
|
||||
}
|
||||
|
||||
public override ScriptableObject CreateScriptable(Type type)
|
||||
{
|
||||
return ScriptableObject.CreateInstance(type);
|
||||
}
|
||||
|
||||
public override void GraphicRaycast(GraphicRaycaster raycaster, PointerEventData data, List<RaycastResult> list)
|
||||
{
|
||||
raycaster.Raycast(data, list);
|
||||
}
|
||||
|
||||
public override string LayerToName(int layer)
|
||||
=> LayerMask.LayerToName(layer);
|
||||
|
||||
|
@ -12,6 +12,18 @@ namespace UnityExplorer.Core.Runtime.Mono
|
||||
public override object Cast(object obj, Type castTo)
|
||||
=> obj;
|
||||
|
||||
public override T TryCast<T>(object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T)obj;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
// Vanilla GetType is fine for mono
|
||||
public override Type GetActualType(object obj)
|
||||
=> obj.GetType();
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -18,6 +19,8 @@ namespace UnityExplorer.Core.Runtime
|
||||
|
||||
public abstract object Cast(object obj, Type castTo);
|
||||
|
||||
public abstract T TryCast<T>(object obj);
|
||||
|
||||
public abstract bool IsAssignableFrom(Type toAssignTo, Type toAssignFrom);
|
||||
|
||||
public abstract bool IsReflectionSupported(Type type);
|
||||
@ -27,5 +30,13 @@ namespace UnityExplorer.Core.Runtime
|
||||
public abstract bool LoadModule(string module);
|
||||
|
||||
public abstract void BoxStringToType(ref object _string, Type castTo);
|
||||
|
||||
public virtual string UnboxString(object value) => (string)value;
|
||||
|
||||
public virtual IDictionary EnumerateDictionary(object value, Type typeOfKeys, Type typeOfValues)
|
||||
=> null;
|
||||
|
||||
public virtual IEnumerable EnumerateEnumerable(object value)
|
||||
=> null;
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.Core.Runtime
|
||||
// Intentionally project-wide namespace so that its always easily accessible.
|
||||
namespace UnityExplorer
|
||||
{
|
||||
// Work in progress, this will be used to replace all the "if CPP / if MONO"
|
||||
// pre-processor directives all over the codebase.
|
||||
|
||||
public abstract class RuntimeProvider
|
||||
{
|
||||
public static RuntimeProvider Instance;
|
||||
@ -28,24 +29,33 @@ namespace UnityExplorer.Core.Runtime
|
||||
|
||||
public static void Init() =>
|
||||
#if CPP
|
||||
Instance = new Il2Cpp.Il2CppProvider();
|
||||
Instance = new Core.Runtime.Il2Cpp.Il2CppProvider();
|
||||
#else
|
||||
Instance = new Mono.MonoProvider();
|
||||
Instance = new Core.Runtime.Mono.MonoProvider();
|
||||
#endif
|
||||
|
||||
|
||||
public abstract void Initialize();
|
||||
|
||||
public abstract void SetupEvents();
|
||||
|
||||
public abstract void StartConsoleCoroutine(IEnumerator routine);
|
||||
public abstract void StartCoroutine(IEnumerator routine);
|
||||
|
||||
public abstract void Update();
|
||||
|
||||
public virtual bool IsReferenceEqual(object a, object b) => ReferenceEquals(a, b);
|
||||
|
||||
// Unity API handlers
|
||||
|
||||
public abstract T AddComponent<T>(GameObject obj, Type type) where T : Component;
|
||||
|
||||
public abstract ScriptableObject CreateScriptable(Type type);
|
||||
|
||||
public abstract string LayerToName(int layer);
|
||||
|
||||
public abstract UnityEngine.Object[] FindObjectsOfTypeAll(Type type);
|
||||
|
||||
public abstract void GraphicRaycast(GraphicRaycaster raycaster, PointerEventData data, List<RaycastResult> list);
|
||||
|
||||
public abstract int GetSceneHandle(Scene scene);
|
||||
|
||||
public abstract GameObject[] GetRootGameObjects(Scene scene);
|
||||
@ -53,5 +63,24 @@ namespace UnityExplorer.Core.Runtime
|
||||
public abstract int GetRootCount(Scene scene);
|
||||
|
||||
public abstract ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null);
|
||||
|
||||
public virtual void FindSingleton(string[] s_instanceNames, Type type, BindingFlags flags, List<object> instances)
|
||||
{
|
||||
// Look for a typical Instance backing field.
|
||||
FieldInfo fi;
|
||||
foreach (var name in s_instanceNames)
|
||||
{
|
||||
fi = type.GetField(name, flags);
|
||||
if (fi != null)
|
||||
{
|
||||
var instance = fi.GetValue(null);
|
||||
if (instance != null)
|
||||
{
|
||||
instances.Add(instance);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,38 +67,8 @@ namespace UnityExplorer.Core.Search
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ToLower().Contains(nameFilter))
|
||||
continue;
|
||||
#if CPP
|
||||
// Only look for Properties in IL2CPP, not for Mono.
|
||||
PropertyInfo pi;
|
||||
foreach (var name in s_instanceNames)
|
||||
{
|
||||
pi = type.GetProperty(name, flags);
|
||||
if (pi != null)
|
||||
{
|
||||
var instance = pi.GetValue(null, null);
|
||||
if (instance != null)
|
||||
{
|
||||
instances.Add(instance);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Look for a typical Instance backing field.
|
||||
FieldInfo fi;
|
||||
foreach (var name in s_instanceNames)
|
||||
{
|
||||
fi = type.GetField(name, flags);
|
||||
if (fi != null)
|
||||
{
|
||||
var instance = fi.GetValue(null);
|
||||
if (instance != null)
|
||||
{
|
||||
instances.Add(instance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RuntimeProvider.Instance.FindSingleton(s_instanceNames, type, flags, instances);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@ -175,15 +145,9 @@ namespace UnityExplorer.Core.Search
|
||||
|
||||
if (canGetGameObject)
|
||||
{
|
||||
#if MONO
|
||||
var go = context == SearchContext.GameObject
|
||||
? obj as GameObject
|
||||
: (obj as Component).gameObject;
|
||||
#else
|
||||
var go = context == SearchContext.GameObject
|
||||
? obj.TryCast<GameObject>()
|
||||
: obj.TryCast<Component>().gameObject;
|
||||
#endif
|
||||
|
||||
// scene check
|
||||
if (sceneFilter != SceneFilter.Any)
|
||||
|
@ -16,6 +16,7 @@ namespace UnityExplorer
|
||||
public static string nullString = null;
|
||||
|
||||
public static Il2CppSystem.Collections.Hashtable testHashset;
|
||||
public static Il2CppSystem.Collections.Generic.List<Il2CppSystem.Object> testList;
|
||||
|
||||
static TestClass()
|
||||
{
|
||||
@ -23,6 +24,12 @@ namespace UnityExplorer
|
||||
testHashset.Add("key1", "itemOne");
|
||||
testHashset.Add("key2", "itemTwo");
|
||||
testHashset.Add("key3", "itemThree");
|
||||
|
||||
testList = new Il2CppSystem.Collections.Generic.List<Il2CppSystem.Object>(3);
|
||||
testList.Add("One");
|
||||
testList.Add("Two");
|
||||
testList.Add("Three");
|
||||
//testIList = list.TryCast<Il2CppSystem.Collections.IList>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace UnityExplorer
|
||||
public class ExplorerCore
|
||||
{
|
||||
public const string NAME = "UnityExplorer";
|
||||
public const string VERSION = "3.3.8";
|
||||
public const string VERSION = "3.3.9";
|
||||
public const string AUTHOR = "Sinai";
|
||||
public const string GUID = "com.sinai.unityexplorer";
|
||||
|
||||
@ -48,11 +48,13 @@ namespace UnityExplorer
|
||||
|
||||
Log($"{NAME} {VERSION} initialized.");
|
||||
|
||||
//InspectorManager.Instance.Inspect(typeof(TestClass));
|
||||
InspectorManager.Instance.Inspect(typeof(TestClass));
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
RuntimeProvider.Instance.Update();
|
||||
|
||||
UIManager.Update();
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,9 @@ namespace UnityExplorer.Loader.ML
|
||||
|
||||
try
|
||||
{
|
||||
// TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED
|
||||
MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter);
|
||||
MelonPreferences.Mapper.RegisterMapper(MenuPagesReader, MenuPagesWriter);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@ -80,6 +82,8 @@ namespace UnityExplorer.Loader.ML
|
||||
MelonPreferences.Save();
|
||||
}
|
||||
|
||||
// TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED
|
||||
|
||||
public static KeyCode KeycodeReader(TomlObject value)
|
||||
{
|
||||
try
|
||||
@ -101,6 +105,28 @@ namespace UnityExplorer.Loader.ML
|
||||
{
|
||||
return MelonPreferences.Mapper.ToToml(value.ToString());
|
||||
}
|
||||
|
||||
public static UI.Main.MenuPages MenuPagesReader(TomlObject value)
|
||||
{
|
||||
try
|
||||
{
|
||||
var kc = (UI.Main.MenuPages)Enum.Parse(typeof(UI.Main.MenuPages), (value as TomlString).Value);
|
||||
|
||||
if (kc == default)
|
||||
throw new Exception();
|
||||
|
||||
return kc;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return UI.Main.MenuPages.Home;
|
||||
}
|
||||
}
|
||||
|
||||
public static TomlObject MenuPagesWriter(UI.Main.MenuPages value)
|
||||
{
|
||||
return MelonPreferences.Mapper.ToToml(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,12 @@ namespace UnityExplorer.UI.CacheObject
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(m_mainContent, "PairedGroup", false, false, true, true, 0, new Vector4(0,0,5,2),
|
||||
bgColor);
|
||||
|
||||
var indexLabel = UIFactory.CreateLabel(rowObj, "IndexLabel", $"{this.PairType} {this.Index}:", TextAnchor.MiddleLeft);
|
||||
|
||||
string lbl = $"{this.PairType}";
|
||||
if (this.PairType == PairTypes.Key)
|
||||
lbl = $"[{Index}] {lbl}";
|
||||
|
||||
var indexLabel = UIFactory.CreateLabel(rowObj, "IndexLabel", lbl, TextAnchor.MiddleLeft);
|
||||
UIFactory.SetLayoutElement(indexLabel.gameObject, minWidth: 80, flexibleWidth: 30, minHeight: 25);
|
||||
|
||||
IValue.m_mainContentParent = rowObj;
|
||||
|
@ -78,11 +78,7 @@ namespace UnityExplorer.UI.Inspectors.GameObjects
|
||||
text.text = SignatureHighlighter.ParseFullSyntax(ReflectionUtility.GetActualType(comp), true);
|
||||
|
||||
var toggle = s_compToggles[i];
|
||||
#if CPP
|
||||
if (comp.TryCast<Behaviour>() is Behaviour behaviour)
|
||||
#else
|
||||
if (comp is Behaviour behaviour)
|
||||
#endif
|
||||
{
|
||||
if (!toggle.gameObject.activeSelf)
|
||||
toggle.gameObject.SetActive(true);
|
||||
@ -109,19 +105,13 @@ namespace UnityExplorer.UI.Inspectors.GameObjects
|
||||
internal static void OnCompToggleClicked(int index, bool value)
|
||||
{
|
||||
var comp = s_compShortlist[index];
|
||||
#if CPP
|
||||
comp.TryCast<Behaviour>().enabled = value;
|
||||
#else
|
||||
(comp as Behaviour).enabled = value;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void OnCompListObjectClicked(int index)
|
||||
{
|
||||
if (index >= s_compShortlist.Count || !s_compShortlist[index])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
InspectorManager.Instance.Inspect(s_compShortlist[index]);
|
||||
}
|
||||
|
@ -203,11 +203,6 @@ namespace UnityExplorer.UI.Main.Home
|
||||
position = mousePos
|
||||
};
|
||||
|
||||
#if MONO
|
||||
var list = new List<RaycastResult>();
|
||||
#else
|
||||
var list = new Il2CppSystem.Collections.Generic.List<RaycastResult>();
|
||||
#endif
|
||||
//ExplorerCore.Log("~~~~~~~~~ begin raycast ~~~~~~~~");
|
||||
GameObject hitObject = null;
|
||||
int highestLayer = int.MinValue;
|
||||
@ -215,7 +210,10 @@ namespace UnityExplorer.UI.Main.Home
|
||||
int highestDepth = int.MinValue;
|
||||
foreach (var gr in graphicRaycasters)
|
||||
{
|
||||
gr.Raycast(ped, list);
|
||||
var list = new List<RaycastResult>();
|
||||
RuntimeProvider.Instance.GraphicRaycast(gr, ped, list);
|
||||
|
||||
//gr.Raycast(ped, list);
|
||||
|
||||
if (list.Count > 0)
|
||||
{
|
||||
@ -290,8 +288,6 @@ namespace UnityExplorer.UI.Main.Home
|
||||
_wasDisabledGraphics.Clear();
|
||||
}
|
||||
|
||||
#region UI
|
||||
|
||||
internal static Text s_objNameLabel;
|
||||
internal static Text s_objPathLabel;
|
||||
internal static Text s_mousePosLabel;
|
||||
@ -328,7 +324,5 @@ namespace UnityExplorer.UI.Main.Home
|
||||
|
||||
s_UIContent.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -54,21 +54,11 @@ namespace UnityExplorer.UI.Inspectors
|
||||
// check if currently inspecting this object
|
||||
foreach (InspectorBase tab in m_currentInspectors)
|
||||
{
|
||||
if (ReferenceEquals(obj, tab.Target))
|
||||
if (RuntimeProvider.Instance.IsReferenceEqual(obj, tab.Target))
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
#if CPP
|
||||
else if (unityObj && tab.Target is UnityEngine.Object uTabObj)
|
||||
{
|
||||
if (unityObj.m_CachedPtr == uTabObj.m_CachedPtr)
|
||||
{
|
||||
SetInspectorTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
InspectorBase inspector;
|
||||
|
@ -13,7 +13,9 @@ using UnityExplorer.UI.CacheObject;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
#if CPP
|
||||
using CppDictionary = Il2CppSystem.Collections.IDictionary;
|
||||
using AltIDictionary = Il2CppSystem.Collections.IDictionary;
|
||||
#else
|
||||
using AltIDictionary = System.Collections.IDictionary;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.UI.InteractiveValues
|
||||
@ -48,11 +50,7 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
}
|
||||
|
||||
internal IDictionary RefIDictionary;
|
||||
#if CPP
|
||||
internal CppDictionary RefCppDictionary;
|
||||
#else
|
||||
internal IDictionary RefCppDictionary = null;
|
||||
#endif
|
||||
internal AltIDictionary RefAltIDictionary;
|
||||
internal Type m_typeOfKeys;
|
||||
internal Type m_typeofValues;
|
||||
|
||||
@ -73,10 +71,11 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
{
|
||||
RefIDictionary = Value as IDictionary;
|
||||
|
||||
#if CPP
|
||||
try { RefCppDictionary = (Value as Il2CppSystem.Object).TryCast<CppDictionary>(); }
|
||||
catch { }
|
||||
#endif
|
||||
if (RefIDictionary == null)
|
||||
{
|
||||
try { RefAltIDictionary = Value.TryCast<AltIDictionary>(); }
|
||||
catch { }
|
||||
}
|
||||
|
||||
if (m_subContentParent.activeSelf)
|
||||
{
|
||||
@ -129,10 +128,8 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
m_entries.Clear();
|
||||
}
|
||||
|
||||
#if CPP
|
||||
if (RefIDictionary == null && Value != null)
|
||||
RefIDictionary = EnumerateWithReflection();
|
||||
#endif
|
||||
RefIDictionary = RuntimeProvider.Instance.Reflection.EnumerateDictionary(Value, m_typeOfKeys, m_typeofValues);
|
||||
|
||||
if (RefIDictionary != null)
|
||||
{
|
||||
@ -212,82 +209,11 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
#region CPP fixes
|
||||
#if CPP
|
||||
// temp fix for Il2Cpp IDictionary until interfaces are fixed
|
||||
|
||||
private IDictionary EnumerateWithReflection()
|
||||
{
|
||||
var valueType = ReflectionUtility.GetActualType(Value);
|
||||
|
||||
var keyList = new List<object>();
|
||||
var valueList = new List<object>();
|
||||
|
||||
var hashtable = Value.Cast(typeof(Il2CppSystem.Collections.Hashtable)) as Il2CppSystem.Collections.Hashtable;
|
||||
|
||||
if (hashtable != null)
|
||||
{
|
||||
EnumerateCppHashtable(hashtable, keyList, valueList);
|
||||
}
|
||||
else
|
||||
{
|
||||
var keys = valueType.GetProperty("Keys").GetValue(Value, null);
|
||||
var values = valueType.GetProperty("Values").GetValue(Value, null);
|
||||
|
||||
EnumerateCppIDictionary(keys, keyList);
|
||||
EnumerateCppIDictionary(values, valueList);
|
||||
}
|
||||
|
||||
var dict = Activator.CreateInstance(typeof(Dictionary<,>)
|
||||
.MakeGenericType(m_typeOfKeys, m_typeofValues))
|
||||
as IDictionary;
|
||||
|
||||
for (int i = 0; i < keyList.Count; i++)
|
||||
dict.Add(keyList[i], valueList[i]);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private void EnumerateCppIDictionary(object collection, List<object> list)
|
||||
{
|
||||
// invoke GetEnumerator
|
||||
var enumerator = collection.GetType().GetMethod("GetEnumerator").Invoke(collection, null);
|
||||
// get the type of it
|
||||
var enumeratorType = enumerator.GetType();
|
||||
// reflect MoveNext and Current
|
||||
var moveNext = enumeratorType.GetMethod("MoveNext");
|
||||
var current = enumeratorType.GetProperty("Current");
|
||||
// iterate
|
||||
while ((bool)moveNext.Invoke(enumerator, null))
|
||||
{
|
||||
list.Add(current.GetValue(enumerator, null));
|
||||
}
|
||||
}
|
||||
|
||||
private void EnumerateCppHashtable(Il2CppSystem.Collections.Hashtable hashtable, List<object> keys, List<object> values)
|
||||
{
|
||||
for (int i = 0; i < hashtable.buckets.Count; i++)
|
||||
{
|
||||
var bucket = hashtable.buckets[i];
|
||||
if (bucket == null || bucket.key == null)
|
||||
continue;
|
||||
keys.Add(bucket.key);
|
||||
values.Add(bucket.val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal GameObject m_listContent;
|
||||
internal LayoutElement m_listLayout;
|
||||
|
||||
internal PageHandler m_pageHandler;
|
||||
|
||||
//internal List<GameObject> m_rowHolders = new List<GameObject>();
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
@ -317,7 +243,5 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
||||
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,6 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
|
||||
internal IEnumerable RefIEnumerable;
|
||||
internal IList RefIList;
|
||||
//#if CPP
|
||||
// internal object CppICollection;
|
||||
//#else
|
||||
// internal object CppICollection = null;
|
||||
//#endif
|
||||
|
||||
internal readonly Type m_baseEntryType;
|
||||
|
||||
@ -56,18 +51,6 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
RefIEnumerable = Value as IEnumerable;
|
||||
RefIList = Value as IList;
|
||||
|
||||
//#if CPP
|
||||
// if (Value != null && RefIList == null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var type = typeof(Il2CppSystem.Collections.ICollection).MakeGenericType(this.m_baseEntryType);
|
||||
// CppICollection = (Value as Il2CppSystem.Object).Cast(type);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
//#endif
|
||||
|
||||
if (m_subContentParent.activeSelf)
|
||||
{
|
||||
GetCacheEntries();
|
||||
@ -96,8 +79,8 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
if (Value != null)
|
||||
{
|
||||
string count = "?";
|
||||
if (m_recacheWanted && RefIList != null)// || CppICollection != null))
|
||||
count = RefIList.Count.ToString();// ?? CppICollection.Count.ToString();
|
||||
if (m_recacheWanted && RefIList != null)
|
||||
count = RefIList.Count.ToString();
|
||||
else if (!m_recacheWanted)
|
||||
count = m_entries.Count.ToString();
|
||||
|
||||
@ -121,10 +104,8 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
m_entries.Clear();
|
||||
}
|
||||
|
||||
#if CPP
|
||||
if (RefIEnumerable == null && Value != null)
|
||||
RefIEnumerable = EnumerateWithReflection();
|
||||
#endif
|
||||
RefIEnumerable = RuntimeProvider.Instance.Reflection.EnumerateEnumerable(Value);
|
||||
|
||||
if (RefIEnumerable != null)
|
||||
{
|
||||
@ -188,62 +169,6 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
RefreshDisplay();
|
||||
}
|
||||
|
||||
#region CPP Helpers
|
||||
|
||||
#if CPP
|
||||
// some temp fixes for Il2Cpp IEnumerables until interfaces are fixed
|
||||
|
||||
internal static readonly Dictionary<Type, MethodInfo> s_getEnumeratorMethods = new Dictionary<Type, MethodInfo>();
|
||||
|
||||
internal static readonly Dictionary<Type, EnumeratorInfo> s_enumeratorInfos = new Dictionary<Type, EnumeratorInfo>();
|
||||
|
||||
internal class EnumeratorInfo
|
||||
{
|
||||
internal MethodInfo moveNext;
|
||||
internal PropertyInfo current;
|
||||
}
|
||||
|
||||
private IEnumerable EnumerateWithReflection()
|
||||
{
|
||||
if (Value == null)
|
||||
return null;
|
||||
|
||||
// new test
|
||||
var CppEnumerable = (Value as Il2CppSystem.Object)?.TryCast<Il2CppSystem.Collections.IEnumerable>();
|
||||
if (CppEnumerable != null)
|
||||
{
|
||||
var type = Value.GetType();
|
||||
if (!s_getEnumeratorMethods.ContainsKey(type))
|
||||
s_getEnumeratorMethods.Add(type, type.GetMethod("GetEnumerator"));
|
||||
|
||||
var enumerator = s_getEnumeratorMethods[type].Invoke(Value, null);
|
||||
var enumeratorType = enumerator.GetType();
|
||||
|
||||
if (!s_enumeratorInfos.ContainsKey(enumeratorType))
|
||||
{
|
||||
s_enumeratorInfos.Add(enumeratorType, new EnumeratorInfo
|
||||
{
|
||||
current = enumeratorType.GetProperty("Current"),
|
||||
moveNext = enumeratorType.GetMethod("MoveNext"),
|
||||
});
|
||||
}
|
||||
var info = s_enumeratorInfos[enumeratorType];
|
||||
|
||||
// iterate
|
||||
var list = new List<object>();
|
||||
while ((bool)info.moveNext.Invoke(enumerator, null))
|
||||
list.Add(info.current.GetValue(enumerator));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal GameObject m_listContent;
|
||||
internal LayoutElement m_listLayout;
|
||||
@ -278,7 +203,5 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
||||
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,7 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
#if CPP
|
||||
// strings boxed as Il2CppSystem.Objects can behave weirdly.
|
||||
// GetActualType will find they are a string, but if its boxed
|
||||
// then we need to unbox it like this...
|
||||
if (!(Value is string) && Value is Il2CppSystem.Object cppobj)
|
||||
Value = cppobj.ToString();
|
||||
#endif
|
||||
Value = RuntimeProvider.Instance.Reflection.UnboxString(Value);
|
||||
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
@ -7,9 +7,19 @@ using UnityEngine.UI;
|
||||
|
||||
namespace UnityExplorer.UI.Main
|
||||
{
|
||||
public enum MenuPages
|
||||
{
|
||||
Home,
|
||||
Search,
|
||||
CSConsole,
|
||||
Options
|
||||
}
|
||||
|
||||
public abstract class BaseMenuPage
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
public abstract MenuPages Type { get; }
|
||||
public bool WasDisabled { get; internal set; }
|
||||
|
||||
public GameObject Content;
|
||||
public Button RefNavbarButton { get; set; }
|
||||
@ -20,7 +30,6 @@ namespace UnityExplorer.UI.Main
|
||||
set => Content?.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
public abstract bool Init();
|
||||
public abstract void Update();
|
||||
}
|
||||
|
@ -13,15 +13,13 @@ using UnityExplorer.UI.Main.CSConsole;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI.Utility;
|
||||
#if CPP
|
||||
using UnityExplorer.Core.Runtime.Il2Cpp;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.UI.Main.CSConsole
|
||||
{
|
||||
public class CSharpConsole : BaseMenuPage
|
||||
{
|
||||
public override string Name => "C# Console";
|
||||
public override MenuPages Type => MenuPages.CSConsole;
|
||||
|
||||
public static CSharpConsole Instance { get; private set; }
|
||||
|
||||
@ -53,9 +51,6 @@ namespace UnityExplorer.UI.Main.CSConsole
|
||||
InitConsole();
|
||||
|
||||
AutoCompleter.Init();
|
||||
#if MONO
|
||||
DummyBehaviour.Setup();
|
||||
#endif
|
||||
|
||||
ResetConsole(false);
|
||||
// Make sure compiler is supported on this platform
|
||||
@ -102,9 +97,6 @@ namespace UnityExplorer.UI.Main.CSConsole
|
||||
UpdateConsole();
|
||||
|
||||
AutoCompleter.Update();
|
||||
#if CPP
|
||||
Il2CppCoroutine.Process();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void AddUsing(string asm)
|
||||
|
@ -219,7 +219,7 @@
|
||||
<Compile Include="Core\Config\ConfigManager.cs" />
|
||||
<Compile Include="Core\Config\IConfigElement.cs" />
|
||||
<Compile Include="Core\Config\ConfigHandler.cs" />
|
||||
<Compile Include="Core\CSharp\DummyBehaviour.cs" />
|
||||
<Compile Include="Core\Runtime\Mono\DummyBehaviour.cs" />
|
||||
<Compile Include="Core\CSharp\ScriptEvaluator.cs" />
|
||||
<Compile Include="Core\CSharp\ScriptInteraction.cs" />
|
||||
<Compile Include="Core\CSharp\Suggestion.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user