mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-01-09 18:48:46 +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()
|
||||
{
|
||||
if (EventSystem.current != UIManager.EventSys)
|
||||
return;
|
||||
|
||||
if (InputManager.CurrentType == InputType.InputSystem)
|
||||
return;
|
||||
|
||||
@ -173,7 +176,7 @@ namespace UnityExplorer.Core.Input
|
||||
m_lastVisibleState = (bool?)CursorType.GetProperty("visible", BF.Public | BF.Static)?.GetValue(null, null)
|
||||
?? false;
|
||||
|
||||
ExplorerCore.Loader.SetupPatches();
|
||||
ExplorerCore.Loader.SetupCursorPatches();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -124,8 +124,11 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
if (nextAsEnumerator != null) // il2cpp IEnumerator also handles CustomYieldInstruction
|
||||
next = new Il2CppEnumeratorWrapper(nextAsEnumerator);
|
||||
else
|
||||
ExplorerCore.LogWarning($"Unknown coroutine yield object of type {il2CppObjectBase} for coroutine {enumerator}");
|
||||
break;
|
||||
ExplorerCore.LogWarning($"Unknown coroutine yield object of type '{il2CppObjectBase}' for coroutine '{enumerator}'");
|
||||
return;
|
||||
default:
|
||||
ExplorerCore.LogWarning($"Unknown coroutine yield object of type '{next}' for coroutine '{enumerator}'");
|
||||
return;
|
||||
}
|
||||
|
||||
ourCoroutinesStore.Add(new CoroTuple { WaitCondition = next, Coroutine = enumerator });
|
||||
|
@ -56,6 +56,11 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
Il2CppCoroutine.Start(routine);
|
||||
}
|
||||
|
||||
internal override void ProcessOnPostRender()
|
||||
{
|
||||
Il2CppCoroutine.ProcessWaitForEndOfFrame();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
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;
|
||||
Reflection = new MonoReflection();
|
||||
TextureUtil = new MonoTextureUtil();
|
||||
|
||||
DummyBehaviour.Setup();
|
||||
}
|
||||
|
||||
public override void SetupEvents()
|
||||
@ -39,7 +37,7 @@ namespace UnityExplorer.Core.Runtime.Mono
|
||||
|
||||
public override void StartCoroutine(IEnumerator routine)
|
||||
{
|
||||
DummyBehaviour.Instance.StartCoroutine(routine);
|
||||
ExplorerBehaviour.Instance.StartCoroutine(routine);
|
||||
}
|
||||
|
||||
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,
|
||||
Color? disabled = null);
|
||||
|
||||
internal virtual void ProcessOnPostRender()
|
||||
{
|
||||
}
|
||||
|
||||
internal virtual void ProcessFixedUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,9 +34,10 @@ namespace UnityExplorer
|
||||
LogWarning("UnityExplorer is already loaded!");
|
||||
return;
|
||||
}
|
||||
|
||||
Loader = loader;
|
||||
|
||||
ExplorerBehaviour.Setup();
|
||||
|
||||
if (!Directory.Exists(Loader.ExplorerFolder))
|
||||
Directory.CreateDirectory(Loader.ExplorerFolder);
|
||||
|
||||
@ -96,6 +97,16 @@ namespace UnityExplorer
|
||||
UIManager.Update();
|
||||
}
|
||||
|
||||
public static void FixedUpdate()
|
||||
{
|
||||
RuntimeProvider.Instance.ProcessFixedUpdate();
|
||||
}
|
||||
|
||||
public static void OnPostRender()
|
||||
{
|
||||
RuntimeProvider.Instance.ProcessOnPostRender();
|
||||
}
|
||||
|
||||
#region LOGGING
|
||||
|
||||
public static void Log(object message)
|
||||
|
@ -57,53 +57,23 @@ namespace UnityExplorer
|
||||
{
|
||||
Instance = this;
|
||||
_configHandler = new BepInExConfigHandler();
|
||||
ExplorerCore.Init(this);
|
||||
}
|
||||
|
||||
#if MONO // Mono-specific
|
||||
#if MONO // Mono
|
||||
internal void Awake()
|
||||
{
|
||||
UniversalInit();
|
||||
ExplorerCore.Init(this);
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
ExplorerCore.Update();
|
||||
}
|
||||
|
||||
#else // Il2Cpp-specific
|
||||
#else // Il2Cpp
|
||||
public override void Load()
|
||||
{
|
||||
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
|
||||
|
||||
public void SetupPatches()
|
||||
public void SetupCursorPatches()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -17,6 +17,6 @@ namespace UnityExplorer
|
||||
Action<object> OnLogWarning { get; }
|
||||
Action<object> OnLogError { get; }
|
||||
|
||||
void SetupPatches();
|
||||
void SetupCursorPatches();
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ namespace UnityExplorer
|
||||
ExplorerCore.Init(this);
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
ExplorerCore.Update();
|
||||
}
|
||||
//public override void OnUpdate()
|
||||
//{
|
||||
// ExplorerCore.Update();
|
||||
//}
|
||||
|
||||
public void SetupPatches()
|
||||
public void SetupCursorPatches()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -87,30 +87,10 @@ namespace UnityExplorer
|
||||
Instance = this;
|
||||
_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);
|
||||
}
|
||||
|
||||
public class ExplorerBehaviour : MonoBehaviour
|
||||
{
|
||||
#if CPP
|
||||
public ExplorerBehaviour(IntPtr ptr) : base(ptr) { }
|
||||
#endif
|
||||
internal void Update()
|
||||
{
|
||||
ExplorerCore.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetupPatches()
|
||||
public void SetupCursorPatches()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -219,6 +219,7 @@
|
||||
<Compile Include="Core\Config\InternalConfigHandler.cs" />
|
||||
<Compile Include="Core\CSharp\ScriptEvaluator.cs" />
|
||||
<Compile Include="Core\CSharp\ScriptInteraction.cs" />
|
||||
<Compile Include="Core\ExplorerBehaviour.cs" />
|
||||
<Compile Include="Core\Utility\MiscUtility.cs" />
|
||||
<Compile Include="Inspectors_OLD\GameObjects\ChildList.cs" />
|
||||
<Compile Include="Inspectors_OLD\GameObjects\ComponentList.cs" />
|
||||
@ -233,16 +234,19 @@
|
||||
<Compile Include="Inspectors_OLD\Reflection\StaticInspector.cs" />
|
||||
<Compile Include="UI\CSConsole\CSConsoleManager.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\CacheMethod.cs" />
|
||||
<Compile Include="UI\Inspectors\CacheObject\CacheObjectBase.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\CacheObjectCell.cs" />
|
||||
<Compile Include="UI\Inspectors\GameObjectInspector.cs" />
|
||||
<Compile Include="UI\Inspectors\InspectorManager.cs" />
|
||||
<Compile Include="UI\Inspectors\InspectorTab.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\ReflectionInspector.cs" />
|
||||
<Compile Include="UI\ObjectPool\IPooledObject.cs" />
|
||||
@ -267,7 +271,6 @@
|
||||
<Compile Include="Core\Runtime\Il2Cpp\Il2CppProvider.cs" />
|
||||
<Compile Include="Core\Runtime\Il2Cpp\Il2CppReflection.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\MonoReflection.cs" />
|
||||
<Compile Include="Core\Runtime\Mono\MonoTextureUtil.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user