Decompiled source of DSP mod settings v0.2.4
plugins/DSP_mod_settings.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using DSP_Mod_Settings.Integration; using DSP_Mod_Settings.Patches; using HarmonyLib; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using UnityEngine.UI.Youthcat; [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: AssemblyVersion("0.0.0.0")] namespace DSP_Mod_Settings { public static class ModSettingsApi { public static TabHandle RegisterTab(string modGuid, string title, int order = 0) { if (string.IsNullOrEmpty(modGuid) || string.IsNullOrEmpty(title)) { Warn("RegisterTab needs a non-empty mod GUID and title; call ignored."); return new TabHandle(null); } RegistrationRegistry.RegisteredTab orCreateTab = RegistrationRegistry.GetOrCreateTab(modGuid, title, order); return new TabHandle(orCreateTab); } internal static void Warn(string message) { if (DSP_Mod_Settings_Plugin.Log != null) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)("[ModSettings] " + message)); } } internal static TabHandle Inert() { return new TabHandle(null); } } public sealed class TabHandle { internal readonly RegistrationRegistry.RegisteredTab Target; public string Title { get { if (Target != null) { return Target.Title; } return string.Empty; } } internal TabHandle(RegistrationRegistry.RegisteredTab target) { Target = target; } public GroupHandle Group(string title, int order = 0) { if (Target == null) { return new GroupHandle(null); } if (string.IsNullOrEmpty(title)) { ModSettingsApi.Warn("Group needs a non-empty title; call ignored."); return new GroupHandle(null); } RegistrationRegistry.RegisteredGroup orCreateGroup = RegistrationRegistry.GetOrCreateGroup(Target, title, order); return new GroupHandle(orCreateGroup); } } public sealed class GroupHandle { internal readonly RegistrationRegistry.RegisteredGroup Target; public string Title { get { if (Target != null) { return Target.Title; } return string.Empty; } } internal GroupHandle(RegistrationRegistry.RegisteredGroup target) { Target = target; } public GroupHandle Int(string label, Func<int> get, Action<int> set) { return Int(label, get, set, requiresRestart: true); } public GroupHandle Int(string label, Func<int> get, Action<int> set, bool requiresRestart) { if (!Valid(label, get != null, set != null, "Int")) { return this; } Func<int> read = get; Action<int> write = set; RegistrationRegistry.RegisteredOption registeredOption = NewOption(RegistrationRegistry.OptionKind.Int, label, requiresRestart); registeredOption.Whole = true; registeredOption.GetNumber = () => read(); registeredOption.SetNumber = delegate(float value) { write((int)Math.Round(value, MidpointRounding.AwayFromZero)); }; Store(registeredOption); return this; } public GroupHandle Float(string label, Func<float> get, Action<float> set) { return Float(label, get, set, requiresRestart: true); } public GroupHandle Float(string label, Func<float> get, Action<float> set, bool requiresRestart) { if (!Valid(label, get != null, set != null, "Float")) { return this; } Func<float> read = get; Action<float> write = set; RegistrationRegistry.RegisteredOption registeredOption = NewOption(RegistrationRegistry.OptionKind.Float, label, requiresRestart); registeredOption.GetNumber = () => read(); registeredOption.SetNumber = delegate(float value) { write(value); }; Store(registeredOption); return this; } public GroupHandle IntRange(string label, Func<int> get, Action<int> set, int min, int max) { return IntRange(label, get, set, min, max, requiresRestart: true); } public GroupHandle IntRange(string label, Func<int> get, Action<int> set, int min, int max, bool requiresRestart) { if (!Valid(label, get != null, set != null, "IntRange")) { return this; } NormaliseRange(ref min, ref max); Func<int> read = get; Action<int> write = set; RegistrationRegistry.RegisteredOption registeredOption = NewOption(RegistrationRegistry.OptionKind.IntRange, label, requiresRestart); registeredOption.Whole = true; registeredOption.Min = min; registeredOption.Max = max; registeredOption.GetNumber = () => read(); registeredOption.SetNumber = delegate(float value) { write((int)Math.Round(value, MidpointRounding.AwayFromZero)); }; Store(registeredOption); return this; } public GroupHandle FloatRange(string label, Func<float> get, Action<float> set, float min, float max) { return FloatRange(label, get, set, min, max, requiresRestart: true); } public GroupHandle FloatRange(string label, Func<float> get, Action<float> set, float min, float max, bool requiresRestart) { if (!Valid(label, get != null, set != null, "FloatRange")) { return this; } if (max < min) { float num = min; min = max; max = num; } if (max <= min) { max = min + 1f; } Func<float> read = get; Action<float> write = set; RegistrationRegistry.RegisteredOption registeredOption = NewOption(RegistrationRegistry.OptionKind.FloatRange, label, requiresRestart); registeredOption.Min = min; registeredOption.Max = max; registeredOption.GetNumber = () => read(); registeredOption.SetNumber = delegate(float value) { write(value); }; Store(registeredOption); return this; } public GroupHandle Text(string label, Func<string> get, Action<string> set) { return Text(label, get, set, requiresRestart: true); } public GroupHandle Text(string label, Func<string> get, Action<string> set, bool requiresRestart) { if (!Valid(label, get != null, set != null, "Text")) { return this; } Func<string> read = get; Action<string> write = set; RegistrationRegistry.RegisteredOption registeredOption = NewOption(RegistrationRegistry.OptionKind.Text, label, requiresRestart); registeredOption.GetText = () => read(); registeredOption.SetText = delegate(string value) { write(value); }; Store(registeredOption); return this; } public GroupHandle Selection(string label, Func<string> get, Action<string> set, string[] options) { return Selection(label, get, set, options, requiresRestart: true); } public GroupHandle Selection(string label, Func<string> get, Action<string> set, string[] options, bool requiresRestart) { if (!Valid(label, get != null, set != null, "Selection") || options == null) { if (options == null) { ModSettingsApi.Warn("Selection('" + label + "') ignored: an options array is required."); } return this; } Func<string> read = get; Action<string> write = set; string[] array = new string[options.Length]; Array.Copy(options, array, options.Length); RegistrationRegistry.RegisteredOption registeredOption = NewOption(RegistrationRegistry.OptionKind.Selection, label, requiresRestart); registeredOption.Options = array; registeredOption.GetText = () => read(); registeredOption.SetText = delegate(string value) { write(value); }; Store(registeredOption); return this; } public GroupHandle Key(string label, Func<string> get, Action<string> set) { return Key(label, get, set, requiresRestart: true); } public GroupHandle Key(string label, Func<string> get, Action<string> set, bool requiresRestart) { return TextLike(RegistrationRegistry.OptionKind.Key, label, get, set, requiresRestart); } public GroupHandle KeyCombination(string label, Func<string> get, Action<string> set) { return KeyCombination(label, get, set, requiresRestart: true); } public GroupHandle KeyCombination(string label, Func<string> get, Action<string> set, bool requiresRestart) { return TextLike(RegistrationRegistry.OptionKind.KeyCombination, label, get, set, requiresRestart); } private GroupHandle TextLike(RegistrationRegistry.OptionKind kind, string label, Func<string> get, Action<string> set, bool requiresRestart) { if (!Valid(label, get != null, set != null, kind.ToString())) { return this; } Func<string> read = get; Action<string> write = set; RegistrationRegistry.RegisteredOption registeredOption = NewOption(kind, label, requiresRestart); registeredOption.GetText = () => read(); registeredOption.SetText = delegate(string value) { write(value); }; Store(registeredOption); return this; } private RegistrationRegistry.RegisteredOption NewOption(RegistrationRegistry.OptionKind kind, string label, bool requiresRestart) { RegistrationRegistry.RegisteredOption registeredOption = new RegistrationRegistry.RegisteredOption(); registeredOption.Kind = kind; registeredOption.Label = label; registeredOption.RequiresRestart = requiresRestart; registeredOption.Min = float.NegativeInfinity; registeredOption.Max = float.PositiveInfinity; return registeredOption; } private void Store(RegistrationRegistry.RegisteredOption option) { if (Target != null) { RegistrationRegistry.SetOption(Target, option); } } private static bool Valid(string label, bool hasGet, bool hasSet, string kind) { if (string.IsNullOrEmpty(label) || !hasGet || !hasSet) { ModSettingsApi.Warn(kind + "('" + (label ?? "?") + "') ignored: a label and both get/set are required."); return false; } return true; } private static void NormaliseRange(ref int min, ref int max) { if (max < min) { int num = min; min = max; max = num; } if (max <= min) { max = min + 1; } } } [BepInPlugin("com.hiul.DSP_mod_settings", "DSP_mod_settings", "0.2.4")] [BepInProcess("DSPGAME.exe")] public class DSP_Mod_Settings_Plugin : BaseUnityPlugin { public static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"Loaded!"); try { _harmony = new Harmony("com.hiul.DSP_mod_settings"); _harmony.PatchAll(typeof(OptionWindowPatch)); Log.LogInfo((object)"[ModSettings] OptionWindow patched"); } catch (Exception ex) { Log.LogError((object)("[ModSettings] OptionWindow patch failed: " + ex)); } } private void OnDestroy() { if (_harmony == null) { return; } try { _harmony.UnpatchSelf(); } catch (Exception ex) { Log.LogError((object)ex.ToString()); } } private void OnApplicationQuit() { try { ItemListWindow.Shutdown(); } catch (Exception ex) { Log.LogError((object)ex.ToString()); } } } public static class ManifesteInfos { public const string GUID = "com.hiul.DSP_mod_settings"; public const string PluginName = "DSP_mod_settings"; public const string VersionString = "0.2.4"; } } namespace DSP_Mod_Settings.Patches { [HarmonyPatch(typeof(UIOptionWindow))] internal static class OptionWindowPatch { private const string TabLinePath = "Top Windows/Option Window/tab-line"; private const string TabLineFallbackPath = "Option Window/tab-line"; private const string DetailsPath = "Top Windows/Option Window/details"; private const string DetailsFallbackPath = "Option Window/details"; private const string PageName = "content-modsettings"; private const string TabName = "tab-button-modsettings"; private const string TabCaption = "Installed Mods"; private static bool _attempted; private static UIOptionWindow _window; private static int _tabIndex = -1; private static RectTransform _page; private static CanvasGroup _pageGroup; [HarmonyPostfix] [HarmonyPatch("SetTabIndex")] public static void Postfix_SetTabIndex(int index, bool immediate, UIOptionWindow __instance) { if (!((Object)(object)_page == (Object)null)) { bool flag = index == _tabIndex; if (((Component)_page).gameObject.activeSelf != flag) { ((Component)_page).gameObject.SetActive(flag); } if (flag) { ForceVisible(); } } } [HarmonyPostfix] [HarmonyPatch("_OnOpen")] public static void Postfix_OnOpen(UIOptionWindow __instance) { if ((Object)(object)__instance == (Object)null || _attempted) { return; } try { _attempted = true; _window = __instance; if (!((Object)(object)GameObject.Find("Top Windows/Option Window/details/content-modsettings") != (Object)null) && !((Object)(object)GameObject.Find("Option Window/details/content-modsettings") != (Object)null)) { Inject(__instance); } } catch (Exception ex) { DSP_Mod_Settings_Plugin.Log.LogError((object)ex.ToString()); } } private static void Inject(UIOptionWindow window) { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Expected O, but got Unknown Transform val = FindTabLine(); if ((Object)(object)val == (Object)null || val.childCount == 0) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)"[ModSettings] options tab: tab-line not found, skipping"); return; } GameObject val2 = FindObject("Top Windows/Option Window/details", "Option Window/details"); if ((Object)(object)val2 == (Object)null) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)"[ModSettings] options tab: details container not found, skipping"); return; } Transform transform = val2.transform; Transform child = val.GetChild(val.childCount - 1); Transform obj = Object.Instantiate<Transform>(child, val, false); RectTransform val3 = (RectTransform)(object)((obj is RectTransform) ? obj : null); if ((Object)(object)val3 == (Object)null) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)"[ModSettings] options tab: could not clone the tab button, skipping"); return; } ((Object)val3).name = "tab-button-modsettings"; val3.anchoredPosition = new Vector2(val3.anchoredPosition.x + 160f, val3.anchoredPosition.y); Component component = ((Component)val3).GetComponent("Localizer"); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } Text componentInChildren = ((Component)val3).GetComponentInChildren<Text>(); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.text = "Installed Mods"; } Button component2 = ((Component)val3).GetComponent<Button>(); if ((Object)(object)component2 == (Object)null) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)"[ModSettings] options tab: cloned button has no Button component, skipping"); Object.Destroy((Object)(object)((Component)val3).gameObject); return; } ((UnityEventBase)component2.onClick).RemoveAllListeners(); Transform val4 = VanillaPage(transform); if ((Object)(object)val4 == (Object)null) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)"[ModSettings] options tab: no content page to clone, skipping"); Object.Destroy((Object)(object)((Component)val3).gameObject); return; } Transform obj2 = Object.Instantiate<Transform>(val4, transform, false); RectTransform val5 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null); if ((Object)(object)val5 == (Object)null) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)"[ModSettings] options tab: could not clone the content page, skipping"); Object.Destroy((Object)(object)((Component)val3).gameObject); return; } Transform val6 = ((Transform)val5).Find("revert-button"); ((Object)((Component)val5).gameObject).name = "content-modsettings"; ((Component)val5).gameObject.SetActive(true); ((Transform)val5).SetAsLastSibling(); UiFactory.AdoptTheme(val5); for (int num = ((Transform)val5).childCount - 1; num >= 0; num--) { Transform child2 = ((Transform)val5).GetChild(num); if (!((Object)(object)child2 == (Object)(object)val6)) { child2.SetParent((Transform)null, false); Object.Destroy((Object)(object)((Component)child2).gameObject); } } if ((Object)(object)val6 != (Object)null) { ((Component)val6).gameObject.SetActive(false); } int tabIndex = window.tabButtons.Length; _tabIndex = tabIndex; AppendArrayField(window, "tabTweeners", ((Component)val5).GetComponent("Tweener")); AppendArrayField(window, "tabButtons", ((Component)val3).GetComponent<UIButton>()); AppendArrayField(window, "tabTexts", componentInChildren); if ((Object)(object)val6 != (Object)null) { AppendArrayField(window, "revertButtons", ((Component)val6).GetComponent<UIButton>()); } ((UnityEvent)component2.onClick).AddListener(new UnityAction(SelectTab)); OptionTabBuilder.Build(val5); _page = val5; ((Component)val5).gameObject.SetActive(false); } private static Transform FindTabLine() { GameObject val = FindObject("Top Windows/Option Window/tab-line", "Option Window/tab-line"); if (!((Object)(object)val == (Object)null)) { return val.transform; } return null; } private static GameObject FindObject(params string[] paths) { for (int i = 0; i < paths.Length; i++) { GameObject val = GameObject.Find(paths[i]); if ((Object)(object)val != (Object)null) { return val; } } return null; } private static Transform VanillaPage(Transform details) { Transform result = null; int num = int.MaxValue; for (int i = 0; i < details.childCount; i++) { Transform child = details.GetChild(i); int num2 = ContentPageNumber(((Object)child).name); if (num2 > 0 && num2 < num) { num = num2; result = child; } } return result; } private static int ContentPageNumber(string name) { if (name == null || !name.StartsWith("content-", StringComparison.Ordinal)) { return 0; } if (!int.TryParse(name.Substring("content-".Length), out var result)) { return 0; } return result; } private static void ForceVisible() { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_page == (Object)null) { return; } ((Component)_page).gameObject.SetActive(true); ((Transform)_page).SetAsLastSibling(); if ((Object)(object)_pageGroup == (Object)null) { _pageGroup = ((Component)_page).gameObject.GetComponent<CanvasGroup>(); if ((Object)(object)_pageGroup == (Object)null) { _pageGroup = ((Component)_page).gameObject.AddComponent<CanvasGroup>(); } } _pageGroup.alpha = 1f; _pageGroup.blocksRaycasts = true; _pageGroup.interactable = true; Rect rect = _page.rect; if (!(((Rect)(ref rect)).width < 10f)) { rect = _page.rect; if (!(((Rect)(ref rect)).height < 10f)) { return; } } _page.anchorMin = Vector2.zero; _page.anchorMax = Vector2.one; _page.offsetMin = Vector2.zero; _page.offsetMax = Vector2.zero; } private static void SelectTab() { if ((Object)(object)_window == (Object)null || _tabIndex < 0) { return; } try { MethodInfo methodInfo = AccessTools.Method(typeof(UIOptionWindow), "SetTabIndex", new Type[2] { typeof(int), typeof(bool) }, (Type[])null); if (methodInfo != null) { methodInfo.Invoke(_window, new object[2] { _tabIndex, false }); } else { DSP_Mod_Settings_Plugin.Log.LogWarning((object)"[ModSettings] options tab: SetTabIndex not found; page forced visible only"); } } catch (Exception ex) { DSP_Mod_Settings_Plugin.Log.LogError((object)ex.ToString()); } } private static void AppendArrayField(object target, string fieldName, object value) { if (value != null) { FieldInfo fieldInfo = AccessTools.Field(typeof(UIOptionWindow), fieldName); if (!(fieldInfo == null)) { Array array = (Array)fieldInfo.GetValue(target); Type elementType = array.GetType().GetElementType(); Array array2 = Array.CreateInstance(elementType, array.Length + 1); Array.Copy(array, array2, array.Length); array2.SetValue(value, array.Length); fieldInfo.SetValue(target, array2); } } } } } namespace DSP_Mod_Settings.Integration { internal sealed class DropdownCleanup : MonoBehaviour { public RectTransform Group; private void OnDestroy() { if ((Object)(object)Group != (Object)null && (Object)(object)((Transform)Group).parent != (Object)(object)((Component)this).transform) { Object.Destroy((Object)(object)((Component)Group).gameObject); } } } internal static class InstalledModsPage { internal const float PageWidth = 760f; private const float TitleHeight = 36f; internal const float RowHeight = 30f; internal const float SliderRowHeight = 40f; private const float SectionHeight = 28f; internal const float LabelWidth = 250f; internal const float ControlX = 264f; internal const float ControlWidth = 210f; internal const float FieldWidth = 96f; internal const float TextFieldWidth = 320f; private const int MaxValueChars = 160; private static bool _syncing; public static float Build(RectTransform parent, PluginInfo info) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0139: 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) if ((Object)(object)parent == (Object)null || info == null || info.Metadata == null) { return 0f; } float num = 0f; UiFactory.Label((Transform)(object)parent, info.Metadata.Name, 0f, num, 760f, 20, bold: true, UiFactory.TextColor); num += 36f; num = InfoRow(parent, "GUID", info.Metadata.GUID, num); num = InfoRow(parent, "Version", (info.Metadata.Version != null) ? info.Metadata.Version.ToString() : "?", num); string location = info.Location; num = InfoRow(parent, "Assembly", string.IsNullOrEmpty(location) ? "?" : Path.GetFileName(location), num); num += 8f; if (RegistrationRegistry.TryGet(info.Metadata.GUID, out var mod) && mod.Tabs.Count > 0) { return RegisteredPage.Build(parent, mod, num); } List<KeyValuePair<ConfigDefinition, ConfigEntryBase>> list = ReadEntries(info); if (list.Count == 0) { string text = (((Object)(object)info.Instance == (Object)null) ? "Settings unavailable: the plugin has no live instance." : "This mod registered no setting in its config file."); UiFactory.Label((Transform)(object)parent, text, 0f, num, 760f, 16, bold: false, UiFactory.MutedColor); return num + 30f; } UiFactory.Label((Transform)(object)parent, "Settings (" + list.Count + ")", 0f, num, 760f, 18, bold: true, UiFactory.TextColor); num += 28f; string text2 = null; for (int i = 0; i < list.Count; i++) { KeyValuePair<ConfigDefinition, ConfigEntryBase> keyValuePair = list[i]; string text3 = keyValuePair.Key.Section ?? string.Empty; if (!string.Equals(text3, text2, StringComparison.Ordinal)) { text2 = text3; UiFactory.Label((Transform)(object)parent, (text2.Length == 0) ? "(no section)" : text2, 0f, num, 760f, 16, bold: true, UiFactory.TextColor); num += 24f; } num = EntryRow(parent, keyValuePair.Key.Key, keyValuePair.Value, num); } return num; } private static List<KeyValuePair<ConfigDefinition, ConfigEntryBase>> ReadEntries(PluginInfo info) { List<KeyValuePair<ConfigDefinition, ConfigEntryBase>> list = new List<KeyValuePair<ConfigDefinition, ConfigEntryBase>>(); ConfigFile val = (((Object)(object)info.Instance == (Object)null) ? null : info.Instance.Config); if (val == null) { return list; } try { foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in val) { if (item.Value != null) { list.Add(item); } } } catch (Exception ex) { DSP_Mod_Settings_Plugin.Log.LogError((object)("[ModSettings] could not read the config of " + info.Metadata.GUID + ": " + ex)); return list; } list.Sort(CompareEntries); return list; } private static int CompareEntries(KeyValuePair<ConfigDefinition, ConfigEntryBase> a, KeyValuePair<ConfigDefinition, ConfigEntryBase> b) { int num = string.Compare(a.Key.Section, b.Key.Section, StringComparison.OrdinalIgnoreCase); if (num != 0) { return num; } return string.Compare(a.Key.Key, b.Key.Key, StringComparison.OrdinalIgnoreCase); } private static float InfoRow(RectTransform parent, string label, string value, float y) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) UiFactory.Label((Transform)(object)parent, label, 0f, y, 120f, 15, bold: false, UiFactory.MutedColor); UiFactory.Label((Transform)(object)parent, value ?? string.Empty, 130f, y, 630f, 15, bold: false, UiFactory.TextColor); return y + 30f; } private static float EntryRow(RectTransform parent, string key, ConfigEntryBase entry, float y) { Type settingType = entry.SettingType; if (settingType == typeof(KeyCode)) { return CaptureRow((Transform)(object)parent, key, entry, y, combination: false); } if (settingType == typeof(KeyboardShortcut)) { return CaptureRow((Transform)(object)parent, key, entry, y, combination: true); } if (settingType == typeof(bool)) { return BoolRow((Transform)(object)parent, key, entry, y); } if ((IsNumeric(settingType) || settingType == typeof(string)) && UiFactory.LooksLikeId(key)) { return IdRow((Transform)(object)parent, key, entry, y); } if (IsNumeric(settingType)) { if (TryGetRange(entry, out var min, out var max)) { return RangedRow((Transform)(object)parent, key, entry, min, max, y); } return NumberRow((Transform)(object)parent, key, entry, y); } List<object> options = GetOptions(entry); if (options.Count > 0) { return OptionsRow((Transform)(object)parent, key, entry, options, y); } return TextRow((Transform)(object)parent, key, entry, y); } private static float OptionsRow(Transform parent, string key, ConfigEntryBase entry, List<object> options, float y) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[options.Count]; for (int i = 0; i < options.Count; i++) { array[i] = ToDisplay(options[i]); } int selectedIndex = IndexOf(options, entry.BoxedValue); UIComboBox val = UiFactory.Dropdown(parent, 264f, y, 200f, 30f, array, selectedIndex, delegate(int index) { if (index >= 0 && index < options.Count) { Write(entry, options[index]); } }); if ((Object)(object)val == (Object)null) { return CycleRow(parent, key, entry, options, y); } UiFactory.Label(parent, key, 16f, y + 5f, 250f, 15, bold: false, UiFactory.MutedColor); return y + 30f; } private static float BoolRow(Transform parent, string key, ConfigEntryBase entry, float y) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) UiFactory.Label(parent, key, 16f, y + 7f, 250f, 15, bold: false, UiFactory.MutedColor); UiFactory.CheckBox(parent, 264f, y, entry.BoxedValue is bool && (bool)entry.BoxedValue, delegate(bool value) { Write(entry, value); }); return y + 40f; } private static float IdRow(Transform parent, string key, ConfigEntryBase entry, float y) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown UiFactory.Label(parent, key, 16f, y + 4f, 250f, 15, bold: false, UiFactory.MutedColor); bool list = entry.SettingType == typeof(string) && (UiFactory.IsPluralId(key) || ValueIsIdList(entry.BoxedValue)); int id; Button val = UiFactory.Button(label: list ? IdListCaption(entry.BoxedValue) : ((!UiFactory.TryGetItemId(entry.BoxedValue, out id)) ? ((entry.BoxedValue == null) ? "None" : entry.BoxedValue.ToString()) : UiFactory.ItemName(id)), parent: parent, x: 264f, y: y + 2f, width: 320f, height: 26f, onClick: null); if ((Object)(object)val == (Object)null) { return y + 30f; } Text caption = ((Component)val).GetComponentInChildren<Text>(); ((UnityEvent)val.onClick).AddListener((UnityAction)delegate { ItemListWindow.Open(selectedIds: (!list) ? ((!UiFactory.TryGetItemId(entry.BoxedValue, out var id2) || id2 <= 0) ? new int[0] : new int[1] { id2 }) : ParseIds(entry.BoxedValue), owner: parent, multiSelect: list, onPicked: delegate(int[] picked) { if (list) { Write(entry, JoinIds(picked)); if ((Object)(object)caption != (Object)null) { caption.text = IdListCaption(entry.BoxedValue); } } else { int num = ((picked != null && picked.Length != 0) ? picked[0] : 0); Write(entry, num); if (UiFactory.TryGetItemId(entry.BoxedValue, out var id3) && (Object)(object)caption != (Object)null) { caption.text = UiFactory.ItemName(id3); } } }); }); return y + 30f; } private static bool ValueIsIdList(object value) { string text = value as string; if (!string.IsNullOrEmpty(text)) { if (text.IndexOf(',') < 0 && text.IndexOf(';') < 0) { return text.IndexOf('|') >= 0; } return true; } return false; } private static List<string> SplitIds(string text) { List<string> list = new List<string>(); if (string.IsNullOrEmpty(text)) { return list; } string[] array = text.Split(new char[4] { ',', ';', '|', ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length > 0) { list.Add(text2); } } return list; } private static string IdListCaption(object value) { string text = value as string; if (string.IsNullOrEmpty(text)) { return "Add item..."; } string text2 = text.Trim(); if (text2.Length > 32) { text2 = text2.Substring(0, 32) + "..."; } return SplitIds(text).Count + " id(s): " + text2; } private static int[] ParseIds(object value) { List<string> list = SplitIds(value as string); List<int> list2 = new List<int>(); for (int i = 0; i < list.Count; i++) { if (int.TryParse(list[i], out var result) && result > 0) { list2.Add(result); } } return list2.ToArray(); } private static string JoinIds(int[] ids) { if (ids == null || ids.Length == 0) { return string.Empty; } string[] array = new string[ids.Length]; for (int i = 0; i < ids.Length; i++) { array[i] = ids[i].ToString(CultureInfo.InvariantCulture); } return string.Join(",", array); } private static float CaptureRow(Transform parent, string key, ConfigEntryBase entry, float y, bool combination) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown UiFactory.Label(parent, key, 16f, y + 5f, 250f, 15, bold: false, UiFactory.MutedColor); Button val = UiFactory.Button(parent, KeyDisplay(entry), 264f, y + 2f, 210f, 26f, null); if ((Object)(object)val == (Object)null) { return y + 30f; } Text caption = ((Component)val).GetComponentInChildren<Text>(); KeyCaptureBehaviour capture = ((Component)val).gameObject.AddComponent<KeyCaptureBehaviour>(); ((UnityEvent)val.onClick).AddListener((UnityAction)delegate { capture.Arm(delegate(KeyCode main, bool ctrl, bool alt, bool shift) { //IL_001f: 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) if (combination) { WriteShortcut(entry, main, ctrl, alt, shift); } else { Write(entry, main); } }, () => KeyDisplay(entry), combination, caption); }); return y + 30f; } private static string KeyDisplay(ConfigEntryBase entry) { if (entry == null) { return "Not set"; } object boxedValue = entry.BoxedValue; if (boxedValue == null) { return "Not set"; } string text = boxedValue.ToString(); if (!string.IsNullOrEmpty(text)) { return text; } return "Not set"; } private static void WriteShortcut(ConfigEntryBase entry, KeyCode main, bool ctrl, bool alt, bool shift) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) if ((int)main != 0) { List<KeyCode> list = new List<KeyCode>(); if (ctrl) { list.Add((KeyCode)306); } if (alt) { list.Add((KeyCode)308); } if (shift) { list.Add((KeyCode)304); } Write(entry, (object)new KeyboardShortcut(main, list.ToArray())); } } private static float RangedRow(Transform parent, string key, ConfigEntryBase entry, float min, float max, float y) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) if (max <= min) { max = min + 1f; } float num = ToSingle(entry.BoxedValue); float value = ((num < min) ? min : ((num > max) ? max : num)); UiFactory.Label(parent, key, 16f, y + 9f, 250f, 15, bold: false, UiFactory.MutedColor); Slider val = UiFactory.Slider(parent, "slider", 264f, y + 9f, 210f, 20f, null); val.wholeNumbers = IsIntegral(entry.SettingType); val.minValue = min; val.maxValue = max; val.value = value; InputField val2 = UiFactory.NumericField(parent, "input", 486f, y + 5f, 96f, 28f, value, null); Slider capturedSlider = val; InputField capturedField = val2; ((UnityEvent<float>)(object)val.onValueChanged).AddListener((UnityAction<float>)delegate(float raw) { if (!_syncing) { float value2 = WriteNumber(entry, raw, min, max); ShowNumber(capturedField, value2); } }); ((UnityEvent<string>)(object)val2.onEndEdit).AddListener((UnityAction<string>)delegate(string text) { if (!_syncing) { if (!TryParse(text, out var value2)) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)("[ModSettings] rejected " + entry.Definition.Key + ": '" + text + "'")); ShowNumber(capturedField, ToSingle(entry.BoxedValue)); } else { float value3 = WriteNumber(entry, (float)value2, min, max); ShowNumber(capturedField, value3); ShowSlider(capturedSlider, value3); } } }); return y + 40f; } private static float NumberRow(Transform parent, string key, ConfigEntryBase entry, float y) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) UiFactory.Label(parent, key, 16f, y + 4f, 250f, 15, bold: false, UiFactory.MutedColor); float value = ToSingle(entry.BoxedValue); InputField capturedField; ((UnityEvent<string>)(object)(capturedField = UiFactory.NumericField(parent, "input", 264f, y + 3f, 96f, 28f, value, null)).onEndEdit).AddListener((UnityAction<string>)delegate(string text) { if (!_syncing) { if (!TryParse(text, out var value2)) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)("[ModSettings] rejected " + entry.Definition.Key + ": '" + text + "'")); ShowNumber(capturedField, ToSingle(entry.BoxedValue)); } else { float value3 = WriteNumber(entry, (float)value2, float.NegativeInfinity, float.PositiveInfinity); ShowNumber(capturedField, value3); } } }); return y + 30f; } private static float CycleRow(Transform parent, string key, ConfigEntryBase entry, List<object> options, float y) { //IL_002b: 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_00a0: Expected O, but got Unknown UiFactory.Label(parent, key, 16f, y + 5f, 250f, 15, bold: false, UiFactory.MutedColor); Button val = UiFactory.Button(parent, ToDisplay(entry.BoxedValue), 264f, y + 2f, 210f, 26f, null); if ((Object)(object)val == (Object)null) { return y + 30f; } Text caption = ((Component)val).GetComponentInChildren<Text>(); ((UnityEvent)val.onClick).AddListener((UnityAction)delegate { Advance(entry, options, caption); }); return y + 30f; } private static void Advance(ConfigEntryBase entry, List<object> options, Text caption) { if (options != null && options.Count != 0) { int num = IndexOf(options, entry.BoxedValue); object value = options[(num + 1) % options.Count]; if (Write(entry, value) && (Object)(object)caption != (Object)null) { caption.text = ToDisplay(entry.BoxedValue); } } } private static int IndexOf(List<object> options, object value) { string b = ToDisplay(value); for (int i = 0; i < options.Count; i++) { if (string.Equals(ToDisplay(options[i]), b, StringComparison.OrdinalIgnoreCase)) { return i; } } return -1; } private static float TextRow(Transform parent, string key, ConfigEntryBase entry, float y) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) UiFactory.Label(parent, key, 16f, y + 4f, 250f, 15, bold: false, UiFactory.MutedColor); InputField capturedField; ((UnityEvent<string>)(object)(capturedField = UiFactory.TextField(parent, "input", 264f, y + 3f, 320f, 28f, Serialized(entry))).onEndEdit).AddListener((UnityAction<string>)delegate(string text) { if (_syncing) { return; } try { entry.SetSerializedValue(text ?? string.Empty); } catch (Exception ex) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)("[ModSettings] rejected " + entry.Definition.Key + ": '" + text + "' (" + ex.Message + ")")); } _syncing = true; try { capturedField.text = Serialized(entry); } finally { _syncing = false; } }); return y + 30f; } private static float WriteNumber(ConfigEntryBase entry, float raw, float min, float max) { float num = raw; if (num < min) { num = min; } if (num > max) { num = max; } Write(entry, num); return ToSingle(entry.BoxedValue); } private static bool Write(ConfigEntryBase entry, object value) { try { if (value != null && !entry.SettingType.IsInstanceOfType(value)) { value = Convert.ChangeType(value, entry.SettingType, CultureInfo.InvariantCulture); } entry.BoxedValue = value; return true; } catch (Exception ex) { DSP_Mod_Settings_Plugin.Log.LogError((object)("[ModSettings] could not write " + entry.Definition.Section + "/" + entry.Definition.Key + ": " + ex)); return false; } } internal static void ShowNumber(InputField field, float value) { if ((Object)(object)field == (Object)null) { return; } _syncing = true; try { field.text = FormatNumber(value); } finally { _syncing = false; } } private static void ShowSlider(Slider slider, float value) { if ((Object)(object)slider == (Object)null) { return; } _syncing = true; try { slider.value = value; } finally { _syncing = false; } } private static bool TryGetRange(ConfigEntryBase entry, out float min, out float max) { min = 0f; max = 0f; object obj = ((entry.Description == null) ? null : entry.Description.AcceptableValues); if (obj == null) { return false; } PropertyInfo property = obj.GetType().GetProperty("MinValue"); PropertyInfo property2 = obj.GetType().GetProperty("MaxValue"); if (property == null || property2 == null) { return false; } try { min = ToSingle(property.GetValue(obj, null)); max = ToSingle(property2.GetValue(obj, null)); return true; } catch (Exception) { return false; } } private static List<object> GetOptions(ConfigEntryBase entry) { List<object> list = new List<object>(); Type settingType = entry.SettingType; if (settingType.IsEnum) { foreach (object value in Enum.GetValues(settingType)) { list.Add(value); } return list; } object obj = ((entry.Description == null) ? null : entry.Description.AcceptableValues); if (obj == null) { return list; } PropertyInfo property = obj.GetType().GetProperty("AcceptableValues"); if (property != null) { if (property.GetValue(obj, null) is IEnumerable enumerable) { foreach (object item in enumerable) { list.Add(item); } } return list; } if (!(obj is IEnumerable enumerable2)) { return list; } foreach (object item2 in enumerable2) { list.Add(item2); } return list; } private static bool IsNumeric(Type type) { TypeCode typeCode = Type.GetTypeCode(type); if ((uint)(typeCode - 5) <= 10u) { return true; } return false; } private static bool IsIntegral(Type type) { TypeCode typeCode = Type.GetTypeCode(type); if ((uint)(typeCode - 5) <= 7u) { return true; } return false; } internal static bool TryParse(string text, out double value) { value = 0.0; string text2 = (text ?? string.Empty).Trim(); if (text2.Length == 0) { return false; } if (!double.TryParse(text2, NumberStyles.Float, CultureInfo.CurrentCulture, out value)) { return double.TryParse(text2.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out value); } return true; } private static float ToSingle(object value) { return Convert.ToSingle(value, CultureInfo.InvariantCulture); } internal static string FormatNumber(float value) { return value.ToString("0.###", CultureInfo.InvariantCulture); } private static string ToDisplay(object value) { if (value != null) { return value.ToString(); } return "null"; } private static string Serialized(ConfigEntryBase entry) { string text; try { text = entry.GetSerializedValue(); } catch (Exception) { object boxedValue = entry.BoxedValue; text = ((boxedValue == null) ? "null" : boxedValue.ToString()); } if (string.IsNullOrEmpty(text)) { return string.Empty; } text = text.Replace('\r', ' ').Replace('\n', ' ').Trim(); if (text.Length > 160) { text = text.Substring(0, 160) + "..."; } return text; } } internal static class ItemListWindow { private sealed class RowView { public ItemProto Proto; public RectTransform Rect; } private sealed class CategoryView { public string Title; public RectTransform Header; public readonly List<RowView> Rows = new List<RowView>(); } private const float PanelWidth = 760f; private const float PanelHeight = 600f; private const float RowHeight = 44f; private const float HeaderHeight = 28f; private const float IconSize = 32f; private static readonly EItemType[] CategoryOrder; private static GameObject _root; private static RectTransform _content; private static RectTransform _emptyRow; private static Text _emptyText; private static bool _multiSelect; private static UnityAction<int[]> _onPicked; private static readonly List<CategoryView> Categories; private static readonly HashSet<int> Selected; private static readonly List<Toggle> Toggles; private static readonly List<int> ToggleIds; private static InputField _idField; private static string _filter; private static bool _syncing; private static bool _quitting; static ItemListWindow() { EItemType[] array = new EItemType[12]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); CategoryOrder = (EItemType[])(object)array; Categories = new List<CategoryView>(); Selected = new HashSet<int>(); Toggles = new List<Toggle>(); ToggleIds = new List<int>(); _filter = string.Empty; Application.quitting += delegate { _quitting = true; }; } public static void Open(Transform owner, bool multiSelect, int[] selectedIds, UnityAction<int[]> onPicked) { //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Expected O, but got Unknown //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Expected O, but got Unknown //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Expected O, but got Unknown //IL_0399: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_0455: Unknown result type (might be due to invalid IL or missing references) //IL_0460: Expected O, but got Unknown //IL_0483: Unknown result type (might be due to invalid IL or missing references) //IL_048e: Expected O, but got Unknown //IL_04b1: Unknown result type (might be due to invalid IL or missing references) //IL_04bc: Expected O, but got Unknown Close(); Canvas val = (((Object)(object)UIRoot.instance != (Object)null) ? UIRoot.instance.overlayCanvas : null); Transform val2 = (((Object)(object)val != (Object)null) ? ((Component)val).transform : (((Object)(object)owner != (Object)null) ? owner.root : null)); if ((Object)(object)val2 == (Object)null) { return; } _multiSelect = multiSelect; _onPicked = onPicked; _filter = string.Empty; if (selectedIds != null) { for (int i = 0; i < selectedIds.Length; i++) { if (selectedIds[i] > 0) { Selected.Add(selectedIds[i]); } } } RectTransform val3 = (RectTransform)(object)((val2 is RectTransform) ? val2 : null); Rect rect; float num; if ((Object)(object)val3 != (Object)null) { rect = val3.rect; if (((Rect)(ref rect)).width > 10f) { rect = val3.rect; num = ((Rect)(ref rect)).width; goto IL_00d1; } } num = 1920f; goto IL_00d1; IL_00d1: float num2 = num; float num3; if ((Object)(object)val3 != (Object)null) { rect = val3.rect; if (((Rect)(ref rect)).height > 10f) { rect = val3.rect; num3 = ((Rect)(ref rect)).height; goto IL_0108; } } num3 = 1080f; goto IL_0108; IL_0108: float num4 = num3; RectTransform val4 = UiFactory.Panel(val2, "modsettings-item-list", 0f, 0f, num2, num4, background: true); if (!((Object)(object)val4 == (Object)null)) { Image component = ((Component)val4).GetComponent<Image>(); if ((Object)(object)component != (Object)null) { ((Graphic)component).color = new Color(0f, 0f, 0f, 0.65f); ((Graphic)component).raycastTarget = true; } Button val5 = ((Component)val4).gameObject.AddComponent<Button>(); ((Selectable)val5).targetGraphic = (Graphic)(object)component; ((Selectable)val5).transition = (Transition)0; ((UnityEvent)val5.onClick).AddListener(new UnityAction(Close)); float x = (num2 - 760f) * 0.5f; float y = (num4 - 600f) * 0.5f; RectTransform val6 = UiFactory.Panel((Transform)(object)val4, "panel", x, y, 760f, 600f, background: true); Image component2 = ((Component)val6).GetComponent<Image>(); if ((Object)(object)component2 != (Object)null) { ((Graphic)component2).color = new Color(0.05f, 0.07f, 0.09f, 0.98f); ((Graphic)component2).raycastTarget = true; } UiFactory.Label((Transform)(object)val6, multiSelect ? "Select items" : "Select an item", 16f, 10f, 500f, 20, bold: true, UiFactory.TextColor); UiFactory.Button((Transform)(object)val6, "X", 716f, 8f, 28f, 28f, new UnityAction(Close)); UiFactory.Label((Transform)(object)val6, "Search", 16f, 44f, 56f, 16, bold: false, UiFactory.MutedColor); InputField searchField = UiFactory.TextField((Transform)(object)val6, "search", 76f, 40f, 380f, 28f, string.Empty); UiFactory.Button((Transform)(object)val6, "Clear", 470f, 40f, 70f, 28f, (UnityAction)delegate { searchField.text = string.Empty; ApplyFilter(string.Empty); }); ((UnityEvent<string>)(object)searchField.onValueChanged).AddListener((UnityAction<string>)delegate(string text) { ApplyFilter(text); }); UiFactory.ScrollView((Transform)(object)val6, "list", 16f, 80f, 728f, 438f, out _content); _emptyRow = UiFactory.Panel((Transform)(object)_content, "empty", 0f, 0f, 728f, 24f); _emptyText = UiFactory.Label((Transform)(object)_emptyRow, string.Empty, 8f, 0f, 712f, 16, bold: false, UiFactory.MutedColor); BuildCategories(); string value = ((!multiSelect && selectedIds != null && selectedIds.Length != 0) ? selectedIds[0].ToString(CultureInfo.InvariantCulture) : string.Empty); UiFactory.Label((Transform)(object)val6, "ID", 16f, 544f, 28f, 16, bold: false, UiFactory.MutedColor); InputField idField = UiFactory.TextField((Transform)(object)val6, "id", 48f, 540f, 120f, 28f, value); _idField = idField; UiFactory.Button((Transform)(object)val6, "Use ID", 180f, 540f, 90f, 28f, (UnityAction)delegate { UseId(idField); }); UiFactory.Button((Transform)(object)val6, "Apply", 560f, 540f, 88f, 28f, new UnityAction(Apply)); UiFactory.Button((Transform)(object)val6, "Cancel", 656f, 540f, 88f, 28f, new UnityAction(Close)); ItemListWatcher itemListWatcher = ((Component)val4).gameObject.AddComponent<ItemListWatcher>(); itemListWatcher.SetOwner(FindOwnerPage(owner)); ApplyFilter(string.Empty); _root = ((Component)val4).gameObject; } } public static void Close() { if (!_quitting && (Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } _root = null; _content = null; _emptyRow = null; _emptyText = null; _onPicked = null; Categories.Clear(); Selected.Clear(); Toggles.Clear(); ToggleIds.Clear(); _idField = null; _filter = string.Empty; _syncing = false; } internal static void Shutdown() { _quitting = true; Close(); } private static void BuildCategories() { //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) Categories.Clear(); Toggles.Clear(); ToggleIds.Clear(); Dictionary<EItemType, List<ItemProto>> dictionary = new Dictionary<EItemType, List<ItemProto>>(); try { ItemProto[] array = (((Object)(object)LDB.items != (Object)null) ? ((ProtoSet<ItemProto>)(object)LDB.items).dataArray : null); if (array != null) { foreach (ItemProto val in array) { if (val != null && ((Proto)val).ID > 0 && !string.IsNullOrEmpty(((Proto)val).name)) { if (!dictionary.TryGetValue(val.Type, out var value)) { value = new List<ItemProto>(); dictionary[val.Type] = value; } value.Add(val); } } } } catch (Exception ex) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)("[ModSettings] item list: could not read LDB.items: " + ex.Message)); } for (int j = 0; j < CategoryOrder.Length; j++) { if (dictionary.TryGetValue(CategoryOrder[j], out var value2) && value2.Count != 0) { value2.Sort(CompareItems); CategoryView categoryView = new CategoryView(); categoryView.Title = CategoryName(CategoryOrder[j]); Categories.Add(categoryView); RectTransform val2 = UiFactory.Panel((Transform)(object)_content, "category", 0f, 0f, 728f, 28f); UiFactory.Label((Transform)(object)val2, categoryView.Title, 8f, 0f, 712f, 18, bold: true, UiFactory.TextColor); categoryView.Header = val2; for (int k = 0; k < value2.Count; k++) { categoryView.Rows.Add(BuildRow(value2[k])); } } } } private static RowView BuildRow(ItemProto proto) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) RowView rowView = new RowView(); rowView.Proto = proto; RectTransform parent = (rowView.Rect = UiFactory.Panel((Transform)(object)_content, "row", 0f, 0f, 728f, 44f)); Toggle toggle = null; UiFactory.InvisibleButton((Transform)(object)parent, "hit", 0f, 0f, 728f, 40f, (UnityAction)delegate { if ((Object)(object)toggle != (Object)null) { toggle.isOn = !toggle.isOn; } }); UiFactory.Icon((Transform)(object)parent, "icon", 8f, 6f, 32f, proto.iconSprite); UiFactory.Label((Transform)(object)parent, ((Proto)proto).name + " (" + ((Proto)proto).ID + ")", 48f, 10f, 610f, 16, bold: false, UiFactory.TextColor); bool value = Selected.Contains(((Proto)proto).ID); toggle = UiFactory.CheckBox((Transform)(object)parent, 676f, 2f, value, null); if ((Object)(object)toggle != (Object)null) { int id = ((Proto)proto).ID; ((UnityEvent<bool>)(object)toggle.onValueChanged).AddListener((UnityAction<bool>)delegate(bool on) { OnToggle(id, on); }); Toggles.Add(toggle); ToggleIds.Add(id); } return rowView; } private static void ApplyFilter(string text) { //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_content == (Object)null) { return; } _filter = text ?? string.Empty; string text2 = _filter.Trim(); float num = 4f; int num2 = 0; for (int i = 0; i < Categories.Count; i++) { CategoryView categoryView = Categories[i]; bool flag = false; for (int j = 0; j < categoryView.Rows.Count; j++) { RowView rowView = categoryView.Rows[j]; bool flag2 = text2.Length == 0 || ((Proto)rowView.Proto).name.IndexOf(text2, StringComparison.OrdinalIgnoreCase) >= 0; ((Component)rowView.Rect).gameObject.SetActive(flag2); if (flag2) { if (!flag) { ((Component)categoryView.Header).gameObject.SetActive(true); categoryView.Header.anchoredPosition = new Vector2(0f, 0f - num); num += 28f; flag = true; } rowView.Rect.anchoredPosition = new Vector2(0f, 0f - num); num += 44f; num2++; } } if (!flag) { ((Component)categoryView.Header).gameObject.SetActive(false); } } if ((Object)(object)_emptyRow != (Object)null) { bool flag3 = num2 == 0; ((Component)_emptyRow).gameObject.SetActive(flag3); if (flag3) { _emptyRow.anchoredPosition = new Vector2(0f, 0f - num); _emptyText.text = ((Categories.Count == 0) ? "Item list unavailable. Type an ID below." : "No item matches this search."); num += 30f; } } _content.sizeDelta = new Vector2(0f, Mathf.Max(num + 8f, 438f)); } private static void OnToggle(int id, bool on) { if (_syncing) { return; } if (_multiSelect) { if (on) { Selected.Add(id); } else { Selected.Remove(id); } return; } Selected.Clear(); if (on) { Selected.Add(id); if ((Object)(object)_idField != (Object)null) { _idField.text = id.ToString(CultureInfo.InvariantCulture); } } else if ((Object)(object)_idField != (Object)null) { _idField.text = string.Empty; } _syncing = true; for (int i = 0; i < Toggles.Count; i++) { Toggle val = Toggles[i]; if ((Object)(object)val != (Object)null && ToggleIds[i] != id && val.isOn) { val.isOn = false; } } _syncing = false; } private static void Apply() { List<int> list = new List<int>(Selected); list.Sort(); if (!_multiSelect && list.Count > 1) { list.RemoveRange(1, list.Count - 1); } UnityAction<int[]> onPicked = _onPicked; int[] array = list.ToArray(); Close(); onPicked?.Invoke(array); } private static void UseId(InputField field) { if ((Object)(object)field == (Object)null || !int.TryParse(field.text, out var result)) { return; } if (!_multiSelect) { Selected.Clear(); if (result > 0) { Selected.Add(result); } } else if (result > 0) { Selected.Add(result); } Apply(); } private static Transform FindOwnerPage(Transform owner) { Transform val = owner; while ((Object)(object)val != (Object)null && !((Object)val).name.StartsWith("content-", StringComparison.Ordinal)) { val = val.parent; } if ((Object)(object)val == (Object)null && (Object)(object)owner != (Object)null) { UIOptionWindow componentInParent = ((Component)owner).GetComponentInParent<UIOptionWindow>(true); if ((Object)(object)componentInParent != (Object)null) { val = ((Component)componentInParent).transform; } } return val; } private unsafe static string CategoryName(EItemType type) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if ((int)type != 0) { return ((object)(*(EItemType*)(&type))/*cast due to .constrained prefix*/).ToString(); } return "Other"; } private static int CompareItems(ItemProto a, ItemProto b) { return string.Compare(((Proto)a).name, ((Proto)b).name, StringComparison.OrdinalIgnoreCase); } } internal sealed class ItemListWatcher : MonoBehaviour { public Transform Owner; private bool _hasOwner; public void SetOwner(Transform owner) { Owner = owner; _hasOwner = (Object)(object)owner != (Object)null; } private void Update() { if (_hasOwner && ((Object)(object)Owner == (Object)null || !((Component)Owner).gameObject.activeInHierarchy)) { ItemListWindow.Close(); } } } internal sealed class KeyCaptureBehaviour : MonoBehaviour { internal delegate void KeyCaptureSink(KeyCode key, bool ctrl, bool alt, bool shift); private const string Prompt = "Press a key... (Esc cancels)"; private const string Empty = "—"; private static KeyCaptureBehaviour _active; private static KeyCode[] _keys; private RegistrationRegistry.RegisteredOption _option; private KeyCaptureSink _sink; private Func<string> _read; private Text _caption; private bool _armed; private bool _combination; private int _armedFrame; private static KeyCode[] Keys { get { if (_keys == null) { KeyCode[] array = (KeyCode[])Enum.GetValues(typeof(KeyCode)); int num = 0; for (int i = 0; i < array.Length; i++) { if (array[i]) { num++; } } KeyCode[] array2 = (KeyCode[])(object)new KeyCode[num]; int num2 = 0; for (int j = 0; j < array.Length; j++) { if (array[j]) { array2[num2++] = array[j]; } } _keys = array2; } return _keys; } } public void Arm(RegistrationRegistry.RegisteredOption option, bool combination, Text caption) { if (option != null) { Begin(option, null, null, combination, caption); } } public void Arm(KeyCaptureSink sink, Func<string> read, bool combination, Text caption) { if (sink != null) { Begin(null, sink, read, combination, caption); } } private void Begin(RegistrationRegistry.RegisteredOption option, KeyCaptureSink sink, Func<string> read, bool combination, Text caption) { if ((Object)(object)_active != (Object)null && (Object)(object)_active != (Object)(object)this) { _active.Cancel(); } _option = option; _sink = sink; _read = read; _combination = combination; _caption = caption; _armed = true; _armedFrame = Time.frameCount; _active = this; if ((Object)(object)_caption != (Object)null) { _caption.text = "Press a key... (Esc cancels)"; } } private unsafe void Update() { //IL_0036: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) if (!_armed || Time.frameCount == _armedFrame || !Input.anyKeyDown) { return; } if (Input.GetKeyDown((KeyCode)27)) { Cancel(); return; } KeyCode[] keys = Keys; KeyCode val = (KeyCode)0; for (int i = 0; i < keys.Length; i++) { if (!IsModifier(keys[i]) && Input.GetKeyDown(keys[i])) { val = keys[i]; break; } } if ((int)val != 0) { bool ctrl = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305); bool alt = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307); bool shift = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303); if (_option != null) { string value = (_combination ? Combination(val, ctrl, alt, shift) : ((object)(*(KeyCode*)(&val))/*cast due to .constrained prefix*/).ToString()); _option.TryWriteText(value); } else if (_sink != null) { _sink(val, ctrl, alt, shift); } Cancel(); } } private void Cancel() { if ((Object)(object)_caption != (Object)null) { string value = null; if (_read != null) { try { value = _read(); } catch (Exception) { value = null; } } else if (_option != null) { _option.TryReadText(out value); } _caption.text = (string.IsNullOrEmpty(value) ? "—" : value); } _armed = false; _option = null; _sink = null; _read = null; _caption = null; if ((Object)(object)_active == (Object)(object)this) { _active = null; } } private void OnDestroy() { Cancel(); _armed = false; _option = null; _sink = null; _read = null; _caption = null; if ((Object)(object)_active == (Object)(object)this) { _active = null; } } private unsafe static string Combination(KeyCode key, bool ctrl, bool alt, bool shift) { string text = string.Empty; if (ctrl) { text += "Ctrl+"; } if (alt) { text += "Alt+"; } if (shift) { text += "Shift+"; } return text + ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString(); } private static bool IsModifier(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 if (key - 303 <= 7) { return true; } return false; } } internal sealed class ModInputField : InputField { private Text _overlay; public void AttachOverlay(Text overlay) { _overlay = overlay; Sync(); } private void Update() { Sync(); } private void Sync() { if (!((Object)(object)_overlay == (Object)null)) { bool isFocused = ((InputField)this).isFocused; Text textComponent = ((InputField)this).textComponent; if (!isFocused) { _overlay.text = ((InputField)this).text; } if (((Behaviour)_overlay).enabled == isFocused) { ((Behaviour)_overlay).enabled = !isFocused; } if ((Object)(object)textComponent != (Object)null && ((Behaviour)textComponent).enabled != isFocused) { ((Behaviour)textComponent).enabled = isFocused; } } } } internal static class ModOptionsRegistry { internal sealed class ModPage { public string Name; public Func<RectTransform, float> Build; } private static readonly List<ModPage> Pages = new List<ModPage>(); public static IReadOnlyList<ModPage> All => Pages; public static int LoadInstalledMods() { Pages.Clear(); List<PluginInfo> list = new List<PluginInfo>(); try { foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos) { PluginInfo value = pluginInfo.Value; if (value != null && value.Metadata != null && !string.Equals(value.Metadata.GUID, "com.hiul.DSP_mod_settings", StringComparison.Ordinal)) { list.Add(value); } } } catch (Exception ex) { DSP_Mod_Settings_Plugin.Log.LogError((object)("[ModSettings] could not read the plugin table: " + ex)); return 0; } list.Sort(CompareByName); foreach (PluginInfo item in list) { PluginInfo captured = item; string text = captured.Metadata.Name; if (string.IsNullOrEmpty(text)) { text = captured.Metadata.GUID; } Pages.Add(new ModPage { Name = text, Build = (RectTransform parent) => InstalledModsPage.Build(parent, captured) }); } return Pages.Count; } public static void Register(string name, Func<RectTransform, float> build) { if (!string.IsNullOrEmpty(name) && build != null) { Pages.Add(new ModPage { Name = name, Build = build }); } } private static int CompareByName(PluginInfo a, PluginInfo b) { return string.Compare(a.Metadata.Name, b.Metadata.Name, StringComparison.OrdinalIgnoreCase); } } internal static class OptionTabBuilder { private const float LeftWidth = 290f; private const float Gutter = 18f; private const float Top = 8f; private const float NavRowHeight = 32f; private const float NavRowGap = 4f; internal const float Padding = 8f; private const float BannerHeight = 26f; private const string BannerText = "Changes are saved to the .cfg files - restart the game to apply them."; private static readonly Color BannerColor = new Color(1f, 0.8f, 0.42f, 1f); private static RectTransform _scrollContent; private static RectTransform _navPanel; private static readonly Dictionary<ModOptionsRegistry.ModPage, Button> NavButtons = new Dictionary<ModOptionsRegistry.ModPage, Button>(); public static void Build(RectTransform page) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)page == (Object)null) { return; } UiFactory.AdoptFontFrom(page); if (!UiFactory.IsReady) { DSP_Mod_Settings_Plugin.Log.LogError((object)"[ModSettings] options tab: no font available, page left empty"); return; } Rect rect = page.rect; float num = ((Rect)(ref rect)).height; if (num < 100f) { num = 900f; } rect = page.rect; float num2 = ((Rect)(ref rect)).width; if (num2 < 508f) { num2 = 1200f; } int num3 = ModOptionsRegistry.LoadInstalledMods(); NavButtons.Clear(); _navPanel = UiFactory.Panel((Transform)(object)page, "modsettings-nav", 0f, 8f, 290f, num - 16f, background: true); float num4 = num2 - 290f - 18f - 8f; float num5 = 34f; UiFactory.Label((Transform)(object)page, "Changes are saved to the .cfg files - restart the game to apply them.", 308f, 6f, num4, 15, bold: false, BannerColor); UiFactory.ScrollView((Transform)(object)page, "modsettings-scroll", 308f, num5, num4, num - num5 - 8f, out _scrollContent); float num6 = 8f; foreach (ModOptionsRegistry.ModPage item in ModOptionsRegistry.All) { ModOptionsRegistry.ModPage pageDef = item; Button val = UiFactory.Button((Transform)(object)_navPanel, pageDef.Name, 8f, num6, 274f, 28f, (UnityAction)delegate { Select(pageDef); }); if ((Object)(object)val != (Object)null) { NavButtons[pageDef] = val; } num6 += 36f; } if (num3 > 0) { Select(ModOptionsRegistry.All[0]); return; } UiFactory.Label((Transform)(object)_scrollContent, "No other mod was loaded by BepInEx.", 8f, 8f, num4 - 16f, 16, bold: false, UiFactory.MutedColor); _scrollContent.sizeDelta = new Vector2(0f, 60f); } private static void Select(ModOptionsRegistry.ModPage mod) { //IL_0099: Unknown result type (might be due to invalid IL or missing references) if (mod != null && !((Object)(object)_scrollContent == (Object)null)) { ItemListWindow.Close(); for (int num = ((Transform)_scrollContent).childCount - 1; num >= 0; num--) { Transform child = ((Transform)_scrollContent).GetChild(num); child.SetParent((Transform)null, false); Object.Destroy((Object)(object)((Component)child).gameObject); } Highlight(mod); float num2 = 0f; try { num2 = mod.Build(_scrollContent); } catch (Exception ex) { DSP_Mod_Settings_Plugin.Log.LogError((object)ex.ToString()); } _scrollContent.sizeDelta = new Vector2(0f, Math.Max(num2 + 16f, 100f)); } } private static void Highlight(ModOptionsRegistry.ModPage selected) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) foreach (KeyValuePair<ModOptionsRegistry.ModPage, Button> navButton in NavButtons) { if (!((Object)(object)navButton.Value == (Object)null)) { Graphic targetGraphic = ((Selectable)navButton.Value).targetGraphic; Image val = (Image)(object)((targetGraphic is Image) ? targetGraphic : null); if ((Object)(object)val != (Object)null) { ((Graphic)val).color = ((navButton.Key == selected) ? UiFactory.ButtonActiveColor : UiFactory.ButtonColor); } } } } } internal static class RegisteredPage { private const float TabHeight = 30f; private const float TabGap = 6f; private const float TabRowHeight = 36f; private const float AreaGap = 6f; private const float GroupGap = 18f; private const float GroupTitleHeight = 24f; private const float MinSurface = 100f; private const float MessageRowHeight = 22f; private static RectTransform _content; private static RectTransform _area; private static RegistrationRegistry.RegisteredMod _mod; private static List<RegistrationRegistry.RegisteredTab> _tabs; private static Button[] _buttons; private static int _active; private static float _areaTop; private static float _areaHeight; public static float Build(RectTransform parent, RegistrationRegistry.RegisteredMod mod, float y) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Expected O, but got Unknown _content = parent; _area = null; _mod = mod; _tabs = ((mod == null) ? new List<RegistrationRegistry.RegisteredTab>() : new List<RegistrationRegistry.RegisteredTab>(mod.Tabs)); _buttons = (Button[])(object)new Button[0]; _active = -1; _areaTop = 0f; _areaHeight = 0f; if ((Object)(object)parent == (Object)null) { return y; } if (_tabs.Count == 0) { UiFactory.Label((Transform)(object)parent, "This mod registers no tab.", 0f, y, 760f, 16, bold: false, UiFactory.MutedColor); return y + 30f; } int num = CountRows(); _buttons = (Button[])(object)new Button[_tabs.Count]; float num2 = 0f; int num3 = 0; for (int i = 0; i < _tabs.Count; i++) { RegistrationRegistry.RegisteredTab registeredTab = _tabs[i]; float num4 = TabWidth(registeredTab.Title); if (num2 > 0f && num2 + num4 > 760f) { num2 = 0f; num3++; } int index = i; RegistrationRegistry.RegisteredMod owner = mod; Button val = UiFactory.Button((Transform)(object)parent, registeredTab.Title, num2, y + (float)num3 * 36f, num4, 30f, (UnityAction)delegate { ShowTab(index, owner); }); _buttons[i] = val; num2 += num4 + 6f; } _areaTop = y + (float)num * 36f + 6f; _area = UiFactory.Panel((Transform)(object)parent, "tab-groups", 0f, _areaTop, 760f, 0f); ShowTab(0, mod); return _areaTop + _areaHeight; } private static void ShowTab(int index, RegistrationRegistry.RegisteredMod owner) { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_area == (Object)null || _mod == null || _mod != owner || _tabs == null || index < 0 || index >= _tabs.Count) { return; } for (int num = ((Transform)_area).childCount - 1; num >= 0; num--) { Transform child = ((Transform)_area).GetChild(num); child.SetParent((Transform)null, false); Object.Destroy((Object)(object)((Component)child).gameObject); } float num2 = (_areaHeight = RenderGroups(_area, _tabs[index])); _area.sizeDelta = new Vector2(760f, num2); _active = index; if ((Object)(object)_content != (Object)null) { float num3 = Mathf.Max(_areaTop + num2 + 16f, 100f); _content.sizeDelta = new Vector2(0f, num3); } for (int i = 0; i < _buttons.Length; i++) { Button val = _buttons[i]; if (!((Object)(object)val == (Object)null)) { Graphic targetGraphic = ((Selectable)val).targetGraphic; Image val2 = (Image)(object)((targetGraphic is Image) ? targetGraphic : null); if ((Object)(object)val2 != (Object)null) { ((Graphic)val2).color = ((i == _active) ? UiFactory.ButtonActiveColor : UiFactory.ButtonColor); } } } } private static float RenderGroups(RectTransform parent, RegistrationRegistry.RegisteredTab tab) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) List<RegistrationRegistry.RegisteredGroup> list = ((tab == null) ? new List<RegistrationRegistry.RegisteredGroup>() : new List<RegistrationRegistry.RegisteredGroup>(tab.Groups)); if (list.Count == 0) { UiFactory.Label((Transform)(object)parent, "This tab has no group.", 0f, 0f, 760f, 16, bold: false, UiFactory.MutedColor); return 22f; } float num = 0f; for (int i = 0; i < list.Count; i++) { if (i > 0) { num += 18f; } RegistrationRegistry.RegisteredGroup registeredGroup = list[i]; UiFactory.Label((Transform)(object)parent, registeredGroup.Title, 0f, num, 760f, 18, bold: true, UiFactory.TextColor); num += 24f; List<RegistrationRegistry.RegisteredOption> list2 = new List<RegistrationRegistry.RegisteredOption>(registeredGroup.Options); for (int j = 0; j < list2.Count; j++) { num = TypedRows.Row((Transform)(object)parent, list2[j], num); } } return num; } private static int CountRows() { int num = 1; float num2 = 0f; for (int i = 0; i < _tabs.Count; i++) { float num3 = TabWidth(_tabs[i].Title); if (num2 > 0f && num2 + num3 > 760f) { num++; num2 = 0f; } num2 += num3 + 6f; } return num; } private static float TabWidth(string title) { int num = title?.Length ?? 0; return Mathf.Clamp(28f + (float)num * 8f, 90f, 200f); } } internal static class RegistrationRegistry { internal enum OptionKind { Int, Float, IntRange, FloatRange, Text, Selection, Key, KeyCombination } internal sealed class RegisteredOption { public OptionKind Kind; public string Label; public int Sequence; public bool RequiresRestart; public Func<float> GetNumber; public Action<float> SetNumber; public float Min = float.NegativeInfinity; public float Max = float.PositiveInfinity; public bool Whole; public Func<string> GetText; public Action<string> SetText; public string[] Options; public bool TryReadNumber(out float value) { value = 0f; Func<float> getNumber = GetNumber; if (getNumber == null) { return false; } try { value = getNumber(); return true; } catch (Exception ex) { Warn("could not read '" + Label + "': " + ex.Message); return false; } } public bool TryReadText(out string value) { value = null; Func<string> getText = GetText; if (getText == null) { return false; } try { value = getText(); return true; } catch (Exception ex) { Warn("could not read '" + Label + "': " + ex.Message); return false; } } public bool TryWriteNumber(float value) { Action<float> setNumber = SetNumber; if (setNumber == null) { return false; } try { setNumber(value); return true; } catch (Exception ex) { Warn("could not write '" + Label + "': " + ex.Message); return false; } } public bool TryWriteText(string value) { Action<string> setText = SetText; if (setText == null) { return false; } try { setText(value); return true; } catch (Exception ex) { Warn("could not write '" + Label + "': " + ex.Message); return false; } } } internal sealed class RegisteredGroup { public string Title; public int Order; public int Sequence; public readonly List<RegisteredOption> Options = new List<RegisteredOption>(); public RegisteredOption Find(string label) { for (int i = 0; i < Options.Count; i++) { if (string.Equals(Options[i].Label, label, StringComparison.OrdinalIgnoreCase)) { return Options[i]; } } return null; } } internal sealed class RegisteredTab { public string Title; public int Order; public int Sequence; public readonly List<RegisteredGroup> Groups = new List<RegisteredGroup>(); public RegisteredGroup Find(string title) { for (int i = 0; i < Groups.Count; i++) { if (string.Equals(Groups[i].Title, title, StringComparison.OrdinalIgnoreCase)) { return Groups[i]; } } return null; } } internal sealed class RegisteredMod { public string Guid; public readonly List<RegisteredTab> Tabs = new List<RegisteredTab>(); public RegisteredTab Find(string title) { for (int i = 0; i < Tabs.Count; i++) { if (string.Equals(Tabs[i].Title, title, StringComparison.OrdinalIgnoreCase)) { return Tabs[i]; } } return null; } } private static readonly Dictionary<string, RegisteredMod> Mods = new Dictionary<string, RegisteredMod>(StringComparer.Ordinal); private static int _sequence; public static RegisteredTab GetOrCreateTab(string guid, string title, int order) { if (string.IsNullOrEmpty(guid) || string.IsNullOrEmpty(title)) { return null; } try { if (!Mods.TryGetValue(guid, out var value)) { value = new RegisteredMod(); value.Guid = guid; Mods[guid] = value; } RegisteredTab registeredTab = value.Find(title); if (registeredTab != null) { return registeredTab; } RegisteredTab registeredTab2 = new RegisteredTab(); registeredTab2.Title = title; registeredTab2.Order = order; registeredTab2.Sequence = _sequence++; value.Tabs.Add(registeredTab2); value.Tabs.Sort(CompareTabs); return registeredTab2; } catch (Exception ex) { Warn("could not register tab '" + title + "': " + ex.Message); return null; } } public static RegisteredGroup GetOrCreateGroup(RegisteredTab tab, string title, int order) { if (tab == null || string.IsNullOrEmpty(title)) { return null; } try { RegisteredGroup registeredGroup = tab.Find(title); if (registeredGroup != null) { return registeredGroup; } RegisteredGroup registeredGroup2 = new RegisteredGroup(); registeredGroup2.Title = title; registeredGroup2.Order = order; registeredGroup2.Sequence = _sequence++; tab.Groups.Add(registeredGroup2); tab.Groups.Sort(CompareGroups); return registeredGroup2; } catch (Exception ex) { Warn("could not register group '" + title + "': " + ex.Message); return null; } } public static void SetOption(RegisteredGroup group, RegisteredOption option) { if (group == null || option == null || string.IsNullOrEmpty(option.Label)) { return; } try { RegisteredOption registeredOption = group.Find(option.Label); if (registeredOption != null) { option.Sequence = registeredOption.Sequence; int num = group.Options.IndexOf(registeredOption); if (num >= 0) { group.Options[num] = option; } } else { option.Sequence = _sequence++; group.Options.Add(option); group.Options.Sort(CompareOptions); } } catch (Exception ex) { Warn("could not register option '" + option.Label + "': " + ex.Message); } } public static bool TryGet(string guid, out RegisteredMod mod) { mod = null; if (string.IsNullOrEmpty(guid)) { return false; } try { if (!Mods.TryGetValue(guid, out var value) || value.Tabs.Count == 0) { return false; } mod = value; return true; } catch (Exception ex) { Warn("could not read the registrations of '" + guid + "': " + ex.Message); return false; } } private static int CompareTabs(RegisteredTab a, RegisteredTab b) { int num = a.Order.CompareTo(b.Order); if (num == 0) { return a.Sequence.CompareTo(b.Sequence); } return num; } private static int CompareGroups(RegisteredGroup a, RegisteredGroup b) { int num = a.Order.CompareTo(b.Order); if (num == 0) { return a.Sequence.CompareTo(b.Sequence); } return num; } private static int CompareOptions(RegisteredOption a, RegisteredOption b) { return a.Sequence.CompareTo(b.Sequence); } private static void Warn(string message) { if (DSP_Mod_Settings_Plugin.Log != null) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)("[ModSettings] " + message)); } } } internal static class TypedRows { private static bool _syncing; private const float RestartHintWidth = 132f; internal static float Row(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { if ((Object)(object)parent == (Object)null || option == null) { return 0f; } float num = BuildRow(parent, option, y); if (option.RequiresRestart) { RestartHint(parent, y, num - y); } return num; } private static void RestartHint(Transform parent, float y, float rowHeight) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) float y2 = ((rowHeight > 30f) ? (y + 12f) : (y + 7f)); UiFactory.Label(parent, "requires restart", 628f, y2, 132f, 13, bold: false, UiFactory.MutedColor); } private static float BuildRow(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { switch (option.Kind) { case RegistrationRegistry.OptionKind.Int: if (UiFactory.LooksLikeId(option.Label)) { return IdRow(parent, option, y); } return NumberRow(parent, option, y); case RegistrationRegistry.OptionKind.Float: return NumberRow(parent, option, y); case RegistrationRegistry.OptionKind.IntRange: case RegistrationRegistry.OptionKind.FloatRange: return RangedRow(parent, option, y); case RegistrationRegistry.OptionKind.Text: return TextRow(parent, option, y); case RegistrationRegistry.OptionKind.Selection: return SelectionRow(parent, option, y); case RegistrationRegistry.OptionKind.Key: case RegistrationRegistry.OptionKind.KeyCombination: return KeyRow(parent, option, y); default: return FallbackRow(parent, option, y); } } private static float IdRow(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown UiFactory.Label(parent, option.Label, 16f, y + 4f, 250f, 15, bold: false, UiFactory.MutedColor); float value; int id = (option.TryReadNumber(out value) ? ((int)value) : 0); Button val = UiFactory.Button(parent, UiFactory.ItemName(id), 264f, y + 2f, 320f, 26f, null); if ((Object)(object)val == (Object)null) { return y + 30f; } Text caption = ((Component)val).GetComponentInChildren<Text>(); ((UnityEvent)val.onClick).AddListener((UnityAction)delegate { float value2; int num = (option.TryReadNumber(out value2) ? ((int)value2) : 0); ItemListWindow.Open(parent, multiSelect: false, (num <= 0) ? new int[0] : new int[1] { num }, delegate(int[] picked) { int num2 = ((picked != null && picked.Length != 0) ? picked[0] : 0); option.TryWriteNumber(num2); if ((Object)(object)caption != (Object)null) { caption.text = UiFactory.ItemName(num2); } }); }); return y + 30f; } private static float NumberRow(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) UiFactory.Label(parent, option.Label, 16f, y + 4f, 250f, 15, bold: false, UiFactory.MutedColor); float value = ReadNumber(option, 0f); InputField captured; ((UnityEvent<string>)(object)(captured = UiFactory.NumericField(parent, "input", 264f, y + 3f, 96f, 28f, value, null)).onEndEdit).AddListener((UnityAction<string>)delegate(string text) { if (!_syncing) { if (!InstalledModsPage.TryParse(text, out var value2)) { Warn("rejected " + option.Label + ": '" + text + "'"); RestoreNumber(captured, option); } else { float num = Clamp((float)value2, option.Min, option.Max); option.TryWriteNumber(num); ShowNumber(captured, ReadNumber(option, num)); } } }); return y + 30f; } private static float RangedRow(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) float min = option.Min; float max = option.Max; if (max <= min) { max = min + 1f; } float current = Clamp(ReadNumber(option, min), min, max); UiFactory.Label(parent, option.Label, 16f, y + 9f, 250f, 15, bold: false, UiFactory.MutedColor); Slider val = UiFactory.Slider(parent, "slider", 264f, y + 9f, 210f, 20f, null); val.wholeNumbers = option.Whole; val.minValue = min; val.maxValue = max; val.value = current; InputField val2 = UiFactory.NumericField(parent, "input", 486f, y + 5f, 96f, 28f, current, null); Slider capturedSlider = val; InputField capturedField = val2; ((UnityEvent<float>)(object)val.onValueChanged).AddListener((UnityAction<float>)delegate(float raw) { if (!_syncing) { float num = Clamp(raw, min, max); option.TryWriteNumber(num); ShowNumber(capturedField, ReadNumber(option, num)); } }); ((UnityEvent<string>)(object)val2.onEndEdit).AddListener((UnityAction<string>)delegate(string text) { if (!_syncing) { if (!InstalledModsPage.TryParse(text, out var value)) { Warn("rejected " + option.Label + ": '" + text + "'"); float value2 = ReadNumber(option, current); ShowNumber(capturedField, value2); ShowSlider(capturedSlider, value2); } else { float num = Clamp((float)value, min, max); option.TryWriteNumber(num); float value3 = ReadNumber(option, num); ShowNumber(capturedField, value3); ShowSlider(capturedSlider, value3); } } }); return y + 40f; } private static float FallbackRow(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) UiFactory.Label(parent, option.Label + " - " + option.Kind.ToString() + " control is not available yet.", 16f, y + 4f, 744f, 15, bold: false, UiFactory.MutedColor); return 30f; } private static float TextRow(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) UiFactory.Label(parent, option.Label, 16f, y + 4f, 250f, 15, bold: false, UiFactory.MutedColor); if (!option.TryReadText(out var value)) { value = string.Empty; } InputField captured; ((UnityEvent<string>)(object)(captured = UiFactory.TextField(parent, "input", 264f, y + 3f, 320f, 28f, value ?? string.Empty)).onEndEdit).AddListener((UnityAction<string>)delegate(string text) { if (!_syncing) { option.TryWriteText(text); if (option.TryReadText(out var value2)) { ShowText(captured, value2 ?? string.Empty); } } }); return y + 30f; } private static float SelectionRow(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown UiFactory.Label(parent, option.Label, 16f, y + 5f, 250f, 15, bold: false, UiFactory.MutedColor); string[] choices = option.Options; if (choices == null || choices.Length == 0) { UiFactory.Label(parent, "(no option registered)", 264f, y + 4f, 210f, 15, bold: false, UiFactory.MutedColor); return y + 30f; } if (!option.TryReadText(out var value)) { value = null; } int selectedIndex = IndexOf(choices, value); UIComboBox val = UiFactory.Dropdown(parent, 264f, y, 200f, 30f, choices, selectedIndex, delegate(int index) { if (index >= 0 && index < choices.Length) { option.TryWriteText(choices[index]); } }); if ((Object)(object)val != (Object)null) { return y + 30f; } Button val2 = UiFactory.Button(parent, Display(value), 264f, y + 2f, 210f, 26f, null); if ((Object)(object)val2 == (Object)null) { return y + 30f; } Text caption = ((Component)val2).GetComponentInChildren<Text>(); ((UnityEvent)val2.onClick).AddListener((UnityAction)delegate { if (!option.TryReadText(out var value2)) { value2 = null; } int num = IndexOf(choices, value2); string text = choices[(num + 1) % choices.Length]; if (option.TryWriteText(text)) { if (!option.TryReadText(out var value3)) { value3 = text; } if ((Object)(object)caption != (Object)null) { caption.text = Display(value3); } } }); return y + 30f; } private static float KeyRow(Transform parent, RegistrationRegistry.RegisteredOption option, float y) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Expected O, but got Unknown UiFactory.Label(parent, option.Label, 16f, y + 5f, 250f, 15, bold: false, UiFactory.MutedColor); if (!option.TryReadText(out var value)) { value = null; } Button val = UiFactory.Button(parent, Display(value), 264f, y + 2f, 210f, 26f, null); if ((Object)(object)val == (Object)null) { return y + 30f; } Text caption = ((Component)val).GetComponentInChildren<Text>(); KeyCaptureBehaviour capture = ((Component)val).gameObject.AddComponent<KeyCaptureBehaviour>(); bool combination = option.Kind == RegistrationRegistry.OptionKind.KeyCombination; ((UnityEvent)val.onClick).AddListener((UnityAction)delegate { capture.Arm(option, combination, caption); }); return y + 30f; } private static int IndexOf(string[] choices, string value) { for (int i = 0; i < choices.Length; i++) { if (string.Equals(choices[i], value, StringComparison.OrdinalIgnoreCase)) { return i; } } return -1; } private static string Display(string value) { if (!string.IsNullOrEmpty(value)) { return value; } return "—"; } private static float ReadNumber(RegistrationRegistry.RegisteredOption option, float fallback) { if (!option.TryReadNumber(out var value)) { return fallback; } return value; } private static float Clamp(float value, float min, float max) { if (value < min) { return min; } if (value > max) { return max; } return value; } private static void RestoreNumber(InputField field, RegistrationRegistry.RegisteredOption option) { if (option.TryReadNumber(out var value)) { ShowNumber(field, value); } } private static void ShowNumber(InputField field, float value) { if ((Object)(object)field == (Object)null) { return; } _syncing = true; try { field.text = InstalledModsPage.FormatNumber(value); } finally { _syncing = false; } } private static void ShowText(InputField field, string value) { if ((Object)(object)field == (Object)null) { return; } _syncing = true; try { field.text = value ?? string.Empty; } finally { _syncing = false; } } private static void ShowSlider(Slider slider, float value) { if ((Object)(object)slider == (Object)null) { return; } _syncing = true; try { slider.value = value; } finally { _syncing = false; } } private static void Warn(string message) { if (DSP_Mod_Settings_Plugin.Log != null) { DSP_Mod_Settings_Plugin.Log.LogWarning((object)("[ModSettings] " + message)); } } } internal static class UiFactory { private const float LabelWidth = 300f; private const float ControlWidth = 280f; private const float ControlHeight = 20f; private const float CheckBoxSize = 40f; private const float HandleWidth = 40f; private const float InputGap = 12f; private const float InputWidth = 100f; private const float InputHeight = 28f; private const float DerivedLabelX = 704f; private const float DerivedLabelWidth = 160f; private static Sprite _white; private static Font _font; private static Font _fontBold; private static Color? _panelTint; private static Color? _buttonTint; private static Color? _trackTint; private static Color? _fillTint; private static Color? _handleTint; private static Color? _toggleTint; private static Color? _checkTint; private static Sprite _toggleOnSprite; private static Sprite _toggleOffSprite; private static Type _toggleImageType; private static Color? _toggleImageColor; private static GameObject _comboBoxTemplate; private static Color? _labelTint; private static Color? _handleTextTint; private static Sprite _buttonSprite; private static Type _buttonImageType; private static Color? _buttonHoverTint; private static Color? _buttonPressedTint; private static int _buttonTextSize; private static int _fontSize; private static int _handleTextSize; public const float RowHeight = 40f; public const float DropdownWidth = 200f; public const float DropdownHeight = 30f; public const float ToggleRowHeight = 40f; public const float HeaderHeight = 40f; public static Color PanelColor => (Color)(((??)_panelTint) ?? new Color(0.07f, 0.09f, 0.11f, 0.75f)); public static Color TrackColor => (Color)(((??)_trackTint) ?? new Color(0f, 0f, 0f, 0.43f)); public static Color FillColor => (Color)(((??)_fillTint) ?? new Color(0f, 0f, 0f, 0.43f)); public static Color HandleColor => (Color)(((??)_handleTint) ?? new Color(0.13f, 0.18f, 0.21f, 1f)); public static Color TextColor => (Color)(((??)_labelTint) ?? new Color(1f, 1f, 1f, 0.78f)); public static Color MutedColor { get { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) Color textColor = TextColor; return new Color(textColor.r * 0.72f, textColor.g * 0.72f, textColor.b * 0.72f, textColor.a); } } public static Color HandleTextColor => (Color)(((??)_handleTextTint) ?? new Color(1f, 1f, 1f, 0.62f)); public static Color ButtonColor => (Color)(((??)_buttonTint) ?? new Color(0.2f, 0.22f, 0.26f, 1f)); public static Color ButtonActiveColor { get { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) Color buttonColor = ButtonColor; return new Color(Math.Min(1f, buttonColor.r * 1.45f), Math.Min(1f, buttonColor.g * 1.45f), Math.Min(1f, buttonColor.b * 1.45f), buttonColor.a); } } public static Color ToggleColor => (Color)(((??)_toggleTint) ?? new Color(1f, 1f, 1f, 0.45f)); public static Color CheckColor => (Color)(((??)_checkTint) ?? new Color(1f, 1f, 1f, 1f)); public static int FontSize { get { if (_fontSize <= 0) { return 18; } return _fontSize; } } public static int HandleTextSize { get { if (_handleTextSize <= 0) { return 13; } return _handleTextSize; } } public static bool IsReady { get { if ((Object)(object)White != (Object)null) { return (Object)(object)Font != (Object)null; } return false; } } private stati