Decompiled source of DoorEnemyFixUpdated v1.1.1

DoorEnemyFixUpdated.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AIGraph;
using Agents;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CullingSystem;
using HarmonyLib;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DoorEnemyFixUpdated")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d6d2b06a5b93ec95b63273051ce6f1ce4429b0d0")]
[assembly: AssemblyProduct("DoorEnemyFixUpdated")]
[assembly: AssemblyTitle("DoorEnemyFixUpdated")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace DoorEnemyFixUpdated
{
	internal static class DinoLogger
	{
		private static ManualLogSource logger = Logger.CreateLogSource("DoorEnemyFix");

		public static void Log(string format, params object[] args)
		{
			Log(string.Format(format, args));
		}

		public static void Log(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)8, (object)str);
			}
		}

		public static void Warning(string format, params object[] args)
		{
			Warning(string.Format(format, args));
		}

		public static void Warning(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)4, (object)str);
			}
		}

		public static void Error(string format, params object[] args)
		{
			Error(string.Format(format, args));
		}

		public static void Error(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)2, (object)str);
			}
		}

		public static void Debug(string format, params object[] args)
		{
			Debug(string.Format(format, args));
		}

		public static void Debug(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)32, (object)str);
			}
		}
	}
	public static class DoorUtil
	{
		private const float PortalCheckBuffer = 0.25f;

		private const float MinDotInNode = 0.1f;

		public static bool TryGetNearbyPortal(Vector3 pos, AIG_CourseNode node, [MaybeNullWhen(false)] out AIG_CoursePortal portal)
		{
			//IL_001e: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			float num = float.MaxValue;
			portal = null;
			Enumerator<AIG_CoursePortal> enumerator = node.m_portals.GetEnumerator();
			float num2 = default(float);
			float num3 = default(float);
			while (enumerator.MoveNext())
			{
				AIG_CoursePortal current = enumerator.Current;
				Vector3 val = pos - current.Position;
				float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
				current.m_cullPortal.GetShapeWidthHeight(ref num2, ref num3);
				num2 /= 2f;
				num3 /= 2f;
				num2 += 0.25f;
				num3 += 0.25f;
				if (sqrMagnitude < num && sqrMagnitude < num2 * num2 + num3 * num3)
				{
					portal = current;
					num = sqrMagnitude;
				}
			}
			return portal != null;
		}

		public static bool TryGetCrossPortal(AIG_CourseNode nodeA, AIG_CourseNode nodeB, [MaybeNullWhen(false)] out AIG_CoursePortal portal)
		{
			int nodeID = nodeB.NodeID;
			Enumerator<AIG_CoursePortal> enumerator = nodeA.m_portals.GetEnumerator();
			while (enumerator.MoveNext())
			{
				AIG_CoursePortal current = enumerator.Current;
				if (current.GetOppositeNode(nodeA).NodeID == nodeID)
				{
					portal = current;
					return true;
				}
			}
			portal = null;
			return false;
		}

		public static bool IsOnSameSide(Vector3 pos, AIG_CourseNode checkNode, AIG_CoursePortal portal)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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)
			C_Portal cullPortal = portal.m_cullPortal;
			Vector3 val = pos - cullPortal.m_center;
			return Vector3.Dot(cullPortal.GetDirIntoNode(checkNode.m_cullNode), val) > 0.1f;
		}

		public static AIG_CourseNode GetCorrectNode(Vector3 pos, AIG_CourseNode node)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (TryGetNearbyPortal(pos, node, out AIG_CoursePortal portal))
			{
				AIG_CourseNode oppositeNode = portal.GetOppositeNode(node);
				if (IsOnSameSide(pos, oppositeNode, portal))
				{
					return oppositeNode;
				}
			}
			return node;
		}

		public static bool CanTouchNode(Vector3 pos, AIG_CourseNode node, AIG_CourseNode checkNode)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (node.NodeID == checkNode.NodeID)
			{
				return true;
			}
			if (!TryGetCrossPortal(node, checkNode, out AIG_CoursePortal portal))
			{
				return false;
			}
			if (portal.IsTraversable)
			{
				return true;
			}
			return IsOnSameSide(pos, checkNode, portal);
		}

		public static bool CanTouchNode(Vector3 pos, AIG_CourseNode checkNode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetNearbyPortal(pos, checkNode, out AIG_CoursePortal portal) || portal.IsTraversable)
			{
				return true;
			}
			return IsOnSameSide(pos, checkNode, portal);
		}
	}
	[BepInPlugin("Localia.DoorEnemyFix", "DoorEnemyFix", "1.1.1")]
	internal sealed class EntryPoint : BasePlugin
	{
		public const string MODNAME = "DoorEnemyFix";

		public override void Load()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("DoorEnemyFix").PatchAll();
			((BasePlugin)this).Log.LogMessage((object)"Loaded DoorEnemyFix");
		}
	}
}
namespace DoorEnemyFixUpdated.Patches
{
	[HarmonyPatch]
	internal static class GluePatches
	{
		[HarmonyPatch(typeof(GlueGunProjectile), "SetLandedStatic")]
		[HarmonyPostfix]
		private static void Post_LandStatic(GlueGunProjectile __instance, bool enableCollider)
		{
			if (!enableCollider)
			{
				__instance.m_landedOnEnemy = true;
				__instance.m_onEnemyVolumeScale = 1f;
			}
		}

		[HarmonyPatch(typeof(GlueGunProjectile), "SetLandedOnEnemy")]
		[HarmonyPostfix]
		private static void Post_LandEnemy(GlueGunProjectile __instance)
		{
			((Collider)__instance.m_collider).enabled = false;
		}

		[HarmonyPatch(typeof(GlueGunProjectile), "CollisionCheck")]
		[HarmonyPostfix]
		private static void Post_Collision(GlueGunProjectile __instance, ref bool __result)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_006a: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (!__result)
			{
				return;
			}
			Collider projLastRayHitCollider = ((StickingProjectileBase)__instance).m_projLastRayHitCollider;
			if ((Object)(object)projLastRayHitCollider == (Object)null || ((Component)((StickingProjectileBase)__instance).m_projLastRayHitCollider).gameObject.layer != LayerManager.LAYER_ENEMY_DAMAGABLE)
			{
				return;
			}
			Agent baseAgent = ((Component)projLastRayHitCollider).GetComponent<IDamageable>().GetBaseAgent();
			if (!DoorUtil.CanTouchNode(((StickingProjectileBase)__instance).m_projTargetPos, baseAgent.CourseNode))
			{
				int num = ((StickingProjectileBase)__instance).CollisionMask & ~LayerManager.MASK_ENEMY_DAMAGABLE;
				Vector3 val = ((StickingProjectileBase)__instance).m_projVelocity * Time.fixedDeltaTime;
				RaycastHit val2 = default(RaycastHit);
				__result = Physics.SphereCast(((StickingProjectileBase)__instance).m_projTargetPos, __instance.m_sphereCastRadius, val, ref val2, 1f, num);
				if (__result)
				{
					((StickingProjectileBase)__instance).m_projLastRayHitPoint = ((RaycastHit)(ref val2)).point;
					((StickingProjectileBase)__instance).m_projLastRayHitNormal = ((RaycastHit)(ref val2)).normal;
					((StickingProjectileBase)__instance).m_projLastRayHitCollider = ((RaycastHit)(ref val2)).collider;
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class MinePatches
	{
		[HarmonyPatch(typeof(MineDeployerInstance), "OnSpawnData")]
		[HarmonyPostfix]
		private static void Post_Spawn(MineDeployerInstance __instance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			__instance.m_courseNode = DoorUtil.GetCorrectNode(((Component)__instance).transform.position, __instance.m_courseNode);
		}

		[HarmonyPatch(typeof(MineDeployerInstance_Detect_Laser), "UpdateDetection")]
		[HarmonyPrefix]
		private static bool Pre_Detection(MineDeployerInstance_Detect_Laser __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if ((int)__instance.m_core.Mode == 0 || __instance.m_maxLineDistance == 0f)
			{
				return true;
			}
			RaycastHit val = default(RaycastHit);
			float num;
			if (Physics.SphereCast(__instance.m_lineRendererAlign.position, 0.1f, __instance.m_lineRendererAlign.forward, ref val, __instance.m_maxLineDistance, __instance.m_scanMask))
			{
				num = ((RaycastHit)(ref val)).distance;
				if (CustomExtensions.IsInLayerMask(__instance.m_enemyMask, ((Component)((RaycastHit)(ref val)).collider).gameObject))
				{
					Agent baseAgent = ((Component)((RaycastHit)(ref val)).collider).GetComponent<IDamageable>().GetBaseAgent();
					if (!DoorUtil.CanTouchNode(baseAgent.Position, baseAgent.CourseNode, __instance.m_core.CourseNode))
					{
						return false;
					}
					Action onTargetDetected = __instance.OnTargetDetected;
					if (onTargetDetected != null)
					{
						onTargetDetected.Invoke();
					}
					return false;
				}
			}
			else
			{
				num = __instance.m_maxLineDistance;
			}
			if (num != __instance.DetectionRange)
			{
				__instance.UpdateDetectionRange(num);
			}
			return false;
		}
	}
}