Decompiled source of Thunderdome v1.0.0

plugins/Thunderdome.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using ValheimMods.Shared;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Thunderdome")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A buildable ward whose dome strikes down monsters with lightning, or keeps them out the way the traders' force fields do. Server-synced mode and radius, shown while placing. Needs Jotunn.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Thunderdome")]
[assembly: AssemblyTitle("Thunderdome")]
[assembly: InternalsVisibleTo("ValheimMods.Tests")]
[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 Thunderdome
{
	internal static class CostList
	{
		public const string Default = "SurtlingCore:5,FineWood:10,ElderBark:10,GreydwarfEye:10";

		public static List<KeyValuePair<string, int>> Parse(string text, List<string> problems)
		{
			List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();
			string[] array = (text ?? "").Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (text2.Length != 0)
				{
					string[] array2 = text2.Split(':');
					if (array2.Length != 2 || array2[0].Trim().Length == 0 || !int.TryParse(array2[1].Trim(), out var result) || result < 1)
					{
						problems.Add(text2);
					}
					else
					{
						list.Add(new KeyValuePair<string, int>(array2[0].Trim(), result));
					}
				}
			}
			return list;
		}
	}
	[BepInPlugin("s992.Thunderdome", "Thunderdome", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			Settings.Bind(((BaseUnityPlugin)this).Config);
			WardPiece.Register();
			Settings.Changed += WardPiece.ApplyCost;
			Settings.Changed += Ward.RefreshAll;
			SynchronizationManager.OnConfigurationSynchronized += delegate
			{
				Settings.Reload();
			};
			((BaseUnityPlugin)this).Logger.LogInfo((object)(ModInfo.Name + " " + ModInfo.Version + " loaded"));
		}
	}
	internal static class Settings
	{
		public static ConfigEntry<WardMode> Mode;

		public static ConfigEntry<float> Radius;

		public static ConfigEntry<string> Cost;

		public static ConfigEntry<bool> ShowDome;

		public static event Action Changed;

		public static void Bind(ConfigFile config)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			Mode = config.Bind<WardMode>("1. Server", "Mode", WardMode.Thunderdome, new ConfigDescription("Thunderdome: lightning kills any hostile creature inside the dome, bosses included, and it drops nothing. Repel: monsters turn away like at the traders' camps. Both: monsters turn away, and lightning kills any that come in anyway. Set by the server in multiplayer.", (AcceptableValueBase)null, new object[1] { Admin(3) }));
			Radius = config.Bind<float>("1. Server", "Radius", 30f, new ConfigDescription("Size of every ward's dome in metres. Lightning strikes inside the dome. Repelling reaches a little further: the area is a box as wide as the dome, and monsters with nothing to chase stay about 15 m beyond it. Changing this updates placed wards. Set by the server in multiplayer.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 100f), new object[1] { Admin(2) }));
			Cost = config.Bind<string>("1. Server", "Cost", "SurtlingCore:5,FineWood:10,ElderBark:10,GreydwarfEye:10", new ConfigDescription("What a ward costs to build, as ItemPrefabName:amount separated by commas. Internal names, e.g. ElderBark is Ancient Bark. Applies to wards built after the change. Set by the server in multiplayer.", (AcceptableValueBase)null, new object[1] { Admin(1) }));
			ShowDome = config.Bind<bool>("2. Personal", "Show dome", true, "Show the dome around placed wards, like the traders'. It always shows while placing a ward. Just for you.");
			Mode.SettingChanged += OnChanged;
			Radius.SettingChanged += OnChanged;
			Cost.SettingChanged += OnChanged;
			ShowDome.SettingChanged += OnChanged;
		}

		private static ConfigurationManagerAttributes Admin(int order)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0019: Expected O, but got Unknown
			return new ConfigurationManagerAttributes
			{
				IsAdminOnly = true,
				Order = order
			};
		}

		private static void OnChanged(object sender, EventArgs e)
		{
			Reload();
		}

		public static void Reload()
		{
			Settings.Changed?.Invoke();
		}
	}
	internal enum WardMode
	{
		Thunderdome,
		Repel,
		Both
	}
	internal static class Targeting
	{
		public static bool Strikes(WardMode mode)
		{
			return mode != WardMode.Repel;
		}

		public static bool Repels(WardMode mode)
		{
			return mode != WardMode.Thunderdome;
		}

		public static bool ShouldStrike(Faction faction, bool isPlayer, bool tamed, bool aggravated)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			if (isPlayer || tamed)
			{
				return false;
			}
			if ((int)faction > 1)
			{
				if ((int)faction == 10)
				{
					return aggravated;
				}
				if (faction - 11 > 1)
				{
					return true;
				}
			}
			return false;
		}
	}
	internal sealed class Ward : MonoBehaviour, Hoverable
	{
		private const float ScanInterval = 0.5f;

		private const float KillDamage = 10000000f;

		private static readonly List<Ward> s_instances = new List<Ward>();

		private static readonly HashSet<Character> s_struck = new HashSet<Character>();

		private static readonly List<Character> s_targets = new List<Character>();

		private Piece m_piece;

		private CircleProjector m_ring;

		private GameObject m_dome;

		private GameObject m_area;

		private float m_areaRadius = -1f;

		private bool m_ghost;

		private bool m_placed;

		private float m_scanTimer;

		private FrameGuard m_guard;

		private void Awake()
		{
			m_piece = ((Component)this).GetComponent<Piece>();
			m_guard = new FrameGuard((Behaviour)(object)this, "the Thunderdome's lightning");
			m_ring = ((Component)this).GetComponentInChildren<CircleProjector>(true);
			if (Object.op_Implicit((Object)(object)m_ring))
			{
				((Component)m_ring).gameObject.SetActive(false);
			}
		}

		private void Start()
		{
			m_ghost = Player.IsPlacementGhost(((Component)this).gameObject);
			ZNetView component = ((Component)this).GetComponent<ZNetView>();
			m_placed = !m_ghost && Object.op_Implicit((Object)(object)component) && component.IsValid();
			if (m_ghost || m_placed)
			{
				s_instances.Add(this);
				Refresh();
				if (m_ghost && Object.op_Implicit((Object)(object)m_ring))
				{
					((Component)m_ring).gameObject.SetActive(true);
				}
			}
		}

		private void OnDestroy()
		{
			s_instances.Remove(this);
		}

		public static void RefreshAll()
		{
			foreach (Ward s_instance in s_instances)
			{
				try
				{
					s_instance.Refresh();
				}
				catch (Exception arg)
				{
					ModInfo.Log.LogError((object)$"Couldn't update a ward: {arg}");
				}
			}
		}

		private void Refresh()
		{
			float value = Settings.Radius.Value;
			if (Object.op_Implicit((Object)(object)m_ring))
			{
				m_ring.m_radius = value;
				m_ring.m_nrOfSegments = Mathf.Max(20, Mathf.RoundToInt(value * 2.5f));
			}
			UpdateDome(value);
			if (m_placed)
			{
				if (!Targeting.Repels(Settings.Mode.Value))
				{
					RemoveArea();
				}
				else if (m_areaRadius != value)
				{
					RebuildArea(value);
				}
			}
		}

		private void Update()
		{
			if (!m_placed)
			{
				return;
			}
			try
			{
				Tick();
			}
			catch (Exception e)
			{
				m_guard.Report(e);
			}
		}

		private void Tick()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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)
			m_scanTimer -= Time.deltaTime;
			if (m_scanTimer > 0f)
			{
				return;
			}
			m_scanTimer = 0.5f;
			if (!Targeting.Strikes(Settings.Mode.Value) || !Object.op_Implicit((Object)(object)WardPiece.Lightning))
			{
				return;
			}
			s_struck.RemoveWhere((Character c) => !Object.op_Implicit((Object)(object)c));
			float num = Settings.Radius.Value * Settings.Radius.Value;
			Vector3 position = ((Component)this).transform.position;
			s_targets.Clear();
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (!Object.op_Implicit((Object)(object)allCharacter) || s_struck.Contains(allCharacter) || allCharacter.IsDead())
				{
					continue;
				}
				ZNetView nview = allCharacter.m_nview;
				if (!Object.op_Implicit((Object)(object)nview) || !nview.IsValid() || !nview.IsOwner())
				{
					continue;
				}
				BaseAI baseAI = allCharacter.GetBaseAI();
				if (Targeting.ShouldStrike(allCharacter.GetFaction(), allCharacter.IsPlayer(), allCharacter.IsTamed(), Object.op_Implicit((Object)(object)baseAI) && baseAI.IsAggravated()))
				{
					Vector3 val = allCharacter.GetCenterPoint() - position;
					if (!(((Vector3)(ref val)).sqrMagnitude > num))
					{
						s_targets.Add(allCharacter);
					}
				}
			}
			foreach (Character s_target in s_targets)
			{
				Strike(s_target);
			}
			s_targets.Clear();
		}

		private static void Strike(Character target)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0060: Expected O, but got Unknown
			s_struck.Add(target);
			Object.Instantiate<GameObject>(WardPiece.Lightning, ((Component)target).transform.position, Quaternion.identity);
			CharacterDrop component = ((Component)target).GetComponent<CharacterDrop>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.SetDropsEnabled(false);
				Object.DestroyImmediate((Object)(object)component);
			}
			HitData val = new HitData
			{
				m_point = target.GetCenterPoint(),
				m_dir = Vector3.down
			};
			val.m_damage.m_damage = 10000000f;
			target.Damage(val);
		}

		private void UpdateDome(float radius)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Material dome = WardPiece.Dome;
			if (!Object.op_Implicit((Object)(object)dome) || (!m_ghost && !Settings.ShowDome.Value))
			{
				if (Object.op_Implicit((Object)(object)m_dome))
				{
					m_dome.SetActive(false);
				}
				return;
			}
			if (!Object.op_Implicit((Object)(object)m_dome))
			{
				m_dome = CreateDome(dome);
			}
			m_dome.SetActive(true);
			m_dome.transform.localScale = Vector3.one * (radius * 2f);
		}

		private GameObject CreateDome(Material material)
		{
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			((Object)obj).name = "ForceField";
			obj.transform.SetParent(((Component)this).transform, false);
			MeshRenderer component = obj.GetComponent<MeshRenderer>();
			((Renderer)component).sharedMaterial = material;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			return obj;
		}

		private void RebuildArea(float radius)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			RemoveArea();
			GameObject val = new GameObject("NoMonsterArea");
			val.SetActive(false);
			val.layer = LayerMask.NameToLayer("character_trigger");
			val.transform.SetParent(((Component)this).transform, false);
			SphereCollider obj = val.AddComponent<SphereCollider>();
			obj.radius = radius;
			((Collider)obj).isTrigger = true;
			val.AddComponent<EffectArea>().m_type = (Type)32;
			val.SetActive(true);
			m_area = val;
			m_areaRadius = radius;
		}

		private void RemoveArea()
		{
			if (Object.op_Implicit((Object)(object)m_area))
			{
				Object.Destroy((Object)(object)m_area);
			}
			m_area = null;
			m_areaRadius = -1f;
		}

		public string GetHoverName()
		{
			if (!Object.op_Implicit((Object)(object)m_piece))
			{
				return "";
			}
			return m_piece.m_name;
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public string GetHoverText()
		{
			string text = Settings.Radius.Value.ToString("0", CultureInfo.InvariantCulture);
			string text2 = Settings.Mode.Value switch
			{
				WardMode.Repel => "$piece_thunderdome_repel", 
				WardMode.Both => "$piece_thunderdome_both", 
				_ => "$piece_thunderdome_strike", 
			};
			return Localization.instance.Localize(GetHoverName() + "\n" + text2 + " " + text + " m");
		}
	}
	internal static class WardPiece
	{
		private const string PrefabName = "Thunderdome";

		private const string GuardStone = "guard_stone";

		private const string DomeSource = "charred_shieldgenerator";

		private const string DomeMaterial = "ForceField";

		private static readonly Color s_tint = new Color(0.35f, 0.7f, 1f);

		private static Piece s_piece;

		private const string LightningName = "Thunderdome_Lightning";

		private const string LightningSource = "lightningAOE";

		public static Material Dome { get; private set; }

		public static GameObject Lightning { get; private set; }

		public static void Register()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				["piece_thunderdome"] = "Thunderdome",
				["piece_thunderdome_description"] = "Raises a force field like the traders' camps have. Hostile creatures that enter are struck by lightning.",
				["piece_thunderdome_strike"] = "Strikes down monsters within",
				["piece_thunderdome_repel"] = "Keeps monsters out within",
				["piece_thunderdome_both"] = "Keeps out and strikes down monsters within"
			});
			PrefabManager.OnVanillaPrefabsAvailable += Create;
			PieceManager.OnPiecesRegistered += ApplyCost;
		}

		private static void Create()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Invalid comparison between Unknown and I4
			PrefabManager.OnVanillaPrefabsAvailable -= Create;
			try
			{
				PieceConfig val = new PieceConfig
				{
					Name = "$piece_thunderdome",
					Description = "$piece_thunderdome_description",
					PieceTable = PieceTables.Hammer,
					Category = PieceCategories.Misc,
					CraftingStation = CraftingStations.Workbench
				};
				foreach (KeyValuePair<string, int> item in CostList.Parse("SurtlingCore:5,FineWood:10,ElderBark:10,GreydwarfEye:10", new List<string>()))
				{
					val.AddRequirement(new RequirementConfig(item.Key, item.Value, 0, true));
				}
				CustomPiece val2 = new CustomPiece("Thunderdome", "guard_stone", val);
				GameObject piecePrefab = val2.PiecePrefab;
				s_piece = val2.Piece;
				Object.DestroyImmediate((Object)(object)piecePrefab.GetComponent<PrivateArea>());
				GuidePoint[] componentsInChildren = piecePrefab.GetComponentsInChildren<GuidePoint>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)((Component)componentsInChildren[i]).gameObject);
				}
				piecePrefab.AddComponent<Ward>();
				if ((int)SystemInfo.graphicsDeviceType != 4)
				{
					Tint(piecePrefab);
				}
				Dome = FindDomeMaterial();
				PieceManager.Instance.AddPiece(val2);
				Lightning = CreateLightning();
			}
			catch (Exception arg)
			{
				ModInfo.Log.LogError((object)$"Couldn't create the Thunderdome piece: {arg}");
				PlayerNotice.Show(ModInfo.Name + ": couldn't create the ward piece. Details are in BepInEx/LogOutput.log.");
			}
		}

		private static GameObject CreateLightning()
		{
			if (!Object.op_Implicit((Object)(object)PrefabManager.Instance.GetPrefab("lightningAOE")))
			{
				ModInfo.Log.LogWarning((object)"lightningAOE not found; wards won't strike");
				return null;
			}
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("Thunderdome_Lightning", "lightningAOE");
			Aoe[] componentsInChildren = val.GetComponentsInChildren<Aoe>(true);
			foreach (Aoe val2 in componentsInChildren)
			{
				if ((Object)(object)((Component)val2).gameObject == (Object)(object)val)
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
				else
				{
					Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
				}
			}
			PrefabManager.Instance.AddPrefab(val);
			return val;
		}

		private static Material FindDomeMaterial()
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("charred_shieldgenerator");
			if (Object.op_Implicit((Object)(object)prefab))
			{
				MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true);
				foreach (MeshRenderer val in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)((Renderer)val).sharedMaterial) && ((Object)((Renderer)val).sharedMaterial).name == "ForceField")
					{
						return ((Renderer)val).sharedMaterial;
					}
				}
			}
			ModInfo.Log.LogWarning((object)"Dome material not found on charred_shieldgenerator; wards will show no dome");
			return null;
		}

		private static void Tint(GameObject prefab)
		{
			//IL_00a9: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val in componentsInChildren)
			{
				Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (Object.op_Implicit((Object)(object)sharedMaterials[j]) && ((Object)sharedMaterials[j]).name.Contains("Glow"))
					{
						sharedMaterials[j] = new Material(sharedMaterials[j]);
						sharedMaterials[j].EnableKeyword("_EMISSION");
						sharedMaterials[j].SetColor("_EmissionColor", s_tint * 2f);
					}
				}
				((Renderer)val).sharedMaterials = sharedMaterials;
			}
			ParticleSystem[] componentsInChildren2 = prefab.GetComponentsInChildren<ParticleSystem>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				MainModule main = componentsInChildren2[i].main;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(s_tint);
			}
			Light[] componentsInChildren3 = prefab.GetComponentsInChildren<Light>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				componentsInChildren3[i].color = s_tint;
			}
		}

		public static void ApplyCost()
		{
			//IL_0086: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)s_piece) || !Object.op_Implicit((Object)(object)ObjectDB.instance))
			{
				return;
			}
			List<string> list = new List<string>();
			List<Requirement> list2 = new List<Requirement>();
			foreach (KeyValuePair<string, int> item in CostList.Parse(Settings.Cost.Value, list))
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item.Key);
				ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if (!Object.op_Implicit((Object)(object)val))
				{
					list.Add(item.Key);
					continue;
				}
				list2.Add(new Requirement
				{
					m_resItem = val,
					m_amount = item.Value,
					m_recover = true
				});
			}
			if (list.Count > 0)
			{
				ModInfo.Log.LogWarning((object)("Cost setting: ignored " + string.Join(", ", list)));
			}
			if (list2.Count > 0)
			{
				s_piece.m_resources = list2.ToArray();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "s992.Thunderdome";

		public const string PLUGIN_NAME = "Thunderdome";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace ValheimMods.Shared
{
	internal sealed class FrameGuard
	{
		private const int MaxErrors = 10;

		private readonly Behaviour m_owner;

		private readonly string m_feature;

		private int m_errors;

		public FrameGuard(Behaviour owner, string feature)
		{
			m_owner = owner;
			m_feature = feature;
		}

		public void Report(Exception e)
		{
			m_errors++;
			if (m_errors == 1)
			{
				ModInfo.Log.LogError((object)$"Error in {m_feature}: {e}");
			}
			if (m_errors >= 10)
			{
				m_owner.enabled = false;
				string text = ModInfo.Name + ": " + m_feature + " kept failing and is off until the game restarts. Details are in BepInEx/LogOutput.log.";
				ModInfo.Log.LogError((object)text);
				PlayerNotice.Show(text);
			}
		}
	}
	internal static class Hotkeys
	{
		private static readonly KeyCode[] s_modifierKeys;

		public static bool Pressed(ConfigEntry<KeyboardShortcut> entry)
		{
			//IL_0007: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = entry.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey == 0 || !ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, false))
			{
				return false;
			}
			List<KeyCode> modifiers = ((KeyboardShortcut)(ref value)).Modifiers.ToList();
			if (modifiers.Any((KeyCode key) => !ZInput.GetKey(key, false)))
			{
				return false;
			}
			return !s_modifierKeys.Any((KeyCode key) => !modifiers.Contains(key) && ZInput.GetKey(key, false));
		}

		public static bool Held(ConfigEntry<KeyboardShortcut> entry)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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)
			KeyboardShortcut value = entry.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0 && ZInput.GetKey(((KeyboardShortcut)(ref value)).MainKey, false))
			{
				return ((KeyboardShortcut)(ref value)).Modifiers.All((KeyCode key) => ZInput.GetKey(key, false));
			}
			return false;
		}

		public static bool IsTyping()
		{
			if (!Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible() && !Minimap.InTextInput())
			{
				if (Object.op_Implicit((Object)(object)Chat.instance))
				{
					return Chat.instance.HasFocus();
				}
				return false;
			}
			return true;
		}

		static Hotkeys()
		{
			KeyCode[] array = new KeyCode[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			s_modifierKeys = (KeyCode[])(object)array;
		}
	}
	internal static class ModInfo
	{
		public static readonly string Name = typeof(ModInfo).Assembly.GetName().Name;

		public static readonly string Version = typeof(ModInfo).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? typeof(ModInfo).Assembly.GetName().Version.ToString(3);

		private static ManualLogSource s_log;

		public static ManualLogSource Log => s_log ?? (s_log = Logger.CreateLogSource(Name));
	}
	internal static class PatchGuard
	{
		private static readonly HashSet<string> s_reported = new HashSet<string>();

		public static Exception Contain(Exception exception, string feature)
		{
			if (exception == null || !FromThisMod(exception))
			{
				return exception;
			}
			if (s_reported.Add(feature))
			{
				ModInfo.Log.LogError((object)$"Error in {feature} (further errors there aren't logged): {exception}");
				PlayerNotice.Show(ModInfo.Name + ": " + feature + " hit an error and may not work until the game restarts. Details are in BepInEx/LogOutput.log.");
			}
			return null;
		}

		private static bool FromThisMod(Exception exception)
		{
			Assembly assembly = typeof(PatchGuard).Assembly;
			for (Exception ex = exception; ex != null; ex = ex.InnerException)
			{
				StackFrame[] array = new StackTrace(ex, fNeedFileInfo: false).GetFrames() ?? Array.Empty<StackFrame>();
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i].GetMethod()?.DeclaringType?.Assembly == assembly)
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	internal sealed class PlayerNotice : MonoBehaviour
	{
		private static PlayerNotice s_instance;

		private readonly List<string> m_pending = new List<string>();

		public static void Show(string message)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)s_instance))
			{
				GameObject val = new GameObject(ModInfo.Name + ".PlayerNotice");
				Object.DontDestroyOnLoad((Object)val);
				s_instance = val.AddComponent<PlayerNotice>();
			}
			s_instance.m_pending.Add(message);
		}

		private void Update()
		{
			if (m_pending.Count == 0 || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)MessageHud.instance))
			{
				return;
			}
			try
			{
				foreach (string item in m_pending)
				{
					Send(item);
				}
			}
			catch (Exception ex)
			{
				ModInfo.Log.LogWarning((object)("Couldn't show a message in game: " + ex.Message));
			}
			m_pending.Clear();
		}

		private static void Send(string message)
		{
			((Character)Player.m_localPlayer).Message((MessageType)1, message, 0, (Sprite)null, false);
			if (Object.op_Implicit((Object)(object)Console.instance))
			{
				Console.instance.Print(message);
			}
		}
	}
	internal static class SafePatching
	{
		public static bool PatchAll(Harmony harmony, ManualLogSource log)
		{
			List<string> list = new List<string>();
			Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(typeof(SafePatching).Assembly);
			foreach (Type type in typesFromAssembly)
			{
				try
				{
					harmony.CreateClassProcessor(type).Patch();
				}
				catch (Exception arg)
				{
					list.Add(type.Name);
					log.LogError((object)$"Patch {type.Name} failed: {arg}");
				}
			}
			if (list.Count == 0)
			{
				return true;
			}
			harmony.UnpatchSelf();
			string text = ModInfo.Name + " is turned off: this game version changed something it relies on (" + string.Join(", ", list) + "). Check for an update to " + ModInfo.Name + ".";
			log.LogError((object)text);
			PlayerNotice.Show(text);
			return false;
		}

		public static void ExpectReplaced(int replaced, int expected, string what)
		{
			if (replaced != expected)
			{
				throw new InvalidOperationException($"{what}: expected {expected} change(s), made {replaced}");
			}
		}
	}
}