Decompiled source of DoorBreach v1.1.0

Nyxchrono-DoorBreach.dll

Decompiled a year 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.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On;
using UnityEngine;

[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("Nyxchrono-DoorBreach")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("DoorBreach is a mod for Lethal Company that allows players to hit a locked door many times with a shovel to open it.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+423a864e5a383142af069a7278a8352f574c8f68")]
[assembly: AssemblyProduct("DoorBreach")]
[assembly: AssemblyTitle("Nyxchrono-DoorBreach")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.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 Nyxchrono.DoorBreach
{
	public class Components
	{
		public class DoorHitInfo : MonoBehaviour
		{
			public int NumOfHits;

			public DoorLock Lock;

			public void Start()
			{
				NumOfHits = 0;
				Lock = ((Component)this).GetComponent<DoorLock>();
				if (Lock != null && Lock.isLocked)
				{
					NumOfHits = new Random().Next(Plugin._configGeneralMinHits.Value, Plugin._configGeneralMaxHits.Value);
					Plugin.LogSource.LogDebug((object)$"Door ({((Object)((Component)Lock).gameObject).GetInstanceID()}) will take {NumOfHits} hits");
				}
			}

			public void OnHit()
			{
				if (--NumOfHits <= 0)
				{
					OpenDoor(Lock);
				}
				else
				{
					Plugin.LogSource.LogDebug((object)string.Format("Door ({0}) has {1} remaining: {2}", ((Object)((Component)Lock).gameObject).GetInstanceID(), "NumOfHits", NumOfHits));
				}
			}

			public void OpenDoor(DoorLock door)
			{
				if (door.isLocked)
				{
					Plugin.LogSource.LogDebug((object)$"Unlocking door ({((Object)((Component)door).gameObject).GetInstanceID()})");
					door.UnlockDoorServerRpc();
				}
				if (!Utils.GetInstanceField<bool>(typeof(DoorLock), door, "isDoorOpened"))
				{
					Plugin.LogSource.LogDebug((object)$"Opening door ({((Object)((Component)door).gameObject).GetInstanceID()})");
					((Component)door).gameObject.GetComponent<AnimatedObjectTrigger>().TriggerAnimationNonPlayer(true, true, false);
					door.OpenDoorAsEnemyServerRpc();
				}
			}
		}
	}
	public class Hooks
	{
		internal static bool IsStartOfRoundLockingDoors;

		internal static void RoundManager_SetLockedDoors(orig_SetLockedDoors orig, RoundManager self, Vector3 mainEntrancePosition)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			IsStartOfRoundLockingDoors = true;
			orig.Invoke(self, mainEntrancePosition);
			IsStartOfRoundLockingDoors = false;
			int num = 0;
			DoorLock[] array = Object.FindObjectsByType<DoorLock>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				((Component)array[i]).gameObject.AddComponent<Components.DoorHitInfo>();
				num++;
			}
			Plugin.LogSource.LogDebug((object)string.Format("Added {0} to {1} doors", "DoorHitInfo", num));
		}

		internal static void Shovel_HitShovel(orig_HitShovel orig, Shovel self, bool cancel)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, cancel);
			Transform transform = ((Component)((GrabbableObject)self).playerHeldBy.gameplayCamera).transform;
			RaycastHit[] array = Physics.SphereCastAll(transform.position + transform.right * -0.35f, 0.75f, transform.forward, 1f, 512, (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				Components.DoorHitInfo component = ((Component)((RaycastHit)(ref val)).collider).gameObject.GetComponent<Components.DoorHitInfo>();
				if ((Object)(object)component != (Object)null)
				{
					component.OnHit();
					break;
				}
			}
		}

		internal static void DoorLock_LockDoor(orig_LockDoor orig, DoorLock self, float timeToLockPick = 30f)
		{
			orig.Invoke(self, timeToLockPick);
			if (!IsStartOfRoundLockingDoors)
			{
				Plugin.LogSource.LogDebug((object)"Locking door after RoundManager.SetLockedDoors");
				Components.DoorHitInfo component = ((Component)self).GetComponent<Components.DoorHitInfo>();
				if (component != null)
				{
					component.NumOfHits = new Random().Next(Plugin._configGeneralMinHits.Value, Plugin._configGeneralMaxHits.Value);
				}
			}
		}
	}
	[BepInPlugin("Nyxchrono-DoorBreach", "DoorBreach", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_HitShovel <0>__Shovel_HitShovel;

			public static hook_SetLockedDoors <1>__RoundManager_SetLockedDoors;

			public static hook_LockDoor <2>__DoorLock_LockDoor;
		}

		internal static ConfigEntry<bool> _configGeneralEnabled;

		internal static ConfigEntry<int> _configGeneralMinHits;

		internal static ConfigEntry<int> _configGeneralMaxHits;

		internal static ManualLogSource LogSource { get; set; }

		private void LoadConfig()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0039: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0074: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00af: Expected O, but got Unknown
			_configGeneralEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("General", "Enabled"), true, new ConfigDescription("Whether to enable the mod or not", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { true, false }), Array.Empty<object>()));
			_configGeneralMinHits = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition("General", "MinHits"), 10, new ConfigDescription("The minimum number of hits required to open a locked door", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 999), Array.Empty<object>()));
			_configGeneralMaxHits = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition("General", "MaxHits"), 20, new ConfigDescription("The maximum number of hits required to open a locked door\nMAKE SURE THIS VALUE IS GREATER THAN MinHits!!!", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 999), Array.Empty<object>()));
			if (_configGeneralMinHits.Value > _configGeneralMaxHits.Value)
			{
				LogSource.LogWarning((object)"_configGeneralMaxHits was less than _configGeneralMinHits!");
				LogSource.LogWarning((object)"Setting _configGeneralMaxHits to (_configGeneralMinHits * 2)");
				_configGeneralMaxHits.Value = _configGeneralMinHits.Value * 2;
			}
		}

		private void Awake()
		{
			LogSource = ((BaseUnityPlugin)this).Logger;
			LoadConfig();
			LogSource.LogInfo((object)"Nyxchrono-DoorBreach v1.1.0 is initializing");
			if (!_configGeneralEnabled.Value)
			{
				LogSource.LogInfo((object)"Nyxchrono-DoorBreach v1.1.0 is disabled due to config setting");
				return;
			}
			ApplyHooks();
			LogSource.LogInfo((object)"Nyxchrono-DoorBreach v1.1.0 has initialized");
		}

		private void OnDestroy()
		{
			LogSource.LogInfo((object)"Nyxchrono-DoorBreach v1.1.0 was unloaded!");
		}

		public void ApplyHooks()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			object obj = <>O.<0>__Shovel_HitShovel;
			if (obj == null)
			{
				hook_HitShovel val = Hooks.Shovel_HitShovel;
				<>O.<0>__Shovel_HitShovel = val;
				obj = (object)val;
			}
			Shovel.HitShovel += (hook_HitShovel)obj;
			object obj2 = <>O.<1>__RoundManager_SetLockedDoors;
			if (obj2 == null)
			{
				hook_SetLockedDoors val2 = Hooks.RoundManager_SetLockedDoors;
				<>O.<1>__RoundManager_SetLockedDoors = val2;
				obj2 = (object)val2;
			}
			RoundManager.SetLockedDoors += (hook_SetLockedDoors)obj2;
			object obj3 = <>O.<2>__DoorLock_LockDoor;
			if (obj3 == null)
			{
				hook_LockDoor val3 = Hooks.DoorLock_LockDoor;
				<>O.<2>__DoorLock_LockDoor = val3;
				obj3 = (object)val3;
			}
			DoorLock.LockDoor += (hook_LockDoor)obj3;
		}
	}
	public class Utils
	{
		internal const BindingFlags BindFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		internal static object GetInstanceField(Type type, object instance, string fieldName)
		{
			return type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(instance);
		}

		internal static T GetInstanceField<T>(Type type, object instance, string fieldName)
		{
			return (T)(type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(instance));
		}

		internal static FieldInfo GetInstanceFieldInfo(object instance, string fieldName)
		{
			return instance.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Nyxchrono-DoorBreach";

		public const string PLUGIN_NAME = "DoorBreach";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}