Decompiled source of RavenwoodContainers v1.0.3

plugins/RavenwoodContainers/RavenwoodContainers.dll

Decompiled 4 months ago
using 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.Bootstrap;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using RavenwoodContainers.Containers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("RavenwoodContainers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MagicMike")]
[assembly: AssemblyProduct("RavenwoodContainers")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RavenwoodContainers
{
	public class ContainerPatches
	{
		[HarmonyPatch]
		public class PlacementPatch
		{
			[HarmonyPatch(typeof(Player), "SetupPlacementGhost")]
			[HarmonyPostfix]
			public static void SetupPlacementGhostPatch(Player __instance)
			{
				if (Object.op_Implicit((Object)(object)__instance.m_placementGhost))
				{
					VisualStack[] componentsInChildren = __instance.m_placementGhost.GetComponentsInChildren<VisualStack>();
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						Object.Destroy((Object)(object)componentsInChildren[i]);
					}
				}
			}
		}

		public static ZNetScene zNetScene;
	}
	public class AddContainers
	{
		public static EffectList buildWood;

		public static EffectList breakWood;

		public static EffectList hitWood;

		public static EffectList buildStone;

		public static EffectList breakStone;

		public static EffectList hitStone;

		public static void LoadPieces()
		{
			SetupGamePrefabs();
			if (RavenwoodContainersPlugin.bamboozledLoaded)
			{
				AddBambooContainer();
			}
			AddAncientBarkContainer();
			AddFlintContainer();
			AddSurtlingContainer();
			if (RavenwoodContainersPlugin.halloweenPiecesLoaded)
			{
				AddPumpkinsContainer();
			}
			AddResinContainer();
			AddEyeContainer();
			AddFeathersContainer();
			AddPukeberriesContainer();
			AddTarContainer();
		}

		public static void SetupGamePrefabs()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			GameObject prefab = Cache.GetPrefab<GameObject>("sfx_build_hammer_wood");
			GameObject prefab2 = Cache.GetPrefab<GameObject>("sfx_wood_break");
			GameObject prefab3 = Cache.GetPrefab<GameObject>("sfx_wood_hit");
			GameObject prefab4 = Cache.GetPrefab<GameObject>("sfx_build_hammer_stone");
			GameObject prefab5 = Cache.GetPrefab<GameObject>("sfx_rock_hit");
			EffectList val = new EffectList();
			val.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
			{
				new EffectData
				{
					m_prefab = prefab
				}
			};
			buildWood = val;
			val = new EffectList();
			val.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
			{
				new EffectData
				{
					m_prefab = prefab2
				}
			};
			breakWood = val;
			val = new EffectList();
			val.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
			{
				new EffectData
				{
					m_prefab = prefab3
				}
			};
			hitWood = val;
			val = new EffectList();
			val.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
			{
				new EffectData
				{
					m_prefab = prefab4
				}
			};
			buildStone = val;
			val = new EffectList();
			val.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
			{
				new EffectData
				{
					m_prefab = prefab5
				}
			};
			breakStone = val;
			val = new EffectList();
			val.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
			{
				new EffectData
				{
					m_prefab = prefab5
				}
			};
			hitStone = val;
		}

		public static void AddBambooContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_bamboo_dynamic_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "OP_Bamboo_Wood",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildWood;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakWood;
			component.m_hitEffect = hitWood;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.PrepareContainer(val);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "OP_Bamboo_Wood" });
		}

		public static void AddAncientBarkContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_ancient_bark_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "ElderBark",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildWood;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakWood;
			component.m_hitEffect = hitWood;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.PrepareContainer(val);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "ElderBark" });
		}

		public static void AddFlintContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_flint_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "Flint",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildStone;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakStone;
			component.m_hitEffect = hitStone;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.PrepareContainer(val);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "Flint" });
		}

		public static void AddSurtlingContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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)
			//IL_0061: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_surtling_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "SurtlingCore",
					Amount = 5,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildStone;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakStone;
			component.m_hitEffect = hitStone;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.PrepareContainer(val);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "SurtlingCore" });
		}

		public static void AddPumpkinsContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_pumpkins_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "BHP_PumpkinDrop",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildWood;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakWood;
			component.m_hitEffect = hitWood;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "BHP_PumpkinDrop" });
		}

		public static void AddResinContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_resin_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "Resin",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildWood;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakWood;
			component.m_hitEffect = hitWood;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "Resin" });
		}

		public static void AddEyeContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_eye_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "GreydwarfEye",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildWood;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakWood;
			component.m_hitEffect = hitWood;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "GreydwarfEye" });
		}

		public static void AddFeathersContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_feathers_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "Feathers",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildWood;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakWood;
			component.m_hitEffect = hitWood;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "Feathers" });
		}

		public static void AddPukeberriesContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_pukeberry_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "Pukeberries",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildWood;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakWood;
			component.m_hitEffect = hitWood;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "Pukeberries" });
		}

		public static void AddTarContainer()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			GameObject val = RavenwoodContainersPlugin.magicBundle.LoadAsset<GameObject>("mm_tar_stack");
			PieceConfig val2 = new PieceConfig();
			val2.CraftingStation = "piece_workbench";
			val2.PieceTable = "_HammerPieceTable";
			val2.Category = "Ravenwood-Containers";
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "Tar",
					Amount = 10,
					Recover = true
				}
			};
			CustomPiece val3 = new CustomPiece(val, true, val2);
			val.GetComponent<Piece>().m_placeEffect = buildWood;
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_destroyedEffect = breakWood;
			component.m_hitEffect = hitWood;
			PieceManager.Instance.AddPiece(val3);
			RavenwoodContainersPlugin.PrepareContainer(val);
			RavenwoodContainersPlugin.allowedItemsByContainer.Add(val.GetComponent<Container>().m_name, new HashSet<string> { "Tar" });
		}
	}
	[BepInPlugin("MagicMike.RavenwoodContainers", "RavenwoodContainers", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class RavenwoodContainersPlugin : BaseUnityPlugin
	{
		public const string PluginName = "RavenwoodContainers";

		public const string PluginVersion = "1.0.3";

		public const string PluginAuthor = "MagicMike";

		public const string PluginGUID = "MagicMike.RavenwoodContainers";

		public static Dictionary<string, HashSet<string>> allowedItemsByContainer = new Dictionary<string, HashSet<string>>();

		private Harmony harmony = new Harmony("MagicMike.RavenwoodContainers");

		public static AssetBundle magicBundle;

		public static bool bamboozledLoaded = false;

		public static bool halloweenPiecesLoaded = false;

		private void Start()
		{
			if (Chainloader.PluginInfos.ContainsKey("org.bepinex.plugins.bamboozled"))
			{
				bamboozledLoaded = true;
			}
			if (Chainloader.PluginInfos.ContainsKey("blacks7ar.HalloweenPieces"))
			{
				halloweenPiecesLoaded = true;
			}
		}

		private void Awake()
		{
			Game.isModded = true;
			LoadBundle();
			PrefabManager.OnVanillaPrefabsAvailable += LoadContainers;
			harmony = Harmony.CreateAndPatchAll(typeof(ContainerPatches).Assembly, "MagicMike.RavenwoodContainers");
		}

		private void LoadBundle()
		{
			try
			{
				magicBundle = AssetUtils.LoadAssetBundleFromResources("stacks", Assembly.GetExecutingAssembly());
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Exception caught while loading bundle: " + ex.Message));
			}
		}

		private void LoadContainers()
		{
			try
			{
				AddContainers.LoadPieces();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Exception caught while loading Containers: " + ex.Message));
			}
			finally
			{
				PrefabManager.OnVanillaPrefabsAvailable -= LoadContainers;
			}
		}

		public static GameObject PrepareContainer(GameObject prefab)
		{
			VisualStack visualStack = prefab.AddComponent<VisualStack>();
			MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>();
			foreach (MeshRenderer val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)((Component)val).gameObject.GetComponent<MeshCollider>()))
				{
					visualStack.stackMeshes.Add(((Component)val).transform);
				}
			}
			return prefab;
		}
	}
}
namespace RavenwoodContainers.Containers
{
	public static class InventoryHelper
	{
		public static string PrefabName(this ItemData item)
		{
			if (Object.op_Implicit((Object)(object)item.m_dropPrefab))
			{
				return ((Object)item.m_dropPrefab).name;
			}
			Logger.LogWarning((object)("Item has missing prefab " + item.m_shared.m_name));
			return item.m_shared.m_name;
		}
	}
	[HarmonyPatch]
	internal static class RestrictContainers
	{
		private static string _loadingContainer;

		private static string _targetContainer;

		private static HashSet<string> _allowedItems;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(InventoryGrid), "DropItem")]
		private static bool DropItemPrefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!CanAddItem(__instance.m_inventory, item))
			{
				return false;
			}
			ItemData itemAt = __instance.m_inventory.GetItemAt(pos.x, pos.y);
			if (itemAt != null)
			{
				return CanAddItem(fromInventory, itemAt);
			}
			return true;
		}

		private static bool CanAddItem(Inventory inventory, ItemData item)
		{
			if (inventory == null || item == null)
			{
				return false;
			}
			if (inventory.m_name == _loadingContainer)
			{
				return true;
			}
			if (IsRestrictedContainer(inventory.m_name, out var allowedItems))
			{
				bool num = allowedItems.Contains(item.PrefabName());
				if (!num)
				{
					Player localPlayer = Player.m_localPlayer;
					if (localPlayer == null)
					{
						return num;
					}
					((Character)localPlayer).Message((MessageType)2, "Restricted Item!", 0, (Sprite)null);
				}
				return num;
			}
			return true;
		}

		public static bool IsRestrictedContainer(string containerName, out HashSet<string> allowedItems)
		{
			return RavenwoodContainersPlugin.allowedItemsByContainer.TryGetValue(containerName, out allowedItems);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		[HarmonyPriority(800)]
		private static bool AddItemPrefix(Inventory __instance, ItemData item, ref bool __result)
		{
			if (!CanAddItem(__instance, item))
			{
				__result = false;
				return __result;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
		{
			typeof(Inventory),
			typeof(ItemData)
		})]
		[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
		{
			typeof(Inventory),
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		[HarmonyPriority(800)]
		private static bool MoveItemToThisPrefix(Inventory __instance, Inventory fromInventory, ItemData item)
		{
			if (__instance == null || fromInventory == null || item == null)
			{
				return false;
			}
			return CanAddItem(__instance, item);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Inventory), "MoveAll", new Type[] { typeof(Inventory) })]
		[HarmonyPriority(800)]
		private static void MoveAllPrefix(Inventory __instance, Inventory fromInventory)
		{
			if (__instance != null && fromInventory != null && IsRestrictedContainer(__instance.m_name, out var allowedItems))
			{
				_targetContainer = __instance.m_name;
				_allowedItems = allowedItems;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Inventory), "MoveAll", new Type[] { typeof(Inventory) })]
		[HarmonyPriority(800)]
		private static void MoveAllPostfix()
		{
			_targetContainer = null;
			_allowedItems = null;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[] { typeof(ItemData) })]
		[HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[]
		{
			typeof(ItemData),
			typeof(int)
		})]
		[HarmonyPriority(800)]
		private static bool RemoveItemPrefix(Inventory __instance, ItemData item)
		{
			return ShouldRemoveItem(__instance, item);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Inventory), "RemoveOneItem", new Type[] { typeof(ItemData) })]
		[HarmonyPriority(800)]
		private static bool RemoveOneItemPrefix(Inventory __instance, ItemData item)
		{
			return ShouldRemoveItem(__instance, item);
		}

		private static bool ShouldRemoveItem(Inventory __instance, ItemData item)
		{
			if (__instance == null || item == null)
			{
				return false;
			}
			if (!string.IsNullOrEmpty(_targetContainer) && _allowedItems != null)
			{
				return _allowedItems.Contains(item.PrefabName());
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Inventory), "Load")]
		private static void LoadPrefix(Inventory __instance)
		{
			if (__instance != null)
			{
				_loadingContainer = __instance.m_name;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Inventory), "Load")]
		private static void LoadPostfix()
		{
			_loadingContainer = null;
		}
	}
	public class VisualStack : MonoBehaviour
	{
		public List<Transform> stackMeshes = new List<Transform>();

		private Container container;

		private Inventory inventory;

		public void Start()
		{
			container = ((Component)this).GetComponentInParent<Container>();
			if (Object.op_Implicit((Object)(object)container))
			{
				inventory = container.GetInventory();
			}
			if (inventory != null)
			{
				Inventory obj = inventory;
				obj.m_onChanged = (Action)Delegate.Combine(obj.m_onChanged, new Action(UpdateVisuals));
				UpdateVisuals();
			}
		}

		public void UpdateVisuals()
		{
			SetVisualsActive(inventory.SlotsUsedPercentage());
		}

		public void SetVisualsActive(float fillPercentage)
		{
			float num = Mathf.Ceil(fillPercentage / 100f * (float)stackMeshes.Count);
			for (int i = 0; i < stackMeshes.Count; i++)
			{
				bool active = i == 0 || (float)i < num;
				((Component)stackMeshes[i]).gameObject.SetActive(active);
			}
		}
	}
}