using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Lightbug.CharacterControllerPro.Core; using Lightbug.CharacterControllerPro.Implementation; using Microsoft.CodeAnalysis; using TMPro; using Unity.Netcode; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.UI; using UnityEngine.InputSystem.Utilities; using UnityEngine.UI; using UnityEngine.UIElements; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ControllerSupport")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+ff1bbba8d38aea5c762f8f77f4aacb1f7c8d74ae")] [assembly: AssemblyProduct("ControllerSupport")] [assembly: AssemblyTitle("ControllerSupport")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ControllerSupport { [BepInPlugin("com.ttr.controllersupport", "ControllerSupport", "1.7.86")] [DefaultExecutionOrder(-100)] public class ControllerSupportPlugin : BaseUnityPlugin { public enum ResponseCurveType { Linear, Exponential, Aggressive, Smooth } internal enum ListType { None, Papyrus, DeadTied } private enum StockpileNavArea { Items, Footer } private class StockpileItemData { public VisualElement Item; public Button TakeButton; } internal class NavGrid { public List> columns = new List>(); public NavGrid(List selectables) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) if (selectables.Count == 0) { return; } List list = selectables.OrderBy((Selectable s) => GetScreenPos(s).x).ToList(); List list2 = new List(); float num = GetScreenPos(list[0]).x; foreach (Selectable item in list) { float x = GetScreenPos(item).x; if (Mathf.Abs(x - num) > 200f && list2.Count > 0) { columns.Add(list2); list2 = new List(); } list2.Add(item); num = x; } if (list2.Count > 0) { columns.Add(list2); } foreach (List column in columns) { column.Sort(delegate(Selectable a, Selectable b) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) int num3 = GetScreenPos(b).y.CompareTo(GetScreenPos(a).y); return (num3 != 0) ? num3 : GetScreenPos(a).x.CompareTo(GetScreenPos(b).x); }); } for (int num2 = 0; num2 < columns.Count; num2++) { List list3 = columns[num2]; list3.Average((Selectable s) => GetScreenPos(s).x); foreach (Selectable item2 in list3) { GetScreenPos(item2); } } } public Selectable FindNeighbor(Selectable current, int dx, int dy) { //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) int num = -1; int num2 = -1; for (int i = 0; i < columns.Count; i++) { for (int j = 0; j < columns[i].Count; j++) { if ((Object)(object)columns[i][j] == (Object)(object)current) { num = i; num2 = j; break; } } if (num >= 0) { break; } } if (num < 0) { return null; } if (dy != 0) { int num3 = num2 + ((dy <= 0) ? 1 : (-1)); if (num3 >= 0 && num3 < columns[num].Count) { return columns[num][num3]; } } if (dx != 0) { int num4 = num + dx; if (num4 < 0 || num4 >= columns.Count) { return null; } int count = columns[num4].Count; if (count == 0) { return null; } float y = GetScreenPos(current).y; Selectable result = null; float num5 = float.MaxValue; int index = Math.Min(num2, count - 1); Selectable val = columns[num4][index]; float num6 = Mathf.Abs(GetScreenPos(val).y - y); if (num6 < 150f) { result = val; num5 = num6; } else { string text = ""; foreach (Selectable item in columns[num4]) { float num7 = Mathf.Abs(GetScreenPos(item).y - y); text += $"{((Object)item).name}[Y={GetScreenPos(item).y:F1},delta={num7:F1}] "; if (num7 < num5) { num5 = num7; result = item; } } } return result; } return null; } public int GetColumnForX(float x) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) float num = float.MaxValue; int result = -1; for (int i = 0; i < columns.Count; i++) { if (columns[i].Count == 0) { continue; } float num2 = 0f; int num3 = 0; for (int j = 0; j < columns[i].Count; j++) { Selectable val = columns[i][j]; if ((Object)(object)val != (Object)null && Object.op_Implicit((Object)(object)val)) { num2 += GetScreenPos(val).x; num3++; } } if (num3 != 0) { num2 /= (float)num3; float num4 = Mathf.Abs(num2 - x); if (num4 < num) { num = num4; result = i; } } } return result; } public Selectable FindYClosestInColumn(float currentY, int colIdx) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) if (colIdx < 0 || colIdx >= columns.Count) { return null; } Selectable result = null; float num = float.MaxValue; foreach (Selectable item in columns[colIdx]) { if (!((Object)(object)item == (Object)null) && Object.op_Implicit((Object)(object)item)) { float num2 = Mathf.Abs(GetScreenPos(item).y - currentY); if (num2 < num) { num = num2; result = item; } } } return result; } } private enum WellNavArea { RecipeList, RightPanel, MapList, HomeCards } private class HomeCardData { public VisualElement Card; public List Elements = new List(); } public const string PluginGuid = "com.ttr.controllersupport"; public const string PluginName = "ControllerSupport"; public const string PluginVersion = "1.7.86"; internal static ManualLogSource Logger; internal static InputAction _jumpAction = null; internal static bool _papyrusOpen = false; private static InputAction _lookAction = null; private static bool _lookActionDisabled = false; private static InputAction _cameraAction = null; private static bool _cameraActionDisabled = false; internal static ConfigEntry LeftStickDeadzone; internal static ConfigEntry RightStickDeadzone; internal static ConfigEntry LeftTriggerDeadzone; internal static ConfigEntry LeftStickCurve; internal static ConfigEntry RightStickCurve; internal static ConfigEntry LeftStickExponent; internal static ConfigEntry RightStickExponent; internal static ConfigEntry LookSensitivity; internal static ConfigEntry MovementSensitivity; internal static ConfigEntry ToggleCrouch; internal static ConfigEntry ToggleSprint; internal static ConfigEntry InvertLookY; private static bool actionsInjected = false; internal static bool CrouchToggled = false; internal static bool SprintToggled = false; private static bool prevCrouchButton = false; private static bool prevSprintButton = false; private static bool _blockCrouchToggleUntilRelease = false; internal static readonly (string action, string path)[] DefaultBindings = new(string, string)[17] { ("Movement", "/leftStick"), ("Run", "/leftStickPress"), ("Look", "/rightStick"), ("Jump", "/buttonSouth"), ("Crouch", "/buttonEast"), ("Interact", "/buttonWest"), ("Push To Talk", "/buttonNorth"), ("Ragdoll", "/leftShoulder"), ("Drop", "/rightShoulder"), ("Push", "/leftTrigger"), ("Attack", "/rightTrigger"), ("Inventory", "/select"), ("Pause", "/start"), ("Item1", "/dpad/up"), ("Item2", "/dpad/right"), ("Item3", "/dpad/down"), ("Item4", "/dpad/left") }; internal static readonly Dictionary RuntimeBindings = new Dictionary(); private static float lastProcessorUpdateTime = -1f; private const float PROCESSOR_UPDATE_INTERVAL = 0.3f; private static bool processorUpdatePending = false; private static float _nextInjectRetryTime = 0f; private static bool _wasUiOpen = false; internal static object _cachedPlayerController = null; private static object _cachedMenuController = null; internal static FieldInfo _isUiOpenField; internal static bool _pcSearched = false; private static float _nextPlayerControllerSearchTime = 0f; internal static int _uiPanelOpenCount = 0; internal static float _prevSprintMoveMag = 0f; internal static bool _movedSinceSprintToggle = false; internal static Slider _selectedSlider = null; internal static bool _sliderEditMode = false; private static float _sliderNavRepeatTimer = 0f; private static float _lastSliderHoriz = 0f; private static float _sliderOriginalValue = 0f; private static Color _sliderOriginalHandleColor; private static bool _sliderColorStored = false; private static float _sliderEditAccum = 0f; private static bool _sliderTypeLogged = false; internal static int _sliderSetGuardCount = 0; internal static int _sliderSetValueGuardCount = 0; internal static float _sliderEditStepCooldown = 0f; internal static bool _sliderOriginalWholeNumbers = false; internal static bool _sliderForceFractional = false; internal static Selectable _pendingNavFocus = null; internal static float _pendingNavTimer = 0f; internal static Canvas _rebindOverlayCanvas = null; internal static int _pendingNavDx = 0; internal static int _pendingNavDy = 0; internal static int _voiceChatGuardFrames = 0; internal static MonoBehaviour _disabledVoiceChatComponent = null; internal static Type _voiceChatOptionsButtonType = null; private static Type _wellPanelModeEnum; private static Array _wellPanelModeValues; private static int _currentWellTab = 0; private static bool _wellPanelModeResolved = false; private static MethodInfo _changeWellPanelMethod; private static float _autoFocusRetryTimer = 0f; internal static int _bButtonConsumedFrames = 0; internal static bool _suppressNextDescriptionDisableClose = false; internal static bool _uiWasOpenLastFrame = false; private static bool _serverListReadyForFocus = false; private static bool _serverListAutoFocused = false; private static bool _serverListPanelWasActive = false; private static float _serverListScrollAccum = 0f; private static float _overlayScrollAccum = 0f; private static List _cachedServerElements = new List(); private static int _cachedServerElementIdx = -1; private static int _serverListLastFocusFrame = -5; private static bool _serverListNavHeldDown = false; private static bool _serverListNavRepeatPhase = false; private static float _serverListNavLastStepTime = -1f; internal static ListType _currentListType = ListType.None; internal static bool _taskListOpen = false; internal static int _taskListSelectedIndex = -1; private static bool _taskListNavHeldDown = false; private static bool _taskListNavRepeatPhase = false; private static float _taskListNavLastStepTime = -1f; internal static FieldInfo _taskPanelField = null; internal static FieldInfo _taskPapyrusField = null; internal static FieldInfo _taskElementParentField = null; internal static FieldInfo _buttonGraphicField = null; internal static FieldInfo _taskTextField = null; internal static Color _origTaskTextColor = Color.white; internal static TaskListUI _cachedTaskListUI = null; internal static List<(PlayerTaskElement element, Image graphic, Image buttonGraphic, GameObject highlightChild, Component mmUiEventListener)> _cachedTaskElements = new List<(PlayerTaskElement, Image, Image, GameObject, Component)>(); private static Color _origHighlightColor = new Color(1f, 1f, 1f, 0f); private static Color _origElementGraphicColor = new Color(1f, 1f, 1f, 0f); private static bool _origElementGraphicColorCaptured = false; private static readonly Color _selectedHighlightColor = new Color(0f, 1f, 0.3f, 1f); private static readonly Color _selectedButtonGraphicColor = new Color(1f, 1f, 1f, 0.35f); internal static Color _origFoldoutTitleColor = Color.white; private static bool _graphicFallbackLogged = false; private static bool _textFallbackLogged = false; private static bool _highlightDiagLogged = false; private static bool _overlayDiagLogged = false; private static bool _feedbackDiagLogged = false; private static bool _diagDumpLogged = false; internal static bool _lateUpdaterDiagLogged = false; internal static bool _lateUpdaterActiveDiagLogged = false; private static int _highlightCallCount = 0; private static bool? _cursorPreviouslyVisible = null; internal static bool _inactiveElementsLogged = false; internal static GraphicRaycaster _disabledRaycaster = null; internal static bool _prevTaskPanelActive = false; internal static PropertyInfo _tiedOrDeadPropInfo = null; internal static bool _deadTiedCleanupPending = false; internal static bool _lastInputWasGamepad = false; private static float _lastMouseMoveTime = 0f; private static Vector2 _lastMousePos = Vector2.zero; private static float _lastGamepadInputTime = -10f; private const float GAMEPAD_INPUT_TIMEOUT = 0.25f; private static int _papyrusCacheRetryCount = 0; private const int MAX_PAPYRUS_CACHE_RETRIES = 60; private static int _deadTiedCacheRetryCount = 0; private const int MAX_DEADTIED_CACHE_RETRIES = 60; private static FieldInfo _mmEnterFeedbackField = null; private static FieldInfo _mmExitFeedbackField = null; private static MethodInfo _mmPlayFeedbacksMethod = null; private static FieldInfo _foldoutTitleField = null; private static FieldInfo _foldoutObjectField = null; private static Sprite _highlightSprite = null; private static Texture2D _highlightTex = null; internal static bool _overlayClosedByRelease = false; internal static bool _mouseOpenedInfoOverlay = false; internal static bool _infoOverlayOpen = false; internal static int _infoFoldoutIndex = -1; private static bool _infoFoldoutNavHeldDown = false; private static bool _infoFoldoutNavRepeatPhase = false; private static float _infoFoldoutNavLastStepTime = -1f; private static bool _overlayStickDiagLogged = false; internal static int _papyrusAPressFrame = -1; internal static bool _sideEffectCloseDetected = false; internal static FieldInfo _descToggleField = null; internal static DescriptionDisplayer _cachedDescriptionDisplayer = null; internal static FieldInfo _descriptionContainerField = null; internal static List<(DescriptionElement element, Toggle toggle)> _cachedFoldouts = new List<(DescriptionElement, Toggle)>(); internal static ScrollRect _foldoutScrollRect = null; private static float _deferredScrollTopTimer = -1f; private static int _deferredScrollTopIdx = -1; internal static bool _suppressManualNavThisFrame = false; internal static float _lastControllerInputTime = -10f; internal static bool _controllerModeActive = false; private static float _lastFoldoutCacheLogTime = -1f; private static int _lastFoldoutCacheCount = -1; internal static bool _lastSettingsVisible = false; private static bool _wasSettingsOpen = false; private static bool _wasPlayerMenuOpen = false; private static GameObject _lastLoggedPlayerMenuPanel = null; internal static List _cachedSelectables = null; internal static bool _cacheNeedsRebuild = true; private static FieldInfo _netFieldCache; private static FieldInfo _brainFieldCache; private static PropertyInfo _scPropCache; private static PropertyInfo _netStateControllerPropCache; private static PropertyInfo _currentStatePropCache; private static float _wallSlideCheckTimer = 0f; private static bool _wallSlideCachedResult = false; private static FieldInfo _wcpFieldCache; private static FieldInfo _homeUpgradePanelFieldCache; private static FieldInfo _mapPanelFieldCache; private static FieldInfo _equipmentCraftingPanelFieldCache; private static FieldInfo _furnitureCraftingPanelFieldCache; private static FieldInfo _potionCraftingPanelFieldCache; private static VisualElement _cachedStockpilePanel = null; private static VisualElement _cachedStockpileDisplay = null; private static ScrollView _cachedStockpileScrollView = null; private static Button _cachedStockpileDepositButton = null; private static Button _cachedStockpileCloseButton = null; private static readonly List _cachedStockpileItems = new List(); private static readonly List