Decompiled source of ServersideQoL AutoDoors BETA v1.99.8

ServersideQoL.AutoDoors.dll

Decompiled 8 hours 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;

[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("1.99.8.0")]
[assembly: AssemblyInformationalVersion("1.99.8-beta+328851184cc278c858ffbc70e717af9f9d7b6973")]
[assembly: AssemblyProduct("ServersideQoL.AutoDoors")]
[assembly: AssemblyTitle("ServersideQoL.AutoDoors")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: AssemblyVersion("1.99.8.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", "1.99.8")]
	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 = "1.99.8";

		public const string PluginInformationalVersion = "1.99.8-beta";

		private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639215507820225253L, 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()
		{
			ServersideQoLPluginBase<AutoDoorsPlugin, Config>.Logger.LogWarning((object)string.Format("You are running a pre-release version: {0} ({1})", "1.99.8-beta", BuildTimestamp.LocalDateTime));
		}
	}
	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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			ZDOVars vars = zdo.Vars;
			if (((ZDOVars)(ref vars)).GetCreator(0L) != 0L)
			{
				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))
				{
					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;
						zdo.DelaySchedulingFor(ConfigBase<Config>.Instance.AutoCloseMinOpenSeconds.Value);
						return (ProcessResult)32;
					}
					float seconds = ((Timestamp)(ref value)).Seconds;
					now = Timestamp.Now;
					float num = seconds - ((Timestamp)(ref now)).Seconds;
					if (num > 0f)
					{
						zdo.DelaySchedulingFor(num);
						return (ProcessResult)32;
					}
					vars = zdo.Vars;
					((ZDOVars)(ref vars)).SetState(0, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoDoors\\DoorProcessor.cs", 45);
					if (_closeAfter.Remove(zdo))
					{
						zdo.Destroyed -= OnDoorDestroyed;
					}
					return (ProcessResult)0;
				}
				return (ProcessResult)32;
			}
			return (ProcessResult)2;
		}

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