Decompiled source of End Of The World v1.0.3

Mods/WoodStudios.EndOfTheWorld.dll

Decompiled 5 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using EndOfTheWorld;
using HarmonyLib;
using HoldTheFort;
using Il2CppFishNet.Object;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Avatar;
using Il2CppScheduleOne.AvatarFramework;
using Il2CppScheduleOne.AvatarFramework.Equipping;
using Il2CppScheduleOne.Cartel;
using Il2CppScheduleOne.Combat;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Doors;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.EntityFramework;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Law;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Behaviour;
using Il2CppScheduleOne.NPCs.Responses;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Police;
using Il2CppScheduleOne.Product;
using Il2CppScheduleOne.Property;
using Il2CppScheduleOne.Quests;
using Il2CppScheduleOne.UI.Phone;
using Il2CppScheduleOne.Vehicles;
using Il2CppScheduleOne.Weather;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using S1API.Entities;
using S1API.GameTime;
using S1API.Money;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(EotwCore), "End Of The World", "1.0.2", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonAdditionalDependencies(new string[] { "HoldTheFort" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WoodStudios.EndOfTheWorld")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WoodStudios.EndOfTheWorld")]
[assembly: AssemblyTitle("WoodStudios.EndOfTheWorld")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EndOfTheWorld
{
	internal enum Stage
	{
		None,
		Warning,
		Storm,
		Riots,
		Infection,
		Final,
		After
	}
	internal static class Arc
	{
		private static int _lastMinute = -1;

		private static int _nightDay;

		private static Stage _lastStage = Stage.None;

		private static int _lastBannerDay;

		private static float _nextTick;

		private static readonly List<int> Waves = new List<int>();

		private static int _wave;

		private static int _waveCount;

		public static int Day => Mathf.Max(1, State.S.ArcDay);

		public static int Minute => FortifyApi.GameMinute;

		public static bool IsNight
		{
			get
			{
				int minute = Minute;
				if (minute < 1200)
				{
					return minute < 240;
				}
				return true;
			}
		}

		public static bool IsCurfew
		{
			get
			{
				int minute = Minute;
				if (minute < 1260)
				{
					return minute < 300;
				}
				return true;
			}
		}

		public static Stage Now => StageOf(Day);

		public static Stage NightStage
		{
			get
			{
				if (_nightDay <= 0)
				{
					return Now;
				}
				return StageOf(_nightDay);
			}
		}

		public static string StageName => Name(Now);

		public static float StageProgress
		{
			get
			{
				int daysPerStage = EotwCore.DaysPerStage;
				int day = Day;
				float num = Mathf.Clamp01((float)Minute / 1440f);
				return Now switch
				{
					Stage.Warning => Mathf.Clamp01(((float)(day - 1) + num) / (float)daysPerStage), 
					Stage.Storm => Mathf.Clamp01(((float)(day - daysPerStage - 1) + num) / (float)daysPerStage), 
					Stage.Riots => Mathf.Clamp01(((float)(day - 2 * daysPerStage - 1) + num) / (float)daysPerStage), 
					Stage.Infection => Mathf.Clamp01(((float)(day - 3 * daysPerStage - 1) + num) / (float)EotwCore.InfectionNights), 
					_ => 1f, 
				};
			}
		}

		public static bool WaveNight
		{
			get
			{
				if (_nightDay > 0)
				{
					if (StageOf(_nightDay) != Stage.Infection)
					{
						return StageOf(_nightDay) == Stage.Final;
					}
					return true;
				}
				return false;
			}
		}

		public static bool FinalNight
		{
			get
			{
				if (_nightDay > 0)
				{
					return StageOf(_nightDay) == Stage.Final;
				}
				return false;
			}
		}

		public static int NightNumber => _nightDay;

		public static int Wave => _wave;

		public static int WaveCount => _waveCount;

		public static bool AllWavesSent
		{
			get
			{
				if (_waveCount > 0)
				{
					return _wave >= _waveCount;
				}
				return false;
			}
		}

		public static Stage StageOf(int day)
		{
			if (!State.S.Active)
			{
				return Stage.None;
			}
			if (!string.IsNullOrEmpty(State.S.Ending))
			{
				return Stage.After;
			}
			int daysPerStage = EotwCore.DaysPerStage;
			if (day <= daysPerStage)
			{
				return Stage.Warning;
			}
			if (day <= 2 * daysPerStage)
			{
				return Stage.Storm;
			}
			if (day <= 3 * daysPerStage)
			{
				return Stage.Riots;
			}
			if (day <= 3 * daysPerStage + EotwCore.InfectionNights)
			{
				return Stage.Infection;
			}
			return Stage.Final;
		}

		public static string Name(Stage s)
		{
			return s switch
			{
				Stage.Warning => "Warning signs", 
				Stage.Storm => "Storms and blackouts", 
				Stage.Riots => "Riots", 
				Stage.Infection => "The infection", 
				Stage.Final => "The final night", 
				Stage.After => "After the end", 
				_ => "Normal", 
			};
		}

		public static int ZombieNight(int day)
		{
			return Mathf.Max(0, day - 3 * EotwCore.DaysPerStage);
		}

		public static void Reset()
		{
			_lastMinute = -1;
			_nightDay = 0;
			_lastStage = Stage.None;
			_lastBannerDay = 0;
			_nextTick = 0f;
			Waves.Clear();
			_wave = 0;
			_waveCount = 0;
		}

		public static void Tick()
		{
			if (Time.unscaledTime < _nextTick)
			{
				return;
			}
			_nextTick = Time.unscaledTime + 0.5f;
			SaveData s = State.S;
			int day = FortifyApi.Day;
			if (s.LastElapsed <= 0 && day > 0 && s.StartElapsed > 0)
			{
				s.LastElapsed = day;
			}
			if (day > s.LastElapsed)
			{
				s.ArcDay += day - s.LastElapsed;
				s.LastElapsed = day;
			}
			int minute = Minute;
			if (_lastMinute < 0)
			{
				_lastMinute = minute;
			}
			bool isNight = IsNight;
			if (isNight && _nightDay == 0)
			{
				BeginNight((minute < 720) ? (Day - 1) : Day);
			}
			if (!isNight && _nightDay > 0 && minute >= 300 && minute < 720)
			{
				EndNight();
			}
			else if (!isNight && _nightDay > 0 && minute >= 720)
			{
				_nightDay = 0;
				Waves.Clear();
			}
			Stage now = Now;
			if (Day != _lastBannerDay && !isNight)
			{
				_lastBannerDay = Day;
				NewDay(now);
			}
			if (now != _lastStage)
			{
				Stage lastStage = _lastStage;
				_lastStage = now;
				if (lastStage != Stage.None)
				{
					World.OnStageChanged(lastStage, now);
				}
			}
			if (_nightDay > 0)
			{
				UpdateWaves(minute);
			}
			_lastMinute = minute;
		}

		private static void NewDay(Stage st)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			string sub = st switch
			{
				Stage.Warning => "Something is wrong. Listen to the radio.", 
				Stage.Storm => "The storms are here. The power won't last.", 
				Stage.Riots => "Everyone is armed. The police are losing control.", 
				Stage.Infection => (ZombieNight(Day) == 1) ? "The dead are walking. Scavenge by day. Survive the night." : "Scavenge by day. Survive the night.", 
				Stage.Final => "This is the last night. Hold on until dawn.", 
				_ => "", 
			};
			if (st != Stage.After)
			{
				Hud.Banner($"DAY {Day}", sub, new Color(1f, 0.55f, 0.15f));
				Radio.OnNewDay(st, Day);
			}
		}

		private static int SinceEight(int m)
		{
			return (m - 1200 + 1440) % 1440;
		}

		private static void BeginNight(int day)
		{
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			_nightDay = Mathf.Max(1, day);
			Waves.Clear();
			_wave = 0;
			Stage stage = StageOf(_nightDay);
			if (stage == Stage.Infection || stage == Stage.Final)
			{
				int num = ZombieNight(_nightDay);
				bool flag = stage == Stage.Final;
				_waveCount = (flag ? 6 : Mathf.Clamp(2 + num, 3, 5));
				int num2 = 60;
				int num3 = 435;
				for (int i = 0; i < _waveCount; i++)
				{
					Waves.Add(num2 + (num3 - num2) * i / Mathf.Max(1, _waveCount - 1));
				}
				string title = (flag ? $"NIGHT {_nightDay}: THE HORDE IS COMING" : $"NIGHT {_nightDay}");
				string sub = (flag ? "Survive until dawn. Hold your fort." : $"{_waveCount} waves tonight. Get to your fort.");
				Hud.Banner(title, sub, new Color(0.9f, 0.12f, 0.1f));
				Radio.Say(flag ? "This is the last broadcast. Whoever is still out there: barricade, and do not open your doors until sunrise." : "Night is falling. Stay inside. Do not open your doors for anyone.");
				Sfx.Ui("sting", 0.8f);
			}
			else
			{
				_waveCount = 0;
				if (stage == Stage.Riots)
				{
					Hud.Banner($"NIGHT {_nightDay}: CURFEW", "Police will shoot anyone on the streets.", new Color(0.3f, 0.5f, 1f));
				}
			}
			World.OnNightfall(_nightDay, stage);
		}

		private static void EndNight()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			int nightDay = _nightDay;
			Stage stage = StageOf(nightDay);
			_nightDay = 0;
			Waves.Clear();
			if (stage == Stage.Infection || stage == Stage.Final)
			{
				State.S.NightsSurvived = Mathf.Max(State.S.NightsSurvived, ZombieNight(nightDay));
				if (stage == Stage.Final)
				{
					World.OnFinalNightSurvived();
					return;
				}
				Hud.Banner("YOU SURVIVED THE NIGHT", $"{ZombieNight(nightDay)} of {EotwCore.InfectionNights + 1} nights", new Color(1f, 0.85f, 0.4f));
			}
			World.OnDawn(nightDay, stage);
		}

		private static void UpdateWaves(int m)
		{
			if (WaveNight && _wave < Waves.Count)
			{
				int num = SinceEight(m);
				if (num >= Waves[_wave] && num <= 480)
				{
					_wave++;
					Zombies.SendWave(_wave, _waveCount, ZombieNight(_nightDay), FinalNight);
				}
			}
		}

		public static void DevWaveNow()
		{
			if (_nightDay == 0)
			{
				BeginNight(Day);
			}
			if (!WaveNight)
			{
				EotwCore.Msg("Dev: tonight isn't a zombie night (stage " + Name(NightStage) + ").");
				Zombies.SendWave(1, 1, Mathf.Max(1, ZombieNight(Day)), final: false);
			}
			else if (_wave < Waves.Count)
			{
				Waves[_wave] = SinceEight(Minute);
			}
			else
			{
				_wave = Mathf.Max(0, Waves.Count - 1);
				Zombies.SendWave(_wave + 1, _waveCount, ZombieNight(_nightDay), FinalNight);
			}
		}

		public static void DevRestartNight()
		{
			_nightDay = 0;
			Waves.Clear();
			_wave = 0;
		}

		public static string NextEventText()
		{
			Stage now = Now;
			int minute = Minute;
			if (_nightDay > 0 && WaveNight)
			{
				if (_wave < Waves.Count)
				{
					int minute2 = (1200 + Waves[_wave]) % 1440;
					return $"Wave {_wave + 1} of {_waveCount} at {Clock(minute2)}";
				}
				return "Hold on until dawn";
			}
			switch (now)
			{
			case Stage.Infection:
			case Stage.Final:
				if (minute >= 1200)
				{
					return "Night";
				}
				return $"Nightfall at 8:00 PM ({(1200 - minute) / 60}h {(1200 - minute) % 60}m)";
			case Stage.Riots:
				return "Curfew at 9:00 PM";
			default:
				return "Day " + EotwCore.TotalDays + " is the last";
			}
		}

		public static string Clock(int minute)
		{
			minute = (minute % 1440 + 1440) % 1440;
			int num = minute / 60;
			int value = minute % 60;
			string value2 = ((num >= 12) ? "PM" : "AM");
			int num2 = num % 12;
			if (num2 == 0)
			{
				num2 = 12;
			}
			return $"{num2}:{value:00} {value2}";
		}
	}
	internal static class Cops
	{
		private static readonly ECheckpointLocation[] Points;

		private static readonly HashSet<ECheckpointLocation> Raised;

		private static readonly List<(Vector3 at, GameObject go)> Posts;

		private static float _nextThink;

		private static float _nextCurfew;

		private static float _curfewWarned;

		private static float _nextLaw;

		private static int _warnedNight;

		private const string Gun = "Avatar/Equippables/M1911";

		private const string Taser = "Avatar/Equippables/Taser";

		private const string Baton = "Avatar/Equippables/Baton";

		private static bool _up;

		public static bool MartialLaw => _up;

		public static bool Bribed => State.S.BribedDay == Arc.Day;

		public static void Reset()
		{
			_up = false;
			Raised.Clear();
			Posts.Clear();
			_nextThink = 0f;
			_nextCurfew = 0f;
			_nextLaw = 0f;
			_warnedNight = -1;
		}

		public static void Update()
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0146: 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)
			float unscaledTime = Time.unscaledTime;
			Stage now = Arc.Now;
			bool flag = now >= Stage.Riots && now != Stage.After;
			if (unscaledTime >= _nextLaw)
			{
				_nextLaw = unscaledTime + 20f;
				if (flag && !_up)
				{
					RaiseCheckpoints();
				}
				else if (!flag && _up)
				{
					LowerCheckpoints();
				}
			}
			if (now < Stage.Storm || unscaledTime < _nextThink)
			{
				return;
			}
			_nextThink = unscaledTime + 1f;
			foreach (PoliceOfficer cop in Nearby.Cops)
			{
				try
				{
					if ((Object)(object)cop == (Object)null || !Nearby.Alive((NPC)(object)cop) || ((Object)(object)cop.PursuitBehaviour != (Object)null && ((Behaviour)cop.PursuitBehaviour).Active))
					{
						continue;
					}
					CombatBehaviour val = (((Object)(object)((NPC)cop).Behaviour != (Object)null) ? ((NPC)cop).Behaviour.CombatBehaviour : null);
					if ((Object)(object)val == (Object)null || ((Behaviour)val).Active)
					{
						continue;
					}
					Actor actor = null;
					float num = 1024f;
					Vector3 position = ((Component)cop).transform.position;
					foreach (Actor item in People.List)
					{
						if (item.Hostile && !item.Dormant && item.Up)
						{
							Vector3 val2 = item.Pos - position;
							float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
							if (sqrMagnitude < num)
							{
								num = sqrMagnitude;
								actor = item;
							}
						}
					}
					if (actor == null || !Nearby.Sees(position, actor.Pos + Vector3.up * 1.2f, ((Component)actor.Npc).transform.root))
					{
						continue;
					}
					string weapon = ((actor.Side != Side.Rioter || actor.Weapon == null || actor.Weapon.Contains("M1911") || actor.Weapon.Contains("Revolver")) ? "Avatar/Equippables/M1911" : ((Random.value < 0.5f) ? "Avatar/Equippables/Taser" : "Avatar/Equippables/Baton"));
					if (EotwCore.CopLethality == "NonLethal" && actor.Side != Side.Zombie)
					{
						weapon = "Avatar/Equippables/Taser";
					}
					val.GiveUpRange = 40f;
					val.GiveUpAfterSuccessfulHits = 1000;
					val.SetWeapon(weapon);
					val.SetTargetAndEnable_Server(((NetworkBehaviour)actor.Npc).NetworkObject);
					if (Random.value < 0.3f)
					{
						try
						{
							((NPC)cop).ShowWorldSpaceDialogue(Lines.Pick(Lines.Cop), 3f);
						}
						catch
						{
						}
					}
				}
				catch (Exception ex)
				{
					EotwCore.ErrorOnce("cops", ex);
				}
			}
			Curfew(unscaledTime, now);
		}

		private static void Curfew(float now, Stage st)
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			if (st < Stage.Riots || !Arc.IsCurfew || EotwCore.CopLethality == "Off" || Bribed || now < _nextCurfew)
			{
				return;
			}
			_nextCurfew = now + 2f;
			Player local = Player.Local;
			if ((Object)(object)local == (Object)null || !Nearby.Alive(local) || (local.IsInVehicle && Random.value < 0.5f))
			{
				return;
			}
			Vector3 position = ((Component)local).transform.position;
			if (Places.OnOwned(position, 3f))
			{
				return;
			}
			try
			{
				EnvironmentManager instance = NetworkSingleton<EnvironmentManager>.Instance;
				if ((Object)(object)instance != (Object)null && instance.IsPositionUnderCover(position))
				{
					return;
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)local.CrimeData != (Object)null && (int)local.CrimeData.CurrentPursuitLevel != 0)
				{
					return;
				}
			}
			catch
			{
			}
			foreach (PoliceOfficer cop in Nearby.Cops)
			{
				try
				{
					if ((Object)(object)cop == (Object)null || !Nearby.Alive((NPC)(object)cop))
					{
						continue;
					}
					Vector3 position2 = ((Component)cop).transform.position;
					Vector3 val = position2 - position;
					if (((Vector3)(ref val)).sqrMagnitude > 1444f || !Nearby.Sees(position2, position + Vector3.up * 1.4f, ((Component)local).transform.root))
					{
						continue;
					}
					bool flag = EotwCore.CopLethality == "Lethal";
					local.CrimeData.SetPursuitLevel((EPursuitLevel)(flag ? 4 : 3));
					local.CrimeData.RecordLastKnownPosition(true);
					cop.BeginFootPursuit_Networked(local.PlayerCode, true);
					try
					{
						((NPC)cop).ShowWorldSpaceDialogue(flag ? "Curfew! Open fire!" : "Curfew! On the ground!", 3f);
					}
					catch
					{
					}
					if (_warnedNight != Arc.Day)
					{
						_warnedNight = Arc.Day;
						Hud.Banner("CURFEW", flag ? "Police are shooting on sight. Get indoors." : "Police are arresting anyone outside.", new Color(0.3f, 0.5f, 1f), small: true);
					}
					_nextCurfew = now + 25f;
					EotwCore.Msg("Curfew: an officer spotted you on the street.");
					break;
				}
				catch (Exception ex)
				{
					EotwCore.ErrorOnce("curfew", ex);
				}
			}
		}

		private unsafe static void RaiseCheckpoints()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_009b: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Invalid comparison between Unknown and I4
			CheckpointManager val = null;
			try
			{
				val = NetworkSingleton<CheckpointManager>.Instance;
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			_up = true;
			ECheckpointLocation[] points = Points;
			for (int i = 0; i < points.Length; i++)
			{
				ECheckpointLocation val2 = points[i];
				try
				{
					RoadCheckpoint checkpoint = val.GetCheckpoint(val2);
					if (!((Object)(object)checkpoint == (Object)null))
					{
						bool flag = false;
						try
						{
							flag = (int)checkpoint.ActivationState == 1;
						}
						catch
						{
						}
						if (!flag)
						{
							val.SetCheckpointEnabled(val2, true, 2);
							Raised.Add(val2);
						}
						Vector3 position = ((Component)checkpoint).transform.position;
						GameObject val3 = Props.CheckpointPost(position, ((Component)checkpoint).transform.rotation);
						Posts.Add((position, val3));
						Usables.Add(position + ((Component)checkpoint).transform.right * 3.5f, 4f, () => (Arc.IsNight || Bribed) ? null : "Talk to the officer at the checkpoint", delegate
						{
							EndScreen.OpenBribe();
						}, val3);
					}
				}
				catch (Exception ex)
				{
					EotwCore.ErrorOnce("checkpoint " + ((object)(*(ECheckpointLocation*)(&val2))/*cast due to .constrained prefix*/).ToString(), ex);
				}
			}
			if (Posts.Count > 0)
			{
				EotwCore.Msg($"Martial law: {Posts.Count} police checkpoints up ({Raised.Count} raised by us).");
				Radio.Say("The governor has declared martial law. Checkpoints are going up on every road out of town.");
			}
		}

		public static void LowerCheckpoints()
		{
			//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)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			CheckpointManager val = null;
			try
			{
				val = NetworkSingleton<CheckpointManager>.Instance;
			}
			catch
			{
			}
			foreach (ECheckpointLocation item2 in Raised)
			{
				try
				{
					if (val != null)
					{
						val.SetCheckpointEnabled(item2, false, 0);
					}
				}
				catch
				{
				}
			}
			Raised.Clear();
			_up = false;
			foreach (var post in Posts)
			{
				GameObject item = post.go;
				try
				{
					Usables.RemoveOwner(item);
					if ((Object)(object)item != (Object)null)
					{
						Object.Destroy((Object)(object)item);
					}
				}
				catch
				{
				}
			}
			Posts.Clear();
		}

		public static Vector3? NearestPost(Vector3 p)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Vector3? result = null;
			float num = float.MaxValue;
			foreach (var post in Posts)
			{
				Vector3 item = post.at;
				Vector3 val = item - p;
				float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					result = item;
				}
			}
			return result;
		}

		public static void Bribe()
		{
			State.S.BribedDay = Arc.Day;
			FortifyApi.Notify("Checkpoint", "Paid off. The night patrols won't shoot you tonight.");
			EotwCore.Msg("Checkpoint: bribe paid for tonight.");
		}

		static Cops()
		{
			ECheckpointLocation[] array = new ECheckpointLocation[4];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			Points = (ECheckpointLocation[])(object)array;
			Raised = new HashSet<ECheckpointLocation>();
			Posts = new List<(Vector3, GameObject)>();
			_warnedNight = -1;
		}
	}
	internal static class Ending
	{
		private sealed class Gen
		{
			public int Index;

			public Vector3 At;

			public GameObject Go;

			public float SpinUntil;

			public bool Done;

			public string Where;
		}

		private static GameObject _convoy;

		private static Vector3 _evacAt;

		private static bool _copperMesa;

		private static bool _leaving;

		private static readonly List<Gen> Gens = new List<Gen>();

		private static float _leaveAt;

		private static readonly Vector3 EastRoadEnd = new Vector3(150f, 4f, -104f);

		public static void Reset()
		{
			_convoy = null;
			Gens.Clear();
			_leaving = false;
		}

		public static void Clear()
		{
			try
			{
				if ((Object)(object)_convoy != (Object)null)
				{
					Usables.RemoveOwner(_convoy);
					Object.Destroy((Object)(object)_convoy);
				}
			}
			catch
			{
			}
			foreach (Gen gen in Gens)
			{
				try
				{
					if ((Object)(object)gen.Go != (Object)null)
					{
						Usables.RemoveOwner(gen.Go);
						Object.Destroy((Object)(object)gen.Go);
					}
				}
				catch
				{
				}
			}
			Reset();
		}

		private static bool CopperMesaInstalled()
		{
			try
			{
				foreach (MelonBase registeredMelon in MelonBase.RegisteredMelons)
				{
					if (((registeredMelon != null) ? registeredMelon.Info : null) != null && registeredMelon.Info.Name.IndexOf("Copper Mesa", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						return true;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		public static string EvacDescription()
		{
			if (!CopperMesaInstalled())
			{
				return "A convoy of armored vans is waiting at the east end of the Suburbia road (flares burning). Get there alive and climb aboard. The world recovers behind you.";
			}
			return "The last bus out is running. Get to the Copper Mesa bus stop at the east end of the Suburbia road and ride it out of town. Make it there alive and the world recovers behind you.";
		}

		public static void Start(string which)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			Clear();
			if (which == "evacuate")
			{
				BuildConvoy();
				Hud.Banner("EVACUATE", _copperMesa ? "Get to the Copper Mesa bus stop and ride out." : "Get to the convoy at the east end of Suburbia.", new Color(1f, 0.82f, 0.35f));
				Radio.Alert("EVACUATION", _copperMesa ? "The last bus out leaves from the east end of the Suburbia road. Go now." : "The convoy is waiting at the east end of the Suburbia road. It won't wait forever.");
			}
			else
			{
				BuildGenerators();
				Hud.Banner("RESTORE THE TOWN", "Restart the three emergency generators.", new Color(1f, 0.82f, 0.35f));
				Radio.Alert("EMERGENCY ALERT", "If anyone can reach the emergency generators, start them. Every one gives a part of town its power back.");
			}
		}

		public static void Rebuild()
		{
			Clear();
			if (State.S.Ending == "evacuate")
			{
				BuildConvoy();
			}
			else if (State.S.Ending == "restore")
			{
				BuildGenerators();
			}
		}

		private static void BuildConvoy()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			_copperMesa = CopperMesaInstalled();
			_evacAt = EastRoadEnd;
			People.Ground(EastRoadEnd, 15f, out _evacAt);
			if (!_copperMesa)
			{
				_convoy = Props.Convoy(_evacAt, Quaternion.Euler(0f, 90f, 0f));
				Usables.Add(_evacAt, 6f, () => (!_leaving) ? "Climb aboard the convoy" : null, Leave, _convoy);
			}
		}

		private static void BuildGenerators()
		{
			//IL_00df: 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_00f0: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			Random random = new Random(State.S.StartElapsed * 31 + 7);
			List<Places.Building> list = new List<Places.Building>(Places.Buildings);
			List<Places.Building> list2 = new List<Places.Building>();
			for (int i = 0; i < 200; i++)
			{
				if (list2.Count >= 3)
				{
					break;
				}
				if (list.Count <= 0)
				{
					break;
				}
				Places.Building building = list[random.Next(list.Count)];
				bool flag = true;
				foreach (Places.Building item in list2)
				{
					if (Vector3.Distance(item.Door, building.Door) < 110f)
					{
						flag = false;
						break;
					}
				}
				if (flag && !Places.OnOwned(building.Door, 15f))
				{
					list2.Add(building);
				}
			}
			for (int j = 0; j < list2.Count; j++)
			{
				Places.Building building2 = list2[j];
				Vector3 at = building2.Door + building2.Out * 3.2f + Vector3.Cross(Vector3.up, building2.Out) * 2.2f;
				Gen gen = new Gen
				{
					Index = j,
					At = at,
					Where = Gangs.Pretty(building2.Name),
					Done = State.S.Generators.Contains(j)
				};
				gen.Go = Props.Generator(at, Quaternion.LookRotation(building2.Out));
				if (!gen.Done)
				{
					Gen gen2 = gen;
					Usables.Add(at, 2.6f, () => (!gen2.Done) ? ((!(gen2.SpinUntil > 0f)) ? "Start the emergency generator" : null) : null, delegate
					{
						StartGen(gen2);
					}, gen.Go);
				}
				Gens.Add(gen);
			}
			EotwCore.Msg($"Restore: {Gens.Count} generators placed ({State.S.Generators.Count} already running).");
		}

		private static void StartGen(Gen g)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (g.Done || g.SpinUntil > 0f)
			{
				return;
			}
			g.SpinUntil = Time.unscaledTime + 25f;
			Hud.Banner("HOLD ON", "The generator is starting. They heard it.", new Color(1f, 0.6f, 0.2f), small: true);
			Sfx.At(g.At, "bash", 1f, 40f, loop: false, 0.6f);
			for (int i = 0; i < 5; i++)
			{
				if (Places.SpawnAround(g.At, 25f, 40f, out var at))
				{
					Zombies.Spawn((i == 0) ? Kind.Runner : Kind.Normal, at);
				}
			}
		}

		private static void Leave()
		{
			if (!_leaving)
			{
				_leaving = true;
				_leaveAt = Time.unscaledTime + 2.2f;
				Hud.Fade(7f, "YOU GOT OUT");
			}
		}

		public static void Update()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			SaveData s = State.S;
			if (s.Ending == "evacuate")
			{
				if (_leaving && Time.unscaledTime >= _leaveAt)
				{
					_leaving = false;
					World.Recover("You got out on the evacuation convoy. Weeks later, the town was rebuilt.");
				}
				else if (_copperMesa && Gfx.PlayerPos().x > 1500f)
				{
					World.Recover("You rode the last bus out to Copper Mesa. Back home, the town was rebuilt.");
				}
			}
			else
			{
				if (!(s.Ending == "restore"))
				{
					return;
				}
				float unscaledTime = Time.unscaledTime;
				foreach (Gen gen in Gens)
				{
					if (gen.Done || gen.SpinUntil <= 0f)
					{
						continue;
					}
					if (unscaledTime >= gen.SpinUntil)
					{
						gen.Done = true;
						gen.SpinUntil = 0f;
						if (!s.Generators.Contains(gen.Index))
						{
							s.Generators.Add(gen.Index);
						}
						string text = Power.RestoreOne() ?? "part of town";
						Hud.Banner("POWER RESTORED", $"{text} has its lights back ({s.Generators.Count} of {Gens.Count}).", new Color(0.6f, 0.9f, 1f), small: true);
						Radio.Say("The lights are back on in " + text + "! Whoever did that: thank you.");
					}
					else if (Random.value < 0.05f)
					{
						Sfx.At(gen.At, "bash", 0.5f, 25f, loop: false, 1.6f);
					}
				}
				if (Gens.Count > 0 && s.Generators.Count >= Gens.Count)
				{
					World.Recover("You brought the power back and cleared the streets. Hyland Point lives.");
				}
			}
		}

		public static string Text()
		{
			//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_0036: 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)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			SaveData s = State.S;
			Vector3 val = Gfx.PlayerPos();
			if (s.Ending == "evacuate")
			{
				return (_copperMesa ? "BUS STOP" : "CONVOY") + "   " + Where(val, _evacAt);
			}
			if (s.Ending == "restore")
			{
				Gen gen = null;
				float num = float.MaxValue;
				foreach (Gen gen2 in Gens)
				{
					if (!gen2.Done)
					{
						float num2 = Vector3.Distance(val, gen2.At);
						if (num2 < num)
						{
							num = num2;
							gen = gen2;
						}
					}
				}
				foreach (Gen gen3 in Gens)
				{
					if (gen3.SpinUntil > 0f)
					{
						return $"GENERATOR STARTING   {Mathf.CeilToInt(gen3.SpinUntil - Time.unscaledTime)} s   HOLD ON";
					}
				}
				if (gen != null)
				{
					return $"GENERATORS {s.Generators.Count} OF {Gens.Count}   NEXT: {Where(val, gen.At)}";
				}
				return "ALL GENERATORS RUNNING";
			}
			return "OPEN THE FORT APP TO CHOOSE";
		}

		private static string Where(Vector3 from, Vector3 to)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			val.y = 0f;
			float magnitude = ((Vector3)(ref val)).magnitude;
			string value = "";
			if (magnitude > 5f)
			{
				float num = Mathf.Atan2(val.x, val.z) * 57.29578f;
				value = (new string[8] { "N", "NE", "E", "SE", "S", "SW", "W", "NW" })[Mathf.RoundToInt((num + 360f) % 360f / 45f) % 8];
			}
			return $"{magnitude:0} m {value}";
		}
	}
	internal static class EndScreen
	{
		private enum Mode
		{
			None,
			Begin,
			Status,
			Trade,
			Bribe,
			Ending,
			ConfirmQuit
		}

		private static Mode _mode = Mode.None;

		private static Fort _fort;

		private static string _note;

		private static float _openedAt;

		private static bool _pendingOpen;

		private static Mode _pendingMode;

		private static readonly Color Text = new Color(0.95f, 0.9f, 0.84f);

		private static readonly Color Dim = new Color(0.75f, 0.68f, 0.6f);

		private static readonly Color Hot = new Color(1f, 0.55f, 0.2f);

		private static readonly Color Bad = new Color(1f, 0.35f, 0.3f);

		private static readonly (string label, string id, int qty, int price)[] Goods = new(string, string, int, int)[6]
		{
			("9mm magazine", "m1911mag", 1, 160),
			("Revolver cylinder", "revolvercylinder", 1, 160),
			("Shotgun shells x4", "shotgunshell", 4, 140),
			("Painkillers x2", "paracetamol", 2, 60),
			("Energy drinks x2", "energydrink", 2, 40),
			("Cukes x2", "cuke", 2, 30)
		};

		public static bool Open => _mode != Mode.None;

		private static float S => Mathf.Clamp((float)Screen.height / 1080f, 0.7f, 2f);

		public static void Reset()
		{
			if (Open)
			{
				Close();
			}
			_pendingOpen = false;
		}

		private static void Show(Mode m)
		{
			try
			{
				Phone instance = PlayerSingleton<Phone>.Instance;
				if ((Object)(object)instance != (Object)null && instance.IsOpen)
				{
					instance.SetIsOpen(false);
				}
			}
			catch
			{
			}
			_pendingOpen = true;
			_pendingMode = m;
			_note = null;
		}

		public static void Tick()
		{
			if (_pendingOpen)
			{
				_pendingOpen = false;
				_mode = _pendingMode;
				_openedAt = Time.unscaledTime;
				FortifyApi.OpenMenu("eotw");
			}
		}

		public static void Close()
		{
			if (_mode != Mode.None)
			{
				_mode = Mode.None;
				_fort = null;
				FortifyApi.CloseMenu("eotw");
			}
		}

		public static void OpenMain()
		{
			SaveData s = State.S;
			if (!s.Active)
			{
				Show(Mode.Begin);
			}
			else if (s.Ending == "choose")
			{
				Show(Mode.Ending);
			}
			else
			{
				Show(Mode.Status);
			}
		}

		public static void OpenTrade(Fort f)
		{
			_fort = f;
			Show(Mode.Trade);
		}

		public static void OpenBribe()
		{
			Show(Mode.Bribe);
		}

		public static void OpenEnding()
		{
			Show(Mode.Ending);
		}

		public static void Draw()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			if (_mode == Mode.None)
			{
				return;
			}
			if (FortifyApi.KeyDown((KeyCode)27) && Time.unscaledTime - _openedAt > 0.3f)
			{
				Close();
				return;
			}
			float s = S;
			float num = Screen.width;
			float num2 = Screen.height;
			FortifyApi.UiFill(new Rect(0f, 0f, num, num2), new Color(0.03f, 0.01f, 0f, 0.82f));
			float num3 = Mathf.Min(900f * s, num - 40f);
			float num4 = Mathf.Min(760f * s, num2 - 40f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor((num - num3) * 0.5f, (num2 - num4) * 0.5f, num3, num4);
			FortifyApi.UiFill(val, new Color(0.09f, 0.06f, 0.05f, 0.97f));
			FortifyApi.UiFrame(val, new Color(0.9f, 0.4f, 0.1f), 3f);
			FortifyApi.UiFill(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, 70f * s), new Color(0.35f, 0.08f, 0.03f));
			FortifyApi.UiText(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, 70f * s), "END OF THE WORLD", Mathf.RoundToInt(40f * s), new Color(1f, 0.7f, 0.3f), (TextAnchor)4, true);
			Rect b = default(Rect);
			((Rect)(ref b))..ctor(((Rect)(ref val)).x + 30f * s, ((Rect)(ref val)).y + 90f * s, ((Rect)(ref val)).width - 60f * s, ((Rect)(ref val)).height - 110f * s);
			try
			{
				switch (_mode)
				{
				case Mode.Begin:
					DrawBegin(b, s);
					break;
				case Mode.Status:
					DrawStatus(b, s);
					break;
				case Mode.Trade:
					DrawTrade(b, s);
					break;
				case Mode.Bribe:
					DrawBribe(b, s);
					break;
				case Mode.Ending:
					DrawEnding(b, s);
					break;
				case Mode.ConfirmQuit:
					DrawConfirmQuit(b, s);
					break;
				}
			}
			catch (Exception ex)
			{
				EotwCore.ErrorOnce("screen " + _mode, ex);
				Close();
			}
		}

		private static float Line(Rect body, ref float y, string text, int size, Color c, float height, bool bold = false, TextAnchor a = (TextAnchor)0)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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)
			float s = S;
			FortifyApi.UiText(new Rect(((Rect)(ref body)).x, y, ((Rect)(ref body)).width, height * s), text, Mathf.RoundToInt((float)size * s), c, a, bold);
			y += height * s;
			return y;
		}

		private static bool Button(Rect r, string label, bool enabled = true)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return FortifyApi.UiButton(r, label, enabled, false, Mathf.RoundToInt(18f * S));
		}

		private static void DrawBegin(Rect b, float s)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			float y = ((Rect)(ref b)).y;
			Line(b, ref y, "Begin the end of the world in THIS save?", 26, Hot, 44f, bold: true, (TextAnchor)0);
			Line(b, ref y, $"Over about {EotwCore.TotalDays} in-game days Hyland Point falls apart: warning signs, then storms and blackouts, then riots with everyone armed and the police shooting curfew breakers, then the infection: zombie waves every night, coming for your Fortify Your Base places. Survive the final horde night, then evacuate or restore the town.", 17, Text, 130f, bold: false, (TextAnchor)0);
			Line(b, ref y, "What to know:", 18, Hot, 30f, bold: true, (TextAnchor)0);
			Line(b, ref y, "- It only happens in this save, and only from now on. Your other saves are never touched.", 16, Text, 26f, bold: false, (TextAnchor)0);
			Line(b, ref y, "- Townspeople become zombies, killers, rioters and survivors for a while. When it ends everyone is given back as they were and the town recovers.", 16, Text, 48f, bold: false, (TextAnchor)0);
			Line(b, ref y, "- You can end it early from this screen at any time. Nothing is saved until the game saves.", 16, Text, 26f, bold: false, (TextAnchor)0);
			Line(b, ref y, $"- Settings: {EotwCore.DaysPerStage} day(s) per stage, {EotwCore.InfectionNights} zombie nights + the final night, cops: {EotwCore.CopLethality}{(EotwCore.NoKill ? ", no-kill mode" : "")}. Change them in MelonPreferences.cfg (End Of The World).", 15, Dim, 48f, bold: false, (TextAnchor)0);
			if (!string.IsNullOrEmpty(_note))
			{
				Line(b, ref y, _note, 16, Bad, 30f, bold: false, (TextAnchor)0);
			}
			float num = 300f * s;
			float num2 = 54f * s;
			float num3 = ((Rect)(ref b)).yMax - num2;
			if (Button(new Rect(((Rect)(ref b)).x, num3, num, num2), "BEGIN THE END"))
			{
				World.Begin();
				Close();
			}
			if (Button(new Rect(((Rect)(ref b)).xMax - num, num3, num, num2), "Not now"))
			{
				Close();
			}
		}

		private static void DrawStatus(Rect b, float s)
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: 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_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			Stage now = Arc.Now;
			float y = ((Rect)(ref b)).y;
			string text = ((now == Stage.After) ? "AFTER THE END" : ((!Arc.WaveNight) ? $"DAY {Arc.Day} OF {EotwCore.TotalDays}" : (Arc.FinalNight ? $"NIGHT {Arc.NightNumber}: THE HORDE" : $"NIGHT {Arc.NightNumber}")));
			Line(b, ref y, text, 34, Hot, 50f, bold: true, (TextAnchor)0);
			Line(b, ref y, Arc.Name(now) + "   |   " + Arc.NextEventText(), 18, Text, 32f, bold: false, (TextAnchor)0);
			Line(b, ref y, "Hyland Point: " + World.CensusText(), 16, Dim, 28f, bold: false, (TextAnchor)0);
			Line(b, ref y, $"Power: {Power.DarkCount} of {Power.DistrictCount} districts dark   |   Fires: {Fires.Count}   |   Martial law: {(Cops.MartialLaw ? "yes" : "no")}{(Cops.Bribed ? " (you paid off a checkpoint today)" : "")}", 16, Dim, 28f, bold: false, (TextAnchor)0);
			Line(b, ref y, $"Nights survived: {State.S.NightsSurvived}   |   Infected down: {State.S.ZombiesDown}   |   Forts helped: {State.S.Helped}   |   With you: {Allies.Count}", 16, Dim, 34f, bold: false, (TextAnchor)0);
			Line(b, ref y, "EMERGENCY RADIO", 18, Hot, 30f, bold: true, (TextAnchor)0);
			int num = 0;
			foreach (string item in Radio.Log)
			{
				if (num++ >= 8)
				{
					break;
				}
				Line(b, ref y, item, 15, Text, 25f, bold: false, (TextAnchor)0);
			}
			float num2 = 260f * s;
			float num3 = 50f * s;
			float num4 = ((Rect)(ref b)).yMax - num3;
			if (Button(new Rect(((Rect)(ref b)).x, num4, num2, num3), "Close"))
			{
				Close();
			}
			if (State.S.Ending == "choose" && Button(new Rect(((Rect)(ref b)).x + num2 + 20f * s, num4, num2, num3), "Choose the ending"))
			{
				_mode = Mode.Ending;
			}
			if (Button(new Rect(((Rect)(ref b)).xMax - num2, num4, num2, num3), "End it now"))
			{
				_mode = Mode.ConfirmQuit;
			}
			if (FortifyApi.DevKeys)
			{
				DrawDev(new Rect(((Rect)(ref b)).x, num4 - 60f * s, ((Rect)(ref b)).width, 46f * s), s);
			}
		}

		private static void DrawDev(Rect r, float s)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			float bw = (((Rect)(ref r)).width - 40f * s) / 5f;
			int i = 0;
			if (Button(B(), "Dev: next day"))
			{
				World.DevNextDay();
			}
			if (Button(B(), "Dev: 7:55 PM"))
			{
				World.DevTime(1955);
			}
			if (Button(B(), "Dev: wave now"))
			{
				Arc.DevWaveNow();
				Close();
			}
			if (Button(B(), "Dev: strike"))
			{
				Sky.Strike(Stage.Storm);
			}
			if (Button(B(), "Dev: final day"))
			{
				World.DevJumpTo(Stage.Final);
			}
			Rect B()
			{
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				Rect result = new Rect(((Rect)(ref r)).x + (float)i * (bw + 10f * s), ((Rect)(ref r)).y, bw, ((Rect)(ref r)).height);
				i++;
				return result;
			}
		}

		private static void DrawConfirmQuit(Rect b, float s)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			float y = ((Rect)(ref b)).y;
			Line(b, ref y, "End it now?", 28, Hot, 50f, bold: true, (TextAnchor)0);
			Line(b, ref y, "The storms clear, the power comes back, the fires go out and everyone the end took is given back as they were. You can begin it again later.", 18, Text, 90f, bold: false, (TextAnchor)0);
			float num = 300f * s;
			float num2 = 54f * s;
			float num3 = ((Rect)(ref b)).yMax - num2;
			if (Button(new Rect(((Rect)(ref b)).x, num3, num, num2), "Yes, end it"))
			{
				World.Recover("You called it off.");
				Close();
			}
			if (Button(new Rect(((Rect)(ref b)).xMax - num, num3, num, num2), "No, keep going"))
			{
				_mode = Mode.Status;
			}
		}

		private static void DrawTrade(Rect b, float s)
		{
			//IL_0033: 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_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b8: 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_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: 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_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_041f: Unknown result type (might be due to invalid IL or missing references)
			Fort fort = _fort;
			if (fort == null)
			{
				Close();
				return;
			}
			float y = ((Rect)(ref b)).y;
			float num = 0f;
			try
			{
				num = Money.GetCashBalance();
			}
			catch
			{
			}
			if (fort.Hostile)
			{
				Line(b, ref y, "The fort at " + fort.Name, 26, Hot, 44f, bold: true, (TextAnchor)0);
				bool flag = fort.Fallen || fort.UpCount == 0;
				Line(b, ref y, flag ? "They're down. What they had is yours." : "They're shooting at you. Take them down first.", 18, Text, 40f, bold: false, (TextAnchor)0);
				if (flag && !fort.Looted && Button(new Rect(((Rect)(ref b)).x, y + 10f * s, 360f * s, 52f * s), "Take their supplies"))
				{
					fort.Looted = true;
					List<string> list = new List<string>();
					for (int i = 0; i < 4; i++)
					{
						(string, string, int, int) tuple = Goods[Random.Range(0, Goods.Length)];
						if (Loot.Give(tuple.Item2, tuple.Item3, out var name))
						{
							list.Add(name);
						}
					}
					_note = ((list.Count > 0) ? ("You took: " + string.Join(", ", list)) : "Your pockets are full.");
				}
				if (!string.IsNullOrEmpty(_note))
				{
					y += 80f * s;
					Line(b, ref y, _note, 16, Dim, 30f, bold: false, (TextAnchor)0);
				}
				if (Button(new Rect(((Rect)(ref b)).xMax - 260f * s, ((Rect)(ref b)).yMax - 50f * s, 260f * s, 50f * s), "Leave"))
				{
					Close();
				}
				return;
			}
			float num2 = (fort.Helped ? 0.6f : 1f);
			Line(b, ref y, "Survivors at " + fort.Name, 26, Hot, 40f, bold: true, (TextAnchor)0);
			Line(b, ref y, fort.Helped ? "\"You helped us through the night. Best prices for you.\"" : "\"Cash only. Or product, if you've got it: we'll pay double.\"", 17, Text, 30f, bold: false, (TextAnchor)0);
			Line(b, ref y, $"Your cash: ${num:N0}", 16, Dim, 34f, bold: false, (TextAnchor)0);
			float num3 = (((Rect)(ref b)).width - 20f * s) / 2f;
			float num4 = 46f * s;
			for (int j = 0; j < Goods.Length; j++)
			{
				(string, string, int, int) tuple2 = Goods[j];
				int num5 = Mathf.RoundToInt((float)tuple2.Item4 * num2);
				if (!Button(new Rect(((Rect)(ref b)).x + (float)(j % 2) * (num3 + 20f * s), y + (float)(j / 2) * (num4 + 10f * s), num3, num4), $"{tuple2.Item1}   ${num5}", num >= (float)num5))
				{
					continue;
				}
				if (Loot.Give(tuple2.Item2, tuple2.Item3, out var name2))
				{
					try
					{
						Money.ChangeCashBalance((float)(-num5), true, true);
					}
					catch
					{
					}
					_note = "Bought " + name2 + ".";
				}
				else
				{
					_note = name2 ?? "No room in your pockets.";
				}
			}
			y += 3f * (num4 + 10f * s) + 10f * s;
			if (Button(new Rect(((Rect)(ref b)).x, y, num3, num4), "Sell them 1 of the product in your hand"))
			{
				_note = SellProduct();
			}
			int num6 = ((!fort.Helped) ? 400 : 0);
			bool enabled = Allies.Count < 2 && num >= (float)num6;
			if (Button(new Rect(((Rect)(ref b)).x + num3 + 20f * s, y, num3, num4), (Allies.Count >= 2) ? "Two are already with you" : ("Take one with you  " + ((num6 == 0) ? "(free)" : ("$" + num6))), enabled))
			{
				if (Survivors.Recruit(fort))
				{
					if (num6 > 0)
					{
						try
						{
							Money.ChangeCashBalance((float)(-num6), true, true);
						}
						catch
						{
						}
					}
					_note = "One of them grabs a gun and comes with you.";
				}
				else
				{
					_note = "Nobody can be spared right now.";
				}
			}
			y += num4 + 16f * s;
			if (!string.IsNullOrEmpty(_note))
			{
				Line(b, ref y, _note, 16, Hot, 30f, bold: false, (TextAnchor)0);
			}
			if (Button(new Rect(((Rect)(ref b)).xMax - 260f * s, ((Rect)(ref b)).yMax - 50f * s, 260f * s, 50f * s), "Leave"))
			{
				Close();
			}
		}

		private static string SellProduct()
		{
			try
			{
				PlayerInventory instance = PlayerSingleton<PlayerInventory>.Instance;
				HotbarSlot val = (((Object)(object)instance != (Object)null) ? instance.equippedSlot : null);
				ItemInstance val2 = ((val != null) ? ((ItemSlot)val).ItemInstance : null);
				ProductItemInstance val3 = ((val2 != null) ? ((Il2CppObjectBase)val2).TryCast<ProductItemInstance>() : null);
				if (val3 == null)
				{
					return "Hold some product in your hand first.";
				}
				float num = 60f;
				try
				{
					ProductDefinition val4 = ((Il2CppObjectBase)((ItemInstance)val3).Definition).TryCast<ProductDefinition>();
					if ((Object)(object)val4 != (Object)null)
					{
						num = Mathf.Max(Mathf.Max(val4.MarketValue, val4.Price), 20f);
					}
				}
				catch
				{
				}
				int num2 = 1;
				try
				{
					num2 = Mathf.Max(1, val3.Amount);
				}
				catch
				{
				}
				float num3 = Mathf.Round(num * (float)num2 * 2f);
				((ItemSlot)val).ChangeQuantity(-1, false);
				Money.ChangeCashBalance(num3, true, true);
				return $"They paid ${num3:N0}. \"Worth every cent right now.\"";
			}
			catch (Exception ex)
			{
				EotwCore.ErrorOnce("sell", ex);
				return "They don't want that.";
			}
		}

		private static void DrawBribe(Rect b, float s)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0093: 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_00af: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			float y = ((Rect)(ref b)).y;
			float num = 0f;
			try
			{
				num = Money.GetCashBalance();
			}
			catch
			{
			}
			int num2 = 300 + 150 * Mathf.Max(0, Arc.Day - 3);
			Line(b, ref y, "Martial law checkpoint", 26, Hot, 44f, bold: true, (TextAnchor)0);
			Line(b, ref y, Cops.Bribed ? "\"We've got an understanding. Stay out of our sights tonight anyway.\"" : $"\"Curfew's at nine and my boys shoot anything that moves. Unless they've been told not to. ${num2} and they won't see you tonight.\"", 18, Text, 80f, bold: false, (TextAnchor)0);
			Line(b, ref y, "\"And word is the infection started out east. If you hear the radio say evacuate: you head for the convoy, you don't stop.\"", 16, Dim, 60f, bold: false, (TextAnchor)0);
			if (!string.IsNullOrEmpty(_note))
			{
				Line(b, ref y, _note, 16, Hot, 30f, bold: false, (TextAnchor)0);
			}
			float num3 = 320f * s;
			float num4 = 52f * s;
			float num5 = ((Rect)(ref b)).yMax - num4;
			if (!Cops.Bribed && Button(new Rect(((Rect)(ref b)).x, num5, num3, num4), $"Pay ${num2}", num >= (float)num2))
			{
				try
				{
					Money.ChangeCashBalance((float)(-num2), true, true);
				}
				catch
				{
				}
				Cops.Bribe();
				_note = "He pockets it without looking at you.";
			}
			if (Button(new Rect(((Rect)(ref b)).xMax - 260f * s, num5, 260f * s, num4), "Leave"))
			{
				Close();
			}
		}

		private static void DrawEnding(Rect b, float s)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00b4: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			float y = ((Rect)(ref b)).y;
			Line(b, ref y, "YOU SURVIVED THE FINAL NIGHT", 30, Hot, 50f, bold: true, (TextAnchor)0);
			Line(b, ref y, "Hyland Point is finished, or it isn't. That's up to you now.", 18, Text, 40f, bold: false, (TextAnchor)0);
			float num = (((Rect)(ref b)).width - 30f * s) / 2f;
			float num2 = 230f * s;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref b)).x, y + 10f * s, num, num2);
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(((Rect)(ref b)).x + num + 30f * s, y + 10f * s, num, num2);
			FortifyApi.UiFill(val, new Color(0.15f, 0.08f, 0.05f));
			FortifyApi.UiFill(val2, new Color(0.15f, 0.08f, 0.05f));
			FortifyApi.UiText(new Rect(((Rect)(ref val)).x + 14f * s, ((Rect)(ref val)).y + 10f * s, ((Rect)(ref val)).width - 28f * s, 40f * s), "EVACUATE", Mathf.RoundToInt(24f * s), Hot, (TextAnchor)0, true);
			FortifyApi.UiText(new Rect(((Rect)(ref val)).x + 14f * s, ((Rect)(ref val)).y + 54f * s, ((Rect)(ref val)).width - 28f * s, num2 - 60f * s), World.EvacDescription(), Mathf.RoundToInt(16f * s), Text, (TextAnchor)0, false);
			FortifyApi.UiText(new Rect(((Rect)(ref val2)).x + 14f * s, ((Rect)(ref val2)).y + 10f * s, ((Rect)(ref val2)).width - 28f * s, 40f * s), "RESTORE THE TOWN", Mathf.RoundToInt(24f * s), Hot, (TextAnchor)0, true);
			FortifyApi.UiText(new Rect(((Rect)(ref val2)).x + 14f * s, ((Rect)(ref val2)).y + 54f * s, ((Rect)(ref val2)).width - 28f * s, num2 - 60f * s), "Restart the three emergency generators around town (marked on your screen). The infected will come for you while you work. When the power's back, the town is cleared and the world recovers.", Mathf.RoundToInt(16f * s), Text, (TextAnchor)0, false);
			float num3 = ((Rect)(ref val)).yMax + 16f * s;
			if (Button(new Rect(((Rect)(ref val)).x, num3, num, 54f * s), "Evacuate"))
			{
				World.ChooseEnding("evacuate");
				Close();
			}
			if (Button(new Rect(((Rect)(ref val2)).x, num3, num, 54f * s), "Restore the town"))
			{
				World.ChooseEnding("restore");
				Close();
			}
			if (Button(new Rect(((Rect)(ref b)).xMax - 260f * s, ((Rect)(ref b)).yMax - 50f * s, 260f * s, 50f * s), "Decide later"))
			{
				Close();
			}
		}
	}
	public sealed class EotwCore : MelonMod
	{
		internal static Instance Log;

		internal static EotwCore Instance;

		internal static bool Ok;

		private static MelonPreferences_Entry<int> _daysPerStage;

		private static MelonPreferences_Entry<int> _infectionNights;

		private static MelonPreferences_Entry<int> _maxZombies;

		private static MelonPreferences_Entry<int> _maxPeople;

		private static MelonPreferences_Entry<int> _maxFires;

		private static MelonPreferences_Entry<float> _storm;

		private static MelonPreferences_Entry<float> _zombieMult;

		private static MelonPreferences_Entry<float> _riotMult;

		private static MelonPreferences_Entry<float> _volume;

		private static MelonPreferences_Entry<string> _copLethality;

		private static MelonPreferences_Entry<bool> _noKill;

		private static MelonPreferences_Entry<bool> _texts;

		private static MelonPreferences_Entry<bool> _sirens;

		private static MelonPreferences_Entry<bool> _hud;

		private static MelonPreferences_Entry<bool> _skyTint;

		private const string DataKey = "woodstudios.endoftheworld";

		private static readonly Dictionary<string, float> _errAt = new Dictionary<string, float>();

		public static int DaysPerStage => Mathf.Clamp(_daysPerStage?.Value ?? 1, 1, 3);

		public static int InfectionNights => Mathf.Clamp(_infectionNights?.Value ?? 3, 1, 6);

		public static float StormStrength => Mathf.Clamp(_storm?.Value ?? 1f, 0f, 2f);

		public static float ZombieNumbers => Mathf.Clamp(_zombieMult?.Value ?? 1f, 0.25f, 3f);

		public static float RiotNumbers => Mathf.Clamp(_riotMult?.Value ?? 1f, 0.25f, 3f);

		public static int MaxZombies => Mathf.Clamp(_maxZombies?.Value ?? 14, 4, 30);

		public static int MaxPeople => Mathf.Clamp(_maxPeople?.Value ?? 10, 4, 24);

		public static int MaxFires => Mathf.Clamp(_maxFires?.Value ?? 6, 0, 16);

		public static string CopLethality
		{
			get
			{
				string text = (_copLethality?.Value ?? "Lethal").Trim();
				if (text.Equals("Off", StringComparison.OrdinalIgnoreCase))
				{
					return "Off";
				}
				if (text.StartsWith("Non", StringComparison.OrdinalIgnoreCase))
				{
					return "NonLethal";
				}
				return "Lethal";
			}
		}

		public static bool NoKill => _noKill?.Value ?? false;

		public static bool Texts => _texts?.Value ?? true;

		public static bool Sirens => _sirens?.Value ?? true;

		public static bool ShowHud => _hud?.Value ?? true;

		public static bool SkyTint => _skyTint?.Value ?? true;

		public static float Volume => Mathf.Clamp01(_volume?.Value ?? 0.8f);

		public static int TotalDays => 3 * DaysPerStage + InfectionNights + 1;

		public override void OnInitializeMelon()
		{
			Log = ((MelonBase)this).LoggerInstance;
			Instance = this;
			bool flag = false;
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				for (int i = 0; i < assemblies.Length; i++)
				{
					if (assemblies[i].GetName().Name == "HoldTheFort")
					{
						flag = true;
						break;
					}
				}
			}
			catch
			{
			}
			if (!flag)
			{
				Log.Error("End Of The World needs Fortify Your Base (HoldTheFort.dll) in your Mods folder. It is not there, so this mod does nothing.");
				return;
			}
			MelonPreferences_Category obj2 = MelonPreferences.CreateCategory("EndOfTheWorld", "End Of The World");
			_daysPerStage = obj2.CreateEntry<int>("DaysPerStage", 1, "Days per stage", "How fast the world falls apart: in-game days each stage lasts (1 = a week in all, 2 or 3 = slower).", false, false, (ValueValidator)null, (string)null);
			_infectionNights = obj2.CreateEntry<int>("InfectionNights", 3, "Zombie nights", "Nights of zombie waves before the final horde night (1 to 6).", false, false, (ValueValidator)null, (string)null);
			_storm = obj2.CreateEntry<float>("StormStrength", 1f, "Storm strength", "0 = no lightning or thunder, 1 = normal, 2 = constant.", false, false, (ValueValidator)null, (string)null);
			_zombieMult = obj2.CreateEntry<float>("ZombieNumbers", 1f, "Zombie numbers", "More or fewer zombies in each wave (0.25 to 3).", false, false, (ValueValidator)null, (string)null);
			_riotMult = obj2.CreateEntry<float>("RiotNumbers", 1f, "Riot numbers", "More or fewer rioters and killers on the streets (0.25 to 3).", false, false, (ValueValidator)null, (string)null);
			_copLethality = obj2.CreateEntry<string>("CopLethality", "Lethal", "Cop lethality", "Lethal = cops shoot curfew breakers on sight at night; NonLethal = they taser and arrest; Off = no curfew chases.", false, false, (ValueValidator)null, (string)null);
			_noKill = obj2.CreateEntry<bool>("NoKillMode", false, "No-kill mode", "Townspeople are only knocked out, never killed (zombies too: they go down and get back up as people at the end).", false, false, (ValueValidator)null, (string)null);
			_maxZombies = obj2.CreateEntry<int>("MaxZombies", 14, "Most zombies at once", "Hard cap on zombies near you at the same time (performance).", false, false, (ValueValidator)null, (string)null);
			_maxPeople = obj2.CreateEntry<int>("MaxPeople", 10, "Most armed people at once", "Hard cap on rioters, killers and survivors near you at the same time (performance).", false, false, (ValueValidator)null, (string)null);
			_maxFires = obj2.CreateEntry<int>("MaxFires", 6, "Most fires at once", "Hard cap on burning cars and fires near you (performance).", false, false, (ValueValidator)null, (string)null);
			_texts = obj2.CreateEntry<bool>("EmergencyTexts", true, "Emergency texts", "Emergency alerts and radio news on your phone.", false, false, (ValueValidator)null, (string)null);
			_sirens = obj2.CreateEntry<bool>("Sirens", true, "Sirens", "The town's air-raid siren during the end.", false, false, (ValueValidator)null, (string)null);
			_hud = obj2.CreateEntry<bool>("ShowCounter", true, "Day counter", "The DAY / NIGHT counter at the top of the screen.", false, false, (ValueValidator)null, (string)null);
			_skyTint = obj2.CreateEntry<bool>("OrangeSky", true, "Orange sky", "The burnt orange sky and darker colours while the end is on.", false, false, (ValueValidator)null, (string)null);
			_volume = obj2.CreateEntry<float>("Volume", 0.8f, "Volume", "Volume of the mod's sounds (0 to 1).", false, false, (ValueValidator)null, (string)null);
			try
			{
				FortifyApi.AfterLoad += OnLoaded;
				FortifyApi.BeforeSave += OnSaving;
				FortifyApi.Unloaded += OnUnloaded;
			}
			catch (Exception ex)
			{
				Log.Error("End Of The World could not link up with Fortify Your Base: " + ex.Message);
				return;
			}
			Ok = true;
			try
			{
				Patches.Apply(((MelonBase)this).HarmonyInstance);
			}
			catch (Exception ex2)
			{
				Warn("Patches: " + ex2.Message);
			}
			try
			{
				FortHook.Install();
			}
			catch (Exception ex3)
			{
				Warn("Fort app: " + ex3.Message);
			}
			Sfx.Prewarm();
			Log.Msg("End Of The World 1.0.2 ready (Fortify Your Base " + SafeFybVersion() + "). Start it from the Fort app on your phone.");
		}

		private static string SafeFybVersion()
		{
			try
			{
				return FortifyApi.Version;
			}
			catch
			{
				return "?";
			}
		}

		internal static void Warn(string msg)
		{
			try
			{
				Instance log = Log;
				if (log != null)
				{
					log.Warning(msg);
				}
			}
			catch
			{
			}
		}

		internal static void Msg(string msg)
		{
			try
			{
				Instance log = Log;
				if (log != null)
				{
					log.Msg(msg);
				}
			}
			catch
			{
			}
		}

		private static void OnLoaded()
		{
			try
			{
				State.Load(FortifyApi.GetData("woodstudios.endoftheworld"));
				World.OnLoaded();
				if (State.S.Active)
				{
					Msg($"This save is in the end of the world: day {Arc.Day} of {TotalDays} ({Arc.StageName}).");
				}
			}
			catch (Exception ex)
			{
				Warn("Load: " + ex.Message);
			}
		}

		private static void OnSaving()
		{
			try
			{
				if (State.S.Started)
				{
					FortifyApi.SetData("woodstudios.endoftheworld", State.Save());
				}
			}
			catch (Exception ex)
			{
				Warn("Save: " + ex.Message);
			}
		}

		private static void OnUnloaded()
		{
			try
			{
				World.ResetAll(unused: false);
			}
			catch (Exception ex)
			{
				Warn("Unload: " + ex.Message);
			}
			State.Clear();
		}

		public override void OnUpdate()
		{
			if (!Ok)
			{
				return;
			}
			bool flag = false;
			try
			{
				flag = FortifyApi.InGame && FortifyApi.DataReady;
			}
			catch
			{
			}
			if (!flag)
			{
				return;
			}
			try
			{
				World.Update();
			}
			catch (Exception ex)
			{
				ErrorOnce("update", ex);
			}
		}

		public override void OnGUI()
		{
			if (!Ok)
			{
				return;
			}
			try
			{
				if (FortifyApi.InGame)
				{
					Hud.Draw();
					EndScreen.Draw();
				}
			}
			catch (Exception ex)
			{
				ErrorOnce("screen", ex);
			}
		}

		internal static void ErrorOnce(string where, Exception ex)
		{
			if (!_errAt.TryGetValue(where, out var value) || !(Time.unscaledTime - value < 60f))
			{
				_errAt[where] = Time.unscaledTime;
				Warn($"{where}: {ex.GetType().Name}: {ex.Message}");
			}
		}
	}
	internal static class Fires
	{
		private sealed class Fire
		{
			public Vector3 Pos;

			public float Size;

			public float Until;

			public float NextPuff;

			public float NextBurn;

			public float Started;

			public Light L;

			public AudioSource Crackle;

			public bool Barrel;

			public GameObject Owner;
		}

		private static readonly List<Fire> All = new List<Fire>();

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

		public static int Count => All.Count;

		public static void Reset()
		{
			foreach (Fire item in All)
			{
				Kill(item);
			}
			All.Clear();
			Burnt.Clear();
			Puffs.Clear();
		}

		public static bool Start(Vector3 at, float seconds, float size, bool barrel = false, GameObject owner = null)
		{
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_00fa: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			if (!barrel && All.Count >= EotwCore.MaxFires)
			{
				Fire fire = null;
				foreach (Fire item2 in All)
				{
					if (!item2.Barrel && (fire == null || item2.Started < fire.Started))
					{
						fire = item2;
					}
				}
				if (fire == null)
				{
					return false;
				}
				Kill(fire);
				All.Remove(fire);
			}
			foreach (Fire item3 in All)
			{
				Vector3 val = item3.Pos - at;
				if (((Vector3)(ref val)).sqrMagnitude < 6.25f)
				{
					item3.Until = Mathf.Max(item3.Until, Time.unscaledTime + seconds);
					return true;
				}
			}
			try
			{
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(at + Vector3.up * 1.5f, Vector3.down, ref val2, 6f, -5, (QueryTriggerInteraction)1))
				{
					at = ((RaycastHit)(ref val2)).point;
				}
			}
			catch
			{
			}
			Fire item = new Fire
			{
				Pos = at,
				Size = size,
				Until = Time.unscaledTime + seconds,
				Started = Time.unscaledTime,
				Barrel = barrel,
				Owner = owner
			};
			All.Add(item);
			return true;
		}

		public static bool StartNearestCar(Vector3 near, float range)
		{
			//IL_006e: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				LandVehicle val = null;
				float num = range * range;
				List<LandVehicle> val2 = (((Object)(object)NetworkSingleton<VehicleManager>.Instance != (Object)null) ? NetworkSingleton<VehicleManager>.Instance.AllVehicles : null);
				for (int i = 0; val2 != null && i < val2.Count; i++)
				{
					LandVehicle val3 = val2[i];
					if ((Object)(object)val3 == (Object)null || Burnt.Contains(((Il2CppObjectBase)val3).Pointer))
					{
						continue;
					}
					try
					{
						if (val3.IsOccupied || val3.IsPlayerOwned)
						{
							continue;
						}
						goto IL_0067;
					}
					catch
					{
						goto IL_0067;
					}
					IL_0067:
					Vector3 val4 = ((Component)val3).transform.position - near;
					float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = val3;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				Burnt.Add(((Il2CppObjectBase)val).Pointer);
				Vector3 val5 = ((Component)val).transform.position + Vector3.up * 0.6f;
				bool num2 = Start(val5, Random.Range(240f, 420f), 1.25f);
				if (num2)
				{
					Sfx.At(val5, "glass", 0.8f, 50f);
				}
				return num2;
			}
			catch (Exception ex)
			{
				EotwCore.ErrorOnce("car fire", ex);
				return false;
			}
		}

		public static void Barrel(Vector3 at, Transform parent)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			GameObject val = Gfx.Model("eotw_barrel", parent) ?? Fallback.Drum(parent);
			try
			{
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(at + Vector3.up * 2f, Vector3.down, ref val2, 6f, -5, (QueryTriggerInteraction)1))
				{
					at = ((RaycastHit)(ref val2)).point;
				}
				val.transform.position = at;
			}
			catch
			{
			}
			Start(at + Vector3.up * 0.95f, 10000000f, 0.35f, barrel: true, ((Object)(object)parent != (Object)null) ? ((Component)parent).gameObject : null);
		}

		public static void Update()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			if (All.Count == 0)
			{
				Puffs.Update();
				return;
			}
			float unscaledTime = Time.unscaledTime;
			Player local = Player.Local;
			Vector3 val = (((Object)(object)local != (Object)null) ? ((Component)local).transform.position : Vector3.zero);
			for (int num = All.Count - 1; num >= 0; num--)
			{
				Fire fire = All[num];
				if (unscaledTime > fire.Until || (fire.Barrel && (Object)(object)fire.Owner == (Object)null))
				{
					Kill(fire);
					All.RemoveAt(num);
				}
				else
				{
					float num2 = Vector3.Distance(fire.Pos, val);
					bool flag = num2 < 140f;
					bool flag2 = num2 < 60f;
					if (flag2 && (Object)(object)fire.L == (Object)null)
					{
						MakeLight(fire);
					}
					else if (!flag2 && (Object)(object)fire.L != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)fire.L).gameObject);
						fire.L = null;
					}
					if (num2 < 35f && (Object)(object)fire.Crackle == (Object)null)
					{
						fire.Crackle = Sfx.At(fire.Pos, "crackle", fire.Barrel ? 0.35f : 0.8f, fire.Barrel ? 14f : 32f, loop: true, Random.Range(0.9f, 1.1f));
					}
					else if (num2 >= 38f && (Object)(object)fire.Crackle != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)fire.Crackle).gameObject);
						fire.Crackle = null;
					}
					if ((Object)(object)fire.L != (Object)null)
					{
						fire.L.intensity = (2.2f + Mathf.PerlinNoise(unscaledTime * 8f, (float)num * 3.1f) * 2.4f) * Mathf.Clamp(fire.Size, 0.4f, 1.5f);
					}
					if (flag)
					{
						float num3 = (flag2 ? 26f : 8f) * fire.Size;
						while (fire.NextPuff <= unscaledTime)
						{
							fire.NextPuff = Mathf.Max(fire.NextPuff, unscaledTime - 0.1f) + 1f / num3;
							float num4 = 0.7f * fire.Size;
							Vector2 val2 = Random.insideUnitCircle * num4;
							Vector3 val3 = fire.Pos + new Vector3(val2.x, 0.05f, val2.y);
							float num5 = Puffs.R(0.5f, 1f) * fire.Size;
							bool flag3 = Random.value < 0.15f;
							Puffs.Emit(flag3 ? Puffs.Look.Ember : Puffs.Look.Flame, val3, new Vector3(Puffs.R(-0.2f, 0.2f), Puffs.R(1f, 2.4f), Puffs.R(-0.2f, 0.2f)), flag3 ? (num5 * 0.22f) : (num5 * 0.6f), flag3 ? (num5 * 0.35f) : (num5 * 1.3f), Puffs.R(0.45f, 0.9f), 0.95f, 1.8f, 0.6f);
							if (Random.value < (fire.Barrel ? 0.1f : 0.3f))
							{
								Puffs.Emit(Puffs.Look.DarkSmoke, val3 + Vector3.up * (1f * fire.Size), Vector3.up * Puffs.R(1.2f, 2.4f) + new Vector3(Puffs.R(-0.3f, 0.3f), 0f, Puffs.R(-0.3f, 0.3f)), 0.6f * fire.Size, Puffs.R(2.5f, 4.5f) * fire.Size, Puffs.R(4f, 7f), 0.55f, 0.5f, 0.25f);
							}
						}
						if (unscaledTime >= fire.NextBurn && !fire.Barrel)
						{
							fire.NextBurn = unscaledTime + 0.5f;
							Burn(fire, local);
						}
					}
				}
			}
			Puffs.Update();
		}

		private static void MakeLight(Fire f)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0012: 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_0032: 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)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject val = new GameObject("EOTW_FireLight");
				val.transform.position = f.Pos + Vector3.up * (0.9f * Mathf.Max(0.5f, f.Size));
				f.L = val.AddComponent<Light>();
				f.L.type = (LightType)2;
				f.L.color = new Color(1f, 0.5f, 0.16f);
				f.L.range = 10f * Mathf.Clamp(f.Size, 0.5f, 1.5f);
				f.L.shadows = (LightShadows)0;
			}
			catch
			{
			}
		}

		private static void Burn(Fire f, Player me)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)me == (Object)null)
			{
				return;
			}
			Vector3 val = ((Component)me).transform.position - f.Pos;
			float num = 1.3f * f.Size;
			if (!(Mathf.Abs(val.y) < 2f))
			{
				return;
			}
			Vector2 val2 = new Vector2(val.x, val.z);
			if (!(((Vector2)(ref val2)).sqrMagnitude < num * num))
			{
				return;
			}
			try
			{
				me.Health.TakeDamage(4f, true, false);
			}
			catch
			{
			}
		}

		private static void Kill(Fire f)
		{
			try
			{
				if ((Object)(object)f.L != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)f.L).gameObject);
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)f.Crackle != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)f.Crackle).gameObject);
				}
			}
			catch
			{
			}
			f.L = null;
			f.Crackle = null;
		}
	}
	internal static class FortHook
	{
		public static void Install()
		{
			Assembly assembly = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly2 in assemblies)
			{
				if (assembly2.GetName().Name == "HoldTheFort")
				{
					assembly = assembly2;
					break;
				}
			}
			if (assembly == null)
			{
				return;
			}
			Type type = assembly.GetType("HoldTheFort.FortFeature");
			FieldInfo fieldInfo = assembly.GetType("HoldTheFort.FortApp")?.GetField("Features", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (type == null || fieldInfo == null)
			{
				EotwCore.Warn("Fort app: its list of rows wasn't found, so start the end from the settings instead.");
			}
			else
			{
				if (!(fieldInfo.GetValue(null) is IList list))
				{
					return;
				}
				foreach (object item in list)
				{
					if (type.GetField("Id")?.GetValue(item) as string == "EndOfTheWorld")
					{
						return;
					}
				}
				object obj = Activator.CreateInstance(type, nonPublic: true);
				Set(type, obj, "Id", "EndOfTheWorld");
				Set(type, obj, "Name", "End Of The World");
				Set(type, obj, "Info", "The slow end of the world, in this save only: storms, riots, the infection. Survive the nights.");
				Set(type, obj, "Value", new Func<string>(ButtonText));
				Set(type, obj, "Cycle", new Action(Clicked));
				Set(type, obj, "Status", new Func<string>(StatusText));
				list.Insert(0, obj);
				EotwCore.Msg("Fort app: End Of The World row added.");
			}
		}

		private static void Set(Type t, object o, string field, object value)
		{
			t.GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.SetValue(o, value);
		}

		private static string ButtonText()
		{
			try
			{
				if (!FortifyApi.InGame)
				{
					return "OPEN";
				}
				SaveData s = State.S;
				if (!s.Active)
				{
					return (s.Started && s.TimesEnded > 0) ? "AGAIN" : "BEGIN";
				}
				if (s.Ending == "choose")
				{
					return "CHOOSE";
				}
				return Arc.WaveNight ? $"NIGHT {Arc.NightNumber}" : $"DAY {Arc.Day}";
			}
			catch
			{
				return "OPEN";
			}
		}

		private static string StatusText()
		{
			try
			{
				SaveData s = State.S;
				if (!s.Active)
				{
					return (s.Started && !string.IsNullOrEmpty(s.Outcome)) ? ("Last time: " + s.Outcome) : "Not started in this save.";
				}
				return Arc.StageName + ". " + Arc.NextEventText();
			}
			catch
			{
				return null;
			}
		}

		private static void Clicked()
		{
			try
			{
				EndScreen.OpenMain();
			}
			catch (Exception ex)
			{
				EotwCore.Warn("Fort app: " + ex.Message);
			}
		}
	}
	internal static class FybLink
	{
		private static Assembly _fyb;

		private static MethodInfo _wallNearest;

		private static MethodInfo _wallHit;

		private static MethodInfo _wallIsDown;

		private static Type _modelsType;

		private static readonly Dictionary<string, MethodInfo> Builders = new Dictionary<string, MethodInfo>();

		private static bool _init;

		private static void Init()
		{
			if (_init)
			{
				return;
			}
			_init = true;
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					if (assembly.GetName().Name == "HoldTheFort")
					{
						_fyb = assembly;
						break;
					}
				}
				if (!(_fyb == null))
				{
					Type type = _fyb.GetType("HoldTheFort.Walls");
					if (type != null)
					{
						_wallNearest = type.GetMethod("Nearest", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						_wallHit = type.GetMethod("Hit", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						_wallIsDown = type.GetMethod("IsDown", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					}
					_modelsType = _fyb.GetType("HoldTheFort.Models");
					EotwCore.Msg($"Fortify Your Base link: walls {((_wallNearest != null && _wallHit != null) ? "yes" : "no")}, building pieces {((_modelsType != null) ? "yes" : "no")}.");
				}
			}
			catch (Exception ex)
			{
				EotwCore.Warn("Fortify Your Base link: " + ex.Message);
			}
		}

		public static bool BashWall(Vector3 at, int hits)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			Init();
			if (_wallNearest == null || _wallHit == null)
			{
				return false;
			}
			try
			{
				object[] array = new object[3]
				{
					at,
					2.6f,
					Vector3.zero
				};
				object? obj = _wallNearest.Invoke(null, array);
				BuildableItem val = (BuildableItem)((obj is BuildableItem) ? obj : null);
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				Vector3 val2 = (Vector3)array[2];
				for (int i = 0; i < hits; i++)
				{
					_wallHit.Invoke(null, new object[3]
					{
						val,
						val2,
						at + Vector3.up * 1.2f
					});
				}
				Sfx.At(val2, "bash", 0.9f, 40f, loop: false, Random.Range(0.85f, 1.1f));
				return true;
			}
			catch (Exception ex)
			{
				EotwCore.ErrorOnce("walls", ex);
				return false;
			}
		}

		public static GameObject Piece(string name, Transform parent)
		{
			Init();
			if (_modelsType == null)
			{
				return null;
			}
			try
			{
				if (!Builders.TryGetValue(name, out var value))
				{
					value = _modelsType.GetMethod(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
					Builders[name] = value;
				}
				if (value == null)
				{
					return null;
				}
				object? obj = value.Invoke(null, null);
				GameObject val = (GameObject)((obj is GameObject) ? obj : null);
				if ((Object)(object)val == (Object)null)
				{
					return null;
				}
				val.transform.SetParent(parent, false);
				((Object)val).name = "EOTW_FYB_" + name;
				val.SetActive(true);
				return val;
			}
			catch (Exception ex)
			{
				EotwCore.ErrorOnce("fyb piece " + name, ex);
				return null;
			}
		}

		public static GameObject Wall(float length, Transform parent)
		{
			Init();
			if (_modelsType == null)
			{
				return null;
			}
			try
			{
				object? obj = _modelsType.GetMethod("Wall", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(float) }, null)?.Invoke(null, new object[1] { length });
				GameObject val = (GameObject)((obj is GameObject) ? obj : null);
				if ((Object)(object)val == (Object)null)
				{
					return null;
				}
				val.transform.SetParent(parent, false);
				val.SetActive(true);
				return val;
			}
			catch (Exception ex)
			{
				EotwCore.ErrorOnce("fyb wall", ex);
				return null;
			}
		}

		public static void PatchFighters(Harmony h)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			Init();
			if (_fyb == null)
			{
				return;
			}
			try
			{
				MethodInfo methodInfo = _fyb.GetType("HoldTheFort.Fighters")?.GetMethod("Threats", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (methodInfo == null)
				{
					EotwCore.Warn("Fortify Your Base: its crew won't fight the infected (Fighters.Threats not found).");
				}
				else
				{
					h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(FybLink), "ThreatsPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				EotwCore.Warn("Fortify Your Base crew link: " + ex.Message);
			}
		}

		private static void ThreatsPostfix(Property prop, Vector3 home, List<GameObject> __result)
		{
			//IL_0020: 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)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_009a: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (__result == null || !State.S.Active || People.List.Count == 0)
				{
					return;
				}
				foreach (Actor item in People.List)
				{
					if (item.Hostile && !item.Dormant && item.Up)
					{
						Vector3 pos = item.Pos;
						Vector3 val = pos - home;
						val.y = 0f;
						bool flag = ((Vector3)(ref val)).sqrMagnitude < 256f;
						if (!flag && (Object)(object)prop != (Object)null)
						{
							Vector3 val2 = Places.Center(prop);
							Vector3 val3 = pos - val2;
							val3.y = 0f;
							flag = ((Vector3)(ref val3)).sqrMagnitude < 484f;
						}
						if (flag)
						{
							__result.Add(((Component)item.Npc).gameObject);
						}
					}
				}
			}
			catch
			{
			}
		}
	}
	internal static class Gangs
	{
		private sealed class Mob
		{
			public int Id;

			public Side Side;

			public Vector3 Site;

			public string SiteName;

			public float Until;

			public float NextMischief;

			public readonly List<Actor> Members = new List<Actor>();
		}

		private const string Pipe = "Avatar/Equippables/Pipe";

		private const string Hammer = "Avatar/Equippables/Hammer";

		private const string Knife = "Avatar/Equippables/Knife";

		private const string Bottle = "Avatar/Equippables/BrokenBottle";

		private const string Bat = "Avatar/Equippables/Baton";

		private const string Pistol = "Avatar/Equippables/M1911";

		private const string Revolver = "Avatar/Equippables/Revolver";

		private const string Shotgun = "Avatar/Equippables/PumpShotgun";

		private static readonly string[] Melee = new string[6] { "Avatar/Equippables/Pipe", "Avatar/Equippables/Hammer", "Avatar/Equippables/Knife", "Avatar/Equippables/BrokenBottle", "Avatar/Equippables/Baton", "Avatar/Equippables/Pipe" };

		private static readonly string[] Guns = new string[4] { "Avatar/Equippables/M1911", "Avatar/Equippables/Revolver", "Avatar/Equippables/M1911", "Avatar/Equippables/PumpShotgun" };

		private static readonly List<Mob> Mobs = new List<Mob>();

		private static int _nextId = 1;

		private static float _nextCheck;

		private static float _nextThink;

		public static int Rioters => People.Live(Side.Rioter);

		public static int Killers => People.Live(Side.Killer);

		public static void Reset()
		{
			Mobs.Clear();
			_nextCheck = 0f;
			_nextThink = 0f;
		}

		public static void Update()
		{
			//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)
			//IL_003f: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to in