Decompiled source of MorDoor v2.1.0

MorDoor.dll

Decompiled 5 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("2.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.0.0")]
[module: UnverifiableCode]
namespace MorDoor
{
	[BepInPlugin("mayo.is.an.instrument.MorDoor", "MorDoor", "2.1.0")]
	public class MorDoor : BaseUnityPlugin
	{
		public const string PluginGuid = "mayo.is.an.instrument.MorDoor";

		public const string PluginName = "MorDoor";

		public const string PluginVersion = "2.1.0";

		public static List<Piece> Doors = 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 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) <= 5f && ((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)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!PluginConfig.IsModEnabled.Value || !MorDoor.PlayerInitiated || !Object.op_Implicit((Object)(object)character) || !Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)__instance.m_nview))
			{
				return;
			}
			MorDoor.Doors = new List<Piece>();
			Piece.GetAllPiecesInRadius(((Component)character).transform.position, 10f, MorDoor.Doors);
			__instance.m_nview.ClaimOwnership();
			MorDoor.PlayerInitiated = false;
			Door val = default(Door);
			foreach (Piece door in MorDoor.Doors)
			{
				if (!Object.op_Implicit((Object)(object)door) || !Object.op_Implicit((Object)(object)door.m_nview) || !Object.op_Implicit((Object)(object)((Component)door.m_nview).gameObject))
				{
					MorDoor.PlayerInitiated = true;
					return;
				}
				if (((Component)door.m_nview).gameObject.TryGetComponent<Door>(ref val) && MorDoor.DoubleDoorCheck(__instance, val))
				{
					val.m_nview.ClaimOwnership();
					val.Interact(character, hold, alt);
				}
			}
			MorDoor.Doors.Clear();
			MorDoor.PlayerInitiated = true;
		}
	}
}