using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Larder.Core; using Larder.Core.Model; using Larder.UI; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("Larder")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("A food planner in the inventory screen: the best three foods you own and the one dish to cook next.")] [assembly: AssemblyFileVersion("0.2.1.0")] [assembly: AssemblyInformationalVersion("0.2.1+491d8ee758fcbc2d21c6a76b4fbc51f6c074b502")] [assembly: AssemblyProduct("Larder")] [assembly: AssemblyTitle("Larder")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.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; } } } internal sealed class ConfigurationManagerAttributes { public int? Order; public bool? IsAdvanced; } namespace Larder { [BepInPlugin("com.jumpingmushroom.larder", "Larder", "0.2.1")] [BepInProcess("valheim.exe")] [BepInProcess("valheim.x86_64")] public sealed class LarderPlugin : BaseUnityPlugin { public const string PluginGuid = "com.jumpingmushroom.larder"; public const string PluginName = "Larder"; public const string PluginVersion = "0.2.1"; internal static ManualLogSource Log; private static readonly HashSet Warned = new HashSet(); private Harmony _harmony; private void Awake() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; PluginConfig.Bind(((BaseUnityPlugin)this).Config); ConsoleCommands.Register(); _harmony = new Harmony("com.jumpingmushroom.larder"); _harmony.PatchAll(typeof(LarderPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Larder 0.2.1 loaded."); } private void Update() { Runtime.Tick(); } private void OnDestroy() { if (_harmony != null) { _harmony.UnpatchSelf(); } } internal static void WarnOnce(string key, Exception e) { if (Warned.Add(key)) { Log.LogWarning((object)(key + ": " + e)); } } } public enum PanelPlacement { Auto, Below, Manual } public static class PluginConfig { public static ConfigEntry Enabled; public static ConfigEntry Radius; public static ConfigEntry ShowUndiscovered; public static ConfigEntry IncludeCartsAndShips; public static ConfigEntry PanelOpen; public static ConfigEntry Placement; public static ConfigEntry ToggleKey; public static ConfigEntry Scale; public static ConfigEntry OffsetX; public static ConfigEntry OffsetY; public static ConfigEntry Verbose; private static ConfigurationManagerAttributes Attr(int order, bool advanced = false) { return new ConfigurationManagerAttributes { Order = order, IsAdvanced = advanced }; } public static void Bind(ConfigFile cfg) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Expected O, but got Unknown //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Expected O, but got Unknown //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Expected O, but got Unknown //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Expected O, but got Unknown //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Expected O, but got Unknown //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Expected O, but got Unknown Enabled = cfg.Bind("General", "Enabled", true, new ConfigDescription("Master switch. Off hides the Larder button and panel.", (AcceptableValueBase)null, new object[1] { Attr(100) })); Radius = cfg.Bind("General", "Radius", 20f, new ConfigDescription("Metres to search for chests, placed feasts and cooking stations.", (AcceptableValueBase)(object)new AcceptableValueRange(5f, 50f), new object[1] { Attr(95) })); ShowUndiscovered = cfg.Bind("General", "ShowUndiscovered", false, new ConfigDescription("Allow cook suggestions for recipes you haven't discovered yet, and name ingredients you haven't seen. Food you own is always shown.", (AcceptableValueBase)null, new object[1] { Attr(90) })); IncludeCartsAndShips = cfg.Bind("General", "IncludeCartsAndShips", true, new ConfigDescription("Count carts and ship holds within range as containers.", (AcceptableValueBase)null, new object[1] { Attr(85) })); PanelOpen = cfg.Bind("UI", "PanelOpen", true, new ConfigDescription("Whether the panel is open. The Larder button toggles this.", (AcceptableValueBase)null, new object[1] { Attr(80) })); Placement = cfg.Bind("UI", "Placement", PanelPlacement.Auto, new ConfigDescription("Where the panel goes. Auto: right of the inventory and anything other mods put beside it. Below: under the chest window (or the inventory when no chest is open). Manual: at OffsetX/OffsetY from the top-left of the screen (negative OffsetY moves down). OffsetX/OffsetY nudge the Auto and Below positions too.", (AcceptableValueBase)null, new object[1] { Attr(79) })); ToggleKey = cfg.Bind("UI", "ToggleKey", KeyboardShortcut.Empty, new ConfigDescription("Optional key that toggles the panel while the inventory is open.", (AcceptableValueBase)null, new object[1] { Attr(78) })); Scale = cfg.Bind("UI", "Scale", 1f, new ConfigDescription("Size of the panel.", (AcceptableValueBase)(object)new AcceptableValueRange(0.6f, 1.6f), new object[1] { Attr(76) })); OffsetX = cfg.Bind("UI", "OffsetX", 0f, new ConfigDescription("Horizontal nudge in pixels (positive is right).", (AcceptableValueBase)(object)new AcceptableValueRange(-1500f, 1500f), new object[1] { Attr(74) })); OffsetY = cfg.Bind("UI", "OffsetY", 0f, new ConfigDescription("Vertical nudge in pixels (positive is up).", (AcceptableValueBase)(object)new AcceptableValueRange(-1000f, 1000f), new object[1] { Attr(72) })); Verbose = cfg.Bind("Logging", "Verbose", false, new ConfigDescription("Log plan timing to the BepInEx log.", (AcceptableValueBase)null, new object[1] { Attr(5, advanced: true) })); } } } namespace Larder.UI { internal sealed class ComboRow { public RectTransform Root; public Image Icon; public TextMeshProUGUI Text; public Button Eat; public string FoodId; public static ComboRow Create(Transform parent, Button template, int index) { //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown ComboRow r = new ComboRow(); r.Root = UiUtil.Rect("Row" + index, parent); HorizontalLayoutGroup obj = ((Component)r.Root).gameObject.AddComponent(); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 8f; ((LayoutGroup)obj).childAlignment = (TextAnchor)3; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false; RectTransform val = UiUtil.Rect("Icon", (Transform)(object)r.Root); r.Icon = ((Component)val).gameObject.AddComponent(); r.Icon.preserveAspect = true; ((Graphic)r.Icon).raycastTarget = false; UiUtil.Size(((Component)val).gameObject, 40f, 40f); r.Text = UiUtil.Text((Transform)(object)r.Root, "Text", 15f, (TextAlignmentOptions)513); ((Component)r.Text).gameObject.AddComponent().flexibleWidth = 1f; r.Eat = UiUtil.Button((Transform)(object)r.Root, "Eat", template, "Eat", (UnityAction)delegate { Eater.Eat(r.FoodId); }); UiUtil.Size(((Component)r.Eat).gameObject, 64f, 30f); ((Component)r.Eat).gameObject.SetActive(false); return r; } } internal static class Eater { public static ItemData FindInBag(Player p, string foodId) { if ((Object)(object)p == (Object)null || string.IsNullOrEmpty(foodId) || FoodCatalog.FeastFood.ContainsKey(foodId)) { return null; } foreach (ItemData allItem in ((Humanoid)p).GetInventory().GetAllItems()) { if (allItem != null && allItem.m_shared != null && allItem.m_shared.m_name == foodId) { return allItem; } } return null; } public static bool CanEatNow(Player p, string foodId) { ItemData val = FindInBag(p, foodId); if (val != null) { return p.CanEat(val, false); } return false; } public static void Eat(string foodId) { try { Player localPlayer = Player.m_localPlayer; ItemData val = FindInBag(localPlayer, foodId); if (val == null) { return; } ((Humanoid)localPlayer).UseItem(((Humanoid)localPlayer).GetInventory(), val, true); } catch (Exception e) { LarderPlugin.WarnOnce("Larder: eat failed", e); } Runtime.Refresh(); } public static void EatAll() { try { Player localPlayer = Player.m_localPlayer; PlanView last = Runtime.Last; if ((Object)(object)localPlayer != (Object)null && last != null && last.Combo.Count > 0) { EatLoop(localPlayer, last.Combo); } } catch (Exception e) { LarderPlugin.WarnOnce("Larder: eat all failed", e); } Runtime.Refresh(); } private static void EatLoop(Player p, List plan) { for (int i = 0; i < 3; i++) { List active = ActiveFoods.Read(p); ISet inBag = StockScanner.BagFoodIds(((Humanoid)p).GetInventory()); List list = EatOrder.Next(plan, active, inBag, Game.m_foodRate); if (list.Count != 0) { string id = list[0].Id; ItemData val = FindInBag(p, id); if (val != null && p.CanEat(val, false)) { int stack = val.m_stack; ((Humanoid)p).UseItem(((Humanoid)p).GetInventory(), val, true); if (((Humanoid)p).GetInventory().ContainsItem(val) && val.m_stack >= stack) { break; } continue; } break; } break; } } } internal static class Format { public const string Hp = "#ff8080"; public const string St = "#ffe080"; public const string Eitr = "#9090ff"; public const string Time = "#ffa040"; public const string Dim = "#b0b0b0"; public const string Good = "#80e080"; public const string Bad = "#ff7070"; public static string C(string color, string text) { return "" + text + ""; } public static string Stats(float hp, float st, float eitr) { string text = C("#ff8080", hp.ToString("0") + " hp") + " " + C("#ffe080", st.ToString("0") + " st"); if (!(eitr > 0f)) { return text; } return text + " " + C("#9090ff", eitr.ToString("0") + " eitr"); } public static string Row(PlannedSlot slot, PlanView v) { FoodStats food = slot.Food; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("").Append(food.Name).Append("\n"); stringBuilder.Append(Stats(food.Health, food.Stamina, food.Eitr)).Append(" ").Append(C("#ffa040", Labels.Duration(food.BurnTime))); string text = Buff(food.Id); if (text != null) { stringBuilder.Append(" ").Append(C("#b0b0b0", "+ " + text)); } stringBuilder.Append("\n").Append(C("#b0b0b0", Where(v.Snapshot, food.Id) + " · " + State(slot))).Append(""); return stringBuilder.ToString(); } public static string State(PlannedSlot slot) { return slot.State switch { SlotState.Active => "active, " + Labels.Duration(slot.Seconds) + " left", SlotState.RefreshNow => C("#80e080", "can refresh now"), SlotState.EatLater => "eat in " + Labels.Duration(slot.Seconds), SlotState.RefreshFirst => "refresh " + FoodCatalog.ItemName(slot.BlockedBy) + " first", _ => C("#80e080", "eat now"), }; } public static string Totals(PlanView v) { return "Plan " + Stats(v.Planned.Health, v.Planned.Stamina, v.Planned.Eitr) + " " + C("#b0b0b0", "regen " + v.Planned.Regen.ToString("0")) + "\n" + C("#b0b0b0", "now " + v.Now.Health.ToString("0") + " hp " + v.Now.Stamina.ToString("0") + " st" + ((v.Now.Eitr > 0f) ? (" " + v.Now.Eitr.ToString("0") + " eitr") : "")) + ""; } public static string Others(PlanView v) { StringBuilder stringBuilder = new StringBuilder(); foreach (OtherFood other in v.Slots.Others) { if (stringBuilder.Length > 0) { stringBuilder.Append('\n'); } stringBuilder.Append(C("#b0b0b0", FoodCatalog.ItemName(other.Id) + " isn't in the plan: " + ((other.SecondsUntilFree <= 0f) ? "replaceable now" : ("slot frees in " + Labels.Duration(other.SecondsUntilFree))))); } return stringBuilder.ToString(); } private static string Where(Snapshot s, string id) { if (s == null || !s.FoodSources.TryGetValue(id, out var value) || value.Count == 0) { return "?"; } foreach (Source item in value) { if (item.Kind != SourceKind.Eaten) { return item.Label; } } return value[0].Label; } private static string Buff(string foodId) { if (!FoodCatalog.Items.TryGetValue(foodId, out var value) || (Object)(object)value.m_shared.m_consumeStatusEffect == (Object)null) { return null; } return FoodCatalog.ItemName(value.m_shared.m_consumeStatusEffect.m_name); } public static string Cook(PlanView v) { if (v.Cook.Ready == null && v.Cook.Almost == null) { if (v.Combo.Count <= 0) { return ""; } return C("#b0b0b0", "Nothing you can cook improves this combo."); } StringBuilder stringBuilder = new StringBuilder(); if (v.Cook.Ready != null) { stringBuilder.Append("Cook next\n"); Suggestion(stringBuilder, v.Cook.Ready, v); } if (v.Cook.Almost != null) { if (stringBuilder.Length > 0) { stringBuilder.Append('\n'); } stringBuilder.Append("If you had…\n"); Suggestion(stringBuilder, v.Cook.Almost, v); } return stringBuilder.ToString(); } private static void Suggestion(StringBuilder sb, CookSuggestion c, PlanView v) { Totals totals = Larder.Core.Model.Totals.Of(c.Combo, v.Planned.Health - Sum(v.Combo, 0), v.Planned.Stamina - Sum(v.Combo, 1)); sb.Append(c.Dish.Food.Name).Append(" → ").Append(Stats(totals.Health, totals.Stamina, totals.Eitr)) .Append(C("#b0b0b0", " (" + Delta(totals.Health - v.Planned.Health, "hp") + Delta(totals.Stamina - v.Planned.Stamina, "st") + Delta(totals.Eitr - v.Planned.Eitr, "eitr") + ")")) .Append('\n'); Producer via = c.Plan.Root.Via; sb.Append("").Append(Station(via, c.Plan.Root.StationMissing)).Append("\n"); Steps(sb, c.Plan.Root, 1); foreach (StationNeed missingStation in c.Plan.MissingStations) { if (missingStation.StationId != via.StationId) { StringBuilder stringBuilder = sb.Append(""); string text = FoodCatalog.StationName(missingStation.StationId); int level = missingStation.Level; stringBuilder.Append(C("#ff7070", "needs " + text + " level " + level)).Append("\n"); } } } private static float Sum(List foods, int stat) { float num = 0f; foreach (FoodStats food in foods) { num += ((stat == 0) ? food.Health : food.Stamina); } return num; } private static string Delta(float d, string unit) { if (d > -0.5f && d < 0.5f) { return ""; } return ((d > 0f) ? "+" : "") + d.ToString("0") + " " + unit + " "; } private static string Station(Producer p, bool missing) { string text = FoodCatalog.StationName(p.StationId); if (p.StationId.Length > 0 && p.StationLevel > 1) { string text2 = text; int stationLevel = p.StationLevel; text = text2 + " level " + stationLevel; } if (!missing) { return C("#80e080", "at " + text); } return C("#ff7070", "at " + text + " (not in range)"); } private static void Steps(StringBuilder sb, CookStep step, int depth) { foreach (CookStep input in step.Inputs) { string color = ((input.Missing > 0) ? "#ff7070" : ((input.Via != null) ? "#ffe080" : "#80e080")); sb.Append("") .Append(C(color, FoodCatalog.ItemName(input.ItemId) + " " + (input.Need - input.Missing) + "/" + input.Need)); if (input.Via != null) { sb.Append(C("#b0b0b0", " make " + (input.Need - input.FromStock) + " " + Station(input.Via, input.StationMissing))); } sb.Append("\n"); if (input.Via != null) { Steps(sb, input, depth + 1); } } } } internal static class LarderPanel { [CompilerGenerated] private static class <>O { public static UnityAction <0>__EatAll; public static UnityAction <1>__Toggle; } private const float Width = 380f; private const float MinBgAlpha = 0.94f; private const float SettleTime = 0.5f; private static readonly Goal[] Goals = new Goal[4] { Goal.Balanced, Goal.Health, Goal.Stamina, Goal.Eitr }; private static readonly Color On = new Color(1f, 0.85f, 0.4f, 1f); private static readonly Color Off = new Color(0.7f, 0.7f, 0.7f, 1f); private static RectTransform _root; private static Button _toggle; private static readonly Button[] Tabs = (Button[])(object)new Button[4]; private static readonly ComboRow[] Rows = new ComboRow[3]; private static Button _eatAll; private static TextMeshProUGUI _eatAllLabel; private static TextMeshProUGUI _totals; private static TextMeshProUGUI _cook; private static TextMeshProUGUI _status; private static bool _hooked; private static InventoryGui _gui; private static float _settleUntil; public static bool Visible { get { if ((Object)(object)_root != (Object)null && ((Component)_root).gameObject.activeSelf) { return InventoryGui.IsVisible(); } return false; } } public static void OnShow(InventoryGui gui) { if ((Object)(object)_root == (Object)null) { Build(gui); } if (!((Object)(object)_root == (Object)null)) { _settleUntil = Time.unscaledTime + 0.5f; ApplyOpen(); } } public static void Toggle() { if (!((Object)(object)_root == (Object)null)) { PluginConfig.PanelOpen.Value = !PluginConfig.PanelOpen.Value; } } private static void ApplyOpen() { if (!((Object)(object)_root == (Object)null)) { bool value = PluginConfig.Enabled.Value; if ((Object)(object)_toggle != (Object)null) { ((Component)_toggle).gameObject.SetActive(value); } ((Component)_root).gameObject.SetActive(value && PluginConfig.PanelOpen.Value); ApplyLayout(); if (Visible) { Runtime.Refresh(); } } } public static void Settle() { if (Visible && Time.unscaledTime < _settleUntil) { ApplyLayout(); } } public static void ApplyLayout() { //IL_0014: 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) if ((Object)(object)_root == (Object)null) { return; } try { ((Transform)_root).localScale = Vector3.one * PluginConfig.Scale.Value; if (Visible && (Object)(object)_gui != (Object)null) { Placement.Apply(_root, _gui, ((Object)(object)_toggle != (Object)null) ? ((Component)_toggle).transform : null); } } catch (Exception e) { LarderPlugin.WarnOnce("Larder: panel layout failed", e); } } public static void ShowError(string message) { try { if ((Object)(object)_status != (Object)null) { ((TMP_Text)_status).text = Format.C("#ff7070", message); } } catch (Exception) { } } private static void Build(InventoryGui gui) { RectTransform player = gui.m_player; if ((Object)(object)player == (Object)null) { LarderPlugin.Log.LogWarning((object)"Larder: no player inventory block to attach to; use the larder console command."); return; } try { BuildInternal(gui, player); _gui = gui; } catch (Exception e) { if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)((Component)_root).gameObject); _root = null; } if ((Object)(object)_toggle != (Object)null) { Object.Destroy((Object)(object)((Component)_toggle).gameObject); _toggle = null; } LarderPlugin.WarnOnce("Larder: panel build failed", e); } } private static void BuildInternal(InventoryGui gui, RectTransform host) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Expected O, but got Unknown //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Expected O, but got Unknown //IL_042e: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_0446: Unknown result type (might be due to invalid IL or missing references) //IL_044d: Unknown result type (might be due to invalid IL or missing references) //IL_0454: Unknown result type (might be due to invalid IL or missing references) //IL_045f: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_0474: Unknown result type (might be due to invalid IL or missing references) //IL_0488: Unknown result type (might be due to invalid IL or missing references) //IL_040f: Unknown result type (might be due to invalid IL or missing references) //IL_0414: Unknown result type (might be due to invalid IL or missing references) //IL_041a: Expected O, but got Unknown Transform inventoryRoot = gui.m_inventoryRoot; RectTransform val = (RectTransform)(object)((inventoryRoot is RectTransform) ? inventoryRoot : null); _root = UiUtil.Rect("LarderPanel", (Transform)(object)(((Object)(object)val != (Object)null) ? val : host)); ((Transform)_root).SetAsLastSibling(); RectTransform root = _root; RectTransform root2 = _root; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); root2.anchorMax = val2; root.anchorMin = val2; _root.pivot = new Vector2(0f, 1f); _root.sizeDelta = new Vector2(380f, 0f); Image val3 = ((Component)_root).gameObject.AddComponent(); Image component = ((Component)host).GetComponent(); if ((Object)(object)component != (Object)null && (Object)(object)component.sprite != (Object)null) { val3.sprite = component.sprite; val3.type = component.type; Color color = ((Graphic)component).color; color.a = Mathf.Max(color.a, 0.94f); ((Graphic)val3).color = color; } else { val3.sprite = UiUtil.White; ((Graphic)val3).color = new Color(0.1f, 0.09f, 0.08f, 0.94f); } VerticalLayoutGroup obj = ((Component)_root).gameObject.AddComponent(); ((LayoutGroup)obj).padding = new RectOffset(14, 14, 12, 12); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 6f; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false; ((Component)_root).gameObject.AddComponent().verticalFit = (FitMode)2; RectTransform val4 = UiUtil.Rect("Goals", (Transform)(object)_root); HorizontalLayoutGroup obj2 = ((Component)val4).gameObject.AddComponent(); ((HorizontalOrVerticalLayoutGroup)obj2).spacing = 4f; ((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true; for (int i = 0; i < Goals.Length; i++) { Goal g = Goals[i]; Tabs[i] = UiUtil.Button((Transform)(object)val4, "Goal" + g, gui.m_craftButton, g.ToString(), (UnityAction)delegate { SetGoal(g); }); UiUtil.Size(((Component)Tabs[i]).gameObject, 80f, 28f); } RectTransform obj3 = UiUtil.Rect("ComboHeader", (Transform)(object)_root); HorizontalLayoutGroup obj4 = ((Component)obj3).gameObject.AddComponent(); ((HorizontalOrVerticalLayoutGroup)obj4).spacing = 8f; ((LayoutGroup)obj4).childAlignment = (TextAnchor)3; ((HorizontalOrVerticalLayoutGroup)obj4).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj4).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandHeight = false; LayoutElement obj5 = ((Component)obj3).gameObject.AddComponent(); float minHeight = (obj5.preferredHeight = 28f); obj5.minHeight = minHeight; TextMeshProUGUI obj6 = UiUtil.Text((Transform)(object)obj3, "ComboHeaderText", 17f, (TextAlignmentOptions)513); ((TMP_Text)obj6).text = "Best combo"; ((Component)obj6).gameObject.AddComponent().flexibleWidth = 1f; Button craftButton = gui.m_craftButton; object obj7 = <>O.<0>__EatAll; if (obj7 == null) { UnityAction val5 = Eater.EatAll; <>O.<0>__EatAll = val5; obj7 = (object)val5; } _eatAll = UiUtil.Button((Transform)(object)obj3, "EatAll", craftButton, "Eat N", (UnityAction)obj7); UiUtil.Size(((Component)_eatAll).gameObject, 72f, 28f); _eatAllLabel = ((Component)_eatAll).GetComponentInChildren(true); ((Component)_eatAll).gameObject.SetActive(false); for (int num2 = 0; num2 < Rows.Length; num2++) { Rows[num2] = ComboRow.Create((Transform)(object)_root, gui.m_craftButton, num2); } _totals = UiUtil.Text((Transform)(object)_root, "Totals", 15f, (TextAlignmentOptions)513); _cook = UiUtil.Text((Transform)(object)_root, "Cook", 14f, (TextAlignmentOptions)257); _status = UiUtil.Text((Transform)(object)_root, "Status", 14f, (TextAlignmentOptions)513); Button craftButton2 = gui.m_craftButton; object obj8 = <>O.<1>__Toggle; if (obj8 == null) { UnityAction val6 = Toggle; <>O.<1>__Toggle = val6; obj8 = (object)val6; } _toggle = UiUtil.Button((Transform)(object)host, "LarderToggle", craftButton2, "Larder", (UnityAction)obj8); RectTransform val7 = (RectTransform)((Component)_toggle).transform; ((Vector2)(ref val2))..ctor(1f, 1f); val7.anchorMax = val2; val7.anchorMin = val2; val7.pivot = new Vector2(1f, 0f); val7.sizeDelta = new Vector2(90f, 30f); val7.anchoredPosition = new Vector2(0f, 4f); if (!_hooked) { _hooked = true; PluginConfig.Enabled.SettingChanged += delegate { ApplyOpen(); }; PluginConfig.PanelOpen.SettingChanged += delegate { ApplyOpen(); }; PluginConfig.Scale.SettingChanged += delegate { ApplyLayout(); }; PluginConfig.OffsetX.SettingChanged += delegate { ApplyLayout(); }; PluginConfig.OffsetY.SettingChanged += delegate { ApplyLayout(); }; PluginConfig.Placement.SettingChanged += delegate { ApplyLayout(); }; PluginConfig.Radius.SettingChanged += delegate { Runtime.RequestRefresh(); }; PluginConfig.ShowUndiscovered.SettingChanged += delegate { Runtime.RequestRefresh(); }; PluginConfig.IncludeCartsAndShips.SettingChanged += delegate { Runtime.RequestRefresh(); }; } } private static void SetGoal(Goal g) { GoalStore.Set(Player.m_localPlayer, g); Runtime.Refresh(); } public static void Render(PlanView v) { //IL_0048: 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) if ((Object)(object)_root == (Object)null || v == null) { return; } for (int i = 0; i < Tabs.Length; i++) { UiUtil.SetLabel(Tabs[i], Goals[i].ToString(), (Goals[i] == v.Goal) ? On : Off); } if (v.Error != null) { ComboRow[] rows = Rows; for (int j = 0; j < rows.Length; j++) { ((Component)rows[j].Root).gameObject.SetActive(false); } ((Component)_eatAll).gameObject.SetActive(false); ((TMP_Text)_totals).text = ""; ((TMP_Text)_cook).text = ""; ((TMP_Text)_status).text = Format.C("#ff7070", "Larder couldn't read the game: " + v.Error); return; } int count = EatOrder.Next(v.Combo, v.Active, v.BagFoods, Game.m_foodRate).Count; ((Component)_eatAll).gameObject.SetActive(count >= 2); if (count >= 2) { ((TMP_Text)_eatAllLabel).text = "Eat " + count; } for (int k = 0; k < Rows.Length; k++) { ComboRow comboRow = Rows[k]; bool flag = k < v.Slots.Planned.Count; ((Component)comboRow.Root).gameObject.SetActive(flag); if (flag) { PlannedSlot plannedSlot = v.Slots.Planned[k]; comboRow.FoodId = plannedSlot.Food.Id; comboRow.Icon.sprite = (FoodCatalog.Items.TryGetValue(plannedSlot.Food.Id, out var value) ? IconOrNull(value) : null); ((TMP_Text)comboRow.Text).text = Format.Row(plannedSlot, v); bool flag2 = plannedSlot.State == SlotState.EatNow || plannedSlot.State == SlotState.RefreshNow; ((Component)comboRow.Eat).gameObject.SetActive(flag2 && Eater.CanEatNow(Player.m_localPlayer, plannedSlot.Food.Id)); } } ((TMP_Text)_totals).text = ((v.Combo.Count > 0) ? Format.Totals(v) : ""); ((TMP_Text)_cook).text = Format.Cook(v); ((TMP_Text)_status).text = ((v.Combo.Count == 0) ? ("No food in your bag or in chests within " + PluginConfig.Radius.Value.ToString("0") + " m.") : Format.Others(v)); } private static Sprite IconOrNull(ItemData item) { SharedData val = item?.m_shared; if (val == null || val.m_icons == null || val.m_icons.Length == 0) { return null; } int num = item.m_variant; if (num < 0 || num >= val.m_icons.Length) { num = 0; } return val.m_icons[num]; } } internal static class Placement { private const float Gap = 24f; private const float Spacing = 12f; private const float MinSize = 8f; private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4]; private static readonly List Graphics = new List(); private static readonly List Candidates = new List(); public static void Apply(RectTransform panel, InventoryGui gui, Transform exclude) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) Transform parent = ((Transform)panel).parent; RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null); Canvas componentInParent = ((Component)panel).GetComponentInParent(); if ((Object)(object)val == (Object)null || (Object)(object)componentInParent == (Object)null || (Object)(object)gui == (Object)null || (Object)(object)gui.m_player == (Object)null) { return; } componentInParent = componentInParent.rootCanvas; Camera val2 = (((int)componentInParent.renderMode == 0) ? null : componentInParent.worldCamera); float num = ((componentInParent.scaleFactor > 0f) ? componentInParent.scaleFactor : 1f); Rect pixelRect = componentInParent.pixelRect; ScreenRect screenRect = ScreenRectOf(gui.m_player, val2); if (!(screenRect.Right - screenRect.Left < 1f) && !(screenRect.Top - screenRect.Bottom < 1f)) { float num2; float num3; switch (PluginConfig.Placement.Value) { case PanelPlacement.Manual: num2 = ((Rect)(ref pixelRect)).xMin; num3 = ((Rect)(ref pixelRect)).yMax; break; case PanelPlacement.Below: { ScreenRect screenRect2 = ScreenRectOf(((Object)(object)gui.m_container != (Object)null && ((Component)gui.m_container).gameObject.activeInHierarchy) ? gui.m_container : gui.m_player, val2); num2 = screenRect2.Left; num3 = screenRect2.Bottom - 12f * num; break; } default: CollectCandidates((Transform)(((Object)(object)gui.m_inventoryRoot != (Object)null) ? ((object)gui.m_inventoryRoot) : ((object)gui.m_player)), panel, exclude, val2, ((Rect)(ref pixelRect)).width); num2 = PlacementMath.ClusterRight(screenRect.Left, screenRect.Right, screenRect.Top, screenRect.Bottom, Candidates, 24f * num) + 12f * num; num3 = screenRect.Top; break; } num2 += PluginConfig.OffsetX.Value * num; num3 += PluginConfig.OffsetY.Value * num; LayoutRebuilder.ForceRebuildLayoutImmediate(panel); ScreenRect screenRect3 = ScreenRectOf(panel, val2); float num4 = screenRect3.Right - screenRect3.Left; float num5 = screenRect3.Top - screenRect3.Bottom; num2 = Mathf.Max(((Rect)(ref pixelRect)).xMin, Mathf.Min(num2, ((Rect)(ref pixelRect)).xMax - num4)); num3 = Mathf.Min(((Rect)(ref pixelRect)).yMax, Mathf.Max(num3, ((Rect)(ref pixelRect)).yMin + num5)); Vector2 val3 = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(val, new Vector2(num2, num3), val2, ref val3)) { ((Transform)panel).localPosition = new Vector3(val3.x, val3.y, ((Transform)panel).localPosition.z); } } } private static void CollectCandidates(Transform root, RectTransform panel, Transform exclude, Camera cam, float screenWidth) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) Candidates.Clear(); Graphics.Clear(); ((Component)root).GetComponentsInChildren(false, Graphics); foreach (Graphic graphic in Graphics) { if ((Object)(object)graphic == (Object)null || !((Behaviour)graphic).enabled || graphic.color.a <= 0.01f || (Object)(object)((Component)graphic).transform == (Object)(object)root) { continue; } TMP_Text val = (TMP_Text)(object)((graphic is TMP_Text) ? graphic : null); if ((Object)(object)val != (Object)null && string.IsNullOrEmpty(val.text)) { continue; } RectTransform rectTransform = graphic.rectTransform; if (!((Transform)rectTransform).IsChildOf((Transform)(object)panel) && (!((Object)(object)exclude != (Object)null) || !((Transform)rectTransform).IsChildOf(exclude))) { ScreenRect item = ScreenRectOf(rectTransform, cam); float num = item.Right - item.Left; if (!(num < 8f) && !(item.Top - item.Bottom < 8f) && !(num > screenWidth * 0.5f)) { Candidates.Add(item); } } } Graphics.Clear(); } private static ScreenRect ScreenRectOf(RectTransform rt, Camera cam) { //IL_0030: 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_003a: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) rt.GetWorldCorners(Corners); float num = float.MaxValue; float num2 = float.MinValue; float num3 = float.MinValue; float num4 = float.MaxValue; for (int i = 0; i < 4; i++) { Vector2 val = RectTransformUtility.WorldToScreenPoint(cam, Corners[i]); num = Mathf.Min(num, val.x); num2 = Mathf.Max(num2, val.x); num3 = Mathf.Max(num3, val.y); num4 = Mathf.Min(num4, val.y); } return new ScreenRect(num, num2, num3, num4); } } internal static class UiUtil { private static Sprite _white; public static Sprite White { get { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_white != (Object)null) { return _white; } Texture2D val = new Texture2D(4, 4, (TextureFormat)4, false); Color32[] array = (Color32[])(object)new Color32[16]; for (int i = 0; i < array.Length; i++) { array[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); } val.SetPixels32(array); val.Apply(); ((Object)val).hideFlags = (HideFlags)61; _white = Sprite.Create(val, new Rect(0f, 0f, 4f, 4f), new Vector2(0.5f, 0.5f), 4f); ((Object)_white).hideFlags = (HideFlags)61; return _white; } } public static TMP_FontAsset Font { get { InventoryGui instance = InventoryGui.instance; TMP_Text val = (((Object)(object)instance != (Object)null && (Object)(object)instance.m_craftButton != (Object)null) ? ((Component)instance.m_craftButton).GetComponentInChildren(true) : null); if ((Object)(object)val != (Object)null) { return val.font; } if (!((Object)(object)Hud.instance != (Object)null) || !((Object)(object)Hud.instance.m_healthText != (Object)null)) { return null; } return Hud.instance.m_healthText.font; } } public static RectTransform Rect(string name, Transform parent) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }) { layer = ((Component)parent).gameObject.layer }.transform; ((Transform)val).SetParent(parent, false); return val; } public static void Stretch(RectTransform rt) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = Vector2.zero; rt.offsetMax = Vector2.zero; } public static void Size(GameObject go, float w, float h) { LayoutElement val = go.GetComponent(); if ((Object)(object)val == (Object)null) { val = go.AddComponent(); } LayoutElement obj = val; float minWidth = (val.preferredWidth = w); obj.minWidth = minWidth; LayoutElement obj2 = val; minWidth = (val.preferredHeight = h); obj2.minHeight = minWidth; } public static TextMeshProUGUI Text(Transform parent, string name, float size, TextAlignmentOptions align) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) RectTransform obj = Rect(name, parent); ((Component)obj).gameObject.SetActive(false); TextMeshProUGUI val = ((Component)obj).gameObject.AddComponent(); TMP_FontAsset font = Font; if ((Object)(object)font != (Object)null) { ((TMP_Text)val).font = font; } ((Component)obj).gameObject.SetActive(true); ((TMP_Text)val).fontSize = size; ((TMP_Text)val).alignment = align; ((TMP_Text)val).textWrappingMode = (TextWrappingModes)1; ((TMP_Text)val).richText = true; ((Graphic)val).raycastTarget = false; ((Graphic)val).color = new Color(0.9f, 0.9f, 0.9f, 1f); return val; } public static Button Button(Transform parent, string name, Button template, string label, UnityAction onClick) { //IL_0075: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) RectTransform obj = Rect(name, parent); Image val = ((Component)obj).gameObject.AddComponent(); Image val2 = (((Object)(object)template != (Object)null) ? ((Component)template).GetComponent() : null); if ((Object)(object)val2 != (Object)null) { val.sprite = val2.sprite; val.type = val2.type; ((Graphic)val).color = ((Graphic)val2).color; } else { val.sprite = White; ((Graphic)val).color = new Color(0.3f, 0.25f, 0.2f, 0.9f); } Button val3 = ((Component)obj).gameObject.AddComponent