mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-17 22:48:04 +08:00
Improve Il2Cpp Coroutine support, make universal ExplorerBehaviour class
This commit is contained in:
parent
d6cde68a44
commit
ab8b736f7e
62
src/Core/ExplorerBehaviour.cs
Normal file
62
src/Core/ExplorerBehaviour.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
#if CPP
|
||||||
|
using UnhollowerRuntimeLib;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace UnityExplorer
|
||||||
|
{
|
||||||
|
// Handles all Behaviour update calls for UnityExplorer (Update, FixedUpdate, OnPostRender).
|
||||||
|
// Basically just a wrapper which calls the corresponding methods in ExplorerCore.
|
||||||
|
|
||||||
|
public class ExplorerBehaviour : MonoBehaviour
|
||||||
|
{
|
||||||
|
internal static ExplorerBehaviour Instance { get; private set; }
|
||||||
|
|
||||||
|
internal static void Setup()
|
||||||
|
{
|
||||||
|
#if CPP
|
||||||
|
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
var obj = new GameObject("ExplorerBehaviour");
|
||||||
|
GameObject.DontDestroyOnLoad(obj);
|
||||||
|
obj.hideFlags |= HideFlags.HideAndDontSave;
|
||||||
|
Instance = obj.AddComponent<ExplorerBehaviour>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if CPP
|
||||||
|
public ExplorerBehaviour(IntPtr ptr) : base(ptr) { }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
internal void Awake()
|
||||||
|
{
|
||||||
|
#if CPP
|
||||||
|
Camera.onPostRender = Camera.onPostRender == null
|
||||||
|
? new Action<Camera>(OnPostRender)
|
||||||
|
: Il2CppSystem.Delegate.Combine(Camera.onPostRender, (Camera.CameraCallback)new Action<Camera>(OnPostRender)).Cast<Camera.CameraCallback>();
|
||||||
|
|
||||||
|
#else
|
||||||
|
Camera.onPostRender += OnPostRender;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Update()
|
||||||
|
{
|
||||||
|
ExplorerCore.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void FixedUpdate()
|
||||||
|
{
|
||||||
|
ExplorerCore.FixedUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void OnPostRender(Camera camera)
|
||||||
|
{
|
||||||
|
ExplorerCore.OnPostRender();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -143,6 +143,9 @@ namespace UnityExplorer.Core.Input
|
|||||||
|
|
||||||
public static void ReleaseEventSystem()
|
public static void ReleaseEventSystem()
|
||||||
{
|
{
|
||||||
|
if (EventSystem.current != UIManager.EventSys)
|
||||||
|
return;
|
||||||
|
|
||||||
if (InputManager.CurrentType == InputType.InputSystem)
|
if (InputManager.CurrentType == InputType.InputSystem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -173,7 +176,7 @@ namespace UnityExplorer.Core.Input
|
|||||||
m_lastVisibleState = (bool?)CursorType.GetProperty("visible", BF.Public | BF.Static)?.GetValue(null, null)
|
m_lastVisibleState = (bool?)CursorType.GetProperty("visible", BF.Public | BF.Static)?.GetValue(null, null)
|
||||||
?? false;
|
?? false;
|
||||||
|
|
||||||
ExplorerCore.Loader.SetupPatches();
|
ExplorerCore.Loader.SetupCursorPatches();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -124,8 +124,11 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
|||||||
if (nextAsEnumerator != null) // il2cpp IEnumerator also handles CustomYieldInstruction
|
if (nextAsEnumerator != null) // il2cpp IEnumerator also handles CustomYieldInstruction
|
||||||
next = new Il2CppEnumeratorWrapper(nextAsEnumerator);
|
next = new Il2CppEnumeratorWrapper(nextAsEnumerator);
|
||||||
else
|
else
|
||||||
ExplorerCore.LogWarning($"Unknown coroutine yield object of type {il2CppObjectBase} for coroutine {enumerator}");
|
ExplorerCore.LogWarning($"Unknown coroutine yield object of type '{il2CppObjectBase}' for coroutine '{enumerator}'");
|
||||||
break;
|
return;
|
||||||
|
default:
|
||||||
|
ExplorerCore.LogWarning($"Unknown coroutine yield object of type '{next}' for coroutine '{enumerator}'");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ourCoroutinesStore.Add(new CoroTuple { WaitCondition = next, Coroutine = enumerator });
|
ourCoroutinesStore.Add(new CoroTuple { WaitCondition = next, Coroutine = enumerator });
|
||||||
|
@ -56,6 +56,11 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
|||||||
Il2CppCoroutine.Start(routine);
|
Il2CppCoroutine.Start(routine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal override void ProcessOnPostRender()
|
||||||
|
{
|
||||||
|
Il2CppCoroutine.ProcessWaitForEndOfFrame();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
Il2CppCoroutine.Process();
|
Il2CppCoroutine.Process();
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
#if MONO
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace UnityExplorer.Core.Runtime.Mono
|
|
||||||
{
|
|
||||||
public class DummyBehaviour : MonoBehaviour
|
|
||||||
{
|
|
||||||
public static DummyBehaviour Instance;
|
|
||||||
|
|
||||||
public static void Setup()
|
|
||||||
{
|
|
||||||
var obj = new GameObject("Explorer_DummyBehaviour");
|
|
||||||
DontDestroyOnLoad(obj);
|
|
||||||
obj.hideFlags |= HideFlags.HideAndDontSave;
|
|
||||||
|
|
||||||
obj.AddComponent<DummyBehaviour>();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void Awake()
|
|
||||||
{
|
|
||||||
Instance = this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -23,8 +23,6 @@ namespace UnityExplorer.Core.Runtime.Mono
|
|||||||
ExplorerCore.Context = RuntimeContext.Mono;
|
ExplorerCore.Context = RuntimeContext.Mono;
|
||||||
Reflection = new MonoReflection();
|
Reflection = new MonoReflection();
|
||||||
TextureUtil = new MonoTextureUtil();
|
TextureUtil = new MonoTextureUtil();
|
||||||
|
|
||||||
DummyBehaviour.Setup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetupEvents()
|
public override void SetupEvents()
|
||||||
@ -39,7 +37,7 @@ namespace UnityExplorer.Core.Runtime.Mono
|
|||||||
|
|
||||||
public override void StartCoroutine(IEnumerator routine)
|
public override void StartCoroutine(IEnumerator routine)
|
||||||
{
|
{
|
||||||
DummyBehaviour.Instance.StartCoroutine(routine);
|
ExplorerBehaviour.Instance.StartCoroutine(routine);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
|
@ -65,5 +65,13 @@ namespace UnityExplorer
|
|||||||
|
|
||||||
public abstract void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null,
|
public abstract void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null,
|
||||||
Color? disabled = null);
|
Color? disabled = null);
|
||||||
|
|
||||||
|
internal virtual void ProcessOnPostRender()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
internal virtual void ProcessFixedUpdate()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,10 @@ namespace UnityExplorer
|
|||||||
LogWarning("UnityExplorer is already loaded!");
|
LogWarning("UnityExplorer is already loaded!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader = loader;
|
Loader = loader;
|
||||||
|
|
||||||
|
ExplorerBehaviour.Setup();
|
||||||
|
|
||||||
if (!Directory.Exists(Loader.ExplorerFolder))
|
if (!Directory.Exists(Loader.ExplorerFolder))
|
||||||
Directory.CreateDirectory(Loader.ExplorerFolder);
|
Directory.CreateDirectory(Loader.ExplorerFolder);
|
||||||
|
|
||||||
@ -96,6 +97,16 @@ namespace UnityExplorer
|
|||||||
UIManager.Update();
|
UIManager.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void FixedUpdate()
|
||||||
|
{
|
||||||
|
RuntimeProvider.Instance.ProcessFixedUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void OnPostRender()
|
||||||
|
{
|
||||||
|
RuntimeProvider.Instance.ProcessOnPostRender();
|
||||||
|
}
|
||||||
|
|
||||||
#region LOGGING
|
#region LOGGING
|
||||||
|
|
||||||
public static void Log(object message)
|
public static void Log(object message)
|
||||||
|
@ -57,53 +57,23 @@ namespace UnityExplorer
|
|||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
_configHandler = new BepInExConfigHandler();
|
_configHandler = new BepInExConfigHandler();
|
||||||
|
ExplorerCore.Init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MONO // Mono-specific
|
#if MONO // Mono
|
||||||
internal void Awake()
|
internal void Awake()
|
||||||
{
|
{
|
||||||
UniversalInit();
|
UniversalInit();
|
||||||
ExplorerCore.Init(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Update()
|
#else // Il2Cpp
|
||||||
{
|
|
||||||
ExplorerCore.Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // Il2Cpp-specific
|
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
UniversalInit();
|
UniversalInit();
|
||||||
|
|
||||||
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
|
|
||||||
|
|
||||||
var obj = new GameObject("ExplorerBehaviour");
|
|
||||||
obj.AddComponent<ExplorerBehaviour>();
|
|
||||||
obj.hideFlags = HideFlags.HideAndDontSave;
|
|
||||||
GameObject.DontDestroyOnLoad(obj);
|
|
||||||
|
|
||||||
ExplorerCore.Init(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// BepInEx Il2Cpp mod class doesn't have monobehaviour methods yet, so wrap them in a dummy.
|
|
||||||
public class ExplorerBehaviour : MonoBehaviour
|
|
||||||
{
|
|
||||||
public ExplorerBehaviour(IntPtr ptr) : base(ptr) { }
|
|
||||||
|
|
||||||
internal void Awake()
|
|
||||||
{
|
|
||||||
Instance.LogSource.LogMessage("ExplorerBehaviour.Awake");
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void Update()
|
|
||||||
{
|
|
||||||
ExplorerCore.Update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public void SetupPatches()
|
public void SetupCursorPatches()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,6 @@ namespace UnityExplorer
|
|||||||
Action<object> OnLogWarning { get; }
|
Action<object> OnLogWarning { get; }
|
||||||
Action<object> OnLogError { get; }
|
Action<object> OnLogError { get; }
|
||||||
|
|
||||||
void SetupPatches();
|
void SetupCursorPatches();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ namespace UnityExplorer
|
|||||||
ExplorerCore.Init(this);
|
ExplorerCore.Init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnUpdate()
|
//public override void OnUpdate()
|
||||||
{
|
//{
|
||||||
ExplorerCore.Update();
|
// ExplorerCore.Update();
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void SetupPatches()
|
public void SetupCursorPatches()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -87,30 +87,10 @@ namespace UnityExplorer
|
|||||||
Instance = this;
|
Instance = this;
|
||||||
_configHandler = new StandaloneConfigHandler();
|
_configHandler = new StandaloneConfigHandler();
|
||||||
|
|
||||||
#if CPP
|
|
||||||
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
|
|
||||||
#endif
|
|
||||||
var obj = new GameObject("ExplorerBehaviour");
|
|
||||||
obj.AddComponent<ExplorerBehaviour>();
|
|
||||||
|
|
||||||
GameObject.DontDestroyOnLoad(obj);
|
|
||||||
obj.hideFlags = HideFlags.HideAndDontSave;
|
|
||||||
|
|
||||||
ExplorerCore.Init(this);
|
ExplorerCore.Init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExplorerBehaviour : MonoBehaviour
|
public void SetupCursorPatches()
|
||||||
{
|
|
||||||
#if CPP
|
|
||||||
public ExplorerBehaviour(IntPtr ptr) : base(ptr) { }
|
|
||||||
#endif
|
|
||||||
internal void Update()
|
|
||||||
{
|
|
||||||
ExplorerCore.Update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetupPatches()
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -219,6 +219,7 @@
|
|||||||
<Compile Include="Core\Config\InternalConfigHandler.cs" />
|
<Compile Include="Core\Config\InternalConfigHandler.cs" />
|
||||||
<Compile Include="Core\CSharp\ScriptEvaluator.cs" />
|
<Compile Include="Core\CSharp\ScriptEvaluator.cs" />
|
||||||
<Compile Include="Core\CSharp\ScriptInteraction.cs" />
|
<Compile Include="Core\CSharp\ScriptInteraction.cs" />
|
||||||
|
<Compile Include="Core\ExplorerBehaviour.cs" />
|
||||||
<Compile Include="Core\Utility\MiscUtility.cs" />
|
<Compile Include="Core\Utility\MiscUtility.cs" />
|
||||||
<Compile Include="Inspectors_OLD\GameObjects\ChildList.cs" />
|
<Compile Include="Inspectors_OLD\GameObjects\ChildList.cs" />
|
||||||
<Compile Include="Inspectors_OLD\GameObjects\ComponentList.cs" />
|
<Compile Include="Inspectors_OLD\GameObjects\ComponentList.cs" />
|
||||||
@ -233,16 +234,19 @@
|
|||||||
<Compile Include="Inspectors_OLD\Reflection\StaticInspector.cs" />
|
<Compile Include="Inspectors_OLD\Reflection\StaticInspector.cs" />
|
||||||
<Compile Include="UI\CSConsole\CSConsoleManager.cs" />
|
<Compile Include="UI\CSConsole\CSConsoleManager.cs" />
|
||||||
<Compile Include="UI\Inspectors\CacheObject\CacheField.cs" />
|
<Compile Include="UI\Inspectors\CacheObject\CacheField.cs" />
|
||||||
|
<Compile Include="UI\Inspectors\CacheObject\CacheListEntry.cs" />
|
||||||
<Compile Include="UI\Inspectors\CacheObject\CacheMember.cs" />
|
<Compile Include="UI\Inspectors\CacheObject\CacheMember.cs" />
|
||||||
<Compile Include="UI\Inspectors\CacheObject\CacheMethod.cs" />
|
<Compile Include="UI\Inspectors\CacheObject\CacheMethod.cs" />
|
||||||
<Compile Include="UI\Inspectors\CacheObject\CacheObjectBase.cs" />
|
<Compile Include="UI\Inspectors\CacheObject\CacheObjectBase.cs" />
|
||||||
<Compile Include="UI\Inspectors\CacheObject\CacheProperty.cs" />
|
<Compile Include="UI\Inspectors\CacheObject\CacheProperty.cs" />
|
||||||
|
<Compile Include="UI\Inspectors\CacheObject\Views\CacheListEntryCell.cs" />
|
||||||
<Compile Include="UI\Inspectors\CacheObject\Views\CacheMemberCell.cs" />
|
<Compile Include="UI\Inspectors\CacheObject\Views\CacheMemberCell.cs" />
|
||||||
<Compile Include="UI\Inspectors\CacheObject\Views\CacheObjectCell.cs" />
|
<Compile Include="UI\Inspectors\CacheObject\Views\CacheObjectCell.cs" />
|
||||||
<Compile Include="UI\Inspectors\GameObjectInspector.cs" />
|
<Compile Include="UI\Inspectors\GameObjectInspector.cs" />
|
||||||
<Compile Include="UI\Inspectors\InspectorManager.cs" />
|
<Compile Include="UI\Inspectors\InspectorManager.cs" />
|
||||||
<Compile Include="UI\Inspectors\InspectorTab.cs" />
|
<Compile Include="UI\Inspectors\InspectorTab.cs" />
|
||||||
<Compile Include="UI\Inspectors\InspectorBase.cs" />
|
<Compile Include="UI\Inspectors\InspectorBase.cs" />
|
||||||
|
<Compile Include="UI\Inspectors\IValues\InteractiveList.cs" />
|
||||||
<Compile Include="UI\Inspectors\IValues\InteractiveValue.cs" />
|
<Compile Include="UI\Inspectors\IValues\InteractiveValue.cs" />
|
||||||
<Compile Include="UI\Inspectors\ReflectionInspector.cs" />
|
<Compile Include="UI\Inspectors\ReflectionInspector.cs" />
|
||||||
<Compile Include="UI\ObjectPool\IPooledObject.cs" />
|
<Compile Include="UI\ObjectPool\IPooledObject.cs" />
|
||||||
@ -267,7 +271,6 @@
|
|||||||
<Compile Include="Core\Runtime\Il2Cpp\Il2CppProvider.cs" />
|
<Compile Include="Core\Runtime\Il2Cpp\Il2CppProvider.cs" />
|
||||||
<Compile Include="Core\Runtime\Il2Cpp\Il2CppReflection.cs" />
|
<Compile Include="Core\Runtime\Il2Cpp\Il2CppReflection.cs" />
|
||||||
<Compile Include="Core\Runtime\Il2Cpp\Il2CppTextureUtil.cs" />
|
<Compile Include="Core\Runtime\Il2Cpp\Il2CppTextureUtil.cs" />
|
||||||
<Compile Include="Core\Runtime\Mono\DummyBehaviour.cs" />
|
|
||||||
<Compile Include="Core\Runtime\Mono\MonoProvider.cs" />
|
<Compile Include="Core\Runtime\Mono\MonoProvider.cs" />
|
||||||
<Compile Include="Core\Runtime\Mono\MonoReflection.cs" />
|
<Compile Include="Core\Runtime\Mono\MonoReflection.cs" />
|
||||||
<Compile Include="Core\Runtime\Mono\MonoTextureUtil.cs" />
|
<Compile Include="Core\Runtime\Mono\MonoTextureUtil.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user