Please disclose if your mod was created primarily 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 TrollberryMead v1.7.2
TrollberryMead.dll
Decompiled 3 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Trollberrymead")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("HP")] [assembly: AssemblyProduct("Trollberrymead")] [assembly: AssemblyCopyright("Copyright © HP 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("379729c7-ddb4-44e4-9365-2f169e344b41")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 TrollberryMeadMod { [BepInPlugin("youdied.trollberry", "Trollberry Mead", "1.7.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class TrollberryMeadPlugin : BaseUnityPlugin { public static SE_Stats toxicityEffect; public static readonly Dictionary<string, Color> RecolorTargets = new Dictionary<string, Color>(); public static readonly Color LightBlue = new Color(0.1f, 0.5f, 1f, 1f); public static Texture2D MeadBaseTexture = null; public static Texture2D MeadTexture = null; public static TrollberryMeadPlugin Instance { get; private set; } private void Awake() { Instance = this; CreateToxicityEffect(); SafePatch(typeof(TrollDropPatch)); SafePatch(typeof(FermenterPatch)); SafePatch(typeof(ObjectDBPatch)); SafePatch(typeof(ToxicityDamagePatch)); SafePatch(typeof(TrollberryConsumePatch)); SafePatch(typeof(ItemDropRecolorPatch)); PrefabManager.OnVanillaPrefabsAvailable += CreateItems; ItemManager.OnItemsRegistered += ApplyMeadBaseTexture; ItemManager.OnItemsRegistered += ApplyMeadTexture; Logger.LogInfo((object)"Trollberry Mead (v1.7.2)"); } private void SafePatch(Type t) { try { Harmony.CreateAndPatchAll(t, (string)null); } catch (Exception ex) { Logger.LogWarning((object)("[TrollberryMead] Patch failed for " + t.Name + ": " + ex.Message)); } } private void CreateToxicityEffect() { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) toxicityEffect = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)toxicityEffect).name = "SE_TrollBerryToxicity"; ((StatusEffect)toxicityEffect).m_name = "Trollberry Toxin"; ((StatusEffect)toxicityEffect).m_tooltip = "Poisoned! 1 damage/sec for 20 seconds."; ((StatusEffect)toxicityEffect).m_icon = null; ((StatusEffect)toxicityEffect).m_ttl = 20f; ((StatusEffect)toxicityEffect).m_startMessageType = (MessageType)1; ((StatusEffect)toxicityEffect).m_startMessage = "You ate a Trollberry..."; ((StatusEffect)toxicityEffect).m_stopMessageType = (MessageType)1; ((StatusEffect)toxicityEffect).m_stopMessage = "The toxin has passed."; } private void CreateItems() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Expected O, but got Unknown //IL_018c: 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_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Expected O, but got Unknown //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Expected O, but got Unknown //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Expected O, but got Unknown //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Expected O, but got Unknown //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Expected O, but got Unknown //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Expected O, but got Unknown //IL_0341: Unknown result type (might be due to invalid IL or missing references) MeadBaseTexture = LoadEmbeddedTexture("meadbase_d2.png"); if ((Object)(object)MeadBaseTexture != (Object)null) { Logger.LogInfo((object)"[TrollberryMead] Loaded meadbase_d2.png successfully."); } else { Logger.LogWarning((object)"[TrollberryMead] meadbase_d2.png not found -- check it is an embedded resource."); } MeadTexture = LoadEmbeddedTexture("staminapot_d2.png"); if ((Object)(object)MeadTexture != (Object)null) { Logger.LogInfo((object)"[TrollberryMead] Loaded staminapot_d2.png successfully."); } else { Logger.LogWarning((object)"[TrollberryMead] staminapot_d2.png not found -- check it is an embedded resource."); } CustomItem val = new CustomItem("trollberry", "Blueberries", new ItemConfig { Name = "Trollberry", Description = "A brown pile of 'berries' often found near trolls. Looks and smells like you shouldn't eat it." }); if ((Object)(object)val.ItemDrop != (Object)null) { SharedData shared = val.ItemDrop.m_itemData.m_shared; shared.m_icons = (Sprite[])(object)new Sprite[1] { LoadEmbeddedSprite("trollberry_icon.png") }; shared.m_itemType = (ItemType)1; shared.m_food = 0f; shared.m_foodStamina = 0f; shared.m_foodBurnTime = 0f; shared.m_foodRegen = 0f; shared.m_consumeStatusEffect = null; shared.m_useDurability = false; shared.m_maxStackSize = 20; ApplyTrollBrown(val.ItemPrefab); ItemManager.Instance.AddItem(val); } ItemConfig val2 = new ItemConfig(); val2.Name = "Mead Base: Trollberry"; val2.Description = "A thick, electric-blue syrup. Needs fermenting."; val2.CraftingStation = "piece_MeadCauldron"; val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "trollberry", Amount = 3 }, new RequirementConfig { Item = "Dandelion", Amount = 3 }, new RequirementConfig { Item = "Coal", Amount = 10 } }; CustomItem val3 = new CustomItem("MeadBaseTrollberry", "MeadBaseHealthMinor", val2); if ((Object)(object)val3.ItemDrop != (Object)null) { SharedData shared2 = val3.ItemDrop.m_itemData.m_shared; shared2.m_icons = (Sprite[])(object)new Sprite[1] { LoadEmbeddedSprite("meadbase_icon.png") }; shared2.m_consumeStatusEffect = null; shared2.m_food = 0f; shared2.m_foodStamina = 0f; shared2.m_foodBurnTime = 0f; ItemManager.Instance.AddItem(val3); } CustomItem val4 = new CustomItem("MeadTrollberry", "MeadStaminaMinor", new ItemConfig { Name = "Trollberry Mead", Description = "Hardens skin (25% Damage Reduction) for 90s." }); if ((Object)(object)val4.ItemDrop != (Object)null) { SharedData shared3 = val4.ItemDrop.m_itemData.m_shared; shared3.m_icons = (Sprite[])(object)new Sprite[1] { LoadEmbeddedSprite("mead_icon.png") }; SE_Stats val5 = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)val5).name = "SE_TrollSkin"; ((StatusEffect)val5).m_name = "Troll Skin"; ((StatusEffect)val5).m_ttl = 90f; val5.m_damageModifier = 0.75f; shared3.m_consumeStatusEffect = (StatusEffect)(object)val5; ItemManager.Instance.AddItem(val4); RecolorTargets["MeadTrollberry"] = new Color(0f, 0.6f, 2f, 0f); } } private void ApplyTrollBrown(GameObject obj) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)obj == (Object)null) { return; } Color color = default(Color); ((Color)(ref color))..ctor(0.25f, 0.15f, 0.05f); Renderer[] componentsInChildren = obj.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { Material[] materials = val.materials; foreach (Material val2 in materials) { val2.color = color; } } } private void ApplyMeadBaseTexture() { if (!((Object)(object)MeadBaseTexture == (Object)null)) { GameObject prefab = PrefabManager.Instance.GetPrefab("MeadBaseTrollberry"); if (!((Object)(object)prefab == (Object)null)) { ApplyTextureToStew(prefab, MeadBaseTexture); Logger.LogInfo((object)"[TrollberryMead] Applied meadbase_d2 texture to MeadBaseTrollberry prefab."); } } } private void ApplyMeadTexture() { if (!((Object)(object)MeadTexture == (Object)null)) { GameObject prefab = PrefabManager.Instance.GetPrefab("MeadTrollberry"); if (!((Object)(object)prefab == (Object)null)) { ApplyTextureToPotion(prefab, MeadTexture); Logger.LogInfo((object)"[TrollberryMead] Applied staminapot_d2.png to MeadTrollberry prefab."); } } } public static void ApplyTextureToChild(GameObject go, string childName, Texture2D tex) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown Transform[] componentsInChildren = go.GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (!string.Equals(((Object)val).name, childName, StringComparison.OrdinalIgnoreCase)) { continue; } Renderer component = ((Component)val).GetComponent<Renderer>(); if ((Object)(object)component == (Object)null) { continue; } Material[] sharedMaterials = component.sharedMaterials; Material[] array = (Material[])(object)new Material[sharedMaterials.Length]; for (int j = 0; j < sharedMaterials.Length; j++) { array[j] = new Material(sharedMaterials[j]); ((Object)array[j]).name = ((Object)sharedMaterials[j]).name + "_trollberry"; if (array[j].HasProperty("_MainTex")) { array[j].SetTexture("_MainTex", (Texture)(object)tex); } } component.sharedMaterials = array; component.SetPropertyBlock((MaterialPropertyBlock)null); Logger.LogInfo((object)$"[TrollberryMead] _MainTex set on '{childName}' ({array.Length} slots)."); } } public static void ApplyTextureToPotion(GameObject go, Texture2D tex) { ApplyTextureToChild(go, "potion", tex); } public static void ApplyTextureToStew(GameObject go, Texture2D tex) { ApplyTextureToChild(go, "stew", tex); } private static Texture2D LoadEmbeddedTexture(string fileName) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown try { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string x) => x.EndsWith(fileName, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(text)) { Logger.LogWarning((object)("[TrollberryMead] Embedded resource not found: " + fileName)); return null; } using Stream stream = executingAssembly.GetManifestResourceStream(text); byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); ((Object)val).name = Path.GetFileNameWithoutExtension(fileName); return ImageConversion.LoadImage(val, array) ? val : null; } catch (Exception ex) { Logger.LogWarning((object)("[TrollberryMead] LoadEmbeddedTexture error: " + ex.Message)); return null; } } private Sprite LoadEmbeddedSprite(string fileName) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) Assembly executingAssembly = Assembly.GetExecutingAssembly(); string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string x) => x.EndsWith(fileName, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(text)) { return null; } using (Stream stream = executingAssembly.GetManifestResourceStream(text)) { byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2); if (ImageConversion.LoadImage(val, array)) { return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } } return null; } } [HarmonyPatch(typeof(ItemDrop), "Awake")] public class ItemDropRecolorPatch { public static void Postfix(ItemDrop __instance) { //IL_00f2: 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) try { if ((Object)(object)__instance == (Object)null) { return; } string text = ((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "").Trim(); if (!TrollberryMeadPlugin.RecolorTargets.TryGetValue(text, out var _)) { return; } Logger.LogInfo((object)("[TrollberryMead] Recoloring instance of '" + text + "'")); if (text == "MeadBaseTrollberry") { if ((Object)(object)TrollberryMeadPlugin.MeadBaseTexture != (Object)null) { TrollberryMeadPlugin.ApplyTextureToStew(((Component)__instance).gameObject, TrollberryMeadPlugin.MeadBaseTexture); } return; } if (text == "MeadTrollberry" && (Object)(object)TrollberryMeadPlugin.MeadTexture != (Object)null) { TrollberryMeadPlugin.ApplyTextureToPotion(((Component)__instance).gameObject, TrollberryMeadPlugin.MeadTexture); Logger.LogInfo((object)"[TrollberryMead] -> Applied staminapot_d2.png to potion mesh instance."); } Light[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Light>(true); foreach (Light val in componentsInChildren) { val.color = TrollberryMeadPlugin.LightBlue; val.intensity = 1.8f; val.range = 2.5f; Logger.LogInfo((object)("[TrollberryMead] -> Recolored light on '" + ((Object)((Component)val).gameObject).name + "'")); } if ((Object)(object)((Component)__instance).GetComponent<Light>() == (Object)null) { Light val2 = ((Component)__instance).gameObject.AddComponent<Light>(); val2.type = (LightType)2; val2.color = TrollberryMeadPlugin.LightBlue; val2.intensity = 1.8f; val2.range = 2.5f; val2.shadows = (LightShadows)0; Logger.LogInfo((object)"[TrollberryMead] -> Added ground glow light on root."); } } catch (Exception ex) { Logger.LogWarning((object)("[TrollberryMead] ItemDropRecolorPatch error: " + ex.Message)); } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] public class ObjectDBPatch { public static void Postfix(ObjectDB __instance) { if ((Object)(object)TrollberryMeadPlugin.toxicityEffect == (Object)null) { return; } if (!__instance.m_StatusEffects.Contains((StatusEffect)(object)TrollberryMeadPlugin.toxicityEffect)) { __instance.m_StatusEffects.Add((StatusEffect)(object)TrollberryMeadPlugin.toxicityEffect); } if (!((Object)(object)((StatusEffect)TrollberryMeadPlugin.toxicityEffect).m_icon == (Object)null)) { return; } StatusEffect val = ((IEnumerable<StatusEffect>)__instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect se) => (Object)(object)se != (Object)null && (((Object)se).name == "Poison" || ((Object)se).name == "SE_Poison"))); if ((Object)(object)val?.m_icon != (Object)null) { ((StatusEffect)TrollberryMeadPlugin.toxicityEffect).m_icon = val.m_icon; return; } StatusEffect val2 = ((IEnumerable<StatusEffect>)__instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect se) => (Object)(object)se?.m_icon != (Object)null)); if ((Object)(object)val2 != (Object)null) { ((StatusEffect)TrollberryMeadPlugin.toxicityEffect).m_icon = val2.m_icon; } } } [HarmonyPatch(typeof(StatusEffect), "UpdateStatusEffect")] public class ToxicityDamagePatch { private static readonly Dictionary<Character, float> timers = new Dictionary<Character, float>(); public static void Postfix(StatusEffect __instance, float dt) { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) if (!(((Object)__instance).name != "SE_TrollBerryToxicity") && !((Object)(object)__instance.m_character == (Object)null)) { Character character = __instance.m_character; if (!timers.ContainsKey(character)) { timers[character] = 0f; } timers[character] += dt; if (timers[character] >= 1f) { HitData val = new HitData(); val.m_damage.m_damage = 1f; val.m_point = character.GetCenterPoint(); character.Damage(val); timers[character] = 0f; } } } } [HarmonyPatch(typeof(Humanoid), "UseItem")] public class TrollberryConsumePatch { public static bool Prefix(Humanoid __instance, Inventory inventory, ItemData item, bool fromInventoryGui) { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) if (item == null) { return true; } if (item.m_shared.m_name != "Trollberry") { return true; } Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val == null) { return true; } if ((Object)(object)TrollberryMeadPlugin.toxicityEffect != (Object)null) { ((Character)val).GetSEMan().AddStatusEffect((StatusEffect)(object)TrollberryMeadPlugin.toxicityEffect, true, 0, 0f); } (inventory ?? ((Humanoid)val).GetInventory()).RemoveOneItem(item); EffectList consumeItemEffects = ((Humanoid)val).m_consumeItemEffects; if (consumeItemEffects != null) { consumeItemEffects.Create(((Component)val).transform.position, Quaternion.identity, (Transform)null, 1f, -1); } return false; } } [HarmonyPatch(typeof(Fermenter), "Awake")] public class FermenterPatch { public static void Postfix(Fermenter __instance) { //IL_0092: 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_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Expected O, but got Unknown ObjectDB instance = ObjectDB.instance; if (!((Object)(object)instance == (Object)null)) { GameObject itemPrefab = instance.GetItemPrefab("MeadBaseTrollberry"); ItemDrop from = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); GameObject itemPrefab2 = instance.GetItemPrefab("MeadTrollberry"); ItemDrop val = ((itemPrefab2 != null) ? itemPrefab2.GetComponent<ItemDrop>() : null); if ((Object)(object)from != (Object)null && (Object)(object)val != (Object)null && !__instance.m_conversion.Any((ItemConversion x) => (Object)(object)x.m_from == (Object)(object)from)) { __instance.m_conversion.Add(new ItemConversion { m_from = from, m_to = val }); } } } } [HarmonyPatch(typeof(Character), "OnDeath")] public class TrollDropPatch { public static void Postfix(Character __instance) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) string text = ((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "").Trim(); if (!(text == "Troll") || !(Random.value <= 0.8f)) { return; } GameObject prefab = PrefabManager.Instance.GetPrefab("trollberry"); if (!((Object)(object)prefab == (Object)null)) { int num = Random.Range(3, 6); for (int i = 0; i < num; i++) { Object.Instantiate<GameObject>(prefab, ((Component)__instance).transform.position + Vector3.up, Quaternion.identity); } } } } }