Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 9e49f09

Browse files
committed
Bump UniverseLib, fix C# Console issues, add Stop helper
1 parent b9a3ab7 commit 9e49f09

File tree

4 files changed

+58
-33
lines changed

4 files changed

+58
-33
lines changed

src/CSConsole/ConsoleController.cs

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using UniverseLib.UI.Models;
2020
using UniverseLib.Utility;
2121
using HarmonyLib;
22+
using UniverseLib.Runtime;
2223

2324
namespace UnityExplorer.CSConsole
2425
{
@@ -61,6 +62,8 @@ public static class ConsoleController
6162

6263
public static void Init()
6364
{
65+
InitEventSystemPropertyHandlers();
66+
6467
// Make sure console is supported on this platform
6568
try
6669
{
@@ -384,37 +387,55 @@ private static void SetCaretPosition(int caretPosition)
384387
RuntimeHelper.StartCoroutine(SetCaretCoroutine(caretPosition));
385388
}
386389

387-
internal static MemberInfo selectionGuardMemberInfo;
390+
static void InitEventSystemPropertyHandlers()
391+
{
392+
try
393+
{
394+
foreach (var member in typeof(EventSystem).GetMembers(AccessTools.all))
395+
{
396+
if (member.Name == "m_CurrentSelected")
397+
{
398+
Type backingType;
399+
if (member.MemberType == MemberTypes.Property)
400+
backingType = (member as PropertyInfo).PropertyType;
401+
else
402+
backingType = (member as FieldInfo).FieldType;
388403

389-
internal static MemberInfo GetSelectionGuardMemberInfo()
404+
usingEventSystemDictionaryMembers = ReflectionUtility.IsDictionary(backingType);
405+
break;
406+
}
407+
}
408+
}
409+
catch (Exception ex)
410+
{
411+
ExplorerCore.LogWarning($"Exception checking EventSystem property backing type: {ex}");
412+
}
413+
}
414+
415+
static bool usingEventSystemDictionaryMembers;
416+
417+
static readonly AmbiguousMemberHandler<EventSystem, GameObject> m_CurrentSelected_Handler_Normal = new("m_CurrentSelected", "m_currentSelected");
418+
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, GameObject>> m_CurrentSelected_Handler_Dictionary = new("m_CurrentSelected", "m_currentSelected");
419+
420+
static readonly AmbiguousMemberHandler<EventSystem, bool> m_SelectionGuard_Handler_Normal = new("m_SelectionGuard", "m_selectionGuard");
421+
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, bool>> m_SelectionGuard_Handler_Dictionary = new("m_SelectionGuard", "m_selectionGuard");
422+
423+
static void SetCurrentSelectedGameObject(EventSystem instance, GameObject value)
390424
{
391-
if (selectionGuardMemberInfo != null)
392-
return selectionGuardMemberInfo;
393-
394-
if (AccessTools.Property(typeof(EventSystem), "m_SelectionGuard") is PropertyInfo pi_m_SelectionGuard)
395-
return selectionGuardMemberInfo = pi_m_SelectionGuard;
396-
397-
if (AccessTools.Property(typeof(EventSystem), "m_selectionGuard") is PropertyInfo pi_m_selectionGuard)
398-
return selectionGuardMemberInfo = pi_m_selectionGuard;
399-
400-
if (AccessTools.Field(typeof(EventSystem), "m_SelectionGuard") is FieldInfo fi_m_SelectionGuard)
401-
return selectionGuardMemberInfo = fi_m_SelectionGuard;
402-
403-
return selectionGuardMemberInfo = AccessTools.Field(typeof(EventSystem), "m_selectionGuard");
425+
instance.SetSelectedGameObject(value);
426+
427+
if (usingEventSystemDictionaryMembers)
428+
m_CurrentSelected_Handler_Dictionary.GetValue(instance)[0] = value;
429+
else
430+
m_CurrentSelected_Handler_Normal.SetValue(instance, value);
404431
}
405432

406-
internal static void SetSelectionGuard(EventSystem instance, bool value)
433+
static void SetSelectionGuard(EventSystem instance, bool value)
407434
{
408-
var member = GetSelectionGuardMemberInfo();
409-
if (member == null)
410-
return;
411-
if (member is PropertyInfo pi)
412-
{
413-
pi.SetValue(instance, value, null);
414-
return;
415-
}
416-
var fi = member as FieldInfo;
417-
fi.SetValue(instance, value);
435+
if (usingEventSystemDictionaryMembers)
436+
m_SelectionGuard_Handler_Dictionary.GetValue(instance)[0] = value;
437+
else
438+
m_SelectionGuard_Handler_Normal.SetValue(instance, value);
418439
}
419440

420441
private static IEnumerator SetCaretCoroutine(int caretPosition)
@@ -423,15 +444,15 @@ private static IEnumerator SetCaretCoroutine(int caretPosition)
423444
color.a = 0f;
424445
Input.Component.selectionColor = color;
425446

426-
try { CursorUnlocker.CurrentEventSystem.m_CurrentSelected = null; }
447+
try { SetCurrentSelectedGameObject(CursorUnlocker.CurrentEventSystem, null); }
427448
catch (Exception ex) { ExplorerCore.Log($"Failed removing selected object: {ex}"); }
428449

429450
yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~
430451

431452
try { SetSelectionGuard(CursorUnlocker.CurrentEventSystem, false); }
432453
catch (Exception ex) { ExplorerCore.Log($"Failed setting selection guard: {ex}"); }
433454

434-
try { CursorUnlocker.CurrentEventSystem.SetSelectedGameObject(Input.GameObject, null); }
455+
try { SetCurrentSelectedGameObject(CursorUnlocker.CurrentEventSystem, Input.GameObject); }
435456
catch (Exception ex) { ExplorerCore.Log($"Failed setting selected gameobject: {ex}"); }
436457

437458
yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~
@@ -695,7 +716,8 @@ public static void HelpSelected(int index)
695716
* Log(obj); - prints a message to the console log
696717
* Inspect(obj); - inspect the object with the Inspector
697718
* Inspect(someType); - inspect a Type with static reflection
698-
* Start(enumerator); - starts the IEnumerator as a Coroutine
719+
* Start(enumerator); - Coroutine, starts the IEnumerator as a Coroutine, and returns the Coroutine.
720+
* Stop(coroutine); - stop the Coroutine ONLY if it was started with Start(ienumerator).
699721
* Copy(obj); - copies the object to the UnityExplorer Clipboard
700722
* Paste(); - System.Object, the contents of the Clipboard.
701723
* GetUsing(); - prints the current using directives to the console log

src/CSConsole/ScriptInteraction.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ public static void Inspect(object obj)
2929
public static void Inspect(Type type)
3030
=> InspectorManager.Inspect(type);
3131

32-
public static void Start(IEnumerator ienumerator)
32+
public static Coroutine Start(IEnumerator ienumerator)
3333
=> RuntimeHelper.StartCoroutine(ienumerator);
3434

35+
public static void Stop(Coroutine coro)
36+
=> RuntimeHelper.StopCoroutine(coro);
37+
3538
public static void Copy(object obj)
3639
=> ClipboardPanel.Copy(obj);
3740

src/UnityExplorer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@
175175
<Private>False</Private>
176176
</Reference>
177177
<Reference Include="UniverseLib.Mono">
178-
<HintPath>packages\UniverseLib.1.2.5\lib\net35\UniverseLib.Mono.dll</HintPath>
178+
<HintPath>packages\UniverseLib.1.2.6\lib\net35\UniverseLib.Mono.dll</HintPath>
179179
</Reference>
180180
</ItemGroup>
181181
<!-- Il2Cpp refs -->
182182
<ItemGroup Condition="'$(IsCpp)'=='true'">
183183
<Reference Include="UniverseLib.IL2CPP">
184-
<HintPath>packages\UniverseLib.1.2.5\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
184+
<HintPath>packages\UniverseLib.1.2.6\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
185185
</Reference>
186186
<Reference Include="UnhollowerBaseLib, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
187187
<HintPath>packages\Il2CppAssemblyUnhollower.BaseLib.0.4.22\lib\net472\UnhollowerBaseLib.dll</HintPath>

src/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" />
77
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
88
<package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" />
9-
<package id="UniverseLib" version="1.2.5" targetFramework="net35" />
9+
<package id="UniverseLib" version="1.2.6" targetFramework="net35" />
1010
<package id="UniverseLib.Analyzers" version="1.0.3" targetFramework="net35" developmentDependency="true" />
1111
</packages>

0 commit comments

Comments
 (0)