From 2cc403ad1732b965814fa3eaabd1b77175eff957 Mon Sep 17 00:00:00 2001
From: Sinai
Date: Wed, 7 Apr 2021 17:20:09 +1000
Subject: [PATCH] Cleanup runtime-specific
---
README.md | 2 +-
src/Core/CSharp/ScriptInteraction.cs | 2 +-
src/Core/Input/CursorUnlocker.cs | 2 +-
src/Core/Input/IHandleInput.cs | 2 +-
src/Core/Input/InputSystem.cs | 15 +-
src/Core/Input/LegacyInput.cs | 2 +-
src/Core/Input/NoInput.cs | 2 +-
src/Core/ReflectionUtility.cs | 6 +-
src/Core/Runtime/Il2Cpp/Il2CppProvider.cs | 59 +++++++-
src/Core/Runtime/Il2Cpp/Il2CppReflection.cs | 130 ++++++++++++++++++
.../Mono}/DummyBehaviour.cs | 2 +-
src/Core/Runtime/Mono/MonoProvider.cs | 25 +++-
src/Core/Runtime/Mono/MonoReflection.cs | 12 ++
src/Core/Runtime/ReflectionProvider.cs | 11 ++
src/Core/Runtime/RuntimeProvider.cs | 45 ++++--
src/Core/Search/SearchProvider.cs | 40 +-----
src/Core/TestClass.cs | 7 +
src/ExplorerCore.cs | 6 +-
src/Loader/ML/MelonLoaderConfigHandler.cs | 26 ++++
src/UI/CacheObject/CachePaired.cs | 8 +-
.../Inspectors/GameObjects/ComponentList.cs | 10 --
src/UI/Inspectors/InspectUnderMouse.cs | 14 +-
src/UI/Inspectors/InspectorManager.cs | 12 +-
.../InteractiveDictionary.cs | 96 ++-----------
.../InteractiveEnumerable.cs | 83 +----------
src/UI/InteractiveValues/InteractiveString.cs | 8 +-
src/UI/Main/BaseMenuPage.cs | 11 +-
src/UI/Main/CSConsole/CSharpConsole.cs | 10 +-
src/UnityExplorer.csproj | 2 +-
29 files changed, 362 insertions(+), 288 deletions(-)
rename src/Core/{CSharp => Runtime/Mono}/DummyBehaviour.cs (93%)
diff --git a/README.md b/README.md
index 4e813a7..7fc463e 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
An in-game explorer and a suite of debugging tools for IL2CPP and Mono Unity games, to aid with modding development.
-## Releases [](../../releases/latest) [](../../releases) [](../../releases/latest)
+## Releases [](../../releases/latest) [](../../releases) [](../../releases/latest)
| Mod Loader | IL2CPP | Mono |
| ----------- | ------ | ---- |
diff --git a/src/Core/CSharp/ScriptInteraction.cs b/src/Core/CSharp/ScriptInteraction.cs
index 034b3c9..0c71220 100644
--- a/src/Core/CSharp/ScriptInteraction.cs
+++ b/src/Core/CSharp/ScriptInteraction.cs
@@ -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)
diff --git a/src/Core/Input/CursorUnlocker.cs b/src/Core/Input/CursorUnlocker.cs
index 7cb3d5c..86a218a 100644
--- a/src/Core/Input/CursorUnlocker.cs
+++ b/src/Core/Input/CursorUnlocker.cs
@@ -189,4 +189,4 @@ namespace UnityExplorer.Core.Input
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/Input/IHandleInput.cs b/src/Core/Input/IHandleInput.cs
index 279e929..6fe0bfe 100644
--- a/src/Core/Input/IHandleInput.cs
+++ b/src/Core/Input/IHandleInput.cs
@@ -18,4 +18,4 @@ namespace UnityExplorer.Core.Input
void AddUIInputModule();
void ActivateModule();
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/Input/InputSystem.cs b/src/Core/Input/InputSystem.cs
index 51c1e31..cb1c1bd 100644
--- a/src/Core/Input/InputSystem.cs
+++ b/src/Core/Input/InputSystem.cs
@@ -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();
- 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(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]);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/Input/LegacyInput.cs b/src/Core/Input/LegacyInput.cs
index bdcebd4..65d4ad1 100644
--- a/src/Core/Input/LegacyInput.cs
+++ b/src/Core/Input/LegacyInput.cs
@@ -54,4 +54,4 @@ namespace UnityExplorer.Core.Input
m_inputModule.ActivateModule();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/Input/NoInput.cs b/src/Core/Input/NoInput.cs
index 3fcf8ca..159767e 100644
--- a/src/Core/Input/NoInput.cs
+++ b/src/Core/Input/NoInput.cs
@@ -19,4 +19,4 @@ namespace UnityExplorer.Core.Input
public void ActivateModule() { }
public void AddUIInputModule() { }
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/ReflectionUtility.cs b/src/Core/ReflectionUtility.cs
index 916d536..863b1ee 100644
--- a/src/Core/ReflectionUtility.cs
+++ b/src/Core/ReflectionUtility.cs
@@ -43,6 +43,9 @@ namespace UnityExplorer
public static object Cast(this object obj, Type castTo)
=> ReflectionProvider.Instance.Cast(obj, castTo);
+ public static T TryCast(this object obj)
+ => ReflectionProvider.Instance.TryCast(obj);
+
///
/// Check if the provided Type is assignable to IEnumerable.
///
@@ -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;
}
}
diff --git a/src/Core/Runtime/Il2Cpp/Il2CppProvider.cs b/src/Core/Runtime/Il2Cpp/Il2CppProvider.cs
index 8d2f920..ad580ae 100644
--- a/src/Core/Runtime/Il2Cpp/Il2CppProvider.cs
+++ b/src/Core/Runtime/Il2Cpp/Il2CppProvider.cs
@@ -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(GameObject obj, Type type)
+ {
+ return obj.AddComponent(Il2CppType.From(type)).TryCast();
+ }
+
+ public override ScriptableObject CreateScriptable(Type type)
+ {
+ return ScriptableObject.CreateInstance(Il2CppType.From(type));
+ }
+
+ public override void GraphicRaycast(GraphicRaycaster raycaster, PointerEventData data, List list)
+ {
+ var il2cppList = new Il2CppSystem.Collections.Generic.List();
+
+ raycaster.Raycast(data, il2cppList);
+
+ if (il2cppList.Count > 0)
+ list.AddRange(il2cppList.ToArray());
+ }
+
+ public override bool IsReferenceEqual(object a, object b)
+ {
+ if (a.TryCast() is UnityEngine.Object ua)
+ {
+ var ub = b.TryCast();
+ 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