Decompiled source of AggroFix v0.0.2

AggroFix.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AIGraph;
using API;
using Agents;
using AggroFix.BepInEx;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using StateMachines;
using UnityEngine;
using UnityEngine.Analytics;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AggroFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+993b34134528fcfa51e1e8571e9ad84aea5be391")]
[assembly: AssemblyProduct("AggroFix")]
[assembly: AssemblyTitle("AggroFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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 AggroFix
{
	[HarmonyPatch]
	internal static class Fix
	{
		private static bool patch = true;

		private static bool IsTargetReachable(AIG_CourseNode source, AIG_CourseNode target)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Invalid comparison between Unknown and I4
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Invalid comparison between Unknown and I4
			if (source == null || target == null)
			{
				return false;
			}
			if (source.NodeID == target.NodeID)
			{
				return true;
			}
			AIG_SearchID.IncrementSearchID();
			ushort searchID = AIG_SearchID.SearchID;
			Queue<AIG_CourseNode> queue = new Queue<AIG_CourseNode>();
			queue.Enqueue(source);
			while (queue.Count > 0)
			{
				AIG_CourseNode val = queue.Dequeue();
				((AIG_CourseGraphMember)val).m_searchID = searchID;
				Enumerator<AIG_CoursePortal> enumerator = val.m_portals.GetEnumerator();
				while (enumerator.MoveNext())
				{
					AIG_CoursePortal current = enumerator.Current;
					LG_Gate gate = current.Gate;
					object obj;
					if (gate == null)
					{
						obj = null;
					}
					else
					{
						iLG_Door_Core spawnedDoor = gate.SpawnedDoor;
						obj = ((spawnedDoor != null) ? ((Il2CppObjectBase)spawnedDoor).TryCast<LG_SecurityDoor>() : null);
					}
					LG_SecurityDoor val2 = (LG_SecurityDoor)obj;
					if ((Object)(object)val2 != (Object)null && (int)val2.LastStatus != 10 && (int)val2.LastStatus != 16)
					{
						continue;
					}
					AIG_CourseNode oppositeNode = current.GetOppositeNode(val);
					if (((AIG_CourseGraphMember)oppositeNode).m_searchID != searchID)
					{
						if (oppositeNode.NodeID == target.NodeID)
						{
							return true;
						}
						queue.Enqueue(oppositeNode);
					}
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(EnemyCourseNavigation), "UpdateTracking")]
		[HarmonyPostfix]
		private static void UpdateTracking(EnemyCourseNavigation __instance)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			if (!patch || !SNet.IsMaster)
			{
				return;
			}
			EnemyAgent owner = __instance.m_owner;
			if (((Agent)owner).CourseNode == null || __instance.m_targetRef == null || (Object)(object)__instance.m_targetRef.m_agent == (Object)null || (int)((StateMachine<ES_Base>)(object)owner.Locomotion).m_currentState.m_stateEnum == 14)
			{
				return;
			}
			if (!IsTargetReachable(((Agent)owner).CourseNode, __instance.m_targetRef.m_agent.CourseNode))
			{
				APILogger.Debug("Invalid current " + ((Il2CppObjectBase)__instance.m_targetRef.m_agent).Cast<PlayerAgent>().Owner.NickName);
				bool flag = false;
				int num = Random.RandomRangeInt(0, PlayerManager.PlayerAgentsInLevel.Count);
				PlayerAgent val = PlayerManager.PlayerAgentsInLevel[num];
				for (int i = 0; i < PlayerManager.PlayerAgentsInLevel.Count; i++)
				{
					APILogger.Debug("Checking " + val.Owner.NickName);
					if (((Agent)val).Alive && ((Object)val).GetInstanceID() != ((Object)__instance.m_targetRef.m_agent).GetInstanceID() && IsTargetReachable(((Agent)owner).CourseNode, ((Agent)val).CourseNode))
					{
						flag = true;
						break;
					}
					num = (num + 1) % PlayerManager.PlayerAgentsInLevel.Count;
					val = PlayerManager.PlayerAgentsInLevel[num];
				}
				if (flag)
				{
					APILogger.Debug("Rerouted to " + val.Owner.NickName);
					patch = false;
					((AgentAI)owner.AI).SetTarget((Agent)(object)val);
					patch = true;
				}
				else
				{
					APILogger.Debug("No valid target found " + ((Il2CppObjectBase)__instance.m_targetRef.m_agent).Cast<PlayerAgent>().Owner.NickName);
				}
			}
			else
			{
				APILogger.Debug("Current " + ((Il2CppObjectBase)__instance.m_targetRef.m_agent).Cast<PlayerAgent>().Owner.NickName);
			}
		}
	}
}
namespace AggroFix.BepInEx
{
	public static class Module
	{
		public const string GUID = "randomuserhi.AggroFix";

		public const string Name = "AggroFix";

		public const string Version = "0.0.1";
	}
	public static class ConfigManager
	{
		public static ConfigFile configFile;

		private static ConfigEntry<bool> debug;

		public static bool Debug
		{
			get
			{
				return debug.Value;
			}
			set
			{
				debug.Value = value;
			}
		}

		static ConfigManager()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "AggroFix.cfg"), true);
			debug = configFile.Bind<bool>("Debug", "enable", false, "Enables debug messages when true.");
		}
	}
	[BepInPlugin("randomuserhi.AggroFix", "AggroFix", "0.0.1")]
	public class Plugin : BasePlugin
	{
		private static Harmony? harmony;

		public override void Load()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			APILogger.Log("Plugin is loaded!");
			harmony = new Harmony("randomuserhi.AggroFix");
			harmony.PatchAll();
			APILogger.Log("Debug is " + (ConfigManager.Debug ? "Enabled" : "Disabled"));
		}
	}
}
namespace API
{
	[HarmonyPatch(typeof(GameDataInit))]
	internal class GameDataInit_Patches
	{
		[HarmonyPatch("Initialize")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		public static void Initialize_Postfix()
		{
			Analytics.enabled = false;
		}
	}
	internal static class APILogger
	{
		private static readonly ManualLogSource logger;

		static APILogger()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			logger = new ManualLogSource("Rand-API");
			Logger.Sources.Add((ILogSource)(object)logger);
		}

		private static string Format(string module, object msg)
		{
			return $"[{module}]: {msg}";
		}

		public static void Info(string module, object data)
		{
			logger.LogMessage((object)Format(module, data));
		}

		public static void Verbose(string module, object data)
		{
		}

		public static void Log(object data)
		{
			logger.LogDebug((object)Format("AggroFix", data));
		}

		public static void Debug(object data)
		{
			if (ConfigManager.Debug)
			{
				Log(data);
			}
		}

		public static void Warn(object data)
		{
			logger.LogWarning((object)Format("AggroFix", data));
		}

		public static void Error(object data)
		{
			logger.LogError((object)Format("AggroFix", data));
		}
	}
}