Decompiled source of VikingSettlements v1.8.2

plugins/VikingSettlements.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Splatform;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using VikingSettlements.Commands;
using VikingSettlements.Npcs;
using VikingSettlements.Party;
using VikingSettlements.Raids;
using VikingSettlements.Settlements;
using VikingSettlements.World;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("VikingSettlements")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VikingSettlements")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.8.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.8.2.0")]
namespace VikingSettlements
{
	internal static class ModConfig
	{
		public static ConfigEntry<int> MeadowsVillages;

		public static ConfigEntry<int> ForestOutposts;

		public static ConfigEntry<int> PlainsSteadings;

		public static ConfigEntry<bool> SettlersDefendPlayers;

		public static ConfigEntry<bool> EnableTrader;

		public static ConfigEntry<bool> ChatterEnabled;

		public static ConfigEntry<float> ChatterInterval;

		public static ConfigEntry<int> RecruitCostCoins;

		public static ConfigEntry<int> MaxSettlersPerSettlement;

		public static ConfigEntry<float> SettlementRadius;

		public static ConfigEntry<float> WorkIntervalSeconds;

		public static ConfigEntry<bool> EnableRaids;

		public static ConfigEntry<bool> RaidsAfterFirstBoss;

		public static ConfigEntry<float> RivalRaidChancePerDay;

		public static ConfigEntry<int> ClanlessCamps;

		public static ConfigEntry<bool> ScaleRaids;

		public static ConfigEntry<float> CampClearRaidReduction;

		public static ConfigEntry<bool> FoodUpkeep;

		public static ConfigEntry<float> MealIntervalSeconds;

		public static ConfigEntry<bool> GrowthEnabled;

		public static ConfigEntry<float> GrowthChancePerDay;

		public static ConfigEntry<int> GrowthFoodCost;

		public static ConfigEntry<bool> RequireWorkstations;

		public static ConfigEntry<bool> VeterancyEnabled;

		public static ConfigEntry<int> XpPerStar;

		public static ConfigEntry<bool> ReputationEnabled;

		public static ConfigEntry<int> DonationCostCoins;

		public static ConfigEntry<int> DonationReputation;

		public static ConfigEntry<int> MaxPartySize;

		public static ConfigEntry<bool> PartyAutoFallback;

		public static ConfigEntry<float> PartyRegenPerSecond;

		public static ConfigEntry<KeyboardShortcut> PartyStanceKey;

		public static ConfigEntry<KeyboardShortcut> PartyFallbackKey;

		public static ConfigEntry<KeyboardShortcut> TalkHotkey;

		public static ConfigEntry<bool> HomesMatter;

		public static void Init(ConfigFile config)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//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_0073: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_01a7: 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_01b4: Expected O, but got Unknown
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Expected O, but got Unknown
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Expected O, but got Unknown
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Expected O, but got Unknown
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Expected O, but got Unknown
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Expected O, but got Unknown
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Expected O, but got Unknown
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Expected O, but got Unknown
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Expected O, but got Unknown
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Expected O, but got Unknown
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Expected O, but got Unknown
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Expected O, but got Unknown
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Expected O, but got Unknown
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Expected O, but got Unknown
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Expected O, but got Unknown
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Expected O, but got Unknown
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Expected O, but got Unknown
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Expected O, but got Unknown
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Expected O, but got Unknown
			//IL_0466: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Expected O, but got Unknown
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Expected O, but got Unknown
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Expected O, but got Unknown
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Expected O, but got Unknown
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Expected O, but got Unknown
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Expected O, but got Unknown
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_052e: Expected O, but got Unknown
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0538: Expected O, but got Unknown
			//IL_0557: Unknown result type (might be due to invalid IL or missing references)
			//IL_055c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Expected O, but got Unknown
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Expected O, but got Unknown
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_059a: Expected O, but got Unknown
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a4: Expected O, but got Unknown
			//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05db: Expected O, but got Unknown
			//IL_05db: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e5: Expected O, but got Unknown
			//IL_0604: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_0611: Expected O, but got Unknown
			//IL_0611: Unknown result type (might be due to invalid IL or missing references)
			//IL_061b: Expected O, but got Unknown
			//IL_0645: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0652: Expected O, but got Unknown
			//IL_0652: Unknown result type (might be due to invalid IL or missing references)
			//IL_065c: Expected O, but got Unknown
			//IL_0682: Unknown result type (might be due to invalid IL or missing references)
			//IL_0687: Unknown result type (might be due to invalid IL or missing references)
			//IL_068f: Expected O, but got Unknown
			//IL_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Expected O, but got Unknown
			//IL_06be: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cb: Expected O, but got Unknown
			//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d5: Expected O, but got Unknown
			//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0701: Expected O, but got Unknown
			//IL_0701: Unknown result type (might be due to invalid IL or missing references)
			//IL_070b: Expected O, but got Unknown
			//IL_073c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0741: Unknown result type (might be due to invalid IL or missing references)
			//IL_0749: Expected O, but got Unknown
			//IL_0749: Unknown result type (might be due to invalid IL or missing references)
			//IL_0753: Expected O, but got Unknown
			//IL_076a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0790: Unknown result type (might be due to invalid IL or missing references)
			//IL_07be: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cb: Expected O, but got Unknown
			//IL_07cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d5: Expected O, but got Unknown
			//IL_07ec: Unknown result type (might be due to invalid IL or missing references)
			MeadowsVillages = config.Bind<int>("Locations", "MeadowsVillages", 60, new ConfigDescription("How many meadows villages the world generator attempts to place. Only applies to newly generated worlds or unexplored areas of existing worlds. Set to 0 to disable.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 500), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			ForestOutposts = config.Bind<int>("Locations", "ForestOutposts", 80, new ConfigDescription("How many black forest outposts the world generator attempts to place. Only applies to newly generated worlds or unexplored areas of existing worlds. Set to 0 to disable.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 500), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			PlainsSteadings = config.Bind<int>("Locations", "PlainsSteadings", 50, new ConfigDescription("How many plains steadings the world generator attempts to place. Only applies to newly generated worlds or unexplored areas of existing worlds. Set to 0 to disable.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 500), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			SettlersDefendPlayers = config.Bind<bool>("Settlers", "DefendPlayers", false, new ConfigDescription("If true, settlers use the player faction and actively fight alongside players. If false (default), settlers are neutral villagers that defend their home and turn hostile when attacked.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			EnableTrader = config.Bind<bool>("Settlers", "EnableTrader", true, new ConfigDescription("Whether meadows villages contain a trader with a small store.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			ChatterEnabled = config.Bind<bool>("Settlers", "Chatter", true, "Whether settlers occasionally greet and talk to players who come close. Client side, purely cosmetic.");
			ChatterInterval = config.Bind<float>("Settlers", "ChatterIntervalSeconds", 25f, new ConfigDescription("Minimum seconds between chatter lines of a single settler.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 300f), Array.Empty<object>()));
			RecruitCostCoins = config.Bind<int>("Recruiting", "RecruitCostCoins", 50, new ConfigDescription("Coins required to recruit a settler from a wild settlement.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			MaxSettlersPerSettlement = config.Bind<int>("Settlement", "MaxSettlers", 10, new ConfigDescription("Maximum settlers that can be assigned to one settlement banner.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			SettlementRadius = config.Bind<float>("Settlement", "SettlementRadius", 32f, new ConfigDescription("Radius in meters around a settlement banner that counts as the settlement (job work area, assignment range, raid target area).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 64f), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			WorkIntervalSeconds = config.Bind<float>("Settlement", "WorkIntervalSeconds", 60f, new ConfigDescription("Seconds between work ticks of an assigned settler (production, repairs, smelting).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 3600f), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			EnableRaids = config.Bind<bool>("Raids", "EnableRaids", true, new ConfigDescription("Register the bandit raid with Valheim's native random event system and allow rival clans to raid player settlements.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			RaidsAfterFirstBoss = config.Bind<bool>("Raids", "RaidsAfterFirstBoss", true, new ConfigDescription("Bandit raids only start after Eikthyr has been defeated.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			RivalRaidChancePerDay = config.Bind<float>("Raids", "RivalRaidChancePerDay", 0.15f, new ConfigDescription("Chance per in-game day that a rival clan raids a player settlement (rolled each night per settlement banner while its area is loaded).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			ClanlessCamps = config.Bind<int>("Raids", "ClanlessCamps", 60, new ConfigDescription("How many clanless bandit camps the world generator attempts to place (new worlds / unexplored areas only). Destroying a camp's war totem permanently reduces rival raid chance. Set to 0 to disable.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 500), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			ScaleRaids = config.Bind<bool>("Raids", "ScaleRaids", true, new ConfigDescription("Rival war parties grow with the target settlement's population and gain star levels as bosses fall (1-star after The Elder, 2-star after Bonemass).", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			CampClearRaidReduction = config.Bind<float>("Raids", "CampClearRaidReduction", 0.05f, new ConfigDescription("Relative reduction of the rival raid chance per cleared clanless camp (destroyed war totem), up to 10 camps. Clearing 10 camps also disables the native bandit raid event.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.1f), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			FoodUpkeep = config.Bind<bool>("Economy", "FoodUpkeep", true, new ConfigDescription("Assigned settlers periodically eat one food item from settlement chests, cheapest first. A settler that finds no food goes hungry and stops working until its next meal.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			MealIntervalSeconds = config.Bind<float>("Economy", "MealIntervalSeconds", 1800f, new ConfigDescription("In-game seconds between meals of an assigned settler. The default of 1800 is roughly one meal per in-game day.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(120f, 7200f), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			GrowthEnabled = config.Bind<bool>("Economy", "GrowthEnabled", true, new ConfigDescription("Settlements below their settler cap can attract a new settler: each night there is a chance a newcomer arrives, provided the settlement has a spare unclaimed bed and enough food in its chests.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			GrowthChancePerDay = config.Bind<float>("Economy", "GrowthChancePerDay", 0.35f, new ConfigDescription("Nightly chance that a new settler arrives when the growth conditions are met.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			GrowthFoodCost = config.Bind<int>("Economy", "GrowthFoodCost", 3, new ConfigDescription("Food items consumed from settlement chests when a new settler arrives.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			RequireWorkstations = config.Bind<bool>("Economy", "RequireWorkstations", true, new ConfigDescription("Jobs need their workstation inside the settlement: blacksmiths a forge, builders a workbench, and farmers a beehive for honey. Disable to restore the ungated 1.1 behavior.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			VeterancyEnabled = config.Bind<bool>("Veterancy", "VeterancyEnabled", true, new ConfigDescription("Settlers earn experience (1 XP per in-game day of assigned service, 2 XP per battle survived) and rise through star levels with vanilla stat scaling.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			XpPerStar = config.Bind<int>("Veterancy", "XpPerStar", 20, new ConfigDescription("Experience required for a settler's first star. The second star costs three times as much.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 200), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			ReputationEnabled = config.Bind<bool>("Reputation", "ReputationEnabled", true, new ConfigDescription("Wild villages track a shared standing toward players: defending villagers and donating coins raise it, attacking them lowers it. Standing scales recruit costs; hated villages refuse recruiting.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			DonationCostCoins = config.Bind<int>("Reputation", "DonationCostCoins", 10, new ConfigDescription("Coins given per donation (Shift+E on a wild settler).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 1000), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			DonationReputation = config.Bind<int>("Reputation", "DonationReputation", 5, new ConfigDescription("Reputation gained per donation.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			MaxPartySize = config.Bind<int>("Party", "MaxPartySize", 4, new ConfigDescription("Maximum recruited villagers that can travel with a player at once. The party is strong because bringing it is a real bet - raising this dilutes the stakes the feature is built on.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 4), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			PartyAutoFallback = config.Bind<bool>("Party", "AutoFallbackWhenGravelyWounded", true, new ConfigDescription("A party member that drops below a quarter health automatically stops fighting and retreats to you. Disabling this removes the telegraphed safety net in front of every companion death.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			PartyRegenPerSecond = config.Bind<float>("Party", "OutOfCombatRegenPerSecond", 2f, new ConfigDescription("Health a party member recovers per second after 10 seconds without taking damage. Keeps losses a moment-to-moment stake instead of an attrition tax between fights. 0 disables.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			PartyStanceKey = config.Bind<KeyboardShortcut>("Party", "StanceHotkey", new KeyboardShortcut((KeyCode)103, Array.Empty<KeyCode>()), "Toggles the whole party between following you and holding position. Client-side.");
			PartyFallbackKey = config.Bind<KeyboardShortcut>("Party", "FallbackHotkey", new KeyboardShortcut((KeyCode)104, Array.Empty<KeyCode>()), "Orders the whole party to fall back: they stop fighting, run to you and take greatly reduced damage. Press again to resume following. Client-side.");
			HomesMatter = config.Bind<bool>("Economy", "HomesMatter", true, new ConfigDescription("Settlers without an assigned home work at half speed. Assign homes by pressing the talk key on a door inside the settlement.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			TalkHotkey = config.Bind<KeyboardShortcut>("Settlers", "TalkHotkey", new KeyboardShortcut((KeyCode)116, Array.Empty<KeyCode>()), "Talk to the settler you are looking at (or the nearest within 5 m): opens a panel with their health, hunger and everything their job still needs before they will work. Client-side.");
		}
	}
	[BepInPlugin("com.abjumb.vikingsettlements", "VikingSettlements", "1.8.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class VikingSettlements : BaseUnityPlugin
	{
		public const string PluginGUID = "com.abjumb.vikingsettlements";

		public const string PluginName = "VikingSettlements";

		public const string PluginVersion = "1.8.2";

		public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			AddLocalizations();
			_harmony = new Harmony("com.abjumb.vikingsettlements");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			PrefabManager.OnVanillaPrefabsAvailable += CreatePrefabs;
			ZoneManager.OnVanillaLocationsAvailable += RegisterLocations;
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new SpawnSettlementCommand());
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new FindSettlementCommand());
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new PartyCommand());
			Logger.LogInfo((object)"VikingSettlements v1.8.2 loaded - settlements appear in newly generated world areas");
		}

		private void CreatePrefabs()
		{
			SettlerPrefabs.CreateAll();
			SettlementPieces.CreateAll();
			PrefabManager.OnVanillaPrefabsAvailable -= CreatePrefabs;
		}

		private void RegisterLocations()
		{
			SettlementLocations.RegisterAll();
		}

		private void Update()
		{
			RaidEvents.EnsureRegistered();
			PartySystem.OnUpdate();
			SettlerTalkPanel.OnUpdate();
		}

		private void AddLocalizations()
		{
			CustomLocalization localization = Localization;
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "vs_settler", "Settler" },
				{ "vs_seer", "Village Seer" },
				{ "vs_trader", "Sigvald the Trader" },
				{ "vs_raider", "Clanless Bandit" },
				{ "vs_banner", "Settlement Banner" },
				{ "vs_banner_desc", "Founds a settlement. Recruit settlers from wild villages and assign them here to work jobs. Beware: settlements attract raids." },
				{ "vs_settlers", "Settlers" },
				{ "vs_recruit", "Recruit" },
				{ "vs_assign", "Assign to settlement" },
				{ "vs_dismiss", "Dismiss" },
				{ "vs_changejob", "Change job" },
				{ "vs_unassign", "Unassign" },
				{ "vs_following", "Following" },
				{ "vs_joined", "joins you!" },
				{ "vs_dismissed", "stays behind" },
				{ "vs_assigned", "settles here!" },
				{ "vs_needcoins", "Not enough coins" },
				{ "vs_nosettlement", "No settlement banner nearby" },
				{ "vs_settlementfull", "This settlement is full" },
				{ "vs_job_villager", "Villager" },
				{ "vs_job_lumberjack", "Lumberjack" },
				{ "vs_job_farmer", "Farmer" },
				{ "vs_job_builder", "Builder" },
				{ "vs_job_blacksmith", "Blacksmith" },
				{ "vs_job_guard", "Guard" },
				{ "vs_job_cook", "Cook" },
				{ "vs_job_miner", "Miner" },
				{ "vs_job_hunter", "Hunter" },
				{ "vs_job_brewer", "Brewer" },
				{ "vs_hungry", "Hungry" },
				{ "vs_veteran", "Veteran" },
				{ "vs_elite", "Elite" },
				{ "vs_levelup", "has grown stronger!" },
				{ "vs_manage", "Manage" },
				{ "vs_rep", "Village standing" },
				{ "vs_rep_honored", "Honored" },
				{ "vs_rep_friendly", "Friendly" },
				{ "vs_rep_neutral", "Neutral" },
				{ "vs_rep_distrusted", "Distrusted" },
				{ "vs_rep_hated", "Hated" },
				{ "vs_rep_refuse", "They refuse to deal with you" },
				{ "vs_donate", "Donate" },
				{ "vs_donated", "The village appreciates your gift" },
				{ "vs_rename", "Rename" },
				{ "vs_rename_topic", "Name your settlement" },
				{ "vs_close", "Close" },
				{ "vs_nosettlers", "No settlers assigned yet — recruit villagers and press E near the banner" },
				{ "vs_col_settler", "SETTLER" },
				{ "vs_col_job", "JOB" },
				{ "vs_col_status", "STATUS" },
				{ "vs_rank_settler", "Settler" },
				{ "vs_status_working", "Working" },
				{ "vs_status_hungry", "Hungry" },
				{ "vs_panel_hint", "Jobs deposit into chests inside the settlement radius" },
				{ "vs_raid_start", "The clanless are raiding!" },
				{ "vs_raid_end", "The clanless retreat" },
				{ "vs_camp_totem", "Clanless War Totem" },
				{ "vs_camp_totem_hint", "Destroy it to weaken the clanless raids" },
				{ "vs_camp_cleared", "A clanless camp is broken! Their raids weaken" },
				{ "vs_party_member", "Party" },
				{ "vs_party_full", "Your party is full" },
				{ "vs_party_waitcmd", "Wait here" },
				{ "vs_party_followcmd", "With me" },
				{ "vs_party_waits", "waits here" },
				{ "vs_party_comes", "follows you" },
				{ "vs_party_stance_follow", "Following" },
				{ "vs_party_stance_hold", "Holding" },
				{ "vs_party_stance_fallback", "Falling back" },
				{ "vs_party_cmd_follow", "Party: with me!" },
				{ "vs_party_cmd_hold", "Party: hold here!" },
				{ "vs_party_cmd_fallback", "Party: fall back!" },
				{ "vs_party_wounded", "is wounded!" },
				{ "vs_party_grave", "is gravely wounded!" },
				{ "vs_party_retreats", "is gravely wounded and retreats to you!" },
				{ "vs_party_fallen", "has fallen" },
				{ "vs_party_aboard", "Your party travels with you" },
				{ "vs_party_ashore", "Your party regroups around you" },
				{ "vs_joined_hint", "They fight at your side — settle them at your banner (E) to put them to work" },
				{ "vs_talk_wild", "A free villager" },
				{ "vs_talk_party", "In your party" },
				{ "vs_talk_party_hint", "Settle them at your settlement banner to give them a job" },
				{ "vs_talk_health", "Health" },
				{ "vs_talk_fed", "Well fed" },
				{ "vs_talk_hungry", "Hungry — nothing to eat! Put food in a settlement chest" },
				{ "vs_talk_nextmeal", "next meal in" },
				{ "vs_talk_needs", "What I need" },
				{ "vs_talk_villager_none", "No duties — press E on me to assign a job" },
				{ "vs_talk_guard_none", "I keep watch. I need nothing more" },
				{ "vs_need_chest", "A chest with room in the settlement" },
				{ "vs_need_food", "Food in a settlement chest" },
				{ "vs_need_workbench", "A workbench in the settlement" },
				{ "vs_need_forge", "A forge in the settlement" },
				{ "vs_need_cookstation", "A cooking station in the settlement" },
				{ "vs_need_fermenter", "A fermenter in the settlement" },
				{ "vs_need_beehive", "A beehive, for honey" },
				{ "vs_need_ore", "Copper/tin ore or iron scraps in one chest" },
				{ "vs_need_rawfood", "Raw meat or fish in one chest" },
				{ "vs_need_brewing", "2 honey or 2 barley together in one chest" },
				{ "vs_need_damage", "Damaged structures to repair" },
				{ "vs_talk_g1", "What do you need, chief?" },
				{ "vs_talk_g2", "The fire is warm tonight." },
				{ "vs_talk_g3", "Odin watches over us." },
				{ "vs_talk_g4", "Good hunting lately, eh?" },
				{ "vs_buildchest", "Builders' Supply Chest" },
				{ "vs_buildchest_desc", "Builders draw construction materials from this chest for their assigned projects. Lumberjacks and miners refill it when an active project runs low." },
				{ "vs_site", "Construction site" },
				{ "vs_bp_cabin", "Cabin" },
				{ "vs_bp_longhouse", "Longhouse" },
				{ "vs_bp_watchtower", "Watchtower" },
				{ "vs_bp_started", "The builders mark out a construction site" },
				{ "vs_bp_busy", "The settlement already has an active construction site" },
				{ "vs_bp_outside", "Too far from the settlement banner — stand where the building should go" },
				{ "vs_bp_cancel", "Cancel project" },
				{ "vs_bp_canceled", "Construction canceled" },
				{ "vs_bp_complete", "The builders have finished" },
				{ "vs_bp_needsbuilder", "Waiting for a builder" },
				{ "vs_supply_low", "The builders are out of materials! Fill the supply chest" },
				{ "vs_talk_build", "What should we build?" },
				{ "vs_talk_project", "Current project" },
				{ "vs_talk_home", "Has a home" },
				{ "vs_talk_homeless", "No home — working slower (talk key on a door)" },
				{ "vs_need_supplies", "Materials in the supply chest" },
				{ "vs_home_title", "Who lives here?" },
				{ "vs_home_occupant", "lives here" },
				{ "vs_home_assign", "Move in" },
				{ "vs_home_unassign", "Move out" },
				{ "vs_home_nosettlement", "This door is not inside a settlement" }
			});
		}
	}
}
namespace VikingSettlements.World
{
	internal static class LayoutBuilder
	{
		private static readonly Dictionary<string, GameObject> _resolved = new Dictionary<string, GameObject>();

		public static int BuildInto(Transform parent, SettlementLayout layout)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			HashSet<string> hashSet = new HashSet<string>();
			foreach (SettlementLayout.Part part in layout.Parts)
			{
				GameObject val = Resolve(part.Prefab);
				if ((Object)(object)val == (Object)null)
				{
					hashSet.Add(part.Prefab);
					continue;
				}
				GameObject obj = Object.Instantiate<GameObject>(val, parent);
				obj.transform.localPosition = part.Position;
				obj.transform.localRotation = Quaternion.Euler(0f, part.RotationY, 0f);
				num++;
			}
			WarnMissing(layout, hashSet);
			return num;
		}

		public static int BuildAt(Vector3 origin, Quaternion rotation, SettlementLayout layout)
		{
			//IL_0046: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			HashSet<string> hashSet = new HashSet<string>();
			foreach (SettlementLayout.Part part in layout.Parts)
			{
				GameObject val = Resolve(part.Prefab);
				if ((Object)(object)val == (Object)null)
				{
					hashSet.Add(part.Prefab);
					continue;
				}
				Object.Instantiate<GameObject>(val, origin + rotation * part.Position, rotation * Quaternion.Euler(0f, part.RotationY, 0f));
				num++;
			}
			WarnMissing(layout, hashSet);
			return num;
		}

		private static GameObject Resolve(string name)
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			if (_resolved.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab(name);
			if ((Object)(object)prefab == (Object)null)
			{
				return null;
			}
			if (name.StartsWith("VS_") || (Object)(object)prefab.GetComponent<WearNTear>() == (Object)null)
			{
				_resolved[name] = prefab;
				return prefab;
			}
			string text = "VS_loc_" + name;
			GameObject val = PrefabManager.Instance.GetPrefab(text) ?? PrefabManager.Instance.CreateClonedPrefab(text, name);
			if ((Object)(object)val == (Object)null)
			{
				_resolved[name] = prefab;
				return prefab;
			}
			WearNTear component = val.GetComponent<WearNTear>();
			component.m_noSupportWear = true;
			component.m_noRoofWear = true;
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val, false));
			_resolved[name] = val;
			return val;
		}

		private static void WarnMissing(SettlementLayout layout, HashSet<string> missing)
		{
			foreach (string item in missing)
			{
				Logger.LogWarning((object)("[" + layout.Name + "] prefab '" + item + "' not found, skipped"));
			}
		}
	}
	internal static class Layouts
	{
		private static SettlementLayout Cabin(string chest = "piece_chest_wood")
		{
			SettlementLayout settlementLayout = new SettlementLayout("cabin");
			float[] array = new float[2] { -1f, 1f };
			foreach (float x in array)
			{
				float[] array2 = new float[2] { -1f, 1f };
				foreach (float z in array2)
				{
					settlementLayout.Add("wood_floor", x, 0f, z);
					settlementLayout.Add("wood_floor", x, 2f, z);
				}
			}
			settlementLayout.Add("wood_wall_full", -1f, 0f, -2f);
			settlementLayout.Add("wood_wall_full", 1f, 0f, -2f);
			settlementLayout.Add("wood_wall_full", -2f, 0f, -1f, 90f);
			settlementLayout.Add("wood_wall_full", -2f, 0f, 1f, 90f);
			settlementLayout.Add("wood_wall_full", 2f, 0f, -1f, 90f);
			settlementLayout.Add("wood_wall_full", 2f, 0f, 1f, 90f);
			settlementLayout.Add("wood_wall_full", -1f, 0f, 2f);
			settlementLayout.Add("wood_door", 1f, 0f, 2f);
			settlementLayout.Add("bed", -1f, 0f, -1f);
			if (chest != null)
			{
				settlementLayout.Add(chest, 1.2f, 0f, -1.5f);
			}
			return settlementLayout;
		}

		private static SettlementLayout Hall(string wall, bool oneMeterCourses, string chest)
		{
			SettlementLayout settlementLayout = new SettlementLayout("hall");
			float[] array = new float[3] { -2f, 0f, 2f };
			float[] array2 = new float[5] { -4f, -2f, 0f, 2f, 4f };
			float[] array3 = array;
			foreach (float x in array3)
			{
				float[] array4 = array2;
				foreach (float z in array4)
				{
					settlementLayout.Add("wood_floor", x, 0f, z);
				}
			}
			array3 = ((!oneMeterCourses) ? new float[1] : new float[2] { 0f, 1f });
			foreach (float y in array3)
			{
				float[] array4 = array2;
				foreach (float z2 in array4)
				{
					settlementLayout.Add(wall, -3f, y, z2, 90f);
					settlementLayout.Add(wall, 3f, y, z2, 90f);
				}
				array4 = array;
				foreach (float x2 in array4)
				{
					settlementLayout.Add(wall, x2, y, -5f);
				}
				settlementLayout.Add(wall, -2f, y, 5f);
				settlementLayout.Add(wall, 2f, y, 5f);
			}
			settlementLayout.Add("wood_door", 0f, 0f, 5f);
			array3 = array2;
			foreach (float z3 in array3)
			{
				settlementLayout.Add("wood_roof_45", -3f, 2f, z3, 90f);
				settlementLayout.Add("wood_roof_45", 3f, 2f, z3, 270f);
				settlementLayout.Add("wood_roof_top_45", 0f, 4f, z3, 90f);
			}
			array3 = new float[2] { -5f, 5f };
			foreach (float num in array3)
			{
				float rotY = ((num < 0f) ? 0f : 180f);
				settlementLayout.Add("wood_wall_roof_45", -2f, 2f, num, rotY);
				settlementLayout.Add("wood_wall_roof_45", 2f, 2f, num, rotY);
				settlementLayout.Add("wood_wall_roof_top_45", 0f, 4f, num, rotY);
			}
			settlementLayout.Add("piece_table", 0f, 0f, -1f);
			settlementLayout.Add("piece_chair", 1.2f, 0f, -1f, 270f);
			settlementLayout.Add("piece_chair", -1.2f, 0f, -1f, 90f);
			settlementLayout.Add("bed", -2f, 0f, -4f);
			settlementLayout.Add("bed", 2f, 0f, -4f);
			if (chest != null)
			{
				settlementLayout.Add(chest, 2f, 0f, -2f, 90f);
			}
			return settlementLayout;
		}

		private static SettlementLayout Watchtower()
		{
			SettlementLayout settlementLayout = new SettlementLayout("watchtower");
			float[] array = new float[2] { -1f, 1f };
			foreach (float x in array)
			{
				float[] array2 = new float[2] { -1f, 1f };
				foreach (float z in array2)
				{
					settlementLayout.Add("wood_pole2", x, 0f, z);
					settlementLayout.Add("wood_pole2", x, 2f, z);
					settlementLayout.Add("wood_pole2", x, 4f, z);
				}
			}
			settlementLayout.Add("wood_floor", 0f, 6f, 0f);
			settlementLayout.Add("wood_fence", 0f, 6f, 1f);
			settlementLayout.Add("wood_fence", 0f, 6f, -1f);
			settlementLayout.Add("wood_fence", 1f, 6f, 0f, 90f);
			settlementLayout.Add("wood_fence", -1f, 6f, 0f, 90f);
			settlementLayout.Add("piece_groundtorch_wood", 0f, 6f, 0f);
			return settlementLayout;
		}

		private static SettlementLayout Farm(string cropA, string cropB)
		{
			SettlementLayout settlementLayout = new SettlementLayout("farm");
			float[] array = new float[3] { -2f, 0f, 2f };
			foreach (float x in array)
			{
				settlementLayout.Add("wood_fence", x, 0f, -2f);
			}
			settlementLayout.Add("wood_fence", -2f, 0f, 2f);
			settlementLayout.Add("wood_fence", 2f, 0f, 2f);
			settlementLayout.Add("wood_gate", 0f, 0f, 2f);
			array = new float[2] { -1f, 1f };
			foreach (float z in array)
			{
				settlementLayout.Add("wood_fence", -3f, 0f, z, 90f);
				settlementLayout.Add("wood_fence", 3f, 0f, z, 90f);
			}
			array = new float[3] { -2f, 0f, 2f };
			foreach (float x2 in array)
			{
				settlementLayout.Add(cropA, x2, 0f, -1f);
				settlementLayout.Add(cropB, x2, 0f, 1f);
			}
			settlementLayout.Add("piece_beehive", 3.8f, 0f, 2.8f);
			return settlementLayout;
		}

		private static SettlementLayout TraderStall()
		{
			SettlementLayout settlementLayout = new SettlementLayout("stall");
			float[] array = new float[2] { -2f, 2f };
			foreach (float x in array)
			{
				float[] array2 = new float[2] { -2f, 2f };
				foreach (float z in array2)
				{
					settlementLayout.Add("wood_pole2", x, 0f, z);
				}
			}
			array = new float[2] { -1f, 1f };
			foreach (float x2 in array)
			{
				float[] array2 = new float[2] { -1f, 1f };
				foreach (float z2 in array2)
				{
					settlementLayout.Add("wood_floor", x2, 2f, z2);
				}
			}
			settlementLayout.Add("VS_Trader", 0f, 0f, 0f, 180f);
			settlementLayout.Add("piece_chest_wood", 1.2f, 0f, -1.2f);
			settlementLayout.Add("piece_banner01", -2f, 0f, 2f);
			return settlementLayout;
		}

		private static SettlementLayout FirePlaza()
		{
			SettlementLayout settlementLayout = new SettlementLayout("plaza");
			settlementLayout.Add("fire_pit", 0f, 0f, 0f);
			settlementLayout.Add("piece_chair", 1.5f, 0f, 0f, 270f);
			settlementLayout.Add("piece_chair", -1.5f, 0f, 0f, 90f);
			settlementLayout.Add("piece_chair", 0f, 0f, 1.5f, 180f);
			settlementLayout.Add("wood_stack", 2.5f, 0f, 1.8f);
			return settlementLayout;
		}

		private static void AddStakeRing(SettlementLayout l, float radius, int segments, float gapDegrees)
		{
			for (int i = 0; i < segments; i++)
			{
				float num = 360f * (float)i / (float)segments;
				if (!(num < gapDegrees / 2f) && !(num > 360f - gapDegrees / 2f))
				{
					float num2 = num * ((float)Math.PI / 180f);
					float x = radius * Mathf.Sin(num2);
					float z = radius * Mathf.Cos(num2);
					l.Add("sharp_stakes", x, 0f, z, num + 90f);
				}
			}
		}

		public static SettlementLayout BlueprintCabin()
		{
			return Cabin();
		}

		public static SettlementLayout BlueprintLonghouse()
		{
			return Hall("wood_wall_full", oneMeterCourses: false, "piece_chest_wood");
		}

		public static SettlementLayout BlueprintWatchtower()
		{
			return Watchtower();
		}

		public static SettlementLayout MeadowsVillage()
		{
			SettlementLayout settlementLayout = new SettlementLayout("VS_MeadowsVillage");
			settlementLayout.Add("VS_VillageHeart", 0f, 0f, 0f);
			settlementLayout.Add("VS_FlattenVillage", 0f, 0f, 0f);
			settlementLayout.Place(FirePlaza(), 0f, 0f);
			settlementLayout.Add("piece_maypole", 4f, 0f, -3f);
			settlementLayout.Place(Cabin(), 0f, -10f);
			settlementLayout.Place(Cabin(), -10f, 0f, 90f);
			settlementLayout.Place(Cabin(null), 10f, 0f, 270f);
			settlementLayout.Place(Hall("wood_wall_full", oneMeterCourses: false, "TreasureChest_meadows"), 0f, 13f, 180f);
			settlementLayout.Place(Farm("Pickable_Carrot", "Pickable_Turnip"), -11f, 10f);
			settlementLayout.Place(TraderStall(), 10f, 9f, 225f);
			settlementLayout.Place(Watchtower(), 10f, -9f);
			(float, float)[] array = new(float, float)[4]
			{
				(2.5f, 2.5f),
				(-2.5f, 3f),
				(-3f, -2.5f),
				(3f, -3.5f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				(float, float) tuple = array[i];
				settlementLayout.Add("piece_groundtorch_wood", tuple.Item1, 0f, tuple.Item2);
			}
			settlementLayout.Add("VS_Settler", 1.2f, 0f, -1.2f, 45f);
			settlementLayout.Add("VS_Settler", -2f, 0f, 1f, 135f);
			settlementLayout.Add("VS_Settler", 0f, 0f, -7f);
			settlementLayout.Add("VS_Settler", -7f, 0f, 1f, 90f);
			settlementLayout.Add("VS_Settler", 7f, 0f, -7f, 315f);
			settlementLayout.Add("VS_Settler", -9f, 0f, 8f);
			settlementLayout.Add("VS_Seer", 0f, 0f, 7f, 180f);
			return settlementLayout;
		}

		public static SettlementLayout ForestOutpost()
		{
			SettlementLayout settlementLayout = new SettlementLayout("VS_ForestOutpost");
			settlementLayout.Add("VS_VillageHeart", 0f, 0f, 0f);
			settlementLayout.Add("VS_FlattenOutpost", 0f, 0f, 0f);
			settlementLayout.Place(Watchtower(), 0f, 0f);
			settlementLayout.Place(Cabin("TreasureChest_blackforest"), -6f, 2f, 90f);
			settlementLayout.Add("fire_pit", 3f, 0f, 2f);
			settlementLayout.Add("wood_stack", 4.5f, 0f, 0.5f);
			settlementLayout.Add("piece_workbench", 3.5f, 0f, -2f, 180f);
			settlementLayout.Add("piece_groundtorch_wood", -1.8f, 0f, 1.8f);
			settlementLayout.Add("piece_groundtorch_wood", 1.8f, 0f, -1.8f);
			AddStakeRing(settlementLayout, 10f, 14, 40f);
			settlementLayout.Add("VS_Settler", 2f, 0f, 2.5f, 225f);
			settlementLayout.Add("VS_Settler", -2.5f, 0f, -1f, 90f);
			settlementLayout.Add("VS_Settler", 0f, 0f, 5f, 180f);
			return settlementLayout;
		}

		public static SettlementLayout ClanlessCamp()
		{
			SettlementLayout settlementLayout = new SettlementLayout("VS_ClanlessCamp");
			settlementLayout.Add("VS_FlattenCamp", 0f, 0f, 0f);
			settlementLayout.Add("fire_pit", 0f, 0f, 0f);
			settlementLayout.Add("VS_CampTotem", 2.5f, 0f, 0.5f);
			settlementLayout.Add("wood_stack", 3f, 0f, -2f);
			(float, float, float)[] array = new(float, float, float)[2]
			{
				(-4.5f, 3.5f, 30f),
				(4f, 4.5f, 300f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				(float, float, float) tuple = array[i];
				float item = tuple.Item1;
				float item2 = tuple.Item2;
				float item3 = tuple.Item3;
				SettlementLayout settlementLayout2 = new SettlementLayout("shelter");
				settlementLayout2.Add("wood_pole2", -1.8f, 0f, -0.8f);
				settlementLayout2.Add("wood_pole2", 1.8f, 0f, -0.8f);
				settlementLayout2.Add("wood_pole2", -1.8f, 0f, 0.8f);
				settlementLayout2.Add("wood_pole2", 1.8f, 0f, 0.8f);
				settlementLayout2.Add("wood_floor", -1f, 2f, 0f);
				settlementLayout2.Add("wood_floor", 1f, 2f, 0f);
				settlementLayout.Place(settlementLayout2, item, item2, item3);
			}
			settlementLayout.Add("TreasureChest_blackforest", -4.5f, 0f, 2.5f, 30f);
			AddStakeRing(settlementLayout, 9f, 10, 70f);
			settlementLayout.Add("VS_Raider", 1.5f, 0f, 1.8f, 200f);
			settlementLayout.Add("VS_Raider", -2f, 0f, -1.2f, 80f);
			settlementLayout.Add("VS_Raider", -1f, 0f, 4f, 160f);
			settlementLayout.Add("VS_Raider", 3.2f, 0f, -3.2f, 340f);
			return settlementLayout;
		}

		public static SettlementLayout PlainsSteading()
		{
			SettlementLayout settlementLayout = new SettlementLayout("VS_PlainsSteading");
			settlementLayout.Add("VS_VillageHeart", 0f, 0f, 0f);
			settlementLayout.Add("VS_FlattenSteading", 0f, 0f, 0f);
			settlementLayout.Place(Hall("stone_wall_2x1", oneMeterCourses: true, "TreasureChest_heath"), 0f, 4f, 180f);
			settlementLayout.Place(Farm("Pickable_Barley", "Pickable_Flax"), -10f, -3f);
			settlementLayout.Place(FirePlaza(), 6f, -5f);
			settlementLayout.Place(Watchtower(), 11f, 2f);
			settlementLayout.Add("piece_groundtorch_wood", 2.5f, 0f, -3f);
			settlementLayout.Add("piece_groundtorch_wood", -2.5f, 0f, -3f);
			AddStakeRing(settlementLayout, 15f, 20, 36f);
			settlementLayout.Add("VS_Settler", 5f, 0f, -4f, 270f);
			settlementLayout.Add("VS_Settler", -8f, 0f, -4f, 90f);
			settlementLayout.Add("VS_Settler", 0f, 0f, -2f, 180f);
			settlementLayout.Add("VS_Seer", 1.5f, 0f, -6f);
			return settlementLayout;
		}
	}
	internal class SettlementLayout
	{
		internal struct Part
		{
			public string Prefab;

			public Vector3 Position;

			public float RotationY;
		}

		public readonly List<Part> Parts = new List<Part>();

		public string Name { get; }

		public SettlementLayout(string name)
		{
			Name = name;
		}

		public void Add(string prefab, float x, float y, float z, float rotY = 0f)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Parts.Add(new Part
			{
				Prefab = prefab,
				Position = new Vector3(x, y, z),
				RotationY = rotY
			});
		}

		public void Place(SettlementLayout structure, float x, float z, float rotY = 0f)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.Euler(0f, rotY, 0f);
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(x, 0f, z);
			foreach (Part part in structure.Parts)
			{
				Parts.Add(new Part
				{
					Prefab = part.Prefab,
					Position = val * part.Position + val2,
					RotationY = part.RotationY + rotY
				});
			}
		}
	}
	internal static class SettlementLocations
	{
		public const string MeadowsVillageLocation = "VS_MeadowsVillage";

		public const string ForestOutpostLocation = "VS_ForestOutpost";

		public const string PlainsSteadingLocation = "VS_PlainsSteading";

		public const string ClanlessCampLocation = "VS_ClanlessCamp";

		private static bool _registered;

		public static void RegisterAll()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0048: 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_005a: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: 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_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: 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_0204: Expected O, but got Unknown
			if (!_registered)
			{
				_registered = true;
				Register(Layouts.MeadowsVillage(), new LocationConfig
				{
					Biome = (Biome)1,
					Quantity = ModConfig.MeadowsVillages.Value,
					Priotized = true,
					ExteriorRadius = 26f,
					ClearArea = true,
					RandomRotation = true,
					MinAltitude = 3f,
					MinDistance = 700f,
					MinDistanceFromSimilar = 900f,
					MaxTerrainDelta = 3f,
					Group = "vs_settlements"
				});
				Register(Layouts.ForestOutpost(), new LocationConfig
				{
					Biome = (Biome)8,
					Quantity = ModConfig.ForestOutposts.Value,
					Priotized = false,
					ExteriorRadius = 14f,
					ClearArea = true,
					RandomRotation = true,
					MinAltitude = 2f,
					MinDistance = 600f,
					MinDistanceFromSimilar = 600f,
					MaxTerrainDelta = 3f,
					Group = "vs_settlements"
				});
				Register(Layouts.PlainsSteading(), new LocationConfig
				{
					Biome = (Biome)16,
					Quantity = ModConfig.PlainsSteadings.Value,
					Priotized = false,
					ExteriorRadius = 20f,
					ClearArea = true,
					RandomRotation = true,
					MinAltitude = 3f,
					MinDistance = 1500f,
					MinDistanceFromSimilar = 800f,
					MaxTerrainDelta = 3f,
					Group = "vs_settlements"
				});
				Register(Layouts.ClanlessCamp(), new LocationConfig
				{
					Biome = (Biome)25,
					Quantity = ModConfig.ClanlessCamps.Value,
					Priotized = false,
					ExteriorRadius = 14f,
					ClearArea = true,
					RandomRotation = true,
					MinAltitude = 2f,
					MinDistance = 900f,
					MinDistanceFromSimilar = 700f,
					MaxTerrainDelta = 3f,
					Group = "vs_camps"
				});
			}
		}

		private static void Register(SettlementLayout layout, LocationConfig config)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			if (config.Quantity <= 0)
			{
				Logger.LogInfo((object)("Location " + layout.Name + " disabled via config"));
				return;
			}
			GameObject val = ZoneManager.Instance.CreateLocationContainer(layout.Name);
			int num = LayoutBuilder.BuildInto(val.transform, layout);
			if (num == 0)
			{
				Logger.LogWarning((object)("Location " + layout.Name + " has no valid parts, not registered"));
				return;
			}
			ZoneManager.Instance.AddCustomLocation(new CustomLocation(val, false, config));
			Logger.LogInfo((object)$"Registered location {layout.Name} ({num} parts, quantity {config.Quantity})");
		}
	}
}
namespace VikingSettlements.Settlements
{
	internal class Blueprint
	{
		public string Id;

		public string NameToken;

		public int WoodCost;

		public int StoneCost;

		public Func<SettlementLayout> Layout;
	}
	internal static class Blueprints
	{
		public static readonly Blueprint[] All = new Blueprint[3]
		{
			new Blueprint
			{
				Id = "cabin",
				NameToken = "$vs_bp_cabin",
				WoodCost = 40,
				StoneCost = 0,
				Layout = Layouts.BlueprintCabin
			},
			new Blueprint
			{
				Id = "watchtower",
				NameToken = "$vs_bp_watchtower",
				WoodCost = 30,
				StoneCost = 0,
				Layout = Layouts.BlueprintWatchtower
			},
			new Blueprint
			{
				Id = "longhouse",
				NameToken = "$vs_bp_longhouse",
				WoodCost = 100,
				StoneCost = 10,
				Layout = Layouts.BlueprintLonghouse
			}
		};

		public static Blueprint Find(string id)
		{
			Blueprint[] all = All;
			foreach (Blueprint blueprint in all)
			{
				if (blueprint.Id == id)
				{
					return blueprint;
				}
			}
			return null;
		}
	}
	public class BuildChest : MonoBehaviour
	{
		public static readonly List<BuildChest> Instances = new List<BuildChest>();

		private Container _container;

		private void Awake()
		{
			_container = ((Component)this).GetComponent<Container>();
		}

		private void OnEnable()
		{
			Instances.Add(this);
		}

		private void OnDisable()
		{
			Instances.Remove(this);
		}

		internal static int CountAround(Vector3 center, string prefabName)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			string text = SettlerWork.SharedName(prefabName);
			if (text == null)
			{
				return 0;
			}
			float value = ModConfig.SettlementRadius.Value;
			int num = 0;
			foreach (BuildChest instance in Instances)
			{
				Inventory val = instance.InventoryIfNear(center, value);
				if (val != null)
				{
					num += val.CountItems(text, -1, true);
				}
			}
			return num;
		}

		internal static int ConsumeAround(Vector3 center, string prefabName, int amount)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			string text = SettlerWork.SharedName(prefabName);
			if (text == null || amount <= 0)
			{
				return 0;
			}
			float value = ModConfig.SettlementRadius.Value;
			int num = 0;
			foreach (BuildChest instance in Instances)
			{
				if (num >= amount)
				{
					break;
				}
				Inventory val = instance.InventoryIfNear(center, value);
				if (val != null)
				{
					int num2 = Mathf.Min(val.CountItems(text, -1, true), amount - num);
					if (num2 > 0)
					{
						val.RemoveItem(text, num2, -1, true);
						num += num2;
					}
				}
			}
			return num;
		}

		internal static bool DepositAround(Vector3 center, ItemData item)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			float value = ModConfig.SettlementRadius.Value;
			foreach (BuildChest instance in Instances)
			{
				Inventory val = instance.InventoryIfNear(center, value);
				if (val != null && val.CanAddItem(item, -1))
				{
					val.AddItem(item);
					return true;
				}
			}
			return false;
		}

		internal static bool AnyAround(Vector3 center)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			float value = ModConfig.SettlementRadius.Value;
			foreach (BuildChest instance in Instances)
			{
				if ((Object)(object)instance != (Object)null && Vector3.Distance(((Component)instance).transform.position, center) <= value)
				{
					return true;
				}
			}
			return false;
		}

		private Inventory InventoryIfNear(Vector3 center, float radius)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_container == (Object)null || Vector3.Distance(((Component)this).transform.position, center) > radius)
			{
				return null;
			}
			return _container.GetInventory();
		}
	}
	public class ConstructionSite : MonoBehaviour, Hoverable, Interactable
	{
		public const string BlueprintKey = "vs_bp";

		public const string WoodKey = "vs_bpwood";

		public const string StoneKey = "vs_bpstone";

		private const int WoodPerTick = 8;

		private const int StonePerTick = 2;

		private const float SupplyWarnSeconds = 120f;

		public static readonly List<ConstructionSite> Instances = new List<ConstructionSite>();

		private ZNetView _nview;

		private float _supplyTimer;

		internal Blueprint Blueprint
		{
			get
			{
				if (!((Object)(object)_nview != (Object)null) || !_nview.IsValid())
				{
					return null;
				}
				return Blueprints.Find(_nview.GetZDO().GetString("vs_bp", ""));
			}
		}

		internal int Wood
		{
			get
			{
				return _nview.GetZDO().GetInt("vs_bpwood", 0);
			}
			set
			{
				_nview.GetZDO().Set("vs_bpwood", value);
			}
		}

		internal int Stone
		{
			get
			{
				return _nview.GetZDO().GetInt("vs_bpstone", 0);
			}
			set
			{
				_nview.GetZDO().Set("vs_bpstone", value);
			}
		}

		private void Awake()
		{
			_nview = ((Component)this).GetComponent<ZNetView>();
		}

		private void OnEnable()
		{
			Instances.Add(this);
		}

		private void OnDisable()
		{
			Instances.Remove(this);
		}

		internal static ConstructionSite FindNear(Vector3 center)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			float value = ModConfig.SettlementRadius.Value;
			foreach (ConstructionSite instance in Instances)
			{
				if ((Object)(object)instance != (Object)null && Vector3.Distance(((Component)instance).transform.position, center) <= value)
				{
					return instance;
				}
			}
			return null;
		}

		internal int RemainingOf(string prefabName)
		{
			Blueprint blueprint = Blueprint;
			if (blueprint == null)
			{
				return 0;
			}
			if (!(prefabName == "Wood"))
			{
				if (prefabName == "Stone")
				{
					return Mathf.Max(0, blueprint.StoneCost - Stone);
				}
				return 0;
			}
			return Mathf.Max(0, blueprint.WoodCost - Wood);
		}

		internal bool StillNeeds(string prefabName)
		{
			return RemainingOf(prefabName) > 0;
		}

		internal bool SuppliesAvailable()
		{
			//IL_0013: 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)
			if (StillNeeds("Wood") && BuildChest.CountAround(((Component)this).transform.position, "Wood") == 0)
			{
				return false;
			}
			if (StillNeeds("Stone") && BuildChest.CountAround(((Component)this).transform.position, "Stone") == 0)
			{
				return false;
			}
			return true;
		}

		internal void BuildTick()
		{
			//IL_0051: 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)
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return;
			}
			Blueprint blueprint = Blueprint;
			if (blueprint != null)
			{
				_nview.ClaimOwnership();
				int num = blueprint.WoodCost - Wood;
				if (num > 0)
				{
					Wood += BuildChest.ConsumeAround(((Component)this).transform.position, "Wood", Mathf.Min(8, num));
				}
				int num2 = blueprint.StoneCost - Stone;
				if (num2 > 0)
				{
					Stone += BuildChest.ConsumeAround(((Component)this).transform.position, "Stone", Mathf.Min(2, num2));
				}
				if (Wood >= blueprint.WoodCost && Stone >= blueprint.StoneCost)
				{
					Complete(blueprint);
				}
			}
		}

		private void Complete(Blueprint blueprint)
		{
			//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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			Vector3 position = ((Component)this).transform.position;
			Quaternion rotation = Quaternion.Euler(0f, ((Component)this).transform.eulerAngles.y, 0f);
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				ZNetScene.instance.Destroy(((Component)this).gameObject);
			}
			LayoutBuilder.BuildAt(position, rotation, blueprint.Layout());
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && Vector3.Distance(((Component)localPlayer).transform.position, position) < 50f)
			{
				((Character)localPlayer).Message((MessageType)2, Localization.instance.Localize("$vs_bp_complete: " + blueprint.NameToken), 0, (Sprite)null);
			}
		}

		private void Update()
		{
			//IL_0031: 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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return;
			}
			if (Vector3.Distance(((Component)localPlayer).transform.position, ((Component)this).transform.position) > ModConfig.SettlementRadius.Value + 30f)
			{
				_supplyTimer = 0f;
				return;
			}
			_supplyTimer += Time.deltaTime;
			if (!(_supplyTimer < 120f))
			{
				_supplyTimer = 0f;
				if (Blueprint != null && !SuppliesAvailable())
				{
					((Character)localPlayer).Message((MessageType)2, Localization.instance.Localize("$vs_supply_low"), 0, (Sprite)null);
				}
			}
		}

		public string GetHoverName()
		{
			return Localization.instance.Localize("$vs_site");
		}

		public string GetHoverText()
		{
			Blueprint blueprint = Blueprint;
			if (blueprint == null)
			{
				return Localization.instance.Localize("$vs_site");
			}
			string text = $"$item_wood {Wood}/{blueprint.WoodCost}";
			if (blueprint.StoneCost > 0)
			{
				text += $"   $item_stone {Stone}/{blueprint.StoneCost}";
			}
			string text2 = "";
			if (!HasBuilder())
			{
				text2 = "\n<color=orange>$vs_bp_needsbuilder</color>";
			}
			else if (!SuppliesAvailable())
			{
				text2 = "\n<color=orange>$vs_supply_low</color>";
			}
			return Localization.instance.Localize("$vs_site: " + blueprint.NameToken + "\n" + text + text2 + "\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] $vs_bp_cancel");
		}

		private bool HasBuilder()
		{
			//IL_0038: 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)
			float value = ModConfig.SettlementRadius.Value;
			foreach (SettlerRecruitable instance in SettlerRecruitable.Instances)
			{
				if (instance.State == SettlerState.Assigned && instance.Job == SettlerJob.Builder && Vector3.Distance(((Component)instance).transform.position, ((Component)this).transform.position) <= value)
				{
					return true;
				}
			}
			return false;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (hold || !alt || (Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return false;
			}
			Player val = (Player)(object)((user is Player) ? user : null);
			_nview.ClaimOwnership();
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				ZNetScene.instance.Destroy(((Component)this).gameObject);
			}
			if ((Object)(object)val != (Object)null)
			{
				((Character)val).Message((MessageType)1, Localization.instance.Localize("$vs_bp_canceled"), 0, (Sprite)null);
			}
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}
	}
	internal static class HomeAssignPanel
	{
		private class PanelBehaviour : MonoBehaviour
		{
			private void Update()
			{
				//IL_0031: 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)
				if (Input.GetKeyDown((KeyCode)27))
				{
					Close();
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)_door == (Object)null || (Object)(object)localPlayer == (Object)null || Vector3.Distance(((Component)localPlayer).transform.position, ((Component)_door).transform.position) > 8f)
				{
					Close();
				}
			}
		}

		private const float PanelWidth = 520f;

		private const float RowHeight = 36f;

		private const int MaxRows = 10;

		private static GameObject _panel;

		private static Door _door;

		private static PlayerSettlement _settlement;

		internal static bool IsOpen => (Object)(object)_panel != (Object)null;

		public static void Open(Door door, PlayerSettlement settlement)
		{
			Close();
			if (!((Object)(object)door == (Object)null) && !((Object)(object)settlement == (Object)null) && GUIManager.Instance != null && !((Object)(object)GUIManager.CustomGUIFront == (Object)null))
			{
				_door = door;
				_settlement = settlement;
				Build();
				GUIManager.BlockInput(true);
			}
		}

		public static void Close()
		{
			if ((Object)(object)_panel != (Object)null)
			{
				Object.Destroy((Object)(object)_panel);
				_panel = null;
				GUIManager.BlockInput(false);
			}
			_door = null;
			_settlement = null;
		}

		private static void Rebuild()
		{
			Door door = _door;
			PlayerSettlement settlement = _settlement;
			Close();
			Open(door, settlement);
		}

		private static void Build()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: 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_0237: 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_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Expected O, but got Unknown
			List<SettlerRecruitable> settlers = _settlement.GetSettlers();
			int num = Mathf.Min(settlers.Count, 10);
			float num2 = 96f + (float)Mathf.Max(1, num) * 36f + 64f;
			_panel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, 520f, num2);
			_panel.AddComponent<PanelBehaviour>();
			GUIManager.Instance.CreateText(Localization.instance.Localize("$vs_home_title"), _panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -36f), GUIManager.Instance.AveriaSerifBold, 24, GUIManager.Instance.ValheimOrange, true, Color.black, 460f, 36f, false);
			GUIManager.Instance.CreateText(_settlement.DisplayName, _panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -66f), GUIManager.Instance.AveriaSerif, 16, UiPalette.SecondaryOnWood, true, Color.black, 460f, 26f, false);
			if (settlers.Count == 0)
			{
				GUIManager.Instance.CreateText(Localization.instance.Localize("$vs_nosettlers"), _panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -114f), GUIManager.Instance.AveriaSerif, 17, UiPalette.SecondaryOnWood, true, Color.black, 460f, 28f, false);
			}
			for (int i = 0; i < num; i++)
			{
				BuildRow(settlers[i], 0f - (96f + 36f * (float)i + 18f));
			}
			((UnityEvent)GUIManager.Instance.CreateButton(Localization.instance.Localize("$vs_close"), _panel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 36f), 140f, 38f).GetComponent<Button>().onClick).AddListener(new UnityAction(Close));
		}

		private static void BuildRow(SettlerRecruitable settler, float y)
		{
			//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_002a: 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_00db: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0193: Expected O, but got Unknown
			Vector3 doorPosition = ((Component)_door).transform.position;
			bool livesHere = SettlerHousing.LivesAt(settler, doorPosition);
			bool flag = !livesHere && SettlerHousing.HasHome(settler);
			string text = settler.GetHoverName() + " — " + Localization.instance.Localize(SettlerRecruitable.JobToken(settler.Job)) + (livesHere ? Localization.instance.Localize(" <color=#a6ffa6>($vs_home_occupant)</color>") : (flag ? Localization.instance.Localize(" <color=grey>($vs_talk_home)</color>") : ""));
			GUIManager.Instance.CreateText(text, _panel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(206f, y), GUIManager.Instance.AveriaSerif, 17, Color.white, true, Color.black, 340f, 30f, false);
			((UnityEvent)GUIManager.Instance.CreateButton(Localization.instance.Localize(livesHere ? "$vs_home_unassign" : "$vs_home_assign"), _panel.transform, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-84f, y), 110f, 30f).GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				//IL_0031: 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)
				if (livesHere)
				{
					SettlerHousing.ClearHome(settler);
				}
				else
				{
					foreach (SettlerRecruitable settler2 in _settlement.GetSettlers())
					{
						if (SettlerHousing.LivesAt(settler2, doorPosition))
						{
							SettlerHousing.ClearHome(settler2);
						}
					}
					SettlerHousing.AssignHome(settler, doorPosition);
				}
				Rebuild();
			});
		}
	}
	public class PlayerSettlement : MonoBehaviour, Hoverable, Interactable, TextReceiver
	{
		private const string LastRaidDayKey = "vs_lastraid";

		private const string NameKey = "vs_name";

		private const int NameCharLimit = 30;

		public static readonly List<PlayerSettlement> Instances = new List<PlayerSettlement>();

		private ZNetView _nview;

		public string DisplayName
		{
			get
			{
				string text = (((Object)(object)_nview != (Object)null && _nview.IsValid()) ? _nview.GetZDO().GetString("vs_name", "") : "");
				if (!string.IsNullOrEmpty(text))
				{
					return text;
				}
				return Localization.instance.Localize("$vs_banner");
			}
		}

		private void Awake()
		{
			_nview = ((Component)this).GetComponent<ZNetView>();
		}

		private void OnEnable()
		{
			Instances.Add(this);
		}

		private void OnDisable()
		{
			Instances.Remove(this);
		}

		public static PlayerSettlement FindNearest(Vector3 position, float maxDistance)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			PlayerSettlement result = null;
			float num = maxDistance;
			foreach (PlayerSettlement instance in Instances)
			{
				float num2 = Vector3.Distance(((Component)instance).transform.position, position);
				if (num2 <= num)
				{
					result = instance;
					num = num2;
				}
			}
			return result;
		}

		internal List<SettlerRecruitable> GetSettlers()
		{
			//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)
			float value = ModConfig.SettlementRadius.Value;
			List<SettlerRecruitable> list = new List<SettlerRecruitable>();
			foreach (SettlerRecruitable instance in SettlerRecruitable.Instances)
			{
				if (instance.State == SettlerState.Assigned && Vector3.Distance(instance.Home, ((Component)this).transform.position) <= value)
				{
					list.Add(instance);
				}
			}
			list.Sort((SettlerRecruitable a, SettlerRecruitable b) => string.CompareOrdinal(a.GetHoverName(), b.GetHoverName()));
			return list;
		}

		public int CountAssignedSettlers()
		{
			return GetSettlers().Count;
		}

		private Dictionary<SettlerJob, int> CountJobs()
		{
			Dictionary<SettlerJob, int> dictionary = new Dictionary<SettlerJob, int>();
			foreach (SettlerRecruitable settler in GetSettlers())
			{
				dictionary.TryGetValue(settler.Job, out var value);
				dictionary[settler.Job] = value + 1;
			}
			return dictionary;
		}

		public string GetText()
		{
			if (!((Object)(object)_nview != (Object)null) || !_nview.IsValid())
			{
				return "";
			}
			return _nview.GetZDO().GetString("vs_name", "");
		}

		public void SetText(string text)
		{
			if (!((Object)(object)_nview == (Object)null) && _nview.IsValid())
			{
				text = ((text == null) ? "" : text.Trim());
				if (text.Length > 30)
				{
					text = text.Substring(0, 30);
				}
				_nview.ClaimOwnership();
				_nview.GetZDO().Set("vs_name", text);
			}
		}

		private void Update()
		{
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid() || !_nview.IsOwner() || (Object)(object)EnvMan.instance == (Object)null || !EnvMan.IsNight())
			{
				return;
			}
			int currentDay = EnvMan.instance.GetCurrentDay();
			int num = _nview.GetZDO().GetInt("vs_lastraid", -1);
			if (currentDay > num)
			{
				_nview.GetZDO().Set("vs_lastraid", currentDay);
				if (ModConfig.EnableRaids.Value && Random.value < RaidSpawner.EffectiveRaidChance())
				{
					RaidSpawner.SpawnRivalRaid(this);
				}
				TryGrow();
			}
		}

		private void TryGrow()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.GrowthEnabled.Value && !(Random.value >= ModConfig.GrowthChancePerDay.Value))
			{
				int num = CountAssignedSettlers();
				if (num < ModConfig.MaxSettlersPerSettlement.Value && CountUnclaimedBeds() >= num + 1 && SettlerWork.ConsumeFoodAround(((Component)this).transform.position, ModConfig.GrowthFoodCost.Value))
				{
					SpawnNewcomer();
				}
			}
		}

		private int CountUnclaimedBeds()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			float value = ModConfig.SettlementRadius.Value;
			int num = 0;
			Bed[] array = Object.FindObjectsOfType<Bed>();
			foreach (Bed val in array)
			{
				if (val.GetOwner() == 0L && Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) <= value)
				{
					num++;
				}
			}
			return num;
		}

		private void SpawnNewcomer()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//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_00b9: 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_00cd: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			string text = ((Random.value < 0.15f) ? "VS_Seer" : "VS_Settler");
			GameObject val = PrefabManager.Instance.GetPrefab(text) ?? PrefabManager.Instance.GetPrefab("VS_Settler");
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 position = ((Component)this).transform.position;
				float num = Random.value * 360f * ((float)Math.PI / 180f);
				float num2 = ModConfig.SettlementRadius.Value + 6f;
				Vector3 val2 = position + new Vector3(Mathf.Sin(num) * num2, 0f, Mathf.Cos(num) * num2);
				if ((Object)(object)ZoneSystem.instance != (Object)null)
				{
					val2.y = ZoneSystem.instance.GetGroundHeight(val2);
				}
				Vector3 val3 = position - val2;
				val3.y = 0f;
				GameObject obj = Object.Instantiate<GameObject>(val, val2, Quaternion.LookRotation(((Vector3)(ref val3)).normalized));
				ZNetView component = obj.GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					component.GetZDO().Set("vs_state", 2);
					component.GetZDO().Set("vs_job", 0);
					component.GetZDO().Set("vs_home", position);
				}
				MonsterAI component2 = obj.GetComponent<MonsterAI>();
				if ((Object)(object)component2 != (Object)null)
				{
					((BaseAI)component2).SetPatrolPoint(position);
				}
				Logger.LogInfo((object)$"A newcomer joined the settlement at {position}");
			}
		}

		public string GetHoverName()
		{
			return DisplayName;
		}

		public string GetHoverText()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<SettlerJob, int> dictionary = CountJobs();
			int num = 0;
			List<string> list = new List<string>();
			foreach (KeyValuePair<SettlerJob, int> item in dictionary)
			{
				num += item.Value;
				list.Add($"{item.Value} {SettlerRecruitable.JobToken(item.Key)}");
			}
			string text = ((list.Count > 0) ? ("\n" + string.Join(", ", list)) : "");
			float value = ModConfig.SettlementRadius.Value;
			int num2 = 0;
			foreach (SettlerRecruitable instance in SettlerRecruitable.Instances)
			{
				if (instance.State == SettlerState.Assigned && instance.IsHungry && Vector3.Distance(instance.Home, ((Component)this).transform.position) <= value)
				{
					num2++;
				}
			}
			string text2 = ((num2 > 0) ? $"\n$vs_hungry: {num2}" : "");
			return Localization.instance.Localize($"{DisplayName}\n$vs_settlers: {num}/{ModConfig.MaxSettlersPerSettlement.Value}{text}{text2}" + "\n[<color=yellow><b>$KEY_Use</b></color>] $vs_manage\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] $vs_rename");
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (hold)
			{
				return false;
			}
			if ((Object)(object)((user is Player) ? user : null) == (Object)null)
			{
				return false;
			}
			if (alt)
			{
				if ((Object)(object)TextInput.instance != (Object)null)
				{
					TextInput.instance.RequestText((TextReceiver)(object)this, "$vs_rename_topic", 30);
				}
				return true;
			}
			SettlementPanel.Toggle(this);
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}
	}
	internal static class SettlementPanel
	{
		private class PanelBehaviour : MonoBehaviour
		{
			private void Update()
			{
				//IL_0031: 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)
				if (Input.GetKeyDown((KeyCode)27))
				{
					Close();
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)_settlement == (Object)null || (Object)(object)localPlayer == (Object)null || Vector3.Distance(((Component)localPlayer).transform.position, ((Component)_settlement).transform.position) > 12f)
				{
					Close();
				}
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__15_0;

			internal void <BuildHeader>b__15_0()
			{
				PlayerSettlement settlement = _settlement;
				Close();
				if ((Object)(object)settlement != (Object)null && (Object)(object)TextInput.instance != (Object)null)
				{
					TextInput.instance.RequestText((TextReceiver)(object)settlement, "$vs_rename_topic", 30);
				}
			}
		}

		private const float PanelWidth = 720f;

		private const float HeaderHeight = 96f;

		private const float ColumnHeaderHeight = 26f;

		private const float RowHeight = 48f;

		private const float FooterHeight = 72f;

		private const int MaxRows = 10;

		private static GameObject _panel;

		private static PlayerSettlement _settlement;

		internal static bool IsOpen => (Object)(object)_panel != (Object)null;

		public static void Toggle(PlayerSettlement settlement)
		{
			if ((Object)(object)_panel != (Object)null && (Object)(object)_settlement == (Object)(object)settlement)
			{
				Close();
			}
			else
			{
				Open(settlement);
			}
		}

		public static void Open(PlayerSettlement settlement)
		{
			Close();
			if (!((Object)(object)settlement == (Object)null) && GUIManager.Instance != null && !((Object)(object)GUIManager.CustomGUIFront == (Object)null))
			{
				_settlement = settlement;
				Build();
				GUIManager.BlockInput(true);
			}
		}

		public static void Close()
		{
			if ((Object)(object)_panel != (Object)null)
			{
				Object.Destroy((Object)(object)_panel);
				_panel = null;
				GUIManager.BlockInput(false);
			}
			_settlement = null;
		}

		private static void Rebuild()
		{
			PlayerSettlement settlement = _settlement;
			Close();
			Open(settlement);
		}

		private static void Build()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_00d3: 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_014e: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			List<SettlerRecruitable> settlers = _settlement.GetSettlers();
			int num = Mathf.Min(settlers.Count, 10);
			float num2 = 122f + (float)Mathf.Max(1, num) * 48f + ((settlers.Count > 10) ? 22f : 0f) + 72f;
			_panel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, 720f, num2);
			_panel.AddComponent<PanelBehaviour>();
			BuildHeader(settlers);
			BuildColumnHeaders();
			if (settlers.Count == 0)
			{
				Text(Localization.instance.Localize("$vs_nosettlers"), new Vector2(0.5f, 1f), new Vector2(0f, -146f), 17, UiPalette.SecondaryOnWood, 600f, 30f).alignment = (TextAnchor)4;
			}
			for (int i = 0; i < num; i++)
			{
				BuildRow(settlers[i], 0f - (122f + 48f * (float)i + 24f));
			}
			if (settlers.Count > 10)
			{
				Text($"+{settlers.Count - 10}", new Vector2(0.5f, 1f), new Vector2(0f, -612f), 14, UiPalette.SecondaryOnWood, 200f, 20f).alignment = (TextAnchor)4;
			}
			BuildFooter();
		}

		private static void BuildHeader(List<SettlerRecruitable> settlers)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: 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)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: 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_026f: Expected O, but got Unknown
			Text(_settlement.DisplayName, new Vector2(0f, 1f), new Vector2(216f, -34f), 26, GUIManager.Instance.ValheimOrange, 380f, 38f, GUIManager.Instance.AveriaSerifBold).alignment = (TextAnchor)3;
			int count = settlers.Count;
			int value = ModConfig.MaxSettlersPerSettlement.Value;
			Text(Localization.instance.Localize($"$vs_settlers {count}/{value}"), new Vector2(0f, 1f), new Vector2(96f, -68f), 15, UiPalette.Beige, 140f, 22f).alignment = (TextAnchor)3;
			Vector2 anchor = default(Vector2);
			((Vector2)(ref anchor))..ctor(0f, 1f);
			UiPalette.CreateRect(_panel.transform, anchor, new Vector2(261f, -68f), 150f, 8f, UiPalette.BarTrack);
			float num = ((value > 0) ? (150f * Mathf.Clamp01((float)count / (float)value)) : 0f);
			if (num > 0f)
			{
				UiPalette.CreateRect(_panel.transform, anchor, new Vector2(186f + num / 2f, -68f), num, 8f, UiPalette.BarFill);
			}
			int num2 = 0;
			foreach (SettlerRecruitable settler in settlers)
			{
				if (settler.IsHungry)
				{
					num2++;
				}
			}
			if (num2 > 0)
			{
				Text(Localization.instance.Localize($"{num2} $vs_hungry"), new Vector2(0f, 1f), new Vector2(410f, -68f), 15, UiPalette.Warning, 120f, 22f).alignment = (TextAnchor)3;
			}
			ButtonClickedEvent onClick = GUIManager.Instance.CreateButton(Localization.instance.Localize("$vs_rename"), _panel.transform, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-81f, -42f), 110f, 36f).GetComponent<Button>().onClick;
			object obj = <>c.<>9__15_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					PlayerSettlement settlement = _settlement;
					Close();
					if ((Object)(object)settlement != (Object)null && (Object)(object)TextInput.instance != (Object)null)
					{
						TextInput.instance.RequestText((TextReceiver)(object)settlement, "$vs_rename_topic", 30);
					}
				};
				<>c.<>9__15_0 = val;
				obj = (object)val;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
		}

		private static void BuildColumnHeaders()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0070: 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_00ab: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			float num = -109f;
			Text(Localization.instance.Localize("$vs_col_settler"), new Vector2(0f, 1f), new Vector2(106f, num), 12, UiPalette.ColumnHeader, 160f, 18f).alignment = (TextAnchor)3;
			Text(Localization.instance.Localize("$vs_col_job"), new Vector2(1f, 1f), new Vector2(-213f, num), 12, UiPalette.ColumnHeader, 210f, 18f).alignment = (TextAnchor)3;
			Text(Localization.instance.Localize("$vs_col_status"), new Vector2(1f, 1f), new Vector2(-61f, num), 12, UiPalette.ColumnHeader, 70f, 18f).alignment = (TextAnchor)5;
		}

		private static void BuildRow(SettlerRecruitable settler, float y)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0092: 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_0104: 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)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: 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_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: 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_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Expected O, but got Unknown
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			Vector2 anchor = default(Vector2);
			((Vector2)(ref anchor))..ctor(0f, 1f);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 1f);
			Character component = ((Component)settler).GetComponent<Character>();
			int num = ((!((Object)(object)component != (Object)null)) ? 1 : component.GetLevel());
			UiPalette.CreateRect(_panel.transform, anchor, new Vector2(52f, y), 52f, 34f, UiPalette.BadgeWood);
			Text($"Lvl. {num}", anchor, new Vector2(52f, y), 13, UiPalette.BadgeGold, 52f, 20f).alignment = (TextAnchor)4;
			string text = ((num >= 3) ? " <color=#FFE300>★★</color>" : ((num == 2) ? " <color=#FFE300>★</color>" : ""));
			string text2 = (((Object)(object)component != (Object)null) ? component.m_name : settler.GetHoverName());
			Text(Localization.instance.Localize(text2) + text, anchor, new Vector2(216f, y - 8f), 17, Color.white, 240f, 24f).alignment = (TextAnchor)3;
			string text3 = ((num >= 3) ? "$vs_elite" : ((num == 2) ? "$vs_veteran" : "$vs_rank_settler"));
			Text(Localization.instance.Localize(text3), anchor, new Vector2(216f, y + 11f), 13, UiPalette.SecondaryOnWood, 240f, 18f).alignment = (TextAnchor)3;
			((UnityEvent)GUIManager.Instance.CreateButton("<", _panel.transform, val, val, new Vector2(-304f, y), 28f, 28f).GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				ChangeJob(settler, -1);
			});
			UiPalette.CreateRect(_panel.transform, val, new Vector2(-208f, y), 148f, 28f, UiPalette.WellDark);
			Text(Localization.instance.Localize(SettlerRecruitable.JobToken(settler.Job)), val, new Vector2(-208f, y), 15, UiPalette.Beige, 148f, 22f).alignment = (TextAnchor)4;
			((UnityEvent)GUIManager.Inst