Decompiled source of AutoTerminalScan v1.0.2

Happyness.Autoscan.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("Happyness.Autoscan")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("Autoscan")]
[assembly: AssemblyTitle("Happyness.Autoscan")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 AutoScan
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Happyness.Autoscan";

		public const string PLUGIN_NAME = "Autoscan";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace AutoTerminalScan
{
	[BepInPlugin("Happyness.Autoscan", "Autoscan", "1.0.2")]
	public class AutoTerminalScan : BaseUnityPlugin
	{
		public class MonoBehaviourProxy : MonoBehaviour
		{
		}

		private static MonoBehaviourProxy coroutineProxy;

		public StartOfRound playersManager;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			playersManager = Object.FindObjectOfType<StartOfRound>();
			SetupCoroutineRunner01();
			Harmony val = new Harmony("com.happyness.autoscan");
			val.PatchAll();
		}

		private void SetupCoroutineRunner01()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (!((Object)(object)coroutineProxy != (Object)null))
			{
				GameObject val = new GameObject("AutoScan_CoroutineRunner");
				coroutineProxy = val.AddComponent<MonoBehaviourProxy>();
				Object.DontDestroyOnLoad((Object)(object)val);
			}
		}

		public static void StartSafeCoroutine01(IEnumerator routine)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)coroutineProxy == (Object)null)
			{
				GameObject val = new GameObject("AutoScan_CoroutineRunner");
				coroutineProxy = val.AddComponent<MonoBehaviourProxy>();
				Object.DontDestroyOnLoad((Object)(object)val);
			}
			((MonoBehaviour)coroutineProxy).StartCoroutine(routine);
		}
	}
	[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
	public static class WaitForScrapToSpawnToSyncPatch01
	{
		public static class AutoScanChatCache
		{
			public static string lastReceivedChatMessage1 = "";
		}

		[HarmonyPatch(typeof(HUDManager), "AddChatMessage")]
		public static class CaptureIncomingChatPatch1
		{
			[HarmonyPostfix]
			public static void PostfixAM(string chatMessage)
			{
				if (!string.IsNullOrWhiteSpace(chatMessage))
				{
					AutoScanChatCache.lastReceivedChatMessage1 = chatMessage;
				}
			}
		}

		public static float lastCleanupTime1 = -999f;

		public const float CleanupCooldown1 = 10f;

		public static string gamelevel111 = "";

		[HarmonyPrefix]
		public static void BeforeWait(RoundManager __instance)
		{
			AutoTerminalScan.StartSafeCoroutine01(CountScrapAndBeehives(__instance));
		}

		private static IEnumerator CountScrapAndBeehives(RoundManager rm)
		{
			gamelevel111 = ((object)RoundManager.Instance.currentLevel).ToString();
			AutoTerminalScan.Logger.LogInfo((object)gamelevel111);
			if (Time.time - lastCleanupTime1 < 10f)
			{
				yield break;
			}
			if (gamelevel111 == "CompanyBuildingLevel (SelectableLevel)")
			{
				AutoTerminalScan.Logger.LogInfo((object)"Moon is CompanyBuildingLevel");
				yield break;
			}
			lastCleanupTime1 = Time.time;
			yield return (object)new WaitForSeconds(5f);
			try
			{
				if ((Object)(object)rm == (Object)null)
				{
					yield break;
				}
				GrabbableObject[] allObjects = Object.FindObjectsOfType<GrabbableObject>();
				int beehiveCount1 = 0;
				int eggCount1 = 0;
				List<GrabbableObject> outsideScrap = new List<GrabbableObject>();
				GrabbableObject[] array = allObjects;
				foreach (GrabbableObject obj in array)
				{
					if ((Object)(object)obj.itemProperties != (Object)null && obj.itemProperties.isScrap && !obj.scrapPersistedThroughRounds && !obj.isInShipRoom)
					{
						outsideScrap.Add(obj);
					}
					if (!obj.isInShipRoom && ((Object)obj).name.Contains("Hive", StringComparison.OrdinalIgnoreCase))
					{
						beehiveCount1++;
					}
					if (!obj.isInShipRoom && ((Object)obj).name.Contains("KiwiBabyItem", StringComparison.OrdinalIgnoreCase))
					{
						eggCount1++;
					}
				}
				int scrapCount1 = outsideScrap.Count - beehiveCount1 - eggCount1;
				if (scrapCount1 < 0)
				{
					scrapCount1 = 0;
				}
				AutoTerminalScan.Logger.LogInfo((object)$"[AutoScan] Scrap: {scrapCount1}, Beehives: {beehiveCount1}, Eggs: {eggCount1}");
				int currentDungeonType = rm.currentDungeonType;
				if (1 == 0)
				{
				}
				string text = currentDungeonType switch
				{
					1 => "Mansion", 
					4 => "Mineshaft", 
					0 => "Factory", 
					_ => "Unknown", 
				};
				if (1 == 0)
				{
				}
				string dungeonName = text;
				if (eggCount1 == 3)
				{
					SendChatMessage1($"{dungeonName} {scrapCount1} {beehiveCount1} Bird");
					yield break;
				}
				string message = $"{dungeonName} {scrapCount1} {beehiveCount1}";
				SendChatMessage1(message);
			}
			catch (Exception ex)
			{
				AutoTerminalScan.Logger.LogError((object)("[AutoScan] Error while counting or sending: " + ex));
			}
		}

		private static void SendChatMessage1(string message)
		{
			try
			{
				string text = message ?? string.Empty;
				if (text.Length > 50)
				{
					text = text.Substring(0, 50);
				}
				if (AutoScanChatCache.lastReceivedChatMessage1 == text)
				{
					AutoTerminalScan.Logger.LogInfo((object)"[AutoScan] Duplicate. Not sending message.");
					return;
				}
				HUDManager instance = HUDManager.Instance;
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				if (!((Object)(object)instance == (Object)null) && !((Object)(object)localPlayerController == (Object)null))
				{
					if (text.Length > 50)
					{
						text = text.Substring(0, 50);
					}
					MethodInfo method = ((object)instance).GetType().GetMethod("AddTextToChatOnServer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						int num = (int)localPlayerController.playerClientId;
						method.Invoke(instance, new object[2] { text, num });
						AutoTerminalScan.Logger.LogInfo((object)("[AutoScan] Chat message '" + text + "'"));
					}
				}
			}
			catch (Exception ex)
			{
				AutoTerminalScan.Logger.LogError((object)("[AutoScan] Error sending chat message: " + ex));
			}
		}
	}
}