Decompiled source of ConsoleStdinHeeler v1.4.1

ConsoleStdinHeeler.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ConsoleStdinHeeler.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("DreamWraith (https://github.com/dreamwraith)")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) 2026 DreamWraith")]
[assembly: AssemblyDescription("Non-blocking STDIN console input and native server management commands for Valheim dedicated servers.")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyInformationalVersion("1.4.1+044ce0cb36d1e3d7ca0fe90152d2ac52f7db4146")]
[assembly: AssemblyProduct("ConsoleStdinHeeler")]
[assembly: AssemblyTitle("ConsoleStdinHeeler")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/dreamwraith/Valheim-ConsoleStdinHeeler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 ConsoleStdinHeeler
{
	public static class CommandFilter
	{
		private static readonly HashSet<string> ClientAndPlayerCommands = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
		{
			"blowkiss", "bow", "challenge", "cheer", "comehere", "cower", "cry", "dance", "despair", "flex",
			"headbang", "kneel", "laugh", "loveyou", "nonono", "point", "relax", "rest", "roar", "shrug",
			"sit", "thumbsup", "toast", "vibe", "wave", "god", "ghost", "fly", "nocost", "die",
			"puke", "heal", "pos", "goto", "beard", "hair", "model", "raiseskill", "resetskill", "freefly",
			"ffsmooth", "tame", "killall", "killenemies", "killenemycreatures", "killtame", "exploremap", "resetmap", "resetsharedmap", "tombstone",
			"itemset", "catch", "resetcharacter", "resetknownitems", "tutorialreset", "clearstatus", "addstatus", "setpower", "repairall", "sortcraft",
			"filtercraft", "inventoryclean", "inventorysize", "nomap", "resetspawn", "s", "w", "whisper", "msg", "tell",
			"debugmode", "dpsdebug", "adrenaline", "aggravate", "achievements", "getstat", "stats", "setkeyplayer", "removekeyplayer", "yesiuseddevcommandsbutiwantmyachievementsanyway",
			"biomeinfo", "haslocation", "printlocations", "printnetobj", "printcreatures", "recall", "vegetation", "height", "forcedelete", "snow",
			"location", "find", "findbiome", "findbiometp", "findtp", "fixhalfdegrotpieces", "stopfire", "stopsmoke", "setfuel", "printseeds",
			"noportals", "removedrops", "removebirds", "removefish", "nextseed", "setworldmodifier", "setworldpreset", "clear", "clearpopups", "fov",
			"lodbias", "maxfps", "cr", "unlockcinematics", "cinematic", "cinematicsleep", "xb:version", "resetbuildui", "resetplayerprefs", "bind",
			"unbind", "printbinds", "resetbinds", "exclusivefullscreen", "hidebetatext", "devcommands", "confirmcheats", "test", "env", "wind",
			"resetenv", "resetwind"
		};

		private static readonly HashSet<string> BuiltInServerCommands = InitializeBuiltInCommands();

		public static bool IsServerIncompatible(string commandName, ConsoleCommand? commandInstance = null)
		{
			if (!ClientAndPlayerCommands.Contains(commandName))
			{
				if (commandInstance == null)
				{
					return false;
				}
				return commandInstance.Description?.StartsWith("emote:", StringComparison.OrdinalIgnoreCase) == true;
			}
			return true;
		}

		public static bool IsBuiltInServerCommand(string commandName)
		{
			return BuiltInServerCommands.Contains(commandName);
		}

		private static HashSet<string> InitializeBuiltInCommands()
		{
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "help", "broadcast", "alert", "teleport" };
			(string, string)[] dedicatedCommands = CommandCustom.DedicatedCommands;
			for (int i = 0; i < dedicatedCommands.Length; i++)
			{
				string[] array = dedicatedCommands[i].Item1.Split('[', '<')[0].Split(new char[1] { '/' });
				for (int j = 0; j < array.Length; j++)
				{
					string text = array[j].Trim();
					if (!string.IsNullOrEmpty(text))
					{
						hashSet.Add(text);
					}
				}
			}
			return hashSet;
		}
	}
	public static class CommandServer
	{
		private static readonly Regex CoordinateRegex = new Regex("^-?\\d+(?:\\.\\d+)?,-?\\d+(?:\\.\\d+)?(?:,-?\\d+(?:\\.\\d+)?)?$", RegexOptions.Compiled);

		public static void Execute(string rawCommandLine)
		{
			if (string.IsNullOrWhiteSpace(rawCommandLine))
			{
				return;
			}
			try
			{
				string value = ModConfig.ConsolePrompt.Value;
				Plugin.Log.LogInfo(TerminalColor.Gray + value + TerminalColor.Cyan + rawCommandLine + TerminalColor.Reset);
				string text = rawCommandLine.Trim();
				int num = text.IndexOf(' ');
				string text2 = ((num < 0) ? text : text.Substring(0, num)).ToLowerInvariant();
				string text3 = ((num < 0) ? string.Empty : text.Substring(num + 1).Trim());
				if (string.IsNullOrEmpty(text2))
				{
					return;
				}
				if (CommandFilter.IsServerIncompatible(text2))
				{
					Plugin.Log.LogWarning("Command '" + text2 + "' requires an active game client or in-game player character and cannot be run from a dedicated server console.");
					return;
				}
				switch (text2)
				{
				case "save":
					CommandCustom.HandleSaveCommand();
					break;
				case "stop":
				case "exit":
				case "quit":
				case "shutdown":
					CommandCustom.HandleShutdownCommand(text3);
					break;
				case "kickall":
					CommandCustom.HandleKickAllCommand(text3);
					break;
				case "teleport":
				case "tp":
					CommandCustom.HandleTeleportCommand(text3);
					break;
				case "list":
				case "players":
					CommandCustom.HandlePlayersCommand();
					break;
				case "findloc":
				case "findlocation":
					CommandCustom.HandleFindLocationCommand(text3);
					break;
				case "say":
					CommandCustom.HandleSayCommand(text3);
					break;
				case "announce":
				case "broadcast":
				case "alert":
					CommandCustom.HandleAnnounceCommand(text3);
					break;
				case "tod":
					CommandOverrides.HandleTodCommand(text3);
					break;
				case "event":
					CommandOverrides.HandleEventCommand(text3);
					break;
				case "stopevent":
					CommandOverrides.HandleStopEventCommand();
					break;
				case "sleep":
					CommandOverrides.HandleSleepCommand();
					break;
				case "spawn":
					CommandOverrides.HandleSpawnCommand(text3);
					break;
				case "help":
					CommandCustom.HandleHelpCommand(text3);
					break;
				default:
					ExecuteTerminalCommand(rawCommandLine);
					break;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError("Error executing STDIN command '" + rawCommandLine + "': " + ex.Message);
				Plugin.Log.LogDebug(ex.ToString());
			}
		}

		public static void ExecuteTerminalCommand(string commandLine)
		{
			if (!Object.op_Implicit((Object)(object)Console.instance))
			{
				Plugin.Log.LogWarning("Valheim Console/Terminal instance is not available yet.");
				return;
			}
			bool cheat = Terminal.m_cheat;
			try
			{
				if (ModConfig.EnableCheatsByDefault.Value)
				{
					Terminal.m_cheat = true;
				}
				((Terminal)Console.instance).TryRunCommand(commandLine, false, true);
			}
			finally
			{
				Terminal.m_cheat = cheat;
			}
		}

		public static ZNetPeer? FindPeer(string playerIdentifier)
		{
			if (string.IsNullOrWhiteSpace(playerIdentifier) || !Object.op_Implicit((Object)(object)ZNet.instance))
			{
				return null;
			}
			string cleanId = playerIdentifier.Trim();
			if (string.IsNullOrEmpty(cleanId))
			{
				return null;
			}
			List<ZNetPeer> connectedPeers = ZNet.instance.GetConnectedPeers();
			if (connectedPeers.Count == 0)
			{
				return null;
			}
			if (string.Equals(cleanId, "@random", StringComparison.OrdinalIgnoreCase))
			{
				int index = Random.Range(0, connectedPeers.Count);
				return connectedPeers[index];
			}
			return connectedPeers.Find(delegate(ZNetPeer peer)
			{
				if (string.Equals(peer.m_playerName, cleanId, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
				if (peer.m_uid.ToString() == cleanId)
				{
					return true;
				}
				if (!string.IsNullOrEmpty(peer.m_playfabId) && string.Equals(peer.m_playfabId, cleanId, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
				if (peer.m_playerID.ToString() == cleanId || ((ZDOID)(ref peer.m_characterID)).UserID.ToString() == cleanId)
				{
					return true;
				}
				string hostName = peer.m_socket.GetHostName();
				return (string.Equals(hostName, cleanId, StringComparison.OrdinalIgnoreCase) || string.Equals(hostName, "Steam_" + cleanId, StringComparison.OrdinalIgnoreCase)) ? true : false;
			});
		}

		public static bool TryResolvePeer(string playerIdentifier, out ZNetPeer peer, string roleDescription = "Player")
		{
			peer = null;
			if (string.IsNullOrWhiteSpace(playerIdentifier))
			{
				return false;
			}
			if (!Object.op_Implicit((Object)(object)ZNet.instance))
			{
				Plugin.Log.LogWarning("Cannot find player: Server world is not loaded.");
				return false;
			}
			if (ZNet.instance.GetConnectedPeers().Count == 0)
			{
				Plugin.Log.LogWarning("Cannot find player: No players are currently connected to the server.");
				return false;
			}
			ZNetPeer val = FindPeer(playerIdentifier);
			if (val == null)
			{
				Plugin.Log.LogWarning(roleDescription + " '" + playerIdentifier.Trim() + "' not found among connected peers.");
				return false;
			}
			peer = val;
			return true;
		}

		public static bool TryParseCoordinates(string text, out Vector3 coordinates)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_00e0: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			coordinates = Vector3.zero;
			if (string.IsNullOrWhiteSpace(text) || !CoordinateRegex.IsMatch(text))
			{
				return false;
			}
			string[] array = text.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length == 3 && float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
			{
				coordinates = new Vector3(result, result2, result3);
				return true;
			}
			if (array.Length == 2 && float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result4) && float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result5))
			{
				float num = (Object.op_Implicit((Object)(object)ZoneSystem.instance) ? (ZoneSystem.instance.GetSolidHeight(new Vector3(result4, 0f, result5)) + 0.5f) : 30f);
				coordinates = new Vector3(result4, num, result5);
				return true;
			}
			return false;
		}

		public static bool TryResolveTarget(string targetToken, out CommandTarget target)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			target = default(CommandTarget);
			if (string.IsNullOrWhiteSpace(targetToken))
			{
				return false;
			}
			if (TryParseCoordinates(targetToken, out var coordinates))
			{
				target = new CommandTarget(coordinates, Vector3.forward, null, null, $"coordinates ({coordinates.x:F1}, {coordinates.y:F1}, {coordinates.z:F1})", isCoordinates: true);
				return true;
			}
			if (!TryResolvePeer(targetToken, out ZNetPeer peer, "Target player or coordinates"))
			{
				return false;
			}
			Player val = Player.GetAllPlayers().Find((Player candidate) => Object.op_Implicit((Object)(object)candidate) && (string.Equals(candidate.GetPlayerName(), peer.m_playerName, StringComparison.OrdinalIgnoreCase) || candidate.GetPlayerID() == peer.m_playerID));
			Vector3 val2;
			Vector3 forward;
			string description;
			if (Object.op_Implicit((Object)(object)val))
			{
				val2 = ((Component)val).transform.position;
				forward = ((Component)val).transform.forward;
				description = $"player '{TerminalColor.Cyan}{val.GetPlayerName()}{TerminalColor.Reset}' at {val2}";
			}
			else
			{
				val2 = peer.m_refPos;
				forward = Vector3.forward;
				description = $"player '{TerminalColor.Cyan}{peer.m_playerName}{TerminalColor.Reset}' at {val2}";
			}
			target = new CommandTarget(val2, forward, peer, val, description, isCoordinates: false);
			return true;
		}
	}
	public readonly struct CommandTarget
	{
		public Vector3 Position { get; }

		public Vector3 Forward { get; }

		public ZNetPeer? Peer { get; }

		public Player? Player { get; }

		public string Description { get; }

		public bool IsCoordinates { get; }

		public CommandTarget(Vector3 position, Vector3 forward, ZNetPeer? peer, Player? player, string description, bool isCoordinates)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			Position = position;
			Forward = forward;
			Peer = peer;
			Player = player;
			Description = description;
			IsCoordinates = isCoordinates;
		}
	}
	public static class CommandCustom
	{
		internal static readonly (string Syntax, string Description)[] DedicatedCommands = new(string, string)[39]
		{
			("save", "Force save world and player profile data"),
			("stop / shutdown / exit / quit [min] [msg]", "Stop server (optional countdown, e.g. 'stop 5 Reboot')"),
			("stop cancel", "Cancel an active shutdown countdown"),
			("players / list", "List connected players, Steam or platform IDs, last ping time, and player IDs"),
			("kick <ID/name>", "Kick a single player. Names must be one word, use the ID from players otherwise"),
			("kickall [seconds] [reason]", "Save world and kick all connected players (default: 3s grace delay)"),
			("ban <ID/name>", "Ban a player. Names must be one word, use the ID from players otherwise"),
			("unban <ID>", "Remove an entry from the ban list. Use the exact value shown by banned"),
			("banned", "List all currently banned players"),
			("say <@all/*|player> <msg>", "Display top-left notification to all clients or a specific player"),
			("announce / broadcast / alert [-t sec] <@all/*|player> <msg>", "Display prominent center banner (optional -t duration up to 60s)"),
			("announce cancel", "Cancel any active persistent announcement"),
			("tp / teleport <player> <target/x,y,z>", "Teleport a player to another player or coordinates"),
			("findlocation / findloc <location> <target/x,y,z/spawn>", "Print coordinates of the closest location to a player, coordinates, or world spawn"),
			("time", "Display current world time, day count, and sleep status"),
			("tod <0-1>", "Set time of day for all connected clients (e.g. tod 0.5)"),
			("skiptime [gameseconds]", "Skip ahead in seconds (default: 240)"),
			("sleep", "Fast-forward time to next morning"),
			("timescale <scale> [fadetime]", "Set game simulation speed, up to 5. Optional fade in seconds"),
			("event <name> <target/x,y,z>", "Start a raid/event near a player or coordinates (e.g. event army_eikthyr Thor)"),
			("stopevent", "Stop any currently active raid/event"),
			("randomevent", "Start a random raid/event near a player"),
			("pevents [list/start/stop/here]", "Manage player events and raids (subcommands: list, start, stop, here)"),
			("spawn <prefab> <target/x,y,z> [amt] [lvl] [-s]", "Spawn near a player or coordinates (e.g. spawn Boar Thor 3 2 -s)"),
			("listkeys", "List active world progress keys, modifiers, and presets"),
			("setkey <name>", "Set a global world progress key (e.g. boss keys)"),
			("removekey <name>", "Remove an active global world progress key"),
			("resetkeys", "Reset all global world progress keys"),
			("resetworldkeys", "Reset all world modifiers to default settings"),
			("optterrain", "Optimize older terrain modifications across loaded sectors"),
			("genloc", "Regenerate missing world locations"),
			("updatecover", "Force refresh of shelter and roof cover calculations"),
			("nospawn", "Toggle natural spawning of monsters on/off"),
			("respawntime <seconds>", "Set player respawn delay timer in seconds"),
			("restartparty", "Restart PlayFab Party network connection"),
			("altbioms", "List biomes with active modifiers"),
			("gc", "Run garbage collection and report freed memory"),
			("ping", "Send a test message from the server to itself. Does not measure player latency"),
			("info", "Print render threading mode and managed memory use")
		};

		private static Coroutine? _activeAnnouncementCoroutine;

		private const float MaxAnnouncementDuration = 60f;

		private const float AnnouncementPulseInterval = 1f;

		private static float _kickDisconnectTime = -1f;

		private static bool _isShutdownScheduled;

		private static float _shutdownTargetTime;

		private static string _shutdownReason = string.Empty;

		private static int _lastAnnouncedSecondsLeft = -1;

		private static readonly int[] ShutdownMilestones = new int[8] { 600, 300, 180, 120, 60, 30, 10, 5 };

		public static void HandleHelpCommand(string helpArguments)
		{
			if (helpArguments.Equals("all", StringComparison.OrdinalIgnoreCase) || helpArguments.Equals("-all", StringComparison.OrdinalIgnoreCase) || helpArguments.Equals("--all", StringComparison.OrdinalIgnoreCase))
			{
				Plugin.Log.LogInfo(TerminalColor.Bold + TerminalColor.Orange + "=== Complete Native Command Catalog (Unfiltered) ===" + TerminalColor.Reset);
				CommandServer.ExecuteTerminalCommand("help");
				return;
			}
			Plugin.Log.LogInfo(TerminalColor.Bold + TerminalColor.Orange + "=== Dedicated Server Commands ===" + TerminalColor.Reset);
			(string, string)[] dedicatedCommands = DedicatedCommands;
			for (int i = 0; i < dedicatedCommands.Length; i++)
			{
				var (syntax, text) = dedicatedCommands[i];
				Plugin.Log.LogInfo("  " + FormatCommandSyntax(syntax) + TerminalColor.Gray + "-" + TerminalColor.Reset + " " + text);
			}
			Dictionary<string, ConsoleCommand> registeredTerminalCommands = GetRegisteredTerminalCommands();
			if (registeredTerminalCommands.Count > 0)
			{
				List<KeyValuePair<string, ConsoleCommand>> list = new List<KeyValuePair<string, ConsoleCommand>>();
				foreach (KeyValuePair<string, ConsoleCommand> item in registeredTerminalCommands)
				{
					string key = item.Key;
					ConsoleCommand value = item.Value;
					if (!CommandFilter.IsBuiltInServerCommand(key) && !CommandFilter.IsServerIncompatible(key, value) && !value.IsSecret)
					{
						list.Add(item);
					}
				}
				if (list.Count > 0)
				{
					Plugin.Log.LogInfo(TerminalColor.Bold + TerminalColor.Orange + "=== Modded & Additional Available Commands ===" + TerminalColor.Reset);
					list.Sort((KeyValuePair<string, ConsoleCommand> first, KeyValuePair<string, ConsoleCommand> second) => string.Compare(first.Key, second.Key, StringComparison.OrdinalIgnoreCase));
					foreach (KeyValuePair<string, ConsoleCommand> item2 in list)
					{
						string text2 = (string.IsNullOrWhiteSpace(item2.Value.Description) ? "No description provided." : item2.Value.Description);
						Plugin.Log.LogInfo("  " + FormatCommandSyntax(item2.Key) + TerminalColor.Gray + "-" + TerminalColor.Reset + " " + text2);
					}
				}
			}
			Plugin.Log.LogInfo(TerminalColor.Gray + "Tip: Type 'help all' to display the complete, unfiltered native command catalog." + TerminalColor.Reset);
		}

		private static Dictionary<string, ConsoleCommand> GetRegisteredTerminalCommands()
		{
			return Terminal.commands;
		}

		private static string FormatCommandSyntax(string syntax, int padWidth = 28)
		{
			int num = syntax.IndexOf(' ');
			if (num < 0)
			{
				string text = ((syntax.Length < padWidth) ? syntax.PadRight(padWidth) : (syntax + " "));
				return TerminalColor.Yellow + text + TerminalColor.Reset;
			}
			string text2 = syntax.Substring(0, num);
			string text3 = syntax.Substring(num);
			string text4 = ((syntax.Length < padWidth) ? text3.PadRight(padWidth - text2.Length) : (text3 + " "));
			return TerminalColor.Yellow + text2 + TerminalColor.Cyan + text4 + TerminalColor.Reset;
		}

		public static void HandleFindLocationCommand(string arguments)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || !Object.op_Implicit((Object)(object)Game.instance) || !Object.op_Implicit((Object)(object)ZoneSystem.instance))
			{
				Plugin.Log.LogWarning("Cannot find location: Server world is still loading.");
				return;
			}
			List<string> list = TerminalUtils.ParseArguments(arguments.Trim());
			if (list.Count != 2)
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: findlocation <location> <player|\"player name\"|coords|spawn>");
				Plugin.Log.LogInfo("Coordinates must strictly follow 0,0 or 0,0,0 mask with no spaces.");
				return;
			}
			string text = list[0];
			string text2 = list[1];
			Vector3 position = default(Vector3);
			string text3;
			if (text2.Equals("spawn", StringComparison.OrdinalIgnoreCase))
			{
				if (!ZoneSystem.instance.GetLocationIcon(Game.instance.m_StartLocation, ref position))
				{
					Plugin.Log.LogWarning("World spawn location '" + Game.instance.m_StartLocation + "' not found.");
					return;
				}
				text3 = "world spawn";
			}
			else
			{
				if (!CommandServer.TryResolveTarget(text2, out var target))
				{
					return;
				}
				position = target.Position;
				text3 = target.Description;
			}
			LocationInstance val = default(LocationInstance);
			if (!ZoneSystem.instance.FindClosestLocation(text, position, ref val))
			{
				Plugin.Log.LogWarning("No '" + text + "' location found in this world. Location names are case-sensitive.");
				return;
			}
			Vector3 position2 = val.m_position;
			string text4 = FormattableString.Invariant($"{position2.x:F1},{position2.y:F1},{position2.z:F1}");
			Plugin.Log.LogInfo("Closest " + TerminalColor.Green + text + TerminalColor.Reset + " to " + text3 + ": " + TerminalColor.Cyan + text4 + TerminalColor.Reset);
		}

		public static void HandleSayCommand(string arguments)
		{
			ZNetPeer peer;
			if (!TryParseMessageTarget(arguments, out string targetPlayer, out string message))
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: say <@all|*|player|\"player name\"> <message>");
			}
			else if (ZRoutedRpc.instance == null)
			{
				Plugin.Log.LogWarning("Cannot send message: ZRoutedRpc is not ready.");
			}
			else if (targetPlayer == null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ShowMessage", new object[2] { 1, message });
				Plugin.Log.LogInfo("Sent top-left notification to all clients: " + TerminalColor.Cyan + "\"" + message + "\"" + TerminalColor.Reset);
			}
			else if (CommandServer.TryResolvePeer(targetPlayer, out peer, "Target player"))
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(peer.m_uid, "ShowMessage", new object[2] { 1, message });
				Plugin.Log.LogInfo("Sent top-left notification to '" + TerminalColor.Cyan + peer.m_playerName + TerminalColor.Reset + "': " + TerminalColor.Cyan + "\"" + message + "\"" + TerminalColor.Reset);
			}
		}

		public static void HandleAnnounceCommand(string arguments)
		{
			string text = arguments.Trim();
			if (text.Equals("cancel", StringComparison.OrdinalIgnoreCase) || text.Equals("abort", StringComparison.OrdinalIgnoreCase))
			{
				CancelActiveAnnouncement();
				return;
			}
			float result = 0f;
			if (text.StartsWith("-t ", StringComparison.OrdinalIgnoreCase) || text.Equals("-t", StringComparison.OrdinalIgnoreCase))
			{
				string[] array = text.Split(new char[1] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);
				if (array.Length < 3 || !float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result) || result <= 0f)
				{
					Plugin.Log.LogWarning("Invalid parameters. The -t flag requires a duration in seconds between 1 and 60 (e.g. -t 15 <target> <message>).");
					return;
				}
				result = Math.Min(result, 60f);
				text = array[2];
			}
			if (!TryParseMessageTarget(text, out string targetPlayer, out string message))
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: announce [-t seconds] <@all|*|player|\"player name\"> <message> OR announce cancel");
				return;
			}
			if (ZRoutedRpc.instance == null)
			{
				Plugin.Log.LogWarning("Cannot send message: ZRoutedRpc is not ready.");
				return;
			}
			long num = 0L;
			string text2 = "all clients";
			if (targetPlayer != null)
			{
				if (!CommandServer.TryResolvePeer(targetPlayer, out ZNetPeer peer, "Target player"))
				{
					return;
				}
				num = peer.m_uid;
				text2 = "'" + TerminalColor.Cyan + peer.m_playerName + TerminalColor.Reset + "'";
			}
			StopActiveAnnouncement();
			ZRoutedRpc.instance.InvokeRoutedRPC(num, "ShowMessage", new object[2] { 2, message });
			string text3 = ((result > 1f) ? $" ({result:F0}s duration)" : string.Empty);
			Plugin.Log.LogInfo("Sent center announcement banner to " + text2 + text3 + ": " + TerminalColor.Gold + "\"" + message + "\"" + TerminalColor.Reset);
			if (result > 1f && Object.op_Implicit((Object)(object)Plugin.Instance))
			{
				_activeAnnouncementCoroutine = ((MonoBehaviour)Plugin.Instance).StartCoroutine(PulseAnnouncementRoutine(num, message, result));
			}
		}

		private static void StopActiveAnnouncement()
		{
			if (_activeAnnouncementCoroutine != null)
			{
				if (Object.op_Implicit((Object)(object)Plugin.Instance))
				{
					((MonoBehaviour)Plugin.Instance).StopCoroutine(_activeAnnouncementCoroutine);
				}
				_activeAnnouncementCoroutine = null;
			}
		}

		private static void CancelActiveAnnouncement()
		{
			if (_activeAnnouncementCoroutine != null)
			{
				StopActiveAnnouncement();
				Plugin.Log.LogInfo(TerminalColor.Green + "Active persistent announcement canceled." + TerminalColor.Reset);
			}
			else
			{
				Plugin.Log.LogInfo("No persistent announcement is currently active.");
			}
		}

		private static IEnumerator PulseAnnouncementRoutine(long targetUid, string message, float duration)
		{
			float elapsed = 0f;
			WaitForSeconds waitPulse = new WaitForSeconds(1f);
			while (elapsed < duration)
			{
				yield return waitPulse;
				elapsed += 1f;
				if (ZRoutedRpc.instance == null || (targetUid != 0L && (!Object.op_Implicit((Object)(object)ZNet.instance) || ZNet.instance.GetPeer(targetUid) == null)))
				{
					yield break;
				}
				ZRoutedRpc.instance.InvokeRoutedRPC(targetUid, "ShowMessage", new object[2] { 2, message });
			}
			_activeAnnouncementCoroutine = null;
		}

		private static bool TryParseMessageTarget(string arguments, out string? targetPlayer, out string message)
		{
			targetPlayer = null;
			message = string.Empty;
			if (string.IsNullOrWhiteSpace(arguments))
			{
				return false;
			}
			string text = arguments.Trim();
			string text2;
			if (text.StartsWith("\""))
			{
				int num = text.IndexOf('"', 1);
				if (num < 0)
				{
					return false;
				}
				text2 = text.Substring(1, num - 1).Trim();
				message = text.Substring(num + 1).Trim();
			}
			else
			{
				int num2 = text.IndexOf(' ');
				if (num2 < 0)
				{
					return false;
				}
				text2 = text.Substring(0, num2).Trim();
				message = text.Substring(num2 + 1).Trim();
			}
			if (string.IsNullOrWhiteSpace(text2) || string.IsNullOrWhiteSpace(message))
			{
				return false;
			}
			if (string.Equals(text2, "@all", StringComparison.OrdinalIgnoreCase) || text2 == "*")
			{
				targetPlayer = null;
			}
			else
			{
				targetPlayer = text2;
			}
			return true;
		}

		public static void HandleTeleportCommand(string arguments)
		{
			//IL_00ff: 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)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ZNet.instance))
			{
				Plugin.Log.LogWarning("Cannot teleport: Server world is not loaded.");
				return;
			}
			if (string.IsNullOrWhiteSpace(arguments))
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: tp <player|\"player name\"> <target|\"target player\"|coords>");
				Plugin.Log.LogInfo("Coordinates must strictly follow 0,0 or 0,0,0 mask with no spaces.");
				return;
			}
			List<string> list = TerminalUtils.ParseArguments(arguments.Trim());
			if (list.Count != 2)
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: tp <player|\"player name\"> <target|\"target player\"|coords>");
				Plugin.Log.LogInfo("Coordinates must strictly follow 0,0 or 0,0,0 mask with no spaces.");
			}
			else
			{
				if (!CommandServer.TryResolvePeer(list[0], out ZNetPeer peer, "Source player") || !CommandServer.TryResolveTarget(list[1], out var target))
				{
					return;
				}
				if (!target.IsCoordinates && target.Peer == peer)
				{
					Plugin.Log.LogWarning("Source player and destination player cannot be the same.");
					return;
				}
				Vector3 val = (target.IsCoordinates ? target.Position : (target.Position + target.Forward * 1.5f + Vector3.up * 0.2f));
				string description = target.Description;
				if (ZRoutedRpc.instance != null)
				{
					ZRoutedRpc.instance.InvokeRoutedRPC(0L, peer.m_characterID, "RPC_TeleportTo", new object[3]
					{
						val,
						Quaternion.identity,
						true
					});
					ZRoutedRpc.instance.InvokeRoutedRPC(peer.m_uid, "ShowMessage", new object[2] { 2, "Teleported by administrator" });
				}
				peer.m_refPos = val;
				Plugin.Log.LogInfo("Teleported '" + TerminalColor.Cyan + peer.m_playerName + TerminalColor.Reset + "' to " + description + ".");
			}
		}

		public static void HandleKickAllCommand(string arguments)
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance))
			{
				Plugin.Log.LogWarning("Cannot kick players: Server is not running.");
				return;
			}
			List<ZNetPeer> connectedPeers = ZNet.instance.GetConnectedPeers();
			if (connectedPeers.Count == 0)
			{
				Plugin.Log.LogInfo("No players are currently connected.");
				return;
			}
			string[] array = arguments.Trim().Split(new char[1] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
			float num = 3f;
			string text = "Kicked by administrator";
			if (array.Length != 0 && float.TryParse(array[0], out var result))
			{
				num = Math.Max(0f, result);
				text = ((array.Length > 1) ? array[1] : text);
			}
			else if (!string.IsNullOrWhiteSpace(arguments))
			{
				text = arguments.Trim();
			}
			Plugin.Log.LogInfo($"Kicking {TerminalColor.Cyan}{connectedPeers.Count}{TerminalColor.Reset} connected player(s) in {num:G}s. Reason: {TerminalColor.Yellow}{text}{TerminalColor.Reset}");
			if (ZRoutedRpc.instance != null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ShowMessage", new object[2]
				{
					2,
					"Server: " + text
				});
			}
			Plugin.Log.LogInfo("Triggering world and player profile save prior to kicking all players...");
			ZNet.instance.Save(false, true, false);
			Plugin.Log.LogInfo(TerminalColor.Green + "World and player profile save triggered successfully." + TerminalColor.Reset);
			_kickDisconnectTime = Time.realtimeSinceStartup + num;
		}

		private static void UpdateKickAll()
		{
			if (!(_kickDisconnectTime >= 0f) || !(Time.realtimeSinceStartup >= _kickDisconnectTime))
			{
				return;
			}
			_kickDisconnectTime = -1f;
			if (!Object.op_Implicit((Object)(object)ZNet.instance))
			{
				return;
			}
			foreach (ZNetPeer item in new List<ZNetPeer>(ZNet.instance.GetConnectedPeers()))
			{
				try
				{
					item.m_rpc.Invoke("Kicked", Array.Empty<object>());
					ZNet.instance.Disconnect(item);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogDebug("Exception disconnecting peer " + item.m_playerName + ": " + ex.Message);
				}
			}
			Plugin.Log.LogInfo(TerminalColor.Green + "All connected players successfully disconnected." + TerminalColor.Reset);
		}

		public static void HandleSaveCommand()
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || !Object.op_Implicit((Object)(object)Game.instance) || !Object.op_Implicit((Object)(object)ZoneSystem.instance))
			{
				Plugin.Log.LogWarning("Cannot save: Server world is still loading. Please wait until startup completes.");
				return;
			}
			Plugin.Log.LogInfo("Triggering world and player profile save...");
			ZNet.instance.Save(false, true, false);
			Plugin.Log.LogInfo(TerminalColor.Green + "World and player profile save triggered successfully." + TerminalColor.Reset);
		}

		public static void HandleShutdownCommand(string arguments)
		{
			string text = arguments.Trim();
			if (text.Equals("cancel", StringComparison.OrdinalIgnoreCase) || text.Equals("abort", StringComparison.OrdinalIgnoreCase))
			{
				if (!_isShutdownScheduled)
				{
					Plugin.Log.LogInfo("No shutdown countdown is currently active.");
					return;
				}
				_isShutdownScheduled = false;
				_lastAnnouncedSecondsLeft = -1;
				if (ZRoutedRpc.instance != null)
				{
					ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ShowMessage", new object[2] { 2, "Server shutdown countdown canceled." });
				}
				Plugin.Log.LogInfo(TerminalColor.Green + "Server shutdown countdown successfully canceled." + TerminalColor.Reset);
				return;
			}
			if (string.IsNullOrEmpty(text))
			{
				ExecuteImmediateShutdown();
				return;
			}
			string[] array = text.Split(new char[1] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
			if (!float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || result <= 0f)
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: stop [minutes] [reason] OR stop cancel");
				return;
			}
			string arg = (_shutdownReason = ((array.Length > 1) ? array[1].Trim() : "Server maintenance"));
			_shutdownTargetTime = Time.realtimeSinceStartup + result * 60f;
			_isShutdownScheduled = true;
			_lastAnnouncedSecondsLeft = (int)(result * 60f);
			string text2 = $"Server shutting down in {result:F0} min! Reason: {arg}";
			if (ZRoutedRpc.instance != null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ShowMessage", new object[2] { 2, text2 });
			}
			Plugin.Log.LogInfo(TerminalColor.Orange + text2 + TerminalColor.Reset);
		}

		public static void HandlePlayersCommand()
		{
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || !Object.op_Implicit((Object)(object)Game.instance))
			{
				Plugin.Log.LogWarning("Cannot list players: Server world is still loading.");
				return;
			}
			List<ZNetPeer> connectedPeers = ZNet.instance.GetConnectedPeers();
			Plugin.Log.LogInfo($"{TerminalColor.Bold}{TerminalColor.Orange}=== Connected Players ({connectedPeers.Count}) ==={TerminalColor.Reset}");
			int num = 1;
			foreach (ZNetPeer item in connectedPeers)
			{
				string hostName = item.m_socket.GetHostName();
				string text = (string.IsNullOrEmpty(item.m_playerName) ? "<connecting>" : item.m_playerName);
				float timeSinceLastPing = item.m_rpc.GetTimeSinceLastPing();
				string text2 = ((timeSinceLastPing < 2f) ? TerminalColor.Green : ((!(timeSinceLastPing < 5f)) ? TerminalColor.Red : TerminalColor.Yellow));
				string text3 = text2;
				string text4 = $"{timeSinceLastPing * 1000f:F0}ms ago";
				Plugin.Log.LogInfo($"  [{num}] {TerminalColor.Cyan}{text}{TerminalColor.Reset} | Last ping: {text3}{text4}{TerminalColor.Reset} | Endpoint: {TerminalColor.Gray}{hostName}{TerminalColor.Reset} | ID: {TerminalColor.Gray}{item.m_characterID}{TerminalColor.Reset}");
				num++;
			}
		}

		internal static void Update()
		{
			UpdateShutdown();
			UpdateKickAll();
		}

		private static void UpdateShutdown()
		{
			if (!_isShutdownScheduled)
			{
				return;
			}
			float num = _shutdownTargetTime - Time.realtimeSinceStartup;
			if (num <= 0f)
			{
				_isShutdownScheduled = false;
				if (ZRoutedRpc.instance != null)
				{
					ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ShowMessage", new object[2] { 2, "Server shutting down NOW!" });
				}
				ExecuteImmediateShutdown();
				return;
			}
			int num2 = (int)num;
			int[] shutdownMilestones = ShutdownMilestones;
			foreach (int num3 in shutdownMilestones)
			{
				if (_lastAnnouncedSecondsLeft > num3 && num2 <= num3)
				{
					_lastAnnouncedSecondsLeft = num3;
					string text = ((num3 >= 60) ? $"{num3 / 60} minute(s)" : $"{num3} seconds");
					string text2 = "Server shutting down in " + text + "! (" + _shutdownReason + ")";
					if (ZRoutedRpc.instance != null)
					{
						ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ShowMessage", new object[2] { 2, text2 });
					}
					Plugin.Log.LogInfo(TerminalColor.Orange + text2 + TerminalColor.Reset);
					break;
				}
			}
		}

		private static void ExecuteImmediateShutdown()
		{
			Plugin.Log.LogInfo("Initiating graceful server shutdown via Application.Quit()...");
			StdinListener.Stop();
			Application.Quit();
		}
	}
	public static class CommandOverrides
	{
		public static void HandleEventCommand(string arguments)
		{
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)RandEventSystem.instance) || !Object.op_Implicit((Object)(object)ZNet.instance))
			{
				Plugin.Log.LogWarning("Cannot trigger event: RandEventSystem is not ready or world is still loading.");
				return;
			}
			if (string.IsNullOrWhiteSpace(arguments))
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: event <event_name> <player|\"player name\"|coords>");
				Plugin.Log.LogInfo("Coordinates must strictly follow 0,0 or 0,0,0 mask with no spaces.");
				ListAvailableEvents();
				return;
			}
			List<string> list = TerminalUtils.ParseArguments(arguments.Trim());
			if (list.Count != 2)
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: event <event_name> <player|\"player name\"|coords>");
				Plugin.Log.LogInfo("Coordinates must strictly follow 0,0 or 0,0,0 mask with no spaces.");
				ListAvailableEvents();
				return;
			}
			string text = list[0];
			RandomEvent val = null;
			if (RandEventSystem.instance.m_events != null)
			{
				foreach (RandomEvent @event in RandEventSystem.instance.m_events)
				{
					if (@event != null && @event.m_enabled && string.Equals(@event.m_name, text, StringComparison.OrdinalIgnoreCase))
					{
						val = @event;
						break;
					}
				}
			}
			CommandTarget target;
			if (val == null)
			{
				Plugin.Log.LogWarning("Random event '" + text + "' not found or is disabled.");
				ListAvailableEvents();
			}
			else if (CommandServer.TryResolveTarget(list[1], out target))
			{
				RandEventSystem.instance.SetRandomEvent(val, target.Position);
				Plugin.Log.LogInfo("Triggered event '" + TerminalColor.Yellow + val.m_name + TerminalColor.Reset + "' at " + target.Description + ".");
			}
		}

		public static void HandleStopEventCommand()
		{
			if (!Object.op_Implicit((Object)(object)RandEventSystem.instance))
			{
				Plugin.Log.LogWarning("Cannot stop event: RandEventSystem is not ready.");
				return;
			}
			RandomEvent currentRandomEvent = RandEventSystem.instance.GetCurrentRandomEvent();
			if (currentRandomEvent == null)
			{
				Plugin.Log.LogInfo("No random event/raid is currently active.");
				return;
			}
			string name = currentRandomEvent.m_name;
			RandEventSystem.instance.ResetRandomEvent();
			Plugin.Log.LogInfo("Stopped active random event: '" + TerminalColor.Yellow + name + TerminalColor.Reset + "'.");
		}

		private static void ListAvailableEvents()
		{
			if (!Object.op_Implicit((Object)(object)RandEventSystem.instance) || RandEventSystem.instance.m_events == null)
			{
				return;
			}
			List<string> list = new List<string>();
			foreach (RandomEvent @event in RandEventSystem.instance.m_events)
			{
				if (@event != null && @event.m_enabled)
				{
					list.Add(@event.m_name);
				}
			}
			list.Sort(StringComparer.OrdinalIgnoreCase);
			Plugin.Log.LogInfo("Available events: " + TerminalColor.Yellow + string.Join(TerminalColor.Reset + ", " + TerminalColor.Yellow, list) + TerminalColor.Reset);
		}

		public static void HandleSpawnCommand(string arguments)
		{
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ZNetScene.instance) || !Object.op_Implicit((Object)(object)ZNet.instance))
			{
				Plugin.Log.LogWarning("Cannot spawn: ZNetScene or server world is not loaded.");
				return;
			}
			if (string.IsNullOrWhiteSpace(arguments))
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: spawn <prefab> <player|\"player name\"|coords> [count] [stars/rank] [-s]");
				Plugin.Log.LogInfo("Coordinates must strictly follow 0,0 or 0,0,0 mask with no spaces.");
				return;
			}
			List<string> list = TerminalUtils.ParseArguments(arguments.Trim());
			bool flag = false;
			if (list.Count > 0 && list[list.Count - 1].Equals("-s", StringComparison.OrdinalIgnoreCase))
			{
				flag = true;
				list.RemoveAt(list.Count - 1);
			}
			if (list.Count < 2 || list.Count > 4 || list.Exists((string part) => part.Equals("-s", StringComparison.OrdinalIgnoreCase)))
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: spawn <prefab> <player|\"player name\"|coords> [count] [stars/rank] [-s]");
				Plugin.Log.LogInfo("Coordinates must strictly follow 0,0 or 0,0,0 mask with no spaces.");
				return;
			}
			string text = list[0];
			string targetToken = list[1];
			int num = 1;
			int num2 = 1;
			if (list.Count > 2)
			{
				if (!int.TryParse(list[2], out var result) || result < 1)
				{
					Plugin.Log.LogWarning("Invalid count '" + list[2] + "'. Count must be a positive integer.");
					return;
				}
				num = Math.Min(1000, result);
			}
			if (list.Count > 3)
			{
				if (!int.TryParse(list[3], out var result2) || result2 < 1)
				{
					Plugin.Log.LogWarning("Invalid level '" + list[3] + "'. Level must be a positive integer.");
					return;
				}
				num2 = Math.Min(10, result2);
			}
			GameObject prefab = ZNetScene.instance.GetPrefab(text);
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				List<string> prefabNames = ZNetScene.instance.GetPrefabNames();
				List<string> list2 = new List<string>(8);
				foreach (string item in prefabNames)
				{
					if (string.Equals(item, text, StringComparison.OrdinalIgnoreCase))
					{
						prefab = ZNetScene.instance.GetPrefab(item);
						break;
					}
					if (list2.Count < 8 && item.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
					{
						list2.Add(item);
					}
				}
				if (!Object.op_Implicit((Object)(object)prefab))
				{
					Plugin.Log.LogWarning("Prefab '" + text + "' not found in ZNetScene.");
					if (list2.Count > 0)
					{
						Plugin.Log.LogInfo("Matching prefabs: " + TerminalColor.Yellow + string.Join(TerminalColor.Reset + ", " + TerminalColor.Yellow, list2) + TerminalColor.Reset);
					}
					return;
				}
			}
			if (!CommandServer.TryResolveTarget(targetToken, out var target))
			{
				return;
			}
			Vector3 position = target.Position;
			Vector3 forward = target.Forward;
			string description = target.Description;
			ItemDrop component = prefab.GetComponent<ItemDrop>();
			int val = ((!Object.op_Implicit((Object)(object)component) || component.m_itemData?.m_shared == null) ? 1 : Math.Max(1, component.m_itemData.m_shared.m_maxStackSize));
			int num3 = num;
			int num4 = 0;
			while (num3 > 0)
			{
				int num5 = Math.Min(num3, val);
				num3 -= num5;
				Vector3 val2 = ((num4 == 0) ? Vector3.zero : (Random.insideUnitSphere * Mathf.Min(8f, 0.5f + (float)num4 * 0.3f)));
				val2.y = Mathf.Abs(val2.y) * 0.2f;
				Vector3 val3 = (target.IsCoordinates ? (position + Vector3.up * 0.5f + val2) : (position + forward * 2f + Vector3.up * 0.5f + val2));
				GameObject val4 = Object.Instantiate<GameObject>(prefab, val3, Quaternion.identity);
				num4++;
				ItemDrop component2 = val4.GetComponent<ItemDrop>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					ItemDrop.OnCreateNew(val4, true);
					if (component2.m_itemData != null)
					{
						component2.m_itemData.m_durability = component2.m_itemData.GetMaxDurability();
						component2.m_itemData.m_stack = num5;
						if (num2 > 1)
						{
							component2.SetQuality(Mathf.Min(num2, 4));
						}
					}
				}
				Character component3 = val4.GetComponent<Character>();
				if (Object.op_Implicit((Object)(object)component3) && num2 > 1)
				{
					component3.SetLevel(num2);
				}
				ZNetView component4 = val4.GetComponent<ZNetView>();
				if (Object.op_Implicit((Object)(object)component4) && component4.IsValid())
				{
					component4.GetZDO().Set(ZDOVars.s_cheated, true);
				}
			}
			if (!flag)
			{
				if (Object.op_Implicit((Object)(object)target.Player))
				{
					((Character)target.Player).Message((MessageType)1, "Spawning object " + ((Object)prefab).name + ((num > 1) ? $" x{num}" : ""), 0, (Sprite)null, false);
				}
				else if (target.Peer != null && ZRoutedRpc.instance != null)
				{
					ZRoutedRpc.instance.InvokeRoutedRPC(target.Peer.m_uid, "ShowMessage", new object[2]
					{
						1,
						"Spawning object " + ((Object)prefab).name + ((num > 1) ? $" x{num}" : "")
					});
				}
			}
			string text2 = ((num2 > 1) ? $" (Level {num2})" : string.Empty);
			string text3 = (flag ? (" " + TerminalColor.Gray + "(silent)" + TerminalColor.Reset) : string.Empty);
			Plugin.Log.LogInfo($"Spawned {TerminalColor.Green}{((Object)prefab).name}{text2} x{num}{TerminalColor.Reset} at {description}{text3}.");
		}

		public static void HandleTodCommand(string arguments)
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance))
			{
				Plugin.Log.LogWarning("Cannot set time of day: Server world is not loaded.");
				return;
			}
			if (string.IsNullOrWhiteSpace(arguments) || !float.TryParse(arguments.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || result < 0f || result > 1f)
			{
				Plugin.Log.LogWarning("Invalid parameters. Usage: tod <0-1> (e.g. tod 0.5 for noon)");
				return;
			}
			double timeSeconds = ZNet.instance.GetTimeSeconds();
			long num = ((Object.op_Implicit((Object)(object)EnvMan.instance) && EnvMan.instance.m_dayLengthSec > 0) ? EnvMan.instance.m_dayLengthSec : 1800);
			long num2 = (long)(timeSeconds / (double)num);
			float num3 = Mathf.Clamp01(result);
			double num4 = (float)(num2 * num) + num3 * (float)num;
			if (num4 < timeSeconds)
			{
				num4 += (double)num;
			}
			if (Object.op_Implicit((Object)(object)EnvMan.instance))
			{
				EnvMan.instance.m_debugTimeOfDay = false;
			}
			ZNet.instance.SetNetTime(num4);
			SynchronizeNetworkTime();
			Plugin.Log.LogInfo($"Setting time of day: {TerminalColor.Cyan}{result:G}{TerminalColor.Reset}");
		}

		public static void HandleSleepCommand()
		{
			if (!Object.op_Implicit((Object)(object)EnvMan.instance) || !Object.op_Implicit((Object)(object)ZNet.instance))
			{
				Plugin.Log.LogWarning("Cannot skip time to morning: EnvMan/ZNet is not ready.");
				return;
			}
			EnvMan.instance.SkipToMorning();
			SynchronizeNetworkTime();
			int day = EnvMan.instance.GetDay();
			Plugin.Log.LogInfo($"Skipping time to morning (Day {TerminalColor.Cyan}{day + 1}{TerminalColor.Reset})...");
		}

		private static void SynchronizeNetworkTime()
		{
			try
			{
				ZNet.instance.SendNetTime();
			}
			catch
			{
			}
		}
	}
	[BepInPlugin("dreamwraith.ConsoleStdinHeeler", "ConsoleStdinHeeler", "1.4.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "dreamwraith.ConsoleStdinHeeler";

		public const string ModName = "ConsoleStdinHeeler";

		public const string ModVersion = "1.4.1";

		private Harmony? _harmony;

		private bool _hasAnnouncedServerReady;

		internal static Plugin? Instance { get; private set; }

		internal static PluginLogger Log { get; private set; }

		private void Awake()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			Instance = this;
			Log = new PluginLogger(((BaseUnityPlugin)this).Logger);
			ModConfig.Initialize(((BaseUnityPlugin)this).Config);
			if (!ModConfig.EnableMod.Value)
			{
				Log.LogInfo("ConsoleStdinHeeler is disabled in config.");
				((Behaviour)this).enabled = false;
				return;
			}
			if (!IsDedicatedServerEnvironment())
			{
				Log.LogWarning("ConsoleStdinHeeler is designed strictly for dedicated servers and cannot run on an interactive game client. Disabling mod.");
				((Behaviour)this).enabled = false;
				return;
			}
			try
			{
				_harmony = new Harmony("dreamwraith.ConsoleStdinHeeler");
				_harmony.PatchAll(typeof(Plugin).Assembly);
			}
			catch (Exception ex)
			{
				Log.LogWarning("Failed to initialize Harmony patches: " + ex.Message);
			}
			StdinListener.Start();
		}

		private void Update()
		{
			if (!_hasAnnouncedServerReady && Object.op_Implicit((Object)(object)Game.instance) && Object.op_Implicit((Object)(object)ZoneSystem.instance))
			{
				_hasAnnouncedServerReady = true;
				Log.LogInfo(TerminalColor.Bold + TerminalColor.Green + "Server world loaded successfully. STDIN console ready for commands." + TerminalColor.Reset);
			}
			CommandCustom.Update();
			string command;
			while (StdinListener.TryDequeue(out command))
			{
				CommandServer.Execute(command);
			}
		}

		private void OnDestroy()
		{
			StdinListener.Stop();
			StdinListener.Interrupt();
			try
			{
				Harmony? harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
			}
		}

		private static bool IsDedicatedServerEnvironment()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			bool num = (int)SystemInfo.graphicsDeviceType == 4;
			string commandLine = Environment.CommandLine;
			bool flag = commandLine.IndexOf("valheim_server", StringComparison.OrdinalIgnoreCase) >= 0;
			bool flag2 = commandLine.IndexOf("-batchmode", StringComparison.OrdinalIgnoreCase) >= 0;
			return num || flag || flag2;
		}
	}
	public class PluginLogger
	{
		private readonly ManualLogSource _underlying;

		public PluginLogger(ManualLogSource underlying)
		{
			_underlying = underlying;
		}

		public void LogInfo(object data)
		{
			_underlying.LogInfo(data);
		}

		public void LogWarning(object data)
		{
			string text = data.ToString();
			string text2 = ((text.StartsWith("Warning:", StringComparison.OrdinalIgnoreCase) || text.StartsWith("[Warning]", StringComparison.OrdinalIgnoreCase)) ? text : ("Warning: " + text));
			_underlying.LogWarning((object)(TerminalColor.Yellow + text2 + TerminalColor.Reset));
		}

		public void LogError(object data)
		{
			string text = data.ToString();
			string text2 = ((text.StartsWith("Error:", StringComparison.OrdinalIgnoreCase) || text.StartsWith("[Error]", StringComparison.OrdinalIgnoreCase) || text.StartsWith("Failed:", StringComparison.OrdinalIgnoreCase) || text.StartsWith("Exception", StringComparison.OrdinalIgnoreCase)) ? text : ("Error: " + text));
			_underlying.LogError((object)(TerminalColor.Red + text2 + TerminalColor.Reset));
		}

		public void LogDebug(object data)
		{
			if (ModConfig.EnableDebugLogs.Value)
			{
				_underlying.LogInfo((object)$"[DEBUG] {data}");
			}
		}

		public void LogMessage(object data)
		{
			_underlying.LogMessage(data);
		}

		public void LogFatal(object data)
		{
			_underlying.LogFatal(data);
		}

		public void Log(LogLevel level, object data)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			if (level - 1 > 1)
			{
				if ((int)level != 4)
				{
					if ((int)level == 32)
					{
						LogDebug(data);
					}
					else
					{
						LogInfo(data);
					}
				}
				else
				{
					LogWarning(data);
				}
			}
			else
			{
				LogError(data);
			}
		}
	}
	internal static class StdinListener
	{
		private const int MaxConsecutiveEofRetries = 3;

		private const int EofRetryIntervalMs = 1000;

		private static readonly ConcurrentQueue<string> _commandQueue = new ConcurrentQueue<string>();

		private static Thread? _stdinThread;

		private static volatile bool _isRunning;

		public static void Start()
		{
			if (!_isRunning)
			{
				Console.SetConsoleEnabledForThisSession();
				_isRunning = true;
				_stdinThread = new Thread(ReadStdinLoop)
				{
					Name = "ConsoleStdinHeeler_Reader",
					IsBackground = true
				};
				_stdinThread.Start();
				Plugin.Log.LogInfo(TerminalColor.Green + "ConsoleStdinHeeler v1.4.1 loaded successfully. STDIN listener started." + TerminalColor.Reset);
			}
		}

		public static void Stop()
		{
			_isRunning = false;
		}

		public static void Interrupt()
		{
			_stdinThread?.Interrupt();
		}

		public static bool TryDequeue(out string command)
		{
			return _commandQueue.TryDequeue(out command);
		}

		private static void ReadStdinLoop()
		{
			int num = 0;
			while (_isRunning)
			{
				try
				{
					string text = Console.ReadLine();
					if (text == null)
					{
						num++;
						if (num >= 3)
						{
							Plugin.Log.LogInfo("STDIN stream closed or detached (EOF detected). Listener thread shutting down.");
							break;
						}
						Thread.Sleep(1000);
					}
					else
					{
						num = 0;
						text = text.Trim();
						if (text.Length > 0)
						{
							_commandQueue.Enqueue(text);
						}
					}
				}
				catch (ThreadAbortException)
				{
					break;
				}
				catch (ThreadInterruptedException)
				{
					break;
				}
				catch (Exception ex3)
				{
					Plugin.Log.LogWarning("Exception in STDIN reader thread: " + ex3.Message);
					Thread.Sleep(1000);
				}
			}
		}
	}
	public static class TerminalColor
	{
		private static bool Enabled
		{
			get
			{
				if (ModConfig.ColorFormatting != null)
				{
					return ModConfig.ColorFormatting.Value == ColorTagMode.Ansi;
				}
				return true;
			}
		}

		public static string Reset
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[0m";
			}
		}

		public static string Bold
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[1m";
			}
		}

		public static string BoldReset
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[22m";
			}
		}

		public static string Default
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[39m";
			}
		}

		public static string Black
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[30m";
			}
		}

		public static string Gray
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[90m";
			}
		}

		public static string DarkGray => Gray;

		public static string Red
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[91m";
			}
		}

		public static string Green
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[92m";
			}
		}

		public static string Yellow
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[93m";
			}
		}

		public static string Blue
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[94m";
			}
		}

		public static string Magenta
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[95m";
			}
		}

		public static string Purple => Magenta;

		public static string Fuchsia => Magenta;

		public static string Cyan
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[96m";
			}
		}

		public static string Aqua => Cyan;

		public static string White
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[97m";
			}
		}

		public static string DarkRed
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[31m";
			}
		}

		public static string Maroon => DarkRed;

		public static string DarkGreen
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[32m";
			}
		}

		public static string DarkYellow
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[33m";
			}
		}

		public static string DarkBlue
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[34m";
			}
		}

		public static string Navy => DarkBlue;

		public static string DarkMagenta
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[35m";
			}
		}

		public static string DarkCyan
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[36m";
			}
		}

		public static string Teal => DarkCyan;

		public static string LightGray
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[37m";
			}
		}

		public static string Silver => LightGray;

		public static string Orange
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[38;2;255;165;0m";
			}
		}

		public static string Gold
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[38;2;234;168;0m";
			}
		}

		public static string Amber => Gold;

		public static string Lime
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[38;2;0;255;0m";
			}
		}

		public static string Olive
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[38;2;128;128;0m";
			}
		}

		public static string Brown
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[38;2;165;42;42m";
			}
		}

		public static string LightBlue
		{
			get
			{
				if (!Enabled)
				{
					return string.Empty;
				}
				return "\u001b[38;2;173;216;230m";
			}
		}

		public static string FromRgb(int red, int green, int blue)
		{
			if (!Enabled)
			{
				return string.Empty;
			}
			return $"\u001b[38;2;{red};{green};{blue}m";
		}

		public static string? FromHex(string hexColor)
		{
			if (!Enabled || string.IsNullOrWhiteSpace(hexColor))
			{
				return string.Empty;
			}
			hexColor = hexColor.TrimStart(new char[1] { '#' });
			if (hexColor.Length == 6 && byte.TryParse(hexColor.Substring(0, 2), NumberStyles.HexNumber, null, out var result) && byte.TryParse(hexColor.Substring(2, 2), NumberStyles.HexNumber, null, out var result2) && byte.TryParse(hexColor.Substring(4, 2), NumberStyles.HexNumber, null, out var result3))
			{
				return FromRgb(result, result2, result3);
			}
			return null;
		}

		public static string? FromName(string name)
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				return null;
			}
			string text = name.Trim().ToLowerInvariant();
			if (text.StartsWith("#") || (text.Length == 6 && IsValidHex(text)))
			{
				string text2 = FromHex(text);
				if (text2 != null)
				{
					return text2;
				}
			}
			switch (text)
			{
			case "red":
				return Red;
			case "darkred":
			case "maroon":
				return DarkRed;
			case "green":
				return Green;
			case "darkgreen":
				return DarkGreen;
			case "lime":
				return Lime;
			case "yellow":
				return Yellow;
			case "darkyellow":
				return DarkYellow;
			case "orange":
				return Orange;
			case "amber":
			case "gold":
				return Gold;
			case "blue":
				return Blue;
			case "navy":
			case "darkblue":
				return DarkBlue;
			case "lightblue":
				return LightBlue;
			case "magenta":
			case "fuchsia":
				return Magenta;
			case "purple":
				return Purple;
			case "darkmagenta":
				return DarkMagenta;
			case "cyan":
			case "aqua":
				return Cyan;
			case "teal":
			case "darkcyan":
				return DarkCyan;
			case "white":
				return White;
			case "grey":
			case "gray":
			case "darkgray":
			case "darkgrey":
				return Gray;
			case "silver":
			case "lightgray":
			case "lightgrey":
				return LightGray;
			case "black":
				return Black;
			case "olive":
				return Olive;
			case "brown":
				return Brown;
			case "default":
				return Default;
			default:
				return null;
			}
		}

		private static bool IsValidHex(string text)
		{
			foreach (char c in text)
			{
				if ((c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F'))
				{
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public static class TerminalPatches
	{
		[HarmonyPatch("AddString", new Type[] { typeof(string) })]
		[HarmonyPrefix]
		private static void AddStringPrefix(ref string text)
		{
			if (!string.IsNullOrEmpty(text) && ModConfig.ColorFormatting != null)
			{
				text = TerminalUtils.ProcessText(text, ModConfig.ColorFormatting.Value);
			}
		}
	}
	public static class TerminalUtils
	{
		private static readonly Regex TagRegex = new Regex("<(/?(?:color|b|i|size|material|quad|sprite)(?:[=\\s][^>]*)?)>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

		public static string ProcessText(string text, ColorTagMode mode)
		{
			if (string.IsNullOrEmpty(text))
			{
				return text;
			}
			return mode switch
			{
				ColorTagMode.Strip => StripRichTextTags(text), 
				ColorTagMode.Ansi => ConvertRichTextToAnsi(text), 
				_ => text, 
			};
		}

		public static string StripRichTextTags(string input)
		{
			if (!string.IsNullOrEmpty(input) && input.IndexOf('<') >= 0)
			{
				return TagRegex.Replace(input, string.Empty);
			}
			return input;
		}

		public static string ConvertRichTextToAnsi(string input)
		{
			if (string.IsNullOrEmpty(input) || input.IndexOf('<') < 0)
			{
				return input;
			}
			bool appliedFormatting = false;
			string text = TagRegex.Replace(input, delegate(Match match)
			{
				string text2 = match.Groups[1].Value.Trim();
				if (text2.StartsWith("color=", StringComparison.OrdinalIgnoreCase))
				{
					string ansiColorCode = GetAnsiColorCode(text2.Substring(6).Trim().Trim(new char[1] { '"' }));
					if (ansiColorCode != null)
					{
						appliedFormatting = true;
						return ansiColorCode;
					}
					return string.Empty;
				}
				if (text2.Equals("/color", StringComparison.OrdinalIgnoreCase))
				{
					return TerminalColor.Reset;
				}
				if (text2.Equals("b", StringComparison.OrdinalIgnoreCase))
				{
					appliedFormatting = true;
					return TerminalColor.Bold;
				}
				return text2.Equals("/b", StringComparison.OrdinalIgnoreCase) ? TerminalColor.BoldReset : string.Empty;
			});
			if (appliedFormatting && !string.IsNullOrEmpty(TerminalColor.Reset) && !text.EndsWith(TerminalColor.Reset))
			{
				text += TerminalColor.Reset;
			}
			return text;
		}

		public static List<string> ParseArguments(string input)
		{
			List<string> list = new List<string>();
			if (string.IsNullOrWhiteSpace(input))
			{
				return list;
			}
			bool flag = false;
			StringBuilder stringBuilder = new StringBuilder();
			foreach (char c in input)
			{
				switch (c)
				{
				case '"':
					flag = !flag;
					continue;
				case ' ':
					if (!flag)
					{
						if (stringBuilder.Length > 0)
						{
							list.Add(stringBuilder.ToString());
							stringBuilder.Clear();
						}
						continue;
					}
					break;
				}
				stringBuilder.Append(c);
			}
			if (stringBuilder.Length > 0)
			{
				list.Add(stringBuilder.ToString());
			}
			return list;
		}

		private static string? GetAnsiColorCode(string colorSpecification)
		{
			if (colorSpecification.StartsWith("#"))
			{
				string text = colorSpecification.Substring(1);
				if (text.Length == 3)
				{
					int red = Convert.ToInt32(new string(text[0], 2), 16);
					int green = Convert.ToInt32(new string(text[1], 2), 16);
					int blue = Convert.ToInt32(new string(text[2], 2), 16);
					return TerminalColor.FromRgb(red, green, blue);
				}
				if (text.Length >= 6)
				{
					int red2 = Convert.ToInt32(text.Substring(0, 2), 16);
					int green2 = Convert.ToInt32(text.Substring(2, 2), 16);
					int blue2 = Convert.ToInt32(text.Substring(4, 2), 16);
					return TerminalColor.FromRgb(red2, green2, blue2);
				}
				return null;
			}
			return TerminalColor.FromName(colorSpecification);
		}
	}
	internal static class VersionInfo
	{
		public const string Version = "1.4.1";
	}
}
namespace ConsoleStdinHeeler.Configuration
{
	public enum ColorTagMode
	{
		Ansi,
		Strip,
		Raw
	}
	internal static class ModConfig
	{
		public static ConfigEntry<bool> EnableMod;

		public static ConfigEntry<bool> EnableCheatsByDefault;

		public static ConfigEntry<ColorTagMode> ColorFormatting;

		public static ConfigEntry<string> ConsolePrompt;

		public static ConfigEntry<bool> EnableDebugLogs;

		public static void Initialize(ConfigFile config)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			EnableMod = config.Bind<bool>("1 - General", "EnableMod", true, new ConfigDescription("Master switch to enable or disable the STDIN console listener.", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableCheatsByDefault = config.Bind<bool>("1 - General", "EnableCheatsByDefault", true, new ConfigDescription("Allows modded and admin cheat commands to execute on the dedicated server.", (AcceptableValueBase)null, Array.Empty<object>()));
			ConsolePrompt = config.Bind<string>("2 - Display", "ConsolePrompt", "> ", new ConfigDescription("Prefix displayed in logs when an STDIN command is received.", (AcceptableValueBase)null, Array.Empty<object>()));
			ColorFormatting = config.Bind<ColorTagMode>("2 - Display", "ColorFormatting", ColorTagMode.Ansi, new ConfigDescription("How Unity rich-text color tags from console outputs are handled: Ansi (render in terminal colors), Strip (clean plain text), or Raw (keep tags unchanged).", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableDebugLogs = config.Bind<bool>("9 - Debug", "EnableDebugLogs", false, new ConfigDescription("Enables verbose diagnostic logging.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					IsAdvanced = true
				}
			}));
		}
	}
	internal class ConfigurationManagerAttributes
	{
		public bool? IsAdvanced { get; set; }

		public int? Order { get; set; }

		public bool? Browsable { get; set; }

		public Action<ConfigEntryBase>? CustomDrawer { get; set; }
	}
}