Decompiled source of MorDoor v1.1.0

MorDoor.dll

Decompiled 6 months 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MorDoor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MorDoor")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ed549bb4-dab5-41ab-aee5-b5eb66f4a045")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace MorDoor
{
	[BepInPlugin("mayo.is.an.instrument.MorDoor", "MorDoor", "1.1.0")]
	public class MorDoor : BaseUnityPlugin
	{
		public const string PluginGuid = "mayo.is.an.instrument.MorDoor";

		public const string PluginName = "MorDoor";

		public const string PluginVersion = "1.1.0";

		public static List<Piece> Doors = new List<Piece>();

		public static List<Piece> Pieces = new List<Piece>();

		public static bool PlayerInitiated = true;

		private Harmony _harmony;

		public void Awake()
		{
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "mayo.is.an.instrument.MorDoor");
		}

		public void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		public static void GetDoors(Humanoid character)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Piece.GetAllPiecesInRadius(((Component)character).transform.position, 10f, Pieces);
			foreach (Piece piece in Pieces)
			{
				if (piece.m_name == "$piece_wooddoor" || piece.m_name == "$piece_woodgate" || piece.m_name == "$piece_irongate" || piece.m_name == "$piece_woodwindowshutter" || piece.m_name == "$piece_darkwoodgate")
				{
					Doors.Add(piece);
				}
			}
			Pieces = new List<Piece>();
		}

		public static bool DoubleDoorCheck(Door point, Door next)
		{
			//IL_0007: 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_002c: 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_004c: 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_0071: 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_008c: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (Vector3.Distance(((Component)point).transform.position, ((Component)next).transform.position) <= 3f && ((Component)point).transform.position != ((Component)next).transform.position && ((Component)point).transform.position.y == ((Component)next).transform.position.y && Math.Abs(Math.Abs(Vector3.SignedAngle(((Component)point).transform.position - ((Component)next).transform.position, ((Component)point).transform.forward, Vector3.up)) - 90f) <= 0.1f && Math.Abs(Quaternion.Angle(((Component)point).transform.rotation, ((Component)next).transform.rotation) - 180f) <= 0.5f && (float)(point.m_nview.GetZDO().GetInt(ZDOVars.s_state, 0) + next.m_nview.GetZDO().GetInt(ZDOVars.s_state, 0)) == 0f)
			{
				return true;
			}
			return false;
		}
	}
	public class PluginConfig
	{
		public static ConfigEntry<bool> IsModEnabled { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			IsModEnabled = config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod.");
		}
	}
}
namespace MorDoor.Patches
{
	[HarmonyPatch(typeof(Door))]
	internal class DoorPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Interact")]
		private static void InteractPrefix(Humanoid character, bool hold, bool alt, Door __instance)
		{
			if (!PluginConfig.IsModEnabled.Value || !MorDoor.PlayerInitiated)
			{
				return;
			}
			MorDoor.GetDoors(character);
			MorDoor.PlayerInitiated = false;
			Door val = default(Door);
			foreach (Piece door in MorDoor.Doors)
			{
				if (((Component)door.m_nview).gameObject.TryGetComponent<Door>(ref val) && MorDoor.DoubleDoorCheck(__instance, val))
				{
					val.Interact(character, hold, alt);
				}
			}
			MorDoor.Doors.Clear();
			MorDoor.PlayerInitiated = true;
		}
	}
}