Decompiled source of SignStyler v0.4.1

SignStyler_v0.4.1.dll

Decompiled 19 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SignStyler")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.1.0")]
[assembly: AssemblyInformationalVersion("0.4.1")]
[assembly: AssemblyProduct("SignStyler")]
[assembly: AssemblyTitle("SignStyler")]
[assembly: AssemblyVersion("0.4.1.0")]
namespace SignStyler;

[BepInPlugin("DEEP_FROST.SignStyler", "SignStyler", "0.4.1")]
[BepInProcess("valheim.exe")]
public class SignStylerPlugin : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static ConsoleEvent <>9__7_0;

		public static ConsoleEvent <>9__7_1;

		internal void <Awake>b__7_0(ConsoleEventArgs args)
		{
			ApplyToHoveredSign(BuildTestText(args));
		}

		internal void <Awake>b__7_1(ConsoleEventArgs args)
		{
			LogFonts(force: true);
		}
	}

	public const string PluginGUID = "DEEP_FROST.SignStyler";

	public const string PluginName = "SignStyler";

	public const string PluginVersion = "0.4.1";

	internal static ConfigEntry<string> CfgColors;

	internal static ConfigEntry<string> CfgSizes;

	internal static ConfigEntry<string> CfgStamps;

	private static bool _fontsLogged;

	private void Awake()
	{
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Expected O, but got Unknown
		CfgColors = ((BaseUnityPlugin)this).Config.Bind<string>("Style", "Colors", "#E5B246,#FF3B30,#4CC94C,#4CA6FF,#FFFFFF,#B04CF0,#FF7A00,#FF6EC7,#2EE6D6,#A8E82A", "Цвета точек (hex через запятую). Первая точка в панели — без цвета");
		CfgSizes = ((BaseUnityPlugin)this).Config.Bind<string>("Style", "Sizes", "10,15,20,25,30,40,50,100,150,200,300", "Размеры шрифта в абсолютных единицах (тег <size=N>), через запятую");
		CfgStamps = ((BaseUnityPlugin)this).Config.Bind<string>("Style", "Stamps", "1=|2=|3=|4=|5=|6=", "Шаблоны: слоты через '|', формат Номер=Вставка (вставка пуста = кнопки нет). \\n = новая строка. Пример: 1=<color=white><size=30>Ресурсы");
		Harmony.CreateAndPatchAll(typeof(SignStylerPatches), "DEEP_FROST.SignStyler");
		object obj = <>c.<>9__7_0;
		if (obj == null)
		{
			ConsoleEvent val = delegate(ConsoleEventArgs args)
			{
				ApplyToHoveredSign(BuildTestText(args));
			};
			<>c.<>9__7_0 = val;
			obj = (object)val;
		}
		new ConsoleCommand("signtest", "signtest [текст] — применить тестовый стиль к знаку под прицелом (отладка)", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		object obj2 = <>c.<>9__7_1;
		if (obj2 == null)
		{
			ConsoleEvent val2 = delegate
			{
				LogFonts(force: true);
			};
			<>c.<>9__7_1 = val2;
			obj2 = (object)val2;
		}
		new ConsoleCommand("signfonts", "список TMP-шрифтов, загруженных в памяти (отладка)", (ConsoleEvent)obj2, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		ZLog.Log((object)"[SignStyler] 0.4.1 загружен");
	}

	private static string BuildTestText(ConsoleEventArgs args)
	{
		string text = "Кузница";
		if (args != null && args.Args != null && args.Args.Length > 1)
		{
			text = string.Join(" ", args.Args, 1, args.Args.Length - 1);
		}
		return "<color=#FF3B30><size=40>" + text + "</size></color>";
	}

	private static Sign FindHoveredSign()
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)GameCamera.instance))
		{
			return null;
		}
		int num = -5;
		if (AccessTools.Field(typeof(Player), "m_removeRayMask")?.GetValue(localPlayer) is LayerMask val)
		{
			num = LayerMask.op_Implicit(val);
		}
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val2, 50f, num))
		{
			return ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Sign>();
		}
		return null;
	}

	private static void ApplyToHoveredSign(string styledText)
	{
		Sign val = FindHoveredSign();
		if ((Object)(object)val == (Object)null)
		{
			ZLog.Log((object)"[SignStyler] signtest: знак под прицелом не найден");
			MessageHud.instance.ShowMessage((MessageType)2, "[SignStyler] Наведи прицел на знак и повтори signtest", 0, (Sprite)null, false, true);
		}
		else
		{
			ZLog.Log((object)("[SignStyler] signtest: применяю к знаку '" + ((Object)val).name + "': " + styledText));
			val.SetText(styledText);
			MessageHud.instance.ShowMessage((MessageType)2, "[SignStyler] Применено — смотри на табличку", 0, (Sprite)null, false, true);
		}
	}

	internal static void LogFonts(bool force)
	{
		if (!_fontsLogged || force)
		{
			_fontsLogged = true;
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append($"[SignStyler] TMP-шрифтов в памяти: {array.Length}");
			TMP_FontAsset[] array2 = array;
			foreach (TMP_FontAsset val in array2)
			{
				stringBuilder.Append("\n[SignStyler]   font: ").Append(((Object)val).name);
			}
			ZLog.Log((object)stringBuilder.ToString());
		}
	}
}
public static class SignStylerPatches
{
	private static Sign GetQueuedSign(TextInput ti)
	{
		object? obj = AccessTools.Field(typeof(TextInput), "m_queuedSign")?.GetValue(ti);
		return (Sign)((obj is Sign) ? obj : null);
	}

	[HarmonyPatch(typeof(TextInput), "Show")]
	[HarmonyPostfix]
	private static void AfterShow(TextInput __instance)
	{
		try
		{
			bool num = (Object)(object)GetQueuedSign(__instance) != (Object)null;
			SignStylerUI.EnsureBuilt(__instance);
			SignStylerUI.SetVisible(num);
			if (num)
			{
				TMP_InputField inputField = (TMP_InputField)(object)__instance.m_inputField;
				string text = SignStylerUI.StripTags(inputField.text);
				if (text != inputField.text)
				{
					inputField.text = text;
				}
				SignStylerUI.RefreshPreview();
			}
		}
		catch (Exception ex)
		{
			ZLog.LogError((object)("[SignStyler] Show postfix: " + ex));
		}
	}

	[HarmonyPatch(typeof(TextInput), "OnEnter")]
	[HarmonyPrefix]
	private static void BeforeOnEnter(TextInput __instance)
	{
		Compose(__instance);
	}

	[HarmonyPatch(typeof(TextInput), "OnInput")]
	[HarmonyPrefix]
	private static void BeforeOnInput(TextInput __instance)
	{
		Compose(__instance);
	}

	private static void Compose(TextInput ti)
	{
		try
		{
			if ((Object)(object)GetQueuedSign(ti) == (Object)null)
			{
				return;
			}
			TMP_InputField inputField = (TMP_InputField)(object)ti.m_inputField;
			if (!((Object)(object)inputField == (Object)null))
			{
				string text = SignStylerUI.ComposeStyled(inputField.text);
				if (text != inputField.text)
				{
					inputField.text = text;
					ZLog.Log((object)("[SignStyler] OK: пишу в знак: " + text));
				}
			}
		}
		catch (Exception ex)
		{
			ZLog.LogError((object)("[SignStyler] Compose: " + ex));
		}
	}
}
public static class SignStylerUI
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static UnityAction <>9__19_0;

		public static UnityAction <>9__19_1;

		public static UnityAction<string> <>9__19_2;

		internal void <Build>b__19_0()
		{
			int num = Sizes().Length + 1;
			_sizeIdx = (_sizeIdx - 1 + num) % num;
			RefreshPreview();
		}

		internal void <Build>b__19_1()
		{
			int num = Sizes().Length + 1;
			_sizeIdx = (_sizeIdx + 1) % num;
			RefreshPreview();
		}

		internal void <Build>b__19_2(string s)
		{
			RefreshPreview();
		}
	}

	private static GameObject _drawer;

	private static TMP_Text _preview;

	private static TMP_Text _sizeValue;

	private static readonly List<GameObject> _dots = new List<GameObject>();

	private static Sprite _circle;

	private static int _colorIdx;

	private static int _sizeIdx;

	private static string[] Colors()
	{
		return Split(SignStylerPlugin.CfgColors.Value);
	}

	private static string[] Sizes()
	{
		return Split(SignStylerPlugin.CfgSizes.Value);
	}

	private static string[][] Stamps()
	{
		string[] array = (SignStylerPlugin.CfgStamps.Value ?? "").Split('|');
		List<string[]> list = new List<string[]>();
		string[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			string text = array2[i].Trim();
			if (text.Length == 0)
			{
				continue;
			}
			int num = text.IndexOf('=');
			if (num > 0)
			{
				string text2 = text.Substring(num + 1);
				if (text2.Trim().Length != 0)
				{
					list.Add(new string[2]
					{
						text.Substring(0, num),
						text2
					});
				}
			}
		}
		return list.ToArray();
	}

	private static string[] Split(string csv)
	{
		string[] array = (csv ?? "").Split(',');
		List<string> list = new List<string>();
		string[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			string text = array2[i].Trim();
			if (text.Length > 0)
			{
				list.Add(text);
			}
		}
		return list.ToArray();
	}

	internal static void EnsureBuilt(TextInput ti)
	{
		if ((Object)(object)_drawer != (Object)null)
		{
			return;
		}
		try
		{
			Build(ti);
		}
		catch (Exception ex)
		{
			ZLog.LogError((object)("[SignStyler] построение панели упало: " + ex));
		}
	}

	internal static void SetVisible(bool visible)
	{
		if ((Object)(object)_drawer != (Object)null)
		{
			_drawer.SetActive(visible);
		}
	}

	internal static string StripTags(string s)
	{
		if (s == null)
		{
			return "";
		}
		return Regex.Replace(s, "<[^>]*>", "");
	}

	internal static string ComposeStyled(string raw)
	{
		if (string.IsNullOrEmpty(raw))
		{
			return raw;
		}
		bool flag = _colorIdx > 0;
		bool flag2 = _sizeIdx > 0;
		if (!flag && !flag2)
		{
			return raw;
		}
		StringBuilder stringBuilder = new StringBuilder();
		if (flag)
		{
			stringBuilder.Append("<color=").Append(Colors()[_colorIdx - 1]).Append(">");
		}
		if (flag2)
		{
			stringBuilder.Append("<size=").Append(Sizes()[_sizeIdx - 1]).Append(">");
		}
		stringBuilder.Append(raw);
		if (flag2)
		{
			stringBuilder.Append("</size>");
		}
		if (flag)
		{
			stringBuilder.Append("</color>");
		}
		return stringBuilder.ToString();
	}

	internal static void RefreshPreview()
	{
		if ((Object)(object)_preview == (Object)null)
		{
			return;
		}
		string text = CurrentInputText().Replace("\\n", "\n");
		if (string.IsNullOrEmpty(StripTags(text)))
		{
			text = "Превью";
		}
		string text2 = "";
		string text3 = "";
		if (_colorIdx > 0)
		{
			text2 = text2 + "<color=" + Colors()[_colorIdx - 1] + ">";
			text3 = "</color>" + text3;
		}
		if (_sizeIdx > 0)
		{
			if (int.TryParse(Sizes()[_sizeIdx - 1], out var result))
			{
				_preview.fontSize = Mathf.Clamp((float)result * 0.8f, 12f, 40f);
			}
		}
		else
		{
			_preview.fontSize = 22f;
		}
		_preview.text = text2 + text + text3;
		if ((Object)(object)_sizeValue != (Object)null)
		{
			_sizeValue.text = ((_sizeIdx == 0) ? "обычный" : Sizes()[_sizeIdx - 1]);
		}
		UpdateDotHighlight();
	}

	private static void UpdateDotHighlight()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < _dots.Count; i++)
		{
			if ((Object)(object)_dots[i] != (Object)null)
			{
				float num = ((i + 1 == _colorIdx) ? 1.25f : 1f);
				((Transform)_dots[i].GetComponent<RectTransform>()).localScale = new Vector3(num, num, 1f);
			}
		}
	}

	private static string CurrentInputText()
	{
		TextInput instance = TextInput.instance;
		if ((Object)(object)instance != (Object)null && (Object)(object)instance.m_inputField != (Object)null)
		{
			return ((TMP_InputField)instance.m_inputField).text ?? "";
		}
		return "";
	}

	private static Sprite CircleSprite()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_circle != (Object)null)
		{
			return _circle;
		}
		int num = 64;
		Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
		float num2 = (float)(num - 1) / 2f;
		float num3 = (float)num / 2f - 2f;
		Color val2 = default(Color);
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num4 = Mathf.Sqrt(((float)j - num2) * ((float)j - num2) + ((float)i - num2) * ((float)i - num2));
				if (num4 > num3 + 1f)
				{
					((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
				}
				else if (num4 > num3 - 2f)
				{
					((Color)(ref val2))..ctor(0.16f, 0.13f, 0.1f, 1f);
				}
				else
				{
					((Color)(ref val2))..ctor(1f, 1f, 1f, 1f);
				}
				val.SetPixel(j, i, val2);
			}
		}
		val.Apply();
		_circle = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f));
		return _circle;
	}

	private static void Build(TextInput ti)
	{
		//IL_003b: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//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_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Expected O, but got Unknown
		//IL_0140: 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_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Invalid comparison between Unknown and I4
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Expected O, but got Unknown
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_0446: Unknown result type (might be due to invalid IL or missing references)
		//IL_0465: Unknown result type (might be due to invalid IL or missing references)
		//IL_0480: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_050d: Unknown result type (might be due to invalid IL or missing references)
		//IL_049e: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a9: Expected O, but got Unknown
		//IL_052b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0530: Unknown result type (might be due to invalid IL or missing references)
		//IL_0536: Expected O, but got Unknown
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03af: Expected O, but got Unknown
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Unknown result type (might be due to invalid IL or missing references)
		//IL_056a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0589: Unknown result type (might be due to invalid IL or missing references)
		//IL_061a: 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)
		//IL_0635: Unknown result type (might be due to invalid IL or missing references)
		//IL_063f: Expected O, but got Unknown
		Image val = null;
		float num = 0f;
		StringBuilder stringBuilder = new StringBuilder("[SignStyler] иерархия TextInput:");
		Image[] componentsInChildren = ti.m_panel.GetComponentsInChildren<Image>(true);
		Rect rect;
		foreach (Image val2 in componentsInChildren)
		{
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			rect = rectTransform.rect;
			float width = ((Rect)(ref rect)).width;
			rect = rectTransform.rect;
			float num2 = width * ((Rect)(ref rect)).height;
			StringBuilder stringBuilder2 = stringBuilder.Append("\n[SignStyler]   Image '").Append(((Object)((Component)val2).gameObject).name).Append("' ");
			rect = rectTransform.rect;
			StringBuilder stringBuilder3 = stringBuilder2.Append(((Rect)(ref rect)).width).Append("x");
			rect = rectTransform.rect;
			stringBuilder3.Append(((Rect)(ref rect)).height);
			if (num2 > num)
			{
				num = num2;
				val = val2;
			}
		}
		ZLog.Log((object)stringBuilder.ToString());
		if ((Object)(object)val == (Object)null)
		{
			ZLog.LogError((object)"[SignStyler] фон диалога не найден");
			return;
		}
		GameObject val3 = new GameObject("SignStylerDrawer", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val3.transform.SetParent((Transform)(object)((Graphic)val).rectTransform, false);
		RectTransform component = val3.GetComponent<RectTransform>();
		component.anchorMin = new Vector2(0.5f, 0f);
		component.anchorMax = new Vector2(0.5f, 0f);
		component.pivot = new Vector2(0.5f, 1f);
		component.anchoredPosition = new Vector2(0f, -8f);
		rect = ((Graphic)val).rectTransform.rect;
		float width2 = ((Rect)(ref rect)).width;
		float num3 = 214f;
		component.sizeDelta = new Vector2(width2, num3);
		Image component2 = val3.GetComponent<Image>();
		component2.sprite = val.sprite;
		component2.type = (Type)(((Object)(object)val.sprite != (Object)null && (int)val.type == 1) ? 1 : 0);
		((Graphic)component2).color = ((Graphic)val).color;
		_drawer = val3;
		val3.SetActive(false);
		_preview = MakeLabel(ti, val3.transform, "preview", width2 - 24f, 48f, new Vector2(12f, -10f), 22f, (TextAlignmentOptions)4098);
		((Graphic)_preview).color = new Color(0.118f, 0.102f, 0.071f, 1f);
		TMP_Text obj = MakeLabel(ti, val3.transform, "colorcap", 96f, 30f, new Vector2(16f, -66f), 18f, (TextAlignmentOptions)4097);
		obj.text = "Цвет:";
		((Graphic)obj).color = Color.white;
		string[] array = Colors();
		float num4 = 114f;
		Color white = default(Color);
		for (int j = 0; j < array.Length; j++)
		{
			string text = array[j];
			GameObject val4 = new GameObject("SignStylerDot" + j, new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val4.transform.SetParent(val3.transform, false);
			RectTransform component3 = val4.GetComponent<RectTransform>();
			component3.sizeDelta = new Vector2(28f, 28f);
			Image component4 = val4.GetComponent<Image>();
			component4.sprite = CircleSprite();
			if (!ColorUtility.TryParseHtmlString(text.StartsWith("#") ? text : ("#" + text), ref white))
			{
				white = Color.white;
			}
			((Graphic)component4).color = white;
			int idx = j + 1;
			((UnityEvent)val4.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				_colorIdx = ((_colorIdx != idx) ? idx : 0);
				RefreshPreview();
			});
			component3.anchorMin = new Vector2(0f, 1f);
			component3.anchorMax = new Vector2(0f, 1f);
			component3.pivot = new Vector2(0f, 1f);
			component3.anchoredPosition = new Vector2(num4, -66f);
			_dots.Add(val4);
			num4 += 40f;
		}
		TMP_Text obj2 = MakeLabel(ti, val3.transform, "sizecap", 96f, 30f, new Vector2(16f, -104f), 18f, (TextAlignmentOptions)4097);
		obj2.text = "Размер:";
		((Graphic)obj2).color = Color.white;
		Transform transform = val3.transform;
		Vector2 pos = new Vector2(118f, -104f);
		object obj3 = <>c.<>9__19_0;
		if (obj3 == null)
		{
			UnityAction val5 = delegate
			{
				int num7 = Sizes().Length + 1;
				_sizeIdx = (_sizeIdx - 1 + num7) % num7;
				RefreshPreview();
			};
			<>c.<>9__19_0 = val5;
			obj3 = (object)val5;
		}
		MakeArrowButton(ti, transform, pos, "‹", (UnityAction)obj3);
		_sizeValue = MakeLabel(ti, val3.transform, "sizeval", width2 - 356f, 30f, new Vector2(178f, -104f), 18f, (TextAlignmentOptions)4098);
		((Graphic)_sizeValue).color = Color.white;
		Transform transform2 = val3.transform;
		Vector2 pos2 = new Vector2(width2 - 158f, -104f);
		object obj4 = <>c.<>9__19_1;
		if (obj4 == null)
		{
			UnityAction val6 = delegate
			{
				int num7 = Sizes().Length + 1;
				_sizeIdx = (_sizeIdx + 1) % num7;
				RefreshPreview();
			};
			<>c.<>9__19_1 = val6;
			obj4 = (object)val6;
		}
		MakeArrowButton(ti, transform2, pos2, "›", (UnityAction)obj4);
		string[][] array2 = Stamps();
		if (array2.Length != 0)
		{
			TMP_Text obj5 = MakeLabel(ti, val3.transform, "stampcap", 96f, 30f, new Vector2(16f, -146f), 18f, (TextAlignmentOptions)4097);
			obj5.text = "Шаблон:";
			((Graphic)obj5).color = Color.white;
			float num5 = 118f;
			string[][] array3 = array2;
			foreach (string[] array4 in array3)
			{
				string text2 = array4[0];
				string snippet = array4[1];
				float num6 = Mathf.Max(40f, 24f + (float)text2.Length * 12f);
				if (num5 + num6 > width2 - 12f)
				{
					ZLog.LogWarning((object)("[SignStyler] шаблон '" + text2 + "' не влез в панель"));
					break;
				}
				MakeStampButton(ti, val3.transform, new Vector2(num5, -146f), new Vector2(num6, 30f), text2, (UnityAction)delegate
				{
					TextInput instance = TextInput.instance;
					if ((Object)(object)instance != (Object)null && (Object)(object)instance.m_inputField != (Object)null)
					{
						((TMP_InputField)instance.m_inputField).text = snippet;
						RefreshPreview();
					}
				});
				num5 += num6 + 8f;
			}
		}
		TMP_InputField inputField = (TMP_InputField)(object)ti.m_inputField;
		if ((Object)(object)inputField != (Object)null)
		{
			((UnityEvent<string>)(object)inputField.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				RefreshPreview();
			});
		}
		RefreshPreview();
		ZLog.Log((object)$"[SignStyler] панель построена: {width2}x{num3}, цветов {array.Length}, размеров {Sizes().Length}, шаблонов {array2.Length}");
	}

	private static TMP_Text MakeLabel(TextInput ti, Transform parent, string name, float width, float height, Vector2 posFromLeftTop, float fontSize, TextAlignmentOptions align)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = Object.Instantiate<GameObject>(((Component)ti.m_topic).gameObject, parent);
		((Object)obj).name = "SignStyler_" + name;
		TMP_Text component = obj.GetComponent<TMP_Text>();
		component.fontSize = fontSize;
		component.alignment = align;
		component.text = "";
		component.enableWordWrapping = false;
		((Graphic)component).raycastTarget = false;
		RectTransform component2 = obj.GetComponent<RectTransform>();
		component2.anchorMin = new Vector2(0f, 1f);
		component2.anchorMax = new Vector2(0f, 1f);
		component2.pivot = new Vector2(0f, 1f);
		component2.sizeDelta = new Vector2(width, height);
		component2.anchoredPosition = posFromLeftTop;
		return component;
	}

	private static Image FindPanelBackground(TextInput ti)
	{
		//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_003a: 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)
		Image result = null;
		float num = 0f;
		Image[] componentsInChildren = ti.m_panel.GetComponentsInChildren<Image>(true);
		foreach (Image val in componentsInChildren)
		{
			Rect rect = ((Graphic)val).rectTransform.rect;
			float width = ((Rect)(ref rect)).width;
			rect = ((Graphic)val).rectTransform.rect;
			float num2 = width * ((Rect)(ref rect)).height;
			if (num2 > num)
			{
				num = num2;
				result = val;
			}
		}
		return result;
	}

	private static void MakeArrowButton(TextInput ti, Transform parent, Vector2 pos, string text, UnityAction onClick)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		MakeStampButton(ti, parent, pos, new Vector2(40f, 30f), text, onClick);
	}

	private static void MakeStampButton(TextInput ti, Transform parent, Vector2 pos, Vector2 size, string text, UnityAction onClick)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("SignStylerBtn", new Type[3]
		{
			typeof(RectTransform),
			typeof(Image),
			typeof(Button)
		});
		val.transform.SetParent(parent, false);
		RectTransform component = val.GetComponent<RectTransform>();
		component.anchorMin = new Vector2(0f, 1f);
		component.anchorMax = new Vector2(0f, 1f);
		component.pivot = new Vector2(0f, 1f);
		component.sizeDelta = size;
		component.anchoredPosition = new Vector2(pos.x, pos.y);
		Image component2 = val.GetComponent<Image>();
		Image val2 = FindPanelBackground(ti);
		if ((Object)(object)val2 != (Object)null && (Object)(object)val2.sprite != (Object)null)
		{
			component2.sprite = val2.sprite;
			component2.type = (Type)1;
			((Graphic)component2).color = new Color(0.85f, 0.8f, 0.7f, 1f);
		}
		TMP_Text obj = MakeLabel(ti, val.transform, "lbl", size.x, size.y, new Vector2(0f, 2f), Mathf.Min(20f, size.y - 6f), (TextAlignmentOptions)4098);
		obj.text = text;
		((Graphic)obj).color = new Color(0.95f, 0.87f, 0.6f, 1f);
		obj.enableWordWrapping = false;
		((UnityEvent)val.GetComponent<Button>().onClick).AddListener(onClick);
	}
}