Decompiled source of DevCommands v1.0.6

IronLabs.DevCommands.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("IronLabs.DevCommands")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IronLabs.DevCommands")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("CA2ABD79-CB95-41E2-999B-52AE9310670C")]
[assembly: AssemblyFileVersion("1.0.6")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.6.0")]
namespace IronLabs.DevCommands;

internal static class AdminAccess
{
	private const string RequestRpc = "IronLabs_DevCommands_AdminRequest";

	private const string ResponseRpc = "IronLabs_DevCommands_AdminResponse";

	private static ZRoutedRpc _registeredRpc;

	private static bool _serverConfirmedAdmin;

	internal static bool LocalPlayerIsAdminOrHost()
	{
		if ((Object)(object)ZNet.instance != (Object)null)
		{
			if (!ZNet.instance.IsServer())
			{
				return _serverConfirmedAdmin;
			}
			return true;
		}
		return false;
	}

	internal static void RegisterRpcs()
	{
		ZRoutedRpc instance = ZRoutedRpc.instance;
		if (instance != null && instance != _registeredRpc)
		{
			instance.Register("IronLabs_DevCommands_AdminRequest", (Action<long>)ReceiveRequest);
			instance.Register<bool>("IronLabs_DevCommands_AdminResponse", (Action<long, bool>)ReceiveResponse);
			_registeredRpc = instance;
			DevCommandsPlugin.ModLogger.LogDebug("Administrator validation RPCs registered.");
		}
	}

	internal static void RequestStatus()
	{
		if (!((Object)(object)ZNet.instance == (Object)null) && !ZNet.instance.IsServer() && ZRoutedRpc.instance != null)
		{
			_serverConfirmedAdmin = false;
			ZRoutedRpc.instance.InvokeRoutedRPC("IronLabs_DevCommands_AdminRequest", Array.Empty<object>());
			DevCommandsPlugin.ModLogger.LogDebug("Requested administrator validation from the server.");
		}
	}

	internal static void ResetSession()
	{
		_registeredRpc = null;
		_serverConfirmedAdmin = false;
	}

	private static void ReceiveRequest(long sender)
	{
		if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer() && ZRoutedRpc.instance != null)
		{
			ZNetPeer peer = ZNet.instance.GetPeer(sender);
			bool flag = peer != null && ZNet.instance.IsAdmin(peer.m_socket.GetHostName());
			ZRoutedRpc.instance.InvokeRoutedRPC(sender, "IronLabs_DevCommands_AdminResponse", new object[1] { flag });
			DevCommandsPlugin.ModLogger.LogDebug($"Administrator validation completed for peer {sender}: {flag}.");
		}
	}

	private static void ReceiveResponse(long sender, bool isAdmin)
	{
		if (!((Object)(object)ZNet.instance == (Object)null) && !ZNet.instance.IsServer() && ZNet.instance.GetPeer(sender) != null)
		{
			_serverConfirmedAdmin = isAdmin;
			DevCommandsPlugin.ModLogger.LogDebug($"Server administrator validation received: {isAdmin}.");
		}
	}
}
internal static class AdminDevCommandsState
{
	internal const string DeveloperZdoKey = "IronLabs.DevCommands.Enabled";

	internal static bool Enabled { get; set; }

	internal static bool LocalPlayerIsAdminOrHost()
	{
		return AdminAccess.LocalPlayerIsAdminOrHost();
	}

	internal static void UpdateReplicatedState()
	{
		Player localPlayer = Player.m_localPlayer;
		ZNetView obj = (((Object)(object)localPlayer != (Object)null) ? ((Component)localPlayer).GetComponent<ZNetView>() : null);
		ZDO val = ((obj != null) ? obj.GetZDO() : null);
		if (val != null && val.IsOwner())
		{
			val.Set("IronLabs.DevCommands.Enabled", Enabled);
		}
	}
}
[HarmonyPatch(typeof(Terminal), "TryRunCommand")]
internal static class DevCommandsTogglePatch
{
	private static void Prefix(string text)
	{
		if (IsDevCommandsCommand(text) && AdminDevCommandsState.LocalPlayerIsAdminOrHost())
		{
			AdminDevCommandsState.Enabled = !AdminDevCommandsState.Enabled;
			AdminDevCommandsState.UpdateReplicatedState();
			DevCommandsPlugin.ModLogger.LogDebug($"Administrator devcommands state changed to {AdminDevCommandsState.Enabled}.");
		}
	}

	private static bool IsDevCommandsCommand(string text)
	{
		return string.Equals(text?.Trim(), "devcommands", StringComparison.OrdinalIgnoreCase);
	}
}
[HarmonyPatch(typeof(Player), "SetLocalPlayer")]
internal static class LocalPlayerDevStatePatch
{
	private static void Postfix()
	{
		AdminAccess.RequestStatus();
		AdminDevCommandsState.UpdateReplicatedState();
	}
}
[HarmonyPatch(typeof(Game), "Start")]
internal static class AdminRpcRegistrationPatch
{
	private static void Postfix()
	{
		AdminAccess.RegisterRpcs();
		PlayerPositionRpc.RegisterResponseRpc();
	}
}
[HarmonyPatch(typeof(Player), "Awake")]
internal static class PlayerPositionRpcRegistrationPatch
{
	private static void Postfix(Player __instance, ZNetView ___m_nview)
	{
		PlayerPositionRpc.RegisterPlayerRpc(__instance, ___m_nview);
	}
}
[HarmonyPatch(typeof(Player), "GetHoverName")]
internal static class DeveloperHoverNamePatch
{
	private static void Postfix(Player __instance, ref string __result)
	{
		ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
		if (component != null)
		{
			ZDO zDO = component.GetZDO();
			if (((zDO != null) ? new bool?(zDO.GetBool("IronLabs.DevCommands.Enabled", false)) : ((bool?)null)) == true)
			{
				__result += " [dev]";
			}
		}
	}
}
[HarmonyPatch(typeof(Terminal), "IsCheatsEnabled")]
internal static class AdminCheatsEnabledPatch
{
	private static void Postfix(ref bool __result)
	{
		if (!__result && AdminDevCommandsState.Enabled)
		{
			__result = AdminDevCommandsState.LocalPlayerIsAdminOrHost();
		}
	}
}
[HarmonyPatch(typeof(ConsoleCommand), "IsValid")]
internal static class AdminCommandValidationPatch
{
	private static void Postfix(ConsoleCommand __instance, ref bool __result)
	{
		if (__instance.OnlyAdmin && !AdminAccess.LocalPlayerIsAdminOrHost())
		{
			__result = false;
		}
	}
}
[HarmonyPatch(typeof(ZNet), "OnDestroy")]
internal static class DevCommandsDisconnectPatch
{
	private static void Postfix()
	{
		AdminDevCommandsState.Enabled = false;
		AdminAccess.ResetSession();
		PlayerPositionRpc.ResetSession();
		AdminDevCommandsState.UpdateReplicatedState();
	}
}
[HarmonyPatch(typeof(Game), "UpdateRespawn")]
internal static class CommandLineSwitches
{
	private static void Prefix(bool ___m_firstSpawn, out bool __state)
	{
		__state = ___m_firstSpawn;
	}

	private static void Postfix(bool ___m_firstSpawn, bool __state)
	{
		if (!(!__state || ___m_firstSpawn))
		{
			EnableGhostMode();
			EnableDevCommandsForAdmin();
		}
	}

	private static void EnableGhostMode()
	{
		if (HasEnabledArgument("--ghost") && !((Object)(object)Player.m_localPlayer == (Object)null))
		{
			Player.m_localPlayer.SetGhostMode(true);
		}
	}

	private static void EnableDevCommandsForAdmin()
	{
		if (HasEnabledArgument("--devcommands"))
		{
			if ((Object)(object)ZNet.instance == (Object)null || (Object)(object)Console.instance == (Object)null)
			{
				DevCommandsPlugin.ModLogger.LogError("Vanilla devcommands could not be enabled because the game is not ready.");
			}
			else if (AdminAccess.LocalPlayerIsAdminOrHost() && !((Terminal)Console.instance).IsCheatsEnabled())
			{
				((Terminal)Console.instance).TryRunCommand("devcommands", false, false);
			}
		}
	}

	private static bool HasEnabledArgument(string argumentName)
	{
		string[] commandLineArgs = Environment.GetCommandLineArgs();
		for (int i = 0; i < commandLineArgs.Length - 1; i++)
		{
			if (MatchesEnabledArgument(commandLineArgs, i, argumentName))
			{
				DevCommandsPlugin.ModLogger.LogDebug("Received command-line switch: " + argumentName + " true.");
				return true;
			}
		}
		return false;
	}

	private static bool MatchesEnabledArgument(string[] arguments, int index, string name)
	{
		if (string.Equals(arguments[index], name, StringComparison.OrdinalIgnoreCase))
		{
			return string.Equals(arguments[index + 1], "true", StringComparison.OrdinalIgnoreCase);
		}
		return false;
	}
}
[HarmonyPatch(typeof(Terminal), "InitTerminal")]
internal static class CommandRegistrationPatch
{
	private static void Postfix()
	{
		DevCommandsPlugin.RegisterCommands();
		DevCommandsPlugin.ModLogger.LogDebug("Custom commands were registered after vanilla terminal initialization.");
	}
}
internal static class EnvCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_002f: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("env", "[value] - Prints or overrides the environment.", new ConsoleEvent(Execute), true, false, false, false, true, new ConsoleOptionsFetcher(GetEnvironmentNames), false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		if ((Object)(object)EnvMan.instance == (Object)null)
		{
			DevCommandsPlugin.ModLogger.LogError("Env command failed because the environment manager is unavailable.");
			args.Context.AddString("The environment manager is not available yet.");
		}
		else if (args.Length < 2)
		{
			EnvSetup currentEnvironment = EnvMan.instance.GetCurrentEnvironment();
			args.Context.AddString("Environment: " + (currentEnvironment?.m_name ?? "unknown") + ".");
			DevCommandsPlugin.ModLogger.LogDebug("Env command reported environment '" + (currentEnvironment?.m_name ?? "unknown") + "'.");
		}
		else
		{
			string text = ResolveEnvironmentName(args);
			EnvMan.instance.m_debugEnv = text;
			args.Context.AddString("Setting debug environment: " + text);
			DevCommandsPlugin.ModLogger.LogDebug("Env command set debug environment to '" + text + "'.");
		}
	}

	private static string ResolveEnvironmentName(ConsoleEventArgs args)
	{
		string name = string.Join(" ", args.Args, 1, args.Args.Length - 1);
		if (EnvMan.instance.m_environments.Exists((EnvSetup environment) => environment.m_name == name))
		{
			return name;
		}
		return name.Replace("_", " ");
	}

	private static List<string> GetEnvironmentNames()
	{
		List<string> list = new List<string>();
		if ((Object)(object)EnvMan.instance == (Object)null)
		{
			return list;
		}
		foreach (EnvSetup environment in EnvMan.instance.m_environments)
		{
			list.Add(environment.m_name.Replace(" ", "_"));
		}
		list.Sort();
		return list;
	}
}
internal static class ExploreMapCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("exploremap", "Explores the entire map.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		if ((Object)(object)Minimap.instance == (Object)null)
		{
			DevCommandsPlugin.ModLogger.LogError("Exploremap command failed because the map is not available.");
			args.Context.AddString("The map is not available yet.");
		}
		else
		{
			Minimap.instance.ExploreAll();
			args.Context.AddString("The entire map has been explored.");
			DevCommandsPlugin.ModLogger.LogDebug("Exploremap command revealed the entire local map.");
		}
	}
}
internal static class GhostCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("ghost", "Toggles ghost mode.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		if ((Object)(object)Player.m_localPlayer == (Object)null)
		{
			DevCommandsPlugin.ModLogger.LogError("Ghost command failed because the player is not available.");
			args.Context.AddString("The player is not available yet.");
			return;
		}
		bool flag = args.HasArgumentAnywhere("on", 0, true) || (!args.HasArgumentAnywhere("off", 0, true) && !((Character)Player.m_localPlayer).InGhostMode());
		Player.m_localPlayer.SetGhostMode(flag);
		args.Context.AddString($"Ghost mode: {flag}");
		DevCommandsPlugin.ModLogger.LogDebug($"Ghost command set ghost mode to {flag}.");
	}
}
internal static class GotoCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("goto", "[x z [y] | player] - Teleports you.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		Vector3 destination;
		if ((Object)(object)Player.m_localPlayer == (Object)null || args.Length < 2)
		{
			Fail(args, "Usage: goto <x> <z> [y] OR goto <player>");
		}
		else if (TryGetCoordinateDestination(args, out destination))
		{
			Teleport(destination, args.Context);
		}
		else if (!PlayerPositionRpc.Request(args[1], delegate(Vector3 position)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Teleport(position, args.Context);
		}))
		{
			Fail(args, "No matching player or valid coordinates were found.");
		}
	}

	private static void Teleport(Vector3 destination, Terminal context)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Player.m_localPlayer == (Object)null))
		{
			((Character)Player.m_localPlayer).TeleportTo(destination, ((Component)Player.m_localPlayer).transform.rotation, true);
			context.AddString($"Teleported to: {destination}");
			DevCommandsPlugin.ModLogger.LogDebug($"Goto command teleported the local player to {destination}.");
		}
	}

	private static bool TryGetCoordinateDestination(ConsoleEventArgs args, out Vector3 destination)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		float num = default(float);
		float num2 = default(float);
		if (args.TryParameterFloat(1, ref num) && args.TryParameterFloat(2, ref num2))
		{
			float num3 = args.TryParameterFloat(3, WorldGenerator.instance.GetHeight(num, num2));
			destination = new Vector3(num, num3, num2);
			return true;
		}
		destination = Vector3.zero;
		return false;
	}

	private static void Fail(ConsoleEventArgs args, string message)
	{
		DevCommandsPlugin.ModLogger.LogError("Goto command failed: " + message);
		args.Context.AddString(message);
	}
}
internal static class GodCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("god", "Toggles invincible mode.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		if ((Object)(object)Player.m_localPlayer == (Object)null)
		{
			DevCommandsPlugin.ModLogger.LogError("God command failed because the player is not available.");
			args.Context.AddString("The player is not available yet.");
			return;
		}
		bool flag = args.HasArgumentAnywhere("on", 0, true) || (!args.HasArgumentAnywhere("off", 0, true) && !((Character)Player.m_localPlayer).InGodMode());
		Player.m_localPlayer.SetGodMode(flag);
		args.Context.AddString($"God mode: {flag}");
		DevCommandsPlugin.ModLogger.LogDebug($"God command set god mode to {flag}.");
	}
}
internal static class IsAdminCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("isadmin", "Prints whether the local player is an administrator.", new ConsoleEvent(Execute), false, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, false);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		bool flag = AdminAccess.LocalPlayerIsAdminOrHost();
		args.Context.AddString(flag.ToString().ToLowerInvariant());
		string message = $"Isadmin command returned {flag}.";
		DevCommandsPlugin.ModLogger.LogDebug(message);
	}
}
internal static class ItemSetCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("itemset", "Replaces current items with the Meadows item set.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		if ((Object)(object)ItemSets.instance == (Object)null || !ItemSets.instance.TryGetSet("Meadows", true, -1, -1))
		{
			args.Context.AddString("The Meadows item set could not be applied.");
			DevCommandsPlugin.ModLogger.LogError("The Meadows item set could not be applied.");
		}
		else
		{
			args.Context.AddString("Applied the Meadows item set.");
			DevCommandsPlugin.ModLogger.LogDebug("The Meadows item set was applied.");
		}
	}
}
internal static class PlayerCommandUtility
{
	internal static bool TryFindPlayer(string name, out Vector3 position, out ZDOID characterId)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: 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)
		position = Vector3.zero;
		characterId = ZDOID.None;
		if ((Object)(object)ZNet.instance == (Object)null)
		{
			return false;
		}
		foreach (PlayerInfo player in ZNet.instance.GetPlayerList())
		{
			if (player.m_name.Equals(name, StringComparison.OrdinalIgnoreCase))
			{
				position = player.m_position;
				characterId = player.m_characterID;
				return true;
			}
		}
		return false;
	}

	internal static void Teleport(ZDOID characterId, Vector3 position, Quaternion rotation)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		ZRoutedRpc.instance.InvokeRoutedRPC(0L, characterId, "RPC_TeleportTo", new object[3] { position, rotation, true });
	}
}
internal static class PlayerListCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("playerlist", "Prints online players.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ZNet.instance == (Object)null)
		{
			DevCommandsPlugin.ModLogger.LogError("Playerlist command failed because ZNet is unavailable.");
			args.Context.AddString("The player list is not available.");
			return;
		}
		List<string> list = new List<string>();
		foreach (PlayerInfo player in ZNet.instance.GetPlayerList())
		{
			list.Add($"{player.m_name} ({player.m_position.x:F0}, {player.m_position.z:F0}, {player.m_position.y:F0})");
		}
		args.Context.AddString(string.Join("\n", list));
		DevCommandsPlugin.ModLogger.LogDebug($"Playerlist command returned {list.Count} online player entries.");
	}
}
internal static class PosCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("pos", "[player/precision] [precision] - Prints a player position.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Player.m_localPlayer == (Object)null)
		{
			Fail(args, "The local player is not available.");
			return;
		}
		Vector3 position = ((Component)Player.m_localPlayer).transform.position;
		int precision = 0;
		if (!TryParseArguments(args, ref position, ref precision))
		{
			Fail(args, "The requested player was not found.");
			return;
		}
		string text = $"F{Mathf.Clamp(precision, 0, 9)}";
		args.Context.AddString("Player position (X,Z,Y): (" + position.x.ToString(text) + ", " + position.z.ToString(text) + ", " + position.y.ToString(text) + ")");
		DevCommandsPlugin.ModLogger.LogDebug($"Pos command returned {position} with precision {precision}.");
	}

	private static bool TryParseArguments(ConsoleEventArgs args, ref Vector3 position, ref int precision)
	{
		if (args.Length < 2)
		{
			return true;
		}
		if (int.TryParse(args[1], out precision))
		{
			return true;
		}
		if (!PlayerCommandUtility.TryFindPlayer(args[1], out position, out var _))
		{
			return false;
		}
		precision = args.TryParameterInt(2, 0);
		return true;
	}

	private static void Fail(ConsoleEventArgs args, string message)
	{
		DevCommandsPlugin.ModLogger.LogError("Pos command failed: " + message);
		args.Context.AddString(message);
	}
}
internal static class RecallCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("recall", "[player] - Teleports a player to you.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		//IL_0048: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Player.m_localPlayer == (Object)null || args.Length < 2 || !PlayerCommandUtility.TryFindPlayer(args[1], out var _, out var characterId))
		{
			DevCommandsPlugin.ModLogger.LogError("Recall command failed because the player was not found.");
			args.Context.AddString("Usage: recall <player>");
		}
		else
		{
			PlayerCommandUtility.Teleport(characterId, ((Component)Player.m_localPlayer).transform.position, ((Component)Player.m_localPlayer).transform.rotation);
			args.Context.AddString("Recalled player: " + args[1]);
			DevCommandsPlugin.ModLogger.LogDebug("Recall command teleported '" + args[1] + "' to the local player.");
		}
	}
}
internal static class ResetMapCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("resetmap", "Hides the entire explored map.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		if ((Object)(object)Minimap.instance == (Object)null)
		{
			DevCommandsPlugin.ModLogger.LogError("Resetmap command failed because the map is unavailable.");
			args.Context.AddString("The map is not available yet.");
		}
		else
		{
			Minimap.instance.Reset();
			args.Context.AddString("The entire map exploration has been reset.");
			DevCommandsPlugin.ModLogger.LogDebug("Resetmap command cleared the local map exploration.");
		}
	}
}
internal static class SeedCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("seed", "Prints the world seed.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		if (ZNet.World == null)
		{
			DevCommandsPlugin.ModLogger.LogError("Seed command failed because the world is unavailable.");
			args.Context.AddString("The world seed is not available.");
		}
		else
		{
			args.Context.AddString(ZNet.World.m_seedName);
			DevCommandsPlugin.ModLogger.LogDebug("Seed command returned the seed for world '" + ZNet.World.m_name + "'.");
		}
	}
}
internal static class SpawnCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_002f: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("spawn", "[prefab] [amount=1] [level=1] [radius=0.5]", new ConsoleEvent(Execute), true, false, false, false, true, new ConsoleOptionsFetcher(GetPrefabNames), false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		if (args.Length < 2 || (Object)(object)ZNetScene.instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null)
		{
			Fail(args, "Usage: spawn <prefab> [amount] [level] [radius]");
			return;
		}
		GameObject prefab = ZNetScene.instance.GetPrefab(args[1]);
		if ((Object)(object)prefab == (Object)null)
		{
			Fail(args, "Prefab not found: " + args[1]);
			return;
		}
		Spawn(prefab, args.TryParameterInt(2, 1), args.TryParameterInt(3, 1), args.TryParameterFloat(4, 0.5f));
		args.Context.AddString("Spawned prefab: " + args[1]);
		DevCommandsPlugin.ModLogger.LogDebug("Spawn command created prefab '" + args[1] + "'.");
	}

	private static void Spawn(GameObject prefab, int amount, int level, float radius)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		amount = Mathf.Max(1, amount);
		for (int i = 0; i < amount; i++)
		{
			Vector3 val = Random.insideUnitSphere * radius;
			Vector3 val2 = ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 2f + Vector3.up + val;
			GameObject obj = Object.Instantiate<GameObject>(prefab, val2, Quaternion.identity);
			ItemDrop.OnCreateNew(obj);
			Character component = obj.GetComponent<Character>();
			if (component != null)
			{
				component.SetLevel(Mathf.Clamp(level, 1, 9));
			}
			ItemDrop component2 = obj.GetComponent<ItemDrop>();
			if (component2 != null)
			{
				component2.SetQuality(Mathf.Clamp(level, 1, 4));
			}
		}
	}

	private static List<string> GetPrefabNames()
	{
		if (!((Object)(object)ZNetScene.instance == (Object)null))
		{
			return ZNetScene.instance.GetPrefabNames();
		}
		return new List<string>();
	}

	private static void Fail(ConsoleEventArgs args, string message)
	{
		DevCommandsPlugin.ModLogger.LogError("Spawn command failed: " + message);
		args.Context.AddString(message);
	}
}
internal static class TodCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("tod", "-1 OR [0-1] - Overrides the time of day.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		float num = default(float);
		if ((Object)(object)EnvMan.instance == (Object)null || args.Length < 2 || !args.TryParameterFloat(1, ref num))
		{
			DevCommandsPlugin.ModLogger.LogError("Tod command failed because its context or value is invalid.");
			args.Context.AddString("Usage: tod -1 OR tod [0-1]");
			return;
		}
		bool flag = num >= 0f;
		EnvMan.instance.m_debugTimeOfDay = flag;
		if (flag)
		{
			EnvMan.instance.m_debugTime = Mathf.Clamp01(num);
		}
		args.Context.AddString(flag ? $"Setting time of day: {EnvMan.instance.m_debugTime}" : "Time of day override disabled.");
		DevCommandsPlugin.ModLogger.LogDebug($"Tod command set override enabled={flag}, value={num}.");
	}
}
internal static class TpCommand
{
	internal static void Register()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		new ConsoleCommand("tp", "[player] [x z y | player] - Teleports a player.", new ConsoleEvent(Execute), true, false, false, false, true, (ConsoleOptionsFetcher)null, false, false, true);
	}

	private static void Execute(ConsoleEventArgs args)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		Vector3 destination;
		if (args.Length < 3 || !PlayerCommandUtility.TryFindPlayer(args[1], out var _, out var characterId))
		{
			Fail(args);
		}
		else if (TryGetCoordinateDestination(args, out destination))
		{
			Teleport(args[1], characterId, destination, args.Context);
		}
		else if (!PlayerPositionRpc.Request(args[2], delegate(Vector3 destination2)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			Teleport(args[1], characterId, destination2, args.Context);
		}))
		{
			Fail(args);
		}
	}

	private static bool TryGetCoordinateDestination(ConsoleEventArgs args, out Vector3 destination)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		float num = default(float);
		float num2 = default(float);
		if (args.TryParameterFloat(2, ref num) && args.TryParameterFloat(3, ref num2))
		{
			float num3 = args.TryParameterFloat(4, WorldGenerator.instance.GetHeight(num, num2));
			destination = new Vector3(num, num3, num2);
			return true;
		}
		destination = Vector3.zero;
		return false;
	}

	private static void Teleport(string playerName, ZDOID characterId, Vector3 destination, Terminal context)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//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_0013: 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)
		PlayerCommandUtility.Teleport(characterId, destination, Quaternion.identity);
		context.AddString($"Teleported {playerName} to {destination}.");
		DevCommandsPlugin.ModLogger.LogDebug($"Tp command teleported '{playerName}' to {destination}.");
	}

	private static void Fail(ConsoleEventArgs args)
	{
		DevCommandsPlugin.ModLogger.LogError("Tp command failed because its player or destination is invalid.");
		args.Context.AddString("Usage: tp <player> <x> <z> [y] OR tp <player> <player>");
	}
}
[BepInPlugin("Ironlabs.Devcommands", "IronLabs.DevCommands", "1.0.6")]
public sealed class DevCommandsPlugin : BaseUnityPlugin
{
	private const string PluginGuid = "Ironlabs.Devcommands";

	private const string PluginName = "IronLabs.DevCommands";

	private const string PluginVersion = "1.0.6";

	private readonly Harmony _harmony = new Harmony("Ironlabs.Devcommands");

	private static bool _patchesApplied;

	internal static ModLog ModLogger { get; } = new ModLog(Logger.CreateLogSource("IronLabs.DevCommands"), "IronLabs.DevCommands");

	private void Awake()
	{
		PatchOwnNamespace();
		RegisterCommands();
		ModLogger.LogInfo("IronLabs.DevCommands 1.0.6 is loaded.");
	}

	private void PatchOwnNamespace()
	{
		if (_patchesApplied)
		{
			ModLogger.LogDebug("Harmony patches are already active; skipping registration.");
			return;
		}
		string text = typeof(DevCommandsPlugin).Namespace;
		Type[] types = Assembly.GetExecutingAssembly().GetTypes();
		foreach (Type type in types)
		{
			if (type.Namespace == text)
			{
				_harmony.CreateClassProcessor(type).Patch();
			}
		}
		_patchesApplied = true;
		ModLogger.LogDebug("Harmony patches were applied for the plugin namespace.");
	}

	private void OnDestroy()
	{
		if (_patchesApplied)
		{
			_harmony.UnpatchSelf();
			_patchesApplied = false;
		}
	}

	internal static void RegisterCommands()
	{
		EnvCommand.Register();
		ExploreMapCommand.Register();
		GodCommand.Register();
		GhostCommand.Register();
		GotoCommand.Register();
		IsAdminCommand.Register();
		ItemSetCommand.Register();
		PlayerListCommand.Register();
		PosCommand.Register();
		RecallCommand.Register();
		ResetMapCommand.Register();
		SeedCommand.Register();
		SpawnCommand.Register();
		TodCommand.Register();
		TpCommand.Register();
	}
}
[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
internal static class MapTeleportPatch
{
	private static bool Prefix(Minimap __instance)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		if (!CanTeleport() || !TryGetMapPosition(__instance, out var position))
		{
			return true;
		}
		position.y = WorldGenerator.instance.GetHeight(position.x, position.z);
		Player localPlayer = Player.m_localPlayer;
		((Character)localPlayer).TeleportTo(position, ((Component)localPlayer).transform.rotation, true);
		__instance.SetMapMode((MapMode)1);
		DevCommandsPlugin.ModLogger.LogDebug($"Map teleport moved the local player to {position}.");
		return false;
	}

	private static bool CanTeleport()
	{
		if ((Object)(object)Player.m_localPlayer != (Object)null && WorldGenerator.instance != null && AdminDevCommandsState.LocalPlayerIsAdminOrHost())
		{
			return ZInput.GetKey((KeyCode)304, true);
		}
		return false;
	}

	private static bool TryGetMapPosition(Minimap map, out Vector3 position)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)map.m_mapImageLarge).transform;
		RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		Vector2 val2 = default(Vector2);
		if ((Object)(object)val == (Object)null || !RectTransformUtility.ScreenPointToLocalPointInRectangle(val, Vector2.op_Implicit(ZInput.mousePosition), (Camera)null, ref val2))
		{
			position = Vector3.zero;
			return false;
		}
		Vector2 val3 = Rect.PointToNormalized(val.rect, val2);
		Rect uvRect = map.m_mapImageLarge.uvRect;
		float num = ((Rect)(ref uvRect)).xMin + val3.x * ((Rect)(ref uvRect)).width;
		float num2 = ((Rect)(ref uvRect)).yMin + val3.y * ((Rect)(ref uvRect)).height;
		float num3 = (float)map.m_textureSize / 2f;
		position = new Vector3((num * (float)map.m_textureSize - num3) * map.m_pixelSize, 0f, (num2 * (float)map.m_textureSize - num3) * map.m_pixelSize);
		return true;
	}
}
internal sealed class ModLog
{
	private readonly ManualLogSource _logger;

	private readonly string _pluginName;

	internal ModLog(ManualLogSource logger, string pluginName)
	{
		_logger = logger;
		_pluginName = pluginName;
	}

	internal void LogFatal(object message)
	{
		Write((LogLevel)1, message);
	}

	internal void LogError(object message)
	{
		Write((LogLevel)2, message);
	}

	internal void LogWarning(object message)
	{
		Write((LogLevel)4, message);
	}

	internal void LogMessage(object message)
	{
		Write((LogLevel)8, message);
	}

	internal void LogInfo(object message)
	{
		Write((LogLevel)16, message);
	}

	internal void LogDebug(object message)
	{
		Write((LogLevel)32, message);
	}

	private void Write(LogLevel level, object message)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		_logger.Log(level, message);
	}
}
internal static class PlayerPositionRpc
{
	private const string RequestRpc = "IronLabs_DevCommands_PositionRequest";

	private const string ResponseRpc = "IronLabs_DevCommands_PositionResponse";

	private static readonly Dictionary<int, Action<Vector3>> PendingRequests = new Dictionary<int, Action<Vector3>>();

	private static ZRoutedRpc _registeredRpc;

	private static int _nextRequestId;

	internal static void RegisterResponseRpc()
	{
		ZRoutedRpc instance = ZRoutedRpc.instance;
		if (instance != null && instance != _registeredRpc)
		{
			instance.Register<int, Vector3>("IronLabs_DevCommands_PositionResponse", (Action<long, int, Vector3>)ReceiveResponse);
			_registeredRpc = instance;
			DevCommandsPlugin.ModLogger.LogDebug("Player position response RPC registered.");
		}
	}

	internal static void RegisterPlayerRpc(Player player, ZNetView netView)
	{
		if (((netView != null) ? netView.GetZDO() : null) != null)
		{
			netView.Register<int>("IronLabs_DevCommands_PositionRequest", (Action<long, int>)delegate(long sender, int requestId)
			{
				SendResponse(player, sender, requestId);
			});
		}
	}

	internal static bool Request(string playerName, Action<Vector3> callback)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if (!PlayerCommandUtility.TryFindPlayer(playerName, out var _, out var characterId) || ZRoutedRpc.instance == null)
		{
			return false;
		}
		int num = ++_nextRequestId;
		PendingRequests[num] = callback;
		ZRoutedRpc.instance.InvokeRoutedRPC(0L, characterId, "IronLabs_DevCommands_PositionRequest", new object[1] { num });
		DevCommandsPlugin.ModLogger.LogDebug($"Requested the private position of '{playerName}' with request {num}.");
		return true;
	}

	internal static void ResetSession()
	{
		_registeredRpc = null;
		_nextRequestId = 0;
		PendingRequests.Clear();
	}

	private static void SendResponse(Player player, long sender, int requestId)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)player == (Object)null) && ZRoutedRpc.instance != null)
		{
			ZRoutedRpc.instance.InvokeRoutedRPC(sender, "IronLabs_DevCommands_PositionResponse", new object[2]
			{
				requestId,
				((Component)player).transform.position
			});
		}
	}

	private static void ReceiveResponse(long sender, int requestId, Vector3 position)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if (PendingRequests.TryGetValue(requestId, out var value))
		{
			PendingRequests.Remove(requestId);
			value(position);
			DevCommandsPlugin.ModLogger.LogDebug($"Received private player position {position} for request {requestId} from peer {sender}.");
		}
	}
}