using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; 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.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Dawn; using Dawn.Utils; using GameNetcodeStuff; using HarmonyLib; using InteractiveTerminalAPI.UI; using LethalConfig; using LethalConfig.ConfigItems; using LethalConfig.ConfigItems.Options; using LobbyCompatibility.Enums; using LobbyCompatibility.Features; using Microsoft.CodeAnalysis; using ModelReplacement; using OpenBodyCams; using OpenBodyCams.API; using OpenLib.Common; using OpenLib.Compat; using OpenLib.ConfigManager; using OpenLib.CoreMethods; using OpenLib.Events; using OpenLib.InteractiveMenus; using OpenLib.Menus; using TMPro; using TerminalStuff; using TerminalStuff.EventSub; using TerminalStuff.SpecialStuff; using TwoRadarMaps; using Unity.Netcode; using UnityEngine; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering.HighDefinition; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("darmuhsTerminalStuff")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("darmuh")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.4.3")] [assembly: AssemblyInformationalVersion("0.4.3+d53fc94fd108f72cca6259e3e75920016687397c")] [assembly: AssemblyProduct("OpenLib")] [assembly: AssemblyTitle("OpenLib")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.4.3.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 BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace OpenLib { public class Loggers { public enum LoggingLevel { WarningsPlus = 4, Message = 8, Info = 0x10, Debug = 0x20 } private static void Log(LogLevel bepLevel, object data) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected I4, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) int value = (int)ConfigSetup.LogLevel.Value; int num = (int)bepLevel; if (num <= value) { Plugin.Log.Log(bepLevel, data); } } internal static void LogDebug(object data) { Log((LogLevel)32, data); } internal static void LogInfo(object data) { Log((LogLevel)16, data); } internal static void LogMessage(object data) { Log((LogLevel)8, data); } internal static void WARNING(object data) { Log((LogLevel)4, data); } internal static void ERROR(object data) { Log((LogLevel)2, data); } internal static void FATAL(object data) { Log((LogLevel)1, data); } } public class PageBuilder { public StringBuilder? Content { get; set; } public int PageNumber { get; set; } } public class PageSplitter { public static List SplitTextIntoPages(string inputText, int maxLinesPerPage, string nextPageBlurb) { string[] array = inputText.Split(new string[1] { Environment.NewLine }, StringSplitOptions.None); List list = new List(); int i = 0; int num = 1; while (i < array.Length) { PageBuilder pageBuilder = new PageBuilder { Content = new StringBuilder(), PageNumber = num }; for (; i < array.Length && string.IsNullOrWhiteSpace(array[i]); i++) { } for (int j = 0; j < maxLinesPerPage; j++) { if (i >= array.Length) { break; } pageBuilder.Content.AppendLine(array[i]); i++; } if (i < array.Length - 2) { pageBuilder.Content.AppendLine(nextPageBlurb ?? ""); } else { pageBuilder.Content.AppendLine("\r\n"); } list.Add(pageBuilder); num++; } return list; } } [HarmonyPatch(typeof(GameNetworkManager), "Start")] public class GameStartPatch { public static void Postfix() { EventManager.GameNetworkManagerStart.Invoke(); NetworkClassBase.RegisterNetworkPrefabs(); } } [HarmonyPatch(typeof(StartOfRound), "Awake")] public class StartRoundAwake { public static void Postfix() { EventManager.StartOfRoundAwake.Invoke(); NetworkClassBase.SpawnNetworkPrefab(); } } [HarmonyPatch(typeof(StartOfRound), "Start")] public class StartRoundPatch { public static void Postfix() { EventManager.StartOfRoundStart.Invoke(); } } [HarmonyPatch(typeof(StartOfRound), "StartGame")] public class LandingPatch { public static void Postfix() { EventManager.StartOfRoundStartGame.Invoke(); } } [HarmonyPatch(typeof(StartOfRound), "ResetShip")] public class ShipResetPatch { public static void Postfix() { EventManager.ShipReset.Invoke(); } } [HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")] public class NextDayPatch { public static void Postfix() { EventManager.NextDayEvent.Invoke(); } } [HarmonyPatch(typeof(StartOfRound), "OnShipLandedMiscEvents")] public class OnShipLandedMiscPatch { public static void Postfix() { EventManager.OnShipLandedMiscPatch.Invoke(); } } [HarmonyPatch(typeof(StartOfRound), "ShipHasLeft")] public class ShipLeftPatch { public static void Postfix() { EventManager.ShipLeft.Invoke(); } } [HarmonyPatch(typeof(StartOfRound), "OnClientConnect")] public class OnClientConnectPatch { public static void Postfix() { EventManager.OnClientConnect.Invoke(); } } [HarmonyPatch(typeof(StartOfRound), "ChangeLevel")] public class RouteEvent { public static void Postfix() { EventManager.StartOfRoundChangeLevel.Invoke(); } } [HarmonyPatch(typeof(RoundManager), "SetBigDoorCodes")] public class SetBigDoorCodes { public static void Postfix() { EventManager.SetBigDoorCodes.Invoke(); } } [HarmonyPatch(typeof(RoundManager), "SpawnMapObjects")] public class SpawnMapObjects { public static void Postfix() { EventManager.SpawnMapObjects.Invoke(); } } [HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")] public class NewQuotaPatch { public static void Postfix() { EventManager.NewQuota.Invoke(); } } [HarmonyPatch(typeof(AutoParentToShip), "Awake")] public class AutoParentGameObjectPatch { public static void Postfix(AutoParentToShip __instance) { if (!((Object)(object)((Component)__instance).gameObject == (Object)null)) { EventManager.AutoParentEvent.Invoke(((Component)__instance).gameObject); } } } [HarmonyPatch(typeof(NetworkObject), "Spawn")] public class ObjectSpawnPatch { public static void Postfix(NetworkObject __instance) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((Component)__instance).gameObject == (Object)null)) { EventManager.NetworkObjectSpawn.Invoke(((Component)__instance).gameObject); } } } [HarmonyPatch(typeof(PlayerControllerB), "StartPerformingEmoteServerRpc")] public class EmotePatch { public static void Postfix() { EventManager.PlayerEmote.Invoke(); } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] public class PlayerUpdatePatch { public static bool usePatch; public static bool inShip; public static bool spectate_inShip; public static bool isDead; public static void Postfix(PlayerControllerB __instance) { if (usePatch && !((Object)(object)StartOfRound.Instance == (Object)null) && !((Object)(object)StartOfRound.Instance.localPlayerController == (Object)null) && !((Object)(object)StartOfRound.Instance.localPlayerController != (Object)(object)__instance)) { if (__instance.isInHangarShipRoom != inShip) { inShip = __instance.isInHangarShipRoom; EventManager.PlayerIsInShip.Invoke(); } if (__instance.isPlayerDead != isDead) { isDead = __instance.isPlayerDead; EventManager.PlayerIsDead.Invoke(); } if (__instance.isPlayerDead && (Object)(object)__instance.spectatedPlayerScript != (Object)null && __instance.spectatedPlayerScript.isInHangarShipRoom != spectate_inShip) { spectate_inShip = __instance.spectatedPlayerScript.isInHangarShipRoom; EventManager.SpecatingPlayerIsInShip.Invoke(); } } } } public class SpectateNextPatch { [HarmonyPatch(typeof(PlayerControllerB), "SpectateNextPlayer")] public class PlayerSpawnPatch : MonoBehaviour { private static void Postfix() { EventManager.SpecateNextPlayer.Invoke(); } } } public class SpawnPatch { [HarmonyPatch(typeof(PlayerControllerB), "SpawnPlayerAnimation")] public class PlayerSpawnPatch { private static void Postfix() { EventManager.PlayerSpawn.Invoke(); } } } [HarmonyPatch(typeof(ShipTeleporter), "Awake")] public class TeleporterInit { private static void Postfix(ShipTeleporter __instance) { EventManager.TeleporterAwake.Invoke(__instance); } } [HarmonyPatch(typeof(Terminal), "Awake")] public class AwakeTermPatch { private static void Postfix(Terminal __instance) { EventManager.TerminalAwake.Invoke(__instance); } } [HarmonyPatch(typeof(Terminal), "Start")] public class TerminalStartPatch { private static void Postfix() { EventManager.TerminalStart.Invoke(); } } [HarmonyPatch(typeof(Terminal), "OnDisable")] public class DisableTermPatch { private static void Postfix() { EventManager.TerminalDisable.Invoke(); } } [HarmonyPatch(typeof(Terminal), "QuitTerminal")] public class QuitTerminalPatch { private static void Postfix() { EventManager.TerminalQuit.Invoke(); } } [HarmonyPatch(typeof(Terminal), "LoadNewNode")] public class LoadNewNodePatch { private static void Postfix(TerminalNode node) { EventManager.TerminalLoadNewNode.Invoke(node); string text = (((Object)(object)node != (Object)null) ? ((Object)node).name : "Null Node"); Loggers.LogDebug("LoadNewNode - " + text); } } [HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")] public class AffordableNodePatch { private static void Postfix(TerminalNode node) { EventManager.TerminalLoadIfAffordable.Invoke(node); } } [HarmonyPatch(typeof(Terminal), "BeginUsingTerminal")] public class Terminal_Begin_Patch { private static void Postfix() { EventManager.TerminalBeginUsing.Invoke(); } } [HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")] public class Terminal_ParsePlayerSentence_Patch { private static void Postfix(ref TerminalNode __result) { if (!((Object)(object)__result == (Object)null)) { TerminalNode val = EventManager.TerminalParseSent.NodeInvoke(ref __result); __result = val; } } } [HarmonyPatch(typeof(Terminal), "Update")] public class TerminalUpdatePatch { public static bool inUse; public static bool usePatch; public static int menuIndex; private static void Postfix(Terminal __instance) { if (usePatch && __instance.placeableObject.inUse != inUse) { inUse = __instance.placeableObject.inUse; EventManager.SetTerminalInUse.Invoke(); } } [HarmonyPrefix] private static bool Prefix(Terminal __instance) { if (!usePatch || !__instance.terminalInUse) { return true; } if (MenusContainer.AnyOpenLibMenuActive()) { __instance.scrollBarCanvasGroup.alpha = 0f; ((TMP_Text)__instance.topRightText).text = $"${__instance.groupCredits}"; if (__instance.placeableObject.inUse != inUse) { inUse = __instance.placeableObject.inUse; EventManager.SetTerminalInUse.Invoke(); } if (((ButtonControl)Keyboard.current.anyKey).wasPressedThisFrame) { EventManager.TerminalMenuKeyPressed.Invoke(); } return false; } if (((ButtonControl)Keyboard.current.anyKey).wasPressedThisFrame) { EventManager.TerminalKeyPressed.Invoke(); } return true; } } [BepInPlugin("darmuh.OpenLib", "OpenLib", "0.4.3")] public class Plugin : BaseUnityPlugin { public static Plugin instance = null; internal static ManualLogSource Log = null; public bool TerminalStuff; public bool LobbyCompat; public bool TerminalFormatter; public bool ITAPI; public bool LethalConfig; public bool OpenBodyCamsMod; public bool TwoRadarMapsMod; public bool ModelReplacement; public bool TooManyEmotes; public bool MirrorDecor; public static List AllCommands = new List(); public static List KeywordsAdded = new List(); public static List NodesAdded = new List(); public static List NounsAdded = new List(); public static List AllTerminalCodes = new List(); public Terminal Terminal; public static List ShopNodes = new List(); public const string Id = "darmuh.OpenLib"; public bool DawnLibPresent => Chainloader.PluginInfos.ContainsKey("com.github.teamxiaolan.dawnlib"); public static string Name => "OpenLib"; public static string Version => "0.4.3"; public static List GetActiveCommands() { if (AllCommands.Count == 0) { return new List(); } return AllCommands.FindAll((CommandManager x) => x.IsCreated); } private void Awake() { instance = this; Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"OpenLib is loading with version 0.4.3!\nThis mod has been compiled for v80 of Lethal Company and may not work with earlier versions!"); ConfigSetup.defaultManaged = new List(); CommandRegistry.InitListing(ref ConfigSetup.defaultListing); ConfigSetup.BindConfigSettings(); ((BaseUnityPlugin)this).Config.ConfigReloaded += OnConfigReloaded; Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null); EventUsage.Subscribers(); AllInteractiveMenus.AllMenus = new List(); string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "openlib.bundle"); if (File.Exists(text)) { AssetBundle val = AssetBundle.LoadFromFile(text); NetworkClassBase.Prefab = val.LoadAsset("Openlib Networker"); } else { Log.LogError((object)("Openlib Networker asset cannot be found! Expected path: " + text)); } Log.LogInfo((object)"OpenLib load complete!"); } internal void OnConfigReloaded(object sender, EventArgs e) { Log.LogInfo((object)"Config has been reloaded!"); ConfigSetup.ReadConfigAndAssignValues(((BaseUnityPlugin)instance).Config, ConfigSetup.defaultManaged); } } public class NodeInfo { [CompilerGenerated] private CommandManager P; public string Name; public string InfoText; public Func InfoAction; public TerminalNode terminalNode; public NodeInfo(CommandManager command) { P = command; Name = P.Name; InfoText = string.Empty; base..ctor(); } public void GetDefaultInfo(CommandManager command) { string text = "[ " + CommonStringStuff.GetKeywordsForMenuItem(command.KeywordList) + " ]\r\n"; text = ((command.IsEnabled == null) ? (text + "No further information on this command!\r\n\r\n") : (text + ((ConfigEntryBase)command.IsEnabled.ConfigItem).Description.Description + "\r\n\r\n")); InfoText = text; } public void CreateInfoNode() { if (!((Object)(object)CommonTerminal.InfoKeyword == (Object)null)) { TerminalKeyword info = CommonTerminal.InfoKeyword; terminalNode = BasicTerminal.CreateNewTerminalNode(); ((Object)terminalNode).name = "info_" + Name; terminalNode.displayText = InfoText; terminalNode.clearPreviousText = true; CollectionExtensions.Do((IEnumerable)P.KeywordList, (Action)delegate(string Keyword) { AddingThings.AddCompatibleNoun(ref info, Keyword, terminalNode); }); Loggers.LogDebug("info node created and assigned to command!"); } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "OpenLib"; public const string PLUGIN_NAME = "OpenLib"; public const string PLUGIN_VERSION = "0.4.3"; } } namespace OpenLib.Menus { public class CommandsMenu { internal static CommandsMenuBase CommandMenu = null; internal static CommandMenuItem MainMenuItem = null; internal static List> AllCommandMenuItems = new List>(); internal static void Init() { CommandMenu = new CommandsMenuBase("Commands Menu") { MainMenu = MainMenuItem, PageSize = 10, AdjustScrollInMenu = false }; MainMenuItem = CreateMainMenu(CommandMenu, "My Commands Menu", () => "=== My Commands Main Menu ===\n\n", () => "Created by darmuh"); } internal static void RuntimeSetup() { List activeCommands = Plugin.GetActiveCommands(); UpdateMenuListing(CommandMenu, MainMenuItem, activeCommands); CreateAndSetControlsFooter(CommandMenu, AllCommandMenuItems); } public static void UpdateMenuListing(CommandsMenuBase menuBase, CommandMenuItem mainMenuItem, List CommandList, string defaultCategory = "Other") { if (mainMenuItem.NestedMenus.Count == 0) { MakeCommandMenuItems(menuBase, CommandList, defaultCategory, mainMenuItem); return; } List> list = mainMenuItem.NestedMenus.ConvertAll((MenuItem x) => x as CommandMenuItem); foreach (CommandMenuItem item in list) { item.isEnabled = CommandList.Contains(item.Command); CommandList.Remove(item.Command); UpdateMenuVisibility(item); } if (CommandList.Count > 0) { MakeCommandMenuItems(menuBase, CommandList, defaultCategory, mainMenuItem); } } private static void UpdateMenuVisibility(CommandMenuItem item) { if (item.isEnabled) { if (item.Parent == null) { if (item.CachedParent == null) { Loggers.WARNING("Unable to update " + item.Name + "'s parent. CachedParent is null!"); } else { item.SetParentMenu(item.CachedParent); } } } else if (item.Parent != null) { item.CachedParent = item.Parent; item.SetParentMenu(null); } } internal static string EnterCommandMenu() { if (MainMenuItem == null) { return "This menu has not been created correctly"; } CommandMenu.EnterAtPage(MainMenuItem); return ""; } public static CommandMenuItem CreateMainMenu(CommandsMenuBase menuBase, string menuName, Func header = null, Func footer = null) { if (header == null) { header = () => string.Empty; } if (footer == null) { footer = () => string.Empty; } CommandMenuItem commandMenuItem = new CommandMenuItem(menuBase, menuName) { Header = header, Footer = footer }; AllCommandMenuItems.Add(commandMenuItem); return commandMenuItem; } public static List> MakeCommandMenuItems(CommandsMenuBase menuBase, List commands, string DefaultCategory, CommandMenuItem MainMenu) { CommandsMenuBase menuBase2 = menuBase; List> commandMenuItems = new List>(); Dictionary dictionary = new Dictionary(); if (commands.Count < 1) { return commandMenuItems; } foreach (CommandManager command in commands) { if (string.IsNullOrEmpty(command.Category)) { dictionary.Add(command, DefaultCategory); } else { dictionary.Add(command, command.Category); } } foreach (KeyValuePair category in dictionary) { MenuItem menuItem = MainMenu.NestedMenus.FirstOrDefault((MenuItem c) => Misc.CompareStringsInvariant(c.Name, category.Value)); CommandMenuItem cat = menuItem as CommandMenuItem; if (cat == null) { cat = new CommandMenuItem(menuBase2, category.Value.ToUpperInvariant()); commandMenuItems.Add(cat); cat.SetParentMenu(MainMenu); cat.Header = () => CommandsMenuBase.ConvertHeader(menuBase2.CategoryHeader, cat.Name); } CreateCommandMenuItems(menuBase2, cat, category.Key, ref commandMenuItems); } foreach (CommandMenuItem item in commandMenuItems) { if (item.Command == null && item.Parent == null) { item.SetParentMenu(MainMenu); } } AllCommandMenuItems.AddRange(commandMenuItems); return commandMenuItems; } public static void CreateAndSetControlsFooter(CommandsMenuBase menuBase, List> MenuItems) { SetMenuItemsFooter(MenuItems, menuBase.Controls); } public static void SetMenuItemsFooter(List> MenuItems, Func footer) { foreach (CommandMenuItem MenuItem in MenuItems) { MenuItem.Footer = footer; } } public static void CreateCommandMenuItems(CommandsMenuBase menuBase, CommandMenuItem parent, CommandManager command, ref List> commandMenuItems) { CommandsMenuBase menuBase2 = menuBase; CommandMenuItem parent2 = parent; CommandManager command2 = command; CommandMenuItem CommandName = TryCreate(menuBase2, command2); commandMenuItems.Add(CommandName); CommandName.Header = () => CommandsMenuBase.ConvertHeader(menuBase2.CommandHeader, parent2.Name, CommandName.Name); CommandName.SetParentMenu(parent2); if (menuBase2.AddKeywordsMenu) { if (!TryGetChild(CommandName, command2.Name + " Keywords", out CommandMenuItem item)) { item = new CommandMenuItem(menuBase2, command2.Name + " Keywords"); commandMenuItems.Add(item); item.SetParentMenu(CommandName); } item.Header = () => CommandsMenuBase.ConvertHeader(menuBase2.KeywordsHeader, parent2.Name, CommandName.Name); foreach (string keyword in command2.KeywordList) { if (!TryGetChild(item, keyword, out CommandMenuItem item2)) { item2 = new CommandMenuItem(menuBase2, keyword); commandMenuItems.Add(item2); item2.SetParentMenu(item); item2.Header = () => CommandsMenuBase.ConvertHeader(menuBase2.KeywordsHeader, parent2.Name, CommandName.Name); } } } if (command2.IsEnabled != null && menuBase2.AddInfoMenu) { if (!TryGetChild(CommandName, command2.Name + " Information", out CommandMenuItem item3)) { item3 = new CommandMenuItem(menuBase2, command2.Name + " Information"); commandMenuItems.Add(item3); item3.SetParentMenu(CommandName); } item3.Header = () => CommandsMenuBase.ConvertHeader(menuBase2.InfoHeader, parent2.Name, CommandName.Name); if (!TryGetChild(item3, ((ConfigEntryBase)command2.IsEnabled.ConfigItem).Description.Description, out CommandMenuItem item4)) { item4 = new CommandMenuItem(menuBase2, ((ConfigEntryBase)command2.IsEnabled.ConfigItem).Description.Description); commandMenuItems.Add(item4); item4.SetParentMenu(item3); } item4.Header = () => CommandsMenuBase.ConvertHeader(menuBase2.InfoHeader, parent2.Name, CommandName.Name); } if ((!command2.AcceptAdditionalText || !menuBase2.AddRunCommand) && !TryGetChild(CommandName, "Run " + command2.Name, out CommandMenuItem item5)) { item5 = new CommandMenuItem(menuBase2, "Run " + command2.Name) { LoadPageOnSelect = false }; commandMenuItems.Add(item5); item5.SetParentMenu(CommandName); OpenLib.Events.Events.CustomEvent customEvent = new OpenLib.Events.Events.CustomEvent(); customEvent.AddListener(delegate { menuBase2.ExitPage = command2; menuBase2.ExitMenu(enableInput: true); }); item5.SelectionEvent = customEvent; } } public static CommandMenuItem TryCreate(CommandsMenuBase menuBase, CommandManager command) { CommandManager command2 = command; CommandMenuItem commandMenuItem = AllCommandMenuItems.FirstOrDefault((CommandMenuItem c) => c.Command == command2); if (commandMenuItem != null) { return commandMenuItem; } return new CommandMenuItem(menuBase, command2.Name) { Command = command2 }; } public static bool TryGetChild(CommandMenuItem Parent, string expectedName, out CommandMenuItem item) { CommandMenuItem Parent2 = Parent; string expectedName2 = expectedName; item = AllCommandMenuItems.FirstOrDefault((CommandMenuItem c) => c.Parent == Parent2 && c.Name == expectedName2); return item != null; } public static bool TryGetCategoryMenuItem(string categoryName, out CommandMenuItem match) { string categoryName2 = categoryName; List> source = AllCommandMenuItems.FindAll((CommandMenuItem x) => x.Parent == MainMenuItem && x.Command == null); match = source.FirstOrDefault((CommandMenuItem x) => x.Name == categoryName2); return match != null; } public static void SetCategoryHeader(string categoryName, Func header) { if (TryGetCategoryMenuItem(categoryName, out CommandMenuItem match)) { match.Header = header; } } public static void SetCategoryFooter(string categoryName, Func footer) { if (TryGetCategoryMenuItem(categoryName, out CommandMenuItem match)) { match.Footer = footer; } } } public class CommandsMenuBase : BetterMenu { public bool AddKeywordsMenu = true; public bool AddInfoMenu = true; public bool AddRunCommand = true; public string CommandHeader = "======== {commandName} ========\n\n"; public string KeywordsHeader = "======== {commandName} Keywords ========\n\n"; public string CategoryHeader = "======== {catName>>} COMMANDS ========\n\n"; public string InfoHeader = "====== {commandName} Information ======\n\n"; public const string CategoryName = "catName"; public const string CommandName = "commandName"; public const string ToUpper = ">>"; public const string ToLower = "<<"; public static readonly List AcceptableVariables = new List(4) { "catName", "commandName", ">>", "<<" }; public CommandManager ExitPage; public CommandsMenuBase(string name, Dictionary MoreMenuActions = null) : base(name, MoreMenuActions) { ExitAction = CustomExitAction; OnEnter.AddListener(delegate { ExitPage = null; }); } public void CustomExitAction() { if (ExitPage != null) { if (LogicHandling.GetDisplayTextFromCommand(ref ExitPage.terminalNode)) { CommonTerminal.LoadNewNode(ExitPage.terminalNode); } else { CommonTerminal.LoadNewNode(CommonTerminal.HomePage); } } else { CommonTerminal.LoadNewNode(CommonTerminal.HomePage); } } public static string ConvertHeader(string query, string catName, string commandName = "") { if (string.IsNullOrEmpty(query)) { return query; } List substrings = Misc.GetSubstrings('{', '}', query); if (substrings.Count == 0) { return query; } foreach (string item in substrings) { string text = item.Replace("{", "").Replace("}", ""); if (Misc.StringContainsInvariant(item, "catName")) { text = text.Replace("catName", catName); } if (Misc.StringContainsInvariant(item, "commandName")) { text = text.Replace("commandName", commandName); } if (Misc.StringContainsInvariant(item, ">>")) { text = text.Replace(">>", "").ToUpperInvariant(); } if (Misc.StringContainsInvariant(item, "<<")) { text = text.Replace("<<", "").ToLowerInvariant(); } query = query.Replace(item, text); } return query; } public string Controls() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append($"\r\n\r\nPage [{leftMenu}] < {CurrentPage}/{Mathf.CeilToInt((float)DisplayMenuItemsOfType.Count / (float)PageSize)} > [{rightMenu}]\r\n"); stringBuilder.Append($"Back: [{leaveMenu}] Select: [{selectMenu}]\r\n"); return stringBuilder.ToString(); } } public class CommandMenuItem : MenuItem where TMenu : BetterMenuBase { private string _name; private bool _showEmpty; private OpenLib.Events.Events.CustomEvent _selection; private List _nested; public bool isEnabled; public CommandManager Command; public MenuItem CachedParent; public TMenu MenuBase; public override string Name { get { return _name; } set { _name = value; } } public override bool ShowIfEmptyNest { get { return _showEmpty; } set { _showEmpty = value; } } public override OpenLib.Events.Events.CustomEvent SelectionEvent { get { return _selection; } set { _selection = value; } } public override List NestedMenus { get { return _nested; } set { _nested = value; } } public CommandMenuItem(TMenu betterMenu, string name) { _name = name; _showEmpty = true; _selection = new OpenLib.Events.Events.CustomEvent(); _nested = new List(); isEnabled = true; MenuBase = betterMenu; base..ctor(betterMenu); } } [Obsolete("Doing away with this style of Menu...")] public class MenuBuild { public static bool isNextEnabled = false; public static int nextCount = 1; public static string currentCategory = ""; public static TerminalMenu currentMenu = null; public static List allMenus = new List(); public static List InitCategories(Dictionary CategoryItems) { Loggers.LogDebug("InitCategories START"); List list = new List(); if (CategoryItems.Count < 1) { return list; } foreach (KeyValuePair CategoryItem in CategoryItems) { TerminalMenuCategory item = new TerminalMenuCategory { CatName = CategoryItem.Key, CatDescription = CategoryItem.Value }; list.Add(item); } Loggers.LogDebug("InitCategories SUCCESS"); return list; } public static bool ShouldAddCategoryNameToMainMenu(List menuItems, string categoryName) { foreach (TerminalMenuItem menuItem in menuItems) { if (menuItem.Category == categoryName) { return true; } } return false; } public static List TerminalMenuItems(List managedBools) { List list = new List(); managedBools.RemoveAll((ManagedConfig m) => m == null); foreach (ManagedConfig managedBool in managedBools) { if (managedBool.menuItem != null && managedBool.KeywordList != null && managedBool.KeywordList.Count > 0) { list.Add(managedBool.menuItem); } } Loggers.LogDebug("\n\n\n"); Loggers.LogDebug($"myMenuItems count: {list.Count}"); Loggers.LogDebug("\n\n\n"); return list; } public static TerminalMenu AssembleMainMenu(string menuName, string keyword, string mainMenuText, List categoryList, List menuItems, bool addToOther = false, string menuDescription = "") { TerminalMenu terminalMenu = new TerminalMenu { MenuName = menuName, setKeyword = keyword, Categories = categoryList, MainMenuText = mainMenuText, menuItems = menuItems, currentCategory = "", nextCount = 1, isNextEnabled = false }; string displayText = AssembleMainMenuText(terminalMenu); if (addToOther) { AddingThings.AddBasicCommand(terminalMenu.MenuName + "_main", terminalMenu.setKeyword, displayText, isVerb: false, clearText: true, "other", menuDescription); } else { AddingThings.AddBasicCommand(terminalMenu.MenuName + "_main", terminalMenu.setKeyword, displayText, isVerb: false, clearText: true); } allMenus.Add(terminalMenu); return terminalMenu; } public static bool InMainMenu(TerminalNode terminalNode, TerminalMenu terminalMenu) { if (terminalMenu == null) { Loggers.ERROR("ERROR: OpenLib menu is NULL, most likely failed to create!"); return false; } if (((Object)terminalNode).name.Contains(terminalMenu.MenuName)) { terminalMenu.isActive = true; terminalMenu.nextCount = 1; terminalMenu.currentCategory = ""; Loggers.LogDebug("In main menu of " + terminalMenu.MenuName); return true; } if (terminalMenu.isNextEnabled && terminalMenu.terminalNodes.Contains(terminalNode)) { Loggers.LogDebug("Still in menus but not main, next is enabled"); return false; } terminalMenu.isActive = false; return false; } public static string AssembleMainMenuText(TerminalMenu terminalMenu) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(terminalMenu.MainMenuText + "\r\n\r\n"); if (terminalMenu.Categories.Count > 0) { foreach (TerminalMenuCategory category in terminalMenu.Categories) { stringBuilder.Append("[" + category.CatName.ToUpper() + "]\r\n" + category.CatDescription + "\r\n\r\n"); } } return stringBuilder.ToString(); } public static string AssembleMainMenuText(string MainMenuText, Dictionary Categories) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(MainMenuText + "\r\n\r\n"); if (Categories.Count > 0) { foreach (KeyValuePair Category in Categories) { stringBuilder.Append("[" + Category.Key.ToUpper() + "]\r\n" + Category.Value + "\r\n\r\n"); } } return stringBuilder.ToString(); } public static void CreateCategoryCommands(TerminalMenu terminalMenu, MainListing yourModListing) { List>> list = new List>>(); foreach (TerminalMenuCategory category in terminalMenu.Categories) { Loggers.LogDebug("checking category in terminalMenu.categories"); Dictionary> item = MakeCategoryList(category, terminalMenu.menuItems); if (!list.Contains(item)) { list.Add(item); } TerminalNode item2 = AddingThings.CreateNode(terminalMenu, category.CatName ?? "", category.CatName.ToLower(), GetFirstInList, yourModListing); terminalMenu.terminalNodes.Add(item2); } terminalMenu.categoryLists = list; TerminalNode item3 = AddingThings.CreateNode(terminalMenu, "nextInMenu", "next", NextInList, yourModListing, isNextPageCommand: true); terminalMenu.terminalNodes.Add(item3); } public static void CreateCategoryFauxCommands(TerminalMenu terminalMenu, MainListing yourModListing) { CreateCategoryFauxCommands(terminalMenu, yourModListing, "more"); } public static void CreateCategoryFauxCommands(TerminalMenu terminalMenu, MainListing yourModListing, string mainWord) { List>> list = new List>>(); foreach (TerminalMenuCategory category in terminalMenu.Categories) { Loggers.LogDebug("checking category in terminalMenu.categories"); Dictionary> item = MakeCategoryList(category, terminalMenu.menuItems); if (!list.Contains(item)) { list.Add(item); } FauxKeyword fauxWord = new FauxKeyword(mainWord, category.CatName, GetFirstInList) { AllowOtherFauxWords = true, requireExact = true }; AddingThings.AddToFauxListing(fauxWord, yourModListing); } terminalMenu.categoryLists = list; FauxKeyword fauxWord2 = new FauxKeyword(mainWord, "next", NextInList) { AllowOtherFauxWords = true }; AddingThings.AddToFauxListing(fauxWord2, yourModListing); } public static void UpdateCategories(TerminalMenu myMenu) { List>> list = new List>>(); foreach (TerminalMenuCategory category in myMenu.Categories) { Loggers.LogDebug("checking category in myMenu.categories"); Dictionary> item = MakeCategoryList(category, myMenu.menuItems); if (!list.Contains(item)) { list.Add(item); } } myMenu.categoryLists = list; } public static List GetCategoryList(string catName, out TerminalMenu menuName) { Loggers.LogDebug("2.1"); List result = new List(); foreach (TerminalMenu allMenu in allMenus) { Loggers.LogDebug("2.2"); if (!allMenu.isActive) { continue; } for (int i = 0; i < allMenu.Categories.Count; i++) { Loggers.LogDebug("2.3"); foreach (KeyValuePair> item in allMenu.categoryLists[i]) { if (Misc.CompareStringsInvariant(item.Key, catName)) { Loggers.LogDebug("categorylist found!!!"); menuName = allMenu; return item.Value; } } } } Loggers.LogDebug("2.1 FAIL"); menuName = null; return result; } public static Dictionary> MakeCategoryList(TerminalMenuCategory category, List terminalMenuItems) { Loggers.LogDebug("MakeCategoryList START"); string catName = category.CatName; Loggers.LogDebug(catName); List list = new List(); Dictionary> dictionary = new Dictionary>(); Loggers.LogDebug($"count: {terminalMenuItems.Count}"); foreach (TerminalMenuItem terminalMenuItem in terminalMenuItems) { Loggers.LogDebug("checking " + terminalMenuItem.ItemName); if (Misc.CompareStringsInvariant(terminalMenuItem.Category, catName)) { list.Add("> " + CommonStringStuff.GetKeywordsForMenuItem(terminalMenuItem.itemKeywords) + "\r\n" + terminalMenuItem.itemDescription + "\r\n"); Loggers.LogDebug(CommonStringStuff.GetKeywordsForMenuItem(terminalMenuItem.itemKeywords) + " added"); Loggers.LogDebug(terminalMenuItem.itemDescription + " added too!"); } } Loggers.LogDebug("setting catName list"); dictionary.Add(catName, list); Loggers.LogDebug("MakeCategoryList END"); return dictionary; } public static string NextInList() { if (!isNextEnabled) { return "Not currently in any menus...\r\n\r\n"; } Loggers.LogDebug("currentCategory = " + currentCategory); nextCount++; GetCategoryFromString(currentCategory); TerminalMenu menuName; List categoryList = GetCategoryList(currentCategory, out menuName); if (menuName == null) { return "ERROR: Unable to get current category!\r\n\r\n"; } menuName.isActive = true; menuName.nextCount = nextCount; menuName.currentCategory = currentCategory; string nextPage = CommonStringStuff.GetNextPage(categoryList, currentCategory, 4, nextCount, out isNextEnabled); Loggers.LogDebug($"currentCategory:{currentCategory} nextCount: {nextCount} isNextEnabled: {isNextEnabled}"); menuName.isNextEnabled = isNextEnabled; return nextPage; } public static string GetFirstInList() { Loggers.LogDebug("1"); nextCount = 1; string text = Plugin.instance.Terminal.screenText.text; int textAdded = Plugin.instance.Terminal.textAdded; int length = text.Length; int num = length - textAdded; string input = text.Substring(num, length - num); currentCategory = GetCategoryFromString(input); Loggers.LogDebug("currentCategory detected as: [" + currentCategory + "]"); Loggers.LogDebug("2"); TerminalMenu menuName; List categoryList = GetCategoryList(currentCategory, out menuName); menuName.isActive = true; menuName.nextCount = nextCount; menuName.currentCategory = currentCategory; Loggers.LogDebug("3"); string nextPage = CommonStringStuff.GetNextPage(categoryList, currentCategory, 4, 1, out isNextEnabled); menuName.isNextEnabled = isNextEnabled; Loggers.LogDebug("4"); return nextPage; } public static string GetCategoryFromString(string input) { string input2 = input; Loggers.LogDebug("Getting Category from string: [" + input2 + "]"); foreach (TerminalMenu allMenu in allMenus) { if (allMenu.categoryLists.Any((Dictionary> c) => c.Any((KeyValuePair> d) => Misc.CompareStringsInvariant(d.Key, input2)))) { Loggers.LogDebug("detected menu with categoryList containing string " + input2 + "!!"); allMenu.isActive = true; int index = allMenu.categoryLists.FindIndex((Dictionary> c) => c.Any>>((KeyValuePair> d) => Misc.CompareStringsInvariant(d.Key, input2))); return allMenu.categoryLists[index].First>>((KeyValuePair> d) => Misc.CompareStringsInvariant(d.Key, input2)).Key; } Loggers.LogDebug("menu does not contain string " + input2); allMenu.isActive = false; } return "CategoryNameFailure"; } public static string GetCategoryFromNode(TerminalNode givenNode) { Loggers.LogDebug("1.1"); if ((Object)(object)givenNode == (Object)null) { Loggers.ERROR("GetCategoryFromNode: givenNode is null!!!!"); return ""; } foreach (TerminalMenu allMenu in allMenus) { if (!allMenu.terminalNodePerCategory.ContainsValue(givenNode)) { Loggers.LogDebug("menu does not contain node " + ((Object)givenNode).name); allMenu.isActive = false; continue; } foreach (KeyValuePair item in allMenu.terminalNodePerCategory) { if ((Object)(object)item.Value == (Object)(object)givenNode) { Loggers.LogDebug("FOUND NODE AND PAIR " + item.Key); allMenu.isActive = true; return item.Key; } } } Loggers.ERROR("GetCategoryFromNode FAILURE: COULD NOT FIND NODE???"); return ""; } public static TerminalMenuItem MakeMenuItem(ManagedConfig managedBool) { if (managedBool.categoryText != "") { return new TerminalMenuItem { itemKeywords = managedBool.KeywordList, itemDescription = managedBool.configDescription, ItemName = managedBool.ConfigItemName, Category = managedBool.categoryText }; } return null; } public static TerminalMenuItem MakeMenuItem(string categoryText, List keywordList, string configDescription, string itemName) { if (categoryText != "") { return new TerminalMenuItem { itemKeywords = keywordList, itemDescription = configDescription, ItemName = itemName, Category = categoryText }; } Loggers.WARNING("Empty categoryText, Unable to create TerminalMenuItem! (null return)"); return null; } } [Obsolete("This style of menu will be deleted in next major update to library, once all mods are confirmed not using this")] public class TerminalMenu { public string MenuName = string.Empty; public string MainMenuText = string.Empty; public string setKeyword = string.Empty; public List Categories = new List(); public List menuItems = new List(); public Dictionary terminalNodePerCategory = new Dictionary(); public List>> categoryLists = new List>>(); public List terminalNodes = new List(); public string currentCategory { get; internal set; } = string.Empty; public bool isActive { get; internal set; } public bool isNextEnabled { get; internal set; } public int nextCount { get; internal set; } = 1; public void Delete() { MenuBuild.allMenus.Remove(this); menuItems.Clear(); categoryLists.Clear(); Categories.Clear(); terminalNodePerCategory.Clear(); terminalNodes.Clear(); } } public class TerminalMenuItem { public string ItemName = string.Empty; public string Category = string.Empty; public List itemKeywords; public string itemDescription = string.Empty; public void Delete() { itemDescription = ""; Category = ""; ItemName = ""; if (itemKeywords.Count > 0) { itemKeywords.Clear(); } } } public class TerminalMenuCategory { public string CatName { get; set; } public string CatDescription { get; set; } } } namespace OpenLib.InteractiveMenus { public abstract class BetterMenuBase { public List AllMenuItemsOfType = new List(); public abstract string Name { get; set; } public abstract Type MenuType { get; } public abstract object BoxedValue { get; } public abstract bool InMenu { get; set; } public abstract OpenLib.Events.Events.CustomEvent InputEvent { get; set; } public abstract OpenLib.Events.Events.CustomEvent ExitTerminal { get; set; } public abstract MenuItem MainMenu { get; set; } public List GetMenuItemsOfType() where T : MenuItem { return AllMenuItemsOfType.OfType().ToList(); } public override string ToString() { return Name; } } public class BetterMenu : BetterMenuBase { [CompilerGenerated] private sealed class d__68 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public BetterMenu <>4__this; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__68(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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 int num = <>1__state; BetterMenu betterMenu = <>4__this; switch (num) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 1; return true; case 1: <>1__state = -1; if (!betterMenu.AcceptAnything) { betterMenu.MenuNode.displayText = betterMenu.GetPageText(); } if (string.IsNullOrEmpty(betterMenu.MenuNode.displayText)) { betterMenu.ExitInTerminal(); } <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 2; return true; case 2: <>1__state = -1; CommonTerminal.LoadNewNode(betterMenu.MenuNode); <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 3; return true; case 3: <>1__state = -1; if (betterMenu.AdjustScrollInMenu) { betterMenu.ScrollAdjust(); } 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(); } } [CompilerGenerated] private sealed class d__78 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public BetterMenu <>4__this; public bool enableInput; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__78(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown int num = <>1__state; BetterMenu betterMenu = <>4__this; switch (num) { default: return false; case 0: <>1__state = -1; betterMenu.OnExit.Invoke(); <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 1; return true; case 1: <>1__state = -1; betterMenu.InMenu = false; betterMenu.AcceptAnything = false; CollectionExtensions.Do((IEnumerable)betterMenu.AllMenuItemsOfType, (Action)delegate(MenuItem x) { x.IsActive = false; }); CommonTerminal.ChangeCaretColor(CommonTerminal.CaretOriginal, saveOriginal: false); <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 2; return true; case 2: <>1__state = -1; if (betterMenu.ExitAction == null) { CommonTerminal.LoadNewNode(CommonTerminal.HomePage); } else { betterMenu.ExitAction(); } if (enableInput) { Plugin.instance.Terminal.screenText.ActivateInputField(); ((Selectable)Plugin.instance.Terminal.screenText).interactable = true; } betterMenu.OnExitComplete.Invoke(); 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(); } } [CompilerGenerated] private sealed class d__79 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public BetterMenu <>4__this; public MenuItem Start; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__79(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown int num = <>1__state; BetterMenu betterMenu = <>4__this; switch (num) { default: return false; case 0: <>1__state = -1; if (betterMenu.InMenu) { return false; } if (Start == null) { Start = betterMenu.MainMenu; } Start.IsActive = true; betterMenu.AcceptAnything = false; <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 1; return true; case 1: <>1__state = -1; betterMenu.InMenu = true; CommonTerminal.ChangeCaretColor(CommonTerminal.transparent, saveOriginal: true); betterMenu.ActiveSelection = 0; betterMenu.CurrentPage = 1; <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 2; return true; case 2: <>1__state = -1; Plugin.instance.Terminal.screenText.DeactivateInputField(false); ((Selectable)Plugin.instance.Terminal.screenText).interactable = false; <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 3; return true; case 3: <>1__state = -1; Start.SelectionEvent?.Invoke(); if (Start.LoadPageOnSelect) { betterMenu.LoadPage.Invoke(); } 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(); } } private string _name = ""; private bool _inMenu; private MenuItem _mainMenu; private OpenLib.Events.Events.CustomEvent _inputEvent = new OpenLib.Events.Events.CustomEvent(); private OpenLib.Events.Events.CustomEvent _exitEvent = new OpenLib.Events.Events.CustomEvent(); public MenuItem CurrentMenuItem; public TerminalNode MenuNode; public Action ExitAction; public OpenLib.Events.Events.CustomEvent OnExit = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent OnExitComplete = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent OnEnter = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent OnLoad = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent LoadPage = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent UpMenuEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent DownMenuEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent LeftMenuEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent RightMenuEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent AcceptAnyKeyEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEventRef> MenuItemList = new OpenLib.Events.Events.CustomEventRef>(); public Key upMenu = (Key)63; public Key downMenu = (Key)64; public Key leftMenu = (Key)61; public Key rightMenu = (Key)62; public Key selectMenu = (Key)2; public Key leaveMenu = (Key)65; public Dictionary MainActions = new Dictionary(); public Dictionary OtherActions = new Dictionary(); public bool IsMenuEnabled; public bool AcceptAnything; public bool AdjustScrollInMenu; private int _activeIndex; private int _endIndex; public int CurrentPage = 1; public int PageSize = 8; public List DisplayMenuItemsOfType = new List(); public override string Name { get { return _name; } set { _name = value; } } public override Type MenuType => typeof(T); public override object BoxedValue => this; public override bool InMenu { get { return _inMenu; } set { _inMenu = value; } } public override MenuItem MainMenu { get { return _mainMenu; } set { _mainMenu = value; } } public override OpenLib.Events.Events.CustomEvent InputEvent { get { return _inputEvent; } set { _inputEvent = value; } } public override OpenLib.Events.Events.CustomEvent ExitTerminal { get { return _exitEvent; } set { _exitEvent = value; } } public int ActiveSelection { get { return _activeIndex; } set { _activeIndex = value; } } public int EndIndex { get { return _endIndex; } set { _endIndex = value; } } public override string ToString() { return Name; } public BetterMenu(string name, Dictionary MoreMenuActions = null) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) if (!TerminalUpdatePatch.usePatch) { TerminalUpdatePatch.usePatch = true; } Name = name; LoadPage.AddListener(Load); InputEvent.AddListener(HandleInput); ExitTerminal.AddListener(ExitTerminalLeave); AcceptAnyKeyEvent.AddListener(DefaultAcceptAnything); UpdateMainActions(); if (MoreMenuActions != null) { OtherActions = MoreMenuActions; } MenusContainer.AllMenus.Add(this); } public void ReplaceEventAction(OpenLib.Events.Events.CustomEvent eventName, OpenLib.Events.Events.CustomEvent.Event newMethod) { if (eventName.Listeners > 0) { eventName.RemoveAllListeners(); } eventName.AddListener(newMethod); } public void AddToOtherActions(Key key, Action action) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (OtherActions.ContainsKey(key)) { OtherActions.Remove(key); } OtherActions.Add(key, action); } public void UpdateMainActions() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) MainActions.Clear(); MainActions.Add(upMenu, UpMenu); MainActions.Add(downMenu, DownMenu); MainActions.Add(leftMenu, LeftMenu); MainActions.Add(rightMenu, RightMenu); MainActions.Add(selectMenu, SelectInMenu); MainActions.Add(leaveMenu, ExitInTerminal); } internal void HandleInput() { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) if (!InMenu || (Object)(object)MenuNode == (Object)null) { return; } if (AcceptAnything && AcceptAnyKeyEvent.HasListeners) { AcceptAnyKeyEvent.Invoke(); return; } Key? main = MainActions.FirstOrDefault>((KeyValuePair x) => ((ButtonControl)Keyboard.current[x.Key]).isPressed).Key; if (main.HasValue) { MainActions.FirstOrDefault>((KeyValuePair x) => (Key?)x.Key == main).Value?.Invoke(); } if (OtherActions.Count == 0) { return; } Key? other = OtherActions.FirstOrDefault>((KeyValuePair x) => ((ButtonControl)Keyboard.current[x.Key]).isPressed).Key; if (other.HasValue) { OtherActions.FirstOrDefault>((KeyValuePair x) => (Key?)x.Key == other).Value?.Invoke(); } } public void Load() { MenuItem menuItem = AllMenuItemsOfType.FirstOrDefault((MenuItem x) => x.IsActive); if (menuItem == null) { Loggers.ERROR("Unable to load current page! Nothing is active!"); return; } if ((Object)(object)MenuNode == (Object)null) { Loggers.ERROR("NRE detected at MenuNode! This menu did not set it's terminal node correctly!"); return; } menuItem.OnPageLoad?.Invoke(); OnLoad.Invoke(); ((MonoBehaviour)Plugin.instance.Terminal).StartCoroutine(DelayUpdateText()); } public void DefaultAcceptAnything() { AcceptAnything = false; MenuItem menuItem = AllMenuItemsOfType.FirstOrDefault((MenuItem x) => x.IsActive); if (menuItem.NestedMenus.Count == 0) { ExitInTerminal(); } else { LoadPage.Invoke(); } } [IteratorStateMachine(typeof(BetterMenu<>.d__68))] private IEnumerator DelayUpdateText() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__68(0) { <>4__this = this }; } private void ScrollAdjust() { float num = ((float)EndIndex - (float)ActiveSelection) / (float)EndIndex; if (num >= 1f) { ((MonoBehaviour)Plugin.instance.Terminal).StartCoroutine(Plugin.instance.Terminal.forceScrollbarUp()); } else if (num == 0f) { ((MonoBehaviour)Plugin.instance.Terminal).StartCoroutine(Plugin.instance.Terminal.forceScrollbarDown()); } else { Plugin.instance.Terminal.scrollBarVertical.value = num; } } public string GetPageText() { StringBuilder stringBuilder = new StringBuilder(); CurrentMenuItem = AllMenuItemsOfType.FirstOrDefault((MenuItem x) => x.IsActive); if (CurrentMenuItem == null) { Loggers.WARNING("Unable to get current menu page!!"); return ""; } stringBuilder.Append(CurrentMenuItem.Header() ?? ""); DisplayMenuItemsOfType = AllMenuItemsOfType.FindAll((MenuItem x) => CurrentMenuItem.NestedMenus.Contains(x)); DisplayMenuItemsOfType.RemoveAll((MenuItem x) => !x.ShowIfEmptyNest && x.NestedMenus.Count == 0); if (DisplayMenuItemsOfType.Count == 0) { stringBuilder.Append("\r\n\r\nThis menu listing is currently empty :(\r\n"); if (CurrentMenuItem != null) { stringBuilder.Append(CurrentMenuItem.Footer() ?? ""); } return stringBuilder.ToString(); } CurrentMenuItem.AdjustNestedMenuList.Invoke(ref DisplayMenuItemsOfType); CurrentPage = Misc.CycleIndex(CurrentPage, 1, Mathf.CeilToInt((float)DisplayMenuItemsOfType.Count / (float)PageSize)); int num = (CurrentPage - 1) * PageSize; int num3 = (EndIndex = Mathf.Min(num + PageSize, DisplayMenuItemsOfType.Count)); ActiveSelection = Misc.CycleIndex(ActiveSelection, num, num3 - 1); Loggers.LogDebug($"{Name} menu activeselection: {ActiveSelection}"); CollectionExtensions.DoIf((IEnumerable)DisplayMenuItemsOfType, (Func)((MenuItem x) => x.OnPageLoad != null), (Action)delegate(MenuItem x) { x.OnPageLoad(); }); for (int i = num; i < num3; i++) { string text = string.Empty; if (ActiveSelection == i) { text = ">>> "; } text += DisplayMenuItemsOfType[i].Prefix; text += DisplayMenuItemsOfType[i].Name; text += DisplayMenuItemsOfType[i].Suffix; stringBuilder.Append(text + "\n"); } int num4 = num3 - num - PageSize; if (num4 < 0) { for (int j = num4; j < 0; j++) { stringBuilder.Append('\n'); } } if (CurrentMenuItem == null) { Loggers.WARNING("Unable to select current menu item!!"); } else { stringBuilder.Append(CurrentMenuItem.Footer() ?? ""); } return stringBuilder.ToString(); } public void SelectInMenu() { if (DisplayMenuItemsOfType.Count == 0) { return; } MenuItem menuItem = AllMenuItemsOfType.FirstOrDefault((MenuItem x) => x.IsActive); if (menuItem == null) { Loggers.WARNING("Unable to select current menu item!!"); return; } Loggers.LogDebug("Selecting Nested Menu Item!"); MenuItem menuItem2 = DisplayMenuItemsOfType[ActiveSelection]; menuItem2.SelectionEvent?.Invoke(); if (menuItem2.NestedMenus.Count > 0) { Loggers.LogDebug("Setting to nested menu item!"); CurrentPage = 1; ActiveSelection = 0; CollectionExtensions.Do((IEnumerable)AllMenuItemsOfType, (Action)delegate(MenuItem x) { x.IsActive = false; }); menuItem2.IsActive = true; } if (menuItem2.LoadPageOnSelect) { LoadPage.Invoke(); } } public void AddMenuItem(MenuItem menuItem) { if (!AllMenuItemsOfType.Contains(menuItem)) { AllMenuItemsOfType.Add(menuItem); } } public void ExitInTerminal() { MenuItem menuItem = AllMenuItemsOfType.FirstOrDefault((MenuItem x) => x.IsActive); if (menuItem == null) { Loggers.WARNING("Unable to get current menu page!!"); } if (menuItem == null) { ExitMenu(enableInput: true); } else if (menuItem.Parent != null) { Loggers.LogDebug("Setting to ParentMenu!"); ActiveSelection = 0; CurrentPage = 1; menuItem.IsActive = false; menuItem.Parent.IsActive = true; LoadPage.Invoke(); } else { ExitMenu(enableInput: true); } } public void ExitTerminalLeave() { ExitMenu(enableInput: false); } public void ExitMenu(bool enableInput) { ((MonoBehaviour)Plugin.instance.Terminal).StartCoroutine(MenuClose(enableInput)); } public void EnterAtPage(MenuItem menuItem) { OnEnter.Invoke(); ((MonoBehaviour)Plugin.instance.Terminal).StartCoroutine(MenuStart(menuItem)); } public void EnterMenu() { OnEnter.Invoke(); ((MonoBehaviour)Plugin.instance.Terminal).StartCoroutine(MenuStart()); } [IteratorStateMachine(typeof(BetterMenu<>.d__78))] internal IEnumerator MenuClose(bool enableInput) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__78(0) { <>4__this = this, enableInput = enableInput }; } [IteratorStateMachine(typeof(BetterMenu<>.d__79))] internal IEnumerator MenuStart(MenuItem Start = null) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__79(0) { <>4__this = this, Start = Start }; } public void UpMenu() { if (InMenu) { ActiveSelection--; UpMenuEvent.Invoke(); LoadPage.Invoke(); } } public void DownMenu() { if (InMenu) { ActiveSelection++; DownMenuEvent.Invoke(); LoadPage.Invoke(); } } public void LeftMenu() { if (InMenu) { CurrentPage--; LeftMenuEvent.Invoke(); LoadPage.Invoke(); } } public void RightMenu() { if (InMenu) { CurrentPage++; RightMenuEvent.Invoke(); LoadPage.Invoke(); } } } public abstract class MenuItem : MenuItem where TMenu : BetterMenuBase { public new TMenu BetterMenu => (TMenu)base.BetterMenu; protected MenuItem(TMenu betterMenu) : base(betterMenu) { } } public abstract class MenuItem { private string _prefix = string.Empty; private string _suffix = string.Empty; private bool _isActive; private bool _LoadOnSelect = true; private MenuItem _parent; private Func _header = () => string.Empty; private Func _footer = () => string.Empty; protected BetterMenuBase? BetterMenu { get; } public abstract string Name { get; set; } public abstract bool ShowIfEmptyNest { get; set; } public virtual string Prefix { get { return _prefix; } set { _prefix = value; } } public virtual string Suffix { get { return _suffix; } set { _suffix = value; } } public virtual bool IsActive { get { return _isActive; } set { _isActive = value; } } public virtual bool LoadPageOnSelect { get { return _LoadOnSelect; } set { _LoadOnSelect = value; } } public virtual Action OnPageLoad { get; set; } public abstract OpenLib.Events.Events.CustomEvent SelectionEvent { get; set; } public virtual OpenLib.Events.Events.CustomEventRef> AdjustNestedMenuList { get; set; } = new OpenLib.Events.Events.CustomEventRef>(); public abstract List NestedMenus { get; set; } public virtual MenuItem Parent { get { return _parent; } set { _parent = value; } } public virtual Func Header { get { return _header; } set { _header = value; } } public virtual Func Footer { get { return _footer; } set { _footer = value; } } [Obsolete("Added for compatibility with older versions, please use the constructor with the bettermenubase")] protected MenuItem() { Loggers.LogInfo("MenuItem created from obsolete constructor! Please use constructor with BetterMenuBase!"); } protected MenuItem(BetterMenuBase betterMenu) { if (betterMenu == null) { Loggers.ERROR("Unable to assign menu item to NULL betterMenu!"); return; } BetterMenu = betterMenu; betterMenu.AllMenuItemsOfType.Add(this); } public override string ToString() { return Name; } public virtual void SetParentMenu(MenuItem parent) { Parent?.NestedMenus.RemoveAll((MenuItem m) => m == this); Parent = parent; if (parent != null && !parent.NestedMenus.Contains(this)) { parent.NestedMenus.Add(this); } } public virtual void AddNestedItem(MenuItem child) { if (child != null) { child.Parent = this; if (!NestedMenus.Contains(child)) { NestedMenus.Add(child); } } } public virtual void RemoveFromParent() { if (Parent != null) { Parent.NestedMenus.RemoveAll((MenuItem m) => m == this); Parent = null; } } public virtual void RemoveChild(MenuItem child) { if (child != null) { if (child.Parent != null) { child.Parent = null; } NestedMenus.Remove(child); } } } public class MenusContainer { public static List AllMenus = new List(); private static int _activeIndex = 0; public static int StaticIndex { get { return _activeIndex; } set { _activeIndex = value; } } public static bool TryGetMenu(string menuName, out BetterMenuBase item) { string menuName2 = menuName; item = AllMenus.FirstOrDefault((BetterMenuBase x) => x.Name == menuName2); if (item == null) { return false; } return true; } public static bool AnyMenuActive() { if (AllInteractiveMenus.AnyInteractiveMenuActive()) { return true; } bool flag = false; if (Plugin.instance.ITAPI) { flag = InteractiveTermAPI.ApplicationInUse(); } if (flag) { return true; } if (AllMenus.Count == 0) { return false; } if (AllMenus.Any((BetterMenuBase x) => x.InMenu)) { return true; } return false; } public static bool AnyBetterMenuActive() { if (AllMenus.Count == 0) { return false; } if (AllMenus.Any((BetterMenuBase x) => x.InMenu)) { return true; } return false; } public static bool AnyOpenLibMenuActive() { if (AllInteractiveMenus.AnyInteractiveMenuActive()) { return true; } if (AllMenus.Count == 0) { return false; } if (AllMenus.Any((BetterMenuBase x) => x.InMenu)) { return true; } return false; } } } namespace OpenLib.Examples { internal class Examples { public static void TestMyTAO() { TerminalCodeObject terminalCodeObject = new TerminalCodeObject(StartOfRound.Instance.localPlayerController, ((Component)StartOfRound.Instance.localPlayerController).gameObject, dynamicMapIcon: true); terminalCodeObject.OnCodeUsed.AddListener((UnityAction)TestCodeEvent); terminalCodeObject.OnCooldownComplete.AddListener((UnityAction)TestCoolDownEvent); terminalCodeObject.SetTimers(10f, 0f); } public static void TestCodeEvent(TerminalAccessibleObject Code, PlayerControllerB playerOfCode) { if ((Object)(object)Code == (Object)null) { Loggers.WARNING("Code is NULL!"); return; } Plugin.Log.LogDebug((object)$"{Code.objectCode} activated! Status: isPoweredOn - {Code.isPoweredOn}, Cooldown: {Code.inCooldown}, Cooldown Timer: {Code.currentCooldownTimer}"); playerOfCode.drunkness = 20f; } public static void TestCoolDownEvent(TerminalAccessibleObject Code, PlayerControllerB playerOfCode) { if ((Object)(object)Code == (Object)null) { Loggers.WARNING("Code is NULL!"); return; } Plugin.Log.LogDebug((object)$"{Code.objectCode} cooldown reached! Status: isPoweredOn - {Code.isPoweredOn}, Cooldown: {Code.inCooldown}, Cooldown Timer: {Code.currentCooldownTimer}"); playerOfCode.drunkness = 0f; } } } namespace OpenLib.Events { public static class EventManager { public static Events.CustomEvent TerminalDisable = new Events.CustomEvent(); public static Events.CustomEvent TerminalStart = new Events.CustomEvent(); public static Events.CustomEvent TerminalBeginUsing = new Events.CustomEvent(); public static Events.CustomEvent TerminalQuit = new Events.CustomEvent(); public static Events.CustomEvent TerminalAwake = new Events.CustomEvent(); public static Events.CustomEvent TerminalLoadIfAffordable = new Events.CustomEvent(); public static Events.TerminalNodeEvent TerminalParseSent = new Events.TerminalNodeEvent(); public static Events.CustomEvent TerminalLoadNewNode = new Events.CustomEvent(); public static Events.TerminalNodeEvent GetNewDisplayText = new Events.TerminalNodeEvent(); public static Events.CustomEvent StartOfRoundAwake = new Events.CustomEvent(); public static Events.CustomEvent StartOfRoundStart = new Events.CustomEvent(); public static Events.CustomEvent StartOfRoundStartGame = new Events.CustomEvent(); public static Events.CustomEvent StartOfRoundChangeLevel = new Events.CustomEvent(); public static Events.CustomEvent ShipReset = new Events.CustomEvent(); public static Events.CustomEvent SetBigDoorCodes = new Events.CustomEvent(); public static Events.CustomEvent SpawnMapObjects = new Events.CustomEvent(); public static Events.CustomEvent NextDayEvent = new Events.CustomEvent(); public static Events.CustomEvent OnShipLandedMiscPatch = new Events.CustomEvent(); public static Events.CustomEvent ShipLeft = new Events.CustomEvent(); public static Events.CustomEvent NewQuota = new Events.CustomEvent(); public static Events.CustomEvent PlayerSpawn = new Events.CustomEvent(); public static Events.CustomEvent PlayerEmote = new Events.CustomEvent(); public static Events.CustomEvent TeleporterAwake = new Events.CustomEvent(); public static Events.CustomEvent NormalTPFound = new Events.CustomEvent(); public static Events.CustomEvent InverseTPFound = new Events.CustomEvent(); public static Events.CustomEvent GameNetworkManagerStart = new Events.CustomEvent(); public static Events.CustomEvent OnClientConnect = new Events.CustomEvent(); public static Events.CustomEvent SpecateNextPlayer = new Events.CustomEvent(); public static Events.CustomEvent TerminalDelayStart = new Events.CustomEvent(); public static Events.CustomEvent SetTerminalInUse = new Events.CustomEvent(); public static Events.CustomEvent TerminalKeyPressed = new Events.CustomEvent(); public static Events.CustomEvent TerminalMenuKeyPressed = new Events.CustomEvent(); public static Events.CustomEvent PlayerIsInShip = new Events.CustomEvent(); public static Events.CustomEvent PlayerIsDead = new Events.CustomEvent(); public static Events.CustomEvent SpecatingPlayerIsInShip = new Events.CustomEvent(); public static Events.CustomEvent AutoParentEvent = new Events.CustomEvent(); public static Events.CustomEvent NetworkObjectSpawn = new Events.CustomEvent(); } public class Events { public class CustomEvent { public delegate void ParameterEvent(T param); public bool HasListeners => Listeners != 0; public int Listeners { get; internal set; } private event ParameterEvent OnParameterEvent; public void Invoke(T param) { this.OnParameterEvent?.Invoke(param); } public void AddListener(ParameterEvent listener) { OnParameterEvent += listener; Listeners++; } public void RemoveListener(ParameterEvent listener) { OnParameterEvent -= listener; Listeners--; } } public class CustomEventRef { public delegate void ParameterEvent(ref T param); public bool HasListeners => Listeners != 0; public int Listeners { get; internal set; } private event ParameterEvent OnParameterEvent; public void Invoke(ref T param) { this.OnParameterEvent?.Invoke(ref param); } public void AddListener(ParameterEvent listener) { OnParameterEvent += listener; Listeners++; } public void RemoveListener(ParameterEvent listener) { OnParameterEvent -= listener; Listeners--; } } public class TerminalNodeEvent { public delegate TerminalNode Event(ref TerminalNode original); public bool HasListeners => Listeners != 0; public int Listeners { get; internal set; } private event Event OnEvent; public TerminalNode NodeInvoke(ref TerminalNode original) { return this.OnEvent?.Invoke(ref original); } public void AddListener(Event listener) { OnEvent += listener; Listeners++; } public void RemoveListener(Event listener) { OnEvent -= listener; Listeners--; } } public class TerminalKeywordEvent { public delegate TerminalKeyword Event(ref TerminalKeyword original); public bool HasListeners => Listeners != 0; public int Listeners { get; internal set; } private event Event OnEvent; public TerminalKeyword WordInvoke(ref TerminalKeyword original) { return this.OnEvent?.Invoke(ref original); } public void AddListener(Event listener) { OnEvent += listener; Listeners++; } public void RemoveListener(Event listener) { OnEvent -= listener; Listeners--; } } public class CustomEvent { public delegate void Event(); public bool HasListeners => Listeners != 0; public int Listeners { get; internal set; } private event Event OnEvent; public void Invoke() { if (HasListeners) { this.OnEvent?.Invoke(); } } public void AddListener(Event listener) { OnEvent += listener; Listeners++; } public void RemoveListener(Event listener) { OnEvent -= listener; Listeners--; } public void RemoveAllListeners() { if (Listeners != 0) { List list = this.OnEvent.GetInvocationList().ToList(); CollectionExtensions.Do((IEnumerable)list, (Action)delegate(Delegate x) { OnEvent -= (Event)x; }); Listeners = 0; } } } } public class EventUsage { public static List configsToReload = new List(); internal static void Subscribers() { EventManager.TerminalAwake.AddListener(OnTerminalAwake); EventManager.TerminalStart.AddListener(OnTerminalStart); EventManager.TerminalQuit.AddListener(OnTerminalQuit); EventManager.TerminalDisable.AddListener(OnTerminalDisable); EventManager.TerminalLoadNewNode.AddListener(OnLoadNewNode); EventManager.TerminalParseSent.AddListener(OnParseSent); EventManager.TerminalBeginUsing.AddListener(OnUsingTerminal); EventManager.GameNetworkManagerStart.AddListener(StartGame.OnGameStart); EventManager.TeleporterAwake.AddListener(Teleporter.CheckTeleporterTypeAndAssign); EventManager.TerminalMenuKeyPressed.AddListener(OnMenuKeyPress); } private static void OnTerminalAwake(Terminal instance) { Plugin.instance.Terminal = instance; Loggers.LogInfo("Setting Plugin.instance.Terminal"); CommandRegistry.GetCommandsToAdd(ConfigSetup.defaultManaged, ConfigSetup.defaultListing); CommandManager.AddAllCommandsToTerminal(); } private static void OnTerminalDisable() { if (Plugin.instance.OpenBodyCamsMod) { OpenBodyCamFuncs.ResidualCamsCheck(); } RemoveThings.OnTerminalDisable(); TerminalStart.delayStartEnum = false; ListManagement.ClearLists(); CollectionExtensions.Do((IEnumerable)Plugin.AllCommands, (Action)delegate(CommandManager x) { x.TerminalDisabled(); }); foreach (ConfigFile item in configsToReload) { Loggers.LogDebug("reloading config from list"); item.Save(); item.Reload(); } configsToReload.Clear(); } private static void OnTerminalStart() { TerminalStart.TerminalStartGroupDelay(); } private static void OnTerminalQuit() { if (MenusContainer.AllMenus.Count != 0) { MenusContainer.AllMenus.FirstOrDefault((BetterMenuBase x) => x.InMenu)?.ExitTerminal.Invoke(); } } internal static void OnMenuKeyPress() { if (AllInteractiveMenus.AllMenus.Count != 0) { AllInteractiveMenus.AllMenus.FirstOrDefault((InteractiveMenu x) => x.inMenu && x.isMenuEnabled)?.HandleInput(); } if (MenusContainer.AllMenus.Count != 0) { MenusContainer.AllMenus.FirstOrDefault((BetterMenuBase x) => x.InMenu)?.InputEvent.Invoke(); } CommonTerminal.TrySyncNodeOnly(Plugin.instance.Terminal.currentNode); } public static void OnUsingTerminal() { Loggers.LogInfo("Start Using Terminal Postfix"); } private static bool ParseFailed(TerminalNode terminalNode, Terminal self) { if ((Object)(object)terminalNode == (Object)(object)self.terminalNodes.specialNodes[10]) { return true; } if ((Object)(object)terminalNode == (Object)(object)self.terminalNodes.specialNodes[11]) { return true; } if ((Object)(object)terminalNode == (Object)(object)self.terminalNodes.specialNodes[12]) { return true; } return false; } public static TerminalNode OnParseSent(ref TerminalNode node) { Loggers.LogDebug("parsing sentence"); if ((Object)(object)node == (Object)null) { Loggers.WARNING("node detected as NULL, returning..."); return node; } if (ParseFailed(node, Plugin.instance.Terminal)) { string text = Plugin.instance.Terminal.screenText.text; int textAdded = Plugin.instance.Terminal.textAdded; int length = text.Length; int num = length - textAdded; string text2 = text.Substring(num, length - num); if (text2.Length > 0) { if (LogicHandling.GetDisplayFromFaux(ConfigSetup.defaultListing.fauxKeywords, text2, ref node)) { Loggers.LogInfo("faux word detected on current node!"); } if (CommonTerminal.TryGetNodeFromList(text2, ConfigSetup.defaultListing.specialListString, out TerminalNode returnNode)) { node = returnNode; Loggers.LogDebug("node found matching specialListString in text - " + text2); } if (CommonTerminal.TryGetCommand(text2, out TerminalNode returnNode2)) { node = returnNode2; Loggers.LogDebug("node found matching CommandManager listing in text - " + text2); } } } if (LogicHandling.GetNewDisplayText(ConfigSetup.defaultListing, ref node)) { Loggers.LogInfo("node found: " + ((Object)node).name); } if (LogicHandling.GetDisplayTextFromCommand(ref node)) { Loggers.LogInfo("command found: " + ((Object)node).name); } return node; } public static void OnLoadNewNode(TerminalNode node) { if (!((Object)(object)node == (Object)null)) { Loggers.LogDebug(((Object)node).name + " has been loaded"); if (node.acceptAnything && node.terminalOptions.Length < 1) { node.acceptAnything = false; Loggers.LogDebug("fixing node property to avoid errors! (eg. LLL route locked)"); } } } } } namespace OpenLib.CoreMethods { public class AddingThings { private static readonly char[] NewLineChars = Environment.NewLine.ToCharArray(); public static void AddKeywordToExistingNode(string keyWord, TerminalNode existingNode, bool addToList = true) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); List list2 = new List(); TerminalKeyword val = BasicTerminal.CreateNewTerminalKeyword(keyWord + "_keyword", keyWord.ToLower()); val.isVerb = false; val.specialKeywordResult = existingNode; if (existingNode.terminalOptions != null) { list2 = existingNode.terminalOptions.ToList(); Loggers.LogDebug(((Object)existingNode).name + " has existing terminalOptions"); } CompatibleNoun item = new CompatibleNoun(val, existingNode); list2.Add(item); existingNode.terminalOptions = list2.ToArray(); list.Add(val); if (addToList) { Plugin.KeywordsAdded.Add(val); } Loggers.LogDebug("Adding " + keyWord + " to existing node " + ((Object)existingNode).name); Plugin.instance.Terminal.terminalNodes.allKeywords = list.ToArray(); } public static TerminalKeyword AddKeywordToNode(string keyWord, TerminalNode existingNode, bool addToList = true) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); List list2 = new List(); TerminalKeyword val = BasicTerminal.CreateNewTerminalKeyword(keyWord + "_keyword", keyWord.ToLower()); val.isVerb = false; val.specialKeywordResult = existingNode; if (existingNode.terminalOptions != null) { list2 = existingNode.terminalOptions.ToList(); Loggers.LogDebug(((Object)existingNode).name + " has existing terminalOptions"); } CompatibleNoun item = new CompatibleNoun(val, existingNode); list2.Add(item); existingNode.terminalOptions = list2.ToArray(); list.Add(val); if (addToList) { Plugin.KeywordsAdded.Add(val); } Loggers.LogDebug("Adding " + keyWord + " to existing node " + ((Object)existingNode).name); Plugin.instance.Terminal.terminalNodes.allKeywords = list.ToArray(); return val; } public static void AddToHelpCommand(string textToAdd) { TerminalNode val = Plugin.instance.Terminal.terminalNodes.specialNodes[13]; if (val.displayText.Contains(textToAdd)) { Loggers.WARNING("Help command already contains this text: " + textToAdd); return; } int startIndex = val.displayText.LastIndexOf('['); val.displayText = val.displayText.Insert(startIndex, textToAdd + "\r\n\r\n"); } public static void AddToExistingNodeText(string textToAdd, ref TerminalNode existingNode) { if (existingNode.displayText.Contains(textToAdd)) { Plugin.Log.LogWarning((object)("Unable to add below text to " + ((Object)existingNode).name + ", it already has this text in it")); return; } Loggers.LogDebug($"oldtext length {existingNode.displayText.Length}"); Loggers.LogDebug(existingNode.displayText); string text = existingNode.displayText.TrimEnd(NewLineChars); text = text + "\n" + textToAdd + "\r\n\r\n"; existingNode.displayText = text; Loggers.LogDebug(((Object)existingNode).name + " text updated!!!"); } public static TerminalNode CreateDummyNode(string nodeName, bool clearPrevious, string displayText) { if (DynamicBools.UseMatchingNode(nodeName, out TerminalNode returnNode)) { returnNode.displayText = displayText; returnNode.clearPreviousText = clearPrevious; } else { returnNode = BasicTerminal.CreateNewTerminalNode(); ((Object)returnNode).name = nodeName; returnNode.displayText = displayText; returnNode.clearPreviousText = clearPrevious; } return returnNode; } public static void AddBasicCommand(string nodeName, string keyWord, string displayText, bool isVerb, bool clearText, string category = "", string keywordDescription = "") { //IL_00ed: Unknown result type (might be due to invalid IL or missing references) if (!LogicHandling.TryGetFromAllNodes("OtherCommands", out TerminalNode outNode) && Misc.CompareStringsInvariant(category, "other")) { Loggers.WARNING("Unable to add " + keyWord + " to " + category + "\n" + category + " TerminalNode could not be found!"); return; } List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); if (!DynamicBools.IsCommandCreatedAlready(keyWord, displayText, list)) { CommonThings.CheckForAndDeleteKeyWord(keyWord.ToLower()); TerminalNode val = BasicTerminal.CreateNewTerminalNode(); ((Object)val).name = nodeName; val.displayText = displayText; val.clearPreviousText = clearText; TerminalKeyword val2 = BasicTerminal.CreateNewTerminalKeyword(nodeName + "_keyword", keyWord.ToLower()); ((Object)val2).name = nodeName + "_keyword"; val2.word = keyWord.ToLower(); val2.isVerb = isVerb; val2.specialKeywordResult = val; new CompatibleNoun(val2, val); list.Add(val2); Plugin.instance.Terminal.terminalNodes.allKeywords = list.ToArray(); if (!Plugin.NodesAdded.Contains(val)) { Plugin.NodesAdded.Add(val); } if (!Plugin.KeywordsAdded.Contains(val2)) { Plugin.KeywordsAdded.Add(val2); } if (Misc.CompareStringsInvariant(category, "other") && (Object)(object)outNode != (Object)null) { AddToExistingNodeText(keywordDescription ?? "", ref outNode); Loggers.LogDebug("adding node to other listing"); } } } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static TerminalNode AddNodeManual(string nodeName, string stringValue, Func commandAction, bool clearText, int CommandType, MainListing yourModListing, int price = 0, Func ConfirmAction = null, Func DenyAction = null, string confirmText = "", string denyText = "", bool alwaysInStock = false, int maxStock = 1, string storeName = "", bool reuseFunc = false, string itemList = "") { TerminalNode val = null; List list = new List(); if (stringValue != null) { list = CommonStringStuff.GetKeywordsPerConfigItem(stringValue); } foreach (string item in list) { val = BaseCommandCreation(nodeName, item, commandAction, clearText, CommandType, yourModListing, price, ConfirmAction, DenyAction, confirmText, denyText, alwaysInStock, maxStock, storeName, reuseFunc, itemList); } if ((Object)(object)val == (Object)null) { Loggers.WARNING("Returning NULL terminal node @AddNodeManual!!!"); } return val; } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static TerminalNode AddNodeManual(string nodeName, ConfigEntry stringValue, Func commandAction, bool clearText, int CommandType, MainListing yourModListing, List managedBools, string category = "", string description = "", int price = 0, Func ConfirmAction = null, Func DenyAction = null, string confirmText = "", string denyText = "", bool alwaysInStock = false, int maxStock = 1, string storeName = "", bool reuseFunc = false, string itemList = "") { TerminalNode val = null; List list = new List(); bool flag = true; if (stringValue != null) { flag = false; list = CommonStringStuff.GetKeywordsPerConfigItem(stringValue.Value); } foreach (string item in list) { val = BaseCommandCreation(nodeName, item, commandAction, clearText, CommandType, yourModListing, price, ConfirmAction, DenyAction, confirmText, denyText, alwaysInStock, maxStock, storeName, reuseFunc, itemList); } if ((Object)(object)val == (Object)null) { Loggers.WARNING("Returning NULL terminal node @AddNodeManual!!!"); } if (ManagedBoolGet.CanAddToManagedBoolList(managedBools, nodeName)) { TerminalMenuItem menuItem = new TerminalMenuItem { Category = category, itemDescription = description, ItemName = nodeName, itemKeywords = list }; ManagedConfig managedConfig = new ManagedConfig { TerminalNode = val, menuItem = menuItem, ConfigItemName = nodeName }; managedBools.Add(managedConfig); if (!flag) { ConfigSetup.AddManagedString(stringValue, ref managedBools, managedConfig); } } return val; } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static TerminalNode CreateNode(TerminalMenu terminalMenu, string nodeName, string keyWord, Func commandAction, MainListing yourModListing, bool isNextPageCommand = false) { List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); Loggers.LogDebug(nodeName ?? ""); Loggers.LogDebug(keyWord); bool clearPreviousText = true; CommonThings.CheckForAndDeleteKeyWord(keyWord.ToLower()); TerminalNode val = BasicTerminal.CreateNewTerminalNode(); ((Object)val).name = nodeName; val.displayText = nodeName; val.clearPreviousText = clearPreviousText; val.buyUnlockable = false; Loggers.LogDebug("node created"); TerminalKeyword val2 = BasicTerminal.CreateNewTerminalKeyword(nodeName + "_keyword", keyWord.ToLower()); val2.isVerb = false; val2.specialKeywordResult = val; Loggers.LogDebug("keyword created"); yourModListing.Listing.Add(val, commandAction); Loggers.LogDebug("func added to listing"); if (!isNextPageCommand) { terminalMenu.terminalNodePerCategory.Add(keyWord, val); Loggers.LogDebug("added terminalNode to menus nodelisting"); } list.Add(val2); Plugin.KeywordsAdded.Add(val2); Plugin.instance.Terminal.terminalNodes.allKeywords = list.ToArray(); Loggers.LogDebug("added to all keyword lists"); return val; } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static void InfoText(ManagedConfig managedBool, string keyWord, TerminalKeyword infoWord, MainListing yourModListing) { if (managedBool.InfoAction != null) { TerminalNode val = BasicTerminal.CreateNewTerminalNode(); ((Object)val).name = "info_" + keyWord; val.displayText = "infoAction should replace this"; yourModListing.Listing.Add(val, managedBool.InfoAction); val.clearPreviousText = true; AddCompatibleNoun(ref infoWord, keyWord, val); Loggers.LogDebug("info node created with infoAction!"); } else if (managedBool.InfoText.Length > 1) { TerminalNode val2 = BasicTerminal.CreateNewTerminalNode(); ((Object)val2).name = "info_" + keyWord; val2.displayText = managedBool.InfoText; val2.clearPreviousText = true; AddCompatibleNoun(ref infoWord, keyWord, val2); Loggers.LogDebug("info node created"); } } public static void AddToFauxListing(FauxKeyword fauxWord, MainListing yourListing) { if (fauxWord != null && fauxWord.Keyword != null && (Object)(object)fauxWord.MainPage != (Object)null) { yourListing.fauxKeywords.Add(fauxWord); } } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static TerminalNode CreateNode(ManagedConfig managedBool, string keyWord, MainListing yourModListing) { List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); Func mainAction = managedBool.MainAction; string text; if (managedBool.nodeName.Length < 2) { text = managedBool.ConfigItemName; Loggers.LogDebug("managedBool nodename is blank, using configitemname"); } else { text = managedBool.nodeName; Loggers.LogDebug("using nodeName: " + text); } bool clearText = managedBool.clearText; TerminalNode val = BaseCommandCreation(text, keyWord, mainAction, managedBool.clearText, managedBool.CommandType, yourModListing, managedBool.price, managedBool.ConfirmAction, managedBool.DenyAction, managedBool.confirmText, managedBool.denyText, managedBool.alwaysInStock, managedBool.maxStock, managedBool.storeName, managedBool.reuseFunc, managedBool.itemList); if ((Object)(object)val == (Object)null) { Loggers.WARNING("terminalNode is NULL at CreateNode!!!"); } return val; } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static void AddConfirm(string nodeName, ManagedConfig managedBool, Dictionary> nodeListing, out CompatibleNoun confirm, out CompatibleNoun deny) { confirm = BasicTerminal.CreateCompatibleNoun(nodeName, "confirm", managedBool.confirmText, managedBool.price, managedBool.ConfirmAction, nodeListing); deny = BasicTerminal.CreateCompatibleNoun(nodeName, "deny", managedBool.denyText, managedBool.price, managedBool.DenyAction, nodeListing); } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static void AddConfirm(string nodeName, int price, Func ConfirmAction, Func DenyAction, string confirmText, string denyText, Dictionary> nodeListing, out CompatibleNoun confirm, out CompatibleNoun deny) { confirm = BasicTerminal.CreateCompatibleNoun(nodeName, "confirm", confirmText, price, ConfirmAction, nodeListing); deny = BasicTerminal.CreateCompatibleNoun(nodeName, "deny", denyText, price, DenyAction, nodeListing); } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static void AddStoreCommand(string nodeName, ref TerminalKeyword keyword, ManagedConfig managedBool, MainListing mainListing, out CompatibleNoun confirm, out CompatibleNoun deny) { if ((Object)(object)managedBool.TerminalNode == (Object)null) { Loggers.ERROR("node is null when adding store command!!!"); confirm = null; deny = null; } else if (managedBool.ConfirmAction != null) { AddConfirm(nodeName, managedBool, mainListing.Listing, out confirm, out deny); StoreStuff(nodeName, managedBool.storeName, ref keyword, ref managedBool.TerminalNode, managedBool.price, managedBool.alwaysInStock, managedBool.maxStock, ref confirm, ref deny); } else { Loggers.ERROR("Shop nodes NEED confirmation, but confirmAction is null for " + nodeName + "!"); confirm = null; deny = null; } } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static void AddStoreCommand(string nodeName, string storeName, ref TerminalKeyword keyword, ref TerminalNode node, int price, Func ConfirmAction, Func DenyAction, string confirmText, string denyText, MainListing mainListing, bool alwaysInStock, int maxStock, out CompatibleNoun confirm, out CompatibleNoun deny) { if ((Object)(object)node == (Object)null) { Loggers.ERROR("node is null when adding store command!!!"); confirm = null; deny = null; } else if (ConfirmAction != null) { AddConfirm(nodeName, price, ConfirmAction, DenyAction, confirmText, denyText, mainListing.Listing, out confirm, out deny); StoreStuff(nodeName, storeName, ref keyword, ref node, price, alwaysInStock, maxStock, ref confirm, ref deny); } else { Loggers.ERROR("Shop nodes NEED confirmation, but confirmAction is null for " + nodeName + "!"); confirm = null; deny = null; } } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static void StoreStuff(string nodeName, string storeName, ref TerminalKeyword keyword, ref TerminalNode node, int price, bool alwaysInStock, int maxStock, ref CompatibleNoun confirm, ref CompatibleNoun deny) { node.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2] { confirm, deny }; UnlockableItem item = AddUnlockable(nodeName, node, alwaysInStock, maxStock); if (!StartOfRound.Instance.unlockablesList.unlockables.Contains(item)) { StartOfRound.Instance.unlockablesList.unlockables.Add(item); } int shipUnlockableID = StartOfRound.Instance.unlockablesList.unlockables.IndexOf(item); node.creatureName = storeName; node.shipUnlockableID = shipUnlockableID; confirm.result.shipUnlockableID = shipUnlockableID; confirm.result.buyUnlockable = false; confirm.result.itemCost = price; if (DynamicBools.TryGetKeyword("buy", out TerminalKeyword terminalKeyword)) { AddToBuyWord(ref terminalKeyword, ref keyword, item); } Plugin.ShopNodes.Add(node); Loggers.LogDebug("Store nodes created for " + nodeName); } public static UnlockableItem AddUnlockable(string storeName, TerminalNode node, bool alwaysInStock, int maxStock) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown if (DynamicBools.TryGetAndReturnUnlockable(storeName, out UnlockableItem itemOut)) { Loggers.LogDebug("found matching item for " + storeName); itemOut.unlockableType = 1; itemOut.shopSelectionNode = node; itemOut.alwaysInStock = alwaysInStock; itemOut.IsPlaceable = false; itemOut.spawnPrefab = false; itemOut.maxNumber = maxStock; return itemOut; } Loggers.LogDebug("Creating unlockable item manually for item: " + storeName); return new UnlockableItem { unlockableType = 1, unlockableName = storeName, shopSelectionNode = node, alwaysInStock = alwaysInStock, IsPlaceable = false, spawnPrefab = false, maxNumber = maxStock }; } public static void AddToBuyWord(ref TerminalKeyword buyKeyword, ref TerminalKeyword terminalKeyword, UnlockableItem item) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown terminalKeyword.defaultVerb = buyKeyword; Loggers.LogDebug("Added buy verb to " + buyKeyword.word); CompatibleNoun item2 = new CompatibleNoun(terminalKeyword, item.shopSelectionNode); List list = buyKeyword.compatibleNouns.ToList(); list.Add(item2); Plugin.NounsAdded.Add(item2); buyKeyword.compatibleNouns = list.ToArray(); } [Obsolete("Use AddCompatibleNoun instead")] public static void AddToKeyword(ref TerminalKeyword originalKeyword, ref TerminalKeyword newWord) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown if (!originalKeyword.isVerb) { Plugin.Log.LogWarning((object)"AddToKeyword called on non-verb"); return; } newWord.defaultVerb = originalKeyword; Loggers.LogDebug("Added verb " + originalKeyword.word + " to " + newWord.word); CompatibleNoun item = new CompatibleNoun(newWord, newWord.specialKeywordResult); List list = originalKeyword.compatibleNouns.ToList(); list.Add(item); Plugin.NounsAdded.Add(item); originalKeyword.compatibleNouns = list.ToArray(); } public static void AddCompatibleNoun(ref TerminalKeyword originalWord, string word, TerminalNode resultNode) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown if (!originalWord.isVerb) { Loggers.WARNING(originalWord.word + " is NOT a verb"); return; } List list = originalWord.compatibleNouns.ToList(); foreach (CompatibleNoun item in list) { if (Misc.CompareStringsInvariant(item.noun.word, word)) { Loggers.WARNING("NOUN: " + item.noun.word + " already exists for WORD: " + originalWord.word); return; } } if (DynamicBools.TryGetKeyword(word, out TerminalKeyword terminalKeyword)) { CompatibleNoun val = new CompatibleNoun(terminalKeyword, resultNode); list.Add(val); originalWord.compatibleNouns = list.ToArray(); Loggers.LogDebug("Added NOUN: " + val.noun.word + " to WORD: " + originalWord.word + " compatible nouns"); Plugin.NounsAdded.Add(val); } else { Loggers.WARNING("word: " + word + " does not exist, unable to add as compatible noun"); } } [Obsolete("use CommandManager class, if equivalent method does not exist will exist in the future")] public static TerminalNode BaseCommandCreation(string nodeName, string keyWord, Func commandAction, bool clearText, int CommandType, MainListing yourModListing, int price, Func ConfirmAction, Func DenyAction, string confirmText, string denyText, bool alwaysInStock, int maxStock, string storeName, bool reuseFunc, string itemList) { List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); if (DynamicBools.IsCommandCreatedAlready(yourModListing.Listing, keyWord, commandAction, list, out TerminalKeyword outKeyword) && !reuseFunc) { return outKeyword.specialKeywordResult; } CommonThings.CheckForAndDeleteKeyWord(keyWord.ToLower()); if (DynamicBools.DoesNodeExist(yourModListing.Listing, commandAction, out TerminalNode node) && !reuseFunc) { AddKeywordToExistingNode(keyWord, node); Loggers.LogDebug("existing node found " + ((Object)node).name + ", reusing associated func and adding additional keyword " + keyWord); return node; } TerminalNode node2 = BasicTerminal.CreateNewTerminalNode(); ((Object)node2).name = nodeName; node2.displayText = nodeName; node2.clearPreviousText = clearText; node2.buyUnlockable = false; TerminalKeyword keyword = BasicTerminal.CreateNewTerminalKeyword(nodeName + "_keyword", keyWord.ToLower()); keyword.isVerb = false; keyword.specialKeywordResult = node2; CompatibleNoun confirm = null; CompatibleNoun deny = null; switch (CommandType) { case 1: AddConfirm(nodeName, price, ConfirmAction, DenyAction, confirmText, denyText, yourModListing.Listing, out confirm, out deny); node2.acceptAnything = false; Loggers.LogDebug("command type 1 detected, adding basic confirmation"); break; case 2: AddStoreCommand(nodeName, storeName, ref keyword, ref node2, price, ConfirmAction, DenyAction, confirmText, denyText, yourModListing, alwaysInStock, maxStock, out confirm, out deny); Loggers.LogDebug("command type 2 detected, adding store logic"); node2.acceptAnything = false; yourModListing.shopNodes.Add(confirm.result); yourModListing.shopNodes.Add(node2); yourModListing.shopNodes.Add(deny.result); if (itemList.Length > 1) { confirm.result.buyUnlockable = false; yourModListing.storePacks.Add(node2, itemList); Loggers.LogDebug("storepack detected, adding itemlist"); } break; } if (confirm != null && deny != null) { list.Add(confirm.noun); Plugin.KeywordsAdded.Add(confirm.noun); list.Add(deny.noun); Plugin.KeywordsAdded.Add(deny.noun); node2.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2] { confirm, deny }; node2.overrideOptions = true; } else { Loggers.LogDebug("no confirmation logic added for " + keyWord); } yourModListing.Listing.Add(node2, commandAction); list.Add(keyword); if (!Plugin.NodesAdded.Contains(node2)) { Plugin.NodesAdded.Add(node2); } if (!Plugin.KeywordsAdded.Contains(keyword)) { Plugin.KeywordsAdded.Add(keyword); } Plugin.instance.Terminal.terminalNodes.allKeywords = list.ToArray(); return node2; } [Obsolete("use AddCompatibleNoun")] public static void AddNounWordSimple(string originalVerb, string nodeName, string keyWord, string displayText, bool clearText) { } } public class CommandManager { public string Name = string.Empty; public string Category = string.Empty; public ConfigWatch IsEnabled; public bool IsCreated; public ConfigEntry KeywordsConfig; public List KeywordList = new List(); public Func MainAction; public bool ClearText = true; public bool AddAtAwake = true; public bool AcceptAdditionalText; public int CommandType; public NodeInfo InfoBase; public NodeConfirmation ConfirmBase; public int VerySpecialNum = -1; public NodeStore StoreBase; public TerminalNode terminalNode; public List terminalKeywords = new List(); public CommandManager(string commandName, ConfigEntry CommandBool, ConfigEntry keywords, Func commandFunc, int type = 0, bool addToMain = true) { Name = commandName; IsEnabled = new ConfigWatch(CommandBool); KeywordsConfig = keywords; MainAction = commandFunc; CommandType = Mathf.Clamp(type, 0, 2); if (addToMain) { Plugin.AllCommands.Add(this); } InfoBase = new NodeInfo(this); ConfirmBase = new NodeConfirmation(this); StoreBase = new NodeStore(this); } public CommandManager(string commandName, ConfigEntry keywords, Func commandFunc, int type = 0, bool addToMain = true) { Name = commandName; KeywordsConfig = keywords; MainAction = commandFunc; CommandType = Mathf.Clamp(type, 0, 2); if (addToMain) { Plugin.AllCommands.Add(this); } InfoBase = new NodeInfo(this); ConfirmBase = new NodeConfirmation(this); StoreBase = new NodeStore(this); } public CommandManager(string commandName, ConfigEntry CommandBool, List manualWords, Func commandFunc, int type = 0, bool addToMain = true) { Name = commandName; IsEnabled = new ConfigWatch(CommandBool); KeywordList = manualWords; MainAction = commandFunc; CommandType = Mathf.Clamp(type, 0, 2); if (addToMain) { Plugin.AllCommands.Add(this); } } public CommandManager(string commandName, List manualWords, Func commandFunc, ConfigEntry CommandBool = null, int type = 0, bool addToMain = true) { Name = commandName; KeywordList = manualWords; MainAction = commandFunc; CommandType = Mathf.Clamp(type, 0, 2); if (CommandBool != null) { IsEnabled = new ConfigWatch(CommandBool); } if (addToMain) { Plugin.AllCommands.Add(this); } InfoBase = new NodeInfo(this); ConfirmBase = new NodeConfirmation(this); StoreBase = new NodeStore(this); } public bool IsCommandEnabled() { if (IsEnabled == null) { return true; } if (!IsEnabled.NetworkingReq || IsEnabled.networkingConfig == null) { return IsEnabled.ConfigItem.Value; } if (IsEnabled.NetworkingReq && IsEnabled.networkingConfig.Value) { return IsEnabled.ConfigItem.Value; } return false; } public void SetInfoText(string infoText) { if (InfoBase == null) { InfoBase = new NodeInfo(this); } InfoBase.InfoText = infoText; } public void SetInfoAction(Func action) { if (InfoBase == null) { InfoBase = new NodeInfo(this); } InfoBase.InfoAction = action; } public void SetupConfirmation(Func confirm, Func deny) { if (ConfirmBase == null) { ConfirmBase = new NodeConfirmation(this); } if (confirm != null) { ConfirmBase.SetConfirmAction(confirm); } if (deny != null) { ConfirmBase.SetDenyAction(deny); } } public void SetupConfirmation(string confirmText, string denyText) { if (ConfirmBase == null) { ConfirmBase = new NodeConfirmation(this); } if (!string.IsNullOrEmpty(confirmText)) { ConfirmBase.SetConfirmText(confirmText); } if (!string.IsNullOrEmpty(denyText)) { ConfirmBase.SetDenyText(denyText); } } public void SetupStore(string displayName, ConfigEntry priceConfig, int maxStock = 0, bool alwaysInStock = false) { if (StoreBase == null) { StoreBase = new NodeStore(this); } StoreBase.Name = displayName; StoreBase.PriceConfig = priceConfig; StoreBase.MaxStock = maxStock; StoreBase.AlwaysInStock = alwaysInStock; } public void SetupStore(string displayName, int manualPrice, int maxStock = 0, bool alwaysInStock = false) { if (StoreBase == null) { StoreBase = new NodeStore(this); } StoreBase.Name = displayName; StoreBase.ManualPrice = manualPrice; StoreBase.MaxStock = maxStock; StoreBase.AlwaysInStock = alwaysInStock; } public void AddToDefaultListing() { if (!Plugin.AllCommands.Contains(this)) { Plugin.AllCommands.Add(this); } } internal static void AddAllCommandsToTerminal() { if (Plugin.AllCommands.Count != 0) { CollectionExtensions.DoIf((IEnumerable)Plugin.AllCommands, (Func)((CommandManager x) => x.AddAtAwake), (Action)delegate(CommandManager x) { x.RegisterCommand(); }); } } internal void GetInfo() { if (InfoBase == null) { InfoBase = new NodeInfo(this); InfoBase.GetDefaultInfo(this); } else if (InfoBase.InfoAction == null && InfoBase.InfoText.Length < 1) { InfoBase.GetDefaultInfo(this); } InfoBase.CreateInfoNode(); } public void TerminalDisabled() { terminalKeywords = new List(); terminalNode = null; } public void RegisterCommand() { RegisterCommand(replaceExistingKW: true); } public void RegisterCommand(bool replaceExistingKW) { if (IsCommandEnabled()) { terminalNode = BasicTerminal.CreateNewTerminalNode(); ((Object)terminalNode).name = Name; terminalNode.displayText = string.Empty; terminalNode.clearPreviousText = ClearText; if (KeywordList.Count == 0 && KeywordsConfig != null) { KeywordList = CommonStringStuff.GetKeywordsPerConfigItem(KeywordsConfig.Value); } CollectionExtensions.Do((IEnumerable)KeywordList, (Action)delegate(string w) { AddKeyword(w, replaceExistingKW); }); IsCreated = true; if (CommandType > 0) { ConfirmBase.CreateConfirmation(); } if (CommandType == 2) { StoreBase.AddToStore(); } GetInfo(); } } public void RegisterKeywords(bool check) { CollectionExtensions.Do((IEnumerable)KeywordList, (Action)delegate(string w) { AddKeyword(w, check); }); IsCreated = true; } public void RegisterNodeOnly() { if (IsCommandEnabled()) { terminalNode = BasicTerminal.CreateNewTerminalNode(); ((Object)terminalNode).name = Name; terminalNode.displayText = string.Empty; terminalNode.clearPreviousText = ClearText; IsCreated = true; } } internal void AddKeyword(string keyword, bool replaceExistingKW) { Loggers.LogDebug("adding " + keyword); TerminalKeyword val = BasicTerminal.CreateNewTerminalKeyword(Name + "_keyword", keyword, replaceExistingKW); val.specialKeywordResult = terminalNode; if (Plugin.instance.DawnLibPresent) { DawnlibCompat.SetCommandPriority(val); } terminalKeywords.Add(val); } } public class CommonThings { public static void CheckForAndDeleteKeyWord(string keyWord) { Loggers.LogDebug("Checking for " + keyWord); List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); for (int num = list.Count - 1; num >= 0; num--) { if (list[num].word.Equals(keyWord)) { Loggers.LogDebug("removing " + list[num].word); list.RemoveAt(num); break; } } Plugin.instance.Terminal.terminalNodes.allKeywords = list.ToArray(); } } public class DynamicBools { public static bool UseMatchingNode(string nodeName, out TerminalNode returnNode) { TerminalNode[] array = Object.FindObjectsOfType(); TerminalNode[] array2 = array; foreach (TerminalNode val in array2) { if (((Object)val).name.ToLower().Equals(nodeName.ToLower())) { returnNode = val; Loggers.LogDebug("Existing terminalNode [" + nodeName + "] found, using it rather than making a new one for this command"); return true; } } returnNode = null; return false; } public static bool TryGetKeyword(string keyWord) { List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); foreach (TerminalKeyword item in list) { if (Misc.CompareStringsInvariant(keyWord, item.word)) { return true; } } return false; } public static bool TryGetKeyword(string keyWord, out TerminalKeyword terminalKeyword) { List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); foreach (TerminalKeyword item in list) { if (Misc.CompareStringsInvariant(keyWord, item.word)) { Loggers.LogDebug("Keyword: [" + keyWord + "] found!"); terminalKeyword = item; return true; } } terminalKeyword = null; return false; } public static bool TryGetAndReturnUnlockable(string unlockableName, out UnlockableItem itemOut) { List list = StartOfRound.Instance.unlockablesList.unlockables.ToList(); foreach (UnlockableItem item in list) { if (item.unlockableName.Equals(unlockableName)) { itemOut = item; return true; } } itemOut = null; return false; } public static bool TryGetAndReturnItem(string unlockableName, out Item itemOut) { List list = Plugin.instance.Terminal.buyableItemsList.ToList(); foreach (Item item in list) { if (item.itemName.ToLower().Equals(unlockableName.ToLower())) { itemOut = item; return true; } } itemOut = null; return false; } public static bool IsCommandCreatedAlready(string keyWord, string displayText, List terminalKeywords) { foreach (TerminalKeyword terminalKeyword in terminalKeywords) { if (Misc.CompareStringsInvariant(terminalKeyword.word, keyWord) && terminalKeyword.specialKeywordResult.displayText == displayText) { Loggers.LogDebug("word: " + keyWord + " found with valid node: " + ((Object)terminalKeyword.specialKeywordResult).name); return true; } } return false; } public static bool IsCommandCreatedAlready(Dictionary> MainCommandListing, string keyWord, Func commandAction, List terminalKeywords) { if (MainCommandListing.Count == 0) { return false; } foreach (KeyValuePair> item in MainCommandListing) { if (!((Delegate?)item.Value == (Delegate?)commandAction)) { continue; } foreach (TerminalKeyword terminalKeyword in terminalKeywords) { if (Misc.CompareStringsInvariant(terminalKeyword.word, keyWord) && (Object)(object)terminalKeyword.specialKeywordResult == (Object)(object)item.Key) { Loggers.LogDebug("word: " + keyWord + " found with valid node: " + ((Object)terminalKeyword.specialKeywordResult).name); return true; } } } return false; } public static bool IsCommandCreatedAlready(Dictionary> MainCommandListing, string keyWord, Func commandAction, List terminalKeywords, out TerminalKeyword outKeyword) { outKeyword = null; if (MainCommandListing.Count == 0) { return false; } foreach (KeyValuePair> item in MainCommandListing) { if (!((Delegate?)item.Value == (Delegate?)commandAction)) { continue; } foreach (TerminalKeyword terminalKeyword in terminalKeywords) { if (Misc.CompareStringsInvariant(terminalKeyword.word, keyWord) && (Object)(object)terminalKeyword.specialKeywordResult == (Object)(object)item.Key) { Loggers.LogDebug("word: " + keyWord + " found with valid node: " + ((Object)terminalKeyword.specialKeywordResult).name); outKeyword = terminalKeyword; return true; } } } return false; } public static bool DoesNodeExist(Dictionary> MainCommandListing, Func commandAction, out TerminalNode node) { node = null; if (MainCommandListing.Count == 0) { return false; } foreach (KeyValuePair> item in MainCommandListing) { if (!((Object)(object)item.Key == (Object)null) && (Delegate?)item.Value == (Delegate?)commandAction) { node = item.Key; return true; } } return false; } } public class FauxKeyword { public TerminalNode? MainPage; public TerminalNode? thisNode = BasicTerminal.CreateNewTerminalNode(); public string? Keyword; public Func? ResultFunc; public Func? ConfirmFunc; public Func? DenyFunc; public string? ConfirmText; public string? DenyText; public bool? GetConfirm; public bool AllowOtherFauxWords; public bool requireExact; public FauxKeyword(string mainWord, string keyword, Func resultFunc) { TerminalKeyword terminalKeyword; if (keyword.Length < 3) { Loggers.WARNING("Unable to create FauxKeyword for {keyword}! It's too short!"); } else if (DynamicBools.TryGetKeyword(mainWord, out terminalKeyword)) { MainPage = terminalKeyword.specialKeywordResult; Keyword = keyword; ResultFunc = resultFunc; thisNode.clearPreviousText = true; ((Object)thisNode).name = keyword; Loggers.LogDebug("FauxKeyword - " + keyword + " created!"); } else { Loggers.WARNING("Could not find main page at word - " + mainWord); MainPage = null; Keyword = keyword; } } public void AddConfirm(Func confirmFunc, Func denyFunc = null) { GetConfirm = false; ConfirmFunc = confirmFunc; if (denyFunc != null) { DenyFunc = denyFunc; } } public void AddText(string denyText, string confirmText = "") { GetConfirm = false; ConfirmText = confirmText; DenyText = denyText; } } public class ListManagement { public static void ClearLists() { Plugin.ShopNodes.Clear(); } } public class LogicHandling { [Obsolete("This is using the OLD system, please use GetDisplayTextFromCommand")] public static bool GetNewDisplayText(MainListing providedListing, ref TerminalNode node) { if (providedListing.Listing.Count == 0) { return false; } Dictionary> listing = providedListing.Listing; if (listing.Count < 1) { return false; } Loggers.LogDebug("command dictionary is not null in provided listing"); if ((Object)(object)node == (Object)null) { return false; } if (listing.TryGetValue(node, out var value)) { NewDisplayTextEventInvoke(ref node); CommonTerminal.parseNode = node; Loggers.LogDebug("Func found for " + ((Object)node).name); node.displayText = value(); return true; } Loggers.LogDebug("Not in special nodeListing dictionary"); return false; } public static List GetConfirmationNodes() { List activeCommands = Plugin.GetActiveCommands(); return activeCommands.ConvertAll((CommandManager x) => x.ConfirmBase).FindAll((NodeConfirmation x) => x != null); } public static bool GetDisplayTextFromCommand(ref TerminalNode node) { if ((Object)(object)node == (Object)null || Plugin.AllCommands.Count == 0) { return false; } List activeCommands = Plugin.GetActiveCommands(); TerminalNode current = node; CommandManager commandManager = activeCommands.FirstOrDefault((CommandManager f) => (Object)(object)f.terminalNode == (Object)(object)current); if (commandManager != null) { CommonTerminal.parseNode = node; NewDisplayTextEventInvoke(ref node); node.displayText = commandManager.MainAction(); Loggers.LogDebug("CommandManager found for " + ((Object)node).name + ", returning MainAction"); return true; } CommandManager commandManager2 = activeCommands.FirstOrDefault((CommandManager i) => i.InfoBase.InfoAction != null && (Object)(object)i.InfoBase.terminalNode == (Object)(object)current); if (commandManager2 != null) { CommonTerminal.parseNode = node; NewDisplayTextEventInvoke(ref node); node.displayText = commandManager2.InfoBase.InfoAction(); Loggers.LogDebug("CommandManager found for " + ((Object)node).name + ", returning InfoAction"); return true; } List confirmationNodes = GetConfirmationNodes(); NodeConfirmation nodeConfirmation = confirmationNodes.FirstOrDefault((NodeConfirmation c) => c.Confirm != null && (Object)(object)c.Confirm.result == (Object)(object)current); if (nodeConfirmation != null) { CommonTerminal.parseNode = node; NewDisplayTextEventInvoke(ref node); node.displayText = nodeConfirmation.ConfirmFunc(); Loggers.LogDebug("CommandManager found for " + ((Object)node).name + ", returning ConfirmFunc"); return true; } NodeConfirmation nodeConfirmation2 = confirmationNodes.FirstOrDefault((NodeConfirmation c) => c.Deny != null && (Object)(object)c.Deny.result == (Object)(object)current); if (nodeConfirmation2 != null) { CommonTerminal.parseNode = node; NewDisplayTextEventInvoke(ref node); node.displayText = nodeConfirmation2.DenyFunc(); Loggers.LogDebug("CommandManager found for " + ((Object)node).name + ", returning DenyFunc"); return true; } Loggers.LogDebug("No matches in GetDisplayTextFromCommand"); return false; } private static void NewDisplayTextEventInvoke(ref TerminalNode node) { if (EventManager.GetNewDisplayText.Listeners > 0) { node = EventManager.GetNewDisplayText.NodeInvoke(ref node); } } [Obsolete("Old system...")] public static bool GetNewDisplayText(List providedListing, ref TerminalNode node) { if (providedListing.Count == 0) { return false; } if ((Object)(object)node == (Object)null) { return false; } bool result = false; int num = 0; foreach (MainListing item in providedListing) { if (item.Listing.Count >= 1) { Dictionary> listing = item.Listing; num++; Loggers.LogDebug($"command dictionary in this listing is not empty ({num})"); if (listing.TryGetValue(node, out var value)) { NewDisplayTextEventInvoke(ref node); CommonTerminal.parseNode = node; Loggers.LogInfo("Func found for " + ((Object)node).name + " in one of provided listings"); node.displayText = value(); result = true; break; } Loggers.LogDebug("Not in special nodeListing dictionary"); } } Loggers.LogInfo("provided listings do not contain this node"); return result; } [Obsolete("Old system...")] public static bool GetDisplayFromFaux(List fauxWords, string words, ref TerminalNode node) { string text = words.Split(' ')[0]; foreach (FauxKeyword fauxWord in fauxWords) { if (fauxWord.ResultFunc == null || fauxWord.Keyword == null || (Object)(object)fauxWord.MainPage == (Object)null) { continue; } if ((Object)(object)fauxWord.thisNode != (Object)null) { fauxWord.thisNode.displayText = ""; } if (Misc.StringStartsWithInvariant(words, fauxWord.Keyword.Substring(0, 3)) && (Object)(object)Plugin.instance.Terminal.currentNode == (Object)(object)fauxWord.MainPage) { if (fauxWord.requireExact && Misc.CompareStringsInvariant(words, fauxWord.Keyword)) { return false; } Loggers.LogDebug("Using faux word associated with MainPage"); if (fauxWord.ConfirmFunc != null && ((!fauxWord.GetConfirm) ?? false)) { fauxWord.GetConfirm = true; } if ((Object)(object)fauxWord.thisNode != (Object)null) { fauxWord.thisNode.displayText = fauxWord.ResultFunc(); } node = fauxWord.thisNode; return true; } if ((Object)(object)Plugin.instance.Terminal.currentNode == (Object)(object)fauxWord.thisNode && (fauxWord.GetConfirm ?? false)) { Loggers.LogDebug("getting confirmation for this faux word"); if (Misc.StringStartsWithInvariant(words, 'c')) { if (fauxWord.ConfirmFunc != null) { fauxWord.thisNode.displayText = fauxWord.ConfirmFunc(); } node = fauxWord.thisNode; fauxWord.GetConfirm = false; } else if (Misc.StringStartsWithInvariant(words, 'd')) { if (fauxWord.DenyFunc != null) { fauxWord.thisNode.displayText = fauxWord.DenyFunc(); } node = fauxWord.thisNode; fauxWord.GetConfirm = false; } else { if (!Misc.StringStartsWithInvariant(words, fauxWord.Keyword)) { return false; } fauxWord.thisNode.displayText = fauxWord.ResultFunc(); node = fauxWord.thisNode; } return true; } if (Misc.StringStartsWithInvariant(words, fauxWord.Keyword.Substring(0, 3)) && fauxWords.Any((FauxKeyword f) => (Object)(object)f.thisNode == (Object)(object)Plugin.instance.Terminal.currentNode && f.AllowOtherFauxWords)) { if (fauxWord.requireExact && Misc.CompareStringsInvariant(words, fauxWord.Keyword)) { return false; } Loggers.LogDebug("Using faux word that can be called from other fauxwords"); if (fauxWord.ConfirmFunc != null && ((!fauxWord.GetConfirm) ?? false)) { fauxWord.GetConfirm = true; } if ((Object)(object)fauxWord.thisNode != (Object)null) { fauxWord.thisNode.displayText = fauxWord.ResultFunc(); } node = fauxWord.thisNode; return true; } } return false; } public static bool TryGetFuncFromTerminalNode(ref TerminalNode node, out Func returnFunc) { returnFunc = null; List activeCommands = Plugin.GetActiveCommands(); if ((Object)(object)node == (Object)null || activeCommands.Count == 0) { Loggers.WARNING("node is null or 0 custom commands have been made"); return false; } TerminalNode query = node; CommandManager commandManager = activeCommands.FirstOrDefault((CommandManager x) => (Object)(object)x.terminalNode == (Object)(object)query); if (commandManager != null) { returnFunc = commandManager.MainAction; return returnFunc != null; } NodeConfirmation nodeConfirmation = GetConfirmationNodes().FirstOrDefault((NodeConfirmation x) => MatchNodeToConfirm(x, query) || MatchNodeToDeny(x, query)); if (nodeConfirmation != null) { if (MatchNodeToConfirm(nodeConfirmation, query)) { returnFunc = nodeConfirmation.ConfirmFunc; } else if (MatchNodeToDeny(nodeConfirmation, query)) { returnFunc = nodeConfirmation.DenyFunc; } } return returnFunc != null; } public static bool MatchNodeToConfirm(NodeConfirmation item, TerminalNode node) { if (item == null) { return false; } if (item.Confirm == null) { return false; } if ((Object)(object)item.Confirm.result == (Object)null) { return false; } return (Object)(object)item.Confirm.result == (Object)(object)node; } public static bool MatchNodeToDeny(NodeConfirmation item, TerminalNode node) { if (item == null) { return false; } if (item.Deny == null) { return false; } if ((Object)(object)item.Deny.result == (Object)null) { return false; } return (Object)(object)item.Deny.result == (Object)(object)node; } [Obsolete("This is using the OLD managedbools and Listing system!!")] public static bool TryGetFuncFromNode(List providedListing, ref TerminalNode node, out Func returnFunc) { if ((Object)(object)node == (Object)null || providedListing.Count == 0) { Loggers.WARNING("node is null or listings do not exist"); returnFunc = null; return false; } int num = 0; foreach (MainListing item in providedListing) { Dictionary> listing = item.Listing; if (listing.Count >= 1) { num++; Loggers.LogDebug($"command dictionary in this listing is not null ({num})"); if (listing.TryGetValue(node, out var value)) { Loggers.LogInfo("Func found for " + ((Object)node).name + " in one of provided listings"); returnFunc = value; return true; } Loggers.LogDebug("Not in this special nodeListing dictionary"); } } Loggers.LogInfo("provided listings do not contain this node"); returnFunc = null; return false; } public static bool TryGetFromAllNodes(string nodeName, out TerminalNode outNode) { List allNodes = GetAllNodes(); outNode = null; foreach (TerminalNode item in allNodes) { if (!((Object)(object)item == (Object)null) && ((Object)item).name == nodeName) { Loggers.LogDebug(nodeName + " found!"); outNode = item; return true; } } Loggers.LogDebug(nodeName + " could not be found, result set to null."); return false; } public static List RefreshAllNodes() { CommonTerminal.AllTerminalNodes = new List(); return GetAllNodes(); } public static List GetAllNodes() { if (CommonTerminal.AllTerminalNodes.Count == 0) { CommonTerminal.AllTerminalNodes = Resources.FindObjectsOfTypeAll().ToList(); } return CommonTerminal.AllTerminalNodes; } public static void SetTerminalInput(string terminalInput) { Terminal terminal = Plugin.instance.Terminal; string currentText = Plugin.instance.Terminal.currentText; int textAdded = Plugin.instance.Terminal.textAdded; terminal.TextChanged(currentText.Substring(0, currentText.Length - textAdded) + terminalInput); Plugin.instance.Terminal.screenText.text = Plugin.instance.Terminal.currentText; Plugin.instance.Terminal.textAdded = terminalInput.Length; } [Obsolete("Use TryGetFuncFromNode instead to avoid getting NULL funcs")] public static Func GetFuncFromNode(List providedListing, ref TerminalNode node) { if ((Object)(object)node == (Object)null || providedListing.Count == 0) { Loggers.WARNING("node is null or listings do not exist"); return null; } int num = 0; foreach (MainListing item in providedListing) { Dictionary> listing = item.Listing; if (listing.Count >= 1) { num++; Loggers.LogDebug($"command dictionary in this listing is not null ({num})"); if (listing.TryGetValue(node, out var value)) { Loggers.LogInfo("Func found for " + ((Object)node).name + " in one of provided listings"); return value; } Loggers.LogDebug("Not in this special nodeListing dictionary"); } } Loggers.LogInfo("provided listings do not contain this node"); return null; } [Obsolete("Use TryGetFromAllNodes instead to avoid getting NULL funcs")] public static TerminalNode GetFromAllNodes(string nodeName) { List allNodes = GetAllNodes(); foreach (TerminalNode item in allNodes) { if (!((Object)(object)item == (Object)null) && ((Object)item).name == nodeName) { Loggers.LogDebug(nodeName + " found!"); return item; } } Loggers.LogDebug(nodeName + " could not be found, result set to null."); return null; } } public class MainListing { public List terminalNodes = new List(); public List terminalKeywords = new List(); public Dictionary> Listing = new Dictionary>(); public List shopNodes = new List(); public List fauxKeywords = new List(); public Dictionary specialListNum = new Dictionary(); public Dictionary specialListString = new Dictionary(); public Dictionary ListNumToString = new Dictionary(); public Dictionary storePacks = new Dictionary(); public void DeleteAll() { terminalKeywords.Clear(); terminalNodes.Clear(); Listing.Clear(); shopNodes.Clear(); specialListNum.Clear(); specialListString.Clear(); ListNumToString.Clear(); storePacks.Clear(); fauxKeywords.Clear(); } } public class CommandRegistry { public static void InitListing(ref MainListing listingName) { if (listingName == null) { listingName = new MainListing(); } listingName.terminalNodes = new List(); listingName.terminalKeywords = new List(); listingName.Listing = new Dictionary>(); listingName.shopNodes = new List(); listingName.specialListNum = new Dictionary(); listingName.specialListString = new Dictionary(); listingName.ListNumToString = new Dictionary(); if (listingName == null) { Loggers.ERROR("InitListing still null"); } } public static void GetCommandsToAdd(List managedBools, MainListing listingName) { Loggers.LogInfo("GetCommandsToAdd"); if (managedBools == null || listingName == null) { Loggers.LogDebug("params are null"); return; } Loggers.LogDebug($"listing count: {listingName.Listing.Count}"); foreach (ManagedConfig managedBool in managedBools) { if (managedBool.BoolValue) { Loggers.LogDebug("configvalue is true"); TerminalMenuItem terminalMenuItem = MenuBuild.MakeMenuItem(managedBool); if (terminalMenuItem != null) { managedBool.menuItem = terminalMenuItem; } Loggers.LogInfo(managedBool.ConfigItemName + " found in managed bools and is active"); if (managedBool.KeywordList == null) { continue; } AddCommandKeyword(managedBool, listingName); if (Misc.CompareStringsInvariant(managedBool.categoryText, "other")) { if (!LogicHandling.TryGetFromAllNodes("OtherCommands", out TerminalNode outNode)) { Loggers.WARNING("Unable to add " + managedBool.configDescription + " to OtherCommands\nOtherCommands TerminalNode could not be found!"); } else { AddingThings.AddToExistingNodeText("\n" + managedBool.configDescription, ref outNode); } } } else { Loggers.LogDebug("configvalue is false, deleting menuItem if not null"); managedBool.menuItem?.Delete(); } } } public static void AddCommandKeyword(ManagedConfig managedBool, MainListing listingName) { if (managedBool == null) { Loggers.ERROR("managedBool is null @AddCommandKeyword()"); return; } if (managedBool.KeywordList.Count == 0) { Loggers.LogDebug("KeywordList Count = 0 for " + managedBool.ConfigItemName); return; } Loggers.LogDebug("AddCommandKeyword starting:"); foreach (string keyword in managedBool.KeywordList) { Loggers.LogDebug("adding " + keyword); GenerateInfoText(managedBool); managedBool.TerminalNode = AddingThings.CreateNode(managedBool, keyword, listingName); if (DynamicBools.TryGetKeyword("info", out TerminalKeyword terminalKeyword)) { AddingThings.InfoText(managedBool, keyword, terminalKeyword, listingName); } if (managedBool.specialNum != -1 && !listingName.specialListNum.ContainsKey(managedBool.TerminalNode)) { listingName.specialListNum.Add(managedBool.TerminalNode, managedBool.specialNum); listingName.ListNumToString.Add(managedBool.specialNum, managedBool.specialString); Loggers.LogInfo($"Added viewnode types to dictionaries, {managedBool.specialNum}"); } else if (managedBool.specialString.Length > 1) { listingName.specialListString.Add(keyword, managedBool.TerminalNode); Loggers.LogInfo("mapping keyword" + keyword + " for " + managedBool.specialString + " node"); } } } public static void GenerateInfoText(ManagedConfig managedBool) { if (managedBool == null) { Loggers.ERROR("managedBool is null @GenerateInfoText()"); } else if (managedBool.KeywordList.Count == 0) { Loggers.LogDebug("KeywordList Count = 0 for " + managedBool.ConfigItemName); } else if (managedBool.InfoAction == null && managedBool.InfoText.Length <= 0) { if (managedBool.menuItem == null) { Loggers.LogDebug("no menu items to grab description from"); } else { managedBool.DefaultInfoText(); } } } public static void AddSpecialListString(ref MainListing listingName, TerminalNode node, string special) { if (listingName.Listing.ContainsKey(node)) { if (!listingName.specialListString.TryAdd(special, node)) { Loggers.WARNING("Listing already contains special string key " + special); } else { Loggers.LogDebug(((Object)node).name + " added to special string listing with key " + special); } } } } public class RemoveThings { public static void OnTerminalDisable() { Loggers.LogDebug("OnTerminalDisable called"); DeleteAllNodes(ref Plugin.NodesAdded); DeleteAllNouns(ref Plugin.NounsAdded); DeleteCams(); ConfigSetup.defaultListing.DeleteAll(); DeleteAllTerminalCodes(ref Plugin.AllTerminalCodes); } private static void DeleteCams() { if ((Object)(object)CamStuff.CameraData != (Object)null) { Object.Destroy((Object)(object)CamStuff.CameraData); } if ((Object)(object)CamStuff.ObcCameraHolder != (Object)null) { Object.Destroy((Object)(object)CamStuff.ObcCameraHolder); } if ((Object)(object)CamStuff.ObcCameraHolder != (Object)null) { Object.Destroy((Object)(object)CamStuff.ObcCameraHolder); } } [Obsolete("Probably dont need to do this anymore")] public static void DeleteNounWord(ref TerminalKeyword keyWord, string terminalKeyword) { List list = keyWord.compatibleNouns.ToList(); List list2 = new List(); foreach (CompatibleNoun item in list) { if (item.noun.word.ToLower() == terminalKeyword.ToLower()) { list2.Add(item); } } for (int num = list2.Count - 1; num >= 0; num--) { Loggers.LogDebug("Deleting noun: " + list2[num].noun.word + " from word: " + keyWord.word); Object.Destroy((Object)(object)list2[num].noun); } keyWord.compatibleNouns = list.ToArray(); } [Obsolete("This doesn't really work right at the moment")] public static void RemoveCompatibleNoun(ref TerminalKeyword mainWord, TerminalKeyword wordToRemove) { bool flag = false; if (mainWord.compatibleNouns == null) { return; } List list = new List(); CompatibleNoun[] compatibleNouns = mainWord.compatibleNouns; foreach (CompatibleNoun val in compatibleNouns) { if ((Object)(object)val.noun != (Object)(object)wordToRemove) { list.Add(val); continue; } flag = true; Loggers.LogDebug("Removing " + wordToRemove.word); } mainWord.compatibleNouns = list.ToArray(); Loggers.LogDebug($"DeleteCompatibleNoun of {wordToRemove.word} from {mainWord.word} complete, word removed: {flag}"); } [Obsolete("This doesn't really work right at the moment")] public static void RemoveCompatibleNoun(ref TerminalKeyword mainWord, string nounToRemove) { bool flag = false; if (mainWord.compatibleNouns == null) { return; } List list = new List(); CompatibleNoun[] compatibleNouns = mainWord.compatibleNouns; foreach (CompatibleNoun val in compatibleNouns) { if (val.noun.word.ToLower() != nounToRemove.ToLower()) { list.Add(val); continue; } flag = true; Loggers.LogDebug("Removing " + nounToRemove); } mainWord.compatibleNouns = list.ToArray(); Loggers.LogDebug($"DeleteCompatibleNoun of {nounToRemove} from {mainWord.word} complete, word removed: {flag}"); } public static void DeleteAllTerminalCodes(ref List codes) { if (codes.Count != 0) { List list = codes; for (int num = list.Count - 1; num >= 0; num--) { Loggers.LogDebug($"Deleting TerminalAccessibleCode Object: {list[num]}"); Object.Destroy((Object)(object)list[num]); } codes = new List(); } } public static void DeleteAllNouns(ref List nounsToDelete) { if (nounsToDelete.Count == 0) { Loggers.LogDebug("no nouns detected to delete"); DeleteAllKeywords(ref Plugin.KeywordsAdded); return; } List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); foreach (CompatibleNoun noun in nounsToDelete) { if (list.Any((TerminalKeyword k) => k.compatibleNouns != null && k.compatibleNouns.Contains(noun))) { List list2 = list.FindAll((TerminalKeyword k) => k.compatibleNouns != null && k.compatibleNouns.Contains(noun)); foreach (TerminalKeyword item in list2) { List list3 = item.compatibleNouns.ToList(); if (list3.Remove(noun)) { item.compatibleNouns = list3.ToArray(); Loggers.LogDebug(noun.noun.word + " removed from word: " + item.word); } else { Loggers.WARNING("Unable to remove compatible noun: " + noun.noun.word + " from word: " + item.word); } } } else { Loggers.WARNING("Unable to find any words " + noun.noun.word + " is associated to"); } } Plugin.NounsAdded.Clear(); Loggers.LogDebug("DeleteAllNouns Completed"); DeleteAllKeywords(ref Plugin.KeywordsAdded); } public static void DeleteAllKeywords(ref List keywordList) { if (keywordList.Count == 0) { return; } List list = keywordList; List list2 = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); foreach (TerminalKeyword keyword in keywordList) { for (int num = list2.Count - 1; num >= 0; num--) { if ((Object)(object)list2[num] == (Object)(object)keyword) { Loggers.LogDebug("Removing " + keyword.word + " from all keywords list"); list2.RemoveAt(num); break; } } } for (int num2 = list.Count - 1; num2 >= 0; num2--) { Loggers.LogDebug("Deleting keyword Object: " + list[num2].word); Object.Destroy((Object)(object)list[num2]); } keywordList.Clear(); Plugin.instance.Terminal.terminalNodes.allKeywords = list2.ToArray(); } public static void DeleteAllNodes(ref Dictionary nodeDictionary) { List list = new List(); foreach (KeyValuePair item in nodeDictionary) { list.Add(item.Key); } nodeDictionary.Clear(); for (int num = list.Count - 1; num >= 0; num--) { Loggers.LogDebug("Deleting node: " + ((Object)list[num]).name); Object.Destroy((Object)(object)list[num]); } } public static void DeleteAllNodes(ref Dictionary> nodeDictionary) { if (nodeDictionary.Count == 0) { return; } List list = new List(); foreach (KeyValuePair> item in nodeDictionary) { list.Add(item.Key); } nodeDictionary.Clear(); for (int num = list.Count - 1; num >= 0; num--) { Loggers.LogDebug("Deleting node: " + ((Object)list[num]).name); Object.Destroy((Object)(object)list[num]); } } public static void DeleteAllNodes(ref List nodeList) { if (nodeList.Count == 0) { return; } List list = new List(); foreach (TerminalNode node in nodeList) { list.Add(node); } nodeList.Clear(); for (int num = list.Count - 1; num >= 0; num--) { Loggers.LogDebug("Deleting node: " + ((Object)list[num]).name); Object.Destroy((Object)(object)list[num]); } } public static void DeleteMatchingNode(string nodeName) { List list = LogicHandling.RefreshAllNodes(); for (int num = list.Count - 1; num >= 0; num--) { if (((Object)list[num]).name.Equals(nodeName)) { Object.Destroy((Object)(object)list[num]); Loggers.LogDebug("Node: [" + nodeName + "] removed"); break; } } } public static bool TryGetAndDeleteUnlockableName(string unlockableName, out int indexPos) { List list = StartOfRound.Instance.unlockablesList.unlockables.ToList(); for (int num = list.Count - 1; num >= 0; num--) { if (list[num].unlockableName.Equals(unlockableName)) { Loggers.LogDebug("Unlockable: [" + unlockableName + "] found! Removing unlockable and noting index position"); StartOfRound.Instance.unlockablesList.unlockables.Remove(list[num]); indexPos = num; return true; } } indexPos = -1; return false; } } public class InteractiveMenu { public string MenuName = ""; public Action LoadPage; public Action EnterMenu; public Action LeaveMenu; public OpenLib.Events.Events.CustomEvent UpMenuEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent DownMenuEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent LeftMenuEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent RightMenuEvent = new OpenLib.Events.Events.CustomEvent(); public OpenLib.Events.Events.CustomEvent AcceptAnyKeyEvent = new OpenLib.Events.Events.CustomEvent(); public Key upMenu = (Key)63; public Key downMenu = (Key)64; public Key leftMenu = (Key)61; public Key rightMenu = (Key)62; public Key selectMenu = (Key)2; public Key leaveMenu = (Key)65; public Dictionary MainActions = new Dictionary(); public Dictionary OtherActions = new Dictionary(); public bool isMenuEnabled; public bool inMenu; public bool acceptAnything; public int activeSelection; public int currentPage = 1; public InteractiveMenu(string name, Action pageLoader, Action enter, Action leave, Dictionary MoreMenuActions = null) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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) if (!TerminalUpdatePatch.usePatch) { TerminalUpdatePatch.usePatch = true; } MenuName = name; LoadPage = pageLoader; EnterMenu = enter; LeaveMenu = leave; SetupMainActions(); if (MoreMenuActions != null) { OtherActions = MoreMenuActions; } AllInteractiveMenus.AllMenus.Add(this); } public void AddToOtherActions(Key key, Action action) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (OtherActions.ContainsKey(key)) { OtherActions.Remove(key); } OtherActions.Add(key, action); } internal void SetupMainActions() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) MainActions.Clear(); MainActions.Add(upMenu, UpMenu); MainActions.Add(downMenu, DownMenu); MainActions.Add(leftMenu, LeftMenu); MainActions.Add(rightMenu, RightMenu); MainActions.Add(selectMenu, EnterMenu.Invoke); MainActions.Add(leaveMenu, LeaveMenu.Invoke); } internal void HandleInput() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) if (!inMenu) { return; } if (acceptAnything && AcceptAnyKeyEvent.HasListeners) { AcceptAnyKeyEvent.Invoke(); return; } Key? main = MainActions.FirstOrDefault>((KeyValuePair x) => ((ButtonControl)Keyboard.current[x.Key]).isPressed).Key; if (main.HasValue) { MainActions.FirstOrDefault>((KeyValuePair x) => (Key?)x.Key == main).Value?.Invoke(); } if (OtherActions.Count == 0) { return; } Key? other = OtherActions.FirstOrDefault>((KeyValuePair x) => ((ButtonControl)Keyboard.current[x.Key]).isPressed).Key; if (other.HasValue) { OtherActions.FirstOrDefault>((KeyValuePair x) => (Key?)x.Key == other).Value?.Invoke(); } } public void UpMenu() { if (inMenu) { if (activeSelection > 0) { activeSelection--; } LoadPage(); UpMenuEvent.Invoke(); } } public void DownMenu() { if (inMenu) { activeSelection++; LoadPage(); DownMenuEvent.Invoke(); } } public void LeftMenu() { if (inMenu) { if (currentPage > 1) { currentPage--; } LoadPage(); LeftMenuEvent.Invoke(); } } public void RightMenu() { if (inMenu) { currentPage++; LoadPage(); RightMenuEvent.Invoke(); } } } public static class AllInteractiveMenus { public static List AllMenus { get; internal set; } = new List(); public static bool TryGetMenu(string menuName, out InteractiveMenu menu) { string menuName2 = menuName; menu = AllMenus.FirstOrDefault((InteractiveMenu x) => x.MenuName == menuName2); if (menu == null) { return false; } return true; } [Obsolete("Use MenusContainer.AnyMenuActive instead")] public static bool AnyMenuActive() { if (MenusContainer.AnyMenuActive()) { return true; } return false; } public static bool AnyInteractiveMenuActive() { if (AllMenus.Count == 0) { return false; } if (AllMenus.Any((InteractiveMenu x) => x.inMenu)) { return true; } return false; } } public class BasicTerminal { public static TerminalKeyword CreateNewTerminalKeyword(string name, string keyword, bool ReplaceExisting = false) { if (DynamicBools.TryGetKeyword(keyword, out TerminalKeyword terminalKeyword)) { if (!ReplaceExisting) { return terminalKeyword; } CheckForAndDeleteKeyWord(keyword); } List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); TerminalKeyword val = ScriptableObject.CreateInstance(); ((Object)val).name = name; val.word = keyword; val.isVerb = false; val.compatibleNouns = Array.Empty(); val.defaultVerb = null; list.Add(val); if (!Plugin.KeywordsAdded.Contains(val)) { Plugin.KeywordsAdded.Add(val); } Plugin.instance.Terminal.terminalNodes.allKeywords = list.ToArray(); return val; } public static TerminalNode CreateNewTerminalNode() { TerminalNode val = ScriptableObject.CreateInstance(); ((Object)val).name = "OpenLibTerminalNode"; val.displayText = string.Empty; val.terminalEvent = string.Empty; val.maxCharactersToType = 25; val.buyItemIndex = -1; val.buyRerouteToMoon = -1; val.displayPlanetInfo = -1; val.shipUnlockableID = -1; val.creatureFileID = -1; val.storyLogFileID = -1; val.playSyncedClip = -1; val.terminalOptions = Array.Empty(); if (!Plugin.NodesAdded.Contains(val)) { Plugin.NodesAdded.Add(val); } return val; } public static CompatibleNoun CreateCompatibleNoun(string nodeName, string word, string displayText = "") { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown TerminalKeyword terminalKeyword; TerminalKeyword val = (TerminalKeyword)((Misc.CompareStringsInvariant(word, "deny") || Misc.CompareStringsInvariant(word, "confirm")) ? CreateNewTerminalKeyword(nodeName + "_" + word, word) : ((!DynamicBools.TryGetKeyword(word, out terminalKeyword)) ? ((object)CreateNewTerminalKeyword(nodeName + "_" + word, word)) : ((object)terminalKeyword))); TerminalNode val2 = CreateNewTerminalNode(); ((Object)val2).name = nodeName + "_" + word; val2.displayText = displayText; val2.clearPreviousText = true; return new CompatibleNoun(val, val2); } public static CompatibleNoun CreateCompatibleNoun(string nodeName, string word, string displayText = "", int price = 0, Func thisAction = null, Dictionary> nodeListing = null) { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown TerminalKeyword terminalKeyword; TerminalKeyword val = (TerminalKeyword)((Misc.CompareStringsInvariant(word, "deny") || Misc.CompareStringsInvariant(word, "confirm")) ? CreateNewTerminalKeyword(nodeName + "_" + word, word) : ((!DynamicBools.TryGetKeyword(word, out terminalKeyword)) ? ((object)CreateNewTerminalKeyword(nodeName + "_" + word, word)) : ((object)terminalKeyword))); TerminalNode val2 = CreateNewTerminalNode(); ((Object)val2).name = nodeName + "_" + word; val2.displayText = displayText; val2.clearPreviousText = true; val2.itemCost = price; val.specialKeywordResult = val2; if (thisAction != null) { nodeListing?.Add(val2, thisAction); } return new CompatibleNoun(val, val2); } public static void CheckForAndDeleteKeyWord(string keyWord) { Loggers.LogDebug("Checking for " + keyWord); List list = Plugin.instance.Terminal.terminalNodes.allKeywords.ToList(); for (int num = list.Count - 1; num >= 0; num--) { if (list[num].word.Equals(keyWord)) { Loggers.LogDebug("removing " + list[num].word); list.RemoveAt(num); break; } } Plugin.instance.Terminal.terminalNodes.allKeywords = list.ToArray(); } } public class NodeConfirmation { public CommandManager Manager; public string Name; public string DenyTxt; public string ConfirmTxt; public CompatibleNoun Confirm; public CompatibleNoun Deny; public Func ConfirmFunc { get; set; } public Func DenyFunc { get; set; } public NodeConfirmation(CommandManager manager, Func confirmAction = null, Func denyAction = null) { Manager = manager; Name = manager.Name; ConfirmFunc = confirmAction; DenyFunc = denyAction; DenyTxt = "DenyFunc"; ConfirmTxt = "ConfirmFunc"; base..ctor(); } public void CreateConfirmation() { Confirm = BasicTerminal.CreateCompatibleNoun(Name + "_confirm", "confirm", ConfirmTxt); Deny = BasicTerminal.CreateCompatibleNoun(Name + "_deny", "deny", DenyTxt); Manager.terminalNode.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2] { Confirm, Deny }; Manager.terminalNode.overrideOptions = true; } public void SetConfirmAction(Func confirmAction) { ConfirmFunc = confirmAction; } public void SetConfirmText(string text) { ConfirmTxt = text; } public void SetDenyAction(Func denyAction) { DenyFunc = denyAction; } public void SetDenyText(string text) { DenyTxt = text; } } public class NodeStore { public bool AlwaysInStock; public int MaxStock; public ConfigEntry PriceConfig; public CommandManager Command; public string Name; public int ManualPrice; public int ActualPrice; public NodeStore(CommandManager cmd) { Command = cmd; Name = cmd.Name; base..ctor(); } public void AddToStore() { if (!((Object)(object)CommonTerminal.BuyKeyword == (Object)null)) { int num = ((PriceConfig != null) ? PriceConfig.Value : ManualPrice); TerminalKeyword buy = CommonTerminal.BuyKeyword; Command.terminalNode.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2] { Command.ConfirmBase.Confirm, Command.ConfirmBase.Deny }; UnlockableItem storeItem = AddingThings.AddUnlockable(Name, Command.terminalNode, AlwaysInStock, MaxStock); if (!StartOfRound.Instance.unlockablesList.unlockables.Contains(storeItem)) { StartOfRound.Instance.unlockablesList.unlockables.Add(storeItem); } int shipUnlockableID = StartOfRound.Instance.unlockablesList.unlockables.IndexOf(storeItem); Command.terminalNode.creatureName = Name; Command.terminalNode.shipUnlockableID = shipUnlockableID; Command.terminalNode.itemCost = num; Command.ConfirmBase.Confirm.result.shipUnlockableID = shipUnlockableID; Command.ConfirmBase.Confirm.result.buyUnlockable = false; Command.ConfirmBase.Confirm.result.itemCost = num; ActualPrice = num; CollectionExtensions.Do((IEnumerable)Command.terminalKeywords, (Action)delegate(TerminalKeyword x) { AddingThings.AddToBuyWord(ref buy, ref x, storeItem); }); Plugin.ShopNodes.Add(Command.terminalNode); Loggers.LogDebug("Store nodes created for " + Name); } } } public class CodeCollection { public static List> terminalCodeObjects = new List>(); } public class TerminalCodeObject : MonoBehaviour { public TerminalAccessibleObject TerminalCode; public bool DynamicMapIcon; public RadarTransform RadarTransform; public UnityEvent OnCodeUsed = (UnityEvent)(object)new UnityEvent(); public UnityEvent OnCooldownComplete = (UnityEvent)(object)new UnityEvent(); public T obj; public TerminalCodeObject(T itemClass, GameObject gameObj, bool dynamicMapIcon = false, bool isDoorType = false) { DynamicMapIcon = dynamicMapIcon; TerminalCode = AssignCodeToObject(gameObj, isDoorType); obj = itemClass; CodeCollection.terminalCodeObjects.Add(this); } public void SetTimers(float codeAccessCooldownTimer, float currentCooldownTimer) { Loggers.LogDebug("SetTimers!"); TerminalCode.codeAccessCooldownTimer = codeAccessCooldownTimer; TerminalCode.currentCooldownTimer = currentCooldownTimer; } public void CodeUsed(PlayerControllerB thisPlayer) { Loggers.LogDebug("CodeUsed!"); ((UnityEvent)(object)OnCodeUsed).Invoke(TerminalCode, (TerminalAccessibleObject)obj); } public void CooldownComplete(PlayerControllerB thisPlayer) { Loggers.LogDebug("CooldownComplete!"); ((UnityEvent)(object)OnCooldownComplete).Invoke(TerminalCode, (TerminalAccessibleObject)obj); } public void OnDestroy() { Loggers.LogDebug("CodeObject is destroyed! Removed from list"); CodeCollection.terminalCodeObjects.Remove(this); } public TerminalAccessibleObject AssignCodeToObject(GameObject gameObj, bool isDoorType = false) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown Loggers.LogDebug("AssignCodeToObject"); if (Plugin.AllTerminalCodes.Count == 0) { Plugin.AllTerminalCodes = Object.FindObjectsByType((FindObjectsSortMode)0).ToList(); } if ((Object)(object)gameObj == (Object)null) { Loggers.ERROR("NULL GAME OBJECT PROVIDED!!"); return null; } TerminalAccessibleObject val = ((!((Object)(object)gameObj.GetComponent() != (Object)null)) ? gameObj.AddComponent() : gameObj.GetComponent()); val.isBigDoor = isDoorType; val.terminalCodeEvent = new InteractEvent(); val.terminalCodeCooldownEvent = new InteractEvent(); ((UnityEvent)(object)val.terminalCodeEvent).AddListener((UnityAction)CodeUsed); ((UnityEvent)(object)val.terminalCodeCooldownEvent).AddListener((UnityAction)CooldownComplete); int codeIndex = 0; int num = 0; do { Loggers.LogDebug($"Object code at index [ {codeIndex} ] in use!"); codeIndex = GetFreshCode(); num++; Loggers.LogDebug($"New index of [ {codeIndex} ] chosen!"); } while (Plugin.AllTerminalCodes.Any((TerminalAccessibleObject x) => x.objectCode == RoundManager.Instance.possibleCodesForBigDoors[codeIndex]) && num < 5); val.SetCodeTo(codeIndex); val.InitializeValues(); Plugin.AllTerminalCodes.Add(val); Plugin.Log.LogInfo((object)(((Object)gameObj).name + " assigned code - " + val.objectCode)); TerminalCode = val; if (DynamicMapIcon) { RadarTransform = gameObj.AddComponent(); RadarTransform.Target = gameObj; RadarTransform.TheCode = TerminalCode; } return val; } public static int GetFreshCode() { Random random = new Random(); return random.Next(RoundManager.Instance.possibleCodesForBigDoors.Length); } } public class RadarTransform : MonoBehaviour { public GameObject? Target; public RectTransform? CodeObj; public TerminalAccessibleObject? TheCode; public void UpdateValues() { Loggers.LogDebug("RadarTransform - UpdateValues"); TerminalAccessibleObject? theCode = TheCode; CodeObj = ((theCode != null) ? ((Component)((Component)theCode.mapRadarBox).transform.parent).GetComponent() : null); if ((Object)(object)CodeObj == (Object)null) { Loggers.ERROR("Unable to get mapcode RectTransform!"); } } private void OnDestroy() { Loggers.LogDebug("RadarTransform destroyed!!!"); Loggers.LogDebug("RadarTransform destroyed!!!"); Loggers.LogDebug("RadarTransform destroyed!!!"); } private void Start() { Loggers.LogDebug("RadarTransform created!"); UpdateValues(); } private void Update() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Target == (Object)null)) { if ((Object)(object)CodeObj != (Object)null) { ((Transform)CodeObj).position = Target.transform.position + Vector3.up * 4.35f; RectTransform? codeObj = CodeObj; ((Transform)codeObj).position = ((Transform)codeObj).position + (((Component)CodeObj).transform.up * 1.2f - ((Component)CodeObj).transform.right * 1.2f); } else { UpdateValues(); } } } } } namespace OpenLib.ConfigManager { public class ConfigHelper { public static List GetAcceptableValues(AcceptableValueBase acceptableValueBase) { List result = new List(); if (acceptableValueBase == null) { return result; } string text = acceptableValueBase.ToDescriptionString(); text = text.Replace("# Acceptable values:", "").Replace(" ", ""); return CommonStringStuff.GetKeywordsPerConfigItem(text, ','); } public static List GetAcceptableValueF(AcceptableValueBase acceptableValueBase) { List result = new List(); if (acceptableValueBase == null) { return result; } string text = acceptableValueBase.ToDescriptionString(); Loggers.LogDebug(text); text = text.Replace("# Acceptable value range: From ", "").Replace("to", "").Replace(" ", ","); return CommonStringStuff.GetFloatListFromStringList(CommonStringStuff.GetKeywordsPerConfigItem(text, ',')); } public static void ChangeBool(ConfigFile ModConfig, ConfigEntryBase configItem, string newValue) { ConfigEntry val = default(ConfigEntry); if (newValue.Length != 0 && ModConfig.TryGetEntry(configItem.Definition, ref val)) { if (newValue == "true") { val.Value = true; } else { val.Value = false; } } } public static void ChangeString(ConfigFile ModConfig, ConfigEntryBase configItem, string newValue) { ConfigEntry val = default(ConfigEntry); if (newValue.Length != 0 && ModConfig.TryGetEntry(configItem.Definition, ref val)) { val.Value = newValue; } } public static void ChangeInt(ConfigFile ModConfig, ConfigEntryBase configItem, string newValue) { ConfigEntry val = default(ConfigEntry); if (newValue.Length != 0 && ModConfig.TryGetEntry(configItem.Definition, ref val)) { val.Value = int.Parse(newValue); } } public static void ChangeFloat(ConfigFile ModConfig, ConfigEntryBase configItem, string newValue) { ConfigEntry val = default(ConfigEntry); if (newValue.Length != 0 && ModConfig.TryGetEntry(configItem.Definition, ref val)) { val.Value = float.Parse(newValue); } } public static bool TryFindConfigItem(string query, ConfigFile ModConfig, out ConfigEntryBase configItem) { Dictionary dictionary = new Dictionary(); ConfigEntryBase[] configEntries = ModConfig.GetConfigEntries(); foreach (ConfigEntryBase val in configEntries) { dictionary.Add(val.Definition, val); Loggers.LogDebug($"added {val.Definition} to list of configItems to check"); } foreach (KeyValuePair item in dictionary) { if (item.Key.Key == query) { configItem = item.Value; return true; } } configItem = null; return false; } } public class ConfigMisc { public static bool CheckChangedConfigSetting(List managedItems, ConfigEntryBase entryBase) { ConfigEntry val = default(ConfigEntry); ConfigEntry val2 = default(ConfigEntry); foreach (ManagedConfig managedItem in managedItems) { if (!(managedItem.configDescription == entryBase.Description.Description)) { continue; } if (entryBase.BoxedValue.GetType() == typeof(bool)) { if (entryBase.ConfigFile.TryGetEntry(entryBase.Definition, ref val)) { if (managedItem.BoolValue != val.Value) { managedItem.ConfigChange(val.Value); Loggers.LogDebug("Updating config item: " + ((ConfigEntryBase)val).Definition.Key + " in managedItems"); return true; } Loggers.LogDebug("item value matches config item: " + ((ConfigEntryBase)val).Definition.Key); } } else if (entryBase.BoxedValue.GetType() == typeof(string) && entryBase.ConfigFile.TryGetEntry(entryBase.Definition, ref val2)) { if (managedItem.StringValue != val2.Value && managedItem.relatedConfigItem != null) { managedItem.ConfigChange(val2.Value); Loggers.LogDebug("Updating config item: " + ((ConfigEntryBase)val2).Definition.Key + " in managedItems"); List keywordsPerConfigItem = CommonStringStuff.GetKeywordsPerConfigItem(val2.Value); managedItem.relatedConfigItem.KeywordList = keywordsPerConfigItem; return true; } Loggers.LogDebug("item value matches config item: " + ((ConfigEntryBase)val2).Definition.Key); } } Loggers.LogDebug("could not match changed config setting to any managed config items"); return false; } public static bool ShouldReloadConfigNow(ConfigEntry entry) { if ((Object)(object)Plugin.instance.Terminal != (Object)null) { if (!EventUsage.configsToReload.Contains(((ConfigEntryBase)entry).ConfigFile)) { EventUsage.configsToReload.Add(((ConfigEntryBase)entry).ConfigFile); } return false; } return true; } } public static class ConfigSetup { [Obsolete("Please don't use this anymore...")] public static List defaultManaged = new List(); [Obsolete("Please don't use this anymore...")] public static MainListing defaultListing = new MainListing(); public static ConfigEntry LogLevel { get; internal set; } = null; public static void BindConfigSettings() { Plugin.Log.LogInfo((object)"Binding configuration settings"); LogLevel = MakeGeneric(((BaseUnityPlugin)Plugin.instance).Config, "Debug", "Logging Level", Loggers.LoggingLevel.WarningsPlus, "Set OpenLib logging level"); } [Obsolete("Please don't use this anymore...")] public static ManagedConfig AddManagedBool(ConfigEntry boolEntry, List managedItems, bool isNetworked = false, string category = "", string configString = "", Func mainAction = null, int commandType = 0, bool clearText = true, Func confirmAction = null, Func denyAction = null, string confirmText = "confirm", string denyText = "deny", string special = "", int specialNum = -1, string nodeName = "", string itemList = "", int price = 0, string storeName = "", bool alwaysInStock = true, int maxStock = 0, bool reuseFunc = false) { List keywordsPerConfigItem = CommonStringStuff.GetKeywordsPerConfigItem(configString); if (ManagedBoolGet.TryGetItemByName(managedItems, ((ConfigEntryBase)boolEntry).Definition.Key, 0, out ManagedConfig result)) { result.SetManagedBoolValues(boolEntry, isNetworked, category, keywordsPerConfigItem, mainAction, commandType, clearText, confirmAction, denyAction, confirmText, denyText, special, specialNum, nodeName, itemList, price, storeName, alwaysInStock, maxStock, reuseFunc); return result; } ManagedConfig managedConfig = new ManagedConfig(); managedConfig.SetManagedBoolValues(boolEntry, isNetworked, category, keywordsPerConfigItem, mainAction, commandType, clearText, confirmAction, denyAction, confirmText, denyText, special, specialNum, nodeName, itemList, price, storeName, alwaysInStock, maxStock, reuseFunc); managedItems.Add(managedConfig); return managedConfig; } [Obsolete("Please don't use this anymore...")] public static ManagedConfig AddManagedBool(ConfigEntry boolEntry, List managedItems, bool isNetworked = false, string category = "", ConfigEntry configString = null, Func mainAction = null, int commandType = 0, bool clearText = true, Func confirmAction = null, Func denyAction = null, string confirmText = "confirm", string denyText = "deny", string special = "", int specialNum = -1, string nodeName = "", string itemList = "", int price = 0, string storeName = "", bool alwaysInStock = true, int maxStock = 0, bool reuseFunc = false) { List keywordList = new List(); bool flag = true; if (configString != null) { flag = false; keywordList = CommonStringStuff.GetKeywordsPerConfigItem(configString.Value); } if (ManagedBoolGet.TryGetItemByName(managedItems, ((ConfigEntryBase)boolEntry).Definition.Key, 0, out ManagedConfig result)) { result.SetManagedBoolValues(boolEntry, isNetworked, category, keywordList, mainAction, commandType, clearText, confirmAction, denyAction, confirmText, denyText, special, specialNum, nodeName, itemList, price, storeName, alwaysInStock, maxStock, reuseFunc); if (!flag) { AddManagedString(configString, ref managedItems, result); } return result; } ManagedConfig managedConfig = new ManagedConfig(); managedConfig.SetManagedBoolValues(boolEntry, isNetworked, category, keywordList, mainAction, commandType, clearText, confirmAction, denyAction, confirmText, denyText, special, specialNum, nodeName, itemList, price, storeName, alwaysInStock, maxStock, reuseFunc); managedItems.Add(managedConfig); if (!flag) { AddManagedString(configString, ref managedItems, managedConfig); } return managedConfig; } [Obsolete("Please don't use this anymore...")] public static ManagedConfig NewManagedBool(ref List managedItems, string configItemName, bool isEnabled, string configDescription, bool isNetworked = false, string category = "", List keywordList = null, Func mainAction = null, int commandType = 0, bool clearText = true, Func confirmAction = null, Func denyAction = null, string confirmText = "confirm", string denyText = "deny", string special = "", int specialNum = -1, string nodeName = "", string itemList = "", int price = 0, string storeName = "", bool alwaysInStock = true, int maxStock = 0, bool reuseFunc = false) { if (ManagedBoolGet.TryGetItemByName(managedItems, configItemName, 0, out ManagedConfig result)) { result.SetManagedBoolValues(configItemName, isEnabled, configDescription, isNetworked, category, keywordList, mainAction, commandType, clearText, confirmAction, denyAction, confirmText, denyText, special, specialNum, nodeName, itemList, price, storeName, alwaysInStock, maxStock, reuseFunc); return result; } ManagedConfig managedConfig = new ManagedConfig(); managedConfig.SetManagedBoolValues(configItemName, isEnabled, configDescription, isNetworked, category, keywordList, mainAction, commandType, clearText, confirmAction, denyAction, confirmText, denyText, special, specialNum, nodeName, itemList, price, storeName, alwaysInStock, maxStock, reuseFunc); managedItems.Add(managedConfig); return managedConfig; } public static ConfigEntry MakeGeneric(ConfigFile ModConfig, string section, string configItemName, T defaultValue, string ConfigDescription) { section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); return ModConfig.Bind(section, configItemName, defaultValue, ConfigDescription); } public static ConfigEntry MakeGeneric(ConfigFile ModConfig, string section, string configItemName, T defaultValue, string description, AcceptableValueList acceptableValues = null) where T : IEquatable { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); return ModConfig.Bind(section, configItemName, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)acceptableValues, Array.Empty())); } public static ConfigEntry MakeGeneric(ConfigFile ModConfig, string section, string configItemName, T defaultValue, string description, T minValue, T maxValue) where T : IComparable { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); AcceptableValueRange val = new AcceptableValueRange(minValue, maxValue); return ModConfig.Bind(section, configItemName, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)val, Array.Empty())); } [Obsolete("Should use MakeGeneric instead")] public static ConfigEntry MakeBool(ConfigFile ModConfig, string section, string configItemName, bool defaultValue, string configDescription) { section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); return ModConfig.Bind(section, configItemName, defaultValue, configDescription); } [Obsolete("Should use MakeGeneric instead")] public static ConfigEntry MakeInt(ConfigFile ModConfig, string section, string configItemName, int defaultValue, string configDescription) { section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); return ModConfig.Bind(section, configItemName, defaultValue, configDescription); } [Obsolete("Should use MakeGeneric instead")] public static ConfigEntry MakeClampedString(ConfigFile ModConfig, string section, string configItemName, string defaultValue, string configDescription, AcceptableValueList acceptedValues) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); return ModConfig.Bind(section, configItemName, defaultValue, new ConfigDescription(configDescription, (AcceptableValueBase)(object)acceptedValues, Array.Empty())); } [Obsolete("Should use MakeGeneric instead")] public static ConfigEntry MakeClampedInt(ConfigFile ModConfig, string section, string configItemName, int defaultValue, string configDescription, int minValue, int maxValue) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); return ModConfig.Bind(section, configItemName, defaultValue, new ConfigDescription(configDescription, (AcceptableValueBase)(object)new AcceptableValueRange(minValue, maxValue), Array.Empty())); } [Obsolete("Should use MakeGeneric instead")] public static ConfigEntry MakeClampedFloat(ConfigFile ModConfig, string section, string configItemName, float defaultValue, string configDescription, float minValue, float maxValue) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); return ModConfig.Bind(section, configItemName, defaultValue, new ConfigDescription(configDescription, (AcceptableValueBase)(object)new AcceptableValueRange(minValue, maxValue), Array.Empty())); } [Obsolete("Should use MakeGeneric instead")] public static ConfigEntry MakeString(ConfigFile ModConfig, string section, string configItemName, string defaultValue, string configDescription) { section = CommonStringStuff.BepinFriendlyString(section); configItemName = CommonStringStuff.BepinFriendlyString(configItemName); return ModConfig.Bind(section, configItemName, defaultValue, configDescription); } public static bool CheckForConfigName(string configName, ConfigFile ModConfig) { string configName2 = configName; return ModConfig.Keys.Any((ConfigDefinition c) => c.Key == configName2); } [Obsolete("Please don't use this anymore...")] public static void AddManagedString(ConfigEntry configItem, ref List managedItems, ManagedConfig relatedConfigItem) { ManagedConfig item = new ManagedConfig { ConfigItemName = ((ConfigEntryBase)configItem).Definition.Key, configDescription = ((ConfigEntryBase)configItem).Description.Description, StringValue = configItem.Value, relatedConfigItem = relatedConfigItem, ConfigType = 1 }; managedItems.Add(item); } public static void RemoveOrphanedEntries(ConfigFile ModConfig) { Loggers.LogInfo("removing orphaned entries (credits to Kittenji)"); PropertyInfo property = ((object)ModConfig).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic); Dictionary dictionary = (Dictionary)property.GetValue(ModConfig, null); dictionary.Clear(); ModConfig.Save(); } public static void NetworkingCheck(bool NetworkConfigOption, ConfigFile ModConfig, List managedBools) { Plugin.Log.LogInfo((object)"Checking if networking is disabled..."); if (NetworkConfigOption) { return; } List> list = new List>(); Dictionary dictionary = new Dictionary(); ConfigEntryBase[] configEntries = ModConfig.GetConfigEntries(); foreach (ConfigEntryBase val in configEntries) { dictionary.Add(val.Definition, val); Loggers.LogDebug($"added {val.Definition} to list of configItems to check"); } ConfigEntry item = default(ConfigEntry); foreach (KeyValuePair item2 in dictionary) { if (item2.Value.BoxedValue.GetType() == typeof(bool)) { if (!ModConfig.TryGetEntry(item2.Key, ref item)) { continue; } if (ManagedBoolGet.TryGetItemByName(managedBools, item2.Key.Key, 0, out ManagedConfig result)) { if (result.ConfigType != 0) { Loggers.LogDebug("ManagedItem is type 0, bool"); } if (result.RequiresNetworking) { list.Add(item); Loggers.LogDebug("Adding " + item2.Key.Key + " to bools list to check against networking"); } else { Loggers.LogDebug(item2.Key.Key + " is not listed as requiring networking"); } } else { Loggers.LogDebug("entry is not a managed bool"); } } else { Loggers.LogDebug("entry is not a bool"); } } CollectionExtensions.DoIf>((IEnumerable>)list, (Func, bool>)((ConfigEntry b) => b.Value), (Action>)DisableConfigBool); ModConfig.Save(); } private static void DisableConfigBool(ConfigEntry entry) { entry.Value = false; Plugin.Log.LogWarning((object)("Setting " + ((ConfigEntryBase)entry).Definition.Key + " to false. Networking is disabled and this setting requires networking!")); } public static void ReadConfigAndAssignValues(ConfigFile ModConfig, List managedBools) { Plugin.Log.LogInfo((object)"attempting to read config and assign values"); Dictionary dictionary = new Dictionary(); ConfigEntryBase[] configEntries = ModConfig.GetConfigEntries(); foreach (ConfigEntryBase val in configEntries) { dictionary.Add(val.Definition, val); Loggers.LogDebug($"added {val.Definition} to list of configItems to check"); } ConfigEntry val2 = default(ConfigEntry); ConfigEntry val3 = default(ConfigEntry); foreach (KeyValuePair item in dictionary) { Loggers.LogDebug("checking item"); if (item.Value.BoxedValue.GetType() == typeof(bool)) { if (ModConfig.TryGetEntry(item.Key, ref val2)) { Loggers.LogDebug("bool entry found"); Loggers.LogDebug(((ConfigEntryBase)val2).Definition.Key ?? ""); if (ManagedBoolGet.TryGetItemByName(managedBools, ((ConfigEntryBase)val2).Definition.Key, 0, out ManagedConfig result)) { result.BoolValue = val2.Value; Loggers.LogDebug($"Assigned ManagedConfig: {result.ConfigItemName} to configValue: {val2.Value}"); } else { Plugin.Log.LogWarning((object)("Could not find ManagedConfig for " + item.Key.Key)); } } } else if (item.Value.BoxedValue.GetType() == typeof(string)) { if (ModConfig.TryGetEntry(item.Key, ref val3)) { Loggers.LogDebug("string entry found"); Loggers.LogDebug(((ConfigEntryBase)val3).Definition.Key ?? ""); if (ManagedBoolGet.TryGetItemByName(managedBools, ((ConfigEntryBase)val3).Definition.Key, 1, out ManagedConfig result2)) { result2.StringValue = val3.Value; Loggers.LogDebug("Assigned ManagedConfig: " + result2.ConfigItemName + " to configValue: " + val3.Value); } else { Plugin.Log.LogWarning((object)("Could not find ManagedConfig for " + item.Key.Key)); } } } else { Plugin.Log.LogWarning((object)("Unable to read configItem " + item.Key.Key + " and match to Managed Config Item")); } } } } public class ConfigWatch { public ConfigEntry ConfigItem; public bool NetworkingReq; public ConfigEntry networkingConfig; public string Name; public ConfigWatch(ConfigEntry entry, bool networking = false) { ConfigItem = entry; NetworkingReq = networking; Name = ((ConfigEntryBase)entry).Definition.Key; base..ctor(); } } public class ManagedConfig { public string ConfigItemName = string.Empty; public bool RequiresNetworking; public int ConfigType = -1; public string? StringValue; public int IntValue; public bool BoolValue; public Func? MainAction; public int CommandType; public bool clearText; public bool alwaysInStock; public bool reuseFunc; public int maxStock; public int price; public int specialNum; public string nodeName = string.Empty; public string storeName = string.Empty; public string itemList = string.Empty; public string specialString = string.Empty; public string confirmText = string.Empty; public string denyText = string.Empty; public string categoryText = string.Empty; public string configDescription = string.Empty; public Func? ConfirmAction; public Func? DenyAction; public Func? InfoAction; public string InfoText = ""; public ConfigEntry? configBool; public string section = ""; public TerminalMenuItem? menuItem; public TerminalNode? TerminalNode; public UnlockableItem? UnlockableItem; public ManagedConfig? relatedConfigItem; public List KeywordList { get; set; } = new List(); public void ConfigChange(bool newValue) { if (newValue) { BoolValue = newValue; } else { BoolValue = newValue; } } public void ConfigChange(string newValue) { if (newValue != StringValue) { StringValue = newValue; Loggers.LogDebug("Updating string value for managed item " + ConfigItemName); } } public void DefaultInfoText() { if (menuItem != null) { string infoText = "[ " + CommonStringStuff.GetKeywordsForMenuItem(menuItem.itemKeywords) + " ]\r\n" + menuItem.itemDescription + "\r\n\r\n"; InfoText = infoText; } } public void AddInfoAction(Func action) { InfoAction = action; } public void SetManagedBoolValues(string configItemName, bool isEnabled, string descrip, bool isNetworked = false, string category = "", List keywordList = null, Func mainAction = null, int commandType = 0, bool clear = true, Func confirmAction = null, Func denyAction = null, string confirmTxt = "confirm", string denyTxt = "deny", string special = "", int specialInt = -1, string nodestring = "", string items = "", int value = 0, string storeString = "", bool inStock = true, int stockMax = 0, bool reuseFnc = false) { ConfigType = 0; BoolValue = isEnabled; MainAction = mainAction; KeywordList = keywordList; ConfigItemName = configItemName; RequiresNetworking = isNetworked; price = value; CommandType = commandType; clearText = clear; ConfirmAction = confirmAction; DenyAction = denyAction; confirmText = confirmTxt; denyText = denyTxt; specialNum = specialInt; specialString = special; itemList = items; storeName = storeString; alwaysInStock = inStock; maxStock = stockMax; nodeName = nodestring; categoryText = category; configDescription = descrip; reuseFunc = reuseFnc; } public void SetManagedBoolValues(ConfigEntry configItem, bool isNetworked = false, string category = "", List keywordList = null, Func mainAction = null, int commandType = 0, bool clear = true, Func confirmAction = null, Func denyAction = null, string confirmTxt = "confirm", string denyTxt = "deny", string special = "", int specialInt = -1, string nodestring = "", string items = "", int value = 0, string storeString = "", bool inStock = true, int stockMax = 0, bool reuseFnc = false) { ConfigType = 0; BoolValue = configItem.Value; MainAction = mainAction; KeywordList = keywordList; ConfigItemName = ((ConfigEntryBase)configItem).Definition.Key; RequiresNetworking = isNetworked; price = value; CommandType = commandType; clearText = clear; ConfirmAction = confirmAction; DenyAction = denyAction; confirmText = confirmTxt; denyText = denyTxt; specialNum = specialInt; specialString = special; itemList = items; storeName = storeString; alwaysInStock = inStock; maxStock = stockMax; nodeName = nodestring; categoryText = category; configDescription = ((ConfigEntryBase)configItem).Description.Description; reuseFunc = reuseFnc; configBool = configItem; section = ((ConfigEntryBase)configItem).Definition.Section; } } public class ManagedBoolGet { public static bool TryGetItemByName(List managedBools, string query, int configType, out ManagedConfig result) { string query2 = query; if (managedBools.Count == 0) { Loggers.LogDebug("managedConfigs count = 0"); result = null; return false; } Loggers.LogDebug("TryGetItemByName: " + query2); result = managedBools.FirstOrDefault((ManagedConfig item) => item.ConfigItemName == query2 && item.ConfigType == configType); return result != null; } public static bool TryGetBySection(List managedBools, string query, int configType, out List result) { string query2 = query; if (managedBools.Count == 0) { Loggers.LogDebug("managedConfigs count = 0"); result = new List(); return false; } Loggers.LogDebug("TryGetBySection: " + query2); result = managedBools.FindAll((ManagedConfig item) => item.section == query2 && item.ConfigType == configType); return result != null; } public static bool CanAddToManagedBoolList(List managedBools, string nodeName) { foreach (ManagedConfig managedBool in managedBools) { if (managedBool.ConfigItemName == nodeName) { Plugin.Log.LogWarning((object)("Tried to add " + nodeName + " to managedBools list when it's already in it!")); return false; } } Loggers.LogDebug("node is not in managedbool list and can be added!"); return true; } public static bool TryGetItemByName(List managedBools, string query) { foreach (ManagedConfig managedBool in managedBools) { if (managedBool.ConfigItemName == query) { return true; } } return false; } } public class ParseHelper { public static List> ParseJsonManually(string jsonString) { string[] array = jsonString.Trim('{', '}').Split(','); List> list = new List>(); string[] array2 = array; foreach (string text in array2) { string[] array3 = text.Split(':'); if (array3.Length == 2) { string key = array3[0].Trim(new char[1] { '"' }).Trim(); string value = array3[1].Trim(new char[1] { '"' }).Trim(); KeyValuePair item = new KeyValuePair(key, value); list.Add(item); } } return list; } public static Dictionary ParseKeyValuePairs(string data) { Dictionary dictionary = new Dictionary(); if (Utility.IsNullOrWhiteSpace(data)) { return dictionary; } string[] array = data.Split(new string[1] { ";:;" }, StringSplitOptions.RemoveEmptyEntries); string[] array2 = array; foreach (string text in array2) { string[] array3 = text.Split(':'); if (array3.Length == 2) { string key = array3[0].Trim(); string value = array3[1].Trim(); dictionary[key] = value; } else { Loggers.WARNING("Invalid pair format: " + text); } } return dictionary; } } public class WebHelper { public static string AddValueToHTMLCode(string value, string configName, int num, bool isDefaultValue) { if (isDefaultValue) { Loggers.LogDebug(configName + " is default value, setting this to checked"); return $"\r\n
"; } return $"\r\n
"; } public static string AddValueToHTMLCode(List values, string configName, string defaultValue, int sliderItem) { if (values.Count != 2) { return ""; } configName = CommonStringStuff.RemovePunctuation(configName).Replace(" ", ""); if (values[1] > 999f) { Loggers.LogDebug($"clamped number-type max value too high for slider - {values[1]}"); return $""; } if (values[0].ToString().Contains('.') || values[1] <= 1f) { return $"\r\n" + $""; } return $"\r\n" + $""; } public static void WebConfig(ConfigFile ModConfig) { List list = new List(); int num = 0; int num2 = 0; string configFilePath = ModConfig.ConfigFilePath; int num3 = ModConfig.ConfigFilePath.LastIndexOf('\\'); string text = configFilePath.Substring(num3, configFilePath.Length - num3); list.Add("" + text.Replace("\\", "") + " Generator"); list.Add(""); list.Add("

" + text.Replace("\\", "") + " Generator

Upload your config:

"); list.Add("
"); Dictionary dictionary = new Dictionary(); ConfigEntryBase[] configEntries = ModConfig.GetConfigEntries(); foreach (ConfigEntryBase val in configEntries) { dictionary.Add(val.Definition, val); Loggers.LogDebug($"added {val.Definition} to list of configItems to check"); } string text2 = ""; foreach (KeyValuePair item in dictionary) { if (item.Key.Section != text2) { if (text2 != "") { list.Add(""); } list.Add("
\r\n" + item.Key.Section + ""); text2 = item.Key.Section; } if (item.Value.BoxedValue.GetType() == typeof(bool)) { Loggers.LogDebug("bool config detected - " + item.Key.Key); if ((bool)item.Value.DefaultValue) { Loggers.LogDebug("default is TRUE"); list.Add("


" + item.Value.Description.Description + "

"); } else { Loggers.LogDebug("default is FALSE"); list.Add("


" + item.Value.Description.Description + "

"); } } else if (item.Value.BoxedValue.GetType() == typeof(string)) { if (item.Value.Description.AcceptableValues != null) { list.Add("

" + item.Key.Key + "
" + item.Value.Description.Description + "
"); List acceptableValues = ConfigHelper.GetAcceptableValues(item.Value.Description.AcceptableValues); int num4 = 1; foreach (string item2 in acceptableValues) { string text3 = ""; text3 = ((!(item2 == (string)item.Value.DefaultValue)) ? AddValueToHTMLCode(item2, item.Key.Key, num4, isDefaultValue: false) : AddValueToHTMLCode(item2, item.Key.Key, num4, isDefaultValue: true)); list.Add(text3); num4++; } list.Add("

"); Loggers.LogDebug("clamped string config detected - " + item.Key.Key); } else if (item.Value.DefaultValue is string text4) { if (text4.StartsWith('#') && text4.Length == 7) { list.Add($"


" + $"

"); num++; } else { list.Add($"


{item.Value.Description.Description}

"); } Loggers.LogDebug("string config detected - " + item.Key.Key); } } else if (item.Value.BoxedValue.GetType() == typeof(int) || item.Value.BoxedValue.GetType() == typeof(float)) { if (item.Value.Description.AcceptableValues != null) { list.Add("

" + item.Key.Key + "
" + item.Value.Description.Description + "
"); List acceptableValueF = ConfigHelper.GetAcceptableValueF(item.Value.Description.AcceptableValues); list.Add(AddValueToHTMLCode(acceptableValueF, item.Key.Key, item.Value.DefaultValue.ToString(), num2)); num2++; list.Add("

"); Loggers.LogDebug("clamped number-type config detected - " + item.Key.Key); } else { list.Add($"


{item.Value.Description.Description}

"); Loggers.LogDebug("number-type config detected - " + item.Key.Key); } } } list.Add("

"); list.Add("\r\n\t"); list.Add("

"); list.Add("
Raw data:


Code:
"); list.Add(""); if (!Directory.Exists(Paths.ConfigPath + "/webconfig")) { Directory.CreateDirectory(Paths.ConfigPath + "/webconfig"); } File.WriteAllLines(Paths.ConfigPath + "/webconfig/" + text + "_generator.htm", list); } private static string DecompressBase64Gzip(string base64) { byte[] buffer = Convert.FromBase64String(base64); using MemoryStream stream = new MemoryStream(buffer); using GZipStream stream2 = new GZipStream(stream, CompressionMode.Decompress); using StreamReader streamReader = new StreamReader(stream2, Encoding.UTF8); return streamReader.ReadToEnd(); } public static void ReadCompressedConfig(ref ConfigEntry configEntry, ConfigFile ModConfig) { string value = configEntry.Value; string data = DecompressBase64Gzip(value); Dictionary dictionary = ParseHelper.ParseKeyValuePairs(data); if (dictionary.Count == 0) { return; } foreach (KeyValuePair item in dictionary) { if (ConfigHelper.TryFindConfigItem(item.Key, ModConfig, out ConfigEntryBase configItem)) { if (configItem.BoxedValue.GetType() == typeof(bool)) { ConfigHelper.ChangeBool(ModConfig, configItem, item.Value.ToLower()); } else if (configItem.BoxedValue.GetType() == typeof(string)) { ConfigHelper.ChangeString(ModConfig, configItem, item.Value); } else if (configItem.BoxedValue.GetType() == typeof(int)) { ConfigHelper.ChangeInt(ModConfig, configItem, item.Value); } else if (configItem.BoxedValue.GetType() == typeof(float)) { ConfigHelper.ChangeFloat(ModConfig, configItem, item.Value); } } } configEntry.Value = ""; } } } namespace OpenLib.Compat { public class BMX_LobbyCompat { internal static void SetCompat(bool isNetworked) { if (Plugin.instance.LobbyCompat) { Version version = Assembly.GetExecutingAssembly().GetName().Version; if (isNetworked) { PluginHelper.RegisterPlugin("OpenLib", version, (CompatibilityLevel)2, (VersionStrictness)3); } else { PluginHelper.RegisterPlugin("OpenLib", version, (CompatibilityLevel)0, (VersionStrictness)3); } } } [Obsolete("This should never have worked.. Need to double check no other mods are using this LMAO")] public static bool SetBMXCompat(bool isNetworked) { if (!Plugin.instance.LobbyCompat) { return false; } Version version = Assembly.GetCallingAssembly().GetName().Version; return true; } [Obsolete("This should never have worked.. Need to double check no other mods are using this LMAO")] public static bool SetBMXCompat(bool isNetworked, Version version) { if (!Plugin.instance.LobbyCompat) { return false; } return true; } } internal class Constants { internal const string LobbyCompat_GUID = "BMX.LobbyCompatibility"; internal const string TF_GUID = "TerminalFormatter"; internal const string ITAPI_GUID = "WhiteSpike.InteractiveTerminalAPI"; internal const string LethalConfig_GUID = "ainavt.lc.lethalconfig"; internal const string OBC_GUID = "Zaggy1024.OpenBodyCams"; internal const string TWORM_GUID = "Zaggy1024.TwoRadarMaps"; internal const string MRAPI_GUID = "meow.ModelReplacementAPI"; internal const string TME_GUID = "FlipMods.TooManyEmotes"; internal const string Mirror_GUID = "quackandcheese.mirrordecor"; internal const string TerminalStuff_GUID = "darmuh.TerminalStuff"; } internal class DawnlibCompat { public static void SetCommandPriority(TerminalKeyword keyword) { if (Plugin.instance.DawnLibPresent) { TerminalExtensions.SetKeywordPriority(keyword, (DawnKeywordType)9); } } } public class InteractiveTermAPI { public static bool ApplicationInUse() { if (!Plugin.instance.ITAPI) { return false; } return InteractiveTerminalManager.InteractiveTerminalBeingUsed(); } } public class LethalConfigSoft { public static Version MinVer = new Version(1, 4, 3); public static Version LethalConfigVersion => Misc.GetPluginVersion("ainavt.lc.lethalconfig"); [Obsolete("Do not call this method from another mod. The config items will be added directly to OpenLib. Instead copy this method and use it in your own mod")] public static void QueueConfig(ConfigFile configName) { if (IsLethalConfigUpdated()) { Loggers.LogDebug("Queuing file " + configName.ConfigFilePath); LethalConfigManager.QueueCustomConfigFileForLateAutoGeneration(configName); } } public static bool IsLethalConfigUpdated() { if (!Plugin.instance.LethalConfig) { return false; } if (LethalConfigVersion == null) { Loggers.FATAL("Unable to get version of LethalConfig!"); return false; } if (LethalConfigVersion < MinVer) { Loggers.WARNING($"Cannot queue config! LethalConfig version is {LethalConfigVersion}, which is below the minimum required for this function {MinVer}"); return false; } return true; } public static void AddButton(string section, string name, string description, string buttonText, Action methodToCall) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Expected O, but got Unknown string buttonText2 = buttonText; Action methodToCall2 = methodToCall; if (Plugin.instance.LethalConfig) { Assembly callingAssembly = Assembly.GetCallingAssembly(); Loggers.LogInfo("AddLoadCodeButton called from " + callingAssembly.GetName().Name + "!\nName: " + name + "\nDescription: " + description + "\nButtonText: " + buttonText2); LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText2, (GenericButtonHandler)delegate { Loggers.LogDebug("LethalConfig button [" + buttonText2 + "] has been pressed"); methodToCall2(); }), callingAssembly); } } [Obsolete("Use OpenLib.Common.Misc.GetPluginVersion() instead!")] public static Version GetVersion(string PluginGUID) { return Misc.GetPluginVersion(PluginGUID); } } public class ModelAPI { public static int GetFirstPersonMask(int originalMask) { if (!Plugin.instance.ModelReplacement) { return 0; } int num = (1 << ViewStateManager.modelLayer) + (1 << ViewStateManager.NoPostModelLayer); int num2 = 1 << ViewStateManager.armsLayer; int num3 = (1 << ViewStateManager.visibleLayer) + (1 << ViewStateManager.NoPostVisibleLayer); originalMask |= num2; originalMask &= ~num; originalMask |= num3; return originalMask; } public static int GetThirdPersonMask(int originalMask) { if (!Plugin.instance.ModelReplacement) { return 0; } int num = (1 << ViewStateManager.modelLayer) + (1 << ViewStateManager.NoPostModelLayer); int num2 = 1 << ViewStateManager.armsLayer; int num3 = (1 << ViewStateManager.visibleLayer) + (1 << ViewStateManager.NoPostVisibleLayer); originalMask &= ~num2; originalMask |= num; originalMask |= num3; return originalMask; } } public class OpenBodyCamFuncs { public static MonoBehaviour TerminalBodyCam = null; public static MonoBehaviour TerminalMirrorCam = null; public static bool ShowingBodyCam = false; private static Vector2Int DefaultRes = new Vector2Int(1000, 700); [MethodImpl(MethodImplOptions.NoInlining)] public static void UpdateCamsTarget(string resolution) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown Loggers.LogInfo("OBC - Getting ZaggyCam texture"); if ((Object)(object)TerminalBodyCam == (Object)null || (Object)(object)((Component)TerminalBodyCam).gameObject == (Object)null || (Object)(BodyCamComponent)TerminalBodyCam == (Object)null) { CreateTerminalBodyCam(resolution); return; } ToggleOpenCams(bodyCam: true, mirrorCam: false); Loggers.LogInfo("OBC - camera already created, assigning targetTexture and enabling camera"); } [MethodImpl(MethodImplOptions.NoInlining)] public static bool BodyCamIsUnlocked() { if (BodyCam.BodyCamsAreAvailable) { return true; } return false; } [MethodImpl(MethodImplOptions.NoInlining)] public static Camera GetCam(MonoBehaviour mono) { BodyCamComponent val = (BodyCamComponent)(object)((mono is BodyCamComponent) ? mono : null); if ((Object)(object)val != (Object)null) { return val.GetCamera(); } Loggers.WARNING("Unable to grab bodycamcomponent @GetCam"); return null; } [MethodImpl(MethodImplOptions.NoInlining)] public static Texture GetTexture(MonoBehaviour mono) { BodyCamComponent val = (BodyCamComponent)(object)((mono is BodyCamComponent) ? mono : null); if ((Object)(object)val != (Object)null) { Camera camera = val.GetCamera(); if ((Object)(object)camera == (Object)null) { Loggers.WARNING("Null camera @GetTexture"); return null; } return (Texture)(object)camera.targetTexture; } Loggers.WARNING("Unable to grab bodycamcomponent @GetTexture"); return null; } private static void CameraEvent(Camera cam) { Loggers.LogInfo("OBC - Camera " + ((Object)cam).name + " created."); } [MethodImpl(MethodImplOptions.NoInlining)] public static void CreateTerminalBodyCam(string resolution) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) Loggers.LogInfo("OBC - CreateTerminalBodyCam()"); if (!Plugin.instance.OpenBodyCamsMod) { return; } ToggleOpenCams(bodyCam: true, mirrorCam: false); if ((Object)(object)TerminalBodyCam != (Object)null || (Object)/*isinst with value type is only supported in some contexts*/ != (Object)null) { Loggers.LogInfo("OBC - bodycam already created and should be enabled, returning"); return; } if (Plugin.instance.TwoRadarMapsMod) { TwoRadarMapsCamCreate(resolution); } else { Loggers.LogInfo("OBC - Creating bodycam synced to mapScreen"); BodyCamComponent val = (BodyCamComponent)(object)(TerminalBodyCam = (MonoBehaviour)(object)BodyCam.CreateBodyCam(((Component)Plugin.instance.Terminal).gameObject, (Material)null, StartOfRound.Instance.mapScreen)); val.Resolution = GetResolutionForOBC(resolution); val.OnRenderTextureCreated += CamStuff.SetBodyCamTexture; val.OnCameraCreated += CameraEvent; val.OnBlankedSet += CamIsBlanked; val.ForceEnableCamera = true; Camera camera = val.GetCamera(); if ((Object)(object)camera == (Object)null) { Loggers.WARNING("Camera is null at creation of CreateTerminalBodyCam!"); return; } ((Object)((Component)camera).gameObject).name = "TerminalStuff OBC bodycam"; CamStuff.SetBodyCamTexture(camera.targetTexture); val.SetTargetToPlayer(StartOfRound.Instance.mapScreen.targetedPlayer); } Loggers.LogInfo("OBC - darmuhsTerminalStuff OBC termcam updated!"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ResidualCamsCheck() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown if ((Object)(object)TerminalBodyCam != (Object)null || (Object)/*isinst with value type is only supported in some contexts*/ != (Object)null) { Object.Destroy((Object)(BodyCamComponent)TerminalBodyCam); TerminalBodyCam = null; Loggers.LogInfo("Attempting to destroy residual TerminalBodyCam"); } if ((Object)(object)TerminalMirrorCam != (Object)null || (Object)/*isinst with value type is only supported in some contexts*/ != (Object)null) { Object.Destroy((Object)(BodyCamComponent)TerminalMirrorCam); TerminalMirrorCam = null; Loggers.LogInfo("Attempting to destroy residual TerminalMirrorCam"); } } [MethodImpl(MethodImplOptions.NoInlining)] public static void TwoRadarMapsCamCreate(string res) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.instance.OpenBodyCamsMod || !Plugin.instance.TwoRadarMapsMod) { return; } ToggleOpenCams(bodyCam: true, mirrorCam: false); if ((Object)(object)TerminalBodyCam != (Object)null || (Object)/*isinst with value type is only supported in some contexts*/ != (Object)null) { Loggers.LogInfo("OBC - bodycam already created and should be enabled, returning"); return; } Loggers.LogInfo("OBC - Tying bodycam to tworadarmaps radarview"); BodyCamComponent val = (BodyCamComponent)(object)(TerminalBodyCam = (MonoBehaviour)(object)BodyCam.CreateBodyCam(((Component)Plugin.instance.Terminal).gameObject, (Material)null, Plugin.TerminalMapRenderer)); val.Resolution = GetResolutionForOBC(res); val.OnRenderTextureCreated += CamStuff.SetBodyCamTexture; val.OnCameraCreated += CameraEvent; val.OnBlankedSet += CamIsBlanked; val.ForceEnableCamera = true; Camera camera = val.GetCamera(); if ((Object)(object)camera == (Object)null) { Loggers.WARNING("2RadarCompat OBC: GetCamera returned NULL at creation!"); return; } ((Object)((Component)camera).gameObject).name = "TerminalStuff 2RadarCompat OBC bodycam"; ((Component)camera).gameObject.SetActive(true); CamStuff.SetBodyCamTexture(camera.targetTexture); } [MethodImpl(MethodImplOptions.NoInlining)] public static void TerminalCameraStatus(bool enabled) { if (!((Object)(object)TerminalBodyCam == (Object)null)) { MonoBehaviour terminalBodyCam = TerminalBodyCam; BodyCamComponent val = (BodyCamComponent)(object)((terminalBodyCam is BodyCamComponent) ? terminalBodyCam : null); if (!((Object)(object)val == (Object)null)) { Loggers.LogInfo($"OBC - BodyCam Screen Enabled: [{enabled}]"); val.ForceEnableCamera = enabled; CamStuff.ToggleCamState(val.GetCamera(), enabled); ShowingBodyCam = enabled; } } } [MethodImpl(MethodImplOptions.NoInlining)] public static void ToggleOpenCams(bool bodyCam, bool mirrorCam) { if ((Object)(object)TerminalBodyCam != (Object)null) { MonoBehaviour terminalBodyCam = TerminalBodyCam; BodyCamComponent val = (BodyCamComponent)(object)((terminalBodyCam is BodyCamComponent) ? terminalBodyCam : null); if ((Object)(object)val != (Object)null) { val.ForceEnableCamera = bodyCam; CamStuff.ToggleCamState(val.GetCamera(), bodyCam); Loggers.LogInfo($"OBC - BodyCam detected and set to [{bodyCam}]"); } } if ((Object)(object)TerminalMirrorCam != (Object)null) { MonoBehaviour terminalMirrorCam = TerminalMirrorCam; BodyCamComponent val2 = (BodyCamComponent)(object)((terminalMirrorCam is BodyCamComponent) ? terminalMirrorCam : null); if ((Object)(object)val2 != (Object)null) { val2.ForceEnableCamera = mirrorCam; CamStuff.ToggleCamState(val2.GetCamera(), mirrorCam); Loggers.LogInfo($"OBC - BodyCam detected and set to [{mirrorCam}]"); } } } [MethodImpl(MethodImplOptions.NoInlining)] public static void TerminalMirrorStatus(bool enabled) { if (!((Object)(object)TerminalMirrorCam == (Object)null)) { MonoBehaviour terminalMirrorCam = TerminalMirrorCam; BodyCamComponent val = (BodyCamComponent)(object)((terminalMirrorCam is BodyCamComponent) ? terminalMirrorCam : null); if (!((Object)(object)val == (Object)null)) { val.ForceEnableCamera = enabled; CamStuff.ToggleCamState(val.GetCamera(), enabled); Loggers.LogInfo($"OBC - BodyCam detected and set to [{enabled}]"); } } } [MethodImpl(MethodImplOptions.NoInlining)] public static void OpenBodyCamsMirror(string res, float zoom, bool ortho, ref GameObject CamHolder) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown Loggers.LogInfo("OBC - Getting ZaggyCam texture OpenBodyCamsMirror()"); if ((Object)(object)TerminalMirrorCam == (Object)null || (Object)(object)((Component)TerminalMirrorCam).gameObject == (Object)null || (Object)(BodyCamComponent)TerminalMirrorCam == (Object)null) { CreateTerminalMirror(res, zoom, ortho, CamHolder); } MonoBehaviour terminalMirrorCam = TerminalMirrorCam; BodyCamComponent val = (BodyCamComponent)(object)((terminalMirrorCam is BodyCamComponent) ? terminalMirrorCam : null); if ((Object)(object)val == (Object)null) { Loggers.WARNING("OpenBodyCamsMirror: Mirror creation failed!"); return; } Loggers.LogInfo("OBC - Attempting to grab targetTexture"); CamStuff.SetMirrorCamTexture(val.GetCamera().targetTexture); val.ForceEnableCamera = true; } [MethodImpl(MethodImplOptions.NoInlining)] public static void OpenBodyCamsMirrorStatus(bool state, string res, float zoom, bool ortho, ref GameObject CamHolder) { Loggers.LogInfo($"OBC - OpenBodyCamsMirrorStatus() state: {state}"); if (state) { OpenBodyCamsMirror(res, zoom, ortho, ref CamHolder); } else { TerminalMirrorStatus(state); } } [MethodImpl(MethodImplOptions.NoInlining)] public static void CreateTerminalMirror(string res, float zoom, bool ortho, GameObject CameraHolder) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.instance.OpenBodyCamsMod) { return; } if ((Object)(object)CameraHolder == (Object)null) { CameraHolder = new GameObject("ObcCamHolder"); } ToggleOpenCams(bodyCam: false, mirrorCam: true); if ((Object)(object)TerminalMirrorCam != (Object)null || (Object)/*isinst with value type is only supported in some contexts*/ != (Object)null) { Loggers.LogInfo("OBC - MirrorCam already created and should be enabled, returning"); return; } Loggers.LogInfo("OBC - CreateTerminalMirror called"); BodyCamComponent val = (BodyCamComponent)(object)(TerminalMirrorCam = (MonoBehaviour)(object)BodyCam.CreateBodyCam(((Component)Plugin.instance.Terminal).gameObject, (Material)null, (ManualCameraRenderer)null)); val.OnRenderTextureCreated += CamStuff.SetMirrorCamTexture; val.OnCameraCreated += ResetTransform; val.OnBlankedSet += CamIsBlanked; val.Resolution = GetResolutionForOBC(res); val.SetTargetToTransform(CameraHolder.transform); Camera camera = val.GetCamera(); if ((Object)(object)camera == (Object)null) { Loggers.WARNING("Mirror camera is null at creation!"); return; } ((Object)((Component)camera).gameObject).name = "OpenLib OBC mirrorcam"; CamStuff.SetMirrorCamTexture(camera.targetTexture); CamStuff.CamInitMirror(CameraHolder, camera, zoom, ortho); Loggers.LogInfo("OBC - TerminalStuff obc mirrorcam created!"); } private static void CamIsBlanked(bool isBlanked) { Loggers.LogInfo($"OBC - CamIsBlanked: {isBlanked}"); } private static void ResetTransform(Camera cam) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) Loggers.LogInfo("OBC - ResetTransform Called!"); CamStuff.CamInitMirror(((Component)(BodyCamComponent)TerminalMirrorCam).gameObject, cam, -1f, ortho: false); } private static Vector2Int GetResolutionForOBC(string configItem) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) List keywordsPerConfigItem = CommonStringStuff.GetKeywordsPerConfigItem(configItem); List numberListFromStringList = CommonStringStuff.GetNumberListFromStringList(keywordsPerConfigItem); Vector2Int defaultRes = default(Vector2Int); if (numberListFromStringList.Count == 2) { ((Vector2Int)(ref defaultRes))..ctor(numberListFromStringList[0], numberListFromStringList[1]); Plugin.Log.LogInfo((object)$"OBC - Resolution set to {numberListFromStringList[0]}x{numberListFromStringList[1]}"); return defaultRes; } defaultRes = DefaultRes; Plugin.Log.LogInfo((object)("OBC - Unable to set resolution to values provided in config: " + configItem + "\nUsing default of 1000x700")); return defaultRes; } } public class TerminalStuffMod { public static void NetSync(TerminalNode node) { if (!((Object)(object)node == (Object)null) && Plugin.instance.TerminalStuff && ConfigSettings.NetworkedNodes.Value && ConfigSettings.ModNetworking.Value) { Loggers.LogDebug("Syncing node with TerminalStuff"); TerminalParse.NetSync(node); } } public static void LoadAndSync(TerminalNode node) { if (!((Object)(object)node == (Object)null)) { Plugin.instance.Terminal.LoadNewNode(node); Loggers.LogDebug("Loading node!"); if (Plugin.instance.TerminalStuff && ConfigSettings.NetworkedNodes.Value && ConfigSettings.ModNetworking.Value) { Loggers.LogDebug("Syncing with TerminalStuff!"); TerminalParse.NetSync(node); } } } public static bool TryLoadHomePage() { if (!Plugin.instance.TerminalStuff) { return false; } if ((Object)(object)TerminalStart.startNode == (Object)null) { return false; } LoadAndSync(TerminalStart.startNode); return true; } public static bool TryLoadStartPage() { if (!Plugin.instance.TerminalStuff) { return false; } if (TerminalEvents.terminalSettings.startPageValue.Length < 1) { return false; } if ((Object)(object)TerminalEvents.terminalSettings.startPage == (Object)null) { return false; } LoadAndSync(TerminalEvents.terminalSettings.startPage); return true; } private static bool TryGetKeywordFashtenstein(string query, out TerminalKeyword word) { word = null; if (!Plugin.instance.TerminalStuff) { return false; } ConflictRes.TryGetBestMatchingKeyword(query, ref word); return (Object)(object)word != (Object)null; } } } namespace OpenLib.Common { public class CamStuff { public static OpenLib.Events.Events.CustomEvent BodyCamTextureSet = new OpenLib.Events.Events.CustomEvent(); public static OpenLib.Events.Events.CustomEvent MirrorCamTextureSet = new OpenLib.Events.Events.CustomEvent(); public static GameObject MyCameraHolder = null; public static GameObject ObcCameraHolder = null; public static HDAdditionalCameraData CameraData = null; public static void SetBodyCamTexture(RenderTexture texture) { BodyCamTextureSet.Invoke(texture); Loggers.LogInfo("Assigning bodycam texture"); } public static void SetMirrorCamTexture(RenderTexture texture) { MirrorCamTextureSet.Invoke(texture); Loggers.LogInfo("Assigning mirror texture"); if (Plugin.instance.OpenBodyCamsMod) { OpenBodyCamFuncs.TerminalMirrorStatus(enabled: true); } } public static void ToggleCamState(Camera playerCam, bool state) { if (!((Object)(object)playerCam == (Object)null)) { ((Component)playerCam).gameObject.SetActive(state); Loggers.LogInfo($"{((Object)((Component)playerCam).gameObject).name} set to state: {state}"); if (state) { SetBodyCamTexture(playerCam.targetTexture); } } } public static void CamInitMirror(GameObject CameraHolder, Camera playerCam, float zoom, bool ortho) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) if (zoom > 0f) { playerCam.cameraType = (CameraType)1; playerCam.orthographic = ortho; playerCam.orthographicSize = zoom; playerCam.usePhysicalProperties = false; playerCam.farClipPlane = 30f; playerCam.nearClipPlane = 0.05f; playerCam.fieldOfView = 130f; } CameraHolder.SetActive(true); ((Component)playerCam).transform.SetParent(CameraHolder.transform); Transform transform = ((Component)Plugin.instance.Terminal.terminalImage).transform; Quaternion rotation = Quaternion.LookRotation(-((Component)transform).transform.forward, transform.up); Loggers.LogInfo("camTransform assigned to MirrorObject, which is assigned to termTransform"); CameraHolder.transform.SetParent(transform); CameraHolder.transform.rotation = rotation; CameraHolder.transform.position = transform.position; Loggers.LogInfo($"initCamHeight: {CameraHolder.transform.position.y}"); } public static Camera HomebrewCam(ref RenderTexture mycamTexture, ref GameObject CamObject) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)CamObject == (Object)null) { CamObject = new GameObject("OpenLib Cam (Homebrew)"); } Camera val = ((!((Object)(object)CamObject.GetComponent() != (Object)null)) ? CamObject.AddComponent() : CamObject.GetComponent()); if ((Object)(object)mycamTexture == (Object)null) { mycamTexture = new RenderTexture(StartOfRound.Instance.localPlayerController.gameplayCamera.targetTexture); } int num = StartOfRound.Instance.localPlayerController.gameplayCamera.cullingMask & ~LayerMask.GetMask(new string[3] { "Ignore Raycast", "UI", "HelmetVisor" }); if (Plugin.instance.ModelReplacement) { num = ModelAPI.GetThirdPersonMask(num); } else { num |= 0x800000; ((Component)StartOfRound.Instance.localPlayerController.thisPlayerModelArms).gameObject.layer = 5; if ((Object)(object)CamObject.GetComponent() == (Object)null) { CameraData = CamObject.AddComponent(); CameraData.volumeLayerMask = LayerMask.op_Implicit(1); CameraData.hasPersistentHistory = true; HDAdditionalCameraData component = ((Component)StartOfRound.Instance.localPlayerController.gameplayCamera).GetComponent(); if (component.customRenderingSettings) { Loggers.LogDebug("Using original customRenderingSettings for OpenLib cams"); CameraData.customRenderingSettings = true; CameraData.renderingPathCustomFrameSettings = component.renderingPathCustomFrameSettings; CameraData.renderingPathCustomFrameSettingsOverrideMask = component.renderingPathCustomFrameSettingsOverrideMask; } } } val.targetTexture = mycamTexture; val.cullingMask = num; CamObject.SetActive(false); Loggers.LogInfo("playerCam instantiated"); return val; } public static void HomebrewCameraState(bool active, Camera playerCam) { if (!((Object)(object)playerCam == (Object)null)) { ((Component)playerCam).gameObject.SetActive(active); } } public static Camera GetCam(GameObject Container) { if ((Object)(object)Container == (Object)null) { return null; } return Container.GetComponent(); } } public class CommonEnums { [CompilerGenerated] private sealed class d__1 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public Terminal terminal; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; if (quitTerminalEnum) { return false; } quitTerminalEnum = true; <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 1; return true; case 1: <>1__state = -1; terminal.QuitTerminal(true); quitTerminalEnum = false; 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(); } } [CompilerGenerated] private sealed class d__2 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public Terminal terminal; public bool syncTerminalInUse; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__2(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; if (quitTerminalEnum) { return false; } quitTerminalEnum = true; <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 1; return true; case 1: <>1__state = -1; terminal.QuitTerminal(syncTerminalInUse); quitTerminalEnum = false; 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 quitTerminalEnum; [IteratorStateMachine(typeof(d__1))] public static IEnumerator TerminalQuitter(Terminal terminal) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0) { terminal = terminal }; } [IteratorStateMachine(typeof(d__2))] public static IEnumerator TerminalQuitter(Terminal terminal, bool syncTerminalInUse) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__2(0) { terminal = terminal, syncTerminalInUse = syncTerminalInUse }; } } public class CommonStringStuff { public static string GetNextPage(List categoryItems, string categoryTitle, int pageSize, int currentPage, out bool isNextEnabled) { currentPage = Mathf.Clamp(currentPage, 1, Mathf.CeilToInt((float)categoryItems.Count / (float)pageSize)); int num = (currentPage - 1) * pageSize; int num2 = Mathf.Min(num + pageSize, categoryItems.Count); int num3 = 0; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("============ All [" + categoryTitle.ToUpper() + "] Commands ============"); stringBuilder.Append("\r\n"); for (int i = num; i < num2; i++) { string text = categoryItems[i]; stringBuilder.Append(text + "\r\n"); num3++; } int num4 = pageSize - num3; for (int j = 0; j < num4; j++) { stringBuilder.Append("\r\n"); } stringBuilder.Append("\r\n"); stringBuilder.Append($"Page {currentPage}/{Mathf.CeilToInt((float)categoryItems.Count / (float)pageSize)}\r\n"); if (num2 < categoryItems.Count) { stringBuilder.Append("Type next to see the next page of [" + categoryTitle + "] commands!\r\n"); isNextEnabled = true; } else { isNextEnabled = false; } return stringBuilder.ToString(); } public static string[] GetWords() { string text = Plugin.instance.Terminal.screenText.text; int textAdded = Plugin.instance.Terminal.textAdded; int length = text.Length; int num = length - textAdded; string text2 = text.Substring(num, length - num); return text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public static string[] GetWordsAndKeyword(List configItemWords, string[] words) { List list = new List(); bool flag = false; foreach (string text in words) { Loggers.LogInfo("checking " + text); foreach (string configItemWord in configItemWords) { if (configItemWord.Contains(text)) { list.Add(configItemWord); flag = true; Loggers.LogInfo("adding " + configItemWord + " to list"); break; } } if (!flag) { list.Add(text); Loggers.LogInfo("adding non-keyword, word: " + text); } } return list.ToArray(); } public static List GetKeywordsPerConfigItem(string configItem) { List result = new List(); if (configItem.Length > 0) { result = (from item in configItem.Split(';') select item.TrimStart()).ToList(); } return result; } public static List GetKeywordsPerConfigItem(string configItem, char separator) { List result = new List(); if (configItem.Length > 0) { result = (from item in configItem.Split(separator) select item.TrimStart()).ToList(); } return result; } public static List GetNumberListFromStringList(List stringList) { List list = new List(); foreach (string @string in stringList) { if (int.TryParse(@string, out var result)) { list.Add(result); } else { Loggers.WARNING("Could not parse " + @string + " to integer"); } } return list; } public static string BepinFriendlyString(string input) { char[] source = new char[7] { '\'', '\n', '\t', '\\', '"', '[', ']' }; string text = ""; input = input.Trim(); string text2 = input; for (int i = 0; i < text2.Length; i++) { char value = text2[i]; if (!source.Contains(value)) { text += value; } } return text; } public static bool TryGetKey(string query, out Key key) { if (Enum.TryParse(query, ignoreCase: true, out key)) { return true; } return false; } public static List GetFloatListFromStringList(List stringList) { List list = new List(); foreach (string @string in stringList) { if (!Utility.IsNullOrWhiteSpace(@string)) { if (float.TryParse(@string, out var result)) { list.Add(result); } else { Loggers.WARNING("Could not parse " + @string + " to float"); } } } return list; } public static List GetItemList(string rawList) { List result = new List(); if (rawList.Length > 0) { result = (from item in rawList.Split(',') select item.TrimStart()).ToList(); } return result; } public static List GetListToLower(List stringList) { return stringList.ConvertAll((string s) => s.ToLower()); } public static string GetKeywordsForMenuItem(List itemKeywords) { if (itemKeywords.Count == 0) { return ""; } if (itemKeywords.Count == 1) { return itemKeywords[0]; } StringBuilder stringBuilder = new StringBuilder(); foreach (string itemKeyword in itemKeywords) { stringBuilder.Append(itemKeyword + ", "); } string text = stringBuilder.ToString(); string text2 = text; return text2.Substring(0, text2.Length - 2); } public static string GetCleanedScreenText(Terminal __instance) { string text = __instance.screenText.text; int textAdded = __instance.textAdded; int length = text.Length; int num = length - textAdded; string s = text.Substring(num, length - num); return RemovePunctuation(s); } public static string RemovePunctuation(string s) { StringBuilder stringBuilder = new StringBuilder(); foreach (char c in s) { if (!char.IsPunctuation(c)) { stringBuilder.Append(c); } } return stringBuilder.ToString().ToLower(); } } public class CommonTerminal { public static TerminalNode parseNode = null; public static Color CaretOriginal; public static Color transparent = new Color(0f, 0f, 0f, 0f); public static List AllTerminalNodes = new List(); private static TerminalNode _home = null; public static TerminalKeyword InfoKeyword { get { if (DynamicBools.TryGetKeyword("info", out TerminalKeyword terminalKeyword)) { return terminalKeyword; } Loggers.WARNING("InfoKeyword reference could not be found! [NULL]"); return null; } } public static TerminalKeyword BuyKeyword { get { if (DynamicBools.TryGetKeyword("buy", out TerminalKeyword terminalKeyword)) { return terminalKeyword; } Loggers.WARNING("BuyKeyword reference could not be found! [NULL]"); return null; } } public static TerminalKeyword OtherKeyword { get { if (DynamicBools.TryGetKeyword("other", out TerminalKeyword terminalKeyword)) { return terminalKeyword; } Loggers.WARNING("OtherKeyword reference could not be found! [NULL]"); return null; } } public static TerminalNode HomePage { get { if ((Object)(object)_home == (Object)null) { _home = Plugin.instance.Terminal.terminalNodes.specialNodes.ToArray()[1]; } return _home; } } public static void ToggleScreen(bool status) { ((MonoBehaviour)Plugin.instance.Terminal).StartCoroutine(Plugin.instance.Terminal.waitUntilFrameEndToSetActive(status)); Loggers.LogDebug($"Screen set to {status}"); } public static void ChangeCaretColor(Color newColor, bool saveOriginal) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (saveOriginal) { CaretOriginal = Plugin.instance.Terminal.screenText.caretColor; } Plugin.instance.Terminal.screenText.caretColor = newColor; } public static void LoadNewNode(TerminalNode node) { if (Plugin.instance.TerminalStuff) { TerminalStuffMod.LoadAndSync(node); } else { Plugin.instance.Terminal.LoadNewNode(node); } } public static void TrySyncNodeOnly(TerminalNode node) { if (Plugin.instance.TerminalStuff) { TerminalStuffMod.NetSync(node); } } public static bool TryLoadKeyword(string keyword) { if (DynamicBools.TryGetKeyword(keyword, out TerminalKeyword terminalKeyword)) { TerminalNode specialKeywordResult = terminalKeyword.specialKeywordResult; Loggers.LogDebug("TryLoadKeyword found keyword [ " + terminalKeyword.word + " ]"); LoadNewNode(specialKeywordResult); return true; } return false; } public static bool TryGetCommand(string words, out TerminalNode returnNode) { string words2 = words; returnNode = null; if (words2.Length == 0) { return false; } List source = Plugin.AllCommands.FindAll((CommandManager x) => x.IsCommandEnabled()); IEnumerable source2 = source.Where((CommandManager x) => x.AcceptAdditionalText); CommandManager commandManager = source2.FirstOrDefault((CommandManager x) => x.terminalKeywords.Any((TerminalKeyword s) => Misc.StringStartsWithInvariant(words2, s.word))); if (commandManager != null) { returnNode = commandManager.terminalNode; return (Object)(object)returnNode != (Object)null; } CommandManager commandManager2 = source.FirstOrDefault((CommandManager x) => x.terminalKeywords.Any((TerminalKeyword s) => Misc.CompareStringsInvariant(words2, s.word))); if (commandManager2 != null) { returnNode = commandManager2.terminalNode; return (Object)(object)returnNode != (Object)null; } if (words2.Length < 3) { Loggers.LogDebug("No matching commands for [ " + words2 + " ] in all enabled commands (short query)"); return false; } CommandManager commandManager3 = source.FirstOrDefault((CommandManager x) => x.terminalKeywords.Any((TerminalKeyword s) => Misc.StringStartsWithInvariant(s.word, words2))); if (commandManager3 != null) { returnNode = commandManager3.terminalNode; return (Object)(object)returnNode != (Object)null; } Loggers.LogDebug("No matching commands for [ " + words2 + " ] in all enabled commands"); return false; } public static bool TryGetNodeFromList(string query, Dictionary nodeListing, out TerminalNode returnNode) { returnNode = null; if (query.Length == 0) { return false; } string[] words = query.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (!nodeListing.Any>((KeyValuePair x) => words.Contains(x.Key.ToLower()))) { return false; } returnNode = nodeListing.FirstOrDefault>((KeyValuePair x) => Misc.CompareStringsInvariant(x.Key, words[0])).Value; if ((Object)(object)returnNode != (Object)null) { return true; } returnNode = nodeListing.FirstOrDefault>((KeyValuePair t) => words.Any((string x) => Misc.CompareStringsInvariant(x, t.Key))).Value; if ((Object)(object)returnNode != (Object)null) { return true; } return false; } public static void AddShopItemsToFurnitureList(List UnlockableNodes) { foreach (TerminalNode UnlockableNode in UnlockableNodes) { if (!Plugin.instance.Terminal.ShipDecorSelection.Contains(UnlockableNode)) { Plugin.instance.Terminal.ShipDecorSelection.Add(UnlockableNode); Loggers.LogDebug("adding " + UnlockableNode.creatureName + " to shipdecorselection"); } else { Loggers.LogDebug(UnlockableNode.creatureName + " already in shipdecorselection"); } } Loggers.LogDebug("nodes have been added"); } public static string ClearText() { string result = "\n"; Loggers.LogDebug("display text cleared for real this time!!!"); return result; } [Obsolete("Use TryGetNodeFromList instead to avoid NRE")] public static TerminalNode GetNodeFromList(string query, Dictionary nodeListing) { foreach (KeyValuePair item in nodeListing) { if (item.Key == query) { return item.Value; } } return null; } } public class Misc { public static Random Random = new Random(); public static bool TryGetPlayerFromName(string playerName, out PlayerControllerB thePlayer) { string playerName2 = playerName; thePlayer = ((IEnumerable)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func)((PlayerControllerB p) => CompareStringsInvariant(p.playerUsername, playerName2))); return (Object)(object)thePlayer != (Object)null; } public static int CycleIndex(int value, int min, int max) { if (value < min) { return max; } if (value > max) { return min; } return value; } public static bool TryGetPlayerUsingTerminal(out PlayerControllerB terminalUser) { terminalUser = ((IEnumerable)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func)((PlayerControllerB player) => !player.isPlayerDead && (Object)(object)player.currentTriggerInAnimationWith == (Object)(object)Plugin.instance.Terminal.terminalTrigger)); return (Object)(object)terminalUser != (Object)null; } public static bool TryGetHostClientID(out int HostClientID) { PlayerControllerB val = ((IEnumerable)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func)((PlayerControllerB player) => player.isHostPlayerObject)); if ((Object)(object)val == (Object)null) { HostClientID = -1; return false; } HostClientID = (int)val.playerClientId; return true; } public static Color HexToColor(string hex) { //IL_0021: 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) Color result = default(Color); if (ColorUtility.TryParseHtmlString(hex, ref result)) { return result; } Loggers.WARNING("Unable to get color from hex: " + hex + "\nReturning color - white"); return Color.white; } public static void LogColorBeforeChange(Color color, ConfigEntry entry) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) string text = ColorUtility.ToHtmlStringRGB(color); Plugin.Log.LogDebug((object)("Previous Color noted as [" + text + "] for configItem - " + ((ConfigEntryBase)entry).Definition.Key)); } public static Version GetPluginVersion(string PluginGUID) { if (Chainloader.PluginInfos.TryGetValue(PluginGUID, out var value)) { return value.Metadata.Version; } return null; } public static bool CompareStringsInvariant(string str1, string str2, bool ignoreCase = true) { StringComparison comparisonType = (ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture); return str1.Equals(str2, comparisonType); } public static bool DoesListHaveInvariant(List stringList, string query, bool ignoreCase = true) { if (stringList == null) { return false; } StringComparison comparisonType = (ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture); for (int i = 1; i < stringList.Count; i++) { if (string.Equals(query, stringList[i], comparisonType)) { return true; } } return false; } public static bool StringStartsWithInvariant(string fullstring, char ch, bool ignoreCase = true) { StringComparison comparisonType = (ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture); return fullstring.StartsWith($"{ch}", comparisonType); } public static bool StringStartsWithInvariant(string fullstring, string str, bool ignoreCase = true) { StringComparison comparisonType = (ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture); return fullstring.StartsWith(str, comparisonType); } public static bool StringContainsInvariant(string fullstring, string query, bool ignoreCase = true) { StringComparison comparisonType = (ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture); return fullstring.Contains(query, comparisonType); } public static List GetSubstrings(char start, char end, string query) { List list = new List(); int num = -1; for (int i = 0; i < query.Length; i++) { if (query[i] == start) { num = i; } else if (query[i] == end && num != -1) { int length = i - num + 1; list.Add(query.Substring(num, length)); num = -1; } } return list; } [Obsolete("Use TryGetHostClientID instead to avoid NRE")] public static int HostClientID() { PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (val.isHostPlayerObject) { Loggers.LogInfo($"Player: {val.playerUsername} is the host, client ID: {val.playerClientId}."); return (int)val.playerClientId; } } return -1; } [Obsolete("Use TryGetPlayerFromName instead to avoid NRE")] public static PlayerControllerB GetPlayerFromName(string playerName) { PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (CompareStringsInvariant(val.playerUsername, playerName)) { return val; } } return null; } [Obsolete("Use TryGetPlayerUsingTerminal instead to avoid NRE")] public static PlayerControllerB GetPlayerUsingTerminal() { PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (!val.isPlayerDead && (Object)(object)val.currentTriggerInAnimationWith == (Object)(object)Plugin.instance.Terminal.terminalTrigger) { Loggers.LogInfo("Player: " + val.playerUsername + " detected using terminal."); return val; } } return null; } } public abstract class NetworkClassBase { internal static GameObject NetObject = null; internal static List NetworkClasses = new List(); internal static GameObject Prefab { get; set; } = null; public virtual ConfigEntry? Toggle { get; set; } internal static void Register(NetworkClass prefabGen) where T : NetworkBehaviour { NetworkClasses.Add(prefabGen); } internal abstract void NetworkInit(); internal static void RegisterNetworkPrefabs() { if ((Object)(object)Prefab == (Object)null) { Loggers.WARNING("Unable to RegisterNetworkPrefabs! Openlib Networker asset has not been loaded!"); } else { if (NetworkClasses.Count == 0) { return; } foreach (NetworkClassBase networkClass in NetworkClasses) { networkClass.NetworkInit(); } NetworkManager.Singleton.AddNetworkPrefab(Prefab); } } internal static void SpawnNetworkPrefab() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (ShouldSpawn()) { if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer) { NetObject = Object.Instantiate(Prefab, Vector3.zero, Quaternion.identity); NetObject.GetComponent().Spawn(false); Loggers.LogMessage("Host client has spawned Openlib's Network Object"); } else { Loggers.LogDebug("Non-host client will not spawn Network Object"); } } } internal static bool ShouldSpawn() { if (NetworkClasses.Count == 0) { return false; } foreach (NetworkClassBase networkClass in NetworkClasses) { if (networkClass.Toggle == null) { Loggers.LogMessage($"{networkClass} does not have a networking toggle. Openlib networker will be spawned for host!"); return true; } if (networkClass.Toggle.Value) { Loggers.LogMessage($"{networkClass}'s network toggle is enabled. Openlib networker will be spawned for host!"); return true; } } Loggers.LogMessage("Openlib networker will not be spawned. Networking is disabled."); return false; } } public class NetworkClass : NetworkClassBase where T : NetworkBehaviour { internal string Name; public NetworkClass(string name, ConfigEntry toggle = null) { Toggle = toggle; Name = name; NetworkClassBase.Register(this); } public override string ToString() { return Name; } internal override void NetworkInit() { NetworkClassBase.Prefab.AddComponent(); Loggers.LogMessage("Network Class: " + Name + " has been initialized on Openlib's Networker!"); } } public class StartGame { internal static bool oneTimeOnly; internal static void CompatibilityCheck() { if (SoftCompatibility("BMX.LobbyCompatibility", ref Plugin.instance.LobbyCompat)) { Loggers.LogDebug("LobbyCompatibility detected, setting appropriate Lobby Compatibility Level depending on networking status"); BMX_LobbyCompat.SetCompat(isNetworked: false); } if (SoftCompatibility("TerminalFormatter", ref Plugin.instance.TerminalFormatter)) { Loggers.LogDebug("Terminal Formatter by mrov detected!"); } if (SoftCompatibility("WhiteSpike.InteractiveTerminalAPI", ref Plugin.instance.ITAPI)) { Loggers.LogDebug("InteractiveTerminalAPI by WhiteSpike detected!"); } if (SoftCompatibility("ainavt.lc.lethalconfig", ref Plugin.instance.LethalConfig)) { Loggers.LogDebug("LethalConfig functions enabled!"); } if (SoftCompatibility("Zaggy1024.OpenBodyCams", ref Plugin.instance.OpenBodyCamsMod)) { Loggers.LogDebug("OpenBodyCams by Zaggy1024 detected!"); } if (SoftCompatibility("Zaggy1024.TwoRadarMaps", ref Plugin.instance.TwoRadarMapsMod)) { Loggers.LogDebug("TwoRadarMaps by Zaggy1024 detected!"); } if (SoftCompatibility("meow.ModelReplacementAPI", ref Plugin.instance.ModelReplacement)) { Loggers.LogDebug("ModelReplacementAPI detected!"); } if (SoftCompatibility("FlipMods.TooManyEmotes", ref Plugin.instance.TooManyEmotes)) { Loggers.LogDebug("TooManyEmotes by FlipMods detected!"); } if (SoftCompatibility("quackandcheese.mirrordecor", ref Plugin.instance.MirrorDecor)) { Loggers.LogDebug("MirrorDecor detected!"); } if (SoftCompatibility("darmuh.TerminalStuff", ref Plugin.instance.TerminalStuff)) { Loggers.LogDebug("TerminalStuff detected!"); } } internal static void OnGameStart() { CompatibilityCheck(); oneTimeOnly = false; } public static bool SoftCompatibility(string PluginGUID, ref bool isDetected) { if (Chainloader.PluginInfos.ContainsKey(PluginGUID)) { string name = Assembly.GetCallingAssembly().GetName().Name; isDetected = true; if ("OpenLib" != name) { Plugin.Log.LogInfo((object)$"{PluginGUID} detected! Plugin: {name} has set compatibility bool - {isDetected}"); } return isDetected; } return isDetected = false; } } public class Teleporter { public static ShipTeleporter NormalTP; public static ShipTeleporter InverseTP; public static void CheckTeleporterTypeAndAssign(ShipTeleporter instance) { if (instance.isInverseTeleporter) { ITPexists(instance); } else { TPexists(instance); } } public static void TPexists(ShipTeleporter instance) { NormalTP = instance; Loggers.LogInfo("NormalTP instance detected and set."); EventManager.NormalTPFound.Invoke(); } public static void ITPexists(ShipTeleporter instance) { InverseTP = instance; Loggers.LogInfo("InverseTP instance detected and set."); EventManager.InverseTPFound.Invoke(); } } public class TerminalStart { [CompilerGenerated] private sealed class d__2 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__2(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; if (delayStartEnum) { return false; } delayStartEnum = true; <>2__current = (object)new WaitForSeconds(1f); <>1__state = 1; return true; case 1: <>1__state = -1; Loggers.LogInfo("1 Second delay methods starting."); EventManager.TerminalDelayStart.Invoke(); AddStoreItems(); delayStartEnum = false; 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(); } } internal static bool delayStartEnum; internal static void TerminalStartGroupDelay() { Loggers.LogDebug("Starting TerminalDelayStartEnumerator"); ((MonoBehaviour)Plugin.instance.Terminal).StartCoroutine(TerminalDelayStartEnumerator()); } [IteratorStateMachine(typeof(d__2))] internal static IEnumerator TerminalDelayStartEnumerator() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__2(0); } internal static void AddStoreItems() { if (!Plugin.instance.TerminalFormatter) { AddShopItemsToFurnitureList(); } } private static void AddShopItemsToFurnitureList() { foreach (TerminalNode shopNode in Plugin.ShopNodes) { if (!Plugin.instance.Terminal.ShipDecorSelection.Contains(shopNode)) { Plugin.instance.Terminal.ShipDecorSelection.Add(shopNode); Loggers.LogDebug("adding " + shopNode.creatureName + " to shipdecorselection"); } else { Loggers.LogDebug(shopNode.creatureName + " already in shipdecorselection"); } } Loggers.LogDebug("nodes have been added"); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }