Decompiled source of ModOptions v1.0.0
ModOptions.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.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using CellMenu; using GameData; using HarmonyLib; using Il2CppInterop.Runtime.Injection; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Microsoft.CodeAnalysis; using ModOptions.Integration; using ModOptions.UI; using TMPro; using TheArchive; using TheArchive.Core; using TheArchive.Core.Attributes.Feature; using TheArchive.Core.Attributes.Feature.Members; using TheArchive.Core.Attributes.Feature.Settings; using TheArchive.Core.FeaturesAPI; using TheArchive.Core.FeaturesAPI.Components; using TheArchive.Core.FeaturesAPI.Settings; using TheArchive.Core.Localization; using TheArchive.Features.Dev; using TheArchive.Utilities; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("ModOptions")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+10f98ea209af659db5fd9f3ec3f01febb70915e8")] [assembly: AssemblyProduct("ModOptions")] [assembly: AssemblyTitle("ModOptions")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ModOptions { public sealed class InfoSection { private readonly ModPage _mod; private readonly List<SettingRow> _rows = new List<SettingRow>(); internal IReadOnlyList<SettingRow> Rows => _rows; internal bool ShowsVersionLine { get; private set; } = true; internal InfoSection(ModPage mod) { _mod = mod; } public LabelRow AddLabel(string text, string? description = null) { return Add(SettingsPage.CreateLabel(_mod, text, description)); } public ButtonRow AddLink(string label, string buttonText, string url, string? description = null) { return Add(SettingsPage.CreateLink(_mod, label, buttonText, url, description)); } public ButtonRow AddButton(string label, string buttonText, Action onClick, string? description = null) { return Add(SettingsPage.CreateButton(_mod, label, buttonText, onClick, description)); } public InfoSection ShowVersionLine(bool show) { ShowsVersionLine = show; return this; } private T Add<T>(T row) where T : SettingRow { _rows.Add(row); Registry.OnRowAdded(row); return row; } } public static class ModOptionsApi { private static readonly List<ModPage> Registered = new List<ModPage>(); public const string Guid = "Oxylight.ModOptions"; public static string Version => "1.0.0"; internal static List<ModPage> Mods { get { lock (Registered) { return Registered.OrderBy((ModPage mod) => (!(mod.Guid == "Oxylight.ModOptions")) ? 1 : 0).ThenBy<ModPage, string>((ModPage mod) => mod.Title, StringComparer.CurrentCultureIgnoreCase).ToList(); } } } public static ModPage Register(string guid, string title, string? description = null) { if (string.IsNullOrWhiteSpace(guid)) { throw new ArgumentException("A GUID is required.", "guid"); } if (string.IsNullOrWhiteSpace(title)) { throw new ArgumentException("A title is required.", "title"); } lock (Registered) { if (Registered.Any((ModPage mod) => string.Equals(mod.Guid, guid, StringComparison.OrdinalIgnoreCase))) { throw new ArgumentException("'" + guid + "' is already registered with ModOptions.", "guid"); } ModPage modPage = new ModPage(guid, title, description); Registered.Add(modPage); Registry.OnRegistered(modPage); return modPage; } } } public abstract class SettingRow { public string Label { get; } internal SettingsPage Page { get; } internal string? Description { get; } internal virtual ConfigEntryBase? Entry => null; internal string? Tooltip { get { if (string.IsNullOrWhiteSpace(Description)) { ConfigEntryBase? entry = Entry; object obj; if (entry == null) { obj = null; } else { ConfigDescription description = entry.Description; obj = ((description != null) ? description.Description : null); } string text = (string)obj; if (text == null || text.Length <= 0) { return null; } return text; } return Description; } } private bool? RestartOverride { get; set; } internal bool NeedsRestart { get { if (Entry != null) { return RestartOverride ?? (!Page.Mod.HotReload); } return false; } } private protected SettingRow(SettingsPage page, string label, string? description) { if (string.IsNullOrWhiteSpace(label)) { if (!(this is ButtonRow) && !(this is SubPageRow)) { throw new ArgumentException("A label is required.", "label"); } } Page = page; Label = label ?? string.Empty; Description = description; } public SettingRow RestartRequired() { RestartOverride = true; return this; } public SettingRow RestartNotRequired() { RestartOverride = false; return this; } } public enum SliderDisplay { Percent, Integer, OneDecimal, TwoDecimals } public sealed class SliderRow : SettingRow { private Func<float, string>? _valueText; private bool _valueTextFailed; internal override ConfigEntryBase Entry { get; } internal float Minimum { get; } internal float Maximum { get; } internal float StepSize { get; private set; } internal bool IsInteger { get; } internal SliderDisplay Display { get; } internal string UnitText { get; private set; } = string.Empty; internal bool HasValueText => _valueText != null; internal SliderRow(SettingsPage page, ConfigEntryBase entry, string label, string? description, float minimum, float maximum, float step, bool isInteger, SliderDisplay display) : base(page, label, description) { if (!(maximum > minimum)) { throw new ArgumentException($"'{entry.Definition}' has an empty range ({minimum}..{maximum}).", "entry"); } Entry = entry; Minimum = minimum; Maximum = maximum; StepSize = step; IsInteger = isInteger; Display = display; } public SliderRow Unit(string unit) { UnitText = unit ?? string.Empty; return this; } public SliderRow Step(float step) { if (float.IsNaN(step) || float.IsInfinity(step) || step <= 0f) { throw new ArgumentException($"'{Entry.Definition}': the step must be a number above 0.", "step"); } if (IsInteger && (step < 1f || step != MathF.Floor(step))) { throw new ArgumentException($"'{Entry.Definition}': an int slider's step must be a whole number of at least 1.", "step"); } StepSize = step; return this; } public SliderRow ValueText(Func<float, string>? format) { _valueText = format; _valueTextFailed = false; return this; } public new SliderRow RestartRequired() { base.RestartRequired(); return this; } public new SliderRow RestartNotRequired() { base.RestartNotRequired(); return this; } internal float Read() { return Convert.ToSingle(Entry.BoxedValue); } internal void Write(float value) { float num = Round(value); if (IsInteger) { int num2 = (int)Math.Round(num); if (!object.Equals(Entry.BoxedValue, num2)) { Entry.BoxedValue = num2; } } else if (!object.Equals(Entry.BoxedValue, num)) { Entry.BoxedValue = num; } } internal float Round(float value) { value = Math.Clamp(value, Minimum, Maximum); if (StepSize > 0f) { double num = Math.Round(((double)value - (double)Minimum) / (double)StepSize); double num2 = Math.Clamp((double)Minimum + num * (double)StepSize, Minimum, Maximum); if ((double)(Maximum - value) < Math.Abs(num2 - (double)value)) { return Maximum; } if (!IsInteger) { return (float)Math.Clamp(Math.Round(num2, 6), Minimum, Maximum); } return (float)num2; } return Math.Clamp((float)Math.Round(value, Display switch { SliderDisplay.Percent => 2, SliderDisplay.Integer => 0, SliderDisplay.OneDecimal => 1, _ => 2, }), Minimum, Maximum); } internal string Format(float value) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown Func<float, string> valueText = _valueText; if (valueText != null) { try { string text = valueText(value); if (text != null) { return text; } } catch (Exception ex) { if (!_valueTextFailed) { _valueTextFailed = true; ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(78, 4, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Slider '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(base.Label); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ConfigDefinition>(Entry.Definition); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): ValueText threw for "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value.ToString(CultureInfo.InvariantCulture)); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; showing the default text (reported once). "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogWarning(val); } } } return Display switch { SliderDisplay.Percent => (!IsInteger) ? (Math.Round(value * 100f).ToString("0", CultureInfo.InvariantCulture) + "%") : (Math.Round(value).ToString("0", CultureInfo.InvariantCulture) + "%"), SliderDisplay.Integer => Math.Round(value).ToString("0", CultureInfo.InvariantCulture), SliderDisplay.OneDecimal => value.ToString("0.0", CultureInfo.InvariantCulture), _ => value.ToString("0.00", CultureInfo.InvariantCulture), } + UnitText; } } public sealed class FilePickerRow : SettingRow { private readonly List<(string Name, string Patterns)> _filters = new List<(string, string)>(); internal override ConfigEntry<string> Entry { get; } internal string? BaseFolder { get; } internal IReadOnlyList<(string Name, string Patterns)> Filters => _filters; internal string? Title { get; private set; } internal string? InitialFolder { get; private set; } internal Action? SameFilePicked { get; private set; } public string? FullPath { get { string text = Entry.Value.Trim().Trim('"'); if (text.Length == 0) { return null; } try { return (Path.IsPathRooted(text) || BaseFolder == null) ? Path.GetFullPath(text) : Path.GetFullPath(Path.Combine(BaseFolder, text)); } catch (Exception) { return null; } } } internal FilePickerRow(SettingsPage page, ConfigEntry<string> entry, string label, string? description, string? baseFolder) : base(page, label, description) { Entry = entry; BaseFolder = (string.IsNullOrWhiteSpace(baseFolder) ? null : baseFolder); } public FilePickerRow Filter(string name, string patterns) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("A filter name is required.", "name"); } if (string.IsNullOrWhiteSpace(patterns)) { throw new ArgumentException("At least one pattern is required.", "patterns"); } _filters.Add((name, patterns.Replace(" ", string.Empty))); return this; } public FilePickerRow DialogTitle(string title) { Title = title; return this; } public FilePickerRow StartFolder(string folder) { InitialFolder = folder; return this; } public FilePickerRow OnSameFilePicked(Action action) { SameFilePicked = action; return this; } public new FilePickerRow RestartRequired() { base.RestartRequired(); return this; } public new FilePickerRow RestartNotRequired() { base.RestartNotRequired(); return this; } internal void Browse() { string initialPath = FullPath ?? InitialFolder ?? BaseFolder; FileDialog.PickFile(Title ?? ("Select file: " + base.Label), initialPath, _filters, delegate(string picked) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown string text = ToStoredPath(picked); if (!string.Equals(Entry.Value, text, StringComparison.Ordinal)) { Entry.Value = text; return; } try { SameFilePicked?.Invoke(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(49, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(base.Label); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': the action for picking the same file failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } }); } private string ToStoredPath(string fullPath) { string text = Path.GetFullPath(fullPath); if (BaseFolder != null) { string text2 = Path.GetFullPath(BaseFolder).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar; if (text.StartsWith(text2, StringComparison.OrdinalIgnoreCase)) { string text3 = text; int length = text2.Length; text = text3.Substring(length, text3.Length - length); } } return ConfigSafe(text); } private static string ConfigSafe(string path) { if (path.Length <= 2 || !char.IsLetter(path[0]) || path[1] != ':' || path[2] != '\\' || path.Contains("\\\\")) { return path.Replace('\\', '/'); } return path; } } public sealed class HeaderRow : SettingRow { internal HeaderRow(SettingsPage page, string text) : base(page, text, null) { } } public sealed class ToggleRow : SettingRow { internal override ConfigEntry<bool> Entry { get; } internal ToggleRow(SettingsPage page, ConfigEntry<bool> entry, string label, string? description) : base(page, label, description) { Entry = entry; } public new ToggleRow RestartRequired() { base.RestartRequired(); return this; } public new ToggleRow RestartNotRequired() { base.RestartNotRequired(); return this; } } public sealed class DropdownRow : SettingRow { internal override ConfigEntryBase Entry { get; } internal Type EnumType { get; } internal Func<object, string> Format { get; } internal DropdownRow(SettingsPage page, ConfigEntryBase entry, Type enumType, string label, string? description, Func<object, string> format) : base(page, label, description) { Entry = entry; EnumType = enumType; Format = format; } public new DropdownRow RestartRequired() { base.RestartRequired(); return this; } public new DropdownRow RestartNotRequired() { base.RestartNotRequired(); return this; } } public sealed class TextRow : SettingRow { internal const int MaximumLength = 260; internal override ConfigEntry<string> Entry { get; } internal string EmptyText { get; } internal TextRow(SettingsPage page, ConfigEntry<string> entry, string label, string? description, string? emptyText) : base(page, label, description) { Entry = entry; EmptyText = emptyText ?? string.Empty; } public new TextRow RestartRequired() { base.RestartRequired(); return this; } public new TextRow RestartNotRequired() { base.RestartNotRequired(); return this; } } public sealed class LabelRow : SettingRow { internal LabelRow(SettingsPage page, string text, string? description) : base(page, text, description) { } } public sealed class ButtonRow : SettingRow { internal string ButtonText { get; } internal Action OnClick { get; } internal ButtonRow(SettingsPage page, string label, string buttonText, Action onClick, string? description) : base(page, label, description) { ButtonText = buttonText; OnClick = onClick; } } internal sealed class SubPageRow : SettingRow { internal SettingsPage Target { get; } internal SubPageRow(SettingsPage page, SettingsPage target) : base(page, target.Title, target.Description) { Target = target; } } public class SettingsPage { private readonly List<SettingRow> _rows = new List<SettingRow>(); public string Title { get; } public string? Description { get; } internal ModPage Mod => OwnerMod ?? ((ModPage)this); internal SettingsPage? Parent { get; } internal IReadOnlyList<SettingRow> Rows => _rows; private ModPage? OwnerMod { get; } private protected SettingsPage(string title, string? description) { Title = title; Description = description; } private SettingsPage(ModPage mod, SettingsPage parent, string title, string? description) : this(title, description) { OwnerMod = mod; Parent = parent; } public SettingsPage AddSubPage(string title, string? description = null) { RequireText(title, "title"); SettingsPage settingsPage = new SettingsPage(Mod, this, title, description); Add(new SubPageRow(this, settingsPage)); return settingsPage; } public HeaderRow AddHeader(string text) { RequireText(text, "text"); return Add(new HeaderRow(this, text)); } public ToggleRow AddToggle(ConfigEntry<bool> entry, string label, string? description = null) { return Add(new ToggleRow(this, Require<bool>(entry), label, description)); } public DropdownRow AddDropdown<TEnum>(ConfigEntry<TEnum> entry, string label, Func<TEnum, string>? format = null, string? description = null) where TEnum : struct, Enum { Func<TEnum, string> text = format ?? ((Func<TEnum, string>)((TEnum value) => value.ToString())); return Add(new DropdownRow(this, (ConfigEntryBase)(object)Require<TEnum>(entry), typeof(TEnum), label, description, (object value) => text((TEnum)value))); } public SliderRow AddSlider(ConfigEntry<float> entry, string label, SliderDisplay display = SliderDisplay.Percent, string? description = null) { Require<float>(entry); if (!(((ConfigEntryBase)entry).Description.AcceptableValues is AcceptableValueRange<float> val)) { throw new ArgumentException($"'{((ConfigEntryBase)entry).Definition}' needs an AcceptableValueRange<float> to be shown as a slider.", "entry"); } return Add(new SliderRow(this, (ConfigEntryBase)(object)entry, label, description, val.MinValue, val.MaxValue, 0f, isInteger: false, display)); } public SliderRow AddSlider(ConfigEntry<int> entry, string label, SliderDisplay display = SliderDisplay.Integer, string? description = null) { Require<int>(entry); if (!(((ConfigEntryBase)entry).Description.AcceptableValues is AcceptableValueRange<int> val)) { throw new ArgumentException($"'{((ConfigEntryBase)entry).Definition}' needs an AcceptableValueRange<int> to be shown as a slider.", "entry"); } return Add(new SliderRow(this, (ConfigEntryBase)(object)entry, label, description, val.MinValue, val.MaxValue, 1f, isInteger: true, display)); } public TextRow AddText(ConfigEntry<string> entry, string label, string? emptyText = null, string? description = null) { return Add(new TextRow(this, Require<string>(entry), label, description, emptyText)); } public FilePickerRow AddFilePicker(ConfigEntry<string> entry, string label, string? baseFolder = null, string? description = null) { return Add(new FilePickerRow(this, Require<string>(entry), label, description, baseFolder)); } public ButtonRow AddButton(string label, string buttonText, Action onClick, string? description = null) { return Add(CreateButton(this, label, buttonText, onClick, description)); } public LabelRow AddLabel(string text, string? description = null) { return Add(CreateLabel(this, text, description)); } public ButtonRow AddLink(string label, string buttonText, string url, string? description = null) { return Add(CreateLink(this, label, buttonText, url, description)); } internal static ButtonRow CreateLink(SettingsPage page, string label, string buttonText, string url, string? description) { RequireText(buttonText, "buttonText"); if (!Uri.TryCreate(url, UriKind.Absolute, out Uri result) || (result.Scheme != Uri.UriSchemeHttp && result.Scheme != Uri.UriSchemeHttps)) { throw new ArgumentException("'" + url + "' is not an http:// or https:// address.", "url"); } string target = result.AbsoluteUri; return new ButtonRow(page, label, buttonText, delegate { Application.OpenURL(target); }, description ?? target); } internal static ButtonRow CreateButton(SettingsPage page, string label, string buttonText, Action onClick, string? description) { RequireText(buttonText, "buttonText"); return new ButtonRow(page, label, buttonText, onClick ?? throw new ArgumentNullException("onClick"), description); } internal static LabelRow CreateLabel(SettingsPage page, string text, string? description) { RequireText(text, "text"); return new LabelRow(page, text, description); } private T Add<T>(T row) where T : SettingRow { _rows.Add(row); Registry.OnRowAdded(row); return row; } private static ConfigEntry<T> Require<T>(ConfigEntry<T> entry) { return entry ?? throw new ArgumentNullException("entry"); } private static void RequireText(string text, string name) { if (string.IsNullOrWhiteSpace(text)) { throw new ArgumentException("Text is required.", name); } } } public sealed class ModPage : SettingsPage { public InfoSection Info { get; } public string Guid { get; } internal bool HotReload { get; private set; } internal bool ManagesOwnConfigFile { get; private set; } internal bool SectionsInMenuOrder { get; private set; } internal bool ShowsInfo { get; private set; } = true; internal string? AuthorName { get; private set; } internal ModPage(string guid, string title, string? description) : base(title, description) { Guid = guid; Info = new InfoSection(this); } public ModPage HotReloadSupported(bool supported) { HotReload = supported; return this; } public ModPage ManageConfigFileYourself() { ManagesOwnConfigFile = true; Registry.OnConfigOptOut(this); return this; } public ModPage ConfigSectionsInMenuOrder() { SectionsInMenuOrder = true; return this; } public ModPage ShowInfo(bool show) { ShowsInfo = show; return this; } public ModPage Author(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("The author name can't be empty.", "name"); } AuthorName = name.Trim(); return this; } } internal static class ConfigSync { private sealed class ManagedFile : IDisposable { private readonly ConfigFile _file; private readonly FileSystemWatcher? _watcher; private readonly bool _savedOnSetBefore; private long _fileDirtyAt; private long _saveDueAt; private volatile bool _valuesDirty; private bool _applying; private string? _knownContent; internal string Path { get; } internal bool SavePending => _saveDueAt != 0; internal ManagedFile(ConfigFile file) { _file = file; Path = file.ConfigFilePath; _savedOnSetBefore = file.SaveOnConfigSet; _knownContent = ReadText(); file.SaveOnConfigSet = false; file.SettingChanged += OnSettingChanged; WriteInMenuOrder(); _watcher = Watch(); } private FileSystemWatcher? Watch() { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown FileSystemWatcher fileSystemWatcher = null; try { string directoryName = System.IO.Path.GetDirectoryName(Path); if (string.IsNullOrEmpty(directoryName) || !Directory.Exists(directoryName)) { return null; } fileSystemWatcher = new FileSystemWatcher(directoryName, System.IO.Path.GetFileName(Path)) { NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite) }; fileSystemWatcher.Changed += delegate { MarkFileDirty(); }; fileSystemWatcher.Created += delegate { MarkFileDirty(); }; fileSystemWatcher.Renamed += delegate { MarkFileDirty(); }; fileSystemWatcher.EnableRaisingEvents = true; return fileSystemWatcher; } catch (Exception ex) { fileSystemWatcher?.Dispose(); ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(57, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not watch '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Path); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' for outside edits; it is still saved: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogWarning(val); return null; } } internal void Tick(long now) { if (_valuesDirty) { _valuesDirty = false; _saveDueAt = now + 500; } long num = Interlocked.Read(in _fileDirtyAt); if (num != 0L && now - num >= 300 && !SavePending) { Interlocked.CompareExchange(ref _fileDirtyAt, 0L, num); ReloadIfEditedOutside(now); } if (_saveDueAt != 0L && now >= _saveDueAt) { Save(); } } internal void Save() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown _saveDueAt = 0L; try { _file.Save(); _knownContent = ReadText(); WriteInMenuOrder(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(19, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not save '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Path); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogWarning(val); } } public void Dispose() { if (SavePending) { Save(); } _watcher?.Dispose(); _file.SettingChanged -= OnSettingChanged; _file.SaveOnConfigSet = _savedOnSetBefore; } private void WriteInMenuOrder() { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown if (_knownContent == null) { return; } List<string> list = SectionOrder.ForFile(_file); if (list == null) { return; } string text = SectionOrder.Apply(_knownContent, list); if (text == _knownContent) { return; } try { File.WriteAllText(Path, text, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); _knownContent = text; } catch (Exception ex) { ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(22, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not reorder '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Path); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogDebug(val); } } private void OnSettingChanged(object? sender, SettingChangedEventArgs args) { if (!_applying) { _valuesDirty = true; } } private void ReloadIfEditedOutside(long now) { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Expected O, but got Unknown string text = ReadText(); if (text == null) { if (File.Exists(Path)) { Interlocked.CompareExchange(ref _fileDirtyAt, now, 0L); } } else { if (text == _knownContent) { return; } _knownContent = text; Dictionary<ConfigDefinition, string> dictionary = Parse(text); int num = 0; _applying = true; bool flag = default(bool); try { foreach (ConfigDefinition item in _file.Keys.ToList()) { if (!dictionary.TryGetValue(item, out var value)) { continue; } ConfigEntryBase val = _file[item]; object boxedValue = val.BoxedValue; try { val.SetSerializedValue(value); } catch (Exception ex) { ManualLogSource log = Plugin.Log; BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(34, 4, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<ConfigDefinition>(item); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' in '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(System.IO.Path.GetFileName(Path)); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' has an invalid value '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(value); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("': "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message); } log.LogWarning(val2); continue; } if (!object.Equals(boxedValue, val.BoxedValue)) { num++; } } } finally { _applying = false; } if (num > 0) { ManualLogSource log2 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(48, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(System.IO.Path.GetFileName(Path)); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" was edited outside the game: "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" value(s) applied."); } log2.LogInfo(val3); } } } private static Dictionary<ConfigDefinition, string> Parse(string content) { //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown Dictionary<ConfigDefinition, string> dictionary = new Dictionary<ConfigDefinition, string>(); string text = string.Empty; string[] array = content.Split('\n'); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length == 0 || text2.StartsWith("#", StringComparison.Ordinal)) { continue; } if (text2.StartsWith("[", StringComparison.Ordinal) && text2.EndsWith("]", StringComparison.Ordinal)) { string text3 = text2; text = text3.Substring(1, text3.Length - 1 - 1).Trim(); continue; } int num = text2.IndexOf('='); if (num > 0) { string text4 = text2.Substring(0, num).Trim(); string text3 = text2; int num2 = num + 1; string value = text3.Substring(num2, text3.Length - num2).Trim(); try { dictionary[new ConfigDefinition(text, text4)] = value; } catch (ArgumentException) { } } } return dictionary; } private string? ReadText() { try { using FileStream stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); using StreamReader streamReader = new StreamReader(stream); return streamReader.ReadToEnd(); } catch (Exception ex) when (((ex is IOException || ex is UnauthorizedAccessException) ? 1 : 0) != 0) { return null; } } private void MarkFileDirty() { Interlocked.Exchange(ref _fileDirtyAt, Math.Max(1L, Clock.ElapsedMilliseconds)); } } internal static class SectionOrder { internal static List<string>? ForFile(ConfigFile file) { List<string> list = new List<string>(); foreach (ModPage item in ModOptionsApi.Mods.Where((ModPage mod) => mod.SectionsInMenuOrder)) { foreach (SettingRow item2 in Registry.AllRows(item)) { ConfigEntryBase entry = item2.Entry; if (entry != null && entry.ConfigFile == file && !list.Contains(entry.Definition.Section)) { list.Add(entry.Definition.Section); } } } if (list.Count <= 0) { return null; } return list; } internal static string Apply(string content, List<string> order) { StringBuilder stringBuilder = new StringBuilder(); List<(string, StringBuilder)> list = new List<(string, StringBuilder)>(); int num = 0; while (num < content.Length) { int num2 = content.IndexOf('\n', num); num2 = ((num2 < 0) ? content.Length : (num2 + 1)); int num3 = num; string text = content.Substring(num3, num2 - num3); string text2 = text.Trim(); if (text2.StartsWith("[", StringComparison.Ordinal) && text2.EndsWith("]", StringComparison.Ordinal)) { string text3 = text2; list.Add((text3.Substring(1, text3.Length - 1 - 1).Trim(), new StringBuilder())); } StringBuilder stringBuilder2; if (list.Count != 0) { stringBuilder2 = list[list.Count - 1].Item2; } else { stringBuilder2 = stringBuilder; } stringBuilder2.Append(text); num = num2; } if (list.Count < 2) { return content; } StringBuilder stringBuilder3 = new StringBuilder(stringBuilder.ToString()); foreach (var item in list.Select<(string, StringBuilder), ((string, StringBuilder), int)>(((string Section, StringBuilder Text) block, int index) => (block: block, index: index)).OrderBy<((string, StringBuilder), int), int>(delegate(((string Section, StringBuilder Text) block, int index) item) { int num4 = order.IndexOf(item.block.Section); return (num4 < 0) ? (order.Count + item.index) : num4; })) { stringBuilder3.Append(item.Item1.Item2); } return stringBuilder3.ToString(); } } private const long DebounceMilliseconds = 300L; private const long SaveDelayMilliseconds = 500L; private static readonly Stopwatch Clock = Stopwatch.StartNew(); private static readonly Dictionary<ConfigFile, ManagedFile> Managed = new Dictionary<ConfigFile, ManagedFile>(); private static readonly HashSet<ConfigFile> Observed = new HashSet<ConfigFile>(); private static ManagedFile[] _ticking = Array.Empty<ManagedFile>(); private static volatile bool _valuesChanged; private static readonly object ChangeLock = new object(); private static HashSet<ConfigEntryBase> _pendingChanges = new HashSet<ConfigEntryBase>(); private static HashSet<ConfigEntryBase> _raisedChanges = new HashSet<ConfigEntryBase>(); private static bool _everythingChanged; internal static event Action<HashSet<ConfigEntryBase>?>? Changed; internal static void Observe(ConfigFile file) { if (Observed.Add(file)) { file.SettingChanged += delegate(object? _, SettingChangedEventArgs args) { MarkChanged(args.ChangedSetting); }; file.ConfigReloaded += delegate { MarkChanged(null); }; } } private static void MarkChanged(ConfigEntryBase? entry) { lock (ChangeLock) { if (entry == null) { _everythingChanged = true; } else { _pendingChanges.Add(entry); } } _valuesChanged = true; } internal static void Manage(ConfigFile file) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown if (Managed.ContainsKey(file)) { return; } try { Managed[file] = new ManagedFile(file); _ticking = Managed.Values.ToArray(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(21, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not manage '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(file.ConfigFilePath); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogWarning(val); } } internal static void Release(ConfigFile file) { if (Managed.Remove(file, out ManagedFile value)) { _ticking = Managed.Values.ToArray(); value.Dispose(); } } internal static void Tick() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown long elapsedMilliseconds = Clock.ElapsedMilliseconds; ManagedFile[] ticking = _ticking; bool flag = default(bool); foreach (ManagedFile managedFile in ticking) { try { managedFile.Tick(elapsedMilliseconds); } catch (Exception ex) { ManualLogSource log = Plugin.Log; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(31, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Config handling for '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(managedFile.Path); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogWarning(val); } } if (_valuesChanged) { RaiseChanged(); } } private static void RaiseChanged() { _valuesChanged = false; bool everythingChanged; HashSet<ConfigEntryBase> pendingChanges; lock (ChangeLock) { everythingChanged = _everythingChanged; _everythingChanged = false; pendingChanges = _pendingChanges; _pendingChanges = _raisedChanges; _raisedChanges = pendingChanges; } try { if (everythingChanged || pendingChanges.Count > 0) { ConfigSync.Changed?.Invoke(everythingChanged ? null : pendingChanges); } } finally { pendingChanges.Clear(); } } internal static void SaveAll() { ManagedFile[] ticking = _ticking; foreach (ManagedFile managedFile in ticking) { if (managedFile.SavePending) { managedFile.Save(); } } } } internal static class Registry { private static bool _started; private static readonly HashSet<string> WarnedLate = new HashSet<string>(StringComparer.OrdinalIgnoreCase); internal static bool ArchiveGenerated { get; set; } internal static void Start() { _started = true; foreach (ModPage mod in ModOptionsApi.Mods) { foreach (SettingRow item in AllRows(mod)) { Track(item); } } } internal static void OnRegistered(ModPage page) { WarnIfLate(page); } internal static void OnRowAdded(SettingRow row) { WarnIfLate(row.Page.Mod); if (_started) { Track(row); } } internal static void OnConfigOptOut(ModPage page) { if (!_started) { return; } foreach (ConfigFile item in AllRows(page).Select(delegate(SettingRow row) { ConfigEntryBase? entry = row.Entry; return (entry == null) ? null : entry.ConfigFile; }).OfType<ConfigFile>().Distinct()) { ConfigSync.Release(item); } } internal static IEnumerable<SettingRow> AllRows(SettingsPage page) { foreach (SettingRow row in page.Rows) { yield return row; if (!(row is SubPageRow subPageRow)) { continue; } foreach (SettingRow item in AllRows(subPageRow.Target)) { yield return item; } } } private static void Track(SettingRow row) { ConfigEntryBase? entry = row.Entry; ConfigFile val = ((entry != null) ? entry.ConfigFile : null); if (val != null) { ConfigSync.Observe(val); if (!row.Page.Mod.ManagesOwnConfigFile) { ConfigSync.Manage(val); } } } private static void WarnIfLate(ModPage mod) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown if (ArchiveGenerated && WarnedLate.Add(mod.Guid)) { ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(117, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(mod.Title); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' added settings after startup; they show in TheArchive only after a restart. Register them in your plugin's Load()."); } log.LogWarning(val); } } } internal static class InfoBlock { internal const string Title = "INFO"; internal static IEnumerable<string> Lines() { int mods = ModOptionsApi.Mods.Count((ModPage mod) => mod.Guid != "Oxylight.ModOptions"); yield return "ModOptions " + Visuals.Paint("v1.0.0", Visuals.Header) + " by Oxylight"; yield return $"{mods} mod{((mods == 1) ? "" : "s")} registered"; yield return "<color=red>[!]</color> - takes effect after restart"; } internal static IEnumerable<string> Lines(ModPage mod) { string text = mod.Title; string text2 = VersionOf(mod.Guid); if (text2 != null) { text = text + " " + Visuals.Paint("v" + text2, Visuals.Header); } if (mod.AuthorName != null) { text = text + " by " + mod.AuthorName; } yield return text; } internal static IEnumerable<SettingRow> Rows(ModPage mod, bool ownFull) { if (!mod.ShowsInfo) { return Array.Empty<SettingRow>(); } object source; if (mod.Info.ShowsVersionLine) { source = ((ownFull && mod.Guid == "Oxylight.ModOptions") ? Lines() : Lines(mod)); } else { IEnumerable<string> enumerable = Array.Empty<string>(); source = enumerable; } List<SettingRow> list = ((IEnumerable<string>)source).Select((Func<string, SettingRow>)((string line) => new LabelRow(mod, line, null))).Concat(mod.Info.Rows).ToList(); if (list.Count != 0) { return list.Prepend(new HeaderRow(mod, "INFO")); } return list; } private static string? VersionOf(string guid) { if (!((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue(guid, out var value)) { return null; } BepInPlugin metadata = value.Metadata; if (metadata == null) { return null; } return ((object)metadata.Version)?.ToString(); } } [BepInPlugin("Oxylight.ModOptions", "ModOptions", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInProcess("GTFO.exe")] internal sealed class Plugin : BasePlugin { public const string GUID = "Oxylight.ModOptions"; public const string NAME = "ModOptions"; public const string VERSION = "1.0.0"; internal const string ArchiveGuid = "dev.AuriRex.gtfo.TheArchive"; private static Harmony? _harmony; internal static ManualLogSource Log { get; private set; } internal static bool ArchiveMode { get; private set; } internal static bool ArchiveFailed { get; private set; } internal static bool ArchiveInstalled { get; private set; } internal static bool MenuEnabled { get; private set; } internal static ConfigEntry<bool> ArchiveIntegration { get; private set; } internal static ConfigEntry<bool> UppercaseLabels { get; private set; } public override void Load() { //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Expected O, but got Unknown //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Expected O, but got Unknown //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Expected O, but got Unknown //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Expected O, but got Unknown //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Expected O, but got Unknown Log = ((BasePlugin)this).Log; string text = "Show the settings menu for every mod that uses ModOptions: the Mod Options tab, or each mod's entry in TheArchive while TheArchive integration is on.\nOff: no settings menu at all. Mods keep working, and their settings stay in their .cfg files, which still apply when edited while the game runs.\nOnce off, it can only be turned back on in BepInEx/config/Oxylight.ModOptions.cfg. Takes effect after restart."; ConfigEntry<bool> val = ((BasePlugin)this).Config.Bind<bool>("Menu", "Enabled", true, text); MenuEnabled = val.Value; string text2 = "Show mod settings in TheArchive's menu instead of this tab: each mod gets its own entry under Mod Settings > Add-ons. Needs the TheArchive_Core mod."; ConfigEntry<bool> val2 = (ArchiveIntegration = ((BasePlugin)this).Config.Bind<bool>("Integration", "TheArchive", false, text2 + " Takes effect after restart.")); UppercaseLabels = ((BasePlugin)this).Config.Bind<bool>("Display", "Uppercase", true, "Show setting names in capital letters only, like the game's own settings.\nOff: show them the way each mod wrote them.\nHas no effect while TheArchive integration is on."); ArchiveInstalled = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("dev.AuriRex.gtfo.TheArchive"); ArchiveMode = MenuEnabled && val2.Value && ArchiveInstalled; if (MenuEnabled && val2.Value && !ArchiveInstalled) { Log.LogError((object)"TheArchive integration is on, but TheArchive_Core is not installed. Falling back to the Mod Options tab in the game's settings menu."); } ClassInjector.RegisterTypeInIl2Cpp<Driver>(); ClassInjector.RegisterTypeInIl2Cpp<LifecycleHook>(); RegisterTypeOptions val4 = new RegisterTypeOptions(); val4.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(new Type[1] { typeof(iStringInputReceiver) })); ClassInjector.RegisterTypeInIl2Cpp<StringInputReceiver>(val4); val4 = new RegisterTypeOptions(); val4.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(new Type[1] { typeof(iFloatInputReceiver) })); ClassInjector.RegisterTypeInIl2Cpp<FloatInputReceiver>(val4); val4 = new RegisterTypeOptions(); val4.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(new Type[1] { typeof(iCellMenuCursorInputAnywhereItem) })); ClassInjector.RegisterTypeInIl2Cpp<ClickAwayListener>(val4); val4 = new RegisterTypeOptions(); val4.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(new Type[1] { typeof(iCellMenuPopupController) })); ClassInjector.RegisterTypeInIl2Cpp<PopupController>(val4); ((BasePlugin)this).AddComponent<Driver>(); ModPage modPage = ModOptionsApi.Register("Oxylight.ModOptions", "Mod Options", "Where your mod settings appear and how they look.").Author("Oxylight").ConfigSectionsInMenuOrder(); modPage.AddToggle(val, "Show settings menu", text); string text3 = "TheArchive integration"; if (!ArchiveInstalled) { text3 = text3 + " " + Visuals.Paint("(not installed)", Visuals.Warning); text2 += "\nTheArchive_Core is not installed, so this setting does nothing."; } modPage.AddToggle(val2, text3, text2); modPage.AddToggle(UppercaseLabels, "Uppercase letters").RestartNotRequired(); _harmony = new Harmony("Oxylight.ModOptions"); bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val5; if (!MenuEnabled) { ManualLogSource log = Log; val5 = new BepInExInfoLogInterpolatedStringHandler(107, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Settings menu turned off ([Menu] Enabled = false in "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>("Oxylight.ModOptions"); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(".cfg): no Mod Options tab, nothing added to TheArchive."); } log.LogInfo(val5); } else { _harmony.PatchAll(typeof(TextCommit)); if (ArchiveMode) { Log.LogInfo((object)"TheArchive integration on: each mod's settings go to its own entry in Mod Settings > Add-ons."); } else { _harmony.PatchAll(typeof(VanillaMenu)); } } ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Finished += OnAllPluginsLoaded; ManualLogSource log2 = Log; val5 = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>("ModOptions"); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>("1.0.0"); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" loaded."); } log2.LogInfo(val5); } public override bool Unload() { ConfigSync.SaveAll(); Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } return ((BasePlugin)this).Unload(); } private static void OnAllPluginsLoaded() { Registry.Start(); if (ArchiveMode) { StartArchive(); } } [MethodImpl(MethodImplOptions.NoInlining)] private static void StartArchive() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown int num = 0; try { num = ArchiveBridge.Generate(); } catch (Exception ex) { ManualLogSource log = Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(42, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not add the settings to TheArchive: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } if (num == 0) { FallBackToVanillaMenu(); } } private static void FallBackToVanillaMenu() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown ArchiveMode = false; ArchiveFailed = true; Log.LogError((object)"No mod could be added to TheArchive's menu. Falling back to the Mod Options tab in the game's settings menu."); try { Harmony? harmony = _harmony; if (harmony != null) { harmony.PatchAll(typeof(VanillaMenu)); } } catch (Exception ex) { ManualLogSource log = Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(42, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not add the Mod Options tab either: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } } } internal static class FileDialog { [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] private struct OpenFileName { public int lStructSize; public IntPtr hwndOwner; public IntPtr hInstance; public IntPtr lpstrFilter; public IntPtr lpstrCustomFilter; public int nMaxCustFilter; public int nFilterIndex; public IntPtr lpstrFile; public int nMaxFile; public IntPtr lpstrFileTitle; public int nMaxFileTitle; public IntPtr lpstrInitialDir; public IntPtr lpstrTitle; public int Flags; public short nFileOffset; public short nFileExtension; public IntPtr lpstrDefExt; public IntPtr lCustData; public IntPtr lpfnHook; public IntPtr lpTemplateName; public IntPtr pvReserved; public int dwReserved; public int FlagsEx; } private struct Rect { public int Left; public int Top; public int Right; public int Bottom; } private const int MaxPath = 32768; private const int OFN_NOCHANGEDIR = 8; private const int OFN_PATHMUSTEXIST = 2048; private const int OFN_FILEMUSTEXIST = 4096; private const int OFN_EXPLORER = 524288; private const int OFN_DONTADDTORECENT = 33554432; private static int _open; private const int WS_POPUP = int.MinValue; private const int WS_EX_TOPMOST = 8; private const int WS_EX_TOOLWINDOW = 128; internal static bool PickFile(string title, string? initialPath, IReadOnlyList<(string Name, string Patterns)> filters, Action<string> onPicked) { if (!OperatingSystem.IsWindows()) { Plugin.Log.LogWarning((object)"The file picker is only available on Windows."); return false; } if (Interlocked.Exchange(ref _open, 1) != 0) { return false; } string filterText = BuildFilter(filters); IntPtr gameWindow = GetActiveWindow(); Thread thread = new Thread((ThreadStart)delegate { IntPtr intPtr = IntPtr.Zero; try { intPtr = CreateOwnerWindow(gameWindow); while (ShowCursor(show: true) < 0) { } string picked = ShowOpenDialog(intPtr, title, initialPath, filterText); if (picked != null) { MainThread.Post(delegate { onPicked(picked); }); } } catch (Exception ex) { Exception ex2 = ex; Exception exception = ex2; MainThread.Post(delegate { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(20, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("File dialog failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(exception); } log.LogError(val); }); } finally { if (intPtr != IntPtr.Zero) { DestroyWindow(intPtr); } Volatile.Write(ref _open, 0); } }); thread.IsBackground = true; thread.Name = "ModOptions file dialog"; thread.SetApartmentState(ApartmentState.STA); thread.Start(); return true; } private static IntPtr CreateOwnerWindow(IntPtr gameWindow) { int x = 100; int y = 100; if (gameWindow != IntPtr.Zero && GetWindowRect(gameWindow, out var rect)) { x = (rect.Left + rect.Right) / 2 - 300; y = (rect.Top + rect.Bottom) / 2 - 200; } IntPtr intPtr = CreateWindowExW(136, "STATIC", "ModOptions", int.MinValue, x, y, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (intPtr != IntPtr.Zero) { SetForegroundWindow(intPtr); } return intPtr; } private static string BuildFilter(IReadOnlyList<(string Name, string Patterns)> filters) { if (filters.Count == 0) { return "All files (*.*)\0*.*\0\0"; } StringBuilder stringBuilder = new StringBuilder(); foreach (var (value, value2) in filters) { stringBuilder.Append(value).Append(" (").Append(value2) .Append(")\0") .Append(value2) .Append('\0'); } return stringBuilder.Append('\0').ToString(); } private static string? ShowOpenDialog(IntPtr owner, string title, string? initialPath, string filterText) { string text = null; string text2 = string.Empty; if (!string.IsNullOrWhiteSpace(initialPath)) { if (Directory.Exists(initialPath)) { text = initialPath; } else { text = Path.GetDirectoryName(initialPath); if (File.Exists(initialPath)) { text2 = Path.GetFileName(initialPath); } } } IntPtr intPtr = Marshal.AllocHGlobal(65536); IntPtr intPtr2 = Marshal.StringToHGlobalUni(filterText); IntPtr intPtr3 = Marshal.StringToHGlobalUni(title); IntPtr intPtr4 = ((text == null) ? IntPtr.Zero : Marshal.StringToHGlobalUni(text)); try { char[] array = new char[32768]; text2.CopyTo(0, array, 0, Math.Min(text2.Length, 32767)); Marshal.Copy(array, 0, intPtr, 32768); OpenFileName ofn = new OpenFileName { lStructSize = Marshal.SizeOf<OpenFileName>(), hwndOwner = owner, lpstrFilter = intPtr2, nFilterIndex = 1, lpstrFile = intPtr, nMaxFile = 32768, lpstrInitialDir = intPtr4, lpstrTitle = intPtr3, Flags = 34084872 }; if (!GetOpenFileNameW(ref ofn)) { int num = CommDlgExtendedError(); if (num != 0) { throw new InvalidOperationException($"GetOpenFileNameW failed with code 0x{num:X}."); } return null; } return Marshal.PtrToStringUni(intPtr); } finally { Marshal.FreeHGlobal(intPtr); Marshal.FreeHGlobal(intPtr2); Marshal.FreeHGlobal(intPtr3); if (intPtr4 != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr4); } } } [DllImport("comdlg32.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern bool GetOpenFileNameW(ref OpenFileName ofn); [DllImport("comdlg32.dll")] private static extern int CommDlgExtendedError(); [DllImport("user32.dll")] private static extern IntPtr GetActiveWindow(); [DllImport("user32.dll")] private static extern bool GetWindowRect(IntPtr window, out Rect rect); [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern IntPtr CreateWindowExW(int exStyle, string className, string windowName, int style, int x, int y, int width, int height, IntPtr parent, IntPtr menu, IntPtr instance, IntPtr param); [DllImport("user32.dll")] private static extern bool DestroyWindow(IntPtr window); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr window); [DllImport("user32.dll")] private static extern int ShowCursor(bool show); } public static class MainThread { private static readonly ConcurrentQueue<Action> Queue = new ConcurrentQueue<Action>(); public static void Post(Action action) { Queue.Enqueue(action ?? throw new ArgumentNullException("action")); } internal static void Drain() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown if (Queue.IsEmpty) { return; } int num = Queue.Count; Action result; bool flag = default(bool); while (num > 0 && Queue.TryDequeue(out result)) { try { result(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Main thread task failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } num--; } } } internal sealed class Driver : MonoBehaviour { public Driver(IntPtr pointer) : base(pointer) { } private void Update() { MainThread.Drain(); ConfigSync.Tick(); } private void LateUpdate() { SliderControl.SyncStaleLabels(); TextCommit.FollowTyping(); } private void OnApplicationQuit() { ConfigSync.SaveAll(); } } internal static class BuildInfo { public const string Version = "1.0.0"; } } namespace ModOptions.UI { internal sealed class LifecycleHook : MonoBehaviour { internal event Action? Enabled; internal event Action? Disabled; public LifecycleHook(IntPtr pointer) : base(pointer) { } private void OnEnable() { this.Enabled?.Invoke(); } private void OnDisable() { this.Disabled?.Invoke(); } } internal sealed class StringInputReceiver : Object { private readonly Func<string> _get; private readonly Action<string> _set; internal iStringInputReceiver AsReceiver => new iStringInputReceiver(((Il2CppObjectBase)this).Pointer); public StringInputReceiver(IntPtr pointer) : base(pointer) { } internal StringInputReceiver(Func<string> get, Action<string> set) : base(ClassInjector.DerivedConstructorPointer<StringInputReceiver>()) { ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this); _get = get; _set = set; } public string GetStringValue(eCellSettingID setting) { return _get(); } public string SetStringValue(eCellSettingID setting, string value) { _set(value); return _get(); } } internal sealed class FloatInputReceiver : Object { private readonly Func<float> _get; private readonly Action<float> _set; internal iFloatInputReceiver AsReceiver => new iFloatInputReceiver(((Il2CppObjectBase)this).Pointer); public FloatInputReceiver(IntPtr pointer) : base(pointer) { } internal FloatInputReceiver(Func<float> get, Action<float> set) : base(ClassInjector.DerivedConstructorPointer<FloatInputReceiver>()) { ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this); _get = get; _set = set; } public float GetFloatValue(eCellSettingID setting) { return _get(); } public float SetFloatValue(eCellSettingID setting, float value) { _set(value); return _get(); } } internal sealed class ClickAwayListener : Object { internal iCellMenuCursorInputAnywhereItem AsListener => new iCellMenuCursorInputAnywhereItem(((Il2CppObjectBase)this).Pointer); public ClickAwayListener(IntPtr pointer) : base(pointer) { } internal ClickAwayListener() : base(ClassInjector.DerivedConstructorPointer<ClickAwayListener>()) { ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this); } public void OnBtnPressAnywhere(iCellMenuInputHandler inputHandler, List<iCellMenuCursorItem> hoverItems) { TextCommit.OnClickAnywhere(inputHandler, hoverItems); } } internal sealed class PopupController : Object { private readonly Action<bool> _setVisible; internal iCellMenuPopupController AsController => new iCellMenuPopupController(((Il2CppObjectBase)this).Pointer); public PopupController(IntPtr pointer) : base(pointer) { } internal PopupController(Action<bool> setVisible) : base(ClassInjector.DerivedConstructorPointer<PopupController>()) { ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this); _setVisible = setVisible; } public void SetPopupVisible(bool visible) { _setVisible(visible); } } internal sealed class LabelFit { private const float TitleWidth = 970f; private const float UnlimitedHeight = 10000f; private const float VerticalPadding = 8f; private static TextMeshPro? _ruler; private readonly CM_SettingsItem _item; private readonly TextMeshPro _title; private readonly RectTransform? _row; private readonly TextAlignmentOptions _alignment; private readonly bool _autoSize; private readonly float _smallestFontSize; private readonly float _rowHeight; private readonly float _titleHeight; private readonly Vector2 _anchorMin; private readonly Vector2 _anchorMax; private readonly Vector2 _pivot; private readonly Vector2 _anchoredPosition; private readonly float _titleLeftInRow; private readonly Vector2 _backgroundSize; private readonly Vector3 _backgroundPosition; private readonly float _backgroundBelowTop; private readonly BoxCollider2D? _collider; private readonly Vector2 _colliderSize; private readonly Vector2 _colliderOffset; private float _extra; internal LabelFit(CM_SettingsItem item, TextMeshPro title) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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_0090: 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_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) _item = item; _title = title; _row = ((Il2CppObjectBase)((Component)item).transform).TryCast<RectTransform>(); _alignment = ((TMP_Text)title).alignment; _autoSize = ((TMP_Text)title).enableAutoSizing; _smallestFontSize = (_autoSize ? ((TMP_Text)title).fontSizeMin : ((TMP_Text)title).fontSize); RectTransform rectTransform = ((TMP_Text)title).rectTransform; _titleHeight = rectTransform.sizeDelta.y; _anchorMin = rectTransform.anchorMin; _anchorMax = rectTransform.anchorMax; _pivot = rectTransform.pivot; _anchoredPosition = rectTransform.anchoredPosition; RectTransform? row = _row; _rowHeight = ((row != null) ? row.sizeDelta.y : 0f); Rect rect; if ((Object)(object)_row != (Object)null) { RectTransform? row2 = _row; rect = rectTransform.rect; _titleLeftInRow = ((Transform)row2).InverseTransformPoint(((Transform)rectTransform).TransformPoint(new Vector3(((Rect)(ref rect)).xMin, 0f, 0f))).x; } ((TMP_Text)title).enableWordWrapping = true; ((TMP_Text)title).overflowMode = (TextOverflowModes)0; rectTransform.sizeDelta = new Vector2(970f, _titleHeight); if ((Object)(object)item.m_background != (Object)null) { _backgroundSize = item.m_background.size; _backgroundPosition = ((Component)item.m_background).transform.localPosition; Sprite sprite = item.m_background.sprite; if (sprite != null && (Object)(object)sprite != (Object)null) { float y = sprite.pivot.y; rect = sprite.rect; _backgroundBelowTop = 1f - y / ((Rect)(ref rect)).height; } } _collider = ((Component)item).GetComponent<BoxCollider2D>(); if ((Object)(object)_collider != (Object)null) { _colliderSize = _collider.size; _colliderOffset = ((Collider2D)_collider).offset; } } internal bool Apply(string text) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown try { float item = Measure(text, _smallestFontSize).Height; float num = ((item > _titleHeight) ? Mathf.Ceil(item + 16f - _rowHeight) : 0f); RectTransform rectTransform = ((TMP_Text)_title).rectTransform; if (Mathf.Approximately(num, _extra)) { return false; } _extra = num; Resize(rectTransform, num); return true; } catch (Exception ex) { ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(28, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not fit the label '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogWarning(val); return false; } } private void Resize(RectTransform rect, float extra) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_0111: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0183: 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_01a5: Unknown result type (might be due to invalid IL or missing references) bool flag = extra > 0f; if ((Object)(object)_row != (Object)null) { _row.sizeDelta = new Vector2(_row.sizeDelta.x, _rowHeight + extra); } if ((Object)(object)_item.m_background != (Object)null) { _item.m_background.size = new Vector2(_backgroundSize.x, _backgroundSize.y + extra); ((Component)_item.m_background).transform.localPosition = _backgroundPosition + new Vector3(0f, (0f - extra) * _backgroundBelowTop, 0f); } if ((Object)(object)_collider != (Object)null) { _collider.size = new Vector2(_colliderSize.x, _colliderSize.y + extra); ((Collider2D)_collider).offset = new Vector2(_colliderOffset.x, _colliderOffset.y - extra / 2f); } ((TMP_Text)_title).enableAutoSizing = !flag && _autoSize; ((TMP_Text)_title).alignment = (TextAlignmentOptions)(flag ? 257 : ((int)_alignment)); if (flag) { ((TMP_Text)_title).fontSize = _smallestFontSize; PlaceAtRowTop(rect); return; } rect.anchorMin = _anchorMin; rect.anchorMax = _anchorMax; rect.pivot = _pivot; rect.sizeDelta = new Vector2(970f, _titleHeight); rect.anchoredPosition = _anchoredPosition; } private void PlaceAtRowTop(RectTransform rect) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0082: 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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_row == (Object)null)) { Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(0f, 1f); rect.anchorMin = val; rect.anchorMax = val; rect.pivot = val; rect.sizeDelta = new Vector2(970f, _rowHeight + _extra - 16f); RectTransform? row = _row; float titleLeftInRow = _titleLeftInRow; Rect rect2 = _row.rect; Vector3 val2 = ((Transform)row).TransformPoint(new Vector3(titleLeftInRow, ((Rect)(ref rect2)).yMax - 8f, 0f)); ((Transform)rect).position = new Vector3(val2.x, val2.y, ((Transform)rect).position.z); } } private (float Height, int Lines) Measure(string text, float fontSize) { //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013c: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_ruler == (Object)null) { GameObject val = new GameObject("ModOptions.TextRuler") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)val); _ruler = val.AddComponent<TextMeshPro>(); ((TMP_Text)_ruler).enableAutoSizing = false; ((TMP_Text)_ruler).enableWordWrapping = true; ((TMP_Text)_ruler).rectTransform.sizeDelta = new Vector2(970f, 10000f); MeshRenderer component = val.GetComponent<MeshRenderer>(); if (component != null) { ((Renderer)component).enabled = false; } } ((TMP_Text)_ruler).font = ((TMP_Text)_title).font; ((TMP_Text)_ruler).isOrthographic = ((TMP_Text)_title).isOrthographic; ((TMP_Text)_ruler).fontSize = fontSize; ((TMP_Text)_ruler).fontStyle = ((TMP_Text)_title).fontStyle; ((TMP_Text)_ruler).characterSpacing = ((TMP_Text)_title).characterSpacing; ((TMP_Text)_ruler).wordSpacing = ((TMP_Text)_title).wordSpacing; ((TMP_Text)_ruler).lineSpacing = ((TMP_Text)_title).lineSpacing; ((TMP_Text)_ruler).SetText(text, true); ((TMP_Text)_ruler).ForceMeshUpdate(true, false); float y = ((TMP_Text)_ruler).GetPreferredValues(text, 970f, 10000f).y; Bounds textBounds = ((TMP_Text)_ruler).textBounds; return (Height: Mathf.Max(y, ((Bounds)(ref textBounds)).size.y), Lines: ((TMP_Text)_ruler).textInfo.lineCount); } } internal sealed class PageView { private const float ItemPadding = 5f; private readonly List<RowView> _rows = new List<RowView>(); private readonly List<RowView> _built = new List<RowView>(); private readonly PopupController _popupController; private bool _isBuilt; internal CM_PageSettings Host { get; } internal CM_ScrollWindow Window { get; } internal bool IsOpen { get; private set; } internal PageView(CM_PageSettings host, CM_ScrollWindow window) { Host = host; Window = window; _popupController = new PopupController(delegate(bool visible) { if (!visible) { HidePopup(); } }); } internal void Add(RowView row) { _rows.Add(row); } internal void EnsureBuilt() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown if (_isBuilt) { return; } _isBuilt = true; bool flag = default(bool); foreach (RowView row in _rows) { try { row.Create(this); _built.Add(row); } catch (Exception ex) { ManualLogSource log = Plugin.Log; BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(24, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Settings row '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(row.Label); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); row.Discard(); } } Layout(); Refresh(); } internal void UpdateVisibility() { foreach (RowView item in _built) { if (item.IsVisible != item.Shown) { Layout(); break; } } } private void Layout() { List<iScrollWindowContent> val = new List<iScrollWindowContent>(); foreach (RowView item in _built) { item.Shown = item.IsVisible; item.LayoutStale = false; ((Component)item.Item).transform.SetParent(((Component)Window).transform); ((Component)item.Item).gameObject.SetActive(item.Shown); if (item.Shown) { val.Add(item.Content); } } Window.SetContentItems(val, 5f); } internal void Refresh(HashSet<ConfigEntryBase>? changed = null) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown bool flag = default(bool); foreach (RowView item in _built) { if (changed != null) { ConfigEntryBase entry = item.Entry; if (entry == null || !changed.Contains(entry)) { continue; } } if ((Object)(object)item.Item == (Object)null) { continue; } try { item.Refresh(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(22, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Refreshing '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item.Label); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogDebug(val); } } } internal void ApplyCase() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown bool flag = default(bool); foreach (RowView item in _built) { if ((Object)(object)item.Item == (Object)null) { continue; } try { item.ApplyCase(); } catch (Exception ex) { ManualLogSource log = Plugin.Log; BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(26, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Letter case of '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item.Label); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } log.LogDebug(val); } } if (_built.Exists((RowView row) => row.LayoutStale)) { Layout(); } } internal void OnShown() { IsOpen = true; UpdateVisibility(); Refresh(); } internal void OnHidden() { IsOpen = false; HidePopup(); foreach (RowView item in _built) { if ((Object)(object)item.Item != (Object)null) { item.OnHidden(); } } } internal CM_SettingsItem CreateItem(string label) { CM_SettingsItem obj = Object.Instantiate<GameObject>(Host.m_settingsItemPrefab, ((Component)Window).transform).GetComponent<CM_SettingsItem>() ?? throw new InvalidOperationException("The settings item prefab has no CM_SettingsItem."); ((CM_Item)obj).TextMeshRoot = ((Component)Host).transform; ((CM_Item)obj).SetText(label); return obj; } internal void ShowPopup(GameObject entryPrefab, Transform? anchor, string header, IEnumerable<(string Label, bool Selected, Action OnClick)> entries) { //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) CM_ScrollWindow popupWindow = Host.m_popupWindow; if ((Object)(object)popupWindow == (Object)null) { return; } List<iScrollWindowContent> val = new List<iScrollWindowContent>(); foreach (var entry in entries) { string item = entry.Label; bool item2 = entry.Selected; Action item3 = entry.OnClick; GameObject val2 = Object.Instantiate<GameObject>(entryPrefab, ((Component)popupWindow).transform); CM_Item component = val2.GetComponent<CM_Item>(); if ((Object)(object)component == (Object)null) { Object.Destroy((Object)(object)val2); continue; } ((RectTransformComp)component).Setup(); component.SetText(item2 ? Visuals.Paint(item, Visuals.Choice) : item); Visuals.ApplyCaps(((Component)component).GetComponentInChildren<TextMeshPro>(true)); ((RectTransformComp)component).SetScaleFactor(1f); ((RectTransformComp)component).ForcePopupLayer(true, (GameObject)null); iScrollWindowContent val3 = ((Il2CppObjectBase)component).TryCast<iScrollWindowContent>(); if (val3 != null) { val.Add(val3); } Action action = item3; Visuals.SetClick(component, delegate { action(); HidePopup(); }); } ((CM_PopupOverlay)popupWindow).SetupFromButton(_popupController.AsController, (CM_PageBase)(object)Host); if ((Object)(object)anchor != (Object)null) { ((Component)popupWindow).transform.position = anchor.position; } popupWindow.SetContentItems(val, 5f); popupWindow.SetHeader(header); ((RectTransformComp)popupWindow).SetVisible(true); } internal void HidePopup() { if ((Object)(object)Host.m_popupWindow != (Object)null) { ((RectTransformComp)Host.m_popupWindow).SetVisible(false); } } } internal static class Visuals { internal static readonly Color On = new Color(0.1f, 0.9f, 0.2f); internal static readonly Color Off = new Color(0.95f, 0.15f, 0.1f); internal static readonly Color Accent = new Color(0.1f, 0.75f, 1f); internal static readonly Color Choice = new Color(1f, 0.5f, 0.05f); internal static readonly Color Header = new Color(1f, 0.5f, 0.05f); internal static readonly Color Muted = new Color(0.74f, 0.74f, 0.74f); internal static readonly Color Warning = new Color(1f, 0.3f, 0.15f); private const float MinimumTextAlpha = 0.85f; internal const string RestartMarker = "<color=red>[!]</color> "; internal const string RestartNote = "Takes effect after restart."; internal static bool Uppercase => Plugin.UppercaseLabels.Value; internal static string Paint(string text, Color color) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) return $"<color=#{ColorUtility.ToHtmlStringRGB(color)}>{text}</color>"; } internal static void ApplyCaps(TextMeshPro? text) { //IL_000b: 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_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)text == (Object)null)) { FontStyles val = (FontStyles)(((TMP_Text)text).fontStyle & -57); ((TMP_Text)text).fontStyle = (FontStyles)(Uppercase ? (val | 0x10) : val); } } internal static void SetClick(CM_Item item, Action<int> onClick) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0017: Expected O, but got Unknown if (item.m_onBtnPress == null) { UnityEvent val = new UnityEvent(); UnityEvent val2 = val; item.m_onBtnPress = val; } item.OnBtnPressCallback = Action<int>.op_Implicit(onClick); } internal static void SetItemColor(CM_Item item, Color color) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) foreach (SpriteRenderer componentsInChild in ((Component)item).GetComponentsInChildren<SpriteRenderer>(true)) { componentsInChild.color = new Color(color.r, color.g, color.b, componentsInChild.color.a); } item.m_spriteColorOrg = color; item.m_spriteColorOut = new Color(color.r, color.g, color.b, item.m_spriteAlphaOut); item.m_spriteColorOver = new Color(color.r, color.g, color.b, item.m_spriteAlphaOver); if (item.m_texts != null) { float num = Math.Max(item.m_textAlphaOut, 0.85f); for (int i = 0; i < ((Il2CppArrayBase<TextMeshPro>)(object)item.m_texts).Count; i++) { ((Il2CppArrayBase<Color>)(object)item.m_textColorOrg)[i] = color; ((Il2CppArrayBase<Color>)(object)item.m_textColorOut)[i] = new Color(color.r, color.g, color.b, num); ((Il2CppArrayBase<Color>)(object)item.m_textColorOver)[i] = new Color(color.r, color.g, color.b, item.m_textAlphaOver); } } item.OnHoverOut(); } } internal abstract class RowView { private const float ControlWidth = 550f; private const float ControlHeight = 50f; private const float ControlOffsetX = 250f; private const float ControlOffsetY = -25f; internal string Label { get; } internal Func<bool>? ShowWhen { get; init; } internal bool IsVisible => ShowWhen?.Invoke() ?? true; internal bool Shown { get; set; } internal bool LayoutStale { get; set; } internal CM_SettingsItem Item { get; private set; } internal iScrollWindowContent Content { get; private set; } protected PageView Page { get; private set; } internal virtual ConfigEntryBase? Entry => null; protected string TooltipHeader { get; init; } private string? Tooltip { get; } protected virtual string TitleText => Label; protected RowView(string label, string? tooltip, bool needsRestart = false) { Label = (needsRestart ? ("<color=red>[!]</color> " + label) : label); TooltipHeader = label; Tooltip = ((!needsRestart) ? tooltip : (string.IsNullOrEmpty(tooltip) ? "Takes effect after restart." : (MentionsRestart(tooltip) ? tooltip : (tooltip + "\n\nTakes effect after restart.")))); } private static bool MentionsRestart(string text) { if (!text.Contains("after restart", StringComparison.OrdinalIgnoreCase)) { return text.Contains("after a restart", StringComparison.OrdinalIgnoreCase); } return true; } internal static IEnumerable<RowView> For(SettingRow row, Action<SettingsPage> open) { if (!(row is HeaderRow headerRow)) { if (!(row is LabelRow labelRow)) { if (!(row is ToggleRow row2)) { if (!(row is DropdownRow row3)) { if (!(row is SliderRow row4)) { if (!(row is TextRow textRow)) { if (!(row is FilePickerRow picker)) { if (!(row is ButtonRow buttonRow)) { SubPageRow subPageRow = row as SubPageRow; if (subPageRow != null) { yield return new ButtonView(subPageRow.Label, "Open >", delegate { open(subPageRow.Target); }, subPageRow.Tooltip); } } else { yield return new ButtonView(buttonRow.Label, buttonRow.ButtonText, buttonRow.OnClick, buttonRow.Tooltip); } } else { yield return new TextView(picker.Label, picker.Tooltip, picker.NeedsRestart, picker.Entry, string.Empty); yield return new ButtonView(string.Empty, "Browse...", picker.Browse, "Pick a file on your computer."); } } else { yield return new TextView(textRow.Label, textRow.Tooltip, textRow.NeedsRestart, textRow.Entry, textRow.EmptyText); } } else { yield return new SliderView(row4); } } else { yield return new DropdownView(row3); } } else { yield return new ToggleView(row2); } } else { yield return new NoteView(labelRow.Label, labelRow.Tooltip); } } else { yield return new HeaderView(headerRow.Label); } } internal void Discard() { if ((Object)(object)Item != (Object)null) { Object.Destroy((Object)(object)((Component)Item).gameObject); } Item = null; Content = null; } internal void Create(PageView page) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown Page = page; Item = page.CreateItem(Label); Content = ((Il2CppObjectBase)Item).TryCast<iScrollWindowContent>() ?? throw new InvalidOperationException("The settings item is not scroll window content."); Build(Item); ApplyCase(); if (!string.IsNullOrEmpty(Tooltip)) { ((CM_Item)Item).TooltipInfo = new TooltipInfo { PositionType = (TooltipPositionType)0, TooltipHeader = TooltipHeader, TooltipText = Tooltip, UseTooptip = true }; } ((RectTransformComp)Item).ForcePopupLayer(true, (GameObject)null); } protected abstract void Build(CM_SettingsItem item); internal void ApplyCase() { //IL_0017: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) TextMeshPro title = Item.m_title; if (!((Object)(object)title == (Object)null)) { FontStyles val = (FontStyles)(((TMP_Text)title).fontStyle & -57); ((TMP_Text)title).fontStyle = (FontStyles)(Visuals.Uppercase ? (val | 0x10) : val); ((TMP_Text)title).SetText(TitleText, true); ApplyControlCase(); } } protected virtual void ApplyControlCase() { } internal virtual void Refresh() { } internal virtual void OnHidden() { } protected static void IgnoreRowClicks(CM_SettingsItem item) { Visuals.SetClick((CM_Item)(object)item, delegate { }); } protected static GameObject SpawnControl(GameObject prefab, Transform parent) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) GameObject obj = Object.Instantiate<GameObject>(prefab, parent, false); obj.transform.localPosition = Vector3.zero; return obj; } protected static (CM_Item Button, TextMeshPro? Label) SpawnButton(CM_SettingsItem item) { GameObject obj = SpawnControl(item.m_toggleInputPrefab, item.m_inputAlign); CM_SettingsToggleButton component = obj.GetComponent<CM_SettingsToggleButton>(); if (component != null) { Object.Destroy((Object)(object)component); } CM_Item val = obj.AddComponent<CM_Item>(); SizeCollider(obj); TextMeshPro componentInChildren = obj.GetComponentInChildren<TextMeshPro>(); if ((Object)(object)componentInChildren != (Object)null) { ((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)4097; } ((RectTransformComp)val).Setup(); return (Button: val, Label: componentInChildren); } protected static void SizeCollider(GameObject control) { //IL_0015: 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) BoxCollider2D component = control.GetComponent<BoxCollider2D>(); if (component != null) { component.size = new Vector2(550f, 50f); ((Collider2D)component).offset = new Vector2(250f, -25f); } } } internal sealed class HeaderView : RowView { private const float HeightFactor = 1.5f; protected override string TitleText => "<b>" + base.Label + "</b>"; internal HeaderView(string label) : base(label, null) { } protected override void Build(CM_SettingsItem item) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)item.m_background != (Object)null) { ((Renderer)item.m_background).enabled = false; } BoxCollider2D component = ((Component)item).GetComponent<BoxCollider2D>(); if (component != null) { ((Behaviour)component).enabled = false; } RectTransform val = ((Il2CppObjectBase)((Component)item).transform).TryCast<RectTransform>(); if (val != null) { val.sizeDelta = new Vector2(val.sizeDelta.x, val.sizeDelta.y * 1.5f); } TextMeshPro title = item.m_title; if (!((Object)(object)title == (Object)null)) { RectTransform rectTransform = ((TMP_Text)title).rectTransform; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = new Vector2(1f, 0.6f); rectTransform.offsetMin = new Vector2(10f, 0f); rectTransform.offsetMax = Vector2.zero; ((TMP_Text)title).alignment = (TextAlignmentOptions)1025; ((TMP_Text)title).fontSizeMax = ((TMP_Text)title).fontSizeMax * 1.5f; ((TMP_Text)title).enableWordWrapping = false; ((Graphic)title).color = Visuals.Header; } } } internal sealed class NoteView : RowView { private readonly bool _hoverable; private LabelFit? _fit; internal NoteView(string label, string? tooltip = null) : base(label, tooltip) { _hoverable = !string.IsNullOrEmpty(tooltip); base.TooltipHeader = string.Empty; } protected override void Build(CM_SettingsItem item) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (_hoverable) { RowView.IgnoreRowClicks(item); } else { BoxCollider2D component = ((Component)item).GetComponent<BoxCollider2D>(); if (component != null) { ((Behaviour)component).enabled = false; } } TextMeshPro title = item.m_title; if (!((Object)(object)title == (Object)null)) { ((Graphic)title).color = Visuals.Muted; _fit = new LabelFit(item, title); } } protected override void ApplyControlCase() { if (_fit != null && _fit.Apply(TitleText)) { base.LayoutStale = true; } } } internal sealed class ToggleView : RowView { private readonly ConfigEntry<bool> _entry; private CM_Item? _button; private TextMeshPro? _text; internal override ConfigEntryBase Entry => (ConfigEntryBase)(object)_entry; internal ToggleView(ToggleRow row) : base(row.Label, row.Tooltip, row.NeedsRestart) { _entry = row.Entry; } protected override void Build(CM_SettingsItem item) { (_button, _text) = RowView.SpawnButton(item); RowView.IgnoreRowClicks(item); Visuals.SetClick(_button, delegate { _entry.Value = !_entry.Value; Refresh(); }); } protect