Decompiled source of ServersideQoL AutoDoors v2.0.0

ServersideQoL.AutoDoors.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using ServersideQoL.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ArgusMagnus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("ArgusMagnus")]
[assembly: AssemblyDescription("Automatically closes doors")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+cdafe98fecdc9c33d99ba13f064e37dcaca41712")]
[assembly: AssemblyProduct("ServersideQoL.AutoDoors")]
[assembly: AssemblyTitle("ServersideQoL.AutoDoors")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: AssemblyVersion("2.0.0.0")]
[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 ServersideQoL.AutoDoors
{
	[BepInPlugin("ArgusMagnus.ServersideQoL.AutoDoors", "ServersideQoL.AutoDoors", "2.0.0")]
	public sealed class AutoDoorsPlugin : ServersideQoLPluginBase<AutoDoorsPlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.AutoDoors";

		public const string PluginGuid = "ArgusMagnus.ServersideQoL.AutoDoors";

		public const string PluginVersion = "2.0.0";

		public const string PluginInformationalVersion = "2.0.0";

		private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639245732084466982L, default(TimeSpan));

		protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger)
		{
			return new Config(configFile, logger);
		}

		protected override void RegisterProcessors(IProcessorCollection processors)
		{
			processors.Add<DoorProcessor>();
		}

		private void Awake()
		{
		}
	}
	public sealed class Config : ConfigBase<Config>
	{
		private const string Section = "AutoDoors";

		public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "AutoDoors", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated<Config>)null, "Enabled");

		public ConfigEntry<float> AutoCloseMinPlayerDistance { get; } = ConfigBase<Config>.BindEx<float>(cfg, "AutoDoors", 4f, FormattableString.Invariant($"Minimum distance all players must have to the door before it is closed."), (AcceptableValueBase)null, (Deprecated<Config>)null, "AutoCloseMinPlayerDistance");

		public ConfigEntry<float> AutoCloseMinOpenSeconds { get; } = ConfigBase<Config>.BindEx<float>(cfg, "AutoDoors", 2f, FormattableString.Invariant($"Minimum time the door must have been open before it is closed."), (AcceptableValueBase)null, (Deprecated<Config>)null, "AutoCloseMinOpenSeconds");

		public Config(ConfigFile cfg, Logger logger)
			: base(cfg, logger)
		{
		}
	}
	[Processor("f91beb92-c76b-43d5-91d4-82c1f7de2929")]
	public sealed class DoorProcessor : Processor<DoorProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(Door Door) : ProcessorPrefabInfo()
		{
			public override bool IsValid
			{
				get
				{
					Door door = Door;
					if (door != null && door.m_keyItem == null)
					{
						return !door.m_canNotBeClosed;
					}
					return false;
				}
			}

			[CompilerGenerated]
			public override string ToString()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("PrefabInfo");
				stringBuilder.Append(" { ");
				if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append('}');
				return stringBuilder.ToString();
			}

			[CompilerGenerated]
			protected override bool PrintMembers(StringBuilder builder)
			{
				if (((ProcessorPrefabInfo)this).PrintMembers(builder))
				{
					builder.Append(", ");
				}
				builder.Append("Door = ");
				builder.Append(Door);
				return true;
			}

			[CompilerGenerated]
			public override int GetHashCode()
			{
				return ((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<Door>.Default.GetHashCode(Door);
			}

			[CompilerGenerated]
			public sealed override bool Equals(ProcessorPrefabInfo? other)
			{
				return ((object)this).Equals((object?)other);
			}

			[CompilerGenerated]
			public bool Equals(PrefabInfo? other)
			{
				if ((object)this != other)
				{
					if (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other))
					{
						return EqualityComparer<Door>.Default.Equals(Door, other.Door);
					}
					return false;
				}
				return true;
			}

			[CompilerGenerated]
			private PrefabInfo(PrefabInfo original)
				: base((ProcessorPrefabInfo)(object)original)
			{
				Door = original.Door;
			}
		}

		private readonly Dictionary<ServersideQoLZDO, Timestamp> _closeAfter = new Dictionary<ServersideQoLZDO, Timestamp>();

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//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_000b: 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_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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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)
			ZDOVars vars = zdo.Vars;
			PlayerID val = default(PlayerID);
			val = ((ZDOVars)(ref vars)).GetCreator(val);
			if (((PlayerID)(ref val)).Value == 0L)
			{
				return (ProcessResult)2;
			}
			vars = zdo.Vars;
			if (((ZDOVars)(ref vars)).GetState(0) == 0)
			{
				if (_closeAfter.Remove(zdo))
				{
					zdo.Destroyed -= OnDoorDestroyed;
				}
				return (ProcessResult)0;
			}
			if (!Processor.CheckMinDistance(peers, zdo, ConfigBase<Config>.Instance.AutoCloseMinPlayerDistance.Value))
			{
				return ((Processor)this).ScheduleReprocessing(0f);
			}
			Timestamp now;
			if (!_closeAfter.TryGetValue(zdo, out var value))
			{
				Dictionary<ServersideQoLZDO, Timestamp> closeAfter = _closeAfter;
				now = Timestamp.Now;
				closeAfter.Add(zdo, value = ((Timestamp)(ref now)).AddSeconds(ConfigBase<Config>.Instance.AutoCloseMinOpenSeconds.Value));
				zdo.Destroyed += OnDoorDestroyed;
				return ((Processor)this).ScheduleReprocessing(ConfigBase<Config>.Instance.AutoCloseMinOpenSeconds.Value);
			}
			float seconds = ((Timestamp)(ref value)).Seconds;
			now = Timestamp.Now;
			float num = seconds - ((Timestamp)(ref now)).Seconds;
			if (num > 0f)
			{
				return ((Processor)this).ScheduleReprocessing(num);
			}
			vars = zdo.Vars;
			((ZDOVars)(ref vars)).SetState(0, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoDoors\\DoorProcessor.cs", 43);
			if (_closeAfter.Remove(zdo))
			{
				zdo.Destroyed -= OnDoorDestroyed;
			}
			return (ProcessResult)0;
		}

		private void OnDoorDestroyed(ServersideQoLZDO zdo)
		{
			_closeAfter.Remove(zdo);
		}
	}
}