|
18 | 18 | using UniverseLib;
|
19 | 19 | using UniverseLib.UI.Models;
|
20 | 20 | using UniverseLib.Utility;
|
| 21 | +using HarmonyLib; |
21 | 22 |
|
22 | 23 | namespace UnityExplorer.CSConsole
|
23 | 24 | {
|
@@ -383,30 +384,59 @@ private static void SetCaretPosition(int caretPosition)
|
383 | 384 | RuntimeHelper.StartCoroutine(SetCaretCoroutine(caretPosition));
|
384 | 385 | }
|
385 | 386 |
|
386 |
| - internal static PropertyInfo SelectionGuardProperty => selectionGuardPropInfo ?? GetSelectionGuardPropInfo(); |
| 387 | + internal static MemberInfo selectionGuardMemberInfo; |
387 | 388 |
|
388 |
| - private static PropertyInfo GetSelectionGuardPropInfo() |
| 389 | + internal static MemberInfo GetSelectionGuardMemberInfo() |
389 | 390 | {
|
390 |
| - selectionGuardPropInfo = typeof(EventSystem).GetProperty("m_SelectionGuard"); |
391 |
| - if (selectionGuardPropInfo == null) |
392 |
| - selectionGuardPropInfo = typeof(EventSystem).GetProperty("m_selectionGuard"); |
393 |
| - return selectionGuardPropInfo; |
| 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"); |
394 | 404 | }
|
395 | 405 |
|
396 |
| - private static PropertyInfo selectionGuardPropInfo; |
| 406 | + internal static void SetSelectionGuard(EventSystem instance, bool value) |
| 407 | + { |
| 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); |
| 418 | + } |
397 | 419 |
|
398 | 420 | private static IEnumerator SetCaretCoroutine(int caretPosition)
|
399 | 421 | {
|
400 | 422 | var color = Input.Component.selectionColor;
|
401 | 423 | color.a = 0f;
|
402 | 424 | Input.Component.selectionColor = color;
|
403 |
| - try { EventSystem.current.SetSelectedGameObject(null, null); } catch { } |
404 |
| - yield return null; |
405 | 425 |
|
406 |
| - try { SelectionGuardProperty.SetValue(EventSystem.current, false, null); } catch { } |
407 |
| - try { EventSystem.current.SetSelectedGameObject(Input.UIRoot, null); } catch { } |
| 426 | + try { CursorUnlocker.CurrentEventSystem.m_CurrentSelected = null; } |
| 427 | + catch (Exception ex) { ExplorerCore.Log($"Failed removing selected object: {ex}"); } |
| 428 | + |
| 429 | + yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~ |
| 430 | + |
| 431 | + try { SetSelectionGuard(CursorUnlocker.CurrentEventSystem, false); } |
| 432 | + catch (Exception ex) { ExplorerCore.Log($"Failed setting selection guard: {ex}"); } |
| 433 | + |
| 434 | + try { CursorUnlocker.CurrentEventSystem.SetSelectedGameObject(Input.GameObject, null); } |
| 435 | + catch (Exception ex) { ExplorerCore.Log($"Failed setting selected gameobject: {ex}"); } |
| 436 | + |
| 437 | + yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~ |
| 438 | + |
408 | 439 | Input.Component.Select();
|
409 |
| - yield return null; |
410 | 440 |
|
411 | 441 | Input.Component.caretPosition = caretPosition;
|
412 | 442 | Input.Component.selectionFocusPosition = caretPosition;
|
|
0 commit comments