Decompiled source of NestFix v1.2.0

NestFix.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("NestFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes Nest Positions")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f1976908e09e3a322f4d764d106c07599371de59")]
[assembly: AssemblyProduct("NestFix")]
[assembly: AssemblyTitle("NestFix")]
[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 NestFix
{
	[BepInPlugin("PureFPSZac.NestFix", "NestFix", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "PureFPSZac.NestFix";

		public const string NAME = "NestFix";

		public const string VERSION = "1.2.0";

		private static ManualLogSource NestLogger;

		private static readonly NavMeshPath TempPath = new NavMeshPath();

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			NestLogger = ((BaseUnityPlugin)this).Logger;
			new Harmony("PureFPSZac.NestFix").PatchAll(typeof(Plugin));
		}

		private static Vector4 Vec4Position(Vector3 position)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			return new Vector4(position.x, position.y, position.z, 1f);
		}

		private static bool NestSpawnPositionIsValid(EnemyType enemyType, Vector3 position, Quaternion rotation)
		{
			//IL_002d: 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_0030: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0077: 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)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)enemyType).name == "BaboonHawk")
			{
				Transform transform = enemyType.nestSpawnPrefab.transform;
				Transform val = transform.Find("WoodPikes");
				Matrix4x4 val2 = Matrix4x4.TRS(position, rotation, transform.localScale) * transform.worldToLocalMatrix;
				if ((Object)(object)val != (Object)null)
				{
					BoxCollider[] componentsInChildren = ((Component)val).GetComponentsInChildren<BoxCollider>();
					RaycastHit val6 = default(RaycastHit);
					NavMeshHit val7 = default(NavMeshHit);
					foreach (BoxCollider val3 in componentsInChildren)
					{
						Transform transform2 = ((Component)val3).transform;
						Vector4 val4 = Vec4Position(val3.center);
						Vector4 val5 = val2 * transform2.localToWorldMatrix * (val4 - new Vector4(0f, 0f, val3.size.z / 2f));
						if (!Physics.Linecast(Vector4.op_Implicit(val2 * transform2.localToWorldMatrix * (val4 + new Vector4(0f, 0f, val3.size.z / 2f))), Vector4.op_Implicit(val5), ref val6, 256))
						{
							return false;
						}
						if (!NavMesh.SamplePosition(((RaycastHit)(ref val6)).point, ref val7, 0.5f, -1))
						{
							return false;
						}
						if (!NavMesh.CalculatePath(position, ((NavMeshHit)(ref val7)).position, -1, TempPath) || (int)TempPath.status != 0)
						{
							return false;
						}
					}
				}
			}
			return true;
		}

		private static void SpawnNest()
		{
			foreach (SpawnableEnemyWithRarity outsideEnemy in RoundManager.Instance.currentLevel.OutsideEnemies)
			{
				EnemyType enemyType = outsideEnemy.enemyType;
				if (((Object)enemyType).name == "BaboonHawk" && (Object)(object)enemyType.nestSpawnPrefab != (Object)null)
				{
					Random random = new Random();
					for (int i = 0; i < 100; i++)
					{
						RoundManager.Instance.SpawnNestObjectForOutsideEnemy(enemyType, random);
					}
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(RoundManager), "SpawnNestObjectForOutsideEnemy")]
		private static bool SpawnNestObjectForOutsideEnemyPrefix(RoundManager __instance, EnemyType enemyType, Random randomSeed)
		{
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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)
			if (((Object)enemyType).name != "BaboonHawk")
			{
				return true;
			}
			GameObject[] array = GameObject.FindGameObjectsWithTag("OutsideAINode");
			int num = 32;
			Vector3? val = null;
			Quaternion? val2 = null;
			while (!val.HasValue && num > 0)
			{
				List<GameObject> list = new List<GameObject>(array);
				NestLogger.LogInfo((object)$"SpawnNestObjectForOutsideEnemyPrefix was called with {array.Length} nodes, {num} tries left");
				while (list.Count > 0)
				{
					int index = randomSeed.Next(0, list.Count);
					Vector3 val3 = list[index].transform.position;
					list.RemoveAt(index);
					val3 = __instance.GetRandomNavMeshPositionInBoxPredictable(val3, 15f, default(NavMeshHit), randomSeed, __instance.GetLayermaskForEnemySizeLimit(enemyType), 1f);
					val3 = __instance.PositionWithDenialPointsChecked(val3, array, enemyType, enemyType.nestDistanceFromShip);
					val3 = __instance.PositionEdgeCheck(val3, enemyType.nestSpawnPrefabWidth);
					Quaternion val4 = Quaternion.Euler(0f, (float)randomSeed.Next(-180, 180), 0f);
					if (!((Vector3)(ref val3)).Equals(Vector3.zero) && NestSpawnPositionIsValid(enemyType, val3, val4))
					{
						val = val3;
						val2 = val4;
						break;
					}
				}
				num--;
			}
			if (!val.HasValue)
			{
				NestLogger.LogWarning((object)("Failed to find a spawn position for the " + ((Object)enemyType).name + " nest."));
				return false;
			}
			GameObject val5 = Object.Instantiate<GameObject>(enemyType.nestSpawnPrefab, val.Value, Quaternion.Euler(Vector3.zero));
			val5.transform.localRotation = val2.Value * val5.transform.localRotation;
			if (!Object.op_Implicit((Object)(object)val5.gameObject.GetComponentInChildren<NetworkObject>()))
			{
				Debug.LogError((object)("Error: No NetworkObject found in enemy nest spawn prefab that was just spawned on the host: '" + ((Object)val5).name + "'"));
			}
			else
			{
				val5.gameObject.GetComponentInChildren<NetworkObject>().Spawn(true);
			}
			if (!Object.op_Implicit((Object)(object)val5.GetComponent<EnemyAINestSpawnObject>()))
			{
				Debug.LogError((object)("Error: No EnemyAINestSpawnObject component in nest object prefab that was just spawned on the host: '" + ((Object)val5).name + "'"));
			}
			else
			{
				__instance.enemyNestSpawnObjects.Add(val5.GetComponent<EnemyAINestSpawnObject>());
			}
			enemyType.nestsSpawned++;
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}