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 ZenBeehive v0.4.0
plugins/ZenBeehive.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using Zen; using Zen.Compatibility; using Zen.Lib; using Zen.Lib.Config; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ZenBeehive")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ZenBeehive")] [assembly: AssemblyCopyright("Copyright \ufffd 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.0")] [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.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] [Microsoft.CodeAnalysis.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] [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 ZenBeehive { [HarmonyPatch] internal static class BeehiveUI { private static bool _allowAddItem; private const string PrefabName = "piece_beehive"; private const string InventoryName = "$piece_beehive"; private static Beehive? _beehive; private static bool IsHoneyOpen() { return Object.op_Implicit((Object)(object)_beehive); } private static bool IsHoneyOpen(out Beehive beehive) { return Object.op_Implicit((Object)(object)(beehive = _beehive)); } internal static void SetupPrefab() { Logging<Plugin>.Info((object)"Setting up beehive prefab container...", 0); GameObject prefab = ZNetScene.instance.GetPrefab("piece_beehive"); Beehive component = prefab.GetComponent<Beehive>(); Container orAddComponent = ExposedGameObjectExtension.GetOrAddComponent<Container>(prefab); orAddComponent.m_name = "$piece_beehive"; orAddComponent.m_width = 1; orAddComponent.m_height = 1; GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(Configs.HoneyItem.Value); if (!Object.op_Implicit((Object)(object)itemPrefab)) { Logging<Plugin>.Error((object)("Item not found: " + Configs.HoneyItem.Value), (ushort)0); } else { component.m_honeyItem = itemPrefab.GetComponent<ItemDrop>(); } if (Configs.MaxHoney.Value > 0) { component.m_maxHoney = Mathf.Min(component.m_honeyItem.m_itemData.m_shared.m_maxStackSize, Configs.MaxHoney.Value); } if (Configs.SecPerUnit.Value > 0) { component.m_secPerUnit = Configs.SecPerUnit.Value; } } private static GameObject GetHoneyItemPrefab(this Beehive beehive) { return ObjectDB.instance.GetItemPrefab(((Object)beehive.m_honeyItem).name); } private static int UpdateHoneyFromContainer(this Beehive beehive) { InventoryGrid containerGrid = InventoryGui.instance.ContainerGrid; Inventory val = ((containerGrid != null) ? containerGrid.GetInventory() : null) ?? ((Component)beehive).GetComponent<Container>().GetInventory(); return beehive.SetHoneyLevel(val.NrOfItemsIncludingStacks()); } private static int SetHoneyLevel(this Beehive beehive, int level) { if (level == beehive.GetHoneyLevel()) { return level; } beehive.m_nview.ClaimOwnership(); beehive.m_nview.GetZDO().Set(ZDOVars.s_level, level, false); return level; } [HarmonyPrefix] [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })] private static void Inventory_AddItem(Inventory __instance, ItemData item, ref bool __result, ref bool __runOriginal) { if (!_allowAddItem && __instance.m_name == "$piece_beehive") { __runOriginal = (__result = false); } } [HarmonyPrefix] [HarmonyPatch(typeof(Beehive), "Extract")] private static void Beehive_Extract(Beehive __instance, ref bool __runOriginal) { Logging<Plugin>.Info((object)"Extracting ... opening beehive container.", 0); ((Component)__instance).GetComponent<Container>().Interact((Humanoid)(object)Player.m_localPlayer, false, false); __runOriginal = false; } private static void FillContainer(this Beehive beehive, Container container) { Inventory inventory = container.GetInventory(); ItemData val = ((inventory.NrOfItems() > 0) ? inventory.GetItem(0) : null); int honeyLevel = beehive.GetHoneyLevel(); if (val == null || val.m_stack != honeyLevel) { GameObject honeyItemPrefab = beehive.GetHoneyItemPrefab(); if (inventory.NrOfItems() > 0) { inventory.RemoveAll(); } if (honeyLevel > 0) { _allowAddItem = true; inventory.AddItem(honeyItemPrefab, honeyLevel); _allowAddItem = false; } } } [HarmonyPostfix] [HarmonyPatch(typeof(Beehive), "UpdateBees")] private static void Beehive_UpdateBees(Beehive __instance) { if (__instance.m_nview.IsOwner()) { __instance.FillContainer(((Component)__instance).GetComponent<Container>()); } } [HarmonyPrefix] [HarmonyPatch(typeof(InventoryGui), "Hide")] private static void InventoryGui_Hide(InventoryGui __instance) { _beehive = null; } [HarmonyPrefix] [HarmonyPatch(typeof(InventoryGui), "Show")] private static void InventoryGui_Show(InventoryGui __instance, Container? container) { Beehive beehive = default(Beehive); if (!((Object)(object)container == (Object)null) && ((Component)container).TryGetComponent<Beehive>(ref beehive)) { _beehive = beehive; InventoryGuiExt.ShowStackAllButton(InventoryGui.instance, false); } } [HarmonyPostfix] [HarmonyPatch(typeof(Humanoid), "UseItem")] private static void Humanoid_UseItem() { if (IsHoneyOpen(out Beehive beehive)) { beehive.UpdateHoneyFromContainer(); } } [HarmonyReversePatch(/*Could not decode attribute arguments.*/)] [HarmonyPatch(typeof(InventoryGui), "OnTakeAll")] private static void TakeAll(this InventoryGui __instance) { throw new NotImplementedException("Placeholder for original method"); } [HarmonyPostfix] [HarmonyPatch(typeof(InventoryGui), "OnTakeAll")] private static void InventoryGui_OnTakeAll_Postfix(InventoryGui __instance) { if (IsHoneyOpen(out Beehive beehive)) { beehive.UpdateHoneyFromContainer(); } } [HarmonyPrefix] [HarmonyPatch(typeof(Inventory), "StackAll")] private static void Inventory_StackAll(ref bool __runOriginal) { if (IsHoneyOpen(out Beehive beehive)) { __runOriginal = false; if (Configs.HoldToTakeAll.Value) { InventoryGui.instance.TakeAll(); beehive.UpdateHoneyFromContainer(); } } } [HarmonyPostfix] [HarmonyPatch(typeof(InventoryGui), "OnDropOutside")] private static void InventoryGui_OnDropOutside() { if (IsHoneyOpen(out Beehive beehive)) { beehive.UpdateHoneyFromContainer(); } } [HarmonyPrefix] [HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")] private static void InventoryGui_OnSelectedItem_Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item, Vector2i pos, Modifier mod, ref bool __runOriginal) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_0045: 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_0072: Unknown result type (might be due to invalid IL or missing references) if (!IsHoneyOpen(out Beehive beehive)) { return; } if ((Object)(object)grid == (Object)(object)__instance.ContainerGrid) { if (__instance.m_dragItem != null) { __instance.SetupDragItem((ItemData)null, (Inventory)null, 0); __runOriginal = false; } } else { if (!((Object)(object)grid == (Object)(object)__instance.m_playerGrid)) { return; } if ((int)mod == 2) { __runOriginal = false; } if ((int)mod == 0 && __instance.m_dragItem != null && __instance.m_dragInventory != __instance.m_playerGrid.GetInventory()) { ItemData itemAt = grid.GetInventory().GetItemAt(pos.x, pos.y); if (itemAt != null && !((Object)(object)itemAt.m_dropPrefab == (Object)(object)beehive.GetHoneyItemPrefab())) { __runOriginal = false; } } } } [HarmonyPostfix] [HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")] private static void InventoryGui_OnSelectedItem_Postfix() { if (IsHoneyOpen(out Beehive beehive)) { beehive.UpdateHoneyFromContainer(); } } [HarmonyPostfix] [HarmonyPatch(typeof(InventoryGrid), "UpdateGui")] private static void InventoryGrid_UpdateGui(InventoryGrid __instance) { if (IsHoneyOpen(out Beehive beehive) && __instance.GetInventory().NrOfItems() != 0) { ItemData item = __instance.GetInventory().GetItem(0); __instance.m_elements[0].m_amount.text = $"{item.m_stack}/{beehive.m_maxHoney}"; } } [HarmonyTranspiler] [HarmonyPatch(typeof(Beehive), "Interact")] private static IEnumerable<CodeInstruction> Beehive_Interact(IEnumerable<CodeInstruction> codes) { MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(PrivateArea), "CheckAccess", (Type[])null, (Type[])null); Func<Vector3, float, bool, bool, bool> func = InterceptCheckAccess; return Transpilers.MethodReplacer(codes, (MethodBase)methodInfo, (MethodBase)func.Method); static bool InterceptCheckAccess(Vector3 point, float radius, bool flash, bool wardCheck) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) if (!Configs.IgnoreWards.Value) { return PrivateArea.CheckAccess(point, radius, flash, wardCheck); } return true; } } } public static class Configs { private const string SECTION_BEEHIVE = "Beehive"; public static readonly ConfigEntry<bool> HoldToTakeAll = Config.Define<bool>(true, "Beehive", "Hold To Take All", true, "Hold down the interact key when opening a beehive to automatically take all the honey."); public static readonly ConfigEntry<int> MaxHoney = Config.Define<int>(true, "Beehive", "Max Capacity", 0, Config.AcceptRange<int>(0, 999), "Max honey that a beehive can hold. Logout for changes to take effect. (Vanilla: 4)\r\nSet to 0 to disable this config.\r\nNote: Max capacity can not exceed the stack size for the Item Prefab.\r\nExample: If the Item Prefab's max stack size is 50 then it won't matter if you put 999 here.\r\nIt will never go above the item's max stack size limit.\r\n[restart game for changes to take effect]"); public static readonly ConfigEntry<string> HoneyItem = Config.Define<string>(true, "Beehive", "Item Prefab", "Honey", "The prefab name of the item that grows inside a beehive. The Honey Item. \r\n[logout for changes to take effect]"); public static readonly ConfigEntry<int> SecPerUnit = Config.Define<int>(true, "Beehive", "Seconds Per Unit", 0, Config.AcceptRange<int>(0, 10000), "The number of seconds it takes to grow one unit of honey. (Vanilla: 1200)\r\nSet to 0 to disable this config.\r\n[restart game for changes to take effect]"); public static readonly ConfigEntry<bool> IgnoreWards = Config.Define<bool>(true, "Beehive", "Ignore Wards", true, "Ignore warded areas (vanilla: false)\r\nIt's just a honey box that generates new honey over time, not a pot of gold.\r\nMost of the time it just goes unharvested since people are busy doing other things.\r\nTrust your neighbors, or share extra, or build a wall and gate to guard your honey."); } [Disable(new Type[] { typeof(Beehive) })] [BepInPlugin("ZenDragon.ZenBeehive", "ZenBeehive", "0.4.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class Plugin : ZenMod<Plugin> { public const string PluginName = "ZenBeehive"; public const string PluginVersion = "0.4.0"; public const string PluginGUID = "ZenDragon.ZenBeehive"; protected override void Setup() { base.ConfigSync += BeehiveUI.SetupPrefab; } protected override void TitleScene(bool isFirstBoot) { } protected override void WorldStart() { } protected override void Shutdown() { } } }