Decompiled source of RoguelikeCharacterSearchBar v0.1.0

plugins/RoguelikeCharacterSearchBar/RoguelikeCharacterSearchBar.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Burst2Flame.Observable;
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 = "")]
[assembly: AssemblyCompany("RoguelikeCharacterSearchBar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds an incremental search box to the Roguelike character creation (class cards) and to the character selection screen (available characters, matched by name or class). Visual only: no gameplay, save or preset change.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("RoguelikeCharacterSearchBar")]
[assembly: AssemblyTitle("RoguelikeCharacterSearchBar")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace RoguelikeCharacterSearchBar;

internal sealed class CreationSearchField : MonoBehaviour
{
	private const float HorizontalInset = 18f;

	private const float VerticalInset = 10f;

	private InputField input;

	private CanvasGroup placeholder;

	private float placeholderAlpha;

	internal static CreationSearchField Create(RectTransform panel, RectTransform header, InputField template, string boxName, UnityAction<string> onChanged)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: 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_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Expected O, but got Unknown
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: 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)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Expected O, but got Unknown
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Expected O, but got Unknown
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Expected O, but got Unknown
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)panel == (Object)null) && !((Object)(object)header == (Object)null) && !((Object)(object)template == (Object)null) && !((Object)(object)template.textComponent == (Object)null))
		{
			Transform transform = ((Component)template).transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (val != null && !((Object)(object)((Transform)val).parent != (Object)(object)panel))
			{
				GameObject val2 = new GameObject("RCS Search Dock (Creation)", new Type[2]
				{
					typeof(RectTransform),
					typeof(LayoutElement)
				});
				val2.SetActive(false);
				RectTransform val3 = (RectTransform)val2.transform;
				((Transform)val3).SetParent((Transform)(object)panel, false);
				Vector2 val4 = default(Vector2);
				((Vector2)(ref val4))..ctor(0f, 1f);
				val3.anchorMax = val4;
				val3.anchorMin = val4;
				val3.pivot = new Vector2(1f, 0.5f);
				Rect rect = header.rect;
				float y = ((Transform)panel).InverseTransformPoint(((Transform)header).TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center))).y;
				rect = panel.rect;
				val3.anchoredPosition = new Vector2(0f, y - ((Rect)(ref rect)).yMax);
				rect = val.rect;
				val3.sizeDelta = Vector2.Scale(((Rect)(ref rect)).size, Vector2.op_Implicit(((Transform)val).localScale)) + new Vector2(36f, 20f);
				val2.GetComponent<LayoutElement>().ignoreLayout = true;
				CopyPanelSkin(val2, ((Component)panel).GetComponent<Image>());
				InputField val5 = Object.Instantiate<InputField>(template, (Transform)(object)val3, false);
				((Object)val5).name = boxName;
				RectTransform val6 = (RectTransform)((Component)val5).transform;
				((Vector2)(ref val4))..ctor(1f, 0.5f);
				val6.anchorMax = val4;
				val6.anchorMin = val4;
				val6.pivot = new Vector2(1f, 0.5f);
				val6.anchoredPosition = new Vector2(-18f, 0f);
				rect = val.rect;
				val6.sizeDelta = ((Rect)(ref rect)).size;
				((Transform)val6).localScale = ((Transform)val).localScale;
				((Transform)val6).localRotation = Quaternion.identity;
				Transform val7 = ((Component)val5).transform.Find(((Object)template).name + " Input Caret");
				if ((Object)(object)val7 != (Object)null)
				{
					((Component)val7).gameObject.SetActive(false);
					Object.Destroy((Object)(object)((Component)val7).gameObject);
				}
				val5.onValueChanged = new OnChangeEvent();
				val5.onEndEdit = new EndEditEvent();
				val5.onSubmit = new SubmitEvent();
				val5.onValidateInput = null;
				val5.SetTextWithoutNotify(string.Empty);
				val5.characterLimit = 32;
				val5.contentType = (ContentType)0;
				val5.lineType = (LineType)0;
				((UnityEvent<string>)(object)val5.onValueChanged).AddListener(onChanged);
				CreationSearchField creationSearchField = val2.AddComponent<CreationSearchField>();
				creationSearchField.ConfigureFocus(val5);
				((Component)val5).gameObject.SetActive(true);
				val2.SetActive(true);
				return creationSearchField;
			}
		}
		return null;
	}

	private static void CopyPanelSkin(GameObject dock, Image source)
	{
		//IL_001e: 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)
		if (!((Object)(object)source == (Object)null))
		{
			Image obj = dock.AddComponent<Image>();
			obj.sprite = source.overrideSprite;
			obj.type = source.type;
			obj.fillCenter = source.fillCenter;
			obj.pixelsPerUnitMultiplier = source.pixelsPerUnitMultiplier;
			((Graphic)obj).color = ((Graphic)source).color;
			((Graphic)obj).material = ((Graphic)source).material;
			((Graphic)obj).raycastTarget = false;
		}
	}

	private void ConfigureFocus(InputField search)
	{
		//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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		input = search;
		Color color = ((Graphic)input.textComponent).color;
		color.a = 1f;
		input.shouldActivateOnSelect = true;
		input.customCaretColor = true;
		input.caretColor = color;
		input.caretWidth = Mathf.Max(2, input.caretWidth);
		input.caretBlinkRate = ((input.caretBlinkRate > 0f) ? input.caretBlinkRate : 0.85f);
		Graphic val = input.placeholder;
		if (!((Object)(object)val == (Object)null))
		{
			UiPlacement.SetPlaceholder(input, OptionsManager.Localize("Search", (LanguageGender)0, (Gender)2));
			val.color = color;
			placeholder = ((Component)val).GetComponent<CanvasGroup>();
			if ((Object)(object)placeholder == (Object)null)
			{
				placeholder = ((Component)val).gameObject.AddComponent<CanvasGroup>();
			}
			placeholderAlpha = placeholder.alpha;
		}
	}

	private void LateUpdate()
	{
		if (!((Object)(object)input == (Object)null) && !((Object)(object)placeholder == (Object)null))
		{
			float num = (input.isFocused ? 0f : placeholderAlpha);
			if (placeholder.alpha != num)
			{
				placeholder.alpha = num;
			}
		}
	}

	private void OnDisable()
	{
		if ((Object)(object)placeholder != (Object)null)
		{
			placeholder.alpha = placeholderAlpha;
		}
	}
}
internal sealed class CreationSearchUi : MonoBehaviour
{
	private const string BoxName = "RCS Search (Creation)";

	private readonly HashSet<GameObject> hiddenByUs = new HashSet<GameObject>();

	private PresetManager manager;

	private CreationSearchField field;

	private string query = string.Empty;

	private bool announcedDiagnostics;

	internal void Ensure(PresetManager presetManager)
	{
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Expected O, but got Unknown
		if ((Object)(object)presetManager == (Object)null)
		{
			return;
		}
		manager = presetManager;
		GameObject rogulikeWindow = presetManager.RogulikeWindow;
		if (!((Object)(object)rogulikeWindow == (Object)null))
		{
			Transform transform = rogulikeWindow.transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (val != null)
			{
				if (!rogulikeWindow.activeInHierarchy)
				{
					return;
				}
				if ((Object)(object)field != (Object)null)
				{
					if ((Object)(object)((Component)field).transform.parent == (Object)(object)val)
					{
						Apply();
						return;
					}
					DestroyBox();
				}
				Transform obj = ((Transform)val).Find("Header");
				RectTransform header = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				field = CreationSearchField.Create(val, header, presetManager.nameFieldRoguelike, "RCS Search (Creation)", OnChanged);
				if ((Object)(object)field == (Object)null)
				{
					Plugin.Log.LogWarning((object)"RCS: cabecalho ou campo de nome nativo indisponivel; busca da criacao nao criada.");
					return;
				}
				query = string.Empty;
				LogDiagnostics(val, (RectTransform)((Component)field).transform);
				Plugin.Log.LogInfo((object)"RCS: caixa de busca criada na tela de criacao.");
				return;
			}
		}
		Plugin.Log.LogWarning((object)"RCS: RogulikeWindow nulo; caixa de busca da criacao nao criada.");
	}

	private void LateUpdate()
	{
		if (!((Object)(object)field == (Object)null) && !((Object)(object)manager == (Object)null))
		{
			GameObject rogulikeWindow = manager.RogulikeWindow;
			if ((Object)(object)rogulikeWindow == (Object)null || !rogulikeWindow.activeInHierarchy)
			{
				Restore();
			}
			else if (Time.frameCount % 15 == 0)
			{
				Apply();
			}
		}
	}

	internal void Apply()
	{
		if ((Object)(object)manager == (Object)null)
		{
			return;
		}
		List<CharacterPresetTile> characterPresetTiles = manager.CharacterPresetTiles;
		if (characterPresetTiles == null)
		{
			return;
		}
		CharacterPresetFile characterPreset = manager.CharacterPreset;
		foreach (CharacterPresetTile item in characterPresetTiles)
		{
			if (!((Object)(object)item == (Object)null))
			{
				CharacterPresetFile characterPresetFile = item.CharacterPresetFile;
				bool matches = (Object)(object)characterPresetFile == (Object)null || (Object)(object)characterPresetFile == (Object)(object)characterPreset || SearchQuery.Matches(query, SearchTargets.Fields(characterPresetFile));
				TileVisibility.Apply(((Component)item).gameObject, matches, hiddenByUs);
			}
		}
	}

	private void OnChanged(string value)
	{
		query = value ?? string.Empty;
		Apply();
	}

	private void Restore()
	{
		if (hiddenByUs.Count > 0)
		{
			TileVisibility.RestoreAll(hiddenByUs);
		}
	}

	private void OnDisable()
	{
		Restore();
	}

	private void DestroyBox()
	{
		Restore();
		if ((Object)(object)field != (Object)null)
		{
			((Component)field).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)field).gameObject);
			field = null;
		}
		query = string.Empty;
	}

	private void LogDiagnostics(RectTransform panel, RectTransform dock)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		if (!announcedDiagnostics)
		{
			announcedDiagnostics = true;
			ManualLogSource log = Plugin.Log;
			string name = ((Object)panel).name;
			Rect rect = dock.rect;
			object arg = ((Rect)(ref rect)).width;
			rect = dock.rect;
			log.LogInfo((object)$"RCS DIAG criacao layout=left-of-panel panel='{name}' dock={arg:F1}x{((Rect)(ref rect)).height:F1}");
		}
	}
}
internal static class SearchPatch
{
	internal static void Run(Action update, string surface)
	{
		try
		{
			update();
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"RCS: {surface}: {arg}");
		}
	}
}
[HarmonyPatch(typeof(PresetManager), "OpenWindow", new Type[] { })]
internal static class Patch_CreationWindow
{
	[HarmonyPostfix]
	private static void Postfix(PresetManager __instance)
	{
		SearchPatch.Run(delegate
		{
			SearchCoordinator.OnCreationOpened(__instance);
		}, "creation");
	}
}
[HarmonyPatch(typeof(PresetManager), "UpdateRoguelikeCharacterPresetTiles", new Type[] { })]
internal static class Patch_PresetTiles
{
	[HarmonyPostfix]
	private static void Postfix(PresetManager __instance)
	{
		SearchPatch.Run(delegate
		{
			SearchCoordinator.OnPresetTilesRebuilt(__instance);
		}, "preset list");
	}
}
[HarmonyPatch(typeof(CharacterChoiceManager), "OpenWindow", new Type[] { })]
internal static class Patch_SelectionWindow
{
	[HarmonyPostfix]
	private static void Postfix(CharacterChoiceManager __instance)
	{
		SearchPatch.Run(delegate
		{
			SearchCoordinator.OnSelectionOpened(__instance);
		}, "selection");
	}
}
[BepInPlugin("com.gumatos.roguelikecharactersearchbar", "Roguelike Character Search Bar", "0.1.0")]
[BepInIncompatibility("com.gumatos.roguelikecharactersearch")]
public sealed class Plugin : BaseUnityPlugin
{
	public const string Guid = "com.gumatos.roguelikecharactersearchbar";

	public const string Version = "0.1.0";

	internal static ManualLogSource Log { get; private set; }

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("com.gumatos.roguelikecharactersearchbar");
		int num = 0;
		Type[] array = new Type[3]
		{
			typeof(Patch_CreationWindow),
			typeof(Patch_PresetTiles),
			typeof(Patch_SelectionWindow)
		};
		foreach (Type type in array)
		{
			try
			{
				val.CreateClassProcessor(type).Patch();
				num++;
				Log.LogInfo((object)("RCS: gancho " + type.Name + " aplicado."));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("RCS: gancho " + type.Name + " FALHOU: " + ex));
			}
		}
		Log.LogInfo((object)"Roguelike Character Search Bar 0.1.0 carregado.");
		Log.LogInfo((object)("RCS: " + num + "/3 ganchos aplicados."));
	}
}
internal static class SearchCoordinator
{
	internal static void OnCreationOpened(PresetManager manager)
	{
		if (!((Object)(object)manager == (Object)null) && !((Object)(object)manager.RogulikeWindow == (Object)null) && manager.RogulikeWindow.activeInHierarchy)
		{
			CreationSearchUi creationSearchUi = ((Component)manager).GetComponent<CreationSearchUi>();
			if ((Object)(object)creationSearchUi == (Object)null)
			{
				creationSearchUi = ((Component)manager).gameObject.AddComponent<CreationSearchUi>();
			}
			creationSearchUi.Ensure(manager);
		}
	}

	internal static void OnPresetTilesRebuilt(PresetManager manager)
	{
		if (!((Object)(object)manager == (Object)null))
		{
			CreationSearchUi component = ((Component)manager).GetComponent<CreationSearchUi>();
			if ((Object)(object)component != (Object)null)
			{
				component.Apply();
			}
		}
	}

	internal static void OnSelectionOpened(CharacterChoiceManager manager)
	{
		if ((Object)(object)manager == (Object)null)
		{
			return;
		}
		SelectionSearchUi selectionSearchUi = ((Component)manager).GetComponent<SelectionSearchUi>();
		NetworkingManager instance = NetworkingManager.Instance;
		if (!((Object)(object)instance == (Object)null))
		{
			NetworkManager networkManager = instance.NetworkManager;
			if (networkManager != null)
			{
				Root root = ((Observer<Root>)(object)networkManager).Root;
				if (((root != null) ? new bool?(root.PlayingRoguelike) : ((bool?)null)) == true)
				{
					if ((Object)(object)selectionSearchUi == (Object)null)
					{
						selectionSearchUi = ((Component)manager).gameObject.AddComponent<SelectionSearchUi>();
					}
					selectionSearchUi.Ensure(manager);
					return;
				}
			}
		}
		if ((Object)(object)selectionSearchUi != (Object)null)
		{
			selectionSearchUi.Deactivate();
		}
	}
}
public static class SearchQuery
{
	public static string Normalize(string value)
	{
		if (string.IsNullOrEmpty(value))
		{
			return string.Empty;
		}
		string text = value.Normalize(NormalizationForm.FormD);
		StringBuilder stringBuilder = new StringBuilder(text.Length);
		bool flag = false;
		string text2 = text;
		foreach (char c in text2)
		{
			if (CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.NonSpacingMark)
			{
				continue;
			}
			if (char.IsWhiteSpace(c))
			{
				flag = stringBuilder.Length > 0;
				continue;
			}
			if (flag)
			{
				stringBuilder.Append(' ');
				flag = false;
			}
			stringBuilder.Append(char.ToLowerInvariant(c));
		}
		return stringBuilder.ToString();
	}

	public static bool Matches(string query, params string[] fields)
	{
		string text = Normalize(query);
		if (text.Length == 0)
		{
			return true;
		}
		StringBuilder stringBuilder = new StringBuilder();
		string[] array;
		if (fields != null)
		{
			array = fields;
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = Normalize(array[i]);
				if (text2.Length != 0)
				{
					if (stringBuilder.Length > 0)
					{
						stringBuilder.Append(' ');
					}
					stringBuilder.Append(text2);
				}
			}
		}
		string text3 = stringBuilder.ToString();
		array = text.Split(' ');
		foreach (string text4 in array)
		{
			if (text4.Length > 0 && text3.IndexOf(text4, StringComparison.Ordinal) < 0)
			{
				return false;
			}
		}
		return true;
	}
}
internal static class SearchTargets
{
	internal static string[] Fields(Character character)
	{
		if (character != null)
		{
			CharacterPresetFile characterPresetFile = character.CharacterPresetFile;
			string text = (((Object)(object)characterPresetFile != (Object)null) ? characterPresetFile.PresetName : string.Empty);
			return new string[3]
			{
				character.CharacterName,
				Localized(text),
				text
			};
		}
		return new string[1] { string.Empty };
	}

	internal static string[] Fields(CharacterPresetFile preset)
	{
		if (!((Object)(object)preset == (Object)null))
		{
			return new string[2]
			{
				Localized(preset.PresetName),
				preset.PresetName
			};
		}
		return new string[1] { string.Empty };
	}

	private static string Localized(string presetName)
	{
		if (!string.IsNullOrEmpty(presetName))
		{
			return OptionsManager.Localize(presetName, (LanguageGender)0, (Gender)2);
		}
		return string.Empty;
	}
}
internal sealed class SelectionSearchUi : MonoBehaviour
{
	private const string BoxName = "RCS Search (Selection)";

	private static readonly FieldInfo SlotsField = AccessTools.Field(typeof(CharacterChoiceManager), "notInPartySlots");

	private static readonly FieldInfo CharactersField = AccessTools.Field(typeof(CharacterChoiceManager), "notInPartyChars");

	private readonly HashSet<GameObject> hiddenByUs = new HashSet<GameObject>();

	private CharacterChoiceManager manager;

	private InputField box;

	private RectTransform title;

	private string query = string.Empty;

	private bool announcedDiagnostics;

	internal void Ensure(CharacterChoiceManager choiceManager)
	{
		if ((Object)(object)choiceManager == (Object)null)
		{
			return;
		}
		if (SlotsField?.FieldType != typeof(List<CharacterChoiceItem>) || CharactersField?.FieldType != typeof(List<Character>))
		{
			Plugin.Log.LogWarning((object)"RCS: lista nativa de personagens indisponivel; busca da selecao desativada.");
			return;
		}
		if ((Object)(object)manager != (Object)(object)choiceManager)
		{
			Deactivate();
			manager = choiceManager;
		}
		if ((Object)(object)box != (Object)null)
		{
			if ((Object)(object)title != (Object)null && (Object)(object)((Component)box).transform.parent == (Object)(object)((Transform)title).parent)
			{
				ResetQuery();
				return;
			}
			DestroyBox();
		}
		title = UiPlacement.FindTitle(((Component)choiceManager).transform, OptionsManager.Localize("Available Characters", (LanguageGender)0, (Gender)2));
		if (!((Object)(object)title == (Object)null))
		{
			Transform parent = ((Transform)title).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if (val != null)
			{
				box = UiPlacement.CreateBox(choiceManager.renameCharacterInput, val, "RCS Search (Selection)", OnChanged);
				ResetQuery();
				return;
			}
		}
		Plugin.Log.LogWarning((object)"RCS: cabecalho 'Available Characters' nao encontrado na selecao; caixa nao criada.");
	}

	private void LateUpdate()
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		if ((Object)(object)box == (Object)null || (Object)(object)manager == (Object)null)
		{
			return;
		}
		if (!((Component)manager).gameObject.activeInHierarchy)
		{
			Restore();
			return;
		}
		bool num = Time.frameCount % 15 == 0;
		if (num || !((Component)box).gameObject.activeSelf)
		{
			bool flag = UiPlacement.TryFitLeftOfTitle((RectTransform)((Component)box).transform, title);
			if (((Component)box).gameObject.activeSelf != flag)
			{
				if (!flag)
				{
					ResetQuery();
				}
				((Component)box).gameObject.SetActive(flag);
			}
			if (flag && !announcedDiagnostics)
			{
				announcedDiagnostics = true;
				Plugin.Log.LogInfo((object)"RCS: caixa de busca criada na tela de selecao.");
			}
		}
		if (num && ((Component)box).gameObject.activeSelf)
		{
			Apply();
		}
	}

	private void Apply()
	{
		ApplyToNativeSlots(query);
		if (query.Length == 0)
		{
			hiddenByUs.Clear();
		}
	}

	private void ApplyToNativeSlots(string filter)
	{
		if ((Object)(object)manager == (Object)null || !(SlotsField.GetValue(manager) is List<CharacterChoiceItem> list) || !(CharactersField.GetValue(manager) is List<Character> list2))
		{
			return;
		}
		CharacterChoiceItem selectedCharacterChoiceItem = manager.selectedCharacterChoiceItem;
		int num = Mathf.Min(list.Count, list2.Count);
		for (int i = 0; i < num; i++)
		{
			CharacterChoiceItem val = list[i];
			Character val2 = list2[i];
			if (!((Object)(object)val == (Object)null) && val2 != null && val.Character == val2 && !val2.IsDeleted && !val2.SelectedForBattle)
			{
				bool matches = filter.Length == 0 || (Object)(object)val == (Object)(object)selectedCharacterChoiceItem || SearchQuery.Matches(filter, SearchTargets.Fields(val2));
				TileVisibility.Apply(((Component)val).gameObject, matches, hiddenByUs);
			}
		}
	}

	private void OnChanged(string value)
	{
		query = value ?? string.Empty;
		Apply();
	}

	private void ResetQuery()
	{
		if ((Object)(object)box != (Object)null)
		{
			box.SetTextWithoutNotify(string.Empty);
		}
		query = string.Empty;
		Restore();
	}

	private void Restore()
	{
		if (hiddenByUs.Count > 0)
		{
			ApplyToNativeSlots(string.Empty);
			hiddenByUs.Clear();
		}
	}

	private void OnDisable()
	{
		Restore();
	}

	private void DestroyBox()
	{
		Restore();
		if ((Object)(object)box != (Object)null)
		{
			((Component)box).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)box).gameObject);
			box = null;
		}
		query = string.Empty;
	}

	internal void Deactivate()
	{
		DestroyBox();
		manager = null;
		title = null;
	}
}
internal static class TileVisibility
{
	internal static void Apply(GameObject target, bool matches, HashSet<GameObject> hiddenByUs)
	{
		if (!((Object)(object)target == (Object)null))
		{
			switch (VisibilityFilter.Decide(target.activeSelf, matches, hiddenByUs.Contains(target)))
			{
			case VisibilityAction.Hide:
				target.SetActive(false);
				hiddenByUs.Add(target);
				break;
			case VisibilityAction.Show:
				target.SetActive(true);
				hiddenByUs.Remove(target);
				break;
			}
		}
	}

	internal static void RestoreAll(HashSet<GameObject> hiddenByUs)
	{
		foreach (GameObject hiddenByU in hiddenByUs)
		{
			if ((Object)(object)hiddenByU != (Object)null && !hiddenByU.activeSelf)
			{
				hiddenByU.SetActive(true);
			}
		}
		hiddenByUs.Clear();
	}
}
internal static class UiPlacement
{
	private const float MaxWidth = 128f;

	private const float MinWidth = 68f;

	private const float BoxHeight = 30f;

	private const float Margin = 10f;

	internal static RectTransform FindTitle(Transform root, string title)
	{
		if ((Object)(object)root == (Object)null || string.IsNullOrEmpty(title))
		{
			return null;
		}
		TextMeshProUGUI[] componentsInChildren = ((Component)root).GetComponentsInChildren<TextMeshProUGUI>(true);
		foreach (TextMeshProUGUI val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)null) && !(((TMP_Text)val).text != title))
			{
				return ((TMP_Text)val).rectTransform;
			}
		}
		return null;
	}

	internal static InputField CreateBox(InputField template, RectTransform header, string boxName, UnityAction<string> onChanged)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Expected O, but got Unknown
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Expected O, but got Unknown
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Expected O, but got Unknown
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)template == (Object)null || (Object)(object)header == (Object)null)
		{
			return null;
		}
		GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject, (Transform)(object)header, false);
		val.SetActive(false);
		((Object)val).name = boxName;
		RectTransform val2 = (RectTransform)val.transform;
		val2.anchorMin = new Vector2(1f, 0.5f);
		val2.anchorMax = new Vector2(1f, 0.5f);
		val2.pivot = new Vector2(1f, 0.5f);
		val2.anchoredPosition = Vector2.zero;
		val2.sizeDelta = new Vector2(128f, 30f);
		((Transform)val2).localScale = Vector3.one;
		((Transform)val2).localRotation = Quaternion.identity;
		LayoutElement val3 = val.GetComponent<LayoutElement>();
		if ((Object)(object)val3 == (Object)null)
		{
			val3 = val.AddComponent<LayoutElement>();
		}
		val3.ignoreLayout = true;
		InputField component = val.GetComponent<InputField>();
		if ((Object)(object)component == (Object)null)
		{
			Plugin.Log.LogWarning((object)"RCS: o modelo clonado nao tem InputField; caixa descartada.");
			Object.Destroy((Object)(object)val);
			return null;
		}
		component.onValueChanged = new OnChangeEvent();
		component.onEndEdit = new EndEditEvent();
		component.onSubmit = new SubmitEvent();
		component.onValidateInput = null;
		component.SetTextWithoutNotify(string.Empty);
		component.characterLimit = 32;
		component.contentType = (ContentType)0;
		component.lineType = (LineType)0;
		((UnityEvent<string>)(object)component.onValueChanged).AddListener(onChanged);
		SetPlaceholder(component, OptionsManager.Localize("Search", (LanguageGender)0, (Gender)2));
		if ((Object)(object)component.placeholder != (Object)null && (Object)(object)component.textComponent != (Object)null)
		{
			component.placeholder.color = ((Graphic)component.textComponent).color;
		}
		return component;
	}

	internal static bool TryFitLeftOfTitle(RectTransform box, RectTransform title)
	{
		//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_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: 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)
		if (!((Object)(object)box == (Object)null) && !((Object)(object)title == (Object)null))
		{
			Transform parent = ((Transform)title).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if (val != null)
			{
				Transform parent2 = ((Transform)val).parent;
				RectTransform val2 = (RectTransform)(object)((parent2 is RectTransform) ? parent2 : null);
				if (val2 != null)
				{
					Rect rect = val2.rect;
					if (!(((Rect)(ref rect)).width <= 0f))
					{
						rect = title.rect;
						if (!(((Rect)(ref rect)).width <= 0f))
						{
							rect = val2.rect;
							float num = ((Transform)val).InverseTransformPoint(((Transform)val2).TransformPoint(((Rect)(ref rect)).xMin, 0f, 0f)).x + 10f;
							rect = title.rect;
							float num2 = ((Transform)val).InverseTransformPoint(((Transform)title).TransformPoint(((Rect)(ref rect)).xMin, 0f, 0f)).x - 10f;
							float num3 = Mathf.Min(128f, num2 - num);
							if (num3 < 68f)
							{
								return false;
							}
							Vector2 val3 = default(Vector2);
							((Vector2)(ref val3))..ctor(num3, 30f);
							float num4 = num + num3;
							rect = val.rect;
							Vector2 val4 = default(Vector2);
							((Vector2)(ref val4))..ctor(num4 - ((Rect)(ref rect)).xMax, 0f);
							if (box.sizeDelta != val3)
							{
								box.sizeDelta = val3;
							}
							if (box.anchoredPosition != val4)
							{
								box.anchoredPosition = val4;
							}
							return true;
						}
					}
				}
			}
		}
		return false;
	}

	internal static void SetPlaceholder(InputField input, string label)
	{
		Graphic placeholder = input.placeholder;
		if ((Object)(object)placeholder == (Object)null)
		{
			return;
		}
		TextMeshProUGUI val = (TextMeshProUGUI)(object)((placeholder is TextMeshProUGUI) ? placeholder : null);
		if (val != null)
		{
			((TMP_Text)val).text = label;
			return;
		}
		Text val2 = (Text)(object)((placeholder is Text) ? placeholder : null);
		if (val2 != null)
		{
			val2.text = label;
			return;
		}
		TextMeshProUGUI[] componentsInChildren = ((Component)placeholder).GetComponentsInChildren<TextMeshProUGUI>(true);
		int num = 0;
		if (num < componentsInChildren.Length)
		{
			((TMP_Text)componentsInChildren[num]).text = label;
		}
	}
}
public enum VisibilityAction
{
	None,
	Hide,
	Show
}
public static class VisibilityFilter
{
	public static VisibilityAction Decide(bool activeNow, bool matches, bool hiddenByUs)
	{
		if (!matches)
		{
			if (!activeNow)
			{
				return VisibilityAction.None;
			}
			return VisibilityAction.Hide;
		}
		if (!hiddenByUs)
		{
			return VisibilityAction.None;
		}
		return VisibilityAction.Show;
	}
}