Decompiled source of SparrohUILib v2.1.0
BepInEx/plugins/SparrohUILib.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; 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.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Pigeon.Movement; using Sparroh.UI; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Sparroh")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.2.3.0")] [assembly: AssemblyInformationalVersion("1.2.3")] [assembly: AssemblyProduct("SparrohUILib")] [assembly: AssemblyTitle("SparrohUILib")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.3.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; } } } [BepInPlugin("sparroh.uilibrary", "SparrohUILib", "1.2.2")] [MycoMod(/*Could not decode attribute arguments.*/)] public class SparrohUILibPlugin : BaseUnityPlugin { public const string PluginGUID = "sparroh.uilibrary"; public const string PluginName = "SparrohUILib"; public const string PluginVersion = "1.2.2"; internal static ManualLogSource Logger; private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; UITheme.Initialize(); SceneManager.sceneUnloaded += OnSceneUnloaded; Logger.LogInfo((object)"SparrohUILib v1.2.2 loaded."); } private void Update() { HudVisibility.Tick(); GearActionBar.Tick(); } private void OnDestroy() { SceneManager.sceneUnloaded -= OnSceneUnloaded; } private static void OnSceneUnloaded(Scene scene) { HudVisibility.ResetSessionState(); GearActionBar.InvalidateHostForSceneUnload(); UITheme.ClearFontCache(); } } namespace Sparroh.UI { public static class RichText { public static string Colorize(string text, Color color) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) return "<color=#" + UIColors.ToHex(color) + ">" + text + "</color>"; } public static string Colorize(string text, string hexWithoutHash) { return "<color=#" + hexWithoutHash + ">" + text + "</color>"; } public static string Bold(string text) { return "<b>" + text + "</b>"; } public static string Italic(string text) { return "<i>" + text + "</i>"; } public static string Size(string text, int percent) { return $"<size={percent}%>{text}</size>"; } public static string Labeled(string label, string value, Color valueColor) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) return label + ": " + Colorize(value, valueColor); } public static string Labeled(string label, string value, Color valueColor, string unit) { //IL_0026: 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) if (string.IsNullOrEmpty(unit)) { return Labeled(label, value, valueColor); } return label + ": " + Colorize(value, valueColor) + " " + unit; } public static string Labeled(string label, float value, Color valueColor, string unit = null, string format = "F1") { //IL_000a: Unknown result type (might be due to invalid IL or missing references) return Labeled(label, value.ToString(format), valueColor, unit); } public static string Labeled(string label, int value, Color valueColor, string unit = null) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) return Labeled(label, value.ToString(), valueColor, unit); } public static string LabeledWithRate(string label, float value, float rate, Color color, string format = "F0", string rateFormat = "F1") { //IL_001d: 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) return label + ": " + Colorize(value.ToString(format), color) + " (" + Colorize(rate.ToString(rateFormat), color) + "/s)"; } } public static class UIFactory { private static Sprite _whiteSprite; public static Sprite WhiteSprite { get { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_whiteSprite != (Object)null) { return _whiteSprite; } Texture2D whiteTexture = Texture2D.whiteTexture; _whiteSprite = Sprite.Create(whiteTexture, new Rect(0f, 0f, (float)((Texture)whiteTexture).width, (float)((Texture)whiteTexture).height), new Vector2(0.5f, 0.5f), 100f); return _whiteSprite; } } public static GameObject Create(string name, Transform parent = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown GameObject val = new GameObject(name); if ((Object)(object)parent != (Object)null) { val.transform.SetParent(parent, false); } return val; } public static RectTransform CreateRect(string name, Transform parent = null) { return Create(name, parent).AddComponent<RectTransform>(); } public static Image CreateImage(string name, Transform parent, Color color, bool raycast = true) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) Image obj = ((Component)CreateRect(name, parent)).gameObject.AddComponent<Image>(); ((Graphic)obj).color = color; ((Graphic)obj).raycastTarget = raycast; return obj; } public static TextMeshProUGUI CreateTmp(string name, Transform parent, string text = "", float fontSize = -1f, Color? color = null, TextAlignmentOptions alignment = (TextAlignmentOptions)513, bool wrap = false) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI obj = ((Component)CreateRect(name, parent)).gameObject.AddComponent<TextMeshProUGUI>(); float fontSize2 = ((fontSize > 0f) ? fontSize : UITheme.ScaledFontBody); UITheme.ApplyTextStyle(obj, fontSize2, color, alignment, wrap); ((TMP_Text)obj).text = text ?? string.Empty; return obj; } public static Canvas CreateOverlayCanvas(string name, int sortingOrder) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) GameObject obj = Create(name); Object.DontDestroyOnLoad((Object)(object)obj); Canvas val = obj.AddComponent<Canvas>(); val.renderMode = (RenderMode)0; val.sortingOrder = sortingOrder; CanvasScaler obj2 = obj.AddComponent<CanvasScaler>(); obj2.uiScaleMode = (ScaleMode)1; obj2.referenceResolution = new Vector2(1920f, 1080f); obj2.screenMatchMode = (ScreenMatchMode)0; obj2.matchWidthOrHeight = 0.5f; obj2.referencePixelsPerUnit = 100f; obj.AddComponent<GraphicRaycaster>(); return val; } public static VerticalLayoutGroup AddVerticalLayout(GameObject go, float spacing = -1f, RectOffset padding = null, TextAnchor childAlignment = (TextAnchor)0, bool controlChildHeight = true, bool expandHeight = false, bool controlChildWidth = true, bool expandWidth = true) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) VerticalLayoutGroup val = go.GetComponent<VerticalLayoutGroup>(); if ((Object)(object)val == (Object)null) { val = go.AddComponent<VerticalLayoutGroup>(); } ((HorizontalOrVerticalLayoutGroup)val).spacing = ((spacing >= 0f) ? spacing : UITheme.S(UITheme.SpacingNormal)); ((LayoutGroup)val).padding = padding ?? UITheme.ScaledPadding(12, 12, 12, 12); ((LayoutGroup)val).childAlignment = childAlignment; ((HorizontalOrVerticalLayoutGroup)val).childControlHeight = controlChildHeight; ((HorizontalOrVerticalLayoutGroup)val).childForceExpandHeight = expandHeight; ((HorizontalOrVerticalLayoutGroup)val).childControlWidth = controlChildWidth; ((HorizontalOrVerticalLayoutGroup)val).childForceExpandWidth = expandWidth; return val; } public static HorizontalLayoutGroup AddHorizontalLayout(GameObject go, float spacing = -1f, RectOffset padding = null, TextAnchor childAlignment = (TextAnchor)3, bool controlChildWidth = true, bool expandWidth = false, bool controlChildHeight = true, bool expandHeight = true) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) HorizontalLayoutGroup val = go.GetComponent<HorizontalLayoutGroup>(); if ((Object)(object)val == (Object)null) { val = go.AddComponent<HorizontalLayoutGroup>(); } ((HorizontalOrVerticalLayoutGroup)val).spacing = ((spacing >= 0f) ? spacing : UITheme.S(UITheme.SpacingNormal)); ((LayoutGroup)val).padding = padding ?? UITheme.ScaledPadding(8, 8, 4, 4); ((LayoutGroup)val).childAlignment = childAlignment; ((HorizontalOrVerticalLayoutGroup)val).childControlWidth = controlChildWidth; ((HorizontalOrVerticalLayoutGroup)val).childForceExpandWidth = expandWidth; ((HorizontalOrVerticalLayoutGroup)val).childControlHeight = controlChildHeight; ((HorizontalOrVerticalLayoutGroup)val).childForceExpandHeight = expandHeight; return val; } public static ContentSizeFitter AddContentSizeFitter(GameObject go, FitMode horizontal = (FitMode)0, FitMode vertical = (FitMode)2) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) ContentSizeFitter val = go.GetComponent<ContentSizeFitter>(); if ((Object)(object)val == (Object)null) { val = go.AddComponent<ContentSizeFitter>(); } val.horizontalFit = horizontal; val.verticalFit = vertical; return val; } public static void ApplyWhiteSprite(Image img) { if ((Object)(object)img != (Object)null && (Object)(object)img.sprite == (Object)null) { img.sprite = WhiteSprite; } } } public static class UIHelpers { public static bool TryGetReticle(out Transform reticle) { reticle = null; try { if ((Object)(object)Player.LocalPlayer == (Object)null || (Object)(object)Player.LocalPlayer.PlayerLook == (Object)null || (Object)(object)Player.LocalPlayer.PlayerLook.Reticle == (Object)null) { return false; } reticle = (Transform)(object)Player.LocalPlayer.PlayerLook.Reticle; return true; } catch { return false; } } public static void SetAnchor(RectTransform rt, Vector2 anchorMin, Vector2 anchorMax, Vector2? pivot = null) { //IL_000b: 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_0024: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)rt == (Object)null)) { rt.anchorMin = anchorMin; rt.anchorMax = anchorMax; if (pivot.HasValue) { rt.pivot = pivot.Value; } } } public static void SetPointAnchor(RectTransform rt, float x, float y, Vector2? pivot = null) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_0021: Unknown result type (might be due to invalid IL or missing references) Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(x, y); SetAnchor(rt, val, val, (Vector2)(((??)pivot) ?? new Vector2(0.5f, 0.5f))); } public static void SetFillParent(RectTransform rt, float padding = 0f) { //IL_000b: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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) if (!((Object)(object)rt == (Object)null)) { rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = new Vector2(padding, padding); rt.offsetMax = new Vector2(0f - padding, 0f - padding); rt.pivot = new Vector2(0.5f, 0.5f); } } public static void SetTopStretch(RectTransform rt, float height, float left = 0f, float right = 0f, float top = 0f) { //IL_0015: 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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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) if (!((Object)(object)rt == (Object)null)) { rt.anchorMin = new Vector2(0f, 1f); rt.anchorMax = new Vector2(1f, 1f); rt.pivot = new Vector2(0.5f, 1f); rt.sizeDelta = new Vector2(0f - (left + right), height); rt.anchoredPosition = new Vector2((left - right) * 0.5f, 0f - top); } } public static void DestroySafe(Object obj) { if (!(obj == (Object)null)) { if (Application.isPlaying) { Object.Destroy(obj); } else { Object.DestroyImmediate(obj); } } } public static void DestroyChildren(Transform parent) { if (!((Object)(object)parent == (Object)null)) { for (int num = parent.childCount - 1; num >= 0; num--) { DestroySafe((Object)(object)((Component)parent.GetChild(num)).gameObject); } } } public static Image EnsureImage(GameObject go, Color color, bool raycast = true) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) Image val = go.GetComponent<Image>(); if ((Object)(object)val == (Object)null) { val = go.AddComponent<Image>(); } ((Graphic)val).color = color; ((Graphic)val).raycastTarget = raycast; return val; } public static LayoutElement EnsureLayoutElement(GameObject go, float? preferredWidth = null, float? preferredHeight = null, float? minHeight = null) { LayoutElement val = go.GetComponent<LayoutElement>(); if ((Object)(object)val == (Object)null) { val = go.AddComponent<LayoutElement>(); } if (preferredWidth.HasValue) { val.preferredWidth = preferredWidth.Value; } if (preferredHeight.HasValue) { val.preferredHeight = preferredHeight.Value; } if (minHeight.HasValue) { val.minHeight = minHeight.Value; } return val; } public static bool ScreenToLocal(RectTransform parent, Vector2 screenPoint, out Vector2 localPoint, Camera cam = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, screenPoint, cam, ref localPoint); } public static Vector2 ScreenPointToNormalizedAnchor(RectTransform parent, Vector2 screenPoint, Camera cam = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: 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_0038: 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_0085: Unknown result type (might be due to invalid IL or missing references) if (!ScreenToLocal(parent, screenPoint, out var localPoint, cam)) { return new Vector2(0.5f, 0.5f); } Rect rect = parent.rect; float num = ((((Rect)(ref rect)).width > 0f) ? ((localPoint.x - ((Rect)(ref rect)).xMin) / ((Rect)(ref rect)).width) : 0.5f); float num2 = ((((Rect)(ref rect)).height > 0f) ? ((localPoint.y - ((Rect)(ref rect)).yMin) / ((Rect)(ref rect)).height) : 0.5f); return new Vector2(Mathf.Clamp01(num), Mathf.Clamp01(num2)); } } public sealed class HudAnchors { public const string DefaultSection = "HUD Positioning"; public ConfigEntry<float> X { get; } public ConfigEntry<float> Y { get; } public float XValue => X.Value; public float YValue => Y.Value; public HudAnchors(ConfigEntry<float> x, ConfigEntry<float> y) { X = x ?? throw new ArgumentNullException("x"); Y = y ?? throw new ArgumentNullException("y"); } public static HudAnchors Bind(ConfigFile config, string name, float defaultX, float defaultY, string section = "HUD Positioning") { if (config == null) { throw new ArgumentNullException("config"); } if (string.IsNullOrEmpty(name)) { throw new ArgumentException("name is required", "name"); } ConfigEntry<float> x = config.Bind<float>(section, name + " X", defaultX, "X anchor position for " + name + " (0-1)."); ConfigEntry<float> y = config.Bind<float>(section, name + " Y", defaultY, "Y anchor position for " + name + " (0-1)."); return new HudAnchors(x, y); } public static HudAnchors BindKeys(ConfigFile config, string keyX, string keyY, float defaultX, float defaultY, string section = "HUD Positioning", string descriptionName = null) { if (config == null) { throw new ArgumentNullException("config"); } if (string.IsNullOrEmpty(keyX)) { throw new ArgumentException("keyX is required", "keyX"); } if (string.IsNullOrEmpty(keyY)) { throw new ArgumentException("keyY is required", "keyY"); } string text = (string.IsNullOrEmpty(descriptionName) ? keyX : descriptionName); ConfigEntry<float> x = config.Bind<float>(section, keyX, defaultX, "X anchor position for " + text + " (0-1)."); ConfigEntry<float> y = config.Bind<float>(section, keyY, defaultY, "Y anchor position for " + text + " (0-1)."); return new HudAnchors(x, y); } } public class HudBuilder { private struct LineSpec { public string Name; public float FontSize; public TextAlignmentOptions Alignment; } private readonly List<LineSpec> _lines = new List<LineSpec>(); private readonly string _name; private Vector2 _anchoredPosition = Vector2.zero; private float _anchorX = 0.5f; private float _anchorY = 0.5f; private Color _backgroundColor = UIColors.WithAlpha(UIColors.PanelBg, 0.55f); private Transform _parent; private bool _parentToReticle = true; private Vector2 _pivot = new Vector2(0f, 1f); private Vector2 _size; private bool _withBackground; private HudBuilder(string name) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_0058: 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_0084: Unknown result type (might be due to invalid IL or missing references) _name = name; _size = new Vector2(UITheme.S(UITheme.HudDefaultWidth), UITheme.S(UITheme.HudLineHeight)); } public static HudBuilder Create(string name) { return new HudBuilder(name); } public HudBuilder ParentToReticle(bool enabled = true) { _parentToReticle = enabled; return this; } public HudBuilder Parent(Transform parent) { _parent = parent; _parentToReticle = false; return this; } public HudBuilder Anchor(float x, float y) { _anchorX = Mathf.Clamp01(x); _anchorY = Mathf.Clamp01(y); return this; } public HudBuilder Pivot(Vector2 pivot) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) _pivot = pivot; return this; } public HudBuilder Size(float width, float height, bool scale = true) { //IL_000f: 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_0014: Unknown result type (might be due to invalid IL or missing references) _size = (Vector2)(scale ? UITheme.ScaledSize(width, height) : new Vector2(width, height)); return this; } public HudBuilder AnchoredPosition(Vector2 pos, bool scale = true) { //IL_0007: 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_0004: 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) _anchoredPosition = (scale ? UITheme.S(pos) : pos); return this; } public HudBuilder WithBackground(Color? color = null) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) _withBackground = true; if (color.HasValue) { _backgroundColor = color.Value; } return this; } public HudBuilder AddText(string name = "Text", float fontSize = -1f, TextAlignmentOptions alignment = (TextAlignmentOptions)513) { //IL_002f: 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) _lines.Add(new LineSpec { Name = name, FontSize = ((fontSize > 0f) ? fontSize : UITheme.FontHud), Alignment = alignment }); return this; } public HudBuilder AddLines(int count, float fontSize = -1f, TextAlignmentOptions alignment = (TextAlignmentOptions)513) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < count; i++) { AddText($"Line{i}", fontSize, alignment); } return this; } public HudHandle Build() { //IL_00b0: 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_00cd: 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_013b: 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) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0190: 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_01b6: Unknown result type (might be due to invalid IL or missing references) Transform reticle = _parent; if (_parentToReticle && !UIHelpers.TryGetReticle(out reticle)) { return null; } if ((Object)(object)reticle == (Object)null) { return null; } float scaledHudLineHeight = UITheme.ScaledHudLineHeight; if (_lines.Count > 1) { float num = scaledHudLineHeight * (float)_lines.Count + UITheme.S(4f); if (_size.y < num) { _size.y = num; } } else if (_lines.Count == 0) { AddText("Text", -1f, (TextAlignmentOptions)513); } RectTransform val = UIFactory.CreateRect(_name, reticle); UIHelpers.SetPointAnchor(val, _anchorX, _anchorY, _pivot); val.sizeDelta = _size; val.anchoredPosition = _anchoredPosition; if (_withBackground) { UIFactory.ApplyWhiteSprite(UIHelpers.EnsureImage(((Component)val).gameObject, _backgroundColor, raycast: false)); } UIText[] array = new UIText[_lines.Count]; for (int i = 0; i < _lines.Count; i++) { LineSpec lineSpec = _lines[i]; float fontSize = UITheme.S(lineSpec.FontSize); UIText uIText = UIText.Create((Transform)(object)val, lineSpec.Name, "", fontSize, UIColors.TextPrimary, lineSpec.Alignment); RectTransform rect = uIText.Rect; rect.anchorMin = new Vector2(0f, 1f); rect.anchorMax = new Vector2(1f, 1f); rect.pivot = new Vector2(0.5f, 1f); rect.sizeDelta = new Vector2(0f, scaledHudLineHeight); rect.anchoredPosition = new Vector2(0f, (float)(-i) * scaledHudLineHeight); array[i] = uIText; } return new HudHandle(((Component)val).gameObject, val, array); } } public class HudHandle { private HudRepositionBinding _reposition; public GameObject GameObject { get; private set; } public RectTransform Rect { get; private set; } public UIText[] Lines { get; private set; } public UIText Primary { get { if (Lines == null || Lines.Length == 0) { return null; } return Lines[0]; } } public bool WantActive { get; private set; } = true; public bool IsAlive => (Object)(object)GameObject != (Object)null; public bool IsActive { get { if (IsAlive) { return GameObject.activeSelf; } return false; } } public Vector2 Size { get { //IL_001a: 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) if (!((Object)(object)Rect != (Object)null)) { return Vector2.zero; } return Rect.sizeDelta; } } public bool HasReposition => _reposition != null; internal HudHandle(GameObject go, RectTransform rt, UIText[] lines) { GameObject = go; Rect = rt; Lines = lines; go.AddComponent<HudHandleLife>().Handle = this; HudVisibility.Register(this); ApplyEffectiveVisibility(); } public static bool IsValid(HudHandle handle) { return handle?.IsAlive ?? false; } internal void MarkDestroyed() { DetachReposition(); HudVisibility.Unregister(this); GameObject = null; Rect = null; Lines = null; } public void SetAnchor(float x, float y) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (IsAlive && !((Object)(object)Rect == (Object)null)) { UIHelpers.SetPointAnchor(Rect, x, y, Rect.pivot); } } public HudHandle EnableReposition(string id, string displayName, ConfigEntry<float> anchorX, ConfigEntry<float> anchorY) { return HudReposition.Bind(this, id, displayName, anchorX, anchorY); } public HudHandle EnableReposition(string id, string displayName, HudAnchors anchors) { return HudReposition.Bind(this, id, displayName, anchors); } public void DisableReposition() { DetachReposition(); } internal void AttachReposition(string id, string displayName, ConfigEntry<float> anchorX, ConfigEntry<float> anchorY) { DetachReposition(); if (IsAlive) { _reposition = new HudRepositionBinding(this, id, displayName, anchorX, anchorY); _reposition.Attach(); } } internal void DetachReposition() { if (_reposition != null) { _reposition.Detach(); _reposition = null; } } public void SetActive(bool active) { WantActive = active; ApplyEffectiveVisibility(); } internal void ApplyEffectiveVisibility() { if (IsAlive) { bool flag = WantActive && !HudVisibility.IsHidden; if (GameObject.activeSelf != flag) { GameObject.SetActive(flag); } } } public void Destroy() { DetachReposition(); HudVisibility.Unregister(this); GameObject gameObject = GameObject; GameObject = null; Rect = null; Lines = null; UIHelpers.DestroySafe((Object)(object)gameObject); } } internal sealed class HudHandleLife : MonoBehaviour { public HudHandle Handle; private void OnDestroy() { Handle?.MarkDestroyed(); Handle = null; } } public static class HudReposition { public static HudHandle Bind(HudHandle handle, string id, string displayName, ConfigEntry<float> anchorX, ConfigEntry<float> anchorY) { if (!HudHandle.IsValid(handle)) { return handle; } if (string.IsNullOrEmpty(id)) { throw new ArgumentException("id is required", "id"); } if (anchorX == null) { throw new ArgumentNullException("anchorX"); } if (anchorY == null) { throw new ArgumentNullException("anchorY"); } handle.AttachReposition(id, displayName ?? id, anchorX, anchorY); return handle; } public static HudHandle Bind(HudHandle handle, string id, string displayName, HudAnchors anchors) { if (anchors == null) { throw new ArgumentNullException("anchors"); } return Bind(handle, id, displayName, anchors.X, anchors.Y); } public static void Unbind(HudHandle handle) { handle?.DetachReposition(); } } internal sealed class HudRepositionBinding { private readonly string _displayName; private readonly string _id; private readonly ConfigEntry<float> _anchorX; private readonly ConfigEntry<float> _anchorY; private readonly EventHandler _onChanged; private HudHandle _handle; private bool _attached; public string Id => _id; public HudRepositionBinding(HudHandle handle, string id, string displayName, ConfigEntry<float> anchorX, ConfigEntry<float> anchorY) { _handle = handle; _id = id; _displayName = displayName; _anchorX = anchorX; _anchorY = anchorY; _onChanged = OnSettingChanged; } public void Attach() { if (!_attached) { _anchorX.SettingChanged += _onChanged; _anchorY.SettingChanged += _onChanged; _attached = true; ApplyAnchors(); RegisterWithApi(); } } public void Detach() { if (_attached) { _anchorX.SettingChanged -= _onChanged; _anchorY.SettingChanged -= _onChanged; _attached = false; HudRepositionClient.Unregister(_id); _handle = null; } } public void RegisterWithApi() { if (_handle != null && _handle.IsAlive && !((Object)(object)_handle.Rect == (Object)null)) { HudRepositionClient.Register(_id, _displayName, _handle.Rect, _anchorX, _anchorY); } } private void OnSettingChanged(object sender, EventArgs e) { ApplyAnchors(); } private void ApplyAnchors() { if (_handle != null && _handle.IsAlive) { float x = Mathf.Clamp01(_anchorX.Value); float y = Mathf.Clamp01(_anchorY.Value); _handle.SetAnchor(x, y); } } } public static class HudRepositionClient { private const string ApiTypeName = "HudRepositionAPI"; private static Type _apiType; private static MethodInfo _register; private static MethodInfo _unregister; private static bool _available; public static bool IsAvailable { get { EnsureResolved(); return _available; } } public static void Register(string id, string displayName, RectTransform rect, ConfigEntry<float> anchorX, ConfigEntry<float> anchorY) { if (!_available) { EnsureResolved(force: true); } if (!_available || (Object)(object)rect == (Object)null || anchorX == null || anchorY == null) { return; } try { _register.Invoke(null, new object[5] { id, displayName, rect, anchorX, anchorY }); } catch (Exception ex) { Debug.LogWarning((object)("[HudRepositionClient] Register failed: " + (ex.InnerException?.Message ?? ex.Message))); } } public static void Unregister(string id) { if (!_available) { EnsureResolved(force: true); } if (!_available || string.IsNullOrEmpty(id)) { return; } try { _unregister.Invoke(null, new object[1] { id }); } catch (Exception) { } } private static void EnsureResolved(bool force = false) { if (_available && !force) { return; } _apiType = null; _register = null; _unregister = null; _available = false; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { try { Type type = assembly.GetType("HudRepositionAPI", throwOnError: false); if (type != null) { _apiType = type; break; } } catch { } } if (_apiType == null) { return; } MethodInfo[] methods = _apiType.GetMethods(BindingFlags.Static | BindingFlags.Public); foreach (MethodInfo methodInfo in methods) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (methodInfo.Name == "Register" && parameters.Length == 5 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(string) && typeof(RectTransform).IsAssignableFrom(parameters[2].ParameterType)) { _register = methodInfo; } else if (methodInfo.Name == "Unregister" && parameters.Length == 1 && parameters[0].ParameterType == typeof(string)) { _unregister = methodInfo; } } _available = _register != null && _unregister != null; } } public static class HudVisibility { private static readonly List<HudHandle> Handles = new List<HudHandle>(8); private static bool? _lastHidden; public static bool IsHidden { get { try { return (Object)(object)PlayerLook.Instance != (Object)null && PlayerLook.Instance.DisablePlayerHUD; } catch { return false; } } } internal static void Register(HudHandle handle) { if (handle != null && !Handles.Contains(handle)) { Handles.Add(handle); } } internal static void Unregister(HudHandle handle) { if (handle != null) { Handles.Remove(handle); } } public static void Tick() { PruneDead(); bool isHidden = IsHidden; if (!_lastHidden.HasValue || _lastHidden.Value != isHidden) { _lastHidden = isHidden; ApplyAll(); } } public static void PruneDead() { for (int num = Handles.Count - 1; num >= 0; num--) { HudHandle hudHandle = Handles[num]; if (hudHandle == null || !hudHandle.IsAlive) { Handles.RemoveAt(num); } } } public static void ResetSessionState() { _lastHidden = null; PruneDead(); } internal static void ApplyAll() { for (int num = Handles.Count - 1; num >= 0; num--) { HudHandle hudHandle = Handles[num]; if (hudHandle == null || !hudHandle.IsAlive) { Handles.RemoveAt(num); } else { hudHandle.ApplyEffectiveVisibility(); } } } } public static class GearActionBar { private class Slot { public UIButton Button; public string Id; public bool Interactable = true; public string Label = string.Empty; public Action OnClick; public int Order; public UIButtonStyle Style; public bool WantVisible = true; } public const int OrderClearGrid = 10; public const int OrderSolve = 20; public const int OrderCancelSolve = 30; public const int OrderClearSelection = 40; public const int OrderCopyGrid = 50; public const int OrderPasteCode = 60; public const int OrderFilter = 100; public const int OrderPriority = 110; public const int OrderScrapMarked = 120; public const int OrderScrapNonFav = 130; public const int OrderUndoScrap = 140; public const int OrderGunStats = 150; private const float CompactHeightRef = 24f; private const float CompactFontRef = 12f; private const float SlotGapRef = 4f; private const float BarPadH = 8f; private const float BarPadV = 4f; private const float BarTopInset = 18f; private const float BarRightNudge = 24f; private const float MinButtonWidth = 64f; private static RectTransform _root; private static RectTransform _row; private static readonly Dictionary<string, Slot> _slots = new Dictionary<string, Slot>(StringComparer.Ordinal); private static bool _contextVisible; private static bool _built; public static void Register(string id, string label, int order, Action onClick, UIButtonStyle style = UIButtonStyle.Default) { //IL_0177: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(id) || !EnsureBuilt()) { return; } label = label ?? string.Empty; if (_slots.TryGetValue(id, out var value)) { bool num = value.Order != order; bool flag = !string.Equals(value.Label, label, StringComparison.Ordinal); bool flag2 = value.Style != style; bool flag3 = (object)value.OnClick != onClick; value.Order = order; value.OnClick = onClick; if (value.Button != null) { if (flag) { value.Label = label; value.Button.SetText(label); value.Button.SetWidth(Mathf.Max(64f, EstimateWidth(label))); } if (flag2) { value.Style = style; value.Button.SetStyle(style); } if (flag3) { ((UnityEventBase)value.Button.Button.onClick).RemoveAllListeners(); if (onClick != null) { value.Button.OnClick(onClick); } } } if (num) { RebuildOrder(); } ApplyVisibility(); } else { UIButton uIButton = UIButton.Create((Transform)(object)_row, label, onClick, style, null, 24f); if ((Object)(object)uIButton.Label != (Object)null) { ((TMP_Text)uIButton.Label).fontSize = 12f; } uIButton.SetWidth(Mathf.Max(64f, EstimateWidth(label))); if ((Object)(object)uIButton.Background != (Object)null) { ((Graphic)uIButton.Background).raycastPadding = new Vector4(0f, 2f, 0f, 2f); } _slots[id] = new Slot { Id = id, Order = order, Button = uIButton, WantVisible = true, Label = label, Style = style, Interactable = true, OnClick = onClick }; RebuildOrder(); ApplyVisibility(); } } public static void SetText(string id, string text) { if (_slots.TryGetValue(id, out var value) && value.Button != null) { text = text ?? string.Empty; if (!string.Equals(value.Label, text, StringComparison.Ordinal)) { value.Label = text; value.Button.SetText(text); value.Button.SetWidth(Mathf.Max(64f, EstimateWidth(text))); } } } public static void SetInteractable(string id, bool interactable) { if (_slots.TryGetValue(id, out var value) && value.Button != null && value.Interactable != interactable) { value.Interactable = interactable; value.Button.SetInteractable(interactable); } } public static void SetStyle(string id, UIButtonStyle style) { if (_slots.TryGetValue(id, out var value) && value.Button != null && value.Style != style) { value.Style = style; value.Button.SetStyle(style); } } public static void SetSlotVisible(string id, bool visible) { if (!_slots.TryGetValue(id, out var value)) { return; } if (value.WantVisible == visible) { if (value.Button != null) { value.Button.SetActive(visible && _contextVisible); } return; } value.WantVisible = visible; if (value.Button != null) { value.Button.SetActive(visible && _contextVisible); } } public static void SetContextVisible(bool visible) { if (_contextVisible == visible && _built && IsHostAlive()) { if (visible) { BringToFront(); } return; } _contextVisible = visible; if (!_built || !IsHostAlive()) { if (!visible) { return; } EnsureBuilt(); } ApplyVisibility(); } public static bool IsGearMenuOpen() { try { if ((Object)(object)Menu.Instance == (Object)null || !Menu.Instance.IsOpen || (Object)(object)Menu.Instance.WindowSystem == (Object)null) { return false; } Window top = Menu.Instance.WindowSystem.GetTop(); return top is GearDetailsWindow || top is OuroGearWindow; } catch { return false; } } public static void Tick() { if (_built && !IsHostAlive()) { InvalidateHost(); } SetContextVisible(IsGearMenuOpen()); } public static void Unregister(string id) { if (_slots.TryGetValue(id, out var value)) { if (value.Button != null && (Object)(object)value.Button.GameObject != (Object)null) { Object.Destroy((Object)(object)value.Button.GameObject); } _slots.Remove(id); } } private static bool IsHostAlive() { if ((Object)(object)_root != (Object)null) { return (Object)(object)_row != (Object)null; } return false; } private static void InvalidateHost() { foreach (Slot value in _slots.Values) { value.Button = null; } _root = null; _row = null; _built = false; _contextVisible = false; } internal static void InvalidateHostForSceneUnload() { InvalidateHost(); } private static Transform TryGetMenuParent() { try { if ((Object)(object)Menu.Instance == (Object)null) { return null; } if ((Object)(object)Menu.Instance.Canvas != (Object)null) { return ((Component)Menu.Instance.Canvas).transform; } return ((Component)Menu.Instance).transform; } catch { return null; } } private static bool EnsureBuilt() { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_00a5: 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_00c5: 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_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown if (_built && IsHostAlive()) { return true; } Transform val = TryGetMenuParent(); if ((Object)(object)val == (Object)null) { return false; } UITheme.Initialize(); if ((Object)(object)_root != (Object)null) { UIHelpers.DestroySafe((Object)(object)((Component)_root).gameObject); _root = null; _row = null; } RectTransform obj = UIFactory.CreateRect("Sparroh_GearActionBar", val); obj.anchorMin = new Vector2(0f, 1f); obj.anchorMax = new Vector2(1f, 1f); obj.pivot = new Vector2(0.5f, 1f); float num = 36f; obj.sizeDelta = new Vector2(0f, num); obj.anchoredPosition = new Vector2(24f, -18f); ((Transform)obj).localScale = Vector3.one; Image obj2 = ((Component)obj).gameObject.AddComponent<Image>(); ((Graphic)obj2).color = UIColors.WithAlpha(UIColors.PanelBg, 0.55f); UIFactory.ApplyWhiteSprite(obj2); ((Graphic)obj2).raycastTarget = false; UIFactory.AddHorizontalLayout(((Component)obj).gameObject, 4f, new RectOffset(Mathf.RoundToInt(8f), Mathf.RoundToInt(8f), Mathf.RoundToInt(4f), Mathf.RoundToInt(4f)), (TextAnchor)4, controlChildWidth: false, expandWidth: false, controlChildHeight: true, expandHeight: false); _root = obj; _row = obj; _built = true; RecreateButtons(); ((Component)_root).gameObject.SetActive(false); return true; } private static void RecreateButtons() { //IL_0120: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_row == (Object)null) { return; } foreach (Slot item in _slots.Values.OrderBy((Slot x) => x.Order)) { if (item.Button != null && (Object)(object)item.Button.GameObject != (Object)null) { item.Button.GameObject.transform.SetParent((Transform)(object)_row, false); continue; } UIButton uIButton = UIButton.Create((Transform)(object)_row, item.Label, item.OnClick, item.Style, null, 24f); if ((Object)(object)uIButton.Label != (Object)null) { ((TMP_Text)uIButton.Label).fontSize = 12f; } uIButton.SetWidth(Mathf.Max(64f, EstimateWidth(item.Label))); uIButton.SetInteractable(item.Interactable); if ((Object)(object)uIButton.Background != (Object)null) { ((Graphic)uIButton.Background).raycastPadding = new Vector4(0f, 2f, 0f, 2f); } item.Button = uIButton; } RebuildOrder(); } private static void BringToFront() { if (!((Object)(object)_root == (Object)null)) { ((Transform)_root).SetAsLastSibling(); } } private static void RebuildOrder() { if ((Object)(object)_row == (Object)null) { return; } foreach (Slot item in _slots.Values.OrderBy((Slot x) => x.Order)) { if (item.Button != null && !((Object)(object)item.Button.GameObject == (Object)null)) { item.Button.GameObject.transform.SetParent((Transform)(object)_row, false); item.Button.GameObject.transform.SetAsLastSibling(); } } LayoutRebuilder.ForceRebuildLayoutImmediate(_row); } private static void ApplyVisibility() { if (!IsHostAlive()) { return; } bool flag = _slots.Values.Any((Slot s) => s.WantVisible); bool flag2 = _contextVisible && flag; if (((Component)_root).gameObject.activeSelf != flag2) { ((Component)_root).gameObject.SetActive(flag2); } if (flag2) { BringToFront(); } foreach (Slot value in _slots.Values) { if (value.Button != null) { value.Button.SetActive(_contextVisible && value.WantVisible); } } if (flag2) { LayoutRebuilder.ForceRebuildLayoutImmediate(_row); } } private static float EstimateWidth(string label) { if (string.IsNullOrEmpty(label)) { return 64f; } return 12f + (float)label.Length * 7.2f + 16f; } } public sealed class ConfigColor { private readonly Color _fallback; public ConfigEntry<string> Entry { get; } public Color Value { get; private set; } public string Hex => Entry.Value; public ConfigColor(ConfigEntry<string> entry, Color fallback) { //IL_001d: 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_0030: Unknown result type (might be due to invalid IL or missing references) Entry = entry ?? throw new ArgumentNullException("entry"); _fallback = fallback; Value = Parse(Entry.Value); Entry.SettingChanged += OnSettingChanged; } public static ConfigColor Bind(ConfigFile config, string section, string key, Color fallback, string description = null) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) string text = UIColors.ToHex(fallback); string text2 = description ?? ("Rich-text value color as hex (RRGGBB or #RRGGBB). Default: " + text + "."); return new ConfigColor(config.Bind<string>(section, key, text, text2), fallback); } public void Refresh() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) Value = Parse(Entry.Value); } private void OnSettingChanged(object sender, EventArgs e) { Refresh(); } private Color Parse(string hex) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) return UIColors.ParseHex(hex, _fallback); } public static implicit operator Color(ConfigColor c) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) return (Color)(((??)c?.Value) ?? default(Color)); } } public static class UIColors { public static readonly Color Sky = new Color(0.45f, 0.85f, 0.95f, 1f); public static readonly Color Rose = new Color(0.95f, 0.3f, 0.35f, 1f); public static readonly Color Shamrock = new Color(0.2f, 0.9f, 0.45f, 1f); public static readonly Color Macaroon = new Color(0.98f, 0.82f, 0.35f, 1f); public static readonly Color Orchid = new Color(0.85f, 0.4f, 0.9f, 1f); public static readonly Color Amber = new Color(1f, 0.75f, 0.15f, 1f); public static readonly Color Electric = new Color(0.3f, 0.65f, 1f, 1f); public static readonly Color TextPrimary = new Color(0.95f, 0.96f, 0.98f, 1f); public static readonly Color TextSecondary = new Color(0.7f, 0.74f, 0.8f, 1f); public static readonly Color TextMuted = new Color(0.5f, 0.54f, 0.6f, 1f); public static readonly Color PanelBg = new Color(0.08f, 0.1f, 0.14f, 0.94f); public static readonly Color Surface = new Color(0.12f, 0.15f, 0.2f, 0.96f); public static readonly Color TitleBar = new Color(0.1f, 0.18f, 0.24f, 1f); public static readonly Color SectionBar = new Color(0.12f, 0.22f, 0.3f, 1f); public static readonly Color EntryBg = new Color(0.14f, 0.17f, 0.22f, 0.9f); public static readonly Color ScrollBg = new Color(0.06f, 0.08f, 0.11f, 0.85f); public static readonly Color TooltipBg = new Color(0.06f, 0.08f, 0.12f, 0.96f); public static readonly Color Border = new Color(0.25f, 0.4f, 0.5f, 0.7f); public static readonly Color BorderAccent = new Color(0.3f, 0.7f, 0.85f, 0.9f); public static readonly Color Separator = new Color(0.3f, 0.4f, 0.5f, 0.4f); public static readonly Color ButtonNormal = new Color(0.16f, 0.22f, 0.3f, 1f); public static readonly Color ButtonHover = new Color(0.26f, 0.38f, 0.5f, 1f); public static readonly Color ButtonPressed = new Color(0.12f, 0.17f, 0.24f, 1f); public static readonly Color ButtonPrimary = new Color(0.14f, 0.42f, 0.62f, 1f); public static readonly Color ButtonPrimaryHover = new Color(0.22f, 0.55f, 0.8f, 1f); public static readonly Color ButtonPrimaryPressed = new Color(0.1f, 0.32f, 0.48f, 1f); public static readonly Color ButtonDanger = new Color(0.58f, 0.18f, 0.22f, 1f); public static readonly Color ButtonDangerHover = new Color(0.78f, 0.28f, 0.32f, 1f); public static readonly Color ButtonDangerPressed = new Color(0.42f, 0.12f, 0.15f, 1f); public static readonly Color ButtonActive = new Color(0.16f, 0.48f, 0.4f, 1f); public static readonly Color ButtonActiveHover = new Color(0.22f, 0.6f, 0.5f, 1f); public static readonly Color ButtonActivePressed = new Color(0.12f, 0.36f, 0.3f, 1f); public static readonly Color ToggleOff = new Color(0.25f, 0.28f, 0.32f, 1f); public static readonly Color ToggleOn = new Color(0.18f, 0.55f, 0.4f, 1f); public static readonly Color Checkmark = new Color(0.3f, 0.95f, 0.55f, 1f); public static readonly Color InputBg = new Color(0.1f, 0.13f, 0.18f, 0.95f); public static readonly Color InputText = new Color(0.92f, 0.94f, 0.96f, 1f); public static readonly Color SliderTrack = new Color(0.15f, 0.18f, 0.24f, 1f); public static readonly Color SliderFill = new Color(0.25f, 0.65f, 0.8f, 1f); public static readonly Color SliderHandle = new Color(0.9f, 0.93f, 0.96f, 1f); public static readonly Color ProgressTrack = new Color(0.12f, 0.15f, 0.2f, 1f); public static readonly Color ProgressFill = new Color(0.25f, 0.75f, 0.55f, 1f); public static readonly Color TabInactive = new Color(0.12f, 0.16f, 0.22f, 1f); public static readonly Color TabActive = new Color(0.18f, 0.3f, 0.4f, 1f); public static readonly Color TabHover = new Color(0.16f, 0.24f, 0.32f, 1f); public static readonly Color Success = Shamrock; public static readonly Color Warning = Amber; public static readonly Color Error = Rose; public static readonly Color Info = Sky; public static Color GameRed { get { //IL_0012: 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_001f: 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) try { if ((Object)(object)Global.Instance != (Object)null) { return Global.Instance.RedUIColor; } } catch { } return Rose; } } public static Color GameGreen { get { //IL_0012: 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_001f: 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) try { if ((Object)(object)Global.Instance != (Object)null) { return Global.Instance.GreenUIColor; } } catch { } return Shamrock; } } public static string ToHex(Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return ColorUtility.ToHtmlStringRGB(color); } public static Color WithAlpha(Color color, float alpha) { //IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) return new Color(color.r, color.g, color.b, alpha); } public static bool TryParseHex(string hex, out Color color) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) color = default(Color); if (string.IsNullOrWhiteSpace(hex)) { return false; } string text = hex.Trim(); if (text.StartsWith("#")) { text = text.Substring(1); } if (text.Length != 6 && text.Length != 8) { return false; } return ColorUtility.TryParseHtmlString("#" + text, ref color); } public static Color ParseHex(string hex, Color fallback) { //IL_000c: 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) if (!TryParseHex(hex, out var color)) { return fallback; } return color; } } public static class UITheme { public const float ReferenceWidth = 1920f; public const float ReferenceHeight = 1080f; public static float FontTitle = 24f; public static float FontHeader = 20f; public static float FontBody = 16f; public static float FontHud = 18f; public static float FontSmall = 13f; public static float FontTiny = 11f; public static float PaddingSmall = 6f; public static float PaddingMedium = 12f; public static float PaddingLarge = 20f; public static float SpacingTight = 4f; public static float SpacingNormal = 8f; public static float SpacingLoose = 14f; public static float ButtonHeight = 32f; public static float InputHeight = 30f; public static float ToggleSize = 22f; public static float SliderHeight = 20f; public static float ProgressHeight = 12f; public static float TitleBarHeight = 44f; public static float SeparatorHeight = 2f; public static float TabHeight = 34f; public static float BorderWidth = 1.5f; public static float CornerRadiusHint = 4f; public static float HudLineHeight = 22f; public static float HudDefaultWidth = 320f; public static int WindowSortingOrder = 100; public static int DialogSortingOrder = 200; public static int DropdownSortingOrder = 220; public static int TooltipSortingOrder = 250; public static float WindowMinWidth = 320f; public static float WindowMinHeight = 200f; private static bool _initialized; private static TMP_FontAsset _cachedFont; public static float Scale => Mathf.Clamp(((Screen.height > 0) ? ((float)Screen.height) : 1080f) / 1080f, 0.65f, 1.75f); public static float ScaleX => Mathf.Clamp(((Screen.width > 0) ? ((float)Screen.width) : 1920f) / 1920f, 0.65f, 1.75f); public static float ScaledFontTitle => S(FontTitle); public static float ScaledFontHeader => S(FontHeader); public static float ScaledFontBody => S(FontBody); public static float ScaledFontHud => S(FontHud); public static float ScaledFontSmall => S(FontSmall); public static float ScaledFontTiny => S(FontTiny); public static float ScaledButtonHeight => S(ButtonHeight); public static float ScaledInputHeight => S(InputHeight); public static float ScaledTitleBarHeight => S(TitleBarHeight); public static float ScaledHudLineHeight => S(HudLineHeight); public static TMP_FontAsset Font { get { if ((Object)(object)_cachedFont != (Object)null) { return _cachedFont; } TryCacheFont(); return _cachedFont; } } public static void Initialize() { if (!_initialized) { _initialized = true; TryCacheFont(); } } public static void ClearFontCache() { _cachedFont = null; } public static float S(float referencePixels) { return referencePixels * Scale; } public static Vector2 S(Vector2 reference) { //IL_0000: 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) return reference * Scale; } public static RectOffset ScaledPadding(int left, int right, int top, int bottom) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown float scale = Scale; return new RectOffset(Mathf.RoundToInt((float)left * scale), Mathf.RoundToInt((float)right * scale), Mathf.RoundToInt((float)top * scale), Mathf.RoundToInt((float)bottom * scale)); } private static void TryCacheFont() { TextMeshProUGUI val = Object.FindObjectOfType<TextMeshProUGUI>(); if ((Object)(object)val != (Object)null && (Object)(object)((TMP_Text)val).font != (Object)null) { _cachedFont = ((TMP_Text)val).font; return; } TMP_FontAsset val2 = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF"); if ((Object)(object)val2 != (Object)null) { _cachedFont = val2; } else if ((Object)(object)TMP_Settings.defaultFontAsset != (Object)null) { _cachedFont = TMP_Settings.defaultFontAsset; } } public static void ApplyTextStyle(TextMeshProUGUI tmp, float fontSize, Color? color = null, TextAlignmentOptions alignment = (TextAlignmentOptions)513, bool wrap = false) { //IL_003e: 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) if (!((Object)(object)tmp == (Object)null)) { if ((Object)(object)Font != (Object)null) { ((TMP_Text)tmp).font = Font; } ((TMP_Text)tmp).fontSize = fontSize; ((Graphic)tmp).color = (Color)(((??)color) ?? UIColors.TextPrimary); ((TMP_Text)tmp).alignment = alignment; ((TMP_Text)tmp).enableWordWrapping = wrap; ((TMP_Text)tmp).richText = true; ((TMP_Text)tmp).overflowMode = (TextOverflowModes)0; ((Graphic)tmp).raycastTarget = false; } } public static Vector2 ScaledSize(float width, float height) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Vector2(S(width), S(height)); } public static Vector2 ClampToScreen(Vector2 size, float maxWidthFraction = 0.92f, float maxHeightFraction = 0.9f) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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) float num = (float)Screen.width * maxWidthFraction; float num2 = (float)Screen.height * maxHeightFraction; return new Vector2(Mathf.Clamp(size.x, S(WindowMinWidth), num), Mathf.Clamp(size.y, S(WindowMinHeight), num2)); } } public enum UIButtonStyle { Default, Primary, Danger, Active } public class UIButton { private Color _hover; private bool _hovered; private Color _normal; private Color _pressed; private bool _pressedDown; public GameObject GameObject { get; } public RectTransform Rect { get; } public Button Button { get; } public Image Background { get; } public TextMeshProUGUI Label { get; } public UIButtonStyle Style { get; private set; } private UIButton(GameObject go, RectTransform rt, Button btn, Image bg, TextMeshProUGUI label) { GameObject = go; Rect = rt; Button = btn; Background = bg; Label = label; } public static UIButton Create(Transform parent, string text, Action onClick = null, UIButtonStyle style = UIButtonStyle.Default, string name = null, float? preferredHeight = null) { //IL_0024: 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_00a5: 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_00b5: 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_00cd: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Expected O, but got Unknown GetStyleColors(style, out var normal, out var hover, out var pressed); Image val = UIFactory.CreateImage(name ?? ("Button_" + text), parent, normal); UIFactory.ApplyWhiteSprite(val); RectTransform rectTransform = ((Graphic)val).rectTransform; float value = preferredHeight ?? UITheme.ScaledButtonHeight; GameObject gameObject = ((Component)val).gameObject; float? preferredHeight2 = value; float? minHeight = value; UIHelpers.EnsureLayoutElement(gameObject, null, preferredHeight2, minHeight); Button val2 = ((Component)val).gameObject.AddComponent<Button>(); ((Selectable)val2).targetGraphic = (Graphic)(object)val; ColorBlock colors = ((Selectable)val2).colors; ((ColorBlock)(ref colors)).normalColor = Color.white; ((ColorBlock)(ref colors)).highlightedColor = Color.white; ((ColorBlock)(ref colors)).pressedColor = Color.white; ((ColorBlock)(ref colors)).selectedColor = Color.white; ((ColorBlock)(ref colors)).disabledColor = new Color(1f, 1f, 1f, 0.4f); ((ColorBlock)(ref colors)).fadeDuration = 0f; ((Selectable)val2).colors = colors; ((Selectable)val2).transition = (Transition)1; TextMeshProUGUI val3 = UIFactory.CreateTmp("Label", (Transform)(object)rectTransform, text, UITheme.ScaledFontBody, UIColors.TextPrimary, (TextAlignmentOptions)514); UIHelpers.SetFillParent(((TMP_Text)val3).rectTransform, UITheme.S(4f)); ((Graphic)val3).raycastTarget = false; ((TMP_Text)val3).enableWordWrapping = false; ((TMP_Text)val3).overflowMode = (TextOverflowModes)1; UIButton result = new UIButton(((Component)val).gameObject, rectTransform, val2, val, val3) { _normal = normal, _hover = hover, _pressed = pressed, Style = style }; EventTrigger trigger = ((Component)val).gameObject.AddComponent<EventTrigger>(); AddTrigger(trigger, (EventTriggerType)0, delegate { result._hovered = true; result.ApplyVisualState(); }); AddTrigger(trigger, (EventTriggerType)1, delegate { result._hovered = false; result._pressedDown = false; result.ApplyVisualState(); }); AddTrigger(trigger, (EventTriggerType)2, delegate { result._pressedDown = true; result.ApplyVisualState(); }); AddTrigger(trigger, (EventTriggerType)3, delegate { result._pressedDown = false; result.ApplyVisualState(); }); if (onClick != null) { ((UnityEvent)val2.onClick).AddListener(new UnityAction(onClick.Invoke)); } return result; } public UIButton OnClick(Action action) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown if (action != null) { ((UnityEvent)Button.onClick).AddListener(new UnityAction(action.Invoke)); } return this; } public UIButton SetText(string text) { if ((Object)(object)Label != (Object)null) { ((TMP_Text)Label).text = text ?? string.Empty; } return this; } public UIButton SetInteractable(bool interactable) { if (((Selectable)Button).interactable == interactable) { return this; } ((Selectable)Button).interactable = interactable; if (!interactable) { _hovered = false; _pressedDown = false; } ApplyVisualState(); return this; } public UIButton SetStyle(UIButtonStyle style) { if (Style == style) { return this; } Style = style; GetStyleColors(style, out _normal, out _hover, out _pressed); ApplyVisualState(); return this; } public UIButton SetWidth(float width) { UIHelpers.EnsureLayoutElement(GameObject, width).minWidth = width; if ((Object)(object)Rect != (Object)null) { Rect.SetSizeWithCurrentAnchors((Axis)0, width); } return this; } public void SetActive(bool active) { GameObject.SetActive(active); } public void ApplyVisualState() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0081: 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) if (!((Object)(object)Background == (Object)null) && !((Object)(object)Button == (Object)null)) { if (!((Selectable)Button).interactable) { ((Graphic)Background).color = UIColors.WithAlpha(_normal, 0.45f); } else if (_pressedDown) { ((Graphic)Background).color = _pressed; } else if (_hovered) { ((Graphic)Background).color = _hover; } else { ((Graphic)Background).color = _normal; } } } private static void GetStyleColors(UIButtonStyle style, out Color normal, out Color hover, out Color pressed) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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) //IL_0032: 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_003e: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_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_0066: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_0082: 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_008d: 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_0098: Unknown result type (might be due to invalid IL or missing references) switch (style) { case UIButtonStyle.Primary: normal = UIColors.ButtonPrimary; hover = UIColors.ButtonPrimaryHover; pressed = UIColors.ButtonPrimaryPressed; break; case UIButtonStyle.Danger: normal = UIColors.ButtonDanger; hover = UIColors.ButtonDangerHover; pressed = UIColors.ButtonDangerPressed; break; case UIButtonStyle.Active: normal = UIColors.ButtonActive; hover = UIColors.ButtonActiveHover; pressed = UIColors.ButtonActivePressed; break; default: normal = UIColors.ButtonNormal; hover = UIColors.ButtonHover; pressed = UIColors.ButtonPressed; break; } } private static void AddTrigger(EventTrigger trigger, EventTriggerType type, UnityAction<BaseEventData> cb) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown Entry val = new Entry { eventID = type }; ((UnityEvent<BaseEventData>)(object)val.callback).AddListener(cb); trigger.triggers.Add(val); } } public class UIDragList { private class Row { public GameObject Go; public int Index; public UIText Label; public RectTransform Rt; } private readonly List<Row> _rows = new List<Row>(); private readonly float _rowHeight; private readonly float _spacing; private readonly float _padTop; private int _dragIndex = -1; private int _dragStartIndex = -1; private float _pointerOffsetY; private LayoutElement _dragLayout; private ScrollRect _scrollRect; private bool _scrollWasEnabled; private Action<int, int> _onReordered; public GameObject GameObject { get; } public RectTransform Rect { get; } public RectTransform Content { get; } private UIDragList(GameObject go, RectTransform rt, RectTransform content, ScrollRect scrollRect) { GameObject = go; Rect = rt; Content = content; _scrollRect = scrollRect; _rowHeight = UITheme.S(28f); _spacing = UITheme.S(UITheme.SpacingNormal); _padTop = UITheme.S(10f); } public static UIDragList Create(Transform parent, string name = "DragList") { UIScrollView uIScrollView = UIScrollView.Create(parent, name); VerticalLayoutGroup component = ((Component)uIScrollView.Content).GetComponent<VerticalLayoutGroup>(); if ((Object)(object)component != (Object)null) { ((HorizontalOrVerticalLayoutGroup)component).spacing = UITheme.S(UITheme.SpacingNormal); ((LayoutGroup)component).padding = UITheme.ScaledPadding(8, 8, 10, 10); } return new UIDragList(uIScrollView.GameObject, uIScrollView.Rect, uIScrollView.Content, uIScrollView.ScrollRect); } public UIDragList FillParent(float padding = 0f) { UIHelpers.SetFillParent(Rect, padding); return this; } public UIDragList OnReordered(Action<int, int> action) { _onReordered = action; return this; } public void SetItems(IList<string> labels) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) CancelDrag(); UIHelpers.DestroyChildren((Transform)(object)Content); _rows.Clear(); if (labels == null) { return; } for (int i = 0; i < labels.Count; i++) { GameObject gameObject = ((Component)UIFactory.CreateImage($"Row_{i}", (Transform)(object)Content, UIColors.EntryBg)).gameObject; UIFactory.ApplyWhiteSprite(gameObject.GetComponent<Image>()); float? preferredHeight = _rowHeight; float? minHeight = _rowHeight; UIHelpers.EnsureLayoutElement(gameObject, null, preferredHeight, minHeight); UIText uIText = UIText.Create(gameObject.transform, "Label", $"{i + 1}. {labels[i]}", UITheme.ScaledFontBody, UIColors.TextPrimary, (TextAlignmentOptions)513); UIHelpers.SetFillParent(uIText.Rect, UITheme.S(8f)); ((Graphic)uIText.Tmp).raycastTarget = false; Row row = new Row { Go = gameObject, Rt = gameObject.GetComponent<RectTransform>(), Label = uIText, Index = i }; _rows.Add(row); EventTrigger trigger = gameObject.AddComponent<EventTrigger>(); Add(trigger, (EventTriggerType)13, delegate(BaseEventData data) { BeginDrag(row, (PointerEventData)(object)((data is PointerEventData) ? data : null)); }); Add(trigger, (EventTriggerType)5, delegate(BaseEventData data) { OnDrag((PointerEventData)(object)((data is PointerEventData) ? data : null)); }); Add(trigger, (EventTriggerType)14, delegate { EndDrag(); }); } } public void SetLabels(IList<string> labels) { if (labels == null || labels.Count != _rows.Count) { SetItems(labels); return; } for (int i = 0; i < _rows.Count; i++) { _rows[i].Label.Text = $"{i + 1}. {labels[i]}"; } } private void BeginDrag(Row row, PointerEventData data) { //IL_0062: 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_0088: Unknown result type (might be due to invalid IL or missing references) _dragIndex = _rows.IndexOf(row); if (_dragIndex < 0 || _dragIndex >= _rows.Count || data == null) { _dragIndex = -1; return; } _dragStartIndex = _dragIndex; Row row2 = _rows[_dragIndex]; ((Graphic)row2.Go.GetComponent<Image>()).color = UIColors.ButtonHover; Vector2 val = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(row2.Rt, data.position, data.pressEventCamera, ref val)) { _pointerOffsetY = val.y; } else { _pointerOffsetY = 0f; } _dragLayout = row2.Go.GetComponent<LayoutElement>(); if ((Object)(object)_dragLayout != (Object)null) { _dragLayout.ignoreLayout = true; } if ((Object)(object)_scrollRect != (Object)null) { _scrollWasEnabled = ((Behaviour)_scrollRect).enabled; _scrollRect.StopMovement(); ((Behaviour)_scrollRect).enabled = false; } row2.Go.transform.SetAsLastSibling(); LayoutRebuilder.ForceRebuildLayoutImmediate(Content); PositionDraggedRow(data); } private void OnDrag(PointerEventData data) { if (_dragIndex < 0 || data == null || (Object)(object)Content == (Object)null) { return; } PositionDraggedRow(data); int num = IndexFromPointer(data); if (num < 0 || num == _dragIndex) { return; } Row row = _rows[_dragIndex]; _rows.RemoveAt(_dragIndex); _rows.Insert(num, row); _dragIndex = num; int num2 = 0; for (int i = 0; i < _rows.Count; i++) { if (i != _dragIndex) { _rows[i].Go.transform.SetSiblingIndex(num2++); } } row.Go.transform.SetAsLastSibling(); Renumber(); LayoutRebuilder.ForceRebuildLayoutImmediate(Content); PositionDraggedRow(data); } private void EndDrag() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) if (_dragIndex < 0 || _dragIndex >= _rows.Count) { CancelDrag(); return; } ((Graphic)_rows[_dragIndex].Go.GetComponent<Image>()).color = UIColors.EntryBg; if ((Object)(object)_dragLayout != (Object)null) { _dragLayout.ignoreLayout = false; _dragLayout = null; } for (int i = 0; i < _rows.Count; i++) { _rows[i].Go.transform.SetSiblingIndex(i); } if ((Object)(object)_scrollRect != (Object)null) { ((Behaviour)_scrollRect).enabled = _scrollWasEnabled; } LayoutRebuilder.ForceRebuildLayoutImmediate(Content); if (_dragStartIndex >= 0 && _dragStartIndex != _dragIndex) { _onReordered?.Invoke(_dragStartIndex, _dragIndex); } _dragIndex = -1; _dragStartIndex = -1; } private void CancelDrag() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (_dragIndex >= 0 && _dragIndex < _rows.Count) { ((Graphic)_rows[_dragIndex].Go.GetComponent<Image>()).color = UIColors.EntryBg; if ((Object)(object)_dragLayout != (Object)null) { _dragLayout.ignoreLayout = false; } } _dragLayout = null; if ((Object)(object)_scrollRect != (Object)null) { ((Behaviour)_scrollRect).enabled = _scrollWasEnabled; } _dragIndex = -1; _dragStartIndex = -1; } private void PositionDraggedRow(PointerEventData data) { //IL_003b: 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_0070: 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_009b: 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_00b8: Unknown result type (might be due to invalid IL or missing references) if (_dragIndex >= 0 && _dragIndex < _rows.Count) { RectTransform rt = _rows[_dragIndex].Rt; Vector2 val = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(Content, data.position, data.pressEventCamera, ref val)) { rt.anchorMin = new Vector2(0f, 1f); rt.anchorMax = new Vector2(1f, 1f); rt.pivot = new Vector2(0.5f, 0.5f); rt.sizeDelta = new Vector2(0f, _rowHeight); rt.anchoredPosition = new Vector2(0f, val.y - _pointerOffsetY); } } } private int IndexFromPointer(PointerEventData data) { //IL_0016: 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) if (_rows.Count == 0) { return -1; } Vector2 val = default(Vector2); if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(Content, data.position, data.pressEventCamera, ref val)) { return _dragIndex; } float num = 0f - val.y; float num2 = _rowHeight + _spacing; if (num2 < 1f) { num2 = ((_rowHeight > 0f) ? _rowHeight : 28f); } return Mathf.Clamp(Mathf.FloorToInt((num - _padTop) / num2 + 0.0001f), 0, _rows.Count - 1); } private void Renumber() { for (int i = 0; i < _rows.Count; i++) { _rows[i].Index = i; string text = _rows[i].Label.Text; int num = text.IndexOf('.'); string arg = ((num >= 0 && num + 1 < text.Length) ? text.Substring(num + 1).TrimStart() : text); _rows[i].Label.Text = $"{i + 1}. {arg}"; } } private static void Add(EventTrigger trigger, EventTriggerType type, UnityAction<BaseEventData> cb) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown Entry val = new Entry { eventID = type }; ((UnityEvent<BaseEventData>)(object)val.callback).AddListener(cb); trigger.triggers.Add(val); } } public class UIDropdown { private readonly RectTransform _listContent; private readonly GameObject _listRoot; private readonly RectTransform _mainBtnRt; private readonly List<string> _options = new List<string>(); private Vector2 _listHomeAnchoredPos; private Vector2 _listHomeAnchorMax; private Vector2 _listHomeAnchorMin; private bool _listHomeCaptured; private Transform _listHomeParent; private Vector2 _listHomePivot; private int _listHomeSiblingIndex; private Vector2 _listHomeSizeDelta; private Action<int, string> _onChanged; public GameObject GameObject { get; } public RectTransform Rect { get; } public TextMeshProUGUI Label { get; } public int SelectedIndex { get; private set; } public string SelectedValue { get { if (SelectedIndex < 0 || SelectedIndex >= _options.Count) { return null; } return _options[SelectedIndex]; } } public bool IsOpen { get; private set; } private UIDropdown(GameObject go, RectTransform rt, TextMeshProUGUI label, GameObject listRoot, RectTransform listContent, RectTransform mainBtnRt) { GameObject = go; Rect = rt; Label = label; _listRoot = listRoot; _listContent = listContent; _mainBtnRt = mainBtnRt; } public static UIDropdown Create(Transform parent, IList<string> options, int initialIndex = 0, Action<int, string> onChanged = null, string name = "Dropdown") { //IL_0045: 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_00af: 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_00ee: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Expected O, but got Unknown float scaledButtonHeight = UITheme.ScaledButtonHeight; RectTransform val = UIFactory.CreateRect(name, parent); GameObject gameObject = ((Component)val).gameObject; float? preferredHeight = scaledButtonHeight; float? minHeight = scaledButtonHeight; UIHelpers.EnsureLayoutElement(gameObject, null, preferredHeight, minHeight); Image val2 = UIFactory.CreateImage("Main", (Transform)(object)val, UIColors.ButtonNormal); UIFactory.ApplyWhiteSprite(val2); UIHelpers.SetFillParent(((Graphic)val2).rectTransform); TextMeshProUGUI val3 = UIFactory.CreateTmp("Label", (Transform)(object)((Graphic)val2).rectTransform, "", UITheme.ScaledFontBody, UIColors.TextPrimary, (TextAlignmentOptions)514); UIHelpers.SetFillParent(((TMP_Text)val3).rectTransform, UITheme.S(6f)); Image val4 = UIFactory.CreateImage("List", (Transform)(object)val, UIColors.Surface); UIFactory.ApplyWhiteSprite(val4); RectTransform rectTransform = ((Graphic)val4).rectTransform; rectTransform.anchorMin = new Vector2(0f, 0f); rectTransform.anchorMax = new Vector2(1f, 0f); rectTransform.pivot = new Vector2(0.5f, 1f); rectTransform.anchoredPosition = new Vector2(0f, -2f); UIFactory.AddVerticalLayout(((Component)val4).gameObject, UITheme.S(2f), UITheme.ScaledPadding(4, 4, 4, 4), (TextAnchor)0); ((Component)val4).gameObject.AddComponent<LayoutElement>().ignoreLayout = true; UIDropdown dropdown = new UIDropdown(((Component)val).gameObject, val, val3, ((Component)val4).gameObject, rectTransform, ((Graphic)val2).rectTransform) { _onChanged = onChanged }; if (options != null) { for (int i = 0; i < options.Count; i++) { dropdown._options.Add(options[i]); } } dropdown.RebuildOptions(); dropdown.Select(Mathf.Clamp(initialIndex, 0, Math.Max(0, dropdown._options.Count - 1)), notify: false); ((Component)val4).gameObject.SetActive(false); Button obj = ((Component)val2).gameObject.AddComponent<Button>(); ((Selectable)obj).targetGraphic = (Graphic)(object)val2; ((UnityEvent)obj.onClick).AddListener((UnityAction)delegate { dropdown.ToggleList(); }); return dropdown; } public void SetOptions(IList<string> options, int selectIndex = 0) { _options.Clear(); if (options != null) { for (int i = 0; i < options.Count; i++) { _options.Add(options[i]); } } RebuildOptions(); Select(Mathf.Clamp(selectIndex, 0, Math.Max(0, _options.Count - 1)), notify: false); } public void Select(int index, bool notify = true) { if (_options.Count == 0) { SelectedIndex = -1; ((TMP_Text)Label).text = string.Empty; return; } SelectedIndex = Mathf.Clamp(index, 0, _options.Count - 1); ((TMP_Text)Label).text = _options[SelectedIndex]; CloseList(); if (notify) { _onChanged?.Invoke(SelectedIndex, _options[SelectedIndex]); } } public UIDropdown OnChanged(Action<int, string> action) { _onChanged = action; return this; } public void ToggleList() { if (IsOpen) { CloseList(); } else { OpenList(); } } public void OpenList() { if (!IsOpen) { IsOpen = true; float height = UITheme.ScaledButtonHeight * 0.85f * (float)Mathf.Max(1, _options.Count) + UITheme.S(8f); float gap = UITheme.S(2f); CaptureListHomeIfNeeded(); EnsureListOverlayComponents(); RectTransform val = ResolvePopupHost(); if ((Object)(object)val != (Object)null && (Object)(object)((Transform)_listContent).parent != (Object)(object)val) { ((Transform)_listContent).SetParent((Transform)(object)val, false); } _listRoot.SetActive(true); ((Transform)_listContent).SetAsLastSibling(); PositionListBelowButton(height, gap); LayoutRebuilder.ForceRebuildLayoutImmediate(_listContent); } } public void CloseList() { if (!IsOpen && ((Object)(object)_listRoot == (Object)null || !_listRoot.activeSelf)) { IsOpen = false; return; } IsOpen = false; if ((Object)(object)_listRoot != (Object)null) { _listRoot.SetActive(false); } RestoreListHome(); } private void CaptureListHomeIfNeeded() { //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_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_0062: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_0089: Unknown result type (might be due to invalid IL or missing references) if (!_listHomeCaptured && !((Object)(object)_listContent == (Object)null)) { _listHomeParent = ((Transform)_listContent).parent; _listHomeSiblingIndex = ((Transform)_listContent).GetSiblingIndex(); _listHomeAnchorMin = _listContent.anchorMin; _listHomeAnchorMax = _listContent.anchorMax; _listHomePivot = _listContent.pivot; _listHomeAnchoredPos = _listContent.anchoredPosition; _listHomeSizeDelta = _listContent.sizeDelta; _listHomeCaptured = true; } } private void RestoreListHome() { //IL_007d: 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_009f: 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_00c1: Unknown result type (might be due to invalid IL or missing references) if (_listHomeCaptured && !((Object)(object)_listContent == (Object)null) && !((Object)(object)_listHomeParent == (Object)null)) { if ((Object)(object)((Transform)_listContent).parent != (Object)(object)_listHomeParent) { ((Transform)_listContent).SetParent(_listHomeParent, false); } int siblingIndex = Mathf.Clamp(_listHomeSiblingIndex, 0, _listHomeParent.childCount - 1); ((Transform)_listContent).SetSiblingIndex(siblingIndex); _listContent.anchorMin = _listHomeAnchorMin; _listContent.anchorMax = _listHomeAnchorMax; _listContent.pivot = _listHomePivot; _listContent.anchoredPosition = _listHomeAnchoredPos; _listContent.sizeDelta = _listHomeSizeDelta; } } private void EnsureListOverlayComponents() { if (!((Object)(object)_listRoot == (Object)null)) { Canvas val = _listRoot.GetComponent<Canvas>(); if ((Object)(object)val == (Object)null) { val = _listRoot.AddComponent<Canvas>(); } val.overrideSorting = true; val.sortingOrder = UITheme.DropdownSortingOrder; if ((Object)(object)_listRoot.GetComponent<GraphicRaycaster>() == (Object)null) { _listRoot.AddComponent<GraphicRaycaster>(); } LayoutElement val2 = _listRoot.GetComponent<LayoutElement>(); if ((Object)(object)val2 == (Object)null) { val2 = _listRoot.AddComponent<LayoutElement>(); } val2.ignoreLayout = true; } } private RectTransform ResolvePopupHost() { if ((Object)(object)Rect == (Object)null) { return null; } Canvas componentInParent = ((Component)Rect).GetComponentInParent<Canvas>(); if ((Object)(object)componentInParent == (Object)null) { return null; } Transform transform = ((Component)(((Object)(object)componentInParent.rootCanvas != (Object)null) ? componentInParent.rootCanvas : componentInParent)).transform; return (RectTransform)(object)((transform is RectTransform) ? transform : null); } private void PositionListBelowButton(float height, float gap) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_005a: 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_0062: 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_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_0097: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_00c3: 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_00da: 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_0112: Unknown result type (might be due to invalid IL or missing references) //IL_012c: 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_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0177: 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) if ((Object)(object)_listContent == (Object)null || (Object)(object)_mainBtnRt == (Object)null) { return; } Transform parent = ((Transform)_listContent).parent; RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null); if (!((Object)(object)val == (Object)null)) { Vector3[] array = (Vector3[])(object)new Vector3[4]; _mainBtnRt.GetWorldCorners(array); Vector3 world = array[0]; Vector3 world2 = array[3]; Vector3 world3 = array[1]; Camera eventCam = null; Canvas componentInParent = ((Component)val).GetComponentInParent<Canvas>(); if ((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) { eventCam = componentInParent.worldCamera; } Vector2 val2 = WorldToLocal(val, world, eventCam); Vector2 val3 = WorldToLocal(val, world2, eventCam); Vector2 val4 = WorldToLocal(val, world3, eventCam); float num = Mathf.Abs(val3.x - val2.x); float num2 = (val2.x + val3.x) * 0.5f; float num3 = val2.y - gap; float hostLocalBottom = GetHostLocalBottom(val); if (num3 - height < hostLocalBottom) { num3 = val4.y + gap + height; } _listContent.anchorMin = new Vector2(0.5f, 0.5f); _listContent.anchorMax = new Vector2(0.5f, 0.5f); _listContent.pivot = new Vector2(0.5f, 1f); _listContent.sizeDelta = new Vector2(Mathf.Max(1f, num), height); _listContent.anchoredPosition = new Vector2(num2, num3); } } private static Vector2 WorldToLocal(RectTransform host, Vector3 world, Camera eventCam) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_0013: Unknown result type (might be due to invalid IL or missing references) Vector2 val = RectTransformUtility.WorldToScreenPoint(eventCam, world); Vector2 result = default(Vector2); RectTransformUtility.ScreenPointToLocalPointInRectangle(host, val, eventCam, ref result); return result; } private static float GetHostLocalBottom(RectTransform host) { //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) Rect rect = host.rect; return ((Rect)(ref rect)).yMin; } private void RebuildOptions() { if (IsOpen) { CloseList(); } UIHelpers.DestroyChildren((Transform)(object)_listContent); float value = UITheme.ScaledButtonHeight * 0.85f; for (int i = 0; i < _options.Count; i++) { int index = i; string text = _options[i]; UIButton.Create((Transform)(object)_listContent, text, delegate { Select(index); }, UIButtonStyle.Default, null, value); } } public void SetActive(bool active) { GameObject.SetActive(active); } } public class UIInputField { public GameObject GameObject { get; } public RectTransform Rect { get; } public TMP_InputField Input { get; } public TextMeshProUGUI TextComponent { get; } public TextMeshProUGUI Placeholder { get; } public string Text { get { return Input.text; } set { Input.text = value ?? string.Empty; } } private UIInputField(GameObject go, RectTransform rt, TMP_InputField input, TextMeshProUGUI text, TextMeshProUGUI placeholder) { GameObject = go; Rect = rt; Input = input; TextComponent = text; Placeholder = placeholder; } public static UIInputField Create(Transform parent, string initial = "", string placeholder = "", Action<string> onChanged = null, string name = "InputField") { //IL_0009: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0174: 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) float scaledInputHeight = UITheme.ScaledInputHeight; Image val = UIFactory.CreateImage(name, parent, UIColors.InputBg); UIFactory.ApplyWhiteSprite(val); GameObject gameObject = ((Component)val).gameObject; float? preferredHeight = scaledInputHeight; float? minHeight = scaledInputHeight; UIHelpers.EnsureLayoutElement(gameObject, null, preferredHeight, minHeight); RectTransform val2 = UIFactory.CreateRect("TextArea", (Transform)(object)((Graphic)val).rectTransform); UIHelpers.SetFillParent(val2, UITheme.S(8f)); ((Component)val2).gameObject.AddComponent<RectMask2D>(); TextMeshProUGUI val3 = UIFactory.CreateTmp("Placeholder", (Transform)(object)val2, placeholder, UITheme.ScaledFontBody, UIColors.TextMuted, (TextAlignmentOptions)513); UIHelpers.SetFillParent(((TMP_Text)val3).rectTransform); ((TMP_Text)val3).fontStyle = (FontStyles)2; TextMeshProUGUI val4 = UIFactory.CreateTmp("Text", (Transform)(object)val2, initial, UITheme.ScaledFontBody, UIColors.InputText, (TextAlignmentOptions)513); UIHelpers.SetFillParent(((TMP_Text)val4).rectTransform); ((Graphic)val4).raycastTarget = true; TMP_InputField val5 = ((Component)val).gameObject.AddComponent<TMP_InputField>(); val5.textViewport = val2; val5.textComponent = (TMP_Text)(object)val4; val5.placeholder = (Graphic)(object)val3; val5.fontAsset = UITheme.Font; val5.pointSize = UITheme.ScaledFontBody; val5.text = initial ?? string.Empty; val5.customCaretColor = true; val5.caretColor = UIColors.Sky; val5.caretWidth = Mathf.Max(2, Mathf.RoundToInt(UITheme.S(2f))); val5.caretBlinkRate = 0.85f; val5.selectionColor = UIColors.WithAlpha(UIColors.Electric, 0.35f); ((Selectable)val5).targetGraphic = (Graphic)(object)val; val5.shouldHideMobileInput = true; ((Behaviour)val5).enabled = false; ((Behaviour)val5).enabled = true; if (onChanged != null) { ((UnityEvent<string>)(object)val5.onValueChanged).AddListener((UnityAction<string>)onChanged.Invoke); } return new UIInputField(((Component)val).gameObject, ((Graphic)val).rectTransform, val5, val4, val3); } public UIInputField OnChanged(Action<string> action) { if (action != null) { ((UnityEvent<string>)(object)Input.onValueChanged).AddListener((UnityAction<string>)action.Invoke); } return this; } public UIInputField OnEndEdit(Action<string> action) { if (action != null) { ((UnityEvent<string>)(object)Input.onEndEdit).AddListener((UnityAction<string>)action.Invoke); } return this; } public UIInputField SetInteractable(bool interactable) { ((Selectable)Input).interactable = interactable; return this; } public void SetActive(bool active) { GameObject.SetActive(active); } } public class UIPanel { public GameObject GameObject { get; } public RectTransform Rect { get; } public Image Background { get; } public Image Border { get; private set; } public Transform Content { get { if (!((Object)(object)Background != (Object)null)) { return GameObject.transform; } return ((Component)Background).transform; } } private UIPanel(GameObject go, RectTransform rt, Image bg) { GameObject = go; Rect = rt; Background = bg; } public static UIPanel Create(Transform parent, string name = "Panel", Color? background = null, bool withBorder = true) { //IL_0005: 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) //I