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.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("SparrohUILib")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("SparrohUILib")] [assembly: AssemblyTitle("SparrohUILib")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [BepInPlugin("sparroh.uilibrary", "SparrohUILib", "1.1.1")] [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.1.1"; internal static ManualLogSource Logger; private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; UITheme.Initialize(); Logger.LogInfo((object)"SparrohUILib v1.1.1 loaded."); } } 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 "" + text + ""; } public static string Colorize(string text, string hexWithoutHash) { return "" + text + ""; } public static string Bold(string text) { return "" + text + ""; } public static string Italic(string text) { return "" + text + ""; } public static string Size(string text, int percent) { return $"{text}"; } 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(); } 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(); ((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(); 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(); val.renderMode = (RenderMode)0; val.sortingOrder = sortingOrder; CanvasScaler obj2 = obj.AddComponent(); obj2.uiScaleMode = (ScaleMode)1; obj2.referenceResolution = new Vector2(1920f, 1080f); obj2.screenMatchMode = (ScreenMatchMode)0; obj2.matchWidthOrHeight = 0.5f; obj2.referencePixelsPerUnit = 100f; obj.AddComponent(); 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(); if ((Object)(object)val == (Object)null) { val = go.AddComponent(); } ((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(); if ((Object)(object)val == (Object)null) { val = go.AddComponent(); } ((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(); if ((Object)(object)val == (Object)null) { val = go.AddComponent(); } 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(); if ((Object)(object)val == (Object)null) { val = go.AddComponent(); } ((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(); if ((Object)(object)val == (Object)null) { val = go.AddComponent(); } 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 static class GearActionBar { private class Slot { public string Id; public int Order; public UIButton Button; public bool WantVisible = true; public string Label = string.Empty; public UIButtonStyle Style; public bool Interactable = true; public Action OnClick; } 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 static Canvas _canvas; private static RectTransform _row; private static readonly Dictionary _slots = new Dictionary(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) { if (string.IsNullOrEmpty(id)) { return; } EnsureBuilt(); 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(UITheme.S(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 { float value2 = UITheme.S(24f); UIButton uIButton = UIButton.Create((Transform)(object)_row, label, onClick, style, null, value2); if ((Object)(object)uIButton.Label != (Object)null) { ((TMP_Text)uIButton.Label).fontSize = UITheme.S(12f); } uIButton.SetWidth(Mathf.Max(UITheme.S(64f), EstimateWidth(label))); _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(UITheme.S(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) { return; } _contextVisible = visible; if (!_built) { 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() { 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 void EnsureBuilt() { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //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_0095: 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) if (!_built || !((Object)(object)_canvas != (Object)null)) { UITheme.Initialize(); _canvas = UIFactory.CreateOverlayCanvas("Sparroh_GearActionBar", UITheme.WindowSortingOrder + 8); RectTransform obj = UIFactory.CreateRect("Bar", ((Component)_canvas).transform); obj.anchorMin = new Vector2(0f, 1f); obj.anchorMax = new Vector2(1f, 1f); obj.pivot = new Vector2(0.5f, 1f); float num = UITheme.S(36f); obj.sizeDelta = new Vector2(0f, num); obj.anchoredPosition = new Vector2(0f, 0f - UITheme.S(6f)); Image obj2 = ((Component)obj).gameObject.AddComponent(); ((Graphic)obj2).color = UIColors.WithAlpha(UIColors.PanelBg, 0.55f); UIFactory.ApplyWhiteSprite(obj2); ((Graphic)obj2).raycastTarget = false; UIFactory.AddHorizontalLayout(((Component)obj).gameObject, UITheme.S(4f), UITheme.ScaledPadding(8, 8, 4, 4), (TextAnchor)3, controlChildWidth: false, expandWidth: false, controlChildHeight: true, expandHeight: false); _row = obj; _built = true; ((Component)_canvas).gameObject.SetActive(false); } } 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) { item.Button.GameObject.transform.SetParent((Transform)(object)_row, false); item.Button.GameObject.transform.SetAsLastSibling(); } } } private static void ApplyVisibility() { if ((Object)(object)_canvas == (Object)null) { return; } bool flag = _slots.Values.Any((Slot s) => s.WantVisible); bool flag2 = _contextVisible && flag; if (((Component)_canvas).gameObject.activeSelf != flag2) { ((Component)_canvas).gameObject.SetActive(flag2); } foreach (Slot value in _slots.Values) { if (value.Button != null) { value.Button.SetActive(_contextVisible && value.WantVisible); } } } private static float EstimateWidth(string label) { if (string.IsNullOrEmpty(label)) { return UITheme.S(64f); } return UITheme.S(12f + (float)label.Length * 7.2f + 16f); } } public class HudBuilder { private struct LineSpec { public string Name; public float FontSize; public TextAlignmentOptions Alignment; } private readonly string _name; private Transform _parent; private float _anchorX = 0.5f; private float _anchorY = 0.5f; private Vector2 _pivot = new Vector2(0f, 1f); private Vector2 _size; private Vector2 _anchoredPosition = Vector2.zero; private bool _parentToReticle = true; private readonly List _lines = new List(); private bool _withBackground; private Color _backgroundColor = UIColors.WithAlpha(UIColors.PanelBg, 0.55f); private HudBuilder(string name) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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 { public GameObject GameObject { get; } public RectTransform Rect { get; } public UIText[] Lines { get; } public UIText Primary { get { if (Lines == null || Lines.Length == 0) { return null; } return Lines[0]; } } public bool IsActive { get { if ((Object)(object)GameObject != (Object)null) { 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; } } internal HudHandle(GameObject go, RectTransform rt, UIText[] lines) { GameObject = go; Rect = rt; Lines = lines; } public void SetAnchor(float x, float y) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Rect == (Object)null)) { UIHelpers.SetPointAnchor(Rect, x, y, Rect.pivot); } } public void SetActive(bool active) { if ((Object)(object)GameObject != (Object)null) { GameObject.SetActive(active); } } public void Destroy() { UIHelpers.DestroySafe((Object)(object)GameObject); } } public sealed class ConfigColor { private readonly ConfigEntry _entry; private readonly Color _fallback; private Color _cached; public ConfigEntry Entry => _entry; public Color Value => _cached; public string Hex => _entry.Value; public ConfigColor(ConfigEntry 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) //IL_0035: Unknown result type (might be due to invalid IL or missing references) _entry = entry ?? throw new ArgumentNullException("entry"); _fallback = fallback; _cached = 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(section, key, text, text2), fallback); } public void Refresh() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) _cached = 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 TooltipSortingOrder = 250; public static int DialogSortingOrder = 200; 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 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(); 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("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 _normal; private Color _hover; private Color _pressed; private bool _hovered; private bool _pressedDown; private UIButtonStyle _style; public GameObject GameObject { get; } public RectTransform Rect { get; } public Button Button { get; } public Image Background { get; } public TextMeshProUGUI Label { get; } public UIButtonStyle Style => _style; 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_016c: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0173: 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_017a: 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_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: 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