Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of AutoScan v2.0.5
abu.AutoScan.dll
Decompiled 4 months agousing 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("2.0.5.0")] [assembly: AssemblyInformationalVersion("2.0.5+a1f11cca079852068b43d7fab3168557c50bc01f")] [assembly: AssemblyProduct("AutoScan")] [assembly: AssemblyTitle("abu.AutoScan")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.0.5.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", "2.0.5")] public class AutoScan : BaseUnityPlugin { [HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")] internal class AutoAnnouncePatch { [CompilerGenerated] private sealed class <DelayedAnnounce>d__2 : IEnumerator<object>, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public StartOfRound __instance; private bool <exactValue>5__1; private string <beforeerror>5__2; private int <beforeitems>5__3; private int <beforevalue>5__4; private string <aftererror>5__5; private int <afteritems>5__6; private int <aftervalue>5__7; private string <msg>5__8; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <DelayedAnnounce>d__2(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <beforeerror>5__2 = null; <aftererror>5__5 = null; <msg>5__8 = null; <>1__state = -2; } private bool MoveNext() { //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; ReloadConfig(); <exactValue>5__1 = AnnounceExactValue && ((NetworkBehaviour)__instance).IsServer; if (!AutoAnnounce || (!((NetworkBehaviour)__instance).IsServer && HostOnly)) { return false; } <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 1; return true; case 1: <>1__state = -1; if (Countitems(<exactValue>5__1, out <beforeerror>5__2, out <beforeitems>5__3, out <beforevalue>5__4)) { Logger.LogInfo((object)$"{<beforeitems>5__3} {<beforevalue>5__4}"); } else { Logger.LogError((object)("Error while counting items: " + <beforeerror>5__2)); } <>2__current = (object)new WaitForSeconds(ScanDelay); <>1__state = 2; return true; case 2: <>1__state = -1; Logger.LogDebug((object)$">> DelayedAutoAnnounce({__instance}) IsServer:{((NetworkBehaviour)__instance).IsServer} AutoAnnounce:{AutoAnnounce}"); if (Countitems(<exactValue>5__1, out <aftererror>5__5, out <afteritems>5__6, out <aftervalue>5__7)) { Logger.LogInfo((object)$"{<afteritems>5__6} {<aftervalue>5__7}"); if (<afteritems>5__6 > 0) { <msg>5__8 = $"<color={AnnounceColor}>{AnnouncePrefix} {<beforeitems>5__3}"; if (AnnounceOutsideLoot) { <msg>5__8 += $"/{<afteritems>5__6 - <beforeitems>5__3}"; } if (AnnounceValue) { if (<exactValue>5__1) { <msg>5__8 += $" {<beforevalue>5__4}"; } else { <msg>5__8 += $" ≈{<beforevalue>5__4}"; } } if (AnnounceOutsideLoot && AnnounceValue) { <msg>5__8 += $"/{<aftervalue>5__7 - <beforevalue>5__4}"; } <msg>5__8 += "</color>"; HUDManager.Instance.AddTextMessageServerRpc(<msg>5__8); <msg>5__8 = null; } } else { Logger.LogError((object)("Error while counting items: " + <aftererror>5__5)); HUDManager.Instance.AddTextMessageServerRpc("<color=#ff0000>Error while counting items: " + <aftererror>5__5 + "</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(bool exactValue, out string? error, out int outsideShip, out int outsideShipValue) { outsideShip = 0; outsideShipValue = 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))) { outsideShip++; outsideShipValue += a(!exactValue, 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 void Postfix(ref StartOfRound __instance) { ((MonoBehaviour)__instance).StartCoroutine(DelayedAnnounce(__instance)); } [IteratorStateMachine(typeof(<DelayedAnnounce>d__2))] private static IEnumerator DelayedAnnounce(StartOfRound __instance) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <DelayedAnnounce>d__2(0) { __instance = __instance }; } } private ConfigEntry<bool>? autoAnnounce; private ConfigEntry<bool>? announceOutsideLoot; private ConfigEntry<bool>? announceValue; private ConfigEntry<bool>? hostOnly; private ConfigEntry<float>? scanDelay; private ConfigEntry<bool>? announceExactValue; private ConfigEntry<string>? announcePrefix; private ConfigEntry<string>? announceColor; 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); public static bool AnnounceExactValue { get { AutoScan instance = Instance; return instance != null && (instance.announceExactValue?.Value).GetValueOrDefault(); } } public static string AnnouncePrefix => Instance?.announcePrefix?.Value ?? "Scan:"; public static string AnnounceColor => Instance?.announceColor?.Value ?? "#00ff00"; private void Awake() { //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013f: 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"); announceExactValue = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AnnounceExactValue", false, "Announce the exact value instead of the terminal's randomized value (Only works for host)"); 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"); announcePrefix = ((BaseUnityPlugin)this).Config.Bind<string>("General", "AnnouncePrefix", "Scan:", "Prefix to use in announce messages"); announceColor = ((BaseUnityPlugin)this).Config.Bind<string>("General", "AnnounceColor", "#00ff00", "Color to use in announce messages (in hex format, e.g. #RRGGBB)"); if (Harmony == null) { Harmony = new Harmony("abu.AutoScan"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(); Logger.LogDebug((object)"Finished patching!"); Logger.LogInfo((object)"abu.AutoScan v2.0.5 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 = "2.0.5"; } }