Decompiled source of SurtlingFlame v0.1.0

plugins/SurtlingFlame.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Extensions;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SurtlingFlame")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7ad7f76510b8a070f27ea39b6344dfebbd4a944e")]
[assembly: AssemblyProduct("SurtlingFlame")]
[assembly: AssemblyTitle("SurtlingFlame")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 SurtlingFlame
{
	public static class Eternal
	{
		private const string RpcAddCore = "SurtlingFlame_AddCore";

		private const string CorePrefab = "SurtlingCore";

		private static readonly int CoresKey = StringExtensionMethods.GetStableHashCode("SurtlingFlame_cores");

		private static readonly int EternalKey = StringExtensionMethods.GetStableHashCode("SurtlingFlame_eternal");

		private static bool TryGetConfigured(ZNetView nview, out PieceConfig config, out ZDO zdo)
		{
			config = null;
			zdo = (((Object)(object)nview != (Object)null) ? nview.GetZDO() : null);
			if (zdo != null)
			{
				return ModConfig.ByPrefabHash.TryGetValue(zdo.GetPrefab(), out config);
			}
			return false;
		}

		private static bool TryGetActive(ZNetView nview, out PieceConfig config, out ZDO zdo)
		{
			if (TryGetConfigured(nview, out config, out zdo) && ModConfig.Enabled.Value)
			{
				return config.Enabled.Value;
			}
			return false;
		}

		private static int GetCores(ZDO zdo)
		{
			return zdo.GetInt(CoresKey, 0);
		}

		private static bool IsEternal(ZDO zdo, PieceConfig config)
		{
			if (!zdo.GetBool(EternalKey, false))
			{
				return GetCores(zdo) >= config.CoreCost.Value;
			}
			return true;
		}

		public static bool IsEternal(ZNetView nview)
		{
			if (TryGetActive(nview, out var config, out var zdo))
			{
				return IsEternal(zdo, config);
			}
			return false;
		}

		public static void Register(ZNetView nview, Action onAccepted)
		{
			if (!TryGetConfigured(nview, out var _, out var _))
			{
				return;
			}
			nview.Register("SurtlingFlame_AddCore", (Action<long>)delegate
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				if (nview.IsOwner())
				{
					if (TryAddCore(nview))
					{
						onAccepted();
					}
					else
					{
						DropCores(((Component)nview).transform.position, 1);
					}
				}
			});
		}

		private static bool TryAddCore(ZNetView nview)
		{
			if (!TryGetActive(nview, out var config, out var zdo) || IsEternal(zdo, config))
			{
				return false;
			}
			int num = GetCores(zdo) + 1;
			zdo.Set(CoresKey, num, false);
			if (num >= config.CoreCost.Value)
			{
				zdo.Set(EternalKey, true);
			}
			return true;
		}

		public static bool TryHandleUse(ZNetView nview, Humanoid user, ItemData item, string pieceName, ItemDrop fuelItem)
		{
			if (!TryGetActive(nview, out var config, out var zdo))
			{
				return false;
			}
			pieceName = Localization.instance.Localize(pieceName);
			if (IsCore(item))
			{
				return InsertCore(nview, user, item, pieceName, config, zdo);
			}
			if (IsEternal(zdo, config) && (item == null || item.m_shared.m_name == fuelItem.m_itemData.m_shared.m_name))
			{
				Say(user, "$surtlingflame_msg_nofuel", pieceName);
				return true;
			}
			return false;
		}

		public static bool TryInsertFromInventory(ZNetView nview, Humanoid user, string pieceName)
		{
			if (!TryGetActive(nview, out var config, out var zdo))
			{
				return false;
			}
			ItemData item = user.GetInventory().GetItem("SurtlingCore", -1, true);
			return InsertCore(nview, user, item, Localization.instance.Localize(pieceName), config, zdo);
		}

		private static bool InsertCore(ZNetView nview, Humanoid user, ItemData core, string pieceName, PieceConfig config, ZDO zdo)
		{
			if (IsEternal(zdo, config))
			{
				Say(user, "$surtlingflame_msg_already", pieceName);
				return true;
			}
			if (core == null)
			{
				Say(user, "$msg_donthaveany " + CoreItemName());
				return true;
			}
			user.GetInventory().RemoveItem(core, 1);
			int num = GetCores(zdo) + 1;
			int value = config.CoreCost.Value;
			if (num >= value)
			{
				Say(user, "$surtlingflame_msg_now", pieceName);
			}
			else
			{
				Say(user, "$surtlingflame_msg_inserted", num.ToString(), value.ToString());
			}
			nview.InvokeRPC("SurtlingFlame_AddCore", Array.Empty<object>());
			return true;
		}

		private static void Say(Humanoid user, string token, params string[] words)
		{
			((Character)user).Message((MessageType)2, Localization.instance.Localize(token, words), 0, (Sprite)null, false);
		}

		public static string Hover(ZNetView nview, string pieceName, string vanilla, string eternalLines = "")
		{
			if (string.IsNullOrEmpty(vanilla) || !TryGetActive(nview, out var config, out var zdo))
			{
				return vanilla;
			}
			if (IsEternal(zdo, config))
			{
				return Localization.instance.Localize(pieceName + "\n( $surtlingflame_hover_eternal )" + eternalLines);
			}
			return vanilla + Localization.instance.Localize($"\n( $surtlingflame_hover_cores {GetCores(zdo)}/{config.CoreCost.Value} )" + "\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] $surtlingflame_hover_insert");
		}

		public static void RefundCores(Piece piece)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.RefundCores.Value && TryGetConfigured(piece.m_nview, out var _, out var zdo))
			{
				int cores = GetCores(zdo);
				if (cores > 0 && !ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey()))
				{
					zdo.Set(CoresKey, 0, false);
					DropCores(((Component)piece).transform.position, cores);
				}
			}
		}

		private static bool IsCore(ItemData item)
		{
			if (item != null && (Object)(object)item.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name == "SurtlingCore";
			}
			return false;
		}

		private static GameObject GetCorePrefab()
		{
			if (!((Object)(object)ObjectDB.instance != (Object)null))
			{
				return null;
			}
			return ObjectDB.instance.GetItemPrefab("SurtlingCore");
		}

		private static string CoreItemName()
		{
			GameObject corePrefab = GetCorePrefab();
			if (!((Object)(object)corePrefab != (Object)null))
			{
				return "SurtlingCore";
			}
			return corePrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name;
		}

		private static void DropCores(Vector3 position, int count)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			GameObject corePrefab = GetCorePrefab();
			if (!((Object)(object)corePrefab == (Object)null))
			{
				int val = Math.Max(1, corePrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxStackSize);
				while (count > 0)
				{
					int num = Math.Min(count, val);
					count -= num;
					Vector3 val2 = position + Vector3.up + Random.insideUnitSphere * 0.3f;
					ItemDrop component = Object.Instantiate<GameObject>(corePrefab, val2, Quaternion.identity).GetComponent<ItemDrop>();
					component.SetStack(num);
					ItemDrop.OnCreateNew(component, false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Fireplace))]
	public static class FireplacePatches
	{
		private const string ToggleLine = "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_use";

		private const string HotbarLine = "\n[<color=yellow><b>$KEY_HotbarUse</b></color>] $piece_useitem";

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void Awake(Fireplace __instance)
		{
			Eternal.Register(__instance.m_nview, delegate
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				__instance.m_fuelAddedEffects.Create(((Component)__instance).transform.position, ((Component)__instance).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
				__instance.UpdateFireplace();
			});
		}

		[HarmonyPrefix]
		[HarmonyPatch("UseItem")]
		private static bool UseItem(Fireplace __instance, Humanoid user, ItemData item, ref bool __result)
		{
			if (!Eternal.TryHandleUse(__instance.m_nview, user, item, __instance.m_name, __instance.m_fuelItem))
			{
				return true;
			}
			__result = true;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("Interact")]
		private static bool Interact(Fireplace __instance, Humanoid user, bool hold, bool alt, ref bool __result)
		{
			if (alt && !hold && Eternal.TryInsertFromInventory(__instance.m_nview, user, __instance.m_name))
			{
				__result = true;
				return false;
			}
			if (!Eternal.IsEternal(__instance.m_nview))
			{
				return true;
			}
			if (__instance.m_canTurnOff && !hold && !alt)
			{
				return true;
			}
			if (!hold)
			{
				Eternal.TryHandleUse(__instance.m_nview, user, null, __instance.m_name, __instance.m_fuelItem);
			}
			__result = false;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("UpdateFireplace")]
		private static void UpdateFireplacePrefix(Fireplace __instance, out bool __state)
		{
			ZNetView nview = __instance.m_nview;
			__state = nview.IsOwner() && Eternal.IsEternal(nview);
			if (__state)
			{
				ZDO zDO = nview.GetZDO();
				if (zDO.GetFloat(ZDOVars.s_fuel, 0f) < __instance.m_maxFuel)
				{
					zDO.Set(ZDOVars.s_fuel, __instance.m_maxFuel);
				}
				__instance.m_infiniteFuel = true;
			}
		}

		[HarmonyFinalizer]
		[HarmonyPatch("UpdateFireplace")]
		private static void UpdateFireplaceFinalizer(Fireplace __instance, bool __state)
		{
			if (__state)
			{
				__instance.m_infiniteFuel = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("GetHoverText")]
		private static void GetHoverText(Fireplace __instance, ref string __result)
		{
			string eternalLines = (__instance.m_canTurnOff ? "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_use" : "") + (__instance.m_canRefill ? "\n[<color=yellow><b>$KEY_HotbarUse</b></color>] $piece_useitem" : "");
			__result = Eternal.Hover(__instance.m_nview, __instance.m_name, __result, eternalLines);
		}
	}
	[HarmonyPatch(typeof(Switch))]
	public static class FuelSwitchPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("Interact")]
		private static bool Interact(Switch __instance, Humanoid character, bool hold, bool alt, ref bool __result)
		{
			if (!alt || hold || !TryGetFuelOpening(__instance, out var nview, out var name))
			{
				return true;
			}
			if (!Eternal.TryInsertFromInventory(nview, character, name))
			{
				return true;
			}
			__result = true;
			return false;
		}

		private static bool TryGetFuelOpening(Switch sw, out ZNetView nview, out string name)
		{
			Smelter componentInParent = ((Component)sw).GetComponentInParent<Smelter>();
			if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.m_addWoodSwitch == (Object)(object)sw)
			{
				ZNetView nview2 = componentInParent.m_nview;
				string name2 = componentInParent.m_name;
				nview = nview2;
				name = name2;
				return true;
			}
			CookingStation componentInParent2 = ((Component)sw).GetComponentInParent<CookingStation>();
			if ((Object)(object)componentInParent2 != (Object)null && (Object)(object)componentInParent2.m_addFuelSwitch == (Object)(object)sw)
			{
				ZNetView nview2 = componentInParent2.m_nview;
				string name2 = componentInParent2.m_name;
				nview = nview2;
				name = name2;
				return true;
			}
			nview = null;
			name = null;
			return false;
		}
	}
	[HarmonyPatch(typeof(Smelter))]
	public static class SmelterPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void Awake(Smelter __instance)
		{
			Eternal.Register(__instance.m_nview, delegate
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				__instance.m_fuelAddedEffects.Create(((Component)__instance).transform.position, ((Component)__instance).transform.rotation, ((Component)__instance).transform, 1f, -1, default(ZDOID));
			});
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnAddFuel")]
		private static bool OnAddFuel(Smelter __instance, Humanoid user, ItemData item, ref bool __result)
		{
			if (!Eternal.TryHandleUse(__instance.m_nview, user, item, __instance.m_name, __instance.m_fuelItem))
			{
				return true;
			}
			__result = true;
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch("GetFuel")]
		private static void GetFuel(Smelter __instance, ref float __result)
		{
			if (__result < (float)__instance.m_maxFuel && Eternal.IsEternal(__instance.m_nview))
			{
				__result = __instance.m_maxFuel;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("SetFuel")]
		private static bool SetFuel(Smelter __instance)
		{
			return !Eternal.IsEternal(__instance.m_nview);
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnHoverAddFuel")]
		private static void OnHoverAddFuel(Smelter __instance, ref string __result)
		{
			__result = Eternal.Hover(__instance.m_nview, __instance.m_name, __result);
		}
	}
	[HarmonyPatch(typeof(CookingStation))]
	public static class CookingStationPatches
	{
		private static bool _readStoredFuel;

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void Awake(CookingStation __instance)
		{
			Eternal.Register(__instance.m_nview, delegate
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				__instance.m_fuelAddedEffects.Create(((Component)__instance).transform.position, ((Component)__instance).transform.rotation, ((Component)__instance).transform, 1f, -1, default(ZDOID));
			});
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnAddFuelSwitch")]
		private static bool OnAddFuelSwitch(CookingStation __instance, Humanoid user, ItemData item, ref bool __result)
		{
			if (!Eternal.TryHandleUse(__instance.m_nview, user, item, __instance.m_name, __instance.m_fuelItem))
			{
				return true;
			}
			__result = true;
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch("GetFuel")]
		private static void GetFuel(CookingStation __instance, ref float __result)
		{
			if (!_readStoredFuel && __result < (float)__instance.m_maxFuel && Eternal.IsEternal(__instance.m_nview))
			{
				__result = __instance.m_maxFuel;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("SetFuel")]
		private static bool SetFuel(CookingStation __instance)
		{
			if (!_readStoredFuel)
			{
				return !Eternal.IsEternal(__instance.m_nview);
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("DropAllItems")]
		private static void DropAllItemsPrefix()
		{
			_readStoredFuel = true;
		}

		[HarmonyFinalizer]
		[HarmonyPatch("DropAllItems")]
		private static void DropAllItemsFinalizer()
		{
			_readStoredFuel = false;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnHoverFuelSwitch")]
		private static void OnHoverFuelSwitch(CookingStation __instance, ref string __result)
		{
			__result = Eternal.Hover(__instance.m_nview, __instance.m_name, __result);
		}
	}
	internal static class Localisation
	{
		public static void Register()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "surtlingflame_msg_inserted", "Surtling core inserted ($1/$2)" },
				{ "surtlingflame_msg_now", "The $1 now has an eternal flame" },
				{ "surtlingflame_msg_already", "The $1 already has an eternal flame" },
				{ "surtlingflame_msg_nofuel", "The $1 has an eternal flame and needs no fuel" },
				{ "surtlingflame_hover_eternal", "Eternal flame" },
				{ "surtlingflame_hover_cores", "Surtling cores" },
				{ "surtlingflame_hover_insert", "Insert surtling core" }
			});
		}
	}
	public sealed class PieceConfig
	{
		public ConfigEntry<bool> Enabled;

		public ConfigEntry<int> CoreCost;
	}
	public static class ModConfig
	{
		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<bool> RefundCores;

		public static readonly Dictionary<int, PieceConfig> ByPrefabHash = new Dictionary<int, PieceConfig>();

		private static ConfigFile _config;

		private const int FirstPieceOrder = 1000;

		public static void Bind(ConfigFile config)
		{
			_config = config;
			Enabled = ConfigFileExtensions.BindConfig<bool>(config, "General", "Enabled", true, "Turns the whole mod on or off. While off, eternal pieces burn fuel normally; their inserted cores are kept and count again when it is turned back on.", true, (int?)1, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			RefundCores = ConfigFileExtensions.BindConfig<bool>(config, "General", "Refund cores on deconstruct", true, "Drops a piece's inserted surtling cores when it is deconstructed or destroyed. Worlds with no build cost never refund, as they drop no build resources either.", true, (int?)0, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			foreach (PieceDefault item in PieceDefaults.Known)
			{
				BindPiece("Pieces", item.DisplayName, item);
			}
		}

		public static void BindDiscovered(PieceDefault d)
		{
			BindPiece("Pieces from other mods", d.Prefab, d);
		}

		private static void BindPiece(string section, string name, PieceDefault d)
		{
			int num = 1000 - 2 * ByPrefabHash.Count;
			ByPrefabHash[StringExtensionMethods.GetStableHashCode(d.Prefab)] = new PieceConfig
			{
				Enabled = ConfigFileExtensions.BindConfig<bool>(_config, section, name, true, "Whether surtling cores can make the " + d.DisplayName + " (" + d.Prefab + ") eternal.", true, (int?)num, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null),
				CoreCost = ConfigFileExtensions.BindConfig<int>(_config, section, name + " cores", d.Cost, "Surtling cores needed to make the " + d.DisplayName + " eternal. Changing it does not affect pieces that are already eternal.", true, (int?)(num - 1), (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null)
			};
		}
	}
	public sealed class PieceDefault
	{
		public readonly string Prefab;

		public readonly string DisplayName;

		public readonly int Cost;

		public PieceDefault(string prefab, string displayName, int cost)
		{
			Prefab = prefab;
			DisplayName = displayName;
			Cost = cost;
		}
	}
	public static class PieceDefaults
	{
		public static readonly IReadOnlyList<PieceDefault> Known = new List<PieceDefault>
		{
			new PieceDefault("piece_walltorch", "Sconce", 1),
			new PieceDefault("piece_groundtorch", "Standing iron torch", 1),
			new PieceDefault("piece_groundtorch_wood", "Standing wood torch", 1),
			new PieceDefault("piece_groundtorch_green", "Standing green-burning iron torch", 1),
			new PieceDefault("piece_groundtorch_blue", "Standing blue-burning iron torch", 1),
			new PieceDefault("piece_brazierfloor01", "Standing brazier", 1),
			new PieceDefault("piece_brazierceiling01", "Hanging brazier", 1),
			new PieceDefault("piece_jackoturnip", "Jack-o-turnip", 1),
			new PieceDefault("piece_brazierfloor02", "Blue standing brazier", 1),
			new PieceDefault("Candle_resin", "Resin candle", 1),
			new PieceDefault("piece_snowlantern", "Snow lantern", 1),
			new PieceDefault("fire_pit", "Campfire", 3),
			new PieceDefault("fire_pit_iron", "Iron fire pit", 3),
			new PieceDefault("bonfire", "Bonfire", 3),
			new PieceDefault("hearth", "Hearth", 3),
			new PieceDefault("piece_bathtub", "Hot tub", 5),
			new PieceDefault("piece_oven", "Stone oven", 5),
			new PieceDefault("smelter", "Smelter", 5),
			new PieceDefault("blastfurnace", "Blast furnace", 10),
			new PieceDefault("eitrrefinery", "Eitr refinery", 10)
		};

		private static readonly HashSet<string> ColdFuels = new HashSet<string> { "FrozenFuel", "Ice" };

		public static MonoBehaviour FuelledComponent(GameObject prefab, out ItemDrop fuelItem)
		{
			fuelItem = null;
			Fireplace component = prefab.GetComponent<Fireplace>();
			if ((Object)(object)component != (Object)null && !component.m_infiniteFuel && (Object)(object)component.m_fuelItem != (Object)null)
			{
				fuelItem = component.m_fuelItem;
				return (MonoBehaviour)(object)component;
			}
			CookingStation component2 = prefab.GetComponent<CookingStation>();
			if ((Object)(object)component2 != (Object)null && component2.m_useFuel && (Object)(object)component2.m_fuelItem != (Object)null)
			{
				fuelItem = component2.m_fuelItem;
				return (MonoBehaviour)(object)component2;
			}
			Smelter component3 = prefab.GetComponent<Smelter>();
			if ((Object)(object)component3 != (Object)null && (Object)(object)component3.m_fuelItem != (Object)null)
			{
				fuelItem = component3.m_fuelItem;
				return (MonoBehaviour)(object)component3;
			}
			return null;
		}

		public static PieceDefault ForDiscovered(string prefab, string displayName, MonoBehaviour fuelled, ItemDrop fuel)
		{
			if (displayName == null || ColdFuels.Contains(((Object)fuel).name))
			{
				return null;
			}
			int cost = ((fuelled is Smelter) ? 10 : ((fuelled is CookingStation) ? 5 : 3));
			return new PieceDefault(prefab, displayName, cost);
		}
	}
	[HarmonyPatch]
	public static class PiecePatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Piece), "DropResources")]
		private static void DropResources(Piece __instance)
		{
			Eternal.RefundCores(__instance);
		}
	}
	[BepInPlugin("SurtlingFlame", "SurtlingFlame", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "SurtlingFlame";

		public const string ModName = "SurtlingFlame";

		public const string ModVersion = "0.1.0";

		private static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			Localisation.Register();
			_harmony = new Harmony("SurtlingFlame");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			PrefabManager.OnPrefabsRegistered += ScanFuelledPieces;
			Log.LogInfo((object)string.Format("{0} {1} loaded; {2} pieces configured.", "SurtlingFlame", "0.1.0", ModConfig.ByPrefabHash.Count));
		}

		private void OnDestroy()
		{
			PrefabManager.OnPrefabsRegistered -= ScanFuelledPieces;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private static void ScanFuelledPieces()
		{
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				return;
			}
			PrefabManager.OnPrefabsRegistered -= ScanFuelledPieces;
			List<string> list = new List<string>();
			foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
			{
				if ((Object)(object)prefab == (Object)null)
				{
					continue;
				}
				ItemDrop fuelItem;
				MonoBehaviour val = PieceDefaults.FuelledComponent(prefab, out fuelItem);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Piece component = prefab.GetComponent<Piece>();
				string text = (((Object)(object)component != (Object)null && Localization.instance != null) ? Localization.instance.Localize(component.m_name) : null);
				string text2 = "configured";
				if (!ModConfig.ByPrefabHash.ContainsKey(StringExtensionMethods.GetStableHashCode(((Object)prefab).name)))
				{
					PieceDefault pieceDefault = PieceDefaults.ForDiscovered(((Object)prefab).name, text, val, fuelItem);
					if (pieceDefault != null)
					{
						ModConfig.BindDiscovered(pieceDefault);
					}
					text2 = ((pieceDefault != null) ? "added to config" : "not configured");
				}
				list.Add($"  {((Object)prefab).name,-32} {((object)val).GetType().Name,-15} fuel={((Object)fuelItem).name,-14} " + "\"" + (text ?? "(not a buildable piece)") + "\" [" + text2 + "]");
			}
			List<string> list2 = (from d in PieceDefaults.Known
				select d.Prefab into name
				where (Object)(object)ZNetScene.instance.GetPrefab(name) == (Object)null
				select name).ToList();
			Log.LogInfo((object)($"Fuelled pieces found ({list.Count}):\n" + string.Join("\n", list.OrderBy((string l) => l))));
			if (list2.Count > 0)
			{
				Log.LogWarning((object)("Configured prefabs not found in the game: " + string.Join(", ", list2)));
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}