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 TerminalUtils v0.0.1
TerminalUtils.dll
Decompiled 7 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; 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 ConsoleTables; using Dawn; using Dawn.Internal; using DunGen.Graph; using HarmonyLib; using LethalLevelLoader; using Microsoft.CodeAnalysis; using MrovLib; using MrovLib.Definitions; using On; using TerminalUtils.Commands; using TerminalUtils.Compatibility; using TerminalUtils.Definitions; using TerminalUtils.Enums; using TerminalUtils.InfoTypes.Moons; using TerminalUtils.Nodes; using Unity.Netcode; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("com.github.teamxiaolan.dawnlib.compatibility")] [assembly: IgnoresAccessChecksTo("com.github.teamxiaolan.dawnlib")] [assembly: IgnoresAccessChecksTo("com.github.teamxiaolan.dawnlib.dusk")] [assembly: IgnoresAccessChecksTo("com.github.teamxiaolan.dawnlib.interfaces")] [assembly: IgnoresAccessChecksTo("LethalLevelLoader")] [assembly: IgnoresAccessChecksTo("LethalLevelLoader.Patcher")] [assembly: IgnoresAccessChecksTo("MrovLib")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TerminalUtils")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("A template for Lethal Company")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: AssemblyInformationalVersion("0.0.1+33607333237e5cbb4807f53a49c2f993d6a8fb1f")] [assembly: AssemblyProduct("TerminalUtils")] [assembly: AssemblyTitle("TerminalUtils")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace TerminalUtils { public static class CommandManager { public static TerminalNode CommandNode; internal static TerminalNode RedirectToMoonsNode; internal static TerminalNode RedirectToStoreNode; public static List<TerminalCommandNode> Commands { get; set; } = new List<TerminalCommandNode>(); public static Dictionary<string, TerminalCommandNode> CommandLookup { get { Dictionary<string, TerminalCommandNode> lookup = new Dictionary<string, TerminalCommandNode>(); Commands.ForEach(delegate(TerminalCommandNode command) { lookup[((CommandNode)command).Name] = command; }); return lookup; } } public static void Init() { Commands.Clear(); CommandNode = TerminalNodeManager.CreateTerminalNode("TerminalUtilsCommandNode"); CommandNode.acceptAnything = false; RedirectToMoonsNode = TerminalNodeManager.CreateTerminalNode("TerminalUtilsRedirectToMoonsNode"); RedirectToMoonsNode.acceptAnything = false; RedirectToStoreNode = TerminalNodeManager.CreateTerminalNode("TerminalUtilsRedirectToStoreNode"); RedirectToStoreNode.acceptAnything = false; } public static TerminalNode RunWeatherCommand(TerminalCommandNode command, string[] args) { string displayText = ""; if (command == null) { CommandNode.displayText = $"Command '{command}' not found."; return CommandNode; } if (command.Subcommands.Count == 0 || args.Length < 1) { ((Logger)Plugin.debugLogger).LogDebug("Running command '" + ((CommandNode)command).Name + "' with no subcommand"); displayText = command.Execute(args); } if ((Object)(object)command.RedirectToNode != (Object)null) { ((Logger)Plugin.debugLogger).LogDebug("Redirecting to node '" + ((Object)command.RedirectToNode).name + "'"); return command.RedirectToNode; } CommandNode.displayText = displayText; return CommandNode; } } public class ConfigManager { internal static ConfigFile configFile; public static ConfigManager Instance { get; private set; } public static ConfigEntry<LoggingType> LoggingLevels { get; private set; } public static ConfigEntry<string> PreviewInfoType { get; private set; } public static ConfigEntry<string> FilterInfoType { get; private set; } public static ConfigEntry<string> SortInfoType { get; private set; } public static void Init(ConfigFile config) { Instance = new ConfigManager(config); } private ConfigManager(ConfigFile config) { configFile = config; LoggingLevels = configFile.Bind<LoggingType>("Debug", "Logging Levels", (LoggingType)0, "Set the logging level for the mod"); PreviewInfoType = configFile.Bind<string>("General", "Preview Info Type", Defaults.defaultPreviewType, "Set the preview info type. Must be the name of an existing preview info type."); FilterInfoType = configFile.Bind<string>("General", "Filter Info Type", Defaults.defaultFilterType, "Set the filter info type. Must be the name of an existing filter info type."); SortInfoType = configFile.Bind<string>("General", "Sort Info Type", Defaults.defaultSortType, "Set the default sort info type. Must be the name of an existing sort info type."); } } public static class Defaults { public static readonly int terminalWidth = 48; internal static readonly int planetWeatherWidth = 18; internal static readonly int planetNameWidth = terminalWidth + 2 - planetWeatherWidth - 9; internal static readonly int itemNameWidth = terminalWidth - 9 - 10; internal static readonly int dividerLength = 17; internal static readonly string defaultPreviewType = "Name;Price;Weather"; internal static readonly string defaultFilterType = "None"; internal static readonly string defaultSortType = "None"; } public static class InfoTypeResolver { public static List<PreviewInfoType<SelectableLevel>> GetPreviewInfoType(string name) { if (string.IsNullOrEmpty(name)) { return (from typeName in Defaults.defaultPreviewType.Split(";") select TerminalManager.PreviewInfoTypes[typeName]).ToList(); } if (!name.Contains("Name")) { name = "Name;" + name; ((Logger)Plugin.debugLogger).LogDebug("Preview type did not contain 'Name', defaulting to 'Name;" + name + "'"); } string[] source = (from s in name.Split(';') where !string.IsNullOrWhiteSpace(s) select s.Trim()).ToArray(); return (from typeName in source select TerminalManager.PreviewInfoTypes.FirstOrDefault((KeyValuePair<string, PreviewInfoType<SelectableLevel>> info) => info.Key.ToLowerInvariant() == typeName.ToLowerInvariant()) into info where info.Value != null select info.Value).ToList(); } public static FilterInfoType<SelectableLevel> GetFilterInfoType(string name) { if (string.IsNullOrEmpty(name)) { return TerminalManager.FilterInfoTypes["None"]; } return TerminalManager.FilterInfoTypes.FirstOrDefault((KeyValuePair<string, FilterInfoType<SelectableLevel>> info) => info.Key.ToLowerInvariant() == name.ToLowerInvariant()).Value; } public static SortInfoType<SelectableLevel> GetSortInfoType(string name) { if (string.IsNullOrEmpty(name)) { return TerminalManager.SortInfoTypes["None"]; } return TerminalManager.SortInfoTypes.FirstOrDefault((KeyValuePair<string, SortInfoType<SelectableLevel>> info) => info.Key.ToLowerInvariant() == name.ToLowerInvariant()).Value; } } public class Logger : Logger { public Logger(string SourceName, LoggingType defaultLoggingType = 1) : base(SourceName, defaultLoggingType) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) ((Logger)this).ModName = SourceName; ((Logger)this).LogSource = Logger.CreateLogSource("TerminalUtils"); ((Logger)this)._name = SourceName; } public override bool ShouldLog(LoggingType type) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) return ConfigManager.LoggingLevels.Value >= type; } } public static class NodeReplacementManager { internal static List<TerminalNodeReplacement> RegisteredNodes = new List<TerminalNodeReplacement>(); } [BepInPlugin("mrov.TerminalUtils", "TerminalUtils", "0.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { internal static ManualLogSource logger; internal static Logger debugLogger = new Logger("Debug", (LoggingType)2); internal static Harmony harmony = new Harmony("mrov.TerminalUtils"); internal static LethalLevelLoaderCompatibility LLLCompatibility = new LethalLevelLoaderCompatibility("imabatby.lethallevelloader"); internal static DawnLibCompatibility DawnCompatibility = new DawnLibCompatibility("com.github.teamxiaolan.dawnlib"); private void Awake() { logger = ((BaseUnityPlugin)this).Logger; harmony.PatchAll(); ConfigManager.Init(((BaseUnityPlugin)this).Config); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin mrov.TerminalUtils is loaded!"); } } public static class StartupManager { public static void Init(Terminal _instance) { TerminalManager.Init(_instance); CommandManager.Init(); PreviewCommand item = new PreviewCommand(); CommandManager.Commands.Add(item); SortCommand item2 = new SortCommand(); CommandManager.Commands.Add(item2); FilterCommand item3 = new FilterCommand(); CommandManager.Commands.Add(item3); SimulateCommand item4 = new SimulateCommand(); CommandManager.Commands.Add(item4); } } public static class TerminalManager { public static Dictionary<string, PreviewInfoType<SelectableLevel>> PreviewInfoTypes = new Dictionary<string, PreviewInfoType<SelectableLevel>>(); public static Dictionary<string, FilterInfoType<SelectableLevel>> FilterInfoTypes = new Dictionary<string, FilterInfoType<SelectableLevel>>(); public static Dictionary<string, SortInfoType<SelectableLevel>> SortInfoTypes = new Dictionary<string, SortInfoType<SelectableLevel>>(); public static Dictionary<TerminalNode, TerminalNodeReplacement> NodeReplacements = new Dictionary<TerminalNode, TerminalNodeReplacement>(); public static Terminal Terminal { get; private set; } public static TerminalNode MoonsPage { get; private set; } public static TerminalNode StorePage { get; private set; } public static List<PreviewInfoType<SelectableLevel>> CurrentPreviewInfoType { get; set; } public static FilterInfoType<SelectableLevel> CurrentFilterInfoType { get; set; } public static SortInfoType<SelectableLevel> CurrentSortInfoType { get; set; } public static void Init(Terminal terminal) { Terminal = terminal; MoonsPage = ContentManager.MoonsKeyword.specialKeywordResult; StorePage = ((IEnumerable<TerminalNode>)ContentManager.Nodes).FirstOrDefault((Func<TerminalNode, bool>)((TerminalNode node) => ((Object)node).name == "0_StoreHub")); RegisterLocalInfoTypes(); CurrentPreviewInfoType = InfoTypeResolver.GetPreviewInfoType(ConfigManager.PreviewInfoType.Value); CurrentFilterInfoType = InfoTypeResolver.GetFilterInfoType(ConfigManager.FilterInfoType.Value); CurrentSortInfoType = InfoTypeResolver.GetSortInfoType(ConfigManager.SortInfoType.Value); NodeReplacements = new Dictionary<TerminalNode, TerminalNodeReplacement> { { MoonsPage, new MoonCatalogue() } }; } private static void RegisterLocalInfoTypes() { PreviewInfoTypes.Add("Name", new PreviewName()); PreviewInfoTypes.Add("Price", new PreviewPrice()); PreviewInfoTypes.Add("Weather", new PreviewWeather()); PreviewInfoTypes.Add("Difficulty", new PreviewDifficulty()); SortInfoTypes.Add("None", new SortNone()); SortInfoTypes.Add("Name", new SortName()); SortInfoTypes.Add("Price", new SortPrice()); FilterInfoTypes.Add("None", new FilterNone()); FilterInfoTypes.Add("Price", new FilterPrice()); FilterInfoTypes.Add("Weather", new FilterWeather()); } } public class TerminalNodeManager { internal static TerminalNode lastResolvedNode; public static void Init() { } public static TerminalKeyword AddVerb(string name, string word) { TerminalKeyword val = ScriptableObject.CreateInstance<TerminalKeyword>(); ((Object)val).name = name; val.word = word; val.isVerb = true; ContentManager.AddTerminalKeywords(new List<TerminalKeyword>(1) { val }); return val; } public static void AddTerminalContent(List<TerminalNode> terminalNodes = null, List<TerminalKeyword> terminalKeywords = null) { if (terminalNodes != null && terminalNodes.Count > 0) { ContentManager.AddTerminalNodes(terminalNodes); } if (terminalKeywords != null && terminalKeywords.Count > 0) { ContentManager.AddTerminalKeywords(terminalKeywords); } } public static TerminalNode CreateTerminalNode(string name, string terminalEvent = "") { TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>(); ((Object)val).name = name; val.terminalEvent = terminalEvent; val.displayText = ""; val.clearPreviousText = true; val.acceptAnything = true; val.terminalOptions = Array.Empty<CompatibleNoun>(); val.maxCharactersToType = 25; val.itemCost = 0; val.buyItemIndex = -1; val.buyVehicleIndex = -1; val.buyRerouteToMoon = -1; val.displayPlanetInfo = -1; val.shipUnlockableID = -1; val.creatureFileID = -1; val.storyLogFileID = -1; val.playSyncedClip = -1; return val; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "mrov.TerminalUtils"; public const string PLUGIN_NAME = "TerminalUtils"; public const string PLUGIN_VERSION = "0.0.1"; } } namespace TerminalUtils.Patches { [HarmonyPatch(typeof(Terminal))] public static class TerminalLoadNewNodePatch { [HarmonyPrefix] [HarmonyPatch("LoadNewNode")] [HarmonyAfter(new string[] { "imabatby.lethallevelloader", "com.github.teamxiaolan.dawnlib", "mrov.TerminalFormatter" })] public static bool PatchMethod(Terminal __instance, TerminalNode node) { if (TerminalManager.NodeReplacements.ContainsKey(node)) { __instance.modifyingText = true; ((Selectable)__instance.screenText).interactable = true; TerminalNodeReplacement terminalNodeReplacement = TerminalManager.NodeReplacements[node]; Plugin.logger.LogInfo((object)("Replacing node " + ((Object)__instance.currentNode).name + " with " + terminalNodeReplacement.Name)); StringBuilder stringBuilder = new StringBuilder(); if (Object.op_Implicit((Object)(object)__instance.displayingPersistentImage)) { stringBuilder.Append("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); } stringBuilder.Append("\n\n"); stringBuilder.Append(terminalNodeReplacement.GetNodeText()); stringBuilder.Append("\n" + new string('-', 17) + "\n"); __instance.LoadTerminalImage(node); __instance.currentNode = node; __instance.screenText.text = stringBuilder.ToString(); __instance.currentText = stringBuilder.ToString(); __instance.textAdded = 0; return false; } return true; } } [HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")] internal class TerminalParsePlayerSentencePatch { [HarmonyPrefix] [HarmonyBefore(new string[] { "mrov.WeatherRegistry" })] public static bool GameMethodPatch(Terminal __instance, ref TerminalNode __result) { string text = __instance.screenText.text; int textAdded = __instance.textAdded; string text2 = text.Substring(text.Length - textAdded); text2 = __instance.RemovePunctuation(text2); List<string> list = text2.Split(' ').ToList(); if (list.Count >= 1 && CommandManager.CommandLookup.TryGetValue(list[0], out var value)) { ((Logger)Plugin.debugLogger).LogWarning("Command detected, passing to CommandManager"); if (list.Count >= 2) { string[] args = list.Skip(1).ToArray(); TerminalNode val = CommandManager.RunWeatherCommand(value, args); __result = val; return false; } return true; } return true; } } [HarmonyPatch(typeof(Terminal))] public static class TerminalStartPatch { [HarmonyPatch("Start")] [HarmonyPostfix] public static void Postfix(Terminal __instance) { StartupManager.Init(__instance); if (((CompatibilityHandler)Plugin.LLLCompatibility).IsModPresent) { Plugin.LLLCompatibility.RemoveMoonNodeEvent(); } } } } namespace TerminalUtils.Nodes { public class MoonCatalogue : TerminalNodeReplacement { public MoonCatalogue() : base("Moon Catalogue", TerminalManager.MoonsPage) { base.HelpText = " Welcome to the exomoons catalogue! \n Use ROUTE to set the autopilot. \n Use INFO to learn about a moon."; } public override string GetNodeText() { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown List<SelectableLevel> inputList = TerminalManager.CurrentFilterInfoType.Filter(LevelHelper.Levels); inputList = TerminalManager.CurrentSortInfoType.Sort(inputList); ((Logger)Plugin.debugLogger).LogDebug("Current preview types: " + string.Join(", ", TerminalManager.CurrentPreviewInfoType.Select((PreviewInfoType<SelectableLevel> info) => info.Name))); StringBuilder stringBuilder = new StringBuilder(); ConsoleTable val = new ConsoleTable(TerminalManager.CurrentPreviewInfoType.Select((PreviewInfoType<SelectableLevel> info) => info.Name).ToArray()); int num = 1; List<PreviewInfoType<SelectableLevel>> currentPreviewInfoType = TerminalManager.CurrentPreviewInfoType; foreach (SelectableLevel level in inputList) { ((Logger)Plugin.debugLogger).LogDebug("Current preview types: " + string.Join(", ", currentPreviewInfoType.Select((PreviewInfoType<SelectableLevel> info) => info.Name))); string[] array = currentPreviewInfoType.Select((PreviewInfoType<SelectableLevel> info) => info.Value(level)).ToArray(); object[] array2 = array; val.AddRow(array2); if (num % 3 == 0) { num = 1; array2 = currentPreviewInfoType.Select((PreviewInfoType<SelectableLevel> _) => "").ToArray(); val.AddRow(array2); } else { num++; } } stringBuilder.AppendLine((base.HelpText != null) ? ("\n" + base.HelpText + "\n\n") : ""); stringBuilder.Append($" The Company // Buying at {Mathf.RoundToInt(StartOfRound.Instance.companyBuyingRate * 100f)}% \n\n"); stringBuilder.Append(val.ToStringCustomDecoration(false, false, false)); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine("PREVIEW: " + string.Join(", ", currentPreviewInfoType.Select((PreviewInfoType<SelectableLevel> info) => info.Name)) + "\nSORT: " + TerminalManager.CurrentSortInfoType.Name + "; FILTER: " + TerminalManager.CurrentFilterInfoType.Name); return stringBuilder.ToString().TrimEnd(); } } } namespace TerminalUtils.InfoTypes.Moons { public class FilterNone : FilterInfoType<SelectableLevel> { public FilterNone() : base("None") { } public override List<SelectableLevel> Filter(List<SelectableLevel> inputList) { return inputList; } } public class FilterPrice : FilterInfoType<SelectableLevel> { public FilterPrice() : base("Price") { } public override List<SelectableLevel> Filter(List<SelectableLevel> inputList) { return inputList.Where((SelectableLevel lvl) => ContentManager.RouteDictionary.GetRoute(lvl).Price <= ContentManager.Terminal.groupCredits).ToList(); } } public class FilterWeather : FilterInfoType<SelectableLevel> { public FilterWeather() : base("Weather") { } public override List<SelectableLevel> Filter(List<SelectableLevel> inputList) { return inputList.Where((SelectableLevel lvl) => ContentManager.RouteDictionary.GetRoute(lvl).Price >= ContentManager.Terminal.groupCredits).ToList(); } } public class PreviewDifficulty : PreviewInfoType<SelectableLevel> { public PreviewDifficulty() : base("Difficulty") { } public override string Value(SelectableLevel inputValue) { return inputValue.riskLevel; } } public class PreviewName : PreviewInfoType<SelectableLevel> { public PreviewName() : base("Name") { base.MaxLength = LevelHelper.LongestPlanetName.Length; } public override string Value(SelectableLevel inputValue) { return StringResolver.GetAlphanumericName(inputValue); } } public class PreviewPrice : PreviewInfoType<SelectableLevel> { public PreviewPrice() : base("Price") { } public override string Value(SelectableLevel inputValue) { return $"${ContentManager.RouteDictionary.GetRoute(inputValue).Price}"; } } public class PreviewWeather : PreviewInfoType<SelectableLevel> { public PreviewWeather() : base("Weather") { } public override string Value(SelectableLevel inputValue) { return ((object)(LevelWeatherType)(ref inputValue.currentWeather)).ToString(); } } public class SortName : SortInfoType<SelectableLevel> { public SortName() : base("Name") { } public override List<SelectableLevel> Sort(List<SelectableLevel> inputList) { inputList.Sort((SelectableLevel a, SelectableLevel b) => StringResolver.GetAlphanumericName(a).CompareTo(StringResolver.GetAlphanumericName(b))); return inputList; } } public class SortNone : SortInfoType<SelectableLevel> { public SortNone() : base("None") { } public override List<SelectableLevel> Sort(List<SelectableLevel> inputList) { return inputList; } } public class SortPrice : SortInfoType<SelectableLevel> { public SortPrice() : base("Price") { } public override List<SelectableLevel> Sort(List<SelectableLevel> inputList) { inputList.Sort((SelectableLevel a, SelectableLevel b) => ContentManager.RouteDictionary.GetRoute(a).Price.CompareTo(ContentManager.RouteDictionary.GetRoute(b).Price)); return inputList; } } } namespace TerminalUtils.Enums { public enum TerminalDisplayType { Preview, Sort, Filter } } namespace TerminalUtils.Definitions { public abstract class ConfigHandler<T, CT> : ConfigHandler<T, CT> { public ConfigHandler(CT value) { ((ConfigHandler<T, CT>)this).DefaultValue = value; } } public class FilterInfoType<T> : TerminalInfoType { public FilterInfoType(string Name) { base.Name = Name; base.Type = TerminalDisplayType.Filter; } public virtual List<T> Filter(List<T> inputList) { return inputList; } } public interface ITerminalInfoType { string Name { get; } TerminalDisplayType Type { get; } } public class TerminalInfoType : ITerminalInfoType { public string Name { get; set; } public TerminalDisplayType Type { get; set; } public override string ToString() { return $"{Name} ({Type})"; } } public class PreviewGroup { public List<PreviewInfoType> PreviewInfoTypes { get; set; } } public class PreviewInfoType : TerminalInfoType { public int MaxLength { get; set; } = Defaults.terminalWidth; public PreviewInfoType(string Name) { base.Name = Name; base.Type = TerminalDisplayType.Preview; } } public abstract class PreviewInfoType<T> : PreviewInfoType { protected PreviewInfoType(string Name) : base(Name) { } public string ValueWithMaxLength(T inputValue) { string text = Value(inputValue); if (text.Length > base.MaxLength) { text = text.Substring(0, base.MaxLength - 3) + "..."; } return text; } public virtual string Value(T inputValue) { return ""; } public override string ToString() { return $"{base.Name} ({base.Type})"; } } public class SortInfoType<T> : TerminalInfoType { public SortInfoType(string Name) { base.Name = Name; base.Type = TerminalDisplayType.Sort; } public virtual List<T> Sort(List<T> inputList) { return inputList; } } public abstract class TerminalCommandNode : CommandNode { public List<TerminalCommandNode> Subcommands { get; set; } = new List<TerminalCommandNode>(); public bool HostOnly { get; set; } public int TerminalSound { get; set; } = -1; public TerminalNode RedirectToNode { get; set; } protected TerminalCommandNode(string Name) : base(Name) { } public virtual bool ShouldRun() { if (!HostOnly || ((NetworkBehaviour)StartOfRound.Instance).IsHost) { return true; } return false; } public virtual string Execute(string[] args) { return ""; } } public abstract class TerminalNodeReplacement { public StringBuilder stringBuilder = new StringBuilder(); public string Name { get; set; } public string HelpText { get; set; } public TerminalNode NodeToMatch { get; set; } public ConfigEntry<bool> Enabled { get; set; } public virtual bool IsNodeValid(TerminalNode node, Terminal terminal) { return true; } public abstract string GetNodeText(); public TerminalNodeReplacement(string name, TerminalNode NodeToMatch) { Name = name; this.NodeToMatch = NodeToMatch; Enabled = ConfigManager.configFile.Bind<bool>("Nodes", name, true, "Enable node " + name); NodeReplacementManager.RegisteredNodes.Add(this); ((Logger)Plugin.debugLogger).LogInfo("Registered node " + name); } } } namespace TerminalUtils.Compatibility { public class DawnLibCompatibility : CompatibilityHandler { public DawnLibCompatibility(string guid, string version = null) : base(guid, version, false) { } public override void Init() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown if (((CompatibilityHandler)this).IsModPresent) { Type type = AccessTools.TypeByName("Dawn.MoonRegistrationHandler"); Plugin.harmony.Patch((MethodBase)AccessTools.Method(type, "DynamicMoonCatalogue", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(DawnLibCompatibility), "InsertMoonCatalogueSkip", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null); } } public (bool locked, bool hidden) GetLevelStatus(SelectableLevel level) { TerminalPurchaseResult val = SelectableLevelExtensions.GetDawnInfo(level).DawnPurchaseInfo.PurchasePredicate.CanPurchase(); HiddenPurchaseResult val2 = (HiddenPurchaseResult)(object)((val is HiddenPurchaseResult) ? val : null); if (val2 == null) { if (!(val is FailedPurchaseResult)) { if (val is SuccessPurchaseResult) { return (false, false); } return (false, false); } return (true, false); } return (val2.IsFailure, true); } public static IEnumerable<CodeInstruction> InsertMoonCatalogueSkip(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null); val.Start().Insert((CodeInstruction[])(object)new CodeInstruction[6] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldarg_1, (object)null), new CodeInstruction(OpCodes.Ldarg_2, (object)null), new CodeInstruction(OpCodes.Ldarg_3, (object)null), new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.Method(typeof(orig_TextPostProcess), "Invoke", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Ret, (object)null) }); return val.InstructionEnumeration(); } public static Dictionary<string, int> GetDungeonRarities(SelectableLevel level) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, int> dictionary = new Dictionary<string, int>(); DawnMoonInfo dawnInfo = SelectableLevelExtensions.GetDawnInfo(level); List<DawnDungeonInfo> list = new List<DawnDungeonInfo>(); List<float> list2 = new List<float>(); foreach (DawnDungeonInfo value6 in ((Registry<DawnDungeonInfo>)(object)LethalContent.Dungeons).Values) { WeatherEffect currentWeatherEffect = TimeOfDayRefs.GetCurrentWeatherEffect(dawnInfo.Level); SpawnWeightContext val = new SpawnWeightContext(dawnInfo, (DawnDungeonInfo)null, (currentWeatherEffect != null) ? WeatherEffectExtensions.GetDawnInfo(currentWeatherEffect) : null); SpawnWeightContext val2 = ((SpawnWeightContext)(ref val)).WithExtra<int>(SpawnWeightExtraKeys.RoutingPriceKey, dawnInfo.DawnPurchaseInfo.Cost.Provide()); int valueOrDefault = ProviderTableSpawnWeightExtensions.GetFor<int?>(value6.Weights, ref val2).GetValueOrDefault(); if (valueOrDefault > 0) { list.Add(value6); list2.Add(valueOrDefault); } } for (int i = 0; i < list.Count; i++) { for (int j = i + 1; j < list.Count; j++) { if (list2[i] < list2[j]) { List<DawnDungeonInfo> list3 = list; int index = i; int index2 = j; DawnDungeonInfo value = list[j]; DawnDungeonInfo value2 = list[i]; list3[index] = value; list[index2] = value2; List<float> list4 = list2; index2 = i; index = j; float value3 = list2[j]; float value4 = list2[i]; list4[index2] = value3; list2[index] = value4; } } } float num = list2.Sum(); for (int k = 0; k < list.Count; k++) { string name = ((Object)list[k].DungeonFlow).name; StringBuilder stringBuilder = new StringBuilder(); int count = Mathf.Max(20 - name.Length, 0); stringBuilder.Append("* " + name + new string(' ', count)); int value5 = (int)list2[k]; dictionary[name] = value5; } return dictionary; } } public class LethalLevelLoaderCompatibility : CompatibilityHandler { public LethalLevelLoaderCompatibility(string guid, string version = null) : base(guid, version, false) { } public void RemoveMoonNodeEvent() { if (((CompatibilityHandler)this).IsModPresent) { TerminalManager.onLoadNewNodeRegisteredEventsDictionary.Clear(); } } public static bool IsLevelLocked(SelectableLevel level) { return SharedMethods.IsMoonLockedLLL(level); } public static bool IsLevelHidden(SelectableLevel level) { return SharedMethods.IsMoonHiddenLLL(level); } public static List<KeyValuePair<DungeonFlow, int>> GetDungeonFlowsWithRarity(SelectableLevel level) { List<KeyValuePair<DungeonFlow, int>> list = new List<KeyValuePair<DungeonFlow, int>>(); ExtendedLevel val = default(ExtendedLevel); LevelManager.TryGetExtendedLevel(level, ref val, (ContentType)2); CollectionExtensions.Do<KeyValuePair<DungeonFlow, int>>(from flow in DungeonManager.GetValidExtendedDungeonFlows(val, false) select new KeyValuePair<DungeonFlow, int>(flow.extendedDungeonFlow.DungeonFlow, flow.rarity), (Action<KeyValuePair<DungeonFlow, int>>)list.Add); return list; } public static List<ExtendedDungeonFlowWithRarity> GetExtendedDungeonFlowsWithRarity(ExtendedLevel extendedLevel) { List<ExtendedDungeonFlowWithRarity> list = new List<ExtendedDungeonFlowWithRarity>(); CollectionExtensions.Do<ExtendedDungeonFlowWithRarity>((IEnumerable<ExtendedDungeonFlowWithRarity>)DungeonManager.GetValidExtendedDungeonFlows(extendedLevel, false), (Action<ExtendedDungeonFlowWithRarity>)list.Add); return list; } public static Dictionary<string, int> GetDungeonRarities(SelectableLevel level) { Dictionary<string, int> result = new Dictionary<string, int>(); ExtendedLevel extendedLevel = default(ExtendedLevel); LevelManager.TryGetExtendedLevel(level, ref extendedLevel, (ContentType)2); CollectionExtensions.Do<ExtendedDungeonFlowWithRarity>((IEnumerable<ExtendedDungeonFlowWithRarity>)GetExtendedDungeonFlowsWithRarity(extendedLevel), (Action<ExtendedDungeonFlowWithRarity>)delegate(ExtendedDungeonFlowWithRarity flow) { result[((Object)flow.extendedDungeonFlow.DungeonFlow).name] = flow.rarity; }); return result; } } } namespace TerminalUtils.Commands { public class FilterCommand : TerminalCommandNode { public FilterCommand() : base("filter") { base.RedirectToNode = TerminalManager.MoonsPage; } public override string Execute(string[] args) { string filterTypeName = "none"; Dictionary<string, FilterInfoType<SelectableLevel>> infoTypes = TerminalManager.FilterInfoTypes.Select((KeyValuePair<string, FilterInfoType<SelectableLevel>> kv) => kv.Value).ToDictionary((FilterInfoType<SelectableLevel> infoType) => infoType.Name.ToLowerInvariant(), (FilterInfoType<SelectableLevel> infoType) => infoType); ((Logger)Plugin.debugLogger).LogDebug("Possible filter types: " + string.Join(", ", infoTypes.Keys)); args.ToList().ForEach(delegate(string arg) { if (infoTypes.ContainsKey(arg)) { filterTypeName = arg; } }); TerminalManager.CurrentFilterInfoType = infoTypes[filterTypeName]; ConfigManager.FilterInfoType.Value = infoTypes[filterTypeName].Name; return ""; } } public class PreviewCommand : TerminalCommandNode { public PreviewCommand() : base("preview") { base.RedirectToNode = TerminalManager.MoonsPage; } public override string Execute(string[] args) { List<string> previewTypeNames = new List<string>(1) { "name" }; Dictionary<string, PreviewInfoType<SelectableLevel>> infoTypes = TerminalManager.PreviewInfoTypes.Select((KeyValuePair<string, PreviewInfoType<SelectableLevel>> kv) => kv.Value).ToDictionary((PreviewInfoType<SelectableLevel> infoType) => infoType.Name.ToLowerInvariant(), (PreviewInfoType<SelectableLevel> infoType) => infoType); ((Logger)Plugin.debugLogger).LogDebug("Possible preview types: " + string.Join(", ", infoTypes.Keys)); args.ToList().ForEach(delegate(string arg) { if (infoTypes.ContainsKey(arg)) { previewTypeNames.Add(arg); } }); TerminalManager.CurrentPreviewInfoType = previewTypeNames.Select((string name) => infoTypes[name]).ToList(); ConfigManager.PreviewInfoType.Value = string.Join(";", TerminalManager.CurrentPreviewInfoType.Select((PreviewInfoType<SelectableLevel> info) => info.Name)); return ""; } } public class SimulateCommand : TerminalCommandNode { public SimulateCommand() : base("simulate") { } public override string Execute(string[] args) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown SelectableLevel val = StringResolver.ResolveStringToLevels(args[0]).FirstOrDefault(); Dictionary<string, int> source = new Dictionary<string, int>(); if (((CompatibilityHandler)Plugin.DawnCompatibility).IsModPresent) { source = DawnLibCompatibility.GetDungeonRarities(StartOfRound.Instance.currentLevel); } else if (((CompatibilityHandler)Plugin.LLLCompatibility).IsModPresent) { source = LethalLevelLoaderCompatibility.GetDungeonRarities(StartOfRound.Instance.currentLevel); } ConsoleTable val2 = new ConsoleTable(new string[3] { "Interior", "Weight", "Chance" }); val2.AddRow(new object[3] { "", "", "" }); source = source.OrderBy((KeyValuePair<string, int> o) => -o.Value).ToDictionary((KeyValuePair<string, int> k) => k.Key, (KeyValuePair<string, int> v) => v.Value); int num = source.Values.Sum(); foreach (KeyValuePair<string, int> item in source) { item.Deconstruct(out var key, out var value); string text = key; int num2 = value; object[] obj = new object[3] { text.PadRight(20), num2, null }; value = num2 / num * 100; obj[2] = (value.ToString("F2") + "%").PadLeft(4); val2.AddRow(obj); } val2.AddRow(new object[3] { "", "", "" }); val2.AddRow(new object[3] { "", "", "" }); val2.AddRow(new object[3] { "", num.ToString().PadRight(6), "100%".ToString().PadLeft(4) }); ((Logger)Plugin.debugLogger).LogDebug("Flows with rarity for level " + val.PlanetName + ": " + string.Join(", ", source.Select((KeyValuePair<string, int> kv) => $"{kv.Key} (rarity: {kv.Value})"))); return val2.ToStringCustomDecoration(true, false, false); } } public class SortCommand : TerminalCommandNode { public SortCommand() : base("sort") { base.RedirectToNode = TerminalManager.MoonsPage; } public override string Execute(string[] args) { string sortTypeName = "none"; Dictionary<string, SortInfoType<SelectableLevel>> infoTypes = TerminalManager.SortInfoTypes.Select((KeyValuePair<string, SortInfoType<SelectableLevel>> kv) => kv.Value).ToDictionary((SortInfoType<SelectableLevel> infoType) => infoType.Name.ToLowerInvariant(), (SortInfoType<SelectableLevel> infoType) => infoType); ((Logger)Plugin.debugLogger).LogDebug("Possible sort types: " + string.Join(", ", infoTypes.Keys)); args.ToList().ForEach(delegate(string arg) { if (infoTypes.ContainsKey(arg)) { sortTypeName = arg; } }); TerminalManager.CurrentSortInfoType = infoTypes[sortTypeName]; ConfigManager.SortInfoType.Value = infoTypes[sortTypeName].Name; return ""; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }