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 WorkbenchPack ExtraSlots Bridge v1.0.0
WorkbenchPack_ExtraSlots_Bridge.dll
Decompiled 11 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ExtraSlots; using HarmonyLib; using Jotunn.Managers; using Microsoft.CodeAnalysis; using UnityEngine; [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("WorkbenchPack_ExtraSlots_Bridge")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("WorkbenchPack_ExtraSlots_Bridge")] [assembly: AssemblyTitle("WorkbenchPack_ExtraSlots_Bridge")] [assembly: AssemblyVersion("1.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 TheShack.WorkbenchPackExtraSlotsBridge { [BepInPlugin("theshack.workbenchpack_extraslots_bridge", "Workbench Pack Extra Slots Bridge", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private class Worn { public ItemData Item; } [HarmonyPatch(typeof(ItemData), "IsEquipable")] private static class ItemData_IsEquipable { private static void Postfix(ItemData __instance, ref bool __result) { __result = __result || IsSlotItem(__instance); } } [HarmonyPatch(typeof(Humanoid), "EquipItem")] private static class Humanoid_EquipItem { private static void Postfix(Humanoid __instance, ItemData item, bool triggerEquipEffects, bool __result) { if (__result && IsSlotItem(item)) { ItemData worn = GetWorn(__instance); if (worn != null && worn != item) { __instance.UnequipItem(worn, triggerEquipEffects); } SetWorn(__instance, item); item.m_equipped = true; SetupEquipment(__instance); } } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] private static class Humanoid_UnequipItem { private static void Postfix(Humanoid __instance, ItemData item) { if (item != null && GetWorn(__instance) == item) { SetWorn(__instance, null); SetupEquipment(__instance); } } } [HarmonyPatch(typeof(Humanoid), "UnequipAllItems")] private static class Humanoid_UnequipAllItems { private static void Postfix(Humanoid __instance) { __instance.UnequipItem(GetWorn(__instance), false); } } [HarmonyPatch(typeof(Humanoid), "IsItemEquiped")] private static class Humanoid_IsItemEquiped { private static void Postfix(Humanoid __instance, ItemData item, ref bool __result) { __result = __result || (item != null && GetWorn(__instance) == item); } } [HarmonyPatch(typeof(Humanoid), "GetEquipmentWeight")] private static class Humanoid_GetEquipmentWeight { private static void Postfix(Humanoid __instance, ref float __result) { ItemData worn = GetWorn(__instance); if (worn != null) { __result += worn.m_shared.m_weight; } } } [HarmonyPatch(typeof(Humanoid), "UpdateEquipment")] private static class Humanoid_UpdateEquipment { private static void Postfix(Humanoid __instance, float dt) { ItemData val = (((Character)__instance).IsPlayer() ? GetWorn(__instance) : null); if (val != null && val.m_shared.m_useDurability) { DrainDurability(__instance, val, dt); } } } [HarmonyPatch(typeof(Inventory), "Changed")] private static class Inventory_Changed { private static void Prefix(Inventory __instance) { Player localPlayer = Player.m_localPlayer; ItemData val = (Object.op_Implicit((Object)(object)localPlayer) ? GetWorn((Humanoid)(object)localPlayer) : null); if (val != null && __instance == ((Humanoid)localPlayer).GetInventory() && !__instance.ContainsItem(val)) { SetWorn((Humanoid)(object)localPlayer, null); SetupEquipment((Humanoid)(object)localPlayer); } } } private class Back { public int Local; public int Shown; public List<GameObject> Instances; } [HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")] private static class Humanoid_SetupVisEquipment { private static void Postfix(Humanoid __instance, VisEquipment visEq) { if (!Object.op_Implicit((Object)(object)visEq)) { return; } ItemData worn = GetWorn(__instance); int num = (Object.op_Implicit((Object)(object)worn?.m_dropPrefab) ? StringExtensionMethods.GetStableHashCode(((Object)worn.m_dropPrefab).name) : 0); Back orCreateValue = backs.GetOrCreateValue(visEq); if (orCreateValue.Local != num) { orCreateValue.Local = num; ZNetView val = VisNview.Invoke(visEq); if (Object.op_Implicit((Object)(object)val) && val.IsValid() && val.IsOwner()) { val.GetZDO().Set(BackKey, num, false); } } } } [HarmonyPatch(typeof(VisEquipment), "UpdateEquipmentVisuals")] private static class VisEquipment_UpdateEquipmentVisuals { private static void Postfix(VisEquipment __instance) { ZNetView val = VisNview.Invoke(__instance); ZDO val2 = ((Object.op_Implicit((Object)(object)val) && val.IsValid()) ? val.GetZDO() : null); backs.TryGetValue(__instance, out var value); int num = ((val2 != null) ? val2.GetInt(BackKey, 0) : (value?.Local ?? 0)); if ((value?.Shown ?? 0) == num) { return; } value = value ?? backs.GetOrCreateValue(__instance); if (value.Instances != null) { LODGroup val3 = VisLod.Invoke(__instance); foreach (GameObject instance in value.Instances) { if (Object.op_Implicit((Object)(object)val3)) { Utils.RemoveFromLodgroup(val3, instance); } Object.Destroy((Object)(object)instance); } value.Instances = null; } value.Shown = num; if (num != 0) { value.Instances = AttachArmor(__instance, num, -1, 0); } UpdateLodgroup(__instance); } } public const string PluginGuid = "theshack.workbenchpack_extraslots_bridge"; public const string PluginName = "Workbench Pack Extra Slots Bridge"; public const string PluginVersion = "1.0.0"; private const string WorkbenchPackGuid = "theshack.workbenchpack"; private const string ExtraSlotsGuid = "shudnal.ExtraSlots"; private const string ItemName = "ShackWorkbenchBackpack"; private const string Token = "$shack_benchpack"; private const string SlotId = "ShackWorkbenchBackpack"; private static readonly int BackKey = StringExtensionMethods.GetStableHashCode("theshack.workbenchpack_extraslots_bridge.back"); internal static ManualLogSource Log; private static ConfigEntry<bool> slotOn; private static ConfigEntry<string> slotName; private static ConfigEntry<int> typeNumber; private static ConfigEntry<bool> wearAfterPackUp; private static ItemType slotType; private static bool typeSet; private static readonly Action<Humanoid> SetupEquipment = AccessTools.MethodDelegate<Action<Humanoid>>(AccessTools.Method(typeof(Humanoid), "SetupEquipment", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Humanoid, ItemData, float> DrainDurability = AccessTools.MethodDelegate<Action<Humanoid, ItemData, float>>(AccessTools.Method(typeof(Humanoid), "DrainEquipedItemDurability", (Type[])null, (Type[])null), (object)null, true); private static readonly Func<VisEquipment, int, int, int, List<GameObject>> AttachArmor = AccessTools.MethodDelegate<Func<VisEquipment, int, int, int, List<GameObject>>>(AccessTools.Method(typeof(VisEquipment), "AttachArmor", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<VisEquipment> UpdateLodgroup = AccessTools.MethodDelegate<Action<VisEquipment>>(AccessTools.Method(typeof(VisEquipment), "UpdateLodgroup", (Type[])null, (Type[])null), (object)null, true); private static readonly FieldRef<VisEquipment, ZNetView> VisNview = AccessTools.FieldRefAccess<VisEquipment, ZNetView>("m_nview"); private static readonly FieldRef<VisEquipment, LODGroup> VisLod = AccessTools.FieldRefAccess<VisEquipment, LODGroup>("m_lodGroup"); private static readonly ConditionalWeakTable<Humanoid, Worn> worn = new ConditionalWeakTable<Humanoid, Worn>(); private static readonly ConditionalWeakTable<VisEquipment, Back> backs = new ConditionalWeakTable<VisEquipment, Back>(); private void Awake() { //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown //IL_0163: 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_0185: Expected O, but got Unknown //IL_0185: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; slotOn = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Backpack slot", true, "Give the workbench backpack its own Extra Slots equipment slot, so wearing it leaves the belt on. Off: it's a utility item again, as without this bridge. Restart the game after changing it."); slotName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Slot name", "Backpack", "The slot's name in the equipment panel."); typeNumber = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Item type number", 57, "The backpack's own item type, which no vanilla slot takes. Change it only if another mod uses the same number (HipLantern uses 56). Restart the game after changing it."); if (!slotOn.Value) { Log.LogInfo((object)"Backpack slot is off; the workbench backpack stays a utility item."); } else if (AddSlot()) { slotType = (ItemType)typeNumber.Value; ItemManager.OnItemsRegistered += SetType; Harmony val = new Harmony("theshack.workbenchpack_extraslots_bridge"); val.PatchAll(typeof(Plugin).Assembly); Type type = AccessTools.TypeByName("TheShack.WorkbenchPack.PlacedBench"); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "Give", (Type[])null, (Type[])null)); Type type2 = AccessTools.TypeByName("TheShack.WorkbenchPack.Settings"); wearAfterPackUp = ((type2 == null) ? null : (AccessTools.Field(type2, "WearAfterPackUp")?.GetValue(null) as ConfigEntry<bool>)); if (methodInfo != null && wearAfterPackUp != null) { val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "GivePrefix", (Type[])null), new HarmonyMethod(typeof(Plugin), "GivePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { Log.LogWarning((object)"This Workbench Pack version is laid out differently; after packing up, put the backpack in the Backpack slot yourself (right-click it)."); } Log.LogInfo((object)string.Format("{0} {1} ready (slot \"{2}\", item type {3}).", "Workbench Pack Extra Slots Bridge", "1.0.0", slotName.Value, typeNumber.Value)); } } [MethodImpl(MethodImplOptions.NoInlining)] private static bool AddSlot() { try { if (API.AddSlot("ShackWorkbenchBackpack", (Func<string>)(() => slotName.Value), (Func<ItemData, bool>)IsOurs, (Func<bool>)(() => slotOn.Value))) { return true; } Log.LogWarning((object)"Extra Slots has no room for another custom slot; the bridge does nothing."); } catch (Exception ex) { Log.LogWarning((object)("This Extra Slots version has no custom slot API the bridge knows; it does nothing. " + ex.Message)); } return false; } private static void SetType() { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab("ShackWorkbenchBackpack") : null); ItemDrop val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<ItemDrop>() : null); if (!Object.op_Implicit((Object)(object)val2)) { Log.LogWarning((object)"No workbench backpack in the game; the Backpack slot stays empty."); return; } val2.m_itemData.m_shared.m_itemType = slotType; typeSet = true; } private static bool IsOurs(ItemData item) { if (item?.m_shared != null) { return item.m_shared.m_name == "$shack_benchpack"; } return false; } private static bool IsSlotItem(ItemData item) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (typeSet && IsOurs(item)) { return item.m_shared.m_itemType == slotType; } return false; } private static ItemData GetWorn(Humanoid humanoid) { if (!Object.op_Implicit((Object)(object)humanoid) || !worn.TryGetValue(humanoid, out var value)) { return null; } return value.Item; } private static void SetWorn(Humanoid humanoid, ItemData item) { worn.GetOrCreateValue(humanoid).Item = item; } private static void GivePrefix(Player player, out List<ItemData> __state) { __state = (Object.op_Implicit((Object)(object)player) ? ((Humanoid)player).GetInventory().GetAllItems().Where(IsOurs) .ToList() : null); } private static void GivePostfix(Player player, bool forge, List<ItemData> __state) { if (!forge && __state != null && Object.op_Implicit((Object)(object)player) && wearAfterPackUp.Value && GetWorn((Humanoid)(object)player) == null) { ItemData val = ((IEnumerable<ItemData>)((Humanoid)player).GetInventory().GetAllItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => IsSlotItem(i) && !i.m_equipped && !__state.Contains(i))); if (val != null) { ((Humanoid)player).EquipItem(val, true); } } } } }