Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SignStyler v1.0.0
plugins/SignStyler.dll
Decompiled a day 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.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; 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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("SignStyler")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+2eb73473d4200c53dcb2f4519ff244c8116b80d0")] [assembly: AssemblyProduct("SignStyler")] [assembly: AssemblyTitle("SignStyler")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SignStyler { internal sealed class ColorPicker { private const int TexSize = 64; private const float ContentWidth = 244f; private const float Gap = 4f; private const float SwatchCell = 26f; private const float SwatchGap = 5f; private const int SwatchColumns = 8; private const float SquareHeight = 120f; private const float HueWidth = 18f; private readonly GameObject _root; private readonly Texture2D _svTexture; private readonly Texture2D _hueTexture; private readonly RectTransform _svRect; private readonly RectTransform _svCursor; private readonly RectTransform _hueCursor; private readonly Image _preview; private readonly TMP_InputField _hexField; private readonly Button _tabText; private readonly Button _tabBackground; private readonly Button _primary; private readonly Button _insert; private readonly Slider _alphaSlider; private readonly TMP_Text _alphaValue; private readonly TMP_Text _hint; private readonly RectTransform _paletteGrid; private readonly RectTransform _recentGrid; private readonly Action<Color, bool> _onApply; private readonly Action<Color, bool> _onInsert; private readonly Func<bool> _hasSelection; private float _h = 0.12f; private float _s = 0.75f; private float _v = 1f; private float _a = 1f; private bool _background; private bool _syncing; private float _paintedHue = -1f; private readonly Color32[] _svBuffer = (Color32[])(object)new Color32[4096]; public GameObject Root => _root; public bool Visible => _root.activeSelf; public bool Background => _background; public Color Current { 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_0025: Unknown result type (might be due to invalid IL or missing references) Color result = Color.HSVToRGB(_h, _s, _v); result.a = _a; return result; } } public void Dispose() { if ((Object)(object)_svTexture != (Object)null) { Object.Destroy((Object)(object)_svTexture); } if ((Object)(object)_hueTexture != (Object)null) { Object.Destroy((Object)(object)_hueTexture); } if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } } public ColorPicker(Transform parent, Action<Color, bool> onApply, Action<Color, bool> onInsert, Func<bool> hasSelection) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_010e: Expected O, but got Unknown //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: 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_0172: Expected O, but got Unknown //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Expected O, but got Unknown //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_047b: Unknown result type (might be due to invalid IL or missing references) //IL_04d4: Unknown result type (might be due to invalid IL or missing references) //IL_054f: Unknown result type (might be due to invalid IL or missing references) //IL_0626: Unknown result type (might be due to invalid IL or missing references) _onApply = onApply; _onInsert = onInsert; _hasSelection = hasSelection; _root = new GameObject("SS_ColorPicker", new Type[1] { typeof(RectTransform) }); _root.transform.SetParent(parent, false); RectTransform val = (RectTransform)_root.transform; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(0f, 1f); ((Graphic)_root.AddComponent<Image>()).color = UiFactory.PanelBackground; VerticalLayoutGroup obj = _root.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)obj).padding = new RectOffset(10, 10, 8, 8); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 5f; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false; ((LayoutGroup)obj).childAlignment = (TextAnchor)1; ContentSizeFitter obj2 = _root.AddComponent<ContentSizeFitter>(); obj2.horizontalFit = (FitMode)2; obj2.verticalFit = (FitMode)2; _svTexture = new Texture2D(64, 64, (TextureFormat)3, false) { filterMode = (FilterMode)1, wrapMode = (TextureWrapMode)1 }; _hueTexture = BuildHueTexture(); RectTransform parent2 = UiFactory.Row(_root.transform, "Header", 26f, (TextAnchor)4); _preview = UiFactory.Swatch((Transform)(object)parent2, Color.white, 26f, 22f); UiFactory.Label((Transform)(object)parent2, "Palette", 144f, (TextAlignmentOptions)513, UiFactory.Gold); UiFactory.Button((Transform)(object)parent2, "Close", delegate { SetVisible(visible: false); }, 62f); RectTransform parent3 = UiFactory.Row(_root.transform, "Target", 26f, (TextAnchor)4); _tabText = UiFactory.Button((Transform)(object)parent3, "Text", delegate { SetTarget(background: false); }, 120f); _tabBackground = UiFactory.Button((Transform)(object)parent3, "Background", delegate { SetTarget(background: true); }, 120f); RectTransform parent4 = UiFactory.Row(_root.transform, "Wheel", 120f, (TextAnchor)4); RawImage val3 = UiFactory.Raw((Transform)(object)parent4, _svTexture, 222f, 120f); _svRect = (RectTransform)((Component)val3).transform; AddPointer(((Component)val3).gameObject, delegate(Vector2 n) { //IL_0001: 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) _s = Mathf.Clamp01(n.x); _v = Mathf.Clamp01(n.y); Sync(); }); _svCursor = Cursor(((Component)val3).transform, 11f, 11f, 2); RawImage val4 = UiFactory.Raw((Transform)(object)parent4, _hueTexture, 18f, 120f); AddPointer(((Component)val4).gameObject, delegate(Vector2 n) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) _h = Mathf.Clamp01(n.y); Sync(); }); _hueCursor = Cursor(((Component)val4).transform, 24f, 6f, 2); RectTransform parent5 = UiFactory.Row(_root.transform, "Hex", 26f, (TextAnchor)4); _hexField = UiFactory.Field((Transform)(object)parent5, "#FFFFFF", 9, OnHexCommitted, 120f); if ((Object)(object)_hexField == (Object)null) { UiFactory.Label((Transform)(object)parent5, "hex unavailable", 120f, (TextAlignmentOptions)513); } UiFactory.Button((Transform)(object)parent5, "Copy", CopyHex, 58f); UiFactory.Button((Transform)(object)parent5, "Paste", PasteHex, 58f); RectTransform parent6 = UiFactory.Row(_root.transform, "Alpha", 26f, (TextAnchor)4); UiFactory.Label((Transform)(object)parent6, "alpha", 44f, (TextAlignmentOptions)513, UiFactory.Muted); _alphaSlider = UiFactory.Slider((Transform)(object)parent6, 0f, 1f, 1f, delegate(float v) { _a = v; Sync(); }, 150f); _alphaValue = UiFactory.Label((Transform)(object)parent6, "100%", 38f, (TextAlignmentOptions)516, UiFactory.Gold); UiFactory.Separator(_root.transform, 244f); RectTransform parent7 = UiFactory.Row(_root.transform, "PaletteHeader", 20f, (TextAnchor)4); UiFactory.Label((Transform)(object)parent7, "PALETTE", 150f, (TextAlignmentOptions)513, UiFactory.Muted, 11f); UiFactory.Button((Transform)(object)parent7, "+ save", SavePreset, 90f); _paletteGrid = UiFactory.Grid(_root.transform, "PaletteGrid", 8, 26f, 5f); UiFactory.Label(_root.transform, "RECENT", 244f, (TextAlignmentOptions)513, UiFactory.Muted, 11f); _recentGrid = UiFactory.Grid(_root.transform, "RecentGrid", 8, 26f, 5f); UiFactory.Separator(_root.transform, 244f); _primary = UiFactory.Button(_root.transform, "Color selection", ApplyPrimary, 244f); _insert = UiFactory.Button(_root.transform, "Insert empty tag at caret", InsertAtCaret, 244f); _hint = UiFactory.Label(_root.transform, string.Empty, 244f, (TextAlignmentOptions)514, UiFactory.Muted, 11f); RefreshSwatches(); SetTarget(background: false); Sync(); _root.SetActive(false); } public void SetVisible(bool visible) { _root.SetActive(visible); if (visible) { RefreshActions(); } } public void Open(bool background, Color current) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) SetTarget(background); SetColor(current); SetVisible(visible: true); } public void Toggle(bool background, Color current) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (Visible && _background == background) { SetVisible(visible: false); } else { Open(background, current); } } private void SetTarget(bool background) { _background = background; UiFactory.SetButtonState(_tabText, "Text", !background); UiFactory.SetButtonState(_tabBackground, "Background", background); RefreshActions(); SetHint(background ? "A highlight shows on the board only, never on the hover label." : "Right-click a palette swatch to remove it."); } public void RefreshLayout() { Sync(); } public void SetColor(Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) Color.RGBToHSV(color, ref _h, ref _s, ref _v); _a = color.a; Slider alphaSlider = _alphaSlider; if (alphaSlider != null) { alphaSlider.SetValueWithoutNotify(_a); } Sync(); } public void SetHint(string message) { if ((Object)(object)_hint != (Object)null) { _hint.text = message ?? string.Empty; } } private void ApplyPrimary() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) _onApply?.Invoke(Current, _background); } private void InsertAtCaret() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) _onInsert?.Invoke(Current, _background); } private void RefreshActions() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) bool flag = _hasSelection != null && _hasSelection(); string text = (_background ? "Highlight " : "Color "); UiFactory.SetButtonDimmed(_primary, text + (flag ? "selection" : "word at caret"), dimmed: false); UiFactory.SetLabel(((Component)_insert).gameObject, "Insert empty tag at caret", UiFactory.Parchment); } private void CopyHex() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) string text = (GUIUtility.systemCopyBuffer = ToTag(Current)); SetHint(text + " copied to the clipboard."); } private void PasteHex() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) string text = (GUIUtility.systemCopyBuffer ?? string.Empty).Trim(); if (text.Length != 0) { if (!text.StartsWith("#")) { text = "#" + text; } Color color = default(Color); if (!ColorUtility.TryParseHtmlString(text, ref color)) { SetHint("Clipboard does not hold a hex colour."); return; } SetColor(color); SetHint(text.ToUpperInvariant() + " pasted."); } } private void SavePreset() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) string text = "#" + ColorUtility.ToHtmlStringRGB(Current); if (Settings.PaletteColors.Contains(text)) { SetHint(text + " is already in the palette."); return; } Settings.PaletteColors.Insert(0, text); if (Settings.PaletteColors.Count > 24) { Settings.PaletteColors.RemoveRange(24, Settings.PaletteColors.Count - 24); } RefreshSwatches(); SetHint(text + " saved to the palette."); } private void RemovePreset(string hex) { Settings.PaletteColors.RemoveAll((string entry) => string.Equals(entry, hex, StringComparison.OrdinalIgnoreCase)); RefreshSwatches(); SetHint(hex + " removed from the palette."); } public void RefreshSwatches() { Fill(_paletteGrid, Settings.PaletteColors.ToArray(), removable: true); Fill(_recentGrid, Settings.RecentColors.ToArray(), removable: false); RefreshSelectedSwatch(); } private void Fill(RectTransform grid, string[] entries, bool removable) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)grid == (Object)null) { return; } UiFactory.Clear((Transform)(object)grid); Color color = default(Color); foreach (string text in entries) { string text2 = (text.StartsWith("#") ? text : ("#" + text)); if (ColorUtility.TryParseHtmlString(text2, ref color)) { string captured = text2; UiFactory.SwatchButton((Transform)(object)grid, color, 26f, delegate { //IL_0007: Unknown result type (might be due to invalid IL or missing references) SetColor(color); SetHint(captured + " loaded."); }, removable ? ((Action)delegate { RemovePreset(captured); }) : null); } } } private void RefreshSelectedSwatch() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) string current = "#" + ColorUtility.ToHtmlStringRGB(Current); Mark(_paletteGrid, Settings.PaletteColors.ToArray(), current); Mark(_recentGrid, Settings.RecentColors.ToArray(), current); } private static void Mark(RectTransform grid, string[] entries, string current) { //IL_0053: 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_0060: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)grid == (Object)null) { return; } int num = 0; Color fill = default(Color); foreach (string text in entries) { string text2 = (text.StartsWith("#") ? text : ("#" + text)); if (ColorUtility.TryParseHtmlString(text2, ref fill)) { if (num >= ((Transform)grid).childCount) { break; } UiFactory.SetSwatch(((Component)((Transform)grid).GetChild(num)).GetComponent<Button>(), fill, string.Equals(text2, current, StringComparison.OrdinalIgnoreCase) ? UiFactory.Gold : UiFactory.SwatchBorder); num++; } } } private void OnHexCommitted(string raw) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) string text = (raw ?? string.Empty).Trim(); if (text.Length == 0) { return; } if (!text.StartsWith("#")) { text = "#" + text; } Color val = default(Color); if (!ColorUtility.TryParseHtmlString(text, ref val)) { Sync(); SetHint("Not a hex colour: " + text); return; } Color.RGBToHSV(val, ref _h, ref _s, ref _v); if (text.Length == 9) { _a = val.a; Slider alphaSlider = _alphaSlider; if (alphaSlider != null) { alphaSlider.SetValueWithoutNotify(_a); } } Sync(); } private void Sync() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_0141: 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_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) if (_syncing) { return; } _syncing = true; try { PaintSvTexture(); Color val = Color.HSVToRGB(_h, _s, _v); ((Graphic)_preview).color = new Color(val.r, val.g, val.b, 1f); if ((Object)(object)_hexField != (Object)null) { _hexField.SetTextWithoutNotify("#" + ColorUtility.ToHtmlStringRGB(val)); } if ((Object)(object)_alphaValue != (Object)null) { _alphaValue.text = Mathf.RoundToInt(_a * 100f) + "%"; } if ((Object)(object)_svCursor != (Object)null) { Rect rect = _svRect.rect; _svCursor.anchoredPosition = new Vector2(Mathf.Lerp(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).xMax, _s), Mathf.Lerp(((Rect)(ref rect)).yMin, ((Rect)(ref rect)).yMax, _v)); } if ((Object)(object)_hueCursor != (Object)null) { RectTransform val2 = (RectTransform)((Transform)_hueCursor).parent; RectTransform hueCursor = _hueCursor; Rect rect2 = val2.rect; float yMin = ((Rect)(ref rect2)).yMin; rect2 = val2.rect; hueCursor.anchoredPosition = new Vector2(0f, Mathf.Lerp(yMin, ((Rect)(ref rect2)).yMax, _h)); } RefreshSelectedSwatch(); } finally { _syncing = false; } } private void PaintSvTexture() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) if (Mathf.Approximately(_paintedHue, _h)) { return; } _paintedHue = _h; Color32[] svBuffer = _svBuffer; for (int i = 0; i < 64; i++) { float num = (float)i / 63f; for (int j = 0; j < 64; j++) { float num2 = (float)j / 63f; svBuffer[i * 64 + j] = Color32.op_Implicit(Color.HSVToRGB(_h, num2, num)); } } _svTexture.SetPixels32(svBuffer); _svTexture.Apply(false); } private static Texture2D BuildHueTexture() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //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_0043: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(1, 64, (TextureFormat)3, false) { filterMode = (FilterMode)1, wrapMode = (TextureWrapMode)1 }; Color32[] array = (Color32[])(object)new Color32[64]; for (int i = 0; i < 64; i++) { array[i] = Color32.op_Implicit(Color.HSVToRGB((float)i / 63f, 1f, 1f)); } val.SetPixels32(array); val.Apply(false); return val; } private static RectTransform Cursor(Transform parent, float width, float height, int radius) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_006a: Expected O, but got Unknown GameObject val = new GameObject("Cursor", new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(parent, false); Image component = val.GetComponent<Image>(); UiFactory.Rounded(component, new Color(1f, 1f, 1f, 0.95f), radius); ((Graphic)component).raycastTarget = false; return Center(val, width, height); } private static RectTransform Center(GameObject go, float width, float height) { //IL_0006: 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_000c: 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_0024: 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_0035: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown RectTransform val = (RectTransform)go.transform; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(0.5f, 0.5f); val.sizeDelta = new Vector2(width, height); return val; } private static void AddPointer(GameObject go, Action<Vector2> onPoint) { go.AddComponent<PointerArea>().OnPoint = onPoint; } public static string ToTag(Color color) { //IL_0000: 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_0012: Unknown result type (might be due to invalid IL or missing references) if (!(color.a >= 0.999f)) { return "#" + ColorUtility.ToHtmlStringRGBA(color); } return "#" + ColorUtility.ToHtmlStringRGB(color); } } internal sealed class PointerArea : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IDragHandler { public Action<Vector2> OnPoint; public void OnPointerDown(PointerEventData eventData) { Emit(eventData); } public void OnDrag(PointerEventData eventData) { Emit(eventData); } private void Emit(PointerEventData eventData) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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_007c: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)((Component)this).transform; Vector2 val2 = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(val, eventData.position, eventData.pressEventCamera, ref val2)) { Action<Vector2> onPoint = OnPoint; if (onPoint != null) { Rect rect = val.rect; float xMin = ((Rect)(ref rect)).xMin; rect = val.rect; float num = Mathf.InverseLerp(xMin, ((Rect)(ref rect)).xMax, val2.x); rect = val.rect; float yMin = ((Rect)(ref rect)).yMin; rect = val.rect; onPoint(new Vector2(num, Mathf.InverseLerp(yMin, ((Rect)(ref rect)).yMax, val2.y))); } } } } internal static class EmojiProbe { public const string Category = "emoji probe (test)"; private static readonly uint[] Bmp = new uint[23] { 9786u, 9787u, 9785u, 9829u, 9824u, 9827u, 9830u, 10084u, 9733u, 9734u, 11088u, 9760u, 9876u, 9874u, 9889u, 9888u, 10004u, 10008u, 10013u, 9728u, 9729u, 9731u, 9968u }; private static readonly uint[] Astral = new uint[24] { 128512u, 128515u, 128516u, 128513u, 128514u, 128578u, 128521u, 128525u, 128526u, 128546u, 128557u, 128545u, 128561u, 128128u, 128077u, 128078u, 128296u, 128481u, 128737u, 127968u, 127794u, 127866u, 128058u, 129517u }; public static uint[] Codepoints { get { uint[] array = new uint[Bmp.Length + Astral.Length]; Bmp.CopyTo(array, 0); Astral.CopyTo(array, Bmp.Length); return array; } } public static void Report(TMP_FontAsset font, ICollection<uint> discovered) { if ((Object)(object)font == (Object)null || discovered == null) { return; } try { HashSet<uint> present = new HashSet<uint>(discovered); string missing; int num = Count(present, Bmp, out missing); string missing2; int num2 = Count(present, Astral, out missing2); SignStylerPlugin.Log.LogInfo((object)("Emoji probe on " + ((Object)font).name + ": BMP symbols " + num + "/" + Bmp.Length + ", astral emoji " + num2 + "/" + Astral.Length + ".")); if (missing.Length > 0) { SignStylerPlugin.Log.LogInfo((object)(" BMP missing: " + missing)); } if (missing2.Length > 0) { SignStylerPlugin.Log.LogInfo((object)(" astral missing: " + missing2)); } if (num2 == 0) { SignStylerPlugin.Log.LogInfo((object)" No astral emoji in this font or its fallbacks. If the probe grid still draws faces, the renderer resolves them somewhere the font walk does not look, and the board's filter is too strict."); } } catch (Exception ex) { SignStylerPlugin.Log.LogWarning((object)("Emoji probe failed: " + ex.Message)); } } private static int Count(HashSet<uint> present, uint[] codepoints, out string missing) { int num = 0; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < codepoints.Length; i++) { uint item = codepoints[i]; if (present.Contains(item)) { num++; continue; } if (stringBuilder.Length > 0) { stringBuilder.Append(' '); } stringBuilder.Append("U+").Append(item.ToString("X4")); } missing = stringBuilder.ToString(); return num; } } internal static class GlyphNames { private struct Block { public uint Low; public uint High; public string Name; } internal struct Query { public string[] Terms; public string Hex; public bool IsEmpty { get { if (Terms == null) { return Hex == null; } return false; } } } private const string Resource = "SignStyler.GlyphNames.txt"; public const string PrivateUse = "Game icons"; private const string Unblocked = "Other"; private static Dictionary<uint, string> _names; private static List<Block> _blocks; public static int Count { get { Load(); return _names.Count; } } public static string Of(uint codepoint) { Load(); if (!_names.TryGetValue(codepoint, out var value)) { return string.Empty; } return value; } public static string BlockOf(uint codepoint) { Load(); int num = 0; int num2 = _blocks.Count - 1; while (num <= num2) { int num3 = (num + num2) / 2; Block block = _blocks[num3]; if (codepoint < block.Low) { num2 = num3 - 1; continue; } if (codepoint > block.High) { num = num3 + 1; continue; } return block.Name; } if (codepoint >= 57344 && codepoint <= 63743) { return "Game icons"; } return "Other"; } public static bool Matches(uint codepoint, Query query) { if (query.Hex != null && codepoint.ToString("X", CultureInfo.InvariantCulture).Equals(query.Hex, StringComparison.OrdinalIgnoreCase)) { return true; } if (query.Terms == null) { return query.Hex == null; } string text = Of(codepoint); if (text.Length == 0) { return false; } string[] terms = query.Terms; foreach (string value in terms) { if (text.IndexOf(value, StringComparison.Ordinal) < 0) { return false; } } return true; } public static Query Parse(string text) { Query result = default(Query); if (string.IsNullOrEmpty(text)) { return result; } string text2 = text.Trim().ToLowerInvariant(); if (text2.Length == 0) { return result; } bool flag = text2.StartsWith("u+", StringComparison.Ordinal) || text2.StartsWith("0x", StringComparison.Ordinal); string text3 = (flag ? text2.Substring(2) : text2); if (text3.Length > 0 && text3.Length <= 6 && IsHex(text3)) { result.Hex = text3; } if (result.Hex != null && flag) { return result; } string[] array = text2.Split(new char[2] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length != 0) { result.Terms = array; } return result; } private static bool IsHex(string value) { foreach (char c in value) { if ((c < '0' || c > '9') && (c < 'a' || c > 'f')) { return false; } } return true; } private static void Load() { if (_names != null) { return; } _names = new Dictionary<uint, string>(6000); _blocks = new List<Block>(64); try { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SignStyler.GlyphNames.txt"); if (stream == null) { SignStylerPlugin.Log.LogWarning((object)"Glyph name table missing from the assembly: the icon board will search by codepoint only."); return; } using StreamReader streamReader = new StreamReader(stream, Encoding.UTF8); string line; while ((line = streamReader.ReadLine()) != null) { ParseLine(line); } } catch (Exception ex) { SignStylerPlugin.Log.LogWarning((object)("Could not read the glyph name table: " + ex.Message)); } } private static void ParseLine(string line) { if (line.Length == 0 || line[0] == '#') { return; } int num = line.IndexOf(';'); if (num <= 0) { return; } string text = line.Substring(0, num); string text2 = line.Substring(num + 1); if (text2.Length == 0) { return; } if (text[0] != '@') { if (TryHex(text, out var result)) { _names[result] = text2; } return; } int num2 = text.IndexOf('-'); if (num2 > 1 && TryHex(text.Substring(1, num2 - 1), out var result2) && TryHex(text.Substring(num2 + 1), out var result3)) { _blocks.Add(new Block { Low = result2, High = result3, Name = text2 }); } } private static bool TryHex(string value, out uint result) { return uint.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result); } } internal sealed class IconBoard { private const float ContentWidth = 276f; private const int Columns = 7; private const int Rows = 6; private const int PageSize = 42; private const float Cell = 36f; private const float CellGap = 4f; private const float GlyphSize = 24f; private const string AllCategories = "all glyphs"; private readonly GameObject _root; private readonly RectTransform _grid; private readonly TMP_Text _title; private readonly TMP_Text _hint; private readonly TMP_Text _caption; private readonly TMP_Text _categoryLabel; private readonly TMP_InputField _search; private readonly Button _previous; private readonly Button _next; private readonly Action<string> _onInsert; private readonly Button[] _cells = (Button[])(object)new Button[42]; private readonly uint[] _cellGlyphs = new uint[42]; private readonly List<uint> _glyphs = new List<uint>(); private readonly List<uint> _filtered = new List<uint>(); private readonly List<string> _categories = new List<string>(); private TMP_FontAsset _font; private string _query = string.Empty; private int _category; private int _page; public GameObject Root => _root; public bool Visible => _root.activeSelf; public int Count => _glyphs.Count; private int PageCount => Mathf.Max(1, Mathf.CeilToInt((float)_filtered.Count / 42f)); public IconBoard(Transform parent, Action<string> onInsert) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_010e: Expected O, but got Unknown //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_037f: Unknown result type (might be due to invalid IL or missing references) //IL_03f3: Unknown result type (might be due to invalid IL or missing references) _onInsert = onInsert; _categories.Add("all glyphs"); _root = new GameObject("SS_IconBoard", new Type[1] { typeof(RectTransform) }); _root.transform.SetParent(parent, false); RectTransform val = (RectTransform)_root.transform; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(1f, 1f); ((Graphic)_root.AddComponent<Image>()).color = UiFactory.PanelBackground; VerticalLayoutGroup obj = _root.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)obj).padding = new RectOffset(10, 10, 8, 8); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 5f; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false; ((LayoutGroup)obj).childAlignment = (TextAnchor)1; ContentSizeFitter obj2 = _root.AddComponent<ContentSizeFitter>(); obj2.horizontalFit = (FitMode)2; obj2.verticalFit = (FitMode)2; RectTransform parent2 = UiFactory.Row(_root.transform, "Header", 26f, (TextAnchor)4); _title = UiFactory.Label((Transform)(object)parent2, "Icons", 210f, (TextAlignmentOptions)513, UiFactory.Gold); UiFactory.Button((Transform)(object)parent2, "Close", delegate { SetVisible(visible: false); }, 62f); RectTransform parent3 = UiFactory.Row(_root.transform, "Search", 26f, (TextAnchor)4); _search = UiFactory.Field((Transform)(object)parent3, string.Empty, 32, OnSearchCommitted, 214f); if ((Object)(object)_search != (Object)null) { ((UnityEvent<string>)(object)_search.onValueChanged).AddListener((UnityAction<string>)OnSearchChanged); } UiFactory.Button((Transform)(object)parent3, "clear", ClearFilters, 58f); RectTransform parent4 = UiFactory.Row(_root.transform, "Category", 26f, (TextAnchor)4); UiFactory.Button((Transform)(object)parent4, "<", delegate { TurnCategory(-1); }, 28f); _categoryLabel = UiFactory.Label((Transform)(object)parent4, "all glyphs", 212f, (TextAlignmentOptions)514, UiFactory.Parchment, 11f); UiFactory.Button((Transform)(object)parent4, ">", delegate { TurnCategory(1); }, 28f); _grid = UiFactory.Grid(_root.transform, "Glyphs", 7, 36f, 4f); BuildCells(); UiFactory.Separator(_root.transform, 276f); RectTransform parent5 = UiFactory.Row(_root.transform, "Paging", 26f, (TextAnchor)4); _previous = UiFactory.Button((Transform)(object)parent5, "<", delegate { TurnPage(-1); }); _hint = UiFactory.Label((Transform)(object)parent5, string.Empty, 188f, (TextAlignmentOptions)514, UiFactory.Muted, 11f); _next = UiFactory.Button((Transform)(object)parent5, ">", delegate { TurnPage(1); }); RectTransform parent6 = UiFactory.Row(_root.transform, "Caption", 26f, (TextAnchor)4); _caption = UiFactory.Label((Transform)(object)parent6, string.Empty, 276f, (TextAlignmentOptions)514, UiFactory.Muted, 10f); _root.SetActive(false); } private void BuildCells() { for (int i = 0; i < 42; i++) { int slot = i; _cells[i] = UiFactory.Button((Transform)(object)_grid, string.Empty, delegate { InsertSlot(slot); }, 36f); ((Component)_cells[i]).gameObject.SetActive(false); } } public void SetVisible(bool visible) { _root.SetActive(visible); if (visible) { RefreshPage(); } } public void Toggle() { SetVisible(!Visible); } public void Dispose() { if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } } public void SetFont(TMP_FontAsset font) { if (!((Object)(object)font == (Object)null) && !((Object)(object)font == (Object)(object)_font)) { _font = font; _page = 0; _glyphs.Clear(); _glyphs.AddRange(FontGlyphs.Discover(font)); BuildCategories(); _title.text = ((_glyphs.Count > 0) ? ("Icons " + _glyphs.Count) : "Icons"); SignStylerPlugin.Log.LogInfo((object)("Icon board: " + _glyphs.Count + " glyphs in " + ((Object)font).name + ", " + (_categories.Count - 1) + " Unicode blocks, " + GlyphNames.Count + " names loaded.")); Refilter(); } } private void BuildCategories() { _categories.Clear(); _categories.Add("all glyphs"); _category = 0; HashSet<string> hashSet = new HashSet<string>(); foreach (uint glyph in _glyphs) { string item = GlyphNames.BlockOf(glyph); if (hashSet.Add(item)) { _categories.Add(item); } } } private void OnSearchChanged(string value) { string text = value ?? string.Empty; if (!(text == _query)) { _query = text; Refilter(); } } private void OnSearchCommitted(string value) { OnSearchChanged(value); } private void ClearFilters() { _query = string.Empty; _category = 0; if ((Object)(object)_search != (Object)null) { _search.text = string.Empty; } _categoryLabel.text = "all glyphs"; Refilter(); } private void TurnCategory(int delta) { if (_categories.Count > 1) { _category = (_category + delta + _categories.Count) % _categories.Count; _categoryLabel.text = _categories[_category]; Refilter(); } } private void Refilter() { GlyphNames.Query query = GlyphNames.Parse(_query); string text = ((_category > 0 && _category < _categories.Count) ? _categories[_category] : null); List<uint> glyphs = _glyphs; _filtered.Clear(); foreach (uint item in (IEnumerable<uint>)glyphs) { if ((text == null || !(GlyphNames.BlockOf(item) != text)) && (query.IsEmpty || GlyphNames.Matches(item, query))) { _filtered.Add(item); } } _page = 0; RefreshPage(); } private void TurnPage(int delta) { int pageCount = PageCount; if (pageCount > 1) { _page = (_page + delta + pageCount) % pageCount; RefreshPage(); } } private void RefreshPage() { int num = _page * 42; for (int i = 0; i < 42; i++) { int num2 = num + i; Button val = _cells[i]; if (!((Object)(object)val == (Object)null)) { string text = ((num2 < _filtered.Count) ? FontGlyphs.ToText(_filtered[num2]) : string.Empty); if (text.Length == 0) { ((Component)val).gameObject.SetActive(false); continue; } _cellGlyphs[i] = _filtered[num2]; UiFactory.SetLabel(((Component)val).gameObject, text, null); UiFactory.SetLabelFont(((Component)val).gameObject, _font, 24f); ((Component)val).gameObject.SetActive(true); } } int pageCount = PageCount; bool flag = _query.Length > 0 || _category > 0; if (_glyphs.Count == 0) { _hint.text = "No icon glyph in this font"; } else if (_filtered.Count == 0) { _hint.text = "no match"; } else if (pageCount > 1) { _hint.text = "page " + (_page + 1) + " / " + pageCount; } else { _hint.text = _filtered.Count + (flag ? " matches" : " glyphs"); } bool flag2 = pageCount > 1; UiFactory.SetButtonDimmed(_previous, "<", !flag2); UiFactory.SetButtonDimmed(_next, ">", !flag2); } private void InsertSlot(int slot) { if (slot < 0 || slot >= 42) { return; } Button val = _cells[slot]; if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeSelf) { uint codepoint = _cellGlyphs[slot]; string text = FontGlyphs.ToText(codepoint); if (text.Length != 0) { _onInsert?.Invoke(text); string text2 = GlyphNames.Of(codepoint); _caption.text = "U+" + codepoint.ToString("X4") + ((text2.Length > 0) ? (" " + text2) : string.Empty); } } } } internal static class FontGlyphs { private const int HardCap = 4096; public static string ToText(uint codepoint) { if (codepoint <= 1114111) { return char.ConvertFromUtf32((int)codepoint); } return string.Empty; } public static List<uint> Discover(TMP_FontAsset font) { SortedSet<uint> sortedSet = new SortedSet<uint>(); try { HashSet<TMP_FontAsset> visited = new HashSet<TMP_FontAsset>(); Collect(font, sortedSet, visited); List<TMP_FontAsset> fallbackFontAssets = TMP_Settings.fallbackFontAssets; if (fallbackFontAssets != null) { foreach (TMP_FontAsset item in fallbackFontAssets) { Collect(item, sortedSet, visited); } } } catch (Exception ex) { SignStylerPlugin.Log.LogWarning((object)("Could not read the font's glyphs: " + ex.Message)); } if (sortedSet.Count >= 4096) { SignStylerPlugin.Log.LogWarning((object)("Icon board: stopped at " + 4096 + " glyphs. Some of this font's glyphs are not on the board.")); } return new List<uint>(sortedSet); } private static void Collect(TMP_FontAsset font, SortedSet<uint> found, HashSet<TMP_FontAsset> visited) { if ((Object)(object)font == (Object)null || !visited.Add(font) || found.Count >= 4096) { return; } List<TMP_Character> characterTable = font.characterTable; if (characterTable != null) { foreach (TMP_Character item in characterTable) { if (item != null) { if (IsIcon(((TMP_TextElement)item).unicode)) { found.Add(((TMP_TextElement)item).unicode); } if (found.Count >= 4096) { return; } } } } List<TMP_FontAsset> fallbackFontAssetTable = font.fallbackFontAssetTable; if (fallbackFontAssetTable == null) { return; } foreach (TMP_FontAsset item2 in fallbackFontAssetTable) { Collect(item2, found, visited); } } private static bool IsIcon(uint c) { switch (c) { case 8232u: case 8233u: return false; case 8234u: case 8235u: case 8236u: case 8237u: case 8238u: return false; default: if (c >= 8288 && c <= 8303) { return false; } if (c == 65279) { return false; } if (c < 161) { return false; } if (c <= 191) { return true; } if (c <= 591) { return false; } if (c < 8208) { return false; } if (c <= 11263) { return true; } if (c < 57344) { return false; } if (c <= 63743) { return true; } if (c < 126976) { return false; } return true; } } } internal sealed class InputFieldAdapter { private readonly TMP_InputField _tmp; private readonly InputField _legacy; private int _cachedStart; private int _cachedEnd; public bool IsAlive { get { if (!((Object)(object)_tmp != (Object)null)) { return (Object)(object)_legacy != (Object)null; } return true; } } public TMP_InputField Tmp => _tmp; public RectTransform Rect { get { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown if ((Object)(object)_tmp != (Object)null) { return (RectTransform)((Component)_tmp).transform; } return (RectTransform)((Component)_legacy).transform; } } public string Text { get { if (!((Object)(object)_tmp != (Object)null)) { return _legacy.text; } return _tmp.text; } set { if ((Object)(object)_tmp != (Object)null) { _tmp.text = value; } else { _legacy.text = value; } } } public int CharacterLimit { get { if (!((Object)(object)_tmp != (Object)null)) { return _legacy.characterLimit; } return _tmp.characterLimit; } set { if ((Object)(object)_tmp != (Object)null) { _tmp.characterLimit = value; } else { _legacy.characterLimit = value; } } } private int Anchor { get { if (!((Object)(object)_tmp != (Object)null)) { return _legacy.selectionAnchorPosition; } return _tmp.selectionStringAnchorPosition; } } private int Focus { get { if (!((Object)(object)_tmp != (Object)null)) { return _legacy.selectionFocusPosition; } return _tmp.selectionStringFocusPosition; } } public bool IsFocused { get { if (!((Object)(object)_tmp != (Object)null)) { return _legacy.isFocused; } return _tmp.isFocused; } } public int SelectionStart => _cachedStart; public int SelectionEnd => _cachedEnd; private InputFieldAdapter(TMP_InputField tmp, InputField legacy) { _tmp = tmp; _legacy = legacy; } public static InputFieldAdapter Find(GameObject panel) { if ((Object)(object)panel == (Object)null) { return null; } TMP_InputField[] componentsInChildren = panel.GetComponentsInChildren<TMP_InputField>(true); foreach (TMP_InputField val in componentsInChildren) { if (!IsOurs(((Component)val).transform)) { return new InputFieldAdapter(val, null); } } InputField[] componentsInChildren2 = panel.GetComponentsInChildren<InputField>(true); foreach (InputField val2 in componentsInChildren2) { if (!IsOurs(((Component)val2).transform)) { return new InputFieldAdapter(null, val2); } } return null; } public static bool IsOurs(Transform transform) { Transform val = transform; while ((Object)(object)val != (Object)null) { string name = ((Object)val).name; if (name.StartsWith("SS_", StringComparison.Ordinal) || name.StartsWith("SignStyler", StringComparison.Ordinal)) { return true; } val = val.parent; } return false; } public void CacheSelection() { if (IsFocused) { int anchor = Anchor; int focus = Focus; _cachedStart = Mathf.Min(anchor, focus); _cachedEnd = Mathf.Max(anchor, focus); } } public void KeepSelectionOnBlur() { if (!((Object)(object)_tmp == (Object)null)) { _tmp.resetOnDeActivation = false; _tmp.onFocusSelectAll = false; } } public void SetRichTextRendering(bool enabled) { if ((Object)(object)_tmp != (Object)null) { _tmp.richText = enabled; if ((Object)(object)_tmp.textComponent != (Object)null) { _tmp.textComponent.richText = enabled; _tmp.textComponent.parseCtrlCharacters = enabled; } } else if ((Object)(object)_legacy != (Object)null && (Object)(object)_legacy.textComponent != (Object)null) { _legacy.textComponent.supportRichText = enabled; } } public void SetCaret(int position) { position = Mathf.Clamp(position, 0, Text?.Length ?? 0); _cachedStart = (_cachedEnd = position); if ((Object)(object)_tmp != (Object)null) { _tmp.stringPosition = position; _tmp.selectionStringAnchorPosition = position; _tmp.selectionStringFocusPosition = position; _tmp.ForceLabelUpdate(); } else { _legacy.caretPosition = position; _legacy.selectionAnchorPosition = position; _legacy.selectionFocusPosition = position; _legacy.ForceLabelUpdate(); } } public void Activate() { if ((Object)(object)_tmp != (Object)null) { _tmp.ActivateInputField(); } else { _legacy.ActivateInputField(); } } } internal sealed class TagSpec { public string Name; public string Label; public string Unit; public float Min; public float Max; public float Default; public float Step = 1f; public Func<float, string> Format; public Func<string, float?> Parse; public TagSpec Alternate; public string Closing; public static readonly TagSpec[] All = new TagSpec[6] { new TagSpec { Name = "size", Label = "size", Unit = "%", Min = 20f, Max = 400f, Default = 150f, Step = 5f, Closing = "<size=100%>", Alternate = new TagSpec { Name = "size", Label = "size", Unit = "", Min = 1f, Max = 800f, Default = 100f, Step = 1f, Closing = "<size=100%>" } }, new TagSpec { Name = "voffset", Label = "offset", Unit = "em", Min = -3f, Max = 3f, Default = 0.5f, Step = 0.05f, Closing = "<voffset=0>" }, new TagSpec { Name = "line-height", Label = "leading", Unit = "%", Min = 30f, Max = 200f, Default = 100f, Step = 5f, Closing = "<line-height=100%>" }, new TagSpec { Name = "cspace", Label = "spacing", Unit = "em", Min = -0.3f, Max = 1f, Default = 0.15f, Step = 0.05f, Closing = "<cspace=0>" }, new TagSpec { Name = "rotate", Label = "rotate", Unit = "", Min = -90f, Max = 90f, Default = 15f, Step = 1f, Closing = "<rotate=0>" }, new TagSpec { Name = "alpha", Label = "opacity", Unit = "", Min = 0f, Max = 255f, Default = 255f, Step = 5f, Closing = "<alpha=#FF>", Format = (float v) => "#" + Mathf.RoundToInt(v).ToString("X2"), Parse = (string s) => (!int.TryParse(s.TrimStart(new char[1] { '#' }), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result)) ? ((float?)null) : new float?(result) } }; public TagSpec FormOf(string raw) { if (Alternate == null) { return this; } string text = (raw ?? string.Empty).Trim().Trim(new char[1] { '"' }); if (text.Length == 0) { return this; } if (Unit.Length > 0 && text.EndsWith(Unit, StringComparison.OrdinalIgnoreCase)) { return this; } if (Alternate.Unit.Length > 0 && text.EndsWith(Alternate.Unit, StringComparison.OrdinalIgnoreCase)) { return Alternate; } if (Alternate.Unit.Length != 0) { return this; } return Alternate; } public float Snap(float value) { if (!(Step > 0f)) { return value; } return Mathf.Clamp(Mathf.Round(value / Step) * Step, Min, Max); } public string FormatValue(float value) { if (Format == null) { return Snap(value).ToString("0.##", CultureInfo.InvariantCulture) + Unit; } return Format(Snap(value)); } public bool TryParseValue(string raw, out float value, out TagSpec form) { form = FormOf(raw); return form.TryParseValue(raw, out value); } public bool TryParseValue(string raw, out float value) { value = 0f; string text = (raw ?? string.Empty).Trim(); if (text.Length == 0) { return false; } if (Parse != null) { float? num = Parse(text); if (!num.HasValue) { return false; } value = Snap(num.Value); return true; } if (Unit.Length > 0 && text.EndsWith(Unit, StringComparison.OrdinalIgnoreCase)) { text = text.Substring(0, text.Length - Unit.Length).TrimEnd(Array.Empty<char>()); } if (!float.TryParse(text.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return false; } value = Snap(result); return true; } } internal sealed class TagBinding { private readonly InputFieldAdapter _field; private int _valueStart; private int _valueLength; private string _lastWritten; public TagSpec Spec { get; private set; } public float Value { get; private set; } public bool IsBound => Spec != null; public TagBinding(InputFieldAdapter field) { _field = field; } public string Bind(TagSpec spec, out int caret) { caret = -1; Spec = spec; string text = _field.Text ?? string.Empty; int num = Mathf.Clamp(_field.SelectionStart, 0, text.Length); int num2 = Mathf.Clamp(_field.SelectionEnd, num, text.Length); Regex regex = new Regex("<" + Regex.Escape(spec.Name) + "=([^<>]*)>"); Match match = null; string value = spec.Closing ?? ("</" + spec.Name + ">"); foreach (Match item in regex.Matches(text)) { if (item.Index > num) { break; } int num3 = text.IndexOf(value, item.Index + item.Length, StringComparison.Ordinal); if (num3 < 0 || num3 >= num) { match = item; } } if (match != null) { Group obj = match.Groups[1]; Spec = spec.FormOf(obj.Value); _valueStart = obj.Index; _valueLength = obj.Length; _lastWritten = obj.Value; Value = Parse(obj.Value, Spec); return text; } string text2 = "<" + spec.Name + "=" + spec.FormatValue(spec.Default) + ">"; string text3 = (Settings.SelfClosingTags ? string.Empty : spec.Closing); string text4 = text.Substring(num, num2 - num); string result = text.Substring(0, num) + text2 + text4 + text3 + text.Substring(num2); _valueStart = num + spec.Name.Length + 2; _valueLength = spec.FormatValue(spec.Default).Length; _lastWritten = spec.FormatValue(spec.Default); Value = spec.Default; caret = num + text2.Length + text4.Length; return result; } public string Write(float value) { if (Spec == null) { return null; } string text = _field.Text ?? string.Empty; if (!StillValid(text)) { Unbind(); return null; } string text2 = Spec.FormatValue(value); string result = text.Substring(0, _valueStart) + text2 + text.Substring(_valueStart + _valueLength); _valueLength = text2.Length; _lastWritten = text2; Value = value; return result; } public string Remove() { if (Spec == null) { return null; } string text = _field.Text ?? string.Empty; if (!StillValid(text)) { Unbind(); return null; } int num = _valueStart - Spec.Name.Length - 2; int num2 = _valueStart + _valueLength + 1; if (num < 0 || num2 > text.Length) { Unbind(); return null; } string text2 = text.Substring(0, num) + text.Substring(num2); string[] array = new string[2] { Spec.Closing, "</" + Spec.Name + ">" }; foreach (string text3 in array) { if (!string.IsNullOrEmpty(text3)) { int num3 = text2.IndexOf(text3, Mathf.Min(num, text2.Length), StringComparison.Ordinal); if (num3 >= 0) { text2 = text2.Substring(0, num3) + text2.Substring(num3 + text3.Length); break; } } } Unbind(); return text2; } public void Reform(TagSpec form) { if (Spec != null && form != null) { Spec = form; } } public void Unbind() { Spec = null; _lastWritten = null; _valueStart = (_valueLength = 0); } private bool StillValid(string text) { if (_lastWritten == null) { return false; } if (_valueStart < 0 || _valueStart + _valueLength > text.Length) { return false; } return string.Equals(text.Substring(_valueStart, _valueLength), _lastWritten, StringComparison.Ordinal); } private static float Parse(string raw, TagSpec spec) { string text = (raw ?? string.Empty).Trim().Trim(new char[1] { '"' }); if (text.StartsWith("#")) { if (!int.TryParse(text.Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result)) { return spec.Default; } return result; } text = text.Replace("%", string.Empty).Replace("em", string.Empty).Replace("px", string.Empty); if (!float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2)) { return spec.Default; } return Mathf.Clamp(result2, spec.Min, spec.Max); } } [BepInPlugin("fr.anthony.signstyler", "Sign Styler", "1.0.0")] [BepInProcess("valheim.exe")] public class SignStylerPlugin : BaseUnityPlugin { public const string PluginGuid = "fr.anthony.signstyler"; public const string PluginName = "Sign Styler"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Settings.CharacterLimitEntry = ((BaseUnityPlugin)this).Config.Bind<int>("General", "CharacterLimit", 400, new ConfigDescription("Maximum number of characters in the input field, tags included. Vanilla is 50. Sign text lives in the sign's ZDO and travels over the network, so a very high value costs bandwidth for everyone on the server.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 2000), Array.Empty<object>())); _harmony = new Harmony("fr.anthony.signstyler"); TextInputPatches.Apply(_harmony); Log.LogInfo((object)"Sign Styler v1.0.0 loaded."); } private void OnDestroy() { StyleToolbar.Dispose(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class Settings { internal const int DefaultCharacterLimit = 400; internal const int MinCharacterLimit = 50; internal const int MaxCharacterLimit = 2000; internal static ConfigEntry<int> CharacterLimitEntry; internal static readonly bool PlainTagEditing = true; internal static readonly bool SignsOnly = true; internal static readonly bool ToolbarEnabled = true; internal static readonly bool PreviewEnabled = true; internal static readonly bool Shortcuts = true; internal static readonly bool SelfClosingTags = false; internal static readonly bool ExpandToWord = true; internal static readonly string NewlineToken = "\\n"; internal static readonly List<string> RecentColors = new List<string> { "#FFD24A", "#FF5555", "#69DB7C", "#4DABF7" }; internal const int MaxRecentColors = 8; internal static readonly List<string> PaletteColors = new List<string> { "#FFC940", "#F2A93B", "#C0392B", "#7B2D26", "#3FA45B", "#2E7D5B", "#3D6CB9", "#5B4B8A", "#E9E4D4", "#9A8C78", "#3A2415", "#12100E" }; internal const int MaxPaletteColors = 24; internal const string DefaultTextColor = "#000000"; internal const string DefaultBackgroundColor = "#3A241500"; internal static int CharacterLimit => CharacterLimitEntry?.Value ?? 400; } internal static class StyleToolbar { private sealed class FormatButton { public string Label; public Button Button; } private static GameObject _root; private static InputFieldAdapter _field; private static TMP_Text _preview; private static TMP_Text _previewHover; private static GameObject _previewRoot; private static ColorPicker _picker; private static IconBoard _icons; private static TMP_FontAsset _signFont; private static TagBinding _binding; private static RectTransform _sliderRow; private static Slider _slider; private static TMP_Text _sliderLabel; private static TMP_InputField _sliderField; private static TMP_Text _sliderValue; private static Button _textColorButton; private static Button _bgColorButton; private static Image _textSwatch; private static Image _bgSwatch; private static TMP_Text _textHex; private static TMP_Text _bgHex; private static Color _textColor; private static Color _bgColor; private static string _lastColorRowKey; private static int? _pendingCaret; private static string _lastPreviewed; private static string _lastCounted; private static string _lastFormatKey; private static TMP_Text _counter; private static RectTransform _anchorField; private static object _receiver; private static int _repositionFrames; private static float _pickerHeight; private static readonly Vector3[] _corners = (Vector3[])(object)new Vector3[4]; private static readonly Vector3[] _canvasCorners = (Vector3[])(object)new Vector3[4]; private static readonly Dictionary<string, Button> _tagButtons = new Dictionary<string, Button>(); private static readonly Dictionary<string, FormatButton> _formatButtons = new Dictionary<string, FormatButton>(); private const float PreviewFontSize = 30f; private const float PreviewHeight = 74f; private const float BoardInset = 12f; private static readonly Color LabelIdle = new Color(0.91f, 0.87f, 0.78f); private static readonly Color LabelActive = new Color(1f, 0.82f, 0.29f); private static readonly Color BoardWood = new Color(0.27f, 0.18f, 0.11f, 1f); private static readonly int FaceColorProperty = Shader.PropertyToID("_FaceColor"); private static readonly Regex TagRegex = new Regex("<[^<>]*>", RegexOptions.Compiled); private static readonly Regex OpaqueMarkRegex = new Regex("<mark=#([0-9A-Fa-f]{6})>", RegexOptions.Compiled); private static readonly Regex ColorTagRegex = new Regex("<color=(#[0-9A-Fa-f]{6}(?:[0-9A-Fa-f]{2})?)>", RegexOptions.Compiled); private static readonly Regex MarkTagRegex = new Regex("<mark=(#[0-9A-Fa-f]{6}(?:[0-9A-Fa-f]{2})?)>", RegexOptions.Compiled); private static readonly Regex HoverIgnoredRegex = new Regex("</?mark[^<>]*>|</?[bius]>", RegexOptions.Compiled); public static void Attach(TextInput textInput, object receiver, string topic) { _receiver = receiver; GameObject val = FindPanel(textInput); if ((Object)(object)val == (Object)null) { return; } _field = InputFieldAdapter.Find(val); if (_field == null) { SignStylerPlugin.Log.LogWarning((object)"No input field found inside the TextInput panel."); return; } bool flag = !string.IsNullOrEmpty(topic) && topic.IndexOf("sign", StringComparison.OrdinalIgnoreCase) >= 0; bool flag2 = !Settings.SignsOnly || flag; bool flag3 = Settings.ToolbarEnabled && flag2; if (!flag2) { Hide(); return; } _field.CharacterLimit = Mathf.Max(_field.CharacterLimit, Settings.CharacterLimit); _field.SetRichTextRendering(!Settings.PlainTagEditing); _field.KeepSelectionOnBlur(); if (!flag3) { Hide(); return; } _binding = new TagBinding(_field); if ((Object)(object)_root == (Object)null) { Build(val); } if (!((Object)(object)_root == (Object)null)) { _root.SetActive(true); if ((Object)(object)_previewRoot != (Object)null) { _previewRoot.SetActive(true); MatchSignAppearance(); MatchHoverAppearance(); } _repositionFrames = 3; _picker?.SetVisible(visible: false); _icons?.SetVisible(visible: false); _icons?.SetFont(GlyphFont()); ShowSliderRow(visible: false); ResetColorTargets(); RefreshPreview(force: true); } } private static void Hide() { if ((Object)(object)_root != (Object)null) { _root.SetActive(false); } if ((Object)(object)_previewRoot != (Object)null) { _previewRoot.SetActive(false); } _picker?.SetVisible(visible: false); _icons?.SetVisible(visible: false); } public static void Dispose() { if ((Object)(object)_previewRoot != (Object)null) { Object.Destroy((Object)(object)_previewRoot); } _picker?.Dispose(); _icons?.Dispose(); if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } UiFactory.ReleaseShapes(); _root = null; _preview = null; _previewHover = null; _previewRoot = null; _picker = null; _icons = null; _signFont = null; _field = null; _binding = null; _counter = null; _sliderRow = null; _slider = null; _sliderLabel = null; _sliderField = null; _sliderValue = null; _textColorButton = null; _bgColorButton = null; _textSwatch = null; _bgSwatch = null; _textHex = null; _bgHex = null; _anchorField = null; _lastPreviewed = null; _lastCounted = null; _lastFormatKey = null; _lastColorRowKey = null; _tagButtons.Clear(); _formatButtons.Clear(); } private static GameObject FindPanel(TextInput textInput) { if ((Object)(object)textInput == (Object)null) { return null; } FieldInfo fieldInfo = AccessTools.Field(typeof(TextInput), "m_panel"); if (fieldInfo != null) { object? value = fieldInfo.GetValue(textInput); GameObject val = (GameObject)((value is GameObject) ? value : null); if (val != null && (Object)(object)val != (Object)null) { return val; } } return ((Component)textInput).gameObject; } private static void Build(GameObject panel) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_0073: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) RectTransform rect = _field.Rect; Transform parent = ((Transform)rect).parent; RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null); if (!((Object)(object)val == (Object)null)) { UiFactory.Init(panel, _field); _root = new GameObject("SignStyler_Toolbar", new Type[1] { typeof(RectTransform) }); RectTransform component = _root.GetComponent<RectTransform>(); ((Transform)component).SetParent((Transform)(object)val, false); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); component.anchorMax = val2; component.anchorMin = val2; component.pivot = new Vector2(0.5f, 0f); _anchorField = rect; ((Graphic)_root.AddComponent<Image>()).color = UiFactory.PanelBackground; VerticalLayoutGroup obj = _root.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)obj).padding = new RectOffset(10, 10, 8, 8); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 4f; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false; ((LayoutGroup)obj).childAlignment = (TextAnchor)7; ContentSizeFitter obj2 = _root.AddComponent<ContentSizeFitter>(); obj2.horizontalFit = (FitMode)2; obj2.verticalFit = (FitMode)2; if (!ColorUtility.TryParseHtmlString("#000000", ref _textColor)) { _textColor = Color.white; } if (!ColorUtility.TryParseHtmlString("#3A241500", ref _bgColor)) { _bgColor = Color.black; } BuildFormatRow(); BuildTagRow(); BuildSliderRow(); BuildColorRows(); _picker = new ColorPicker((Transform)(object)val, ApplyColor, InsertColorTag, HasSelection); _icons = new IconBoard((Transform)(object)val, Insert); RefreshColorRows(force: true); if (Settings.PreviewEnabled) { BuildPreview(panel, val, rect); } _root.AddComponent<ToolbarRuntime>().OnTick = Tick; Canvas.ForceUpdateCanvases(); _repositionFrames = 3; Reposition(); } } private static void BuildFormatRow() { //IL_013f: Unknown result type (might be due to invalid IL or missing references) RectTransform obj = UiFactory.Row(_root.transform, "Format", 26f, (TextAnchor)4); _formatButtons.Clear(); AddFormatButton((Transform)(object)obj, "b", "B"); AddFormatButton((Transform)(object)obj, "i", "I"); AddFormatButton((Transform)(object)obj, "u", "U"); AddFormatButton((Transform)(object)obj, "s", "S"); UiFactory.Button((Transform)(object)obj, "BR", delegate { Insert(Settings.NewlineToken); }); AddFormatButton((Transform)(object)obj, "noparse", "no parse", 72f); UiFactory.Button((Transform)(object)obj, "CLR", StripTags); UiFactory.Button((Transform)(object)obj, "icons", ToggleIcons, 58f); _counter = UiFactory.Label((Transform)(object)obj, string.Empty, 130f, (TextAlignmentOptions)516, UiFactory.Gold); } private static void AddFormatButton(Transform row, string name, string label, float width = 40f) { Button button = UiFactory.Button(row, label, delegate { Wrap("<" + name + ">", "</" + name + ">"); }, width); _formatButtons[name] = new FormatButton { Label = label, Button = button }; } private static void BuildTagRow() { //IL_0072: Unknown result type (might be due to invalid IL or missing references) RectTransform parent = UiFactory.Row(_root.transform, "Tags", 26f, (TextAnchor)4); _tagButtons.Clear(); TagSpec[] all = TagSpec.All; foreach (TagSpec tagSpec in all) { TagSpec captured = tagSpec; _tagButtons[captured.Name] = UiFactory.Button((Transform)(object)parent, captured.Label, delegate { SelectTag(captured); }, 70f, LabelIdle); } } private static void BuildSliderRow() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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) _sliderRow = UiFactory.Row(_root.transform, "Slider", 34f, (TextAnchor)4); HorizontalLayoutGroup component = ((Component)_sliderRow).GetComponent<HorizontalLayoutGroup>(); ((LayoutGroup)component).padding = new RectOffset(9, 9, 4, 4); ((HorizontalOrVerticalLayoutGroup)component).spacing = 9f; UiFactory.Backdrop(_sliderRow, UiFactory.Recess, UiFactory.RecessBorder); _sliderLabel = UiFactory.Label((Transform)(object)_sliderRow, string.Empty, 62f, (TextAlignmentOptions)513, UiFactory.Gold, 14f); _sliderField = UiFactory.Field((Transform)(object)_sliderRow, string.Empty, 8, OnSliderFieldCommitted, 64f); if ((Object)(object)_sliderField == (Object)null) { _sliderValue = UiFactory.Label((Transform)(object)_sliderRow, string.Empty, 64f, (TextAlignmentOptions)513, UiFactory.Gold, 14f); } _slider = UiFactory.Slider((Transform)(object)_sliderRow, 0f, 1f, 0f, OnSliderChanged, 196f); UiFactory.Button((Transform)(object)_sliderRow, "remove", RemoveBoundTag, 66f); ((Component)_sliderRow).gameObject.SetActive(false); } private static void OnSliderFieldCommitted(string raw) { if (_binding == null || !_binding.IsBound) { return; } if (!_binding.Spec.TryParseValue(raw, out var value, out var form)) { UpdateSliderLabel(); return; } if (form != _binding.Spec) { _binding.Reform(form); ApplySliderRange(form); } Slider slider = _slider; if (slider != null) { slider.SetValueWithoutNotify(value); } OnSliderChanged(value); } private static void BuildColorRows() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_0119: Unknown result type (might be due to invalid IL or missing references) RectTransform parent = UiFactory.Row(_root.transform, "TextColor", 26f, (TextAnchor)4); _textSwatch = UiFactory.Swatch((Transform)(object)parent, _textColor, 26f, 22f); _textColorButton = UiFactory.Button((Transform)(object)parent, "Text colour", delegate { OpenPicker(background: false); }, 130f); _textHex = UiFactory.Label((Transform)(object)parent, string.Empty, 80f, (TextAlignmentOptions)513, UiFactory.Muted, 11f); RectTransform parent2 = UiFactory.Row(_root.transform, "BackgroundColor", 26f, (TextAnchor)4); _bgSwatch = UiFactory.Swatch((Transform)(object)parent2, _bgColor, 26f, 22f); _bgColorButton = UiFactory.Button((Transform)(object)parent2, "Highlight", delegate { OpenPicker(background: true); }, 130f); _bgHex = UiFactory.Label((Transform)(object)parent2, string.Empty, 80f, (TextAlignmentOptions)513, UiFactory.Muted, 11f); } private static void ResetColorTargets() { //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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) string text = ((_field != null && _field.IsAlive) ? _field.Text : null); _textColor = LastTagColor(ColorTagRegex, text, "#000000", Color.black); _bgColor = LastTagColor(MarkTagRegex, text, "#3A241500", Color.clear); _picker?.SetColor(_picker.Background ? _bgColor : _textColor); RefreshColorRows(force: true); } private static Color LastTagColor(Regex regex, string text, string fallbackHex, Color lastResort) { //IL_003c: 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_0050: Unknown result type (might be due to invalid IL or missing references) MatchCollection matchCollection = regex.Matches(text ?? string.Empty); Color result = default(Color); for (int num = matchCollection.Count - 1; num >= 0; num--) { if (ColorUtility.TryParseHtmlString(matchCollection[num].Groups[1].Value, ref result)) { return result; } } Color result2 = default(Color); if (!ColorUtility.TryParseHtmlString(fallbackHex, ref result2)) { return lastResort; } return result2; } private static TMP_FontAsset GlyphFont() { if ((Object)(object)_signFont != (Object)null) { return _signFont; } if (!((Object)(object)UiFactory.TextTemplate != (Object)null)) { return null; } return UiFactory.TextTemplate.font; } private static void ToggleIcons() { _icons?.SetFont(GlyphFont()); _icons?.Toggle(); _repositionFrames = 3; } private static void OpenPicker(bool background) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) _picker?.Toggle(background, background ? _bgColor : _textColor); RefreshColorRows(force: true); _repositionFrames = 3; } private static void RefreshColorRows(bool force) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_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_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_textColorButton == (Object)null || (Object)(object)_bgColorButton == (Object)null) { return; } bool flag = _picker != null && _picker.Visible; bool flag2 = _picker != null && _picker.Background; string text = (flag ? "1" : "0") + (flag2 ? "b" : "t") + ColorUtility.ToHtmlStringRGBA(_textColor) + ColorUtility.ToHtmlStringRGBA(_bgColor); if (force || !(text == _lastColorRowKey)) { _lastColorRowKey = text; if ((Object)(object)_textSwatch != (Object)null) { ((Graphic)_textSwatch).color = Opaque(_textColor); } if ((Object)(object)_bgSwatch != (Object)null) { ((Graphic)_bgSwatch).color = Opaque(_bgColor); } if ((Object)(object)_textHex != (Object)null) { _textHex.text = ColorPicker.ToTag(_textColor); } if ((Object)(object)_bgHex != (Object)null) { _bgHex.text = ColorPicker.ToTag(_bgColor); } UiFactory.SetButtonState(_textColorButton, "Text colour", flag && !flag2); UiFactory.SetButtonState(_bgColorButton, "Highlight", flag && flag2); } } private static Color Opaque(Color color) { //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_0017: Unknown result type (might be due to invalid IL or missing references) return new Color(color.r, color.g, color.b, 1f); } private static bool HasSelection() { if (_field != null && _field.IsAlive) { return _field.SelectionEnd > _field.SelectionStart; } return false; } private static void BuildPreview(GameObject panel, RectTransform parent, RectTransform fieldRect) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)UiFactory.TextTemplate == (Object)null) { SignStylerPlugin.Log.LogWarning((object)"No TMP_Text template found: preview disabled."); return; } _previewRoot = new GameObject("SignStyler_Preview", new Type[1] { typeof(RectTransform) }); RectTransform val = (RectTransform)_previewRoot.transform; ((Transform)val).SetParent((Transform)(object)parent, false); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(0.5f, 1f); Image obj = _previewRoot.AddComponent<Image>(); ((Graphic)obj).color = new Color(0.1f, 0.09f, 0.08f, 0.93f); ((Graphic)obj).raycastTarget = false; VerticalLayoutGroup obj2 = _previewRoot.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)obj2).padding = new RectOffset(10, 10, 6, 8); ((HorizontalOrVerticalLayoutGroup)obj2).spacing = 2f; ((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false; ((LayoutGroup)obj2).childAlignment = (TextAnchor)1; ContentSizeFitter obj3 = _previewRoot.AddComponent<ContentSizeFitter>(); obj3.horizontalFit = (FitMode)2; obj3.verticalFit = (FitMode)2; Rect rect = fieldRect.rect; float num = Mathf.Max(((Rect)(ref rect)).width, 300f); UiFactory.Label(_previewRoot.transform, "on the sign", num, (TextAlignmentOptions)513); _preview = NewPreviewText(NewBoard(num).transform, num - 12f); UiFactory.Label(_previewRoot.transform, "on hover", num, (TextAlignmentOptions)513); _previewHover = NewPreviewText(_previewRoot.transform, num); MatchSignAppearance(); MatchHoverAppearance(); } private static TMP_Text NewPreviewText(Transform parent, float width) { TMP_Text obj = Object.Instantiate<TMP_Text>(UiFactory.TextTemplate, parent); ((Object)((Component)obj).gameObject).name = "SS_PreviewText"; obj.richText = true; obj.alignment = (TextAlignmentOptions)514; obj.textWrappingMode = (TextWrappingModes)1; ((Graphic)obj).raycastTarget = false; obj.text = string.Empty; UiFactory.Size(((Component)obj).gameObject, width, 74f); return obj; } private static GameObject NewBoard(float width) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0064: Expected O, but got Unknown GameObject val = new GameObject("SS_PreviewBoard", new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(_previewRoot.transform, false); Image component = val.GetComponent<Image>(); ((Graphic)component).color = BoardWood; ((Graphic)component).raycastTarget = false; UiFactory.Size(val, width, 86f); return val; } private static void MatchSignAppearance() { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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) if ((Object)(object)_preview == (Object)null || _receiver == null) { return; } object? obj = AccessTools.Field(_receiver.GetType(), "m_textWidget")?.GetValue(_receiver); TMP_Text val = (TMP_Text)((obj is TMP_Text) ? obj : null); if (val != null) { if ((Object)(object)val.font != (Object)null) { _preview.font = val.font; _signFont = val.font; _icons?.SetFont(_signFont); } ((Graphic)_preview).color = RenderedFaceColor(val); _preview.alignment = val.alignment; _preview.fontStyle = (FontStyles)(val.fontStyle | 0x10); _preview.enableAutoSizing = false; _preview.fontSize = 30f; _preview.overrideColorTags = false; } } private static Color RenderedFaceColor(TMP_Text widget) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) Color val = ((Graphic)widget).color; Material fontSharedMaterial = widget.fontSharedMaterial; if ((Object)(object)fontSharedMaterial != (Object)null && fontSharedMaterial.HasProperty(FaceColorProperty)) { val *= fontSharedMaterial.GetColor(FaceColorProperty); } return new Color(val.r, val.g, val.b, 1f); } private static void MatchHoverAppearance() { //IL_0060: 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) if ((Object)(object)_previewHover == (Object)null) { return; } TMP_Text val = FindHoverLabel(); if (!((Object)(object)val == (Object)null)) { if ((Object)(object)val.font != (Object)null) { _previewHover.font = val.font; } if ((Object)(object)val.fontSharedMaterial != (Object)null) { _previewHover.fontSharedMaterial = val.fontSharedMaterial; } ((Graphic)_previewHover).color = ((Graphic)val).color; _previewHover.fontStyle = val.fontStyle; _previewHover.enableAutoSizing = false; _previewHover.fontSize = 30f; _previewHover.overrideColorTags = true; } } private static TMP_Text FindHoverLabel() { Type type = AccessTools.TypeByName("Hud"); if (type == null) { return null; } object obj = AccessTools.Field(type, "m_instance")?.GetValue(null) ?? AccessTools.Property(type, "instance")?.GetValue(null); if (obj == null) { return null; } string[] array = new string[2] { "m_hoverName", "m_hoverText" }; foreach (string text in array) { object? obj2 = AccessTools.Field(type, text)?.GetValue(obj); TMP_Text val = (TMP_Text)((obj2 is TMP_Text) ? obj2 : null); if (val != null) { return val; } } return null; } private static void ApplyColor(Color color, bool background) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) string text = ColorPicker.ToTag(color); if (background) { Wrap("<mark=" + text + ">", "</mark>", "mark"); } else { Wrap("<color=" + text + ">", "</color>", "color"); } Remember(color, background); _picker?.SetHint(text + (background ? " applied as highlight." : " applied to the text.")); } private static void InsertColorTag(Color color, bool background) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) if (_field != null && _field.IsAlive) { string text = ColorPicker.ToTag(color); string text2 = (background ? ("<mark=" + text + ">") : ("<color=" + text + ">")); string text3 = (background ? "</mark>" : "</color>"); string text4 = _field.Text ?? string.Empty; int num = Mathf.Clamp(_field.SelectionStart, 0, text4.Length); int num2 = Mathf.Clamp(_field.SelectionEnd, num, text4.Length); if (num == num2 && IsInsideTag(text4, num)) { int num3 = text4.IndexOf('>', num); num = (num2 = ((num3 >= 0) ? (num3 + 1) : text4.Length)); } if (ApplyText(text4.Substring(0, num) + text2 + text3 + text4.Substring(num2), num + text2.Length)) { Remember(color, background); _picker?.SetHint("Empty " + text + " tag inserted — type inside it."); } } } private static void Remember(Color color, bool background) { //IL_000b: 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_0003: 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_0016: Unknown result type (might be due to invalid IL or missing references) if (background) { _bgColor = color; } else { _textColor = color; } PushRecentColor("#" + ColorUtility.ToHtmlStringRGB(color)); RefreshColorRows(force: true); } private static void PushRecentColor(string hex) { List<string> recentColors = Settings.RecentColors; recentColors.RemoveAll((string entry) => string.Equals(entry, hex, StringComparison.OrdinalIgnoreCase)); recentColors.Insert(0, hex); if (recentColors.Count > 8) { recentColors.RemoveRange(8, recentColors.Count - 8); } _picker?.RefreshSwatches(); } private static void SelectTag(TagSpec spec) { if (_field != null && _field.IsAlive && _binding != null) { int caret; string text = _binding.Bind(spec, out caret); if (text != null && !ApplyText(text, caret)) { _binding.Unbind(); return; } ApplySliderRange(_binding.Spec); _slider.SetValueWithoutNotify(_binding.Value); UpdateSliderLabel(); HighlightTag(spec.Name); ShowSliderRow(visible: true); } } private static void ApplySliderRange(TagSpec spec) { if (!((Object)(object)_slider == (Object)null) && spec != null) { _slider.maxValue = Mathf.Max(spec.Max, _slider.minValue); _slider.minValue = spec.Min; _slider.maxValue = spec.Max; } } private static void OnSliderChanged(float value) { if (_binding == null || !_binding.IsBound) { return; } string text = _binding.Write(_binding.Spec.Snap(value)); if (text == null) { ShowSliderRow(visible: false); return; } if (text.Length <= _field.CharacterLimit) { _field.Text = text; } UpdateSliderLabel(); } private static void RemoveBoundTag() { if (_binding != null && _binding.IsBound) { string text = _binding.Remove(); ShowSliderRow(visible: false); if (text != null) { ApplyText(text, -1); } } } private static void UpdateSliderLabel() { if (_binding != null && _binding.IsBound) { string text = _binding.Spec.FormatValue(_binding.Value); if ((Object)(object)_sliderLabel != (Object)null) { _sliderLabel.text = _binding.Spec.Label; } if ((Object)(object)_sliderValue != (Object)null) { _sliderValue.text = text; } TMP_InputField sliderField = _sliderField; if (sliderField != null) { sliderField.SetTextWithoutNotify(text); } } } private static void ShowSliderRow(bool visible) { if ((Object)(object)_sliderRow != (Object)null) { ((Component)_sliderRow).gameObject.SetActive(visible); } if (!visible) { _binding?.Unbind(); HighlightTag(null); } } private static void HighlightTag(string active) { //IL_004c: 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) TagSpec[] all = TagSpec.All; foreach (TagSpec tagSpec in all) { if (_tagButtons.TryGetValue(tagSpec.Name, out var value) && !((Object)(object)value == (Object)null)) { UiFactory.SetLabel(((Component)value).gameObject, tagSpec.Label, (tagSpec.Name == active) ? LabelActive : LabelIdle); } } } private static void Reposition() { //IL_0030: 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_004b: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_00a0: 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_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Expected O, but got Unknown //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Expected O, but got Unknown if ((Object)(object)_root == (Object)null || (Object)(object)_anchorField == (Object)null) { return; } Transform parent = ((Transform)_anchorField).parent; RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null); float x = ((Transform)_anchorField).localPosition.x; RectTransform val2 = (RectTransform)_root.transform; Rect rect; if ((Object)(object)val != (Object)null) { rect = val.rect; ((Transform)val2).localPosition = new Vector3(x, ((Rect)(ref rect)).yMax + 14f, 0f); if ((Object)(object)_previewRoot != (Object)null) { RectTransform val3 = (RectTransform)_previewRoot.transform; rect = val.rect; ((Transform)val3).localPosition = new Vector3(x, ((Rect)(ref rect)).yMin - 14f, 0f); } float y = ((Transform)val2).localPosition.y; rect = val2.rect; float num = y + ((Rect)(ref rect)).height; if ((Object)(object)_picker?.Root != (Object)null) { RectTransform val4 = (RectTransform)_picker.Root.transform; rect = val.rect; ((Transform)val4).localPosition = new Vector3(((Rect)(ref rect)).xMax + 12f, num, 0f); ClampToCanvas(val4); } if ((Object)(object)_icons?.Root != (Object)null) { RectTransform val5 = (RectTransform)_icons.Root.transform; rect = val.rect; ((Transform)val5).localPosition = new Vector3(((Rect)(ref rect)).xMin - 12f, num, 0f); ClampToCanvas(val5); } } else { rect = _anchorField.rect; float num2 = ((Rect)(ref rect)).height * 0.5f; ((Transform)val2).localPosition = ((Transform)_anchorField).localPosition + new Vector3(0f, num2 + 14f, 0f); } _picker?.RefreshLayout(); } private static void ClampToCanvas(RectTransform rect) { //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) Canvas componentInParent = ((Component)rect).GetComponentInParent<Canvas>(); RectTransform val = (RectTransform)(((Object)(object)componentInParent != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if (!((Object)(object)val == (Object)null)) { rect.GetWorldCorners(_corners); val.GetWorldCorners(_canvasCorners); float num = 0f; if (_corners[0].y < _canvasCorners[0].y + 8f) { num = _canvasCorners[0].y + 8f - _corners[0].y; } if (_corners[1].y + num > _canvasCorners[1].y - 8f) { num = _canvasCorners[1].y - 8f - _corners[1].y; } float num2 = 0f; if (_corners[2].x > _canvasCorners[2].x - 8f) { num2 = _canvasCorners[2].x - 8f - _corners[2].x; } if (_corners[0].x + num2 < _canvasCorners[0].x + 8f) { num2 = _canvasCorners[0].x + 8f - _corners[0].x; } if (num2 != 0f || num != 0f) { ((Transform)rect).position = ((Transform)rect).position + new Vector3(num2, num, 0f); } } } private static bool ApplyText(string result, int caret) { if (result == null || _field == null || !_field.IsAlive) { return false; } if (result.Length > _field.CharacterLimit) { SignStylerPlugin.Log.LogWarning((object)("Edit rejected: " + result.Length + " characters for a limit of " + _field.CharacterLimit + ".")); return false; } _field.Text = result; if (caret >= 0) { _pendingCaret = caret; } _field.Activate(); return true; } private static void Wrap(string open, string close) { Wrap(open, close, null); } private static void Wrap(string open, string close, string tagName) { if (_field == null || !_field.IsAlive) { return; } string text = _field.Text ?? string.Empty; int start = Mathf.Clamp(_field.SelectionSt