Decompiled source of BetterStoves v1.0.0

BetterStoves.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterStoves
{
	[BepInPlugin("com.dixiecapt.sailwind.betterstoves", "Better Stoves", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BetterStovesPlugin : BaseUnityPlugin
	{
		public const string Guid = "com.dixiecapt.sailwind.betterstoves";

		public const string Version = "1.0.0";

		internal static ConfigFile Cfg;

		internal static ManualLogSource Log;

		internal static string StripForeignBehaviours(GameObject go)
		{
			List<string> list = new List<string>();
			Assembly assembly = typeof(ShipItem).Assembly;
			Assembly assembly2 = typeof(BetterStovesPlugin).Assembly;
			MonoBehaviour[] componentsInChildren = go.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Assembly assembly3 = ((object)val).GetType().Assembly;
				if (!(assembly3 == assembly) && !(assembly3 == assembly2))
				{
					string name = assembly3.GetName().Name;
					if (!name.StartsWith("Assembly-CSharp") && !name.StartsWith("UnityEngine") && !name.StartsWith("Unity."))
					{
						list.Add(((object)val).GetType().Name + (((Object)(object)((Component)val).gameObject != (Object)(object)go) ? (" on " + ((Object)((Component)val).gameObject).name) : ""));
						Object.DestroyImmediate((Object)(object)val);
					}
				}
			}
			if (list.Count != 0)
			{
				return string.Join(", ", list.ToArray());
			}
			return "none";
		}

		internal static void KeepInDirectory(int index, GameObject template, string who)
		{
			try
			{
				PrefabsDirectory instance = PrefabsDirectory.instance;
				if ((Object)(object)instance == (Object)null || instance.directory == null || (Object)(object)template == (Object)null)
				{
					return;
				}
				if (instance.directory.Length <= index)
				{
					Array.Resize(ref instance.directory, index + 1);
				}
				if (!((Object)(object)instance.directory[index] == (Object)(object)template) && !((Object)(object)instance.directory[index] != (Object)null))
				{
					instance.directory[index] = template;
					if (instance.shipItems != null && instance.shipItems.Length > index)
					{
						instance.shipItems[index] = template.GetComponent<ShipItem>();
					}
					Log.LogWarning((object)(who + ": save number " + index + " had gone empty in the game's prefab list (another mod replaced the list) - put back."));
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)(who + " (keep): " + ex.Message));
			}
		}

		internal static Material FindGameGlass(string owner)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.shader == (Object)null))
				{
					string text = ((Object)val).name.ToLowerInvariant();
					string text2 = ((Object)val.shader).name.ToLowerInvariant();
					if (text.Contains("glass") && (text2.Contains("transparent") || text2.Contains("glass") || val.renderQueue >= 2900))
					{
						Material val2 = new Material(val);
						((Object)val2).name = owner + " glass (the game's " + ((Object)val).name + ")";
						Log.LogInfo((object)(owner + ": the game's glass for the pane setting is '" + ((Object)val).name + "' (" + ((Object)val.shader).name + ")."));
						return val2;
					}
				}
			}
			return null;
		}

		internal static void ApplyGlassTo(Transform root, string mode, string pieceName, Material clear, Material game)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			Transform val = root.Find(pieceName);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			if (!((Object)(object)component == (Object)null))
			{
				Material val2 = ((mode == "game" && (Object)(object)game != (Object)null) ? game : clear);
				((Renderer)component).enabled = mode != "none";
				if ((Object)(object)val2 != (Object)null && (Object)(object)((Renderer)component).sharedMaterial != (Object)(object)val2)
				{
					((Renderer)component).sharedMaterial = val2;
				}
			}
		}

		internal static void ShowPiece(Transform root, string pieceName, bool on)
		{
			if (!((Object)(object)root == (Object)null))
			{
				Transform val = root.Find(pieceName);
				if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeSelf != on)
				{
					((Component)val).gameObject.SetActive(on);
				}
			}
		}

		private void Update()
		{
			StoveLooks.Tick();
		}

		internal static float? FloorBelow(Vector3 p, float reach = 6f)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			CharacterController val = (((Object)(object)main != (Object)null) ? ((Component)main).GetComponentInParent<CharacterController>() : null);
			float? result = null;
			RaycastHit[] array = Physics.RaycastAll(p, Vector3.down, reach, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val2 = array[i];
				Collider collider = ((RaycastHit)(ref val2)).collider;
				if (!((Object)(object)collider == (Object)null) && !(collider is CharacterController) && (!((Object)(object)val != (Object)null) || (!((Object)(object)((Component)collider).transform == (Object)(object)((Component)val).transform) && !((Component)collider).transform.IsChildOf(((Component)val).transform))) && !((Object)(object)((Component)collider).GetComponentInParent<ShipItem>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<ItemRigidbody>() != (Object)null) && (!result.HasValue || ((RaycastHit)(ref val2)).point.y > result.Value))
				{
					result = ((RaycastHit)(ref val2)).point.y;
				}
			}
			return result;
		}

		public static void ScaleHeat(ShipItemStove __instance, ref float heat)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return;
				}
				int num;
				int num2;
				if ((Object)(object)((Component)__instance).GetComponent<TinyStoveItem>() != (Object)null)
				{
					num = 3;
					num2 = ((TinyStovePlugin.LogsAtOnce == null) ? 1 : TinyStovePlugin.LogsAtOnce.Value);
				}
				else if ((Object)(object)((Component)__instance).GetComponent<CabinStoveItem>() != (Object)null)
				{
					num = CabinStovePlugin.StockFuel;
					num2 = ((CabinStovePlugin.LogsAtOnce == null) ? 1 : CabinStovePlugin.LogsAtOnce.Value);
				}
				else if ((Object)(object)((Component)__instance).GetComponent<GRRange>() != (Object)null)
				{
					num = 3;
					num2 = ((GalleyRangePlugin.LogsAtOnce == null) ? 1 : GalleyRangePlugin.LogsAtOnce.Value);
				}
				else
				{
					HearthItem component;
					if (!((Object)(object)(component = ((Component)__instance).GetComponent<HearthItem>()) != (Object)null) || component.kind == null)
					{
						return;
					}
					num = 3;
					num2 = component.kind.LogsAtOnce.Value;
				}
				if (num2 < 1)
				{
					num2 = 1;
				}
				if (num > num2)
				{
					heat *= (float)num / (float)num2;
				}
			}
			catch (Exception)
			{
			}
		}

		private void Awake()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00bb: 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_00ff: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			Cfg = ((BaseUnityPlugin)this).Config;
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Better Stoves 1.0.0: the Tiny Stove, the Galley Range and the Cabin Stove, in one.");
			((Component)this).gameObject.AddComponent<TinyStovePlugin>();
			((Component)this).gameObject.AddComponent<GalleyRangePlugin>();
			((Component)this).gameObject.AddComponent<CabinStovePlugin>();
			((Component)this).gameObject.AddComponent<HearthStovesPlugin>();
			try
			{
				SaveWatch.Arm(new Harmony("com.dixiecapt.sailwind.betterstoves.savewatch"));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Save watch: could not arm - " + ex.Message));
			}
			try
			{
				StoveLooks.Arm(new Harmony("com.dixiecapt.sailwind.betterstoves.looks"));
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Stove looks: could not arm - " + ex2.Message));
			}
			try
			{
				new Harmony("com.dixiecapt.sailwind.betterstoves.heat").Patch((MethodBase)AccessTools.Method(typeof(ShipItemStove), "AddHeat", (Type[])null, (Type[])null), new HarmonyMethod(typeof(BetterStovesPlugin), "ScaleHeat", (Type[])null)
				{
					priority = 800
				}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex3)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Full heat: could not arm - " + ex3.Message));
			}
			try
			{
				SmallStoveRails.Arm(new Harmony("com.dixiecapt.sailwind.betterstoves.rails"));
			}
			catch (Exception ex4)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Small stove rails: could not arm - " + ex4.Message));
			}
			try
			{
				SoupSpoilFix.Arm(new Harmony("com.dixiecapt.sailwind.betterstoves.soupspoil"));
			}
			catch (Exception ex5)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Soup spoil fix: could not arm - " + ex5.Message));
			}
		}
	}
	internal static class SaveWatch
	{
		private static int _calls;

		public static void Arm(Harmony h)
		{
			//IL_0047: 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_0069: Expected O, but got Unknown
			//IL_0069: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			MethodBase methodBase = AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(SaveLoadManager), "DoSaveGame", (Type[])null, (Type[])null));
			if (methodBase == null)
			{
				BetterStovesPlugin.Log.LogWarning((object)"Save watch: the game's save coroutine was not found.");
				return;
			}
			h.Patch(methodBase, new HarmonyMethod(typeof(SaveWatch), "BeforeStep", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(SaveWatch), "AfterStep", (Type[])null), (HarmonyMethod)null);
			MethodBase methodBase2 = AccessTools.Method(typeof(ShipItem), "DestroyItem", (Type[])null, (Type[])null);
			if (methodBase2 != null)
			{
				h.Patch(methodBase2, (HarmonyMethod)null, new HarmonyMethod(typeof(SaveWatch), "AfterDestroyItem", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			BetterStovesPlugin.Log.LogInfo((object)"Save watch: armed on the game's save coroutine (reports before each save, and the stage if a save dies); child items are unregistered with a destroyed item.");
		}

		public static void AfterDestroyItem(ShipItem __instance, bool __runOriginal)
		{
			try
			{
				if (!__runOriginal || __instance == null)
				{
					return;
				}
				int num = 0;
				SaveablePrefab[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<SaveablePrefab>(true);
				foreach (SaveablePrefab val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)(object)((Component)__instance).gameObject))
					{
						try
						{
							val.Unregister();
							num++;
						}
						catch (Exception)
						{
						}
					}
				}
				if (num > 0)
				{
					BetterStovesPlugin.Log.LogInfo((object)("Save watch: '" + __instance.name + "' is being destroyed with " + num + " item(s) inside it - they leave the save list with it."));
				}
			}
			catch (Exception ex2)
			{
				BetterStovesPlugin.Log.LogWarning((object)("Save watch (destroy): " + ex2.Message));
			}
		}

		private static bool IsNull(Object o)
		{
			return o == null;
		}

		public static void BeforeStep(object __instance)
		{
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Traverse.Create(__instance).Field("<>1__state").GetValue<int>() != 0)
				{
					return;
				}
				_calls++;
				SaveLoadManager instance = SaveLoadManager.instance;
				if ((Object)(object)instance == (Object)null)
				{
					BetterStovesPlugin.Log.LogWarning((object)"Save watch: no SaveLoadManager at save time.");
					return;
				}
				StringBuilder stringBuilder = new StringBuilder();
				List<SaveablePrefab> currentPrefabs = instance.GetCurrentPrefabs();
				int num = 0;
				int num2 = 0;
				int num3 = 0;
				int num4 = 0;
				if (currentPrefabs != null)
				{
					for (int num5 = currentPrefabs.Count - 1; num5 >= 0; num5--)
					{
						SaveablePrefab val = currentPrefabs[num5];
						if (IsNull((Object)(object)val))
						{
							num++;
							currentPrefabs.RemoveAt(num5);
						}
						else if ((Object)(object)val == (Object)null)
						{
							num2++;
							currentPrefabs.RemoveAt(num5);
						}
						else
						{
							if (val.prefabIndex >= 32701 && val.prefabIndex <= 32706)
							{
								num3++;
							}
							if ((Object)(object)((Component)val).GetComponent<ShipItem>() == (Object)null)
							{
								num4++;
								stringBuilder.Append(" [no ShipItem: ").Append(((Object)val).name).Append(" #")
									.Append(val.prefabIndex)
									.Append("]");
							}
						}
					}
				}
				int num6 = 0;
				if (currentPrefabs != null)
				{
					for (int num7 = currentPrefabs.Count - 1; num7 >= 0; num7--)
					{
						SaveablePrefab val2 = currentPrefabs[num7];
						try
						{
							val2.PrepareSaveData();
						}
						catch (Exception ex)
						{
							num6++;
							currentPrefabs.RemoveAt(num7);
							ManualLogSource log = BetterStovesPlugin.Log;
							string[] obj = new string[14]
							{
								"Save watch: '",
								((Object)val2).name,
								"' (save number ",
								val2.prefabIndex.ToString(),
								", parent object ",
								val2.GetParentObject().ToString(),
								", at ",
								null,
								null,
								null,
								null,
								null,
								null,
								null
							};
							Vector3 position = ((Component)val2).transform.position;
							obj[7] = ((Vector3)(ref position)).ToString("F1");
							obj[8] = ") cannot be saved - ";
							obj[9] = ex.GetType().Name;
							obj[10] = ": ";
							obj[11] = ex.Message;
							obj[12] = " - SET ASIDE so the save goes on; it will be missing on the next load. ";
							obj[13] = ex.StackTrace;
							log.LogError((object)string.Concat(obj));
						}
					}
				}
				stringBuilder.Append((num6 > 0) ? (" [" + num6 + " SET ASIDE]") : "");
				SaveableObject[] currentObjects = instance.GetCurrentObjects();
				int num8 = 0;
				int num9 = ((currentObjects != null) ? currentObjects.Length : (-1));
				if (currentObjects != null)
				{
					SaveableObject[] array = currentObjects;
					for (int i = 0; i < array.Length; i++)
					{
						if ((Object)(object)array[i] == (Object)null)
						{
							num8++;
						}
					}
				}
				Traverse val3 = Traverse.Create((object)instance);
				TraderBoat[] value = val3.Field("traderBoats").GetValue<TraderBoat[]>();
				int num10 = 0;
				if (value != null)
				{
					TraderBoat[] array2 = value;
					foreach (TraderBoat val4 in array2)
					{
						if (IsNull((Object)(object)val4) || (Object)(object)val4 == (Object)null)
						{
							num10++;
						}
					}
				}
				NPCBoatController[] value2 = val3.Field("npcBoats").GetValue<NPCBoatController[]>();
				int num11 = 0;
				if (value2 != null)
				{
					NPCBoatController[] array3 = value2;
					foreach (NPCBoatController val5 in array3)
					{
						if (IsNull((Object)(object)val5) || (Object)(object)val5 == (Object)null)
						{
							num11++;
						}
					}
				}
				int num12 = 0;
				int num13 = 0;
				int num14 = 0;
				if (Port.ports != null)
				{
					Port[] ports = Port.ports;
					foreach (Port val6 in ports)
					{
						if ((Object)(object)val6 == (Object)null)
						{
							num12++;
							continue;
						}
						if ((Object)(object)val6.island == (Object)null)
						{
							num13++;
						}
						if ((Object)(object)((Component)val6).GetComponent<IslandMarket>() == (Object)null)
						{
							num14++;
						}
					}
				}
				int num15 = 0;
				if (PlayerMissions.missions != null)
				{
					Mission[] missions = PlayerMissions.missions;
					for (int i = 0; i < missions.Length; i++)
					{
						if (missions[i] == null)
						{
							num15++;
						}
					}
				}
				string text = (((Object)(object)MissionLog.instance == (Object)null) ? " MissionLog" : "") + (((Object)(object)DayLogs.instance == (Object)null) ? " DayLogs" : "") + (((Object)(object)CurrencyMarket.instance == (Object)null) ? " CurrencyMarket" : "") + (((Object)(object)Quests.instance == (Object)null) ? " Quests" : "") + (((Object)(object)ItemSpawners.instance == (Object)null) ? " ItemSpawners" : "") + (((Object)(object)TradeReceiptsUI.instance == (Object)null) ? " TradeReceiptsUI" : "") + (((Object)(object)PlayerTobacco.instance == (Object)null) ? " PlayerTobacco" : "") + (((Object)(object)Moon.instance == (Object)null) ? " Moon" : "") + (((Object)(object)Sun.sun == (Object)null) ? " Sun" : "") + (((Object)(object)FloatingOriginManager.instance == (Object)null) ? " FloatingOrigin" : "") + (((Object)(object)CrateInventoryUI.instance == (Object)null) ? " CrateInventoryUI" : "");
				int num16 = (((Object)(object)DayLogs.instance != (Object)null && DayLogs.instance.dayLogs != null) ? DayLogs.instance.dayLogs.Length : (-1));
				int num17 = 0;
				if (num16 > 0)
				{
					DayLog[] dayLogs = DayLogs.instance.dayLogs;
					for (int i = 0; i < dayLogs.Length; i++)
					{
						if (dayLogs[i] == null)
						{
							num17++;
						}
					}
				}
				int num18 = ((PlayerGold.currency != null) ? PlayerGold.currency.Length : (-1));
				BetterStovesPlugin.Log.LogInfo((object)("Save watch #" + _calls + ": prefabs " + (currentPrefabs?.Count ?? (-1)) + " (ours " + num3 + "; removed " + num + " plain null, " + num2 + " destroyed; " + num4 + " without a ShipItem" + stringBuilder?.ToString() + "); scene objects " + num9 + " (" + num8 + " empty); trader boats " + ((value != null) ? value.Length : (-1)) + " (" + num10 + " null); npc boats " + ((value2 != null) ? value2.Length : (-1)) + " (" + num11 + " null); ports " + ((Port.ports != null) ? Port.ports.Length : (-1)) + " (" + num12 + " null, " + num13 + " without island, " + num14 + " without market); missions " + ((PlayerMissions.missions != null) ? PlayerMissions.missions.Length : (-1)) + " (" + num15 + " empty); day logs " + num16 + " (" + num17 + " null) for " + num18 + " currencies; mod data " + ((GameState.modData == null) ? "NULL" : GameState.modData.Count.ToString()) + "; missing singletons:" + ((text.Length == 0) ? " none" : text) + "."));
			}
			catch (Exception ex2)
			{
				BetterStovesPlugin.Log.LogWarning((object)("Save watch (before): " + ex2));
			}
		}

		public static Exception AfterStep(Exception __exception, object __instance)
		{
			if (__exception == null)
			{
				return null;
			}
			try
			{
				SaveContainer val = null;
				FieldInfo[] fields = __instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (fieldInfo.FieldType == typeof(SaveContainer))
					{
						object? value = fieldInfo.GetValue(__instance);
						val = (SaveContainer)((value is SaveContainer) ? value : null);
						break;
					}
				}
				string text = ((val != null) ? ("container: marketsSupply " + ((val.marketsSupply == null) ? "NOT SET" : "set") + ", traderBoatData " + ((val.traderBoatData == null) ? "NOT SET" : val.traderBoatData.Length.ToString()) + ", npcBoatData " + ((val.npcBoatData == null) ? "NOT SET" : val.npcBoatData.Length.ToString()) + ", savedObjects " + ((val.savedObjects == null) ? "null" : val.savedObjects.Count.ToString()) + ", savedPrefabs " + ((val.savedPrefabs == null) ? "null" : val.savedPrefabs.Count.ToString()) + ", savedMissions " + ((val.savedMissions == null) ? "NOT SET" : "set") + ", portDemands " + ((val.portDemands == null) ? "NOT SET" : "set") + ", loggedMissions " + ((val.loggedMissions == null) ? "NOT SET" : "set") + ", currencyDayLogs[0] " + ((val.currencyDayLogs == null || val.currencyDayLogs.Length == 0 || val.currencyDayLogs[0] == null) ? "NOT SET" : "set") + ", modData " + ((val.modData == null) ? "NOT SET" : "set") + " - the save died right after the last SET item") : "no save container yet (died at the very start: the crate inventory UI or the first frame)");
				BetterStovesPlugin.Log.LogError((object)("Save watch: THE SAVE DIED - " + __exception.GetType().Name + ": " + __exception.Message + " | " + text + " | " + __exception.StackTrace));
			}
			catch (Exception ex)
			{
				BetterStovesPlugin.Log.LogWarning((object)("Save watch (after): " + ex.Message));
			}
			return __exception;
		}
	}
	internal static class BoilerHook
	{
		internal const string HhmGuid = "com.raddude.hookshangmore";

		private const float HookOut = 0.128f;

		internal static void Arm(Harmony h, string name)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("HooksHangMore.HHM_Plugin");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "AddHangingOffset", (Type[])null, (Type[])null) : null);
			if (methodInfo == null)
			{
				BetterStovesPlugin.Log.LogInfo((object)"Galley Range: HooksHangMore is not loaded - the copper boiler hangs on no hook.");
				return;
			}
			string[] array = new string[2]
			{
				name,
				name + "(Clone)"
			};
			foreach (string text in array)
			{
				methodInfo.Invoke(null, new object[5]
				{
					text,
					(object)new Vector3(0f, -0.48f, -0.12f),
					Vector3.zero,
					true,
					true
				});
			}
			h.Patch((MethodBase)AccessTools.Method(typeof(HangableItem), "LateUpdate", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BoilerHook), "AfterHangLateUpdate", (Type[])null)
			{
				priority = 0
			}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			BetterStovesPlugin.Log.LogInfo((object)"Galley Range: the copper boiler hangs on hooks (HooksHangMore), by its lid's handle.");
		}

		public static void AfterHangLateUpdate(HangableItem __instance, Collider ___currentHook)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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)
			//IL_00a6: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)___currentHook == (Object)null)
			{
				return;
			}
			try
			{
				if ((Object)(object)((Component)__instance).GetComponent<GRBoiler>() == (Object)null)
				{
					return;
				}
				MeshFilter component = ((Component)__instance).GetComponent<MeshFilter>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
				{
					Bounds bounds = component.sharedMesh.bounds;
					Transform transform = ((Component)___currentHook).transform;
					Vector3 val = Vector3.ProjectOnPlane(-transform.forward, Vector3.up);
					if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
					{
						((Vector3)(ref val)).Normalize();
						Vector3 val2 = default(Vector3);
						((Vector3)(ref val2))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y - 0.01f, ((Bounds)(ref bounds)).center.z);
						float num = Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.z);
						float num2 = Mathf.Max(0.01f, val2.y - GalleyRangePlugin.BoilerTopY);
						float num3 = Mathf.Sqrt(num2 * num2 + num * num);
						float num4 = Mathf.Clamp(0.11800001f / num3, -1f, 1f);
						float num5 = Mathf.Clamp((Mathf.Atan2(num, num2) - Mathf.Asin(num4)) * 57.29578f, 0f, 60f);
						Quaternion val3 = Quaternion.LookRotation(val, Vector3.up) * Quaternion.Euler(0f - num5, 0f, 0f);
						Vector3 val4 = transform.position - transform.forward * 0.128f;
						((Component)__instance).transform.SetPositionAndRotation(val4 - val3 * val2, val3);
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}
	public class CabinStovePlugin : MonoBehaviour
	{
		public const string Guid = "com.dixiecapt.sailwind.cabinstove";

		public const string Version = "0.1.0";

		internal const int StoveIndex = 32704;

		private const int AlAnkhStove = 107;

		private const string BundleFile = "cabinstove";

		private const string ItemName = "cabin stove";

		private const float PotBottom = 0.08f;

		internal static CabinStovePlugin Instance;

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> ChimneyDefault;

		internal static ConfigEntry<float> ShopAlong;

		internal static ConfigEntry<float> ShopSide;

		internal static ConfigEntry<float> StoveSize;

		internal static ConfigEntry<bool> SellAtStoveShops;

		internal static ConfigEntry<bool> ReportShapes;

		internal static ConfigEntry<bool> MarkSpot;

		internal static ConfigEntry<bool> UseMarked;

		internal static ConfigEntry<float> SpotX;

		internal static ConfigEntry<float> SpotZ;

		internal static ConfigEntry<float> SpotYaw;

		internal static ConfigEntry<float> LoadHours;

		internal static ConfigEntry<int> LogsAtOnce;

		internal static ConfigEntry<int> Firewood;

		internal static int StockFuel = 3;

		internal static ConfigEntry<string> MarkedShop;

		internal static ConfigEntry<string> GlassMode;

		internal static ConfigEntry<bool> PotRail;

		internal static StoveLooks.Look LookChimney;

		internal static StoveLooks.Look LookGlass;

		internal static StoveLooks.Look LookRail;

		private static Material _glassGame;

		private static GameObject _template;

		private static Transform _holder;

		private static bool _repopulating;

		private static bool _gaveUp;

		private static AssetBundle _bundle;

		private static GameObject _pieces;

		private static Material _iron;

		private static Material _brass;

		private static Material _soot;

		private static Material _glass;

		private static Material _pipe;

		private static Material _wood;

		private static float _scale = 1f;

		private static readonly Dictionary<string, Mesh> _scaled = new Dictionary<string, Mesh>();

		private static int _logOrder;

		private float _nextShopCheck;

		private const string SpotName = "cabin stove (shop spot)";

		private readonly List<Transform> _shopsDone = new List<Transform>();

		private static readonly int[] StockStoves = new int[1] { 107 };

		private ConfigFile Config => BetterStovesPlugin.Cfg;

		private ManualLogSource Logger => BetterStovesPlugin.Log;

		private static void ApplyRail()
		{
			if ((Object)(object)_template != (Object)null)
			{
				BetterStovesPlugin.ShowPiece(_template.transform, "cabin_rail", StoveLooks.Default<bool>(LookRail));
			}
		}

		private static void ApplyGlass()
		{
			if ((Object)(object)_template != (Object)null)
			{
				DressPane(_template.transform, StoveLooks.Default<string>(LookGlass));
			}
		}

		internal static void DressPane(Transform root, string mode)
		{
			if ((Object)(object)_glassGame == (Object)null && mode == "game")
			{
				_glassGame = BetterStovesPlugin.FindGameGlass("Cabin Stove");
			}
			BetterStovesPlugin.ApplyGlassTo(root, mode, "cabin_glass", _glass, _glassGame);
		}

		private void Awake()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Expected O, but got Unknown
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Expected O, but got Unknown
			//IL_040a: Expected O, but got Unknown
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Expected O, but got Unknown
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Expected O, but got Unknown
			//IL_048a: Expected O, but got Unknown
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Expected O, but got Unknown
			Instance = this;
			Log = Logger;
			StoveSize = Config.Bind<float>("Cabin Stove", "Stove size", 1f, new ConfigDescription("How big the cabin stove is, as a share of the model: 1 = 0.75 m wide and 0.93 m to the top, 0.8 = 0.60 m wide. Takes effect when the game is next started.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 1.5f), Array.Empty<object>()));
			ChimneyDefault = Config.Bind<float>("Cabin Stove", "Chimney length (m)", 0.8f, new ConfigDescription("How tall the pipe stands above the stove's collar. Changes at once: within 2 m of a stove you own, that stove only; anywhere else, every stove not set by hand and the ones for sale.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 3f), Array.Empty<object>()));
			LookChimney = StoveLooks.Add<float>(Config, ChimneyDefault, "cabin.chimney", "cabin stove's chimney", typeof(CabinStoveItem));
			Firewood = Config.Bind<int>("Cabin Stove", "Firewood it holds", 6, new ConfigDescription("Pieces of firewood the firebox takes, read when the game starts.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(3, 9), Array.Empty<object>()));
			LoadHours = Config.Bind<float>("Cabin Stove", "Hours a full load burns", 12f, new ConfigDescription("How long a full load of logs lasts, in game hours, burnt one after another. The game's open stoves get 2 hours a log; a closed stove makes its wood go further. The heat on the pots is the same.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 48f), Array.Empty<object>()));
			LogsAtOnce = Config.Bind<int>("Cabin Stove", "Logs burning at once", 1, new ConfigDescription("How many logs burn at the same time; the rest wait their turn. The pots get a full stock stove's heat either way, so this only sets how fast the wood goes: 1 = a load that lasts longest; 3 = wood burnt as fast as on the game's stoves.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), Array.Empty<object>()));
			SellAtStoveShops = Config.Bind<bool>("Cabin Stove", "Sell at the stove seller", true, "Put a cabin stove out beside the stock Al'Ankh stoves wherever they are sold, at the Al'Ankh stove's price.");
			ShopAlong = Config.Bind<float>("Cabin Stove", "Spot along the stove row (m)", 1.2f, "How far past the end stock stove our stove's spot is, along the same row. Move it if it lands in something.");
			ShopSide = Config.Bind<float>("Cabin Stove", "Spot sideways (m)", 0f, "Moves our stove's spot sideways off the row, in metres.");
			MarkSpot = Config.Bind<bool>("Cabin Stove", "Mark the spot where I stand", false, "Switch on while standing in a port shop where the stove should stand for sale, facing the way its door should face. The spot moves there at once and the switch goes off again.");
			UseMarked = Config.Bind<bool>("Cabin Stove", "Use the marked spot", false, "Set by the mark above. Off = the spot is found along the stock stove row.");
			MarkedShop = Config.Bind<string>("Cabin Stove", "Marked spot shop", "", "Which port scenery the mark was made in; set by the mark.");
			SpotX = Config.Bind<float>("Cabin Stove", "Marked spot x", 0f, "In the port scenery frame, set by the mark.");
			SpotZ = Config.Bind<float>("Cabin Stove", "Marked spot z", 0f, "");
			SpotYaw = Config.Bind<float>("Cabin Stove", "Marked spot facing", 0f, "");
			GlassMode = Config.Bind<string>("Cabin Stove", "Glass pane", "clear", new ConfigDescription("What the door's pane is drawn with: none = no pane at all; clear = an all but invisible pane; game = the game's own glass as it is. Changes at once: within 2 m of a stove you own, that stove only; anywhere else, every stove not set by hand and the ones for sale.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "none", "clear", "game" }), Array.Empty<object>()));
			LookGlass = StoveLooks.Add<string>(Config, GlassMode, "cabin.glass", "cabin stove's glass pane", typeof(CabinStoveItem), null, delegate
			{
				try
				{
					ApplyGlass();
				}
				catch (Exception)
				{
				}
			});
			PotRail = Config.Bind<bool>("Cabin Stove", "Pot rail", true, "The safety rail round the top that keeps the pots from sliding off in a seaway. Switch it off for a stove ashore. Changes at once: within 2 m of a stove you own, that stove only; anywhere else, every stove not set by hand and the ones for sale.");
			LookRail = StoveLooks.Add<bool>(Config, PotRail, "cabin.rail", "cabin stove's pot rail", typeof(CabinStoveItem), null, delegate
			{
				try
				{
					ApplyRail();
				}
				catch (Exception)
				{
				}
			});
			ReportShapes = Config.Bind<bool>("Cabin Stove", "Report each stove shape", true, "Three seconds after a stove appears, the first three write a line to the log saying where their picture, pointing box and physics body are. For bug reports; switch off once all is well.");
			LoadBundle();
			try
			{
				Harmony val = new Harmony("com.dixiecapt.sailwind.cabinstove");
				val.Patch((MethodBase)AccessTools.Method(typeof(PrefabsDirectory), "PopulateShipItems", (Type[])null, (Type[])null), new HarmonyMethod(typeof(CabinStovePlugin), "BeforePopulate", (Type[])null), new HarmonyMethod(typeof(CabinStovePlugin), "AfterPopulate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				val.Patch((MethodBase)AccessTools.Method(typeof(StoveFuelTrigger), "InsertFuel", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(CabinStovePlugin), "AfterInsertFuel", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				val.Patch((MethodBase)AccessTools.Method(typeof(StoveFuel), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(CabinStovePlugin), "BeforeFuelUpdate", (Type[])null), new HarmonyMethod(typeof(CabinStovePlugin), "AfterFuelUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				val.Patch((MethodBase)AccessTools.Method(typeof(ShipItem), "OnDrop", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(CabinStovePlugin), "AfterDrop", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Logger.LogInfo((object)("Cabin Stove 0.1.0: armed (save number " + 32704 + ")."));
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Cabin Stove: could not patch the game - " + ex));
			}
		}

		private void LoadBundle()
		{
			string text = Path.Combine(Path.GetDirectoryName(typeof(CabinStovePlugin).Assembly.Location) ?? "", "cabinstove");
			if (!File.Exists(text))
			{
				Logger.LogError((object)("Cabin Stove: NO BUNDLE - the file 'cabinstove' must sit beside BetterStoves.dll, at " + text + ". Without it there is no stove, and a save that holds one will not load."));
				return;
			}
			try
			{
				_bundle = AssetBundle.LoadFromFile(text);
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Cabin Stove: bundle would not open - " + ex.Message));
			}
			if ((Object)(object)_bundle == (Object)null)
			{
				Logger.LogError((object)"Cabin Stove: bundle loaded as nothing (built with the wrong Unity? Sailwind needs 2019.1.10).");
				return;
			}
			string[] allAssetNames = _bundle.GetAllAssetNames();
			foreach (string text2 in allAssetNames)
			{
				if (text2.EndsWith(".fbx"))
				{
					_pieces = _bundle.LoadAsset<GameObject>(text2);
				}
			}
			if ((Object)(object)_pieces == (Object)null)
			{
				Logger.LogError((object)"Cabin Stove: the bundle holds no stove model.");
				return;
			}
			Logger.LogInfo((object)("Cabin Stove: bundle opened, model '" + ((Object)_pieces).name + "' with " + _pieces.transform.childCount + " piece(s)."));
		}

		private static Transform Piece(string name)
		{
			if ((Object)(object)_pieces == (Object)null)
			{
				return null;
			}
			Transform[] componentsInChildren = _pieces.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}

		private static Mesh MeshOf(string name)
		{
			Transform val = Piece(name);
			MeshFilter val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<MeshFilter>() : null);
			if (!((Object)(object)val2 != (Object)null))
			{
				return null;
			}
			return val2.sharedMesh;
		}

		private static Vector3 Mark(string name, Vector3 fallback)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Piece(name);
			if (!((Object)(object)val != (Object)null))
			{
				return fallback;
			}
			return val.localPosition;
		}

		private static void MakeMaterials()
		{
			//IL_0031: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_iron != (Object)null))
			{
				Shader std = Shader.Find("Standard");
				Func<Color, float, float, Material> obj = delegate(Color c, float metal, float gloss)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0012: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					//IL_002b: Expected O, but got Unknown
					Material val2 = new Material(std)
					{
						color = c
					};
					val2.SetFloat("_Metallic", metal);
					val2.SetFloat("_Glossiness", gloss);
					return val2;
				};
				_iron = obj(Color.white, 0.42f, 0.2f);
				((Object)_iron).name = "cabin stove cast iron";
				_iron.mainTexture = (Texture)(object)ScuffTexture(512, 0.05f, 0.5f);
				_pipe = obj(new Color(0.09f, 0.088f, 0.086f), 0.4f, 0.3f);
				((Object)_pipe).name = "cabin stove pipe";
				Texture2D val = PitNormals(256);
				_iron.SetTexture("_BumpMap", (Texture)(object)val);
				_iron.SetFloat("_BumpScale", 0.12f);
				_iron.EnableKeyword("_NORMALMAP");
				_iron.mainTextureScale = new Vector2(1f, 1f);
				_brass = obj(new Color(0.702f, 0.584f, 0.353f), 0.85f, 0.72f);
				((Object)_brass).name = "cabin stove brass";
				_soot = obj(new Color(0.045f, 0.035f, 0.03f), 0f, 0.02f);
				((Object)_soot).name = "cabin stove soot";
				_wood = obj(Color.white, 0f, 0.3f);
				((Object)_wood).name = "cabin stove handle wood";
				_wood.mainTexture = (Texture)(object)WoodTexture(256);
				_glass = GlassMaterial();
			}
		}

		internal static Texture2D ScuffTexture(int n, float rustAmount, float wear = 1f)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(n, n, (TextureFormat)4, true);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val).anisoLevel = 4;
			Color[] array = (Color[])(object)new Color[n * n];
			wear = Mathf.Clamp01(wear);
			Color val2 = Color.Lerp(new Color(0.06f, 0.058f, 0.056f), new Color(0.105f, 0.1f, 0.096f), wear);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.3f, 0.17f, 0.09f);
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.05f, 0.048f, 0.046f);
			Color val5 = Color.Lerp(new Color(0.105f, 0.102f, 0.099f), new Color(0.15f, 0.148f, 0.145f), wear);
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
				{
					float num = (float)j / (float)n;
					float num2 = (float)i / (float)n;
					float num3 = Mathf.PerlinNoise(num * 5f + 3.1f, num2 * 5f + 7.3f);
					float num4 = Mathf.PerlinNoise(num * 38f + 11.2f, num2 * 38f + 5.7f);
					float num5 = Mathf.PerlinNoise(num * 110f + 2.3f, num2 * 110f + 9.1f);
					float num6 = 0.9f + 0.1f * num3 * wear + 0.05f * (num4 - 0.5f) + 0.04f * (num5 - 0.5f);
					Color val6 = Color.Lerp(val2 * num6, val5, 0.25f * num3 * wear);
					if (num5 > 0.86f)
					{
						val6 = Color.Lerp(val6, val4 * Mathf.Lerp(0.6f, 1f, wear), 0.35f);
					}
					float num7 = Mathf.Clamp01((Mathf.PerlinNoise(num * 7f + 21.4f, num2 * 7f + 17.9f) - 0.66f) * 3f) * (0.4f + 0.6f * num4);
					val6 = Color.Lerp(val6, val3 * (0.8f + 0.4f * num5), num7 * rustAmount * 2f);
					val6.a = 1f;
					array[i * n + j] = val6;
				}
			}
			val.SetPixels(array);
			val.Apply(true, true);
			return val;
		}

		internal static Texture2D WoodTexture(int n)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_00db: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(n, n, (TextureFormat)4, true);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)2;
			Color[] array = (Color[])(object)new Color[n * n];
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.34f, 0.2f, 0.09f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.16f, 0.08f, 0.035f);
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
				{
					float num = (float)j / (float)n;
					float num2 = (float)i / (float)n;
					float num3 = Mathf.PerlinNoise(num * 3f + 5.5f, num2 * 9f + 2.2f) * 0.25f;
					float num4 = Mathf.Pow(Mathf.Sin((num + num3) * 60f) * 0.5f + 0.5f, 3f);
					float num5 = Mathf.PerlinNoise(num * 2f + 9.9f, num2 * 2f + 4.4f);
					Color val4 = Color.Lerp(val2, val3, 0.25f + 0.55f * num4 + 0.2f * num5);
					val4.a = 1f;
					array[i * n + j] = val4;
				}
			}
			val.SetPixels(array);
			val.Apply(true, true);
			return val;
		}

		internal static Texture2D PitNormals(int n)
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			float[] array = new float[n * n];
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
				{
					float num = (float)j / (float)n;
					float num2 = (float)i / (float)n;
					float num3 = Mathf.PerlinNoise(num * 60f + 4.4f, num2 * 60f + 8.8f) * 0.5f + Mathf.PerlinNoise(num * 14f + 1.1f, num2 * 14f + 3.3f) * 0.5f;
					float num4 = Mathf.PerlinNoise(num * 120f + 6.6f, num2 * 120f + 2.2f);
					array[i * n + j] = num3 - ((num4 > 0.72f) ? ((num4 - 0.72f) * 3f) : 0f);
				}
			}
			Texture2D val = new Texture2D(n, n, (TextureFormat)4, true, true);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)2;
			Color[] array2 = (Color[])(object)new Color[n * n];
			for (int k = 0; k < n; k++)
			{
				for (int l = 0; l < n; l++)
				{
					float num5 = array[k * n + (l + 1) % n] - array[k * n + (l + n - 1) % n];
					float num6 = array[(k + 1) % n * n + l] - array[(k + n - 1) % n * n + l];
					Vector3 val2 = new Vector3((0f - num5) * 6f, (0f - num6) * 6f, 1f);
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					array2[k * n + l] = new Color(normalized.x * 0.5f + 0.5f, normalized.y * 0.5f + 0.5f, normalized.z * 0.5f + 0.5f, 1f);
				}
			}
			val.SetPixels(array2);
			val.Apply(true, true);
			return val;
		}

		internal static Material UnlitPane(string owner)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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)
			Color val = default(Color);
			((Color)(ref val))..ctor(0.85f, 0.88f, 0.92f, 0.015f);
			string[] array = new string[5] { "Unlit/Transparent", "Sprites/Default", "UI/Default", "Legacy Shaders/Transparent/Diffuse", "Mobile/Particles/Alpha Blended" };
			foreach (string text in array)
			{
				Shader val2 = Shader.Find(text);
				if (!((Object)(object)val2 == (Object)null) && val2.isSupported)
				{
					Material val3 = new Material(val2);
					if (text == "Unlit/Transparent" || text == "Mobile/Particles/Alpha Blended")
					{
						Texture2D val4 = new Texture2D(2, 2, (TextureFormat)4, false);
						val4.SetPixels((Color[])(object)new Color[4] { val, val, val, val });
						val4.Apply();
						val3.mainTexture = (Texture)(object)val4;
					}
					if (val3.HasProperty("_Color"))
					{
						val3.color = val;
					}
					if (val3.HasProperty("_TintColor"))
					{
						val3.SetColor("_TintColor", val);
					}
					val3.renderQueue = 3000;
					((Object)val3).name = owner + " glass";
					Instance.Logger.LogInfo((object)(owner + ": glass is an unlit pane on '" + text + "'."));
					return val3;
				}
			}
			return null;
		}

		private static Material GallusGlass(string owner)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.shader == (Object)null) && ((Object)val).name.StartsWith("GAL_glass"))
				{
					Material val2 = new Material(val);
					((Object)val2).name = owner + " glass (Gallus)";
					Instance.Logger.LogInfo((object)(owner + ": glass is the Gallus skylight's own '" + ((Object)val).name + "' (" + ((Object)val.shader).name + ", queue " + val.renderQueue + ")."));
					return val2;
				}
			}
			return null;
		}

		private static Material GlassMaterial()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Expected O, but got Unknown
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			Material val = GallusGlass("Cabin Stove");
			if ((Object)(object)val == (Object)null)
			{
				val = UnlitPane("Cabin Stove");
			}
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Shader val2 = Shader.Find("Standard");
			if ((Object)(object)val2 != (Object)null)
			{
				Material val3 = new Material(val2);
				val3.SetFloat("_Mode", 3f);
				val3.SetInt("_SrcBlend", 1);
				val3.SetInt("_DstBlend", 10);
				val3.SetInt("_ZWrite", 0);
				val3.DisableKeyword("_ALPHATEST_ON");
				val3.DisableKeyword("_ALPHABLEND_ON");
				val3.EnableKeyword("_ALPHAPREMULTIPLY_ON");
				val3.renderQueue = 3000;
				val3.color = new Color(0.68f, 0.72f, 0.755f, 0.05f);
				val3.SetFloat("_Metallic", 0.03f);
				val3.SetFloat("_Glossiness", 0f);
				((Object)val3).name = "cabin stove glass";
				Instance.Logger.LogInfo((object)"Cabin Stove: glass set like Kemy's telescope glass (transparent, no gloss, alpha 0.05).");
				return val3;
			}
			Material val4 = null;
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val5 in array)
			{
				if (!((Object)(object)val5 == (Object)null) && !((Object)(object)val5.shader == (Object)null))
				{
					string text = ((Object)val5).name.ToLowerInvariant();
					string text2 = ((Object)val5.shader).name.ToLowerInvariant();
					if (text.Contains("glass") && (text2.Contains("transparent") || text2.Contains("glass") || val5.renderQueue >= 2900))
					{
						val4 = val5;
						break;
					}
				}
			}
			Material val6;
			if ((Object)(object)val4 != (Object)null)
			{
				val6 = new Material(val4);
				if (val6.HasProperty("_Color"))
				{
					val6.color = new Color(1f, 1f, 1f, 0.07f);
				}
				if (val6.HasProperty("_Glossiness"))
				{
					val6.SetFloat("_Glossiness", 0.95f);
				}
				Instance.Logger.LogInfo((object)("Cabin Stove: glass copied from the game's '" + ((Object)val4).name + "' (" + ((Object)val4.shader).name + ")."));
			}
			else
			{
				val6 = new Material(Shader.Find("Standard"));
				val6.SetFloat("_Mode", 3f);
				val6.SetInt("_SrcBlend", 1);
				val6.SetInt("_DstBlend", 10);
				val6.SetInt("_ZWrite", 0);
				val6.DisableKeyword("_ALPHATEST_ON");
				val6.DisableKeyword("_ALPHABLEND_ON");
				val6.EnableKeyword("_ALPHAPREMULTIPLY_ON");
				val6.renderQueue = 3000;
				val6.color = new Color(1f, 1f, 1f, 0.07f);
				val6.SetFloat("_Glossiness", 0.95f);
				Instance.Logger.LogInfo((object)"Cabin Stove: no glass material found in the game - Standard set to transparent.");
			}
			((Object)val6).name = "cabin stove glass";
			return val6;
		}

		public static void BeforePopulate(PrefabsDirectory __instance)
		{
			try
			{
				if ((Object)(object)__instance != (Object)null && __instance.directory != null && __instance.directory.Length <= 32704)
				{
					Array.Resize(ref __instance.directory, 32705);
				}
			}
			catch (Exception ex)
			{
				Instance.Logger.LogWarning((object)("Cabin Stove (resize): " + ex.Message));
			}
		}

		public static void AfterPopulate(PrefabsDirectory __instance)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			if (_repopulating)
			{
				return;
			}
			try
			{
				if ((Object)(object)_template == (Object)null && !_gaveUp)
				{
					try
					{
						_template = BuildTemplate(__instance);
					}
					catch (Exception ex)
					{
						Instance.Logger.LogError((object)("Cabin Stove: building the stove failed - " + ex));
						if ((Object)(object)_holder != (Object)null)
						{
							List<Transform> list = new List<Transform>();
							foreach (Transform item2 in _holder)
							{
								Transform item = item2;
								list.Add(item);
							}
							foreach (Transform item3 in list)
							{
								Object.DestroyImmediate((Object)(object)((Component)item3).gameObject);
							}
						}
						_template = null;
					}
					_gaveUp = (Object)(object)_template == (Object)null;
				}
				if ((Object)(object)_template == (Object)null)
				{
					_template = StandIn(__instance);
				}
				if ((Object)(object)_template == (Object)null)
				{
					return;
				}
				GameObject val = __instance.directory[32704];
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)_template)
				{
					Instance.Logger.LogError((object)("Cabin Stove: save number " + 32704 + " is already held by '" + ((Object)val).name + "' (another mod) - NOT taking it. The stove will not be in the game. Tell Roy."));
					return;
				}
				__instance.directory[32704] = _template;
				_repopulating = true;
				try
				{
					AccessTools.Method(typeof(PrefabsDirectory), "PopulateShipItems", (Type[])null, (Type[])null).Invoke(__instance, null);
				}
				finally
				{
					_repopulating = false;
				}
				Instance.Logger.LogInfo((object)("Cabin Stove: the cabin stove is in the game's prefab list at " + 32704 + "."));
			}
			catch (Exception ex2)
			{
				Instance.Logger.LogError((object)("Cabin Stove: " + ex2));
			}
		}

		private static Transform Holder()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_holder != (Object)null)
			{
				return _holder;
			}
			GameObject val = new GameObject("CabinStove templates (switched off)");
			Object.DontDestroyOnLoad((Object)val);
			val.SetActive(false);
			_holder = val.transform;
			return _holder;
		}

		private static GameObject Donor(PrefabsDirectory dir)
		{
			GameObject val = ((107 < dir.directory.Length) ? dir.directory[107] : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<ShipItemStove>() != (Object)null)
			{
				return val;
			}
			GameObject[] directory = dir.directory;
			foreach (GameObject val2 in directory)
			{
				if ((Object)(object)val2 != (Object)null && ((Object)val2).name.Contains("stove_small_A") && (Object)(object)val2.GetComponent<ShipItemStove>() != (Object)null)
				{
					return val2;
				}
			}
			return null;
		}

		private static GameObject StandIn(PrefabsDirectory dir)
		{
			GameObject val = Donor(dir);
			if ((Object)(object)val == (Object)null)
			{
				Instance.Logger.LogError((object)"Cabin Stove: no Al'Ankh stove to stand in either - a save holding a cabin stove will not load.");
				return null;
			}
			GameObject obj = Object.Instantiate<GameObject>(val, Holder(), false);
			((Object)obj).name = "cabin stove (stand-in)";
			obj.SetActive(true);
			obj.GetComponent<SaveablePrefab>().prefabIndex = 32704;
			obj.AddComponent<CabinStoveItem>().length = StoveLooks.Default<float>(LookChimney);
			Instance.Logger.LogError((object)("Cabin Stove: our stove could not be built, so a plain Al'Ankh stove stands in under number " + 32704 + " - saves load, but the stoves look like Al'Ankh stoves. Put the 'cabinstove' file back beside BetterStoves.dll."));
			return obj;
		}

		private static string StripInheritedColliders(Transform root)
		{
			List<string> list = new List<string>();
			Collider[] componentsInChildren = ((Component)root).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).transform == (Object)(object)root)
				{
					continue;
				}
				bool flag = false;
				Transform val2 = ((Component)val).transform;
				while ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)root)
				{
					if ((Object)(object)((Component)val2).GetComponent<StoveCookTrigger>() != (Object)null || (Object)(object)((Component)val2).GetComponent<StoveFuelTrigger>() != (Object)null)
					{
						flag = true;
						break;
					}
					val2 = val2.parent;
				}
				if (!flag)
				{
					list.Add(((Object)((Component)val).gameObject).name + (((Component)val).gameObject.CompareTag("ItemSubcollider") ? " (sub-collider)" : ""));
					Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
				}
			}
			if (list.Count != 0)
			{
				return string.Join(", ", list.ToArray());
			}
			return "none";
		}

		private static GameObject BuildTemplate(PrefabsDirectory dir)
		{
			//IL_0558: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_0593: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_092b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0932: Expected O, but got Unknown
			//IL_0943: Unknown result type (might be due to invalid IL or missing references)
			//IL_0991: Unknown result type (might be due to invalid IL or missing references)
			//IL_099b: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e7: Expected O, but got Unknown
			//IL_0a18: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a30: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a35: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0900: Unknown result type (might be due to invalid IL or missing references)
			//IL_090f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_060f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0620: Unknown result type (might be due to invalid IL or missing references)
			//IL_0638: Unknown result type (might be due to invalid IL or missing references)
			//IL_063d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_064e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0652: Unknown result type (might be due to invalid IL or missing references)
			//IL_0657: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0765: Unknown result type (might be due to invalid IL or missing references)
			//IL_076a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0779: Unknown result type (might be due to invalid IL or missing references)
			//IL_077e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c41: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c74: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c79: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0caa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b90: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d6f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d74: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d95: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eb3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eb8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ed5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eda: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_pieces == (Object)null)
			{
				return null;
			}
			GameObject val = Donor(dir);
			if ((Object)(object)val == (Object)null)
			{
				Instance.Logger.LogError((object)"Cabin Stove: the game's Al'Ankh stove (107, stove_small_A) was not found.");
				return null;
			}
			MakeMaterials();
			GameObject val2 = Object.Instantiate<GameObject>(val, Holder(), false);
			((Object)val2).name = "cabin stove";
			val2.SetActive(true);
			Transform root = val2.transform;
			string text = BetterStovesPlugin.StripForeignBehaviours(val2);
			if (text != "none")
			{
				Instance.Logger.LogInfo((object)("Cabin Stove: other mods' behaviours taken off the copy: " + text + "."));
			}
			float S = Mathf.Clamp((StoveSize != null) ? StoveSize.Value : 1f, 0.5f, 1.5f);
			root.localScale = Vector3.one;
			_scale = S;
			ShipItemStove stove = val2.GetComponent<ShipItemStove>();
			ShipItem val3 = (ShipItem)(object)stove;
			string text2 = "donor '" + ((Object)val).name + "': value " + val3.value + ", mass " + val3.mass;
			val3.name = "cabin stove";
			val2.GetComponent<MeshFilter>().sharedMesh = ScaledMesh("cabin_iron");
			((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterials = (Material[])(object)new Material[1] { _iron };
			MeshCollider component = val2.GetComponent<MeshCollider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			BoxCollider val4 = val2.GetComponent<BoxCollider>();
			if ((Object)(object)val4 == (Object)null)
			{
				val4 = val2.AddComponent<BoxCollider>();
			}
			Mesh val5 = MeshOf("cabin_col");
			if ((Object)(object)val5 != (Object)null)
			{
				BoxCollider obj = val4;
				Bounds bounds = val5.bounds;
				obj.center = ((Bounds)(ref bounds)).center * S;
				BoxCollider obj2 = val4;
				bounds = val5.bounds;
				obj2.size = ((Bounds)(ref bounds)).size * S;
			}
			else
			{
				val4.center = new Vector3(0f, 0.508f, 0f) * S;
				val4.size = new Vector3(0.75f, 1.016f, 0.59f) * S;
			}
			StoveFuelTrigger componentInChildren = ((Component)root).GetComponentInChildren<StoveFuelTrigger>(true);
			StoveCookTrigger val6 = (((Object)(object)componentInChildren != (Object)null) ? Traverse.Create((object)componentInChildren).Field("cookTrigger").GetValue<StoveCookTrigger>() : null);
			if ((Object)(object)val6 == (Object)null)
			{
				val6 = ((Component)root).GetComponentInChildren<StoveCookTrigger>(true);
			}
			StoveCookTrigger[] componentsInChildren = ((Component)root).GetComponentsInChildren<StoveCookTrigger>(true);
			foreach (StoveCookTrigger val7 in componentsInChildren)
			{
				if ((Object)(object)val7 != (Object)(object)val6)
				{
					Object.DestroyImmediate((Object)(object)((Component)val7).gameObject);
				}
			}
			Transform val8 = root.Find("extras");
			if ((Object)(object)val8 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val8).gameObject);
			}
			string text3 = StripInheritedColliders(root);
			StoveCookTrigger component2 = Object.Instantiate<GameObject>(((Component)val6).gameObject, root).GetComponent<StoveCookTrigger>();
			Action<StoveCookTrigger, string, string> obj3 = delegate(StoveCookTrigger ct, string name, string mark)
			{
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: 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_0062: 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_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: 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)
				((Object)((Component)ct).gameObject).name = "cook place " + name;
				((Component)ct).transform.SetParent(root, false);
				((Component)ct).transform.localPosition = Mark(mark, new Vector3(0f, 0.945f, -0.12f)) * S + new Vector3(0f, 0.08f, 0f);
				((Component)ct).transform.localRotation = Quaternion.identity;
				((Component)ct).transform.localScale = new Vector3(0.3f, 0.05f, 0.3f) * S;
				ct.stove = stove;
				ct.currentFood = null;
				ct.smoking = false;
			};
			obj3(val6, "eye a", "cp_eye_a");
			obj3(component2, "eye b", "cp_eye_b");
			stove.slots = (StoveCookTrigger[])(object)new StoveCookTrigger[2] { val6, component2 };
			if ((Object)(object)Piece("cabin_brass") != (Object)null)
			{
				Add(root, "cabin_brass", _brass);
			}
			Add(root, "cabin_wood", _wood);
			Add(root, "cabin_glass", _glass);
			Add(root, "cabin_firebox", _soot);
			Add(root, "cabin_grate", _pipe);
			if ((Object)(object)Piece("cabin_rail") != (Object)null)
			{
				Transform val9 = Add(root, "cabin_rail", _iron);
				if ((Object)(object)val9 != (Object)null && LookRail != null && !StoveLooks.Default<bool>(LookRail))
				{
					((Component)val9).gameObject.SetActive(false);
				}
			}
			Transform val10 = Add(root, "cabin_pipe", _pipe);
			Transform cap = Add(root, "cabin_cap", _pipe);
			Light val11 = null;
			ParticleSystem val12 = null;
			ParticleSystem val13 = null;
			string text4 = "";
			Vector3 val14 = Mark("cp_fire", new Vector3(0f, 0.375f, 0.02f)) * S;
			if ((Object)(object)componentInChildren != (Object)null)
			{
				Traverse val15 = Traverse.Create((object)componentInChildren);
				val11 = val15.Field("light").GetValue<Light>();
				val12 = val15.Field("fireParticles").GetValue<ParticleSystem>();
				val13 = val15.Field("smokeParticles").GetValue<ParticleSystem>();
				try
				{
					StockFuel = Mathf.Max(1, val15.Field("maxFuel").GetValue<int>());
				}
				catch (Exception)
				{
				}
				try
				{
					val15.Field("maxFuel").SetValue((object)Firewood.Value);
				}
				catch (Exception)
				{
				}
				Transform transform = ((Component)componentInChildren).transform;
				transform.localPosition = val14;
				transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
				transform.localScale = new Vector3(0.5f, 0.36f, 0.5f) * S;
				BoxCollider component3 = ((Component)componentInChildren).GetComponent<BoxCollider>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.center = new Vector3(0f, 0f, 0.5f);
					component3.size = Vector3.one;
				}
			}
			if ((Object)(object)val12 != (Object)null)
			{
				((Component)val12).transform.SetParent(root, false);
				((Component)val12).transform.localRotation = Quaternion.identity;
				((Component)val12).transform.localScale = Vector3.one;
				((Component)val12).transform.localPosition = val14 + new Vector3(0f, -0.02f, -0.045f * S);
				MainModule main = val12.main;
				ShapeModule shape = val12.shape;
				text4 = "fire was: size " + ((MainModule)(ref main)).startSizeMultiplier.ToString("0.###") + ", speed " + ((MainModule)(ref main)).startSpeedMultiplier.ToString("0.###") + ", life " + ((MainModule)(ref main)).startLifetimeMultiplier.ToString("0.###") + ", radius " + ((ShapeModule)(ref shape)).radius.ToString("0.###") + ", scaling " + ((object)((MainModule)(ref main)).scalingMode/*cast due to .constrained prefix*/).ToString();
				((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * (0.9f * S);
				((MainModule)(ref main)).startSpeedMultiplier = ((MainModule)(ref main)).startSpeedMultiplier * 0.8f;
				((MainModule)(ref main)).startLifetimeMultiplier = ((MainModule)(ref main)).startLifetimeMultiplier * 0.9f;
				((ShapeModule)(ref shape)).radius = ((ShapeModule)(ref shape)).radius * (0.45f * S);
				ColorOverLifetimeModule colorOverLifetime = val12.colorOverLifetime;
				if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
				{
					((ColorOverLifetimeModule)(ref colorOverLifetime)).color = TrimTail(((ColorOverLifetimeModule)(ref colorOverLifetime)).color);
				}
			}
			string text5 = (((Object)(object)val13 != (Object)null) ? "the Al'Ankh stove's own" : "none on the Al'Ankh stove");
			if ((Object)(object)val13 == (Object)null && (Object)(object)componentInChildren != (Object)null)
			{
				try
				{
					GameObject val16 = ((105 < dir.directory.Length) ? dir.directory[105] : null);
					StoveFuelTrigger val17 = (((Object)(object)val16 != (Object)null) ? val16.GetComponentInChildren<StoveFuelTrigger>(true) : null);
					ParticleSystem val18 = (((Object)(object)val17 != (Object)null) ? Traverse.Create((object)val17).Field("smokeParticles").GetValue<ParticleSystem>() : null);
					if ((Object)(object)val18 != (Object)null)
					{
						val13 = Object.Instantiate<GameObject>(((Component)val18).gameObject, root).GetComponent<ParticleSystem>();
						((Object)((Component)val13).gameObject).name = "chimney smoke";
						Traverse.Create((object)componentInChildren).Field("smokeParticles").SetValue((object)val13);
						text5 = "borrowed from the Aestrin stove";
					}
				}
				catch (Exception ex3)
				{
					text5 = "could not be borrowed: " + ex3.Message;
				}
			}
			if ((Object)(object)val13 != (Object)null)
			{
				((Component)val13).transform.SetParent(root, false);
				((Component)val13).transform.localRotation = Quaternion.identity;
				((Component)val13).transform.localScale = Vector3.one;
				MainModule main2 = val13.main;
				EmissionModule emission = val13.emission;
				((MainModule)(ref main2)).startSizeMultiplier = ((MainModule)(ref main2)).startSizeMultiplier * 1.6f;
				((MainModule)(ref main2)).startLifetimeMultiplier = ((MainModule)(ref main2)).startLifetimeMultiplier * 1.4f;
				MinMaxCurve rateOverTime = ((EmissionModule)(ref emission)).rateOverTime;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(((MinMaxCurve)(ref rateOverTime)).constant * 2f);
				((MainModule)(ref main2)).simulationSpace = (ParticleSystemSimulationSpace)1;
			}
			Material val19 = new Material(Shader.Find("Standard"));
			val19.color = new Color(0.07f, 0.02f, 0.01f);
			val19.SetFloat("_Metallic", 0f);
			val19.SetFloat("_Glossiness", 0.1f);
			val19.EnableKeyword("_EMISSION");
			val19.SetColor("_EmissionColor", new Color(1f, 0.32f, 0.06f) * 1.2f);
			((Object)val19).name = "cabin stove coals";
			val19.SetColor("_EmissionColor", new Color(1f, 0.42f, 0.14f) * 1.6f);
			GameObject val20 = new GameObject("coals");
			val20.layer = ((Component)root).gameObject.layer;
			val20.transform.SetParent(root, false);
			val20.transform.localPosition = val14 + new Vector3(0f, -0.05f * S, 0f);
			List<MeshRenderer> list = new List<MeshRenderer>();
			Random random = new Random(4421);
			for (int num = 0; num < 80; num++)
			{
				GameObject obj4 = GameObject.CreatePrimitive((PrimitiveType)0);
				((Object)obj4).name = "coal";
				obj4.layer = ((Component)root).gameObject.layer;
				Collider component4 = obj4.GetComponent<Collider>();
				if ((Object)(object)component4 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component4);
				}
				obj4.transform.SetParent(val20.transform, false);
				float num2 = 0.035f + 0.035f * (float)random.NextDouble();
				obj4.transform.localScale = new Vector3(num2 * (0.7f + 0.6f * (float)random.NextDouble()), num2 * (0.5f + 0.3f * (float)random.NextDouble()), num2 * (0.7f + 0.6f * (float)random.NextDouble())) * S;
				bool flag = num >= 50;
				obj4.transform.localPosition = new Vector3((-0.23f + 0.46f * (float)random.NextDouble()) * S, ((flag ? 0.045f : 0.018f) + 0.012f * (float)random.NextDouble()) * S, (-0.13f + 0.26f * (float)random.NextDouble()) * S);
				obj4.transform.localRotation = Quaternion.Euler((float)random.NextDouble() * 40f - 20f, (float)random.NextDouble() * 180f, (float)random.NextDouble() * 40f - 20f);
				MeshRenderer component5 = obj4.GetComponent<MeshRenderer>();
				((Renderer)component5).sharedMaterial = val19;
				((Renderer)component5).shadowCastingMode = (ShadowCastingMode)0;
				list.Add(component5);
			}
			MeshRenderer[] coals = list.ToArray();
			Light val21 = null;
			if ((Object)(object)val11 != (Object)null)
			{
				Color color = default(Color);
				((Color)(ref color))..ctor(1f, 0.58f, 0.26f);
				val11.color = color;
				val11.range = 1.3f * S;
				val11.intensity = 1.7f;
				val11.shadows = (LightShadows)0;
				GameObject val22 = new GameObject("door glow");
				val22.transform.SetParent(root, false);
				val22.transform.localPosition = Mark("cp_glow", new Vector3(0f, 0.58f, -0.39f)) * S;
				val21 = val22.AddComponent<Light>();
				val21.type = (LightType)2;
				val21.color = color;
				val21.range = 8f;
				val21.intensity = 1.5f;
				val21.shadows = (LightShadows)1;
			}
			CabinStoveItem cabinStoveItem = val2.AddComponent<CabinStoveItem>();
			cabinStoveItem.pipe = val10;
			cabinStoveItem.cap = cap;
			cabinStoveItem.smoke = (((Object)(object)val13 != (Object)null) ? ((Component)val13).transform : null);
			cabinStoveItem.inside = val11;
			cabinStoveItem.glow = val21;
			cabinStoveItem.insideFull = (((Object)(object)val11 != (Object)null) ? val11.intensity : 1.7f);
			cabinStoveItem.coals = coals;
			cabinStoveItem.coalsFull = val19.GetColor("_EmissionColor");
			cabinStoveItem.pipeBaseY = (((Object)(object)val10 != (Object)null) ? val10.localPosition.y : (1.01f * S));
			cabinStoveItem.pipeMeshLength = 1f * S;
			cabinStoveItem.length = StoveLooks.Default<float>(LookChimney);
			val2.GetComponent<SaveablePrefab>().prefabIndex = 32704;
			ManualLogSource logger = Instance.Logger;
			string[] obj5 = new string[25]
			{
				"Cabin Stove: built from the ",
				text2,
				" (kept: the Al'Ankh stove's value, mass, cooking and fuel); size ",
				S.ToString("0.00"),
				" (",
				(0.75f * S).ToString("0.00"),
				" m wide, ",
				(0.93f * S).ToString("0.00"),
				" m to the top); two pot places; inherited collider children stripped: ",
				text3,
				"; ",
				text4,
				"; smoke ",
				text5,
				"; chimney ",
				cabinStoveItem.length.ToString("0.0"),
				" m; collider = one box, centre ",
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null
			};
			Vector3 val23 = val4.center;
			obj5[17] = ((Vector3)(ref val23)).ToString("F3");
			obj5[18] = " size ";
			val23 = val4.size;
			obj5[19] = ((Vector3)(ref val23)).ToString("F3");
			obj5[20] = "; Unity ";
			obj5[21] = Application.unityVersion;
			obj5[22] = ", game ";
			obj5[23] = Application.version;
			obj5[24] = ".";
			logger.LogInfo((object)string.Concat(obj5));
			return val2;
		}

		private static Mesh ScaledMesh(string piece)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = MeshOf(piece);
			if ((Object)(object)val == (Object)null || Mathf.Approximately(_scale, 1f))
			{
				return val;
			}
			if (!val.isReadable)
			{
				Instance.Logger.LogWarning((object)("Cabin Stove: the bundle's '" + piece + "' is not readable, so the F1 size cannot be applied to it."));
				return val;
			}
			if (_scaled.TryGetValue(piece, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = Object.Instantiate<Mesh>(val);
			((Object)value).name = ((Object)val).name + " x" + _scale.ToString("0.00");
			Vector3[] vertices = value.vertices;
			for (int i = 0; i < vertices.Length; i++)
			{
				ref Vector3 reference = ref vertices[i];
				reference *= _scale;
			}
			value.vertices = vertices;
			value.RecalculateBounds();
			_scaled[piece] = value;
			return value;
		}

		internal static MinMaxGradient TrimTail(MinMaxGradient g)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_002a: Invalid comparison between Unknown and I4
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_005f: 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)
			Func<Gradient, Gradient> func = delegate(Gradient src)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Expected O, but got Unknown
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: 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_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				if (src == null)
				{
					return (Gradient)null;
				}
				Gradient val = new Gradient();
				GradientColorKey[] array = (GradientColorKey[])(object)new GradientColorKey[5];
				GradientAlphaKey[] array2 = (GradientAlphaKey[])(object)new GradientAlphaKey[5];
				for (int i = 0; i < 5; i++)
				{
					float num = (float)i / 4f;
					Color val2 = src.Evaluate(num * 0.5f);
					array[i] = new GradientColorKey(val2, num);
				}
				array2[0] = new GradientAlphaKey(src.Evaluate(0f).a, 0f);
				array2[1] = new GradientAlphaKey(src.Evaluate(0.15f).a, 0.3f);
				array2[2] = new GradientAlphaKey(src.Evaluate(0.3f).a * 0.9f, 0.55f);
				array2[3] = new GradientAlphaKey(0f, 0.75f);
				array2[4] = new GradientAlphaKey(0f, 1f);
				val.SetKeys(array, array2);
				return val;
			};
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref g)).mode;
			if ((int)mode != 1)
			{
				if ((int)mode == 3)
				{
					return new MinMaxGradient(func(((MinMaxGradient)(ref g)).gradientMin), func(((MinMaxGradient)(ref g)).gradientMax));
				}
				return g;
			}
			return new MinMaxGradient(func(((MinMaxGradient)(ref g)).gradient));
		}

		private static Transform Add(Transform root, string piece, Material mat)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_006c: 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_0080: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Piece(piece);
			Mesh val2 = ScaledMesh(piece);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Instance.Logger.LogWarning((object)("Cabin Stove: piece '" + piece + "' is not in the bundle."));
				return null;
			}
			GameObject val3 = new GameObject(piece)
			{
				layer = ((Component)root).gameObject.layer
			};
			val3.transform.SetParent(root, false);
			val3.transform.localPosition = val.localPosition * _scale;
			val3.transform.localRotation = val.localRotation;
			val3.transform.localScale = val.localScale;
			val3.AddComponent<MeshFilter>().sharedMesh = val2;
			MeshRenderer val4 = val3.AddComponent<MeshRenderer>();
			((Renderer)val4).sharedMaterial = mat;
			if ((Object)(object)mat == (Object)(object)_glass)
			{
				((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
			}
			return val3.transform;
		}

		public static void AfterDrop(ShipItem __instance)
		{
			try
			{
				CabinStoveItem cabinStoveItem = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponent<CabinStoveItem>() : null);
				if ((Object)(object)cabinStoveItem != (Object)null)
				{
					cabinStoveItem.ReportDrop();
				}
			}
			catch (Exception)
			{
			}
		}

		public static bool BeforeFuelUpdate(StoveFuel __instance, out float __state)
		{
			__state = -1f;
			try
			{
				if ((Object)(object)__instance == (Object)null || !__instance.inserted || (Object)(object)((Component)__instance).transform.parent == (Object)null)
				{
					return true;
				}
				if ((Object)(object)((Component)((Component)__instance).transform.parent).GetComponent<CabinStoveItem>() == (Object)null)
				{
					return true;
				}
				ShipItem component = ((Component)__instance).GetComponent<ShipItem>();
				CSLog cSLog = ((Component)__instance).GetComponent<CSLog>();
				if ((Object)(object)cSLog == (Object)null)
				{
					cSLog = ((Component)__instance).gameObject.AddComponent<CSLog>();
					cSLog.order = ++_logOrder;
				}
				int num = 0;
				StoveFuel[] componentsInChildren = ((Component)((Component)__instance).transform.parent).GetComponentsInChildren<StoveFuel>(true);
				foreach (StoveFuel val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)__instance) && val.inserted)
					{
						CSLog cSLog2 = ((Component)val).GetComponent<CSLog>();
						if ((Object)(object)cSLog2 == (Object)null)
						{
							cSLog2 = ((Component)val).gameObject.AddComponent<CSLog>();
							cSLog2.order = ++_logOrder;
						}
						ShipItem component2 = ((Component)val).GetComponent<ShipItem>();
						if (cSLog2.order < cSLog.order && (Object)(object)component2 != (Object)null && component2.health > 0f)
						{
							num++;
						}
					}
				}
				if (num >= ((LogsAtOnce == null) ? 1 : LogsAtOnce.Value))
				{
					return false;
				}
				__state = (((Object)(object)component != (Object)null) ? component.health : (-1f));
				return true;
			}
			catch (Exception)
			{
				return true;
			}
		}

		public static void AfterFuelUpdate(StoveFuel __instance, float __state)
		{
			try
			{
				if (__state < 0f || (Object)(object)__instance == (Object)null)
				{
					return;
				}
				ShipItem component = ((Component)__instance).GetComponent<ShipItem>();
				if ((Object)(object)component == (Object)null || component.health <= 0f)
				{
					return;
				}
				float num = __state - component.health;
				if (!(num <= 0f))
				{
					float num2 = 200f;
					try
					{
						num2 = Traverse.Create((object)__instance).Field("initialFuel").GetValue<float>();
					}
					catch (Exception)
					{
					}
					float num3 = (float)((Firewood != null) ? Firewood.Value : 6) * num2 / 100f;
					float num4 = ((LoadHours != null) ? LoadHours.Value : 8f);
					float num5 = Mathf.Clamp01(1f - num3 / num4);
					component.health += num * num5;
				}
			}
			catch (Exception)
			{
			}
		}

		public static void AfterInsertFuel(StoveFuelTrigger __instance, ShipItem item)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: 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_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)item == (Object)null || (Object)(object)((Component)__instance).transform.parent == (Object)null || (Object)(object)((Component)((Component)__instance).transform.parent).GetComponent<CabinStoveItem>() == (Object)null || (Object)(object)((Component)item).transform.parent != (Object)(object)((Component)__instance).transform.parent)
				{
					return;
				}
				Transform parent = ((Component)__instance).transform.parent;
				Vector3 localPosition = ((Component)__instance).transform.localPosition;
				float scale = _scale;
				Vector3[] array = (Vector3[])(object)new Vector3[9]
				{
					new Vector3(