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 Enigmas Useful Tasty Mead v0.1.0
EnigmasUsefulTastyMead.dll
Decompiled 4 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace EnigmasUsefulTastyMead { [BepInPlugin("EnigmaPrime.EnigmasUsefulTastyMead", "Enigma's Useful Tasty Mead", "0.1.0")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "EnigmaPrime.EnigmasUsefulTastyMead"; public const string PluginName = "Enigma's Useful Tasty Mead"; public const string PluginVersion = "0.1.0"; internal static ManualLogSource Log; internal static ConfigEntry<float> DurationSeconds; internal static ConfigEntry<float> FadePower; internal static ConfigEntry<bool> ApplyToEitr; private Harmony _harmony; private void Awake() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; DurationSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DurationSeconds", 120f, new ConfigDescription("How long the Tasty Mead boost lasts, in seconds. This is also the time shown on the status icon.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 600f), Array.Empty<object>())); FadePower = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FadePower", 0.5f, new ConfigDescription("Shape of the fade. The boost strength is (time left / duration) raised to this power. Food itself uses 0.3. Higher means it drops sooner, lower means it holds longer and then crashes at the end.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 2f), Array.Empty<object>())); ApplyToEitr = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ApplyToEitr", true, "Also boost the Eitr cap from food (health and stamina are always boosted)."); ((BaseUnityPlugin)this).Config.SettingChanged += delegate { TastyEffect.Apply(ObjectDB.instance); }; _harmony = new Harmony("EnigmaPrime.EnigmasUsefulTastyMead"); _harmony.PatchAll(); foreach (MethodBase patchedMethod in _harmony.GetPatchedMethods()) { Log.LogInfo((object)("Patched: " + patchedMethod.DeclaringType?.Name + "." + patchedMethod.Name)); } Log.LogInfo((object)"Enigma's Useful Tasty Mead 0.1.0 loaded."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class BoostMath { internal static float Weight(float remaining, float duration, float power) { if (duration <= 0f) { return 0f; } float num = remaining / duration; if (num <= 0f) { return 0f; } if (num >= 1f) { return 1f; } return (float)Math.Pow(num, power); } internal static float Blend(float real, float full, float weight) { if (full <= real) { return real; } if (weight <= 0f) { return real; } if (weight >= 1f) { return full; } return real + (full - real) * weight; } } internal static class TastyEffect { internal const string ItemName = "MeadTasty"; internal const string EffectName = "Potion_tasty"; internal static StatusEffect Effect; internal const string Description = "A sweet mead that leaves you feeling full and refreshed again."; internal const string Tooltip = "Your active foods count as freshly eaten, lifting your max health, stamina and Eitr to the full values they gave when eaten. The boost fades back to what your food really gives. Does not heal you and does not change food timers."; private static string _lastReport = ""; internal static void Apply(ObjectDB db) { if ((Object)(object)db == (Object)null || db.m_items == null || db.m_items.Count == 0) { return; } GameObject val = db.m_items.Find((GameObject go) => (Object)(object)go != (Object)null && ((Object)go).name == "MeadTasty"); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); StatusEffect val3 = (((Object)(object)val2 != (Object)null) ? val2.m_itemData.m_shared.m_consumeStatusEffect : null); StatusEffect val4 = ((db.m_StatusEffects != null) ? db.m_StatusEffects.Find((StatusEffect se) => (Object)(object)se != (Object)null && ((Object)se).name == "Potion_tasty") : null); if ((Object)(object)val3 == (Object)null && (Object)(object)val4 == (Object)null) { Plugin.Log.LogWarning((object)"Tasty Mead (MeadTasty / Potion_tasty) not found in the item database, nothing changed."); return; } HashSet<StatusEffect> hashSet = new HashSet<StatusEffect>(); StatusEffect[] array = (StatusEffect[])(object)new StatusEffect[2] { val3, val4 }; foreach (StatusEffect val5 in array) { if (!((Object)(object)val5 == (Object)null) && hashSet.Add(val5)) { Tune(val5); } } Effect = (((Object)(object)val3 != (Object)null) ? val3 : val4); if ((Object)(object)val2 != (Object)null) { val2.m_itemData.m_shared.m_description = "A sweet mead that leaves you feeling full and refreshed again."; } string text = "Tasty Mead retuned: duration " + Plugin.DurationSeconds.Value + "s, fade power " + Plugin.FadePower.Value + ", Eitr " + (Plugin.ApplyToEitr.Value ? "on" : "off") + "."; if (text != _lastReport) { Plugin.Log.LogInfo((object)text); _lastReport = text; } } private static void Tune(StatusEffect se) { se.m_ttl = Plugin.DurationSeconds.Value; se.m_tooltip = "Your active foods count as freshly eaten, lifting your max health, stamina and Eitr to the full values they gave when eaten. The boost fades back to what your food really gives. Does not heal you and does not change food timers."; SE_Stats val = (SE_Stats)(object)((se is SE_Stats) ? se : null); if ((Object)(object)val != (Object)null) { val.m_healthRegenMultiplier = 1f; val.m_staminaRegenMultiplier = 1f; val.m_eitrRegenMultiplier = 1f; } else { Plugin.Log.LogWarning((object)(((Object)se).name + " is not an SE_Stats, regen values were not reset.")); } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class ObjectDBAwakePatch { private static void Postfix(ObjectDB __instance) { TastyEffect.Apply(__instance); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] internal static class ObjectDBCopyPatch { private static void Postfix(ObjectDB __instance) { TastyEffect.Apply(__instance); } } internal static class TastyBoost { private static bool _wasBoosting; private static Action<Player, float, bool> _setMaxEitr; internal static bool WasBoosting { get { return _wasBoosting; } set { _wasBoosting = value; } } internal static float ActiveWeight(Player p) { if ((Object)(object)p == (Object)null || (Object)(object)p != (Object)(object)Player.m_localPlayer || (Object)(object)TastyEffect.Effect == (Object)null) { return -1f; } StatusEffect statusEffect = ((Character)p).GetSEMan().GetStatusEffect(TastyEffect.Effect.NameHash()); if ((Object)(object)statusEffect == (Object)null) { return -1f; } return BoostMath.Weight(statusEffect.GetRemaningTime(), statusEffect.m_ttl, Plugin.FadePower.Value); } internal static void Compute(Player p, float weight, out float hp, out float stamina, out float eitr) { hp = p.m_baseHP; stamina = p.m_baseStamina; eitr = 0f; float weight2 = (Plugin.ApplyToEitr.Value ? weight : 0f); foreach (Food food in p.GetFoods()) { SharedData shared = food.m_item.m_shared; hp += BoostMath.Blend(food.m_health, shared.m_food, weight); stamina += BoostMath.Blend(food.m_stamina, shared.m_foodStamina, weight); eitr += BoostMath.Blend(food.m_eitr, shared.m_foodEitr, weight2); } } internal static void ApplyCaps(Player p, float hp, float stamina, float eitr, bool flash) { if (Math.Abs(((Character)p).GetMaxHealth() - hp) > 0.05f) { p.SetMaxHealth(hp, flash); } if (Math.Abs(((Character)p).GetMaxStamina() - stamina) > 0.05f) { p.SetMaxStamina(stamina, flash); } if (Math.Abs(((Character)p).GetMaxEitr() - eitr) > 0.05f) { if (_setMaxEitr == null) { MethodInfo method = AccessTools.Method(typeof(Player), "SetMaxEitr", (Type[])null, (Type[])null); _setMaxEitr = (Action<Player, float, bool>)Delegate.CreateDelegate(typeof(Action<Player, float, bool>), method); } _setMaxEitr(p, eitr, flash); } } } [HarmonyPatch(typeof(Player), "GetTotalFoodValue")] internal static class GetTotalFoodValuePatch { private static void Postfix(Player __instance, ref float hp, ref float stamina, ref float eitr) { float num = TastyBoost.ActiveWeight(__instance); if (!(num < 0f)) { TastyBoost.Compute(__instance, num, out hp, out stamina, out eitr); } } } [HarmonyPatch(typeof(Player), "UpdateFood")] internal static class UpdateFoodPatch { private static void Postfix(Player __instance) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { float num = TastyBoost.ActiveWeight(__instance); if (num >= 0f) { TastyBoost.Compute(__instance, num, out var hp, out var stamina, out var eitr); TastyBoost.ApplyCaps(__instance, hp, stamina, eitr, !TastyBoost.WasBoosting); TastyBoost.WasBoosting = true; } else if (TastyBoost.WasBoosting) { TastyBoost.Compute(__instance, 0f, out var hp2, out var stamina2, out var eitr2); TastyBoost.ApplyCaps(__instance, hp2, stamina2, eitr2, flash: false); TastyBoost.WasBoosting = false; } } } } }