Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of DraggableUI v1.1.1
DraggableUI.dll
Decompiled 2 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using DraggableUI.Patches; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("DraggableUI")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+58202811ff20d819581d750e23d60c517d78c78d")] [assembly: AssemblyProduct("DraggableUI")] [assembly: AssemblyTitle("DraggableUI")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [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 YourMod { internal static class DraggableUIShim { public const string DraggableUIGuid = "rhenn.draggableui"; private const string ApiTypeName = "DraggableUI.DraggableApi"; private static bool resolved; private static Type api; private static MethodInfo registerHudPiece; private static MethodInfo registerWindow; private static MethodInfo isRegistered; private static MethodInfo unregister; private static MethodInfo reset; private static MethodInfo tryGetPlacement; private static EventInfo placementApplied; private static PropertyInfo isAvailable; private static PropertyInfo extraSlotsActive; private static MethodInfo extraSlotKindAt; public static bool IsAvailable { get { if (Resolve() && isAvailable != null) { return (bool)isAvailable.GetValue(null, null); } return false; } } public static bool ExtraSlotsActive { get { if (Resolve() && extraSlotsActive != null) { return (bool)extraSlotsActive.GetValue(null, null); } return false; } } public static string ExtraSlotKindAt(int x, int y) { if (!Resolve() || extraSlotKindAt == null) { return null; } try { return (string)extraSlotKindAt.Invoke(null, new object[2] { x, y }); } catch (Exception) { return null; } } public static bool RegisterHudPiece(string pluginGuid, string key, string label, RectTransform root) { return Call(registerHudPiece, pluginGuid, key, label, root, null); } public static bool RegisterWindow(string pluginGuid, string key, string label, RectTransform root) { return Call(registerWindow, pluginGuid, key, label, root, null); } public static bool IsRegistered(string pluginGuid, string key) { return Call(isRegistered, pluginGuid, key); } public static bool Unregister(string pluginGuid, string key) { return Call(unregister, pluginGuid, key); } public static bool Reset(string pluginGuid, string key) { return Call(reset, pluginGuid, key); } public static bool TryGetPlacement(string pluginGuid, string key, out Vector2 position, out float scale) { //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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) position = Vector2.zero; scale = 1f; if (!Resolve() || tryGetPlacement == null) { return false; } try { object[] array = new object[4] { pluginGuid, key, Vector2.zero, 1f }; bool num = (bool)tryGetPlacement.Invoke(null, array); if (num) { position = (Vector2)array[2]; scale = (float)array[3]; } return num; } catch (Exception) { return false; } } public static bool AddPlacementListener(Action<string> listener) { return Subscribe(listener, add: true); } public static bool RemovePlacementListener(Action<string> listener) { return Subscribe(listener, add: false); } private static bool Subscribe(Action<string> listener, bool add) { if (listener == null || !Resolve() || placementApplied == null) { return false; } try { if (add) { placementApplied.AddEventHandler(null, listener); } else { placementApplied.RemoveEventHandler(null, listener); } return true; } catch (Exception) { return false; } } private static bool Call(MethodInfo method, params object[] args) { if (!Resolve() || method == null) { return false; } try { return (bool)method.Invoke(null, args); } catch (Exception) { return false; } } private static bool Resolve() { if (resolved) { return api != null; } resolved = true; if (!Chainloader.PluginInfos.TryGetValue("rhenn.draggableui", out var value) || (Object)(object)value.Instance == (Object)null) { return false; } try { api = ((object)value.Instance).GetType().Assembly.GetType("DraggableUI.DraggableApi"); if (api == null) { return false; } isAvailable = api.GetProperty("IsAvailable", BindingFlags.Static | BindingFlags.Public); registerHudPiece = api.GetMethod("RegisterHudPiece", BindingFlags.Static | BindingFlags.Public); registerWindow = api.GetMethod("RegisterWindow", BindingFlags.Static | BindingFlags.Public); isRegistered = api.GetMethod("IsRegistered", BindingFlags.Static | BindingFlags.Public); unregister = api.GetMethod("Unregister", BindingFlags.Static | BindingFlags.Public); reset = api.GetMethod("Reset", BindingFlags.Static | BindingFlags.Public); tryGetPlacement = api.GetMethod("TryGetPlacement", BindingFlags.Static | BindingFlags.Public); placementApplied = api.GetEvent("PlacementApplied", BindingFlags.Static | BindingFlags.Public); extraSlotsActive = api.GetProperty("ExtraSlotsActive", BindingFlags.Static | BindingFlags.Public); extraSlotKindAt = api.GetMethod("ExtraSlotKindAt", BindingFlags.Static | BindingFlags.Public); return true; } catch (Exception) { api = null; return false; } } } } namespace DraggableUI { public sealed class PieceOptions { public Func<bool> IsHidden; public Action Preview; public Func<GameObject> VisibilityObject; public bool KeepLastBounds; public bool ClipToRoot; public Func<Transform, bool> IgnoreGraphic; } public static class DraggableApi { private sealed class Registration { public string PluginGuid; public string Key; public string Label; public RectTransform Root; public PieceOptions Options; public bool Window; } public const int ApiVersion = 2; private static readonly Dictionary<string, Registration> registrations = new Dictionary<string, Registration>(); public static bool ExtraSlotsActive => ExtraSlots.Active; public static bool IsAvailable => (Object)(object)Plugin.Driver != (Object)null; public static event Action<string> PlacementApplied; public static string ExtraSlotKindAt(int x, int y) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) try { if (!ExtraSlots.Active) { return null; } return ExtraSlots.KindAt(new Vector2i(x, y)).ToString(); } catch (Exception arg) { Plugin.Log.LogError((object)$"ExtraSlotKindAt({x}, {y}) failed: {arg}"); return null; } } public static string FullKey(string pluginGuid, string key) { return pluginGuid + ":" + key; } public static bool RegisterHudPiece(string pluginGuid, string key, string label, RectTransform root, PieceOptions options = null) { return Guarded(pluginGuid, key, "registering", () => Register(pluginGuid, key, label, root, options, window: false)); } public static bool RegisterWindow(string pluginGuid, string key, string label, RectTransform root, PieceOptions options = null) { return Guarded(pluginGuid, key, "registering", () => Register(pluginGuid, key, label, root, options, window: true)); } public static bool IsRegistered(string pluginGuid, string key) { return Guarded(pluginGuid, key, "looking up", () => Find(pluginGuid, key)?.IsAlive ?? false); } public static bool Unregister(string pluginGuid, string key) { return Guarded(pluginGuid, key, "unregistering", delegate { string key2 = FullKey(pluginGuid, key); registrations.Remove(key2); return ElementRegistry.Unregister(key2); }); } public static bool Reset(string pluginGuid, string key) { return Guarded(pluginGuid, key, "resetting", delegate { UiElement uiElement = Find(pluginGuid, key); if (uiElement == null || !uiElement.IsAlive) { return false; } uiElement.Reset(); LayoutStore.SaveIfDirty(); return true; }); } public static bool TryGetPlacement(string pluginGuid, string key, out Vector2 position, out float scale) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) Vector2 foundPosition = Vector2.zero; float foundScale = 1f; bool result = Guarded(pluginGuid, key, "reading the placement of", delegate { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) UiElement uiElement = Find(pluginGuid, key); if (uiElement == null || !uiElement.IsAlive) { return false; } Placement current = uiElement.Current; foundPosition = current.Position; foundScale = current.Scale; return true; }); position = foundPosition; scale = foundScale; return result; } internal static void Restore() { if (registrations.Count == 0) { return; } List<Registration> list = new List<Registration>(); List<string> list2 = new List<string>(); foreach (KeyValuePair<string, Registration> registration in registrations) { if ((Object)(object)registration.Value.Root != (Object)null) { list.Add(registration.Value); } else { list2.Add(registration.Key); } } foreach (string item in list2) { registrations.Remove(item); Plugin.Log.LogDebug((object)(item + ": its root died with the HUD; its mod registers it again when it builds it again")); } foreach (Registration r in list) { Guarded(r.PluginGuid, r.Key, "registering again", () => Register(r.PluginGuid, r.Key, r.Label, r.Root, r.Options, r.Window)); } } private static bool Register(string pluginGuid, string key, string label, RectTransform root, PieceOptions options, bool window) { if (!IsAvailable) { Plugin.Log.LogDebug((object)(pluginGuid + ": " + key + " not registered, DraggableUI is switched off")); return false; } string text = FullKey(pluginGuid, key); string text2 = (string.IsNullOrEmpty(label) ? key : label); UiElement uiElement = (window ? ElementCatalog.AddWindow(text, text2, root) : ElementCatalog.Add(text, text2, ElementKind.Hud, root)); if (uiElement == null) { return false; } if (options != null) { uiElement.IsHiddenFunc = options.IsHidden; uiElement.PreviewAction = options.Preview; uiElement.VisibilityObjectFunc = options.VisibilityObject; uiElement.KeepLastBounds = options.KeepLastBounds; uiElement.ClipToRoot = options.ClipToRoot; uiElement.IgnoreGraphicFunc = options.IgnoreGraphic; } registrations[text] = new Registration { PluginGuid = pluginGuid, Key = key, Label = text2, Root = root, Options = options, Window = window }; Plugin.Log.LogInfo((object)(pluginGuid + ": " + (window ? "window" : "HUD piece") + " \"" + text2 + "\" registered as " + text)); return true; } private static UiElement Find(string pluginGuid, string key) { return ElementRegistry.Find(FullKey(pluginGuid, key)); } private static bool Guarded(string pluginGuid, string key, string verb, Func<bool> action) { if (string.IsNullOrEmpty(pluginGuid) || string.IsNullOrEmpty(key)) { Plugin.Log.LogWarning((object)("A mod called DraggableUI without a plugin GUID or a key (guid \"" + pluginGuid + "\", key \"" + key + "\"); refused")); return false; } try { return action(); } catch (Exception ex) { Plugin.Log.LogError((object)$"{pluginGuid}: {verb} {key} failed: {ex}"); return false; } } internal static void NotifyPlacement(string fullKey) { Action<string> placementApplied = DraggableApi.PlacementApplied; if (placementApplied == null) { return; } try { placementApplied(fullKey); } catch (Exception arg) { Plugin.Log.LogError((object)$"A PlacementApplied subscriber threw for {fullKey}: {arg}"); } } } [DefaultExecutionOrder(1000)] internal sealed class DraggableUiDriver : MonoBehaviour { private const float SaveDelaySeconds = 0.5f; private int lastWidth; private int lastHeight; private int clampAtFrame = -1; private bool clampWhenHudVisible; private void Awake() { lastWidth = Screen.width; lastHeight = Screen.height; } private void Start() { OtherMods.Resolve(); ExtraSlots.Resolve(); } public void RequestDeferredClamp() { clampAtFrame = Time.frameCount + 2; } public void RequestClampWhenHudVisible() { clampWhenHudVisible = true; } private void Update() { if (Screen.width != lastWidth || Screen.height != lastHeight) { lastWidth = Screen.width; lastHeight = Screen.height; Plugin.Log.LogInfo((object)$"Screen size is now {lastWidth}x{lastHeight}; layout \"{LayoutStore.ActiveName}\" stays active"); ElementCatalog.PrimeInactiveCanvases(); ElementRegistry.ApplyAll(clamp: false); RequestDeferredClamp(); } if (clampAtFrame >= 0 && Time.frameCount >= clampAtFrame) { clampAtFrame = -1; ElementCatalog.RegisterModHud(Hud.instance, final: true); ElementRegistry.ApplyAll(clamp: true); } if (clampWhenHudVisible && (Object)(object)Hud.instance != (Object)null && Hud.instance.IsVisible()) { clampWhenHudVisible = false; Plugin.Log.LogDebug((object)"HUD visible again; running the clamp held back while it was hidden"); ElementRegistry.ApplyAll(clamp: true); } if (Plugin.EditModeKeys.IsDown() && !LayoutPanel.IsTyping && !Console.IsVisible() && !TextInput.IsVisible() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !EditMode.IsTypingInGameField()) { EditMode.Toggle(); } EditMode.Tick(); Clocks.Tick(); ExtraSlots.Tick(); ExtraSlotBars.Tick(); if (EditMode.Active && !EditMode.IsTypingInGameField() && Plugin.GridWheelKeys.IsHeld()) { float num = EditMode.ReadWheel(); if (num > 0f) { EditGrid.Step(1); } else if (num < 0f) { EditGrid.Step(-1); } } if (EditMode.Active && ZInput.GetKeyDown((KeyCode)27, false) && Hud.IsPieceSelectionVisible() && !EditMode.IsTypingInGameField()) { Hud.HidePieceSelection(); } LayoutStore.SaveIfDirtyFor(0.5f); } private void LateUpdate() { EditMode.LateTick(); } private void OnDestroy() { EditMode.Exit(silent: true); LayoutStore.SaveIfDirty(); } } internal static class EditGrid { private static readonly Color GridColor = new Color(1f, 1f, 1f, 0.12f); private static readonly Color CenterColor = new Color(1f, 0.25f, 0.25f, 0.75f); private const float GridThickness = 1f; private const float CenterThickness = 2f; private static readonly int[] Steps = new int[9] { 10, 20, 25, 50, 100, 200, 250, 500, 1000 }; private static RectTransform root; private static readonly List<RectTransform> gridLines = new List<RectTransform>(); private static RectTransform centerVertical; private static RectTransform centerHorizontal; private static int builtWidth; private static int builtHeight; private static float builtFactor; private static int spacing; private static int configSpacingSeen; private static bool spacingChanged; public static int Spacing => spacing; public static void Step(int direction) { if (!Plugin.ShowGrid.Value) { EditMode.Notify("DraggableUI: the grid is off (ShowGrid in the config)"); return; } int num = spacing; if (direction > 0) { for (int i = 0; i < Steps.Length; i++) { if (Steps[i] > spacing) { num = Steps[i]; break; } } } else { for (int num2 = Steps.Length - 1; num2 >= 0; num2--) { if (Steps[num2] < spacing) { num = Steps[num2]; break; } } } if (num != spacing) { spacing = num; spacingChanged = true; if ((Object)(object)root != (Object)null) { Build(builtFactor); } } EditMode.OnGridChanged(); } public static void Create(RectTransform canvas, float scaleFactor) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) DestroyObjects(); spacing = Plugin.GridSpacing.Value; configSpacingSeen = spacing; spacingChanged = false; if (!((Object)(object)canvas == (Object)null) && (Plugin.ShowGrid.Value || Plugin.ShowCenterLines.Value)) { GameObject val = new GameObject("Grid", new Type[1] { typeof(RectTransform) }); val.transform.SetParent((Transform)(object)canvas, false); val.transform.SetAsFirstSibling(); Transform transform = val.transform; root = (RectTransform)(object)((transform is RectTransform) ? transform : null); root.anchorMin = Vector2.zero; root.anchorMax = Vector2.one; root.offsetMin = Vector2.zero; root.offsetMax = Vector2.zero; val.AddComponent<Canvas>(); Build(scaleFactor); } } public static void Sync(float scaleFactor) { if (!((Object)(object)root == (Object)null)) { int value = Plugin.GridSpacing.Value; if (value != configSpacingSeen) { configSpacingSeen = value; spacing = value; spacingChanged = false; Build(scaleFactor); EditMode.OnGridChanged(); } else if (Screen.width != builtWidth || Screen.height != builtHeight || Mathf.Abs(scaleFactor - builtFactor) > 0.0001f) { Build(scaleFactor); } } } public static void Close() { if (spacingChanged) { spacingChanged = false; configSpacingSeen = spacing; Plugin.GridSpacing.Value = spacing; } DestroyObjects(); } private static void DestroyObjects() { if ((Object)(object)root != (Object)null) { Object.Destroy((Object)(object)((Component)root).gameObject); } root = null; gridLines.Clear(); centerVertical = null; centerHorizontal = null; } private static void Build(float scaleFactor) { //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) float num = ((scaleFactor > 0.0001f) ? scaleFactor : 1f); builtWidth = Screen.width; builtHeight = Screen.height; builtFactor = scaleFactor; int num2 = 0; if (Plugin.ShowGrid.Value) { float num3 = Mathf.Max(10f, (float)spacing); int num4 = Mathf.CeilToInt((float)Screen.width / num * 0.5f / num3); int num5 = Mathf.CeilToInt((float)Screen.height / num * 0.5f / num3); for (int i = -num4; i <= num4; i++) { PlaceGridLine(num2++, vertical: true, (float)i * num3); } for (int j = -num5; j <= num5; j++) { PlaceGridLine(num2++, vertical: false, (float)j * num3); } } for (int k = num2; k < gridLines.Count; k++) { if (((Component)gridLines[k]).gameObject.activeSelf) { ((Component)gridLines[k]).gameObject.SetActive(false); } } if (Plugin.ShowCenterLines.Value) { if ((Object)(object)centerVertical == (Object)null) { centerVertical = CreateLine("CenterV", CenterColor); centerHorizontal = CreateLine("CenterH", CenterColor); SetLine(centerVertical, vertical: true, 0f, 2f); SetLine(centerHorizontal, vertical: false, 0f, 2f); } ((Transform)centerVertical).SetAsLastSibling(); ((Transform)centerHorizontal).SetAsLastSibling(); } } private static void PlaceGridLine(int index, bool vertical, float offset) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) RectTransform val; if (index < gridLines.Count) { val = gridLines[index]; } else { val = CreateLine("GridLine", GridColor); gridLines.Add(val); } SetLine(val, vertical, offset, 1f); if (!((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(true); } } private static RectTransform CreateLine(string name, Color color) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent((Transform)(object)root, false); Image component = val.GetComponent<Image>(); ((Graphic)component).color = color; ((Graphic)component).raycastTarget = false; Transform transform = val.transform; return (RectTransform)(object)((transform is RectTransform) ? transform : null); } private static void SetLine(RectTransform rt, bool vertical, float offset, float thickness) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) if (vertical) { rt.anchorMin = new Vector2(0.5f, 0f); rt.anchorMax = new Vector2(0.5f, 1f); rt.sizeDelta = new Vector2(thickness, 0f); rt.anchoredPosition = new Vector2(offset, 0f); } else { rt.anchorMin = new Vector2(0f, 0.5f); rt.anchorMax = new Vector2(1f, 0.5f); rt.sizeDelta = new Vector2(0f, thickness); rt.anchoredPosition = new Vector2(0f, offset); } } } internal static class EditMode { public const string PreviewText = "DraggableUI preview"; private static GameObject canvasGo; private static Canvas canvas; private static RectTransform canvasRt; private static CanvasScaler scaler; private static TMP_FontAsset font; private static TextMeshProUGUI bannerText; private static readonly Dictionary<string, EditOverlay> overlays = new Dictionary<string, EditOverlay>(); private static readonly HashSet<string> stale = new HashSet<string>(); private const int MeasureInterval = 10; private static readonly HashSet<string> reportedFailures = new HashSet<string>(); public static bool Active { get; private set; } public static bool ReadingWheel { get; private set; } public static void Toggle() { if (Active) { Exit(); } else { TryEnter(); } } public static bool TryEnter() { if (Active) { return true; } if (!CanEdit(out var reason)) { Notify("DraggableUI: cannot edit " + reason); return false; } if (LayoutStore.ReloadIfChangedOnDisk()) { ElementRegistry.ApplyAll(clamp: true); } ElementCatalog.PrimeInactiveCanvases(); Active = true; CreateCanvas(); Plugin.Log.LogInfo((object)"Edit mode on"); return true; } public static void Exit(bool silent = false) { if (Active) { Active = false; DestroyCanvas(); PreviewClone.ClearAll(); LayoutStore.Save(); Plugin.Log.LogInfo((object)"Edit mode off, layout saved"); if (!silent) { Notify("DraggableUI: layout saved"); } } } public static void Tick() { if (Active && !CanEdit(out var reason)) { Plugin.Log.LogInfo((object)("Edit mode ended: " + reason)); Exit(); } } public static void LateTick() { if (Active && !((Object)(object)canvasGo == (Object)null)) { SyncCanvasScale(); EditGrid.Sync(canvas.scaleFactor); LayoutPanel.LateTick(); PreviewClone.Follow(); SyncOverlays(); } } private static bool CanEdit(out string reason) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)Hud.instance == (Object)null || (Object)(object)localPlayer == (Object)null) { reason = "outside a game"; return false; } if (((Character)localPlayer).IsDead()) { reason = "while dead"; return false; } if (((Character)localPlayer).IsTeleporting()) { reason = "while teleporting"; return false; } if (((Character)localPlayer).InCutscene()) { reason = "during a cutscene"; return false; } if (Console.IsVisible()) { reason = "with the console open"; return false; } if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { reason = "while typing in chat"; return false; } if (TextInput.IsVisible()) { reason = "while typing"; return false; } if (Menu.IsVisible()) { reason = "with the menu open"; return false; } if (Hud.IsUserHidden()) { reason = "while the HUD is hidden"; return false; } if (Minimap.IsOpen()) { reason = "with the map open"; return false; } if (Hud.InRadial()) { reason = "with the radial menu open"; return false; } if (IsTypingInGameField()) { reason = "while typing"; return false; } if (GameCamera.InFreeFly()) { reason = "in free-fly camera"; return false; } if (ZInput.IsGamepadActive()) { reason = "with a gamepad; use the mouse"; return false; } reason = null; return true; } public static bool IsTypingInGameField() { if (Minimap.InTextInput()) { return true; } if ((Object)(object)Hud.instance != (Object)null && (Object)(object)Hud.instance.m_buildUi != (Object)null) { return Hud.instance.m_buildUi.SearchFieldFocused; } return false; } public static float ReadWheel() { ReadingWheel = true; try { return ZInput.GetMouseScrollWheel(); } finally { ReadingWheel = false; } } public static void OnGridChanged() { if ((Object)(object)bannerText != (Object)null) { ((TMP_Text)bannerText).text = BannerText(); } Notify($"DraggableUI: grid {EditGrid.Spacing}"); } internal static void Notify(string text) { if ((Object)(object)MessageHud.instance != (Object)null) { MessageHud.instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, Hud.IsUserHidden(), false); } } private static void CreateCanvas() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown font = FindFont(); canvasGo = new GameObject("DraggableUI_EditCanvas", new Type[4] { typeof(RectTransform), typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster) }); canvas = canvasGo.GetComponent<Canvas>(); canvas.renderMode = (RenderMode)0; canvas.sortingOrder = 32000; Transform transform = canvasGo.transform; canvasRt = (RectTransform)(object)((transform is RectTransform) ? transform : null); scaler = canvasGo.GetComponent<CanvasScaler>(); scaler.uiScaleMode = (ScaleMode)0; SyncCanvasScale(); EditGrid.Create(canvasRt, canvas.scaleFactor); if (Plugin.ShowBanner.Value) { CreateBanner(); } LayoutPanel.Create(canvasRt, Plugin.ShowBanner.Value); } private static void DestroyCanvas() { overlays.Clear(); EditGrid.Close(); LayoutPanel.Destroy(); if ((Object)(object)canvasGo != (Object)null) { Object.Destroy((Object)(object)canvasGo); } canvasGo = null; canvas = null; canvasRt = null; scaler = null; bannerText = null; } private static void SyncCanvasScale() { if ((Object)(object)scaler == (Object)null || (Object)(object)Hud.instance == (Object)null) { return; } Canvas componentInParent = ((Component)Hud.instance).GetComponentInParent<Canvas>(true); if ((Object)(object)componentInParent != (Object)null) { float scaleFactor = componentInParent.rootCanvas.scaleFactor; if (scaleFactor > 0f && Mathf.Abs(scaler.scaleFactor - scaleFactor) > 0.0001f) { scaler.scaleFactor = scaleFactor; canvas.scaleFactor = scaleFactor; } } } private static TMP_FontAsset FindFont() { if ((Object)(object)Hud.instance != (Object)null && (Object)(object)Hud.instance.m_healthText != (Object)null && (Object)(object)Hud.instance.m_healthText.font != (Object)null) { return Hud.instance.m_healthText.font; } TMP_Text val = Object.FindAnyObjectByType<TMP_Text>(); if ((Object)(object)val != (Object)null) { return val.font; } return TMP_Settings.defaultFontAsset; } private static void CreateBanner() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Banner", new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent((Transform)(object)canvasRt, false); Transform transform = val.transform; Transform obj = ((transform is RectTransform) ? transform : null); ((RectTransform)obj).anchorMin = new Vector2(0.5f, 1f); ((RectTransform)obj).anchorMax = new Vector2(0.5f, 1f); ((RectTransform)obj).pivot = new Vector2(0.5f, 1f); ((RectTransform)obj).anchoredPosition = new Vector2(0f, -8f); ((RectTransform)obj).sizeDelta = new Vector2(1100f, 30f); Image component = val.GetComponent<Image>(); ((Graphic)component).color = new Color(0f, 0f, 0f, 0.65f); ((Graphic)component).raycastTarget = false; TextMeshProUGUI obj2 = CreateText((RectTransform)(object)obj, "Text", 15f, (TextAlignmentOptions)514); ((TMP_Text)obj2).rectTransform.anchorMin = Vector2.zero; ((TMP_Text)obj2).rectTransform.anchorMax = Vector2.one; ((TMP_Text)obj2).rectTransform.offsetMin = new Vector2(8f, 0f); ((TMP_Text)obj2).rectTransform.offsetMax = new Vector2(-8f, 0f); ((TMP_Text)obj2).enableAutoSizing = true; ((TMP_Text)obj2).fontSizeMin = 10f; ((TMP_Text)obj2).fontSizeMax = 15f; ((TMP_Text)obj2).text = BannerText(); bannerText = obj2; } private static string BannerText() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) string text = $"DraggableUI edit mode | Drag: move | Wheel or Ctrl+drag: scale | Right-click: reset | {Plugin.EditModeShortcut.Value} or Esc: finish"; if (Plugin.ShowGrid.Value) { text += $" | {Plugin.GridWheelModifier.Value} + wheel: grid {EditGrid.Spacing}"; } return text; } public static TextMeshProUGUI CreateText(RectTransform parent, string name, float size, TextAlignmentOptions alignment) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); val.SetActive(false); val.transform.SetParent((Transform)(object)parent, false); TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>(); if ((Object)(object)font != (Object)null) { ((TMP_Text)val2).font = font; } ((TMP_Text)val2).fontSize = size; ((TMP_Text)val2).alignment = alignment; ((TMP_Text)val2).overflowMode = (TextOverflowModes)0; ((Graphic)val2).raycastTarget = false; ((Graphic)val2).color = Color.white; val.SetActive(true); return val2; } private static void SyncOverlays() { if ((Object)(object)canvasRt == (Object)null) { return; } stale.Clear(); foreach (string key in overlays.Keys) { stale.Add(key); } IReadOnlyList<UiElement> all = ElementRegistry.All; int frameCount = Time.frameCount; for (int i = 0; i < all.Count; i++) { UiElement uiElement = all[i]; try { if (SyncOverlay(uiElement, (frameCount + i) % 10 == 0)) { stale.Remove(uiElement.Key); } } catch (Exception arg) { if (reportedFailures.Add(uiElement.Key)) { Plugin.Log.LogError((object)$"{uiElement.Key}: overlay failed and is skipped: {arg}"); } } } foreach (string item in stale) { if (overlays.TryGetValue(item, out var value) && (Object)(object)value != (Object)null) { Object.Destroy((Object)(object)((Component)value).gameObject); } overlays.Remove(item); } } private static bool SyncOverlay(UiElement e, bool measureDue) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) bool isHidden = e.IsHidden; if (!e.IsAlive || (e.Kind == ElementKind.Window && isHidden) || (Object)(object)e.Canvas == (Object)null) { return false; } EditOverlay value; bool flag = overlays.TryGetValue(e.Key, out value) && (Object)(object)value != (Object)null; if (measureDue || !flag || value.ShowsStandIn != isHidden) { ElementBounds.Measure(e); } if (!ElementBounds.TryGetCanvasBounds(e, out var bounds)) { return false; } if (!ToEditCanvas(e, bounds, out var min, out var max)) { return false; } if (!flag) { value = EditOverlay.Create(canvasRt, e); overlays[e.Key] = value; } value.Refresh(min, max, isHidden); return true; } private static bool ToEditCanvas(UiElement e, Rect bounds, out Vector2 min, out Vector2 max) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)e.Canvas).transform; Transform obj = ((transform is RectTransform) ? transform : null); Camera camera = e.Camera; Vector3 val = obj.TransformPoint(new Vector3(((Rect)(ref bounds)).xMin, ((Rect)(ref bounds)).yMin, 0f)); Vector3 val2 = obj.TransformPoint(new Vector3(((Rect)(ref bounds)).xMax, ((Rect)(ref bounds)).yMax, 0f)); Vector2 val3 = RectTransformUtility.WorldToScreenPoint(camera, val); Vector2 val4 = RectTransformUtility.WorldToScreenPoint(camera, val2); bool num = RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRt, val3, (Camera)null, ref min); bool flag = RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRt, val4, (Camera)null, ref max); if (!num || !flag) { return false; } Rect rect = canvasRt.rect; min -= new Vector2(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMin); max -= new Vector2(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMin); return true; } } internal sealed class EditOverlay : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler, IScrollHandler, IPointerClickHandler { internal sealed class PreviewButton : MonoBehaviour, IPointerClickHandler, IEventSystemHandler { public EditOverlay Owner; public void OnPointerClick(PointerEventData eventData) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Owner == (Object)null)) { if ((int)eventData.button == 0) { Owner.OnPreviewClicked(); } else { Owner.OnPointerClick(eventData); } } } } private static readonly Color VisibleColor = new Color(0.25f, 0.6f, 1f, 0.28f); private static readonly Color HiddenColor = new Color(1f, 0.55f, 0.15f, 0.32f); private static readonly Color ButtonColor = new Color(0.1f, 0.1f, 0.1f, 0.85f); private UiElement element; private RectTransform rect; private Image image; private TextMeshProUGUI label; private GameObject previewButton; private bool hidden; private bool styled; private bool placed; private Vector2 placedMin; private Vector2 placedMax; private bool labelSet; private bool labelHidden; private int labelPercent; private bool labelIgnored; private bool dragging; private bool scaling; private Placement dragStart; private Vector2 dragStartScreen; private Vector2 dragStartLocal; public bool ShowsStandIn { get { if (styled) { return hidden; } return false; } } public static EditOverlay Create(RectTransform parent, UiElement element) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Overlay_" + element.Key, new Type[3] { typeof(RectTransform), typeof(Image), typeof(EditOverlay) }); val.transform.SetParent((Transform)(object)parent, false); EditOverlay component = val.GetComponent<EditOverlay>(); component.element = element; ref RectTransform reference = ref component.rect; Transform transform = val.transform; reference = (RectTransform)(object)((transform is RectTransform) ? transform : null); component.rect.anchorMin = Vector2.zero; component.rect.anchorMax = Vector2.zero; component.rect.pivot = Vector2.zero; component.image = val.GetComponent<Image>(); ((Graphic)component.image).color = VisibleColor; ((Graphic)component.image).raycastTarget = true; component.label = EditMode.CreateText(component.rect, "Label", 13f, (TextAlignmentOptions)257); RectTransform rectTransform = ((TMP_Text)component.label).rectTransform; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.offsetMin = new Vector2(4f, 2f); rectTransform.offsetMax = new Vector2(-4f, -2f); ((TMP_Text)component.label).fontStyle = (FontStyles)1; component.previewButton = CreatePreviewButton(component); component.previewButton.SetActive(false); return component; } private static GameObject CreatePreviewButton(EditOverlay overlay) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("PreviewButton", new Type[3] { typeof(RectTransform), typeof(Image), typeof(PreviewButton) }); val.transform.SetParent((Transform)(object)overlay.rect, false); Transform transform = val.transform; Transform obj = ((transform is RectTransform) ? transform : null); ((RectTransform)obj).anchorMin = new Vector2(1f, 0f); ((RectTransform)obj).anchorMax = new Vector2(1f, 0f); ((RectTransform)obj).pivot = new Vector2(1f, 0f); ((RectTransform)obj).anchoredPosition = new Vector2(-3f, 3f); ((RectTransform)obj).sizeDelta = new Vector2(64f, 20f); Image component = val.GetComponent<Image>(); ((Graphic)component).color = ButtonColor; ((Graphic)component).raycastTarget = true; val.GetComponent<PreviewButton>().Owner = overlay; TextMeshProUGUI obj2 = EditMode.CreateText((RectTransform)(object)obj, "Text", 12f, (TextAlignmentOptions)514); ((TMP_Text)obj2).rectTransform.anchorMin = Vector2.zero; ((TMP_Text)obj2).rectTransform.anchorMax = Vector2.one; ((TMP_Text)obj2).rectTransform.offsetMin = Vector2.zero; ((TMP_Text)obj2).rectTransform.offsetMax = Vector2.zero; ((TMP_Text)obj2).text = "Preview"; return val; } public void Refresh(Vector2 min, Vector2 max, bool isHidden) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) if (placed) { Vector2 val = min - placedMin; if (!(((Vector2)(ref val)).sqrMagnitude > 0.0001f)) { val = max - placedMax; if (!(((Vector2)(ref val)).sqrMagnitude > 0.0001f)) { goto IL_0071; } } } placed = true; placedMin = min; placedMax = max; rect.anchoredPosition = min; rect.sizeDelta = max - min; goto IL_0071; IL_0071: if (!styled || hidden != isHidden) { styled = true; hidden = isHidden; ((Graphic)image).color = (hidden ? HiddenColor : VisibleColor); previewButton.SetActive(hidden); } int num = Mathf.RoundToInt(element.ScaleFactor * 100f); bool hasIgnoredPlacement = element.HasIgnoredPlacement; if (!labelSet || num != labelPercent || hidden != labelHidden || hasIgnoredPlacement != labelIgnored) { labelSet = true; labelPercent = num; labelHidden = hidden; labelIgnored = hasIgnoredPlacement; string text = ((num != 100) ? $" {num}%" : ""); string text2 = (hasIgnoredPlacement ? " (saved placement ignored, see log)" : ""); ((TMP_Text)label).text = (hidden ? (element.Label + " (hidden)" + text) : (element.Label + text)) + text2; } } internal void OnPreviewClicked() { PreviewClone.Show(element); } public void OnBeginDrag(PointerEventData eventData) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) dragging = false; if ((int)eventData.button == 0 && element != null && !((Object)(object)element.Root == (Object)null) && !((Object)(object)element.Parent == (Object)null)) { scaling = ZInput.GetKey((KeyCode)306, false) || ZInput.GetKey((KeyCode)305, false); dragStart = element.Current; dragStartScreen = eventData.position; if (RectTransformUtility.ScreenPointToLocalPointInRectangle(element.Parent, eventData.position, element.Camera, ref dragStartLocal)) { ElementBounds.Measure(element); dragging = true; } } } public void OnDrag(PointerEventData eventData) { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) if (!dragging || (Object)(object)element.Root == (Object)null) { return; } Vector2 val = default(Vector2); if (scaling) { float num = element.RoundScale(dragStart.Scale + (eventData.position.y - dragStartScreen.y) / 200f * element.DefaultScale); if (Mathf.Abs(num - element.Current.Scale) > 0.0001f) { element.SetScale(num); } } else if (RectTransformUtility.ScreenPointToLocalPointInRectangle(element.Parent, eventData.position, element.Camera, ref val)) { Vector2 position = dragStart.Position + (val - dragStartLocal); position = ElementBounds.ClampPosition(element, new Placement(position, element.Current.Scale)); element.SetPosition(position); } } public void OnEndDrag(PointerEventData eventData) { if (dragging) { dragging = false; LayoutStore.Save(); } } public void OnScroll(PointerEventData eventData) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (element == null || (Object)(object)element.Root == (Object)null || Plugin.GridWheelKeys.IsHeld()) { return; } float y = eventData.scrollDelta.y; if (!(Mathf.Abs(y) < 0.01f)) { float scaleStep = element.ScaleStep; float num = element.RoundScale(element.Current.Scale + ((y > 0f) ? scaleStep : (0f - scaleStep))); if (Mathf.Abs(num - element.Current.Scale) > 0.0001f) { element.SetScale(num); } } } public void OnPointerClick(PointerEventData eventData) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 if ((int)eventData.button == 1 && element != null && (Object)(object)element.Root != (Object)null) { element.Reset(); LayoutStore.Save(); Plugin.Log.LogInfo((object)(element.Key + " reset to its default placement")); } } } internal static class PreviewClone { private sealed class Entry { public UiElement Element; public RectTransform Rect; } public const float Seconds = 3f; private const string HolderName = "DraggableUI_Previews"; private static readonly Dictionary<string, Entry> live = new Dictionary<string, Entry>(); private static readonly List<string> gone = new List<string>(); private static readonly List<int> indexPath = new List<int>(); private static RectTransform holder; private static Transform HolderUnder(Transform hudRoot) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)holder == (Object)null || (Object)(object)((Transform)holder).parent != (Object)(object)hudRoot) { Transform transform = new GameObject("DraggableUI_Previews", new Type[1] { typeof(RectTransform) }).transform; holder = (RectTransform)(object)((transform is RectTransform) ? transform : null); ((Transform)holder).SetParent(hudRoot, false); holder.anchorMin = Vector2.zero; holder.anchorMax = Vector2.one; holder.offsetMin = Vector2.zero; holder.offsetMax = Vector2.zero; ((Transform)holder).SetAsLastSibling(); } return (Transform)(object)holder; } public static void Show(UiElement e) { if (e == null || (Object)(object)e.Root == (Object)null) { return; } if (e.PreviewAction != null) { e.PreviewAction(); return; } Hide(e.Key); GameObject val = Object.Instantiate<GameObject>(((Component)e.Root).gameObject, ((Transform)e.Root).parent); ((Object)val).name = "DraggableUI_Preview_" + e.Key; val.transform.SetSiblingIndex(((Transform)e.Root).GetSiblingIndex() + 1); Strip(val); GameObject visibilityObject = e.VisibilityObject; if ((Object)(object)visibilityObject != (Object)null && (Object)(object)visibilityObject != (Object)(object)((Component)e.Root).gameObject) { Transform val2 = Counterpart(visibilityObject.transform, (Transform)(object)e.Root, val.transform); if ((Object)(object)val2 != (Object)null) { ((Component)val2).gameObject.SetActive(true); } else { Plugin.Log.LogDebug((object)("Preview of " + e.Key + ": " + ((Object)visibilityObject).name + " has no counterpart in the copy; the copy may show nothing")); } } CanvasGroup val3 = val.GetComponent<CanvasGroup>(); if ((Object)(object)val3 == (Object)null) { val3 = val.AddComponent<CanvasGroup>(); } val3.alpha = 1f; val3.interactable = false; val3.blocksRaycasts = false; val.SetActive(true); if (!val.activeInHierarchy) { Transform parent = ((Transform)e.Root).parent; while ((Object)(object)parent != (Object)null && !((Component)parent).gameObject.activeInHierarchy) { parent = parent.parent; } if ((Object)(object)parent == (Object)null) { Object.Destroy((Object)(object)val); Plugin.Log.LogDebug((object)("Preview of " + e.Key + ": no active ancestor to show it under")); return; } val.transform.SetParent(parent, true); val.transform.SetAsLastSibling(); } Transform val4 = (((Object)(object)Hud.instance != (Object)null && (Object)(object)Hud.instance.m_rootObject != (Object)null) ? Hud.instance.m_rootObject.transform : null); if ((Object)(object)val4 != (Object)null && (Object)(object)val.transform.parent == (Object)(object)val4) { val.transform.SetParent(HolderUnder(val4), true); val.transform.SetAsLastSibling(); } live[e.Key] = new Entry { Element = e, Rect = (RectTransform)/*isinst with value type is only supported in some contexts*/ }; Object.Destroy((Object)(object)val, 3f); Plugin.Log.LogDebug((object)$"Preview of {e.Key} for {3f} s"); } public static void Hide(string key) { if (live.TryGetValue(key, out var value)) { if ((Object)(object)value.Rect != (Object)null) { Object.Destroy((Object)(object)((Component)value.Rect).gameObject); } live.Remove(key); } } public static void ClearAll() { foreach (Entry value in live.Values) { if ((Object)(object)value.Rect != (Object)null) { Object.Destroy((Object)(object)((Component)value.Rect).gameObject); } } live.Clear(); } public static void Follow() { //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) if (live.Count == 0) { return; } gone.Clear(); foreach (KeyValuePair<string, Entry> item in live) { RectTransform rect = item.Value.Rect; RectTransform root = item.Value.Element.Root; if ((Object)(object)rect == (Object)null || (Object)(object)root == (Object)null) { gone.Add(item.Key); } else if ((Object)(object)((Transform)rect).parent == (Object)(object)((Transform)root).parent) { rect.anchoredPosition = root.anchoredPosition; ((Transform)rect).localScale = ((Transform)root).localScale; ((Transform)rect).localRotation = ((Transform)root).localRotation; } else { ((Transform)rect).position = ((Transform)root).position; ((Transform)rect).rotation = ((Transform)root).rotation; ((Transform)rect).localScale = LocalScaleFor(((Transform)root).lossyScale, ((Transform)rect).parent); } } foreach (string item2 in gone) { live.Remove(item2); } } private static Transform Counterpart(Transform original, Transform originalRoot, Transform cloneRoot) { indexPath.Clear(); Transform val = original; while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)originalRoot) { indexPath.Add(val.GetSiblingIndex()); val = val.parent; } if ((Object)(object)val == (Object)null) { return null; } Transform val2 = cloneRoot; for (int num = indexPath.Count - 1; num >= 0; num--) { int num2 = indexPath[num]; if (num2 >= val2.childCount) { return null; } val2 = val2.GetChild(num2); } return val2; } private static Vector3 LocalScaleFor(Vector3 world, Transform parent) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (((Object)(object)parent != (Object)null) ? parent.lossyScale : Vector3.one); return new Vector3((Mathf.Abs(val.x) > 0.0001f) ? (world.x / val.x) : world.x, (Mathf.Abs(val.y) > 0.0001f) ? (world.y / val.y) : world.y, (Mathf.Abs(val.z) > 0.0001f) ? (world.z / val.z) : world.z); } private static void Strip(GameObject root) { Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true); foreach (Component val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !(val is Transform) && !(val is CanvasRenderer) && !(val is Graphic) && !(val is BaseMeshEffect) && !(val is Canvas) && !(val is CanvasGroup) && !(val is Mask) && !(val is RectMask2D) && !(val is LayoutElement) && !(val is ContentSizeFitter) && !(val is AspectRatioFitter) && !(val is HorizontalOrVerticalLayoutGroup)) { Animator val2 = (Animator)(object)((val is Animator) ? val : null); if ((Object)(object)val2 != (Object)null) { ForceVisible(val2); } else { Object.DestroyImmediate((Object)(object)val); } } } } private static void ForceVisible(Animator animator) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 if ((Object)(object)animator.runtimeAnimatorController == (Object)null) { return; } AnimatorControllerParameter[] parameters = animator.parameters; foreach (AnimatorControllerParameter val in parameters) { if ((int)val.type == 4 && string.Equals(val.name, "Visible", StringComparison.OrdinalIgnoreCase)) { animator.SetBool(val.nameHash, true); } } } } internal sealed class WindowDragHandle : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler { private const string CatcherName = "DraggableUI_DragCatcher"; private const float TightFraction = 0.95f; private const float MoveThresholdPixels = 4f; public UiElement Element; private bool pressed; private bool moved; private int pointerId; private Placement dragStart; private Vector2 pressScreen; private Vector2 dragStartLocal; public static void Attach(UiElement element) { if (!((Object)(object)element.Root == (Object)null)) { WindowDragHandle windowDragHandle = ((Component)element.Root).GetComponent<WindowDragHandle>(); if ((Object)(object)windowDragHandle == (Object)null) { windowDragHandle = ((Component)element.Root).gameObject.AddComponent<WindowDragHandle>(); } windowDragHandle.Element = element; windowDragHandle.EnsureCatcher(); } } public static void Detach(UiElement element) { if (element != null && !((Object)(object)element.Root == (Object)null)) { WindowDragHandle component = ((Component)element.Root).GetComponent<WindowDragHandle>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } Transform val = ((Transform)element.Root).Find("DraggableUI_DragCatcher"); if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)((Component)val).gameObject); } } } private void EnsureCatcher() { //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) if (Element != null && !((Object)(object)Element.Root == (Object)null) && !((Object)(object)Element.Canvas == (Object)null) && !((Object)(object)((Transform)Element.Root).Find("DraggableUI_DragCatcher") != (Object)null)) { if (ElementBounds.IsScreenSized(Element.Root, Element.Canvas)) { Plugin.Log.LogDebug((object)(Element.Key + ": root is screen-sized, no drag catcher added; drag it by its own panel")); return; } GameObject val = new GameObject("DraggableUI_DragCatcher", new Type[3] { typeof(RectTransform), typeof(Image), typeof(LayoutElement) }); val.transform.SetParent((Transform)(object)Element.Root, false); val.transform.SetAsFirstSibling(); Transform transform = val.transform; Transform obj = ((transform is RectTransform) ? transform : null); ((RectTransform)obj).anchorMin = Vector2.zero; ((RectTransform)obj).anchorMax = Vector2.one; ((RectTransform)obj).offsetMin = Vector2.zero; ((RectTransform)obj).offsetMax = Vector2.zero; Image component = val.GetComponent<Image>(); ((Graphic)component).color = Color.clear; ((Graphic)component).raycastTarget = true; val.GetComponent<LayoutElement>().ignoreLayout = true; } } private bool CanDrag(PointerEventData eventData) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Invalid comparison between Unknown and I4 if (Element != null && (Object)(object)Element.Root != (Object)null && (Object)(object)Element.Parent != (Object)null && (Object)(object)Element.Canvas != (Object)null && !EditMode.Active && Plugin.WindowsDraggableWhenOpen.Value) { return (int)eventData.button == 0; } return false; } public void OnPointerDown(PointerEventData eventData) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) pressed = false; moved = false; if (!CanDrag(eventData)) { return; } RaycastResult val = eventData.pointerPressRaycast; GameObject gameObject = ((RaycastResult)(ref val)).gameObject; if ((Object)(object)gameObject == (Object)null) { val = eventData.pointerCurrentRaycast; gameObject = ((RaycastResult)(ref val)).gameObject; } if ((Object)(object)gameObject != (Object)null) { if ((Object)(object)ExecuteEvents.GetEventHandler<IDragHandler>(gameObject) != (Object)null) { return; } Transform transform = gameObject.transform; RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null); if ((Object)(object)val2 != (Object)null && ElementBounds.IsScreenSized(val2, Element.Canvas)) { return; } } if (RectTransformUtility.ScreenPointToLocalPointInRectangle(Element.Parent, eventData.position, Element.Camera, ref dragStartLocal)) { pressed = true; pointerId = eventData.pointerId; pressScreen = eventData.position; dragStart = Element.Current; ElementBounds.Measure(Element); } } public void OnPointerUp(PointerEventData eventData) { if (pressed && eventData.pointerId == pointerId) { pressed = false; if (moved) { moved = false; LayoutStore.Save(); } } } private void Update() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) if (!pressed) { return; } if (Element == null || (Object)(object)Element.Root == (Object)null || (Object)(object)Element.Parent == (Object)null || EditMode.Active) { pressed = false; return; } Vector2 val = Vector2.op_Implicit(ZInput.pointerPosition); if (!moved) { Vector2 val2 = val - pressScreen; if (((Vector2)(ref val2)).magnitude < 4f) { return; } } moved = true; Vector2 val3 = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(Element.Parent, val, Element.Camera, ref val3)) { Vector2 position = dragStart.Position + (val3 - dragStartLocal); position = ElementBounds.ClampPosition(Element, new Placement(position, Element.Current.Scale)); Element.SetPosition(position); } } private void OnDisable() { if (pressed && moved) { LayoutStore.Save(); } pressed = false; moved = false; } private void LateUpdate() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) if (Element != null && !((Object)(object)Element.Root == (Object)null) && Element.HasCustomPlacement) { RectTransform root = Element.Root; Placement current = Element.Current; Placement placement = Element.Default; Vector2 anchoredPosition = root.anchoredPosition; Vector2 lastAppliedPosition = Element.LastAppliedPosition; Vector2 val = current.Position - placement.Position; bool flag = false; if (Mathf.Abs(anchoredPosition.x - lastAppliedPosition.x) > 0.0001f) { anchoredPosition.x += val.x; flag = true; } if (Mathf.Abs(anchoredPosition.y - lastAppliedPosition.y) > 0.0001f) { anchoredPosition.y += val.y; flag = true; } if (flag) { root.anchoredPosition = anchoredPosition; Element.LastAppliedPosition = anchoredPosition; } float x = ((Transform)root).localScale.x; if (Mathf.Abs(x - Element.LastAppliedScale) > 0.0001f) { float num = ((placement.Scale > 0.0001f) ? (current.Scale / placement.Scale) : current.Scale); float num2 = x * num; ((Transform)root).localScale = Element.ScaleVector(num2); Element.LastAppliedScale = num2; } } } } internal static class ElementBounds { public const float MinWidth = 64f; public const float MinHeight = 24f; private const float ScreenSizedFraction = 0.95f; private static readonly Vector3[] corners = (Vector3[])(object)new Vector3[4]; private static readonly List<Graphic> graphics = new List<Graphic>(); private static readonly List<RectMask2D> rectMasks = new List<RectMask2D>(); private static readonly List<Mask> masks = new List<Mask>(); private static readonly Dictionary<Transform, Rect> clipRects = new Dictionary<Transform, Rect>(); private static readonly List<Transform> nestedRoots = new List<Transform>(); public static bool IsUnderHiddenHud(UiElement e) { Hud instance = Hud.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_rootObject == (Object)null || (Object)(object)e.Root == (Object)null || instance.IsVisible()) { return false; } return ((Transform)e.Root).IsChildOf(instance.m_rootObject.transform); } public static bool Measure(UiElement e) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) RectTransform root = e.Root; if ((Object)(object)root == (Object)null || (Object)(object)((Transform)root).parent == (Object)null || (Object)(object)e.Canvas == (Object)null) { return false; } Transform transform = ((Component)e.Canvas).transform; RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null); Rect rect = val.rect; float num = float.MaxValue; float num2 = float.MaxValue; float num3 = float.MinValue; float num4 = float.MinValue; bool flag = false; GameObject visibilityObject = e.VisibilityObject; CollectNestedRoots(e); CollectClipRects(root, val, visibilityObject); float minX = 0f; float minY = 0f; float maxX = 0f; float maxY = 0f; if (e.ClipToRoot) { CanvasCorners(root, val, out minX, out minY, out maxX, out maxY); } graphics.Clear(); ((Component)root).GetComponentsInChildren<Graphic>(true, graphics); for (int i = 0; i < graphics.Count; i++) { Graphic val2 = graphics[i]; if ((Object)(object)val2 == (Object)null || IsNested(((Component)val2).transform) || !WouldBeActive(((Component)val2).transform, (Transform)(object)root, visibilityObject) || (e.IgnoreGraphicFunc != null && e.IgnoreGraphicFunc(((Component)val2).transform))) { continue; } RectTransform rectTransform = val2.rectTransform; Rect rect2 = rectTransform.rect; if (((Rect)(ref rect2)).width <= 0f) { continue; } rect2 = rectTransform.rect; if (((Rect)(ref rect2)).height <= 0f) { continue; } TMP_Text val3 = (TMP_Text)(object)((val2 is TMP_Text) ? val2 : null); if ((Object)(object)val3 != (Object)null && string.IsNullOrWhiteSpace(val3.text)) { continue; } GraphicCorners(val2, val, out var minX2, out var minY2, out var maxX2, out var maxY2); if ((maxX2 - minX2 >= ((Rect)(ref rect)).width * 0.95f && maxY2 - minY2 >= ((Rect)(ref rect)).height * 0.95f) || !ClipToMasks((Transform)(object)rectTransform, (Transform)(object)root, ref minX2, ref minY2, ref maxX2, ref maxY2)) { continue; } if (e.ClipToRoot) { if (minX2 < minX) { minX2 = minX; } if (minY2 < minY) { minY2 = minY; } if (maxX2 > maxX) { maxX2 = maxX; } if (maxY2 > maxY) { maxY2 = maxY; } if (maxX2 <= minX2 || maxY2 <= minY2) { continue; } } flag = true; if (minX2 < num) { num = minX2; } if (minY2 < num2) { num2 = minY2; } if (maxX2 > num3) { num3 = maxX2; } if (maxY2 > num4) { num4 = maxY2; } } graphics.Clear(); clipRects.Clear(); nestedRoots.Clear(); if (flag) { e.LocalBounds = CanvasToLocal(root, val, num, num2, num3, num4); e.LocalBoundsFromGraphics = true; } else if (!e.KeepLastBounds || !e.HasMeasurement || !e.LocalBoundsFromGraphics) { e.LocalBounds = root.rect; e.LocalBoundsFromGraphics = false; } e.HasMeasurement = true; return true; } public static bool TryGetCanvasBounds(UiElement e, out Rect bounds) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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) bounds = default(Rect); RectTransform root = e.Root; if ((Object)(object)root == (Object)null || (Object)(object)((Transform)root).parent == (Object)null || (Object)(object)e.Canvas == (Object)null) { return false; } if (!e.HasMeasurement && !Measure(e)) { return false; } Vector3 localScale = ((Transform)root).localScale; bounds = LocalToCanvas(e, ((Transform)root).localPosition, ((Transform)root).localRotation, localScale.x, localScale.y); return true; } public static Vector2 ClampPosition(UiElement e, Placement p) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) RectTransform root = e.Root; if ((Object)(object)root == (Object)null || (Object)(object)((Transform)root).parent == (Object)null || (Object)(object)e.Canvas == (Object)null) { return p.Position; } if (!e.HasMeasurement && !Measure(e)) { return p.Position; } Vector2 val = p.Position + e.GameOffset - root.anchoredPosition; Vector3 localPosition = ((Transform)root).localPosition + new Vector3(val.x, val.y, 0f); Vector3 val2 = e.ScaleVector(p.Scale); Rect val3 = LocalToCanvas(e, localPosition, ((Transform)root).localRotation, val2.x, val2.y); Transform transform = ((Component)e.Canvas).transform; RectTransform val4 = (RectTransform)(object)((transform is RectTransform) ? transform : null); Rect rect = val4.rect; Vector2 zero = Vector2.zero; if (((Rect)(ref val3)).width >= ((Rect)(ref rect)).width) { zero.x = ((Rect)(ref rect)).xMin - ((Rect)(ref val3)).xMin; } else if (((Rect)(ref val3)).xMin < ((Rect)(ref rect)).xMin) { zero.x = ((Rect)(ref rect)).xMin - ((Rect)(ref val3)).xMin; } else if (((Rect)(ref val3)).xMax > ((Rect)(ref rect)).xMax) { zero.x = ((Rect)(ref rect)).xMax - ((Rect)(ref val3)).xMax; } if (((Rect)(ref val3)).height >= ((Rect)(ref rect)).height) { zero.y = ((Rect)(ref rect)).yMax - ((Rect)(ref val3)).yMax; } else if (((Rect)(ref val3)).yMin < ((Rect)(ref rect)).yMin) { zero.y = ((Rect)(ref rect)).yMin - ((Rect)(ref val3)).yMin; } else if (((Rect)(ref val3)).yMax > ((Rect)(ref rect)).yMax) { zero.y = ((Rect)(ref rect)).yMax - ((Rect)(ref val3)).yMax; } if (((Vector2)(ref zero)).sqrMagnitude < 0.0001f) { return p.Position; } Vector3 val5 = ((Transform)val4).TransformVector(new Vector3(zero.x, zero.y, 0f)); Vector3 val6 = ((Transform)root).parent.InverseTransformVector(val5); return p.Position + new Vector2(val6.x, val6.y); } private static Rect LocalToCanvas(UiElement e, Vector3 localPosition, Quaternion localRotation, float scaleX, float scaleY) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)e.Canvas).transform; RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null); Transform parent = ((Transform)e.Root).parent; Rect localBounds = e.LocalBounds; float num = float.MaxValue; float num2 = float.MaxValue; float num3 = float.MinValue; float num4 = float.MinValue; for (int i = 0; i < 4; i++) { float num5 = ((i == 1 || i == 2) ? ((Rect)(ref localBounds)).xMax : ((Rect)(ref localBounds)).xMin); float num6 = ((i >= 2) ? ((Rect)(ref localBounds)).yMax : ((Rect)(ref localBounds)).yMin); Vector3 val2 = localPosition + localRotation * new Vector3(num5 * scaleX, num6 * scaleY, 0f); Vector3 val3 = ((Transform)val).InverseTransformPoint(parent.TransformPoint(val2)); if (val3.x < num) { num = val3.x; } if (val3.y < num2) { num2 = val3.y; } if (val3.x > num3) { num3 = val3.x; } if (val3.y > num4) { num4 = val3.y; } } if (num3 - num < 64f) { float num7 = (num + num3) * 0.5f; num = num7 - 32f; num3 = num7 + 32f; } if (num4 - num2 < 24f) { float num8 = (num2 + num4) * 0.5f; num2 = num8 - 12f; num4 = num8 + 12f; } return Rect.MinMaxRect(num, num2, num3, num4); } private static Rect CanvasToLocal(RectTransform root, RectTransform canvasRt, float minX, float minY, float maxX, float maxY) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0122: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) Transform parent = ((Transform)root).parent; Quaternion val = Quaternion.Inverse(((Transform)root).localRotation); Vector3 localPosition = ((Transform)root).localPosition; Vector3 localScale = ((Transform)root).localScale; float num = float.MaxValue; float num2 = float.MaxValue; float num3 = float.MinValue; float num4 = float.MinValue; for (int i = 0; i < 4; i++) { float num5 = ((i == 1 || i == 2) ? maxX : minX); float num6 = ((i >= 2) ? maxY : minY); Vector3 val2 = parent.InverseTransformPoint(((Transform)canvasRt).TransformPoint(new Vector3(num5, num6, 0f))); Vector3 val3 = val * (val2 - localPosition); float num7 = ((Mathf.Abs(localScale.x) > 0.0001f) ? (val3.x / localScale.x) : val3.x); float num8 = ((Mathf.Abs(localScale.y) > 0.0001f) ? (val3.y / localScale.y) : val3.y); if (num7 < num) { num = num7; } if (num8 < num2) { num2 = num8; } if (num7 > num3) { num3 = num7; } if (num8 > num4) { num4 = num8; } } return Rect.MinMaxRect(num, num2, num3, num4); } private static void CollectClipRects(RectTransform root, RectTransform canvasRt, GameObject shown) { clipRects.Clear(); rectMasks.Clear(); ((Component)root).GetComponentsInChildren<RectMask2D>(true, rectMasks); foreach (RectMask2D rectMask in rectMasks) { if ((Object)(object)rectMask != (Object)null && ((Behaviour)rectMask).enabled && WouldBeActive(((Component)rectMask).transform, (Transform)(object)root, shown)) { AddClipRect(rectMask.rectTransform, canvasRt); } } rectMasks.Clear(); masks.Clear(); ((Component)root).GetComponentsInChildren<Mask>(true, masks); foreach (Mask mask in masks) { if ((Object)(object)mask != (Object)null && ((Behaviour)mask).enabled && (Object)(object)mask.graphic != (Object)null && WouldBeActive(((Component)mask).transform, (Transform)(object)root, shown)) { AddClipRect(mask.rectTransform, canvasRt); } } masks.Clear(); } private static void CollectNestedRoots(UiElement e) { nestedRoots.Clear(); IReadOnlyList<UiElement> all = ElementRegistry.All; for (int i = 0; i < all.Count; i++) { UiElement uiElement = all[i]; if (uiElement != e && (Object)(object)uiElement.Root != (Object)null && (Object)(object)uiElement.Root != (Object)(object)e.Root && ((Transform)uiElement.Root).IsChildOf((Transform)(object)e.Root)) { nestedRoots.Add((Transform)(object)uiElement.Root); } } } private static bool IsNested(Transform t) { for (int i = 0; i < nestedRoots.Count; i++) { if (t.IsChildOf(nestedRoots[i])) { return true; } } return false; } private static void AddClipRect(RectTransform rt, RectTransform canvasRt) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) CanvasCorners(rt, canvasRt, out var minX, out var minY, out var maxX, out var maxY); clipRects[(Transform)(object)rt] = Rect.MinMaxRect(minX, minY, maxX, maxY); } private static bool ClipToMasks(Transform t, Transform root, ref float minX, ref float minY, ref float maxX, ref float maxY) { if (clipRects.Count == 0) { return true; } while ((Object)(object)t != (Object)null) { if (clipRects.TryGetValue(t, out var value)) { if (((Rect)(ref value)).xMin > minX) { minX = ((Rect)(ref value)).xMin; } if (((Rect)(ref value)).yMin > minY) { minY = ((Rect)(ref value)).yMin; } if (((Rect)(ref value)).xMax < maxX) { maxX = ((Rect)(ref value)).xMax; } if (((Rect)(ref value)).yMax < maxY) { maxY = ((Rect)(ref value)).yMax; } if (maxX - minX <= 0f || maxY - minY <= 0f) { return false; } } if ((Object)(object)t == (Object)(object)root) { break; } t = t.parent; } return true; } public static bool IsScreenSized(RectTransform rt, Canvas canvas) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)rt == (Object)null || (Object)(object)canvas == (Object)null) { return false; } Transform transform = ((Component)canvas).transform; RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null); Rect rect = val.rect; CanvasCorners(rt, val, out var minX, out var minY, out var maxX, out var maxY); if (maxX - minX >= ((Rect)(ref rect)).width * 0.95f) { return maxY - minY >= ((Rect)(ref rect)).height * 0.95f; } return false; } private static void GraphicCorners(Graphic g, RectTransform canvasRt, out float minX, out float minY, out float maxX, out float maxY) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) TMP_Text val = (TMP_Text)(object)((g is TMP_Text) ? g : null); if ((Object)(object)val != (Object)null && TryGetTextRect(val, out var local)) { LocalRectCorners(g.rectTransform, local, canvasRt, out minX, out minY, out maxX, out maxY); } else { CanvasCorners(g.rectTransform, canvasRt, out minX, out minY, out maxX, out maxY); } } private static bool TryGetTextRect(TMP_Text text, out Rect local) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Invalid comparison between Unknown and I4 //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Invalid comparison between Unknown and I4 //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Invalid comparison between Unknown and I4 //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Invalid comparison between Unknown and I4 //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Invalid comparison between Unknown and I4 //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Invalid comparison between Unknown and I4 //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Invalid comparison between Unknown and I4 //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Invalid comparison between Unknown and I4 //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Invalid comparison between Unknown and I4 //IL_0236: Unknown result type (might be due to invalid IL or missing references) local = default(Rect); try { if (string.IsNullOrEmpty(text.text)) { return false; } TMP_TextInfo textInfo = t