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 DeerberryMead v1.6.2
DeerberryMead.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.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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.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 DeerberryMeadMod { [BepInPlugin("youdied.deerberrymead", "Deerberry Mead", "1.6.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class DeerberryMeadPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(ItemDrop), "Awake")] private class ItemDropTexturePatch { private static void Postfix(ItemDrop __instance) { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_0100: 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 (!TextureTargets.Contains(text)) { return; } if (text == "MeadDeerberry" && (Object)(object)MeadTexture != (Object)null) { ApplyTextureToPotion(((Component)__instance).gameObject, MeadTexture); Logger.LogInfo((object)"[DeerberryMead] Applied staminapot_d2.png to MeadDeerberry instance."); Light[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Light>(true); foreach (Light val in componentsInChildren) { val.color = OrangeGlow; val.intensity = 1.8f; val.range = 2.5f; } if ((Object)(object)((Component)__instance).GetComponent<Light>() == (Object)null) { Light val2 = ((Component)__instance).gameObject.AddComponent<Light>(); val2.type = (LightType)2; val2.color = OrangeGlow; val2.intensity = 1.8f; val2.range = 2.5f; val2.shadows = (LightShadows)0; } Logger.LogInfo((object)"[DeerberryMead] Orange glow light set on MeadDeerberry instance."); } else if (text == "MeadBaseDeerberry" && (Object)(object)MeadBaseTexture != (Object)null) { ApplyTextureToStew(((Component)__instance).gameObject, MeadBaseTexture); Logger.LogInfo((object)"[DeerberryMead] Applied meadbase_d2.png to MeadBaseDeerberry instance."); } } catch (Exception ex) { Logger.LogWarning((object)("[DeerberryMead] ItemDropTexturePatch error: " + ex.Message)); } } } [HarmonyPatch(typeof(StatusEffect), "UpdateStatusEffect")] private class RegretUpdatePatch { private static void Postfix(StatusEffect __instance, float dt) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) if (((Object)__instance).name == "SE_DeerberryRegret" && (Object)(object)__instance.m_character != (Object)null) { float remaningTime = __instance.GetRemaningTime(); float num = remaningTime + dt; if (Mathf.FloorToInt(remaningTime) < Mathf.FloorToInt(num)) { HitData val = new HitData(); val.m_damage.m_damage = 1f; val.m_point = __instance.m_character.GetCenterPoint(); __instance.m_character.ApplyDamage(val, false, false, (DamageModifier)0); } } } } [HarmonyPatch(typeof(StatusEffect), "GetTooltipString")] private class TooltipPatch { private static void Postfix(StatusEffect __instance, ref string __result) { if (((Object)__instance).name == null || !((Object)__instance).name.Contains("Deerberry")) { return; } string[] array = __result.Split('\n'); List<string> list = new List<string>(); string[] array2 = array; foreach (string text in array2) { if (!text.Contains("150%")) { list.Add(text); } } __result = string.Join("\n", list); } } [HarmonyPatch(typeof(Fermenter), "Awake")] private class FermenterPatch { private 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("MeadBaseDeerberry"); ItemDrop from = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); GameObject itemPrefab2 = instance.GetItemPrefab("MeadDeerberry"); 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")] private class DeerDropPatch { private static void Postfix(Character __instance) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) string text = ((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "").Trim(); if (text == "Deer" && Random.value <= 0.2f) { GameObject prefab = PrefabManager.Instance.GetPrefab("Deerberries"); if ((Object)(object)prefab != (Object)null) { Object.Instantiate<GameObject>(prefab, ((Component)__instance).transform.position + Vector3.up, Quaternion.identity); } } } } public static Texture2D MeadTexture = null; public static readonly Color OrangeGlow = new Color(1f, 0.45f, 0f); public static Texture2D MeadBaseTexture = null; public static readonly HashSet<string> TextureTargets = new HashSet<string> { "MeadDeerberry", "MeadBaseDeerberry" }; private void Awake() { Harmony.CreateAndPatchAll(typeof(DeerDropPatch), (string)null); Harmony.CreateAndPatchAll(typeof(FermenterPatch), (string)null); Harmony.CreateAndPatchAll(typeof(TooltipPatch), (string)null); Harmony.CreateAndPatchAll(typeof(RegretUpdatePatch), (string)null); Harmony.CreateAndPatchAll(typeof(ItemDropTexturePatch), (string)null); PrefabManager.OnVanillaPrefabsAvailable += CreateItems; ItemManager.OnItemsRegistered += ApplyPrefabTextures; Logger.LogInfo((object)"Deerberry Mead (v1.6.2)"); } private void CreateItems() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Expected O, but got Unknown //IL_0198: 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_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Expected O, but got Unknown //IL_01b4: 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_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Expected O, but got Unknown //IL_01d0: 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_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Expected O, but got Unknown //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Expected O, but got Unknown //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Expected O, but got Unknown //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Expected O, but got Unknown MeadTexture = LoadEmbeddedTexture("staminapot_d2.png"); MeadBaseTexture = LoadEmbeddedTexture("meadbase_d2.png"); if ((Object)(object)MeadTexture != (Object)null) { Logger.LogInfo((object)"[DeerberryMead] Loaded staminapot_d2.png."); } else { Logger.LogWarning((object)"[DeerberryMead] staminapot_d2.png not found -- check embedded resources."); } if ((Object)(object)MeadBaseTexture != (Object)null) { Logger.LogInfo((object)"[DeerberryMead] Loaded meadbase_d2.png."); } else { Logger.LogWarning((object)"[DeerberryMead] meadbase_d2.png not found -- check embedded resources."); } CustomItem val = new CustomItem("Deerberries", "Pukeberries", new ItemConfig()); if ((Object)(object)val.ItemDrop != (Object)null) { SharedData shared = val.ItemDrop.m_itemData.m_shared; shared.m_name = "Deerberries"; shared.m_description = "A cluster of dark, compressed organic matter found on the forest floor. I wouldn't eat that if I were you"; shared.m_icons = (Sprite[])(object)new Sprite[1] { LoadEmbeddedSprite("deerberry_icon.png") }; SE_Stats val2 = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)val2).name = "SE_DeerberryRegret"; ((StatusEffect)val2).m_name = "Berry Regret"; ((StatusEffect)val2).m_tooltip = "Tastes exactly how it looks."; ((StatusEffect)val2).m_ttl = 10f; ((StatusEffect)val2).m_icon = LoadEmbeddedSprite("deerberry_icon.png"); val2.m_healthOverTime = 0f; val2.m_staminaOverTime = 0f; val2.m_staminaRegenMultiplier = 1f; shared.m_consumeStatusEffect = (StatusEffect)(object)val2; ApplyPoopLook(val.ItemPrefab); ItemManager.Instance.AddItem(val); } ItemConfig val3 = new ItemConfig(); val3.CraftingStation = "piece_MeadCauldron"; val3.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "Deerberries", Amount = 1 }, new RequirementConfig { Item = "Resin", Amount = 1 }, new RequirementConfig { Item = "Coal", Amount = 10 } }; CustomItem val4 = new CustomItem("MeadBaseDeerberry", "MeadBaseStaminaMinor", val3); if ((Object)(object)val4.ItemDrop != (Object)null) { SharedData shared2 = val4.ItemDrop.m_itemData.m_shared; shared2.m_name = "Mead Base: Deerberry"; shared2.m_description = "Needs to be fermented."; shared2.m_icons = (Sprite[])(object)new Sprite[1] { LoadEmbeddedSprite("meadbase_icon.png") }; SE_Stats val5 = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)val5).name = "SE_DeerberryBaseEffect"; ((StatusEffect)val5).m_name = "Deerberry Mead"; ((StatusEffect)val5).m_tooltip = "Speed 150%"; ((StatusEffect)val5).m_ttl = 30f; val5.m_speedModifier = 1.5f; shared2.m_consumeStatusEffect = (StatusEffect)(object)val5; ItemManager.Instance.AddItem(val4); } CustomItem val6 = new CustomItem("MeadDeerberry", "MeadStaminaMinor", new ItemConfig()); if ((Object)(object)val6.ItemDrop != (Object)null) { SharedData shared3 = val6.ItemDrop.m_itemData.m_shared; shared3.m_name = "Deerberry Mead"; shared3.m_description = "Tastes like dirt and lightning."; shared3.m_icons = (Sprite[])(object)new Sprite[1] { LoadEmbeddedSprite("mead_icon.png") }; SE_Stats val7 = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)val7).name = "SE_DeerberrySpeed"; ((StatusEffect)val7).m_name = "Deer Swiftness"; ((StatusEffect)val7).m_tooltip = "Speed 150%"; ((StatusEffect)val7).m_ttl = 30f; val7.m_speedModifier = 1.5f; ((StatusEffect)val7).m_icon = LoadEmbeddedSprite("speed_status.png"); shared3.m_consumeStatusEffect = (StatusEffect)(object)val7; ItemManager.Instance.AddItem(val6); } } private void ApplyPrefabTextures() { if ((Object)(object)MeadTexture != (Object)null) { GameObject prefab = PrefabManager.Instance.GetPrefab("MeadDeerberry"); if ((Object)(object)prefab != (Object)null) { ApplyTextureToPotion(prefab, MeadTexture); Logger.LogInfo((object)"[DeerberryMead] Applied staminapot_d2.png to MeadDeerberry prefab."); } } if ((Object)(object)MeadBaseTexture != (Object)null) { GameObject prefab2 = PrefabManager.Instance.GetPrefab("MeadBaseDeerberry"); if ((Object)(object)prefab2 != (Object)null) { ApplyTextureToStew(prefab2, MeadBaseTexture); Logger.LogInfo((object)"[DeerberryMead] Applied meadbase_d2.png to MeadBaseDeerberry 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 + "_deerberry"; if (array[j].HasProperty("_MainTex")) { array[j].SetTexture("_MainTex", (Texture)(object)tex); } } component.sharedMaterials = array; component.SetPropertyBlock((MaterialPropertyBlock)null); Logger.LogInfo((object)$"[DeerberryMead] _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 void ApplyPoopLook(GameObject obj) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)obj == (Object)null) { return; } Color val = default(Color); ((Color)(ref val))..ctor(0.22f, 0.12f, 0.04f); obj.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); Renderer[] componentsInChildren = obj.GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if (((object)val2).GetType().Name.Contains("ParticleSystemRenderer")) { continue; } Material[] materials = val2.materials; foreach (Material val3 in materials) { if (val3.HasProperty("_Color")) { val3.SetColor("_Color", val); } if (val3.HasProperty("_EmissionColor")) { val3.SetColor("_EmissionColor", Color.black); } val3.DisableKeyword("_EMISSION"); } } } 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)("[DeerberryMead] 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)("[DeerberryMead] LoadEmbeddedTexture error: " + ex.Message)); return null; } } private Sprite LoadEmbeddedSprite(string fileName) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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, (int)stream.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; } } } namespace DeerberryMead { public class Class1 { } }