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 VikingNutrition v0.1.0
VikingNutrition.dll
Decompiled 15 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.IO; 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 Microsoft.CodeAnalysis; using UnityEngine; using VikingLib.Configuration; using VikingLib.Stats; using VikingLib.UI.Hub; using VikingLib.UI.Hub.Core; using VikingLib.UI.Hub.Rendering; using VikingNutrition.Achievements; using VikingNutrition.Config; using VikingNutrition.Core; using VikingNutrition.Data; using VikingNutrition.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("DigitalVikings")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0")] [assembly: AssemblyProduct("VikingNutrition")] [assembly: AssemblyTitle("VikingNutrition")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace VikingNutrition { [BepInPlugin("com.digitalvikings.vikingnutrition", "VikingNutrition", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string ModGuid = "com.digitalvikings.vikingnutrition"; public const string ModName = "VikingNutrition"; public const string ModVersion = "0.1.0"; private Harmony? _harmony; private NutritionFoodBaseModifier? _foodBaseModifier; private NutritionHubTab? _nutritionHubTab; private bool _openedInventoryForHotkey; public static ManualLogSource Log { get; private set; } private void Awake() { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; ModConfig.Init(((BaseUnityPlugin)this).Config); ModConfig.OnConfigChanged += HandleConfigChanged; FoodCatalog.Initialize(); AchievementManager.Initialize(); _foodBaseModifier = new NutritionFoodBaseModifier(); FoodModifierRegistry.Register((IFoodBaseModifier)(object)_foodBaseModifier, 0); _nutritionHubTab = new NutritionHubTab(); SyncHubTabRegistration(); CharacterStatsHubTab.OnCollectVitalSources += HandleCollectVitalSources; _harmony = new Harmony("com.digitalvikings.vikingnutrition"); _harmony.PatchAll(); Log.LogInfo((object)string.Format("[{0}] v{1} initialized ({2} curated foods, {3} achievements loaded).", "VikingNutrition", "0.1.0", FoodCatalog.Count, AchievementCatalog.Count)); } private void Update() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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) if (ModConfig.Enabled == null || !ModConfig.Enabled.Value || ModConfig.HubHotkey == null) { return; } KeyCode value = ModConfig.HubHotkey.Value; if ((int)value == 0 || !Input.GetKeyDown(value) || (Object)(object)Player.m_localPlayer == (Object)null || ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || TextInput.IsVisible() || Menu.IsVisible() || Minimap.IsOpen()) { return; } if (VikingHubRegistry.IsOpen) { if (string.Equals(VikingHubRegistry.ActiveTabId, "nutrition", StringComparison.OrdinalIgnoreCase)) { VikingHubRegistry.CloseHub(); if (_openedInventoryForHotkey) { _openedInventoryForHotkey = false; InventoryGui instance = InventoryGui.instance; if (instance != null) { instance.Hide(); } } } else { VikingHubRegistry.SwitchTab("nutrition"); } } else { if (!InventoryGui.IsVisible() && (Object)(object)InventoryGui.instance != (Object)null) { InventoryGui.instance.Show((Container)null, 1); _openedInventoryForHotkey = true; } else { _openedInventoryForHotkey = false; } VikingHubRegistry.OpenHub("nutrition"); } } private void OnDestroy() { CharacterStatsHubTab.OnCollectVitalSources -= HandleCollectVitalSources; ModConfig.OnConfigChanged -= HandleConfigChanged; VikingHubRegistry.UnregisterTab("nutrition"); _nutritionHubTab?.Dispose(); _nutritionHubTab = null; AchievementManager.Shutdown(); if (_foodBaseModifier != null) { FoodModifierRegistry.Unregister((IFoodBaseModifier)(object)_foodBaseModifier); _foodBaseModifier = null; } if ((Object)(object)Player.m_localPlayer != (Object)null) { NutritionManager.ClearAllNutritionModifiers(Player.m_localPlayer); } Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; } private void SyncHubTabRegistration() { if (_nutritionHubTab != null) { if (ModConfig.Enabled.Value) { VikingHubRegistry.RegisterTab((IVikingHubTab)(object)_nutritionHubTab); } else { VikingHubRegistry.UnregisterTab("nutrition"); } } } private static void HandleCollectVitalSources(Player player, string vitalKey, List<StatBreakdownEntry> entries) { //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Expected O, but got Unknown if ((Object)(object)player == (Object)null || !ModConfig.Enabled.Value) { return; } float num = 0f; IReadOnlyList<LongTermEchoEntry> activeEchoes = NutritionManager.GetActiveEchoes(player); Dictionary<CharacterStatType, float> dictionary = new Dictionary<CharacterStatType, float>(); Dictionary<CharacterStatType, float> resistanceMultipliers = new Dictionary<CharacterStatType, float>(); AchievementManager.CollectActiveBonuses(player, dictionary, resistanceMultipliers); string arg; switch (vitalKey) { default: return; case "Health": { arg = "HP"; if (ModConfig.EnableLongHorizonEchoes.Value) { for (int j = 0; j < activeEchoes.Count; j++) { num += activeEchoes[j].LiveHealth; } } if (dictionary.TryGetValue((CharacterStatType)0, out var value2)) { num += value2; } break; } case "Stamina": { arg = "pts"; if (ModConfig.EnableLongHorizonEchoes.Value) { for (int k = 0; k < activeEchoes.Count; k++) { num += activeEchoes[k].LiveStamina; } } if (dictionary.TryGetValue((CharacterStatType)1, out var value3)) { num += value3; } break; } case "Eitr": { arg = "pts"; if (ModConfig.EnableLongHorizonEchoes.Value) { for (int i = 0; i < activeEchoes.Count; i++) { num += activeEchoes[i].LiveEitr; } } if (dictionary.TryGetValue((CharacterStatType)2, out var value)) { num += value; } break; } } if (num >= 0.05f) { entries.Add(new StatBreakdownEntry("Nourishment", $"+{num:F0} {arg}", "positive")); } } private void HandleConfigChanged() { SyncHubTabRegistration(); Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { NutritionManager.ForceRefresh(localPlayer); if (ModConfig.Enabled.Value && ModConfig.EnableAchievements.Value) { AchievementManager.EvaluatePlayer(localPlayer, allowToasts: false); } else { AchievementManager.ClearModifiers(localPlayer); } } if (VikingHubRegistry.IsOpen) { VikingHubRegistry.RefreshActiveTab(); } } } } namespace VikingNutrition.UI { public sealed class NutritionHubTab : IStructuredHubTab, IVikingHubTab, IDisposable { private enum SubView { Ledger, Achievements } public const string TabId = "nutrition"; private static Sprite? _hubIcon; private SubView _activeSubView; private readonly Dictionary<CharacterStatType, float> _combinedAdditive = new Dictionary<CharacterStatType, float>(); private readonly Dictionary<CharacterStatType, float> _combinedResistMult = new Dictionary<CharacterStatType, float>(); public string Id => "nutrition"; public string DisplayName => "Nutrition"; public int SortOrder => 30; public Sprite? HubIcon => _hubIcon ?? (_hubIcon = VikingHubTheme.LoadEmbeddedSprite(typeof(NutritionHubTab).Assembly, "hub_nutrition.png")); public HubPortalSummary GetPortalSummary() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { IReadOnlyList<ActiveMealSnapshot> activeMeals = NutritionManager.GetActiveMeals(localPlayer); IReadOnlyList<LongTermEchoEntry> activeEchoes = NutritionManager.GetActiveEchoes(localPlayer); int uniqueDigestedCount = NutritionManager.GetUniqueDigestedCount(localPlayer); List<HubPortalPip> list = new List<HubPortalPip>(3); for (int i = 0; i < 3; i++) { bool flag = i < activeMeals.Count; string text = (flag ? activeMeals[i].DisplayName : $"Slot {i + 1}"); list.Add(new HubPortalPip(text, flag, flag ? "positive" : null)); } string arg = ((uniqueDigestedCount == 1) ? "Unique Dish" : "Unique Dishes"); return new HubPortalSummary($"{activeMeals.Count}/3 Active Meals • {uniqueDigestedCount} {arg}", (activeEchoes.Count > 0) ? $"{activeEchoes.Count} Nourishment" : null, "Active meals, nourishment & culinary achievements.", (IReadOnlyList<HubPortalPip>)list); } return new HubPortalSummary("No active character", (string)null, "Active meals, nourishment & culinary achievements.", (IReadOnlyList<HubPortalPip>)null); } public HubView BuildView(HubViewContext ctx) { //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_0024: 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_006c: Expected O, but got Unknown //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Expected O, but got Unknown //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: 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_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Expected O, but got Unknown HubView val = new HubView { ViewTitle = "Nutrition", ShowBackToHub = true }; Player localPlayer = Player.m_localPlayer; int count = AchievementCatalog.Count; int num = (((Object)(object)localPlayer != (Object)null) ? AchievementManager.GetUnlockedCount(localPlayer) : 0); IReadOnlyList<ActiveMealSnapshot> activeMeals = NutritionManager.GetActiveMeals(localPlayer); IReadOnlyList<LongTermEchoEntry> activeEchoes = NutritionManager.GetActiveEchoes(localPlayer); int uniqueDigestedCount = NutritionManager.GetUniqueDigestedCount(localPlayer); SubTabBarNode val2 = new SubTabBarNode(); ((HubNode)val2).Id = "NutritionSubTabs"; val2.SummaryText = (((Object)(object)localPlayer == (Object)null) ? "No active character" : string.Format("{0}/3 Active • {1} Nourishment • {2} {3}", activeMeals.Count, activeEchoes.Count, uniqueDigestedCount, (uniqueDigestedCount == 1) ? "Unique Dish" : "Unique Dishes")); val2.OnTabSelected = delegate(string tabId) { SubView subView = (string.Equals(tabId, "achievements", StringComparison.OrdinalIgnoreCase) ? SubView.Achievements : SubView.Ledger); if (_activeSubView != subView) { _activeSubView = subView; ctx.ActiveCategory = "all"; } }; SubTabBarNode val3 = val2; val3.Tabs.Add(new FilterChip("ledger", "Nourishment Ledger", _activeSubView == SubView.Ledger)); val3.Tabs.Add(new FilterChip("achievements", $"Achievements ({num}/{count})", _activeSubView == SubView.Achievements)); HubNode second = ((_activeSubView == SubView.Ledger) ? BuildLedgerView(localPlayer, activeMeals, activeEchoes) : BuildAchievementsView(localPlayer, ctx)); val.Root = (HubNode)new SplitPaneNode { Id = "NutritionRoot", Horizontal = false, SplitRatio = 0.001f, First = (HubNode)(object)val3, Second = second }; return val; } public void BuildContent(RectTransform container) { } public void OnShow() { } public void OnHide() { } public void OnRefresh() { } public bool HandleBack() { return false; } public void Dispose() { } private HubNode BuildLedgerView(Player? player, IReadOnlyList<ActiveMealSnapshot> activeMeals, IReadOnlyList<LongTermEchoEntry> activeEchoes) { //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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown //IL_00d1: 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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown ScrollColumnNode val = new ScrollColumnNode { Id = "LedgerScroll", ItemGap = 14f }; val.Children.Add((HubNode)(object)BuildActiveMealsCard(activeMeals)); val.Children.Add((HubNode)(object)BuildNourishmentBonusesCard(player, activeEchoes)); CardNode val2 = new CardNode { Id = "ActiveNourishmentCard", Title = "Active Nourishment", HeaderBadge = (ModConfig.EnableLongHorizonEchoes.Value ? $"{activeEchoes.Count}" : null) }; if (!ModConfig.EnableLongHorizonEchoes.Value) { val2.Children.Add((HubNode)new TextNode("Long-term nourishment is currently disabled in server configuration.", (TextStyle)5, (TextAlign)0)); } else if (activeEchoes.Count == 0) { val2.Children.Add((HubNode)new TextNode("Eat prepared meals past their digestion gate to build long-term nourishment.", (TextStyle)5, (TextAlign)0)); } else { BentoGridNode val3 = new BentoGridNode { Id = "EchoesBento", Columns = 5 }; for (int i = 0; i < activeEchoes.Count; i++) { val3.Items.Add((HubNode)(object)BuildEchoTile(activeEchoes[i])); } val2.Children.Add((HubNode)(object)val3); } val.Children.Add((HubNode)(object)val2); return (HubNode)(object)val; } private static CardNode BuildActiveMealsCard(IReadOnlyList<ActiveMealSnapshot> activeMeals) { //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_0010: 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_0037: Expected O, but got Unknown //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Expected O, but got Unknown //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Expected O, but got Unknown //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_020d: 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_0225: Expected O, but got Unknown //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_0296: 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) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Expected O, but got Unknown CardNode val = new CardNode { Id = "ActiveMealsCard", Title = "Active Meals", HeaderBadge = $"{activeMeals.Count}/3" }; BentoGridNode val2 = new BentoGridNode { Id = "ActiveMealsGrid", Columns = 3 }; for (int i = 0; i < 3; i++) { if (i < activeMeals.Count) { ActiveMealSnapshot activeMealSnapshot = activeMeals[i]; string text = null; if ((Object)(object)activeMealSnapshot.Icon != (Object)null) { text = $"vn_food_{i}_{activeMealSnapshot.DisplayName}"; HubSpriteAtlas.RegisterExternalSprite(text, activeMealSnapshot.Icon); } string label; string toneKey; if (FoodCatalog.GetEffectiveLongTermStrength(activeMealSnapshot.Profile) <= 0.0001f) { label = (activeMealSnapshot.IsEchoLocked ? "No Nourishment • Digested" : "No Nourishment"); toneKey = "weight"; } else if (activeMealSnapshot.IsEchoLocked) { label = "✓ Nourishment Locked"; toneKey = "eitr"; } else { label = "Digestion"; toneKey = "stamina"; } SelectableCardNode val3 = new SelectableCardNode { Id = $"MealSlot_{i}", IconKey = text, Title = activeMealSnapshot.DisplayName, AlertBadge = NutritionStatHelper.FormatDuration(activeMealSnapshot.TimeRemaining), MinHeight = 104f }; float num = (activeMealSnapshot.IsEchoLocked ? 1f : activeMealSnapshot.DigestionGateProgress); val3.Children.Add((HubNode)new ProgressBarNode { Id = $"MealBar_{i}", Label = label, Value = num, Max = 1f, ValueText = $"{Mathf.RoundToInt(num * 100f)}%", ToneKey = toneKey }); string value = FormatVitalsCompact(activeMealSnapshot.EffectiveHealth, activeMealSnapshot.EffectiveStamina, activeMealSnapshot.EffectiveEitr, useDecimals: false); val3.Children.Add((HubNode)new StatRowNode { Id = $"MealVitals_{i}", Label = "Vitals", Value = value }); if (ModConfig.EnableSignatureStats.Value && activeMealSnapshot.SignatureStat.HasValue && Mathf.Abs(activeMealSnapshot.LiveSignatureValue) > 0.0001f) { val3.Children.Add((HubNode)new StatRowNode { Id = $"MealSig_{i}", Label = NutritionStatHelper.GetDisplayName(activeMealSnapshot.SignatureStat.Value), Value = NutritionStatHelper.FormatStatValueOnly(activeMealSnapshot.SignatureStat.Value, activeMealSnapshot.LiveSignatureValue), Highlight = true, ToneKey = "positive" }); } val2.Items.Add((HubNode)(object)val3); } else { val2.Items.Add((HubNode)new SelectableCardNode { Id = $"MealSlotEmpty_{i}", Title = $"Slot {i + 1} — Empty", IsDimmed = true, MinHeight = 104f }); } } val.Children.Add((HubNode)(object)val2); return val; } private CardNode BuildNourishmentBonusesCard(Player? player, IReadOnlyList<LongTermEchoEntry> activeEchoes) { //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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0159: 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_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_018a: 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_01a1: Expected O, but got Unknown //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Expected O, but got Unknown //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Expected O, but got Unknown //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Invalid comparison between Unknown and I4 //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Invalid comparison between Unknown and I4 //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0380: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Expected O, but got Unknown //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Expected O, but got Unknown CardNode val = new CardNode { Id = "NourishmentBonusesCard", Title = "Long-Term Nourishment Bonuses" }; _combinedAdditive.Clear(); _combinedResistMult.Clear(); if (ModConfig.EnableLongHorizonEchoes.Value) { bool value = ModConfig.EnableSignatureStats.Value; for (int i = 0; i < activeEchoes.Count; i++) { LongTermEchoEntry longTermEchoEntry = activeEchoes[i]; if (longTermEchoEntry.LiveHealth > 0.001f) { AccumulateCombinedStat((CharacterStatType)0, longTermEchoEntry.LiveHealth); } if (longTermEchoEntry.LiveStamina > 0.001f) { AccumulateCombinedStat((CharacterStatType)1, longTermEchoEntry.LiveStamina); } if (longTermEchoEntry.LiveEitr > 0.001f) { AccumulateCombinedStat((CharacterStatType)2, longTermEchoEntry.LiveEitr); } if (value && longTermEchoEntry.SignatureStat.HasValue && Mathf.Abs(longTermEchoEntry.LiveSignatureValue) > 0.0001f) { AccumulateCombinedStat(longTermEchoEntry.SignatureStat.Value, longTermEchoEntry.LiveSignatureValue); } } } AchievementManager.CollectActiveBonuses(player, _combinedAdditive, _combinedResistMult); _combinedAdditive.TryGetValue((CharacterStatType)0, out var value2); _combinedAdditive.TryGetValue((CharacterStatType)1, out var value3); _combinedAdditive.TryGetValue((CharacterStatType)2, out var value4); if (value2 > 0.05f) { val.Children.Add((HubNode)new StatRowNode { Id = "Bonus_HP", Label = "Bonus Health", Value = $"+{value2:0.#} HP", Highlight = true, ToneKey = "positive" }); } if (value3 > 0.05f) { val.Children.Add((HubNode)new StatRowNode { Id = "Bonus_Stam", Label = "Bonus Stamina", Value = $"+{value3:0.#} pts", Highlight = true, ToneKey = "positive" }); } if (value4 > 0.05f) { val.Children.Add((HubNode)new StatRowNode { Id = "Bonus_Eitr", Label = "Bonus Eitr", Value = $"+{value4:0.#} pts", Highlight = true, ToneKey = "positive" }); } List<(string, string)> list = new List<(string, string)>(); foreach (KeyValuePair<CharacterStatType, float> item in _combinedAdditive) { if ((int)item.Key != 0 && (int)item.Key != 1 && (int)item.Key != 2 && !(Mathf.Abs(item.Value) <= 0.0005f)) { list.Add((NutritionStatHelper.GetDisplayName(item.Key), NutritionStatHelper.FormatStatValueOnly(item.Key, item.Value))); } } foreach (KeyValuePair<CharacterStatType, float> item2 in _combinedResistMult) { float num = 1f - item2.Value; if (!(num <= 0.0005f)) { list.Add((NutritionStatHelper.GetDisplayName(item2.Key), NutritionStatHelper.FormatStatValueOnly(item2.Key, num))); } } list.Sort(((string Label, string Value) a, (string Label, string Value) b) => string.Compare(a.Label, b.Label, StringComparison.OrdinalIgnoreCase)); for (int num2 = 0; num2 < list.Count; num2++) { val.Children.Add((HubNode)new StatRowNode { Id = $"Bonus_Stat_{num2}", Label = list[num2].Item1, Value = list[num2].Item2, Highlight = true, ToneKey = "positive" }); } if (val.Children.Count == 0) { val.Children.Add((HubNode)new TextNode("No long-term bonuses active yet. Digest meals past their nourishment gate or unlock culinary achievements to earn permanent bonuses.", (TextStyle)5, (TextAlign)0)); } return val; } private static SelectableCardNode BuildEchoTile(LongTermEchoEntry entry) { //IL_003b: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: 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_0113: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Expected O, but got Unknown //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Expected O, but got Unknown string localizedFoodName = NutritionManager.GetLocalizedFoodName(entry.PrefabName); string text = null; Sprite foodIcon = NutritionManager.GetFoodIcon(entry.PrefabName); if ((Object)(object)foodIcon != (Object)null) { text = "vn_echo_" + entry.PrefabName; HubSpriteAtlas.RegisterExternalSprite(text, foodIcon); } SelectableCardNode val = new SelectableCardNode { Id = "Echo_" + entry.PrefabName, IconKey = text, Title = localizedFoodName, AlertBadge = NutritionStatHelper.FormatDuration(entry.RemainingTime) }; if (entry.LiveHealth >= 0.05f) { val.Children.Add((HubNode)new StatRowNode { Id = "EchoHP_" + entry.PrefabName, Label = "Health", Value = $"+{entry.LiveHealth:0.0} HP", ToneKey = "positive" }); } if (entry.LiveStamina >= 0.05f) { val.Children.Add((HubNode)new StatRowNode { Id = "EchoStam_" + entry.PrefabName, Label = "Stamina", Value = $"+{entry.LiveStamina:0.0} pts", ToneKey = "positive" }); } if (entry.LiveEitr >= 0.05f) { val.Children.Add((HubNode)new StatRowNode { Id = "EchoEitr_" + entry.PrefabName, Label = "Eitr", Value = $"+{entry.LiveEitr:0.0} pts", ToneKey = "positive" }); } if (ModConfig.EnableSignatureStats.Value && entry.SignatureStat.HasValue && Mathf.Abs(entry.LiveSignatureValue) >= 0.0005f) { val.Children.Add((HubNode)new StatRowNode { Id = "EchoSig_" + entry.PrefabName, Label = NutritionStatHelper.GetDisplayName(entry.SignatureStat.Value), Value = NutritionStatHelper.FormatStatValueOnly(entry.SignatureStat.Value, entry.LiveSignatureValue), Highlight = true, ToneKey = "positive" }); } return val; } private static HubNode BuildAchievementsView(Player? player, HubViewContext ctx) { //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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Expected O, but got Unknown //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Expected O, but got Unknown //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Expected O, but got Unknown //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Expected O, but got Unknown //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Expected O, but got Unknown //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Expected O, but got Unknown //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Expected O, but got Unknown //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Expected O, but got Unknown FilterBarNode val = new FilterBarNode { Id = "AchFilterBar", ShowSearch = false, Placeholder = string.Empty }; string activeCategory = ctx.ActiveCategory; val.Chips.Add(new FilterChip("all", "All", IsCat(activeCategory, "all"))); val.Chips.Add(new FilterChip("unlocked", "Unlocked", IsCat(activeCategory, "unlocked"))); val.Chips.Add(new FilterChip("biomes", "Biomes", IsCat(activeCategory, "biomes"))); val.Chips.Add(new FilterChip("culinary", "Culinary Sets", IsCat(activeCategory, "culinary"))); val.Chips.Add(new FilterChip("milestones", "Milestones", IsCat(activeCategory, "milestones"))); val.Chips.Add(new FilterChip("iconic", "Iconic", IsCat(activeCategory, "iconic"))); ScrollColumnNode val2 = new ScrollColumnNode { Id = "AchievementsScroll", ItemGap = 12f }; if (!ModConfig.EnableAchievements.Value) { CardNode val3 = new CardNode { Id = "AchDisabled", Title = "Culinary Achievements" }; val3.Children.Add((HubNode)new TextNode("Spice of Life Achievements are currently disabled in server configuration.", (TextStyle)5, (TextAlign)0)); val2.Children.Add((HubNode)(object)val3); } else { List<AchievementProgress> allProgress = AchievementManager.GetAllProgress(player); float value = ModConfig.AchievementRewardScale.Value; BentoGridNode val4 = new BentoGridNode { Id = "AchievementsBento", Columns = 2 }; for (int i = 0; i < allProgress.Count; i++) { AchievementProgress progress = allProgress[i]; if (MatchesAchievementFilter(progress, activeCategory)) { val4.Items.Add((HubNode)(object)BuildAchievementCard(progress, value)); } } if (val4.Items.Count == 0) { CardNode val5 = new CardNode { Id = "AchEmpty", Title = "Culinary Achievements" }; val5.Children.Add((HubNode)new TextNode("No achievements match the selected filter.", (TextStyle)5, (TextAlign)0)); val2.Children.Add((HubNode)(object)val5); } else { val2.Children.Add((HubNode)(object)val4); } } return (HubNode)new SplitPaneNode { Id = "AchievementsRoot", Horizontal = false, SplitRatio = 0.001f, First = (HubNode)(object)val, Second = (HubNode)(object)val2 }; } private static CardNode BuildAchievementCard(AchievementProgress progress, float rewardScale) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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_0053: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0245: 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_00d8: 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_025f: Expected O, but got Unknown //IL_0129: Expected O, but got Unknown //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0280: 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_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Expected O, but got Unknown //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Expected O, but got Unknown AchievementDefinition definition = progress.Definition; bool isUnlocked = progress.IsUnlocked; string headerBadge = (isUnlocked ? "UNLOCKED" : AchievementCatalog.GetCategoryShortTag(definition.Category)); CardNode val = new CardNode { Id = "Ach_" + definition.Id, Title = definition.Title, HeaderBadge = headerBadge }; val.Children.Add((HubNode)new TextNode(definition.FormatDescription(), (TextStyle)5, (TextAlign)0)); if (progress.HasSecondaryRequirement) { val.Children.Add((HubNode)new ProgressBarNode { Id = "AchPrimary_" + definition.Id, Label = "Servings", Value = (isUnlocked ? progress.PrimaryTarget : Mathf.Min(progress.PrimaryCurrent, progress.PrimaryTarget)), Max = Mathf.Max(1, progress.PrimaryTarget), ValueText = $"{Mathf.Min(progress.PrimaryCurrent, progress.PrimaryTarget)} / {progress.PrimaryTarget} {progress.PrimaryUnit}", ToneKey = (isUnlocked ? "eitr" : "stamina") }); val.Children.Add((HubNode)new ProgressBarNode { Id = "AchSecondary_" + definition.Id, Label = "Unique Dishes", Value = (isUnlocked ? progress.SecondaryTarget : Mathf.Min(progress.SecondaryCurrent, progress.SecondaryTarget)), Max = Mathf.Max(1, progress.SecondaryTarget), ValueText = $"{Mathf.Min(progress.SecondaryCurrent, progress.SecondaryTarget)} / {progress.SecondaryTarget} {progress.SecondaryUnit}", ToneKey = "eitr" }); } else { val.Children.Add((HubNode)new ProgressBarNode { Id = "AchPrimary_" + definition.Id, Label = "Progress", Value = (isUnlocked ? progress.PrimaryTarget : Mathf.Min(progress.PrimaryCurrent, progress.PrimaryTarget)), Max = Mathf.Max(1, progress.PrimaryTarget), ValueText = progress.ProgressSummary, ToneKey = (isUnlocked ? "eitr" : "stamina") }); } val.Children.Add((HubNode)new StatRowNode { Id = "AchReward_" + definition.Id, Label = (isUnlocked ? "Active Bonus" : "Reward"), Value = definition.FormatRewardsSummary(rewardScale), Highlight = isUnlocked, ToneKey = (isUnlocked ? "positive" : "accent") }); if (!string.IsNullOrWhiteSpace(progress.HintText)) { val.Children.Add((HubNode)new TextNode(progress.HintText, (TextStyle)4, (TextAlign)0)); } return val; } private void AccumulateCombinedStat(CharacterStatType stat, float magnitude) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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_003e: Unknown result type (might be due to invalid IL or missing references) if (NutritionStatHelper.IsResistanceStat(stat)) { float value; float num = (_combinedResistMult.TryGetValue(stat, out value) ? value : 1f); float num2 = Mathf.Clamp(1f - magnitude, 0.2f, 1f); _combinedResistMult[stat] = num * num2; } else { _combinedAdditive.TryGetValue(stat, out var value2); _combinedAdditive[stat] = value2 + magnitude; } } private static bool MatchesAchievementFilter(AchievementProgress progress, string filter) { if (IsCat(filter, "all")) { return true; } if (IsCat(filter, "unlocked")) { return progress.IsUnlocked; } return filter.ToLowerInvariant() switch { "biomes" => progress.Definition.Category == AchievementCategory.Biomes, "culinary" => progress.Definition.Category == AchievementCategory.CulinarySets, "milestones" => progress.Definition.Category == AchievementCategory.Milestones, "iconic" => progress.Definition.Category == AchievementCategory.Iconic, _ => true, }; } private static bool IsCat(string active, string candidate) { return string.Equals(active, candidate, StringComparison.OrdinalIgnoreCase); } private static string FormatVitalsCompact(float hp, float stam, float eitr, bool useDecimals) { List<string> list = new List<string>(3); if (hp >= 0.05f) { list.Add(useDecimals ? $"+{hp:0.0} HP" : $"+{Mathf.RoundToInt(hp)} HP"); } if (stam >= 0.05f) { list.Add(useDecimals ? $"+{stam:0.0} Stam" : $"+{Mathf.RoundToInt(stam)} Stam"); } if (eitr >= 0.05f) { list.Add(useDecimals ? $"+{eitr:0.0} Eitr" : $"+{Mathf.RoundToInt(eitr)} Eitr"); } if (list.Count <= 0) { return "No active pools"; } return string.Join(" • ", list); } } } namespace VikingNutrition.Patches { [HarmonyPatch] public static class NutritionPatches { [HarmonyPatch(typeof(ObjectDB), "Awake")] [HarmonyPostfix] public static void PostfixObjectDBAwake(ObjectDB __instance) { FoodCatalog.ScanObjectDB(__instance); } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] [HarmonyPostfix] public static void PostfixObjectDBCopyOtherDB(ObjectDB __instance) { FoodCatalog.ScanObjectDB(__instance); } [HarmonyPatch(typeof(Player), "UpdateFood", new Type[] { typeof(float), typeof(bool) })] [HarmonyPostfix] public static void PostfixPlayerUpdateFood(Player __instance, float dt, bool forceUpdate) { NutritionManager.OnUpdateFood(__instance, dt, forceUpdate); } [HarmonyPatch(typeof(Player), "EatFood", new Type[] { typeof(ItemData) })] [HarmonyPrefix] public static void PrefixPlayerEatFood(Player __instance) { NutritionManager.OnBeforeEatFood(__instance); } [HarmonyPatch(typeof(Player), "EatFood", new Type[] { typeof(ItemData) })] [HarmonyPostfix] public static void PostfixPlayerEatFood(Player __instance, ItemData item, bool __result) { NutritionManager.OnAfterEatFood(__instance, item, __result); } [HarmonyPatch(typeof(Player), "RemoveOneFood")] [HarmonyPostfix] public static void PostfixPlayerRemoveOneFood(Player __instance, bool __result) { NutritionManager.OnRemoveOneFood(__instance, __result); } [HarmonyPatch(typeof(Player), "ClearFood")] [HarmonyPostfix] public static void PostfixPlayerClearFood(Player __instance) { NutritionManager.OnClearFood(__instance); } [HarmonyPatch(typeof(Player), "OnDeath")] [HarmonyPostfix] public static void PostfixPlayerOnDeath(Player __instance) { NutritionManager.OnPlayerDeath(__instance); } [HarmonyPatch(typeof(Player), "Save", new Type[] { typeof(ZPackage) })] [HarmonyPrefix] public static void PrefixPlayerSave(Player __instance) { NutritionManager.OnPlayerSave(__instance); } [HarmonyPatch(typeof(Player), "Load", new Type[] { typeof(ZPackage) })] [HarmonyPostfix] public static void PostfixPlayerLoad(Player __instance) { NutritionManager.OnPlayerLoad(__instance); } [HarmonyPatch(typeof(Player), "OnSpawned", new Type[] { typeof(bool) })] [HarmonyPostfix] public static void PostfixPlayerOnSpawned(Player __instance) { NutritionManager.OnPlayerSpawned(__instance); } [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int), typeof(bool) })] [HarmonyPostfix] public static void PostfixGetTooltip(ItemData item, ref string __result) { //IL_009c: Unknown result type (might be due to invalid IL or missing references) if (item?.m_shared == null || string.IsNullOrEmpty(__result) || ModConfig.Enabled == null || !ModConfig.Enabled.Value || !FoodCatalog.IsEdibleFood(item.m_shared)) { return; } FoodProfile orClassify = FoodCatalog.GetOrClassify(item); if (orClassify == null) { return; } StringBuilder stringBuilder = new StringBuilder(__result.Length + 160); stringBuilder.Append(__result); if (ModConfig.EnableSignatureStats.Value && orClassify.SignatureStat.HasValue) { float effectiveSignatureValue = FoodCatalog.GetEffectiveSignatureValue(orClassify); if (Mathf.Abs(effectiveSignatureValue) > 0.0001f) { string value = NutritionStatHelper.FormatStatBonus(orClassify.SignatureStat.Value, effectiveSignatureValue); stringBuilder.Append("\n<color=#E5A93C>Signature:</color> <color=#F4D38B>"); stringBuilder.Append(value); stringBuilder.Append("</color>"); } } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { int digestedCount = NutritionManager.GetDigestedCount(localPlayer, orClassify.PrefabName); if (digestedCount <= 0) { stringBuilder.Append("\n<color=#F59E0B>Servings Eaten: 0 (New Dish)</color>"); } else { stringBuilder.Append("\n<color=#8FBC8F>Servings Eaten: "); stringBuilder.Append(digestedCount); stringBuilder.Append("</color>"); } } __result = stringBuilder.ToString(); } } } namespace VikingNutrition.Data { public static class FoodCatalog { private static readonly Dictionary<string, FoodProfile> _profiles = new Dictionary<string, FoodProfile>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, string> _sharedNameToPrefab = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, FoodOverrideStore.FoodOverrideEntry> _overrideEntries = new Dictionary<string, FoodOverrideStore.FoodOverrideEntry>(StringComparer.OrdinalIgnoreCase); private static bool _initialized; public static int Count => _profiles.Count; public static void Initialize() { if (!_initialized) { _initialized = true; _profiles.Clear(); _overrideEntries.Clear(); PopulateCuratedCatalog(); LoadAndApplyOverrides(); if (ModConfig.EnableDebugLogging != null && ModConfig.EnableDebugLogging.Value) { Plugin.Log.LogInfo((object)$"[VikingNutrition] Initialized curated catalog with {_profiles.Count} foods and {_overrideEntries.Count} JSON overrides."); } } } public static void ReloadOverrides() { _profiles.Clear(); _overrideEntries.Clear(); PopulateCuratedCatalog(); LoadAndApplyOverrides(); if ((Object)(object)ObjectDB.instance != (Object)null) { ScanObjectDB(ObjectDB.instance); } } public static void ScanObjectDB(ObjectDB? db) { if (!_initialized) { Initialize(); } if ((Object)(object)db == (Object)null || db.m_items == null) { return; } int num = 0; for (int i = 0; i < db.m_items.Count; i++) { GameObject val = db.m_items[i]; if ((Object)(object)val == (Object)null) { continue; } ItemDrop component = val.GetComponent<ItemDrop>(); if (component?.m_itemData?.m_shared == null) { continue; } SharedData shared = component.m_itemData.m_shared; if (!IsEdibleFood(shared)) { continue; } string text = StripCloneSuffix(((Object)val).name); if (string.IsNullOrEmpty(text)) { continue; } if (!string.IsNullOrEmpty(shared.m_name)) { _sharedNameToPrefab[shared.m_name] = text; } if (!_profiles.ContainsKey(text)) { FoodProfile foodProfile = AutoClassify(text, shared); if (_overrideEntries.TryGetValue(text, out FoodOverrideStore.FoodOverrideEntry value)) { foodProfile = FoodOverrideStore.ApplyOverride(foodProfile, value); } _profiles[text] = foodProfile; num++; } } RegisterKnownFeastSharedNames(); if (num > 0 && ModConfig.EnableDebugLogging != null && ModConfig.EnableDebugLogging.Value) { Plugin.Log.LogInfo((object)$"[VikingNutrition] Auto-classified {num} modded food item(s) from ObjectDB."); } } public static bool IsEdibleFood(SharedData? shared) { if (shared == null) { return false; } if (!(shared.m_food > 0f) && !(shared.m_foodStamina > 0f)) { return shared.m_foodEitr > 0f; } return true; } public static string ResolvePrefabName(ItemData? item) { if (item == null) { return string.Empty; } if ((Object)(object)item.m_dropPrefab != (Object)null && !string.IsNullOrEmpty(((Object)item.m_dropPrefab).name)) { return StripCloneSuffix(((Object)item.m_dropPrefab).name); } string text = item.m_shared?.m_name; if (!string.IsNullOrEmpty(text) && _sharedNameToPrefab.TryGetValue(text, out string value)) { return value; } return string.Empty; } public static string ResolvePrefabName(Food? food) { if (food == null) { return string.Empty; } if (!string.IsNullOrEmpty(food.m_name)) { return StripCloneSuffix(food.m_name); } return ResolvePrefabName(food.m_item); } public static bool TryGetProfile(string? prefabName, out FoodProfile profile) { if (!_initialized) { Initialize(); } if (!string.IsNullOrEmpty(prefabName) && _profiles.TryGetValue(StripCloneSuffix(prefabName), out FoodProfile value)) { profile = value; return true; } profile = null; return false; } public static FoodProfile? GetOrClassify(ItemData? item) { if (!_initialized) { Initialize(); } SharedData val = item?.m_shared; if (!IsEdibleFood(val)) { return null; } string text = ResolvePrefabName(item); if (string.IsNullOrEmpty(text)) { text = val.m_name ?? "UnknownFood"; } if (_profiles.TryGetValue(text, out FoodProfile value)) { return value; } FoodProfile foodProfile = AutoClassify(text, val); if (_overrideEntries.TryGetValue(text, out FoodOverrideStore.FoodOverrideEntry value2)) { foodProfile = FoodOverrideStore.ApplyOverride(foodProfile, value2); } _profiles[text] = foodProfile; if (!string.IsNullOrEmpty(val.m_name)) { _sharedNameToPrefab[val.m_name] = text; } return foodProfile; } public static IReadOnlyDictionary<string, FoodProfile> GetAllProfiles() { if (!_initialized) { Initialize(); } return _profiles; } public static float GetEffectiveBaseMultiplier(FoodProfile? profile) { if (profile == null) { return 1f; } if (ModConfig.Enabled == null || !ModConfig.Enabled.Value) { return 1f; } if (ModConfig.EnableBiomeTrim == null || !ModConfig.EnableBiomeTrim.Value) { return 1f; } if (profile.BaseMultiplierOverride.HasValue) { return Mathf.Max(0.1f, profile.BaseMultiplierOverride.Value); } if (profile.IsJerky) { return Mathf.Max(0.1f, ModConfig.JerkyBaseMultiplier.Value); } return Mathf.Max(0.1f, ModConfig.GetBiomeMultiplier(profile.Biome)); } public static float GetEffectiveLongTermStrength(FoodProfile? profile) { if (profile == null || profile.LongTermStrength <= 0.0001f) { return 0f; } if (ModConfig.EnableLongHorizonEchoes == null || !ModConfig.EnableLongHorizonEchoes.Value) { return 0f; } float num = ((ModConfig.DefaultEchoStrength != null) ? ModConfig.DefaultEchoStrength.Value : 0.1f); if (num <= 0.0001f) { return 0f; } float num2 = num / 0.1f; return Mathf.Clamp(profile.LongTermStrength * num2, 0f, 1f); } public static float GetEffectiveEchoDuration(FoodProfile? profile, float baseBurnTime) { if (baseBurnTime <= 0.001f) { return 0f; } float num = ((ModConfig.DefaultEchoDurationMultiplier != null) ? ModConfig.DefaultEchoDurationMultiplier.Value : 8f); float num2 = profile?.LongTermDurationMultiplier ?? 1f; return baseBurnTime * Mathf.Max(0.5f, num * num2); } public static float GetEffectiveSignatureValue(FoodProfile? profile) { if (profile == null || !profile.SignatureStat.HasValue) { return 0f; } if (ModConfig.EnableSignatureStats == null || !ModConfig.EnableSignatureStats.Value) { return 0f; } float num = ((ModConfig.SignatureStatScale != null) ? ModConfig.SignatureStatScale.Value : 1f); return profile.SignatureValue * Mathf.Max(0f, num); } private static string StripCloneSuffix(string name) { if (name.EndsWith("(Clone)", StringComparison.Ordinal)) { return name.Substring(0, name.Length - "(Clone)".Length).Trim(); } return name.Trim(); } private static void LoadAndApplyOverrides() { List<FoodOverrideStore.FoodOverrideEntry> list = FoodOverrideStore.LoadOverrides(); for (int i = 0; i < list.Count; i++) { FoodOverrideStore.FoodOverrideEntry foodOverrideEntry = list[i]; string key = foodOverrideEntry.PrefabName.Trim(); _overrideEntries[key] = foodOverrideEntry; if (_profiles.TryGetValue(key, out FoodProfile value)) { _profiles[key] = FoodOverrideStore.ApplyOverride(value, foodOverrideEntry); } } } private static void RegisterKnownFeastSharedNames() { _sharedNameToPrefab["$item_feastmeadows"] = "FeastMeadows"; _sharedNameToPrefab["$item_feastblackforest"] = "FeastBlackforest"; _sharedNameToPrefab["$item_feastoceans"] = "FeastOceans"; _sharedNameToPrefab["$item_feastswamps"] = "FeastSwamps"; _sharedNameToPrefab["$item_feastmountains"] = "FeastMountains"; _sharedNameToPrefab["$item_feastplains"] = "FeastPlains"; _sharedNameToPrefab["$item_feastmistlands"] = "FeastMistlands"; _sharedNameToPrefab["$item_feastashlands"] = "FeastAshlands"; _sharedNameToPrefab["$item_feastdeepnorth"] = "FeastDeepNorth"; } private static FoodProfile AutoClassify(string prefabName, SharedData shared) { //IL_051f: Unknown result type (might be due to invalid IL or missing references) //IL_052f: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Unknown result type (might be due to invalid IL or missing references) //IL_053f: Unknown result type (might be due to invalid IL or missing references) //IL_054c: Unknown result type (might be due to invalid IL or missing references) //IL_0627: Unknown result type (might be due to invalid IL or missing references) //IL_062b: Invalid comparison between Unknown and I4 //IL_063a: Unknown result type (might be due to invalid IL or missing references) //IL_063e: Unknown result type (might be due to invalid IL or missing references) //IL_0640: Invalid comparison between Unknown and I4 //IL_062d: Unknown result type (might be due to invalid IL or missing references) //IL_0630: Invalid comparison between Unknown and I4 //IL_0642: Unknown result type (might be due to invalid IL or missing references) //IL_0646: Invalid comparison between Unknown and I4 //IL_0632: Unknown result type (might be due to invalid IL or missing references) //IL_0636: Invalid comparison between Unknown and I4 //IL_059b: Unknown result type (might be due to invalid IL or missing references) //IL_055f: Unknown result type (might be due to invalid IL or missing references) //IL_06a0: Unknown result type (might be due to invalid IL or missing references) //IL_06a3: Invalid comparison between Unknown and I4 //IL_057a: Unknown result type (might be due to invalid IL or missing references) //IL_06a5: Unknown result type (might be due to invalid IL or missing references) //IL_06a9: Invalid comparison between Unknown and I4 //IL_0595: Unknown result type (might be due to invalid IL or missing references) //IL_0720: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Max(0f, shared.m_food); float num2 = Mathf.Max(0f, shared.m_foodStamina); float num3 = Mathf.Max(0f, shared.m_foodEitr); float num4 = num + num2 + num3; float num5 = Mathf.Max(0f, shared.m_foodBurnTime); string text = prefabName.ToLowerInvariant(); FoodBiomeTier foodBiomeTier = ((!(num4 <= 48f)) ? ((num4 <= 64f) ? FoodBiomeTier.BlackForest : ((num4 <= 76f) ? FoodBiomeTier.Swamp : ((num4 <= 90f) ? FoodBiomeTier.Mountain : ((num4 <= 104f) ? FoodBiomeTier.Plains : ((num4 <= 124f) ? FoodBiomeTier.Mistlands : ((!(num4 <= 142f)) ? FoodBiomeTier.DeepNorth : FoodBiomeTier.Ashlands)))))) : FoodBiomeTier.Meadows); FoodBiomeTier foodBiomeTier2 = foodBiomeTier; FoodCategoryFlags foodCategoryFlags = FoodCategoryFlags.None; if (text.Contains("feast") || text.Contains("banquet") || num5 >= 2700f) { foodCategoryFlags |= FoodCategoryFlags.Feast; } if (text.Contains("jerky") || text.Contains("ration") || text.Contains("pemmican")) { foodCategoryFlags |= FoodCategoryFlags.Meat | FoodCategoryFlags.Jerky; } if (text.Contains("fish") || text.Contains("serpent") || text.Contains("salmon") || text.Contains("cod") || text.Contains("tuna") || text.Contains("sushi")) { foodCategoryFlags |= FoodCategoryFlags.Fish; } if (text.Contains("soup") || text.Contains("stew") || text.Contains("broth") || text.Contains("porridge") || text.Contains("chowder") || text.Contains("sauce")) { foodCategoryFlags |= FoodCategoryFlags.SoupStew; } if (text.Contains("pie") || text.Contains("bread") || text.Contains("cake") || text.Contains("bun") || text.Contains("tart") || text.Contains("wrap") || text.Contains("baked") || text.Contains("pancake") || text.Contains("omelette")) { foodCategoryFlags |= FoodCategoryFlags.Baked; } if (text.Contains("jam") || text.Contains("honey") || text.Contains("berry") || text.Contains("sweet") || text.Contains("smoothie") || text.Contains("shake") || text.Contains("candy") || text.Contains("marmalade") || text.Contains("cream") || text.Contains("jelly")) { foodCategoryFlags |= FoodCategoryFlags.Sweet; } if (text.Contains("meat") || text.Contains("steak") || text.Contains("sausage") || text.Contains("skewer") || text.Contains("roast") || text.Contains("kebab") || text.Contains("boar") || text.Contains("deer") || text.Contains("wolf") || text.Contains("lox") || text.Contains("chicken") || text.Contains("hare") || text.Contains("bear") || text.Contains("moose")) { foodCategoryFlags |= FoodCategoryFlags.Meat; } if (num3 >= 15f) { foodCategoryFlags |= FoodCategoryFlags.Eitr; } if ((num5 <= 900f && shared.m_foodRegen <= 1f && num4 <= 65f && (foodCategoryFlags & (FoodCategoryFlags.SoupStew | FoodCategoryFlags.Baked | FoodCategoryFlags.Feast | FoodCategoryFlags.Jerky)) == 0) || text.StartsWith("raw") || (text.Contains("berry") && !text.Contains("jam") && !text.Contains("pie") && !text.Contains("broth") && !text.Contains("smoothie") && !text.Contains("dricka") && !text.Contains("cake")) || (text.Contains("mushroom") && !text.Contains("soup") && !text.Contains("omelette") && !text.Contains("stuffed") && !text.Contains("shake") && !text.Contains("stew"))) { foodCategoryFlags |= FoodCategoryFlags.Raw; return new FoodProfile(prefabName, foodBiomeTier2, foodCategoryFlags, null, 0f, 0f, 1f, null, isAutoClassified: true); } CharacterStatType val = (((foodCategoryFlags & FoodCategoryFlags.Eitr) != FoodCategoryFlags.None) ? ((CharacterStatType)((num3 >= num) ? 54 : 10)) : (((foodCategoryFlags & FoodCategoryFlags.Fish) != FoodCategoryFlags.None) ? ((CharacterStatType)18) : (((foodCategoryFlags & FoodCategoryFlags.Jerky) != FoodCategoryFlags.None) ? ((CharacterStatType)94) : (((foodCategoryFlags & FoodCategoryFlags.Feast) != FoodCategoryFlags.None) ? ((CharacterStatType)65) : (((foodCategoryFlags & FoodCategoryFlags.Sweet) != FoodCategoryFlags.None) ? ((CharacterStatType)9) : (((foodCategoryFlags & FoodCategoryFlags.SoupStew) != FoodCategoryFlags.None) ? ((CharacterStatType)((num >= num2) ? 8 : 94)) : ((num > num2 * 1.25f) ? ((CharacterStatType)(((foodCategoryFlags & FoodCategoryFlags.Baked) != FoodCategoryFlags.None) ? 22 : 52)) : ((!(num2 > num * 1.25f)) ? ((CharacterStatType)9) : ((CharacterStatType)(((foodCategoryFlags & FoodCategoryFlags.Baked) != FoodCategoryFlags.None) ? 15 : 57)))))))))); float num6; switch (foodBiomeTier2) { case FoodBiomeTier.Meadows: num6 = 0.85f; break; case FoodBiomeTier.BlackForest: case FoodBiomeTier.Ocean: num6 = 0.82f; break; case FoodBiomeTier.Swamp: num6 = 0.79f; break; case FoodBiomeTier.Mountain: num6 = 0.75f; break; case FoodBiomeTier.Plains: num6 = 0.71f; break; case FoodBiomeTier.Mistlands: num6 = 0.67f; break; case FoodBiomeTier.Ashlands: num6 = 0.63f; break; default: num6 = 0.6f; break; } float num7 = num6; float num8 = Mathf.Clamp01((num4 * num7 - 25f) / 75f); if ((int)val <= 22) { if ((int)val != 8) { if ((int)val != 22) { goto IL_0689; } num6 = Mathf.Lerp(1.5f, 4.5f, num8); } else { num6 = Mathf.Lerp(0.1f, 0.35f, num8); } } else { if (val - 27 > 1 && (int)val != 35) { goto IL_0689; } num6 = Mathf.Lerp(0.03f, 0.07f, num8); } goto IL_069c; IL_069c: float num9 = num6; num6 = (((int)val == 8) ? (Mathf.Round(num9 * 20f) / 20f) : (((int)val != 22) ? (Mathf.Round(num9 * 200f) / 200f) : (Mathf.Round(num9 * 2f) / 2f))); num9 = num6; float longTermStrength = (((foodCategoryFlags & FoodCategoryFlags.Feast) != FoodCategoryFlags.None) ? 0.13f : (((foodCategoryFlags & FoodCategoryFlags.Jerky) != FoodCategoryFlags.None) ? 0.02f : 0.1f)); return new FoodProfile(prefabName, foodBiomeTier2, foodCategoryFlags, val, num9, longTermStrength, 1f, null, isAutoClassified: true); IL_0689: num6 = Mathf.Lerp(0.03f, 0.075f, num8); goto IL_069c; } private static void Add(string prefab, FoodBiomeTier biome, FoodCategoryFlags cats, CharacterStatType? sigStat, float sigVal, float ltStrength = 0.1f, float ltDurMult = 1f) { _profiles[prefab] = new FoodProfile(prefab, biome, cats, sigStat, sigVal, ltStrength, ltDurMult); } private static void PopulateCuratedCatalog() { Add("Raspberry", FoodBiomeTier.Meadows, FoodCategoryFlags.Raw | FoodCategoryFlags.Sweet, null, 0f, 0f); Add("Mushroom", FoodBiomeTier.Meadows, FoodCategoryFlags.Raw, null, 0f, 0f); Add("Honey", FoodBiomeTier.Meadows, FoodCategoryFlags.Raw | FoodCategoryFlags.Sweet, null, 0f, 0f); Add("NeckTailGrilled", FoodBiomeTier.Meadows, FoodCategoryFlags.Meat, (CharacterStatType)18, 0.035f); Add("CookedMeat", FoodBiomeTier.Meadows, FoodCategoryFlags.Meat, (CharacterStatType)52, 0.025f); Add("CookedDeerMeat", FoodBiomeTier.Meadows, FoodCategoryFlags.Meat, (CharacterStatType)15, 0.03f); Add("CookedEgg", FoodBiomeTier.Meadows, FoodCategoryFlags.Meat, (CharacterStatType)8, 0.1f); Add("BoarJerky", FoodBiomeTier.Meadows, FoodCategoryFlags.Meat | FoodCategoryFlags.Jerky, (CharacterStatType)94, 0.035f, 0.02f); Add("FeastMeadows", FoodBiomeTier.Meadows, FoodCategoryFlags.Meat | FoodCategoryFlags.Sweet | FoodCategoryFlags.Feast, (CharacterStatType)143, 0.05f, 0.13f); Add("Blueberries", FoodBiomeTier.BlackForest, FoodCategoryFlags.Raw | FoodCategoryFlags.Sweet, null, 0f, 0f); Add("MushroomYellow", FoodBiomeTier.BlackForest, FoodCategoryFlags.Raw, null, 0f, 0f); Add("MushroomBlue", FoodBiomeTier.BlackForest, FoodCategoryFlags.Raw, null, 0f, 0f); Add("Carrot", FoodBiomeTier.BlackForest, FoodCategoryFlags.Raw, null, 0f, 0f); Add("CookedBjornMeat", FoodBiomeTier.BlackForest, FoodCategoryFlags.Meat, (CharacterStatType)64, 0.04f); Add("PulledBear", FoodBiomeTier.BlackForest, FoodCategoryFlags.Meat, (CharacterStatType)22, 2f); Add("MinceMeatSauce", FoodBiomeTier.BlackForest, FoodCategoryFlags.Meat | FoodCategoryFlags.SoupStew, (CharacterStatType)52, 0.035f); Add("QueensJam", FoodBiomeTier.BlackForest, FoodCategoryFlags.Sweet, (CharacterStatType)9, 0.04f); Add("CarrotSoup", FoodBiomeTier.BlackForest, FoodCategoryFlags.SoupStew, (CharacterStatType)94, 0.045f); Add("FishCooked", FoodBiomeTier.BlackForest, FoodCategoryFlags.Fish, (CharacterStatType)18, 0.045f); Add("DeerStew", FoodBiomeTier.BlackForest, FoodCategoryFlags.Meat | FoodCategoryFlags.SoupStew, (CharacterStatType)8, 0.15f); Add("FeastBlackforest", FoodBiomeTier.BlackForest, FoodCategoryFlags.Meat | FoodCategoryFlags.SoupStew | FoodCategoryFlags.Feast, (CharacterStatType)27, 0.04f, 0.13f); Add("SerpentMeatCooked", FoodBiomeTier.Ocean, FoodCategoryFlags.Meat | FoodCategoryFlags.Fish, (CharacterStatType)18, 0.06f); Add("SerpentStew", FoodBiomeTier.Ocean, FoodCategoryFlags.Fish | FoodCategoryFlags.SoupStew, (CharacterStatType)65, 0.065f); Add("FeastOceans", FoodBiomeTier.Ocean, FoodCategoryFlags.Fish | FoodCategoryFlags.Feast, (CharacterStatType)18, 0.07f, 0.13f); Add("ShocklateSmoothie", FoodBiomeTier.Swamp, FoodCategoryFlags.Sweet, (CharacterStatType)15, 0.045f); Add("BlackSoup", FoodBiomeTier.Swamp, FoodCategoryFlags.Meat | FoodCategoryFlags.SoupStew, (CharacterStatType)35, 0.05f); Add("TurnipStew", FoodBiomeTier.Swamp, FoodCategoryFlags.Meat | FoodCategoryFlags.SoupStew, (CharacterStatType)143, 0.055f); Add("Sausages", FoodBiomeTier.Swamp, FoodCategoryFlags.Meat, (CharacterStatType)52, 0.045f); Add("FeastSwamps", FoodBiomeTier.Swamp, FoodCategoryFlags.Meat | FoodCategoryFlags.SoupStew | FoodCategoryFlags.Feast, (CharacterStatType)35, 0.065f, 0.13f); Add("Onion", FoodBiomeTier.Mountain, FoodCategoryFlags.Raw, null, 0f, 0f); Add("CookedWolfMeat", FoodBiomeTier.Mountain, FoodCategoryFlags.Meat, (CharacterStatType)57, 0.04f); Add("WolfJerky", FoodBiomeTier.Mountain, FoodCategoryFlags.Meat | FoodCategoryFlags.Jerky, (CharacterStatType)94, 0.045f, 0.02f); Add("OnionSoup", FoodBiomeTier.Mountain, FoodCategoryFlags.SoupStew, (CharacterStatType)9, 0.055f); Add("WolfMeatSkewer", FoodBiomeTier.Mountain, FoodCategoryFlags.Meat, (CharacterStatType)53, 0.05f); Add("VikingCupcake", FoodBiomeTier.Mountain, FoodCategoryFlags.Baked | FoodCategoryFlags.Sweet, (CharacterStatType)8, 0.2f); Add("Eyescream", FoodBiomeTier.Mountain, FoodCategoryFlags.Sweet, (CharacterStatType)28, 0.05f); Add("FeastMountains", FoodBiomeTier.Mountain, FoodCategoryFlags.Meat | FoodCategoryFlags.Feast, (CharacterStatType)64, 0.06f, 0.13f); Add("Cloudberry", FoodBiomeTier.Plains, FoodCategoryFlags.Raw | FoodCategoryFlags.Sweet, null, 0f, 0f); Add("CookedLoxMeat", FoodBiomeTier.Plains, FoodCategoryFlags.Meat, (CharacterStatType)22, 3f); Add("Bread", FoodBiomeTier.Plains, FoodCategoryFlags.Baked, (CharacterStatType)94, 0.06f); Add("FishWraps", FoodBiomeTier.Plains, FoodCategoryFlags.Fish | FoodCategoryFlags.Baked, (CharacterStatType)57, 0.055f); Add("LoxPie", FoodBiomeTier.Plains, FoodCategoryFlags.Meat | FoodCategoryFlags.Baked, (CharacterStatType)27, 0.055f); Add("BloodPudding", FoodBiomeTier.Plains, FoodCategoryFlags.Meat | FoodCategoryFlags.Baked, (CharacterStatType)15, 0.055f); Add("FeastPlains", FoodBiomeTier.Plains, FoodCategoryFlags.Meat | FoodCategoryFlags.Baked | FoodCategoryFlags.Feast, (CharacterStatType)65, 0.065f, 0.13f); Add("RoyalJelly", FoodBiomeTier.Mistlands, FoodCategoryFlags.Raw | FoodCategoryFlags.Sweet, null, 0f, 0f); Add("MushroomJotunPuffs", FoodBiomeTier.Mistlands, FoodCategoryFlags.Raw, null, 0f, 0f); Add("MushroomMagecap", FoodBiomeTier.Mistlands, FoodCategoryFlags.Raw | FoodCategoryFlags.Eitr, null, 0f, 0f); Add("CookedChickenMeat", FoodBiomeTier.Mistlands, FoodCategoryFlags.Meat, (CharacterStatType)8, 0.25f); Add("CookedBugMeat", FoodBiomeTier.Mistlands, FoodCategoryFlags.Meat, (CharacterStatType)22, 3.5f); Add("CookedHareMeat", FoodBiomeTier.Mistlands, FoodCategoryFlags.Meat, (CharacterStatType)15, 0.055f); Add("MeatPlatter", FoodBiomeTier.Mistlands, FoodCategoryFlags.Meat | FoodCategoryFlags.Baked, (CharacterStatType)52, 0.065f); Add("HoneyGlazedChicken", FoodBiomeTier.Mistlands, FoodCategoryFlags.Meat | FoodCategoryFlags.Baked | FoodCategoryFlags.Sweet, (CharacterStatType)8, 0.3f); Add("Salad", FoodBiomeTier.Mistlands, FoodCategoryFlags.None, (CharacterStatType)9, 0.065f); Add("MagicallyStuffedShroom", FoodBiomeTier.Mistlands, FoodCategoryFlags.Baked | FoodCategoryFlags.Eitr, (CharacterStatType)54, 0.065f); Add("MisthareSupreme", FoodBiomeTier.Mistlands, FoodCategoryFlags.Meat | FoodCategoryFlags.Baked, (CharacterStatType)53, 0.065f); Add("MushroomOmelette", FoodBiomeTier.Mistlands, FoodCategoryFlags.Baked, (CharacterStatType)143, 0.07f); Add("FishAndBread", FoodBiomeTier.Mistlands, FoodCategoryFlags.Fish | FoodCategoryFlags.Baked, (CharacterStatType)94, 0.07f); Add("YggdrasilPorridge", FoodBiomeTier.Mistlands, FoodCategoryFlags.SoupStew | FoodCategoryFlags.Eitr, (CharacterStatType)10, 0.065f); Add("SeekerAspic", FoodBiomeTier.Mistlands, FoodCategoryFlags.Meat | FoodCategoryFlags.Eitr, (CharacterStatType)28, 0.065f); Add("FeastMistlands", FoodBiomeTier.Mistlands, FoodCategoryFlags.Meat | FoodCategoryFlags.Eitr | FoodCategoryFlags.Feast, (CharacterStatType)10, 0.075f, 0.13f); Add("MushroomSmokePuff", FoodBiomeTier.Ashlands, FoodCategoryFlags.Raw, null, 0f, 0f); Add("Fiddleheadfern", FoodBiomeTier.Ashlands, FoodCategoryFlags.Raw, null, 0f, 0f); Add("Vineberry", FoodBiomeTier.Ashlands, FoodCategoryFlags.Raw | FoodCategoryFlags.Sweet | FoodCategoryFlags.Eitr, null, 0f, 0f); Add("CookedVoltureMeat", FoodBiomeTier.Ashlands, FoodCategoryFlags.Meat, (CharacterStatType)53, 0.065f); Add("CookedAsksvinMeat", FoodBiomeTier.Ashlands, FoodCategoryFlags.Meat, (CharacterStatType)64, 0.065f); Add("CookedBoneMawSerpentMeat", FoodBiomeTier.Ashlands, FoodCategoryFlags.Meat | FoodCategoryFlags.Fish, (CharacterStatType)18, 0.075f); Add("SpicyMarmalade", FoodBiomeTier.Ashlands, FoodCategoryFlags.Sweet, (CharacterStatType)57, 0.065f); Add("ScorchingMedley", FoodBiomeTier.Ashlands, FoodCategoryFlags.SoupStew, (CharacterStatType)15, 0.07f); Add("SizzlingBerryBroth", FoodBiomeTier.Ashlands, FoodCategoryFlags.SoupStew | FoodCategoryFlags.Sweet | FoodCategoryFlags.Eitr, (CharacterStatType)54, 0.075f); Add("FierySvinstew", FoodBiomeTier.Ashlands, FoodCategoryFlags.Meat | FoodCategoryFlags.SoupStew, (CharacterStatType)52, 0.075f); Add("RoastedCrustPie", FoodBiomeTier.Ashlands, FoodCategoryFlags.Baked, (CharacterStatType)9, 0.075f); Add("MashedMeat", FoodBiomeTier.Ashlands, FoodCategoryFlags.Meat, (CharacterStatType)22, 4.5f); Add("SparklingShroomshake", FoodBiomeTier.Ashlands, FoodCategoryFlags.Sweet | FoodCategoryFlags.Eitr, (CharacterStatType)10, 0.075f); Add("PiquantPie", FoodBiomeTier.Ashlands, FoodCategoryFlags.Meat | FoodCategoryFlags.Baked, (CharacterStatType)65, 0.075f); Add("MarinatedGreens", FoodBiomeTier.Ashlands, FoodCategoryFlags.Eitr, (CharacterStatType)28, 0.07f); Add("FeastAshlands", FoodBiomeTier.Ashlands, FoodCategoryFlags.Meat | FoodCategoryFlags.Eitr | FoodCategoryFlags.Feast, (CharacterStatType)27, 0.07f, 0.13f); Add("GlowWorm", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Raw, null, 0f, 0f); Add("Oat", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Raw, null, 0f, 0f); Add("Lingonberry", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Raw | FoodCategoryFlags.Sweet, null, 0f, 0f); Add("Kale", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Raw, null, 0f, 0f); Add("Poteitr", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Raw | FoodCategoryFlags.Eitr, null, 0f, 0f); Add("CookedSealBlubber", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Meat, (CharacterStatType)28, 0.065f); Add("CookedMooseMeat", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Meat, (CharacterStatType)64, 0.07f); Add("KaleChips", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Baked, (CharacterStatType)94, 0.08f); Add("SmokedMooseMeat", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Meat, (CharacterStatType)22, 5f); Add("Lingondricka", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Sweet, (CharacterStatType)9, 0.08f); Add("SmokedFish", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Fish | FoodCategoryFlags.Eitr, (CharacterStatType)54, 0.08f); Add("MooseKebab", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Meat, (CharacterStatType)52, 0.085f); Add("OatMilk", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Sweet, (CharacterStatType)143, 0.085f); Add("SealSoup", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Meat | FoodCategoryFlags.SoupStew, (CharacterStatType)8, 0.4f); Add("BakedPoteitr", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Baked | FoodCategoryFlags.Eitr, (CharacterStatType)10, 0.085f); Add("Pancakes", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Baked | FoodCategoryFlags.Sweet, (CharacterStatType)15, 0.08f); Add("MeatballsMashedPoteitr", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Meat | FoodCategoryFlags.Eitr, (CharacterStatType)53, 0.085f); Add("FishSoup", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Fish | FoodCategoryFlags.SoupStew | FoodCategoryFlags.Eitr, (CharacterStatType)18, 0.085f); Add("OvenPancake", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Baked | FoodCategoryFlags.Sweet | FoodCategoryFlags.Eitr, (CharacterStatType)57, 0.08f); Add("OatmealLingonberryJam", FoodBiomeTier.DeepNorth, FoodCategoryFlags.SoupStew | FoodCategoryFlags.Sweet | FoodCategoryFlags.Eitr, (CharacterStatType)65, 0.09f); Add("FeastDeepNorth", FoodBiomeTier.DeepNorth, FoodCategoryFlags.Meat | FoodCategoryFlags.Eitr | FoodCategoryFlags.Feast, (CharacterStatType)28, 0.075f, 0.13f); } } public static class FoodOverrideStore { [Serializable] public sealed class OverrideFileSchema { public int SchemaVersion = 1; public string Notes = "Optional per-food overrides for VikingNutrition. Leave string fields empty or numeric fields at -1 to keep catalog/auto defaults. Valid Biomes: Meadows, BlackForest, Ocean, Swamp, Mountain, Plains, Mistlands, Ashlands, DeepNorth. Valid SignatureStats: None, DamageMelee, DamageRanged, DamageMagic, AttackSpeed, DamageAgainstBosses, StaggerDamage, RunSpeed, SwimSpeed, SprintEfficiency, ResistancePhysical, ResistanceElemental, ResistancePoison, BodyArmor, HealthRegen, StaminaRegen, EitrRegen, ToolStaminaEfficiency."; public List<FoodOverrideEntry> Overrides = new List<FoodOverrideEntry>(); } [Serializable] public sealed class FoodOverrideEntry { public string PrefabName = string.Empty; public string Biome = string.Empty; public string Categories = string.Empty; public float BaseMultiplierOverride = -1f; public string SignatureStat = string.Empty; public float SignatureValue = -1f; public float LongTermStrength = -1f; public float LongTermDurationMultiplier = -1f; } public const string FileName = "VikingNutrition_Overrides.json"; public static string FilePath => Path.Combine(Paths.ConfigPath, "VikingNutrition_Overrides.json"); public static List<FoodOverrideEntry> LoadOverrides() { List<FoodOverrideEntry> list = new List<FoodOverrideEntry>(); try { if (!File.Exists(FilePath)) { WriteTemplateFile(); return list; } string text = File.ReadAllText(FilePath); if (string.IsNullOrWhiteSpace(text)) { return list; } OverrideFileSchema overrideFileSchema = JsonUtility.FromJson<OverrideFileSchema>(text); if (overrideFileSchema?.Overrides == null) { return list; } foreach (FoodOverrideEntry @override in overrideFileSchema.Overrides) { if (@override != null && !string.IsNullOrWhiteSpace(@override.PrefabName)) { list.Add(@override); } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("[VikingNutrition] Failed to read VikingNutrition_Overrides.json: " + ex.Message)); } return list; } public static FoodProfile ApplyOverride(FoodProfile baseProfile, FoodOverrideEntry entry) { //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) FoodBiomeTier? biome = null; if (!string.IsNullOrWhiteSpace(entry.Biome)) { if (Enum.TryParse<FoodBiomeTier>(entry.Biome.Trim(), ignoreCase: true, out var result)) { biome = result; } else { Plugin.Log.LogWarning((object)("[VikingNutrition] Override for '" + entry.PrefabName + "' has unknown Biome '" + entry.Biome + "'.")); } } FoodCategoryFlags? categories = null; if (!string.IsNullOrWhiteSpace(entry.Categories)) { if (Enum.TryParse<FoodCategoryFlags>(entry.Categories.Trim(), ignoreCase: true, out var result2)) { categories = result2; } else { Plugin.Log.LogWarning((object)("[VikingNutrition] Override for '" + entry.PrefabName + "' has unknown Categories '" + entry.Categories + "'.")); } } float? baseMultiplierOverride = ((entry.BaseMultiplierOverride >= 0f) ? new float?(Mathf.Clamp(entry.BaseMultiplierOverride, 0.1f, 3f)) : ((float?)null)); CharacterStatType? signatureStat = null; bool clearSignatureStat = false; if (!string.IsNullOrWhiteSpace(entry.SignatureStat)) { string text = entry.SignatureStat.Trim(); CharacterStatType result3; if (text.Equals("None", StringComparison.OrdinalIgnoreCase)) { clearSignatureStat = true; } else if (Enum.TryParse<CharacterStatType>(text, ignoreCase: true, out result3)) { if (NutritionStatHelper.IsAllowedSignatureStat(result3)) { signatureStat = result3; } else { Plugin.Log.LogWarning((object)$"[VikingNutrition] Override for '{entry.PrefabName}' requested disallowed SignatureStat '{result3}'. Ignored."); } } else { Plugin.Log.LogWarning((object)("[VikingNutrition] Override for '" + entry.PrefabName + "' has unknown SignatureStat '" + entry.SignatureStat + "'.")); } } float? signatureValue = ((entry.SignatureValue >= 0f) ? new float?(entry.SignatureValue) : ((float?)null)); float? longTermStrength = ((entry.LongTermStrength >= 0f) ? new float?(Mathf.Clamp(entry.LongTermStrength, 0f, 1f)) : ((float?)null)); float? longTermDurationMultiplier = ((entry.LongTermDurationMultiplier > 0f) ? new float?(Mathf.Clamp(entry.LongTermDurationMultiplier, 0.1f, 10f)) : ((float?)null)); return baseProfile.WithOverride(biome, categories, baseMultiplierOverride, clearBaseOverride: false, signatureStat, clearSignatureStat, signatureValue, longTermStrength, longTermDurationMultiplier); } private static void WriteTemplateFile() { try { Directory.CreateDirectory(Paths.ConfigPath); string contents = JsonUtility.ToJson((object)new OverrideFileSchema(), true); File.WriteAllText(FilePath, contents); } catch (Exception ex) { Plugin.Log.LogWarning((object)("[VikingNutrition] Could not write template VikingNutrition_Overrides.json: " + ex.Message)); } } } public enum FoodBiomeTier { Meadows, BlackForest, Ocean, Swamp, Mountain, Plains, Mistlands, Ashlands, DeepNorth } [Flags] public enum FoodCategoryFlags { None = 0, Raw = 1, Meat = 2, Fish = 4, SoupStew = 8, Baked = 0x10, Sweet = 0x20, Eitr = 0x40, Feast = 0x80, Jerky = 0x100 } public sealed class FoodProfile { public string PrefabName { get; } public FoodBiomeTier Biome { get; } public FoodCategoryFlags Categories { get; } public float? BaseMultiplierOverride { get; } public CharacterStatType? SignatureStat { get; } public float SignatureValue { get; } public float LongTermStrength { get; } public float LongTermDurationMultiplier { get; } public bool IsAutoClassified { get; } public bool IsOverridden { get; } public bool IsTrivialRaw { get { if ((Categories & FoodCategoryFlags.Raw) != FoodCategoryFlags.None) { return LongTermStrength <= 0.0001f; } return false; } } public bool IsJerky => (Categories & FoodCategoryFlags.Jerky) != 0; public bool IsFeast => (Categories & FoodCategoryFlags.Feast) != 0; public FoodProfile(string prefabName, FoodBiomeTier biome, FoodCategoryFlags categories, CharacterStatType? signatureStat, float signatureValue, float longTermStrength = 0.1f, float longTermDurationMultiplier = 1f, float? baseMultiplierOverride = null, bool isAutoClassified = false, bool isOverridden = false) { PrefabName = prefabName; Biome = biome; Categories = categories; SignatureStat = signatureStat; SignatureValue = (signatureStat.HasValue ? signatureValue : 0f); LongTermStrength = ((longTermStrength < 0f) ? 0f : longTermStrength); LongTermDurationMultiplier = ((longTermDurationMultiplier > 0.01f) ? longTermDurationMultiplier : 1f); BaseMultiplierOverride = baseMultiplierOverride; IsAutoClassified = isAutoClassified; IsOverridden = isOverridden; } public FoodProfile WithOverride(FoodBiomeTier? biome = null, FoodCategoryFlags? categories = null, float? baseMultiplierOverride = null, bool clearBaseOverride = false, CharacterStatType? signatureStat = null, bool clearSignatureStat = false, float? signatureValue = null, float? longTermStrength = null, float? longTermDurationMultiplier = null) { CharacterStatType? signatureStat2 = (clearSignatureStat ? ((CharacterStatType?)null) : (signatureStat ?? SignatureStat)); float? baseMultiplierOverride2 = (clearBaseOverride ? ((float?)null) : (baseMultiplierOverride ?? BaseMultiplierOverride)); return new FoodProfile(PrefabName, biome ?? Biome, categories ?? Categories, signatureStat2, signatureValue ?? SignatureValue, longTermStrength ?? LongTermStrength, longTermDurationMultiplier ?? LongTermDurationMultiplier, baseMultiplierOverride2, IsAutoClassified, isOverridden: true); } } } namespace VikingNutrition.Core { public sealed class NutritionFoodBaseModifier : IFoodBaseModifier { public void ModifyFoodBase(ItemData item, ref float health, ref float stamina, ref float eitr, ref float regen) { if (item?.m_shared == null || ModConfig.Enabled == null || !ModConfig.Enabled.Value || ModConfig.EnableBiomeTrim == null || !ModConfig.EnableBiomeTrim.Value) { return; } FoodProfile orClassify = FoodCatalog.GetOrClassify(item); if (orClassify != null) { float effectiveBaseMultiplier = FoodCatalog.GetEffectiveBaseMultiplier(orClassify); if (!(effectiveBaseMultiplier <= 0.001f) && !(Math.Abs(effectiveBaseMultiplier - 1f) <= 0.0001f)) { health *= effectiveBaseMultiplier; stamina *= effectiveBaseMultiplier; eitr *= effectiveBaseMultiplier; } } } } public static class NutritionManager { public const string ActiveOwnerKey = "VikingNutrition_Active"; public const string EchoesOwnerKey = "VikingNutrition_Echoes"; public const string AchievementsOwnerKey = "VikingNutrition_Achievements"; public const string CustomDataKey = "VikingNutrition_Data"; private const float ModifierSyncIntervalSeconds = 1f; private const float PeriodicSaveIntervalSeconds = 30f; private const float RefreshTimeJumpThreshold = 5f; private static readonly ConditionalWeakTable<Player, PlayerNutritionState> _states = new ConditionalWeakTable<Player, PlayerNutritionState>(); private static readonly List<string> _expiredKeysScratch = new List<string>(16); private static readonly HashSet<string> _activePrefabsScratch = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private static readonly List<string> _staleSlotKeysScratch = new List<string>(8); private static readonly List<StatModifier> _activeModsScratch = new List<StatModifier>(8); private static readonly List<StatModifier> _echoModsScratch = new List<StatModifier>(24); private static readonly Dictionary<CharacterStatType, float> _echoStatSumScratch = new Dictionary<CharacterStatType, float>(); private static readonly Dictionary<CharacterStatType, float> _echoResistanceMultScratch = new Dictionary<CharacterStatType, float>(); private static readonly Action<Player, float, bool>? _setMaxEitrDelegate = CreateSetMaxEitrDelegate(); private static readonly IReadOnlyDictionary<string, int> EmptyIntDict = new Dictionary<string, int>(0); public static event Action<Player, string, FoodProfile?>? OnMealDigested; public static event Action<Player>? OnNutritionStateChanged; private static PlayerNutritionState GetState(Player player) { return _states.GetOrCreateValue(player); } public static IReadOnlyList<ActiveMealSnapshot> GetActiveMeals(Player? player) { List<ActiveMealSnapshot> list = new List<ActiveMealSnapshot>(3); if ((Object)(object)player == (Object)null) { return list; } PlayerNutritionState state = GetState(player); List<Food> foods = player.GetFoods(); if (foods == null || foods.Count == 0) { return list; } float num2 = default(float); float num3 = default(float); float num4 = default(float); float num5 = default(float); for (int i = 0; i < foods.Count; i++) { Food val = foods[i]; if (val != null && val.m_item?.m_shared != null) { SharedData shared = val.m_item.m_shared; string text = FoodCatalog.ResolvePrefabName(val); FoodProfile orClassify = FoodCatalog.GetOrClassify(val.m_item); if (orClassify != null) { string displayName = LocalizeFoodName(shared.m_name, text); Sprite icon = ((shared.m_icons != null && shared.m_icons.Length != 0) ? shared.m_icons[0] : null); float num = ComputeActiveFadeRatio(val); FoodModifierRegistry.EvaluateBaseValues(val.m_item, ref num2, ref num3, ref num4, ref num5); float effectiveHealth = num2 * num; float effectiveStamina = num3 * num; float effectiveEitr = num4 * num; float effectiveSignatureValue = FoodCatalog.GetEffectiveSignatureValue(orClassify); float liveSignatureValue = (orClassify.SignatureStat.HasValue ? (effectiveSignatureValue * num) : 0f); ActiveSlotTrack value; bool isEchoLocked = state.ActiveSlots.TryGetValue(text, out value) && value.EchoLocked; list.Add(new ActiveMealSnapshot(text, displayName, icon, val.m_time, shared.m_foodBurnTime, isEchoLocked, effectiveHealth, effectiveStamina, effectiveEitr, num, orClassify.SignatureStat, effectiveSignatureValue, liveSignatureValue, orClassify)); } } } return list; } public static IReadOnlyList<LongTermEchoEntry> GetActiveEchoes(Player? player) { List<LongTermEchoEntry> list = new List<LongTermEchoEntry>(); if ((Object)(object)player == (Object)null) { return list; } foreach (LongTermEchoEntry value in GetState(player).Echoes.Values) { if (value.RemainingTime > 0f) { list.Add(value); } } list.Sort((LongTermEchoEntry a, LongTermEchoEntry b) => b.RemainingTime.CompareTo(a.RemainingTime)); return list; } public static IReadOnlyDictionary<string, int> GetDigestedCounts(Player? player) { if ((Object)(object)player == (Object)null) { return EmptyIntDict; } return GetState(player).DigestedCounts; } public static int GetDigestedCount(Player? player, string? prefabName) { if ((Object)(object)player == (Object)null || string.IsNullOrEmpty(prefabName)) { return 0; } if (!GetState(player).DigestedCounts.TryGetValue(prefabName, out var value)) { return 0; } return value; } public static int GetUniqueDigestedCount(Player? player, bool excludeTrivialRaw = false) { if ((Object)(object)player == (Object)null) { return 0; } PlayerNutritionState state = GetState(player); int num = 0; foreach (KeyValuePair<string, int> digestedCount in state.DigestedCounts) { if (digestedCount.Value > 0 && (!excludeTrivialRaw || !FoodCatalog.TryGetProfile(digestedCount.Key, out FoodProfile profile) || !profile.IsTrivialRaw)) { num++; } } return num; } public static int GetTotalDigestedServings(Player? player, bool excludeTrivialRaw = false) { if ((Object)(object)player == (Object)null) { return 0; } PlayerNutritionState state = GetState(player); int num = 0; foreach (KeyValuePair<string, int> digestedCount in state.DigestedCounts) { if (digestedCount.Value > 0 && (!excludeTrivialRaw || !FoodCatalog.TryGetProfile(digestedCount.Key, out FoodProfile profile) || !profile.IsTrivialRaw)) { num += digestedCount.Value; } } return num; } public static void ForceRefresh(Player? player) { if (!((Object)(object)player == (Object)null)) { PlayerNutritionState state = GetState(player); if (!ModConfig.Enabled.Value) { ClearAllNutritionModifiers(player); RefreshPlayerVitals(player); return; } RefreshEchoBaseSnapshotsFromCatalog(state); state.ModifiersDirty = true; SyncModifiers(player, state, refreshVitals: true); NutritionManager.OnNutritionStateChanged?.Invoke(player); } } public static void ClearAllNutritionModifiers(Player? player) { if (!((Object)(object)player == (Object)null)) { CharacterStatManager.RemoveModifiersByOwner((Character)(object)player, (object)"VikingNutrition_Active"); CharacterStatManager.RemoveModifiersByOwner((Character)(object)player, (object)"VikingNutrition_Echoes"); CharacterStatManager.RemoveModifiersByOwner((Character)(object)player, (object)"VikingNutrition_Achievements"); } } public static string GetLocalizedFoodName(string? prefabName) { if (string.IsNullOrEmpty(prefabName)) { return string.Empty; } if ((Object)(object)ObjectDB.instance != (Object)null) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName); SharedData val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null)?.m_itemData?.m_shared; if (val != null && !string.IsNullOrEmpty(val.m_name)) { return LocalizeFoodName(val.m_name, prefabName); } } return HumanizePrefabName(prefabName); } public static Sprite? GetFoodIcon(string? prefabName) { if (string.IsNullOrEmpty(prefabName) || (Object)(object)ObjectDB.instance == (Object)null) { return null; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName); ItemData val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null)?.m_itemData; if (val?.m_shared?.m_icons != null && val.m_shared.m_icons.Length != 0) { return val.GetIcon(); } return null; } internal static void OnUpdateFood(Player player, float dt, bool forceUpdate) { if ((Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer) { return; } if (!ModConfig.Enabled.Value) { ClearAllNutritionModifiers(player); return; } PlayerNutritionState state = GetState(player); if (!state.IsLoadedFromCustomData) { LoadFromCustomData(player, state); } if (!forceUpdate && dt > 0f && state.Echoes.Count > 0) { float num = ComputeEchoScaledDt(player, dt); if (num > 0f) { _expiredKeysScratch.Clear(); foreach (KeyValuePair<string, LongTermEchoEntry> echo in state.Echoes) { LongTermEchoEntry value = echo.Value; value.RemainingTime -= num; if (value.RemainingTime <= 0f) { _expiredKeysScratch.Add(echo.Key); } } if (_expiredKeysScratch.Count > 0) { for (int i = 0; i < _expiredKeysScratch.Count; i++) { state.Echoes.Remove(_expiredKeysScratch[i]); } state.ModifiersDirty = true; state.PersistenceDirty = true; NutritionManager.OnNutritionStateChanged?.Invoke(player); } } } CheckActiveSlotsForLockIn(player, state, allowLockIn: true); if (!forceUpdate && dt > 0f) { state.ModifierSyncAccumulator += dt; state.PersistenceSaveAccumulator += dt; } if (state.ModifiersDirty || forceUpdate || state.ModifierSyncAccumulator >= 1f) { state.ModifierSyncAccumulator = 0f; bool modifiersDirty = state.ModifiersDirty; state.ModifiersDirty = false; bool refreshVitals = modifiersDirty || forceUpdate || state.Echoes.Count > 0; SyncModifiers(player, state, refreshVitals); } if (state.PersistenceSaveAccumulator >= 30f && (state.PersistenceDirty || state.Echoes.Count > 0)) { state.PersistenceSaveAccumulator = 0f; state.PersistenceDirty = false; SaveToCustomData(player, state); } } internal static void OnBeforeEatFood(Player player) { if (!((Object)(object)player == (Object)null) && !((Object)(object)player != (Object)(object)Player.m_localPlayer) && ModConfig.Enabled.Value) { PlayerNutritionState state = GetState(player); if (!state.IsLoadedFromCustomData) { LoadFromCustomData(player, state); } CheckActiveSlotsForLockIn(player, state, allowLockIn: true); } } internal static void OnAfterEatFood(Player player, ItemData item, bool eaten) { if (eaten && !((Object)(object)player == (Object)null) && !((Object)(object)player != (Object)(object)Player.m_localPlayer) && ModConfig.Enabled.Value) { PlayerNutritionState state = GetState(player); string text = FoodCatalog.ResolvePrefabName(item); if (!string.IsNullOrEmpty(text)) { float lastObservedTime = ((item.m_shared != null) ? item.m_shared.m_foodBurnTime : 0f); state.ActiveSlots[text] = new ActiveSlotTrack(text, echoLocked: false, lastObservedTime); } CheckActiveSlotsForLockIn(player, state, allowLockIn: false); state.ModifiersDirty = true; state.PersistenceDirty = true; SyncModifiers(player, state, refreshVitals: true); SaveToCustomData(player, state); NutritionManager.OnNutritionStateChanged?.Invoke(player); } } internal static void OnRemoveOneFood(Player player, bool removed) { if (removed && !((Object)(object)player == (Object)null) && !((Object)(object)player != (Object)(object)Player.m_localPlayer) && ModConfig.Enabled.Value) { PlayerNutritionState state = GetState(player); CheckActiveSlotsForLockIn(player, state, allowLockIn: false); state.ModifiersDirty = true; state.PersistenceDirty = true; SyncModifiers(player, state, refreshVitals: true); NutritionManager.OnNutritionS