Decompiled source of YesFox v1.1.2

BepInEx/plugins/YesFox/uk.1a3.yesfox.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using YesFox.Compatibility;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("uk.1a3.yesfox")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+405a88b6013ab6a5dd6ac33f74cc44eec478c5f7")]
[assembly: AssemblyProduct("YesFox")]
[assembly: AssemblyTitle("uk.1a3.yesfox")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 YesFox
{
	[BepInPlugin("uk.1a3.yesfox", "YesFox", "1.1.2")]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("uk.1a3.yesfox");

		internal static ManualLogSource logSource;

		internal static List<GameObject> _networkPrefabs = new List<GameObject>();

		internal static ConfigEntry<bool> Shroud_AllMoons;

		internal static ConfigEntry<float> Shroud_SpawnChance_SameMoon;

		internal static ConfigEntry<float> Shroud_SpawnChance_OtherMoons;

		internal static ConfigEntry<float> Shroud_GrowChance_SameMoon;

		internal static ConfigEntry<float> Shroud_GrowChance_OtherMoons;

		internal static ConfigEntry<int> Shroud_MaximumIterations;

		internal static ConfigEntry<float> Shroud_MinimumDistance;

		internal static ConfigEntry<int> Fox_MinimumWeeds;

		internal static ConfigEntry<int> Fox_SpawnChance;

		public static GameObject BushWolfAddonPrefab { get; internal set; }

		private void Awake()
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected O, but got Unknown
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Expected O, but got Unknown
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Expected O, but got Unknown
			logSource = ((BaseUnityPlugin)this).Logger;
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			harmony.PatchAll(executingAssembly);
			logSource.LogInfo((object)"Patches Loaded");
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "bush_wolf"));
			if ((Object)(object)val == (Object)null)
			{
				logSource.LogError((object)"[AssetBundle] Failed to load asset bundle: bush_wolf");
				return;
			}
			BushWolfAddonPrefab = val.LoadAsset<GameObject>("Assets/LethalCompany/Game/Prefabs/EnemyAI/BushWolfEnemy.prefab");
			if ((Object)(object)BushWolfAddonPrefab != (Object)null)
			{
				if (!_networkPrefabs.Contains(BushWolfAddonPrefab))
				{
					_networkPrefabs.Add(BushWolfAddonPrefab);
				}
				logSource.LogInfo((object)"[AssetBundle] Successfully loaded prefab: BushWolfEnemy");
			}
			else
			{
				logSource.LogError((object)"[AssetBundle] Failed to load prefab: BushWolfEnemy");
			}
			Shroud_AllMoons = ((BaseUnityPlugin)this).Config.Bind<bool>("Weed Spawning", "All Moons", false, "Should weeds be able to spawn on all moons excluding gordion?");
			Shroud_SpawnChance_SameMoon = ((BaseUnityPlugin)this).Config.Bind<float>("Weed Spawning", "Spawn Chance (Current Moon)", 8.5f, new ConfigDescription("What should the chance for them to initially spawn the moon you are routed to be? Weeds attempt to spawn on all moons when you go into orbit after each day.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			Shroud_SpawnChance_OtherMoons = ((BaseUnityPlugin)this).Config.Bind<float>("Weed Spawning", "Spawn Chance (Other Moons)", 4f, new ConfigDescription("What should the chance for them to initially spawn on other moons be? Weeds attempt to spawn on all moons when you go into orbit after each day.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			Shroud_GrowChance_SameMoon = ((BaseUnityPlugin)this).Config.Bind<float>("Weed Spawning", "Growth Chance (Current Moon)", 100f, new ConfigDescription("What is the chance that weeds should grow another \"step\" after leaving a moon? This applies at the end of the day, only once the spawn chance has succeeded for the first time.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			Shroud_GrowChance_OtherMoons = ((BaseUnityPlugin)this).Config.Bind<float>("Weed Spawning", "Growth Chance (Other Moons)", 100f, new ConfigDescription("What is the chance that weeds should grow another \"step\" for all other moons? This applies at the end of the day, only once the spawn chance has succeeded for the first time.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			Shroud_MaximumIterations = ((BaseUnityPlugin)this).Config.Bind<int>("Weed Spawning", "Maximum Iterations", 20, new ConfigDescription("How many days in a row are additional weeds allowed to grow on the same moon?", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			Shroud_MinimumDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Weed Spawning", "Minimum Distance", 40f, new ConfigDescription("How many units away from the ship must the starting points for weed growth be?", (AcceptableValueBase)(object)new AcceptableValueRange<float>(30f, 70f), Array.Empty<object>()));
			Fox_MinimumWeeds = ((BaseUnityPlugin)this).Config.Bind<int>("Fox Spawning", "Minimum Weeds", 31, "The minimum amount of weeds required to spawn");
			Fox_SpawnChance = ((BaseUnityPlugin)this).Config.Bind<int>("Fox Spawning", "Spawn Chance", -1, new ConfigDescription("What should the spawn chance be? If left as -1 then it will be the same as vanilla (a higher chance the more weeds there are)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1, 100), Array.Empty<object>()));
		}
	}
	[HarmonyPatch]
	internal static class HarmonyPatches
	{
		private static MoldSpreadManager _moldSpreadManager;

		public static Random WeedEnemySpawnRandom;

		public static List<SpawnableEnemyWithRarity> WeedEnemies = new List<SpawnableEnemyWithRarity>();

		private static GameObject _moldAttractionPoint;

		private static VehicleController vehicleController;

		private static readonly MethodInfo MOLD_SPREAD_MANAGER_INSTANCE = AccessTools.DeclaredPropertyGetter(typeof(HarmonyPatches), "MoldSpreadManager");

		private static readonly MethodInfo MOLD_ATTRACTION_POINT = AccessTools.DeclaredPropertyGetter(typeof(HarmonyPatches), "MoldAttractionPoint");

		private static readonly MethodInfo FIND_MOLD_SPORES = AccessTools.Method(typeof(HarmonyPatches), "FindMoldSpores", (Type[])null, (Type[])null);

		private static readonly MethodInfo FIND_GAME_OBJECT_WITH_TAG = AccessTools.Method(typeof(GameObject), "FindGameObjectWithTag", (Type[])null, (Type[])null);

		private static readonly MethodInfo FIND_GAME_OBJECTS_WITH_TAG = AccessTools.Method(typeof(GameObject), "FindGameObjectsWithTag", (Type[])null, (Type[])null);

		private static MoldSpreadManager MoldSpreadManager
		{
			get
			{
				if ((Object)(object)_moldSpreadManager == (Object)null)
				{
					_moldSpreadManager = Object.FindAnyObjectByType<MoldSpreadManager>();
				}
				return _moldSpreadManager;
			}
		}

		private static GameObject MoldAttractionPoint
		{
			get
			{
				if ((Object)(object)_moldAttractionPoint == (Object)null)
				{
					_moldAttractionPoint = GameObject.FindGameObjectWithTag("MoldAttractionPoint");
				}
				return _moldAttractionPoint;
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		[HarmonyPostfix]
		private static void GameNetworkManager_Start(GameNetworkManager __instance)
		{
			if (__instance.gameVersionNum >= 64)
			{
				foreach (GameObject networkPrefab in Plugin._networkPrefabs)
				{
					if (!NetworkManager.Singleton.NetworkConfig.Prefabs.Contains(networkPrefab))
					{
						NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
					}
				}
			}
			else
			{
				foreach (GameObject networkPrefab2 in Plugin._networkPrefabs)
				{
					if (NetworkManager.Singleton.NetworkConfig.Prefabs.Contains(networkPrefab2))
					{
						NetworkManager.Singleton.RemoveNetworkPrefab(networkPrefab2);
					}
				}
			}
			if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
			{
				LobbyCompatibility.Init(__instance.gameVersionNum);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "SetPlanetsMold")]
		[HarmonyPrefix]
		public static bool SetPlanetsMold(StartOfRound __instance)
		{
			if (!((NetworkBehaviour)__instance).IsOwner)
			{
				return false;
			}
			Random random = new Random(__instance.randomMapSeed + 32);
			Terminal val = Object.FindAnyObjectByType<Terminal>();
			for (int i = 0; i < __instance.levels.Length; i++)
			{
				if (i == 3 || (!__instance.levels[i].canSpawnMold && !Plugin.Shroud_AllMoons.Value))
				{
					Plugin.logSource.LogInfo((object)$"Skipping level #{i} {__instance.levels[i].PlanetName} mold iterations");
					continue;
				}
				if (__instance.levels[i].moldSpreadIterations > 0)
				{
					if (__instance.levels[i].moldSpreadIterations < Plugin.Shroud_MaximumIterations.Value)
					{
						float num = (((Object)(object)__instance.levels[i] == (Object)(object)__instance.currentLevel) ? Plugin.Shroud_GrowChance_SameMoon.Value : Plugin.Shroud_GrowChance_OtherMoons.Value) / 100f;
						if (random.NextDouble() <= (double)num)
						{
							SelectableLevel obj = __instance.levels[i];
							obj.moldSpreadIterations++;
							Plugin.logSource.LogInfo((object)$"Increasing level #{i} {__instance.levels[i].PlanetName} mold iterations by 1; risen to {__instance.levels[i].moldSpreadIterations}");
						}
					}
					continue;
				}
				float num2;
				if ((Object)(object)__instance.levels[i] == (Object)(object)__instance.currentLevel)
				{
					num2 = Plugin.Shroud_SpawnChance_SameMoon.Value / 100f;
				}
				else
				{
					num2 = Plugin.Shroud_SpawnChance_OtherMoons.Value / 100f;
					if (val.groupCredits < 200 && __instance.levels[i].levelID == 12)
					{
						num2 *= 1.25f;
					}
					else if (val.groupCredits < 500 && (__instance.levels[i].levelID == 7 || __instance.levels[i].levelID == 6 || __instance.levels[i].levelID >= 10) && (__instance.currentLevel.levelID == 5 || __instance.currentLevel.levelID == 8 || __instance.currentLevel.levelID == 4 || __instance.currentLevel.levelID <= 2))
					{
						num2 *= 0.5f;
					}
				}
				if (random.NextDouble() <= (double)num2)
				{
					SelectableLevel obj2 = __instance.levels[i];
					obj2.moldSpreadIterations += random.Next(1, 3);
					Plugin.logSource.LogInfo((object)$"Increasing level #{i} {__instance.levels[i].PlanetName} mold iterations for the first time; risen to {__instance.levels[i].moldSpreadIterations}");
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(StartOfRound), "PlayerLoadedServerRpc")]
		[HarmonyPostfix]
		private static void PlayerLoadedServerRpc(StartOfRound __instance)
		{
			//IL_00a0: 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_00fd: 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_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).IsServer || __instance.currentLevel.moldSpreadIterations < 1)
			{
				return;
			}
			if (!__instance.currentLevel.canSpawnMold && !Plugin.Shroud_AllMoons.Value)
			{
				__instance.currentLevel.moldSpreadIterations = 0;
				__instance.currentLevel.moldStartPosition = -1;
				return;
			}
			if (__instance.currentLevel.moldSpreadIterations > Plugin.Shroud_MaximumIterations.Value)
			{
				__instance.currentLevel.moldSpreadIterations = Plugin.Shroud_MaximumIterations.Value;
			}
			GameObject[] array = GameObject.FindGameObjectsWithTag("OutsideAINode");
			if (array == null || array.Length < 1)
			{
				return;
			}
			Vector3 shipPos = new Vector3(1.2714634f, 0.27843857f, -7.5f);
			List<GameObject> list = new List<GameObject>();
			list.AddRange(array.OrderBy((GameObject x) => Vector3.Distance(x.transform.position, shipPos)));
			array = list.ToArray();
			if (__instance.currentLevel.moldStartPosition >= 0 && __instance.currentLevel.moldStartPosition < array.Length)
			{
				float num = Vector3.Distance(array[__instance.currentLevel.moldStartPosition].transform.position, shipPos);
				if (num >= 30f)
				{
					return;
				}
				Plugin.logSource.LogInfo((object)$"Mold growth is starting from node #{__instance.currentLevel.moldStartPosition} which is too close to the ship ({num} < 30)");
			}
			Random random = new Random(__instance.randomMapSeed + 2017);
			int moldSpreadIterations = __instance.currentLevel.moldSpreadIterations;
			RaycastHit val = default(RaycastHit);
			for (int i = 0; i < array.Length; i++)
			{
				float num2 = Vector3.Distance(array[i].transform.position, shipPos);
				if (!(num2 >= Plugin.Shroud_MinimumDistance.Value) || (random.Next(100) >= 13 && array.Length - i >= 20))
				{
					continue;
				}
				Plugin.logSource.LogDebug((object)$"Mold growth: outsideAINodes[{i}] is candidate (ship dist: {num2} > {Plugin.Shroud_MinimumDistance.Value})");
				if (Physics.Raycast(array[i].transform.position, Vector3.down, ref val, 8f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
				{
					MoldSpreadManager.GenerateMold(array[i].transform.position, Plugin.Shroud_MaximumIterations.Value);
					int count = MoldSpreadManager.generatedMold.Count;
					MoldSpreadManager.RemoveAllMold();
					if (count >= Plugin.Fox_MinimumWeeds.Value)
					{
						__instance.currentLevel.moldStartPosition = i;
						__instance.currentLevel.moldSpreadIterations = moldSpreadIterations;
						Plugin.logSource.LogInfo((object)$"Mold growth: Selected outsideAINodes[{i}]: coords {array[i].transform.position}, dist {num2}");
						return;
					}
					Plugin.logSource.LogDebug((object)$"Mold growth: outsideAINodes[{i}] rejected (max weeds: {count} < {Plugin.Fox_MinimumWeeds.Value})");
				}
				else
				{
					Plugin.logSource.LogDebug((object)$"Mold growth: outsideAINodes[{i}] rejected (no ground)");
				}
			}
			__instance.currentLevel.moldSpreadIterations = 0;
			__instance.currentLevel.moldStartPosition = -1;
			Plugin.logSource.LogInfo((object)("Level \"" + __instance.currentLevel.PlanetName + "\" has no valid AI nodes"));
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static void StartOfRound_Start()
		{
			GenerateWeedEnemiesList();
		}

		public static void GenerateWeedEnemiesList()
		{
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01d0: Expected O, but got Unknown
			WeedEnemies.Clear();
			try
			{
				EnemyType val = ((IEnumerable<SpawnableEnemyWithRarity>)Object.FindAnyObjectByType<QuickMenuManager>()?.testAllEnemiesLevel?.OutsideEnemies).FirstOrDefault((Func<SpawnableEnemyWithRarity, bool>)delegate(SpawnableEnemyWithRarity x)
				{
					if (((Object)x.enemyType).name == "BushWolf")
					{
						GameObject enemyPrefab4 = x.enemyType.enemyPrefab;
						if (enemyPrefab4 == null)
						{
							return false;
						}
						return enemyPrefab4.GetComponentsInChildren<SkinnedMeshRenderer>()?.Length > 0;
					}
					return false;
				})?.enemyType;
				EnemyType val2 = ((IEnumerable<EnemyType>)Resources.FindObjectsOfTypeAll<EnemyType>()).FirstOrDefault((Func<EnemyType, bool>)((EnemyType x) => ((Object)x).name == "BushWolf" && (Object)(object)x.enemyPrefab == (Object)(object)Plugin.BushWolfAddonPrefab));
				if (!((Object)(object)val != (Object)(object)val2))
				{
					return;
				}
				if ((Object)(object)val == (Object)null && (Object)(object)val2 != (Object)null)
				{
					val = val2;
					val2 = null;
				}
				if (!((Object)(object)val != (Object)null))
				{
					return;
				}
				if ((Object)(object)val2 != (Object)null)
				{
					if ((Object)(object)val2.enemyPrefab == (Object)(object)Plugin.BushWolfAddonPrefab)
					{
						Plugin.logSource.LogInfo((object)"[GenerateWeedEnemiesList] BushWolf: Renamed addon EnemyType name");
						((Object)val2).name = "BushWolfAddon";
					}
					GameObject enemyPrefab = val2.enemyPrefab;
					object obj;
					if (enemyPrefab == null)
					{
						obj = null;
					}
					else
					{
						GameObject gameObject = enemyPrefab.gameObject;
						obj = ((gameObject != null) ? gameObject.GetComponent<EnemyAI>() : null);
					}
					if (Object.op_Implicit((Object)obj))
					{
						val2.enemyPrefab.gameObject.GetComponent<EnemyAI>().enemyType = val;
						Plugin.logSource.LogInfo((object)"[GenerateWeedEnemiesList] BushWolf: Replaced addon EnemyAI enemyType");
					}
					if (GameNetworkManager.Instance.gameVersionNum >= 64)
					{
						GameObject enemyPrefab2 = val.enemyPrefab;
						SkinnedMeshRenderer[] array = ((enemyPrefab2 != null) ? enemyPrefab2.GetComponentsInChildren<SkinnedMeshRenderer>() : null);
						GameObject enemyPrefab3 = val2.enemyPrefab;
						SkinnedMeshRenderer[] array2 = ((enemyPrefab3 != null) ? enemyPrefab3.GetComponentsInChildren<SkinnedMeshRenderer>() : null);
						foreach (SkinnedMeshRenderer obj2 in array2)
						{
							((Renderer)obj2).material = ((Renderer)array[0]).material;
							((Renderer)obj2).materials = ((Renderer)array[0]).materials;
						}
						val.enemyPrefab = val2.enemyPrefab;
						Plugin.logSource.LogInfo((object)"[GenerateWeedEnemiesList] BushWolf: Replaced original EnemyType prefab");
					}
				}
				WeedEnemies.Add(new SpawnableEnemyWithRarity
				{
					enemyType = val,
					rarity = 100
				});
			}
			catch (Exception ex)
			{
				Plugin.logSource.LogError((object)ex);
			}
		}

		public static void SpawnWeedEnemies(int currentHour)
		{
			int num = 0;
			if ((Object)(object)MoldSpreadManager != (Object)null)
			{
				num = MoldSpreadManager.generatedMold.Count((GameObject x) => (Object)(object)x != (Object)null && x.activeSelf);
			}
			if (num < Plugin.Fox_MinimumWeeds.Value)
			{
				Plugin.logSource.LogDebug((object)$"Weed enemies attempted to spawn but were denied. Reason: WeedCount | Amount: {num}");
				return;
			}
			if (Plugin.Fox_SpawnChance.Value >= 0)
			{
				int num2 = WeedEnemySpawnRandom.Next(1, 100);
				if (num2 > Plugin.Fox_SpawnChance.Value)
				{
					Plugin.logSource.LogDebug((object)$"Weed enemies attempted to spawn but were denied. Reason: SpawnChance | Amount: {num2}");
					return;
				}
			}
			else
			{
				int num3 = WeedEnemySpawnRandom.Next(0, 80);
				if (num3 > num)
				{
					Plugin.logSource.LogDebug((object)$"Weed enemies attempted to spawn but were denied. Reason: SpawnChance | Amount: {num3}");
					return;
				}
			}
			int num4 = WeedEnemySpawnRandom.Next(1, 3);
			GameObject[] spawnPoints = GameObject.FindGameObjectsWithTag("OutsideAINode");
			float timeUpToCurrentHour = TimeOfDay.Instance.lengthOfHours * (float)currentHour;
			if (WeedEnemies.Count == 0)
			{
				GenerateWeedEnemiesList();
				if (WeedEnemies.Count == 0)
				{
					Plugin.logSource.LogError((object)"Weed enemies attempted to spawn but were denied. Reason: ListEmpty");
					return;
				}
			}
			for (int i = 0; i < num4; i++)
			{
				if (!SpawnRandomWeedEnemy(spawnPoints, timeUpToCurrentHour, num))
				{
					break;
				}
			}
		}

		public static bool SpawnRandomWeedEnemy(GameObject[] spawnPoints, float timeUpToCurrentHour, int numberOfWeeds)
		{
			//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_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: 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_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			RoundManager.Instance.SpawnProbabilities.Clear();
			int num = 0;
			for (int i = 0; i < WeedEnemies.Count; i++)
			{
				EnemyType enemyType = WeedEnemies[i].enemyType;
				if (RoundManager.Instance.firstTimeSpawningWeedEnemies)
				{
					enemyType.numberSpawned = 0;
				}
				if (enemyType.PowerLevel > RoundManager.Instance.currentMaxOutsidePower - RoundManager.Instance.currentOutsideEnemyPower || enemyType.numberSpawned >= enemyType.MaxCount || enemyType.spawningDisabled)
				{
					RoundManager.Instance.SpawnProbabilities.Add(0);
					Plugin.logSource.LogDebug((object)"A weed enemy attempted to spawn but was denied. Reason: Probability | Amount: 0");
					continue;
				}
				int num2 = ((RoundManager.Instance.increasedOutsideEnemySpawnRateIndex == i) ? 100 : ((!enemyType.useNumberSpawnedFalloff) ? ((int)((float)WeedEnemies[i].rarity * enemyType.probabilityCurve.Evaluate(timeUpToCurrentHour / RoundManager.Instance.timeScript.totalTime))) : ((int)((float)WeedEnemies[i].rarity * (enemyType.probabilityCurve.Evaluate(timeUpToCurrentHour / RoundManager.Instance.timeScript.totalTime) * enemyType.numberSpawnedFalloff.Evaluate((float)enemyType.numberSpawned / 10f))))));
				if (enemyType.spawnFromWeeds)
				{
					num2 = (int)Mathf.Clamp((float)num2 * ((float)numberOfWeeds / 60f), 0f, 200f);
				}
				RoundManager.Instance.SpawnProbabilities.Add(num2);
				num += num2;
			}
			RoundManager.Instance.firstTimeSpawningWeedEnemies = false;
			if (num <= 0)
			{
				Plugin.logSource.LogDebug((object)$"A weed enemy attempted to spawn but was denied. Reason: SpawnRate | Amount: {num}");
				return false;
			}
			bool result = false;
			int randomWeightedIndex = RoundManager.Instance.GetRandomWeightedIndex(RoundManager.Instance.SpawnProbabilities.ToArray(), WeedEnemySpawnRandom);
			EnemyType enemyType2 = WeedEnemies[randomWeightedIndex].enemyType;
			float num3 = Mathf.Max(enemyType2.spawnInGroupsOf, 1);
			for (int j = 0; (float)j < num3; j++)
			{
				float num4 = RoundManager.Instance.currentMaxOutsidePower - RoundManager.Instance.currentOutsideEnemyPower;
				if (enemyType2.PowerLevel > num4)
				{
					Plugin.logSource.LogDebug((object)$"A weed enemy attempted to spawn but was denied. Reason: PowerLevel | Amount: {num4}");
					break;
				}
				RoundManager instance = RoundManager.Instance;
				instance.currentOutsideEnemyPower += enemyType2.PowerLevel;
				Vector3 position = spawnPoints[RoundManager.Instance.AnomalyRandom.Next(0, spawnPoints.Length)].transform.position;
				position = RoundManager.Instance.GetRandomNavMeshPositionInBoxPredictable(position, 10f, default(NavMeshHit), RoundManager.Instance.AnomalyRandom, RoundManager.Instance.GetLayermaskForEnemySizeLimit(enemyType2));
				position = RoundManager.Instance.PositionWithDenialPointsChecked(position, spawnPoints, enemyType2);
				GameObject val = Object.Instantiate<GameObject>(enemyType2.enemyPrefab, position, Quaternion.Euler(Vector3.zero));
				val.GetComponentInChildren<NetworkObject>().Spawn(true);
				RoundManager.Instance.SpawnedEnemies.Add(val.GetComponent<EnemyAI>());
				EnemyType enemyType3 = val.GetComponent<EnemyAI>().enemyType;
				enemyType3.numberSpawned++;
				result = true;
			}
			Plugin.logSource.LogDebug((object)(enemyType2.enemyName + " attempted to spawn and was allowed"));
			return result;
		}

		[HarmonyPatch(typeof(RoundManager), "InitializeRandomNumberGenerators")]
		[HarmonyPostfix]
		public static void InitializeRandomNumberGenerators(RoundManager __instance)
		{
			WeedEnemySpawnRandom = new Random(__instance.playersManager.randomMapSeed + 42);
		}

		[HarmonyPatch(typeof(RoundManager), "AdvanceHourAndSpawnNewBatchOfEnemies")]
		[HarmonyPrefix]
		public static void AdvanceHourAndSpawnNewBatchOfEnemies(RoundManager __instance)
		{
			if (GameNetworkManager.Instance.gameVersionNum >= 64)
			{
				SpawnWeedEnemies(__instance.currentHour + __instance.hourTimeBetweenEnemySpawnBatches);
			}
		}

		[HarmonyPatch(typeof(BushWolfEnemy), "GetBiggestWeedPatch")]
		[HarmonyPrefix]
		public static void Pre_GetBiggestWeedPatch(ref Collider[] ___nearbyColliders)
		{
			if ((___nearbyColliders == null || ___nearbyColliders.Length <= 10) && MoldSpreadManager?.generatedMold != null && (___nearbyColliders == null || MoldSpreadManager.generatedMold.Count > ___nearbyColliders.Length))
			{
				___nearbyColliders = (Collider[])(object)new Collider[MoldSpreadManager.generatedMold.Count];
			}
		}

		[HarmonyPatch(typeof(BushWolfEnemy), "GetBiggestWeedPatch")]
		[HarmonyPostfix]
		public static void Post_GetBiggestWeedPatch(BushWolfEnemy __instance, bool __result)
		{
			//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)
			if (__result && (Object)(object)MoldAttractionPoint == (Object)null)
			{
				__instance.aggressivePosition = __instance.mostHiddenPosition;
			}
		}

		[HarmonyPatch(typeof(MoldSpreadManager), "GenerateMold")]
		[HarmonyPrefix]
		private static void Pre_GenerateMold(MoldSpreadManager __instance, ref int __state)
		{
			__state = StartOfRound.Instance.currentLevel.moldStartPosition;
		}

		[HarmonyPatch(typeof(MoldSpreadManager), "GenerateMold")]
		[HarmonyPostfix]
		private static void Post_GenerateMold(MoldSpreadManager __instance, int __state, int iterations)
		{
			if (__instance.iterationsThisDay < 1 && iterations > 0)
			{
				Plugin.logSource.LogInfo((object)$"Mold growth on \"{StartOfRound.Instance.currentLevel.PlanetName}\" erroneously reset from {iterations} iterations");
				StartOfRound.Instance.currentLevel.moldSpreadIterations = iterations;
				StartOfRound.Instance.currentLevel.moldStartPosition = __state;
			}
		}

		[HarmonyPatch(typeof(MoldSpreadManager), "Start")]
		[HarmonyPostfix]
		private static void MoldSpreadManager_Start(MoldSpreadManager __instance)
		{
			if ((Object)(object)_moldSpreadManager == (Object)null)
			{
				_moldSpreadManager = __instance;
			}
		}

		[HarmonyPatch(typeof(VehicleController), "Awake")]
		[HarmonyPostfix]
		private static void VehicleController_Awake(VehicleController __instance)
		{
			if ((Object)(object)vehicleController == (Object)null)
			{
				vehicleController = __instance;
			}
		}

		[HarmonyPatch(typeof(BushWolfEnemy), "Update")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> CacheVehicleController(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Call)
				{
					string text = list[i].operand.ToString();
					if (text.Contains("FindObjectOfType") && text.Contains("VehicleController"))
					{
						list[i].opcode = OpCodes.Ldsfld;
						list[i].operand = AccessTools.Field(typeof(HarmonyPatches), "vehicleController");
						Plugin.logSource.LogDebug((object)"Use cached VehicleController in Kidnapper Fox AI");
						break;
					}
				}
			}
			return list;
		}

		[HarmonyPatch(typeof(GameNetworkManager), "SaveGameValues")]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
		[HarmonyPatch(typeof(RoundManager), "SpawnRandomOutsideEnemy")]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(StartOfRound), "ResetMoldStates")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> CacheMoldSpreadManager(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
		{
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Call)
				{
					string text = list[i].operand.ToString();
					if (text.Contains("FindObjectOfType") && text.Contains("MoldSpreadManager"))
					{
						list[i].operand = MOLD_SPREAD_MANAGER_INSTANCE;
						Plugin.logSource.LogDebug((object)$"Use cached MoldSpreadManager in {__originalMethod.DeclaringType}.{__originalMethod.Name}");
					}
				}
			}
			return list;
		}

		public static GameObject[] FindMoldSpores()
		{
			if (MoldSpreadManager?.generatedMold == null)
			{
				return GameObject.FindGameObjectsWithTag("MoldSpore");
			}
			return MoldSpreadManager.generatedMold.Where((GameObject x) => (Object)(object)x != (Object)null && x.activeSelf).ToArray();
		}

		[HarmonyPatch(typeof(MoldSpreadManager), "GenerateMold")]
		[HarmonyPatch(typeof(BushWolfEnemy), "GetBiggestWeedPatch")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> CacheMoldGameObjects(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
		{
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 1; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Call)
				{
					MethodInfo methodInfo = list[i].operand as MethodInfo;
					if (methodInfo == FIND_GAME_OBJECT_WITH_TAG && list[i - 1].opcode == OpCodes.Ldstr && (string)list[i - 1].operand == "MoldAttractionPoint")
					{
						list[i].operand = MOLD_ATTRACTION_POINT;
						list[i - 1].opcode = OpCodes.Nop;
						Plugin.logSource.LogDebug((object)$"Use cached MoldAttractionPoint in {__originalMethod.DeclaringType}.{__originalMethod.Name}");
					}
					else if (methodInfo == FIND_GAME_OBJECTS_WITH_TAG && list[i - 1].opcode == OpCodes.Ldstr && (string)list[i - 1].operand == "MoldSpore")
					{
						list[i].operand = FIND_MOLD_SPORES;
						list[i - 1].opcode = OpCodes.Nop;
						Plugin.logSource.LogDebug((object)$"Use cached MoldSpore game objects in {__originalMethod.DeclaringType}.{__originalMethod.Name}");
					}
				}
			}
			return list;
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "uk.1a3.yesfox";

		public const string PLUGIN_NAME = "YesFox";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}
namespace YesFox.Compatibility
{
	internal class LobbyCompatibility
	{
		public static void Init(int versionNum)
		{
			Plugin.logSource.LogWarning((object)"LobbyCompatibility detected, registering plugin with LobbyCompatibility.");
			Version version = Version.Parse("1.1.2");
			PluginHelper.RegisterPlugin("uk.1a3.yesfox", version, (CompatibilityLevel)((versionNum < 64) ? 1 : 2), (VersionStrictness)2);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}