Decompiled source of IndependentBrains v0.0.0

IndependentBrains.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CG;
using CG.Ship.Modules.Weapons;
using CG.Space;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("IndependentBrains")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("IndependentBrains")]
[assembly: AssemblyTitle("IndependentBrains")]
[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 IndependentBrains
{
	[HarmonyPatch(typeof(AutoShootingTurretController))]
	internal class AutoShootingTurretControllerPatch
	{
		private static readonly MethodInfo SetActiveTargetMethod = AccessTools.Method(typeof(AutoShootingTurretController), "SetActiveTarget", (Type[])null, (Type[])null);

		private static Random random = new Random();

		[HarmonyPrefix]
		[HarmonyPatch("SelectBestTarget")]
		private static void SelectBestTargetPrefix(WeaponTarget ___activeTarget, out OrbitObject __state)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			__state = ___activeTarget.TargetedUnit;
		}

		[HarmonyPostfix]
		[HarmonyPatch("SelectBestTarget")]
		private static void SelectBestTargetPostfix(AutoShootingTurretController __instance, WeaponTarget ___activeTarget, List<WeaponTarget> ___potentialTargets, ref int ___currentTargetPriority, OrbitObject __state)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_009d: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (((!(___activeTarget.TargetedUnit is AbstractDrone) || !Configs.randomFightersConfig.Value) && (!(___activeTarget.TargetedUnit is AbstractProximityMine) || !Configs.randomMinesConfig.Value) && !Configs.randomAllConfig.Value) || (Object)(object)___activeTarget.TargetedUnit == (Object)(object)__state)
			{
				return;
			}
			int num = ___currentTargetPriority;
			___currentTargetPriority = -1;
			___potentialTargets = ___potentialTargets.OrderBy((WeaponTarget _) => random.Next()).ToList();
			int num2 = default(int);
			foreach (WeaponTarget ___potentialTarget in ___potentialTargets)
			{
				if ((!(((object)___potentialTarget.TargetedUnit).GetType() != ((object)___activeTarget.TargetedUnit).GetType()) || Configs.randomAllConfig.Value) && ProjectileUtils.IsHigherPriorityTarget((ITaggable)(object)___potentialTarget.TargetedUnit, ___currentTargetPriority, ref num2))
				{
					SetActiveTargetMethod.Invoke(__instance, new object[1] { ___potentialTarget });
					___currentTargetPriority = num2;
				}
			}
			if (___currentTargetPriority == -1)
			{
				___currentTargetPriority = num;
			}
		}
	}
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.independentbrains";

		internal const string PLUGIN_NAME = "IndependentBrains";

		internal const string PLUGIN_VERSION = "0.0.0";
	}
	[BepInPlugin("id107.independentbrains", "IndependentBrains", "0.0.0")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "id107.independentbrains");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.independentbrains is loaded!");
		}
	}
	internal class Configs
	{
		internal static ConfigEntry<bool> randomFightersConfig;

		internal static ConfigEntry<bool> randomMinesConfig;

		internal static ConfigEntry<bool> randomAllConfig;

		internal static void Load(BepinPlugin plugin)
		{
			randomFightersConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("IndependentBrains", "RandomFighters", true, (ConfigDescription)null);
			randomMinesConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("IndependentBrains", "RandomMines", true, (ConfigDescription)null);
			randomAllConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("IndependentBrains", "RandomAll", false, (ConfigDescription)null);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		public override string Name()
		{
			return "Independent Brains";
		}

		public override void Draw()
		{
			GUITools.DrawCheckbox("Target separate fighters", ref Configs.randomFightersConfig);
			GUITools.DrawCheckbox("Target separate mines", ref Configs.randomMinesConfig);
			GUITools.DrawCheckbox("Independently target everything", ref Configs.randomAllConfig);
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)4;

		public override string Author => "18107";

		public override string Description => "Makes B.R.A.I.N turrets select different targets";
	}
}