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.6.0")] [assembly: AssemblyInformationalVersion("1.0.6")] [assembly: AssemblyProduct("Autoscan")] [assembly: AssemblyTitle("Happyness.Autoscan")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.6.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.6"; } } namespace AutoTerminalScan { [BepInPlugin("Happyness.Autoscan", "Autoscan", "1.0.6")] 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(); 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(); 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(); Object.DontDestroyOnLoad((Object)(object)val); } ((MonoBehaviour)coroutineProxy).StartCoroutine(routine); } } [HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")] public static class WaitForScrapToSpawnToSyncPatch01 { [HarmonyPostfix] public static void Postfix(RoundManager __instance) { string text = ((object)RoundManager.Instance.currentLevel).ToString(); if (!(text == "AssuranceLevel (SelectableLevel)") && !share.sentToday) { share.sentToday = true; AutoTerminalScan.StartSafeCoroutine01(share.CountScrapAndBeehives(__instance)); } } } [HarmonyPatch(typeof(RoundManager), "SyncScrapValuesClientRpc")] public static class WaitForScrapToSpawnToSyncPatch02 { [HarmonyPostfix] public static void Postfix(RoundManager __instance) { string text = ((object)RoundManager.Instance.currentLevel).ToString(); if (!(text != "AssuranceLevel (SelectableLevel)") && !share.sentToday) { share.sentToday = true; AutoTerminalScan.StartSafeCoroutine01(share.CountScrapAndBeehives(__instance)); } } } public static class share { [CompilerGenerated] private sealed class d__3 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public RoundManager rm; private string 5__1; private GrabbableObject[] 5__2; private int 5__3; private int 5__4; private int 5__5; private List 5__6; private string 5__7; private string 5__8; private GrabbableObject[] <>s__9; private int <>s__10; private GrabbableObject 5__11; private int <>s__12; private Exception 5__13; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__3(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__1 = null; 5__2 = null; 5__6 = null; 5__7 = null; 5__8 = null; <>s__9 = null; 5__11 = null; 5__13 = null; <>1__state = -2; } private bool MoveNext() { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; 5__1 = ((object)RoundManager.Instance.currentLevel).ToString(); AutoTerminalScan.Logger.LogInfo((object)5__1); if (Time.time - lastCleanupTime < 10f) { return false; } if (5__1 == "CompanyBuildingLevel (SelectableLevel)") { return false; } lastCleanupTime = Time.time; <>2__current = (object)new WaitForSeconds(5f); <>1__state = 1; return true; case 1: <>1__state = -1; try { if ((Object)(object)rm == (Object)null) { return false; } 5__2 = Object.FindObjectsOfType(); 5__3 = 0; 5__4 = 0; 5__5 = 0; 5__6 = new List(); <>s__9 = 5__2; for (<>s__10 = 0; <>s__10 < <>s__9.Length; <>s__10++) { 5__11 = <>s__9[<>s__10]; if ((Object)(object)5__11.itemProperties != (Object)null && 5__11.itemProperties.isScrap && !5__11.scrapPersistedThroughRounds && !5__11.isInShipRoom) { 5__6.Add(5__11); } if (!5__11.isInShipRoom && ((Object)5__11).name.Contains("Hive", StringComparison.OrdinalIgnoreCase)) { 5__4++; } if (!5__11.isInShipRoom && ((Object)5__11).name.Contains("KiwiBabyItem", StringComparison.OrdinalIgnoreCase)) { 5__5++; } 5__11 = null; } <>s__9 = null; 5__3 = 5__6.Count - 5__4 - 5__5; if (5__3 < 0) { 5__3 = 0; } AutoTerminalScan.Logger.LogInfo((object)$"[AutoScan] Scrap: {5__3}, Beehives: {5__4}, Eggs: {5__5}"); <>s__12 = rm.currentDungeonType; if (1 == 0) { } string text = <>s__12 switch { 1 => "Mansion", 3 => "Factory (march)", 4 => "Mineshaft", 0 => "Factory", _ => "Unknown", }; if (1 == 0) { } 5__7 = text; 5__8 = ((5__5 == 3) ? $"{5__7} {5__3} {5__4} Bird" : $"{5__7} {5__3} {5__4}"); SendChatMessage(5__8); 5__2 = null; 5__6 = null; 5__7 = null; 5__8 = null; } catch (Exception ex) { 5__13 = ex; AutoTerminalScan.Logger.LogError((object)("[AutoScan] Error while counting or sending: " + 5__13)); } 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 float lastCleanupTime = -999f; public const float CleanupCooldown = 10f; public static bool sentToday = false; [IteratorStateMachine(typeof(d__3))] public static IEnumerator CountScrapAndBeehives(RoundManager rm) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__3(0) { rm = rm }; } public static void SendChatMessage(string message) { try { string text = message ?? string.Empty; if (text.Length > 50) { text = text.Substring(0, 50); } if (AutoScanChatCache.lastReceivedChatMessage == 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)) { 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 + "'")); sentToday = false; } } } catch (Exception ex) { AutoTerminalScan.Logger.LogError((object)("[AutoScan] Error sending chat message: " + ex)); } } } public static class AutoScanChatCache { public static string lastReceivedChatMessage = ""; } [HarmonyPatch(typeof(HUDManager), "AddChatMessage")] public static class CaptureIncomingChatPatch1 { [HarmonyPostfix] public static void PostfixAM(string chatMessage) { if (!string.IsNullOrWhiteSpace(chatMessage)) { AutoScanChatCache.lastReceivedChatMessage = chatMessage; } } } }