Decompiled source of AutoCloseDoors v2.0.2

AutoCloseDoors.dll

Decompiled 3 weeks ago
using System;
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 AutoCloseDoors.Systems;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Systems;
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("AutoCloseDoors")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Automatically close doors")]
[assembly: AssemblyFileVersion("2.0.2.0")]
[assembly: AssemblyInformationalVersion("2.0.2+4262b76a4208eb9723d936e16a3c0c32287729a8")]
[assembly: AssemblyProduct("AutoCloseDoors")]
[assembly: AssemblyTitle("AutoCloseDoors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.2.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.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
{
	[BepInPlugin("AutoCloseDoors", "AutoCloseDoors", "2.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static bool isInitialized;

		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>("AutoCloseDoors");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("2.0.2");
					((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>("AutoCloseDoors");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("2.0.2");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log2.LogInfo(val);
			_harmony = new Harmony("AutoCloseDoors");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			CommandRegistry.RegisterAll();
		}

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

		public void OnGameInitialized()
		{
			if (!isInitialized)
			{
				AutoCloseDoor.isAutoCloseDoor = AutoCloseDoorsConfig.EnableAutoCloseDoors.Value;
				AutoCloseDoor.AutoCloseTimer = AutoCloseDoorsConfig.AutoCloseTimer.Value;
				isInitialized = true;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "AutoCloseDoors";

		public const string PLUGIN_NAME = "AutoCloseDoors";

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

		public static float AutoCloseTimer = 2f;

		public static EntityManager em = VWorld.Server.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();
		}
	}
	[HarmonyPatch(typeof(SettingsManager), "VerifyServerGameSettings")]
	public class ServerGameSetting_Patch
	{
		private static bool isInitialized;

		public static void Postfix()
		{
			if (!isInitialized)
			{
				AutoCloseDoor.RevertAutoClose();
				if (AutoCloseDoor.isAutoCloseDoor)
				{
					AutoCloseDoor.InitializeAutoClose();
				}
				isInitialized = true;
			}
		}
	}
}
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)
		{
			AutoCloseDoor.isAutoCloseDoor = false;
			AutoCloseDoorsConfig.Save();
			AutoCloseDoor.RevertAutoClose();
			ctx.Reply("AutoCloseDoor globally disabled");
		}

		[Command("enable", null, "", "Command to globally enable AutoCloseDoors", null, true)]
		public static void EnableCommand(ChatCommandContext ctx)
		{
			AutoCloseDoor.isAutoCloseDoor = true;
			AutoCloseDoorsConfig.Save();
			AutoCloseDoor.InitializeAutoClose();
			ctx.Reply("AutoCloseDoor globally enabled");
		}

		[Command("time", null, "time <seconds>", "Set the AutoCloseDoors timer", null, true)]
		public static void TimeCommand(ChatCommandContext ctx, string time)
		{
			AutoCloseDoor.AutoCloseTimer = float.Parse(time, CultureInfo.InvariantCulture);
			AutoCloseDoorsConfig.Save();
			AutoCloseDoor.RevertAutoClose();
			AutoCloseDoor.InitializeAutoClose();
			ctx.Reply("AutoCloseDoor time set");
		}
	}
}