Decompiled source of ForceUnlockDoors v2.0.2

ForceUnlockDoors_BPE5.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Gloomwood.Input;
using Gloomwood.World;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ForceUnlockDoors_BPE5")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("2.0.2.0")]
[assembly: AssemblyInformationalVersion("2.0.2")]
[assembly: AssemblyProduct("ES-ForceUnlockDoors")]
[assembly: AssemblyTitle("ForceUnlockDoors_BPE5")]
[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;
		}
	}
}
namespace ForceUnlockDoors_BPE5
{
	[BepInPlugin("EverSkiesVR.ForceUnlockDoors", "ES-ForceUnlockDoors", "2.0.2")]
	public class ForceUnlockDoors : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Door), "CreateInputEvents")]
		public static class Door_CreateInputEvents_Patch
		{
			private static void Postfix(Door __instance)
			{
				Logger.LogInfo((object)$"[Log] CreateInputEvents: Door #{((Object)__instance).GetInstanceID()}");
				MethodInfo method = typeof(Door).GetMethod("AddInputEvent", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[5]
				{
					typeof(InputActions),
					typeof(InputActivateTypes),
					typeof(float),
					typeof(float),
					typeof(UnityAction<GameObject>)
				}, null);
				if (method == null)
				{
					Logger.LogWarning((object)"[Warn] Could not find AddInputEvent overload");
					return;
				}
				Logger.LogInfo((object)"[Log] Found AddInputEvent overload");
				UnityAction<GameObject> val = delegate(GameObject inst)
				{
					OnInputInteractForceUnlock(__instance, inst);
				};
				try
				{
					method.Invoke(__instance, new object[5]
					{
						(object)(InputActions)23,
						(object)(InputActivateTypes)2,
						0f,
						0f,
						val
					});
					Logger.LogInfo((object)"[Log] Successfully injected InputEvent");
				}
				catch (Exception arg)
				{
					Logger.LogError((object)$"[Error] Error injecting input event: {arg}");
				}
			}
		}

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin EverSkies-ForceUnlockDoors is loaded!");
			Harmony val = new Harmony("EverSkiesVR.ForceUnlockDoors");
			val.PatchAll();
			Logger.LogInfo((object)"[Log] Harmony patches applied");
		}

		private static void OnInputInteractForceUnlock(Door door, GameObject instigator)
		{
			Logger.LogInfo((object)$"[Log] Input detected: Door #{((Object)door).GetInstanceID()} by {instigator}");
			int keyLockCount = door.KeyLockCount;
			for (int i = 0; i < keyLockCount; i++)
			{
				KeyLock keyLock = door.GetKeyLock(i);
				if ((Object)(object)keyLock != (Object)null && keyLock.IsLocked)
				{
					Logger.LogInfo((object)$"[Log] Forcing unlock on KeyLock: Door #{((Object)door).GetInstanceID()}");
					((LockEntity)keyLock).Unlock(instigator, false, true, true);
				}
				else
				{
					Logger.LogWarning((object)$"[Warn] No locked KeyLock found: Door #{((Object)door).GetInstanceID()}");
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ForceUnlockDoors_BPE5";

		public const string PLUGIN_NAME = "ES-ForceUnlockDoors";

		public const string PLUGIN_VERSION = "2.0.2";
	}
}