Decompiled source of Home Brew v1.0.3

Mods/WoodStudios.HomeBrew.dll

Decompiled 10 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using DP_HomeBrew.FybCommon;
using DP_HomeBrew.WoodKit;
using DP_HomeBrew.WoodLabs;
using DrugPack;
using HarmonyLib;
using HoldTheFort;
using HomeBrewMod;
using Il2CppFishNet;
using Il2CppFishNet.Connection;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.AvatarFramework;
using Il2CppScheduleOne.AvatarFramework.Animation;
using Il2CppScheduleOne.Building;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.Effects.MixMaps;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.EntityFramework;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.Instancing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Levelling;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.Messaging;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Relation;
using Il2CppScheduleOne.Networking;
using Il2CppScheduleOne.ObjectScripts;
using Il2CppScheduleOne.Packaging;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Product;
using Il2CppScheduleOne.Product.Packaging;
using Il2CppScheduleOne.Property;
using Il2CppScheduleOne.Quests;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.Temperature;
using Il2CppScheduleOne.Tiles;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.UI.Phone;
using Il2CppScheduleOne.UI.Phone.ProductManagerApp;
using Il2CppScheduleOne.UI.Relations;
using Il2CppScheduleOne.UI.Shop;
using Il2CppScheduleOne.Weather;
using Il2CppSteamworks;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using S1API.DeadDrops;
using S1API.Economy;
using S1API.Entities;
using S1API.Entities.Customer;
using S1API.Entities.Relation;
using S1API.Entities.Schedule;
using S1API.Entities.Supplier;
using S1API.GameTime;
using S1API.Items;
using S1API.Items.Storable;
using S1API.Lifecycle;
using S1API.Map;
using S1API.Messaging;
using S1API.Money;
using S1API.Products;
using S1API.Properties;
using S1API.Properties.Interfaces;
using S1API.Rendering;
using S1API.Shops;
using Schedule2;
using Schedule2.Game;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(BrewCore), "Home Brew", "1.0.3", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonColor(255, 217, 140, 38)]
[assembly: AssemblyTitle("Home Brew")]
[assembly: MelonOptionalDependencies(new string[] { "HoldTheFort" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 Schedule2
{
	internal static class FrameShare
	{
		private static int _frame = -1;

		private static Vector2 _mouse;

		private static bool _down;

		private static bool _legacyBroken;

		public static void Mouse(out Vector2 guiMouse, out bool leftDown)
		{
			//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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			int frameCount = Time.frameCount;
			if (frameCount != _frame)
			{
				_frame = frameCount;
				Vector2 val = default(Vector2);
				bool flag = false;
				bool down = false;
				if (!_legacyBroken)
				{
					try
					{
						val = Vector2.op_Implicit(Input.mousePosition);
						down = Input.GetMouseButtonDown(0);
						flag = true;
					}
					catch
					{
						_legacyBroken = true;
					}
				}
				if (!flag)
				{
					try
					{
						Mouse current = Mouse.current;
						if (current != null)
						{
							val = ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue();
							down = current.leftButton.wasPressedThisFrame;
						}
					}
					catch
					{
					}
				}
				_mouse = new Vector2(val.x, (float)Screen.height - val.y);
				_down = down;
			}
			guiMouse = _mouse;
			leftDown = _down;
		}
	}
	internal static class PlayerSnap
	{
		private static readonly List<Player> _l = new List<Player>();

		private static int _f = -1;

		public static List<Player> List()
		{
			if (_f == Time.frameCount)
			{
				return _l;
			}
			_f = Time.frameCount;
			_l.Clear();
			try
			{
				List<Player> playerList = Player.PlayerList;
				int num = playerList?.Count ?? 0;
				for (int i = 0; i < num; i++)
				{
					Player val = playerList[i];
					if ((Object)(object)val != (Object)null)
					{
						_l.Add(val);
					}
				}
			}
			catch
			{
			}
			return _l;
		}
	}
	internal static class CamSnap
	{
		private static int _f = -1;

		private static bool _ok;

		private static Vector3 _p;

		public static bool Pos(out Vector3 p)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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)
			if (_f != Time.frameCount)
			{
				_f = Time.frameCount;
				_ok = false;
				try
				{
					PlayerCamera instance = PlayerSingleton<PlayerCamera>.Instance;
					Transform val = (((Object)(object)instance != (Object)null && (Object)(object)instance.Camera != (Object)null) ? ((Component)instance.Camera).transform : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform : null));
					if ((Object)(object)val != (Object)null)
					{
						_p = val.position;
						_ok = true;
					}
				}
				catch
				{
				}
			}
			p = _p;
			return _ok;
		}
	}
	internal static class LocalsCache
	{
		private static readonly List<NPC> _list = new List<NPC>();

		private static readonly HashSet<IntPtr> _set = new HashSet<IntPtr>();

		private static int _count = -1;

		private static float _at = -1000f;

		internal static void Fill(List<NPC> into, HashSet<IntPtr> set)
		{
			Refresh();
			foreach (NPC item in _list)
			{
				into.Add(item);
			}
			foreach (IntPtr item2 in _set)
			{
				set.Add(item2);
			}
		}

		private static void Refresh()
		{
			List<NPC> nPCRegistry = NPCManager.NPCRegistry;
			int num = nPCRegistry?.Count ?? 0;
			bool flag = _list.Count > 0 && (Object)(object)_list[0] == (Object)null;
			if (num == _count && !flag && Time.unscaledTime - _at < 300f)
			{
				return;
			}
			long t = Perf.Start();
			_count = num;
			_at = Time.unscaledTime;
			_list.Clear();
			_set.Clear();
			HashSet<IntPtr> hashSet = new HashSet<IntPtr>();
			Assembly assembly = typeof(NPC).Assembly;
			try
			{
				foreach (NPC item in NPC.All)
				{
					try
					{
						if (item != null && ((object)item).GetType().Assembly != assembly && (Object)(object)item.gameObject != (Object)null)
						{
							hashSet.Add(((Il2CppObjectBase)item.gameObject).Pointer);
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			int num2 = 0;
			while (nPCRegistry != null && num2 < nPCRegistry.Count)
			{
				NPC val = nPCRegistry[num2];
				try
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)null) && !hashSet.Contains(((Il2CppObjectBase)((Component)val).gameObject).Pointer) && val.RelationData != null && !((Object)(object)((Component)val).GetComponent<Customer>() == (Object)null))
					{
						_list.Add(val);
						_set.Add(((Il2CppObjectBase)val).Pointer);
					}
				}
				catch
				{
				}
				num2++;
			}
			Perf.Stop("Locals.Find", t);
		}
	}
	internal static class NpcCompat
	{
		private static bool _no;

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static CapsuleCollider Field(NPCMovement m)
		{
			return m._capsuleCollider;
		}

		internal static CapsuleCollider Cap(NPCMovement m)
		{
			if ((Object)(object)m == (Object)null)
			{
				return null;
			}
			if (!_no)
			{
				try
				{
					return Field(m);
				}
				catch (Exception)
				{
					_no = true;
				}
			}
			return ((Component)m).GetComponent<CapsuleCollider>();
		}
	}
	internal static class Npcs
	{
		internal sealed class Info
		{
			public IntPtr Key;

			public NPC Npc;

			private NPCMovement _move;

			private NavMeshAgent _agent;

			private Transform _agentTr;

			private bool _haveMove;

			private string _id;

			private bool _haveId;

			public NPCMovement Move
			{
				get
				{
					if (!_haveMove)
					{
						_haveMove = true;
						try
						{
							_move = Npc.Movement;
							_agent = (((Object)(object)_move != (Object)null) ? _move._agent : null);
							_agentTr = (((Object)(object)_agent != (Object)null) ? ((Component)_agent).transform : null);
						}
						catch
						{
						}
					}
					return _move;
				}
			}

			public NavMeshAgent Agent
			{
				get
				{
					_ = Move;
					return _agent;
				}
			}

			public Transform AgentTr
			{
				get
				{
					_ = Move;
					return _agentTr;
				}
			}

			public string Id
			{
				get
				{
					if (!_haveId)
					{
						_haveId = true;
						try
						{
							_id = Npc.ID ?? "";
						}
						catch
						{
							_id = "";
						}
					}
					return _id;
				}
			}
		}

		private static readonly List<Info> _list = new List<Info>();

		private static readonly Dictionary<IntPtr, Info> _byKey = new Dictionary<IntPtr, Info>();

		private static readonly HashSet<IntPtr> _seen = new HashSet<IntPtr>();

		private static float _at = -10f;

		private static int _count = -1;

		public static List<Info> All
		{
			get
			{
				float unscaledTime = Time.unscaledTime;
				if (unscaledTime - _at < 1f && unscaledTime >= _at)
				{
					return _list;
				}
				_at = unscaledTime;
				try
				{
					List<NPC> nPCRegistry = NPCManager.NPCRegistry;
					int num = nPCRegistry?.Count ?? 0;
					_list.Clear();
					_seen.Clear();
					for (int i = 0; i < num; i++)
					{
						NPC val = nPCRegistry[i];
						if (!((Object)(object)val == (Object)null))
						{
							IntPtr pointer = ((Il2CppObjectBase)val).Pointer;
							if (!_byKey.TryGetValue(pointer, out var value) || (Object)(object)value.Npc == (Object)null)
							{
								value = new Info
								{
									Key = pointer,
									Npc = val
								};
								_byKey[pointer] = value;
							}
							_list.Add(value);
							_seen.Add(pointer);
						}
					}
					if (_byKey.Count > _list.Count + 32)
					{
						List<IntPtr> list = new List<IntPtr>();
						foreach (IntPtr key in _byKey.Keys)
						{
							if (!_seen.Contains(key))
							{
								list.Add(key);
							}
						}
						foreach (IntPtr item in list)
						{
							_byKey.Remove(item);
						}
					}
					_count = num;
				}
				catch
				{
				}
				return _list;
			}
		}

		public static void Reset()
		{
			_list.Clear();
			_byKey.Clear();
			_at = -10f;
		}
	}
	internal static class Perf
	{
		internal static bool On;

		public static long Start()
		{
			return 0L;
		}

		public static void Stop(string key, long t0)
		{
		}
	}
	internal static class Prim
	{
		private static readonly Dictionary<PrimitiveType, Mesh> Meshes = new Dictionary<PrimitiveType, Mesh>();

		private static Mesh MeshOf(PrimitiveType t)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (Meshes.TryGetValue(t, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			GameObject obj = GameObject.CreatePrimitive(t);
			value = obj.GetComponent<MeshFilter>().sharedMesh;
			Object.DestroyImmediate((Object)(object)obj);
			Meshes[t] = value;
			return value;
		}

		internal unsafe static GameObject Part(Transform parent, PrimitiveType type, Vector3 pos, Vector3 scale, Material m, Vector3? euler, bool collider, string name)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			GameObject val;
			if (collider)
			{
				val = GameObject.CreatePrimitive(type);
			}
			else
			{
				val = new GameObject(((object)(*(PrimitiveType*)(&type))/*cast due to .constrained prefix*/).ToString());
				val.AddComponent<MeshFilter>().sharedMesh = MeshOf(type);
				val.AddComponent<MeshRenderer>();
			}
			Transform transform = val.transform;
			transform.SetParent(parent, false);
			transform.localPosition = pos;
			transform.localRotation = Quaternion.Euler((Vector3)(((??)euler) ?? Vector3.zero));
			transform.localScale = scale;
			((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = m;
			if (name != null)
			{
				((Object)val).name = name;
			}
			return val;
		}
	}
	internal static class Res
	{
		private static readonly Assembly Asm = typeof(Res).Assembly;

		public static Stream Open(string name)
		{
			Stream manifestResourceStream = Asm.GetManifestResourceStream(name);
			if (manifestResourceStream == null)
			{
				return null;
			}
			int num = manifestResourceStream.ReadByte();
			int num2 = manifestResourceStream.ReadByte();
			manifestResourceStream.Position = 0L;
			if (num != 31 || num2 != 139)
			{
				return manifestResourceStream;
			}
			MemoryStream memoryStream = new MemoryStream();
			using (GZipStream gZipStream = new GZipStream(manifestResourceStream, CompressionMode.Decompress))
			{
				gZipStream.CopyTo(memoryStream);
			}
			memoryStream.Position = 0L;
			return memoryStream;
		}
	}
	internal static class S2Asm
	{
		internal static bool Is(Assembly a)
		{
			if (a == null)
			{
				return false;
			}
			try
			{
				string name = a.GetName().Name;
				return name == "HoldTheFort" || name == "WoodStudios.Schedule2";
			}
			catch
			{
				return false;
			}
		}
	}
	internal static class S2Core
	{
		internal static readonly HashSet<string> DevSkip = new HashSet<string>();
	}
	internal static class S2Ui
	{
		private static Font _font;

		internal static (GameObject, Button, Text) ButtonWithLabel(string name, string label, Transform parent, Color bgColor, float Width, float Height)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<RectTransform>().sizeDelta = new Vector2(Width, Height);
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = bgColor;
			Button val3 = val.AddComponent<Button>();
			((Selectable)val3).targetGraphic = (Graphic)(object)val2;
			GameObject val4 = new GameObject("Label");
			val4.transform.SetParent(val.transform, false);
			RectTransform obj = val4.AddComponent<RectTransform>();
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
			Text val5 = val4.AddComponent<Text>();
			val5.text = label;
			val5.alignment = (TextAnchor)4;
			val5.fontSize = 16;
			val5.fontStyle = (FontStyle)1;
			((Graphic)val5).color = Color.white;
			if ((Object)(object)_font == (Object)null)
			{
				_font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			}
			val5.font = _font;
			return (val, val3, val5);
		}
	}
}
namespace Schedule2.Game
{
	internal static class CrewWar
	{
		public static bool Active => false;
	}
	internal static class Gate
	{
		public static bool BenziesAround => true;

		public static bool LabOpen(string t)
		{
			return true;
		}
	}
	internal static class GateTw
	{
	}
	internal static class Peace
	{
		public static bool Quiet => false;
	}
	public sealed class S2State
	{
		public static readonly S2State Current = new S2State();

		public bool Flag(string k)
		{
			return true;
		}

		public void SetFlag(string k)
		{
		}
	}
	internal static class Sfx
	{
		public static AudioClip Create(string name, int lengthSamples, int channels, int frequency, bool stream)
		{
			return AudioClip.Create(name, lengthSamples, channels, frequency, stream);
		}

		public static bool SetData(AudioClip clip, Il2CppStructArray<float> data, int offset)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			if ((Object)clip != (Object)null)
			{
				return clip.SetData(data, offset);
			}
			return false;
		}
	}
}
namespace HomeBrewMod
{
	public sealed class BrewCore : LabModule
	{
		internal static readonly (string Id, int Rank, string RankName)[] Locks = new(string, int, string)[6]
		{
			("br_bucket", 1, "Hoodlum"),
			("br_carboy", 2, "Peddler"),
			("br_freezer", 2, "Peddler"),
			("br_potstill", 3, "Hustler"),
			("br_barrel", 3, "Hustler"),
			("br_reflux", 4, "Bagman")
		};

		private static Color Amber => new Color(0.85f, 0.55f, 0.15f);

		private static ProductSpec P(string key, string name, float price, float addict, string model, Color tint, string desc, params PropertyBase[] props)
		{
			//IL_002a: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			return new ProductSpec
			{
				Key = key,
				Name = name,
				Price = price,
				Addictiveness = addict,
				Model = model,
				Tint = tint,
				Description = desc,
				Properties = props,
				IconEuler = new Vector3(12f, 30f, 0f)
			};
		}

		private static ItemDef I(string id, string name, float price, string model, Color color, string desc, Color? tint = null, int stack = 20)
		{
			//IL_0022: 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)
			return new ItemDef
			{
				Id = id,
				Name = name,
				Price = price,
				Model = model,
				Color = color,
				Tint = tint,
				Stack = stack,
				Description = desc
			};
		}

		private static InputSpec In(string item, int qty = 1)
		{
			return new InputSpec
			{
				Item = item,
				Qty = qty
			};
		}

		private static InputSpec InP(string product, int qty = 1)
		{
			return new InputSpec
			{
				Product = product,
				Qty = qty
			};
		}

		private static RecipeSpec R(string name, string note, float minutes, string outProduct, int qty, int quality, params InputSpec[] inputs)
		{
			return new RecipeSpec
			{
				Name = name,
				Note = note,
				Minutes = minutes,
				OutProduct = outProduct,
				OutQty = qty,
				Quality = quality,
				Inputs = inputs
			};
		}

		private static RecipeSpec RI(string name, string note, float minutes, string outItem, int qty, params InputSpec[] inputs)
		{
			return new RecipeSpec
			{
				Name = name,
				Note = note,
				Minutes = minutes,
				OutItem = outItem,
				OutQty = qty,
				Inputs = inputs
			};
		}

		internal static LabDef Build()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0078: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: 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_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: 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_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: 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_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_059c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0623: Unknown result type (might be due to invalid IL or missing references)
			//IL_0664: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06be: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_070e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0745: Unknown result type (might be due to invalid IL or missing references)
			//IL_0787: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0829: Unknown result type (might be due to invalid IL or missing references)
			//IL_086b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0884: Unknown result type (might be due to invalid IL or missing references)
			//IL_08bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_090d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0926: Unknown result type (might be due to invalid IL or missing references)
			//IL_099a: Unknown result type (might be due to invalid IL or missing references)
			//IL_099f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b8a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e5b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e60: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ffe: Unknown result type (might be due to invalid IL or missing references)
			//IL_1003: Unknown result type (might be due to invalid IL or missing references)
			//IL_10d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_10d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_1277: Unknown result type (might be due to invalid IL or missing references)
			//IL_127c: Unknown result type (might be due to invalid IL or missing references)
			//IL_141f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1424: Unknown result type (might be due to invalid IL or missing references)
			//IL_1513: Unknown result type (might be due to invalid IL or missing references)
			//IL_1518: Unknown result type (might be due to invalid IL or missing references)
			//IL_158a: Unknown result type (might be due to invalid IL or missing references)
			//IL_158f: Unknown result type (might be due to invalid IL or missing references)
			//IL_15af: Unknown result type (might be due to invalid IL or missing references)
			//IL_15b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_15df: Unknown result type (might be due to invalid IL or missing references)
			//IL_15e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_1604: Unknown result type (might be due to invalid IL or missing references)
			//IL_1609: Unknown result type (might be due to invalid IL or missing references)
			//IL_1629: Unknown result type (might be due to invalid IL or missing references)
			//IL_162e: Unknown result type (might be due to invalid IL or missing references)
			//IL_164e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1653: Unknown result type (might be due to invalid IL or missing references)
			//IL_1673: Unknown result type (might be due to invalid IL or missing references)
			//IL_1678: Unknown result type (might be due to invalid IL or missing references)
			LabDef labDef = new LabDef
			{
				Title = "Home Brew",
				Folder = "HomeBrew",
				Prefix = "br_",
				Ns = "woodstudios.homebrew",
				Short = "brew",
				KindName = "Home Brew",
				Accent = Amber,
				Compat = (DrugType)0,
				InputType = (DrugType)0,
				InputName = "brew",
				Template = "ogkush",
				Region = (Region)0,
				DevKey = (KeyCode)13,
				DevRow = 9
			};
			Color tint = default(Color);
			((Color)(ref tint))..ctor(0.9f, 0.82f, 0.45f);
			Color tint2 = default(Color);
			((Color)(ref tint2))..ctor(0.86f, 0.55f, 0.12f);
			Color tint3 = default(Color);
			((Color)(ref tint3))..ctor(0.45f, 0.25f, 0.1f);
			Color tint4 = default(Color);
			((Color)(ref tint4))..ctor(0.9f, 0.68f, 0.25f);
			Color tint5 = default(Color);
			((Color)(ref tint5))..ctor(0.55f, 0.08f, 0.25f);
			Color tint6 = default(Color);
			((Color)(ref tint6))..ctor(0.38f, 0.04f, 0.12f);
			Color tint7 = default(Color);
			((Color)(ref tint7))..ctor(0.78f, 0.42f, 0.1f);
			Color tint8 = default(Color);
			((Color)(ref tint8))..ctor(0.9f, 0.92f, 0.88f);
			Color tint9 = default(Color);
			((Color)(ref tint9))..ctor(0.82f, 0.9f, 0.86f);
			Color tint10 = default(Color);
			((Color)(ref tint10))..ctor(0.62f, 0.3f, 0.07f);
			Color tint11 = default(Color);
			((Color)(ref tint11))..ctor(0.92f, 0.92f, 0.86f);
			labDef.Products = new ProductSpec[12]
			{
				P("kilju", "Kilju", 14f, 0.15f, "BR_Jug.glb", tint, "Finnish sugar wine: sugar, water and yeast, nothing else. Cloudy, strong and cheap. Made in a jug fermenter.", Property.Disorienting, Property.Euphoric),
				P("kvass", "Kvass", 12f, 0.1f, "BR_SwingTop.glb", tint3, "A dark, lightly fizzy brew made from soaked rye bread, sugar and yeast. Tastes like bread you can drink.", Property.Refreshing, Property.Calming),
				P("hard-cider", "Hard Cider", 18f, 0.15f, "BR_SwingTop.glb", tint4, "Apple juice fermented dry and bottled with a swing top. Crisp, golden and easy to sell.", Property.Refreshing, Property.Euphoric),
				P("mead", "Mead", 32f, 0.2f, "BR_SwingTop.glb", tint2, "Honey wine, the oldest drink there is. Sweet, smooth and stronger than it tastes.", Property.Euphoric, Property.Calming),
				P("berry-wine", "Berry Wine", 30f, 0.2f, "BR_WineBottle.glb", tint5, "Deep red wine from mixed berries, corked and foiled.", Property.Calming, Property.Euphoric),
				P("red-wine", "Red Wine", 45f, 0.2f, "BR_WineBottle.glb", tint6, "A proper grape red, fermented slow in a glass carboy. The good stuff.", Property.Calming, Property.ThoughtProvoking),
				P("applejack", "Applejack", 58f, 0.3f, "BR_Mason.glb", tint7, "Hard cider frozen until the water turns to ice and the strong stuff is left behind. Old American freeze-jacked apple brandy.", Property.Euphoric, Property.Sedating, Property.Energizing),
				P("moonshine", "Moonshine", 55f, 0.35f, "BR_Mason.glb", tint11, "Clear corn liquor from a copper pot still, in a mason jar. Burns all the way down.", Property.Disorienting, Property.Euphoric, Property.Sedating),
				P("vodka", "Vodka", 62f, 0.3f, "BR_Liquor.glb", tint8, "Clean, neutral vodka run through the reflux column and cut to bottle strength.", Property.Euphoric, Property.Focused),
				P("gin", "Gin", 72f, 0.3f, "BR_Liquor.glb", tint9, "Vodka vapour run through a basket of juniper and botanicals. Piney, bright and dangerous.", Property.Refreshing, Property.Euphoric, Property.ThoughtProvoking),
				P("whiskey", "Barrel-Aged Whiskey", 100f, 0.35f, "BR_Whiskey.glb", tint10, "New-make spirit aged in an oak barrel until it turns amber. Smooth, smoky and worth the wait.", Property.Calming, Property.Euphoric, Property.Sedating),
				P("everclear", "Everclear", 120f, 0.45f, "BR_Liquor.glb", new Color(0.95f, 0.95f, 0.97f), "Grain spirit run twice through the column until it is near pure alcohol. Do not drink it straight.", Property.Disorienting, Property.Energizing, Property.Euphoric, Property.Toxic)
			};
			labDef.Products[0].Base = true;
			labDef.Items = new ItemDef[15]
			{
				I("br_sugar", "Sugar", 5f, "BR_Sugar.glb", new Color(0.9f, 0.9f, 0.95f), "A paper sack of white sugar. The yeast eats it and makes alcohol."),
				I("br_yeast", "Bread Yeast", 3f, "BR_Yeast.glb", new Color(0.85f, 0.65f, 0.15f), "A packet of baker's yeast. It works, but gives a rougher brew. Fine for Kilju, Kvass and jug ferments.", (Color?)new Color(0.85f, 0.65f, 0.15f), 20),
				I("br_wineyeast", "Wine Yeast", 7f, "BR_Yeast.glb", new Color(0.6f, 0.1f, 0.2f), "A packet of proper wine yeast. Cleaner, stronger ferments: needed for wine and mead in the bucket and carboy.", (Color?)new Color(0.6f, 0.1f, 0.2f), 20),
				I("br_turbo", "Turbo Yeast", 10f, "BR_Yeast.glb", new Color(0.12f, 0.12f, 0.14f), "Distiller's turbo yeast with nutrients. Ferments a sugar wash or grain mash fast and strong, ready for the still.", (Color?)new Color(0.12f, 0.12f, 0.14f), 20),
				I("br_honey", "Honey", 14f, "BR_Honey.glb", new Color(0.86f, 0.55f, 0.12f), "A jar of wildflower honey, for mead."),
				I("br_rye", "Rye Bread", 5f, "BR_RyeBread.glb", new Color(0.32f, 0.18f, 0.08f), "A dark rye loaf. Soak it in hot water for Kvass."),
				I("br_juice", "Apple Juice", 6f, "BR_Juice.glb", new Color(0.85f, 0.6f, 0.15f), "A bottle of pressed apple juice, for Hard Cider.", (Color?)new Color(0.85f, 0.6f, 0.15f), 20),
				I("br_berries", "Mixed Berries", 8f, "BR_Berries.glb", new Color(0.35f, 0.06f, 0.35f), "A punnet of blackberries, raspberries and blueberries, for Berry Wine.", (Color?)new Color(0.3f, 0.05f, 0.35f), 20),
				I("br_grapes", "Wine Grapes", 12f, "BR_Grapes.glb", new Color(0.3f, 0.07f, 0.25f), "A bunch of dark wine grapes, for Red Wine."),
				I("br_corn", "Cracked Corn", 6f, "BR_Sack.glb", new Color(0.9f, 0.75f, 0.2f), "A sack of cracked corn for a grain mash. Moonshine and whiskey start here.", (Color?)new Color(0.9f, 0.72f, 0.2f), 20),
				I("br_barley", "Malted Barley", 9f, "BR_Sack.glb", new Color(0.65f, 0.45f, 0.2f), "A sack of malted barley. Its enzymes turn the corn's starch into sugar in a grain mash.", (Color?)new Color(0.62f, 0.4f, 0.18f), 20),
				I("br_botanicals", "Juniper Botanicals", 16f, "BR_Botanicals.glb", new Color(0.15f, 0.18f, 0.35f), "Juniper berries, coriander and citrus peel for the gin basket."),
				I("br_wash", "Sugar Wash", 8f, "BR_Wash.glb", new Color(0.85f, 0.78f, 0.5f), "A jug of fermented sugar wash, ready for a still. Made in a Fermenting Bucket or Glass Carboy.", (Color?)new Color(0.85f, 0.78f, 0.5f), 20),
				I("br_mash", "Grain Mash", 10f, "BR_Wash.glb", new Color(0.7f, 0.55f, 0.25f), "A jug of fermented corn and barley mash. Run it through the Copper Pot Still.", (Color?)new Color(0.66f, 0.5f, 0.22f), 20),
				I("br_newmake", "New-Make Spirit", 30f, "BR_Mason.glb", new Color(0.92f, 0.92f, 0.86f), "Clear unaged whiskey straight off the pot still. Age it in an Oak Barrel.", (Color?)new Color(0.92f, 0.92f, 0.86f), 20)
			};
			labDef.Stations = new StationSpec[7]
			{
				new StationSpec
				{
					Id = "br_jugrack",
					Name = "Jug Fermenter",
					Price = 150f,
					Model = "BR_JugRack.glb",
					Verb = "Fermenting",
					Box = new Vector3(0.75f, 0.5f, 0.42f),
					Description = "Three 2 L bottles in a crate, each under a balloon held on with a rubber band: the balloon blows up while it ferments and goes limp when it's done. Rough but cheap. Keep it somewhere dark and warm (70-80 F) for better quality.",
					Busy = "Balloons",
					Tray = "Ready",
					Recipes = new RecipeSpec[5]
					{
						R("Kilju", "Two sacks of sugar and a packet of bread yeast make four jugs of Kilju.", 300f, "kilju", 4, 1, In("br_sugar", 2), In("br_yeast")),
						R("Kvass", "Two rye loaves, a sack of sugar and bread yeast make four bottles of Kvass.", 240f, "kvass", 4, 1, In("br_rye", 2), In("br_sugar"), In("br_yeast")),
						R("Hard Cider", "Two bottles of apple juice and bread yeast make three bottles of Hard Cider.", 360f, "hard-cider", 3, 1, In("br_juice", 2), In("br_yeast")),
						R("Mead", "A jar of honey and bread yeast make two bottles of Mead.", 480f, "mead", 2, 1, In("br_honey"), In("br_yeast")),
						R("Rough Berry Wine", "Two punnets of berries, a sack of sugar and bread yeast make two bottles of rough Berry Wine.", 480f, "berry-wine", 2, 1, In("br_berries", 2), In("br_sugar"), In("br_yeast"))
					}
				},
				new StationSpec
				{
					Id = "br_bucket",
					Name = "Fermenting Bucket",
					Price = 900f,
					Model = "BR_Bucket.glb",
					Verb = "Fermenting",
					Box = new Vector3(0.6f, 0.7f, 0.6f),
					Description = "A food-grade 6 gallon bucket with a lid, an airlock and a tap. Bigger batches and cleaner ferments than the jugs, and it makes sugar wash and grain mash for a still. Unlocks at Hoodlum. Dark and 70-80 F is best.",
					Busy = "Bubbles",
					Tray = "Ready",
					Bob = new string[1] { "Cap:0.006:2.5" },
					Recipes = new RecipeSpec[8]
					{
						R("Hard Cider", "Four bottles of apple juice and wine yeast make seven bottles of Hard Cider.", 360f, "hard-cider", 7, 2, In("br_juice", 4), In("br_wineyeast")),
						R("Mead", "Two jars of honey and wine yeast make five bottles of Mead.", 600f, "mead", 5, 2, In("br_honey", 2), In("br_wineyeast")),
						R("Berry Wine", "Three punnets of berries, a sack of sugar and wine yeast make four bottles of Berry Wine.", 600f, "berry-wine", 4, 2, In("br_berries", 3), In("br_sugar"), In("br_wineyeast")),
						R("Big Batch Kilju", "Four sacks of sugar and turbo yeast make eight jugs of stronger Kilju.", 300f, "kilju", 8, 2, In("br_sugar", 4), In("br_turbo")),
						R("Big Batch Kvass", "Four rye loaves, a sack of sugar and bread yeast make eight bottles of Kvass.", 240f, "kvass", 8, 2, In("br_rye", 4), In("br_sugar"), In("br_yeast")),
						R("Bucket Red Wine", "Five bunches of grapes and wine yeast make five bottles of Red Wine, quicker but rougher than the carboy.", 480f, "red-wine", 5, 2, In("br_grapes", 5), In("br_wineyeast")),
						RI("Sugar Wash", "Three sacks of sugar and turbo yeast ferment two jugs of Sugar Wash for the still.", 240f, "br_wash", 2, In("br_sugar", 3), In("br_turbo")),
						RI("Grain Mash", "Two sacks of corn, a sack of malted barley and turbo yeast make two jugs of Grain Mash.", 300f, "br_mash", 2, In("br_corn", 2), In("br_barley"), In("br_turbo"))
					}
				},
				new StationSpec
				{
					Id = "br_carboy",
					Name = "Glass Carboy",
					Price = 1800f,
					Model = "BR_Carboy.glb",
					Verb = "Fermenting",
					Box = new Vector3(0.45f, 0.9f, 0.45f),
					Description = "A 6 gallon glass carboy on a dolly with an S-bubbler. Slow, clean ferments: the best wine and mead come out of here. Unlocks at Peddler. Keep it in the dark at 70-80 F.",
					Busy = "Bubbles",
					Tray = "Ready",
					Recipes = new RecipeSpec[4]
					{
						R("Red Wine", "Four bunches of grapes and wine yeast make five bottles of Red Wine.", 720f, "red-wine", 5, 3, In("br_grapes", 4), In("br_wineyeast")),
						R("Berry Wine", "Four punnets of berries, sugar and wine yeast make six bottles of Berry Wine.", 600f, "berry-wine", 6, 3, In("br_berries", 4), In("br_sugar"), In("br_wineyeast")),
						R("Mead", "Three jars of honey and wine yeast make eight bottles of fine Mead.", 840f, "mead", 8, 3, In("br_honey", 3), In("br_wineyeast")),
						R("Hard Cider", "Five bottles of apple juice and wine yeast make nine bottles of Hard Cider.", 420f, "hard-cider", 9, 3, In("br_juice", 5), In("br_wineyeast"))
					}
				},
				new StationSpec
				{
					Id = "br_freezer",
					Name = "Chest Freezer",
					Price = 1400f,
					Model = "BR_Freezer.glb",
					Verb = "Freezing",
					Box = new Vector3(1.1f, 0.85f, 0.62f),
					Description = "A chest freezer for freeze-jacking: freeze hard cider, the water turns to ice and you pour off the strong stuff. Turns cider into Applejack. Unlocks at Peddler.",
					Lamp = "Lamp",
					Busy = "Frost",
					Tray = "Ready",
					Recipes = new RecipeSpec[1] { R("Applejack", "Four bottles of Hard Cider freeze down to two jars of Applejack.", 240f, "applejack", 2, 2, InP("hard-cider", 4)) }
				},
				new StationSpec
				{
					Id = "br_potstill",
					Name = "Copper Pot Still",
					Price = 4500f,
					Model = "BR_PotStill.glb",
					Verb = "Distilling",
					Box = new Vector3(1.3f, 1.1f, 0.6f),
					Description = "A copper onion-pot still on a propane burner, with a swan neck down to a worm in a barrel of cold water. Makes moonshine from sugar wash and new-make whiskey from grain mash. Unlocks at Hustler.",
					Lamp = "Flame",
					Busy = "Drip",
					Tray = "Ready",
					Recipes = new RecipeSpec[5]
					{
						R("Sugar Shine", "Two jugs of Sugar Wash run down to two jars of Moonshine.", 180f, "moonshine", 2, 2, In("br_wash", 2)),
						R("Corn Moonshine", "Two jugs of Grain Mash make three jars of smoother corn Moonshine.", 240f, "moonshine", 3, 3, In("br_mash", 2)),
						RI("New-Make Whiskey", "Two jugs of Grain Mash make two jars of New-Make Spirit for the barrel.", 240f, "br_newmake", 2, In("br_mash", 2)),
						R("Apple Brandy", "Four bottles of Hard Cider run through the pot still make three jars of Applejack (stronger and cleaner than freezing).", 240f, "applejack", 3, 3, InP("hard-cider", 4)),
						R("Pot-Still Gin", "Two bottles of Vodka redistilled with a jar of botanicals make two bottles of Gin.", 180f, "gin", 2, 3, InP("vodka", 2), In("br_botanicals"))
					}
				},
				new StationSpec
				{
					Id = "br_reflux",
					Name = "Reflux Column Still",
					Price = 8500f,
					Model = "BR_Reflux.glb",
					Verb = "Distilling",
					Box = new Vector3(0.6f, 1.9f, 0.6f),
					Description = "A stainless keg boiler under a tall copper-packed column with a cooling coil. Strips everything but alcohol: vodka, gin through the botanical basket, and Everclear on a second run. Unlocks at Bagman.",
					Lamp = "Lamp",
					Busy = "Drip",
					Tray = "Ready",
					Recipes = new RecipeSpec[5]
					{
						R("Vodka", "Three jugs of Sugar Wash make three bottles of Vodka.", 240f, "vodka", 3, 3, In("br_wash", 3)),
						R("Gin", "Two jugs of Sugar Wash and a jar of botanicals make two bottles of Gin.", 240f, "gin", 2, 3, In("br_wash", 2), In("br_botanicals")),
						R("Everclear", "Three bottles of Vodka run again make two bottles of Everclear.", 300f, "everclear", 2, 4, InP("vodka", 3)),
						R("Grain Vodka", "Three jugs of Grain Mash make three bottles of smoother grain Vodka.", 300f, "vodka", 3, 4, In("br_mash", 3)),
						R("Straight Everclear", "Five jugs of Sugar Wash stripped twice in one long run make two bottles of Everclear.", 420f, "everclear", 2, 3, In("br_wash", 5))
					}
				},
				new StationSpec
				{
					Id = "br_barrel",
					Name = "Oak Barrel",
					Price = 2500f,
					Model = "BR_Barrel.glb",
					Verb = "Aging",
					Box = new Vector3(0.9f, 0.8f, 0.6f),
					Description = "A charred white-oak barrel on a cradle. Pour in new-make spirit and leave it a day: it comes out amber Barrel-Aged Whiskey. Unlocks at Hustler.",
					Busy = "Chalk",
					Tray = "Ready",
					Recipes = new RecipeSpec[2]
					{
						R("Barrel-Aged Whiskey", "Three jars of New-Make Spirit age into three bottles of whiskey in a day.", 1440f, "whiskey", 3, 4, In("br_newmake", 3)),
						R("Aged Corn Whiskey", "Four jars of Moonshine aged in the barrel make three bottles of whiskey.", 1440f, "whiskey", 3, 3, InP("moonshine", 4))
					}
				}
			};
			labDef.Pack = new PackSpec
			{
				Id = "br_case",
				Name = "Six-Pack Carrier",
				Model = "BR_Case.glb",
				Template = "jar",
				Price = 3f,
				Tint = new Color(0.55f, 0.3f, 0.1f),
				Description = "A cardboard carrier that holds five bottles, jugs or jars. Pack them into it at a packaging station, the same as a jar."
			};
			labDef.Supplier = new PersonSpec
			{
				Id = "br_earl",
				First = "Earl",
				Last = "Haskins",
				Gender = 0f,
				Height = 1f,
				Weight = 0.7f,
				Skin = new Color32((byte)222, (byte)178, (byte)146, byte.MaxValue),
				Hair = "Avatar/Hair/balding/Balding",
				HairCol = new Color(0.82f, 0.8f, 0.76f),
				Face = "Avatar/Layers/Face/Face_SlightSmile",
				Top = "Avatar/Layers/Top/FlannelButtonUp",
				TopCol = new Color(0.2f, 0.32f, 0.2f),
				Bottom = "Avatar/Layers/Bottom/Jeans",
				BottomCol = new Color(0.18f, 0.2f, 0.28f),
				Shoes = "Avatar/Accessories/Feet/CombatBoots/CombatBoots",
				ShoeCol = new Color(0.3f, 0.2f, 0.1f),
				Head = "Avatar/Accessories/Head/PorkpieHat/PorkpieHat",
				HeadCol = new Color(0.25f, 0.2f, 0.14f),
				Chest = "Avatar/Accessories/Chest/OpenVest/OpenVest",
				ChestCol = new Color(0.35f, 0.25f, 0.12f)
			};
			labDef.StashDrop = "86835825-f5f8-454d-9c74-c31e257f9cc2";
			labDef.StashText = "Settle up at my stash {where} when you've got the cash. It's on your map.";
			labDef.SupplierIntro = "Earl Haskins. My granddaddy ran shine and so did I. Start small: get a Jug Fermenter, sugar and yeast and make yourself some Kilju. As you come up I'll sell you a bucket, a glass carboy, a chest freezer for applejack, a copper pot still, a reflux column and an oak barrel. Brew in the dark and keep it warm, 70 to 80, and it comes out better.";
			labDef.Customers = Array.Empty<PersonSpec>();
			labDef.FinishQuality = BrewEnv.Adjust;
			return labDef;
		}

		public override void OnInitializeMelon()
		{
			try
			{
				VanCheckCache.Patch(((MelonBase)this).HarmonyInstance);
				LabHost.Init(this, Build(), ((MelonBase)this).HarmonyInstance);
				((MelonBase)this).LoggerInstance.Msg("Home Brew loaded. Earl Haskins texts you once you're in your save: start with a Jug Fermenter, sugar and yeast.");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Home Brew couldn't start: " + ex.Message + ". It needs MelonLoader 0.7 and S1API (Bars fork) 3.2.3 or newer.");
			}
		}

		public override void OnUpdate()
		{
			LabHost.Update();
			try
			{
				BrewEnv.ApplyRankLocks();
			}
			catch
			{
			}
		}

		public override void OnGUI()
		{
			LabHost.OnGUI();
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			VanCheckCache.Reset();
		}
	}
	internal static class BrewEnv
	{
		private static float _lockAt;

		private static bool _locked;

		internal static int Adjust(StationSpec spec, Vector3 pos, int q)
		{
			//IL_0017: 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)
			if (spec == null || spec.Verb != "Fermenting")
			{
				return q;
			}
			string why;
			bool flag = Lit(pos, out why);
			float num = 20f;
			try
			{
				num = AcBoost.TempAt(pos);
			}
			catch
			{
			}
			float value = num * 9f / 5f + 32f;
			int num2 = 0;
			string value2;
			if (num >= 21f && num <= 27f)
			{
				num2++;
				value2 = $"{value:0} F, right in the sweet spot";
			}
			else if (num < 16f)
			{
				num2--;
				value2 = $"{value:0} F, too cold";
			}
			else if (num > 30f)
			{
				num2--;
				value2 = $"{value:0} F, too hot";
			}
			else
			{
				value2 = $"{value:0} F, a bit {((num < 21f) ? "cool" : "warm")} (70-80 F is best)";
			}
			if (flag)
			{
				num2--;
			}
			int num3 = Mathf.Clamp(q + num2, 0, 4);
			string value3 = (flag ? (why + " (brew in the dark for better flavour)") : "dark");
			string value4 = ((num2 > 0) ? "came out better" : ((num2 < 0) ? "came out worse" : "came out as expected"));
			try
			{
				FortifyApi.Notify(spec.Name, $"Batch {value4}: {value3}, {value2}.");
			}
			catch
			{
			}
			Instance log = Kit.Log;
			if (log != null)
			{
				log.Msg($"Home Brew: {spec.Name} batch finished {q} -> {num3} ({value3}; {num:0.0} C).");
			}
			return num3;
		}

		private static bool Lit(Vector3 pos, out string why)
		{
			//IL_00d6: 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_00e1: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			why = "";
			try
			{
				foreach (Light item in Object.FindObjectsOfType<Light>())
				{
					if (!((Object)(object)item == (Object)null) && ((Behaviour)item).enabled && ((Component)item).gameObject.activeInHierarchy && !(item.intensity <= 0.05f) && (int)item.type != 1 && Vector3.Distance(((Component)item).transform.position, pos) < Mathf.Min(item.range * 0.6f, 6f))
					{
						why = "under a light";
						return true;
					}
				}
			}
			catch
			{
			}
			try
			{
				TimeManager instance = NetworkSingleton<TimeManager>.Instance;
				if ((Object)(object)instance != (Object)null && !instance.IsNight && instance.CurrentTime >= 700 && instance.CurrentTime < 1900 && !Physics.Raycast(pos + Vector3.up * 1.2f, Vector3.up, 40f, -1, (QueryTriggerInteraction)1))
				{
					why = "out in the sun";
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		internal static void ApplyRankLocks()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			if (_locked || Time.unscaledTime < _lockAt)
			{
				return;
			}
			_lockAt = Time.unscaledTime + 3f;
			int num = 0;
			(string, int, string)[] locks = BrewCore.Locks;
			for (int i = 0; i < locks.Length; i++)
			{
				var (text, num2, _) = locks[i];
				try
				{
					StorableItemDefinition item = Registry.GetItem<StorableItemDefinition>(text);
					if (!((Object)(object)item == (Object)null))
					{
						item.RequiresLevelToPurchase = true;
						item.RequiredRank = new FullRank((ERank)num2, 1);
						num++;
					}
				}
				catch
				{
				}
			}
			if (num == BrewCore.Locks.Length)
			{
				_locked = true;
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Msg("Home Brew: bigger gear locked to ranks (bucket Hoodlum, carboy and freezer Peddler, pot still and barrel Hustler, reflux column Bagman).");
				}
			}
		}
	}
	internal static class VanCheckCache
	{
		private const string Key = "WoodStudios.S1VanCheckCache";

		private static float _okUntil = -1f;

		public static void Patch(Harmony h)
		{
			//IL_0056: 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_0078: Expected O, but got Unknown
			//IL_0078: Expected O, but got Unknown
			try
			{
				if (AppDomain.CurrentDomain.GetData("WoodStudios.S1VanCheckCache") == null)
				{
					Type type = AccessTools.TypeByName("S1API.Internal.Deliveries.SupplierDeliveryVehicleRuntime");
					MethodInfo methodInfo = ((type != null) ? AccessTools.PropertyGetter(type, "PrefabsReadyForLocalProcess") : null);
					if (!(methodInfo == null))
					{
						h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(VanCheckCache), "Prefix", (Type[])null), new HarmonyMethod(typeof(VanCheckCache), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						AppDomain.CurrentDomain.SetData("WoodStudios.S1VanCheckCache", "HomeBrew");
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Home Brew: van check cache: " + ex.Message);
			}
		}

		public static void Reset()
		{
			_okUntil = -1f;
		}

		private static bool Prefix(ref bool __result)
		{
			if (Time.unscaledTime < _okUntil)
			{
				__result = true;
				return false;
			}
			return true;
		}

		private static void Postfix(bool __result)
		{
			if (__result)
			{
				_okUntil = Time.unscaledTime + 5f;
			}
		}
	}
}
namespace DrugPack
{
	public static class GreenBoost
	{
		private const string Key = "WoodStudios.GreenhouseBoost";

		private static float _lookedAt = -100f;

		public static float At(Vector3 pos)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (AppDomain.CurrentDomain.GetData("WoodStudios.GreenhouseBoost") is Func<Vector3, float> func)
				{
					return Mathf.Max(1f, func(pos));
				}
				if (Time.unscaledTime - _lookedAt > 30f)
				{
					_lookedAt = Time.unscaledTime;
					Func<Vector3, float> func2 = FromStandalone();
					if (func2 != null)
					{
						AppDomain.CurrentDomain.SetData("WoodStudios.GreenhouseBoost", func2);
						return Mathf.Max(1f, func2(pos));
					}
				}
			}
			catch
			{
			}
			return 1f;
		}

		private static Func<Vector3, float> FromStandalone()
		{
			Type type = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					type = assembly.GetType("GreenhouseMod.Greenhouses", throwOnError: false);
				}
				catch
				{
				}
				if (type != null)
				{
					break;
				}
			}
			if (type == null)
			{
				return null;
			}
			FieldInfo all = type.GetField("All", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo inside = type.GetMethod("Inside", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo boost = type.GetMethod("Boost", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (all == null || inside == null || boost == null)
			{
				return null;
			}
			return delegate(Vector3 pos)
			{
				//IL_00b9: 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)
				try
				{
					if (all.GetValue(null) is IEnumerable enumerable)
					{
						bool flag = default(bool);
						foreach (object item in enumerable)
						{
							object obj2 = item?.GetType().GetField("P")?.GetValue(item);
							object? obj3 = obj2?.GetType().GetField("Go")?.GetValue(obj2);
							GameObject val = (GameObject)((obj3 is GameObject) ? obj3 : null);
							if (!((Object)(object)val == (Object)null))
							{
								object[] parameters = ((inside.GetParameters().Length < 3) ? new object[2] { val, pos } : new object[3] { val, pos, 0f });
								object obj4 = inside.Invoke(null, parameters);
								int num;
								if (obj4 is bool)
								{
									flag = (bool)obj4;
									num = 1;
								}
								else
								{
									num = 0;
								}
								if (((uint)num & (flag ? 1u : 0u)) != 0)
								{
									return 1f + Convert.ToSingle(boost.Invoke(null, new object[1] { item })) / 100f;
								}
							}
						}
					}
				}
				catch
				{
				}
				return 1f;
			};
		}
	}
	public abstract class LabModule : MelonMod
	{
	}
}
namespace DP_HomeBrew.WoodLabs
{
	internal static class AcBoost
	{
		private static float _scanAt = -1f;

		private static Il2CppStructArray<TemperatureEmitterInfo> _emitters;

		private static float _ambient = 20f;

		private static float _min = 20f;

		private static float _max = 30f;

		private static float _maxMult = 2f;

		private static bool _consts;

		private static void Constants()
		{
			_consts = true;
			try
			{
				_ambient = TemperatureEmitter.DefaultAmbientTemperature;
			}
			catch
			{
			}
			try
			{
				_min = DryingRack.WARMTH_MIN_THRESHOLD;
			}
			catch
			{
			}
			try
			{
				_max = DryingRack.WARMTH_MAX_THRESHOLD;
			}
			catch
			{
			}
			try
			{
				_maxMult = DryingRack.MAX_DRY_MULTIPLIER;
			}
			catch
			{
			}
			if (_max <= _min + 0.01f)
			{
				_max = _min + 1f;
			}
			if (_maxMult < 1f)
			{
				_maxMult = 1f;
			}
		}

		private static void Scan()
		{
			//IL_0037: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			_scanAt = Time.unscaledTime + 3f;
			try
			{
				Il2CppArrayBase<AirConditioner> val = Object.FindObjectsOfType<AirConditioner>();
				int num = 0;
				foreach (AirConditioner item in val)
				{
					if ((Object)(object)item != (Object)null && (int)item.CurrentMode != 0 && (Object)(object)item.TemperatureEmitter != (Object)null)
					{
						num++;
					}
				}
				Il2CppStructArray<TemperatureEmitterInfo> val2 = new Il2CppStructArray<TemperatureEmitterInfo>((long)num);
				int num2 = 0;
				foreach (AirConditioner item2 in val)
				{
					if (!((Object)(object)item2 == (Object)null) && (int)item2.CurrentMode != 0 && !((Object)(object)item2.TemperatureEmitter == (Object)null))
					{
						TemperatureEmitter temperatureEmitter = item2.TemperatureEmitter;
						((Il2CppArrayBase<TemperatureEmitterInfo>)(object)val2)[num2++] = new TemperatureEmitterInfo(temperatureEmitter.Temperature, temperatureEmitter.Range * temperatureEmitter.Range, ((Component)temperatureEmitter).transform.position);
					}
				}
				_emitters = val2;
			}
			catch
			{
				_emitters = null;
			}
		}

		internal static float TempAt(Vector3 p)
		{
			//IL_003c: 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)
			if (!_consts)
			{
				Constants();
			}
			if (Time.unscaledTime >= _scanAt)
			{
				Scan();
			}
			if (_emitters == null || ((Il2CppArrayBase<TemperatureEmitterInfo>)(object)_emitters).Length == 0)
			{
				return _ambient;
			}
			try
			{
				return TemperatureAlgorithm.GetTemperatureAtPoint(_ambient, p, p, _emitters);
			}
			catch
			{
				return _ambient;
			}
		}

		internal static float At(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			float num = TempAt(p);
			float num2 = Mathf.InverseLerp(_min, _max, num);
			return Mathf.Lerp(1f, _maxMult, num2);
		}

		public static string DevTest(string temp)
		{
			//IL_0175: 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)
			//IL_001b: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (!_consts)
			{
				Constants();
			}
			Player local = Player.Local;
			Vector3 val = (((Object)(object)local != (Object)null) ? ((Component)local).transform.position : Vector3.zero);
			float num = float.Parse(temp, CultureInfo.InvariantCulture);
			Il2CppStructArray<TemperatureEmitterInfo> val2 = new Il2CppStructArray<TemperatureEmitterInfo>(1L);
			((Il2CppArrayBase<TemperatureEmitterInfo>)(object)val2)[0] = new TemperatureEmitterInfo(num, 25f, val + Vector3.right);
			float temperatureAtPoint = TemperatureAlgorithm.GetTemperatureAtPoint(_ambient, val, val, val2);
			bool value = true;
			try
			{
				value = TemperatureUtility.TemperatureSystemEnabled;
			}
			catch
			{
			}
			float value2 = Mathf.Lerp(1f, _maxMult, Mathf.InverseLerp(_min, _max, temperatureAtPoint));
			return $"system {value}, fake AC {num} C 1 m away -> {temperatureAtPoint:0.0} C, x{value2:0.00} (ambient {_ambient}, warm {_min}-{_max}, max x{_maxMult}); real: {Dev(val)}";
		}

		internal static string Dev(Vector3 p)
		{
			//IL_0000: 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)
			float value = TempAt(p);
			return $"temp {value:0.0} C (ambient {_ambient}, warm {_min}-{_max}), x{At(p):0.00} (max x{_maxMult}), emitters {((_emitters != null) ? ((Il2CppArrayBase<TemperatureEmitterInfo>)(object)_emitters).Length : 0)}";
		}
	}
	internal static class AnyListed
	{
		private struct Option
		{
			public Tuple<ProductDefinition, int> E;

			public float Appeal;
		}

		private const string HarmonyId = "WoodStudios.AnyListed";

		private const float MinAppeal = 0.05f;

		private static MelonPreferences_Entry<bool> _on;

		private static bool _mine;

		private static IntPtr _choosing;

		private static int _choosingFrame = -1;

		private static int _prefixed;

		private static int _replaced;

		private static readonly List<Option> Sorted = new List<Option>();

		private static readonly List<Option> Ok = new List<Option>();

		private static readonly Dictionary<IntPtr, float> Appeals = new Dictionary<IntPtr, float>();

		private static bool _warned;

		private static float _surveyAt = -1f;

		private static int _surveyStep;

		private static readonly List<string> Listed = new List<string>();

		public static bool On => _on?.Value ?? true;

		public static void Init(string by)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00ae: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			try
			{
				MelonPreferences_Category val = MelonPreferences.GetCategory("WoodStudiosOrders") ?? MelonPreferences.CreateCategory("WoodStudiosOrders", "Wood Studios: customer orders");
				_on = val.GetEntry<bool>("OrderAnyListed") ?? val.CreateEntry<bool>("OrderAnyListed", true, "Customers order anything you list", "On: customers can ask for any product you list that they'd buy, still mostly what they like best. Off: the game's own way (each customer only ever orders one of their top 4).", false, false, (ValueValidator)null, (string)null);
				if (!Harmony.HasAnyPatches("WoodStudios.AnyListed"))
				{
					Harmony val2 = new Harmony("WoodStudios.AnyListed");
					val2.Patch((MethodBase)AccessTools.Method(typeof(Customer), "TryGenerateContract", (Type[])null, (Type[])null), new HarmonyMethod(typeof(AnyListed), "ContractPrefix", (Type[])null), new HarmonyMethod(typeof(AnyListed), "ContractPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					val2.Patch((MethodBase)AccessTools.Method(typeof(Customer), "GetOrderableProductsWithQuantities", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(AnyListed), "OrderablePostfix", (Type[])null)
					{
						priority = 0
					}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					_mine = true;
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Msg("Customers order anything you list (set up by " + by + (On ? "" : "; switched off in [WoodStudiosOrders]") + ").");
					}
				}
			}
			catch (Exception ex)
			{
				Instance log2 = Kit.Log;
				if (log2 != null)
				{
					log2.Warning("Customer orders: " + ex.Message);
				}
			}
		}

		private static void ContractPrefix(Customer __instance)
		{
			_prefixed++;
			_choosing = (((Object)(object)__instance != (Object)null) ? ((Il2CppObjectBase)__instance).Pointer : IntPtr.Zero);
			_choosingFrame = Time.frameCount;
		}

		private static void ContractPostfix()
		{
			_choosing = IntPtr.Zero;
		}

		private static float AppealOf(Customer c, ProductDefinition p)
		{
			if (Appeals.TryGetValue(((Il2CppObjectBase)p).Pointer, out var value))
			{
				return value;
			}
			float marketValue = p.MarketValue;
			float price = p.Price;
			float num = ((marketValue > 0f) ? Mathf.Clamp01(price / marketValue * 0.5f) : ((price > 0f) ? 1f : 0f));
			value = c.GetProductEnjoyment(p) + 1f - 2f * num;
			Appeals[((Il2CppObjectBase)p).Pointer] = value;
			return value;
		}

		private static void OrderablePostfix(Customer __instance, ref List<Tuple<ProductDefinition, int>> __result)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null || _choosing == IntPtr.Zero || ((Il2CppObjectBase)__instance).Pointer != _choosing || Time.frameCount != _choosingFrame)
				{
					return;
				}
				_choosing = IntPtr.Zero;
				if (On && __result != null && __result.Count > 4)
				{
					int rank;
					int buyable;
					Tuple<ProductDefinition, int> val = Choose(__instance, __result, out rank, out buyable);
					if (val != null)
					{
						List<Tuple<ProductDefinition, int>> val2 = new List<Tuple<ProductDefinition, int>>();
						val2.Add(val);
						__result = val2;
						_replaced++;
					}
				}
			}
			catch (Exception ex)
			{
				if (!_warned)
				{
					_warned = true;
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Warning("Customer orders: " + ex.Message + "; using the game's own choice.");
					}
				}
			}
		}

		private static Tuple<ProductDefinition, int> Choose(Customer c, List<Tuple<ProductDefinition, int>> list, out int rank, out int buyable)
		{
			rank = -1;
			buyable = 0;
			Sorted.Clear();
			Appeals.Clear();
			for (int i = 0; i < list.Count; i++)
			{
				Tuple<ProductDefinition, int> val = list[i];
				if (!((Object)(object)val?.Item1 == (Object)null))
				{
					Option item = new Option
					{
						E = val,
						Appeal = AppealOf(c, val.Item1)
					};
					int num = Sorted.Count;
					while (num > 0 && Sorted[num - 1].Appeal < item.Appeal)
					{
						num--;
					}
					Sorted.Insert(num, item);
				}
			}
			if (Sorted.Count <= 4)
			{
				return null;
			}
			float num2 = Random.Range(0f, 1f);
			int index = ((!(num2 <= 0.5f)) ? ((num2 <= 0.75f) ? 1 : ((num2 <= 0.875f) ? 2 : 3)) : 0);
			if (Sorted[index].Appeal < 0.05f)
			{
				return Sorted[index].E;
			}
			Ok.Clear();
			foreach (Option item2 in Sorted)
			{
				if (item2.Appeal >= 0.05f)
				{
					Ok.Add(item2);
				}
			}
			buyable = Ok.Count;
			float num3 = 0f;
			for (int j = 0; j < Ok.Count; j++)
			{
				num3 += 1f / (float)(j + 1);
			}
			float num4 = Random.Range(0f, num3);
			for (int k = 0; k < Ok.Count; k++)
			{
				num4 -= 1f / (float)(k + 1);
				if (num4 <= 0f)
				{
					rank = k;
					return Ok[k].E;
				}
			}
			rank = Ok.Count - 1;
			return Ok[Ok.Count - 1].E;
		}

		public static void Loaded()
		{
			_surveyAt = Time.unscaledTime + 30f;
			_surveyStep = 0;
		}

		public static void Update()
		{
			if (!_mine || _surveyAt < 0f || Time.unscaledTime < _surveyAt || !FortifyApi.InGame)
			{
				return;
			}
			if (!FortifyApi.DevKeys)
			{
				_surveyAt = -1f;
				return;
			}
			try
			{
				ProductManager instance = NetworkSingleton<ProductManager>.Instance;
				if (_surveyStep == 0)
				{
					Listed.Clear();
					int num = ProductManager.ListedProducts?.Count ?? 0;
					List<ProductDefinition> discoveredProducts = ProductManager.DiscoveredProducts;
					int num2 = 0;
					while (discoveredProducts != null && num2 < discoveredProducts.Count && num < 12)
					{
						ProductDefinition val = discoveredProducts[num2];
						if (!((Object)(object)val == (Object)null) && !ProductManager.ListedProducts.Contains(val))
						{
							instance.SetProductListed(((BaseItemDefinition)val).ID, true);
							Listed.Add(((BaseItemDefinition)val).ID);
							num++;
						}
						num2++;
					}
					_surveyStep = 1;
					_surveyAt = Time.unscaledTime + 4f;
					return;
				}
				if (instance.TimeSinceProductListingChanged < 3.3f && _surveyStep < 30)
				{
					_surveyStep++;
					_surveyAt = Time.unscaledTime + 2f;
					return;
				}
				_surveyAt = -1f;
				List<ProductDefinition> listedProducts = ProductManager.ListedProducts;
				StringBuilder stringBuilder = new StringBuilder($"Survey: {listedProducts?.Count ?? 0} listed ({Listed.Count} listed just for this), accepting orders {ProductManager.IsAcceptingOrders}, listing changed {instance.TimeSinceProductListingChanged:0.0} ago.");
				List<Customer> unlockedCustomers = Customer.UnlockedCustomers;
				int num3 = 0;
				Customer val2 = ((unlockedCustomers != null && unlockedCustomers.Count > 0) ? unlockedCustomers[0] : null);
				if ((Object)(object)val2 != (Object)null)
				{
					float value = default(float);
					int value2 = default(int);
					ProductDefinition weightedRandomProduct = val2.GetWeightedRandomProduct((Dealer)null, ref value, ref value2);
					_choosing = ((Il2CppObjectBase)val2).Pointer;
					_choosingFrame = Time.frameCount;
					int replaced = _replaced;
					float value3 = default(float);
					int value4 = default(int);
					ProductDefinition weightedRandomProduct2 = val2.GetWeightedRandomProduct((Dealer)null, ref value3, ref value4);
					StringBuilder stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder3 = stringBuilder2;
					StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(61, 7, stringBuilder2);
					handler.AppendLiteral("\n  step by step: game's pick ");
					handler.AppendFormatted((weightedRandomProduct != null) ? ((BaseItemDefinition)weightedRandomProduct).ID : null);
					handler.AppendLiteral(" (");
					handler.AppendFormatted(value, "0.00");
					handler.AppendLiteral(", ");
					handler.AppendFormatted(value2);
					handler.AppendLiteral("); ours ");
					handler.AppendFormatted((weightedRandomProduct2 != null) ? ((BaseItemDefinition)weightedRandomProduct2).ID : null);
					handler.AppendLiteral(" (");
					handler.AppendFormatted(value3, "0.00");
					handler.AppendLiteral(", ");
					handler.AppendFormatted(value4);
					handler.AppendLiteral(", list swapped ");
					handler.AppendFormatted(_replaced - replaced);
					handler.AppendLiteral(")");
					stringBuilder3.Append(ref handler);
					bool dEBUG = val2.DEBUG;
					val2.DEBUG = true;
					int prefixed = _prefixed;
					ContractInfo val3 = val2.TryGenerateContract((Dealer)null);
					val2.DEBUG = dEBUG;
					stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder4 = stringBuilder2;
					handler = new StringBuilder.AppendInterpolatedStringHandler(26, 2, stringBuilder2);
					handler.AppendLiteral("; an order: ");
					object value5;
					if (val3 != null)
					{
						ProductList products = val3.Products;
						value5 = ((products != null) ? products.GetCommaSeperatedString() : null);
					}
					else
					{
						value5 = "none";
					}
					handler.AppendFormatted((string?)value5);
					handler.AppendLiteral(" (prefix ran ");
					handler.AppendFormatted(_prefixed - prefixed);
					handler.AppendLiteral(")");
					stringBuilder4.Append(ref handler);
				}
				int num4 = 0;
				while (unlockedCustomers != null && num4 < unlockedCustomers.Count && num3 < 4)
				{
					Customer val4 = unlockedCustomers[num4];
					if (!((Object)(object)val4 == (Object)null))
					{
						Dictionary<string, int> dictionary = new Dictionary<string, int>();
						int num5 = 0;
						for (int i = 0; i < 200; i++)
						{
							ContractInfo obj = val4.TryGenerateContract((Dealer)null);
							object obj2;
							if (obj == null)
							{
								obj2 = null;
							}
							else
							{
								ProductList products2 = obj.Products;
								obj2 = ((products2 != null) ? products2.entries : null);
							}
							List<Entry> val5 = (List<Entry>)obj2;
							if (val5 == null || val5.Count == 0)
							{
								num5++;
								continue;
							}
							string key = val5[0].ProductID ?? "?";
							dictionary.TryGetValue(key, out var value6);
							dictionary[key] = value6 + 1;
						}
						string value7 = "";
						try
						{
							value7 = (((Object)(object)val4.NPC != (Object)null) ? val4.NPC.FullName : "");
						}
						catch
						{
						}
						List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>(dictionary);
						list.Sort((KeyValuePair<string, int> x, KeyValuePair<string, int> y) => y.Value.CompareTo(x.Value));
						List<string> list2 = new List<string>();
						foreach (KeyValuePair<string, int> item in list)
						{
							list2.Add($"{item.Key} {item.Value}");
						}
						StringBuilder stringBuilder5 = stringBuilder;
						StringBuilder.AppendInterpolatedStringHandler handler2 = new StringBuilder.AppendInterpolatedStringHandler(32, 4, stringBuilder5);
						handler2.AppendLiteral("\n  ");
						handler2.AppendFormatted(value7);
						handler2.AppendLiteral(": ");
						handler2.AppendFormatted(dictionary.Count);
						handler2.AppendLiteral(" different, no order ");
						handler2.AppendFormatted(num5);
						handler2.AppendLiteral("/200: ");
						handler2.AppendFormatted(string.Join(", ", list2));
						stringBuilder5.Append(ref handler2);
						num3++;
					}
					num4++;
				}
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Msg(stringBuilder.ToString());
				}
				foreach (string item2 in Listed)
				{
					instance.SetProductListed(item2, false);
				}
				Listed.Clear();
			}
			catch (Exception ex)
			{
				_surveyAt = -1f;
				Instance log2 = Kit.Log;
				if (log2 != null)
				{
					log2.Warning("Survey: " + ex.Message);
				}
			}
		}
	}
	internal static class DeadDrops
	{
		private static readonly (string Name, string Guid)[] All = new(string, string)[25]
		{
			("BehindSupermarket", "fe1782b0-64e5-4ae6-a3f9-56af509af104"),
			("BehindMotelOffice", "d66b3fd6-7b7f-4e98-b000-6d5a197f7437"),
			("SkatePark", "eda8c6a4-07be-4d8f-97f4-ddd6dfca19df"),
			("BehindGasMart", "64d10032-64a9-4cd9-8750-8048d71c5029"),
			("UnderWestBridge", "0fd91cf3-ac6a-41ce-968f-1f356f996a83"),
			("BehindCasino", "f5614c42-2c74-42d5-bee2-025e84718792"),
			("TacoTicklersExteriorWall", "79200bb6-7d39-44d9-ab22-c63f136d8cdf"),
			("TownHallFountain", "d28c727e-5175-4989-8c33-2a36c159c817"),
			("PawnShopWestWall", "fde97bca-d21a-476c-bf03-b00768a45030"),
			("BehindSlopShop", "58ec86b5-647e-456d-9266-4cd77413e9c3"),
			("Gazebo", "94eef741-d688-4380-ac64-cf190e812b10"),
			("BehindRandysBaitAndTackle", "baf08ceb-a0e7-4e4a-baa8-6b4cc992cb15"),
			("BehindBank", "e5399b56-22a5-4a2c-a254-cc81e3ab2f75"),
			("BehindCrimsonCanary", "51e8f8ec-adcb-4800-8020-55cc24f9ba40"),
			("BehindThompsonConstruction", "766389cd-b2e3-44ec-84fe-9c59eccfcdd7"),
			("CentralCanal", "4ac50ff1-ad3c-415b-aa77-c80249dfa473"),
			("NorthArcadeWall", "dd3d22f1-da56-4673-9203-640eeaf915fc"),
			("BrownApartmentBlock", "b77ed1a0-c729-41d5-b8a2-81b480ca971f"),
			("BehindMedicalPractice", "683fa5b9-c55d-4b3f-8026-6f29857d09d1"),
			("BehindLaundromat", "555e565d-2f65-4882-9edb-7167168b2e00"),
			("BehindAutoShop", "aaea12a7-ee38-47ba-aeb8-fb0d45a03957"),
			("GreyDocksBuilding", "eff8fff2-0f89-4936-aef5-c4d383ea4f50"),
			("BehindGroceryStore", "5aeef10c-955d-4fdb-9061-38f4ad7a6289"),
			("BehindFireStation", "86835825-f5f8-454d-9c74-c31e257f9cc2"),
			("BehindTopTattoo", "3ed706ba-458d-44b5-95cd-d65e4a699043")
		};

		public static string Names => string.Join(", ", All.Select(((string Name, string Guid) d) => d.Name));

		private static string Key(string s)
		{
			return new string((s ?? "").Where(char.IsLetterOrDigit).ToArray()).ToLowerInvariant();
		}

		public static string FirstFree(IEnumerable<string> taken, string after)
		{
			HashSet<string> hashSet = new HashSet<string>(taken ?? Array.Empty<string>(), StringComparer.OrdinalIgnoreCase);
			int val = Array.FindIndex(All, ((string Name, string Guid) d) => string.Equals(d.Guid, after, StringComparison.OrdinalIgnoreCase));
			for (int num = 1; num <= All.Length; num++)
			{
				(string, string) tuple = All[(Math.Max(val, 0) + num) % All.Length];
				if (!hashSet.Contains(tuple.Item2) && !string.Equals(tuple.Item2, after, StringComparison.OrdinalIgnoreCase))
				{
					return tuple.Item2;
				}
			}
			return null;
		}

		public static string Guid(string name)
		{
			string text = Key(name);
			(string, string)[] all = All;
			for (int i = 0; i < all.Length; i++)
			{
				(string, string) tuple = all[i];
				if (Key(tuple.Item1) == text || string.Equals(tuple.Item2, (name ?? "").Trim(), StringComparison.OrdinalIgnoreCase))
				{
					return tuple.Item2;
				}
			}
			return null;
		}

		public static string NameOf(string guid)
		{
			(string, string)[] all = All;
			for (int i = 0; i < all.Length; i++)
			{
				(string, string) tuple = all[i];
				if (string.Equals(tuple.Item2, guid, StringComparison.OrdinalIgnoreCase))
				{
					return tuple.Item1;
				}
			}
			return guid ?? "";
		}
	}
	internal sealed class InputSpec
	{
		public string Item;

		public string Product;

		public bool AnyOfType;

		public DrugType? Type;

		public int Qty = 1;

		public string Label;
	}
	internal sealed class ItemDef
	{
		public string Id;

		public string Name;

		public string Description;

		public string Model;

		public float Price;

		public int Stack = 20;

		public Color Color = Color.gray;

		public Color? Tint;

		public float Scale = 1f;

		public Vector3? IconTilt;

		public int IconCopies = 1;
	}
	public abstract class LabCustomerNpc : NPC
	{
		public override bool IsPhysical => true;

		public override bool IsCustomer => true;

		protected abstract int Index { get; }

		protected override void ConfigurePrefab(NPCPrefabBuilder b)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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)
			LabDef d = LabHost.Def;
			PersonSpec p = d.Customers[Index];
			Vector3[] spots = LabNpcs.Spots(d.Region, Index);
			List<string> others = new List<string>();
			PersonSpec[] customers = d.Customers;
			foreach (PersonSpec personSpec in customers)
			{
				if (personSpec != p)
				{
					others.Add(personSpec.Id);
				}
			}
			b.WithIdentity(p.Id, p.First, p.Last).WithAppearanceDefaults((Action<AvatarDefaultsBuilder>)delegate(AvatarDefaultsBuilder av)
			{
				LabNpcs.Dress(av, p);
			}).WithSpawnPosition(spots[0])
				.WithRegion(d.Region)
				.EnsureCustomer()
				.WithCustomerDefaults((Action<CustomerDataBuilder>)delegate(CustomerDataBuilder cd)
				{
					//IL_003d: Unknown result type (might be due to invalid IL or missing references)
					//IL_005d: 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)
					cd.WithSpending(p.MinSpend, p.MaxSpend).WithOrdersPerWeek(p.MinOrders, p.MaxOrders).WithPreferredOrderDay(p.OrderDay)
						.WithOrderTime(p.OrderTime)
						.WithStandards(p.Standards)
						.AllowDirectApproach(true)
						.GuaranteeFirstSample(true)
						.WithMutualRelationRequirement(2f, 3.5f)
						.WithCallPoliceChance(0.08f)
						.WithDependence(0.15f, 1.1f)
						.WithAffinities((IEnumerable<ValueTuple<DrugType, float>>)new(DrugType, float)[1] { (d.Compat, p.Affinity) });
					if (p.Likes != null && p.Likes.Length != 0)
					{
						cd.WithPreferredProperties(p.Likes);
					}
				})
				.WithRelationshipDefaults((Action<NPCRelationshipDataBuilder>)delegate(NPCRelationshipDataBuilder r)
				{
					r.WithDelta(1f).SetUnlocked(false).SetUnlockType((UnlockType)1)
						.WithConnectionsById((IEnumerable<string>)others);
				})
				.WithSchedule((Action<PrefabScheduleBuilder>)delegate(PrefabScheduleBuilder plan)
				{
					//IL_000d: 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_005b: 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)
					plan.EnsureDealSignal().WalkTo(spots[0], 700, true, 1f, false, (Vector3?)null, (string)null).WalkTo(spots[1], 1130, true, 1f, false, (Vector3?)null, (string)null)
						.WalkTo(spots[2], 1600, true, 1f, false, (Vector3?)null, (string)null)
						.WalkTo(spots[0], 2030, true, 1f, false, (Vector3?)null, (string)null);
				});
		}

		protected override void OnCreated()
		{
			((NPC)this).OnCreated();
			try
			{
				((NPC)this).Appearance.Build();
			}
			catch
			{
			}
			try
			{
				((NPC)this).Schedule.Enable();
			}
			catch
			{
			}
			LabNpcs.Customers.Add(this);
		}
	}
	internal sealed class LabDef
	{
		public string Title;

		public string Folder;

		public string Prefix;

		public string Ns;

		public string Short;

		public string KindName;

		public Color Accent = new Color(0.2f, 0.75f, 0.8f);

		public DrugType Compat;

		public DrugType InputType;

		public string InputName = "weed";

		public string Template;

		public Region Region = (Region)1;

		public ProductSpec[] Products = Array.Empty<ProductSpec>();

		public ItemDef[] Items = Array.Empty<ItemDef>();

		public StationSpec[] Stations = Array.Empty<StationSpec>();

		public PackSpec Pack;

		public PersonSpec Supplier;

		public string SupplierIntro;

		public string SupplierHint;

		public string StashDrop;

		public string OldStashDrop;

		public string StashText;

		public PersonSpec[] Customers = Array.Empty<PersonSpec>();

		public float PriceMultiplier = 1f;

		public KeyCode DevKey = (KeyCode)44;

		public int DevRow;

		public Action<ProductSpec, GameObject> Decorate;

		public Func<StationSpec, Vector3, int, int> FinishQuality;

		public ProductSpec Product(string key)
		{
			ProductSpec[] products = Products;
			foreach (ProductSpec productSpec in products)
			{
				if (string.Equals(productSpec.Key, key, StringComparison.OrdinalIgnoreCase))
				{
					return productSpec;
				}
			}
			return null;
		}

		public ItemDef Item(string id)
		{
			ItemDef[] items = Items;
			foreach (ItemDef itemDef in items)
			{
				if (string.Equals(itemDef.Id, id, StringComparison.OrdinalIgnoreCase))
				{
					return itemDef;
				}
			}
			return null;
		}

		public StationSpec Station(string id)
		{
			StationSpec[] stations = Stations;
			foreach (StationSpec stationSpec in stations)
			{
				if (string.Equals(stationSpec.Id, id, StringComparison.OrdinalIgnoreCase))
				{
					return stationSpec;
				}
			}
			return null;
		}

		public bool IsOurs(string productId)
		{
			if (string.IsNullOrEmpty(productId))
			{
				return false;
			}
			ProductSpec[] products = Products;
			for (int i = 0; i < products.Length; i++)
			{
				if (string.Equals(products[i].Id, productId, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class LabHost
	{
		public static LabDef Def;

		private static MelonPreferences_Entry<float> _price;

		private static MelonPreferences_Entry<float> _time;

		private static MelonPreferences_Entry<bool> _walk;

		private static MelonPreferences_Entry<bool> _workerMsgs;

		private static MelonPreferences_Entry<string> _stash;

		private static float _warnedAt = -100f;

		private static float _ctrlAt = -10f;

		private static bool _guiWarned;

		private static AudioClip _start;

		private static AudioClip _done;

		internal static string Rerouted;

		private static int _devOpen;

		public static float TimeMult => _time?.Value ?? 1f;

		public static bool WorkersWalk => _walk?.Value ?? true;

		public static bool WorkerMessages => _workerMsgs?.Value ?? true;

		public static string StashDrop
		{
			get
			{
				if (!string.IsNullOrEmpty(Rerouted))
				{
					return Rerouted;
				}
				string text = (_stash?.Value ?? "").Trim();
				if (text.Length > 0)
				{
					string text2 = DeadDrops.Guid(text);
					if (text2 != null)
					{
						return text2;
					}
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Warning($"{Def.Title}: there's no dead drop called '{text}' (try one of: {DeadDrops.Names}). Using the usual one.");
					}
				}
				return Def.StashDrop;
			}
		}

		public static void Init(LabModule mod, LabDef def, Harmony harmony)
		{
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			Def = def;
			LabQuality.AddHeavenly(def);
			Host.Init(mod, def.Folder, def.Title, def.Prefix, null, Loaded, Unloaded);
			StashRoute.Hook(harmony);
			MelonPreferences_Category obj = MelonPreferences.GetCategory(def.Folder) ?? MelonPreferences.CreateCategory(def.Folder, def.Title);
			_price = obj.CreateEntry<float>("PriceMultiplier", 1f, "Price multiplier", "Multiplies the supplier's prices for the lab gear and supplies (1 = normal, 0 = free). Applies after a game restart.", false, false, (ValueValidator)null, (string)null);
			_time = obj.CreateEntry<float>("TimeMultiplier", 1f, "Time multiplier", "Multiplies how long each batch takes in game time (1 = normal, 0.5 = twice as fast).", false, false, (ValueValidator)null, (string)null);
			_walk = obj.CreateEntry<bool>("WorkersWalk", true, "Workers walk over", "Workers walk to a station before loading or unloading it (off: they do it from wherever they are).", false, false, (ValueValidator)null, (string)null);
			_workerMsgs = obj.CreateEntry<bool>("WorkerMessages", true, "Worker messages", "Phone messages from your workers at the lab's stations (waiting for supplies, shelf full) and the restock receipts. Off: no messages; each station's screen still shows what its worker is doing.", false, false, (ValueValidator)null, (string)null);
			_stash = obj.CreateEntry<string>("SupplierStash", "", "Supplier stash", "Which dead drop the supplier's stash is at, if you want a different one (for example if another mod's supplier uses the same spot). Blank = " + DeadDrops.NameOf(def.StashDrop) + ". One of: " + DeadDrops.Names + ". Applies after a game restart.", false, false, (ValueValidator)null, (string)null);
			Kit.PriceMultiplier = () => _price?.Value ?? 1f;
			Kit.Stores = Array.Empty<string>();
			FortifyApi.SetNotifyIcon((def.Stations.Length != 0) ? def.Stations[0].Id : null);
			StationSpec[] stations = def.Stations;
			foreach (StationSpec stationSpec in stations)
			{
				StationSpec spec = stationSpec;
				Catalog.Add(new ItemSpec
				{
					Id = stationSpec.Id,
					Name = stationSpec.Name,
					Kind = PlaceKind.Ground,
					Price = stationSpec.Price,
					RotateStep = 90f,
					StackLimit = 2,
					NotSold = true,
					IconColor = def.Accent,
					BuildModel = () => LabModels.Station(spec),
					FitLift = 0.15f,
					Description = stationSpec.Description
				});
				Kit.Use[stationSpec.Id] = LabStations.TryUse;
			}
			ItemDef[] items = def.Items;
			foreach (ItemDef itemDef in items)
			{
				ItemDef item = itemDef;
				Catalog.Add(new ItemSpec
				{
					Id = itemDef.Id,
					Name = itemDef.Name,
					Kind = PlaceKind.Ground,
					Price = itemDef.Price,
					RotateStep = 0f,
					StackLimit = itemDef.Stack,
					NotSold = true,
					IconColor = itemDef.Color,
					BuildModel = () => LabModels.Item(item),
					Description = itemDef.Description,
					IconModel = ((itemDef.IconTilt.HasValue || itemDef.IconCopies > 1) ? ((Func<GameObject>)delegate
					{
						//IL_001a: Unknown result type (might be due to invalid IL or missing references)
						//IL_0020: Expected O, but got Unknown
						//IL_0085: Unknown result type (might be due to invalid IL or missing references)
						//IL_00b2: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
						GameObject val = new GameObject(Kit.Prefix + "Icon_" + item.Id);
						int num2 = Math.Max(1, item.IconCopies);
						for (int i = 0; i < num2; i++)
						{
							GameObject obj2 = LabModels.Item(item);
							obj2.transform.SetParent(val.transform, false);
							obj2.transform.localPosition = new Vector3(((float)i - (float)(num2 - 1) * 0.5f) * 0.028f, 0f, (i % 2 == 0) ? 0f : 0.02f);
							obj2.transform.localRotation = Quaternion.Euler((Vector3)(((??)item.IconTilt) ?? Vector3.zero));
						}
						return val;
					}) : null)
				});
				Kit.CustomPlace[itemDef.Id] = Holding;
			}
			Kit.Created += LabStations.OnCreated;
			Kit.Removed += LabStations.OnRemoved;
			Kit.CanPickUp = (Placement.Placed p) => LabStations.CanPickUp(p);
			LabNet.Init();
			Kit.Busy = () => LabScreen.Open;
			LabProducts.Init();
			LabProducts.Patch(harmony);
			LabPack.Patch(harmony);
			LabOrderList.Patch(harmony);
			AnyListed.Init(def.Title);
			SenderFix.Init(def.Title);
			Host.Ok = true;
		}

		private static void Loaded()
		{
			LabPmPictures.Loaded();
			AnyListed.Loaded();
		}

		private static void Unloaded()
		{
			if (LabScreen.Open)
			{
				LabScreen.Close();
			}
			LabStations.Reset();
			LabWorkers.Reset();
			LabNpcs.Reset();
			LabProducts.Reset();
		}

		private static bool Holding(ItemSpec s, Camera cam, Player pl, out string hint)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			hint = null;
			if (Placement.Aim(cam, 3.5f, pl, out var best))
			{
				Placement.Placed placed = Placement.FindPlaced(((RaycastHit)(ref best)).collider);
				if (placed != null && Def.Station(placed.Spec.Id) != null && LabStations.TryUse(placed, best, out hint))
				{
					return true;
				}
			}
			string text = null;
			StationSpec[] stations = Def.Stations;
			foreach (StationSpec stationSpec in stations)
			{
				RecipeSpec[] recipes = stationSpec.Recipes;
				for (int j = 0; j < recipes.Length; j++)
				{
					InputSpec[] inputs = recipes[j].Inputs;
					for (int k = 0; k < inputs.Length; k++)
					{
						if (inputs[k].Item == s.Id)
						{
							text = stationSpec.Name;
							break;
						}
					}
				}
			}
			hint = ((text != null) ? $"{s.Name}: load it at a {text} (look at it and press {FortifyApi.UseKey})." : s.Name);
			return true;
		}

		public static void Update()
		{
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				LabPack.TryMake();
			}
			catch
			{
			}
			long t = (Perf.On ? Perf.Start() : 0);
			bool num = (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.Host")) && Host.Update();
			if (Perf.On)
			{
				Perf.Stop("DP.Host.Update", t);
			}
			if (!num)
			{
				return;
			}
			try
			{
				DP_HomeBrew.WoodKit.Ui.Capture();
			}
			catch
			{
			}
			try
			{
				if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.LabPack"))
				{
					long t2 = (Perf.On ? Perf.Start() : 0);
					LabPack.Update();
					if (Perf.On)
					{
						Perf.Stop("DP.LabPack.Update", t2);
					}
				}
				if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.LabProducts"))
				{
					long t3 = (Perf.On ? Perf.Start() : 0);
					LabProducts.Update();
					if (Perf.On)
					{
						Perf.Stop("DP.LabProducts.Update", t3);
					}
				}
				if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.LabPmPictures"))
				{
					long t4 = (Perf.On ? Perf.Start() : 0);
					LabPmPictures.Update();
					if (Perf.On)
					{
						Perf.Stop("DP.LabPmPictures.Update", t4);
					}
				}
				if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.LabStations"))
				{
					long t5 = (Perf.On ? Perf.Start() : 0);
					LabStations.Update();
					if (Perf.On)
					{
						Perf.Stop("DP.LabStations.Update", t5);
					}
				}
				if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.LabWorkers"))
				{
					long t6 = (Perf.On ? Perf.Start() : 0);
					LabWorkers.Update();
					if (Perf.On)
					{
						Perf.Stop("DP.LabWorkers.Update", t6);
					}
				}
				if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.LabScreen"))
				{
					long t7 = (Perf.On ? Perf.Start() : 0);
					LabScreen.Update();
					if (Perf.On)
					{
						Perf.Stop("DP.LabScreen.Update", t7);
					}
				}
				if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.LabNpcs"))
				{
					long t8 = (Perf.On ? Perf.Start() : 0);
					LabNpcs.Update();
					if (Perf.On)
					{
						Perf.Stop("DP.LabNpcs.Update", t8);
					}
				}
				if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.AnyListed"))
				{
					long t9 = (Perf.On ? Perf.Start() : 0);
					AnyListed.Update();
					if (Perf.On)
					{
						Perf.Stop("DP.AnyListed.Update", t9);
					}
				}
				if (FortifyApi.KeyHeld((KeyCode)306) || FortifyApi.KeyHeld((KeyCode)305) || FortifyApi.KeyDown((KeyCode)306) || FortifyApi.KeyDown((KeyCode)305))
				{
					_ctrlAt = Time.unscaledTime;
				}
				if (FortifyApi.DevKeys && Time.unscaledTime - _ctrlAt < 0.3f && FortifyApi.KeyDown(Def.DevKey))
				{
					if (LabStations.All.Count == 0)
					{
						DevPlace();
						DevGive();
					}
					else
					{
						DevOpen();
					}
				}
				LabNpcs.DevDump();
				StashRoute.DevTestOnce();
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime - _warnedAt > 30f)
				{
					_warnedAt = Time.unscaledTime;
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Warning(Def.Title + ": " + ex.Message);
					}
				}
			}
		}

		public static void OnGUI()
		{
			if (!Host.Ok || !FortifyApi.InGame)
			{
				return;
			}
			try
			{
				if (LabScreen.Open)
				{
					LabScreen.Draw();
					return;
				}
			}
			catch (Exception value)
			{
				if (!_guiWarned)
				{
					_guiWarned = true;
					Instance log = Kit.Log;
					if (log != null)
					{
						log.Warning($"{Def.Title}: the station screen ({value}).");
					}
				}
			}
			if (S2Core.DevSkip.Count <= 0 || !S2Core.DevSkip.Contains("DP.Hint"))
			{
				Host.DrawHint();
			}
		}

		public static void Sound(Placement.Placed p, bool start)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)p?.Go == (Object)null))
				{
					AudioSource.PlayClipAtPoint(start ? (_start ?? (_start = Tone("lab_start", new float[2] { 523f, 659f }, 0.16f))) : (_done ?? (_done = Tone("lab_done", new float[3] { 784f, 659f, 988f }, 0.14f))), p.Go.transform.position + Vector3.up, 0.45f);
				}
			}
			catch
			{
			}
		}

		public static void Done(LabStations.Station st)
		{
			Sound(st.P, start: false);
			if (st.Current != null && (st.Job == null || string.IsNullOrEmpty(st.Job.Worker)))
			{
				FortifyApi.Notify(Def.Title, $"The {st.Spec.Name} is done: {st.ReadyCount} ready to take.");
			}
		}

		private static AudioClip Tone(string name, float[] notes, float each)
		{
			int num = (int)(44100f * each);
			int num2 = num * notes.Length + 8820;
			float[] array = new float[num2];
			for (int i = 0; i < notes.Length; i++)
			{
				for (int j = 0; j < num + 8820 && i * num + j < num2; j++)
				{
					float num3 = (float)j / 44100f;
					float num4 = Mathf.Clamp01(num3 / 0.01f) * Mathf.Exp((0f - num3) * 9f);
					array[i * num + j] += (Mathf.Sin((float)Math.PI * 2f * notes[i] * num3) * 0.6f + Mathf.Sin((float)Math.PI * 4f * notes[i] * num3) * 0.15f) * num4 * 0.5f;
				}
			}
			AudioClip obj = Sfx.Create(Kit.Prefix + name, num2, 1, 44100, stream: false);
			Sfx.SetData(obj, new Il2CppStructArray<float>(array), 0);
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}

		public static void DevGive()
		{
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				StationSpec[] stations = Def.Stations;
				foreach (StationSpec stationSpec in stations)
				{
					if (stationSpec.Recipes.Length == 0)
					{
						continue;
					}
					RecipeSpec[] recipes = stationSpec.Recipes;
					foreach (RecipeSpec recipeSpec in recipes)
					{
						if (recipeSpec != stationSpec.Recipes[0] && !Array.Exists(recipeSpec.Inputs, (InputSpec x) => x.Type.HasValue))
						{
							continue;
						}
						InputSpec[] inputs = recipeSpec.Inputs;
						foreach (InputSpec inputSpec in inputs)
						{
							int n = inputSpec.Qty * 2;
							if (inputSpec.Item != null)
							{
								LabInv.Give(inputSpec.Item, -1, n);
							}
							else if (inputSpec.Product != null)
							{
								LabInv.Give(Def.Product(inputSpec.Product)?.Id, 3, n);
							}
							else if (inputSpec.AnyOfType)
							{
								LabInv.Give(LabInv.AnyOfTypeId((DrugType)(((??)inputSpec.Type) ?? Def.InputType)) ?? "ogkush", 3, n);
							}
						}
					}
				}
				PackagingDefinition item = Registry.GetItem<PackagingDefinition>("baggie");
				ProductDefinition val = ((Def.Products.Length != 0) ? Registry.GetItem<ProductDefinition>(Def.Products[Def.Products.Length - 1].Id) : null);
				if ((Object)(object)val != (Object)null)
				{
					if ((Object)(object)LabPack.Def != (Object)null)
					{
						LabInv.GiveProduct(val, 3, 2, LabPack.Def);
					}
					if ((Object)(object)item != (Object)null)
					{
						LabInv.GiveProduct(val, 3, 3, item);
					}
				}
				Instance log = Kit.Log;
				if (log != null)
				{
					log.Msg("Dev: " + Def.Title + " supplies.");
				}
			}
			catch (Exception ex)
			{
				Instance log2 = Kit.Log;
				if (log2 != null)
				{
					log2.Warning("Dev give: " + ex.Message);
				}
			}
		}

		public static void DevGiveAll()
		{
			ItemDef[] items = Def.Items;
			foreach (ItemDef itemDef in items)
			{
				LabInv.Give(itemDef.Id, -1, Math.Min(itemDef.Stack, 5));
			}
			if ((Object)(object)LabPack.Def != (Object)null)
			{
				LabInv.GiveItem((ItemDefinition)(object)LabPack.Def, 5);
			}
		}

		public static void DevPlace()
		{
			//IL_0029: 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_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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0095: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00dc: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0112: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Player local = Player.Local;
				Camera main = Camera.main;
				if ((Object)(object)local == (Object)null || (Object)(object)main == (Object)null)
				{
					return;
				}
				Vector3 forward = ((Component)