Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of TwixTweaks v1.2.1
TwixTweaks.dll
Decompiled 5 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using ComfortAudit; using ComfortAudit.Core; using ComfortAudit.Core.Pure; using ComfortAudit.L10n; using ComfortAudit.Model; using ComfortAudit.Rules; using ComfortAudit.UI; using HarmonyLib; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.TextCore; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("TwixTweaks")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("The Ucross Valheim pack's own tweaks in one mod.")] [assembly: AssemblyFileVersion("1.2.1.0")] [assembly: AssemblyInformationalVersion("1.2.1")] [assembly: AssemblyProduct("TwixTweaks")] [assembly: AssemblyTitle("TwixTweaks")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ComfortAudit { public sealed class ComfortAuditPlugin : MonoBehaviour { public const string PluginName = "TwixTweaks Comfort"; public const string OldTwixComfortGuid = "_twix.TwixComfort"; public const string UpstreamGuid = "com.jumpingmushroom.comfortaudit"; internal static ManualLogSource Log = Logger.CreateLogSource("TwixTweaks Comfort"); private static ConfigFile _config; private readonly ComfortPanel _panel = new ComfortPanel(); private ComfortSnapshot _snapshot = new ComfortSnapshot(); private float _nextScan; private bool _guiReady; private Player _lastPlayer; private bool _hadPlayer; public static bool Active { get; private set; } public static bool Owns(Type type) { if (type != null && type.Namespace != null) { if (!(type.Namespace == "ComfortAudit")) { return type.Namespace.StartsWith("ComfortAudit.", StringComparison.Ordinal); } return true; } return false; } public static void Init(ConfigFile config, GameObject host) { if (Chainloader.PluginInfos.ContainsKey("_twix.TwixComfort")) { Active = false; Log.LogError((object)"TwixComfort is still installed. Its comfort and Rested rules are now part of TwixTweaks (sections 7 and 8), so this copy stays off until TwixComfort is removed."); } else { Active = true; _config = config; host.AddComponent<ComfortAuditPlugin>(); } } private void Awake() { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) PluginConfig.Bind(_config); RulesConfig.Bind(_config); GoodSleep.Bind(_config); Strings.Register(); GoodSleep.Register(); CostTable.Load(); ConsoleCommands.Register(); GUIManager.OnCustomGUIAvailable += OnGuiAvailable; PluginConfig.LayoutChanged += OnLayoutChanged; PluginConfig.ContentChanged += OnContentChanged; Log.LogInfo((object)("Comfort and Good Sleep loaded (comfort panel on " + ((object)PluginConfig.ToggleKey.Value/*cast due to .constrained prefix*/).ToString() + ").")); } private void Start() { if (Chainloader.PluginInfos.ContainsKey("com.jumpingmushroom.comfortaudit")) { Log.LogWarning((object)"ComfortAudit is also installed. TwixTweaks already contains it (with the pack's rules), and the two will fight over comfort and the F7 panel: remove ComfortAudit."); } } private void OnDestroy() { GUIManager.OnCustomGUIAvailable -= OnGuiAvailable; PluginConfig.LayoutChanged -= OnLayoutChanged; PluginConfig.ContentChanged -= OnContentChanged; _panel.Destroy(); } private void OnGuiAvailable() { if (!GUIManager.IsHeadless()) { if ((Object)(object)Player.m_localPlayer == (Object)null) { _panel.SetOpen(open: false); } _panel.Create(); _guiReady = _panel.Created; if (PluginConfig.Verbose.Value) { Log.LogDebug((object)("panel created: " + _guiReady)); } } } private void OnLayoutChanged() { _panel.ApplyLayout(); } private void OnContentChanged() { _panel.InvalidateText(); } private void LocalPlayerGone() { _panel.SetOpen(open: false); ForgetWorld(); } private void LocalPlayerArrived() { ForgetWorld(); LogRestedPrefab(); } private static void LogRestedPrefab() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) SE_Rested val = ComfortRules.Prefab(); if (!((Object)(object)val == (Object)null)) { Log.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "Rested prefab: health regen x{0}, stamina regen x{1}, eitr regen x{2}, skill {3} +{4}, baseTTL {5}s, per comfort {6}s. Rules {7}: {8} per kind, radius {9} m, {10}-{11} min, stamina regen only, +{12:0}% at comfort 1 to +{13:0}% at comfort {14}, rising past it.", ((SE_Stats)val).m_healthRegenMultiplier, ((SE_Stats)val).m_staminaRegenMultiplier, ((SE_Stats)val).m_eitrRegenMultiplier, ((SE_Stats)val).m_raiseSkill, ((SE_Stats)val).m_raiseSkillModifier, val.m_baseTTL, val.m_TTLPerComfortLevel, ComfortRules.Enabled ? "on" : "off", ComfortRules.PiecesPerKind, ComfortRules.Radius, RulesConfig.MinMinutes.Value, RulesConfig.MinutesAtReference.Value, RulesConfig.MinStaminaRegen.Value * 100f, RulesConfig.StaminaRegenAtReference.Value * 100f, RulesConfig.ReferenceComfort.Value)); } } private void ForgetWorld() { _snapshot = new ComfortSnapshot(); SnapshotService.Clear(); _nextScan = 0f; PieceCatalog.Invalidate(); BossTrophies.Invalidate(); Ceiling.Invalidate(); ComfortScanner.ResetHistory(); Diagnostics.Reset(); ContainerStock.Reset(); } private void Update() { //IL_0065: 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) if (!_guiReady) { return; } Player localPlayer = Player.m_localPlayer; bool flag = (Object)(object)localPlayer != (Object)null; bool flag2 = localPlayer == _lastPlayer; if (!flag && _hadPlayer) { LocalPlayerGone(); } else if (flag && (!_hadPlayer || !flag2)) { LocalPlayerArrived(); } _hadPlayer = flag; _lastPlayer = localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } KeyboardShortcut value = PluginConfig.ToggleKey.Value; if (((KeyboardShortcut)(ref value)).IsDown() && !InputBlocked()) { _panel.Toggle(); } if (!_panel.IsOpen) { return; } if (Time.time >= _nextScan) { _nextScan = Time.time + Mathf.Max(0.1f, PluginConfig.ScanInterval.Value); _snapshot = SnapshotService.Get(Mathf.Max(0.1f, PluginConfig.ScanInterval.Value)); Diagnostics.ReportOnce(_snapshot); Diagnostics.ReportEmptyRecommendations(_snapshot); if (PluginConfig.Verbose.Value) { Log.LogDebug((object)$"comfort={_snapshot.ComfortLevel} vanilla={_snapshot.VanillaComfortLevel} shelter={_snapshot.InShelter} cover={_snapshot.CoverPercentage:0.00} pieces={_snapshot.PieceCount}"); } } if (PluginConfig.ShowPlacementPreview.Value) { _panel.SetPreview(PlacementPreview.Compute(localPlayer, _snapshot)); } else { _panel.SetPreview(null); } IconAtlas.EnsureBuilt(); _panel.SetSpriteAsset(PluginConfig.ShowIcons.Value ? IconAtlas.Primary : null); _panel.Render(_snapshot); } private static bool InputBlocked() { if (Console.IsVisible()) { return true; } if (Menu.IsVisible()) { return true; } if (TextInput.IsVisible()) { return true; } if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return true; } return false; } } public enum RecommendationFilter { KnownOnly, KnownAndStationInRange, Buildable } public static class PluginConfig { public static ConfigEntry<KeyboardShortcut> ToggleKey; public static ConfigEntry<Vector2> PanelPosition; public static ConfigEntry<float> PanelWidth; public static ConfigEntry<float> PanelScale; public static ConfigEntry<float> ScanInterval; public static ConfigEntry<bool> ShowDistances; public static ConfigEntry<bool> ShowIcons; public static ConfigEntry<bool> ShowPrefabNames; public static ConfigEntry<bool> Verbose; public static ConfigEntry<RecommendationFilter> Filter; public static ConfigEntry<int> MaxRecommendations; public static ConfigEntry<int> MaxIgnored; public static ConfigEntry<bool> ShowMaterials; public static ConfigEntry<float> ChestRadius; public static ConfigEntry<bool> ShowCeiling; public static ConfigEntry<bool> ShowComfortOnIcon; public static ConfigEntry<bool> ShowPlacementPreview; public static readonly Vector2 DefaultPosition = Vector2.zero; public const float MinScale = 0.5f; public const float MaxScale = 2f; private const string PanelSection = "7 - Comfort Panel"; private const string SuggestSection = "7 - Comfort Suggestions"; public static event Action LayoutChanged; public static event Action ContentChanged; private static ConfigurationManagerAttributes Attr(int order, bool advanced = false) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown return new ConfigurationManagerAttributes { Order = order, IsAdvanced = advanced }; } public static void Bind(ConfigFile cfg) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Expected O, but got Unknown //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Expected O, but got Unknown //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Expected O, but got Unknown //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Expected O, but got Unknown //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Expected O, but got Unknown //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Expected O, but got Unknown //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Expected O, but got Unknown //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Expected O, but got Unknown //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Expected O, but got Unknown //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Expected O, but got Unknown //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_0390: Expected O, but got Unknown //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Expected O, but got Unknown //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Expected O, but got Unknown //IL_041c: Unknown result type (might be due to invalid IL or missing references) //IL_0426: Expected O, but got Unknown ToggleKey = cfg.Bind<KeyboardShortcut>("7 - Comfort Panel", "ToggleKey", new KeyboardShortcut((KeyCode)288, Array.Empty<KeyCode>()), new ConfigDescription("Key that shows and hides the comfort panel.", (AcceptableValueBase)null, new object[1] { Attr(100) })); ScanInterval = cfg.Bind<float>("7 - Comfort Panel", "ScanInterval", 0.5f, new ConfigDescription("Seconds between rescans while the panel is open. The game itself only recomputes comfort every 2 s, so values below that show fresher numbers than the vanilla HUD.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), new object[1] { Attr(90) })); PanelPosition = cfg.Bind<Vector2>("7 - Comfort Panel", "Position", DefaultPosition, new ConfigDescription("Panel offset from the top-left of the screen, in pixels, measured to the panel's top-left corner. (0, 0) means 'centre on screen' and is what the reset button restores. Dragging the panel updates this value. The panel is always kept fully on screen.", (AcceptableValueBase)null, new object[1] { Attr(80) })); PanelWidth = cfg.Bind<float>("7 - Comfort Panel", "Width", 420f, new ConfigDescription("Panel width in pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(280f, 900f), new object[1] { Attr(70) })); PanelScale = cfg.Bind<float>("7 - Comfort Panel", "Scale", 1f, new ConfigDescription("Size of the whole panel, text included. Ctrl + mouse wheel over the panel changes this in game while the cursor is free (inventory open).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 2f), new object[1] { Attr(65) })); cfg.Bind<bool>("7 - Comfort Panel", "ResetPosition", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { Order = 60, HideSettingName = true, HideDefaultButton = true, CustomDrawer = DrawResetButton } })); ShowDistances = cfg.Bind<bool>("7 - Comfort Panel", "ShowDistances", false, new ConfigDescription("Show each piece's distance from you, for checking the comfort radius.", (AcceptableValueBase)null, new object[1] { Attr(50) })); ShowIcons = cfg.Bind<bool>("7 - Comfort Panel", "ShowIcons", true, new ConfigDescription("Show each piece's build-menu icon beside its name in the panel.", (AcceptableValueBase)null, new object[1] { Attr(52) })); ShowPrefabNames = cfg.Bind<bool>("7 - Comfort Panel", "ShowPrefabNames", false, new ConfigDescription("Show prefab names alongside display names. Useful when diagnosing modded pieces.", (AcceptableValueBase)null, new object[1] { Attr(40, advanced: true) })); Filter = cfg.Bind<RecommendationFilter>("7 - Comfort Suggestions", "Filter", RecommendationFilter.KnownAndStationInRange, new ConfigDescription("Which pieces count as available to you. KnownOnly is the broadest. KnownAndStationInRange matches what your hammer would actually let you place here. Buildable additionally requires the materials on hand, which is the most actionable but often empties the list.", (AcceptableValueBase)null, new object[1] { Attr(35) })); MaxRecommendations = cfg.Bind<int>("7 - Comfort Suggestions", "MaxShown", 5, new ConfigDescription("How many suggestions to list.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 15), new object[1] { Attr(30) })); ShowMaterials = cfg.Bind<bool>("7 - Comfort Suggestions", "ShowMaterials", true, new ConfigDescription("List each suggestion's material cost, and whether you have enough.", (AcceptableValueBase)null, new object[1] { Attr(25) })); ChestRadius = cfg.Bind<float>("7 - Comfort Suggestions", "ChestRadius", 20f, new ConfigDescription("Count materials in chests, carts and ships within this many metres when checking what you have. Chests you could not open (warded, or someone else's private chest) are skipped. Vanilla cannot build straight from a chest, so these are shown apart from what you carry. 0 turns this off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), new object[1] { Attr(24) })); ShowCeiling = cfg.Bind<bool>("7 - Comfort Panel", "ShowCeiling", true, new ConfigDescription("Show the highest comfort reachable at a sheltered spot: what you could build today, and what exists once everything is unlocked.", (AcceptableValueBase)null, new object[1] { Attr(45) })); MaxIgnored = cfg.Bind<int>("7 - Comfort Panel", "MaxIgnoredShown", 8, new ConfigDescription("How many ignored pieces to list before collapsing the rest into a count. This is the only list with no natural bound, and it is what made the panel outgrow the screen in a hall full of duplicate chairs.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), new object[1] { Attr(48) })); ShowComfortOnIcon = cfg.Bind<bool>("7 - Comfort Panel", "ShowComfortOnIcon", true, new ConfigDescription("Append current comfort and your ceiling to the Rested icon's label. This is the only always-visible surface: Valheim locks the cursor during play, so a hover tooltip would only be reachable with the inventory or map open.", (AcceptableValueBase)null, new object[1] { Attr(18) })); ShowPlacementPreview = cfg.Bind<bool>("7 - Comfort Panel", "ShowPlacementPreview", true, new ConfigDescription("While building, show what the held piece would add if placed where the ghost is, and what already beats it if the answer is nothing.", (AcceptableValueBase)null, new object[1] { Attr(55) })); Verbose = cfg.Bind<bool>("7 - Comfort Panel", "Verbose", false, new ConfigDescription("Log scan details to the BepInEx log. Off by default; nothing is logged per tick.", (AcceptableValueBase)null, new object[1] { Attr(10, advanced: true) })); PanelPosition.SettingChanged += delegate { Raise(PluginConfig.LayoutChanged); }; PanelWidth.SettingChanged += delegate { Raise(PluginConfig.LayoutChanged); }; PanelScale.SettingChanged += delegate { Raise(PluginConfig.LayoutChanged); }; ShowDistances.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; ShowIcons.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; Filter.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; MaxRecommendations.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; ShowMaterials.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; ChestRadius.SettingChanged += delegate { ContainerStock.Reset(); Raise(PluginConfig.ContentChanged); }; ShowCeiling.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; ShowPlacementPreview.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; ShowPrefabNames.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; MaxIgnored.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; Verbose.SettingChanged += delegate { Raise(PluginConfig.ContentChanged); }; } private static void DrawResetButton(ConfigEntryBase entry) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (GUILayout.Button("Centre panel on screen", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) })) { PanelPosition.Value = DefaultPosition; } } private static void Raise(Action a) { if (a == null) { return; } try { a(); } catch (Exception ex) { ComfortAuditPlugin.Log.LogWarning((object)("config apply failed: " + ex.Message)); } } } } namespace ComfortAudit.UI { public sealed class ComfortPanel { private const float Padding = 18f; private const float BottomSlack = 10f; private GameObject _panel; private RectTransform _panelRect; private RectTransform _bodyRect; private RectTransform _thumbRect; private TextMeshProUGUI _body; private float _scroll; private float _contentHeight; private float _viewportHeight; private const float ScrollStep = 40f; private const float ScaleStep = 0.05f; private string _lastText; private bool _dirty = true; private int _builtRevision = -1; private Vector2 _lastSeenPosition; private float _positionSettleAt; private bool _suppressLayoutApply; private bool _needsCentre; private const float PositionSettleDelay = 0.4f; private PlacementPreviewResult _preview; private const float HeightMargin = 24f; private static readonly Color BodyColor = Color32.op_Implicit(new Color32((byte)242, (byte)233, (byte)216, byte.MaxValue)); private const string Dim = "<color=#BCAF97>"; private const string Reset = "</color>"; public bool IsOpen { get; private set; } public bool Created => (Object)(object)_panel != (Object)null; private static float Scale => PluginConfig.PanelScale.Value; public void Create() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: 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) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Expected O, but got Unknown //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Expected O, but got Unknown //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Expected O, but got Unknown //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_panel != (Object)null) && !((Object)(object)GUIManager.CustomGUIFront == (Object)null)) { float value = PluginConfig.PanelWidth.Value; _panel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), PluginConfig.PanelPosition.Value, value, 200f, false); ((Object)_panel).name = "ComfortAuditPanel"; _panelRect = _panel.GetComponent<RectTransform>(); _panel.AddComponent<PanelInput>().Owner = this; _panelRect.pivot = new Vector2(0f, 1f); GameObject val = new GameObject("Backdrop", new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(_panel.transform, false); RectTransform component = val.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = new Vector2(9f, 9f); component.offsetMax = new Vector2(-9f, -9f); Image component2 = val.GetComponent<Image>(); ((Graphic)component2).color = new Color(0.04f, 0.03f, 0.02f, 0.82f); ((Graphic)component2).raycastTarget = false; GameObject val2 = new GameObject("Viewport", new Type[2] { typeof(RectTransform), typeof(RectMask2D) }); val2.transform.SetParent(_panel.transform, false); RectTransform component3 = val2.GetComponent<RectTransform>(); component3.anchorMin = Vector2.zero; component3.anchorMax = Vector2.one; component3.offsetMin = new Vector2(18f, 18f); component3.offsetMax = new Vector2(-18f, -18f); GameObject val3 = new GameObject("Body", new Type[2] { typeof(RectTransform), typeof(TextMeshProUGUI) }); val3.transform.SetParent(val2.transform, false); RectTransform obj = (_bodyRect = val3.GetComponent<RectTransform>()); obj.anchorMin = new Vector2(0f, 1f); obj.anchorMax = new Vector2(0f, 1f); obj.pivot = new Vector2(0f, 1f); obj.anchoredPosition = Vector2.zero; obj.sizeDelta = new Vector2(value - 36f, 0f); GameObject val4 = new GameObject("ScrollThumb", new Type[2] { typeof(RectTransform), typeof(Image) }); val4.transform.SetParent(_panel.transform, false); _thumbRect = val4.GetComponent<RectTransform>(); _thumbRect.anchorMin = new Vector2(1f, 1f); _thumbRect.anchorMax = new Vector2(1f, 1f); _thumbRect.pivot = new Vector2(1f, 1f); Image component4 = val4.GetComponent<Image>(); ((Graphic)component4).color = new Color(0.95f, 0.91f, 0.85f, 0.45f); ((Graphic)component4).raycastTarget = false; val4.SetActive(false); _body = val3.GetComponent<TextMeshProUGUI>(); ((TMP_Text)_body).font = GUIManager.Instance.TMP_Norse; ((TMP_Text)_body).fontSize = 15f; ((Graphic)_body).color = BodyColor; ((Graphic)_body).raycastTarget = false; ((TMP_Text)_body).richText = true; ((TMP_Text)_body).alignment = (TextAlignmentOptions)257; ((TMP_Text)_body).textWrappingMode = (TextWrappingModes)1; ((TMP_Text)_body).overflowMode = (TextOverflowModes)0; _panel.SetActive(IsOpen); _lastText = null; _dirty = true; ApplyLayout(); } } public void ApplyLayout() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_00a0: 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) if (!((Object)(object)_panelRect == (Object)null) && !_suppressLayoutApply) { if (PluginConfig.PanelPosition.Value == Vector2.zero) { _needsCentre = true; } float value = PluginConfig.PanelWidth.Value; _panelRect.sizeDelta = new Vector2(value, _panelRect.sizeDelta.y); ((Transform)_panelRect).localScale = new Vector3(Scale, Scale, 1f); if ((Object)(object)_bodyRect != (Object)null) { _bodyRect.sizeDelta = new Vector2(value - 36f, _bodyRect.sizeDelta.y); } _panelRect.anchoredPosition = ClampToCanvas(PluginConfig.PanelPosition.Value); _lastSeenPosition = _panelRect.anchoredPosition; _positionSettleAt = 0f; _lastText = null; _dirty = true; } } private Vector2 CanvasSize() { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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) RectTransform val = (RectTransform)(((Object)(object)_panelRect != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val != (Object)null) { Rect rect = val.rect; if (((Rect)(ref rect)).width > 1f) { rect = val.rect; if (((Rect)(ref rect)).height > 1f) { rect = val.rect; float width = ((Rect)(ref rect)).width; rect = val.rect; return new Vector2(width, ((Rect)(ref rect)).height); } } } return new Vector2((float)Screen.width, (float)Screen.height); } private Vector2 ScaledSize() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) return _panelRect.sizeDelta * Scale; } private Vector2 ClampToCanvas(Vector2 pos) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) Vector2 val = CanvasSize(); Vector2 val2 = ScaledSize(); return new Vector2(Mathf.Clamp(pos.x, 0f, Mathf.Max(0f, val.x - val2.x)), Mathf.Clamp(pos.y, 0f - Mathf.Max(0f, val.y - val2.y), 0f)); } internal void DragTo(Vector2 pos) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_panelRect != (Object)null) { _panelRect.anchoredPosition = ClampToCanvas(pos); } } internal void ScrollBy(float notches) { _scroll -= notches * 40f; ApplyScroll(); } internal void ScaleBy(float notches) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Round((Scale + Mathf.Sign(notches) * 0.05f) / 0.05f) * 0.05f; num = Mathf.Clamp(num, 0.5f, 2f); if (!Mathf.Approximately(num, Scale)) { PersistPosition(_panelRect.anchoredPosition); PluginConfig.PanelScale.Value = num; } } private void ApplyScroll() { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: 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) if ((Object)(object)_bodyRect == (Object)null) { return; } float num = Mathf.Max(0f, _contentHeight - _viewportHeight); _scroll = Mathf.Clamp(_scroll, 0f, num); _bodyRect.anchoredPosition = new Vector2(0f, _scroll); if (!((Object)(object)_thumbRect == (Object)null)) { bool flag = num > 0.5f; ((Component)_thumbRect).gameObject.SetActive(flag); if (flag) { float num2 = Mathf.Max(24f, _viewportHeight * _viewportHeight / _contentHeight); float num3 = _viewportHeight - num2; _thumbRect.sizeDelta = new Vector2(4f, num2); _thumbRect.anchoredPosition = new Vector2(-11f, -18f - num3 * (_scroll / num)); } } } private void CentreOnCanvas() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_panelRect == (Object)null) { return; } Vector2 val = CanvasSize(); Vector2 val2 = ScaledSize(); Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(Mathf.Round((val.x - val2.x) * 0.5f), 0f - Mathf.Round((val.y - val2.y) * 0.5f)); _panelRect.anchoredPosition = val3; _lastSeenPosition = val3; _positionSettleAt = 0f; _needsCentre = false; _suppressLayoutApply = true; try { PluginConfig.PanelPosition.Value = val3; } finally { _suppressLayoutApply = false; } } private void PersistPositionWhenSettled() { //IL_0015: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_005e: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_panelRect == (Object)null)) { Vector2 anchoredPosition = _panelRect.anchoredPosition; if (anchoredPosition != _lastSeenPosition) { _lastSeenPosition = anchoredPosition; _positionSettleAt = Time.unscaledTime + 0.4f; } else if (!(_positionSettleAt <= 0f) && !(Time.unscaledTime < _positionSettleAt)) { PersistPosition(anchoredPosition); } } } private void PersistPosition(Vector2 current) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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) _positionSettleAt = 0f; _lastSeenPosition = current; if (current != PluginConfig.PanelPosition.Value) { _suppressLayoutApply = true; try { PluginConfig.PanelPosition.Value = current; } finally { _suppressLayoutApply = false; } } } public void InvalidateText() { _dirty = true; } public void Toggle() { SetOpen(!IsOpen); } public void SetOpen(bool open) { IsOpen = open; if ((Object)(object)_panel != (Object)null) { _panel.SetActive(open); } } public void Destroy() { if ((Object)(object)_panel != (Object)null) { Object.Destroy((Object)(object)_panel); } _panel = null; _panelRect = null; _bodyRect = null; _thumbRect = null; _body = null; _lastText = null; IsOpen = false; } public void SetSpriteAsset(TMP_SpriteAsset asset) { if (!((Object)(object)_body == (Object)null) && ((TMP_Text)_body).spriteAsset != asset) { ((TMP_Text)_body).spriteAsset = asset; _dirty = true; } } public void SetPreview(PlacementPreviewResult preview) { if (!Same(_preview, preview)) { _preview = preview; _dirty = true; } } private static bool Same(PlacementPreviewResult a, PlacementPreviewResult b) { if (a == b) { return true; } if (a == null || b == null) { return false; } if (!a.Active && !b.Active) { return true; } if (a.Active == b.Active && a.Delta == b.Delta && a.InRange == b.InRange && a.NewTotal == b.NewTotal && a.DisplayName == b.DisplayName && a.PrefabName == b.PrefabName && a.BlockedBy == b.BlockedBy) { return Mathf.Abs(a.Distance - b.Distance) < 0.05f; } return false; } public void Render(ComfortSnapshot snap) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_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_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_013b: 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_014f: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0178: 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_0182: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_body == (Object)null || !IsOpen) { return; } PersistPositionWhenSettled(); int revision = SnapshotService.Revision; if (!_dirty && revision == _builtRevision) { return; } _dirty = false; _builtRevision = revision; string text = Build(snap); if (text == _lastText) { return; } _lastText = text; ((TMP_Text)_body).text = text; float value = PluginConfig.PanelWidth.Value; float y = ((TMP_Text)_body).GetPreferredValues(text, value - 36f, 0f).y; if (!((Object)(object)_panelRect != (Object)null)) { return; } _contentHeight = y + 10f; _bodyRect.sizeDelta = new Vector2(value - 36f, _contentHeight); Vector2 val = CanvasSize(); float num = Mathf.Min(_contentHeight + 36f, (val.y - 24f) / Scale); _panelRect.sizeDelta = new Vector2(value, num); _viewportHeight = num - 36f; ApplyScroll(); if (_needsCentre) { CentreOnCanvas(); return; } Vector2 anchoredPosition = _panelRect.anchoredPosition; float num2 = Mathf.Min(0f, num * Scale - val.y); if (anchoredPosition.y < num2) { anchoredPosition.y = num2; _panelRect.anchoredPosition = anchoredPosition; _lastSeenPosition = anchoredPosition; } } private static string Orange(string s) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) Color valheimOrange = GUIManager.Instance.ValheimOrange; return $"<color=#{ColorUtility.ToHtmlStringRGB(valheimOrange)}>{s}</color>"; } private static string Good(string s) { return "<color=#9BD97A>" + s + "</color>"; } private static string Bad(string s) { return "<color=#FF8A6B>" + s + "</color>"; } private static string Amber(string s) { return "<color=#F2C14E>" + s + "</color>"; } private string Build(ComfortSnapshot snap) { StringBuilder stringBuilder = new StringBuilder(1024); stringBuilder.Append(Orange("<b>" + Strings.Get("$comfortaudit_panel_title") + "</b>")); stringBuilder.Append('\n'); if (!snap.Valid) { stringBuilder.Append("<color=#BCAF97>").Append(Strings.Get("$comfortaudit_not_resting")).Append("</color>"); return stringBuilder.ToString(); } AppendHeadline(stringBuilder, snap); stringBuilder.Append('\n'); AppendPreview(stringBuilder, snap); AppendShelter(stringBuilder, snap); stringBuilder.Append('\n'); AppendGate(stringBuilder, snap); stringBuilder.Append('\n'); AppendPieces(stringBuilder, snap); stringBuilder.Append('\n'); AppendRecommendations(stringBuilder, snap); if (snap.Mismatch) { stringBuilder.Append('\n').Append(Bad(Strings.Get("$comfortaudit_mismatch", snap.VanillaComfortLevel, snap.ComfortLevel))); } return stringBuilder.ToString(); } private void AppendHeadline(StringBuilder sb, ComfortSnapshot snap) { sb.Append("<b>").Append(Strings.Get("$comfortaudit_comfort")).Append(" ") .Append(snap.ComfortLevel) .Append("</b>"); sb.Append(" ").Append(Strings.Get("$comfortaudit_rested")).Append(' ') .Append(RestedMath.Format(snap.RestedSeconds)); if (!snap.TtlFromLiveEffect && !snap.RulesOn && PluginConfig.Verbose.Value) { sb.Append(' ').Append("<color=#BCAF97>").Append('(') .Append(Strings.Get("$comfortaudit_from_prefab")) .Append(')') .Append("</color>"); } if (snap.RulesOn) { sb.Append(" ").Append(Orange(Strings.Get("$twix_stamina", Mathf.FloorToInt(snap.StaminaRegenPct + 0.001f)))); int value = RulesConfig.ReferenceComfort.Value; sb.Append('\n').Append("<color=#BCAF97>").Append(Strings.Get("$twix_full_at", value, Mathf.FloorToInt(RulesConfig.StaminaRegenAtReference.Value * 100f + 0.001f), RestedMath.Format(ComfortRules.SecondsFor(value)))) .Append("</color>"); } sb.Append('\n').Append("<color=#BCAF97>"); sb.Append(snap.InShelter ? Strings.Get("$comfortaudit_baseline") : Strings.Get("$comfortaudit_baseline_noshelter")); if (snap.PostureBonus > 0 && !string.IsNullOrEmpty(snap.PostureToken)) { sb.Append(" + ").Append(Strings.Get(snap.PostureToken, snap.PostureBonus)); } sb.Append("</color>").Append('\n'); AppendCeiling(sb, snap); } private void AppendCeiling(StringBuilder sb, ComfortSnapshot snap) { if (PluginConfig.ShowCeiling.Value && snap.CeilingValid && snap.CeilingUnlocked > 0) { sb.Append("<color=#BCAF97>").Append(" "); string text = RestedMath.Format(RestedMath.SecondsFor(snap, snap.CeilingUnlocked)); if (snap.ComfortLevel >= snap.CeilingUnlocked) { sb.Append(Strings.Get("$comfortaudit_ceiling", snap.CeilingUnlocked, text)).Append(" — ").Append(Strings.Get("$comfortaudit_ceiling_atmax")); } else { sb.Append(Strings.Get("$comfortaudit_ceiling", snap.CeilingUnlocked, text)); } if (snap.CeilingAll > snap.CeilingUnlocked) { string text2 = RestedMath.Format(RestedMath.SecondsFor(snap, snap.CeilingAll)); sb.Append(", ").Append(Strings.Get("$comfortaudit_ceiling_all", snap.CeilingAll, text2)); } sb.Append("</color>").Append('\n'); } } private void AppendPreview(StringBuilder sb, ComfortSnapshot snap) { if (_preview == null || !_preview.Active) { return; } sb.Append(Orange(Strings.Get("$comfortaudit_preview"))).Append('\n').Append(" ") .Append(IconAtlas.Tag(_preview.PrefabName)); if (!_preview.InRange) { sb.Append("<color=#BCAF97>").Append(Strings.Get("$comfortaudit_preview_outofrange", _preview.DisplayName, _preview.Distance, (int)ComfortScanner.ComfortRadius)).Append("</color>") .Append('\n') .Append('\n'); return; } if (_preview.Delta > 0) { sb.Append(Good(Strings.Get("$comfortaudit_preview_gain", _preview.DisplayName, _preview.Delta, _preview.NewTotal))); } else { sb.Append("<color=#BCAF97>").Append(Strings.Get("$comfortaudit_preview_nogain", _preview.DisplayName)); if (!snap.InShelter) { sb.Append(" — ").Append(Strings.Get("$comfortaudit_preview_noshelter")); } else if (!string.IsNullOrEmpty(_preview.BlockedBy)) { sb.Append(" — ").Append(Strings.Get("$comfortaudit_preview_blocked", _preview.BlockedBy)); } sb.Append("</color>"); } sb.Append('\n').Append('\n'); } private void AppendShelter(StringBuilder sb, ComfortSnapshot snap) { int num = Mathf.RoundToInt(snap.CoverPercentage * 100f); if (snap.InShelter) { sb.Append(Good(Strings.Get("$comfortaudit_shelter_ok", num))).Append('\n'); return; } string text = Strings.Get(snap.UnderRoof ? "$comfortaudit_yes" : "$comfortaudit_no"); sb.Append(Bad(Strings.Get("$comfortaudit_shelter_no", num, text))).Append('\n'); sb.Append(Bad(Strings.Get("$comfortaudit_shelter_warn", snap.PotentialIfSheltered))).Append('\n'); } private void AppendGate(StringBuilder sb, ComfortSnapshot snap) { if (snap.Gate != null) { sb.Append(Orange(Strings.Get("$comfortaudit_gate_header"))).Append('\n'); for (int i = 0; i < snap.Gate.Conditions.Count; i++) { GateCondition gateCondition = snap.Gate.Conditions[i]; sb.Append(gateCondition.Met ? Good(" + ") : Bad(" - ")); sb.Append(gateCondition.Met ? "<color=#BCAF97>" : string.Empty); sb.Append(Strings.Get(gateCondition.Token)); sb.Append(gateCondition.Met ? "</color>" : string.Empty); sb.Append('\n'); } } } private void AppendPieces(StringBuilder sb, ComfortSnapshot snap) { //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) if (snap.PieceCount == 0) { sb.Append("<color=#BCAF97>").Append(Strings.Get("$comfortaudit_no_pieces", (int)ComfortScanner.ComfortRadius)).Append("</color>") .Append('\n'); AppendMissing(sb, snap); return; } bool inShelter = snap.InShelter; sb.Append(Orange(Strings.Get(inShelter ? "$comfortaudit_contributing" : "$comfortaudit_contributing_noshelter"))).Append('\n'); bool flag = false; for (int i = 0; i < snap.Pieces.Count; i++) { PieceEntry pieceEntry = snap.Pieces[i]; if (pieceEntry.Status == PieceStatus.Counted) { flag = true; sb.Append(" ").Append(IconAtlas.Tag(pieceEntry.PrefabName)).Append(ComfortGroups.Name(pieceEntry.Group)) .Append(": ") .Append(pieceEntry.DisplayName); if (pieceEntry.Inactive) { sb.Append(" ").Append((pieceEntry.LightGain > 0) ? Bad(Strings.Get("$comfortaudit_unlit_hint", pieceEntry.LightGain)) : Bad(Strings.Get("$comfortaudit_unlit"))); } else if (inShelter) { sb.Append(" ").Append(Orange("+" + pieceEntry.Comfort)); } else { sb.Append(" ").Append("<color=#BCAF97>").Append("+") .Append(pieceEntry.Comfort) .Append("</color>"); } AppendSuffix(sb, pieceEntry); sb.Append('\n'); } } if (!flag) { sb.Append("<color=#BCAF97>").Append(" —").Append("</color>") .Append('\n'); } bool flag2 = false; int num = 0; int num2 = 0; int num3 = Mathf.Max(1, PluginConfig.MaxIgnored.Value); for (int j = 0; j < snap.Pieces.Count; j++) { PieceEntry pieceEntry2 = snap.Pieces[j]; if (pieceEntry2.Status == PieceStatus.Counted) { continue; } if (!flag2) { sb.Append('\n').Append(Orange(Strings.Get("$comfortaudit_ignored"))).Append('\n'); flag2 = true; } if (num >= num3) { num2++; continue; } num++; sb.Append("<color=#BCAF97>").Append(" ").Append(IconAtlas.Tag(pieceEntry2.PrefabName)) .Append(ComfortGroups.Name(pieceEntry2.Group)) .Append(": ") .Append(pieceEntry2.DisplayName) .Append(" "); if (pieceEntry2.Status == PieceStatus.ShadowedByName) { sb.Append(Strings.Get(snap.RulesOn ? "$twix_copy_of" : "$comfortaudit_dupe_of", pieceEntry2.ShadowedBy)); } else if (snap.RulesOn) { sb.Append(Strings.Get("$twix_beyond_best", ComfortRules.PiecesPerKind, pieceEntry2.ShadowedBy)); } else { sb.Append(Strings.Get("$comfortaudit_beaten_by", pieceEntry2.ShadowedBy)); } sb.Append(" — "); if (pieceEntry2.Inactive && pieceEntry2.LightGain > 0) { sb.Append("</color>").Append(Good(Strings.Get("$comfortaudit_unlit_hint", pieceEntry2.LightGain))).Append("<color=#BCAF97>"); } else if (pieceEntry2.RemovalLoss > 0) { sb.Append(Strings.Get("$comfortaudit_keep_removal_costs", pieceEntry2.RemovalLoss)); } else { sb.Append(Strings.Get("$comfortaudit_safe_to_remove")); } AppendSuffix(sb, pieceEntry2); sb.Append("</color>").Append('\n'); } if (num2 > 0) { sb.Append("<color=#BCAF97>").Append(" ").Append(Strings.Get("$comfortaudit_ignored_more", num2)) .Append("</color>") .Append('\n'); } AppendMissing(sb, snap); } private void AppendRecommendations(StringBuilder sb, ComfortSnapshot snap) { sb.Append(Orange(Strings.Get("$comfortaudit_recommend"))).Append('\n'); if (!snap.RecommendationsReady) { sb.Append("<color=#BCAF97>").Append(" ").Append(Strings.Get("$comfortaudit_rec_loading")) .Append("</color>") .Append('\n'); return; } if (snap.Recommendations.Count == 0) { AppendNothingToDo(sb, snap); return; } for (int i = 0; i < snap.Recommendations.Count; i++) { AppendRecommendation(sb, snap.Recommendations[i]); } } private void AppendNothingToDo(StringBuilder sb, ComfortSnapshot snap) { RecommendationStats recStats = snap.RecStats; if (recStats == null || recStats.Catalogue == 0) { sb.Append("<color=#BCAF97>").Append(" ").Append(Strings.Get("$comfortaudit_rec_none")) .Append("</color>") .Append('\n'); return; } if (recStats.StationOutOfRange > 0 || recStats.MaterialsShort > 0) { sb.Append("<color=#BCAF97>").Append(" ").Append(Strings.Get("$comfortaudit_rec_none_filtered")) .Append("</color>") .Append('\n'); } else if (recStats.NoGain > 0) { sb.Append(" ").Append(Good(Strings.Get("$comfortaudit_rec_none_best"))).Append('\n'); } else { sb.Append("<color=#BCAF97>").Append(" ").Append(Strings.Get("$comfortaudit_rec_none")) .Append("</color>") .Append('\n'); } if (recStats.RecipeUnknown > 0) { AppendNote(sb, Strings.Get("$comfortaudit_rec_locked", recStats.RecipeUnknown)); } if (recStats.StationOutOfRange > 0) { AppendNote(sb, Strings.Get("$comfortaudit_rec_needstation", recStats.StationOutOfRange)); } if (recStats.MaterialsShort > 0) { AppendNote(sb, Strings.Get("$comfortaudit_rec_needmaterials", recStats.MaterialsShort)); } } private void AppendNote(StringBuilder sb, string text) { sb.Append("<color=#BCAF97>").Append(" ").Append(text) .Append("</color>") .Append('\n'); } private void AppendRecommendation(StringBuilder sb, Recommendation r) { //IL_0114: Unknown result type (might be due to invalid IL or missing references) sb.Append(" ").Append(Orange("+" + r.Gain)).Append(" ") .Append(IconAtlas.Tag(r.PrefabName)) .Append(r.DisplayName); if (r.Kind == RecommendationKind.LightIt) { sb.Append(" ").Append(Good(Strings.Get("$comfortaudit_rec_light"))); } if (!string.IsNullOrEmpty(r.Replaces)) { sb.Append(" ").Append("<color=#BCAF97>").Append(Strings.Get("$comfortaudit_rec_replaces", r.Replaces)) .Append("</color>"); } else if (r.Kind == RecommendationKind.Stacking) { sb.Append(" ").Append("<color=#BCAF97>").Append(Strings.Get("$comfortaudit_rec_stacking")) .Append("</color>"); } else if (r.Kind == RecommendationKind.NewGroup && r.GroupKnown) { string text = ComfortGroups.Name(r.Group); if (!string.Equals(text, r.DisplayName, StringComparison.OrdinalIgnoreCase)) { sb.Append(" ").Append("<color=#BCAF97>").Append(text) .Append("</color>"); } } sb.Append('\n'); if (r.Free || r.Kind == RecommendationKind.Shelter) { return; } if (!r.StationInRange) { sb.Append(" ").Append(Bad(Strings.Get("$comfortaudit_rec_nostation"))).Append('\n'); } else { if (!PluginConfig.ShowMaterials.Value || r.Materials.Count == 0) { return; } sb.Append(" "); for (int i = 0; i < r.Materials.Count; i++) { MaterialLine materialLine = r.Materials[i]; if (i > 0) { sb.Append("<color=#BCAF97>").Append(", ").Append("</color>"); } string text2 = materialLine.Amount + " " + materialLine.DisplayName; switch (MaterialMath.Annotate(materialLine.Amount, materialLine.Have, materialLine.InChests)) { case MaterialAnnotation.Have: text2 = text2 + " " + Strings.Get("$comfortaudit_have", materialLine.Have); break; case MaterialAnnotation.HaveAndChests: text2 = text2 + " " + Strings.Get("$comfortaudit_in_chests", materialLine.Have, materialLine.InChests); break; } switch (materialLine.State) { case MaterialState.Enough: sb.Append("<color=#BCAF97>").Append(text2).Append("</color>"); break; case MaterialState.EnoughWithChests: sb.Append(Amber(text2)); break; default: sb.Append(Bad(text2)); break; } } sb.Append('\n'); } } private void AppendSuffix(StringBuilder sb, PieceEntry e) { if (PluginConfig.ShowDistances.Value) { sb.Append("<color=#BCAF97>").Append($" {e.Distance:0.0}m").Append("</color>"); } if (PluginConfig.ShowPrefabNames.Value) { sb.Append("<color=#BCAF97>").Append(" [").Append(e.PrefabName) .Append(']') .Append("</color>"); } } private void AppendMissing(StringBuilder sb, ComfortSnapshot snap) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) if (snap.MissingGroups.Count == 0) { return; } sb.Append('\n').Append(Orange(Strings.Get("$comfortaudit_missing"))).Append('\n') .Append("<color=#BCAF97>") .Append(" "); for (int i = 0; i < snap.MissingGroups.Count; i++) { if (i > 0) { sb.Append(", "); } sb.Append(ComfortGroups.Name(snap.MissingGroups[i])); } sb.Append("</color>").Append('\n'); } } public static class IconAtlas { private const float PointSize = 100f; private const float Ascent = 80f; private const float Advance = 105f; private static readonly List<TMP_SpriteAsset> Assets = new List<TMP_SpriteAsset>(); private static readonly HashSet<string> Glyphs = new HashSet<string>(); private static bool _built; private static Shader _shader; public static TMP_SpriteAsset Primary { get { if (Assets.Count <= 0) { return null; } return Assets[0]; } } public static string Tag(string prefabName) { if (!_built || !PluginConfig.ShowIcons.Value) { return ""; } string text = SpriteTags.GlyphName(prefabName); if (text == null || !Glyphs.Contains(text)) { return ""; } return SpriteTags.Tag(text); } public static void Invalidate() { for (int i = 0; i < Assets.Count; i++) { if (!((Object)(object)Assets[i] == (Object)null)) { if ((Object)(object)((TMP_Asset)Assets[i]).material != (Object)null) { Object.Destroy((Object)(object)((TMP_Asset)Assets[i]).material); } Object.Destroy((Object)(object)Assets[i]); } } Assets.Clear(); Glyphs.Clear(); _built = false; } public static void EnsureBuilt() { //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) if (_built || !PluginConfig.ShowIcons.Value || !PieceCatalog.Ready) { return; } _built = true; if ((Object)(object)_shader == (Object)null) { _shader = Shader.Find("TextMeshPro/Sprite"); } if ((Object)(object)_shader == (Object)null) { ComfortAuditPlugin.Log.LogWarning((object)"icons: TextMeshPro/Sprite shader not found; panel will show no icons"); return; } Dictionary<Texture2D, List<KeyValuePair<string, Rect>>> dictionary = new Dictionary<Texture2D, List<KeyValuePair<string, Rect>>>(); HashSet<string> hashSet = new HashSet<string>(); int num = 0; List<PieceCatalog.Entry> list = PieceCatalog.Entries(); for (int i = 0; i < list.Count; i++) { PieceCatalog.Entry entry = list[i]; Sprite val = (((Object)(object)entry.Piece != (Object)null) ? entry.Piece.m_icon : null); string text = SpriteTags.GlyphName(entry.PrefabName); if (!((Object)(object)val == (Object)null) && !((Object)(object)val.texture == (Object)null) && text != null && !hashSet.Contains(text)) { Rect textureRect; try { textureRect = val.textureRect; } catch (Exception) { num++; continue; } if (!dictionary.TryGetValue(val.texture, out var value)) { value = (dictionary[val.texture] = new List<KeyValuePair<string, Rect>>()); } value.Add(new KeyValuePair<string, Rect>(text, textureRect)); hashSet.Add(text); } } foreach (KeyValuePair<Texture2D, List<KeyValuePair<string, Rect>>> item2 in dictionary) { TMP_SpriteAsset item; try { item = Build(item2.Key, item2.Value); } catch (Exception ex2) { ComfortAuditPlugin.Log.LogWarning((object)("icons: failed to build sprite asset for texture \"" + ((Object)item2.Key).name + "\": " + ex2.Message)); continue; } Assets.Add(item); for (int j = 0; j < item2.Value.Count; j++) { Glyphs.Add(item2.Value[j].Key); } } if (Assets.Count > 1) { Assets[0].fallbackSpriteAssets = Assets.GetRange(1, Assets.Count - 1); } ComfortAuditPlugin.Log.LogInfo((object)$"icons: {Glyphs.Count} glyph(s) over {Assets.Count} texture(s), {num} skipped"); } private static TMP_SpriteAsset Build(Texture2D texture, List<KeyValuePair<string, Rect>> icons) { //IL_0030: 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_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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Expected O, but got Unknown //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown TMP_SpriteAsset val = ScriptableObject.CreateInstance<TMP_SpriteAsset>(); ((Object)val).name = "ComfortAudit_" + ((Object)texture).name; ((TMP_Asset)val).version = "1.1.0"; val.spriteSheet = (Texture)(object)texture; FaceInfo faceInfo = default(FaceInfo); ((FaceInfo)(ref faceInfo)).pointSize = 100f; ((FaceInfo)(ref faceInfo)).scale = 1f; ((FaceInfo)(ref faceInfo)).lineHeight = 100f; ((FaceInfo)(ref faceInfo)).ascentLine = 80f; ((FaceInfo)(ref faceInfo)).descentLine = -20f; ((TMP_Asset)val).faceInfo = faceInfo; for (int i = 0; i < icons.Count; i++) { Rect value = icons[i].Value; TMP_SpriteGlyph val2 = new TMP_SpriteGlyph((uint)i, new GlyphMetrics(100f, 100f, 0f, 80f, 105f), new GlyphRect((int)((Rect)(ref value)).x, (int)((Rect)(ref value)).y, (int)((Rect)(ref value)).width, (int)((Rect)(ref value)).height), 1f, 0); val.spriteGlyphTable.Add(val2); TMP_SpriteCharacter val3 = new TMP_SpriteCharacter(65534u, val, val2); val3.name = icons[i].Key; val.spriteCharacterTable.Add(val3); } Material val4 = new Material(_shader); val4.SetTexture(ShaderUtilities.ID_MainTex, (Texture)(object)texture); ((TMP_Asset)val).material = val4; val.UpdateLookupTables(); return val; } } internal sealed class PanelInput : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler, IScrollHandler { internal ComfortPanel Owner; private RectTransform _rect; private Vector2 _startPointer; private Vector2 _startPosition; private bool _dragging; private void Awake() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown _rect = (RectTransform)((Component)this).transform; } public void OnBeginDrag(PointerEventData eventData) { //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) _dragging = TryPointer(eventData, out _startPointer); _startPosition = _rect.anchoredPosition; } public void OnDrag(PointerEventData eventData) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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) if (_dragging && Owner != null && TryPointer(eventData, out var local)) { Owner.DragTo(_startPosition + (local - _startPointer)); } } public void OnEndDrag(PointerEventData eventData) { _dragging = false; } public void OnScroll(PointerEventData eventData) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (Owner == null || (int)Cursor.lockState == 1) { return; } float y = eventData.scrollDelta.y; if (!Mathf.Approximately(y, 0f)) { if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305)) { Owner.ScaleBy(y); } else { Owner.ScrollBy(y); } } } private bool TryPointer(PointerEventData eventData, out Vector2 local) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) local = Vector2.zero; Transform parent = ((Transform)_rect).parent; RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null); if ((Object)(object)val != (Object)null) { return RectTransformUtility.ScreenPointToLocalPointInRectangle(val, eventData.position, eventData.pressEventCamera, ref local); } return false; } } } namespace ComfortAudit.Rules { public static class BossTrophies { private static HashSet<int> _hashes; private static List<string> _names; public static List<string> Names { get { Ensure(); return _names ?? new List<string>(); } } public static void Invalidate() { _hashes = null; _names = null; } public static bool Contains(int itemHash) { Ensure(); if (_hashes != null) { return _hashes.Contains(itemHash); } return false; } private static void Ensure() { //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Invalid comparison between Unknown and I4 if (_hashes != null || (Object)(object)ZNetScene.instance == (Object)null || ZNetScene.instance.m_prefabs == null) { return; } List<string> list = new List<string>(); HashSet<string> hashSet = new HashSet<string>(); foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if ((Object)(object)prefab == (Object)null) { continue; } Character component = prefab.GetComponent<Character>(); if ((Object)(object)component == (Object)null) { continue; } CharacterDrop component2 = prefab.GetComponent<CharacterDrop>(); if ((Object)(object)component2 == (Object)null || component2.m_drops == null) { continue; } foreach (Drop drop in component2.m_drops) { if (drop == null || (Object)(object)drop.m_prefab == (Object)null) { continue; } ItemDrop component3 = drop.m_prefab.GetComponent<ItemDrop>(); if ((Object)(object)component3 == (Object)null || component3.m_itemData == null || component3.m_itemData.m_shared == null || (int)component3.m_itemData.m_shared.m_itemType != 13) { continue; } if (component.m_boss) { if (!list.Contains(((Object)drop.m_prefab).name)) { list.Add(((Object)drop.m_prefab).name); } } else { hashSet.Add(((Object)drop.m_prefab).name); } } } HashSet<int> hashSet2 = new HashSet<int>(); List<string> list2 = new List<string>(); foreach (string item in list) { if (!hashSet.Contains(item) && hashSet2.Add(StringExtensionMethods.GetStableHashCode(item))) { list2.Add(item); } } _hashes = hashSet2; _names = list2; ComfortAuditPlugin.Log.LogInfo((object)("Boss trophies (" + list2.Count + "): " + string.Join(", ", list2.ToArray()))); } } public static class ComfortRules { public struct Trophy { public Piece Stand; public string PrefabName; public string DisplayToken; } private sealed class Applied { public float Fraction; } public const ComfortGroup TrophyGroup = (ComfortGroup)100; private static readonly List<Piece> GamePieces = new List<Piece>(128); private static readonly List<Trophy> GameTrophies = new List<Trophy>(8); private static readonly List<ComfortWalk.Item> GameItems = new List<ComfortWalk.Item>(136); private static readonly ConditionalWeakTable<SE_Rested, Applied> AppliedFraction = new ConditionalWeakTable<SE_Rested, Applied>(); private const string SaveKey = "TwixComfort.Rested"; internal static bool Restoring; private static int _restoredForGame; public static bool Enabled { get { if (RulesConfig.Enabled != null) { return RulesConfig.Enabled.Value; } return false; } } public static float Radius { get { if (!Enabled) { return 10f; } return RulesConfig.ComfortRadius.Value; } } public static int PiecesPerKind { get { if (!Enabled) { return 1; } return Mathf.Max(1, RulesConfig.PiecesPerKind.Value); } } public static void Collect(Vector3 pos, List<Piece> pieces, List<Trophy> trophies) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) pieces.Clear(); trophies?.Clear(); Piece.GetAllComfortPiecesInRadius(pos, Radius, pieces); if (trophies == null || !Enabled || RulesConfig.TrophyComfort.Value <= 0) { return; } for (int i = 0; i < pieces.Count; i++) { ItemStand component = ((Component)pieces[i]).GetComponent<ItemStand>(); if ((Object)(object)component == (Object)null) { continue; } int attachedItem = component.GetAttachedItem(); if (attachedItem != 0 && BossTrophies.Contains(attachedItem)) { GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(attachedItem) : null); if (!((Object)(object)val == (Object)null)) { ItemDrop component2 = val.GetComponent<ItemDrop>(); trophies.Add(new Trophy { Stand = pieces[i], PrefabName = ((Object)val).name, DisplayToken = (((Object)(object)component2 != (Object)null) ? component2.m_itemData.m_shared.m_name : ((Object)val).name) }); } } } } public static void ToItems(List<Piece> pieces, List<Trophy> trophies, List<ComfortWalk.Item> items) { //IL_001e: 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_0072: Unknown result type (might be due to invalid IL or missing references) items.Clear(); for (int i = 0; i < pieces.Count; i++) { Piece val = pieces[i]; items.Add(new ComfortWalk.Item { Group = val.m_comfortGroup, Comfort = val.GetComfort(), NameToken = val.m_name, Source = i }); } if (trophies != null) { for (int j = 0; j < trophies.Count; j++) { items.Add(new ComfortWalk.Item { Group = (ComfortGroup)100, Comfort = Mathf.Max(0, RulesConfig.TrophyComfort.Value), NameToken = trophies[j].PrefabName, Source = pieces.Count + j }); } } } public static int Posture(Player player, out string token) { token = null; if (!Enabled || (Object)(object)player == (Object)null) { return 0; } if (((Character)player).InBed()) { token = "$twix_posture_bed"; return Mathf.Max(0, RulesConfig.BedComfort.Value); } if (((Character)player).IsSitting()) { token = "$twix_posture_sit"; return Mathf.Max(0, RulesConfig.SittingComfort.Value); } return 0; } public static int Furniture(bool inShelter, Vector3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) Collect(pos, GamePieces, GameTrophies); ToItems(GamePieces, GameTrophies, GameItems); return ComfortWalk.Run(GameItems, inShelter); } public static int Compute(Player player) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) string token; return Furniture(player.InShelter(), ((Component)player).transform.position) + Posture(player, out token); } public static float Fraction(int comfort) { int num = Mathf.Max(2, RulesConfig.ReferenceComfort.Value); return Mathf.Max(0f, ((float)comfort - 1f) / ((float)num - 1f)); } public static float SecondsFor(int comfort) { return Mathf.LerpUnclamped(RulesConfig.MinMinutes.Value, RulesConfig.MinutesAtReference.Value, Fraction(comfort)) * 60f; } public static float StaminaBonusAt(float fraction) { return Mathf.LerpUnclamped(RulesConfig.MinStaminaRegen.Value, RulesConfig.StaminaRegenAtReference.Value, Mathf.Max(0f, fraction)); } public static SE_Rested Prefab() { if (!((Object)(object)ObjectDB.instance != (Object)null)) { return null; } StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(SEMan.s_statusEffectRested); return (SE_Rested)(object)((statusEffect is SE_Rested) ? statusEffect : null); } public static float FractionOf(SE_Rested se) { if (!((Object)(object)se != (Object)null) || !AppliedFraction.TryGetValue(se, out var value)) { return -1f; } return value.Fraction; } public static void ApplyStrength(SE_Rested se, float fraction) { if (!((Object)(object)se == (Object)null)) { ((SE_Stats)se).m_healthRegenMultiplier = 1f; ((SE_Stats)se).m_staminaRegenMultiplier = 1f + Mathf.Max(0f, StaminaBonusAt(fraction)); ((SE_Stats)se).m_eitrRegenMultiplier = 1f; ((SE_Stats)se).m_raiseSkillModifier = 0f; AppliedFraction.Remove(se); AppliedFraction.Add(se, new Applied { Fraction = fraction }); } } public static void UpdateTtl(SE_Rested se, Player player) { int comfortLevel = player.GetComfortLevel(); float fraction = Fraction(comfortLevel); float num = SecondsFor(comfortLevel); float num2 = ((StatusEffect)se).m_ttl - ((StatusEffect)se).m_time; if (num > num2) { ((StatusEffect)se).m_ttl = num; ((StatusEffect)se).m_time = 0f; ApplyStrength(se, fraction); } } public static void WriteSave(Player player) { if ((Object)(object)player == (Object)null || player.m_customData == null) { return; } player.m_customData.Remove("TwixComfort.Rested"); if (!Enabled || !RulesConfig.KeepThroughLogout.Value) { return; } StatusEffect statusEffect = ((Character)player).GetSEMan().GetStatusEffect(SEMan.s_statusEffectRested); SE_Rested val = (SE_Rested)(object)((statusEffect is SE_Rested) ? statusEffect : null); if (!((Object)(object)val == (Object)null)) { float num = ((StatusEffect)val).m_ttl - ((StatusEffect)val).m_time; float num2 = FractionOf(val); if (!(num <= 1f) && !(num2 < 0f)) { player.m_customData["TwixComfort.Rested"] = num.ToString("0.0", CultureInfo.InvariantCulture) + ";" + num2.ToString("0.000", CultureInfo.InvariantCulture); } } } public static void ClearSave(Player player) { if ((Object)(object)player != (Object)null && player.m_customData != null) { player.m_customData.Remove("TwixComfort.Rested"); } } public static void RestoreSave(Player player) { if ((Object)(object)player == (Object)null || player.m_customData == null || (Object)(object)Game.instance == (Object)null) { return; } int instanceID = ((Object)Game.instance).GetInstanceID(); bool flag = instanceID != _restoredForGame; _restoredForGame = instanceID; if (!player.m_customData.TryGetValue("TwixComfort.Rested", out var value)) { return; } player.m_customData.Remove("TwixComfort.Rested"); if (!flag || !Enabled || !RulesConfig.KeepThroughLogout.Value) { return; } string[] array = value.Split(new char[1] { ';' }); if (array.Length != 2 || !float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || !float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || result <= 1f) { return; } Restoring = true; try { StatusEffect obj = ((Character)player).GetSEMan().AddStatusEffect(SEMan.s_statusEffectRested, true, 0, 0f, (short)(-1)); SE_Rested val = (SE_Rested)(object)((obj is SE_Rested) ? obj : null); if ((Object)(object)val == (Object)null) { return; } ((StatusEffect)val).m_ttl = result; ((StatusEffect)val).m_time = 0f; ApplyStrength(val, Mathf.Max(0f, result2)); ComfortAuditPlugin.Log.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "Rested restored after logout: {0:0}s left, +{1:0}% stamina regen", result, StaminaBonusAt(result2) * 100f)); } finally { Restoring = false; } ((Character)player).Message((MessageType)1, Strings.Get("$twix_rested_kept", RestedMath.Format(result)), 0, (Sprite)null, false); } } [HarmonyPatch] public static class GoodSleep { public const string EffectName = "TwixGoodSleep"; public static ConfigEntry<bool> Enabled; public static ConfigEntry<float> Minutes; public static ConfigEntry<float> HealthRegen; private static SE_Stats _template; private static bool _sleptInOwnBed; private const string Section = "8 - Good Sleep"; private static ConfigurationManagerAttributes Admin(int order) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown return new ConfigurationManagerAttributes { Order = order, IsAdminOnly = true }; } public static void Bind(ConfigFile cfg) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown Enabled = cfg.Bind<bool>("8 - Good Sleep", "Enabled", true, new ConfigDescription("Sleeping through the night in your own claimed bed gives Good Sleep when you wake.", (AcceptableValueBase)null, new object[1] { Admin(100) })); Minutes = cfg.Bind<float>("8 - Good Sleep", "Minutes", 20f, new ConfigDescription("How long Good Sleep lasts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), new object[1] { Admin(90) })); HealthRegen = cfg.Bind<float>("8 - Good Sleep", "HealthRegen", 0.5f, new ConfigDescription("Good Sleep's health regen bonus (0.5 = +50%). Its only bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), new object[1] { Admin(80) })); } public static void Register() { //IL_003d: 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_0070: Expected O, but got Unknown _template = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)_template).name = "TwixGoodSleep"; ((StatusEffect)_template).m_name = "$twix_se_goodsleep"; ((StatusEffect)_template).m_tooltip = "$twix_se_goodsleep_tooltip"; ((StatusEffect)_template).m_startMessageType = (MessageType)1; ((StatusEffect)_template).m_startMessage = "$twix_se_goodsleep_start"; ApplyConfig(_template); ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)_template, false)); } private static void ApplyConfig(SE_Stats se) { ((StatusEffect)se).m_ttl = Mathf.Max(1f, Minutes.Value) * 60f; se.m_healthRegenMultiplier = 1f + Mathf.Max(0f, HealthRegen.Value); } [HarmonyPatch(typeof(Player), "SetSleeping")] [HarmonyPrefix] private static void BeforeSetSleeping(Player __instance, bool __0) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || __instance.m_sleeping == __0) { return; } if (__0) { Bed val = (((Object)(object)__instance.m_attachPoint != (Object)null) ? ((Component)__instance.m_attachPoint).GetComponentInParent<Bed>() : null); _sleptInOwnBed = (Object)(object)val != (Object)null && val.IsMine(); return; } bool sleptInOwnBed = _sleptInOwnBed; _sleptInOwnBed = false; if (!sleptInOwnBed || Enabled == null || !Enabled.Value || (Object)(object)_template == (Object)null) { return; } if ((Object)(object)((StatusEffect)_template).m_icon == (Object)null) { SE_Rested val2 = ComfortRules.Prefab(); if ((Object)(object)val2 != (Object)null) { ((StatusEffect)_template).m_icon = ((StatusEffect)val2).m_icon; } } ApplyConfig(_template); StatusEffect val3 = ((Character)__instance).GetSEMan().AddStatusEffect(StringExtensionMethods.GetStableHashCode("TwixGoodSleep"), true, 0, 0f, (short)(-1)); if ((Object)(object)val3 == (Object)null) { ComfortAuditPlugin.Log.LogWarning((object)"Good Sleep: the effect is not registered in ObjectDB."); return; } val3.m_icon = ((StatusEffect)_template).m_icon; ComfortAuditPlugin.Log.LogInfo((object)("Good Sleep granted for " + Minutes.Value + " min.")); } } [HarmonyPatch] public static class RestedPatches { [HarmonyPatch(typeof(SE_Rested), "CalculateComfortLevel", new Type[] { typeof(Player) })] [HarmonyPrefix] private static bool CalculateForPlayer(Player __0, ref int __result) { if (!ComfortRules.Enabled || (Object)(object)__0 == (Object)null) { return true; } __result = ComfortRules.Compute(__0); return false; } [HarmonyPatch(typeof(SE_Rested), "CalculateComfortLevel", new Type[] { typeof(bool), typeof(Vector3) })] [HarmonyPrefix] private static bool CalculateAtPosition(bool __0, Vector3 __1, ref int __result) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!ComfortRules.Enabled) { return true; } __result = ComfortRules.Furniture(__0, __1); return false; } [HarmonyPatch(typeof(SE_Rested), "UpdateTTL")] [HarmonyPrefix] private static bool UpdateTtl(SE_Rested __instance) { if (!ComfortRules.Enabled) { return true; } if (ComfortRules.Restoring) { return false; } Character character = ((StatusEffect)__instance).m_character; Player val = (Player)(object)((character is Player) ? character : null); if ((Object)(object)val == (Object)null) { return true; } ComfortRules.UpdateTtl(__instance, val); return false; } [HarmonyPatch(typeof(Player), "Message")] [HarmonyPrefix] private static bool QuietWhileRestoring() { return !ComfortRules.Restoring; } [HarmonyPatch(typeof(Player), "Save")] [HarmonyPrefix] private static void BeforeSave(Player __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { ComfortRules.WriteSave(__instance); } } [HarmonyPatch(typeof(Player), "OnSpawned")] [HarmonyPostfix] private static void AfterSpawn(Player __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { ComfortRules.RestoreSave(__instance); } } [HarmonyPatch(typeof(Player), "OnDeath")] [HarmonyPrefix] private static void OnDeath(Player __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { ComfortRules.ClearSave(__instance); } } } public static class RulesConfig { public static ConfigEntry<bool> Enabled; public static ConfigEntry<int> PiecesPerKind; public static ConfigEntry<float> ComfortRadius; public static ConfigEntry<int> SittingComfort; public static ConfigEntry<int> BedComfort; public static ConfigEntry<int> TrophyComfort; public static ConfigEntry<int> ReferenceComfort; public static ConfigEntry<float> MinMinutes; public static ConfigEntry<float> MinutesAtReference; public static ConfigEntry<float> MinStaminaRegen; public static ConfigEntry<float> StaminaRegenAtReference; public static ConfigEntry<bool> KeepThroughLogout; private const string Section = "7 - Comfort"; private static ConfigurationManagerAttributes Admin(int order) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown return new ConfigurationManagerAttributes { Order = order, IsAdminOnly = true }; } public static void Bind(ConfigFile cfg) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Expected O, but got Unknown //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Expected O, but got Unknown //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Expected O, but got Unknown //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Expected O, but got Unknown //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Expected O, but got Unknown //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Expected O, but got Unknown //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Expected O, but got Unknown Enabled = cfg.Bind<bool>("7 - Comfort", "Enabled", true, new ConfigDescription("The pack's comfort and Rested rules. Off: comfort and Rested work as in the base game, and the panel just explains them.", (AcceptableValueBase)null, new object[1] { Admin(200) })); PiecesPerKind = cfg.Bind<int>("7 - Comfort", "PiecesPerKind", 3, new ConfigDescription("How many different pieces of each kind count (fires, beds, seats, tables, banners, rugs...). The best ones count; copies of the same piece never do. The base game counts 1.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), new object[1] { Admin(190) })); ComfortRadius = cfg.Bind<float>("7 - Comfort", "ComfortRadius", 20f, new ConfigDescription("Metres around you that furniture counts from. The base game uses 10.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 50f), new object[1] { Admin(180) })); SittingComfort = cfg.Bind<int>("7 - Comfort", "SittingComfort", 2, new ConfigDescription("Extra comfort while sitting.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), new object[1] { Admin(170) })); BedComfort = cfg.Bind<int>("7 - Comfort", "BedComfort", 4, new ConfigDescription("Extra comfort while lying in a bed (instead of the sitting bonus).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), new object[1] { Admin(165) })); TrophyComfort = cfg.Bind<int>("7 - Comfort", "BossTrophyComfort", 1, new ConfigDescription("Extra comfort for each different boss trophy on an item stand nearby. Like furniture, it only counts under a roof.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 5), new object[1] { Admin(160) })); ReferenceComfort = cfg.Bind<int>("7 - Comfort", "ReferenceComfort", 70, new ConfigDescription("The comfort where Rested lasts MinutesAtReference and gives StaminaRegenAtReference. Both rise in a straight line from comfort 1 to here, and keep rising past it with no limit.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 200), new object[1] { Admin(150) })); MinMinutes = cfg.Bind<float>("7 - Comfort", "MinutesAtComfort1", 2f, new ConfigDescription("How long Rested lasts at comfort 1.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 60f), new object[1] { Admin(140) })); MinutesAtReference = cfg.Bind<float>("7 - Comfort", "MinutesAtReference", 30f, new ConfigDescription("How long Rested lasts at ReferenceComfort. 30 minutes is one full Valheim day. Comfort above ReferenceComfort lasts longer still.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 120f), new object[1] { Admin(135) })); MinStaminaRegen = cfg.Bind<float>("7 - Comfort", "StaminaRegenAtComfort1", 0.5f, new ConfigDescription("Rested's stamina regen bonus at comfort 1 (0.5 = +50%). Rested gives nothing else: no health regen, eitr regen or skill XP bonus.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), new object[1] { Admin(130) })); StaminaRegenAtReference = cfg.Bind<float>("7 - Comfort", "StaminaRegenAtReference", 2f, new ConfigDescription("Rested's stamina regen bonus at ReferenceComfort (2 = +200%). Comfort above ReferenceComfort gives more still.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), new object[1] { Admin(125) })); KeepThroughLogout = cfg.Bind<bool>("7 - Comfort", "KeepRestedThroughLogout", true, new ConfigDescription("Logging out keeps Rested: it comes back with the time it had left and the same stamina regen when you next enter that character's world. Dying still ends it.", (AcceptableValueBase)null, new object[1] { Admin(110) })); } } } namespace ComfortAudit.Patches { [HarmonyPatch(typeof(StatusEffect), "GetIconText")] public static class StatusEffect_GetIconText_Patch { private const float FreshScanSeconds = 2.5f; private static int _comfort = -1; private static int _ceiling = -1; private static string _suffix = string.Empty; private static void Postfix(StatusEffect __instance, ref string __result) { if (PluginConfig.ShowComfortOnIcon.Value && __instance is SE_Rested) { Refresh(); if (_suffix.Length != 0) { __result = (string.IsNullOrEmpty(__result) ? _suffix : (__result + " " + _suffix)); } } } private static void Refresh() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { Set(0, 0); return; } ComfortSnapshot current = SnapshotService.Current; int comfortLevel; int ceiling; if (current.Valid && Time.time - SnapshotService.LastScanTime < 2.5f) { comfortLevel = current.ComfortLevel; ceiling = (current.CeilingValid ? current.CeilingUnlocked : 0); } else { comfortLevel = localPlayer.GetComfortLevel(); Ceiling.Result result = Ceiling.Get(localPlayer); ceiling = (result.Valid ? result.Unlocked : 0); } Set(comfortLevel, ceiling); } private static void Set(int comfort, int ceiling) { if (comfort != _comfort || ceiling != _ceiling) { _comfort = comfort; _ceiling = ceiling; if (comfort <= 0) { _suffix = string.Empty; } else if (ceiling > 0) { _suffix = comfort + "/" + ceiling; } else { _suffix = comfort.ToString(); } } } } } namespace ComfortAudit.Model { public enum PieceStatus { Counted, ShadowedByGroup, ShadowedByName } public sealed class PieceEntry { public string PrefabName; public string DisplayName; public string NameToken; public ComfortGroup Group; public bool GroupKnown; public int Comfort; public int RawComfort; public bool Inactive; public PieceStatus Status; public string ShadowedBy; public int LightGain; public int RemovalLoss; public float Distance; public bool Contributing { get { if (Status == PieceStatus.Counted) { return Comfort > 0; } return false; } } } public sealed class GateCondition { public string Token; public bool Met; public GateCondition(string token, bool met) { Token = token; Met = met; } } public sealed class RestGateResult { public List<GateCondition> Conditions = new List<GateCondition>(); } public enum RecommendationKind { LightIt, Shelter, NewGroup, Stacking, Upgrade } public sealed class MaterialLine { public string DisplayName; public int Amount; public int Have; public int InChests; public MaterialState State => MaterialMath.Classify(Amount, Have, InChests); } public sealed class Recommendation { public RecommendationKind Kind; public string DisplayName; public string PrefabName; public ComfortGroup Group; public bool GroupKnown; public int Gain; public float CostScore; public List<MaterialLine> Materials = new List<MaterialLine>(); public bool HaveAllMaterials; public bool HaveAllWithChests; public bool StationInRange; public string Replaces; public bool Free => Kind == RecommendationKind.LightIt; } public sealed class RecommendationStats { public int Catalogue; public int NotInMenu; public int NoGain; public int RecipeUnknown; public int StationOutOfRange; public int MaterialsShort; public int Candidates; public override string ToString() { return $"catalogue={Catalogue} notInMenu={NotInMenu} noGain={NoGain} recipeUnknown={RecipeUnknown} stationOutOfRange={StationOutOfRange} materialsShort={MaterialsShort} -> candidates={Candidates}"; } } public sealed class PlacementPreviewResult { public bool Active; public string DisplayName; public string PrefabName; public int Delta; public int NewTotal; public float Distance; public bool InRange; public string BlockedBy; } public sealed class ComfortSnapshot { public bool Valid; public int ComfortLevel; public int VanillaComfortLevel; public bool Mismatch; public bool InShelter; public float CoverPercentage; public bool UnderRoof; public int PotentialIfSheltered; public float RestedSeconds; public float BaseTTL; public float TTLPerLevel; public bool TtlFromLiveEffect; public int PostureBonus; public string PostureToken; public bool RulesOn; public float StaminaRegenPct; public RestGateResult Gate; public List<PieceEntry> Pieces = new List<PieceEntry>(); public List<ComfortGroup> MissingGroups = new List<ComfortGroup>(); public List<Recommendation> Recommendations = new List<Recommendation>(); public bool RecommendationsReady; public RecommendationStats RecStats; public int CeilingUnlocked; public int CeilingAll; public bool CeilingValid; public int PieceCount => Pieces.Count; } } namespace ComfortAudit.L10n { public static class Strings { public static void Register() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); Add(localization, "English", "ComfortAudit.L10n.en.json"); Add(localization, "Norwegian", "ComfortAudit.L10n.nb.json"); } private static void Add(CustomLocalization loc, string language, string resource) { string text = ReadEmbedded(resource); if (!string.IsNullOrEmpty(text)) { loc.AddJsonFile(language, text); } } public static string Get(string token) { if (string.IsNullOrEmpty(token)) { return string.Empty; } if (token[0] != '$') { token = "$" + token; } if (Localization.instance == null) { return token; } return Localization.instance.Localize(token); } public static string Get(string token, params object[] args) { string text = Get(token); if (args != null && args.Length != 0) { return string.Format(text, args); } return text; } internal static string ReadEmbedded(string name) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name); if (stream == null) { return null; } using StreamReader streamReader = new StreamReader(stream); return streamReader.ReadToEnd(); } } } namespace ComfortAudit.Core { public static class Ceiling { public struct Result { public int Unlocked; public int All; public bool Valid; } private const float TtlSeconds = 10f; private static Result _cached; private static float _computedAt = -999f; public static void Invalidate() { _computedAt = -999f; } public static Result Get(Player player) { if (Time.time - _computedAt < 10f) { return _cached; } Result result = Compute(player); if (result.Valid) { _cached = result; _computedAt = Time.time; } return result; } private static Result Compute(Player player) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) Result result = default(Result); List<PieceCatalog.Entry> list = PieceCatalog.Entries(); if (list == null || (Object)(object)player == (Object)null) { return result; } Dictionary<ComfortGroup, Dictionary<string, int>> map = new Dictionary<ComfortGroup, Dictionary<string, int>>(); Dictionary<ComfortGroup, Dictionary<string, int>> map2 = new Dictionary<ComfortGroup, Dictionary<string, int>>(); Dictionary<string, int> map3 = new Dictionary<string, int>(); Dictionary<string, int> map4 = new Dictionary<string, int>(); for (int i = 0; i < list.Count; i++) { PieceCatalog.Entry entry = list[i]; if (!entry.InBuildMenu) { continue; } bool flag = PieceCatalog.Available(entry, player) && player.HaveRequirements(entry.Piece, (RequirementMode)1); if (ComfortGroups.Stacks(entry.Group)) { Accumulate(map3, entry.NameToken, entry.Comfort); if (flag) { Accumulate(map4, entry.NameToken, entry.Comfort); } } else { AccumulateKind(map, entry.Group, entry.NameToken, entry.Comfort); if (flag) { AccumulateKind(map2, entry.Group, entry.NameToken, entry.Comfort); } } } int piecesPerKind = ComfortRules.PiecesPerKind; result.All = 2 + SumTop(map, piecesPerKind) + Sum(map3); result.Unlocked = 2 + SumTop(map2, piecesPerKind) + Sum(map4); if (ComfortRules.Enabled) { int num = Mathf.Max(0, Mathf.Max(RulesConfig.BedComfort.Value, RulesConfig.SittingComfort.Value)); int num2 = Mathf.Max(0, RulesConfig.TrophyComfort.Value); List<string> names = BossTrophies.Names; int num3 = 0; for (int j = 0; j < names.Count; j++) { if (player.IsMaterialKnown(names[j])) { num3++; } } result.All += num + names.Count * num2; result.Unlocked += num + num3 * num2; } result.Valid = true; return result; } private static void AccumulateKind(Dictionary<ComfortGroup, Dictionary<string, int>> map, ComfortGroup group, string name, int value) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (!map.TryGetValue(group, out var value2)) { value2 = (map[group] = new Dictionary<string, int>()); } Accumulate(value2, name ?? string.Empty, value); } private static int SumTop(Dictionary<ComfortGroup, Dictionary<string, int>> map, int perKind) { int num = 0; List<int> list = new List<int>(); foreach (KeyValuePair<ComfortGroup, Dictionary<string, int>> item in map) { list.Clear(); list.AddRange(item.Value.Values); list.Sort(); int num2 = list.Count - 1; int num3 = 0; while (num2 >= 0 && num3 < perKind) { num += list[num2]; num2--; num3++; } } return num; } private static void Accumulate<TKey>(Dictionary<TKey, int> map, TKey key, int value) { if (key != null && (!map.TryGetValue(key, out var value2) || value > value2)) { map[key] = value; } } private static int Sum<TKey>(Dictionary<TKey, int> map) { int num = 0; foreach (KeyValuePair<TKey, int> item in map) { num += item.Value; } return num; } } public static class ComfortGroups { public static readonly ComfortGroup[] Real; private static readonly Dictionary<ComfortGroup, string> Tokens; static ComfortGroups() { ComfortGroup[] array = new ComfortGroup[11]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); Real = (ComfortGroup[])(object)array; Tokens = new Dictionary<ComfortGroup, string>(); Tokens[(ComfortGroup)0] = "$comfortaudit_group_none"; for (int i = 0; i < Real.Length; i++) { Tokens[Real[i]] = "$comfortaudit_group_" + ((object)Unsafe.As<ComfortGroup, ComfortGroup>(ref Real[i])/*cast due to .constrained prefix*/).ToString().ToLowerInvariant(); } Tokens[(ComfortGroup)100] = "$twix_group_trophy"; } public static bool IsKnown(ComfortGroup g) { //