Decompiled source of Independent Brains v0.0.1

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.Ship.Modules.Weapons;
using CG.Space;
using Gameplay.Tags;
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: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+0ac0fc639c70d1ebeaf900b1cb8c01de1b40bf9b")]
[assembly: AssemblyProduct("IndependentBrains")]
[assembly: AssemblyTitle("Makes B.R.A.I.N turrets select different targets. Host Side")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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;
			}
		}
	}
	[BepInPlugin("18107.IndependentBrains", "Independent Brains", "0.0.1")]
	[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(), "18107.IndependentBrains");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin 18107.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 MyPluginInfo
	{
		public const string PLUGIN_GUID = "18107.IndependentBrains";

		public const string PLUGIN_NAME = "IndependentBrains";

		public const string USERS_PLUGIN_NAME = "Independent Brains";

		public const string PLUGIN_VERSION = "0.0.1";

		public const string PLUGIN_DESCRIPTION = "Makes B.R.A.I.N turrets select different targets. Host Side";

		public const string PLUGIN_ORIGINAL_AUTHOR = "18107";

		public const string PLUGIN_AUTHORS = "18107";

		public const string PLUGIN_THUNDERSTORE_ID = "VoidCrewModdingTeam/Independent_Brains";
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)14;

		public override string Author => "18107";

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

		public override string ThunderstoreID => "VoidCrewModdingTeam/Independent_Brains";

		public override SessionChangedReturn OnSessionChange(SessionChangedInput input)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			SessionChangedReturn result = default(SessionChangedReturn);
			result.SetMod_Session = true;
			return result;
		}
	}
}