Decompiled source of Lockdown v1.0.3

NicholaScott.LethalCompany.Lockdown.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using NicholaScott.BepInEx.Utils.Configuration;
using NicholaScott.BepInEx.Utils.Instancing;
using NicholaScott.BepInEx.Utils.Patching;
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("NicholaScott.LethalCompany.Lockdown")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NicholaScott.LethalCompany.Lockdown")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("F1E58CD9-995C-4551-8F0A-2CDA92D85C13")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NicholaScott.LethalCompany.Lockdown;

[BepInDependency("NicholaScott.BepInEx.Utils", "1.2.0")]
[BepInPlugin("NicholaScott.LethalCompany.Lockdown", "Lockdown", "1.0.3")]
public class Lockdown : BaseUnityPlugin
{
	public struct Configuration
	{
		public enum PermissionLevel
		{
			Unrestricted,
			HostOnly
		}

		[ConfigEntryDefinition(Name = "RestrictPurchasingItems", Description = "Whether any client, or only the host, can purchase items.")]
		public PermissionLevel PurchaseStoreItems;

		[ConfigEntryDefinition(Name = "RestrictPurchasingUnlockables", Description = "Whether any client, or only the host, can purchase unlockables.")]
		public PermissionLevel PurchaseStoreUnlocks;

		[ConfigEntryDefinition(Name = "RestrictRoutingShipToMoon", Description = "Whether any client, or only the host, can use the `route` command in the terminal.")]
		public PermissionLevel RouteShipToMoon;

		[ConfigEntryDefinition(Name = "RestrictPlacingObjectIntoStorage", Description = "Whether any client, or only the host, can put items into storage with the <B> key.")]
		public PermissionLevel PlaceObjectIntoStorage;

		[ConfigEntryDefinition(Name = "RestrictTakingObjectFromStorage", Description = "Whether any client, or only the host, can take items out of storage with the terminal.")]
		public PermissionLevel ReturnObjectFromStorage;

		[ConfigEntryDefinition(Name = "RestrictMovingObjectsInShip", Description = "Whether any client, or only the host, can move placeable objects in the ship.")]
		public PermissionLevel MoveObjects;

		[ConfigEntryDefinition(Name = "RestrictShipLights", Description = "Whether any client, or only the host, can toggle ship lights (except when host is not nearby).")]
		public PermissionLevel ToggleShipLights;

		[ConfigEntryDefinition(Description = "How fast time passes.")]
		public float TimeMultiplier;
	}

	public void Awake()
	{
		Singleton<Lockdown>.Instance = this;
		Singleton<Lockdown, Configuration>.Configuration = Extensions.BindStruct<Configuration>(((BaseUnityPlugin)this).Config, new Configuration
		{
			PurchaseStoreItems = Configuration.PermissionLevel.HostOnly,
			PurchaseStoreUnlocks = Configuration.PermissionLevel.HostOnly,
			RouteShipToMoon = Configuration.PermissionLevel.HostOnly,
			PlaceObjectIntoStorage = Configuration.PermissionLevel.HostOnly,
			ReturnObjectFromStorage = Configuration.PermissionLevel.HostOnly,
			MoveObjects = Configuration.PermissionLevel.HostOnly,
			ToggleShipLights = Configuration.PermissionLevel.HostOnly,
			TimeMultiplier = 0.5f
		});
		Extensions.PatchAttribute<Production>(Assembly.GetExecutingAssembly(), ((BaseUnityPlugin)this).Info.Metadata.GUID, (Action<object>)((BaseUnityPlugin)this).Logger.LogInfo);
	}
}
[Production]
public static class LockdownPatches
{
	private static readonly int PullLever = Animator.StringToHash("pullLever");

	private static bool IsHostSender(__RpcParams rpcParams)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		return rpcParams.Server.Receive.SenderClientId == GameNetworkManager.Instance.localPlayerController.actualClientId;
	}

	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void ChangeTimeSpeedMultiplier(TimeOfDay __instance)
	{
		if (NetworkManager.Singleton.IsServer)
		{
			__instance.globalTimeSpeedMultiplier = Singleton<Lockdown, Lockdown.Configuration>.Configuration.TimeMultiplier;
		}
	}

	[HarmonyPatch(typeof(Terminal), "__rpc_handler_4003509079")]
	[HarmonyPrefix]
	public static bool IgnoreClientButNotHostPurchases(NetworkBehaviour target, __RpcParams rpcParams)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		if (Singleton<Lockdown, Lockdown.Configuration>.Configuration.PurchaseStoreItems == Lockdown.Configuration.PermissionLevel.Unrestricted || IsHostSender(rpcParams))
		{
			return true;
		}
		Singleton<Lockdown>.Logger.LogInfo((object)"Blocking purchase from client!");
		Terminal val = (Terminal)(object)((target is Terminal) ? target : null);
		if (val != null)
		{
			val.SyncGroupCreditsClientRpc(val.groupCredits, val.orderedItemsFromTerminal.Count);
		}
		return false;
	}

	[HarmonyPatch(typeof(StartOfRound), "__rpc_handler_3953483456")]
	[HarmonyPrefix]
	public static bool IgnoreClientButNotHostPurchaseUnlockables(NetworkBehaviour target, __RpcParams rpcParams)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		if (Singleton<Lockdown, Lockdown.Configuration>.Configuration.PurchaseStoreUnlocks == Lockdown.Configuration.PermissionLevel.Unrestricted || IsHostSender(rpcParams))
		{
			return true;
		}
		Singleton<Lockdown>.Logger.LogInfo((object)"Blocking unlock-able purchase from client!");
		StartOfRound val = (StartOfRound)(object)((target is StartOfRound) ? target : null);
		if (val != null)
		{
			val.BuyShipUnlockableClientRpc(Object.FindObjectOfType<Terminal>().groupCredits, -1);
		}
		return false;
	}

	[HarmonyPatch(typeof(StartOfRound), "__rpc_handler_1134466287")]
	[HarmonyPrefix]
	public static bool IgnoreClientButNotHostRouteChanges(__RpcParams rpcParams)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		Singleton<Lockdown>.Logger.LogInfo((object)"Checking route change from client.");
		return Singleton<Lockdown, Lockdown.Configuration>.Configuration.RouteShipToMoon == Lockdown.Configuration.PermissionLevel.Unrestricted || IsHostSender(rpcParams);
	}

	[HarmonyPatch(typeof(StartOfRound), "__rpc_handler_3380566632")]
	[HarmonyPrefix]
	public static bool IgnoreClientButNotHostReturnFromStorage(__RpcParams rpcParams)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		Singleton<Lockdown>.Logger.LogInfo((object)"Checking spawn unlock-able from client.");
		return Singleton<Lockdown, Lockdown.Configuration>.Configuration.ReturnObjectFromStorage == Lockdown.Configuration.PermissionLevel.Unrestricted || IsHostSender(rpcParams);
	}

	[HarmonyPatch(typeof(ShipBuildModeManager), "__rpc_handler_3086821980")]
	[HarmonyPrefix]
	public static bool IgnoreClientButNotHostPlaceInStorage(FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		if (Singleton<Lockdown, Lockdown.Configuration>.Configuration.PlaceObjectIntoStorage == Lockdown.Configuration.PermissionLevel.Unrestricted || IsHostSender(rpcParams))
		{
			return true;
		}
		Singleton<Lockdown>.Logger.LogInfo((object)"Blocking unlock-able move to storage from client!");
		NetworkObjectReference val = default(NetworkObjectReference);
		((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref val, default(ForNetworkSerializable));
		NetworkObject val2 = default(NetworkObject);
		if (!((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null))
		{
			return false;
		}
		PlaceableShipObject componentInChildren = ((Component)val2).gameObject.GetComponentInChildren<PlaceableShipObject>();
		if ((Object)(object)componentInChildren != (Object)null)
		{
			Object.FindObjectOfType<StartOfRound>().ReturnUnlockableFromStorageClientRpc(componentInChildren.unlockableID);
		}
		return false;
	}

	[HarmonyPatch(typeof(ShipBuildModeManager), "__rpc_handler_861494715")]
	[HarmonyPrefix]
	public static bool IgnoreClientButNotHostMoveCabinet(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		if (Singleton<Lockdown, Lockdown.Configuration>.Configuration.MoveObjects == Lockdown.Configuration.PermissionLevel.Unrestricted || IsHostSender(rpcParams))
		{
			return true;
		}
		Vector3 val = default(Vector3);
		((FastBufferReader)(ref reader)).ReadValueSafe(ref val);
		((FastBufferReader)(ref reader)).ReadValueSafe(ref val);
		NetworkObjectReference val2 = default(NetworkObjectReference);
		((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref val2, default(ForNetworkSerializable));
		NetworkObject val3 = default(NetworkObject);
		if (!((NetworkObjectReference)(ref val2)).TryGet(ref val3, (NetworkManager)null))
		{
			return false;
		}
		PlaceableShipObject componentInChildren = ((Component)val3).gameObject.GetComponentInChildren<PlaceableShipObject>();
		if ((Object)(object)componentInChildren != (Object)null)
		{
			Transform transform = ((Component)componentInChildren).transform;
			NetworkBehaviour obj = ((target is ShipBuildModeManager) ? target : null);
			if (obj != null)
			{
				((ShipBuildModeManager)obj).PlaceShipObjectClientRpc(transform.position, transform.eulerAngles, val2, (int)GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}
		return false;
	}

	[HarmonyPatch(typeof(ShipLights), "__rpc_handler_1625678258")]
	[HarmonyPrefix]
	public static bool IgnoreClientButNotHostSetLights(__RpcParams rpcParams)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		if (Singleton<Lockdown, Lockdown.Configuration>.Configuration.ToggleShipLights == Lockdown.Configuration.PermissionLevel.Unrestricted || IsHostSender(rpcParams))
		{
			return true;
		}
		ShipLights val = Object.FindObjectOfType<ShipLights>();
		if (GameNetworkManager.Instance.localPlayerController.isPlayerDead || Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)val).transform.position) >= 20f)
		{
			return true;
		}
		val.SetShipLightsClientRpc(val.areLightsOn);
		return false;
	}
}