Decompiled source of ConfigurableLockpicker v0.0.3

ConfigurableLockpicker.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 ConfigurableLockpicker.NetcodePatcher;
using ConfigurableLockpicker.Patches;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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("ConfigurableLockpicker")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Makes The Lockpicker time configurable")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ConfigurableLockpicker")]
[assembly: AssemblyTitle("ConfigurableLockpicker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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 ConfigurableLockpicker
{
	internal class Networker : NetworkBehaviour
	{
		public static Networker Instance { get; private set; }

		public override void OnNetworkSpawn()
		{
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		public override void OnNetworkDespawn()
		{
			((NetworkBehaviour)this).OnNetworkDespawn();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void LockDoorServerRpc(ulong lockpickID, ulong doorID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_007e: 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)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2090514130u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, lockpickID);
					BytePacker.WriteValueBitPacked(val2, doorID);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2090514130u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					LockDoorClientRpc(lockpickID, doorID);
				}
			}
		}

		[ClientRpc]
		public void LockDoorClientRpc(ulong lockpickID, ulong doorID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_007e: 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)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(4089986782u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, lockpickID);
				BytePacker.WriteValueBitPacked(val2, doorID);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 4089986782u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			base.__rpc_exec_stage = (__RpcExecStage)0;
			Plugin.CustomLogger.LogWarning((object)$"[ClientRpc] LockDoorClientRpc called on client {NetworkManager.Singleton.LocalClientId}");
			if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(lockpickID, out var value) && NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(doorID, out var value2))
			{
				LockPicker componentInChildren = ((Component)value).gameObject.GetComponentInChildren<LockPicker>();
				DoorLock componentInChildren2 = ((Component)value2).gameObject.GetComponentInChildren<DoorLock>();
				if (Object.op_Implicit((Object)(object)componentInChildren) && Object.op_Implicit((Object)(object)componentInChildren2))
				{
					LockpickerPatch.startLocking(componentInChildren, componentInChildren2);
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(2090514130u, new RpcReceiveHandler(__rpc_handler_2090514130), "LockDoorServerRpc");
			((NetworkBehaviour)this).__registerRpc(4089986782u, new RpcReceiveHandler(__rpc_handler_4089986782), "LockDoorClientRpc");
			((NetworkBehaviour)this).__initializeRpcs();
		}

		private static void __rpc_handler_2090514130(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong lockpickID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref lockpickID);
				ulong doorID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref doorID);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((Networker)(object)target).LockDoorServerRpc(lockpickID, doorID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_4089986782(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong lockpickID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref lockpickID);
				ulong doorID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref doorID);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((Networker)(object)target).LockDoorClientRpc(lockpickID, doorID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "Networker";
		}
	}
	[BepInPlugin("Slayer6409.ConfigurableLockpicker", "Configurable_Lockpicker", "0.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Slayer6409.ConfigurableLockpicker";

		private const string modName = "Configurable_Lockpicker";

		private const string modVersion = "0.0.3";

		public static ConfigEntry<float> LockpickTime;

		public static ConfigEntry<bool> Relock;

		public static ConfigEntry<float> RelockTime;

		private readonly Harmony harmony = new Harmony("Slayer6409.ConfigurableLockpicker");

		public static ManualLogSource CustomLogger;

		public static GameObject NetworkerPrefab;

		public static AssetBundle LoadedAssets;

		public void configStuff()
		{
			LockpickTime = ((BaseUnityPlugin)this).Config.Bind<float>("Lockpicker", "Time", 10f, "How long should the lockpicker take");
			Relock = ((BaseUnityPlugin)this).Config.Bind<bool>("Lockpicker", "Relock", true, "Should the lockpicker be able to re-lock doors?");
			RelockTime = ((BaseUnityPlugin)this).Config.Bind<float>("Lockpicker", "Relock Time", 5f, "How long should it take to re-lock doors?");
		}

		private void Awake()
		{
			LoadedAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "configurablelockpicker"));
			NetcodeWeaver();
			NetworkerPrefab = LoadedAssets.LoadAsset<GameObject>("Networker");
			NetworkerPrefab.AddComponent<Networker>();
			CustomLogger = Logger.CreateLogSource("Slayer6409.ConfigurableLockpicker");
			configStuff();
			harmony.PatchAll();
			NetworkPrefabs.RegisterNetworkPrefab(NetworkerPrefab);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Configurable Lockpicker is loaded!");
		}

		private static void NetcodeWeaver()
		{
			try
			{
				Type[] types = Assembly.GetExecutingAssembly().GetTypes();
				Type[] array = types;
				foreach (Type type in array)
				{
					MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo[] array2 = methods;
					foreach (MethodInfo methodInfo in array2)
					{
						object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
						if (customAttributes.Length != 0)
						{
							methodInfo.Invoke(null, null);
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ConfigurableLockpicker";

		public const string PLUGIN_NAME = "ConfigurableLockpicker";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ConfigurableLockpicker.Patches
{
	[HarmonyPatch(typeof(DoorLock))]
	public class DoorlockPatch
	{
		[HarmonyPatch(typeof(DoorLock), "Awake")]
		[HarmonyPostfix]
		public static void AwakePostfix(DoorLock __instance)
		{
			__instance.maxTimeLeft = Plugin.LockpickTime.Value;
			__instance.lockPickTimeLeft = Plugin.LockpickTime.Value;
		}

		[HarmonyPatch(typeof(DoorLock), "Update")]
		[HarmonyPostfix]
		public static void UpdatePostfix(DoorLock __instance)
		{
			if (__instance.isLocked && __instance.isPickingLock && __instance.lockPickTimeLeft > Plugin.LockpickTime.Value)
			{
				__instance.lockPickTimeLeft = Plugin.LockpickTime.Value;
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void AddPrefab(ref GameNetworkManager __instance)
		{
			((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(Plugin.NetworkerPrefab);
		}
	}
	[HarmonyPatch(typeof(LockPicker))]
	public class LockpickerPatch
	{
		[CompilerGenerated]
		private sealed class <LockWait>d__2 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public LockPicker __instance;

			public DoorLock door;

			private float <waitTime>5__1;

			private float <elapsed>5__2;

			private float <remainingTime>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LockWait>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					Plugin.CustomLogger.LogWarning((object)"LockWait");
					<waitTime>5__1 = Plugin.RelockTime.Value;
					<elapsed>5__2 = 0f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<elapsed>5__2 < <waitTime>5__1)
				{
					if ((Object)(object)__instance == (Object)null || (Object)(object)door == (Object)null || door.isLocked || (Object)(object)((Component)door).gameObject == (Object)null)
					{
						return false;
					}
					<elapsed>5__2 += Time.deltaTime;
					<remainingTime>5__3 = <waitTime>5__1 - <elapsed>5__2;
					door.doorTrigger.hoverTip = $"Locking in {Mathf.CeilToInt(<remainingTime>5__3)}s";
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				StopPicking(__instance, door);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[HarmonyPatch(typeof(LockPicker), "ItemActivate")]
		[HarmonyPostfix]
		public static void ItemActivatePostfix(LockPicker __instance)
		{
			//IL_0035: 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)
			if (!Plugin.Relock.Value)
			{
				return;
			}
			FieldInfo field = typeof(LockPicker).GetField("hit", BindingFlags.Instance | BindingFlags.NonPublic);
			RaycastHit val = (RaycastHit)field.GetValue(__instance);
			if (!((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) && !((Object)(object)((RaycastHit)(ref val)).transform == (Object)null))
			{
				DoorLock component = ((Component)((RaycastHit)(ref val)).transform).GetComponent<DoorLock>();
				if (!((Object)(object)component == (Object)null) && !component.isLocked)
				{
					Networker.Instance.LockDoorServerRpc(((NetworkBehaviour)__instance).NetworkObject.NetworkObjectId, ((NetworkBehaviour)component).NetworkObject.NetworkObjectId);
				}
			}
		}

		public static void startLocking(LockPicker __instance, DoorLock door)
		{
			//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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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)
			Transform parent = ((Vector3.Distance(door.lockPickerPosition.position, ((Component)__instance).transform.position) < Vector3.Distance(door.lockPickerPosition2.position, ((Component)__instance).transform.position)) ? door.lockPickerPosition : door.lockPickerPosition2);
			if ((Object)(object)((GrabbableObject)__instance).playerHeldBy != (Object)null)
			{
				((GrabbableObject)__instance).playerHeldBy.DiscardHeldObject(true, ((NetworkBehaviour)door).NetworkObject, Vector3.zero, false);
				((Component)__instance).transform.SetParent(parent);
			}
			__instance.lockPickerAudio.PlayOneShot(__instance.finishPickingLockClips[Random.Range(0, __instance.finishPickingLockClips.Length)]);
			__instance.armsAnimator.SetBool("mounted", true);
			__instance.armsAnimator.SetBool("picking", true);
			__instance.currentlyPickingDoor = door;
			((GrabbableObject)__instance).grabbable = false;
			((GrabbableObject)__instance).grabbableToEnemies = false;
			((MonoBehaviour)Networker.Instance).StartCoroutine(LockWait(__instance, door));
		}

		[IteratorStateMachine(typeof(<LockWait>d__2))]
		private static IEnumerator LockWait(LockPicker __instance, DoorLock door)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LockWait>d__2(0)
			{
				__instance = __instance,
				door = door
			};
		}

		public static void StopPicking(LockPicker __instance, DoorLock door)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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)
			Plugin.CustomLogger.LogWarning((object)"StopPicking");
			__instance.lockPickerAudio.PlayOneShot(__instance.finishPickingLockClips[Random.Range(0, __instance.finishPickingLockClips.Length)]);
			__instance.armsAnimator.SetBool("mounted", false);
			__instance.armsAnimator.SetBool("picking", false);
			((GrabbableObject)__instance).grabbable = true;
			((GrabbableObject)__instance).grabbableToEnemies = true;
			__instance.currentlyPickingDoor = null;
			((Component)__instance).transform.SetParent((Transform)null);
			((GrabbableObject)__instance).startFallingPosition = ((Component)__instance).transform.position;
			((GrabbableObject)__instance).FallToGround(false, false, default(Vector3));
			door.LockDoor(30f);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void InstantiateNetworker(StartOfRound __instance)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(Plugin.NetworkerPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(true);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace ConfigurableLockpicker.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}