Decompiled source of AutoCloseDoors v3.1.0

AutoCloseDoors.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AutoCloseDoors.Systems;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Systems;
using ProjectM.Physics;
using ScarletRCON.Shared;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Midon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Automatically close doors")]
[assembly: AssemblyFileVersion("3.1.0.0")]
[assembly: AssemblyInformationalVersion("3.1.0+7b0f61a2650e899c30c99bf4dd2dec593381cf6d")]
[assembly: AssemblyProduct("AutoCloseDoors")]
[assembly: AssemblyTitle("AutoCloseDoors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public static class AutoCloseDoorsConfig
{
	public static ConfigFile Config;

	public static ConfigEntry<bool> EnableAutoCloseDoors { get; private set; }

	public static ConfigEntry<float> AutoCloseTimer { get; private set; }

	public static void Init(ConfigFile config)
	{
		Config = config;
		EnableAutoCloseDoors = config.Bind<bool>("General", "EnableAutoCloseDoors", true, "Enable AutoCloseDoors");
		AutoCloseTimer = config.Bind<float>("General", "AutoCloseTimer", 2f, "How many second(s) to wait before door is automatically closed");
	}

	public static void Save()
	{
		EnableAutoCloseDoors.Value = AutoCloseDoor.isAutoCloseDoor;
		AutoCloseTimer.Value = AutoCloseDoor.AutoCloseTimer;
		Config.Save();
	}
}
public static class LogUtil
{
	public static ManualLogSource Logger;

	public static void Init(ManualLogSource logger)
	{
		Logger = logger;
	}

	public static void LogMessage(object data)
	{
		Logger.LogMessage(data);
	}

	public static void LogInfo(object data)
	{
		Logger.LogInfo(data);
	}

	public static void LogError(object data)
	{
		Logger.LogError(data);
	}
}
namespace AutoCloseDoors
{
	internal static class Core
	{
		public static bool _hasInitialized = false;

		private static MonoBehaviour monoBehaviour;

		public static World Server { get; } = GetWorld() ?? throw new Exception("There is no Server world (yet)");


		public static EntityManager EntityManager { get; } = Server.EntityManager;


		internal static void InitializeAfterLoaded()
		{
			if (!_hasInitialized)
			{
				AutoCloseDoor.isAutoCloseDoor = AutoCloseDoorsConfig.EnableAutoCloseDoors.Value;
				AutoCloseDoor.AutoCloseTimer = AutoCloseDoorsConfig.AutoCloseTimer.Value;
				_hasInitialized = true;
				LogUtil.LogInfo("InitializeAfterLoaded completed");
			}
		}

		private static World GetWorld()
		{
			return ((IEnumerable<World>)World.s_AllWorlds.ToArray()).FirstOrDefault((Func<World, bool>)((World world) => world.Name == "Server"));
		}

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if ((Object)(object)monoBehaviour == (Object)null)
			{
				GameObject val = new GameObject("AutoCloseDoors");
				monoBehaviour = (MonoBehaviour)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
				Object.DontDestroyOnLoad((Object)val);
			}
			return monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}

		public static void StopCoroutine(Coroutine coroutine)
		{
			if (!((Object)(object)monoBehaviour == (Object)null))
			{
				monoBehaviour.StopCoroutine(coroutine);
			}
		}
	}
	[BepInPlugin("io.midon.AutoCloseDoors", "AutoCloseDoors", "3.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		[CompilerGenerated]
		private sealed class <RefreshDoorList>d__4 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <RefreshDoorList>d__4(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Expected O, but got Unknown
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
				}
				else
				{
					<>1__state = -1;
				}
				if (AutoCloseDoor.isAutoCloseDoor)
				{
					AutoCloseDoor.InitializeAutoClose();
				}
				<>2__current = (object)new WaitForSeconds(5f);
				<>1__state = 1;
				return true;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private Harmony _harmony;

		public override void Load()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			LogUtil.Init(((BasePlugin)this).Log);
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val;
			if (Application.productName != "VRisingServer")
			{
				ManualLogSource log = ((BasePlugin)this).Log;
				val = new BepInExInfoLogInterpolatedStringHandler(56, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("io.midon.AutoCloseDoors");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("3.1.0");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" NOT loaded. This is a server mod only.!");
				}
				log.LogInfo(val);
				return;
			}
			AutoCloseDoorsConfig.Init(((BasePlugin)this).Config);
			ManualLogSource log2 = ((BasePlugin)this).Log;
			val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("io.midon.AutoCloseDoors");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("3.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log2.LogInfo(val);
			_harmony = new Harmony("io.midon.AutoCloseDoors");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			CommandRegistry.RegisterAll();
			RconCommandRegistrar.RegisterAll();
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			RconCommandRegistrar.UnregisterAssembly();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}

		public void OnGameInitialized()
		{
			Core.InitializeAfterLoaded();
			Core.StartCoroutine(RefreshDoorList());
		}

		[IteratorStateMachine(typeof(<RefreshDoorList>d__4))]
		public static IEnumerator RefreshDoorList()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RefreshDoorList>d__4(0);
		}
	}
	internal static class Helper
	{
		public static void EnableMod()
		{
			AutoCloseDoor.isAutoCloseDoor = true;
			AutoCloseDoorsConfig.Save();
		}

		public static void DisableMod()
		{
			AutoCloseDoor.isAutoCloseDoor = false;
			AutoCloseDoorsConfig.Save();
			AutoCloseDoor.RevertAutoClose();
		}

		public static void SetModTimer(float time)
		{
			AutoCloseDoor.AutoCloseTimer = time;
			AutoCloseDoorsConfig.Save();
			AutoCloseDoor.RevertAutoClose();
			AutoCloseDoor.InitializeAutoClose();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "io.midon.AutoCloseDoors";

		public const string PLUGIN_NAME = "AutoCloseDoors";

		public const string PLUGIN_VERSION = "3.1.0";
	}
}
namespace AutoCloseDoors.Systems
{
	public static class AutoCloseDoor
	{
		public static bool isAutoCloseDoor = false;

		public static float AutoCloseTimer = 2f;

		public static EntityManager em = Core.EntityManager;

		public static void DoorReceiver(Entity entity, EntityManager em)
		{
			//IL_0002: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			if (((EntityManager)(ref em)).HasComponent<Door>(entity) && ((EntityManager)(ref em)).HasComponent<CastleHeartConnection>(entity))
			{
				Door componentData = ((EntityManager)(ref em)).GetComponentData<Door>(entity);
				if (isAutoCloseDoor)
				{
					componentData.AutoCloseTime = AutoCloseTimer;
					((EntityManager)(ref em)).SetComponentData<Door>(entity, componentData);
				}
			}
		}

		public static void RevertAutoClose()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0042: Unknown result type (might be due to invalid IL or missing references)
			//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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<Door>() });
			val.Options = (EntityQueryOptions)2;
			array[0] = val;
			EntityQuery val2 = ((EntityManager)(ref em)).CreateEntityQuery((EntityQueryDesc[])(object)array);
			NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			if (val3.Length > 0)
			{
				Enumerator<Entity> enumerator = val3.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					Door componentData = ((EntityManager)(ref em)).GetComponentData<Door>(current);
					componentData.AutoCloseTime = 0f;
					((EntityManager)(ref em)).SetComponentData<Door>(current, componentData);
				}
			}
		}

		public static void InitializeAutoClose()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (!isAutoCloseDoor)
			{
				return;
			}
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<Door>() });
			val.Options = (EntityQueryOptions)2;
			array[0] = val;
			EntityQuery val2 = ((EntityManager)(ref em)).CreateEntityQuery((EntityQueryDesc[])(object)array);
			NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			if (val3.Length > 0)
			{
				Enumerator<Entity> enumerator = val3.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					Door componentData = ((EntityManager)(ref em)).GetComponentData<Door>(current);
					componentData.AutoCloseTime = AutoCloseTimer;
					((EntityManager)(ref em)).SetComponentData<Door>(current, componentData);
				}
			}
		}
	}
}
namespace AutoCloseDoors.Hooks
{
	[HarmonyPatch(typeof(OpenDoorSystem), "OnUpdate")]
	public class OpenDoorSystem_Patch
	{
		private static void Prefix(OpenDoorSystem __instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_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_001e: 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_0028: 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)
			if (AutoCloseDoor.isAutoCloseDoor)
			{
				EntityQuery _query_1834203323_ = __instance.__query_1834203323_0;
				Enumerator<Entity> enumerator = ((EntityQuery)(ref _query_1834203323_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
				while (enumerator.MoveNext())
				{
					AutoCloseDoor.DoorReceiver(enumerator.Current, ((ComponentSystemBase)__instance).EntityManager);
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameBootstrap), "Start")]
	public static class GameBootstrapStart_Patch
	{
		public static void Postfix()
		{
			new Plugin().OnGameInitialized();
		}
	}
	[HarmonyPatch(typeof(GameBootstrap), "OnApplicationQuit")]
	public static class GameBootstrapQuit_Patch
	{
		public static void Prefix()
		{
			AutoCloseDoor.RevertAutoClose();
		}
	}
}
namespace AutoCloseDoors.Commands
{
	[CommandGroup("acd", null)]
	public static class AutoCloseDoorCommands
	{
		[Command("disable", null, "", "Command to globally disable AutoCloseDoors", null, true)]
		public static void DisableCommand(ChatCommandContext ctx)
		{
			Helper.DisableMod();
			ctx.Reply("AutoCloseDoor globally disabled");
		}

		[Command("enable", null, "", "Command to globally enable AutoCloseDoors", null, true)]
		public static void EnableCommand(ChatCommandContext ctx)
		{
			Helper.EnableMod();
			ctx.Reply("AutoCloseDoor globally enabled");
		}

		[Command("time", null, "time <seconds>", "Set the AutoCloseDoors timer", null, true)]
		public static void TimeCommand(ChatCommandContext ctx, string time)
		{
			if (float.TryParse(time, out var result))
			{
				Helper.SetModTimer(result);
				ctx.Reply("AutoCloseDoor time set");
			}
			else
			{
				ctx.Reply("Invalid timer format, please use int or float");
			}
		}
	}
	[RconCommandCategory("AutoCloseDoors")]
	public class AutoCloseDoorRconCommands
	{
		[RconCommand("disable", "Disable AutoCloseDoors.", null)]
		public static string DisableCommand()
		{
			Helper.DisableMod();
			return "AutoCloseDoors disabled";
		}

		[RconCommand("enable", "Enable AutoCloseDoors.", null)]
		public static string EnableCommand()
		{
			Helper.EnableMod();
			return "AutoCloseDoors enabled";
		}

		[RconCommand("time", "Set the AutoCloseDoors timer in seconds.", null)]
		public static string TimeCommand(string time)
		{
			if (float.TryParse(time, out var result))
			{
				Helper.SetModTimer(result);
				return "AutoCloseDoor time set";
			}
			return "Invalid timer format, please use int or float";
		}
	}
}
namespace ScarletRCON.Shared
{
	[AttributeUsage(AttributeTargets.Class)]
	public class RconCommandCategoryAttribute : Attribute
	{
		public string Name { get; }

		public RconCommandCategoryAttribute(string categoryName)
		{
			Name = categoryName;
			base..ctor();
		}
	}
	[AttributeUsage(AttributeTargets.Method)]
	public class RconCommandAttribute : Attribute
	{
		public string Name { get; set; }

		public string? Description { get; set; }

		public string? Usage { get; set; }

		public RconCommandAttribute(string name, string? description = null, string? usage = null)
		{
			Name = name;
			Description = description;
			Usage = usage;
			base..ctor();
		}
	}
	public static class RconCommandRegistrar
	{
		private static bool? _isScarletRconAvailable;

		public static bool IsScarletRconAvailable()
		{
			bool valueOrDefault = _isScarletRconAvailable.GetValueOrDefault();
			if (!_isScarletRconAvailable.HasValue)
			{
				valueOrDefault = Type.GetType("ScarletRCON.CommandSystem.CommandHandler, ScarletRCON") != null;
				_isScarletRconAvailable = valueOrDefault;
			}
			return _isScarletRconAvailable.Value;
		}

		public static void RegisterAll()
		{
			if (!IsScarletRconAvailable())
			{
				return;
			}
			Assembly callingAssembly = Assembly.GetCallingAssembly();
			string item = callingAssembly.GetName().Name?.ToLowerInvariant() + ".";
			List<(string, string, MethodInfo, string, string, string)> list = new List<(string, string, MethodInfo, string, string, string)>();
			Type[] types = callingAssembly.GetTypes();
			foreach (Type obj in types)
			{
				string item2 = obj.GetCustomAttribute<RconCommandCategoryAttribute>()?.Name ?? "Uncategorized";
				MethodInfo[] methods = obj.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					RconCommandAttribute customAttribute = methodInfo.GetCustomAttribute<RconCommandAttribute>();
					if (customAttribute == null)
					{
						continue;
					}
					string text = customAttribute.Usage;
					if (string.IsNullOrWhiteSpace(text))
					{
						ParameterInfo[] parameters = methodInfo.GetParameters();
						text = ((parameters.Length == 0) ? "" : string.Join(" ", parameters.Select((ParameterInfo p) => (!(p.ParameterType == typeof(List<string>))) ? ("<" + p.Name + ">") : "<...text>")));
					}
					list.Add((item2, item, methodInfo, customAttribute.Name, customAttribute.Description, text ?? ""));
				}
			}
			Type? type = Type.GetType("ScarletRCON.CommandSystem.CommandHandler, ScarletRCON");
			MethodInfo methodInfo2 = type?.GetMethod("RegisterExternalCommandsBatch", BindingFlags.Static | BindingFlags.Public);
			if (type == null)
			{
				throw new InvalidOperationException("ScarletRCON.CommandSystem.CommandHandler not found.");
			}
			if (methodInfo2 == null)
			{
				throw new InvalidOperationException("ScarletRCON.CommandSystem.CommandHandler.RegisterExternalCommandsBatch not found.");
			}
			methodInfo2.Invoke(null, new object[1] { list });
		}

		public static void UnregisterAssembly(Assembly? assembly = null)
		{
			if (IsScarletRconAvailable())
			{
				if ((object)assembly == null)
				{
					assembly = Assembly.GetCallingAssembly();
				}
				Type? type = Type.GetType("ScarletRCON.CommandSystem.CommandHandler, ScarletRCON");
				MethodInfo methodInfo = type?.GetMethod("UnregisterAssembly", BindingFlags.Static | BindingFlags.Public);
				if (type == null)
				{
					throw new InvalidOperationException("ScarletRCON.CommandSystem.CommandHandler not found.");
				}
				if (methodInfo == null)
				{
					throw new InvalidOperationException("ScarletRCON.CommandSystem.CommandHandler.UnregisterAssembly not found.");
				}
				methodInfo.Invoke(null, new object[1] { assembly });
			}
		}
	}
}