using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("FishyUI")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0")] [assembly: AssemblyProduct("FishyUI")] [assembly: AssemblyTitle("FishyUI")] [assembly: AssemblyVersion("0.1.0.0")] namespace FishyUI; internal static class Options { public static Page Page(string title) { if (string.IsNullOrWhiteSpace(title)) { title = "Unnamed"; } Page page = Registry.Find(title); if (page == null) { page = new Page(title.Trim()); Registry.Add(page); } return page; } public static void Remove(string title) { Page page = Registry.Find(title); if (page != null) { Registry.Remove(page); } } public static void Remove(Page page) { Registry.Remove(page); } public static Page AutoPage(ConfigFile config, string title) { Page page = Page(title); if (config != null) { AutoPages.Fill(page, config); } return page; } } public class Page { internal readonly string Title; internal readonly List Rows = new List(); internal int Version; public int RowCount => Rows.Count; internal Page(string title) { Title = title; } public Page Search(string hint = "Search") { return Add(new Row { Kind = RowKind.Search, Label = hint, Height = 0.9f }); } public Page Header(string text) { return Add(new Row { Kind = RowKind.Header, Label = text, Height = 0.7f }); } public Page Label(string text) { return Add(new Row { Kind = RowKind.Label, Label = text, Height = 0.6f }); } public Page Space(float rows = 0.5f) { return Add(new Row { Kind = RowKind.Space, Height = Mathf.Clamp(rows, 0.1f, 3f) }); } public Page Toggle(string label, ConfigEntry entry) { return Add(new Row { Kind = RowKind.Toggle, Label = label, Get = () => entry.Value, Set = delegate(object v) { entry.Value = (bool)v; } }); } public Page Toggle(string label, bool value, Action onChanged) { return Add(new Row { Kind = RowKind.Toggle, Label = label, Get = () => value, Set = delegate(object v) { value = (bool)v; onChanged?.Invoke(value); } }); } public Page Slider(string label, ConfigEntry entry) { float min = 0f; float max = 1f; AutoPages.TryRange((ConfigEntryBase)(object)entry, ref min, ref max); return Slider(label, entry, min, max); } public Page Slider(string label, ConfigEntry entry, float min, float max) { return Add(new Row { Kind = RowKind.Slider, Label = label, Min = min, Max = max, Get = () => entry.Value, Set = delegate(object v) { entry.Value = (float)v; } }); } public Page Slider(string label, ConfigEntry entry) { float min = 0f; float max = 10f; AutoPages.TryRange((ConfigEntryBase)(object)entry, ref min, ref max); return Slider(label, entry, (int)min, (int)max); } public Page Slider(string label, ConfigEntry entry, int min, int max) { return Add(new Row { Kind = RowKind.Slider, Label = label, Min = min, Max = max, Whole = true, Get = () => (float)entry.Value, Set = delegate(object v) { entry.Value = Mathf.RoundToInt((float)v); } }); } public Page Slider(string label, float value, float min, float max, Action onChanged) { return Add(new Row { Kind = RowKind.Slider, Label = label, Min = min, Max = max, Get = () => value, Set = delegate(object v) { value = (float)v; onChanged?.Invoke(value); } }); } public Page Dropdown(string label, ConfigEntry entry) where T : Enum { string[] names = Enum.GetNames(typeof(T)); Array values = Enum.GetValues(typeof(T)); return Add(new Row { Kind = RowKind.Cycle, Label = label, OptionsF = () => names, Get = () => Mathf.Max(0, ((IList)values).IndexOf((object?)entry.Value)), Set = delegate(object v) { entry.Value = (T)values.GetValue((int)v); } }); } public Page Dropdown(string label, string[] options, int index, Action onChanged) { if (options == null || options.Length == 0) { options = new string[1] { "-" }; } int cur = Mathf.Clamp(index, 0, options.Length - 1); return Add(new Row { Kind = RowKind.Cycle, Label = label, OptionsF = () => options, Get = () => cur, Set = delegate(object v) { cur = (int)v; onChanged?.Invoke(cur); } }); } public Page Input(string label, ConfigEntry entry) { return Add(new Row { Kind = RowKind.Input, Label = label, Get = () => entry.Value, Set = delegate(object v) { entry.Value = (string)v; } }); } public Page Input(string label, string value, Action onChanged) { string cur = value ?? ""; return Add(new Row { Kind = RowKind.Input, Label = label, Get = () => cur, Set = delegate(object v) { cur = (string)v; onChanged?.Invoke(cur); } }); } public Page Colour(string label, ConfigEntry entry) { return Add(new Row { Kind = RowKind.Colour, Label = label, Get = () => entry.Value, Set = delegate(object v) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) entry.Value = (Color)v; }, GetDefault = () => ((ConfigEntryBase)entry).DefaultValue }); } public Page Colour(string label, Color value, Action onChanged) { //IL_000e: 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) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) Color cur = value; Color def = value; return Add(new Row { Kind = RowKind.Colour, Label = label, Get = () => cur, Set = delegate(object v) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) cur = (Color)v; onChanged?.Invoke(cur); }, GetDefault = () => def }); } public Page Keybind(string label, ConfigEntry entry) { return Add(new Row { Kind = RowKind.Keybind, Label = label, Get = () => entry.Value, Set = delegate(object v) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) entry.Value = (KeyboardShortcut)v; } }); } public Page Keybind(string label, ConfigEntry entry) { return Add(new Row { Kind = RowKind.Keybind, Label = label, KeyOnly = true, Get = () => entry.Value, Set = delegate(object v) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) entry.Value = (KeyCode)v; } }); } public Page Bar(string label, Func value) { return Add(new Row { Kind = RowKind.Bar, Label = label, Live = () => value() }); } public Page Readout(string label, Func value) { return Add(new Row { Kind = RowKind.Readout, Label = label, Live = () => value() }); } public Page Button(string label, Action onClick) { return Add(new Row { Kind = RowKind.Button, Label = label, Click = onClick }); } public Page Buttons(params (string label, Action onClick)[] buttons) { return Add(new Row { Kind = RowKind.Buttons, Multi = buttons }); } public Page Custom(string label, float heightRows, Action build) { return Add(new Row { Kind = RowKind.Custom, Label = label, Height = Mathf.Clamp(heightRows, 0.3f, 10f), CustomBuild = build }); } public Page Tip(ConfigEntryBase entry) { string text = ((entry != null && entry.Description != null) ? entry.Description.Description : null); if (!string.IsNullOrEmpty(text)) { return Tip(text); } return this; } public Page Tip(string text) { if (Rows.Count > 0) { Rows[Rows.Count - 1].Tip = text; } return this; } public Page Clear() { Rows.Clear(); Version++; Registry.MarkDirty(); return this; } internal Page AddRow(Row r) { return Add(r); } private Page Add(Row r) { Rows.Add(r); Version++; Registry.MarkDirty(); return this; } } internal enum RowKind { Header, Label, Space, Toggle, Slider, Cycle, Input, Colour, Keybind, Button, Buttons, Bar, Readout, Search, Custom } internal class Row { public RowKind Kind; public string Label; public Func Get; public Action Set; public Func GetDefault; public Func Live; public string Tip; public Action CustomBuild; public float Min; public float Max; public bool Whole; public bool KeyOnly; public Func OptionsF; public Action Click; public (string label, Action act)[] Multi; public float Height = 1f; } internal static class Registry { private static readonly List Pages = new List(); public static bool Dirty; public static List All => Pages; public static int Count => Pages.Count; public static void Add(Page p) { Pages.Add(p); MarkDirty(); } public static void Remove(Page p) { if (p != null && Pages.Remove(p)) { MarkDirty(); } } public static Page Find(string title) { foreach (Page page in Pages) { if (string.Equals(page.Title, title, StringComparison.OrdinalIgnoreCase)) { return page; } } return null; } public static void MarkDirty() { Dirty = true; Injector.OnRegistryChanged(); } public static Dictionary KeyUse() { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) Dictionary dictionary = new Dictionary(); foreach (Page page in Pages) { foreach (Row row in page.Rows) { if (row.Kind == RowKind.Keybind && row.Get != null) { object obj; try { obj = row.Get(); } catch { continue; } KeyCode val = (KeyCode)((!(obj is KeyboardShortcut val2)) ? ((obj is KeyCode val3) ? ((int)val3) : 0) : ((int)((KeyboardShortcut)(ref val2)).MainKey)); if ((int)val != 0) { dictionary.TryGetValue(val, out var value); dictionary[val] = value + 1; } } } } return dictionary; } } internal static class AutoPages { public static void Fill(Page p, ConfigFile cfg) { List list = new List(); Dictionary> dictionary = new Dictionary>(); foreach (ConfigDefinition key in cfg.Keys) { ConfigEntryBase val = cfg[key]; if (val != null) { string text = key.Section ?? ""; if (!dictionary.TryGetValue(text, out var value)) { value = (dictionary[text] = new List()); list.Add(text); } value.Add(val); } } bool flag = list.Count > 1; foreach (string item in list) { if (flag) { p.Header(string.IsNullOrEmpty(item) ? "General" : item); } foreach (ConfigEntryBase item2 in dictionary[item]) { AddEntry(p, item2); } } } private static void AddEntry(Page p, ConfigEntryBase e) { int count = p.Rows.Count; AddRowFor(p, e); string text = ((e.Description != null) ? e.Description.Description : null); if (!string.IsNullOrEmpty(text) && p.Rows.Count > count) { p.Tip(text); } } private static void AddRowFor(Page p, ConfigEntryBase e) { Type settingType = e.SettingType; string key = e.Definition.Key; if (settingType == typeof(bool)) { p.Toggle(key, (ConfigEntry)(object)e); } else if (settingType == typeof(string)) { if (TryListOptions(e, out var opts)) { p.AddRow(new Row { Kind = RowKind.Cycle, Label = key, OptionsF = () => opts, Get = () => Mathf.Max(0, Array.IndexOf(opts, (string)e.BoxedValue)), Set = delegate(object v) { e.BoxedValue = opts[(int)v]; } }); } else { p.Input(key, (ConfigEntry)(object)e); } } else if (settingType == typeof(float) || settingType == typeof(int) || settingType == typeof(double)) { float min = 0f; float max = 0f; if (TryRange(e, ref min, ref max)) { if (settingType == typeof(float)) { p.Slider(key, (ConfigEntry)(object)e, min, max); } else if (settingType == typeof(int)) { p.Slider(key, (ConfigEntry)(object)e, (int)min, (int)max); } else { NumberInput(p, key, e, min, max, clamp: true); } } else { NumberInput(p, key, e, float.MinValue, float.MaxValue, clamp: false); } } else if (settingType.IsEnum) { string[] names = Enum.GetNames(settingType); Array values = Enum.GetValues(settingType); p.AddRow(new Row { Kind = RowKind.Cycle, Label = key, OptionsF = () => names, Get = () => Mathf.Max(0, ((IList)values).IndexOf(e.BoxedValue)), Set = delegate(object v) { e.BoxedValue = values.GetValue((int)v); } }); } else if (settingType == typeof(Color)) { p.Colour(key, (ConfigEntry)(object)e); } else if (settingType == typeof(KeyboardShortcut)) { p.Keybind(key, (ConfigEntry)(object)e); } else if (settingType == typeof(KeyCode)) { p.Keybind(key, (ConfigEntry)(object)e); } else { Plugin.Log.LogDebug((object)("AutoPage skipped '" + key + "' (" + settingType.Name + ")")); } } private static void NumberInput(Page p, string label, ConfigEntryBase e, float min, float max, bool clamp) { Type t = e.SettingType; p.AddRow(new Row { Kind = RowKind.Input, Label = label, Get = () => Convert.ToDouble(e.BoxedValue).ToString("0.###", CultureInfo.InvariantCulture), Set = delegate(object v) { if (double.TryParse((((string)v) ?? "").Trim().Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { if (clamp) { result = Math.Min(max, Math.Max(min, result)); } if (t == typeof(int)) { e.BoxedValue = (int)Math.Round(result); } else if (t == typeof(float)) { e.BoxedValue = (float)result; } else { e.BoxedValue = result; } } } }); } public static bool TryRange(ConfigEntryBase e, ref float min, ref float max) { AcceptableValueBase val = ((e.Description != null) ? e.Description.AcceptableValues : null); if (val is AcceptableValueRange val2) { min = val2.MinValue; max = val2.MaxValue; } else if (val is AcceptableValueRange val3) { min = val3.MinValue; max = val3.MaxValue; } else { if (!(val is AcceptableValueRange val4)) { return false; } min = (float)val4.MinValue; max = (float)val4.MaxValue; } return max > min; } private static bool TryListOptions(ConfigEntryBase e, out string[] options) { options = null; if (((e.Description != null) ? e.Description.AcceptableValues : null) is AcceptableValueList val && val.AcceptableValues != null && val.AcceptableValues.Length != 0) { options = val.AcceptableValues; return true; } return false; } } internal static class Chooser { private static GameObject _open; private static Window _plain; private static readonly Dictionary Mats = new Dictionary(); private static readonly Dictionary Cols = new Dictionary(); public static void Close() { if ((Object)(object)_open != (Object)null) { Object.Destroy((Object)(object)_open); } _open = null; _plain = null; Mats.Clear(); Cols.Clear(); } public static void Open(Widgets w, RectTransform anchor, string[] options, int current, Action pick) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_03d2: Unknown result type (might be due to invalid IL or missing references) //IL_03dc: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Expected O, but got Unknown //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_040f: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_0445: Unknown result type (might be due to invalid IL or missing references) //IL_046b: Unknown result type (might be due to invalid IL or missing references) //IL_04c2: Unknown result type (might be due to invalid IL or missing references) //IL_04c7: Unknown result type (might be due to invalid IL or missing references) //IL_0495: Unknown result type (might be due to invalid IL or missing references) //IL_049a: Unknown result type (might be due to invalid IL or missing references) //IL_049f: Unknown result type (might be due to invalid IL or missing references) //IL_0533: Unknown result type (might be due to invalid IL or missing references) //IL_053d: Unknown result type (might be due to invalid IL or missing references) Close(); if (w == null || (Object)(object)anchor == (Object)null || options == null || options.Length == 0) { return; } Canvas componentInParent = ((Component)anchor).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null) { return; } RectTransform val = (RectTransform)((Component)componentInParent).transform; GameObject val2 = new GameObject("ChooserBack", new Type[1] { typeof(RectTransform) }); RectTransform val3 = (RectTransform)val2.transform; ((Transform)val3).SetParent((Transform)(object)val, false); val3.anchorMin = Vector2.zero; val3.anchorMax = Vector2.one; val3.offsetMin = Vector2.zero; val3.offsetMax = Vector2.zero; ((Graphic)val2.AddComponent()).color = Color.clear; Button obj = val2.AddComponent