Bump UniverseLib, fix C# Console issues, add Stop helper

This commit is contained in:
Sinai 2022-02-04 20:34:05 +11:00
parent b9a3ab7439
commit 9e49f09a79
4 changed files with 58 additions and 33 deletions

View File

@ -19,6 +19,7 @@ using UniverseLib;
using UniverseLib.UI.Models; using UniverseLib.UI.Models;
using UniverseLib.Utility; using UniverseLib.Utility;
using HarmonyLib; using HarmonyLib;
using UniverseLib.Runtime;
namespace UnityExplorer.CSConsole namespace UnityExplorer.CSConsole
{ {
@ -61,6 +62,8 @@ namespace UnityExplorer.CSConsole
public static void Init() public static void Init()
{ {
InitEventSystemPropertyHandlers();
// Make sure console is supported on this platform // Make sure console is supported on this platform
try try
{ {
@ -384,37 +387,55 @@ namespace UnityExplorer.CSConsole
RuntimeHelper.StartCoroutine(SetCaretCoroutine(caretPosition)); RuntimeHelper.StartCoroutine(SetCaretCoroutine(caretPosition));
} }
internal static MemberInfo selectionGuardMemberInfo; static void InitEventSystemPropertyHandlers()
internal static MemberInfo GetSelectionGuardMemberInfo()
{ {
if (selectionGuardMemberInfo != null) try
return selectionGuardMemberInfo; {
foreach (var member in typeof(EventSystem).GetMembers(AccessTools.all))
{
if (member.Name == "m_CurrentSelected")
{
Type backingType;
if (member.MemberType == MemberTypes.Property)
backingType = (member as PropertyInfo).PropertyType;
else
backingType = (member as FieldInfo).FieldType;
if (AccessTools.Property(typeof(EventSystem), "m_SelectionGuard") is PropertyInfo pi_m_SelectionGuard) usingEventSystemDictionaryMembers = ReflectionUtility.IsDictionary(backingType);
return selectionGuardMemberInfo = pi_m_SelectionGuard; break;
}
if (AccessTools.Property(typeof(EventSystem), "m_selectionGuard") is PropertyInfo pi_m_selectionGuard) }
return selectionGuardMemberInfo = pi_m_selectionGuard; }
catch (Exception ex)
if (AccessTools.Field(typeof(EventSystem), "m_SelectionGuard") is FieldInfo fi_m_SelectionGuard) {
return selectionGuardMemberInfo = fi_m_SelectionGuard; ExplorerCore.LogWarning($"Exception checking EventSystem property backing type: {ex}");
}
return selectionGuardMemberInfo = AccessTools.Field(typeof(EventSystem), "m_selectionGuard");
} }
internal static void SetSelectionGuard(EventSystem instance, bool value) static bool usingEventSystemDictionaryMembers;
static readonly AmbiguousMemberHandler<EventSystem, GameObject> m_CurrentSelected_Handler_Normal = new("m_CurrentSelected", "m_currentSelected");
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, GameObject>> m_CurrentSelected_Handler_Dictionary = new("m_CurrentSelected", "m_currentSelected");
static readonly AmbiguousMemberHandler<EventSystem, bool> m_SelectionGuard_Handler_Normal = new("m_SelectionGuard", "m_selectionGuard");
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, bool>> m_SelectionGuard_Handler_Dictionary = new("m_SelectionGuard", "m_selectionGuard");
static void SetCurrentSelectedGameObject(EventSystem instance, GameObject value)
{ {
var member = GetSelectionGuardMemberInfo(); instance.SetSelectedGameObject(value);
if (member == null)
return; if (usingEventSystemDictionaryMembers)
if (member is PropertyInfo pi) m_CurrentSelected_Handler_Dictionary.GetValue(instance)[0] = value;
{ else
pi.SetValue(instance, value, null); m_CurrentSelected_Handler_Normal.SetValue(instance, value);
return; }
}
var fi = member as FieldInfo; static void SetSelectionGuard(EventSystem instance, bool value)
fi.SetValue(instance, value); {
if (usingEventSystemDictionaryMembers)
m_SelectionGuard_Handler_Dictionary.GetValue(instance)[0] = value;
else
m_SelectionGuard_Handler_Normal.SetValue(instance, value);
} }
private static IEnumerator SetCaretCoroutine(int caretPosition) private static IEnumerator SetCaretCoroutine(int caretPosition)
@ -423,7 +444,7 @@ namespace UnityExplorer.CSConsole
color.a = 0f; color.a = 0f;
Input.Component.selectionColor = color; Input.Component.selectionColor = color;
try { CursorUnlocker.CurrentEventSystem.m_CurrentSelected = null; } try { SetCurrentSelectedGameObject(CursorUnlocker.CurrentEventSystem, null); }
catch (Exception ex) { ExplorerCore.Log($"Failed removing selected object: {ex}"); } catch (Exception ex) { ExplorerCore.Log($"Failed removing selected object: {ex}"); }
yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~ yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~
@ -431,7 +452,7 @@ namespace UnityExplorer.CSConsole
try { SetSelectionGuard(CursorUnlocker.CurrentEventSystem, false); } try { SetSelectionGuard(CursorUnlocker.CurrentEventSystem, false); }
catch (Exception ex) { ExplorerCore.Log($"Failed setting selection guard: {ex}"); } catch (Exception ex) { ExplorerCore.Log($"Failed setting selection guard: {ex}"); }
try { CursorUnlocker.CurrentEventSystem.SetSelectedGameObject(Input.GameObject, null); } try { SetCurrentSelectedGameObject(CursorUnlocker.CurrentEventSystem, Input.GameObject); }
catch (Exception ex) { ExplorerCore.Log($"Failed setting selected gameobject: {ex}"); } catch (Exception ex) { ExplorerCore.Log($"Failed setting selected gameobject: {ex}"); }
yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~ yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~
@ -695,7 +716,8 @@ var x = 5;
* Log(obj); - prints a message to the console log * Log(obj); - prints a message to the console log
* Inspect(obj); - inspect the object with the Inspector * Inspect(obj); - inspect the object with the Inspector
* Inspect(someType); - inspect a Type with static reflection * Inspect(someType); - inspect a Type with static reflection
* Start(enumerator); - starts the IEnumerator as a Coroutine * Start(enumerator); - Coroutine, starts the IEnumerator as a Coroutine, and returns the Coroutine.
* Stop(coroutine); - stop the Coroutine ONLY if it was started with Start(ienumerator).
* Copy(obj); - copies the object to the UnityExplorer Clipboard * Copy(obj); - copies the object to the UnityExplorer Clipboard
* Paste(); - System.Object, the contents of the Clipboard. * Paste(); - System.Object, the contents of the Clipboard.
* GetUsing(); - prints the current using directives to the console log * GetUsing(); - prints the current using directives to the console log

View File

@ -29,9 +29,12 @@ namespace UnityExplorer.CSConsole
public static void Inspect(Type type) public static void Inspect(Type type)
=> InspectorManager.Inspect(type); => InspectorManager.Inspect(type);
public static void Start(IEnumerator ienumerator) public static Coroutine Start(IEnumerator ienumerator)
=> RuntimeHelper.StartCoroutine(ienumerator); => RuntimeHelper.StartCoroutine(ienumerator);
public static void Stop(Coroutine coro)
=> RuntimeHelper.StopCoroutine(coro);
public static void Copy(object obj) public static void Copy(object obj)
=> ClipboardPanel.Copy(obj); => ClipboardPanel.Copy(obj);

View File

@ -175,13 +175,13 @@
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="UniverseLib.Mono"> <Reference Include="UniverseLib.Mono">
<HintPath>packages\UniverseLib.1.2.5\lib\net35\UniverseLib.Mono.dll</HintPath> <HintPath>packages\UniverseLib.1.2.6\lib\net35\UniverseLib.Mono.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<!-- Il2Cpp refs --> <!-- Il2Cpp refs -->
<ItemGroup Condition="'$(IsCpp)'=='true'"> <ItemGroup Condition="'$(IsCpp)'=='true'">
<Reference Include="UniverseLib.IL2CPP"> <Reference Include="UniverseLib.IL2CPP">
<HintPath>packages\UniverseLib.1.2.5\lib\net472\UniverseLib.IL2CPP.dll</HintPath> <HintPath>packages\UniverseLib.1.2.6\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
</Reference> </Reference>
<Reference Include="UnhollowerBaseLib, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="UnhollowerBaseLib, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Il2CppAssemblyUnhollower.BaseLib.0.4.22\lib\net472\UnhollowerBaseLib.dll</HintPath> <HintPath>packages\Il2CppAssemblyUnhollower.BaseLib.0.4.22\lib\net472\UnhollowerBaseLib.dll</HintPath>

View File

@ -6,6 +6,6 @@
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" /> <package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" />
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" /> <package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
<package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" /> <package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" />
<package id="UniverseLib" version="1.2.5" targetFramework="net35" /> <package id="UniverseLib" version="1.2.6" targetFramework="net35" />
<package id="UniverseLib.Analyzers" version="1.0.3" targetFramework="net35" developmentDependency="true" /> <package id="UniverseLib.Analyzers" version="1.0.3" targetFramework="net35" developmentDependency="true" />
</packages> </packages>