Decompiled source of Loadout Presets UI Overhaul v1.0.0
LoadoutPresets.dll
Decompiled 6 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.TextCore; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("LoadoutPresets")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("LoadoutPresets")] [assembly: AssemblyTitle("LoadoutPresets")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace LoadoutPresets { internal static class CanvasDump { public static void DumpAll() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); Canvas[] array = Object.FindObjectsOfType<Canvas>(); foreach (Canvas val in array) { if (val.isRootCanvas) { object[] obj = new object[4] { ((Object)val).name, val.renderMode, val.sortingOrder, null }; Scene scene = ((Component)val).gameObject.scene; obj[3] = ((Scene)(ref scene)).name; stringBuilder.AppendLine(string.Format("##### Canvas '{0}' mode={1} order={2} scene={3}", obj)); Walk(((Component)val).transform, 0, stringBuilder); } } string text = Path.Combine(Paths.BepInExRootPath, "ui-dump.txt"); File.WriteAllText(text, stringBuilder.ToString()); Plugin.Log.LogInfo((object)("UI dump written to " + text)); } private static void Walk(Transform t, int depth, StringBuilder sb) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: 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_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Expected O, but got Unknown //IL_0230: Unknown result type (might be due to invalid IL or missing references) if (depth > 9) { return; } sb.Append(new string(' ', depth * 2)).Append(((Object)t).name); if (!((Component)t).gameObject.activeSelf) { sb.Append(" [off]"); } RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null); if (val != null) { object[] array = new object[10]; Rect rect = val.rect; array[0] = ((Rect)(ref rect)).width; rect = val.rect; array[1] = ((Rect)(ref rect)).height; array[2] = val.anchorMin.x; array[3] = val.anchorMin.y; array[4] = val.anchorMax.x; array[5] = val.anchorMax.y; array[6] = val.anchoredPosition.x; array[7] = val.anchoredPosition.y; array[8] = val.pivot.x; array[9] = val.pivot.y; sb.Append(string.Format(" r={0:F0}x{1:F0} a=({2:F2},{3:F2})-({4:F2},{5:F2}) p=({6:F0},{7:F0}) pv=({8:F1},{9:F1})", array)); } sb.Append(" {"); Component[] components = ((Component)t).GetComponents<Component>(); foreach (Component val2 in components) { if ((Object)(object)val2 == (Object)null || val2 is Transform || val2 is CanvasRenderer) { continue; } sb.Append(((object)val2).GetType().Name); TMP_Text val3 = (TMP_Text)(object)((val2 is TMP_Text) ? val2 : null); if (val3 != null) { sb.Append("='" + Short(val3.text) + "'"); } else { Text val4 = (Text)(object)((val2 is Text) ? val2 : null); if (val4 != null) { sb.Append("='" + Short(val4.text) + "'"); } else { Image val5 = (Image)(object)((val2 is Image) ? val2 : null); if (val5 != null) { sb.Append("(" + (((Object)(object)val5.sprite != (Object)null) ? ((Object)val5.sprite).name : "-") + "," + ColorUtility.ToHtmlStringRGBA(((Graphic)val5).color) + ")"); } } } sb.Append(' '); } sb.AppendLine("}"); if (!((Component)t).gameObject.activeInHierarchy && depth > 2) { return; } int num = 0; foreach (Transform item in t) { Transform t2 = item; if (num++ >= 40) { sb.Append(new string(' ', depth * 2 + 2)).AppendLine("…"); break; } Walk(t2, depth + 1, sb); } } private static string Short(string s) { if (string.IsNullOrEmpty(s)) { return ""; } s = s.Replace("\n", "\\n"); if (s.Length <= 40) { return s; } return s.Substring(0, 40) + "…"; } } internal static class Fonts { private class Orig { public TMP_Text tmp; public TMP_FontAsset font; public Material mat; public bool autoSize; public float sizeMin; public float sizeMax; } internal static ConfigEntry<bool> Enabled; private static ConfigEntry<string> FontName; private static ConfigEntry<string> KeepFonts; private static TMP_FontAsset target; private static bool resolved; private static bool warned; private static float nextAttempt; private static HashSet<string> keep = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<int, Orig> Changed = new Dictionary<int, Orig>(); private static readonly Dictionary<Material, Material> MaterialCache = new Dictionary<Material, Material>(); internal static readonly List<LegacyTextMirror> Mirrors = new List<LegacyTextMirror>(); internal static TMP_FontAsset Target { get { //IL_010a: 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) if (resolved) { return target; } if (Time.realtimeSinceStartup < nextAttempt) { return null; } nextAttempt = Time.realtimeSinceStartup + 5f; keep = new HashSet<string>(from s in KeepFonts.Value.Split(',') select s.Trim() into s where s.Length > 0 select s, StringComparer.OrdinalIgnoreCase); string text = FontName.Value.Trim(); target = Pick(Resources.FindObjectsOfTypeAll<TMP_FontAsset>(), text) ?? Pick(Resources.LoadAll<TMP_FontAsset>(""), text); if ((Object)(object)target != (Object)null) { resolved = true; ManualLogSource log = Plugin.Log; string[] obj = new string[5] { "Menu font: ", ((Object)target).name, " (", null, null }; FaceInfo faceInfo = target.faceInfo; obj[3] = ((FaceInfo)(ref faceInfo)).familyName; obj[4] = ")"; log.LogInfo((object)string.Concat(obj)); } else if (!warned && (warned = true)) { Plugin.Log.LogWarning((object)("Font '" + text + "' not found. Loaded fonts: " + string.Join(", ", (from f in Resources.FindObjectsOfTypeAll<TMP_FontAsset>() select ((Object)f).name).Distinct()))); } return target; } } public static void BindConfig(ConfigFile cfg) { Enabled = cfg.Bind<bool>("Fonts", "UnifyFonts", true, "Use one font for all menu text (never Unity's default fonts)."); FontName = cfg.Bind<string>("Fonts", "FontAsset", "regular_comfortable SDF", "TextMeshPro font asset to use everywhere (default is the game's Brass Mono). A family name like 'Brass Mono' also works."); KeepFonts = cfg.Bind<string>("Fonts", "KeepFonts", "Magzetician Regular SDF", "Comma-separated font assets that are never replaced (HUD/MFD fonts)."); } private static TMP_FontAsset Pick(IEnumerable<TMP_FontAsset> fonts, string want) { return fonts.FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && string.Equals(((Object)f).name, want, StringComparison.OrdinalIgnoreCase))) ?? fonts.FirstOrDefault((Func<TMP_FontAsset, bool>)delegate(TMP_FontAsset f) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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) if ((Object)(object)f != (Object)null) { FaceInfo faceInfo = f.faceInfo; if (((FaceInfo)(ref faceInfo)).familyName != null) { faceInfo = f.faceInfo; return ((FaceInfo)(ref faceInfo)).familyName.StartsWith(want, StringComparison.OrdinalIgnoreCase); } } return false; }); } private static bool IsMenuText(Component c) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 if (Theme.StyleWorldSpace.Value) { return true; } Canvas componentInParent = c.GetComponentInParent<Canvas>(); if (!((Object)(object)componentInParent == (Object)null)) { return (int)componentInParent.rootCanvas.renderMode != 2; } return true; } private static Material MaterialFor(Material old) { //IL_0078: 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_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_012c: Unknown result type (might be due to invalid IL or missing references) Material material = ((TMP_Asset)target).material; if ((Object)(object)old == (Object)null) { return material; } if (MaterialCache.TryGetValue(old, out var value) && (Object)(object)value != (Object)null) { return value; } bool num = old.HasProperty(ShaderUtilities.ID_OutlineWidth) && old.GetFloat(ShaderUtilities.ID_OutlineWidth) > 0.001f; bool flag = old.IsKeywordEnabled("UNDERLAY_ON") || old.IsKeywordEnabled("UNDERLAY_INNER"); Material val = material; if (num || flag) { val = new Material(material) { name = ((Object)material).name + " (" + ((Object)old).name + ")", hideFlags = (HideFlags)61 }; string[] array = new string[9] { "_OutlineWidth", "_OutlineColor", "_OutlineSoftness", "_FaceDilate", "_UnderlayColor", "_UnderlayOffsetX", "_UnderlayOffsetY", "_UnderlayDilate", "_UnderlaySoftness" }; foreach (string text in array) { if (old.HasProperty(text) && val.HasProperty(text)) { if (text.EndsWith("Color")) { val.SetColor(text, old.GetColor(text)); } else { val.SetFloat(text, old.GetFloat(text)); } } } array = new string[3] { "OUTLINE_ON", "UNDERLAY_ON", "UNDERLAY_INNER" }; foreach (string text2 in array) { if (old.IsKeywordEnabled(text2)) { val.EnableKeyword(text2); } } } MaterialCache[old] = val; return val; } public static void Apply(TMP_Text t) { if ((Object)(object)t == (Object)null || !Enabled.Value || t is TextMeshPro || (Object)(object)((Component)t).GetComponent<LegacyTextMirror.Marker>() != (Object)null) { return; } TMP_FontAsset val = Target; uint[] array = default(uint[]); if (!((Object)(object)val == (Object)null) && !((Object)(object)t.font == (Object)(object)val) && !((Object)(object)t.font == (Object)null) && !keep.Contains(((Object)t.font).name) && IsMenuText((Component)(object)t) && (string.IsNullOrEmpty(t.text) || val.HasCharacters(t.text, ref array, true, true))) { int instanceID = ((Object)t).GetInstanceID(); if (!Changed.ContainsKey(instanceID)) { Changed[instanceID] = new Orig { tmp = t, font = t.font, mat = t.fontSharedMaterial, autoSize = t.enableAutoSizing, sizeMin = t.fontSizeMin, sizeMax = t.fontSizeMax }; } Material fontSharedMaterial = t.fontSharedMaterial; t.font = val; t.fontSharedMaterial = MaterialFor(fontSharedMaterial); } } public static void Apply(Text t) { if (!((Object)(object)t == (Object)null) && Enabled.Value && !((Object)(object)Target == (Object)null) && IsMenuText((Component)(object)t) && !((Object)(object)((Component)t).GetComponent<LegacyTextMirror>() != (Object)null)) { Mirrors.Add(LegacyTextMirror.Create(t, target)); } } public static void Refresh() { foreach (Orig value in Changed.Values) { if (!((Object)(object)value.tmp == (Object)null)) { value.tmp.font = value.font; value.tmp.fontSharedMaterial = value.mat; value.tmp.enableAutoSizing = value.autoSize; value.tmp.fontSizeMin = value.sizeMin; value.tmp.fontSizeMax = value.sizeMax; } } Changed.Clear(); foreach (LegacyTextMirror mirror in Mirrors) { if ((Object)(object)mirror != (Object)null) { mirror.Remove(); } } Mirrors.Clear(); MaterialCache.Clear(); resolved = false; warned = false; nextAttempt = 0f; SweepAll(); } public static void SweepAll() { if (Enabled.Value) { TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>(); for (int i = 0; i < array.Length; i++) { Apply((TMP_Text)(object)array[i]); } Text[] array2 = Object.FindObjectsOfType<Text>(); for (int i = 0; i < array2.Length; i++) { Apply(array2[i]); } } } } internal class LegacyTextMirror : MonoBehaviour { internal class Marker : MonoBehaviour { } private Text src; private TextMeshProUGUI dst; private string lastText; private int lastSize; private TextAnchor lastAnchor; private float baseSize; private float fitSize; private float lastWidth = -1f; private Transform group; private bool constrained; private const float SizeScale = 0.9f; private const float MinScale = 0.5f; private static readonly Dictionary<Transform, List<LegacyTextMirror>> Groups = new Dictionary<Transform, List<LegacyTextMirror>>(); private RectTransform fitRect; public static LegacyTextMirror Create(Text src, TMP_FontAsset font) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Invalid comparison between Unknown and I4 //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Invalid comparison between Unknown and I4 //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown LegacyTextMirror legacyTextMirror = ((Component)src).gameObject.AddComponent<LegacyTextMirror>(); legacyTextMirror.src = src; GameObject val = new GameObject("TMP Mirror", new Type[1] { typeof(RectTransform) }) { layer = ((Component)src).gameObject.layer }; val.AddComponent<Marker>(); RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent(((Component)src).transform, false); val2.anchorMin = Vector2.zero; val2.anchorMax = Vector2.one; val2.offsetMin = Vector2.zero; val2.offsetMax = Vector2.zero; val.AddComponent<LayoutElement>().ignoreLayout = true; TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>(); ((TMP_Text)val3).font = font; ((TMP_Text)val3).fontSharedMaterial = ((TMP_Asset)font).material; ((Graphic)val3).raycastTarget = false; ((TMP_Text)val3).richText = src.supportRichText; ((TMP_Text)val3).enableWordWrapping = (int)src.horizontalOverflow == 0; ((TMP_Text)val3).overflowMode = (TextOverflowModes)0; ((TMP_Text)val3).enableAutoSizing = false; legacyTextMirror.dst = val3; Button val4 = ((Component)src).GetComponentInParent<Button>(); if ((Object)(object)val4 != (Object)null && Theme.IsExcluded((Selectable)(object)val4)) { val4 = null; } legacyTextMirror.constrained = (Object)(object)val4 != (Object)null || (int)src.horizontalOverflow == 0; if ((Object)(object)val4 != (Object)null) { legacyTextMirror.fitRect = (RectTransform)((Component)val4).transform; } if ((Object)(object)val4 != (Object)null && (Object)(object)((Component)val4).transform.parent != (Object)null) { legacyTextMirror.group = ((Component)val4).transform.parent; if (!Groups.TryGetValue(legacyTextMirror.group, out var value)) { value = (Groups[legacyTextMirror.group] = new List<LegacyTextMirror>()); } value.Add(legacyTextMirror); } legacyTextMirror.Sync(force: true); return legacyTextMirror; } private void ComputeFit() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: 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) Rect rect = ((RectTransform)(((Object)(object)fitRect != (Object)null) ? ((object)fitRect) : ((object)(RectTransform)((TMP_Text)dst).transform))).rect; float num = (lastWidth = ((Rect)(ref rect)).width); if (!constrained || ((TMP_Text)dst).enableWordWrapping || num <= 1f || string.IsNullOrEmpty(((TMP_Text)dst).text)) { fitSize = baseSize; return; } float num2 = ((((TMP_Text)dst).fontSize > 0f) ? ((TMP_Text)dst).fontSize : baseSize); float num3 = ((TMP_Text)dst).GetPreferredValues(((TMP_Text)dst).text, float.PositiveInfinity, float.PositiveInfinity).x * (baseSize / num2); float num4 = num - 28f; if ((Object)(object)fitRect != (Object)null) { float num5 = ((TMP_Text)dst).transform.lossyScale.x / Mathf.Max(1E-05f, ((Transform)fitRect).lossyScale.x); if (num5 > 0.0001f) { num4 /= num5; } } fitSize = ((num3 <= num4) ? baseSize : Mathf.Max(baseSize * 0.5f, baseSize * num4 / num3)); } private void ApplySize() { float num = fitSize; if ((Object)(object)group != (Object)null && Groups.TryGetValue(group, out var value)) { value.RemoveAll((LegacyTextMirror m) => (Object)(object)m == (Object)null); foreach (LegacyTextMirror item in value) { if (item.fitSize > 0f) { num = Mathf.Min(num, item.fitSize); } } } if (num > 0f && !Mathf.Approximately(((TMP_Text)dst).fontSize, num)) { ((TMP_Text)dst).fontSize = num; } } private void Sync(bool force) { //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Invalid comparison between Unknown and I4 //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Invalid comparison between Unknown and I4 //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Invalid comparison between Unknown and I4 //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Invalid comparison between Unknown and I4 if ((Object)(object)src == (Object)null || (Object)(object)dst == (Object)null) { return; } bool flag = force; if (force || src.text != lastText) { lastText = src.text; ((TMP_Text)dst).text = src.text; flag = true; } if (force || src.fontSize != lastSize) { lastSize = src.fontSize; baseSize = (float)(src.resizeTextForBestFit ? src.resizeTextMaxSize : src.fontSize) * 0.9f; if (force) { ((TMP_Text)dst).fontSize = baseSize; } flag = true; } if (!flag) { Rect rect = ((RectTransform)(((Object)(object)fitRect != (Object)null) ? ((object)fitRect) : ((object)(RectTransform)((TMP_Text)dst).transform))).rect; if (Mathf.Approximately(((Rect)(ref rect)).width, lastWidth)) { goto IL_011b; } } ComputeFit(); goto IL_011b; IL_011b: ApplySize(); if (force || src.alignment != lastAnchor) { lastAnchor = src.alignment; ((TMP_Text)dst).alignment = Map(src.alignment); } ((Graphic)dst).color = ((Graphic)src).color; ((TMP_Text)dst).fontStyle = (FontStyles)(((int)src.fontStyle == 1 || (int)src.fontStyle == 3) ? 1 : 0); if ((int)src.fontStyle == 2 || (int)src.fontStyle == 3) { TextMeshProUGUI obj = dst; ((TMP_Text)obj).fontStyle = (FontStyles)(((TMP_Text)obj).fontStyle | 2); } } private void LateUpdate() { if ((Object)(object)src == (Object)null) { Object.Destroy((Object)(object)this); return; } Sync(force: false); ((Graphic)src).canvasRenderer.SetAlpha(0f); bool flag = ((Behaviour)src).enabled && ((Component)src).gameObject.activeInHierarchy; if (((Component)dst).gameObject.activeSelf != flag) { ((Component)dst).gameObject.SetActive(flag); } } public void Remove() { if ((Object)(object)src != (Object)null) { ((Graphic)src).canvasRenderer.SetAlpha(1f); } if ((Object)(object)dst != (Object)null) { Object.Destroy((Object)(object)((Component)dst).gameObject); } Object.Destroy((Object)(object)this); } private static TextAlignmentOptions Map(TextAnchor a) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected I4, but got Unknown return (TextAlignmentOptions)((int)a switch { 0 => 257, 1 => 258, 2 => 260, 3 => 513, 5 => 516, 6 => 1025, 7 => 1026, 8 => 1028, _ => 514, }); } } [HarmonyPatch] internal static class FontPatches { private static bool swept; [HarmonyPatch(typeof(TextMeshProUGUI), "OnEnable")] [HarmonyPostfix] private static void TmpOnEnable(TextMeshProUGUI __instance) { try { if (!swept) { swept = true; Fonts.SweepAll(); } Fonts.Apply((TMP_Text)(object)__instance); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Font swap failed on " + ((__instance != null) ? ((Object)__instance).name : null) + ": " + ex.Message)); } } [HarmonyPatch(typeof(Text), "OnEnable")] [HarmonyPostfix] private static void TextOnEnable(Text __instance) { try { Fonts.Apply(__instance); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Font swap failed on " + ((__instance != null) ? ((Object)__instance).name : null) + ": " + ex.Message)); } } } internal static class LoadoutAccess { private static readonly FieldRef<LoadoutSelector, List<WeaponSelector>> SelectorsRef = AccessTools.FieldRefAccess<LoadoutSelector, List<WeaponSelector>>("weaponSelectors"); private static readonly FieldRef<LoadoutSelector, Aircraft> AircraftRef = AccessTools.FieldRefAccess<LoadoutSelector, Aircraft>("aircraft"); private static readonly FieldRef<LoadoutSelector, Slider> FuelRef = AccessTools.FieldRefAccess<LoadoutSelector, Slider>("fuelLevel"); private static readonly FieldRef<LoadoutSelector, TMP_Dropdown> LiveryRef = AccessTools.FieldRefAccess<LoadoutSelector, TMP_Dropdown>("liveryDropdown"); private static readonly FieldRef<LoadoutSelector, Transform> BackgroundRef = AccessTools.FieldRefAccess<LoadoutSelector, Transform>("backgroundTransform"); private static readonly FieldInfo DropdownOptionsField = AccessTools.Field(typeof(WeaponSelector), "dropdownOptions"); private static FieldInfo tupleItem2; private static readonly FieldInfo CustomizationField = AccessTools.Field(typeof(GameManager), "aircraftCustomization"); private static readonly FieldRef<WeaponSelector, TMP_Dropdown> SelDropdownRef = AccessTools.FieldRefAccess<WeaponSelector, TMP_Dropdown>("dropdown"); private static readonly FieldRef<WeaponSelector, TMP_Text> SelHeaderRef = AccessTools.FieldRefAccess<WeaponSelector, TMP_Text>("hardpointName"); private static readonly FieldRef<AircraftSelectionMenu, Button> FlyButtonRef = AccessTools.FieldRefAccess<AircraftSelectionMenu, Button>("flyButton"); public static Aircraft GetAircraft(LoadoutSelector ls) { return AircraftRef.Invoke(ls); } public static TMP_Dropdown GetLiveryDropdown(LoadoutSelector ls) { return LiveryRef.Invoke(ls); } public static Slider GetFuelSlider(LoadoutSelector ls) { return FuelRef.Invoke(ls); } public static Transform GetBackground(LoadoutSelector ls) { return BackgroundRef.Invoke(ls); } public static List<WeaponSelector> GetSelectors(LoadoutSelector ls) { return SelectorsRef.Invoke(ls); } public static TMP_Dropdown GetSelectorDropdown(WeaponSelector s) { return SelDropdownRef.Invoke(s); } public static TMP_Text GetSelectorHeader(WeaponSelector s) { return SelHeaderRef.Invoke(s); } public static Button GetFlyButton(AircraftSelectionMenu m) { if (!((Object)(object)m == (Object)null)) { return FlyButtonRef.Invoke(m); } return null; } public static string AircraftKey(AircraftDefinition def) { if ((Object)(object)def == (Object)null) { return null; } if (!string.IsNullOrEmpty(((UnitDefinition)def).jsonKey)) { return ((UnitDefinition)def).jsonKey; } if (!string.IsNullOrEmpty(((UnitDefinition)def).unitName)) { return ((UnitDefinition)def).unitName; } return ((Object)def).name; } public static string AircraftKey(LoadoutSelector ls) { Aircraft val = AircraftRef.Invoke(ls); if (!((Object)(object)val == (Object)null)) { return AircraftKey(val.definition); } return null; } public static bool SessionHasCustomization(AircraftDefinition def) { if ((Object)(object)def == (Object)null || CustomizationField == null) { return false; } if (CustomizationField.GetValue(null) is IDictionary dictionary) { return dictionary.Contains(def); } return false; } private static IEnumerable<WeaponMount> AvailableMounts(WeaponSelector selector) { if (!(DropdownOptionsField?.GetValue(selector) is IList list)) { yield break; } foreach (object item in list) { if (item != null) { if ((object)tupleItem2 == null) { tupleItem2 = item.GetType().GetField("Item2"); } object? obj = tupleItem2?.GetValue(item); WeaponMount val = (WeaponMount)((obj is WeaponMount) ? obj : null); if (val != null && (Object)(object)val != (Object)null) { yield return val; } } } } private static WeaponMount FindAvailable(WeaponSelector selector, string jsonKey) { foreach (WeaponMount item in AvailableMounts(selector)) { if (item.jsonKey == jsonKey) { return item; } } return null; } public static PresetData Capture(LoadoutSelector ls, string name) { PresetData presetData = new PresetData { Name = name, SavedUtc = DateTime.UtcNow }; foreach (WeaponSelector item in SelectorsRef.Invoke(ls)) { WeaponMount val = null; try { val = item.GetValue(); } catch { } presetData.Weapons.Add(((Object)(object)val == (Object)null) ? null : val.jsonKey); } Slider val2 = FuelRef.Invoke(ls); presetData.Fuel = (((Object)(object)val2 != (Object)null) ? val2.value : 1f); TMP_Dropdown val3 = LiveryRef.Invoke(ls); if ((Object)(object)val3 != (Object)null && val3.value >= 0 && val3.value < val3.options.Count) { presetData.Livery = val3.options[val3.value].text; } return presetData; } public static int Apply(LoadoutSelector ls, PresetData p) { List<WeaponSelector> list = SelectorsRef.Invoke(ls); int num = 0; for (int i = 0; i < list.Count; i++) { string text = ((i < p.Weapons.Count) ? p.Weapons[i] : null); WeaponMount val = null; if (!string.IsNullOrEmpty(text)) { val = FindAvailable(list[i], text); if ((Object)(object)val == (Object)null) { num++; } } list[i].SetValue(val); } ls.UpdateWeapons(true); Slider val2 = FuelRef.Invoke(ls); if ((Object)(object)val2 != (Object)null) { val2.SetValueWithoutNotify(Mathf.Clamp(p.Fuel, val2.minValue, val2.maxValue)); ls.ChangeFuelLevel(); } TMP_Dropdown val3 = LiveryRef.Invoke(ls); if ((Object)(object)val3 != (Object)null && !string.IsNullOrEmpty(p.Livery)) { int num2 = val3.options.FindIndex((OptionData o) => o.text == p.Livery); if (num2 >= 0) { val3.SetValueWithoutNotify(num2); val3.RefreshShownValue(); ls.SelectLivery(); } } ls.SaveDefaults(); return num; } } internal static class MainMenuLayout { internal static ConfigEntry<bool> Enabled; private static ConfigEntry<float> PanelWidth; private static ConfigEntry<float> ItemFontSize; private static readonly string[][] Groups = new string[3][] { new string[2] { "SinglePlayerButton", "MultiplayerButton" }, new string[2] { "MissionEditorButton", "WorkshopButton" }, new string[2] { "EncyclopediaButton", "SettingsButton" } }; private const float ItemHeight = 42f; private const float GroupGap = 26f; private const float SidePad = 44f; private const float BottomPad = 40f; public static void BindConfig(ConfigFile cfg) { Enabled = cfg.Bind<bool>("MainMenu", "DcsLayout", true, "Main menu laid out like DCS: right-side panel with grouped items at the bottom right."); PanelWidth = cfg.Bind<float>("MainMenu", "PanelWidth", 470f, "Width of the right-side menu panel (UI units, canvas is 1080 tall)."); ItemFontSize = cfg.Bind<float>("MainMenu", "ItemFontSize", 21f, "Font size of the menu items."); } public static void Apply(MainMenu menu) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_03eb: Unknown result type (might be due to invalid IL or missing references) //IL_0401: Unknown result type (might be due to invalid IL or missing references) //IL_0417: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_0443: Unknown result type (might be due to invalid IL or missing references) //IL_0472: Unknown result type (might be due to invalid IL or missing references) //IL_047c: Expected O, but got Unknown //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_05b6: Unknown result type (might be due to invalid IL or missing references) if (!Enabled.Value || (Object)(object)menu == (Object)null) { return; } Transform transform = ((Component)menu).transform; Transform obj = transform.Find("LeftPanel"); RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)"Main menu layout: LeftPanel not found."); } else { if ((Object)(object)((Transform)val).Find("DcsMenu") != (Object)null) { return; } float value = PanelWidth.Value; val.anchorMin = new Vector2(1f, 0f); val.anchorMax = new Vector2(1f, 1f); val.pivot = new Vector2(1f, 0.5f); val.sizeDelta = new Vector2(value, 0f); val.anchoredPosition = Vector2.zero; Image component = ((Component)val).GetComponent<Image>(); if ((Object)(object)component != (Object)null) { component.sprite = null; ((Graphic)component).color = new Color(0.035f, 0.055f, 0.07f, 0.8f); } RectTransform obj2 = NewRect("Edge", (Transform)(object)val); obj2.anchorMin = new Vector2(0f, 0f); obj2.anchorMax = new Vector2(0f, 1f); obj2.pivot = new Vector2(0f, 0.5f); obj2.sizeDelta = new Vector2(2f, 0f); obj2.anchoredPosition = Vector2.zero; Image obj3 = ((Component)obj2).gameObject.AddComponent<Image>(); ((Graphic)obj3).color = new Color(1f, 1f, 1f, 0.07f); ((Graphic)obj3).raycastTarget = false; Transform val2 = ((Transform)val).Find("Container"); if ((Object)(object)val2 != (Object)null) { Image component2 = ((Component)val2).GetComponent<Image>(); if ((Object)(object)component2 != (Object)null) { ((Behaviour)component2).enabled = false; } } Transform obj4 = transform.Find("NewLogo"); RectTransform val3 = (RectTransform)(object)((obj4 is RectTransform) ? obj4 : null); Vector2 val4 = default(Vector2); if ((Object)(object)val3 != (Object)null) { ((Transform)val3).SetParent((Transform)(object)val, false); float num = (value - 88f) * 0.92f; ((Vector2)(ref val4))..ctor(0.5f, 1f); val3.anchorMax = val4; val3.anchorMin = val4; val3.pivot = new Vector2(0.5f, 1f); val3.sizeDelta = new Vector2(num, num * 0.25f); val3.anchoredPosition = new Vector2(0f, -40f); Image component3 = ((Component)val3).GetComponent<Image>(); if ((Object)(object)component3 != (Object)null) { component3.preserveAspect = true; ((Graphic)component3).color = new Color(1f, 1f, 1f, 0.92f); } } Transform obj5 = ((Transform)val).Find("playerNameInput"); RectTransform val5 = (RectTransform)(object)((obj5 is RectTransform) ? obj5 : null); if ((Object)(object)val5 != (Object)null) { ((Vector2)(ref val4))..ctor(0f, 1f); val5.anchorMax = val4; val5.anchorMin = val4; val5.pivot = new Vector2(0f, 1f); val5.sizeDelta = new Vector2(value - 88f, 44f); val5.anchoredPosition = new Vector2(44f, ((Object)(object)val3 != (Object)null) ? (0f - (40f + (value - 88f) * 0.25f + 28f)) : (-40f)); TMP_InputField component4 = ((Component)val5).GetComponent<TMP_InputField>(); TMP_Text val6 = ((component4 != null) ? component4.textComponent : null); if ((Object)(object)val6 != (Object)null) { val6.alignment = (TextAlignmentOptions)4097; val6.enableAutoSizing = false; val6.fontSize = ItemFontSize.Value; } TMP_InputField component5 = ((Component)val5).GetComponent<TMP_InputField>(); Graphic obj6 = ((component5 != null) ? component5.placeholder : null); TMP_Text val7 = (TMP_Text)(object)((obj6 is TMP_Text) ? obj6 : null); if ((Object)(object)val7 != (Object)null) { val7.alignment = (TextAlignmentOptions)4097; val7.enableAutoSizing = false; val7.fontSize = ItemFontSize.Value; } } RectTransform val8 = NewRect("DcsMenu", (Transform)(object)val); val8.anchorMin = new Vector2(0f, 0f); val8.anchorMax = new Vector2(1f, 0f); val8.pivot = new Vector2(0.5f, 0f); val8.anchoredPosition = new Vector2(0f, 40f); val8.sizeDelta = new Vector2(0f, 0f); VerticalLayoutGroup obj7 = ((Component)val8).gameObject.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)obj7).childAlignment = (TextAnchor)6; ((HorizontalOrVerticalLayoutGroup)obj7).spacing = 0f; ((LayoutGroup)obj7).padding = new RectOffset(16, 16, 0, 0); ((HorizontalOrVerticalLayoutGroup)obj7).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj7).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj7).childForceExpandWidth = true; ((HorizontalOrVerticalLayoutGroup)obj7).childForceExpandHeight = false; ((Component)val8).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2; bool flag = true; string[][] groups = Groups; foreach (string[] obj8 in groups) { bool flag2 = false; string[] array = obj8; foreach (string name in array) { Transform val9 = FindDeep((Transform)(object)val, name); if (!((Object)(object)val9 == (Object)null)) { if (!flag && !flag2) { Spacer(val8, 26f); } AdoptItem(val9, val8); flag2 = true; } } if (flag2) { flag = false; } } Transform val10 = FindDeep((Transform)(object)val, "ExitButton"); if ((Object)(object)val10 != (Object)null) { Spacer(val8, 52f); (((Component)val10).gameObject.GetComponent<ThemeHint>() ?? ((Component)val10).gameObject.AddComponent<ThemeHint>()).accent = Accent.Neutral; AdoptItem(val10, val8); } object obj9 = transform.Find("NewsPanel"); if (obj9 == null) { Transform parent = transform.parent; obj9 = ((parent != null) ? parent.Find("NewsPanel") : null); } RectTransform val11 = (RectTransform)((obj9 is RectTransform) ? obj9 : null); if ((Object)(object)val11 != (Object)null) { val11.anchoredPosition = new Vector2(16f, 16f); } Plugin.Log.LogInfo((object)"Main menu: DCS layout applied."); } } private static void AdoptItem(Transform button, RectTransform list) { //IL_005f: 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_007f: 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_00a8: Unknown result type (might be due to invalid IL or missing references) button.SetParent((Transform)(object)list, false); LayoutElement obj = ((Component)button).GetComponent<LayoutElement>() ?? ((Component)button).gameObject.AddComponent<LayoutElement>(); obj.ignoreLayout = false; obj.minHeight = 42f; obj.preferredHeight = 42f; obj.flexibleHeight = 0f; TMP_Text componentInChildren = ((Component)button).GetComponentInChildren<TMP_Text>(true); if ((Object)(object)componentInChildren != (Object)null) { RectTransform rectTransform = componentInChildren.rectTransform; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.pivot = new Vector2(0f, 0.5f); rectTransform.offsetMin = new Vector2(28f, 0f); rectTransform.offsetMax = new Vector2(-12f, 0f); componentInChildren.alignment = (TextAlignmentOptions)4097; componentInChildren.enableAutoSizing = false; componentInChildren.enableWordWrapping = false; componentInChildren.fontSize = ItemFontSize.Value; componentInChildren.characterSpacing = 2f; } (((Component)button).GetComponent<ThemeHint>() ?? ((Component)button).gameObject.AddComponent<ThemeHint>()).look = ButtonLook.Text; Theme.Restyle(((Component)button).GetComponent<Selectable>()); ((Component)button).GetComponent<ButtonExtras>()?.Rebase(); } private static void Spacer(RectTransform list, float h) { LayoutElement obj = ((Component)NewRect("Gap", (Transform)(object)list)).gameObject.AddComponent<LayoutElement>(); obj.minHeight = h; obj.preferredHeight = h; } private static Transform FindDeep(Transform t, string name) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown if (((Object)t).name == name) { return t; } foreach (Transform item in t) { Transform val = FindDeep(item, name); if ((Object)(object)val != (Object)null) { return val; } } return null; } private static RectTransform NewRect(string name, Transform parent) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }) { layer = ((Component)parent).gameObject.layer }.transform; ((Transform)val).SetParent(parent, false); return val; } } [HarmonyPatch] internal static class MainMenuPatches { [HarmonyPatch(typeof(MainMenu), "Start")] [HarmonyPostfix] private static void StartPostfix(MainMenu __instance) { try { MainMenuLayout.Apply(__instance); } catch (Exception arg) { Plugin.Log.LogError((object)$"Main menu layout failed: {arg}"); } } } internal static class PageLayout { public const float CardPadding = 8f; public const float ControlHeight = 36f; public static void InsetInCard(RectTransform rt) { //IL_000b: 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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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) if ((Object)(object)rt == (Object)null) { return; } bool num = Mathf.Approximately(rt.anchorMin.x, 0f) && Mathf.Approximately(rt.anchorMax.x, 1f); bool flag = Mathf.Approximately(rt.anchorMin.y, 0f) && Mathf.Approximately(rt.anchorMax.y, 0f); if (num) { if (!flag) { rt.offsetMin = new Vector2(8f, rt.offsetMin.y); rt.offsetMax = new Vector2(-8f, rt.offsetMax.y); } else { rt.pivot = new Vector2(0.5f, 0f); rt.sizeDelta = new Vector2(-16f, 36f); rt.anchoredPosition = new Vector2(0f, 8f); } } } } [HarmonyPatch] internal static class Patches { private static bool assigning; [HarmonyPatch(typeof(LoadoutSelector), "AssignAircraft")] [HarmonyPrefix] private static void AssignAircraftPrefix(Aircraft aircraft, out bool __state) { assigning = true; __state = (Object)(object)aircraft != (Object)null && LoadoutAccess.SessionHasCustomization(aircraft.definition); } [HarmonyPatch(typeof(LoadoutSelector), "AssignAircraft")] [HarmonyPostfix] private static void AssignAircraftPostfix(LoadoutSelector __instance, bool __state) { assigning = false; try { PresetBar presetBar = PresetBar.Ensure(__instance); if (!__state && Plugin.RestoreLastLoadout.Value) { PresetData last = Plugin.Store.GetLast(LoadoutAccess.AircraftKey(__instance)); if (last != null) { int num = LoadoutAccess.Apply(__instance, last); presetBar?.ShowStatus((num > 0) ? $"Restored last loadout ({num} unavailable)" : "Restored last loadout"); } } presetBar?.RefreshForAircraft(); } catch (Exception arg) { Plugin.Log.LogError((object)$"AssignAircraft postfix failed: {arg}"); } } [HarmonyPatch(typeof(LoadoutSelector), "ShowHardpoints")] [HarmonyPostfix] private static void ShowHardpointsPostfix(LoadoutSelector __instance) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown if (!Theme.Enabled.Value) { return; } try { foreach (WeaponSelector selector in LoadoutAccess.GetSelectors(__instance)) { TMP_Dropdown selectorDropdown = LoadoutAccess.GetSelectorDropdown(selector); if ((Object)(object)selectorDropdown != (Object)null) { PageLayout.InsetInCard((RectTransform)((Component)selectorDropdown).transform); } } TMP_Dropdown liveryDropdown = LoadoutAccess.GetLiveryDropdown(__instance); if ((Object)(object)liveryDropdown != (Object)null) { PageLayout.InsetInCard((RectTransform)((Component)liveryDropdown).transform); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Card padding failed: " + ex.Message)); } } [HarmonyPatch(typeof(LoadoutSelector), "SaveDefaults")] [HarmonyPostfix] private static void SaveDefaultsPostfix(LoadoutSelector __instance) { RecordLast(__instance); } [HarmonyPatch(typeof(LoadoutSelector), "ChangeFuelLevel")] [HarmonyPostfix] private static void ChangeFuelPostfix(LoadoutSelector __instance) { RecordLast(__instance); } [HarmonyPatch(typeof(LoadoutSelector), "SelectLivery")] [HarmonyPostfix] private static void SelectLiveryPostfix(LoadoutSelector __instance) { RecordLast(__instance); } private static void RecordLast(LoadoutSelector ls) { if (assigning || !Plugin.RestoreLastLoadout.Value) { return; } try { string text = LoadoutAccess.AircraftKey(ls); if (text != null) { Plugin.Store.SetLast(text, LoadoutAccess.Capture(ls, "(last)")); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not record last loadout: " + ex.Message)); } } } [BepInPlugin("vgf.nuclearoption.loadoutpresets", "Loadout Presets & UI Overhaul", "1.0.0")] public class Plugin : BaseUnityPlugin { private class Runner : MonoBehaviour { private float nextCheck; private DateTime lastWrite; private void Start() { try { lastWrite = File.GetLastWriteTimeUtc(((BaseUnityPlugin)Instance).Config.ConfigFilePath); } catch { } } private void Update() { float unscaledTime = Time.unscaledTime; if (Store.Dirty && unscaledTime - Store.DirtySince > 1.5f) { Store.FlushIfDirty(); } if (unscaledTime < nextCheck) { return; } nextCheck = unscaledTime + 1f; try { DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(((BaseUnityPlugin)Instance).Config.ConfigFilePath); if (!(lastWriteTimeUtc == lastWrite)) { lastWrite = lastWriteTimeUtc; int value = DumpUiNow.Value; ((BaseUnityPlugin)Instance).Config.Reload(); if (DumpUiNow.Value != value) { CanvasDump.DumpAll(); WeaponIcons.ExportSheet(Path.Combine(Paths.BepInExRootPath, "weapon-icons.png")); } else { Theme.Refresh(); Fonts.Refresh(); Log.LogInfo((object)"Config reloaded, theme refreshed."); } } } catch (Exception ex) { Log.LogWarning((object)("Config reload failed: " + ex.Message)); } } private void OnApplicationQuit() { Store?.FlushIfDirty(); } } public const string Guid = "vgf.nuclearoption.loadoutpresets"; public const string Name = "Loadout Presets & UI Overhaul"; public const string Version = "1.0.0"; internal static Plugin Instance; internal static ManualLogSource Log; internal static PresetStore Store; internal static ConfigEntry<bool> RestoreLastLoadout; internal static ConfigEntry<float> BarOffsetY; internal static ConfigEntry<float> BarOffsetX; internal static ConfigEntry<float> BarWidth; internal static ConfigEntry<bool> DumpUiHierarchy; internal static ConfigEntry<int> DumpUiNow; private void Awake() { //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; RestoreLastLoadout = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RestoreLastLoadout", true, "Remember the last loadout/fuel/livery used for each aircraft across game restarts."); BarOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "BarOffsetX", 0f, "Horizontal offset (pixels) of the preset bar relative to the loadout panel."); BarOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "BarOffsetY", 6f, "Vertical offset (pixels) of the preset bar above the loadout panel. Negative moves it down."); BarWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "BarWidth", 0f, "Fixed width for the preset bar. 0 = match the loadout panel width."); DumpUiHierarchy = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DumpUiHierarchy", false, "Log the loadout panel UI hierarchy once per session (helps adjust the layout)."); Theme.BindConfig(((BaseUnityPlugin)this).Config); Fonts.BindConfig(((BaseUnityPlugin)this).Config); WeaponIcons.BindConfig(((BaseUnityPlugin)this).Config); MainMenuLayout.BindConfig(((BaseUnityPlugin)this).Config); DumpUiNow = ((BaseUnityPlugin)this).Config.Bind<int>("Debug", "DumpUiNow", 0, "Change this number while the game runs to log the full UI hierarchy of every open canvas."); Theme.RebuildSprites(); Store = new PresetStore(Path.Combine(Paths.ConfigPath, "LoadoutPresets.json")); Store.Load(); new Harmony("vgf.nuclearoption.loadoutpresets").PatchAll(typeof(Plugin).Assembly); GameObject val = new GameObject("LoadoutPresetsRunner"); Object.DontDestroyOnLoad((Object)val); ((Object)val).hideFlags = (HideFlags)61; val.AddComponent<Runner>(); Log.LogInfo((object)("Loadout Presets & UI Overhaul 1.0.0 loaded. Presets file: " + Store.FilePath)); } } internal class PresetBar : MonoBehaviour { private static readonly Dictionary<LoadoutSelector, PresetBar> Bars = new Dictionary<LoadoutSelector, PresetBar>(); private static bool dumpedHierarchy; private const float CardHeight = 80f; private const float RowHeight = 40f; private const string ActionsHeader = "Actions"; private LoadoutSelector selector; private TMP_Dropdown dropdown; private TMP_InputField nameInput; private Button deleteButton; private TMP_Text deleteLabel; private TMP_Text statusHeader; private readonly List<string> shownNames = new List<string>(); private float statusUntil; private float deleteArmedUntil; private string aircraftKey; private string SelectedName { get { if (!((Object)(object)dropdown != (Object)null) || dropdown.value <= 0 || dropdown.value > shownNames.Count) { return null; } return shownNames[dropdown.value - 1]; } } public static PresetBar Ensure(LoadoutSelector ls) { if ((Object)(object)ls == (Object)null) { return null; } if (Bars.TryGetValue(ls, out var value) && (Object)(object)value != (Object)null) { return value; } if (Plugin.DumpUiHierarchy.Value && !dumpedHierarchy) { dumpedHierarchy = true; UiDump.Dump(ls); } try { value = Build(ls); if ((Object)(object)value != (Object)null) { Bars[ls] = value; } return value; } catch (Exception arg) { Plugin.Log.LogError((object)$"Failed to build preset bar: {arg}"); return null; } } private static PresetBar Build(LoadoutSelector ls) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Expected O, but got Unknown //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Expected O, but got Unknown //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Expected O, but got Unknown //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_040f: Expected O, but got Unknown //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_0447: Expected O, but got Unknown //IL_045b: Unknown result type (might be due to invalid IL or missing references) //IL_046c: Expected O, but got Unknown List<WeaponSelector> selectors = LoadoutAccess.GetSelectors(ls); WeaponSelector val = ((selectors != null && selectors.Count > 0) ? selectors[0] : null); TMP_Dropdown val2 = (((Object)(object)val != (Object)null) ? LoadoutAccess.GetSelectorDropdown(val) : LoadoutAccess.GetLiveryDropdown(ls)); TMP_Text headerSample = (((Object)(object)val != (Object)null) ? LoadoutAccess.GetSelectorHeader(val) : null); if ((Object)(object)val2 == (Object)null) { Plugin.Log.LogWarning((object)"No dropdown to copy the style from; preset bar not built."); return null; } GameObject val3 = new GameObject("LoadoutPresetsBar", new Type[1] { typeof(RectTransform) }); val3.SetActive(false); val3.layer = ((Component)ls).gameObject.layer; val3.transform.SetParent(((Component)ls).transform, false); val3.AddComponent<LayoutElement>().ignoreLayout = true; RectTransform val4 = (RectTransform)val3.transform; bool flag = Plugin.BarWidth.Value > 0f; val4.anchorMin = new Vector2(flag ? 0.5f : 0f, 1f); val4.anchorMax = new Vector2(flag ? 0.5f : 1f, 1f); val4.pivot = new Vector2(0.5f, 0f); val4.sizeDelta = new Vector2(flag ? Plugin.BarWidth.Value : 0f, 80f); val4.anchoredPosition = new Vector2(Plugin.BarOffsetX.Value, Plugin.BarOffsetY.Value); Image component = ((Component)ls).GetComponent<Image>(); if ((Object)(object)component != (Object)null) { CopyImage(component, val3.AddComponent<Image>()); } HorizontalLayoutGroup component2 = ((Component)ls).GetComponent<HorizontalLayoutGroup>(); HorizontalLayoutGroup obj = val3.AddComponent<HorizontalLayoutGroup>(); ((LayoutGroup)obj).padding = (((Object)(object)component2 != (Object)null) ? new RectOffset(((LayoutGroup)component2).padding.left, ((LayoutGroup)component2).padding.right, ((LayoutGroup)component2).padding.top, ((LayoutGroup)component2).padding.bottom) : new RectOffset()); ((HorizontalOrVerticalLayoutGroup)obj).spacing = (((Object)(object)component2 != (Object)null) ? ((HorizontalOrVerticalLayoutGroup)component2).spacing : 4f); ((LayoutGroup)obj).childAlignment = (TextAnchor)3; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = true; PresetBar presetBar = val3.AddComponent<PresetBar>(); presetBar.selector = ls; Image style = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Image>() : null); RectTransform val5 = NewCard(val3.transform, "PresetsCard", style, headerSample, "Presets", 2f, 260f); GameObject val6 = Object.Instantiate<GameObject>(((Component)val2).gameObject, (Transform)(object)val5, false); ((Object)val6).name = "PresetDropdown"; Sanitize(val6); val6.AddComponent<ThemeHint>().always = true; presetBar.dropdown = val6.GetComponent<TMP_Dropdown>(); WeaponIcons.StripSlots(presetBar.dropdown); presetBar.dropdown.onValueChanged = new DropdownEvent(); presetBar.dropdown.ClearOptions(); ((Selectable)presetBar.dropdown).interactable = true; ((UnityEvent<int>)(object)presetBar.dropdown.onValueChanged).AddListener((UnityAction<int>)presetBar.OnPresetPicked); object rt = (object)(RectTransform)val6.transform; Transform transform = ((Component)val2).transform; PlaceBottomRow((RectTransform)rt, (RectTransform)(object)((transform is RectTransform) ? transform : null)); if ((Object)(object)presetBar.dropdown.captionText != (Object)null) { ((Graphic)presetBar.dropdown.captionText).color = SampleTextColor(val2); } RectTransform card = NewCard(val3.transform, "NameCard", style, headerSample, "Preset name", 1.5f, 200f); presetBar.nameInput = NewInputField((Transform)(object)card, val2); RectTransform val7 = NewCard(val3.transform, "ActionsCard", style, headerSample, "Actions", 0f, 330f); Transform obj2 = ((Transform)val7).Find("Header"); presetBar.statusHeader = ((obj2 != null) ? ((Component)obj2).GetComponent<TMP_Text>() : null); RectTransform val8 = NewRect("Buttons", (Transform)(object)val7); Transform transform2 = ((Component)val2).transform; PlaceBottomRow(val8, (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null)); HorizontalLayoutGroup obj3 = ((Component)val8).gameObject.AddComponent<HorizontalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)obj3).spacing = 8f; ((LayoutGroup)obj3).padding = new RectOffset(0, 0, 0, 0); ((HorizontalOrVerticalLayoutGroup)obj3).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj3).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = true; ((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = true; NewButton((Transform)(object)val8, val2, "Save", Accent.Positive, new UnityAction(presetBar.OnSave), out var _); presetBar.deleteButton = NewButton((Transform)(object)val8, val2, "Delete", Accent.Danger, new UnityAction(presetBar.OnDelete), out presetBar.deleteLabel); val3.SetActive(true); return presetBar; } private static void Sanitize(GameObject go) { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown MonoBehaviour[] componentsInChildren = go.GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if (!((Object)(object)val == (Object)null)) { string name = ((object)val).GetType().Assembly.GetName().Name; if ((!name.StartsWith("UnityEngine") && !(name == "Unity.TextMeshPro")) || val is ContentSizeFitter || val is AspectRatioFitter) { Object.DestroyImmediate((Object)(object)val); } } } EventTrigger[] componentsInChildren2 = go.GetComponentsInChildren<EventTrigger>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].triggers.Clear(); } Button[] componentsInChildren3 = go.GetComponentsInChildren<Button>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { componentsInChildren3[i].onClick = new ButtonClickedEvent(); } Toggle[] componentsInChildren4 = go.GetComponentsInChildren<Toggle>(true); foreach (Toggle val2 in componentsInChildren4) { if ((Object)(object)((Component)val2).GetComponentInParent<TMP_Dropdown>(true) == (Object)null) { val2.onValueChanged = new ToggleEvent(); } } } private static Button FindButtonByLabel(Transform searchRoot, string contains) { if ((Object)(object)searchRoot == (Object)null) { return null; } Button[] componentsInChildren = ((Component)searchRoot).GetComponentsInChildren<Button>(true); foreach (Button val in componentsInChildren) { TMP_Text componentInChildren = ((Component)val).GetComponentInChildren<TMP_Text>(true); object obj; if (!((Object)(object)componentInChildren != (Object)null)) { Text componentInChildren2 = ((Component)val).GetComponentInChildren<Text>(true); obj = ((componentInChildren2 != null) ? componentInChildren2.text : null); } else { obj = componentInChildren.text; } string text = (string)obj; if (text != null && text.IndexOf(contains, StringComparison.OrdinalIgnoreCase) >= 0) { return val; } } return null; } private static RectTransform NewCard(Transform parent, string name, Image style, TMP_Text headerSample, string title, float flex, float minWidth) { //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0082: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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) RectTransform val = NewRect(name, parent); if ((Object)(object)style != (Object)null) { CopyImage(style, ((Component)val).gameObject.AddComponent<Image>()); } LayoutElement obj = ((Component)val).gameObject.AddComponent<LayoutElement>(); obj.minWidth = minWidth; obj.preferredWidth = minWidth; obj.flexibleWidth = flex; TMP_Text val2; if ((Object)(object)headerSample != (Object)null) { GameObject obj2 = Object.Instantiate<GameObject>(((Component)headerSample).gameObject, (Transform)(object)val, false); Sanitize(obj2); val2 = obj2.GetComponent<TMP_Text>(); RectTransform val3 = (RectTransform)headerSample.transform; RectTransform val4 = (RectTransform)obj2.transform; val4.anchorMin = val3.anchorMin; val4.anchorMax = val3.anchorMax; val4.pivot = val3.pivot; val4.anchoredPosition = val3.anchoredPosition; Rect rect = val3.rect; float num; if (!(((Rect)(ref rect)).height > 0f)) { num = 40f; } else { rect = val3.rect; num = ((Rect)(ref rect)).height; } val4.sizeDelta = new Vector2(0f, num); } else { RectTransform obj3 = NewRect("Header", (Transform)(object)val); obj3.anchorMin = new Vector2(0f, 1f); obj3.anchorMax = new Vector2(1f, 1f); obj3.pivot = new Vector2(0.5f, 1f); obj3.sizeDelta = new Vector2(0f, 40f); val2 = (TMP_Text)(object)((Component)obj3).gameObject.AddComponent<TextMeshProUGUI>(); val2.alignment = (TextAlignmentOptions)514; } ((Object)((Component)val2).gameObject).name = "Header"; val2.text = title; val2.overflowMode = (TextOverflowModes)1; ((Graphic)val2).raycastTarget = false; return val; } private static void PlaceBottomRow(RectTransform rt, RectTransform sample) { //IL_0051: 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_007b: 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_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)sample != (Object)null) { rt.anchorMin = sample.anchorMin; rt.anchorMax = sample.anchorMax; rt.pivot = sample.pivot; rt.anchoredPosition = sample.anchoredPosition; rt.sizeDelta = sample.sizeDelta; } else { rt.anchorMin = new Vector2(0f, 0f); rt.anchorMax = new Vector2(1f, 0f); rt.pivot = new Vector2(0.5f, 0f); rt.anchoredPosition = new Vector2(0f, 5f); rt.sizeDelta = new Vector2(-4f, 40f); } } private static Button NewButton(Transform parent, TMP_Dropdown style, string label, Accent accent, UnityAction onClick, out TMP_Text labelText) { //IL_0020: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) RectTransform val = NewRect(label + "Button", parent); GameObject gameObject = ((Component)val).gameObject; Image val2 = gameObject.AddComponent<Image>(); ((Graphic)val2).color = Color.white; ThemeHint themeHint = gameObject.AddComponent<ThemeHint>(); themeHint.accent = accent; themeHint.always = true; Button val3 = gameObject.AddComponent<Button>(); ((Selectable)val3).targetGraphic = (Graphic)(object)val2; Navigation navigation = default(Navigation); ((Navigation)(ref navigation)).mode = (Mode)0; ((Selectable)val3).navigation = navigation; ((UnityEvent)val3.onClick).AddListener(onClick); TextMeshProUGUI val4 = ((Component)NewRect("Label", (Transform)(object)val)).gameObject.AddComponent<TextMeshProUGUI>(); TMP_Text captionText = style.captionText; if ((Object)(object)captionText != (Object)null) { ((TMP_Text)val4).font = captionText.font; ((TMP_Text)val4).fontSize = captionText.fontSize; ((Graphic)val4).color = ((Graphic)captionText).color; } ((TMP_Text)val4).text = label; ((TMP_Text)val4).alignment = (TextAlignmentOptions)514; ((TMP_Text)val4).enableWordWrapping = false; ((TMP_Text)val4).overflowMode = (TextOverflowModes)0; ((Graphic)val4).raycastTarget = false; Stretch((RectTransform)((TMP_Text)val4).transform, 6f, 0f, 6f); LayoutElement obj = gameObject.AddComponent<LayoutElement>(); obj.minWidth = 120f; obj.preferredWidth = 150f; obj.flexibleWidth = 1f; labelText = (TMP_Text)(object)val4; return val3; } private static TMP_InputField NewInputField(Transform card, TMP_Dropdown style) { //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) RectTransform val = NewRect("PresetName", card); ((Component)val).gameObject.SetActive(false); Transform transform = ((Component)style).transform; PlaceBottomRow(val, (RectTransform)(object)((transform is RectTransform) ? transform : null)); Image val2 = ((Component)val).gameObject.AddComponent<Image>(); Graphic targetGraphic = ((Selectable)style).targetGraphic; Image val3 = (Image)(((object)((targetGraphic is Image) ? targetGraphic : null)) ?? ((object)((Component)style).GetComponent<Image>())); if ((Object)(object)val3 != (Object)null) { CopyImage(val3, val2); } ((Component)val).gameObject.AddComponent<ThemeHint>().always = true; TMP_Text cap = style.captionText; RectTransform area = NewRect("Text Area", (Transform)(object)val); Stretch(area, 14f, 2f, 14f, 2f); ((Component)area).gameObject.AddComponent<RectMask2D>(); Color val4 = SampleTextColor(style); TextMeshProUGUI val5 = MakeText("Placeholder"); ((TMP_Text)val5).text = "Name this loadout…"; ((Graphic)val5).color = new Color(val4.r, val4.g, val4.b, 0.35f); TextMeshProUGUI val6 = MakeText("Text"); ((Graphic)val6).color = val4; TMP_InputField val7 = ((Component)val).gameObject.AddComponent<TMP_InputField>(); ((Selectable)val7).targetGraphic = (Graphic)(object)val2; ((Selectable)val7).colors = ((Selectable)style).colors; ((Selectable)val7).transition = ((Selectable)style).transition; ((Selectable)val7).spriteState = ((Selectable)style).spriteState; val7.textViewport = area; val7.textComponent = (TMP_Text)(object)val6; val7.placeholder = (Graphic)(object)val5; if ((Object)(object)cap != (Object)null) { val7.fontAsset = cap.font; val7.pointSize = cap.fontSize; } val7.characterLimit = 32; val7.lineType = (LineType)0; val7.customCaretColor = true; val7.caretColor = val4; val7.caretWidth = 2; val7.selectionColor = new Color(val4.r, val4.g, val4.b, 0.25f); Navigation navigation = default(Navigation); ((Navigation)(ref navigation)).mode = (Mode)0; ((Selectable)val7).navigation = navigation; ((Component)val).gameObject.SetActive(true); return val7; TextMeshProUGUI MakeText(string name) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown TextMeshProUGUI val8; if ((Object)(object)cap != (Object)null) { GameObject obj = Object.Instantiate<GameObject>(((Component)cap).gameObject, (Transform)(object)area, false); Sanitize(obj); ((Object)obj).name = name; val8 = obj.GetComponent<TextMeshProUGUI>(); } else { val8 = ((Component)NewRect(name, (Transform)(object)area)).gameObject.AddComponent<TextMeshProUGUI>(); } Stretch((RectTransform)((TMP_Text)val8).transform); ((TMP_Text)val8).alignment = (TextAlignmentOptions)4097; ((TMP_Text)val8).enableWordWrapping = false; ((Graphic)val8).raycastTarget = false; ((TMP_Text)val8).text = ""; return val8; } } private static Color SampleTextColor(TMP_Dropdown style) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) Color result = (((Object)(object)style.captionText != (Object)null) ? ((Graphic)style.captionText).color : Color.white); result.a = 1f; return result; } private static void CopyImage(Image src, Image dst) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) dst.sprite = src.sprite; dst.type = src.type; ((Graphic)dst).color = ((Graphic)src).color; ((Graphic)dst).material = ((Graphic)src).material; dst.fillCenter = src.fillCenter; dst.pixelsPerUnitMultiplier = src.pixelsPerUnitMultiplier; dst.preserveAspect = src.preserveAspect; ((Graphic)dst).raycastTarget = true; } private static RectTransform NewRect(string name, Transform parent) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }) { layer = ((Component)parent).gameObject.layer }; val.transform.SetParent(parent, false); return (RectTransform)val.transform; } private static void Stretch(RectTransform rt, float l = 0f, float t = 0f, float r = 0f, float b = 0f) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = new Vector2(l, b); rt.offsetMax = new Vector2(0f - r, 0f - t); } private void Start() { ((UnityEvent<string>)(object)nameInput.onSubmit).AddListener((UnityAction<string>)delegate { OnSave(); }); } public void RefreshForAircraft() { aircraftKey = LoadoutAccess.AircraftKey(selector); RebuildOptions(null); if ((Object)(object)nameInput != (Object)null) { nameInput.SetTextWithoutNotify(""); } } private void RebuildOptions(string select) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown if ((Object)(object)dropdown == (Object)null) { return; } shownNames.Clear(); List<OptionData> list = new List<OptionData>(); List<PresetData> list2 = ((aircraftKey != null) ? Plugin.Store.GetPresets(aircraftKey) : new List<PresetData>()); list.Add(new OptionData((list2.Count == 0) ? "No saved presets" : "Select a preset…")); foreach (PresetData item in list2) { shownNames.Add(item.Name); list.Add(new OptionData(item.Name)); } dropdown.ClearOptions(); dropdown.AddOptions(list); int num = ((select != null) ? (shownNames.FindIndex((string n) => string.Equals(n, select, StringComparison.OrdinalIgnoreCase)) + 1) : 0); dropdown.SetValueWithoutNotify(Mathf.Max(0, num)); dropdown.RefreshShownValue(); UpdateButtons(); } private void OnPresetPicked(int index) { string name = SelectedName; DisarmDelete(); UpdateButtons(); if (name == null || aircraftKey == null) { return; } PresetData presetData = Plugin.Store.GetPresets(aircraftKey).Find((PresetData p) => p.Name == name); if (presetData == null) { return; } try { int num = LoadoutAccess.Apply(selector, presetData); nameInput.SetTextWithoutNotify(name); ShowStatus((num > 0) ? $"Loaded, {num} unavailable here" : "Loaded"); } catch (Exception arg) { Plugin.Log.LogError((object)$"Applying preset '{name}' failed: {arg}"); ShowStatus("Load failed (see log)"); } } private void OnSave() { if (aircraftKey != null) { string name = (nameInput.text ?? "").Trim(); if (name.Length == 0) { name = SelectedName ?? NextDefaultName(); } bool flag = Plugin.Store.GetPresets(aircraftKey).Exists((PresetData p) => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)); Plugin.Store.Upsert(aircraftKey, LoadoutAccess.Capture(selector, name)); RebuildOptions(name); nameInput.SetTextWithoutNotify(name); ShowStatus(flag ? "Updated" : "Saved"); } } private string NextDefaultName() { List<PresetData> presets = Plugin.Store.GetPresets(aircraftKey); int num = 1; string n; while (true) { n = $"Preset {num}"; if (!presets.Exists((PresetData p) => string.Equals(p.Name, n, StringComparison.OrdinalIgnoreCase))) { break; } num++; } return n; } private void OnDelete() { string selectedName = SelectedName; if (selectedName == null) { return; } if (Time.unscaledTime > deleteArmedUntil) { deleteArmedUntil = Time.unscaledTime + 3f; if ((Object)(object)deleteLabel != (Object)null) { deleteLabel.text = "Confirm?"; } } else { DisarmDelete(); Plugin.Store.Delete(aircraftKey, selectedName); RebuildOptions(null); nameInput.SetTextWithoutNotify(""); ShowStatus("Deleted"); } } private void DisarmDelete() { deleteArmedUntil = 0f; if ((Object)(object)deleteLabel != (Object)null) { deleteLabel.text = "Delete"; } } private void UpdateButtons() { if ((Object)(object)deleteButton != (Object)null) { ((Selectable)deleteButton).interactable = SelectedName != null; } } public void ShowStatus(string msg) { if (!((Object)(object)statusHeader == (Object)null)) { statusHeader.text = msg; statusUntil = Time.unscaledTime + 3.5f; } } private void Update() { if (statusUntil > 0f && Time.unscaledTime > statusUntil) { statusUntil = 0f; if ((Object)(object)statusHeader != (Object)null) { statusHeader.text = "Actions"; } } if (deleteArmedUntil > 0f && Time.unscaledTime > deleteArmedUntil) { DisarmDelete(); } if (Plugin.Store.Dirty && Time.unscaledTime - Plugin.Store.DirtySince > 1.5f) { Plugin.Store.FlushIfDirty(); } } private void OnDisable() { Plugin.Store?.FlushIfDirty(); } private void OnDestroy() { if ((Object)(object)selector != (Object)null) { Bars.Remove(selector); } } } internal static class UiDump { public static void Dump(LoadoutSelector ls) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("=== LoadoutPresets UI dump: parent chain ==="); Transform val = ((Component)ls).transform; while ((Object)(object)val != (Object)null) { stringBuilder.AppendLine(" " + Describe(val)); val = val.parent; } AircraftSelectionMenu componentInParent = ((Component)ls).GetComponentInParent<AircraftSelectionMenu>(); if ((Object)(object)componentInParent != (Object)null) { stringBuilder.AppendLine("=== Buttons under AircraftSelectionMenu ==="); Button[] componentsInChildren = ((Component)componentInParent).GetComponentsInChildren<Button>(true); foreach (Button val2 in componentsInChildren) { TMP_Text componentInChildren = ((Component)val2).GetComponentInChildren<TMP_Text>(true); stringBuilder.AppendLine(" " + Describe(((Component)val2).transform) + " label='" + ((componentInChildren != null) ? componentInChildren.text : null) + "'"); } } Plugin.Log.LogInfo((object)stringBuilder.ToString()); } private static string Describe(Transform t) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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) StringBuilder stringBuilder = new StringBuilder(((Object)t).name); if (!((Component)t).gameObject.activeSelf) { stringBuilder.Append(" [inactive]"); } RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null); if (val != null) { Rect rect = val.rect; object arg = ((Rect)(ref rect)).width; rect = val.rect; stringBuilder.Append($" rect={arg:F0}x{((Rect)(ref rect)).height:F0}"); } stringBuilder.Append(" {"); Component[] components = ((Component)t).GetComponents<Component>(); foreach (Component val2 in components) { if (!(val2 is Transform) && (Object)(object)val2 != (Object)null) { stringBuilder.Append(((object)val2).GetType().Name).Append(' '); } } stringBuilder.Append('}'); return stringBuilder.ToString(); } } public class PresetData { public string Name; public List<string> Weapons = new List<string>(); public float Fuel; public string Livery; public DateTime SavedUtc; } public class PresetFile { public int Version = 1; public Dictionary<string, List<PresetData>> Presets = new Dictionary<string, List<PresetData>>(); public Dictionary<string, PresetData> Last = new Dictionary<string, PresetData>(); } public class PresetStore { public readonly string FilePath; private PresetFile data = new PresetFile(); public bool Dirty { get; private set; } public float DirtySince { get; private set; } public PresetStore(string path) { FilePath = path; } public void Load() { try { if (File.Exists(FilePath)) { data = JsonConvert.DeserializeObject<PresetFile>(File.ReadAllText(FilePath)) ?? new PresetFile(); PresetFile presetFile = data; if (presetFile.Presets == null) { presetFile.Presets = new Dictionary<string, List<PresetData>>(); } presetFile = data; if (presetFile.Last == null) { presetFile.Last = new Dictionary<string, PresetData>(); } } } catch (Exception ex) { Plugin.Log.LogError((object)("Failed to read " + FilePath + ", starting empty (old file kept as .bad): " + ex.Message)); try { File.Copy(FilePath, FilePath + ".bad", overwrite: true); } catch { } data = new PresetFile(); } } public void Save() { try { string text = FilePath + ".tmp"; File.WriteAllText(text, JsonConvert.SerializeObject((object)data, (Formatting)1)); if (File.Exists(FilePath)) { File.Replace(text, FilePath, null); } else { File.Move(text, FilePath); } } catch (Exception ex) { Plugin.Log.LogError((object)("Failed to write " + FilePath + ": " + ex.Message)); } } public List<PresetData> GetPresets(string aircraftKey) { if (!data.Presets.TryGetValue(aircraftKey, out var value)) { value = new List<PresetData>(); data.Presets[aircraftKey] = value; } return value; } public void Upsert(string aircraftKey, PresetData preset) { List<PresetData> presets = GetPresets(aircraftKey); int num = presets.FindIndex((PresetData p) => string.Equals(p.Name, preset.Name, StringComparison.OrdinalIgnoreCase)); if (num >= 0) { presets[num] = preset; } else { presets.Add(preset); } presets.Sort((PresetData a, PresetData b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase)); Save(); } public bool Delete(string aircraftKey, string name) { int num = GetPresets(aircraftKey).RemoveAll((PresetData p) => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)); if (num > 0) { Save(); } return num > 0; } public PresetData GetLast(string aircraftKey) { if (!data.Last.TryGetValue(aircraftKey, out var value)) { return null; } return value; } public void SetLast(string aircraftKey, PresetData preset) { data.Last[aircraftKey] = preset; if (!Dirty) { DirtySince = Time.unscaledTime; } Dirty = true; } public void FlushIfDirty() { if (Dirty) { Dirty = false; Save(); } } } public enum Accent { Auto, Neutral, Positive, Danger, Info, Warning } public enum ButtonLook { Default, Text, Boxed } public class ThemeHint : MonoBehaviour { public Accent accent; public ButtonLook look; public bool always; } internal static class Theme { private enum Kind { Button, Field, Item } private class Entry { public Selectable sel; public Kind kind; public Accent accent; public bool forced; public Image img; public Sprite sprite; public Type type; public Color color; public float ppum; public ColorBlock colors; public Transition transition; public TMP_Text label; public Color labelColor; public bool ghost; } internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> StyleWorldSpace; internal static ConfigEntry<bool> PressedEffect; private static ConfigEntry<int> CornerRadius; private static ConfigEntry<int> BorderWidth; private static ConfigEntry<float> Scale; private static ConfigEntry<float> ButtonFill; private static ConfigEntry<float> ButtonFillAlpha; private static ConfigEntry<float> FieldFill; private static ConfigEntry<float> FieldFillAlpha; private static ConfigEntry<float> FieldBorderAlpha; private static ConfigEntry<float> FadeDuration; private static ConfigEntry<string> NeutralHex; private static ConfigEntry<string> PositiveHex; private static ConfigEntry<string> DangerHex; private static ConfigEntry<string> InfoHex; private static ConfigEntry<string> WarningHex; private static ConfigEntry<string> TextHex; private static ConfigEntry<string> ButtonStyle; private static ConfigEntry<float> HoverAlpha; private static readonly Dictionary<int, Entry> Entries = new Dictionary<int, Entry>(); private static readonly Dictionary<int, Entry> ByImage = new Dictionary<int, Entry>(); private static readonly Dictionary<int, Entry> ByLabel = new Dictionary<int, Entry>(); private static Sprite buttonSprite; private static Sprite fieldSprite; private static Sprite panelSprite; private static Sprite itemSprite; private static bool applying; private static readonly string[] ExcludedComponents = new string[1] { "AircraftSelectionButton" }; private static readonly HashSet<int> Polished = new HashSet<int>(); internal const float TextInset = 14f; private const float ArrowSize = 13f; private const float ItemHeight = 30f; private static bool TextButtons => !string.Equals(ButtonStyle.Value, "Boxed", StringComparison.OrdinalIgnoreCase); public static void BindConfig(ConfigFile cfg) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown Enabled = cfg.Bind<bool>("Theme", "Enabled", true, "Restyle all buttons, input fields and dropdowns in the game."); StyleWorldSpace = cfg.Bind<bool>("Theme", "StyleCockpitScreens", false, "Also restyle world-space (cockpit/MFD) controls."); ButtonStyle = cfg.Bind<string>("Theme", "ButtonStyle", "Boxed", new ConfigDescription("Style for buttons outside the main menu. Boxed = filled buttons with a border. Text = no background (just the label, soft highlight on hover). The main menu items are always text-style.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Text", "Boxed" }), Array.Empty<object>())); HoverAlpha = cfg.Bind<float>("Theme", "TextButtonHoverAlpha", 0.14f, "Strength of the hover highlight behind text-style buttons (0-1)."); PressedEffect = cfg.Bind<bool>("Theme", "PressedEffect", false, "Darken buttons while held / keep them tinted after a click. Off = only the hover highlight."); CornerRadius = cfg.Bind<int>("Theme", "CornerRadius", 12, new ConfigDescription("Corner radius in sprite pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 24), Array.Empty<object>())); BorderWidth = cfg.Bind<int>("Theme", "BorderWidth", 3, new ConfigDescription("Border thickness in sprite pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 8), Array.Empty<object>())); Scale = cfg.Bind<float>("Theme", "SpriteScale", 2f, "Sprite pixels per UI unit (higher = thinner border / smaller radius)."); ButtonFill = cfg.Bind<float>("Theme", "ButtonFillBrightness", 0.3f, "Button fill brightness relative to its accent colour (0-1)."); ButtonFillAlpha = cfg.Bind<float>("Theme", "ButtonFillAlpha", 0.92f, "Button fill opacity."); FieldFill = cfg.Bind<float>("Theme", "FieldFillBrightness", 0.1f, "Input/dropdown fill brightness (0-1)."); FieldFillAlpha = cfg.Bind<float>("Theme", "FieldFillAlpha", 0.88f, "Input/dropdown fill opacity."); FieldBorderAlpha = cfg.Bind<float>("Theme", "FieldBorderAlpha", 0.55f, "Input/dropdown border opacity."); FadeDuration = cfg.Bind<float>("Theme", "FadeDuration", 0.08f, "Hover/press transition time in seconds."); NeutralHex = cfg.Bind<string>("Theme", "ColorNeutral", "#AFC3C4", "Accent for neutral/grey controls."); PositiveHex = cfg.Bind<string>("Theme", "ColorPositive", "#5BC46A", "Accent for green controls (fly, buy, confirm...)."); DangerHex = cfg.Bind<string>("Theme", "ColorDanger", "#E0574F", "Accent for red controls (back, delete...)."); InfoHex = cfg.Bind<string>("Theme", "ColorInfo", "#5FA8E8", "Accent for blue controls."); WarningHex = cfg.Bind<string>("Theme", "ColorWarning", "#E8B04B", "Accent for yellow/orange controls."); TextHex = cfg.Bind<string>("Theme", "ColorText", "#E4F1EC", "Text colour used when a label would be unreadable."); } public static void RebuildSprites() { int value = CornerRadius.Value; int value2 = BorderWidth.Value; buttonSprite = MakeSprite("NOTheme_Button", value, value2, ButtonFill.Value, ButtonFillAlpha.Value, 1f, 1f, 0.1f); fieldSprite = MakeSprite("NOTheme_Field", value, value2, FieldFill.Value, FieldFillAlpha.Value, 0.85f, FieldBorderAlpha.Value, 0.03f); panelSprite = MakeSprite("NOTheme_Panel", value, value2, FieldFill.Value * 0.8f, 0.97f, 0.85f, FieldBorderAlpha.Value, 0f); itemSprite = MakeSprite("NOTheme_Item", Mathf.Max(2, value / 2), 0, 1f, 1f, 1f, 1f, 0f); } private static Sprite MakeSprite(string name, int radius, int border, float fillV, float fillA, float borderV, float borderA, float gradient) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Max(32, (radius + border) * 2 + 8); Texture2D val = new Texture2D(num, num, (TextureFormat)4, false) { name = name, wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1, hideFlags = (HideFlags)61 }; Color32[] array = (Color32[])(object)new Color32[num * num]; float num2 = (float)num / 2f; float num3 = num2 - (float)radius; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { float num4 = Mathf.Abs((float)j + 0.5f - num2) - num3; float num5 = Mathf.Abs((float)i + 0.5f - num2) - num3; Vector2 val2 = new Vector2(Mathf.Max(num4, 0f), Mathf.Max(num5, 0f)); float num6 = ((Vector2)(ref val2)).magnitude + Mathf.Min(Mathf.Max(num4, num5), 0f) - (float)radius; float num7 = Mathf.Clamp01(0.5f - num6); float num8 = ((border > 0) ? Mathf.Clamp01((float)border + 0.5f + num6) : 0f); float num9 = (float)i / (float)(num - 1); float num10 = Mathf.Lerp(Mathf.Clamp01(fillV * (1f + gradient * (num9 - 0.5f) * 2f)), borderV, num8); float num11 = Mathf.Lerp(fillA, borderA, num8) * num7; array[i * num + j] = Color32.op_Implicit(new Color(num10, num10, num10, num11)); } } val.SetPixels32(array); val.Apply(false, true); float num12 = radius + border + 1; Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(num12, num12, num12, num12)); ((Object)obj).name = name; ((Object)obj).hideFlags = (HideFlags)61; return obj; } private static Color Hex(ConfigEntry<string> e, Color fallback) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) Color result = default(Color); if (!ColorUtility.TryParseHtmlString(e.Value, ref result)) { return fallback; } return result; } private static Color AccentColor(Accent a) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) return (Color)(a switch { Accent.Positive => Hex(PositiveHex, new Color(0.36f, 0.77f, 0.42f)), Accent.Danger => Hex(DangerHex, new Color(0.88f, 0.34f, 0.31f)), Accent.Info => Hex(InfoHex, new Color(0.37f, 0.66f, 0.91f)), Accent.Warning => Hex(WarningHex, new Color(0.91f, 0.69f, 0.29f)), _ => Hex(NeutralHex, new Color(0.69f, 0.76f, 0.77f)), }); } private static Accent Classify(Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) float num = default(float); float num2 = default(float); float num3 = default(float); Color.RGBToHSV(c, ref num, ref num2, ref num3); if (num2 < 0.28f || num3 < 0.2f) { return Accent.Neutral; } if (num < 0.05f || num > 0.92f) { return Accent.Danger; } if (num < 0.16f) { return Accent.Warning; } if (num < 0.47f) { return Accent.Positive; } if (num < 0.75f) { return Accent.Info; } return Accent.Neutral; } private static float Luma(Color c) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to