Decompiled source of AutoScan v1.4.0

abu.AutoScan.dll

Decompiled a month ago
using System;
using System.Collections;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("abu.AutoScan")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0+b14ed4b591892b98492763298b50ddf9fd3645fd")]
[assembly: AssemblyProduct("AutoScan")]
[assembly: AssemblyTitle("abu.AutoScan")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.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.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;
		}
	}
	[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 AutoScan
{
	[BepInPlugin("abu.AutoScan", "AutoScan", "1.4.0")]
	public class AutoScan : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")]
		internal class AutoAnnouncePatch
		{
			[CompilerGenerated]
			private sealed class <DelayedAnnounce>d__3 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public StartOfRound __instance;

				private string <error>5__1;

				private int <outsideShip>5__2;

				private int <outsideShipBees>5__3;

				private int <outsideShipValueNoBees>5__4;

				private int <outsideShipValueBees>5__5;

				private string <msg>5__6;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <DelayedAnnounce>d__3(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<error>5__1 = null;
					<msg>5__6 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>2__current = (object)new WaitForSeconds(ScanDelay);
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						ReloadConfig();
						Logger.LogDebug((object)$">> DelayedAutoAnnounce({__instance}) IsServer:{((NetworkBehaviour)__instance).IsServer} AutoAnnounce:{AutoAnnounce}");
						if (!AutoAnnounce || (!((NetworkBehaviour)__instance).IsServer && HostOnly))
						{
							return false;
						}
						if (Countitems(out <error>5__1, out <outsideShip>5__2, out <outsideShipBees>5__3, out <outsideShipValueNoBees>5__4, out <outsideShipValueBees>5__5))
						{
							Logger.LogInfo((object)$"{<outsideShip>5__2} {<outsideShipBees>5__3} {<outsideShipValueNoBees>5__4} {<outsideShipValueBees>5__5}");
							if (<outsideShip>5__2 > 0 || <outsideShipBees>5__3 > 0)
							{
								<msg>5__6 = $"<color=#00ff00>Scan: {<outsideShip>5__2}";
								if (AnnounceOutsideLoot)
								{
									<msg>5__6 += $"/{<outsideShipBees>5__3}";
								}
								if (AnnounceValue)
								{
									<msg>5__6 += $" {<outsideShipValueNoBees>5__4}";
								}
								if (AnnounceOutsideLoot && AnnounceValue)
								{
									<msg>5__6 += $"/{<outsideShipValueBees>5__5}";
								}
								<msg>5__6 += "</color>";
								HUDManager.Instance.AddTextMessageServerRpc(<msg>5__6);
								<msg>5__6 = null;
							}
						}
						else
						{
							Logger.LogError((object)("Error while counting items: " + <error>5__1));
							HUDManager.Instance.AddTextMessageServerRpc("<color=#ff0000>Error while counting items: " + <error>5__1 + "</color>");
						}
						return false;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			public static bool Countitems(out string? error, out int outsideShip, out int outsideShipBees, out int outsideShipValueNoBees, out int outsideShipValueBees)
			{
				outsideShip = 0;
				outsideShipBees = 0;
				outsideShipValueNoBees = 0;
				outsideShipValueBees = 0;
				error = "items is null";
				GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
				if (array == null)
				{
					return false;
				}
				error = "ship is null";
				GameObject val = GameObject.Find("Environment/HangarShip");
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				error = "vehicles is null";
				VehicleController[] array2 = Object.FindObjectsOfType<VehicleController>();
				if (array2 == null)
				{
					return false;
				}
				Random random = new Random(StartOfRound.Instance.randomMapSeed + 91);
				for (int j = 0; j < array.Length; j++)
				{
					GrabbableObject item2 = array[j];
					if (item2.itemProperties.isScrap && !item2.isInShipRoom && !((Component)item2).transform.IsChildOf(val.transform) && !array2.Any((VehicleController _car) => ((Component)item2).transform.IsChildOf(((Component)_car).transform)))
					{
						if (IsBees(item2))
						{
							outsideShipBees++;
							outsideShipValueBees += a(randomize: true, item2, j);
						}
						else
						{
							outsideShip++;
							outsideShipValueNoBees += a(randomize: true, item2, j);
						}
					}
				}
				return true;
				int a(bool randomize, GrabbableObject item, int i)
				{
					return randomize ? Mathf.Clamp(random.Next(item.itemProperties.minValue, item.itemProperties.maxValue), item.scrapValue - 6 * i, item.scrapValue + 9 * i) : item.scrapValue;
				}
			}

			private static bool IsBees(GrabbableObject item)
			{
				Logger.LogDebug((object)$">> IsBees({item}) name:{((Object)item).name}");
				return ((Object)item).name == "RedLocustHive(Clone)" || ((Object)item).name == "KiwiBabyItem(Clone)";
			}

			private static void Postfix(ref StartOfRound __instance)
			{
				((MonoBehaviour)__instance).StartCoroutine(DelayedAnnounce(__instance));
			}

			[IteratorStateMachine(typeof(<DelayedAnnounce>d__3))]
			private static IEnumerator DelayedAnnounce(StartOfRound __instance)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <DelayedAnnounce>d__3(0)
				{
					__instance = __instance
				};
			}
		}

		private ConfigEntry<bool>? autoAnnounce;

		private ConfigEntry<bool>? announceOutsideLoot;

		private ConfigEntry<bool>? announceValue;

		private ConfigEntry<bool>? hostOnly;

		private ConfigEntry<float>? scanDelay;

		public static AutoScan Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		public static bool AutoAnnounce
		{
			get
			{
				AutoScan instance = Instance;
				return instance != null && (instance.autoAnnounce?.Value).GetValueOrDefault();
			}
		}

		public static bool AnnounceOutsideLoot
		{
			get
			{
				AutoScan instance = Instance;
				return instance != null && (instance.announceOutsideLoot?.Value).GetValueOrDefault();
			}
		}

		public static bool AnnounceValue
		{
			get
			{
				AutoScan instance = Instance;
				return instance != null && (instance.announceValue?.Value).GetValueOrDefault();
			}
		}

		public static bool HostOnly
		{
			get
			{
				AutoScan instance = Instance;
				return instance != null && (instance.hostOnly?.Value).GetValueOrDefault();
			}
		}

		public static float ScanDelay => (Instance?.scanDelay?.Value).GetValueOrDefault(2.5f);

		private void Awake()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			autoAnnounce = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AutoAnnounce", true, "Automatically announce the number of items outside the ship at the start of the round");
			announceOutsideLoot = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AnnounceOutsideLoot", true, "Announce the amount of loot outside the facility including Beehives and Sapsucker eggs");
			announceValue = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AnnounceValue", true, "Announce the total loot value when scanning");
			scanDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScanDelay", 2.5f, "Delay in seconds before scanning starts");
			hostOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HostOnly", true, "Only announce if you are the host");
			if (Harmony == null)
			{
				Harmony = new Harmony("abu.AutoScan");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
			Logger.LogInfo((object)"abu.AutoScan v1.4.0 has loaded!");
		}

		public static void ReloadConfig()
		{
			if (!((Object)(object)Chainloader.ManagerObject == (Object)null))
			{
				AutoScan component = Chainloader.ManagerObject.GetComponent<AutoScan>();
				if (!((Object)(object)component == (Object)null))
				{
					((BaseUnityPlugin)component).Config.Reload();
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "abu.AutoScan";

		public const string PLUGIN_NAME = "AutoScan";

		public const string PLUGIN_VERSION = "1.4.0";
	}
}