Decompiled source of TobaccoPotAndCigar v1.2.3

BepInEx/plugins/TobaccoPotAndCigar/TobaccoPotAndCigar.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TobaccoPotAndCigar.Compatibility;
using TobaccoPotAndCigar.Prefabs;
using TobaccoPotAndCigar.Runtime;
using TobaccoPotAndCigar.Shops;
using TobaccoPotAndCigar.Smoking;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("TobaccoPotAndCigar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.3.0")]
[assembly: AssemblyInformationalVersion("1.2.3")]
[assembly: AssemblyProduct("TobaccoPotAndCigar")]
[assembly: AssemblyTitle("TobaccoPotAndCigar")]
[assembly: AssemblyVersion("1.2.3.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 TobaccoPotAndCigar
{
	[BepInPlugin("DogEggz.Cigar", "Tobacco pot and cigar", "1.2.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "DogEggz.Cigar";

		public const string PluginName = "Tobacco pot and cigar";

		public const string PluginVersion = "1.2.3";

		private Harmony harmony;

		internal static ManualLogSource LogSource { get; private set; }

		internal static string PluginDirectory { get; private set; }

		private void Awake()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			LogSource = ((BaseUnityPlugin)this).Logger;
			PluginDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? string.Empty;
			RuntimeDiagnostics.InfoSink = delegate(string message)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)message);
			};
			RuntimeDiagnostics.WarningSink = delegate(string message)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)message);
			};
			RuntimeDiagnostics.ErrorSink = delegate(string message)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)message);
			};
			try
			{
				CigarAssetBundle.Load(PluginDirectory);
				harmony = new Harmony("DogEggz.Cigar");
				harmony.PatchAll(typeof(Plugin).Assembly);
				ShopPlacement.ResetDiagnostics();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Tobacco pot and cigar 1.2.3 loaded.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Cigar initialization failed: " + ex));
				throw;
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			CigarEffectService.Reset();
			RadRefinementsCompatibility.Reset();
			CigarPrefabRegistrar.Reset();
			CigarAssetBundle.Unload();
			ShopPlacement.ResetDiagnostics();
			RuntimeDiagnostics.Reset();
			PluginDirectory = null;
			LogSource = null;
		}
	}
}
namespace TobaccoPotAndCigar.Shops
{
	internal static class ShopPlacement
	{
		private const string GoldRockScene = "island 1 A Gold Rock";

		private const string DragonCliffsScene = "island 9 E Dragon Cliffs";

		private const string SageHillsScene = "island 13 E (Sage Hills)";

		private const string FortAestrinScene = "island 15 M (Fort)";

		private const string NeverdinScene = "island 3 A Neverdin";

		private const string SirenSongScene = "island 21 M (siren song)";

		private const string CrabBeachScene = "island 11 E (Crab Beach)";

		private const string OasisScene = "island 20 A (Oasis)";

		private const string EastwindScene = "island 19 M (Eastwind)";

		private const string PonderingPeakScene = "island 39 (onsen)";

		private const string ChronosScene = "island 25 (chronos)";

		private static readonly HashSet<string> LoggedIdentityFailures = new HashSet<string>();

		private static readonly FieldInfo StockItem = typeof(ShopItemSpawner).GetField("item", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo ItemShopArea = typeof(ShipItem).GetField("shopArea", BindingFlags.Instance | BindingFlags.NonPublic);

		internal static void ResetDiagnostics()
		{
			LoggedIdentityFailures.Clear();
		}

		internal static void ConfigureSpawnerBeforeStart(ShopItemSpawner spawner)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			StorageShopPlacement.Configure(spawner);
			if (!CigarPrefabRegistrar.IsReady || (Object)(object)spawner == (Object)null)
			{
				return;
			}
			Scene scene = ((Component)spawner).gameObject.scene;
			if (!((Scene)(ref scene)).IsValid())
			{
				return;
			}
			scene = ((Component)spawner).gameObject.scene;
			string name = ((Scene)(ref scene)).name;
			string name2 = ((Object)((Component)spawner).gameObject).name;
			if ((name == "island 1 A Gold Rock" && (name2 == "shop item (171)" || name2 == "shop item (173)")) || (name == "island 9 E Dragon Cliffs" && name2 == "shop item spawner (184)"))
			{
				if (!IsUniqueSpawner(spawner))
				{
					LogIdentityFailure(name + "/" + name2);
				}
				else
				{
					spawner.itemPrefab = CigarAssetBundle.GetPrefab(614);
				}
			}
		}

		internal static void AddRelativeDisplaysAfterStart(ShopItemSpawner anchor)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			if (!CigarPrefabRegistrar.IsReady || (Object)(object)anchor == (Object)null)
			{
				return;
			}
			Scene scene = ((Component)anchor).gameObject.scene;
			if (!((Scene)(ref scene)).IsValid())
			{
				return;
			}
			scene = ((Component)anchor).gameObject.scene;
			string name = ((Scene)(ref scene)).name;
			string name2 = ((Object)((Component)anchor).gameObject).name;
			if ((IsWrapperDisplay(anchor) || (name == "island 15 M (Fort)" && name2 == "shop item (24)") || (name == "island 3 A Neverdin" && name2 == "shop item (32)") || (name == "island 21 M (siren song)" && name2 == "shop item (77)") || (name == "island 11 E (Crab Beach)" && name2 == "shop spawner crab cakes (50)") || (name == "island 20 A (Oasis)" && name2 == "shop item (65)") || (name == "island 19 M (Eastwind)" && name2 == "shop item (42)") || (name == "island 39 (onsen)" && name2 == "shop item (80)") || (name == "island 25 (chronos)" && name2 == "shop item (136)")) && IsUniqueSpawner(anchor))
			{
				if (name == "island 9 E Dragon Cliffs" && name2 == "shop item spawner (184)")
				{
					AlignWrapper(anchor);
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.DriedLeaf.DragonCliffs.2", new Vector3(0f, 0f, -0.29f), Vector3.zero, 614);
				}
				else if (name == "island 15 M (Fort)" && name2 == "shop item (24)")
				{
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.DriedLeaf.Fort.1", new Vector3(-0.734f, 0f, 0f), new Vector3(90f, 0f, 0f), 614);
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.DriedLeaf.Fort.2", new Vector3(-0.734f, 0f, -0.367f), new Vector3(90f, 0f, 0f), 614);
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.DriedLeaf.Fort.3", new Vector3(-0.734f, 0f, -0.734f), new Vector3(90f, 0f, 0f), 614);
				}
				if (IsWrapperDisplay(anchor))
				{
					AlignWrapper(anchor);
					ReconcileWrapperStock(anchor);
				}
				if (name == "island 1 A Gold Rock" && name2 == "shop item (171)")
				{
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.Ashtray.AlAnkh", new Vector3(0.024026f, -0.062822f, -2.044131f), new Vector3(0.159581f, 0.015844f, 11.33965f), 618);
				}
				if (name == "island 9 E Dragon Cliffs" && name2 == "shop item spawner (184)")
				{
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.Ashtray.Emerald", new Vector3(-0.03281f, -0.082593f, 0.246239f), new Vector3(359.5197f, 0.031987f, 352.3793f), 620);
				}
				if (name == "island 15 M (Fort)" && name2 == "shop item (24)")
				{
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.Ashtray.Aestrin", new Vector3(-0.749037f, -0.127f, -0.995985f), Vector3.zero, 619);
				}
				if (name == "island 3 A Neverdin" && name2 == "shop item (32)")
				{
					CreateTavernAshtray(anchor, "Neverdin", new Vector3(0.749442f, -0.032372f, -0.702033f), 615);
				}
				if (name == "island 21 M (siren song)" && name2 == "shop item (77)")
				{
					CreateTavernAshtray(anchor, "SirenSong", new Vector3(0.089528f, -0.031021f, -0.304271f), 616);
				}
				if (name == "island 11 E (Crab Beach)" && name2 == "shop spawner crab cakes (50)")
				{
					CreateTavernAshtray(anchor, "CrabBeach", new Vector3(-0.226775f, -0.114298f, 0.099208f), 617);
				}
				if (name == "island 20 A (Oasis)" && name2 == "shop item (65)")
				{
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.Ashtray.Oasis", new Vector3(-0.2249f, -0.223426f, -4.4E-05f), new Vector3(359.7922f, 358.0053f, 0.11785f), 623);
				}
				if (name == "island 19 M (Eastwind)" && name2 == "shop item (42)")
				{
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.Ashtray.Eastwind", new Vector3(0.069258f, -0.080073f, 0.195737f), new Vector3(0.171237f, 291.8018f, 359.9076f), 621);
				}
				if (name == "island 39 (onsen)" && name2 == "shop item (80)")
				{
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.Ashtray.PonderingPeak", new Vector3(-0.154666f, -0.120439f, -0.173347f), new Vector3(359.2273f, 311.1519f, 359.3744f), 622);
				}
				if (name == "island 25 (chronos)" && name2 == "shop item (136)")
				{
					CreateRelativeSpawner(anchor, "DogEggz.Cigar.Ashtray.Chronos", new Vector3(-0.095731f, -0.085555f, 0.224801f), new Vector3(359.0469f, 68.82883f, 0.145291f), 624);
				}
			}
		}

		private static void CreateTavernAshtray(ShopItemSpawner anchor, string town, Vector3 offset, int prefabIndex)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			string hostName = "DogEggz.Cigar.Ashtray." + town;
			Quaternion val = Quaternion.Inverse(((Component)anchor).transform.rotation);
			CreateRelativeSpawner(anchor, hostName, offset, ((Quaternion)(ref val)).eulerAngles, prefabIndex);
		}

		internal static bool IsWrapperDisplay(ShopItemSpawner spawner)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)spawner == (Object)null))
			{
				Scene scene = ((Component)spawner).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					scene = ((Component)spawner).gameObject.scene;
					string name = ((Scene)(ref scene)).name;
					string name2 = ((Object)((Component)spawner).gameObject).name;
					if ((!(name == "island 1 A Gold Rock") || (!(name2 == "shop item (171)") && !(name2 == "shop item (173)"))) && (!(name == "island 9 E Dragon Cliffs") || (!(name2 == "shop item spawner (184)") && !(name2 == "DogEggz.Cigar.DriedLeaf.DragonCliffs.2"))))
					{
						if (name == "island 15 M (Fort)")
						{
							if (!(name2 == "DogEggz.Cigar.DriedLeaf.Fort.1") && !(name2 == "DogEggz.Cigar.DriedLeaf.Fort.2"))
							{
								return name2 == "DogEggz.Cigar.DriedLeaf.Fort.3";
							}
							return true;
						}
						return false;
					}
					return true;
				}
			}
			return false;
		}

		internal static void PrepareWrapperRestock(ShopItemSpawner spawner)
		{
			if (CigarPrefabRegistrar.IsReady && IsWrapperDisplay(spawner))
			{
				spawner.itemPrefab = CigarAssetBundle.GetPrefab(614);
				AlignWrapper(spawner);
			}
		}

		private static void AlignWrapper(ShopItemSpawner spawner)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			Scene scene = ((Component)spawner).gameObject.scene;
			if (((Scene)(ref scene)).name == "island 9 E Dragon Cliffs")
			{
				Quaternion val = Quaternion.Euler(0f, 317.992f, 0f);
				((Component)spawner).transform.localPosition = new Vector3(-34.694f, 3.453f, -557.039f) + val * new Vector3(0f, 0f, (((Object)spawner).name == "shop item spawner (184)") ? (-0.08f) : (-0.37f));
				((Component)spawner).transform.localRotation = val;
				return;
			}
			scene = ((Component)spawner).gameObject.scene;
			if (((Scene)(ref scene)).name == "island 1 A Gold Rock")
			{
				((Component)spawner).transform.localPosition = ((((Object)spawner).name == "shop item (171)") ? new Vector3(1568.4852f, 7.368f, -399.9322f) : new Vector3(1568.1798f, 7.368f, -399.5058f));
				((Component)spawner).transform.localEulerAngles = new Vector3(0f, 145.594f, 0f);
			}
			else
			{
				((Component)spawner).transform.rotation = Quaternion.FromToRotation(((Component)spawner).transform.up, Vector3.up) * ((Component)spawner).transform.rotation;
			}
		}

		private static void ReconcileWrapperStock(ShopItemSpawner spawner)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			object? value = StockItem.GetValue(spawner);
			ShipItem val = (ShipItem)((value is ShipItem) ? value : null);
			if ((Object)(object)val == (Object)null || val.sold)
			{
				return;
			}
			SaveablePrefab component = ((Component)val).GetComponent<SaveablePrefab>();
			if ((Object)(object)component == (Object)null || component.prefabIndex != 613)
			{
				return;
			}
			GameObject prefab = CigarAssetBundle.GetPrefab(614);
			if (!((Object)(object)prefab == (Object)null))
			{
				ShipItem component2 = Object.Instantiate<GameObject>(prefab, ((Component)spawner).transform.position, ((Component)spawner).transform.rotation).GetComponent<ShipItem>();
				((Component)component2).transform.SetParent(((Component)spawner).transform, true);
				object? value2 = ItemShopArea.GetValue(val);
				ShopArea val2 = (ShopArea)((value2 is ShopArea) ? value2 : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.itemsForSale.Remove(val);
					component2.AddToShop(val2);
				}
				((Component)component2).gameObject.SetActive(((Component)val).gameObject.activeSelf);
				StockItem.SetValue(spawner, component2);
				((Component)val).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}

		internal static void AddSageHillsPotAfterStart(Shopkeeper shopkeeper)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			if (!CigarPrefabRegistrar.IsReady || (Object)(object)shopkeeper == (Object)null)
			{
				return;
			}
			Scene scene = ((Component)shopkeeper).gameObject.scene;
			if (!((Scene)(ref scene)).IsValid())
			{
				return;
			}
			scene = ((Component)shopkeeper).gameObject.scene;
			if (((Scene)(ref scene)).name != "island 13 E (Sage Hills)" || ((Object)((Component)shopkeeper).gameObject).name != "shopkeeper (2)" || !IsUniqueShopkeeper(shopkeeper))
			{
				return;
			}
			Transform parent = ((Component)shopkeeper).transform.parent;
			Transform val = FindDirectChild(parent, "shop area (3)");
			if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).GetComponent<ShopArea>() == (Object)null)
			{
				LogIdentityFailure("island 13 E (Sage Hills)/shopkeeper (2)+shop area (3)");
				return;
			}
			Transform val2 = FindDirectChild(parent, "east_market_stall 1 (1)");
			if ((Object)(object)val2 == (Object)null)
			{
				LogIdentityFailure("island 13 E (Sage Hills)/east_market_stall 1 (1)");
				return;
			}
			Vector3 val3 = Vector3.ProjectOnPlane(-val2.up, Vector3.up);
			Vector3 val4 = ((Vector3)(ref val3)).normalized;
			if (Vector3.Dot(val4, ((Component)shopkeeper).transform.forward) < 0f)
			{
				val4 = -val4;
			}
			Vector3 val5 = ((Component)shopkeeper).transform.InverseTransformVector(val4 * 0.72f);
			Quaternion val6 = Quaternion.Inverse(((Component)shopkeeper).transform.rotation) * Quaternion.LookRotation(val4, Vector3.up);
			Vector3 eulerAngles = ((Quaternion)(ref val6)).eulerAngles;
			for (int i = 0; i < 3; i++)
			{
				CreateRelativeSpawner(((Component)shopkeeper).transform, availableAtNight: false, 1f, "DogEggz.Cigar.TobaccoPot.SageHills" + ((i == 0) ? "" : ("." + (i + 1))), new Vector3(-2.175f, 0.6f, 3.931f) + val5 * (float)i, eulerAngles, 610);
			}
		}

		private static void CreateRelativeSpawner(ShopItemSpawner anchor, string hostName, Vector3 localPosition, Vector3 localEuler, int prefabIndex)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			CreateRelativeSpawner(((Component)anchor).transform, anchor.availableAtNight, anchor.priceMult, hostName, localPosition, localEuler, prefabIndex);
		}

		private static void CreateRelativeSpawner(Transform anchor, bool availableAtNight, float priceMultiplier, string hostName, Vector3 localPosition, Vector3 localEuler, int prefabIndex)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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)
			//IL_009f: 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)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = anchor.parent;
			if ((Object)(object)parent == (Object)null)
			{
				return;
			}
			Transform val = FindDirectChild(parent, hostName);
			if ((Object)(object)val != (Object)null)
			{
				ShopItemSpawner component = ((Component)val).GetComponent<ShopItemSpawner>();
				if (prefabIndex == 614 && (Object)(object)component != (Object)null)
				{
					component.itemPrefab = CigarAssetBundle.GetPrefab(prefabIndex);
					AlignWrapper(component);
					ReconcileWrapperStock(component);
				}
				return;
			}
			GameObject val2 = new GameObject(hostName)
			{
				layer = ((Component)anchor).gameObject.layer
			};
			val2.transform.SetParent(parent, true);
			val2.transform.position = anchor.TransformPoint(localPosition);
			val2.transform.rotation = anchor.rotation * Quaternion.Euler(localEuler);
			val2.transform.localScale = Vector3.one;
			val2.AddComponent<MeshFilter>();
			val2.AddComponent<MeshRenderer>();
			ShopItemSpawner val3 = val2.AddComponent<ShopItemSpawner>();
			val3.itemPrefab = CigarAssetBundle.GetPrefab(prefabIndex);
			val3.availableAtNight = availableAtNight;
			val3.priceMult = priceMultiplier;
			if (prefabIndex == 614)
			{
				AlignWrapper(val3);
			}
			ManualLogSource logSource = Plugin.LogSource;
			if (logSource != null)
			{
				string[] obj = new string[5] { "Added shop display ", hostName, " in ", null, null };
				Scene scene = ((Component)anchor).gameObject.scene;
				obj[3] = ((Scene)(ref scene)).name;
				obj[4] = ".";
				logSource.LogInfo((object)string.Concat(obj));
			}
		}

		private static bool IsUniqueSpawner(ShopItemSpawner target)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//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)
			int num = 0;
			ShopItemSpawner[] array = Resources.FindObjectsOfTypeAll<ShopItemSpawner>();
			for (int i = 0; i < array.Length; i++)
			{
				if (!((Object)(object)array[i] != (Object)null))
				{
					continue;
				}
				Scene scene = ((Component)array[i]).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					scene = ((Component)array[i]).gameObject.scene;
					int handle = ((Scene)(ref scene)).handle;
					scene = ((Component)target).gameObject.scene;
					if (handle == ((Scene)(ref scene)).handle && ((Object)((Component)array[i]).gameObject).name == ((Object)((Component)target).gameObject).name)
					{
						num++;
					}
				}
			}
			return num == 1;
		}

		private static bool IsUniqueShopkeeper(Shopkeeper target)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//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)
			int num = 0;
			Shopkeeper[] array = Resources.FindObjectsOfTypeAll<Shopkeeper>();
			for (int i = 0; i < array.Length; i++)
			{
				if (!((Object)(object)array[i] != (Object)null))
				{
					continue;
				}
				Scene scene = ((Component)array[i]).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					scene = ((Component)array[i]).gameObject.scene;
					int handle = ((Scene)(ref scene)).handle;
					scene = ((Component)target).gameObject.scene;
					if (handle == ((Scene)(ref scene)).handle && ((Object)((Component)array[i]).gameObject).name == ((Object)((Component)target).gameObject).name)
					{
						num++;
					}
				}
			}
			return num == 1;
		}

		private static Transform FindDirectChild(Transform parent, string name)
		{
			if ((Object)(object)parent == (Object)null)
			{
				return null;
			}
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform child = parent.GetChild(i);
				if (((Object)child).name == name)
				{
					return child;
				}
			}
			return null;
		}

		private static void LogIdentityFailure(string identity)
		{
			if (LoggedIdentityFailures.Add(identity))
			{
				ManualLogSource logSource = Plugin.LogSource;
				if (logSource != null)
				{
					logSource.LogError((object)("Shop placement identity did not resolve exactly once: " + identity + ". That display was skipped."));
				}
			}
		}
	}
	internal static class StorageShopPlacement
	{
		internal static void Configure(ShopItemSpawner first)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			if (!CigarPrefabRegistrar.IsReady || (Object)(object)first == (Object)null)
			{
				return;
			}
			Scene scene = ((Component)first).gameObject.scene;
			if (!((Scene)(ref scene)).IsValid())
			{
				return;
			}
			scene = ((Component)first).gameObject.scene;
			int num = ((Scene)(ref scene)).name switch
			{
				"island 9 E Dragon Cliffs" => 2, 
				"island 15 M (Fort)" => 1, 
				"island 1 A Gold Rock" => 0, 
				_ => -1, 
			};
			if (num < 0)
			{
				return;
			}
			string anchorName = num switch
			{
				1 => "shop item (24)", 
				0 => "shop item (171)", 
				_ => "shop item spawner (184)", 
			};
			ShopItemSpawner[] all = (from s in Resources.FindObjectsOfTypeAll<ShopItemSpawner>()
				where ((Component)s).gameObject.scene == ((Component)first).gameObject.scene
				select s).ToArray();
			ShopItemSpawner val = ((IEnumerable<ShopItemSpawner>)all).SingleOrDefault((Func<ShopItemSpawner, bool>)((ShopItemSpawner s) => ((Object)s).name == anchorName));
			if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).GetComponent<StorageShopMarker>() != (Object)null)
			{
				return;
			}
			((Component)val).gameObject.AddComponent<StorageShopMarker>();
			Vector3 position = ((Component)val).transform.position;
			position.y = 0f;
			switch (num)
			{
			case 0:
				Replace(all, "shop item (176)", 627, position + new Vector3(-0.68553f, 3.6329f, 0.85053f), Quaternion.Euler(348.659f, 236.368f, 0f) * Quaternion.Euler(0f, 180f, 0f));
				Create(val, 630, position + new Vector3(-66.07019f, 3.31741f, -4.52365f), Quaternion.Euler(0f, 161.34f, 0f), tavern: true);
				return;
			case 1:
			{
				Vector3 val2 = position + new Vector3(0.04406f, 3.064f, 0.35797f);
				Quaternion val3 = Quaternion.Euler(0f, 179.065f, 0f);
				Create(val, 625, val2, val3, tavern: false);
				Quaternion val4 = Quaternion.Euler(0f, 359.065f, 0f);
				BoxCollider component = CigarAssetBundle.GetPrefab(625).GetComponent<BoxCollider>();
				BoxCollider component2 = CigarAssetBundle.GetPrefab(626).GetComponent<BoxCollider>();
				Vector3 position2 = val2 + val3 * (component.center + Vector3.right * 0.48f) - val4 * component2.center;
				position2.y = val2.y + component.center.y - component.size.y * 0.5f - component2.center.y + component2.size.y * 0.5f;
				Create(val, 626, position2, val4, tavern: false);
				Create(val, 629, position + new Vector3(-38.75871f, 3.03934f, -12.07408f), Quaternion.Euler(0f, 179.5f, 0f), tavern: true);
				return;
			}
			}
			Replace(all, "shop item spawner (188)", 628, position + new Vector3(0.77688f, 3.32881f, -0.54858f), Quaternion.Euler(0f, 321.609f, 352.364f) * Quaternion.Euler(0f, 180f, 0f));
			Create(val, 631, position + new Vector3(-35.08951f, 3.39949f, 22.71332f), Quaternion.Euler(0f, 135.68f, 0f), tavern: true);
			ShopItemSpawner[] array = new int[3] { 185, 186, 187 }.Select((int n) => all.Single((ShopItemSpawner s) => ((Object)s).name == "shop item spawner (" + n + ")")).ToArray();
			Vector3 val5 = position + new Vector3(0.95999f, 3.48246f, -1.14672f);
			Vector3 val6 = default(Vector3);
			((Vector3)(ref val6))..ctor(0.027805f, 0.26464f, 0.02203f);
			for (int num2 = 0; num2 < 3; num2++)
			{
				((Component)array[num2]).transform.position = val5 + val6 * (float)num2;
			}
			GameObject val7 = new GameObject("DogEggz.Cigar.TobaccoStockStack");
			val7.transform.SetParent(((Component)val).transform.parent, false);
			val7.transform.position = val5;
			val7.AddComponent<StorageStockStack>().Configure(array, val5, val6);
		}

		private static void Replace(ShopItemSpawner[] all, string name, int id, Vector3 position, Quaternion rotation)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			ShopItemSpawner obj = all.Single((ShopItemSpawner s) => ((Object)s).name == name);
			obj.itemPrefab = CigarAssetBundle.GetPrefab(id);
			((Component)obj).transform.SetPositionAndRotation(position, rotation);
		}

		private static void Create(ShopItemSpawner anchor, int id, Vector3 position, Quaternion rotation, bool tavern)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("DogEggz.Cigar.Storage." + id);
			val.transform.SetParent(((Component)anchor).transform.parent, false);
			val.transform.SetPositionAndRotation(position, rotation);
			val.AddComponent<MeshFilter>();
			val.AddComponent<MeshRenderer>();
			ShopItemSpawner obj = val.AddComponent<ShopItemSpawner>();
			obj.itemPrefab = CigarAssetBundle.GetPrefab(id);
			obj.priceMult = 1f;
			obj.availableAtNight = tavern || anchor.availableAtNight;
		}
	}
	public sealed class StorageShopMarker : MonoBehaviour
	{
	}
	public sealed class StorageStockStack : MonoBehaviour
	{
		private ShopItemSpawner[] spawners;

		private Vector3 baseLocal;

		private Vector3 stepLocal;

		private float nextCheck;

		private static readonly FieldInfo Stock = typeof(ShopItemSpawner).GetField("item", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo ReturnPosition = typeof(ShipItem).GetField("shopPos", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo Shop = typeof(ShipItem).GetField("shopArea", BindingFlags.Instance | BindingFlags.NonPublic);

		public void Configure(ShopItemSpawner[] values, Vector3 bottom, Vector3 step)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			spawners = values;
			baseLocal = ((Component)this).transform.InverseTransformPoint(bottom);
			stepLocal = ((Component)this).transform.InverseTransformVector(step);
		}

		private void LateUpdate()
		{
			if (!(Time.unscaledTime < nextCheck) && spawners != null)
			{
				nextCheck = Time.unscaledTime + 0.2f;
				Reconcile();
			}
		}

		public void Reconcile()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			for (int i = 0; i < spawners.Length; i++)
			{
				object? value = Stock.GetValue(spawners[i]);
				ShipItem val = (ShipItem)((value is ShipItem) ? value : null);
				bool num2 = (Object)(object)val != (Object)null && !val.sold;
				Vector3 val2 = (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : Vector3.zero);
				Vector3 val3 = ((Component)this).transform.TransformPoint(baseLocal + stepLocal * (float)num);
				((Component)spawners[i]).transform.position = val3;
				if (num2)
				{
					((Component)val).transform.position = (((Object)(object)((PickupableItem)val).held == (Object)null) ? val3 : val2);
					object? value2 = Shop.GetValue(val);
					ShopArea val4 = (ShopArea)((value2 is ShopArea) ? value2 : null);
					if ((Object)(object)val4 != (Object)null)
					{
						ReturnPosition.SetValue(val, ((Component)val4).transform.InverseTransformPoint(val3));
					}
					num++;
				}
			}
		}
	}
}
namespace TobaccoPotAndCigar.Compatibility
{
	internal struct BlueEffectProfile
	{
		internal float ImmediateSleepChange;

		internal float GreenVisualChargeRate;

		internal static BlueEffectProfile VanillaGreen => new BlueEffectProfile
		{
			ImmediateSleepChange = -0.11f,
			GreenVisualChargeRate = 2f
		};

		internal static BlueEffectProfile RadEnhanced(int multiplier)
		{
			multiplier = Math.Max(0, multiplier);
			return new BlueEffectProfile
			{
				ImmediateSleepChange = -0.11f * (float)multiplier,
				GreenVisualChargeRate = 2f * (float)multiplier * 0.33f
			};
		}
	}
	internal static class RadRefinementsCompatibility
	{
		internal const string PluginGuid = "com.raddude.radrefinements";

		private static ConfigEntry<bool> enableBlueTobacco;

		private static ConfigEntry<int> bluePotencyMult;

		private static bool warnedAboutIncompatibleVersion;

		internal static BlueEffectProfile GetBlueEffectProfile()
		{
			if (!Chainloader.PluginInfos.TryGetValue("com.raddude.radrefinements", out var value))
			{
				return BlueEffectProfile.VanillaGreen;
			}
			if ((enableBlueTobacco == null || bluePotencyMult == null) && !TryBindConfigEntries(((object)value.Instance).GetType().Assembly))
			{
				WarnOnce();
				return BlueEffectProfile.VanillaGreen;
			}
			if (!enableBlueTobacco.Value)
			{
				return BlueEffectProfile.VanillaGreen;
			}
			return BlueEffectProfile.RadEnhanced(bluePotencyMult.Value);
		}

		internal static void Reset()
		{
			enableBlueTobacco = null;
			bluePotencyMult = null;
			warnedAboutIncompatibleVersion = false;
		}

		private static bool TryBindConfigEntries(Assembly assembly)
		{
			Type type = assembly.GetType("RadRefinements.Configs", throwOnError: false);
			if (type == null)
			{
				return false;
			}
			FieldInfo field = type.GetField("enableBlueTobacco", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			FieldInfo field2 = type.GetField("bluePotencyMult", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			enableBlueTobacco = ((field == null) ? null : (field.GetValue(null) as ConfigEntry<bool>));
			bluePotencyMult = ((field2 == null) ? null : (field2.GetValue(null) as ConfigEntry<int>));
			if (enableBlueTobacco != null)
			{
				return bluePotencyMult != null;
			}
			return false;
		}

		private static void WarnOnce()
		{
			if (!warnedAboutIncompatibleVersion)
			{
				warnedAboutIncompatibleVersion = true;
				ManualLogSource logSource = Plugin.LogSource;
				if (logSource != null)
				{
					logSource.LogWarning((object)"Rad Refinements was detected but its blue-tobacco settings could not be read. Cigar blue tobacco will use vanilla green effects.");
				}
			}
		}
	}
}
namespace TobaccoPotAndCigar.Smoking
{
	internal static class CigarEffectService
	{
		private sealed class DoseChannel
		{
			internal CigarTobaccoType Type;

			internal float Charge;
		}

		private sealed class DoseGroup
		{
			internal readonly List<DoseChannel> Channels = new List<DoseChannel>(3);
		}

		private static readonly Dictionary<int, DoseGroup> Doses = new Dictionary<int, DoseGroup>();

		private static readonly List<int> RemovalBuffer = new List<int>();

		internal static void ApplyInhale(CigarRuntimeState source, TobaccoBlend blend, float deltaTime)
		{
			if (!((Object)(object)source == (Object)null) && !(deltaTime <= 0f))
			{
				DoseGroup orCreateDose = GetOrCreateDose(source, blend);
				BlueEffectProfile blueEffectProfile = RadRefinementsCompatibility.GetBlueEffectProfile();
				CigarEffectTotals cigarEffectTotals = CigarEffectMath.Calculate(blend, blueEffectProfile.ImmediateSleepChange, blueEffectProfile.GreenVisualChargeRate);
				PlayerNeeds.sleep += deltaTime * cigarEffectTotals.ImmediateSleepPerSecond;
				for (int i = 0; i < orCreateDose.Channels.Count; i++)
				{
					DoseChannel doseChannel = orCreateDose.Channels[i];
					float num = ((doseChannel.Type == CigarTobaccoType.Blue) ? blueEffectProfile.GreenVisualChargeRate : 2f);
					doseChannel.Charge += deltaTime * num;
				}
			}
		}

		internal static void TickAndCompose(PlayerTobacco vanilla, float deltaTime)
		{
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)vanilla == (Object)null || Doses.Count == 0 || deltaTime <= 0f)
			{
				return;
			}
			float num = vanilla.white;
			float num2 = vanilla.green;
			float num3 = vanilla.black;
			RemovalBuffer.Clear();
			foreach (KeyValuePair<int, DoseGroup> dose in Doses)
			{
				bool flag = false;
				List<DoseChannel> channels = dose.Value.Channels;
				for (int i = 0; i < channels.Count; i++)
				{
					DoseChannel doseChannel = channels[i];
					if (!(doseChannel.Charge <= 0f))
					{
						flag = true;
						doseChannel.Charge = Mathf.Max(0f, doseChannel.Charge - deltaTime * 0.5f);
						switch (doseChannel.Type)
						{
						case CigarTobaccoType.White:
							num += doseChannel.Charge;
							PlayerNeeds.sleep -= deltaTime * 0.165f;
							break;
						case CigarTobaccoType.Green:
							num2 += doseChannel.Charge;
							PlayerNeeds.sleep -= deltaTime * 0.055f;
							break;
						case CigarTobaccoType.Blue:
							num2 += doseChannel.Charge;
							PlayerNeeds.sleep -= deltaTime * 0.055f;
							break;
						case CigarTobaccoType.Black:
							num3 += doseChannel.Charge;
							PlayerNeeds.sleep -= deltaTime * 0.3f;
							break;
						case CigarTobaccoType.Brown:
							PlayerNeeds.sleep -= deltaTime * 0.2f;
							break;
						}
					}
				}
				if (!flag)
				{
					RemovalBuffer.Add(dose.Key);
				}
			}
			for (int j = 0; j < RemovalBuffer.Count; j++)
			{
				Doses.Remove(RemovalBuffer[j]);
			}
			PlayerTobacco.saturationOverride = 1f + (num2 - num) / 100f;
			if ((Object)(object)vanilla.postProcessing != (Object)null)
			{
				Settings settings = vanilla.postProcessing.bloom.settings;
				settings.bloom.intensity = Mathf.Lerp(0.66f, 0f, Mathf.Clamp01(num3 / 100f));
				vanilla.postProcessing.bloom.settings = settings;
			}
		}

		internal static void Reset()
		{
			Doses.Clear();
			RemovalBuffer.Clear();
			CigarSmokeContext.Current = null;
		}

		private static DoseGroup GetOrCreateDose(CigarRuntimeState source, TobaccoBlend blend)
		{
			int instanceID = ((Object)source).GetInstanceID();
			if (Doses.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			value = new DoseGroup();
			AddChannels(value, CigarTobaccoType.White, blend.White);
			AddChannels(value, CigarTobaccoType.Green, blend.Green);
			AddChannels(value, CigarTobaccoType.Black, blend.Black);
			AddChannels(value, CigarTobaccoType.Brown, blend.Brown);
			AddChannels(value, CigarTobaccoType.Blue, blend.Blue);
			Doses.Add(instanceID, value);
			return value;
		}

		private static void AddChannels(DoseGroup group, CigarTobaccoType type, int count)
		{
			for (int i = 0; i < count; i++)
			{
				group.Channels.Add(new DoseChannel
				{
					Type = type
				});
			}
		}
	}
	internal static class CigarSmokeContext
	{
		internal static CigarRuntimeState Current;
	}
}
namespace TobaccoPotAndCigar.Prefabs
{
	internal static class VanillaPipeSmokeProfile
	{
		internal const float EmissionRate = 120f;

		internal const float MaximumLifetime = 12f;

		internal const int MaximumParticles = 1536;

		internal static void ApplyRequired(GameObject prefab, int prefabIndex)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				throw new InvalidOperationException("Vanilla pipe prefab " + prefabIndex + " is missing.");
			}
			SaveablePrefab component = prefab.GetComponent<SaveablePrefab>();
			ShipItemPipe component2 = prefab.GetComponent<ShipItemPipe>();
			if ((Object)(object)component == (Object)null || component.prefabIndex != prefabIndex || (Object)(object)component2 == (Object)null || !Apply(component2))
			{
				throw new InvalidOperationException("Vanilla pipe prefab " + prefabIndex + " does not expose its expected smoke profile.");
			}
		}

		internal static bool ApplyIfVanilla(ShipItemPipe pipe)
		{
			if ((Object)(object)pipe == (Object)null)
			{
				return false;
			}
			SaveablePrefab component = ((Component)pipe).GetComponent<SaveablePrefab>();
			if ((Object)(object)component == (Object)null || component.prefabIndex < 300 || component.prefabIndex > 302)
			{
				return false;
			}
			return Apply(pipe);
		}

		private static bool Apply(ShipItemPipe pipe)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem componentInChildren = ((Component)pipe).GetComponentInChildren<ParticleSystem>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return false;
			}
			pipe.maxLifetime = 12f;
			pipe.maxEmission = 120f;
			MainModule main = componentInChildren.main;
			((MainModule)(ref main)).maxParticles = 1536;
			EmissionModule emission = componentInChildren.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(120f);
			return true;
		}
	}
	internal static class CigarAssetBundle
	{
		internal const string BundleName = "dogeggz.cigar.assets";

		private static readonly Dictionary<int, GameObject> Prefabs = new Dictionary<int, GameObject>();

		private static AssetBundle bundle;

		internal static bool IsLoaded
		{
			get
			{
				if ((Object)(object)bundle != (Object)null)
				{
					return Prefabs.Count == 22;
				}
				return false;
			}
		}

		internal static void Load(string pluginDirectory)
		{
			if (IsLoaded)
			{
				return;
			}
			string text = Path.Combine(pluginDirectory, "assets", "dogeggz.cigar.assets");
			if (!File.Exists(text))
			{
				throw new FileNotFoundException("Cigar AssetBundle is missing.", text);
			}
			bundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)bundle == (Object)null)
			{
				throw new InvalidOperationException("Unity could not load " + text);
			}
			CigarWrapperVisual.BindBundleData(bundle.LoadAsset<CigarWrapperVisualData>("assets/cigar/generated/modelpreview/wrappervisualdata.asset"));
			Prefabs.Clear();
			GameObject[] array = bundle.LoadAllAssets<GameObject>();
			for (int i = 0; i < array.Length; i++)
			{
				SaveablePrefab component = array[i].GetComponent<SaveablePrefab>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				int prefabIndex = component.prefabIndex;
				if (prefabIndex >= 610 && prefabIndex <= 631)
				{
					if (Prefabs.ContainsKey(prefabIndex))
					{
						throw new InvalidOperationException("AssetBundle contains duplicate prefab index " + prefabIndex + ".");
					}
					Prefabs.Add(prefabIndex, array[i]);
				}
			}
			for (int j = 610; j <= 631; j++)
			{
				if (!Prefabs.ContainsKey(j))
				{
					throw new InvalidOperationException("AssetBundle is missing prefab index " + j + ".");
				}
			}
		}

		internal static GameObject GetPrefab(int index)
		{
			if (!Prefabs.TryGetValue(index, out var value))
			{
				return null;
			}
			return value;
		}

		internal static void Unload()
		{
			CigarWrapperVisual.ClearBundleData();
			Prefabs.Clear();
			if ((Object)(object)bundle != (Object)null)
			{
				bundle.Unload(false);
			}
			bundle = null;
		}
	}
	internal static class CigarPrefabRegistrar
	{
		private const int RequiredDirectoryLength = 632;

		private static bool registered;

		internal static bool IsReady => registered;

		internal static void EnsureRegistered(PrefabsDirectory directory)
		{
			if (registered)
			{
				return;
			}
			if ((Object)(object)directory == (Object)null || directory.directory == null)
			{
				throw new InvalidOperationException("PrefabsDirectory is unavailable.");
			}
			if (!CigarAssetBundle.IsLoaded)
			{
				throw new InvalidOperationException("Cigar AssetBundle is not loaded.");
			}
			GameObject[] array = directory.directory;
			if (array.Length < 632)
			{
				Array.Resize(ref array, 632);
			}
			for (int i = 610; i <= 631; i++)
			{
				GameObject prefab = CigarAssetBundle.GetPrefab(i);
				GameObject val = array[i];
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)prefab)
				{
					throw new InvalidOperationException("Prefab index " + i + " is already occupied by " + ((Object)val).name + "; registration aborted without overwriting it.");
				}
				ValidateBundledPrefab(i, prefab);
			}
			directory.directory = array;
			for (int j = 610; j <= 631; j++)
			{
				GameObject prefab2 = CigarAssetBundle.GetPrefab(j);
				directory.directory[j] = prefab2;
				PrefabReplacement.RegisterCustomPrefab(j, prefab2);
			}
			registered = true;
		}

		internal static void ValidateAndConfigure(PrefabsDirectory directory)
		{
			if (!registered || (Object)(object)directory == (Object)null || directory.shipItems == null || directory.shipItems.Length < 632)
			{
				throw new InvalidOperationException("PrefabsDirectory ship-item cache was not populated for indices 610-631.");
			}
			for (int i = 610; i <= 631; i++)
			{
				if ((Object)(object)directory.directory[i] != (Object)(object)CigarAssetBundle.GetPrefab(i) || (Object)(object)directory.shipItems[i] == (Object)null)
				{
					throw new InvalidOperationException("Runtime prefab cache validation failed at index " + i + ".");
				}
			}
			for (int j = 300; j <= 302; j++)
			{
				VanillaPipeSmokeProfile.ApplyRequired(directory.directory[j], j);
			}
			ConfigureTobaccoHint(directory.directory[310], 310);
			ConfigureTobaccoHint(directory.directory[312], 312);
			ConfigureTobaccoHint(directory.directory[314], 314);
			ConfigureTobaccoHint(directory.directory[316], 316);
			ConfigureTobaccoHint(directory.directory[318], 318);
			ConfigureVanillaDrying(directory.directory[312], 310);
			ConfigureVanillaDrying(directory.directory[310], 316);
			ConfigureVanillaDrying(directory.directory[316], 314);
			ManualLogSource logSource = Plugin.LogSource;
			if (logSource != null)
			{
				logSource.LogInfo((object)"Registered bundled prefabs 610-631 and rack-only tobacco drying.");
			}
		}

		internal static void Reset()
		{
			registered = false;
			PrefabReplacement.ClearCustomPrefabs();
		}

		private static void ConfigureVanillaDrying(GameObject prefab, int resultPrefabIndex)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				throw new InvalidOperationException("Vanilla drying source for result " + resultPrefabIndex + " is missing.");
			}
			RackOnlyDrying rackOnlyDrying = prefab.GetComponent<RackOnlyDrying>();
			if ((Object)(object)rackOnlyDrying == (Object)null)
			{
				rackOnlyDrying = prefab.AddComponent<RackOnlyDrying>();
			}
			rackOnlyDrying.ConfigureResultPrefab(resultPrefabIndex);
		}

		private static void ConfigureTobaccoHint(GameObject prefab, int prefabIndex)
		{
			ShipItemTobacco val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ShipItemTobacco>() : null);
			if ((Object)(object)val == (Object)null || string.IsNullOrEmpty(((ShipItem)val).name))
			{
				throw new InvalidOperationException("Tobacco prefab " + prefabIndex + " cannot provide its pointer hint name.");
			}
			((GoPointerButton)val).description = ((ShipItem)val).name;
		}

		private static void ValidateBundledPrefab(int index, GameObject prefab)
		{
			if ((Object)(object)prefab == (Object)null || (Object)(object)prefab.GetComponent<ShipItem>() == (Object)null || (Object)(object)prefab.GetComponent<SaveablePrefab>() == (Object)null)
			{
				throw new InvalidOperationException("Bundled prefab " + index + " is missing its item/save contract.");
			}
			int num;
			if (index != 610)
			{
				if (index != 611)
				{
					if (index != 612)
					{
						if (index != 613)
						{
							if (index != 614)
							{
								num = (((index <= 624) ? ((Object)(object)prefab.GetComponent<AshtrayState>() != (Object)null) : ((index <= 628) ? ((Object)(object)prefab.GetComponent<PipeRackState>() != (Object)null) : ((Object)(object)prefab.GetComponent<CigarBoxState>() != (Object)null))) ? 1 : 0);
							}
							else
							{
								if (!((Object)(object)prefab.GetComponent<CigarWrapperState>() != (Object)null))
								{
									goto IL_0114;
								}
								num = (((Object)(object)prefab.GetComponent<CigarWrapperVisual>() != (Object)null) ? 1 : 0);
							}
						}
						else
						{
							num = (((Object)(object)prefab.GetComponent<DriedTobaccoLeafState>() != (Object)null) ? 1 : 0);
						}
					}
					else
					{
						num = (((Object)(object)prefab.GetComponent<CigarRuntimeState>() != (Object)null) ? 1 : 0);
					}
				}
				else
				{
					if (!((Object)(object)prefab.GetComponent<FreshTobaccoLeafState>() != (Object)null))
					{
						goto IL_0114;
					}
					num = (((Object)(object)prefab.GetComponent<RackOnlyDrying>() != (Object)null) ? 1 : 0);
				}
			}
			else
			{
				num = (((Object)(object)prefab.GetComponent<TobaccoPlantPotState>() != (Object)null) ? 1 : 0);
			}
			if (num != 0)
			{
				if (index == 614 && !prefab.GetComponent<CigarWrapperVisual>().IsConfigured(out var error))
				{
					throw new InvalidOperationException("Bundled wrapper filling is invalid: " + error);
				}
				return;
			}
			goto IL_0114;
			IL_0114:
			throw new InvalidOperationException("Bundled prefab " + index + " does not contain its authored runtime component.");
		}
	}
}
namespace TobaccoPotAndCigar.Patches
{
	[HarmonyPatch(typeof(ShipItemPipe), "OnItemClick")]
	internal static class CigarRefillBlockPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ShipItemPipe __instance, ref bool __result)
		{
			if ((Object)(object)((Component)__instance).GetComponent<CigarRuntimeState>() == (Object)null)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(ShipItemPipe), "ExtraLateUpdate")]
	internal static class CigarPipeContextPatch
	{
		[HarmonyPrefix]
		private static void Prefix(ShipItemPipe __instance, out CigarRuntimeState __state)
		{
			__state = ((Component)__instance).GetComponent<CigarRuntimeState>();
			CigarSmokeContext.Current = __state;
		}

		[HarmonyPostfix]
		private static void Postfix(CigarRuntimeState __state, float ___currentHeat, bool ___inhaling)
		{
			if ((Object)(object)__state != (Object)null && !__state.TryDestroyIfConsumed())
			{
				__state.SyncVisuals(snap: false, ___currentHeat / 100f, ___inhaling);
			}
			if ((Object)(object)CigarSmokeContext.Current == (Object)(object)__state)
			{
				CigarSmokeContext.Current = null;
			}
		}
	}
	[HarmonyPatch(typeof(ShipItemPipe), "OnLoad")]
	internal static class CigarPipeLoadPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ShipItemPipe __instance)
		{
			VanillaPipeSmokeProfile.ApplyIfVanilla(__instance);
			RestingPipeState.Ensure(__instance);
			CigarRuntimeState component = ((Component)__instance).GetComponent<CigarRuntimeState>();
			if ((Object)(object)component != (Object)null && !component.TryDestroyIfConsumed())
			{
				component.RefreshValue();
				component.SyncVisuals(snap: true, 0f, inhaling: false);
			}
		}
	}
	[HarmonyPatch(typeof(ShipItemPipe), "Smoke")]
	internal static class PipeHeldSmokePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ShipItemPipe __instance)
		{
			if (((ShipItem)__instance).sold)
			{
				return (Object)(object)((PickupableItem)__instance).held != (Object)null;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ShipItemPipe), "StopSmoking")]
	internal static class PipeIdleExhalePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ShipItemPipe __instance, bool ___inhaling)
		{
			if (!___inhaling)
			{
				return (Object)(object)((PickupableItem)__instance).held != (Object)null;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerTobacco), "Smoke")]
	internal static class CigarSmokeRecipePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(int tobaccoType)
		{
			if (tobaccoType >= 0)
			{
				return true;
			}
			CigarRuntimeState current = CigarSmokeContext.Current;
			if ((Object)(object)current == (Object)null || !TobaccoBlendCodec.TryDecode(-tobaccoType, out var blend))
			{
				RuntimeDiagnostics.Error("Rejected a cigar smoke call with no valid cigar recipe context.");
				return false;
			}
			CigarEffectService.ApplyInhale(current, blend, Time.deltaTime);
			return false;
		}
	}
	[HarmonyPatch(typeof(PlayerTobacco), "Update")]
	internal static class CigarEffectUpdatePatch
	{
		[HarmonyPostfix]
		private static void Postfix(PlayerTobacco __instance)
		{
			CigarEffectService.TickAndCompose(__instance, Time.deltaTime);
		}
	}
	[HarmonyPatch(typeof(CrateInventoryUI), "GetCrateDimensions")]
	internal static class RackJarDimensionsPatch
	{
		internal static bool IsJar(CrateInventory crate)
		{
			PipeRackState pipeRackState = (((Object)(object)crate != (Object)null) ? ((Component)crate).GetComponent<PipeRackState>() : null);
			if ((Object)(object)pipeRackState != (Object)null)
			{
				return pipeRackState.HasJar;
			}
			return false;
		}

		[HarmonyPrefix]
		private static bool Prefix(CrateInventoryUI __instance, ref Vector2 __result)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!IsJar(__instance.currentCrate))
			{
				return true;
			}
			__result = new Vector2(4f, 4f);
			return false;
		}
	}
	[HarmonyPatch(typeof(CrateInventory), "LateUpdate")]
	internal static class RackJarContentsPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(CrateInventory __instance)
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if (!RackJarDimensionsPatch.IsJar(__instance))
			{
				return true;
			}
			ShipItem component = ((Component)__instance).GetComponent<ShipItem>();
			SaveablePrefab component2 = ((Component)component).GetComponent<SaveablePrefab>();
			bool flag = (Object)(object)CrateInventoryUI.instance != (Object)null && CrateInventoryUI.instance.showingUI && (Object)(object)CrateInventoryUI.instance.currentCrate == (Object)(object)__instance;
			foreach (ShipItem containedItem in __instance.containedItems)
			{
				if (!((Object)(object)containedItem == (Object)null) && !((Object)(object)containedItem.itemRigidbodyC == (Object)null))
				{
					containedItem.currentActualBoat = component.currentActualBoat;
					containedItem.currentWalkCol = component.currentWalkCol;
					((Component)containedItem).GetComponent<SaveablePrefab>().SetParentObject(component2.GetParentObject());
					if (!flag)
					{
						((Component)containedItem).transform.SetPositionAndRotation(((Component)component).transform.position, ((Component)component).transform.rotation);
					}
					if ((Object)(object)containedItem.currentActualBoat != (Object)null && (Object)(object)containedItem.currentWalkCol != (Object)null)
					{
						containedItem.itemRigidbodyC.ForceRigidbodyToWalkCol();
					}
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(CrateInventoryUI), "RefreshButtons")]
	internal static class RackJarLayoutPatch
	{
		private static readonly FieldRef<CrateInventoryUI, Transform> Tracker = AccessTools.FieldRefAccess<CrateInventoryUI, Transform>("localPosTracker");

		private static CrateInventoryUI scaledUI;

		private static Vector3 originalScale;

		[HarmonyPostfix]
		private static void Postfix(CrateInventoryUI __instance)
		{
			//IL_003d: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			if (!RackJarDimensionsPatch.IsJar(__instance.currentCrate))
			{
				Restore(__instance);
				return;
			}
			if ((Object)(object)scaledUI != (Object)(object)__instance)
			{
				scaledUI = __instance;
				originalScale = ((Component)__instance).transform.localScale;
			}
			((Component)__instance).transform.localScale = originalScale * 0.5f;
			for (int i = 0; i < __instance.buttons.Length; i++)
			{
				((Component)__instance.buttons[i]).gameObject.SetActive(i < 16);
				if (i < 16)
				{
					((Component)__instance.buttons[i]).transform.localPosition = new Vector3(0.75f - (float)(i % 4) * 0.5f, -0.75f + (float)(i / 4) * 0.5f, 0f);
				}
			}
			if (__instance.showingUI)
			{
				Position(__instance);
			}
		}

		internal static void Restore(CrateInventoryUI ui)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)scaledUI == (Object)(object)ui)
			{
				((Component)ui).transform.localScale = originalScale;
				scaledUI = null;
			}
		}

		internal static void Position(CrateInventoryUI ui)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			//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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			if (RackJarDimensionsPatch.IsJar(ui.currentCrate) && !((Object)(object)Camera.main == (Object)null))
			{
				Transform transform = ((Component)Camera.main).transform;
				Bounds bounds = ((Component)ui.currentCrate).GetComponent<Collider>().bounds;
				Vector3 forward = transform.forward;
				float num = Vector3.Dot(((Bounds)(ref bounds)).extents, new Vector3(Mathf.Abs(forward.x), Mathf.Abs(forward.y), Mathf.Abs(forward.z)));
				float num2 = Mathf.Clamp(Vector3.Dot(((Bounds)(ref bounds)).center - transform.position, forward) - num - 0.12f, 0.3f, 0.65f);
				((Component)ui).transform.localScale = originalScale * (0.5f * num2);
				((Component)ui).transform.position = transform.position + forward * num2 + transform.up * (0.07f * num2);
				((Component)ui).transform.LookAt(transform.position);
				Tracker.Invoke(ui).SetPositionAndRotation(((Component)ui).transform.position, ((Component)ui).transform.rotation);
			}
		}
	}
	[HarmonyPatch(typeof(CrateInventoryUI), "ShowInventory")]
	internal static class RackJarPositionPatch
	{
		[HarmonyPostfix]
		private static void Postfix(CrateInventoryUI __instance)
		{
			if (__instance.showingUI)
			{
				RackJarLayoutPatch.Position(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(CrateInventoryUI), "HideInventory")]
	internal static class RackJarClosePatch
	{
		[HarmonyPostfix]
		private static void Postfix(CrateInventoryUI __instance)
		{
			RackJarLayoutPatch.Restore(__instance);
		}
	}
	[HarmonyPatch(typeof(CrateInventoryButton), "OnActivate")]
	internal static class RackJarInsertPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(GoPointer activatingPointer)
		{
			if ((Object)(object)CrateInventoryUI.instance == (Object)null || !RackJarDimensionsPatch.IsJar(CrateInventoryUI.instance.currentCrate))
			{
				return true;
			}
			PickupableItem heldItem = activatingPointer.GetHeldItem();
			ShipItem val = (ShipItem)(object)((heldItem is ShipItem) ? heldItem : null);
			if (!((Object)(object)val == (Object)null))
			{
				if (CrateInventoryUI.instance.currentCrate.containedItems.Count < 16)
				{
					if (!(val is ShipItemTobacco))
					{
						return (Object)(object)((Component)val).GetComponent<DriedTobaccoLeafState>() != (Object)null;
					}
					return true;
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(CrateInventory), "InsertItem")]
	internal static class RackJarItemScalePatch
	{
		[HarmonyPostfix]
		private static void Postfix(CrateInventory __instance, ShipItem item)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && RackJarDimensionsPatch.IsJar(__instance))
			{
				((Component)item).transform.localScale = Vector3.one * RackJarDisplay.ItemScale(item.inventoryScale);
			}
		}
	}
	[HarmonyPatch(typeof(ShipItem), "AddLODGroup")]
	internal static class CustomItemLodPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ShipItem __instance)
		{
			SaveablePrefab component = ((Component)__instance).GetComponent<SaveablePrefab>();
			if ((Object)(object)component == (Object)null || component.prefabIndex < 610 || component.prefabIndex > 631 || component.prefabIndex == 614)
			{
				return true;
			}
			List<Renderer> list = new List<Renderer>();
			MeshRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val in componentsInChildren)
			{
				if ((Object)(object)((Renderer)val).sharedMaterial != (Object)null && ((Object)((Renderer)val).sharedMaterial).name == "InteractionOutlineProxy")
				{
					((Renderer)val).enabled = false;
				}
				else
				{
					list.Add((Renderer)(object)val);
				}
			}
			LODGroup val2 = ((Component)__instance).GetComponent<LODGroup>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = ((Component)__instance).gameObject.AddComponent<LODGroup>();
			}
			LOD[] array = (LOD[])RefsDirectory.instance.LODtemplateItems.GetLODs().Clone();
			array[0].renderers = list.ToArray();
			val2.SetLODs(array);
			val2.RecalculateBounds();
			return false;
		}
	}
	[HarmonyPatch(typeof(ShipItem), "OnItemClick")]
	internal static class CustomItemClickPatch
	{
		private static readonly FieldRef<GoPointer, RaycastHit> ReadPointerHit = AccessTools.FieldRefAccess<GoPointer, RaycastHit>("hit");

		[HarmonyPrefix]
		private static bool Prefix(ShipItem __instance, PickupableItem heldItem, ref bool __result)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			DisplayStorageState component = ((Component)__instance).GetComponent<DisplayStorageState>();
			if ((Object)(object)component != (Object)null)
			{
				__result = false;
				ShipItem val = (((Object)(object)heldItem != (Object)null) ? ((Component)heldItem).GetComponent<ShipItem>() : null);
				if ((Object)(object)val != (Object)null && (Object)(object)((PickupableItem)val).held != (Object)null)
				{
					component.TryPlace(val, ((RaycastHit)(ref ReadPointerHit.Invoke(((PickupableItem)val).held))).point);
				}
				return false;
			}
			TobaccoPlantPotState component2 = ((Component)__instance).GetComponent<TobaccoPlantPotState>();
			if ((Object)(object)component2 != (Object)null)
			{
				__result = false;
				if ((Object)(object)heldItem != (Object)null)
				{
					component2.TryAcceptWater(((Component)heldItem).GetComponent<ShipItemBottle>());
				}
				return false;
			}
			if ((Object)(object)((Component)__instance).GetComponent<FreshTobaccoLeafState>() != (Object)null)
			{
				__result = false;
				return false;
			}
			AshtrayState component3 = ((Component)__instance).GetComponent<AshtrayState>();
			if ((Object)(object)component3 != (Object)null)
			{
				__result = false;
				CigarRuntimeState cigarRuntimeState = (((Object)(object)heldItem != (Object)null) ? ((Component)heldItem).GetComponent<CigarRuntimeState>() : null);
				ShipItemPipe val2 = (((Object)(object)heldItem != (Object)null) ? ((Component)heldItem).GetComponent<ShipItemPipe>() : null);
				GoPointer val3 = (((Object)(object)val2 != (Object)null) ? ((PickupableItem)val2).held : null);
				if ((Object)(object)val3 != (Object)null && (Object)(object)val3.GetHeldItem() == (Object)(object)heldItem)
				{
					RaycastHit val4 = ReadPointerHit.Invoke(val3);
					if ((Object)(object)((RaycastHit)(ref val4)).collider != (Object)null && (Object)(object)((Component)((RaycastHit)(ref val4)).collider).GetComponentInParent<AshtrayState>() == (Object)(object)component3)
					{
						if ((Object)(object)cigarRuntimeState != (Object)null)
						{
							component3.TrySeatAt(cigarRuntimeState, ((RaycastHit)(ref val4)).point);
						}
						else
						{
							component3.TrySeatPipe(val2);
						}
					}
				}
				return false;
			}
			CigarWrapperState component4 = ((Component)__instance).GetComponent<CigarWrapperState>();
			if ((Object)(object)component4 != (Object)null)
			{
				__result = false;
				if ((Object)(object)heldItem != (Object)null)
				{
					component4.TryInsert(((Component)heldItem).GetComponent<ShipItemTobacco>());
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ShipItem), "OnAltActivate")]
	internal static class CustomAltInteractionPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ShipItem __instance)
		{
			CigarBoxState component = ((Component)__instance).GetComponent<CigarBoxState>();
			if ((Object)(object)component != (Object)null && __instance.sold)
			{
				component.ToggleLid();
				return false;
			}
			TobaccoPlantPotState component2 = ((Component)__instance).GetComponent<TobaccoPlantPotState>();
			if ((Object)(object)component2 != (Object)null && __instance.sold)
			{
				component2.TryHarvest();
				return false;
			}
			CigarWrapperState component3 = ((Component)__instance).GetComponent<CigarWrapperState>();
			if ((Object)(object)component3 != (Object)null && __instance.sold)
			{
				component3.TryRoll();
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ShipItemBottle), "AllowOnItemClick")]
	internal static class PotWaterTargetPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ShipItemBottle __instance, GoPointerButton lookedAtButton, ref bool __result)
		{
			if (!__result && !((Object)(object)lookedAtButton == (Object)null) && ((ShipItem)__instance).sold)
			{
				TobaccoPlantPotState component = ((Component)lookedAtButton).GetComponent<TobaccoPlantPotState>();
				if ((Object)(object)component != (Object)null && component.StoredWater < 15f && (Object)(object)((Component)lookedAtButton).GetComponent<ShipItem>() != (Object)null && ((Component)lookedAtButton).GetComponent<ShipItem>().sold && ((ShipItem)__instance).amount == 1f && ((ShipItem)__instance).health > 0f)
				{
					__result = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(ShipItemTobacco), "AllowOnItemClick")]
	internal static class TobaccoTargetPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ShipItemTobacco __instance, GoPointerButton lookedAtButton, ref bool __result)
		{
			if ((Object)(object)lookedAtButton == (Object)null)
			{
				return;
			}
			if ((Object)(object)((Component)lookedAtButton).GetComponent<CigarRuntimeState>() != (Object)null)
			{
				__result = false;
				return;
			}
			if ((Object)(object)((Component)lookedAtButton).GetComponent<FreshTobaccoLeafState>() != (Object)null || (Object)(object)((Component)lookedAtButton).GetComponent<DriedTobaccoLeafState>() != (Object)null)
			{
				__result = false;
				return;
			}
			CigarWrapperState component = ((Component)lookedAtButton).GetComponent<CigarWrapperState>();
			if ((Object)(object)component != (Object)null)
			{
				__result = component.CanInsert(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(ShipItem), "AllowOnItemClick")]
	internal static class DryLeafCombineTargetPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ShipItem __instance, GoPointerButton lookedAtButton, ref bool __result)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			FreshTobaccoLeafState component = ((Component)__instance).GetComponent<FreshTobaccoLeafState>();
			FreshTobaccoLeafState freshTobaccoLeafState = (((Object)(object)lookedAtButton != (Object)null) ? ((Component)lookedAtButton).GetComponent<FreshTobaccoLeafState>() : null);
			if ((Object)(object)component != (Object)null && (Object)(object)freshTobaccoLeafState != (Object)null)
			{
				__result = freshTobaccoLeafState.CanCombineWith(component);
			}
			CigarRuntimeState component2 = ((Component)__instance).GetComponent<CigarRuntimeState>();
			AshtrayState ashtrayState = (((Object)(object)lookedAtButton != (Object)null) ? ((Component)lookedAtButton).GetComponent<AshtrayState>() : null);
			if ((Object)(object)component2 != (Object)null && (Object)(object)ashtrayState != (Object)null)
			{
				__result = ashtrayState.CanUse(component2);
			}
			else if ((Object)(object)ashtrayState != (Object)null && __instance is ShipItemPipe)
			{
				__result = ashtrayState.CanSeatPipe((ShipItemPipe)__instance);
			}
			StoragePointerTarget storagePointerTarget = (((Object)(object)lookedAtButton != (Object)null) ? ((Component)lookedAtButton).GetComponent<StoragePointerTarget>() : null);
			DisplayStorageState displayStorageState = (((Object)(object)storagePointerTarget != (Object)null) ? storagePointerTarget.Owner : (((Object)(object)lookedAtButton != (Object)null) ? ((Component)lookedAtButton).GetComponent<DisplayStorageState>() : null));
			if ((Object)(object)displayStorageState != (Object)null)
			{
				__result = displayStorageState.Available && displayStorageState.NearestEmpty(__instance, ((Object)(object)storagePointerTarget != (Object)null) ? storagePointerTarget.Point : ((Component)displayStorageState).transform.position) >= 0;
			}
		}
	}
	[HarmonyPatch(typeof(GoPointerButton), "OnAltActivate", new Type[] { typeof(GoPointer) })]
	internal static class HeldCigarAndLeafAltPatch
	{
		[HarmonyPostfix]
		private static void Postfix(GoPointerButton __instance, GoPointer activatingPointer)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)activatingPointer == (Object)null || (Object)(object)activatingPointer.GetHeldItem() != (Object)(object)__instance || GameState.inCursorMenu || GameState.sleeping || Object.op_Implicit((Object)(object)GameState.inBed) || BoatCamera.on)
			{
				return;
			}
			AshtrayState component = ((Component)__instance).GetComponent<AshtrayState>();
			if ((Object)(object)component != (Object)null)
			{
				component.BeginEmptying();
			}
			else
			{
				RaycastHit val = default(RaycastHit);
				if (!Physics.Raycast(((Component)activatingPointer).transform.position, ((Component)activatingPointer).transform.forward, ref val, 1.8f, -604165))
				{
					return;
				}
				ShipItem component2 = ((Component)((RaycastHit)(ref val)).collider).GetComponent<ShipItem>();
				if (!((Object)(object)component2 == (Object)null) && component2.sold && !((GoPointerButton)component2).unclickable)
				{
					FreshTobaccoLeafState component3 = ((Component)__instance).GetComponent<FreshTobaccoLeafState>();
					FreshTobaccoLeafState component4 = ((Component)component2).GetComponent<FreshTobaccoLeafState>();
					if ((Object)(object)component3 != (Object)null && (Object)(object)component4 != (Object)null)
					{
						component4.TryCombineWith(component3);
					}
					CigarRuntimeState component5 = ((Component)__instance).GetComponent<CigarRuntimeState>();
					AshtrayState component6 = ((Component)component2).GetComponent<AshtrayState>();
					if ((Object)(object)component5 != (Object)null && (Object)(object)component6 != (Object)null)
					{
						component6.TryClearAsh(component5);
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(ShipItemHammer), "CanNail")]
	internal static class AshtrayHammerPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ShipItem item, ref bool __result)
		{
			if (!__result && !((Object)(object)item == (Object)null) && item.sold)
			{
				__result = (Object)(object)((Component)item).GetComponent<AshtrayState>() != (Object)null || (Object)(object)((Component)item).GetComponent<DisplayStorageState>() != (Object)null;
			}
		}
	}
	[HarmonyPatch(typeof(ShipItem), "OnPickup")]
	internal static class CigarLeaveRestPatch
	{
		[HarmonyPrefix]
		private static void Prefix(ShipItem __instance)
		{
			SecuredDisplayItem component = ((Component)__instance).GetComponent<SecuredDisplayItem>();
			if ((Object)(object)component != (Object)null)
			{
				component.Detach();
			}
			CigarRuntimeState component2 = ((Component)__instance).GetComponent<CigarRuntimeState>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.LeaveRest();
			}
			RestingPipeState component3 = ((Component)__instance).GetComponent<RestingPipeState>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.LeaveRest();
			}
			AshtrayState component4 = ((Component)__instance).GetComponent<AshtrayState>();
			if ((Object)(object)component4 != (Object)null)
			{
				component4.PreparePickup();
			}
			PipeRackState component5 = ((Component)__instance).GetComponent<PipeRackState>();
			if ((Object)(object)component5 != (Object)null)
			{
				component5.PreparePickup();
			}
		}
	}
	[HarmonyPatch(typeof(GoPointer), "DoRaycast")]
	internal static class SeatedCigarPointerPatch
	{
		private static readonly RaycastHit[] NearbyHits = (RaycastHit[])(object)new RaycastHit[16];

		private static readonly FieldRef<GoPointer, Ray> ReadPointerRay = AccessTools.FieldRefAccess<GoPointer, Ray>("raycastRay");

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			FieldInfo hitField = AccessTools.Field(typeof(GoPointer), "hit");
			bool writesPointerHit = false;
			int replaced = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldflda && object.Equals(instruction.operand, hitField))
				{
					writesPointerHit = true;
				}
				yield return instruction;
				MethodInfo methodInfo = instruction.operand as MethodInfo;
				if (writesPointerHit && !(instruction.opcode != OpCodes.Call) && !(methodInfo == null) && !(methodInfo.ReturnType != typeof(bool)))
				{
					ParameterInfo[] parameters = methodInfo.GetParameters();
					if (parameters.Length == 4 && parameters[0].ParameterType == typeof(Ray) && parameters[1].ParameterType == typeof(RaycastHit).MakeByRefType() && parameters[2].ParameterType == typeof(float) && parameters[3].ParameterType == typeof(int))
					{
						yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						yield return new CodeInstruction(OpCodes.Ldflda, (object)hitField);
						yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SeatedCigarPointerPatch), "PreferCigar", (Type[])null, (Type[])null));
						replaced++;
						writesPointerHit = false;
					}
				}
			}
			if (replaced != 1)
			{
				throw new InvalidOperationException("Cannot locate native pointer raycast for seated cigar targeting.");
			}
		}

		private static bool PreferCigar(bool didHit, GoPointer pointer, ref RaycastHit hit)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			if (!didHit)
			{
				return false;
			}
			if ((Object)(object)pointer.GetHeldItem() != (Object)null)
			{
				return StoragePointerPatch.SkipHeldCollider(pointer, ref hit);
			}
			AshtrayState component = ((Component)((RaycastHit)(ref hit)).collider).GetComponent<AshtrayState>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			Ray val = (pointer.debugEditorPointer ? Camera.main.ScreenPointToRay(Input.mousePosition) : ReadPointerRay.Invoke(pointer));
			Collider val2 = TargetCollider(((Object)(object)component.Occupant != (Object)null) ? component.Occupant.Pipe : null);
			Collider val3 = TargetCollider(((Object)(object)component.PipeOccupant != (Object)null) ? component.PipeOccupant.Pipe : null);
			if ((Object)(object)val2 == (Object)null && (Object)(object)val3 == (Object)null)
			{
				return true;
			}
			bool flag = false;
			float num = 1.8f;
			RaycastHit val4 = default(RaycastHit);
			if ((Object)(object)val2 != (Object)null && val2.Raycast(val, ref val4, num))
			{
				hit = val4;
				num = ((RaycastHit)(ref val4)).distance;
				flag = true;
			}
			if ((Object)(object)val3 != (Object)null && val3.Raycast(val, ref val4, num))
			{
				hit = val4;
				flag = true;
			}
			if (flag)
			{
				return true;
			}
			int num2 = Physics.SphereCastNonAlloc(val, 0.012f, NearbyHits, 1.8f, -604165);
			for (int i = 0; i < num2; i++)
			{
				if (((Object)(object)((RaycastHit)(ref NearbyHits[i])).collider == (Object)(object)val2 || (Object)(object)((RaycastHit)(ref NearbyHits[i])).collider == (Object)(object)val3) && ((RaycastHit)(ref NearbyHits[i])).distance < num)
				{
					hit = NearbyHits[i];
					num = ((RaycastHit)(ref hit)).distance;
				}
			}
			return true;
		}

		private static Collider TargetCollider(ShipItemPipe item)
		{
			if (!((Object)(object)item != (Object)null) || ((GoPointerButton)item).unclickable || ((ShipItem)item).nailed)
			{
				return null;
			}
			return ((Component)item).GetComponent<Collider>();
		}
	}
	[HarmonyPatch(typeof(ShipItem), "ExtraFixedUpdate")]
	internal static class RestingCigarBoatPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ShipItem __instance)
		{
			CigarRuntimeState component = ((Component)__instance).GetComponent<CigarRuntimeState>();
			RestingPipeState component2 = ((Component)__instance).GetComponent<RestingPipeState>();
			SecuredDisplayItem component3 = ((Component)__instance).GetComponent<SecuredDisplayItem>();
			if (((Object)(object)component3 == (Object)null || (Object)(object)component3.Owner == (Object)null) && ((Object)(object)component == (Object)null || !component.IsResting))
			{
				if (!((Object)(object)component2 == (Object)null))
				{
					return !component2.IsResting;
				}
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ShipItem), "OnEnterInventory")]
	internal static class AshtrayInventoryPatch
	{
		[HarmonyPrefix]
		private static void Prefix(ShipItem __instance)
		{
			SecuredDisplayItem component = ((Component)__instance).GetComponent<SecuredDisplayItem>();
			if ((Object)(object)component != (Object)null)
			{
				component.Detach();
			}
			PipeRackState component2 = ((Component)__instance).GetComponent<PipeRackState>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.PreparePickup();
			}
			AshtrayState component3 = ((Component)__instance).GetComponent<AshtrayState>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.ReleaseOccupant();
			}
			RestingPipeState component4 = ((Component)__instance).GetComponent<RestingPipeState>();
			if ((Object)(object)component4 != (Object)null)
			{
				component4.LeaveRest();
			}
		}
	}
	[HarmonyPatch(typeof(GoPointer), "DoRaycast")]
	internal static class StoragePointerPatch
	{
		private static readonly RaycastHit[] SelfHits = (RaycastHit[])(object)new RaycastHit[64];

		private static readonly FieldRef<GoPointer, RaycastHit> Hit = AccessTools.FieldRefAccess<GoPointer, RaycastHit>("hit");

		private static readonly FieldRef<GoPointer, Ray> Ray = AccessTools.FieldRefAccess<GoPointer, Ray>("raycastRay");

		private static readonly FieldRef<GoPointer, GoPointerButton> Pointed = AccessTools.FieldRefAccess<GoPointer, GoPointerButton>("pointedAtButton");

		private static readonly FieldRef<GoPointer, float> Distance = AccessTools.FieldRefAccess<GoPointer, float>("currentLookDistance");

		internal static bool SkipHeldCollider(GoPointer pointer, ref RaycastHit hit)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			PickupableItem heldItem = pointer.GetHeldItem();
			ShipItem val = (ShipItem)(object)((heldItem is ShipItem) ? heldItem : null);
			if ((Object)(object)val == (Object)null || (!(val is ShipItemPipe) && (Object)(object)((Component)val).GetComponent<DisplayStorageState>() == (Object)null))
			{
				return true;
			}
			if (!IsHeld(((RaycastHit)(ref hit)).collider, val))
			{
				return true;
			}
			int num = Physics.RaycastNonAlloc((pointer.debugEditorPointer && (Object)(object)Camera.main != (Object)null) ? Camera.main.ScreenPointToRay(Input.mousePosition) : Ray.Invoke(pointer), SelfHits, 1.8f, -604165);
			float num2 = float.MaxValue;
			bool flag = false;
			for (int i = 0; i < num; i++)
			{
				if (!IsHeld(((RaycastHit)(ref SelfHits[i])).collider, val) && ((RaycastHit)(ref SelfHits[i])).distance < num2)
				{
					hit = SelfHits[i];
					num2 = ((RaycastHit)(ref hit)).distance;
					flag = true;
				}
			}
			if (!flag)
			{
				hit = default(RaycastHit);
			}
			return flag;
		}

		private static bool IsHeld(Collider collider, ShipItem held)
		{
			if ((Object)(object)collider == (Object)null)
			{
				return false;
			}
			if (!((Component)collider).transform.IsChildOf(((Component)held).transform))
			{
				if ((Object)(object)held.itemRigidbodyC != (Object)null)
				{
					return ((Component)collider).transform.IsChildOf(((Component)held.itemRigidbodyC).transform);
				}
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		private static void Postfix(GoPointer __instance)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			if (GameState.inCursorMenu || GameState.sleeping || Object.op_Implicit((Object)(object)GameState.inBed) || BoatCamera.on)
			{
				return;
			}
			RaycastHit val = Hit.Invoke(__instance);
			if ((Object)(object)((RaycastHit)(ref val)).collider == (Object)null)
			{
				return;
			}
			SecuredDisplayItem componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<SecuredDisplayItem>();
			DisplayStorageState displayStorageState = (((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.Owner != (Object)null) ? componentInParent.Owner : ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<DisplayStorageState>());
			if ((Object)(object)displayStorageState == (Object)null || (Object)(object)((PickupableItem)displayStorageState.Item).held != (Object)null || ((GoPointerButton)displayStorageState.Item).unclickable)
			{
				return;
			}
			Ray val2 = ((__instance.debugEditorPointer && (Object)(object)Camera.main != (Object)null) ? Camera.main.ScreenPointToRay(Input.mousePosition) : Ray.Invoke(__instance));
			ShipItem val3 = (((Object)(object)__instance.GetHeldItem() != (Object)null) ? ((Component)__instance.GetHeldItem()).GetComponent<ShipItem>() : null);
			if (!displayStorageState.Item.sold || val3 is ShipItemHammer)
			{
				if ((Object)(object)val3 == (Object)null || ((GoPointerButton)val