Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of HexDevTools v1.3.2
Plugins/HexDevTools.dll
Decompiled a week agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Managers; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("HexDevTools")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("HexDevTools")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("baf6dd8e-8466-4ff0-b61c-9cc9e48cc9ed")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace HexDevTools; internal static class Constants { internal static class DevCommands { internal const string DevCommand = "devcommands"; internal const string DebugMode = "debugmode"; internal const string NoBuildCost = "nocost"; internal const string Fly = "fly"; internal const string DayTime = "tod 0.5"; internal const string NightTime = "tod 0"; internal const string Spawn = "spawn"; internal const string God = "god"; internal const string FreeFly = "freefly"; internal const string ResetTimeOfDayToDefault = "tod -1"; } internal static class HexDevToolsGuiText { internal const string Title = "Dev Tools"; internal const string EnableDevCommands = "Enable Devcommands"; internal const string DisableDevCommands = "Disable Devcommands"; internal const string DevCommands = "Dev Commands"; internal const string Spawn = "Spawn"; internal const string Close = "Close"; internal const string NoBuildCost = "No Build Cost"; internal const string DayTime = "Day Time"; internal const string NightTime = "Night Time"; internal const string Fly = "Fly"; internal const string God = "God Mode"; internal const string FreeFly = "Free Fly"; internal const string ResetTimeOfDayToDefault = "Reset Time of Day"; internal const string SpawnPlaceholder = "prefabName arg1 arg2"; } } [BepInPlugin("hex.devtools", "HexDevTools", "1.3.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private const string PluginGuid = "hex.devtools"; private const string PluginName = "HexDevTools"; private const string PluginVersion = "1.3.2"; private static readonly FieldInfo CheatEnabledField = AccessTools.Field(typeof(Terminal), "m_cheat"); private readonly PrefabSearchService _prefabSearchService = new PrefabSearchService(); private ConfigEntry<KeyboardShortcut> _toggleKey; private bool _uiVisible; private bool _devCommandsEnabled; private Coroutine _devCommandsCoroutine; private GameObject _uiRoot; private GameObject _clickOutsideBackground; private GameObject _mainPanel; private GameObject _devCommandPanel; private GameObject _devCommandButtonArea; private GameObject _spawnPanel; private Button _enableDevCommandsButton; private InputField _spawnInputField; private Text _spawnSuggestionsText; private List<string> _spawnMatches = new List<string>(); private int _spawnMatchIndex = -1; private bool _spawnPrefabSelected; internal static Plugin Instance { get; private set; } private void Awake() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) Instance = this; _toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Toggle Dev Tools UI"); GUIManager.OnCustomGUIAvailable += OnCustomGUIAvailable; } private void Update() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) if (_toggleKey != null) { KeyboardShortcut value = _toggleKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { SetPanelVisible(!_uiVisible); return; } } if (_uiVisible && Input.GetKeyDown((KeyCode)27)) { SetPanelVisible(visible: false); } else if ((Object)(object)_spawnInputField != (Object)null && _spawnInputField.isFocused && !_spawnPrefabSelected && Input.GetKeyDown((KeyCode)9)) { bool reverse = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307); CycleSpawnSuggestion(reverse); } } private void OnDestroy() { GUIManager.OnCustomGUIAvailable -= OnCustomGUIAvailable; GUIManager.BlockInput(false); if (_devCommandsCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(_devCommandsCoroutine); _devCommandsCoroutine = null; } Instance = null; } private void OnCustomGUIAvailable() { _prefabSearchService.CachePrefabNames(); CreateUiRoot(); _uiVisible = false; _uiRoot.SetActive(false); CreateClickOutsideBackground(); CreateMainPanel(); CreateHeader(); CreateEnableDevCommandsButton(); CreateDevCommandPanel(); CreateSpawnPanel(); CreateCloseButton(); ResetDevCommandUiState(); ResetSpawnAutocomplete(); } private void CreateUiRoot() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0037: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) _uiRoot = new GameObject("HexDevToolsRoot"); _uiRoot.transform.SetParent(GUIManager.CustomGUIFront.transform, false); RectTransform obj = _uiRoot.AddComponent<RectTransform>(); obj.anchorMin = Vector2.zero; obj.anchorMax = Vector2.one; obj.offsetMin = Vector2.zero; obj.offsetMax = Vector2.zero; } private void CreateClickOutsideBackground() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown _clickOutsideBackground = new GameObject("ClickOutsideBackground"); _clickOutsideBackground.transform.SetParent(_uiRoot.transform, false); RectTransform obj = _clickOutsideBackground.AddComponent<RectTransform>(); obj.anchorMin = Vector2.zero; obj.anchorMax = Vector2.one; obj.offsetMin = Vector2.zero; obj.offsetMax = Vector2.zero; Image obj2 = _clickOutsideBackground.AddComponent<Image>(); ((Graphic)obj2).color = new Color(0f, 0f, 0f, 0.001f); ((Graphic)obj2).raycastTarget = true; Button obj3 = _clickOutsideBackground.AddComponent<Button>(); ((Selectable)obj3).transition = (Transition)0; ((UnityEvent)obj3.onClick).AddListener((UnityAction)delegate { SetPanelVisible(visible: false); }); } private void CreateMainPanel() { //IL_001b: 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) //IL_002f: Unknown result type (might be due to invalid IL or missing references) _mainPanel = GUIManager.Instance.CreateWoodpanel(_uiRoot.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, 430f, 680f, true); _mainPanel.transform.SetAsLastSibling(); } private void CreateHeader() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002e: 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_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) GUIManager.Instance.CreateText("Dev Tools", _mainPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -45f), GUIManager.Instance.AveriaSerifBold, 30, GUIManager.Instance.ValheimOrange, true, Color.black, 300f, 40f, false); } private void CreateEnableDevCommandsButton() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002e: 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_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown GameObject val = GUIManager.Instance.CreateButton("Enable Devcommands", _mainPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -95f), 180f, 30f); _enableDevCommandsButton = val.GetComponent<Button>(); ((UnityEvent)_enableDevCommandsButton.onClick).AddListener(new UnityAction(OnEnableDevCommandsClicked)); } private void OnEnableDevCommandsClicked() { if (_devCommandsCoroutine == null) { if (_devCommandsEnabled) { _devCommandsCoroutine = ((MonoBehaviour)this).StartCoroutine(DisableDevCommandsCoroutine()); } else { _devCommandsCoroutine = ((MonoBehaviour)this).StartCoroutine(EnableDevCommandsCoroutine()); } } } private IEnumerator EnableDevCommandsCoroutine() { if ((Object)(object)_enableDevCommandsButton != (Object)null) { ((Selectable)_enableDevCommandsButton).interactable = false; } if ((Object)(object)Console.instance == (Object)null) { ShowHudMessage("Console is not available."); ResetDevCommandsAttempt(); yield break; } if ((Object)(object)Player.m_localPlayer == (Object)null) { ResetDevCommandsAttempt(); yield break; } if (!AreDevCommandsEnabled()) { RunConsoleCommand("devcommands"); float timeoutAt = Time.realtimeSinceStartup + 5f; while (!AreDevCommandsEnabled() && Time.realtimeSinceStartup < timeoutAt) { yield return null; } } if (!AreDevCommandsEnabled()) { ShowHudMessage("Devcommands authorization failed."); ResetDevCommandsAttempt(); yield break; } if (!Player.m_debugMode) { RunConsoleCommand("debugmode"); float timeoutAt = Time.realtimeSinceStartup + 2f; while (!Player.m_debugMode && Time.realtimeSinceStartup < timeoutAt) { yield return null; } } if (!Player.m_debugMode) { ShowHudMessage("Debugmode was not authorized."); ResetDevCommandsAttempt(); } else { _devCommandsCoroutine = null; ResetDevCommandUiState(); ShowHudMessage("Devcommands and debugmode enabled."); } } private IEnumerator DisableDevCommandsCoroutine() { if ((Object)(object)_enableDevCommandsButton != (Object)null) { ((Selectable)_enableDevCommandsButton).interactable = false; } if ((Object)(object)Console.instance == (Object)null) { ShowHudMessage("Console is not available."); ResetDevCommandsAttempt(); yield break; } if ((Object)(object)Player.m_localPlayer == (Object)null) { ResetDevCommandsAttempt(); yield break; } if (Player.m_debugMode) { RunConsoleCommand("debugmode"); float timeoutAt = Time.realtimeSinceStartup + 2f; while (Player.m_debugMode && Time.realtimeSinceStartup < timeoutAt) { yield return null; } } if (Player.m_debugMode) { ShowHudMessage("Debugmode could not be disabled."); ResetDevCommandsAttempt(); yield break; } if (AreDevCommandsEnabled()) { RunConsoleCommand("devcommands"); float timeoutAt = Time.realtimeSinceStartup + 5f; while (AreDevCommandsEnabled() && Time.realtimeSinceStartup < timeoutAt) { yield return null; } } if (AreDevCommandsEnabled()) { ShowHudMessage("Devcommands could not be disabled."); ResetDevCommandsAttempt(); } else { _devCommandsCoroutine = null; ResetDevCommandUiState(); ShowHudMessage("Devcommands and debugmode disabled."); } } private void ResetDevCommandsAttempt() { _devCommandsCoroutine = null; ResetDevCommandUiState(); } private void CreateDevCommandPanel() { //IL_001b: 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) //IL_0039: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) _devCommandPanel = GUIManager.Instance.CreateWoodpanel(_mainPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -260f), 330f, 290f, false); GUIManager.Instance.CreateText("Dev Commands", _devCommandPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -25f), GUIManager.Instance.AveriaSerifBold, 16, GUIManager.Instance.ValheimOrange, true, Color.black, 200f, 30f, false); CreateDevCommandButtonArea(); CreateDevCommandButton("No Build Cost", "nocost"); CreateDevCommandButton("Fly", "fly"); CreateDevCommandButton("Free Fly", "freefly"); CreateDevCommandButton("God Mode", "god"); CreateDevCommandButton("Day Time", "tod 0.5"); CreateDevCommandButton("Night Time", "tod 0"); CreateDevCommandButton("Reset Time of Day", "tod -1"); } private void CreateDevCommandButtonArea() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown _devCommandButtonArea = new GameObject("HexDevToolsDevCommandButtonArea"); _devCommandButtonArea.transform.SetParent(_devCommandPanel.transform, false); RectTransform obj = _devCommandButtonArea.AddComponent<RectTransform>(); obj.anchorMin = new Vector2(0.5f, 1f); obj.anchorMax = new Vector2(0.5f, 1f); obj.anchoredPosition = new Vector2(0f, -150f); obj.sizeDelta = new Vector2(260f, 220f); VerticalLayoutGroup obj2 = _devCommandButtonArea.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)obj2).childAlignment = (TextAnchor)1; ((HorizontalOrVerticalLayoutGroup)obj2).spacing = 6f; ((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 0); ((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = false; ((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = false; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false; } private void CreateDevCommandButton(string text, string command) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown ((UnityEvent)GUIManager.Instance.CreateButton(text, _devCommandButtonArea.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), Vector2.zero, 180f, 28f).GetComponent<Button>().onClick).AddListener((UnityAction)delegate { RunConsoleCommand(command); }); } private void CreateSpawnPanel() { //IL_001b: 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) //IL_0039: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Expected O, but got Unknown _spawnPanel = GUIManager.Instance.CreateWoodpanel(_mainPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -535f), 330f, 175f, false); GUIManager.Instance.CreateText("Spawn", _spawnPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -25f), GUIManager.Instance.AveriaSerifBold, 16, GUIManager.Instance.ValheimOrange, true, Color.black, 200f, 25f, false); Text component = GUIManager.Instance.CreateText("Tab Key: Select/Cycle Prefabs\r\nEnter Key: Spawn", _spawnPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -48f), GUIManager.Instance.AveriaSerif, 11, Color.white, true, Color.black, 280f, 40f, false).GetComponent<Text>(); component.alignment = (TextAnchor)1; ((Graphic)component).raycastTarget = false; GameObject val = GUIManager.Instance.CreateInputField(_spawnPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(-45f, -82f), (ContentType)0, "prefabName arg1 arg2", 14, 200f, 30f); _spawnInputField = val.GetComponent<InputField>(); ((UnityEvent<string>)(object)_spawnInputField.onEndEdit).AddListener((UnityAction<string>)delegate { if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271)) { ExecuteSpawn(); } }); GameObject obj = GUIManager.Instance.CreateButton("Spawn", _spawnPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(105f, -82f), 80f, 30f); GameObject val2 = GUIManager.Instance.CreateText(string.Empty, _spawnPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -137f), GUIManager.Instance.AveriaSerif, 11, Color.white, true, Color.black, 300f, 60f, false); _spawnSuggestionsText = val2.GetComponent<Text>(); _spawnSuggestionsText.alignment = (TextAnchor)0; _spawnSuggestionsText.horizontalOverflow = (HorizontalWrapMode)0; _spawnSuggestionsText.verticalOverflow = (VerticalWrapMode)0; ((Graphic)_spawnSuggestionsText).raycastTarget = false; ((UnityEvent<string>)(object)_spawnInputField.onValueChanged).AddListener((UnityAction<string>)HandleSpawnInputChanged); ((UnityEvent)obj.GetComponent<Button>().onClick).AddListener(new UnityAction(ExecuteSpawn)); } private void HandleSpawnInputChanged(string value) { if (string.IsNullOrWhiteSpace(value)) { ResetSpawnAutocomplete(); return; } if (value.IndexOf(' ') >= 0) { _spawnPrefabSelected = true; ClearSpawnSuggestions(); return; } _spawnPrefabSelected = false; _spawnMatchIndex = -1; _spawnMatches = _prefabSearchService.FindMatches(value); UpdateSpawnSuggestions(); } private void CycleSpawnSuggestion(bool reverse) { if ((Object)(object)_spawnInputField == (Object)null || _spawnMatches == null || _spawnMatches.Count == 0) { return; } if (reverse) { _spawnMatchIndex--; if (_spawnMatchIndex < 0) { _spawnMatchIndex = _spawnMatches.Count - 1; } } else { _spawnMatchIndex++; if (_spawnMatchIndex >= _spawnMatches.Count) { _spawnMatchIndex = 0; } } string text = _spawnMatches[_spawnMatchIndex]; _spawnInputField.SetTextWithoutNotify(text); int length = text.Length; _spawnInputField.caretPosition = length; _spawnInputField.selectionAnchorPosition = length; _spawnInputField.selectionFocusPosition = length; _spawnInputField.ActivateInputField(); UpdateSpawnSuggestions(); } private void UpdateSpawnSuggestions() { if ((Object)(object)_spawnSuggestionsText == (Object)null) { return; } if (_spawnMatches == null || _spawnMatches.Count == 0) { _spawnSuggestionsText.text = string.Empty; return; } List<string> list = new List<string>(); for (int i = 0; i < _spawnMatches.Count; i++) { string text = _spawnMatches[i]; if (i == _spawnMatchIndex) { list.Add("> " + text + " <"); } else { list.Add(text); } } _spawnSuggestionsText.text = string.Join(" ", list); } private void ResetSpawnAutocomplete() { _spawnMatches.Clear(); _spawnMatchIndex = -1; _spawnPrefabSelected = false; ClearSpawnSuggestions(); } private void ClearSpawnSuggestions() { if ((Object)(object)_spawnSuggestionsText != (Object)null) { _spawnSuggestionsText.text = string.Empty; } } private void CreateCloseButton() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002e: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown ((UnityEvent)GUIManager.Instance.CreateButton("Close", _mainPanel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 35f), 140f, 30f).GetComponent<Button>().onClick).AddListener((UnityAction)delegate { SetPanelVisible(visible: false); }); } private void ResetDevCommandUiState() { bool flag = AreDevCommandsEnabled(); bool flag2 = (Object)(object)Player.m_localPlayer != (Object)null && Player.m_debugMode; _devCommandsEnabled = flag && flag2; if ((Object)(object)_enableDevCommandsButton != (Object)null) { ((Selectable)_enableDevCommandsButton).interactable = _devCommandsCoroutine == null; Text componentInChildren = ((Component)_enableDevCommandsButton).GetComponentInChildren<Text>(); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.text = (_devCommandsEnabled ? "Disable Devcommands" : "Enable Devcommands"); } } if ((Object)(object)_devCommandPanel != (Object)null) { _devCommandPanel.SetActive(_devCommandsEnabled); } if ((Object)(object)_spawnPanel != (Object)null) { _spawnPanel.SetActive(_devCommandsEnabled); } } private void SetPanelVisible(bool visible) { _uiVisible = visible; if (visible) { ResetDevCommandUiState(); } if ((Object)(object)_uiRoot != (Object)null) { _uiRoot.SetActive(visible); GUIManager.BlockInput(visible); } if (!visible) { ResetSpawnAutocomplete(); if ((Object)(object)_spawnInputField != (Object)null) { _spawnInputField.SetTextWithoutNotify(string.Empty); } } } private void ExecuteSpawn() { if (!((Object)(object)_spawnInputField == (Object)null)) { if (string.IsNullOrWhiteSpace(_spawnInputField.text)) { ShowHudMessage("Enter a prefab name and optional spawn arguments."); return; } ExecuteSpawnInput(_spawnInputField); _spawnInputField.SetTextWithoutNotify(string.Empty); ResetSpawnAutocomplete(); ((MonoBehaviour)this).StartCoroutine(RefocusSpawnInput()); } } private static void ExecuteSpawnInput(InputField spawnInput) { if ((Object)(object)spawnInput == (Object)null) { return; } string text = spawnInput.text; if (string.IsNullOrEmpty(text)) { ShowHudMessage("Enter a prefab name and optional spawn arguments."); return; } text = text.Trim(); if (string.IsNullOrEmpty(text)) { ShowHudMessage("Enter a prefab name and optional spawn arguments."); } else { RunConsoleCommand("spawn " + text); } } private static void ShowHudMessage(string message) { if (!((Object)(object)Player.m_localPlayer == (Object)null)) { ((Character)Player.m_localPlayer).Message((MessageType)1, message, 0, (Sprite)null, false); } } private static void RunConsoleCommand(string command) { if (!((Object)(object)Console.instance == (Object)null)) { ((Terminal)Console.instance).TryRunCommand(command, false, false); } } private IEnumerator RefocusSpawnInput() { yield return null; if ((Object)(object)_spawnInputField != (Object)null && _uiVisible && ((Component)_spawnInputField).gameObject.activeInHierarchy) { _spawnInputField.ActivateInputField(); ((Selectable)_spawnInputField).Select(); } } private static bool AreDevCommandsEnabled() { if (CheatEnabledField == null) { return false; } object value = CheatEnabledField.GetValue(null); if (value is bool) { return (bool)value; } return false; } } internal class PrefabSearchService { private readonly List<string> _prefabNames = new List<string>(); internal void CachePrefabNames() { _prefabNames.Clear(); if ((Object)(object)ZNetScene.instance == (Object)null) { return; } foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if (!((Object)(object)prefab == (Object)null) && !string.IsNullOrWhiteSpace(((Object)prefab).name)) { _prefabNames.Add(((Object)prefab).name); } } List<string> collection = _prefabNames.Distinct<string>(StringComparer.OrdinalIgnoreCase).OrderBy<string, string>((string name) => name, StringComparer.OrdinalIgnoreCase).ToList(); _prefabNames.Clear(); _prefabNames.AddRange(collection); Logger.LogInfo((object)$"Cached {_prefabNames.Count} prefab names."); } internal List<string> FindMatches(string input, int maxResults = 10) { string searchText = GetPrefabSearchText(input); if (string.IsNullOrWhiteSpace(searchText)) { return new List<string>(); } return _prefabNames.Where((string name) => name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0).Take(maxResults).ToList(); } internal static string GetPrefabSearchText(string input) { if (string.IsNullOrWhiteSpace(input)) { return string.Empty; } string text = input.TrimStart(Array.Empty<char>()); int num = text.IndexOf(' '); if (num < 0) { return text; } return text.Substring(0, num); } internal static string ReplacePrefabName(string input, string prefabName) { if (string.IsNullOrWhiteSpace(prefabName)) { return input; } if (string.IsNullOrWhiteSpace(input)) { return prefabName; } string text = input.TrimStart(Array.Empty<char>()); int num = text.IndexOf(' '); if (num < 0) { return prefabName; } string text2 = text.Substring(num); return prefabName + text2; } }