Decompiled source of ZUI Lib v0.1.0
BepInEx/plugins/ZUI-Lib.dll
Decompiled 13 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.UI; using ZUI.Core; using ZUI.Debug; using ZUI.Fixes; using ZUI.MainMenu; using ZUI.Notifications; using ZUI.Panels; using ZUI.PauseMenu; using ZUI.Popups; using ZUI.Screens; using ZUI.Settings; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ZUI-Lib")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+6c82c8951c6081e3d853e59a6cb857ace3661501")] [assembly: AssemblyProduct("ZUI-Lib")] [assembly: AssemblyTitle("ZUI-Lib")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ZUI { public static class ZUIAPI { public static bool IsPauseMenuOpen => ZUIPauseMenu.IsOpen; public static bool IsPanelOpen => ZUIPanel.CurrentOpenPanel != null; public static bool IsScreenOpen => ZUIScreen.CurrentOpenScreen != null; public static void CloseAll() { ZUIPanel.CloseActive(); ZUIScreen.CloseActive(); ZUIPauseMenu.Close(); } public static void ClosePauseMenu() { ZUIPauseMenu.Close(); } public static void CloseActivePanel() { ZUIPanel.CloseActive(); } public static void CloseActiveScreen() { ZUIScreen.CloseActive(); } } [BepInPlugin("mods.krwclassic.zuilib", "ZUI-Lib", "0.1.0")] public class Plugin : BaseUnityPlugin { private Harmony _harmony; private readonly List<IZUIModule> _loadedModules = new List<IZUIModule>(); public static ManualLogSource Log { get; private set; } public static Plugin Instance { get; private set; } public static ConfigEntry<bool> EnableExampleModules { get; private set; } private void Awake() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; EnableExampleModules = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableExampleModules", true, "Whether to load the built-in ZUI.Example showcase modules on startup."); Log.LogInfo((object)"ZUI-Lib v0.1.0 initializing..."); ZUICrashHandler.Initialize((MonoBehaviour)(object)this); _harmony = new Harmony("mods.krwclassic.zuilib"); _harmony.PatchAll(); ZUISettings.Initialize((MonoBehaviour)(object)this); ZUIPanel.Initialize((MonoBehaviour)(object)this); ZUIMainMenu.Initialize((MonoBehaviour)(object)this); ZUIPauseMenu.Initialize((MonoBehaviour)(object)this); ZUIScreen.Initialize((MonoBehaviour)(object)this); ZUIInfoText.Initialize((MonoBehaviour)(object)this); MainMenuDrawer mainMenuDrawer = ZUIMainMenu.RegisterSubmenu("zui_lib_drawer", "ZUI-Lib", paginated: false, -100); mainMenuDrawer.AddButton("zui_lib_about", "About", delegate { ZUIPopup.ShowInfo("ZUI-Lib", "ZUI-Lib v0.1.0\nModular UI library for Zort mods.\nDeveloped by KRWCLASSIC.", "Awesome", null, "#64B5F6"); }); mainMenuDrawer.AddButton("zui_lib_settings", "Settings", delegate { ZUIPanel.Open("zui_lib_settings"); }); ZUIPanel zUIPanel = ZUIPanel.Register("zui_lib_settings", "ZUI-LIB SETTINGS"); zUIPanel.AddHeader("Core Preferences"); zUIPanel.AddToggle("zui_pref_verbose", "Verbose Logging", defaultValue: false, delegate(bool val) { Log.LogInfo((object)$"[ZUI-Lib] Verbose logging preference set to: {val}"); }); zUIPanel.AddSlider("zui_pref_ui_scale", "Interface Scale", 0.5f, 2f, 1f, wholeNumbers: false, (float v) => $"{v:F1}x"); zUIPanel.AddDivider(); zUIPanel.AddHeader("Diagnostics & Inspection"); zUIPanel.AddButton("zui_pref_dump", "Hierarchy Dump", "EXPORT", delegate { ZUIDebug.DumpHierarchy(); ZUIPopup.ShowInfo("Diagnostics Exported", "Full UI hierarchy and state have been dumped to BepInEx log.", "OK", null, "#64B5F6"); }); PauseMenuDrawer pauseMenuDrawer = ZUIPauseMenu.RegisterSubmenu("zui_lib_pause_drawer", "ZUI-Lib", paginated: false, -100); pauseMenuDrawer.AddButton("zui_lib_pause_about", "About", delegate { ZUIPopup.ShowInfo("ZUI-Lib", "ZUI-Lib v0.1.0\nModular UI library for Zort mods.\nDeveloped by KRWCLASSIC.", "Awesome", null, "#64B5F6"); }); pauseMenuDrawer.AddButton("zui_lib_pause_settings", "Settings", delegate { ZUIPanel.Open("zui_lib_settings"); }); ZUIDebug.RegisterPauseDebugSubsection(pauseMenuDrawer); LoadModules(); Log.LogInfo((object)string.Format("{0} v{1} loaded successfully with {2} module(s)!", "ZUI-Lib", "0.1.0", _loadedModules.Count)); } private void LoadModules() { _loadedModules.Clear(); try { IEnumerable<Type> enumerable = from t in Assembly.GetExecutingAssembly().GetTypes() where typeof(IZUIModule).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract select t; bool flag = EnableExampleModules == null || EnableExampleModules.Value; foreach (Type item in enumerable) { if (flag || item.Namespace == null || !item.Namespace.StartsWith("ZUI.Example", StringComparison.Ordinal)) { try { IZUIModule iZUIModule = (IZUIModule)Activator.CreateInstance(item); iZUIModule.Initialize(); _loadedModules.Add(iZUIModule); Log.LogInfo((object)("[ZUI] Loaded modular extension: " + iZUIModule.Name)); } catch (Exception ex) { ZUICrashHandler.HandleException(ex, "Module '" + item.FullName + "'", item.Assembly); Log.LogError((object)$"[ZUI] Failed to initialize module {item.FullName}: {ex}"); } } } } catch (Exception arg) { Log.LogError((object)$"[ZUI] Error scanning for modules: {arg}"); } } private void OnDestroy() { ZUIScreen.Shutdown(); ZUIPauseMenu.Shutdown(); ZUIMainMenu.Shutdown(); ZUISettings.Shutdown(); ZUICrashHandler.Shutdown(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } public static class PluginInfo { public const string PLUGIN_GUID = "mods.krwclassic.zuilib"; public const string PLUGIN_NAME = "ZUI-Lib"; public const string PLUGIN_VERSION = "0.1.0"; } } namespace ZUI.Settings { public interface ISettingItem { string Id { get; } string Label { get; set; } GameObject SpawnedObject { get; } bool HasPendingChanges { get; } GameObject Instantiate(Transform parent, SettingsTemplates templates); void Apply(); void Revert(); void RefreshUI(); void Destroy(); } public enum ButtonAlignment { Center, Right, Left, Fill } public class ButtonSettingItem : ISettingItem { private TMP_Text _labelText; private TMP_Text _buttonTextComp; private Button _button; public string Id { get; } public string Label { get; set; } public string ButtonText { get; set; } public Action OnClick { get; set; } public float? Width { get; set; } public float? Height { get; set; } public ButtonAlignment Alignment { get; set; } = ButtonAlignment.Center; public bool FullWidth { get { return Alignment == ButtonAlignment.Fill; } set { Alignment = (value ? ButtonAlignment.Fill : ButtonAlignment.Center); } } public Color? ButtonColor { get; set; } public Color? TextColor { get; set; } public Color? HoverColor { get; set; } public Color? PressedColor { get; set; } public Color? LabelColor { get; set; } public float? FontSize { get; set; } public float? FontSizeMin { get; set; } public float? FontSizeMax { get; set; } public bool SquishTextToFit { get; set; } = true; public string ButtonColorHex { set { ButtonColor = UIUtils.ParseColor(value); } } public string TextColorHex { set { TextColor = UIUtils.ParseColor(value); } } public string HoverColorHex { set { HoverColor = UIUtils.ParseColor(value); } } public string PressedColorHex { set { PressedColor = UIUtils.ParseColor(value); } } public string LabelColorHex { set { LabelColor = UIUtils.ParseColor(value); } } public GameObject SpawnedObject { get; private set; } public bool HasPendingChanges => false; public ButtonSettingItem(string id, string label, string buttonText, Action onClick) { Id = id; Label = label; ButtonText = buttonText; OnClick = onClick; } public ButtonSettingItem WithSize(float width, float height) { Width = width; Height = height; return this; } public ButtonSettingItem WithWidth(float width) { Width = width; return this; } public ButtonSettingItem WithHeight(float height) { Height = height; return this; } public ButtonSettingItem WithAlignment(ButtonAlignment alignment) { Alignment = alignment; return this; } public ButtonSettingItem WithFullWidth(bool fullWidth = true, float? height = null) { FullWidth = fullWidth; if (height.HasValue) { Height = height.Value; } return this; } public ButtonSettingItem WithColors(Color buttonColor, Color textColor) { //IL_0002: 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) ButtonColor = buttonColor; TextColor = textColor; return this; } public ButtonSettingItem WithColors(string buttonHex, string textHex) { ButtonColorHex = buttonHex; TextColorHex = textHex; return this; } public ButtonSettingItem WithButtonColor(Color color) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) ButtonColor = color; return this; } public ButtonSettingItem WithButtonColor(string hex) { ButtonColorHex = hex; return this; } public ButtonSettingItem WithTextColor(Color color) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) TextColor = color; return this; } public ButtonSettingItem WithTextColor(string hex) { TextColorHex = hex; return this; } public ButtonSettingItem WithFontSize(float fontSize, bool squish = true) { FontSize = fontSize; SquishTextToFit = squish; return this; } public ButtonSettingItem WithSquish(bool squish = true) { SquishTextToFit = squish; return this; } public GameObject Instantiate(Transform parent, SettingsTemplates templates) { //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_0193: 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_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0578: Unknown result type (might be due to invalid IL or missing references) //IL_057f: Expected O, but got Unknown //IL_03bd: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: 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_0314: Unknown result type (might be due to invalid IL or missing references) //IL_066c: Unknown result type (might be due to invalid IL or missing references) //IL_04de: Unknown result type (might be due to invalid IL or missing references) //IL_07f8: Unknown result type (might be due to invalid IL or missing references) //IL_0802: Expected O, but got Unknown //IL_07ca: Unknown result type (might be due to invalid IL or missing references) //IL_07d4: Expected O, but got Unknown //IL_079a: Unknown result type (might be due to invalid IL or missing references) //IL_07a4: Expected O, but got Unknown //IL_0767: Unknown result type (might be due to invalid IL or missing references) //IL_0771: Expected O, but got Unknown //IL_0852: Unknown result type (might be due to invalid IL or missing references) //IL_085c: Expected O, but got Unknown //IL_08cc: Unknown result type (might be due to invalid IL or missing references) //IL_08d1: Unknown result type (might be due to invalid IL or missing references) //IL_0a24: Unknown result type (might be due to invalid IL or missing references) //IL_0a31: Unknown result type (might be due to invalid IL or missing references) //IL_0a48: Unknown result type (might be due to invalid IL or missing references) //IL_0a5f: Unknown result type (might be due to invalid IL or missing references) //IL_09eb: Unknown result type (might be due to invalid IL or missing references) //IL_09f2: Expected O, but got Unknown //IL_08f9: Unknown result type (might be due to invalid IL or missing references) //IL_08e4: Unknown result type (might be due to invalid IL or missing references) //IL_08e6: Unknown result type (might be due to invalid IL or missing references) //IL_08f0: Unknown result type (might be due to invalid IL or missing references) //IL_08fe: Unknown result type (might be due to invalid IL or missing references) //IL_0ac5: Unknown result type (might be due to invalid IL or missing references) //IL_0abc: Unknown result type (might be due to invalid IL or missing references) //IL_0926: Unknown result type (might be due to invalid IL or missing references) //IL_0911: Unknown result type (might be due to invalid IL or missing references) //IL_0913: Unknown result type (might be due to invalid IL or missing references) //IL_091d: Unknown result type (might be due to invalid IL or missing references) //IL_0aca: Unknown result type (might be due to invalid IL or missing references) //IL_0ad2: Unknown result type (might be due to invalid IL or missing references) //IL_0ae0: Unknown result type (might be due to invalid IL or missing references) //IL_0ae2: Unknown result type (might be due to invalid IL or missing references) //IL_092b: Unknown result type (might be due to invalid IL or missing references) //IL_097a: Unknown result type (might be due to invalid IL or missing references) //IL_097f: Unknown result type (might be due to invalid IL or missing references) //IL_0990: Unknown result type (might be due to invalid IL or missing references) //IL_099a: Unknown result type (might be due to invalid IL or missing references) //IL_09a4: Unknown result type (might be due to invalid IL or missing references) //IL_09ae: Unknown result type (might be due to invalid IL or missing references) //IL_09bc: Unknown result type (might be due to invalid IL or missing references) //IL_095d: Unknown result type (might be due to invalid IL or missing references) //IL_0bd1: Unknown result type (might be due to invalid IL or missing references) //IL_0bdb: Expected O, but got Unknown if ((Object)(object)templates.ToggleTemplate == (Object)null) { throw new InvalidOperationException("[ZUI] Cannot instantiate ButtonSettingItem '" + Id + "': ToggleTemplate is null."); } GameObject val = Object.Instantiate<GameObject>(((Component)templates.ToggleTemplate).gameObject, parent, false); ((Object)val).name = Id; val.SetActive(true); SpawnedObject = val; ToggleSetting component = val.GetComponent<ToggleSetting>(); if ((Object)(object)component != (Object)null) { FieldInfo fieldInfo = typeof(GameSetting).GetField("settingNameText", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("GameSetting", "settingNameText"); _labelText = (TMP_Text)fieldInfo.GetValue(component); Object.DestroyImmediate((Object)(object)component); } Toggle component2 = val.GetComponent<Toggle>(); if ((Object)(object)component2 != (Object)null) { Object.DestroyImmediate((Object)(object)component2); } Transform val2 = val.transform.Find("Check"); if ((Object)(object)val2 != (Object)null) { Object.DestroyImmediate((Object)(object)((Component)val2).gameObject); } ContentSizeFitter component3 = val.GetComponent<ContentSizeFitter>(); if ((Object)(object)component3 != (Object)null) { Object.DestroyImmediate((Object)(object)component3); } float num = Width ?? ((Alignment == ButtonAlignment.Fill) ? 0f : 260f); float num2 = Height ?? 44f; float num3 = Math.Max(48f, num2 + 6f); RectTransform component4 = val.GetComponent<RectTransform>(); component4.anchorMin = new Vector2(0f, 1f); component4.anchorMax = new Vector2(1f, 1f); component4.pivot = new Vector2(0.5f, 1f); component4.offsetMin = new Vector2(0f, component4.offsetMin.y); component4.offsetMax = new Vector2(0f, component4.offsetMax.y); component4.sizeDelta = new Vector2(0f, num3); LayoutElement val3 = val.GetComponent<LayoutElement>() ?? val.AddComponent<LayoutElement>(); val3.preferredHeight = num3; val3.minHeight = num3; val3.preferredWidth = -1f; val3.flexibleWidth = 1f; Transform val4 = val.transform.Find("Text"); if ((Object)(object)_labelText == (Object)null && (Object)(object)val4 != (Object)null) { Transform obj = val4.Find("OptionText"); _labelText = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null); } bool flag = !string.IsNullOrEmpty(Label); if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label ?? string.Empty; if (LabelColor.HasValue) { ((Graphic)_labelText).color = LabelColor.Value; } _labelText.alignment = (TextAlignmentOptions)4100; _labelText.textWrappingMode = (TextWrappingModes)0; _labelText.overflowMode = (TextOverflowModes)1; _labelText.enableAutoSizing = true; _labelText.fontSizeMin = 14f; _labelText.fontSizeMax = 28f; _labelText.fontSize = 28f; UIUtils.ApplyFontSafe(_labelText); _labelText.ForceMeshUpdate(false, false); RectTransform rectTransform = _labelText.rectTransform; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; } if ((Object)(object)val4 != (Object)null) { HorizontalLayoutGroup[] components = ((Component)val4).GetComponents<HorizontalLayoutGroup>(); foreach (HorizontalLayoutGroup val5 in components) { Object.DestroyImmediate((Object)(object)val5); } ContentSizeFitter[] components2 = ((Component)val4).GetComponents<ContentSizeFitter>(); foreach (ContentSizeFitter val6 in components2) { Object.DestroyImmediate((Object)(object)val6); } if (!flag || Alignment == ButtonAlignment.Fill) { ((Component)val4).gameObject.SetActive(false); } else { ((Component)val4).gameObject.SetActive(true); float num4 = (((Object)(object)_labelText != (Object)null) ? _labelText.preferredWidth : 200f); float num5 = Mathf.Clamp(num4 + 8f, 40f, 650f); RectTransform component5 = ((Component)val4).GetComponent<RectTransform>(); component5.sizeDelta = new Vector2(num5, num3); LayoutElement val7 = ((Component)val4).GetComponent<LayoutElement>() ?? ((Component)val4).gameObject.AddComponent<LayoutElement>(); val7.preferredWidth = num5; val7.minWidth = num5; val7.preferredHeight = num3; val7.flexibleWidth = 0f; val4.SetSiblingIndex(0); } } GameObject val8; if ((Object)(object)templates.ButtonTemplate != (Object)null) { val8 = Object.Instantiate<GameObject>(((Component)templates.ButtonTemplate).gameObject, val.transform, false); } else { val8 = new GameObject(Id + "_Button"); val8.transform.SetParent(val.transform, false); val8.AddComponent<Image>(); val8.AddComponent<Button>(); } ((Object)val8).name = Id + "_Btn"; val8.SetActive(true); ButtonAnimation[] componentsInChildren = val8.GetComponentsInChildren<ButtonAnimation>(true); foreach (ButtonAnimation val9 in componentsInChildren) { Object.DestroyImmediate((Object)(object)val9); } Animator[] componentsInChildren2 = val8.GetComponentsInChildren<Animator>(true); foreach (Animator val10 in componentsInChildren2) { Object.DestroyImmediate((Object)(object)val10); } LocalizedTextUI[] componentsInChildren3 = val8.GetComponentsInChildren<LocalizedTextUI>(true); foreach (LocalizedTextUI val11 in componentsInChildren3) { Object.DestroyImmediate((Object)(object)val11); } RectTransform val12 = val8.GetComponent<RectTransform>() ?? val8.AddComponent<RectTransform>(); val12.sizeDelta = new Vector2(num, num2); LayoutElement val13 = val8.GetComponent<LayoutElement>() ?? val8.AddComponent<LayoutElement>(); if (Alignment == ButtonAlignment.Fill) { val13.preferredWidth = -1f; val13.flexibleWidth = 1f; } else { val13.preferredWidth = num; val13.minWidth = num; val13.flexibleWidth = 0f; } val13.preferredHeight = num2; val13.minHeight = num2; val8.transform.SetSiblingIndex(1); HorizontalLayoutGroup val14 = val.GetComponent<HorizontalLayoutGroup>() ?? val.AddComponent<HorizontalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)val14).spacing = 24f; ((HorizontalOrVerticalLayoutGroup)val14).childControlHeight = false; ((HorizontalOrVerticalLayoutGroup)val14).childForceExpandHeight = false; switch (Alignment) { case ButtonAlignment.Fill: ((LayoutGroup)val14).childAlignment = (TextAnchor)4; ((LayoutGroup)val14).padding = new RectOffset(20, 20, 0, 0); ((HorizontalOrVerticalLayoutGroup)val14).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)val14).childForceExpandWidth = true; break; case ButtonAlignment.Left: ((LayoutGroup)val14).childAlignment = (TextAnchor)3; ((LayoutGroup)val14).padding = new RectOffset(40, 40, 0, 0); ((HorizontalOrVerticalLayoutGroup)val14).childControlWidth = false; ((HorizontalOrVerticalLayoutGroup)val14).childForceExpandWidth = false; break; case ButtonAlignment.Right: ((LayoutGroup)val14).childAlignment = (TextAnchor)5; ((LayoutGroup)val14).padding = new RectOffset(40, 40, 0, 0); ((HorizontalOrVerticalLayoutGroup)val14).childControlWidth = false; ((HorizontalOrVerticalLayoutGroup)val14).childForceExpandWidth = false; break; default: ((LayoutGroup)val14).childAlignment = (TextAnchor)4; ((LayoutGroup)val14).padding = new RectOffset(0, 0, 0, 0); ((HorizontalOrVerticalLayoutGroup)val14).childControlWidth = false; ((HorizontalOrVerticalLayoutGroup)val14).childForceExpandWidth = false; break; } _button = val8.GetComponent<Button>() ?? val8.AddComponent<Button>(); ((UnityEventBase)_button.onClick).RemoveAllListeners(); ((UnityEvent)_button.onClick).AddListener((UnityAction)delegate { try { StaticInstance<InitUI>.Instance.PlayClickSFX(); } catch { } OnClick?.Invoke(); }); ((Selectable)_button).interactable = true; ((Selectable)_button).transition = (Transition)1; Image val15 = val8.GetComponent<Image>() ?? val8.GetComponentInChildren<Image>(); if ((Object)(object)val15 != (Object)null) { ((Selectable)_button).targetGraphic = (Graphic)(object)val15; } if (ButtonColor.HasValue) { Color value = ButtonColor.Value; Color highlightedColor = (Color)(((??)HoverColor) ?? Color.Lerp(value, Color.white, 0.25f)); Color pressedColor = (Color)(((??)PressedColor) ?? Color.Lerp(value, Color.black, 0.25f)); Graphic[] componentsInChildren4 = val8.GetComponentsInChildren<Graphic>(true); Graphic[] array = componentsInChildren4; foreach (Graphic val16 in array) { if (!(val16 is TMP_Text)) { val16.color = value; } } ColorBlock colors = ((Selectable)_button).colors; ((ColorBlock)(ref colors)).colorMultiplier = 1f; ((ColorBlock)(ref colors)).normalColor = value; ((ColorBlock)(ref colors)).highlightedColor = highlightedColor; ((ColorBlock)(ref colors)).pressedColor = pressedColor; ((ColorBlock)(ref colors)).selectedColor = value; ((Selectable)_button).colors = colors; } _buttonTextComp = val8.GetComponentInChildren<TMP_Text>(true); if ((Object)(object)_buttonTextComp == (Object)null) { GameObject val17 = new GameObject("Text"); val17.transform.SetParent(val8.transform, false); _buttonTextComp = (TMP_Text)(object)val17.AddComponent<TextMeshProUGUI>(); } RectTransform rectTransform2 = _buttonTextComp.rectTransform; rectTransform2.anchorMin = Vector2.zero; rectTransform2.anchorMax = Vector2.one; rectTransform2.offsetMin = new Vector2(12f, 2f); rectTransform2.offsetMax = new Vector2(-12f, -2f); _buttonTextComp.text = ButtonText ?? "Click"; _buttonTextComp.alignment = (TextAlignmentOptions)514; UIUtils.ApplyFontSafe(_buttonTextComp); Color val18 = (Color)(((??)TextColor) ?? Color.white); ((Graphic)_buttonTextComp).color = val18; _buttonTextComp.faceColor = Color32.op_Implicit(val18); float num7 = FontSize ?? FontSizeMax ?? 20f; float fontSizeMin = FontSizeMin ?? 10f; if (SquishTextToFit) { _buttonTextComp.textWrappingMode = (TextWrappingModes)0; _buttonTextComp.overflowMode = (TextOverflowModes)1; _buttonTextComp.enableAutoSizing = true; _buttonTextComp.fontSizeMin = fontSizeMin; _buttonTextComp.fontSizeMax = num7; _buttonTextComp.fontSize = num7; } else { _buttonTextComp.textWrappingMode = (TextWrappingModes)1; _buttonTextComp.overflowMode = (TextOverflowModes)0; _buttonTextComp.enableAutoSizing = false; _buttonTextComp.fontSize = num7; } LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)val.transform); return val; } public void Apply() { } public void Revert() { } public void RefreshUI() { //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Expected O, but got Unknown //IL_0141: 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_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label ?? string.Empty; _labelText.ForceMeshUpdate(false, false); if ((Object)(object)SpawnedObject != (Object)null) { Transform val = SpawnedObject.transform.Find("Text"); if ((Object)(object)val != (Object)null) { float num = Mathf.Clamp(_labelText.preferredWidth + 8f, 40f, 650f); RectTransform component = ((Component)val).GetComponent<RectTransform>(); if ((Object)(object)component != (Object)null) { component.sizeDelta = new Vector2(num, component.sizeDelta.y); } LayoutElement component2 = ((Component)val).GetComponent<LayoutElement>(); if ((Object)(object)component2 != (Object)null) { component2.preferredWidth = num; component2.minWidth = num; } } } } if ((Object)(object)_buttonTextComp != (Object)null) { _buttonTextComp.text = ButtonText ?? "Click"; Color val2 = (Color)(((??)TextColor) ?? Color.white); ((Graphic)_buttonTextComp).color = val2; _buttonTextComp.faceColor = Color32.op_Implicit(val2); } if ((Object)(object)SpawnedObject != (Object)null) { LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)SpawnedObject.transform); } } public void Destroy() { if ((Object)(object)SpawnedObject != (Object)null) { Object.Destroy((Object)(object)SpawnedObject); SpawnedObject = null; } _labelText = null; _buttonTextComp = null; _button = null; } } public class DividerSettingItem : ISettingItem { public string Id { get; } public string Label { get; set; } public GameObject SpawnedObject { get; private set; } public bool HasPendingChanges => false; public DividerSettingItem(string id = null) { Id = (string.IsNullOrEmpty(id) ? ("ZUI_Divider_" + Guid.NewGuid().ToString("N").Substring(0, 8)) : id); Label = ""; } public GameObject Instantiate(Transform parent, SettingsTemplates templates) { if ((Object)(object)templates.LineTemplate == (Object)null) { return null; } GameObject val = Object.Instantiate<GameObject>(((Component)templates.LineTemplate).gameObject, parent, false); ((Object)val).name = Id; SpawnedObject = val; return val; } public void Apply() { } public void Revert() { } public void RefreshUI() { } public void Destroy() { if ((Object)(object)SpawnedObject != (Object)null) { Object.Destroy((Object)(object)SpawnedObject); SpawnedObject = null; } } } public class DropdownSettingItem : ISettingItem { private TMP_Dropdown _dropdown; private TMP_Text _labelText; public string Id { get; } public string Label { get; set; } public List<string> Options { get; } = new List<string>(); public GameObject SpawnedObject { get; private set; } public int CurrentIndex { get; private set; } public int PendingIndex { get; set; } public bool HasPendingChanges => CurrentIndex != PendingIndex; public Action<int> OnApply { get; set; } public Action<int> OnChanged { get; set; } public DropdownSettingItem(string id, string label, IList<string> options, int defaultIndex = 0, Action<int> onApply = null, Action<int> onChanged = null) { Id = id; Label = label; if (options != null) { Options.AddRange(options); } CurrentIndex = Mathf.Clamp(defaultIndex, 0, Math.Max(0, Options.Count - 1)); PendingIndex = CurrentIndex; OnApply = onApply; OnChanged = onChanged; } public GameObject Instantiate(Transform parent, SettingsTemplates templates) { //IL_00b6: 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_00df: Expected O, but got Unknown //IL_0112: 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_013b: Expected O, but got Unknown if ((Object)(object)templates.DropdownTemplate == (Object)null) { throw new InvalidOperationException("[ZUI] Dropdown template could not be found in Settings panel."); } GameObject val = Object.Instantiate<GameObject>(((Component)templates.DropdownTemplate).gameObject, parent, false); ((Object)val).name = Id; SpawnedObject = val; DropdownSetting component = val.GetComponent<DropdownSetting>(); if ((Object)(object)component == (Object)null) { Transform dropdownTemplate = templates.DropdownTemplate; throw new InvalidOperationException("[ZUI] Dropdown template '" + ((dropdownTemplate != null) ? ((Object)dropdownTemplate).name : null) + "' is missing the DropdownSetting component."); } FieldInfo fieldInfo = typeof(GameSetting).GetField("settingNameText", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("GameSetting", "settingNameText"); TMP_Text val2 = (TMP_Text)fieldInfo.GetValue(component); if ((int)val2 == 0) { throw new InvalidOperationException("[ZUI] Dropdown template '" + ((Object)component).name + "' has null settingNameText."); } _labelText = val2; FieldInfo fieldInfo2 = typeof(DropdownSetting).GetField("dropdown", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("DropdownSetting", "dropdown"); TMP_Dropdown val3 = (TMP_Dropdown)fieldInfo2.GetValue(component); if ((int)val3 == 0) { throw new InvalidOperationException("[ZUI] Dropdown template '" + ((Object)component).name + "' has null dropdown."); } _dropdown = val3; Object.DestroyImmediate((Object)(object)component); _dropdown.ClearOptions(); _dropdown.AddOptions(Options); ((UnityEventBase)_dropdown.onValueChanged).RemoveAllListeners(); _dropdown.SetValueWithoutNotify(PendingIndex); UpdateCaption(); ((UnityEvent<int>)(object)_dropdown.onValueChanged).AddListener((UnityAction<int>)delegate(int idx) { PendingIndex = idx; UpdateCaption(); OnChanged?.Invoke(idx); ZUISettings.MarkChangesMade(); }); if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label; UIUtils.ApplyFontSafe(_labelText); } if ((Object)(object)_dropdown.captionText != (Object)null) { UIUtils.ApplyFontSafe(_dropdown.captionText); } if ((Object)(object)_dropdown.itemText != (Object)null) { UIUtils.ApplyFontSafe(_dropdown.itemText); } return val; } private void UpdateCaption() { if ((Object)(object)_dropdown != (Object)null && (Object)(object)_dropdown.captionText != (Object)null) { if (_dropdown.options.Count > 0 && PendingIndex >= 0 && PendingIndex < _dropdown.options.Count) { _dropdown.captionText.text = _dropdown.options[PendingIndex].text; } else { _dropdown.captionText.text = "NONE"; } } } public void Apply() { if (HasPendingChanges) { CurrentIndex = PendingIndex; OnApply?.Invoke(CurrentIndex); } } public void Revert() { PendingIndex = CurrentIndex; if ((Object)(object)_dropdown != (Object)null) { _dropdown.SetValueWithoutNotify(CurrentIndex); } UpdateCaption(); } public void RefreshUI() { if ((Object)(object)_dropdown != (Object)null) { _dropdown.SetValueWithoutNotify(PendingIndex); } UpdateCaption(); if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label; } } public void Destroy() { if ((Object)(object)SpawnedObject != (Object)null) { Object.Destroy((Object)(object)SpawnedObject); SpawnedObject = null; } _dropdown = null; _labelText = null; } } public class HeaderSettingItem : TextSettingItem { public static readonly Color DefaultHeaderColor = new Color(0.95f, 0.85f, 0.45f, 1f); public HeaderSettingItem(string id, string title, Color? color = null, TMP_FontAsset font = null, float? fontSize = null, FontStyles? fontStyle = null, float? height = null) : base(id, title, (Color)(((??)color) ?? DefaultHeaderColor), font, fontSize, fontStyle.GetValueOrDefault(), (TextAlignmentOptions)514, height ?? 52f) { }//IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) public HeaderSettingItem(string id, string title, string hexColor) : base(id, title, UIUtils.ParseColor(hexColor, DefaultHeaderColor), null, null, (FontStyles)0, (TextAlignmentOptions)514, 52f) { }//IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) } public class SliderSettingItem : ISettingItem { private Slider _slider; private TMP_Text _labelText; private TMP_Text _valueText; public string Id { get; } public string Label { get; set; } public GameObject SpawnedObject { get; private set; } public float MinValue { get; set; } public float MaxValue { get; set; } public bool WholeNumbers { get; set; } public Func<float, string> ValueFormatter { get; set; } public float CurrentValue { get; private set; } public float PendingValue { get; set; } public bool HasPendingChanges => Math.Abs(CurrentValue - PendingValue) > 0.0001f; public Action<float> OnApply { get; set; } public Action<float> OnChanged { get; set; } public SliderSettingItem(string id, string label, float minValue, float maxValue, float defaultValue, bool wholeNumbers = false, Func<float, string> valueFormatter = null, Action<float> onApply = null, Action<float> onChanged = null) { Id = id; Label = label; MinValue = minValue; MaxValue = maxValue; WholeNumbers = wholeNumbers; CurrentValue = defaultValue; PendingValue = defaultValue; ValueFormatter = valueFormatter ?? ((Func<float, string>)((float v) => wholeNumbers ? v.ToString("0") : v.ToString("0.00"))); OnApply = onApply; OnChanged = onChanged; } public GameObject Instantiate(Transform parent, SettingsTemplates templates) { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Expected O, but got Unknown //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Expected O, but got Unknown if ((Object)(object)templates.SliderTemplate == (Object)null) { return null; } GameObject val = Object.Instantiate<GameObject>(((Component)templates.SliderTemplate).gameObject, parent, false); ((Object)val).name = Id; SpawnedObject = val; SliderSetting component = val.GetComponent<SliderSetting>(); if ((Object)(object)component == (Object)null) { Transform sliderTemplate = templates.SliderTemplate; throw new InvalidOperationException("[ZUI] Slider template '" + ((sliderTemplate != null) ? ((Object)sliderTemplate).name : null) + "' is missing the SliderSetting component."); } FieldInfo fieldInfo = typeof(GameSetting).GetField("settingNameText", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("GameSetting", "settingNameText"); TMP_Text val2 = (TMP_Text)fieldInfo.GetValue(component); if ((int)val2 == 0) { throw new InvalidOperationException("[ZUI] Slider template '" + ((Object)component).name + "' has null settingNameText."); } _labelText = val2; FieldInfo fieldInfo2 = typeof(SliderSetting).GetField("valueText", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("SliderSetting", "valueText"); TMP_Text val3 = (TMP_Text)fieldInfo2.GetValue(component); if ((int)val3 == 0) { throw new InvalidOperationException("[ZUI] Slider template '" + ((Object)component).name + "' has null valueText."); } _valueText = val3; FieldInfo fieldInfo3 = typeof(SliderSetting).GetField("slider", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("SliderSetting", "slider"); Slider val4 = (Slider)fieldInfo3.GetValue(component); if ((int)val4 == 0) { throw new InvalidOperationException("[ZUI] Slider template '" + ((Object)component).name + "' has null slider."); } _slider = val4; Object.DestroyImmediate((Object)(object)component); if ((Object)(object)_slider != (Object)null) { _slider.minValue = MinValue; _slider.maxValue = MaxValue; _slider.wholeNumbers = WholeNumbers; ((UnityEventBase)_slider.onValueChanged).RemoveAllListeners(); _slider.SetValueWithoutNotify(PendingValue); ((UnityEvent<float>)(object)_slider.onValueChanged).AddListener((UnityAction<float>)delegate(float num) { PendingValue = num; UpdateValueLabel(num); OnChanged?.Invoke(num); ZUISettings.MarkChangesMade(); }); } if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label; UIUtils.ApplyFontSafe(_labelText); } UpdateValueLabel(PendingValue); return val; } private void UpdateValueLabel(float value) { if ((Object)(object)_valueText != (Object)null) { _valueText.text = ((ValueFormatter != null) ? ValueFormatter(value) : value.ToString("0.00")); UIUtils.ApplyFontSafe(_valueText); } } public void Apply() { if (HasPendingChanges) { CurrentValue = PendingValue; OnApply?.Invoke(CurrentValue); } } public void Revert() { PendingValue = CurrentValue; if ((Object)(object)_slider != (Object)null) { _slider.SetValueWithoutNotify(CurrentValue); } UpdateValueLabel(CurrentValue); } public void RefreshUI() { if ((Object)(object)_slider != (Object)null) { _slider.SetValueWithoutNotify(PendingValue); } UpdateValueLabel(PendingValue); if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label; } } public void Destroy() { if ((Object)(object)SpawnedObject != (Object)null) { Object.Destroy((Object)(object)SpawnedObject); SpawnedObject = null; } _slider = null; _labelText = null; _valueText = null; } } public class SpaceSettingItem : ISettingItem { public string Id { get; } public string Label { get; set; } = ""; public GameObject SpawnedObject { get; private set; } public bool HasPendingChanges => false; public float Height { get; set; } public SpaceSettingItem(string id = null, float height = 15f) { Id = (string.IsNullOrEmpty(id) ? ("ZUI_Space_" + Guid.NewGuid().ToString("N").Substring(0, 8)) : id); Height = height; } public GameObject Instantiate(Transform parent, SettingsTemplates templates) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_004c: 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) GameObject val = new GameObject(Id, new Type[2] { typeof(RectTransform), typeof(LayoutElement) }); val.transform.SetParent(parent, false); SpawnedObject = val; RectTransform component = val.GetComponent<RectTransform>(); component.sizeDelta = new Vector2(component.sizeDelta.x, Height); LayoutElement component2 = val.GetComponent<LayoutElement>(); component2.preferredHeight = Height; component2.minHeight = Height; return val; } public void Apply() { } public void Revert() { } public void RefreshUI() { } public void Destroy() { if ((Object)(object)SpawnedObject != (Object)null) { Object.Destroy((Object)(object)SpawnedObject); SpawnedObject = null; } } } public class TextSettingItem : ISettingItem { private TMP_Text _labelText; public string Id { get; } public string Label { get; set; } public GameObject SpawnedObject { get; private set; } public bool HasPendingChanges => false; public Color? Color { get; set; } public TMP_FontAsset Font { get; set; } public float? FontSize { get; set; } public FontStyles FontStyle { get; set; } = (FontStyles)0; public TextAlignmentOptions? Alignment { get; set; } public float Height { get; set; } public TextSettingItem(string id, string text, Color? color = null, TMP_FontAsset font = null, float? fontSize = null, FontStyles? fontStyle = null, TextAlignmentOptions? alignment = null, float? height = null) { //IL_0002: 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) Id = id; Label = text; Color = color; Font = font; FontSize = fontSize; FontStyle = fontStyle.GetValueOrDefault(); Alignment = alignment; Height = height ?? 38f; } public GameObject Instantiate(Transform parent, SettingsTemplates templates) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown //IL_011a: 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_0140: Expected O, but got Unknown //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_0375: Unknown result type (might be due to invalid IL or missing references) //IL_03c3: 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_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)templates.ToggleTemplate == (Object)null) { throw new InvalidOperationException("[ZUI] Cannot instantiate TextSettingItem '" + Id + "': ToggleTemplate is null."); } GameObject val = Object.Instantiate<GameObject>(((Component)templates.ToggleTemplate).gameObject, parent, false); ((Object)val).name = Id; SpawnedObject = val; ToggleSetting component = val.GetComponent<ToggleSetting>(); if ((Object)(object)component == (Object)null) { throw new InvalidOperationException("[ZUI] Toggle template '" + ((Object)templates.ToggleTemplate).name + "' is missing the ToggleSetting component."); } FieldInfo fieldInfo = typeof(GameSetting).GetField("settingNameText", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("GameSetting", "settingNameText"); TMP_Text val2 = (TMP_Text)fieldInfo.GetValue(component); if ((int)val2 == 0) { throw new InvalidOperationException("[ZUI] Toggle template '" + ((Object)component).name + "' has null settingNameText."); } _labelText = val2; FieldInfo fieldInfo2 = typeof(ToggleSetting).GetField("toggle", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("ToggleSetting", "toggle"); Toggle val3 = (Toggle)fieldInfo2.GetValue(component); if ((int)val3 == 0) { throw new InvalidOperationException("[ZUI] Toggle template '" + ((Object)component).name + "' has null toggle."); } Toggle val4 = val3; if ((Object)(object)((Component)val4).gameObject != (Object)(object)val && !_labelText.transform.IsChildOf(((Component)val4).transform)) { ((Component)val4).gameObject.SetActive(false); } else { if ((Object)(object)val4.graphic != (Object)null && (Object)(object)val4.graphic != (Object)(object)_labelText) { ((Component)val4.graphic).gameObject.SetActive(false); } if ((Object)(object)((Selectable)val4).targetGraphic != (Object)null && (Object)(object)((Selectable)val4).targetGraphic != (Object)(object)_labelText) { ((Component)((Selectable)val4).targetGraphic).gameObject.SetActive(false); } } Object.DestroyImmediate((Object)(object)component); Object.DestroyImmediate((Object)(object)val4); LocalizedTextUI[] componentsInChildren = val.GetComponentsInChildren<LocalizedTextUI>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } val.SetActive(true); ((Component)_labelText).gameObject.SetActive(true); ((Behaviour)_labelText).enabled = true; _labelText.richText = true; _labelText.text = Label; if (Color.HasValue) { ((Graphic)_labelText).color = Color.Value; } else { Color color = ((Graphic)_labelText).color; if (color.a <= 0.01f) { color.a = 1f; } ((Graphic)_labelText).color = color; } if ((Object)(object)Font != (Object)null) { _labelText.font = Font; } else { UIUtils.ApplyFontSafe(_labelText); } if (FontSize.HasValue) { _labelText.fontSize = FontSize.Value; } _labelText.fontStyle = FontStyle; if (Alignment.HasValue) { _labelText.alignment = Alignment.Value; } _labelText.overflowMode = (TextOverflowModes)0; _labelText.margin = Vector4.zero; RectTransform component2 = val.GetComponent<RectTransform>(); if ((Object)(object)component2 != (Object)null) { component2.sizeDelta = new Vector2(component2.sizeDelta.x, Height); } LayoutElement val5 = val.GetComponent<LayoutElement>() ?? val.AddComponent<LayoutElement>(); val5.preferredHeight = Height; val5.minHeight = Height; return val; } public TextSettingItem SetColor(Color color) { //IL_0002: 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) Color = color; if ((Object)(object)_labelText != (Object)null) { ((Graphic)_labelText).color = color; } return this; } public TextSettingItem SetColor(string hexColor) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) Color? val = UIUtils.ParseColor(hexColor); if (val.HasValue) { SetColor(val.Value); } return this; } public TextSettingItem WithColor(Color color) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return SetColor(color); } public TextSettingItem WithColor(string hexColor) { return SetColor(hexColor); } public TextSettingItem WithFontSize(float size) { FontSize = size; if ((Object)(object)_labelText != (Object)null) { _labelText.fontSize = size; } return this; } public TextSettingItem WithHeight(float height) { //IL_0033: 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) Height = height; if ((Object)(object)SpawnedObject != (Object)null) { RectTransform component = SpawnedObject.GetComponent<RectTransform>(); if ((Object)(object)component != (Object)null) { component.sizeDelta = new Vector2(component.sizeDelta.x, Height); } LayoutElement component2 = SpawnedObject.GetComponent<LayoutElement>(); if ((Object)(object)component2 != (Object)null) { component2.preferredHeight = Height; component2.minHeight = Height; } } return this; } public void Apply() { } public void Revert() { } public void RefreshUI() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label; if (Color.HasValue) { ((Graphic)_labelText).color = Color.Value; } if ((Object)(object)Font != (Object)null) { _labelText.font = Font; } if (FontSize.HasValue) { _labelText.fontSize = FontSize.Value; } _labelText.fontStyle = FontStyle; if (Alignment.HasValue) { _labelText.alignment = Alignment.Value; } } } public void Destroy() { if ((Object)(object)SpawnedObject != (Object)null) { Object.Destroy((Object)(object)SpawnedObject); SpawnedObject = null; } _labelText = null; } } public class ToggleSettingItem : ISettingItem { private Toggle _toggle; private TMP_Text _labelText; public string Id { get; } public string Label { get; set; } public GameObject SpawnedObject { get; private set; } public bool CurrentValue { get; private set; } public bool PendingValue { get; set; } public bool HasPendingChanges => CurrentValue != PendingValue; public Action<bool> OnApply { get; set; } public Action<bool> OnChanged { get; set; } public ToggleSettingItem(string id, string label, bool defaultValue, Action<bool> onApply = null, Action<bool> onChanged = null) { Id = id; Label = label; CurrentValue = defaultValue; PendingValue = defaultValue; OnApply = onApply; OnChanged = onChanged; } public GameObject Instantiate(Transform parent, SettingsTemplates templates) { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Expected O, but got Unknown if ((Object)(object)templates.ToggleTemplate == (Object)null) { return null; } GameObject val = Object.Instantiate<GameObject>(((Component)templates.ToggleTemplate).gameObject, parent, false); ((Object)val).name = Id; SpawnedObject = val; ToggleSetting component = val.GetComponent<ToggleSetting>(); if ((Object)(object)component == (Object)null) { Transform toggleTemplate = templates.ToggleTemplate; throw new InvalidOperationException("[ZUI] Toggle template '" + ((toggleTemplate != null) ? ((Object)toggleTemplate).name : null) + "' is missing the ToggleSetting component."); } FieldInfo fieldInfo = typeof(GameSetting).GetField("settingNameText", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("GameSetting", "settingNameText"); TMP_Text val2 = (TMP_Text)fieldInfo.GetValue(component); if ((int)val2 == 0) { throw new InvalidOperationException("[ZUI] Toggle template '" + ((Object)component).name + "' has null settingNameText."); } _labelText = val2; FieldInfo fieldInfo2 = typeof(ToggleSetting).GetField("toggle", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new MissingFieldException("ToggleSetting", "toggle"); Toggle val3 = (Toggle)fieldInfo2.GetValue(component); if ((int)val3 == 0) { throw new InvalidOperationException("[ZUI] Toggle template '" + ((Object)component).name + "' has null toggle."); } _toggle = val3; Object.DestroyImmediate((Object)(object)component); if ((Object)(object)_toggle != (Object)null) { ((UnityEventBase)_toggle.onValueChanged).RemoveAllListeners(); _toggle.SetIsOnWithoutNotify(PendingValue); ((UnityEvent<bool>)(object)_toggle.onValueChanged).AddListener((UnityAction<bool>)delegate(bool flag) { PendingValue = flag; OnChanged?.Invoke(flag); ZUISettings.MarkChangesMade(); }); } if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label; UIUtils.ApplyFontSafe(_labelText); } return val; } public void Apply() { if (CurrentValue != PendingValue) { CurrentValue = PendingValue; OnApply?.Invoke(CurrentValue); } } public void Revert() { PendingValue = CurrentValue; if ((Object)(object)_toggle != (Object)null) { _toggle.SetIsOnWithoutNotify(CurrentValue); } } public void RefreshUI() { if ((Object)(object)_toggle != (Object)null) { _toggle.SetIsOnWithoutNotify(PendingValue); } if ((Object)(object)_labelText != (Object)null) { _labelText.text = Label; } } public void Destroy() { if ((Object)(object)SpawnedObject != (Object)null) { Object.Destroy((Object)(object)SpawnedObject); SpawnedObject = null; } _toggle = null; _labelText = null; } } public class SettingContainer { private readonly List<ISettingItem> _items = new List<ISettingItem>(); public IReadOnlyList<ISettingItem> Items => _items.AsReadOnly(); public bool HasPendingChanges => _items.Any((ISettingItem i) => i.HasPendingChanges); public event Action<ISettingItem> OnItemAdded; public event Action OnChangesMade; public bool Contains(ISettingItem item) { return item != null && _items.Contains(item); } public bool Contains(string id) { return !string.IsNullOrEmpty(id) && _items.Any((ISettingItem i) => i.Id.Equals(id, StringComparison.OrdinalIgnoreCase)); } public void AddItem(ISettingItem item) { if (item == null) { throw new ArgumentNullException("item"); } _items.Add(item); this.OnItemAdded?.Invoke(item); } public void NotifyChangesMade() { this.OnChangesMade?.Invoke(); } public void ApplyPending() { foreach (ISettingItem item in _items) { item.Apply(); } } public void RevertPending() { foreach (ISettingItem item in _items) { item.Revert(); } } public void RefreshUI() { foreach (ISettingItem item in _items) { item.RefreshUI(); } } public void DestroyItems() { foreach (ISettingItem item in _items) { item.Destroy(); } _items.Clear(); } public ToggleSettingItem AddToggle(string id, string label, bool defaultValue, Action<bool> onApply = null, Action<bool> onChanged = null) { ToggleSettingItem toggleSettingItem = new ToggleSettingItem(id, label, defaultValue, onApply, delegate(bool val) { onChanged?.Invoke(val); NotifyChangesMade(); }); AddItem(toggleSettingItem); return toggleSettingItem; } public SliderSettingItem AddSlider(string id, string label, float minValue, float maxValue, float defaultValue, bool wholeNumbers = false, Func<float, string> valueFormatter = null, Action<float> onApply = null, Action<float> onChanged = null) { SliderSettingItem sliderSettingItem = new SliderSettingItem(id, label, minValue, maxValue, defaultValue, wholeNumbers, valueFormatter, onApply, delegate(float val) { onChanged?.Invoke(val); NotifyChangesMade(); }); AddItem(sliderSettingItem); return sliderSettingItem; } public DropdownSettingItem AddDropdown(string id, string label, IList<string> options, int defaultIndex = 0, Action<int> onApply = null, Action<int> onChanged = null) { DropdownSettingItem dropdownSettingItem = new DropdownSettingItem(id, label, options, defaultIndex, onApply, delegate(int idx) { onChanged?.Invoke(idx); NotifyChangesMade(); }); AddItem(dropdownSettingItem); return dropdownSettingItem; } public DropdownSettingItem AddDropdown<TEnum>(string id, string label, TEnum defaultValue = default(TEnum), Action<TEnum> onApply = null, Action<TEnum> onChanged = null) where TEnum : struct, Enum { string[] names = Enum.GetNames(typeof(TEnum)); int num = Array.IndexOf(names, defaultValue.ToString()); if (num < 0) { num = 0; } DropdownSettingItem dropdownSettingItem = new DropdownSettingItem(id, label, names, num, delegate(int idx) { if (Enum.TryParse<TEnum>(names[idx], out var result)) { onApply?.Invoke(result); } }, delegate(int idx) { if (Enum.TryParse<TEnum>(names[idx], out var result)) { onChanged?.Invoke(result); NotifyChangesMade(); } }); AddItem(dropdownSettingItem); return dropdownSettingItem; } public HeaderSettingItem AddHeader(string title) { string id = "ZUI_Header_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddHeader(id, title, null, null, null, null, null); } public HeaderSettingItem AddHeader(string title, Color color) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) string id = "ZUI_Header_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddHeader(id, title, color); } public HeaderSettingItem AddHeader(string title, string hexColor) { string id = "ZUI_Header_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddHeader(id, title, UIUtils.ParseColor(hexColor)); } public HeaderSettingItem AddHeader(string id, string title, Color? color = null, TMP_FontAsset font = null, float? fontSize = null, FontStyles? fontStyle = null, float? height = null) { HeaderSettingItem headerSettingItem = new HeaderSettingItem(id, title, color, font, fontSize, fontStyle, height); AddItem(headerSettingItem); return headerSettingItem; } public HeaderSettingItem AddHeader(string id, string title, string hexColor) { return AddHeader(id, title, UIUtils.ParseColor(hexColor)); } public TextSettingItem AddCategory(string title) { string id = "ZUI_Category_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddCategory(id, title, null, null, null, null, null); } public TextSettingItem AddCategory(string title, Color color) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) string id = "ZUI_Category_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddCategory(id, title, color); } public TextSettingItem AddCategory(string title, string hexColor) { string id = "ZUI_Category_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddCategory(id, title, UIUtils.ParseColor(hexColor)); } public TextSettingItem AddCategory(string id, string title, Color? color = null, TMP_FontAsset font = null, float? fontSize = null, FontStyles? fontStyle = null, float? height = null) { HeaderSettingItem headerSettingItem = new HeaderSettingItem(id, title, color, font, fontSize, fontStyle, height); AddItem(headerSettingItem); return headerSettingItem; } public TextSettingItem AddCategory(string id, string title, string hexColor) { return AddCategory(id, title, UIUtils.ParseColor(hexColor)); } public TextSettingItem AddText(string text) { string id = "ZUI_Text_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddText(id, text, null, null, null, null, null, null); } public TextSettingItem AddText(string text, Color color) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) string id = "ZUI_Text_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddText(id, text, color); } public TextSettingItem AddText(string text, string hexColor) { string id = "ZUI_Text_" + Guid.NewGuid().ToString("N").Substring(0, 8); return AddText(id, text, UIUtils.ParseColor(hexColor)); } public TextSettingItem AddText(string id, string text, Color? color = null, TMP_FontAsset font = null, float? fontSize = null, FontStyles? fontStyle = null, TextAlignmentOptions? alignment = null, float? height = null) { TextSettingItem textSettingItem = new TextSettingItem(id, text, color, font, fontSize, fontStyle, alignment, height); AddItem(textSettingItem); return textSettingItem; } public TextSettingItem AddText(string id, string text, string hexColor) { return AddText(id, text, UIUtils.ParseColor(hexColor)); } public SpaceSettingItem AddSpace(float height = 15f) { SpaceSettingItem spaceSettingItem = new SpaceSettingItem(null, height); AddItem(spaceSettingItem); return spaceSettingItem; } public SpaceSettingItem AddSpacer(float height = 15f) { return AddSpace(height); } public DividerSettingItem AddDivider(string id = null) { DividerSettingItem dividerSettingItem = new DividerSettingItem(id); AddItem(dividerSettingItem); return dividerSettingItem; } public ButtonSettingItem AddButton(string id, string label, string buttonText, Action onClick) { ButtonSettingItem buttonSettingItem = new ButtonSettingItem(id, label, buttonText, onClick); AddItem(buttonSettingItem); return buttonSettingItem; } public ButtonSettingItem AddButton(string id, string label, string buttonText, Action onClick, float? width = null, float? height = null, ButtonAlignment alignment = ButtonAlignment.Right, string buttonHex = null, string textHex = null, float? fontSize = null, bool squishTextToFit = true) { ButtonSettingItem buttonSettingItem = new ButtonSettingItem(id, label, buttonText, onClick) { Width = width, Height = height, Alignment = alignment, FontSize = fontSize, SquishTextToFit = squishTextToFit }; if (!string.IsNullOrEmpty(buttonHex)) { buttonSettingItem.ButtonColorHex = buttonHex; } if (!string.IsNullOrEmpty(textHex)) { buttonSettingItem.TextColorHex = textHex; } AddItem(buttonSettingItem); return buttonSettingItem; } public ButtonSettingItem AddButton(ButtonSettingItem item) { if (item == null) { throw new ArgumentNullException("item"); } AddItem(item); return item; } } public class SettingsTemplates { public Transform LineTemplate { get; set; } public Transform ToggleTemplate { get; set; } public Transform SliderTemplate { get; set; } public Transform DropdownTemplate { get; set; } public Transform ButtonTemplate { get; set; } public static SettingsTemplates Discover(Transform content, Transform canvasRoot) { SettingsTemplates settingsTemplates = new SettingsTemplates(); if ((Object)(object)content == (Object)null) { return settingsTemplates; } settingsTemplates.LineTemplate = content.Find("Line"); if ((Object)(object)settingsTemplates.LineTemplate == (Object)null) { for (int i = 0; i < content.childCount; i++) { Transform child = content.GetChild(i); if (((Object)child).name.IndexOf("line", StringComparison.OrdinalIgnoreCase) >= 0) { settingsTemplates.LineTemplate = child; break; } } } settingsTemplates.ToggleTemplate = content.Find("subtitlesToggle"); if ((Object)(object)settingsTemplates.ToggleTemplate == (Object)null) { for (int j = 0; j < content.childCount; j++) { Transform child2 = content.GetChild(j); if ((Object)(object)((Component)child2).GetComponentInChildren<Toggle>(true) != (Object)null) { settingsTemplates.ToggleTemplate = child2; break; } } } settingsTemplates.SliderTemplate = content.Find("sensitivityMouseSlider") ?? content.Find("masterVolumeSlider") ?? content.Find("voicechatVolumeSlider"); if ((Object)(object)settingsTemplates.SliderTemplate == (Object)null) { for (int k = 0; k < content.childCount; k++) { Transform child3 = content.GetChild(k); if ((Object)(object)((Component)child3).GetComponentInChildren<Slider>(true) != (Object)null) { settingsTemplates.SliderTemplate = child3; break; } } } settingsTemplates.DropdownTemplate = content.Find("targetFpsDropdown") ?? content.Find("graphicsDrowdown") ?? content.Find("m_VSyncDropdown") ?? content.Find("voicechatDropdown"); if ((Object)(object)settingsTemplates.DropdownTemplate == (Object)null) { for (int l = 0; l < content.childCount; l++) { Transform child4 = content.GetChild(l); if ((Object)(object)((Component)child4).GetComponentInChildren<TMP_Dropdown>(true) != (Object)null) { settingsTemplates.DropdownTemplate = child4; break; } } } if ((Object)(object)canvasRoot != (Object)null) { Button[] componentsInChildren = ((Component)canvasRoot).GetComponentsInChildren<Button>(true); foreach (Button val in componentsInChildren) { if (((Object)((Component)val).gameObject).name == "ApplyButton") { settingsTemplates.ButtonTemplate = ((Component)val).transform; break; } } } return settingsTemplates; } } public static class ZUISettings { private const string ContentPath = "settingsPanel/Panel/Scroll View/Viewport/Content"; private static readonly SettingContainer _container = new SettingContainer(); private static MonoBehaviour _coroutineHost; private static bool _initialized = false; public static SettingContainer Container => _container; public static IReadOnlyList<ISettingItem> Items => _container.Items; public static void Initialize(MonoBehaviour host) { if (!_initialized) { _initialized = true; _coroutineHost = host; _container.OnChangesMade += MarkChangesMade; SceneManager.sceneLoaded += OnSceneLoaded; if ((Object)(object)_coroutineHost != (Object)null) { _coroutineHost.StartCoroutine(InstallWhenReadyRoutine()); } } } public static ToggleSettingItem AddToggle(string id, string label, bool defaultValue, Action<bool> onApply = null, Action<bool> onChanged = null) { ToggleSettingItem toggleSettingItem = _container.AddToggle(id, label, defaultValue, onApply, onChanged); InstallItemIfOpen(toggleSettingItem); return toggleSettingItem; } public static SliderSettingItem AddSlider(string id, string label, float minValue, float maxValue, float defaultValue, bool wholeNumbers = false, Func<float, string> valueFormatter = null, Action<float> onApply = null, Action<float> onChanged = null) { SliderSettingItem sliderSettingItem = _container.AddSlider(id, label, minValue, maxValue, defaultValue, wholeNumbers, valueFormatter, onApply, onChanged); InstallItemIfOpen(sliderSettingItem); return sliderSettingItem; } public static DropdownSettingItem AddDropdown(string id, string label, IList<string> options, int defaultIndex = 0, Action<int> onApply = null, Action<int> onChanged = null) { DropdownSettingItem dropdownSettingItem = _container.AddDropdown(id, label, options, defaultIndex, onApply, onChanged); InstallItemIfOpen(dropdownSettingItem); return dropdownSettingItem; } public static DropdownSettingItem AddDropdown<TEnum>(string id, string label, TEnum defaultValue = default(TEnum), Action<TEnum> onApply = null, Action<TEnum> onChanged = null) where TEnum : struct, Enum { DropdownSettingItem dropdownSettingItem = _container.AddDropdown(id, label, defaultValue, onApply, onChanged); InstallItemIfOpen(dropdownSettingItem); return dropdownSettingItem; } public static HeaderSettingItem AddHeader(string title) { HeaderSettingItem headerSettingItem = _container.AddHeader(title); InstallItemIfOpen(headerSettingItem); return headerSettingItem; } public static HeaderSettingItem AddHeader(string title, Color color) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) HeaderSettingItem headerSettingItem = _container.AddHeader(title, color); InstallItemIfOpen(headerSettingItem); return headerSettingItem; } public static HeaderSettingItem AddHeader(string title, string hexColor) { HeaderSettingItem headerSettingItem = _container.AddHeader(title, hexColor); InstallItemIfOpen(headerSettingItem); return headerSettingItem; } public static HeaderSettingItem AddHeader(string id, string title, Color? color = null, TMP_FontAsset font = null, float? fontSize = null, FontStyles? fontStyle = null, float? height = null) { HeaderSettingItem headerSettingItem = _container.AddHeader(id, title, color, font, fontSize, fontStyle, height); InstallItemIfOpen(headerSettingItem); return headerSettingItem; } public static HeaderSettingItem AddHeader(string id, string title, string hexColor) { HeaderSettingItem headerSettingItem = _container.AddHeader(id, title, hexColor); InstallItemIfOpen(headerSettingItem); return headerSettingItem; } public static TextSettingItem AddCategory(string title) { TextSettingItem textSettingItem = _container.AddCategory(title); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddCategory(string title, Color color) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) TextSettingItem textSettingItem = _container.AddCategory(title, color); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddCategory(string title, string hexColor) { TextSettingItem textSettingItem = _container.AddCategory(title, hexColor); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddCategory(string id, string title, Color? color = null, TMP_FontAsset font = null, float? fontSize = null, FontStyles? fontStyle = null, float? height = null) { TextSettingItem textSettingItem = _container.AddCategory(id, title, color, font, fontSize, fontStyle, height); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddCategory(string id, string title, string hexColor) { TextSettingItem textSettingItem = _container.AddCategory(id, title, hexColor); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddText(string text) { TextSettingItem textSettingItem = _container.AddText(text); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddText(string text, Color color) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) TextSettingItem textSettingItem = _container.AddText(text, color); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddText(string text, string hexColor) { TextSettingItem textSettingItem = _container.AddText(text, hexColor); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddText(string id, string text, Color? color = null, TMP_FontAsset font = null, float? fontSize = null, FontStyles? fontStyle = null, TextAlignmentOptions? alignment = null, float? height = null) { TextSettingItem textSettingItem = _container.AddText(id, text, color, font, fontSize, fontStyle, alignment, height); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static TextSettingItem AddText(string id, string text, string hexColor) { TextSettingItem textSettingItem = _container.AddText(id, text, hexColor); InstallItemIfOpen(textSettingItem); return textSettingItem; } public static SpaceSettingItem AddSpace(float height = 15f) { SpaceSettingItem spaceSettingItem = _container.AddSpace(height); InstallItemIfOpen(spaceSettingItem); return spaceSettingItem; } public static SpaceSettingItem AddSpacer(float height = 15f) { return AddSpace(height); } public static DividerSettingItem AddDivider(string id = null) { DividerSettingItem dividerSettingItem = _container.AddDivider(id); InstallItemIfOpen(dividerSettingItem); return dividerSettingItem; } public static ButtonSettingItem AddButton(string id, string label, string buttonText, Action onClick) { ButtonSettingItem buttonSettingItem = _container.AddButton(id, label, buttonText, onClick); InstallItemIfOpen(buttonSettingItem); return buttonSettingItem; } public static ButtonSettingItem AddButton(string id, string label, string buttonText, Action onClick, float? width = null, float? height = null, ButtonAlignment alignment = ButtonAlignment.Right, string buttonHex = null, string textHex = null, float? fontSize = null, bool squishTextToFit = true) { ButtonSettingItem buttonSettingItem = _container.AddButton(id, label, buttonText, onClick, width, height, alignment, buttonHex, textHex, fontSize, squishTextToFit); InstallItemIfOpen(buttonSettingItem); return buttonSettingItem; } public static ButtonSettingItem AddButton(ButtonSettingItem item) { if (item == null) { throw new ArgumentNullException("item"); } _container.AddItem(item); InstallItemIfOpen(item); return item; } public static void AddItem(ISettingItem item) { if (item != null) { if (!_container.Contains(item)) { _container.AddItem(item); } InstallItemIfOpen(item); } } private static void InstallItemIfOpen(ISettingItem item) { Transform val = FindContentTransform(); if ((Object)(object)val != (Object)null) { GameObject obj = FindCanvas(); Transform canvasRoot = ((obj != null) ? obj.transform : null); SettingsTemplates templates = SettingsTemplates.Discover(val, canvasRoot); if ((Object)(object)val.Find(item.Id) == (Object)null) { item.Instantiate(val, templates); } } } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if ((Object)(object)_coroutineHost != (Object)null) { _coroutineHost.StartCoroutine(InstallWhenReadyRoutine()); } } public static void OnSettingsOpened() { TryInstallElements(); RefreshUI(); SetApplyButtonInteractable(interactable: false); } public static IEnumerator InstallWhenReadyRoutine() { for (int i = 0; i < 120; i++) { if (TryInstallElements()) { break; } yield return null; } } public static bool TryInstallElements() { //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) Scene activeScene = SceneManager.GetActiveScene(); if (((Scene)(ref activeScene)).name == "SplashScreen" || string.IsNullOrEmpty(((Scene)(ref activeScene)).name)) { return false; } GameObject val = FindCanvas(); if ((Object)(object)val == (Object)null) { return false; } Transform val2 = val.transform.Find("settingsPanel/Panel/Scroll View/Viewport/Content"); if ((Object)(object)val2 == (Object)null) { return false; } SettingsTemplates templates = SettingsTemplates.Discover(val2, val.transform); foreach (ISettingItem item in _container.Items) { if ((Object)(object)val2.Find(item.Id) == (Object)null) { item.Instantiate(val2, templates); } } return true; } public static void MarkChangesMade() { if (ZUIPanel.CurrentOpenPanel != null) { ZUIPanel.CurrentOpenPanel.NotifyChangesMade(); return; } SetApplyButtonInteractable(interactable: true); if (!((Object)(object)StaticInstance<InitUI>.Instance != (Object)null)) { return; } try { typeof(InitUI).GetField("changesMade", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(StaticInstance<InitUI>.Instance, true); } catch { } } public static void SetApplyButtonInteractable(bool interactable) { if ((Object)(object)StaticInstance<InitUI>.Instance != (Object)null) { try { object? obj = typeof(InitUI).GetField("applyButton", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(StaticInstance<InitUI>.Instance); Button val = (Button)((obj is Button) ? obj : null); if ((Object)(object)val != (Object)null) { ((Selectable)val).interactable = interactable; return; } } catch { } } GameObject val2 = FindCanvas(); if (!((Object)(object)val2 != (Object)null)) { return; } Button[] componentsInChildren = val2.GetComponentsInChildren<Button>(true); foreach (Button val3 in componentsInChildren) { if (((Object)((Component)val3).gameObject).name == "ApplyButton") { ((Selectable)val3).interactable = interactable; break; } } } public static void ApplyPending() { _container.ApplyPending(); SetApplyButtonInteractable(interactable: false); } public static void RevertPending() { _container.RevertPending(); SetApplyButtonInteractable(interactable: false); } public static void RefreshUI() { _container.RefreshUI(); } public static Transform FindContentTransform() { GameObject val = FindCanvas(); return ((Object)(object)val == (Object)null) ? null : val.transform.Find("settingsPanel/Panel/Scroll View/Viewport/Content"); } public static GameObject FindCanvas() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.Find("InGameUICanvas"); if ((Object)(object)val != (Object)null) { return val; } GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>(); foreach (GameObject val2 in array) { if (((Object)val2).name == "InGameUICanvas") { Scene scene = val2.scene; if (((Scene)(ref scene)).IsValid()) { return val2; } } } return null; } public static void Shutdown() { SceneManager.sceneLoaded -= OnSceneLoaded; _container.DestroyItems(); _coroutineHost = null; _initialized = false; } } } namespace ZUI.Settings.Patches { [HarmonyPatch(typeof(InitUI), "ApplyChanges_Btn")] internal static class ApplySettingsPatch { [HarmonyPostfix] private static void Postfix() { ZUISettings.ApplyPending(); } } [HarmonyPatch(typeof(InitUI), "RevertAllChanges")] internal static class RevertSettingsPatch { [HarmonyPostfix] private static void Postfix() { ZUISettings.RevertPending(); } } [HarmonyPatch(typeof(InitUI), "OpenSettings_Btn")] internal static class OpenSettingsPatch { [HarmonyPostfix] private static void Postfix() { ZUISettings.OnSettingsOpened(); } } [HarmonyPatch(typeof(ButtonFunctions), "OpenSettings_Btn")] internal static class ButtonFunctionsOpenSettingsPatch { [HarmonyPostfix] private static void Postfix() { ZUISettings.OnSettingsOpened(); } } } namespace ZUI.Screens { public class ZUIScreen { private static readonly Dictionary<string, ZUIScreen> _registry = new Dictionary<string, ZUIScreen>(StringComparer.OrdinalIgnoreCase); public static IReadOnlyDictionary<string, ZUIScreen> Registry => _registry; public static ZUIScreen CurrentOpenScreen => ZUIScreenController.CurrentOpenScreen; public static bool IsAnyScreenOpen => ZUIScreenController.CurrentOpenScreen != null; public string Id { get; } public string Title { get; set; } public string TitleHex { get; set; } public bool ShowLeftHeader { get; set; } = true; public string CloseButtonLabel { get; set; } = "CLOSE"; public PauseMenuDrawer RootDrawer { get; } public PauseMenuRightPanel RightPanel => RootDrawer.RightPanel; public Action OnOpened { get; set; } public Action OnClosed { get; set; } public bool IsOpen => CurrentOpenScreen == this; internal ZUIScreenView ViewInstance { get; set; } public ZUIScreen(string id, string title, bool paginated = true, string titleHex = null) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } Id = id; Title = title ?? string.Empty; TitleHex = titleHex; RootDrawer = new PauseMenuDrawer("zui_screen_root_" + id, Title, paginated, titleHex) { OwningScreen = this }; RootDrawer.RightPanel.SetHeader(Title.ToUpperInvariant(), string.Empty, titleHex); } public static void Initialize(MonoBehaviour host) { ZUIScreenController.EnsureInitialized(host); } public static ZUIScreen Register(string id, string title, bool paginated = true, string titleHex = null) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } if (_registry.TryGetValue(id, out var value)) { value.Title = title ?? string.Empty; value.TitleHex = titleHex; value.RootDrawer.Title = value.Title; value.RootDrawer.Paginated = paginated; value.RootDrawer.BreadcrumbHex = titleHex; return value; } ZUIScreen zUIScreen = new ZUIScreen(id, title, paginated, titleHex); _registry[id] = zUIScreen; return zUIScreen; } public static ZUIScreen Get(string id) { if (string.IsNullOrEmpty(id)) { return null; } _registry.TryGetValue(id, out var value); return value; } public static bool Unregister(string id) { if (string.IsNullOrEmpty(id)) { return false; } if (_registry.TryGetValue(id, out var value)) { if (CurrentOpenScreen == value) { value.Close(); } if (value.ViewInstance != null) { value.ViewInstance.DestroyView(); value.ViewInstance = null; } _registry.Remove(id); return true; } return false; } public static void Open(string id) { ZUIScreen zUIScreen = Get(id); if (zUIScreen == null) { Plugin.Log.LogWarning((object)("[ZUIScreen] Screen with ID '" + id + "' is not registered.")); } else { zUIScreen.Open(); } } public static void Toggle(string id) { ZUIScreen zUIScreen = Get(id); if (zUIScreen == null) { Plugin.Log.LogWarning((object)("[ZUIScreen] Screen with ID '" + id + "' is not registered.")); } else { zUIScreen.Toggle(); } } public static void CloseActive() { if (CurrentOpenScreen != null) { ZUIScreenController.CloseScreen(CurrentOpenScreen); } } public static void Shutdown() { CloseActive(); foreach (ZUIScreen value in _registry.Values) { if (value.ViewInstance != null) { value.ViewInstance.DestroyView(); value.ViewInstance = null; } } _registry.Clear(); } public void Open() { ZUIScreenController.OpenScreen(this); } public void Close() { if (CurrentOpenScreen == this) { ZUIScreenController.CloseScreen(this); } } public void Toggle() { if (IsOpen) { Close(); } else { Open(); } } public void PushDrawer(PauseMenuDrawer drawer) { if (drawer != null) { drawer.OwningScreen = this; ViewInstance?.PushDrawer(drawer); } } public void PopDrawer() { ViewInstance?.PopDrawer(); } public ZUIScreen SetTitle(string title, string titleHex = null) { Title = title ?? string.Empty; if (titleHex != null) { TitleHex = titleHex; } RootDrawer.Title = Title; if (titleHex != null) { RootDrawer.BreadcrumbHex = titleHex; } ZUIScreenController.RefreshIfOpen(this); return this; } public PauseMenuButtonRegistration AddButton(string id, string label, Action onClick, int priority = 0) { return RootDrawer.AddButton(id, label, onClick, priority); } public PauseMenuDrawer AddSubmenu(string id, string label, bool paginated = true, int priority = 0, string breadcrumbHex = null) { return RootDrawer.AddSubmenu(id, label, paginated, priority, breadcrumbHex); } public bool RemoveButton(string id) { return RootDrawer.RemoveButton(id); } public ZUIScreen SetRightHeader(string title, string counter = "", string titleHex = null, string counterHex = null) { RightPanel.SetHeader(title, counter, titleHex, counterHex); return this; } public ZUIScreen SetContent(GameObject customRoot) { RightPanel.SetCustomContent(customRoot); return this; } public PauseMenuRightCard AddCard(string id, string title, string subtitle = null, Sprite icon = null, Action onClick = null, float? height = null, string titleHex = null, string subtitleHex = null) { return RightPanel.AddCard(id, title, subtitle, icon, onClick, height, titleHex, subtitleHex); } public PauseMenuRightCard AddEntry(string id, string title, string subtitle = null, Sprite icon = null, Action onClick = null, float? height = null, string titleHex = null, string subtitleHex = null) { return RightPanel.AddCard(id, title, subtitle, icon, onClick, height, titleHex, subtitleHex); } public PauseMenuRightButton AddRightButton(string id, string label, Action onClick, float? height = null, string textHex = null, string backgroundHex = null) { return RightPanel.AddButton(id, label, onClick, height, textHex, backgroundHex); } } public class ZUIScreenController : MonoBehaviour { private static readonly PropertyInfo IsGamePausedProp = typeof(InGameUI).GetProperty("IsGamePaused", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); public static ZUIScreenController Instance { get; private set; } public static ZUIScreen CurrentOpenScreen { get; private set; } public static int LastEscConsumedFrame { get; internal set; } = -1; public static void EnsureInitialized(MonoBehaviour host) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Instance != (Object)null)) { GameObject val = (GameObject)(((Object)(object)host != (Object)null) ? ((object)((Component)host).gameObject) : ((object)new GameObject("ZUIScreenController"))); Instance = val.GetComponent<ZUIScreenController>() ?? val.AddComponent<ZUIScreenController>(); Object.DontDestroyOnLoad((Object)(object)((Component)Instance).gameObject); } } private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); SceneManager.sceneLoaded += OnSceneLoaded; } else if ((Object)(object)Instance != (Object)(object)this) { Object.Destroy((Object)(object)this); } } private void OnDestroy() { if ((Object)(object)Instance == (Object)(object)this) { SceneManager.sceneLoaded -= OnSceneLoaded; Instance = null; } } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { CurrentOpenScreen = null; foreach (ZUIScreen value in ZUIScreen.Registry.Values) { if (value.ViewInstance != null) { value.ViewInstance.CleanupBeforeSceneUnload(); value.ViewInstance = null; } } } public bool HandleEscape() { if (CurrentOpenScreen == null) { return false; } if (Time.frameCount == LastEscConsumedFrame) { return true; } if (ZUIPanelController.CurrentOpenPanel != null || ZUIPanelController.LastEscConsumedFrame == Time.frameCount) { return true; } if (ZUIPopup.LastEscConsumedFrame == Time.frameCount) { return true; } LastEscConsumedFrame = Time.frameCount; InitUI instance = StaticInstance<InitUI>.Instance; if (instance != null) { instance.PlayClickSFX(); } ZUIScreenView viewInstance = CurrentOpenScreen.ViewInstance; if (viewInstance != null && viewInstance.HasNestedDrawers) { viewInstance.PopDrawer(); } else { CloseScreen(CurrentOpenScreen); } return true; } public static void OpenScreen(ZUIScreen screen) { if (screen == null) { throw new ArgumentNullException("screen"); } if (CurrentOpenScreen == screen) { screen.ViewInstance?.RefreshView(); return; } if (CurrentOpenScreen != null) { HideScreenInternal(CurrentOpenScreen); } if (ZUIPanel.CurrentOpenPanel != null) { ZUIPanel.CloseActive(); } if (ZUIPauseMenu.IsOpen) { ZUIPauseMenu.Close(); } GameObject val = ZUISettings.FindCanvas(); if ((Object)(object)val == (Object)null) { Plugin.Log.LogError((object)("[ZUIScreen] Cannot open screen '" + screen.Id + "': InGameUICanvas not found in active scene.")); return; } GameObject val2 = FindVanillaPausePanel(val); if ((Object)(object)val2 == (Object)null) { Plugin.Log.LogError((object)("[ZUIScreen] Cannot open screen '" + screen.Id + "': vanilla pausePanel template not found.")); return; } if (screen.ViewInstance == null || (Object)(object)screen.ViewInstance.RootObject == (Object)null) { screen.ViewInstance = ZUIScreenView.Create(screen, val.transform, val2); } if (screen.ViewInstance == null || (Object)(object)screen.ViewInstance.RootObject == (Object)null) { Plugin.Log.LogError((object)("[ZUIScreen] Failed to build screen view for '" + screen.Id + "'.")); return; } CurrentOpenScreen = screen; screen.ViewInstance.Show(val2.transform.GetSiblingIndex() + 1); InGameUI.RecalculateCursorLock(); ApplyCursorAndInputLock(); screen.OnOpened?.Invoke(); } public static void CloseScreen(ZUIScreen screen) { if (screen != null) { if (Input.GetKey((KeyCode)27) || Input.GetKeyDown((KeyCode)27)) { LastEscConsumedFrame = Time.frameCount; } HideScreenInternal(screen); InGameUI.RecalculateCursorLock(); } } private static void HideScreenInternal(ZUIScreen screen) { if (screen.ViewInstance != null) { screen.ViewInstance.Hide(); } if (CurrentOpenScreen == screen) { CurrentOpenScreen = null; } screen.OnClosed?.Invoke(); } internal static void RefreshIfOpen(ZUIScreen screen) { if (screen != null && CurrentOpenScreen == screen && screen.ViewInstance != null) { screen.ViewInstance.RefreshView(); } } internal static bool IsDisplayingRightPanel(PauseMenuRightPanel panel) { return panel != null && CurrentOpenScreen != null && CurrentOpenScreen.ViewInstance != null && CurrentOpenScreen.ViewInstance.CurrentRightPanel == panel; } internal static void SyncRightPanelIfDisplayed(PauseMenuRightPanel panel) { if (IsDisplayingRightPanel(panel)) { CurrentOpenScreen.ViewInstance.SyncRightPanel(); } } internal static void ApplyRightPanelHeaderIfDisplayed(PauseMenuRightPanel panel) { if (IsDisplayingRightPanel(panel)) { CurrentOpenScreen.ViewInstance.ApplyRightPanelHeader(); } } internal static void RebuildActiveRightLayout() { if (CurrentOpenScreen != null && CurrentOpenScreen.ViewInstance != null) { CurrentOpenScreen.ViewInstance.RebuildRightLayout(); } } internal static void ApplyCursorAndInputLock() { if (CurrentOpenScreen != null) { try { IsGamePausedProp?.SetValue(null, true); } catch { } Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; } } private static GameObject FindVanillaPausePanel(GameObject canvas) { if ((Object)(object)StaticInstance<InGameUI>.Instance != (Object)null) { try { object? obj = typeof(InGameUI).GetField("pauseMenu", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(StaticInstance<InGameUI>.Instance); GameObject val = (GameObject)((obj is GameObject) ? obj : null); if (val != null && (Object)(object)val != (Object)null) { return val; } } catch { } } if ((Object)(object)canvas != (Object)null) { Transform val2 = canvas.transform.Find("pausePanel"); if ((Object)(object)val2 != (Object)null) { return ((Component)val2).gameObject; } } return null; } } internal class ZUIScreenView { public const int MaxSlots = 6; public const int PaginatedSlotsPerPage = 5; private GameObject _leftHeaderObj; private TMP_Text _leftHeaderText; private GameObject _buttonTemplate; private readonly GameObject[] _modSlots = (GameObject[])(object)new GameObject[6]; private readonly TextMeshProUGUI[] _modSlotTexts = (TextMeshProUGUI[])(object)new TextMeshProUGUI[6]; private readonly Button[] _modSlotButtons = (Button[])(object)new Button[6]; private readonly CanvasGroup[] _modSlotCanvasGroups = (CanvasGroup[])(object)new CanvasGroup[6]; private GameObject _backButtonObj; private TextMeshProUGUI _backButtonText; private GameObject _paginationRow; private Button _prevButton; private Button _nextButton; private TextMeshProUGUI _prevButtonText; private TextMeshProUGUI _nextButtonText; private TextMeshProUGUI _pageIndicatorText; private ArrowButtonHoverEffect _prevHoverEffect; private ArrowButtonHoverEffect _nextHoverEffect; private GameObject _breadcrumbBar; private TextMeshProUGUI _breadcrumbText; private GameObject _rightContainerObj; private Transform _rightTopTransform; private readonly List<GameObject> _spawnedRightItems = new List<GameObject>(); private readonly Stack<PauseMenuDrawer> _navigationStack = new Stack<PauseMenuDrawer>(); public ZUIScreen Screen { get; } public GameObject RootObject { get; private set; } public int CurrentPage { get; private set; } = 0; public bool HasNestedDrawers => _navigationStack.Count > 0; public PauseMenuDrawer CurrentDrawer => (_navigationStack.Count > 0) ? _navigationStack.Peek() : Screen.RootDrawer; public PauseMenuRightPanel CurrentRightPanel { get; private set; } private ZUIScreenView(ZUIScreen screen) { Screen = screen; } public static ZUIScreenView Create(ZUIScreen screen, Transform canvasTransform, GameObject vanillaPausePanel) { ZUIScreenView zUIScreenView = new ZUIScreenView(screen); if (!zUIScreenView.BuildHierarchy(canvasTransform, vanillaPausePanel)) { return null; } return zUIScreenView; } private bool BuildHierarchy(Transform canvasTransform, GameObject vanillaPausePanel) { //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Expected O, but got Unknown RootObject = Object.Instantiate<GameObject>(vanillaPausePanel, canvasTransform, false); ((Object)RootObject).name = "ZUI_CustomScreen_" + Screen.Id; RootObject.SetActive(false); Transform val = RootObject.transform.Find("Buttons/Buttons"); Transform val2 = RootObject.transform.Find("Players"); Transform val3 = RootObject.transform.Find("Players/Players"); if ((Object)(object)val == (Object)null || (Object)(object)val3 == (Object)null) { Plugin.Log.LogError((object)("[ZUIScreen] Cloned pausePanel for '" + Screen.Id + "' is missing Buttons/Buttons or Players/Players.")); Object.Destroy((Object)(object)RootObject); RootObject = null; return false; } PauseMenuTabController component = ((Component)val).GetComponent<PauseMenuTabController>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } Transform val4 = val.Find("Header"); if ((Object)(object)val4 != (Object)null) { _leftHeaderObj = ((Component)val4).gameObject; LocalizedTextUI componentInChildren = _leftHeaderObj.GetComponentInChildren<LocalizedTextUI>(true); if ((Object)(object)componentInChildren != (Object)null) { Object.DestroyImmediate((Object)(object)componentInChildren); } _leftHeaderText = _leftHeaderObj.GetComponentInChildren<TMP_Text>(true); } Transform val5 = val.Find("QuitButton"); if ((Object)(object)val5 == (Object)null) { Plugin.Log.LogError((object)("[ZUIScreen] Cloned pausePanel for '" + Screen.Id + "' is missing QuitButton template.")); Object.Destroy((Object)(object)RootObject); RootObject = null; return false; } _buttonTemplate = Object.Instantiate<GameObject>(((Component)val5).gameObject, RootObject.transform); ((Object)_buttonTemplate).name = "ZUI_ScreenButtonTemplate"; CleanupClonedButton(_buttonTemplate); _buttonTemplate.SetActive(false); List<GameObject> list = new List<GameObject>(); for (int i = 0; i < val.childCount; i++) { Transform child = val.GetChild(i); if ((Object)(object)child != (Object)(object)val4) { list.Add(((Component)child).gameObject); } } for (int j = 0; j < list.Count; j++) { Object.DestroyImmediate((Object)(object)list[j]); } Navigation navigation; for (int k = 0; k < 6; k++) { GameObject val6 = Object.Instantiate<GameObject>(_buttonTemplate, val); ((Object)val6).name = $"ZUI_ScreenSlot_{k}"; CleanupClonedButton(val6); _modSlots[k] = val6; _modSlotTexts[k] = val6.GetComponentInChildren<TextMeshProUGUI>(true); _modSlotButtons[k] = val6.GetComponent<Button>(); if ((Object)(object)_modSlotButtons[k] != (Object)null) { Button obj = _modSlotButtons[k]; navigation = default(Navigation); ((Navigation)(ref navigation)).mode = (Mode)0; ((Selectable)obj).navigation = navigation; } CanvasGroup val7 = val6.GetComponent<CanvasGroup>() ?? val6.AddComponent<CanvasGroup>(); _modSlotCanvasGroups[k] = val7; val6.SetActive(false); } _backButtonObj = Object.Instantiate<GameObject>(_buttonTemplate, val); ((Object)_backButtonObj).name = "ZUI_ScreenBackButton"; CleanupClonedButton(_backButtonObj); _backButtonText = _backButtonObj.