Decompiled source of KeysLockDoors v1.1.3

plugins/KeysLockDoors/KeysLockDoors.dll

Decompiled 3 months ago
using System;
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.Logging;
using GameNetcodeStuff;
using KeysLockDoors.MonoBehaviours;
using KeysLockDoors.Patches;
using On;
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: AssemblyTitle("KeysLockDoors")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KeysLockDoors")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7a979f41-95a7-468b-bbda-5f26db59f9f3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace KeysLockDoors
{
	[BepInPlugin("sophisticasean.keyslockdoors", "KeysLockDoors", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "sophisticasean.keyslockdoors";

		public const string ModName = "KeysLockDoors";

		public const string ModVersion = "0.2.0";

		public static ManualLogSource logger;

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			KeyPatch.Load();
			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);
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"KeysLockDoors loaded and ready to go.");
		}
	}
}
namespace KeysLockDoors.Patches
{
	public class KeyPatch
	{
		public static void Load()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			GameNetworkManager.Start += new hook_Start(GameNetworkManager_Start);
			KeyItem.ItemActivate += new hook_ItemActivate(KeyItem_ItemActivate);
		}

		private static void GameNetworkManager_Start(orig_Start orig, GameNetworkManager self)
		{
			orig.Invoke(self);
			foreach (NetworkPrefab prefab in ((Component)self).GetComponent<NetworkManager>().NetworkConfig.Prefabs.m_Prefabs)
			{
				if ((Object)(object)prefab.Prefab.GetComponent<GrabbableObject>() != (Object)null)
				{
					Plugin.logger.LogInfo((object)((NetworkBehaviour)prefab.Prefab.GetComponent<GrabbableObject>()).__getTypeName());
					if (((NetworkBehaviour)prefab.Prefab.GetComponent<GrabbableObject>()).__getTypeName() == "KeyItem")
					{
						KeyItem keyItem = prefab.Prefab.AddComponent<KeyItem>();
					}
				}
			}
		}

		private static void KeyItem_ItemActivate(orig_ItemActivate orig, KeyItem self, bool used, bool buttonDown = true)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			bool flag = ((object)GameNetworkManager.Instance.localPlayerController.ItemSlots[GameNetworkManager.Instance.localPlayerController.currentItemSlot]).GetType() == typeof(KeyItem);
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			RaycastHit val = default(RaycastHit);
			if (!((Object)(object)localPlayerController == (Object)null) && Physics.Raycast(new Ray(((Component)localPlayerController.gameplayCamera).transform.position, ((Component)localPlayerController.gameplayCamera).transform.forward), ref val, 3f, 2816))
			{
				DoorLock component = ((Component)((RaycastHit)(ref val)).transform).GetComponent<DoorLock>();
				if ((Object)(object)component != (Object)null && !component.isLocked)
				{
					ulong networkObjectId = ((NetworkBehaviour)component).NetworkObjectId;
					KeyItem val2 = (KeyItem)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
					((Component)val2).GetComponent<KeyItem>().LockDoor(networkObjectId);
					component.LockDoor(30f);
					GameNetworkManager.Instance.localPlayerController.DespawnHeldObject();
				}
				else
				{
					orig.Invoke(self, used, buttonDown);
				}
			}
		}
	}
}
namespace KeysLockDoors.MonoBehaviours
{
	public class KeyItem : NetworkBehaviour
	{
		public void LockDoor(ulong doorID)
		{
			LockDoorServerRpc(doorID);
		}

		[ServerRpc(RequireOwnership = false)]
		public void LockDoorServerRpc(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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_0089: 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(1185374495u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, doorID);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1185374495u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					LockDoorClientRpc(doorID);
				}
			}
		}

		[ClientRpc]
		public void LockDoorClientRpc(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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_0089: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(267027776u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, doorID);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 267027776u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			DoorLock[] array = Object.FindObjectsOfType<DoorLock>();
			foreach (DoorLock val3 in array)
			{
				if (((NetworkBehaviour)val3).NetworkObjectId == doorID)
				{
					Plugin.logger.LogInfo((object)"found door to lock, locking door");
					val3.LockDoor(30f);
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_KeyItem()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1185374495u, new RpcReceiveHandler(__rpc_handler_1185374495));
			NetworkManager.__rpc_func_table.Add(267027776u, new RpcReceiveHandler(__rpc_handler_267027776));
		}

		private static void __rpc_handler_1185374495(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong doorID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref doorID);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((KeyItem)(object)target).LockDoorServerRpc(doorID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_267027776(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong doorID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref doorID);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((KeyItem)(object)target).LockDoorClientRpc(doorID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "KeyItem";
		}
	}
}