Please disclose if your mod was created primarily 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 ScanPlus v1.2.1
plugins/ScanPlus.dll
Decompiled 5 days agousing 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 System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AidanTweedy")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Ship scanner mod for Lethal Company")] [assembly: AssemblyFileVersion("1.2.1.0")] [assembly: AssemblyInformationalVersion("1.2.1+aa37098608aeea49035588e044b94b7513069da0")] [assembly: AssemblyProduct("ScanPlus")] [assembly: AssemblyTitle("ScanPlus")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/AidanTweedy/scanplus")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.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 ScanPlus { public class ConfigManager { private ConfigEntry<int> _detailLevel; private ConfigEntry<bool> _shipUpgrade; private ConfigEntry<int> _upgradePrice; private ConfigEntry<string> _commandStrings; private ConfigFile _config; private static readonly string[] ScannerCommands = new string[5] { "irscan", "infrared", "infraredscanner", "scanlife", "scanenemy" }; public int DetailLevel => _detailLevel.Value; public bool ShipUpgrade => _shipUpgrade.Value; public int UpgradePrice => _upgradePrice.Value; public HashSet<string> CommandStrings => (from s in _commandStrings.Value.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(Utils.NormalizeCommand) where !string.IsNullOrWhiteSpace(s) select s).ToHashSet(); public ConfigManager(ConfigFile config) { _config = config; } public void LoadConfigurations() { _detailLevel = _config.Bind<int>("DETAIL", "DetailLevel", 2, "Life Scan Detail -> | 0 = LOW | 1 = MEDIUM | 2 = HIGH | 3 = EXCESSIVE"); _shipUpgrade = _config.Bind<bool>("PREFERENCES", "ShipUpgrade", true, "Enable Ship Upgrade -> | false = No | true = Yes"); _upgradePrice = _config.Bind<int>("PREFERENCES", "UpgradePrice", 300, "Ship Scanner Upgrade Cost"); _commandStrings = _config.Bind<string>("PREFERENCES", "CommandStrings", string.Join(",", ScannerCommands), "Comma-Separated Terminal Commands to Activate IR Scanner"); } } public class Scanner { private ConfigManager ConfigManager; private UnlockableManager UnlockableManager; internal const string DefaultString = "Infrared Scanner unavailable - required upgrade not installed.\n\n"; public static Scanner Instance { get; private set; } public Scanner(ConfigManager _configManager, UnlockableManager _unlockableManager) { Instance = this; ConfigManager = _configManager; UnlockableManager = _unlockableManager; ScanPlus.Harmony.PatchAll(typeof(Scanner)); } [HarmonyPrefix] [HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")] public static bool ParsePlayerSentence(ref TerminalNode __result, Terminal __instance) { string item = Utils.NormalizeCommand(__instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded)); if (Instance.ConfigManager.CommandStrings.Contains(item)) { TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>(); if (Instance.UseInfraredScan()) { val.displayText = Instance.BuildEnemyString(); val.clearPreviousText = true; } else { val.displayText = "Infrared Scanner unavailable - required upgrade not installed.\n\n"; val.clearPreviousText = true; } __result = val; return false; } return true; } public string BuildEnemyString() { List<IGrouping<string, EnemyAI>> list = (from ai in RoundManager.Instance.SpawnedEnemies group ai by ai.enemyType.enemyName into g orderby g.Key select g).ToList(); if (list.Count == 0) { return "No life detected.\n"; } int num = list.SelectMany((IGrouping<string, EnemyAI> group) => group).Count(); float num2 = (from ai in list.SelectMany((IGrouping<string, EnemyAI> @group) => @group) where !ai.enemyType.isDaytimeEnemy select ai).Sum(delegate(EnemyAI ai) { if ((Object)(object)ai?.enemyType == (Object)null) { return 0f; } FieldInfo field = ((object)ai.enemyType).GetType().GetField("PowerLevel"); return (!(field != null)) ? 0f : Convert.ToSingle(field.GetValue(ai.enemyType)); }); int num3 = RoundManager.Instance.currentLevel.maxEnemyPowerCount + RoundManager.Instance.currentLevel.maxOutsideEnemyPowerCount; string text = BuildColoredPercentage(num2 / (float)num3); string nextSpawn = GetNextSpawn(); StringBuilder stringBuilder = new StringBuilder(); switch (ConfigManager.DetailLevel) { case 0: stringBuilder.Append("Threat level: " + text); break; case 1: stringBuilder.Append($"Threat level: {text}\n\n{num} lifeforms detected, totalling a threat level of {(int)num2}."); break; case 2: stringBuilder.Append($"Threat level: {text}\n\n{num} lifeforms detected, totalling a threat level of {(int)num2}.\n\nLife detected:"); foreach (IGrouping<string, EnemyAI> item in list) { stringBuilder.AppendLine($"\n {item.Key}: {item.Count()}"); } break; case 3: stringBuilder.Append($"Threat level: {text}\n\n{num} lifeforms detected, totalling a threat level of {(int)num2}.\n\nLife detected:"); foreach (IGrouping<string, EnemyAI> item2 in list) { stringBuilder.AppendLine($"\n {item2.Key}: {item2.Count()}"); } stringBuilder.AppendLine("\nNext spawn: " + nextSpawn); break; } stringBuilder.AppendLine(); return stringBuilder.ToString(); } private static string BuildColoredPercentage(float value) { float num = Math.Max(0f, Math.Min(1f, value)); int num2; int num3; if ((double)num <= 0.5) { num2 = (int)(num * 2f * 255f); num3 = 255; } else { num2 = 255; num3 = (int)((1.0 - (double)num) * 2.0 * 255.0); } string text = $"#{num2:X2}{num3:X2}00"; string text2 = (num * 100f).ToString("0.##") + "%"; return "<color=" + text + ">" + text2 + "</color>"; } private static string GetNextSpawn() { if ((float)(RoundManager.Instance.enemySpawnTimes.Any((int t) => (float)t > RoundManager.Instance.timeScript.currentDayTime) ? RoundManager.Instance.enemySpawnTimes.Min() : (-1)) - RoundManager.Instance.timeScript.currentDayTime >= 60f) { return "Incoming"; } return "Unknown"; } public bool UseInfraredScan() { if (!ConfigManager.ShipUpgrade) { return true; } if (UnlockableManager.IsScannerUnlocked()) { return true; } return false; } } [BepInPlugin("ScanPlus", "ScanPlus", "1.2.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class ScanPlus : BaseUnityPlugin { internal static ManualLogSource Log = null; internal static Harmony Harmony = new Harmony("ScanPlus"); private ConfigManager _configManager; private UnlockableManager _unlockableManager; internal Scanner _scanner; public static ScanPlus Instance { get; private set; } private void Awake() { Instance = this; Log = ((BaseUnityPlugin)this).Logger; _configManager = new ConfigManager(((BaseUnityPlugin)this).Config); _configManager.LoadConfigurations(); _unlockableManager = new UnlockableManager(_configManager); _scanner = new Scanner(_configManager, _unlockableManager); ((BaseUnityPlugin)this).Logger.LogInfo((object)"ScanPlus is loaded"); } } public class UnlockableManager { private ConfigManager ConfigManager; private const string UpgradeName = "Infrared Scanner"; private const string UpgradeInfo = "\nUpgrades the ship's scanner with an infrared sensor, allowing for the detection of lifeforms present on the current moon.\n"; private int UpgradePrice; internal UnlockableItem ScanUpgrade = new UnlockableItem { unlockableName = "Infrared Scanner", spawnPrefab = false, alwaysInStock = true, prefabObject = null, unlockableType = 1, IsPlaceable = false, maxNumber = 1, canBeStored = false, alreadyUnlocked = false }; public static UnlockableManager Instance { get; private set; } public UnlockableManager(ConfigManager _configManager) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown Instance = this; ConfigManager = _configManager; if (ConfigManager.ShipUpgrade) { ScanPlus.Log.LogInfo((object)"ScanPlus: adding scanner to store"); ScanPlus.Harmony.PatchAll(typeof(UnlockableManager)); } } [HarmonyPostfix] [HarmonyPatch(typeof(Terminal), "Awake")] public static void TerminalAwake(Terminal __instance) { try { Instance?.AddScannerToStore(__instance); } catch (Exception arg) { ScanPlus.Log.LogInfo((object)string.Format("{0}: error occurred adding scanner to store:\n{1}", "ScanPlus", arg)); } } [HarmonyPrefix] [HarmonyPatch(typeof(Terminal), "TextPostProcess")] public static void TextPostProcess(ref string modifiedDisplayText, TerminalNode node) { try { if (modifiedDisplayText.Contains("[buyableItemsList]") && modifiedDisplayText.Contains("[unlockablesSelectionList]")) { int num = modifiedDisplayText.IndexOf(":"); string value = string.Format("\n* {0} // Price: ${1}", "Infrared Scanner", Instance.UpgradePrice); modifiedDisplayText = modifiedDisplayText.Insert(num + 1, value); } } catch (Exception ex) { ScanPlus.Log.LogError((object)ex); } } private static TerminalKeyword CreateKeyword(string word, TerminalKeyword defaultVerb) { TerminalKeyword obj = ScriptableObject.CreateInstance<TerminalKeyword>(); ((Object)obj).name = word; obj.word = word; obj.isVerb = false; obj.accessTerminalObjects = false; obj.defaultVerb = defaultVerb; return obj; } public void AddScannerToStore(Terminal terminal) { //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Expected O, but got Unknown //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Expected O, but got Unknown //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Expected O, but got Unknown //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Expected O, but got Unknown int num = -1; UnlockablesList unlockablesList = StartOfRound.Instance.unlockablesList; if (unlockablesList.unlockables.FindIndex((UnlockableItem unlockable) => unlockable.unlockableName == "Infrared Scanner") == -1) { TerminalKeyword val = terminal.terminalNodes.allKeywords.First((TerminalKeyword keyword) => keyword.word == "buy"); TerminalNode result = val.compatibleNouns[0].result.terminalOptions[1].result; TerminalKeyword val2 = terminal.terminalNodes.allKeywords.First((TerminalKeyword keyword) => keyword.word == "info"); TerminalKeyword val3 = CreateKeyword("Infrared Scanner".ToLowerInvariant().Replace(" ", "") ?? "", val); UpgradePrice = ConfigManager.UpgradePrice; unlockablesList.unlockables.Capacity++; unlockablesList.unlockables.Add(ScanUpgrade); num = unlockablesList.unlockables.FindIndex((UnlockableItem unlockable) => unlockable.unlockableName == "Infrared Scanner"); TerminalNode val4 = ScriptableObject.CreateInstance<TerminalNode>(); ((Object)val4).name = "Infrared Scanner".Replace(" ", "-") + "BuyNode2"; val4.displayText = "Ordered Infrared Scanner! Your new balance is [playerCredits].\n\n"; val4.clearPreviousText = true; val4.maxCharactersToType = 15; val4.buyItemIndex = -1; val4.shipUnlockableID = num; val4.buyUnlockable = true; val4.creatureName = "Infrared Scanner"; val4.isConfirmationNode = false; val4.itemCost = UpgradePrice; TerminalNode val5 = ScriptableObject.CreateInstance<TerminalNode>(); ((Object)val5).name = "Infrared Scanner".Replace(" ", "-") + "BuyNode1"; val5.displayText = "You have requested to order Infrared Scanner.\nTotal cost of item: [totalCost].\n\nPlease CONFIRM or DENY.\n\n"; val5.clearPreviousText = true; val5.maxCharactersToType = 15; val5.shipUnlockableID = num; val5.itemCost = UpgradePrice; val5.creatureName = "Infrared Scanner"; val5.overrideOptions = true; val5.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2] { new CompatibleNoun(terminal.terminalNodes.allKeywords.First((TerminalKeyword keyword2) => keyword2.word == "confirm"), val4), new CompatibleNoun(terminal.terminalNodes.allKeywords.First((TerminalKeyword keyword2) => keyword2.word == "deny"), result) }; string displayText = "\nUpgrades the ship's scanner with an infrared sensor, allowing for the detection of lifeforms present on the current moon.\n"; TerminalNode val6 = ScriptableObject.CreateInstance<TerminalNode>(); ((Object)val6).name = "Infrared Scanner".Replace(" ", "-") + "InfoNode"; val6.displayText = displayText; val6.clearPreviousText = true; val6.maxCharactersToType = 25; List<TerminalKeyword> list = terminal.terminalNodes.allKeywords.ToList(); list.Add(val3); terminal.terminalNodes.allKeywords = list.ToArray(); List<CompatibleNoun> list2 = val.compatibleNouns.ToList(); list2.Add(new CompatibleNoun(val3, val5)); val.compatibleNouns = list2.ToArray(); List<CompatibleNoun> list3 = val2.compatibleNouns.ToList(); list3.Add(new CompatibleNoun(val3, val6)); val2.compatibleNouns = list3.ToArray(); ScanPlus.Log.LogInfo((object)"ScanPlus: successfully added Infrared Scanner to the store."); } } public bool IsScannerUnlocked() { return ScanUpgrade?.hasBeenUnlockedByPlayer ?? false; } } public static class Utils { public static string NormalizeCommand(string input) { return new string((from c in input.ToLowerInvariant() where !char.IsWhiteSpace(c) && c != '-' && c != '_' select c).ToArray()); } } public static class PluginInfo { public const string PLUGIN_GUID = "ScanPlus"; public const string PLUGIN_NAME = "ScanPlus"; public const string PLUGIN_VERSION = "1.2.1"; } }