Decompiled source of Huntdown v1.5.2

Huntdown.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Huntdown.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Huntdown")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Huntdown")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2b817e02-a71e-44d9-aa9a-94bb15fecd9f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Huntdown
{
	public enum GeneralConfigKey
	{
		DisplayTarget,
		GeneralPercentageChance,
		ToggleWeightDynamic
	}
	public enum RewardConfigKey
	{
		RewardLow,
		RewardMedium,
		RewardHigh,
		RewardExtreme
	}
	public static class ConfigSettings
	{
		public struct ConfigurableSetting
		{
			public Enum Index;

			public string Section;

			public string Key;

			public object DefaultValue;

			public ConfigDescription Description;
		}

		private enum ConfigSections
		{
			[Description("1: General Settings")]
			General,
			[Description("2: Toggle Missions")]
			Toggle,
			[Description("3: Mission Weights")]
			Weight,
			[Description("4: Mission Rewards")]
			Reward
		}

		public enum DisplayTargetSettings
		{
			Full,
			Some,
			None
		}

		public enum ConfigIndexes
		{
			DisplayTarget,
			GeneralPercentageChance,
			ToggleWeightDynamic,
			ToggleFlea,
			ToggleSpider,
			ToggleHoarder,
			ToggleBracken,
			ToggleThumper,
			ToggleNutcracker,
			ToggleMasked,
			ToggleDog,
			ToggleMafia,
			ToggleBlunderbug,
			ToggleInfestation,
			ToggleLastcrew,
			ToggleButler,
			ToggleManeater,
			ToggleBaboonGang,
			WeightFlea,
			WeightSpider,
			WeightHoarder,
			WeightBracken,
			WeightThumper,
			WeightNutcracker,
			WeightMasked,
			WeightDog,
			WeightMafia,
			WeightBlunderbug,
			WeightInfestation,
			WeightLastcrew,
			WeightButler,
			WeightManeater,
			WeightBaboonGang,
			RewardLow,
			RewardMedium,
			RewardHigh,
			RewardExtreme
		}

		public static readonly ConfigurableSetting[] AllConfigurableSettings = new ConfigurableSetting[37]
		{
			new ConfigurableSetting
			{
				Index = ConfigIndexes.DisplayTarget,
				Section = ConfigSections.General.GetDescription(),
				Key = "Display Target at Round Start",
				DefaultValue = DisplayTargetSettings.Full,
				Description = new ConfigDescription("0: Display both whether you have a target, and its name.\n1: Display whether you have a target, but without its name.\n2: Never display if you have a target.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, Enum.GetNames(typeof(DisplayTargetSettings)).Length - 1), Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.GeneralPercentageChance,
				Section = ConfigSections.General.GetDescription(),
				Key = "Percentage Chance of Mission",
				DefaultValue = 100,
				Description = new ConfigDescription("The percent chance that your team will receive a target to hunt.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleWeightDynamic,
				Section = ConfigSections.General.GetDescription(),
				Key = "Dynamic Weighting System",
				DefaultValue = true,
				Description = new ConfigDescription("Makes it more likely to get missions you haven't been given yet to keep things fresh.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleFlea,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Snare Flea Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether a Snare Flea can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleSpider,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Bunker Spider Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether a Bunker Spider can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleHoarder,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Hoarder Bug Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether a Hoarding Bug can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleBracken,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Bracken Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether a Bracken can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleThumper,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Thumper Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether a Thumper can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleNutcracker,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Nutcracker Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether a Nutcracker can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleMasked,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Masked Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether a Masked can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleDog,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Good Boy Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether a Good Boy can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleMafia,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Bug Mafia Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether the Bug Mafia can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleBlunderbug,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Blunderbug Mission Enabled",
				DefaultValue = false,
				Description = new ConfigDescription("(WIP, recommended to keep disabled) Whether the Blunderbug can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleInfestation,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Infestation Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether the Infestation (2 hoarding bugs, 2 snare fleas and 1 bunker spider) can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleLastcrew,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Last Months Interns Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether the Last Month's Interns (4 masked) can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleButler,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Butler Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether the Butler can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleManeater,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Maneater Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether the Maneater can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.ToggleBaboonGang,
				Section = ConfigSections.Toggle.GetDescription(),
				Key = "Baboon Gang Mission Enabled",
				DefaultValue = true,
				Description = new ConfigDescription("Whether the Baboon Gang (3 baboon hawks) can be assigned as the hunt target or not.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightFlea,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Snare Flea Mission Weight",
				DefaultValue = 100,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that a Snare Flea will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightSpider,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Bunker Spider Mission Weight",
				DefaultValue = 100,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that a Bunker Spider will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightHoarder,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Hoarder Bug Mission Weight",
				DefaultValue = 100,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that a Hoarder Bug will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightBracken,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Bracken Mission Weight",
				DefaultValue = 50,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that a Bracken will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightThumper,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Thumper Mission Weight",
				DefaultValue = 100,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that a Thumper will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightNutcracker,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Nutcracker Mission Weight",
				DefaultValue = 50,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that a Nutcracker will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightMasked,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Masked Mission Weight",
				DefaultValue = 75,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that a Masked will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightDog,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Good Boy Mission Weight",
				DefaultValue = 20,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that a Good Boy will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightMafia,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Bug Mafia Mission Weight",
				DefaultValue = 50,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that the Bug Mafia will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightBlunderbug,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Blunderbug Mission Weight",
				DefaultValue = 0,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that the Blunderbug will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightInfestation,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Infestation Mission Weight",
				DefaultValue = 25,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that the Infestation will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightLastcrew,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Last Months Interns Mission Weight",
				DefaultValue = 15,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that Last Month's Interns will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightButler,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Butler Mission Weight",
				DefaultValue = 50,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that the Butler will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightManeater,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Maneater Mission Weight",
				DefaultValue = 10,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that the Maneater will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.WeightBaboonGang,
				Section = ConfigSections.Weight.GetDescription(),
				Key = "Baboon Gang Mission Weight",
				DefaultValue = 30,
				Description = new ConfigDescription("Higher value = more likely. The likelihood that the Baboon Gang will be the target.", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.RewardLow,
				Section = ConfigSections.Reward.GetDescription(),
				Key = "Easy Mission Reward",
				DefaultValue = 50,
				Description = new ConfigDescription("How much the scrap dropped from an easy mission is worth (Snare Flea, Hoarding Bug).", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.RewardMedium,
				Section = ConfigSections.Reward.GetDescription(),
				Key = "Medium Mission Reward",
				DefaultValue = 100,
				Description = new ConfigDescription("How much the scrap dropped from a medium mission is worth (Thumper, Bunker Spider, Masked, Butler, Blunderbug).", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.RewardHigh,
				Section = ConfigSections.Reward.GetDescription(),
				Key = "Hard Mission Reward",
				DefaultValue = 200,
				Description = new ConfigDescription("How much the scrap dropped from a hard mission is worth (Bracken, Nutcracker, Bug Mafia, Infestation, Baboon Gang).", (AcceptableValueBase)null, Array.Empty<object>())
			},
			new ConfigurableSetting
			{
				Index = ConfigIndexes.RewardExtreme,
				Section = ConfigSections.Reward.GetDescription(),
				Key = "Extreme Mission Reward",
				DefaultValue = 300,
				Description = new ConfigDescription("How much the scrap dropped from an extreme mission is worth (Good Boy, Last Months Interns, Maneater).", (AcceptableValueBase)null, Array.Empty<object>())
			}
		};

		public static ConfigEntryBase[] ConfigEntries = (ConfigEntryBase[])(object)new ConfigEntryBase[AllConfigurableSettings.Length];

		private static string GetDescription(this Enum value)
		{
			if (value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), inherit: false) is DescriptionAttribute[] source && source.Any())
			{
				return source.First().Description;
			}
			return value.ToString();
		}

		public static void BindConfigSettings()
		{
			for (int i = 0; i < AllConfigurableSettings.Length; i++)
			{
				Huntdown._logger.LogInfo((object)$"[{i}] Binding: {AllConfigurableSettings[i].Key}");
				BindAnyObject(AllConfigurableSettings[i], i);
			}
		}

		private static void BindAnyObject(ConfigurableSetting setting, int index)
		{
			if (setting.DefaultValue is int || setting.DefaultValue is Enum)
			{
				ConfigEntryBase[] configEntries = ConfigEntries;
				string section = setting.Section;
				string key = setting.Key;
				int defaultValue = (int)setting.DefaultValue;
				ConfigDescription description = setting.Description;
				configEntries[index] = (ConfigEntryBase)(object)Bind(section, key, defaultValue, (description != null) ? description.Description : null);
			}
			else if (setting.DefaultValue is bool)
			{
				ConfigEntryBase[] configEntries2 = ConfigEntries;
				string section2 = setting.Section;
				string key2 = setting.Key;
				bool defaultValue2 = (bool)setting.DefaultValue;
				ConfigDescription description2 = setting.Description;
				configEntries2[index] = (ConfigEntryBase)(object)Bind(section2, key2, defaultValue2, (description2 != null) ? description2.Description : null);
			}
			else if (setting.DefaultValue is float)
			{
				ConfigEntryBase[] configEntries3 = ConfigEntries;
				string section3 = setting.Section;
				string key3 = setting.Key;
				float defaultValue3 = (float)setting.DefaultValue;
				ConfigDescription description3 = setting.Description;
				configEntries3[index] = (ConfigEntryBase)(object)Bind(section3, key3, defaultValue3, (description3 != null) ? description3.Description : null);
			}
			else
			{
				LogUnsupportedType(setting.Key);
			}
		}

		private static void LogUnsupportedType(string settingKey)
		{
			Huntdown._logger.LogError((object)("Unsupported DefaultValue type for setting " + settingKey + "."));
		}

		private static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description = null)
		{
			return ((BaseUnityPlugin)Huntdown._instance).Config.Bind<T>(section, key, defaultValue, description);
		}
	}
	public enum EnemyKey
	{
		SnareFlea,
		BunkerSpider,
		HoarderBug,
		Bracken,
		Thumper,
		Nutcracker,
		Masked,
		EyelessDog,
		Butler,
		Maneater,
		BaboonHawk
	}
	public class StoredEnemy
	{
		private EnemyKey _key;

		private string _ID;

		private string _name;

		private SpawnableEnemyWithRarity _storedEnemy;

		public EnemyKey Key
		{
			get
			{
				return _key;
			}
			set
			{
				_key = value;
			}
		}

		public string ID
		{
			get
			{
				return _ID;
			}
			set
			{
				_ID = value;
			}
		}

		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
			}
		}

		public SpawnableEnemyWithRarity SpawnableEnemy
		{
			get
			{
				return _storedEnemy;
			}
			set
			{
				_storedEnemy = value;
			}
		}

		public StoredEnemy(EnemyKey key, string id)
		{
			_key = key;
			_ID = id;
		}
	}
	public enum MissionKey
	{
		SnareFlea,
		BunkerSpider,
		HoarderBug,
		Bracken,
		Thumper,
		Nutcracker,
		Masked,
		GoodBoy,
		BugMafia,
		Butler,
		Maneater,
		BaboonGang
	}
	public class Mission
	{
		private readonly string _name;

		private readonly Dictionary<EnemyKey, int> _enemiesToSpawn;

		private static List<EnemyAI> _aliveEnemies = new List<EnemyAI>();

		public static int _maxEnemies;

		private RewardPool _rewardPool;

		private readonly int _baseWeight;

		private int _weight;

		private static int _totalWeight;

		private static readonly int _missionChance = (int)ConfigSettings.ConfigEntries[1].BoxedValue;

		private bool _enabled;

		public string Name => _name;

		public Dictionary<EnemyKey, int> EnemiesToSpawn => _enemiesToSpawn;

		public RewardPool RewardPool
		{
			get
			{
				return _rewardPool;
			}
			set
			{
				_rewardPool = value;
			}
		}

		public int BaseWeight => _baseWeight;

		public int Weight
		{
			get
			{
				return _weight;
			}
			set
			{
				_weight = value;
			}
		}

		public static int TotalWeight
		{
			get
			{
				return _totalWeight;
			}
			set
			{
				_totalWeight = value;
			}
		}

		public static int MissionChance => _missionChance;

		public bool Enabled
		{
			get
			{
				return _enabled;
			}
			set
			{
				_enabled = value;
			}
		}

		public static List<EnemyAI> AliveEnemies
		{
			get
			{
				return _aliveEnemies;
			}
			set
			{
				_aliveEnemies = value;
			}
		}

		public Mission(string name, int baseWeight, Dictionary<EnemyKey, int> enemiesToSpawn, bool enabled, RewardPool rewardPool)
		{
			_name = name;
			_baseWeight = baseWeight;
			_weight = baseWeight;
			_enemiesToSpawn = enemiesToSpawn;
			_enabled = enabled;
			_rewardPool = rewardPool;
		}

		public void Start(ref SelectableLevel level, EnemyVent[] allVents)
		{
			Huntdown._currentLevel = level;
			Huntdown._allEnemyVents = allVents;
			SpawnEnemiesAtVent(ref level, RollRandomFarVent(allVents));
		}

		public void End()
		{
			if (Huntdown._currentMission != null)
			{
				_aliveEnemies.Clear();
				Huntdown._currentMission = null;
			}
		}

		public static EnemyVent RollRandomFarVent(EnemyVent[] allVents)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			Huntdown._logger.LogInfo((object)"Rolling for a random faraway vent...");
			Vector3 entrancePos = RoundManager.FindMainEntrancePosition(false, false);
			float longestDist = 0f;
			List<EnemyVent> list = new List<EnemyVent>();
			ManualLogSource logger = Huntdown._logger;
			Vector3 val = entrancePos;
			logger.LogInfo((object)("MainEntrancePos: " + ((object)(Vector3)(ref val)).ToString()));
			for (int i = 0; i < allVents.Length; i++)
			{
				ManualLogSource logger2 = Huntdown._logger;
				string text = i.ToString();
				val = ((Component)allVents[i]).transform.position;
				logger2.LogInfo((object)(text + "VentPosEntrancePos: " + ((object)(Vector3)(ref val)).ToString()));
				float num = Vector3.Distance(entrancePos, ((Component)allVents[i]).transform.position);
				if (num > longestDist)
				{
					longestDist = num;
				}
			}
			Huntdown._logger.LogInfo((object)("longest dist: " + longestDist));
			Vector3 val2 = (entrancePos + ((Component)allVents.Where((EnemyVent vent) => Vector3.Distance(entrancePos, ((Component)vent).transform.position) == longestDist).FirstOrDefault()).transform.position) / 2f;
			ManualLogSource logger3 = Huntdown._logger;
			val = val2;
			logger3.LogInfo((object)("midpoint: " + ((object)(Vector3)(ref val)).ToString()));
			float num2 = Vector3.Distance(entrancePos, val2);
			Huntdown._logger.LogInfo((object)("halfway dist: " + num2));
			for (int j = 0; j < allVents.Length; j++)
			{
				ManualLogSource logger4 = Huntdown._logger;
				string text2 = j.ToString();
				val = ((Component)allVents[j]).transform.position;
				logger4.LogInfo((object)(text2 + "VentPosEntrancePos: " + ((object)(Vector3)(ref val)).ToString()));
				float num3 = Vector3.Distance(entrancePos, ((Component)allVents[j]).transform.position);
				if (num3 >= num2)
				{
					Huntdown._logger.LogInfo((object)("dist: " + num3));
					Huntdown._logger.LogInfo((object)("halfwaydist " + num2));
					list.Add(allVents[j]);
				}
			}
			int index = new Random().Next(0, list.Count);
			Huntdown._logger.LogInfo((object)("Rolled " + index + " out of " + list.Count + "."));
			return list[index];
		}

		public static bool RollMissionChance()
		{
			Huntdown._logger.LogInfo((object)"Rolling for mission generation...");
			int num = new Random().Next(0, 100);
			ManualLogSource logger = Huntdown._logger;
			string[] obj = new string[5]
			{
				"Rolled ",
				num.ToString(),
				" out of ",
				null,
				null
			};
			int missionChance = _missionChance;
			obj[3] = missionChance.ToString();
			obj[4] = ".";
			logger.LogInfo((object)string.Concat(obj));
			Huntdown._logger.LogInfo((object)("Mission received: " + (num <= _missionChance) + "."));
			return num <= _missionChance;
		}

		private void ForceAIInside(EnemyAI enemyAI)
		{
			Huntdown._logger.LogInfo((object)"Forcing dog AI to work indoors.");
			enemyAI.enemyType = Object.Instantiate<EnemyType>(enemyAI.enemyType);
			enemyAI.enemyType.isOutsideEnemy = false;
			enemyAI.allAINodes = GameObject.FindGameObjectsWithTag("AINode");
			enemyAI.SyncPositionToClients();
		}

		private void SpawnUnnaturalEnemiesAtVent(ref SelectableLevel level, EnemyVent vent, KeyValuePair<EnemyKey, int> entry)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			Huntdown._logger.LogInfo((object)"Enemy does not spawn naturally on this moon. Temporarily adding it to spawnable enemies.");
			level.Enemies.Add(Huntdown._storedEnemies[(int)entry.Key].SpawnableEnemy);
			for (int i = 0; i < entry.Value; i++)
			{
				RoundManager.Instance.SpawnEnemyOnServer(((Component)vent).transform.position, 0f, level.Enemies.IndexOf(Huntdown._storedEnemies[(int)entry.Key].SpawnableEnemy));
				_aliveEnemies.Add(RoundManager.Instance.SpawnedEnemies[RoundManager.Instance.SpawnedEnemies.Count - 1]);
				EnemyAI val = _aliveEnemies[_aliveEnemies.Count - 1];
				if (val is MouthDogAI)
				{
					Huntdown._logger.LogInfo((object)"Dog detected, forcing it to work inside.");
					ForceAIInside(val);
					Huntdown._logger.LogInfo((object)"Forced doggo inside successfully.");
				}
				if (Object.op_Implicit((Object)(object)((Component)val).gameObject.GetComponentInChildren<ScanNodeProperties>()))
				{
					((Component)val).gameObject.GetComponentInChildren<ScanNodeProperties>().headerText = "<color=white>TARGET</color>";
				}
			}
			level.Enemies.Remove(Huntdown._storedEnemies[(int)entry.Key].SpawnableEnemy);
		}

		public void SpawnEnemiesAtVent(ref SelectableLevel level, EnemyVent vent)
		{
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			Huntdown._logger.LogInfo((object)"Spawning mission targets...");
			foreach (KeyValuePair<EnemyKey, int> item in _enemiesToSpawn)
			{
				Huntdown._logger.LogInfo((object)("Spawning " + item.Value + " " + Huntdown._storedEnemies[(int)item.Key].Name + "."));
				if (!level.Enemies.Contains(Huntdown._storedEnemies[(int)item.Key].SpawnableEnemy))
				{
					SpawnUnnaturalEnemiesAtVent(ref level, vent, item);
					continue;
				}
				for (int i = 0; i < item.Value; i++)
				{
					try
					{
						SpawnableEnemyWithRarity spawnableEnemy = Huntdown._storedEnemies[(int)item.Key].SpawnableEnemy;
						spawnableEnemy.enemyType = Object.Instantiate<EnemyType>(spawnableEnemy.enemyType);
						spawnableEnemy.enemyType.enemyPrefab = Object.Instantiate<GameObject>(spawnableEnemy.enemyType.enemyPrefab);
						spawnableEnemy.enemyType.enemyPrefab.GetComponentInChildren<ScanNodeProperties>().headerText = "<color=white>TARGET</color>";
						level.Enemies.Add(spawnableEnemy);
						RoundManager.Instance.SpawnEnemyOnServer(((Component)vent).transform.position, 0f, level.Enemies.IndexOf(level.Enemies.Last()));
						level.Enemies.Remove(level.Enemies.Last());
						Huntdown._logger.LogInfo((object)"Enemy spawned successfully.");
					}
					catch (Exception ex)
					{
						Huntdown._logger.LogError((object)("Could not spawn enemy.\n" + ex.Message));
					}
					_aliveEnemies.Add(RoundManager.Instance.SpawnedEnemies[RoundManager.Instance.SpawnedEnemies.Count - 1]);
					EnemyAI val = _aliveEnemies[_aliveEnemies.Count - 1];
					if (val is MouthDogAI)
					{
						Huntdown._logger.LogInfo((object)"Dog detected, forcing it to work inside.");
						ForceAIInside(val);
						Huntdown._logger.LogInfo((object)"Forced doggo inside successfully.");
					}
					try
					{
						if (Object.op_Implicit((Object)(object)((Component)val).gameObject.GetComponentInChildren<ScanNodeProperties>()))
						{
							((Component)val).gameObject.GetComponentInChildren<ScanNodeProperties>().headerText = "<color=white>TARGET</color>";
							Huntdown._logger.LogInfo((object)"Applied header text to enemy's scan node successfully.");
						}
					}
					catch (Exception ex2)
					{
						Huntdown._logger.LogError((object)("EnemyAI does not have a gameObject, or something is wrong with this function.\n" + ex2.Message));
					}
				}
			}
			_maxEnemies = _aliveEnemies.Count;
		}
	}
	public enum ItemKey
	{
		Binoculars,
		Boombox,
		CardboardBox,
		Flashlight,
		Jetpack,
		Key,
		LockPicker,
		LungApparatus,
		MapDevice,
		ProFlashlight,
		Shovel,
		StunGrenade,
		ExtensionLadder,
		TZPInhalant,
		WalkieTalkie,
		ZapGun,
		_7Ball,
		Airhorn,
		Bell,
		BigBolt,
		BottleBin,
		Brush,
		Candy,
		CashRegister,
		ChemicalJug,
		ClownHorn,
		Cog1,
		Dentures,
		DustPan,
		EggBeater,
		EnginePart1,
		FancyCup,
		FancyLamp,
		FancyPainting,
		FishTestProp,
		FlashLaserPointer,
		GoldBar,
		Hairdryer,
		MagnifyingGlass,
		MetalSheet,
		MoldPan,
		Mug,
		PerfumeBottle,
		Phone,
		PickleJar,
		PillBottle,
		Remote,
		Ring,
		RobotToy,
		RubberDuck,
		SodaCanRed,
		SteeringWheel,
		StopSign,
		TeaKettle,
		Toothpaste,
		ToyCube,
		RedLocustHive,
		RadarBooster,
		YieldSign,
		Shotgun,
		GunAmmo,
		SprayPaint,
		DiyFlashbang,
		GiftBox,
		Flask,
		TragedyMask,
		ComedyMask,
		WhoopieCushion,
		EasterEgg,
		GarbageLid,
		ToiletPaperRolls,
		Zeddog,
		WeedKillerBottle,
		ToyTrain,
		SoccerBall,
		Knife,
		ControlPad,
		PlasticCup
	}
	public class StoredItem
	{
		private ItemKey _key;

		private string _ID;

		private string _name;

		private Item _gameItem;

		public ItemKey Key
		{
			get
			{
				return _key;
			}
			set
			{
				_key = value;
			}
		}

		public string ID
		{
			get
			{
				return _ID;
			}
			set
			{
				_ID = value;
			}
		}

		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
			}
		}

		public Item GameItem
		{
			get
			{
				return _gameItem;
			}
			set
			{
				_gameItem = value;
			}
		}

		public StoredItem(ItemKey key, string id)
		{
			_key = key;
			_ID = id;
		}
	}
	public enum RewardPoolKey
	{
		SmallRewardPool,
		MediumRewardPool,
		LargeRewardPool,
		HugeRewardPool,
		MaskRewardPool
	}
	public class RewardPool
	{
		private List<StoredItem> _rewards;

		private int _value;

		public List<StoredItem> Rewards
		{
			get
			{
				return _rewards;
			}
			set
			{
				_rewards = value;
			}
		}

		public int Value
		{
			get
			{
				return _value;
			}
			set
			{
				_value = value;
			}
		}

		public RewardPool(StoredItem[] rewards, int value)
		{
			_rewards = new List<StoredItem>(rewards);
			_value = value;
		}
	}
	[BepInPlugin("doggosuki.Huntdown", "Huntdown", "1.4.1")]
	public class Huntdown : BaseUnityPlugin
	{
		private const string _modGUID = "doggosuki.Huntdown";

		private const string _modName = "Huntdown";

		private const string _modVersion = "1.4.1";

		private readonly Harmony _harmony = new Harmony("doggosuki.Huntdown");

		public static Huntdown _instance;

		public static ManualLogSource _logger;

		public static bool _isHost = false;

		public static bool _objectsStored = false;

		public static int _framesPassedSinceInput = 0;

		public static SelectableLevel _currentLevel;

		public static EnemyVent[] _allEnemyVents;

		public static int[] _allScrapValue;

		public static NetworkObjectReference[] _allScrapNetwork;

		public static StoredEnemy[] _storedEnemies;

		public static StoredItem[] _storedItems;

		public static RewardPool[] _possibleRewardPools;

		public static Mission[] _possibleMissions;

		public static TerminalNode _terminalNode = new TerminalNode();

		public static TerminalKeyword _terminalKeyword = new TerminalKeyword();

		public static Mission _currentMission;

		public static EnemyAI _lastEnemyKilled;

		private Dictionary<EnemyKey, int> CreateEnemyDictionary(params (EnemyKey key, int value)[] keyValuePairs)
		{
			Dictionary<EnemyKey, int> dictionary = new Dictionary<EnemyKey, int>();
			for (int i = 0; i < keyValuePairs.Length; i++)
			{
				(EnemyKey, int) tuple = keyValuePairs[i];
				dictionary.Add(tuple.Item1, tuple.Item2);
			}
			return dictionary;
		}

		private RewardPool CreateRewardPool(StoredItem[] items, ConfigSettings.ConfigIndexes index)
		{
			int num = (int)ConfigSettings.ConfigEntries[(int)index].BoxedValue;
			_logger.LogInfo((object)$"Creating reward pool. Index: {index}, Value: {num}");
			return new RewardPool(items, (int)ConfigSettings.ConfigEntries[(int)index].BoxedValue);
		}

		private Mission CreateMission(string name, ConfigSettings.ConfigIndexes weightIndex, Dictionary<EnemyKey, int> enemies, ConfigSettings.ConfigIndexes toggleIndex, RewardPool rewardPool)
		{
			int num = (int)ConfigSettings.ConfigEntries[(int)weightIndex].BoxedValue;
			bool flag = (bool)ConfigSettings.ConfigEntries[(int)toggleIndex].BoxedValue;
			_logger.LogInfo((object)$"Creating mission: {name}, Weight: {num}, Enabled: {flag}");
			return new Mission(name, num, enemies, flag, rewardPool);
		}

		private void Awake()
		{
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = this;
			}
			_logger = ((BaseUnityPlugin)this).Logger;
			try
			{
				_logger.LogInfo((object)"Binding configs.");
				ConfigSettings.BindConfigSettings();
				_logger.LogInfo((object)"Configs successfully bound.");
			}
			catch (Exception ex)
			{
				_logger.LogError((object)("Could not bind configs.\n" + ex.Message));
			}
			try
			{
				_logger.LogInfo((object)"Assigning keys to enemies.");
				_storedEnemies = new StoredEnemy[11]
				{
					new StoredEnemy(EnemyKey.SnareFlea, "Centipede (EnemyType)"),
					new StoredEnemy(EnemyKey.BunkerSpider, "SandSpider (EnemyType)"),
					new StoredEnemy(EnemyKey.HoarderBug, "HoarderBug (EnemyType)"),
					new StoredEnemy(EnemyKey.Bracken, "Flowerman (EnemyType)"),
					new StoredEnemy(EnemyKey.Thumper, "Crawler (EnemyType)"),
					new StoredEnemy(EnemyKey.Nutcracker, "Nutcracker (EnemyType)"),
					new StoredEnemy(EnemyKey.Masked, "MaskedPlayerEnemy (EnemyType)"),
					new StoredEnemy(EnemyKey.EyelessDog, "MouthDog (EnemyType)"),
					new StoredEnemy(EnemyKey.Butler, "Butler (EnemyType)"),
					new StoredEnemy(EnemyKey.Maneater, "CaveDweller (EnemyType)"),
					new StoredEnemy(EnemyKey.BaboonHawk, "BaboonHawk (EnemyType)")
				};
				_logger.LogInfo((object)"Keys successfully assigned to enemies.");
			}
			catch (Exception ex2)
			{
				_logger.LogError((object)("Could not assign keys to enemies.\n" + ex2.Message));
			}
			try
			{
				_logger.LogInfo((object)"Assigning keys to items.");
				_storedItems = new StoredItem[78]
				{
					new StoredItem(ItemKey.Binoculars, "Binoculars (Item)"),
					new StoredItem(ItemKey.Boombox, "Boombox (Item)"),
					new StoredItem(ItemKey.CardboardBox, "CardboardBox (Item)"),
					new StoredItem(ItemKey.Flashlight, "Flashlight (Item)"),
					new StoredItem(ItemKey.Jetpack, "Jetpack (Item)"),
					new StoredItem(ItemKey.Key, "Key (Item)"),
					new StoredItem(ItemKey.LockPicker, "LockPicker (Item)"),
					new StoredItem(ItemKey.LungApparatus, "LungApparatus (Item)"),
					new StoredItem(ItemKey.MapDevice, "MapDevice (Item)"),
					new StoredItem(ItemKey.ProFlashlight, "ProFlashlight (Item)"),
					new StoredItem(ItemKey.Shovel, "Shovel (Item)"),
					new StoredItem(ItemKey.StunGrenade, "StunGrenade (Item)"),
					new StoredItem(ItemKey.ExtensionLadder, "ExtensionLadder (Item)"),
					new StoredItem(ItemKey.TZPInhalant, "TZPInhalant (Item)"),
					new StoredItem(ItemKey.WalkieTalkie, "WalkieTalkie (Item)"),
					new StoredItem(ItemKey.ZapGun, "ZapGun (Item)"),
					new StoredItem(ItemKey._7Ball, "7Ball (Item)"),
					new StoredItem(ItemKey.Airhorn, "Airhorn (Item)"),
					new StoredItem(ItemKey.Bell, "Bell (Item)"),
					new StoredItem(ItemKey.BigBolt, "BigBolt (Item)"),
					new StoredItem(ItemKey.BottleBin, "BottleBin (Item)"),
					new StoredItem(ItemKey.Brush, "Brush (Item)"),
					new StoredItem(ItemKey.Candy, "Candy (Item)"),
					new StoredItem(ItemKey.CashRegister, "CashRegister (Item)"),
					new StoredItem(ItemKey.ChemicalJug, "ChemicalJug (Item)"),
					new StoredItem(ItemKey.ClownHorn, "ClownHorn (Item)"),
					new StoredItem(ItemKey.Cog1, "Cog1 (Item)"),
					new StoredItem(ItemKey.Dentures, "Dentures (Item)"),
					new StoredItem(ItemKey.DustPan, "DustPan (Item)"),
					new StoredItem(ItemKey.EggBeater, "EggBeater (Item)"),
					new StoredItem(ItemKey.EnginePart1, "EnginePart1 (Item)"),
					new StoredItem(ItemKey.FancyCup, "FancyCup (Item)"),
					new StoredItem(ItemKey.FancyLamp, "FancyLamp (Item)"),
					new StoredItem(ItemKey.FancyPainting, "FancyPainting (Item)"),
					new StoredItem(ItemKey.FishTestProp, "FishTestProp (Item)"),
					new StoredItem(ItemKey.FlashLaserPointer, "FlashLaserPointer (Item)"),
					new StoredItem(ItemKey.GoldBar, "GoldBar (Item)"),
					new StoredItem(ItemKey.Hairdryer, "Hairdryer (Item)"),
					new StoredItem(ItemKey.MagnifyingGlass, "MagnifyingGlass (Item)"),
					new StoredItem(ItemKey.MetalSheet, "MetalSheet (Item)"),
					new StoredItem(ItemKey.MoldPan, "MoldPan (Item)"),
					new StoredItem(ItemKey.Mug, "Mug (Item)"),
					new StoredItem(ItemKey.PerfumeBottle, "PerfumeBottle (Item)"),
					new StoredItem(ItemKey.Phone, "Phone (Item)"),
					new StoredItem(ItemKey.PickleJar, "PickleJar (Item)"),
					new StoredItem(ItemKey.PillBottle, "PillBottle (Item)"),
					new StoredItem(ItemKey.Remote, "Remote (Item)"),
					new StoredItem(ItemKey.Ring, "Ring (Item)"),
					new StoredItem(ItemKey.RobotToy, "RobotToy (Item)"),
					new StoredItem(ItemKey.RubberDuck, "RubberDuck (Item)"),
					new StoredItem(ItemKey.SodaCanRed, "SodaCanRed (Item)"),
					new StoredItem(ItemKey.SteeringWheel, "SteeringWheel (Item)"),
					new StoredItem(ItemKey.StopSign, "StopSign (Item)"),
					new StoredItem(ItemKey.TeaKettle, "TeaKettle (Item)"),
					new StoredItem(ItemKey.Toothpaste, "Toothpaste (Item)"),
					new StoredItem(ItemKey.ToyCube, "ToyCube (Item)"),
					new StoredItem(ItemKey.RedLocustHive, "RedLocustHive (Item)"),
					new StoredItem(ItemKey.RadarBooster, "RadarBooster (Item)"),
					new StoredItem(ItemKey.YieldSign, "YieldSign (Item)"),
					new StoredItem(ItemKey.Shotgun, "Shotgun (Item)"),
					new StoredItem(ItemKey.GunAmmo, "GunAmmo (Item)"),
					new StoredItem(ItemKey.SprayPaint, "SprayPaint (Item)"),
					new StoredItem(ItemKey.DiyFlashbang, "DiyFlashbang (Item)"),
					new StoredItem(ItemKey.GiftBox, "GiftBox (Item)"),
					new StoredItem(ItemKey.Flask, "Flask (Item)"),
					new StoredItem(ItemKey.TragedyMask, "TragedyMask (Item)"),
					new StoredItem(ItemKey.ComedyMask, "ComedyMask (Item)"),
					new StoredItem(ItemKey.WhoopieCushion, "WhoopieCushion (Item)"),
					new StoredItem(ItemKey.EasterEgg, "EasterEgg (Item)"),
					new StoredItem(ItemKey.GarbageLid, "GarbageLid (Item)"),
					new StoredItem(ItemKey.ToiletPaperRolls, "ToiletPaperRolls (Item)"),
					new StoredItem(ItemKey.Zeddog, "Zeddog (Item)"),
					new StoredItem(ItemKey.WeedKillerBottle, "WeedKillerBottle (Item)"),
					new StoredItem(ItemKey.ToyTrain, "ToyTrain (Item)"),
					new StoredItem(ItemKey.SoccerBall, "SoccerBall (Item)"),
					new StoredItem(ItemKey.Knife, "Knife (Item)"),
					new StoredItem(ItemKey.ControlPad, "ControlPad (Item)"),
					new StoredItem(ItemKey.PlasticCup, "PlasticCup (Item)")
				};
				_logger.LogInfo((object)"Keys successfully assigned to items.");
			}
			catch (Exception ex3)
			{
				_logger.LogError((object)("Could not assign keys to items.\n" + ex3.Message));
			}
			try
			{
				_logger.LogInfo((object)"Creating reward pools for missions.");
				_possibleRewardPools = new RewardPool[5]
				{
					CreateRewardPool(new StoredItem[10]
					{
						_storedItems[49],
						_storedItems[55],
						_storedItems[22],
						_storedItems[67],
						_storedItems[34],
						_storedItems[61],
						_storedItems[13],
						_storedItems[11],
						_storedItems[68],
						_storedItems[72]
					}, ConfigSettings.ConfigIndexes.RewardLow),
					CreateRewardPool(new StoredItem[8]
					{
						_storedItems[44],
						_storedItems[43],
						_storedItems[46],
						_storedItems[37],
						_storedItems[48],
						_storedItems[38],
						_storedItems[27],
						_storedItems[69]
					}, ConfigSettings.ConfigIndexes.RewardMedium),
					CreateRewardPool(new StoredItem[12]
					{
						_storedItems[47],
						_storedItems[33],
						_storedItems[42],
						_storedItems[31],
						_storedItems[32],
						_storedItems[4],
						_storedItems[15],
						_storedItems[75],
						_storedItems[73],
						_storedItems[74],
						_storedItems[76],
						_storedItems[70]
					}, ConfigSettings.ConfigIndexes.RewardHigh),
					CreateRewardPool(new StoredItem[5]
					{
						_storedItems[36],
						_storedItems[23],
						_storedItems[8],
						_storedItems[71],
						_storedItems[77]
					}, ConfigSettings.ConfigIndexes.RewardExtreme),
					CreateRewardPool(new StoredItem[2]
					{
						_storedItems[65],
						_storedItems[66]
					}, ConfigSettings.ConfigIndexes.RewardMedium)
				};
				_logger.LogInfo((object)"Reward pools successfully created.");
			}
			catch (Exception ex4)
			{
				_logger.LogError((object)("Could not create reward pools.\n" + ex4.Message));
			}
			try
			{
				_logger.LogInfo((object)"Creating missions with information from player configuration.");
				_possibleMissions = new Mission[15]
				{
					CreateMission("Snare Flea", ConfigSettings.ConfigIndexes.WeightFlea, CreateEnemyDictionary((EnemyKey.SnareFlea, 1)), ConfigSettings.ConfigIndexes.ToggleFlea, _possibleRewardPools[0]),
					CreateMission("Bunker Spider", ConfigSettings.ConfigIndexes.WeightSpider, CreateEnemyDictionary((EnemyKey.BunkerSpider, 1)), ConfigSettings.ConfigIndexes.ToggleSpider, _possibleRewardPools[1]),
					CreateMission("Hoarding Bug", ConfigSettings.ConfigIndexes.WeightHoarder, CreateEnemyDictionary((EnemyKey.HoarderBug, 1)), ConfigSettings.ConfigIndexes.ToggleHoarder, _possibleRewardPools[0]),
					CreateMission("Bracken", ConfigSettings.ConfigIndexes.WeightBracken, CreateEnemyDictionary((EnemyKey.Bracken, 1)), ConfigSettings.ConfigIndexes.ToggleBracken, _possibleRewardPools[2]),
					CreateMission("Thumper", ConfigSettings.ConfigIndexes.WeightThumper, CreateEnemyDictionary((EnemyKey.Thumper, 1)), ConfigSettings.ConfigIndexes.ToggleThumper, _possibleRewardPools[1]),
					CreateMission("Nutcracker", ConfigSettings.ConfigIndexes.WeightNutcracker, CreateEnemyDictionary((EnemyKey.Nutcracker, 1)), ConfigSettings.ConfigIndexes.ToggleNutcracker, _possibleRewardPools[2]),
					CreateMission("Masked", ConfigSettings.ConfigIndexes.WeightMasked, CreateEnemyDictionary((EnemyKey.Masked, 1)), ConfigSettings.ConfigIndexes.ToggleMasked, _possibleRewardPools[4]),
					CreateMission("A Good Boy", ConfigSettings.ConfigIndexes.WeightDog, CreateEnemyDictionary((EnemyKey.EyelessDog, 1)), ConfigSettings.ConfigIndexes.ToggleDog, _possibleRewardPools[3]),
					CreateMission("Bug Mafia", ConfigSettings.ConfigIndexes.WeightMafia, CreateEnemyDictionary((EnemyKey.HoarderBug, 5)), ConfigSettings.ConfigIndexes.ToggleMafia, _possibleRewardPools[1]),
					CreateMission("Blunderbug", ConfigSettings.ConfigIndexes.WeightBlunderbug, CreateEnemyDictionary((EnemyKey.HoarderBug, 1)), ConfigSettings.ConfigIndexes.ToggleBlunderbug, _possibleRewardPools[1]),
					CreateMission("Infestation", ConfigSettings.ConfigIndexes.WeightInfestation, CreateEnemyDictionary((EnemyKey.HoarderBug, 2), (EnemyKey.SnareFlea, 2), (EnemyKey.BunkerSpider, 1)), ConfigSettings.ConfigIndexes.ToggleInfestation, _possibleRewardPools[2]),
					CreateMission("Last Month's Interns", ConfigSettings.ConfigIndexes.WeightLastcrew, CreateEnemyDictionary((EnemyKey.Masked, 4)), ConfigSettings.ConfigIndexes.ToggleLastcrew, _possibleRewardPools[3]),
					CreateMission("Butler", ConfigSettings.ConfigIndexes.WeightButler, CreateEnemyDictionary((EnemyKey.Butler, 1)), ConfigSettings.ConfigIndexes.ToggleButler, _possibleRewardPools[1]),
					CreateMission("Maneater", ConfigSettings.ConfigIndexes.WeightManeater, CreateEnemyDictionary((EnemyKey.Maneater, 1)), ConfigSettings.ConfigIndexes.ToggleManeater, _possibleRewardPools[3]),
					CreateMission("Baboon Gang", ConfigSettings.ConfigIndexes.WeightBaboonGang, CreateEnemyDictionary((EnemyKey.BaboonHawk, 3)), ConfigSettings.ConfigIndexes.ToggleBaboonGang, _possibleRewardPools[2])
				};
				_logger.LogInfo((object)"Missions successfully created.");
			}
			catch (Exception ex5)
			{
				_logger.LogError((object)("Could not create missions.\n" + ex5.Message));
			}
			try
			{
				_logger.LogInfo((object)"Patching mod.");
				_harmony.PatchAll(typeof(Huntdown));
				_harmony.PatchAll(typeof(StartOfRoundPatch));
				_harmony.PatchAll(typeof(RoundManagerPatch));
				_harmony.PatchAll(typeof(TerminalPatch));
				_harmony.PatchAll(typeof(MouthDogAIPatch));
				_harmony.PatchAll(typeof(HoarderBugAIPatch));
				_logger.LogInfo((object)"Patches were successful.");
			}
			catch (Exception ex6)
			{
				_logger.LogError((object)("Could not patch mod.\n" + ex6.Message));
			}
			_logger.LogInfo((object)"Huntdown mod loaded.");
		}
	}
}
namespace Huntdown.Patches
{
	[HarmonyPatch(typeof(HoarderBugAI))]
	internal class HoarderBugAIPatch
	{
		private static float _blunderbugShootTimer = 3f;

		private static float _blunderbugAngryTimer = 0f;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void WeaponiseBugs(HoarderBugAI __instance)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Expected O, but got Unknown
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			if (!Huntdown._isHost)
			{
				return;
			}
			for (int i = 0; i < Mission.AliveEnemies.Count; i++)
			{
				if (!((Object)(object)__instance == (Object)(object)Mission.AliveEnemies[i]))
				{
					continue;
				}
				if (Huntdown._currentMission.Name == "Bug Mafia")
				{
					for (int j = 0; j < StartOfRound.Instance.allItemsList.itemsList.Count; j++)
					{
						if (((object)StartOfRound.Instance.allItemsList.itemsList[j]).ToString() == Huntdown._storedItems[10].ID)
						{
							GameObject obj = Object.Instantiate<GameObject>(StartOfRound.Instance.allItemsList.itemsList[j].spawnPrefab, ((EnemyAI)__instance).serverPosition, Quaternion.identity, StartOfRound.Instance.propsContainer);
							obj.GetComponent<GrabbableObject>().fallTime = 0f;
							NetworkObject component = obj.GetComponent<NetworkObject>();
							GrabbableObject component2 = ((Component)component).gameObject.GetComponent<GrabbableObject>();
							__instance.targetItem = null;
							HoarderBugAI.HoarderBugItems.Add(new HoarderBugItem(component2, (HoarderBugItemStatus)0, __instance.nestPosition));
							__instance.heldItem = HoarderBugAI.HoarderBugItems[HoarderBugAI.HoarderBugItems.Count - 1];
							component2.parentObject = __instance.grabTarget;
							component2.hasHitGround = false;
							component2.isHeldByEnemy = true;
							component2.grabbableToEnemies = false;
							component2.grabbable = true;
							component2.GrabItemFromEnemy((EnemyAI)(object)__instance);
							component2.EnablePhysics(false);
							component.Spawn(false);
							__instance.GrabItemServerRpc(NetworkObjectReference.op_Implicit(component));
						}
					}
				}
				else
				{
					if (!(Huntdown._currentMission.Name == "Blunderbug"))
					{
						continue;
					}
					for (int k = 0; k < StartOfRound.Instance.allItemsList.itemsList.Count; k++)
					{
						if (((object)StartOfRound.Instance.allItemsList.itemsList[k]).ToString() == Huntdown._storedItems[59].ID)
						{
							GameObject obj2 = Object.Instantiate<GameObject>(StartOfRound.Instance.allItemsList.itemsList[k].spawnPrefab, ((EnemyAI)__instance).serverPosition, Quaternion.identity, RoundManager.Instance.spawnedScrapContainer);
							obj2.GetComponent<GrabbableObject>().fallTime = 0f;
							NetworkObject component3 = obj2.GetComponent<NetworkObject>();
							GrabbableObject component4 = ((Component)component3).gameObject.GetComponent<GrabbableObject>();
							__instance.targetItem = null;
							HoarderBugAI.HoarderBugItems.Add(new HoarderBugItem(component4, (HoarderBugItemStatus)0, __instance.nestPosition));
							__instance.heldItem = HoarderBugAI.HoarderBugItems[HoarderBugAI.HoarderBugItems.Count - 1];
							component4.parentObject = __instance.grabTarget;
							component4.hasHitGround = false;
							component4.isHeldByEnemy = true;
							component4.grabbableToEnemies = false;
							component4.grabbable = false;
							component4.GrabItemFromEnemy((EnemyAI)(object)__instance);
							component4.EnablePhysics(false);
							component3.Spawn(false);
							__instance.GrabItemServerRpc(NetworkObjectReference.op_Implicit(component3));
						}
					}
				}
			}
		}

		[HarmonyPatch("DropItem")]
		[HarmonyPrefix]
		public static bool ForcePreventDrop(HoarderBugAI __instance)
		{
			if (!Huntdown._isHost)
			{
				return true;
			}
			for (int i = 0; i < Mission.AliveEnemies.Count; i++)
			{
				if ((Object)(object)__instance == (Object)(object)Mission.AliveEnemies[i] && !((EnemyAI)__instance).isEnemyDead && (Huntdown._currentMission.Name == "Bug Mafia" || Huntdown._currentMission.Name == "Blunderbug"))
				{
					__instance.targetItem = null;
					return false;
				}
			}
			return true;
		}

		private static void ShootGun(ShotgunItem item, HoarderBugAI instance)
		{
			//IL_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			if (item.safetyOn)
			{
				item.safetyOn = false;
			}
			if (item.shellsLoaded == 0)
			{
				item.shellsLoaded = 2;
			}
			Vector3 position = ((Component)instance.watchingPlayer).transform.position;
			Vector3 forward = item.shotgunRayPoint.forward;
			item.ShootGunServerRpc(position, forward);
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void BlunderShoot(HoarderBugAI __instance)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			for (int i = 0; i < Mission.AliveEnemies.Count; i++)
			{
				if (!((Object)(object)__instance == (Object)(object)Mission.AliveEnemies[i]) || !(Huntdown._currentMission.Name == "Blunderbug"))
				{
					continue;
				}
				_blunderbugShootTimer += Time.deltaTime;
				if (__instance.heldItem == null)
				{
					continue;
				}
				GrabbableObject itemGrabbableObject = __instance.heldItem.itemGrabbableObject;
				if ((Object)(object)((Component)itemGrabbableObject).GetComponent<ShotgunItem>() != (Object)null && __instance.angryTimer > 0f)
				{
					_blunderbugAngryTimer += Time.deltaTime;
					if (_blunderbugAngryTimer >= 1f && _blunderbugShootTimer >= 3f)
					{
						ShootGun((ShotgunItem)itemGrabbableObject, __instance);
						_blunderbugShootTimer = 0f;
					}
				}
				else if (__instance.angryTimer <= 0f)
				{
					_blunderbugAngryTimer = 0f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void DebugMode(ref float ___sprintMeter, ref float ___sprintMultiplier)
		{
			if (!Huntdown._isHost)
			{
				return;
			}
			___sprintMeter = 1f;
			___sprintMultiplier = 3f;
			if (((ButtonControl)Keyboard.current.digit1Key).wasPressedThisFrame && Huntdown._framesPassedSinceInput >= 60)
			{
				Huntdown._framesPassedSinceInput = 0;
				Huntdown._logger.LogInfo((object)"Spawning DEBUG target.");
				RoundManagerPatch.SpawnTargetPatch(ref Huntdown._currentLevel, ref Huntdown._allEnemyVents);
			}
			else if (((ButtonControl)Keyboard.current.digit2Key).wasPressedThisFrame && Huntdown._framesPassedSinceInput >= 60)
			{
				Huntdown._framesPassedSinceInput = 0;
				Huntdown._logger.LogInfo((object)"Killing DEBUG target.");
				for (int i = 0; i < Mission.AliveEnemies.Count; i++)
				{
					Mission.AliveEnemies[i].KillEnemyClientRpc(false);
				}
			}
			Huntdown._framesPassedSinceInput++;
		}
	}
	[HarmonyPatch(typeof(Application))]
	public class ApplicationPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		public static void ForceIsEditor(ref bool __result)
		{
			__result = true;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		public static void IsPlayerHost(StartOfRound __instance)
		{
			Huntdown._isHost = ((NetworkBehaviour)__instance).IsServer || ((NetworkBehaviour)__instance).IsHost;
		}

		[HarmonyPatch("ShipLeave")]
		[HarmonyPrefix]
		public static void ShipLeavePatch(StartOfRound __instance)
		{
			if (Huntdown._isHost && Huntdown._currentMission != null)
			{
				HUDManager.Instance.AddTextToChatOnServer("<color=red>MISSION FAILED. TARGET WAS: </color><color=white>" + Huntdown._currentMission.Name + "</color>", -1);
				Huntdown._currentMission.End();
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StoreItems()
		{
			if (!Huntdown._isHost)
			{
				return;
			}
			for (int i = 0; i < StartOfRound.Instance.allItemsList.itemsList.Count; i++)
			{
				for (int j = 0; j < Huntdown._storedItems.Length; j++)
				{
					if (((object)StartOfRound.Instance.allItemsList.itemsList[i]).ToString() == Huntdown._storedItems[j].ID)
					{
						Huntdown._storedItems[j].GameItem = StartOfRound.Instance.allItemsList.itemsList[i];
						Huntdown._storedItems[j].Name = StartOfRound.Instance.allItemsList.itemsList[i].itemName;
						break;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(MouthDogAI))]
	internal class MouthDogAIPatch
	{
		public static void EnterLunge(MouthDogAI __instance, Ray ray, RaycastHit rayHit, RoundManager roundManager)
		{
			//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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)__instance).SwitchToBehaviourState(3);
			__instance.endingLunge = false;
			((Ray)(ref ray))..ctor(((Component)__instance).transform.position + Vector3.up, ((Component)__instance).transform.forward);
			Vector3 val = ((!Physics.Raycast(ray, ref rayHit, 17f, StartOfRound.Instance.collidersAndRoomMask)) ? ((Ray)(ref ray)).GetPoint(17f) : ((RaycastHit)(ref rayHit)).point);
			val = roundManager.GetNavMeshPosition(val, default(NavMeshHit), 5f, -1);
			((EnemyAI)__instance).SetDestinationToPosition(val, false);
			((EnemyAI)__instance).agent.speed = 13f;
		}

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		public static bool FixIndoorDogBehaviourForClients(MouthDogAI __instance, ref Collider other, bool ___inKillAnimation, ref Collider ___debugCollider, ref bool ___inLunge, Ray ___ray, RaycastHit ___rayHit, RoundManager ___roundManager)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: 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_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			if (!((EnemyAI)__instance).enemyType.isOutsideEnemy && Huntdown._isHost)
			{
				if (!((EnemyAI)__instance).isEnemyDead && !___inKillAnimation && !(((EnemyAI)__instance).stunNormalizedTimer >= 0f))
				{
					PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
					if (!((Object)(object)component != (Object)null))
					{
						Huntdown._logger.LogError((object)"Player returned null");
						return false;
					}
					Vector3 val = Vector3.Normalize((((Component)__instance).transform.position + Vector3.up - ((Component)component.gameplayCamera).transform.position) * 100f);
					RaycastHit val2 = default(RaycastHit);
					if (Physics.Linecast(((Component)__instance).transform.position + Vector3.up + val * 0.5f, ((Component)component.gameplayCamera).transform.position, ref val2, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1))
					{
						if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)(object)___debugCollider))
						{
							Debug.Log((object)("Eyeless dog collide, linecast obstructed: " + ((Object)((Component)((RaycastHit)(ref val2)).collider).gameObject).name));
							___debugCollider = ((RaycastHit)(ref val2)).collider;
							return false;
						}
						return false;
					}
					if (((EnemyAI)__instance).currentBehaviourStateIndex == 3)
					{
						component.inAnimationWithEnemy = (EnemyAI)(object)__instance;
						__instance.KillPlayerServerRpc((int)component.playerClientId);
						return false;
					}
					if (((EnemyAI)__instance).currentBehaviourStateIndex == 0 || ((EnemyAI)__instance).currentBehaviourStateIndex == 1)
					{
						((EnemyAI)__instance).SwitchToBehaviourState(2);
						((EnemyAI)__instance).ChangeOwnershipOfEnemy(NetworkManager.Singleton.LocalClientId);
						((EnemyAI)__instance).SetDestinationToPosition(((Component)component).transform.position, false);
						return false;
					}
					if (((EnemyAI)__instance).currentBehaviourStateIndex == 2 && !___inLunge)
					{
						((Component)__instance).transform.LookAt(((Component)other).transform.position);
						((Component)__instance).transform.localEulerAngles = new Vector3(0f, ((Component)__instance).transform.eulerAngles.y, 0f);
						___inLunge = true;
						EnterLunge(__instance, ___ray, ___rayHit, ___roundManager);
						return false;
					}
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		public static int CalculateTotalWeight()
		{
			Huntdown._logger.LogInfo((object)"Calculating total weight of all missions...");
			int num = 0;
			for (int i = 0; i < Huntdown._possibleMissions.Length; i++)
			{
				if (Huntdown._possibleMissions[i].Enabled)
				{
					Huntdown._logger.LogInfo((object)("Adding " + Huntdown._possibleMissions[i].Name + "'s weight of " + Huntdown._possibleMissions[i].Weight + " to total weight."));
					num += Huntdown._possibleMissions[i].Weight;
				}
				else
				{
					Huntdown._logger.LogInfo((object)(Huntdown._possibleMissions[i].Name + " is a disabled mission, not adding weight."));
				}
				Huntdown._logger.LogInfo((object)("New total weight: " + num + "."));
			}
			Huntdown._logger.LogInfo((object)("Final total weight: " + num + "."));
			return num;
		}

		public static bool ChooseRandomMission(int weightTotal)
		{
			Huntdown._logger.LogInfo((object)"Choosing random mission...");
			int num = new Random().Next(0, weightTotal);
			bool flag = false;
			for (int i = 0; i < Huntdown._possibleMissions.Length; i++)
			{
				if (!Huntdown._possibleMissions[i].Enabled)
				{
					continue;
				}
				Huntdown._logger.LogInfo((object)("Rolling for the mission " + Huntdown._possibleMissions[i].Name + "."));
				Huntdown._logger.LogInfo((object)("Rolled " + (num - Huntdown._possibleMissions[i].Weight)));
				if ((num -= Huntdown._possibleMissions[i].Weight) < 0 && !flag)
				{
					flag = true;
					Huntdown._currentMission = Huntdown._possibleMissions[i];
					if ((bool)ConfigSettings.ConfigEntries[2].BoxedValue)
					{
						Huntdown._possibleMissions[i].Weight = Huntdown._possibleMissions[i].BaseWeight;
					}
					Huntdown._logger.LogInfo((object)("Mission chosen: " + Huntdown._currentMission.Name + "."));
				}
				else if ((bool)ConfigSettings.ConfigEntries[2].BoxedValue)
				{
					Huntdown._possibleMissions[i].Weight += Huntdown._possibleMissions[i].BaseWeight;
				}
			}
			return flag;
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		public static void SetIsHost()
		{
			Huntdown._isHost = ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost;
			Huntdown._logger.LogInfo((object)("Is the player the host: " + Huntdown._isHost + "."));
			if (Huntdown._currentMission != null)
			{
				Huntdown._currentMission.End();
			}
		}

		[HarmonyPatch("BeginEnemySpawning")]
		[HarmonyPostfix]
		public static void SpawnTargetPatch(ref SelectableLevel ___currentLevel, ref EnemyVent[] ___allEnemyVents)
		{
			if (!Huntdown._isHost || !Mission.RollMissionChance())
			{
				Huntdown._currentMission = null;
				return;
			}
			Mission.TotalWeight = CalculateTotalWeight();
			if (!ChooseRandomMission(Mission.TotalWeight))
			{
				Huntdown._logger.LogError((object)"Error: Somehow no mission was selected, do you have all your missions disabled?.");
				return;
			}
			try
			{
				Huntdown._logger.LogInfo((object)("Attempting to generate mission '" + Huntdown._currentMission.Name + "'."));
				Huntdown._currentMission.Start(ref ___currentLevel, ___allEnemyVents);
				Huntdown._logger.LogInfo((object)("Mission '" + Huntdown._currentMission.Name + "' generated successfully."));
			}
			catch (Exception ex)
			{
				Huntdown._logger.LogError((object)("There was an error when trying to generate the mission.\n" + ex.Message));
			}
			if ((int)ConfigSettings.ConfigEntries[0].BoxedValue == 0)
			{
				HUDManager.Instance.AddTextToChatOnServer("<color=purple>TARGET: </color><color=white>" + Huntdown._currentMission.Name + "</color>", -1);
			}
			else if ((int)ConfigSettings.ConfigEntries[0].BoxedValue == 1)
			{
				HUDManager.Instance.AddTextToChatOnServer("<color=purple>TARGET: </color><color=white>???</color>", -1);
			}
			if ((int)ConfigSettings.ConfigEntries[0].BoxedValue == 0)
			{
				Huntdown._terminalNode.displayText = "Your team's mission: " + Huntdown._currentMission.Name;
			}
			else
			{
				Huntdown._terminalNode.displayText = "You have the 'display target' setting off in your configuration, so your mission cannot be displayed using this command.";
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void CheckEnemyDead()
		{
			//IL_01a5: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: 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)
			if (Huntdown._currentMission == null || !Huntdown._isHost)
			{
				return;
			}
			for (int i = 0; i < Mission.AliveEnemies.Count; i++)
			{
				if (Mission.AliveEnemies[i].isEnemyDead)
				{
					try
					{
						Huntdown._lastEnemyKilled = Mission.AliveEnemies[i];
						Mission.AliveEnemies.RemoveAt(i);
						HUDManager.Instance.AddTextToChatOnServer("(" + (Mission._maxEnemies - Mission.AliveEnemies.Count) + "/" + Mission._maxEnemies + ") <color=purple>TARGETS TERMINATED</color>", -1);
						Huntdown._logger.LogInfo((object)("The mission enemy '" + ((Object)Huntdown._lastEnemyKilled).name + "' was killed."));
					}
					catch (Exception ex)
					{
						Huntdown._logger.LogError((object)("A mission enemy was killed, but there was an error.\n" + ex.Message));
					}
					break;
				}
			}
			if (Mission.AliveEnemies.Count != 0)
			{
				return;
			}
			Huntdown._logger.LogInfo((object)("Mission '" + Huntdown._currentMission.Name + "'has been completed!"));
			if ((int)ConfigSettings.ConfigEntries[0].BoxedValue == 0)
			{
				Huntdown._terminalNode.displayText = "Your team currently has no mission.";
			}
			else
			{
				Huntdown._terminalNode.displayText = "You have the 'display target' setting off in your configuration, so your mission cannot be displayed using this command.";
			}
			Random random = new Random();
			int index = random.Next(0, Huntdown._currentMission.RewardPool.Rewards.Count);
			StoredItem storedItem = Huntdown._currentMission.RewardPool.Rewards[index];
			GameObject val = Object.Instantiate<GameObject>(storedItem.GameItem.spawnPrefab, Huntdown._lastEnemyKilled.serverPosition, Quaternion.identity, RoundManager.Instance.spawnedScrapContainer);
			GrabbableObject component = val.GetComponent<GrabbableObject>();
			((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
			component.fallTime = 0f;
			new Random();
			int num = random.Next(0, 11) - 5;
			if (storedItem.GameItem.isScrap)
			{
				if (Huntdown._currentMission.RewardPool.Value + num > 0)
				{
					component.SetScrapValue(Huntdown._currentMission.RewardPool.Value + num);
				}
				else
				{
					component.SetScrapValue(Huntdown._currentMission.RewardPool.Value);
				}
			}
			try
			{
				NetworkObject component2 = val.GetComponent<NetworkObject>();
				component2.Spawn(false);
				HUDManager.Instance.AddTextToChatOnServer("<color=purple>MISSION COMPLETED</color>\n<color=green>REWARD: </color><color=white>" + storedItem.Name + "</color>", -1);
				if (storedItem.GameItem.isScrap)
				{
					int resultBefore = 0;
					Array.ForEach(Huntdown._allScrapValue, delegate(int value)
					{
						resultBefore += value;
					});
					Huntdown._logger.LogInfo((object)("Value of total scrap before correction: " + resultBefore));
					Huntdown._logger.LogInfo((object)("Length of AllScrapNetwork array: " + Huntdown._allScrapNetwork.Length));
					NetworkObjectReference[] array = (NetworkObjectReference[])(object)new NetworkObjectReference[Huntdown._allScrapNetwork.Length + 1];
					Huntdown._logger.LogInfo((object)("Length of correctedScrapNetworkArray array: " + array.Length));
					Huntdown._allScrapNetwork.CopyTo(array, 0);
					array[Huntdown._allScrapNetwork.Length] = NetworkObjectReference.op_Implicit(component2);
					int[] array2 = new int[Huntdown._allScrapValue.Length + 1];
					Huntdown._allScrapValue.CopyTo(array2, 0);
					array2[Huntdown._allScrapValue.Length] = component.scrapValue;
					Huntdown._logger.LogInfo((object)"Attempting to sync server and client scrap values.");
					RoundManager.Instance.SyncScrapValuesClientRpc(array, array2);
					int resultAfter = 0;
					Array.ForEach(array2, delegate(int value)
					{
						resultAfter += value;
					});
					Huntdown._logger.LogInfo((object)("Value of total scrap after correction: " + resultAfter));
				}
			}
			catch (Exception ex2)
			{
				Huntdown._logger.LogError((object)("Calculation of new total scrap in level failed.\n" + ex2.Message));
			}
			Huntdown._currentMission.End();
		}

		[HarmonyPatch("waitForScrapToSpawnToSync")]
		[HarmonyPrefix]
		public static void StoreGeneratedScrap(ref NetworkObjectReference[] spawnedScrap, ref int[] scrapValues)
		{
			if (Huntdown._isHost)
			{
				Huntdown._logger.LogInfo((object)"Storing values for scrap generated on new level.");
				Huntdown._allScrapNetwork = spawnedScrap;
				Huntdown._allScrapValue = scrapValues;
			}
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StoreObjects(ref Terminal __instance, ref SelectableLevel[] ___moonsCatalogueList)
		{
			if (!Huntdown._objectsStored)
			{
				Huntdown._logger.LogInfo((object)"Attempting to store enemies and items for later use.");
				try
				{
					List<SpawnableEnemyWithRarity> list = new List<SpawnableEnemyWithRarity>();
					SelectableLevel[] array = ___moonsCatalogueList;
					foreach (SelectableLevel val in array)
					{
						list.AddRange(val.Enemies);
						list.AddRange(val.OutsideEnemies);
						foreach (SpawnableEnemyWithRarity enemy in list)
						{
							if (!Huntdown._storedEnemies.Any((StoredEnemy b) => b.ID == ((object)enemy.enemyType).ToString()))
							{
								continue;
							}
							for (int j = 0; j < Huntdown._storedEnemies.Length; j++)
							{
								if (Huntdown._storedEnemies[j].ID == ((object)enemy.enemyType).ToString() && Huntdown._storedEnemies[j].SpawnableEnemy == null)
								{
									Huntdown._storedEnemies[j].SpawnableEnemy = enemy;
									Huntdown._storedEnemies[j].Name = enemy.enemyType.enemyName;
									Huntdown._logger.LogInfo((object)("Stored: " + Huntdown._storedEnemies[j].Name + "."));
								}
							}
						}
					}
				}
				catch (Exception ex)
				{
					Huntdown._logger.LogError((object)ex.Message);
				}
				Huntdown._objectsStored = true;
				Huntdown._logger.LogInfo((object)"Finished storing enemies and items.");
			}
			try
			{
				Huntdown._terminalNode.displayText = "Command not available - you must be the host and start the round to use this command.";
				Huntdown._terminalNode.clearPreviousText = true;
				Huntdown._terminalKeyword.word = "target";
				Huntdown._terminalKeyword.specialKeywordResult = Huntdown._terminalNode;
				TerminalKeyword[] array2 = (TerminalKeyword[])(object)new TerminalKeyword[__instance.terminalNodes.allKeywords.Length + 1];
				__instance.terminalNodes.allKeywords.CopyTo(array2, 0);
				array2[__instance.terminalNodes.allKeywords.Length] = Huntdown._terminalKeyword;
				__instance.terminalNodes.allKeywords = array2;
			}
			catch (Exception ex2)
			{
				Huntdown._logger.LogError((object)("Couldn't create terminal 'target' command.\n" + ex2.Message));
			}
		}
	}
}