Decompiled source of FurnitureLock v1.3.3

BepInEx/plugins/FurnitureLock.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using FurnitureLock.Config;
using FurnitureLock.Dependency;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("FurnitureLock")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.3.0")]
[assembly: AssemblyInformationalVersion("1.3.3+8057770a6731b24ba1f41a9fc7bb3f955ff04a06")]
[assembly: AssemblyProduct("FurnitureLock")]
[assembly: AssemblyTitle("FurnitureLock")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.3.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 FurnitureLock
{
	[BepInPlugin("mattymatty.FurnitureLock", "FurnitureLock", "1.3.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class FurnitureLock : BaseUnityPlugin
	{
		internal static class PluginConfig
		{
			internal static readonly Dictionary<UnlockableItem, UnlockableConfig> UnlockableConfigs = new Dictionary<UnlockableItem, UnlockableConfig>();

			internal static void Init()
			{
				ConfigFile config = ((BaseUnityPlugin)INSTANCE).Config;
				if (LethalConfigProxy.Enabled)
				{
					LethalConfigProxy.AddButton("Cleanup", "Clear old entries", "remove unused entries in the config file\n(IF RUN FROM MENU WILL DELETE ALL ITEMS!!)", "Clean&Save", CleanAndSave);
				}
			}

			internal static void CleanAndSave()
			{
				ConfigFile config = ((BaseUnityPlugin)INSTANCE).Config;
				PropertyInfo property = ((object)config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
				Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(config, null);
				dictionary.Clear();
				config.Save();
			}
		}

		public const string GUID = "mattymatty.FurnitureLock";

		public const string NAME = "FurnitureLock";

		public const string VERSION = "1.3.3";

		internal static ManualLogSource Log;

		public static FurnitureLock INSTANCE { get; private set; }

		private void Awake()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			INSTANCE = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				if (LobbyCompatibilityChecker.Enabled)
				{
					LobbyCompatibilityChecker.Init();
				}
				Log.LogInfo((object)"Initializing Configs");
				PluginConfig.Init();
				Log.LogInfo((object)"Patching Methods");
				Harmony val = new Harmony("mattymatty.FurnitureLock");
				val.PatchAll(Assembly.GetExecutingAssembly());
				Log.LogInfo((object)"FurnitureLock v1.3.3 Loaded!");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Exception while initializing: \n" + ex));
			}
		}
	}
}
namespace FurnitureLock.Patches
{
	[HarmonyPatch]
	internal class AutoParentToShipPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(AutoParentToShip), "Awake")]
		private static void AfterAwake(AutoParentToShip __instance)
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			PlaceableShipObject componentInChildren = ((Component)__instance).GetComponentInChildren<PlaceableShipObject>();
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				UnlockableItem val = StartOfRound.Instance.unlockablesList.unlockables[componentInChildren.unlockableID];
				if (!FurnitureLock.PluginConfig.UnlockableConfigs.TryGetValue(val, out var value))
				{
					value = new UnlockableConfig(val, componentInChildren.unlockableID);
					FurnitureLock.PluginConfig.UnlockableConfigs.Add(val, value);
				}
				if (Object.op_Implicit((Object)(object)componentInChildren.parentObjectSecondary))
				{
					value.DefaultPosition = componentInChildren.parentObject.startingPosition - (((Component)componentInChildren.parentObjectSecondary).transform.position - ((Component)componentInChildren.mainMesh).transform.position) - (((Component)componentInChildren.mainMesh).transform.position - ((Component)componentInChildren.placeObjectCollider).transform.position);
					Quaternion val2 = Quaternion.Inverse(Quaternion.Euler(componentInChildren.parentObject.startingRotation));
					Quaternion val3 = val2 * ((Component)componentInChildren.parentObjectSecondary).transform.rotation;
					UnlockableConfig unlockableConfig = value;
					Quaternion val4 = Quaternion.Inverse(((Component)componentInChildren.mainMesh).transform.rotation) * val3;
					unlockableConfig.DefaultRotation = ((Quaternion)(ref val4)).eulerAngles;
				}
				else
				{
					Quaternion val5 = Quaternion.Euler(componentInChildren.parentObject.rotationOffset);
					Quaternion val6 = Quaternion.Inverse(((Component)componentInChildren.parentObject).transform.rotation) * val5 * ((Component)componentInChildren.mainMesh).transform.rotation;
					value.DefaultRotation = ((Quaternion)(ref val6)).eulerAngles;
					Vector3 val7 = StartOfRound.Instance.elevatorTransform.TransformPoint(componentInChildren.parentObject.positionOffset);
					value.DefaultPosition = val7 - (((Component)componentInChildren.parentObject).transform.position - ((Component)componentInChildren.mainMesh).transform.position) - (((Component)componentInChildren.mainMesh).transform.position - ((Component)componentInChildren.placeObjectCollider).transform.position);
				}
				value.DefaultsInitialized = true;
				FurnitureLock.Log.LogDebug((object)$"{value} defaults are Pos:{value.DefaultPosition} Rot:{value.DefaultRotation}");
			}
		}
	}
	[HarmonyPatch(typeof(ShipBuildModeManager))]
	internal class ShipBuildModeManagerPatch
	{
		[HarmonyFinalizer]
		[HarmonyPatch("StoreObjectServerRpc")]
		[HarmonyPriority(0)]
		private static void PreventStore(ShipBuildModeManager __instance, NetworkObjectReference objectRef)
		{
			NetworkObject val = default(NetworkObject);
			if (!((NetworkBehaviour)__instance).IsServer || !((NetworkObjectReference)(ref objectRef)).TryGet(ref val, (NetworkManager)null))
			{
				return;
			}
			PlaceableShipObject componentInChildren = ((Component)val).gameObject.GetComponentInChildren<PlaceableShipObject>();
			if (!((Object)(object)componentInChildren == (Object)null))
			{
				UnlockableItem val2 = StartOfRound.Instance.unlockablesList.unlockables[componentInChildren.unlockableID];
				if (val2.inStorage && FurnitureLock.PluginConfig.UnlockableConfigs.TryGetValue(val2, out var value) && value.Locked)
				{
					FurnitureLock.Log.LogDebug((object)("Prevented Store for " + val2.unlockableName));
					StartOfRound.Instance.ReturnUnlockableFromStorageServerRpc(componentInChildren.unlockableID);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("PlaceShipObjectServerRpc")]
		[HarmonyPriority(0)]
		private static void OnMoveFurniture(ShipBuildModeManager __instance, ref Vector3 newPosition, ref Vector3 newRotation, NetworkObjectReference objectRef, ref int playerWhoMoved)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
			NetworkObject val = default(NetworkObject);
			if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening || (int)((NetworkBehaviour)__instance).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost) || !((NetworkObjectReference)(ref objectRef)).TryGet(ref val, (NetworkManager)null))
			{
				return;
			}
			PlaceableShipObject componentInChildren = ((Component)val).gameObject.GetComponentInChildren<PlaceableShipObject>();
			if (!((Object)(object)componentInChildren == (Object)null))
			{
				UnlockableItem val2 = StartOfRound.Instance.unlockablesList.unlockables[componentInChildren.unlockableID];
				if (!val2.inStorage && FurnitureLock.PluginConfig.UnlockableConfigs.TryGetValue(val2, out var value) && value.Locked && value.IsValid)
				{
					FurnitureLock.Log.LogDebug((object)$"{val2.unlockableName} forced to pos:{value.Position} rot:{value.Rotation}");
					newPosition = value.Position;
					newRotation = value.Rotation;
					playerWhoMoved = -1;
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		[HarmonyPriority(800)]
		private static void BeforeStart(StartOfRound __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			for (int i = 0; i < __instance.unlockablesList.unlockables.Count; i++)
			{
				UnlockableItem val = __instance.unlockablesList.unlockables[i];
				if (val.unlockableType != 0 && val.IsPlaceable && !FurnitureLock.PluginConfig.UnlockableConfigs.ContainsKey(val))
				{
					try
					{
						FurnitureLock.PluginConfig.UnlockableConfigs[val] = new UnlockableConfig(val, i);
					}
					catch (Exception ex)
					{
						FurnitureLock.Log.LogError((object)ex);
					}
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("LoadUnlockables")]
		[HarmonyPriority(0)]
		private static void AfterLoadUnlockables(StartOfRound __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer)
			{
				ApplyDefaults(__instance, skipMoved: true);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "SpawnUnlockable")]
		private static void AfterUnlockableSpawn(StartOfRound __instance, int unlockableIndex)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			UnlockableItem val = __instance.unlockablesList.unlockables[unlockableIndex];
			if (!__instance.SpawnedShipUnlockables.TryGetValue(unlockableIndex, out var value) || !FurnitureLock.PluginConfig.UnlockableConfigs.TryGetValue(val, out var value2))
			{
				return;
			}
			GameNetworkManager instance = GameNetworkManager.Instance;
			if (ES3.KeyExists("ShipUnlockMoved_" + val.unlockableName, instance.currentSaveFileName))
			{
				FurnitureLock.Log.LogDebug((object)$"{val.unlockableName} was moved locked {value2.Locked}");
				if (!value2.Locked)
				{
					return;
				}
			}
			value2.ApplyValues(value, placementSound: false);
		}

		[HarmonyPostfix]
		[HarmonyPatch("EndPlayersFiredSequenceClientRpc")]
		private static void AfterEject(StartOfRound __instance)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
			if (!((Object)(object)networkManager == (Object)null) && networkManager.IsListening && (int)((NetworkBehaviour)__instance).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && ((NetworkBehaviour)__instance).IsServer)
			{
				ApplyDefaults(__instance, skipMoved: false);
			}
		}

		private static void ApplyDefaults(StartOfRound startOfRound, bool skipMoved)
		{
			PlaceableShipObject[] array = Object.FindObjectsOfType<PlaceableShipObject>();
			PlaceableShipObject[] array2 = array;
			foreach (PlaceableShipObject val in array2)
			{
				UnlockableItem val2 = startOfRound.unlockablesList.unlockables[val.unlockableID];
				try
				{
					GameObject gameObject = ((Component)val.parentObject).gameObject;
					if (val2.unlockableType != 0 && val2.IsPlaceable && (!skipMoved || !val2.hasBeenMoved) && FurnitureLock.PluginConfig.UnlockableConfigs.TryGetValue(val2, out var value))
					{
						value.ApplyValues(gameObject, placementSound: false);
					}
				}
				catch (Exception arg)
				{
					FurnitureLock.Log.LogError((object)$"Error defaulting {val2.unlockableName}:\n{arg}");
				}
			}
		}
	}
}
namespace FurnitureLock.Dependency
{
	public static class LethalConfigProxy
	{
		private static bool? _enabled;

		public static bool Enabled
		{
			get
			{
				bool valueOrDefault = _enabled.GetValueOrDefault();
				if (!_enabled.HasValue)
				{
					valueOrDefault = Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");
					_enabled = valueOrDefault;
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfig(ConfigEntry<string> entry, bool requiresRestart = false)
		{
			//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)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(entry, new TextInputFieldOptions
			{
				RequiresRestart = requiresRestart,
				Name = GetPrettyConfigName<string>(entry)
			}));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfig(ConfigEntry<bool> entry, bool requiresRestart = false)
		{
			//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)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(entry, new BoolCheckBoxOptions
			{
				RequiresRestart = requiresRestart,
				Name = GetPrettyConfigName<bool>(entry)
			}));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfig(ConfigEntry<float> entry, bool requiresRestart = false)
		{
			//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)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(entry, new FloatInputFieldOptions
			{
				RequiresRestart = requiresRestart,
				Name = GetPrettyConfigName<float>(entry)
			}));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfig(ConfigEntry<int> entry, bool requiresRestart = false)
		{
			//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)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(entry, new IntInputFieldOptions
			{
				RequiresRestart = requiresRestart,
				Name = GetPrettyConfigName<int>(entry)
			}));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddButton(string section, string name, string description, string buttonText, Action callback)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText, (GenericButtonHandler)delegate
			{
				callback?.Invoke();
			}));
		}

		private static string GetPrettyConfigName<T>(ConfigEntry<T> entry)
		{
			return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(((ConfigEntryBase)entry).Definition.Key.Replace("_", " "));
		}
	}
	public static class LobbyCompatibilityChecker
	{
		private static bool? _enabled;

		public static bool Enabled
		{
			get
			{
				bool valueOrDefault = _enabled.GetValueOrDefault();
				if (!_enabled.HasValue)
				{
					valueOrDefault = Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility");
					_enabled = valueOrDefault;
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void Init()
		{
			PluginHelper.RegisterPlugin("mattymatty.FurnitureLock", Version.Parse("1.3.3"), (CompatibilityLevel)1, (VersionStrictness)2);
		}
	}
}
namespace FurnitureLock.Config
{
	public class UnlockableConfig
	{
		private bool _stored;

		private Vector3? _position;

		private Vector3? _rotation;

		public bool DefaultsInitialized { get; internal set; }

		public bool IsValid
		{
			get
			{
				if (!_position.HasValue && !DefaultsInitialized)
				{
					return false;
				}
				if (!_rotation.HasValue && !DefaultsInitialized)
				{
					return false;
				}
				return true;
			}
		}

		public UnlockableItem Unlockable { get; }

		public int UnlockableID { get; }

		public Vector3 Position
		{
			get
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				return (Vector3)(((??)_position) ?? DefaultPosition);
			}
			private set
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				_position = value;
			}
		}

		public Vector3 Rotation
		{
			get
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				return (Vector3)(((??)_rotation) ?? DefaultRotation);
			}
			private set
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				_rotation = value;
			}
		}

		public Vector3 DefaultPosition { get; internal set; }

		public Vector3 DefaultRotation { get; internal set; }

		public bool Locked { get; private set; }

		public bool Stored
		{
			get
			{
				if (_stored)
				{
					return !Locked;
				}
				return false;
			}
			private set
			{
				_stored = value;
			}
		}

		internal ConfigEntry<string> PositionConfig { get; private set; }

		internal ConfigEntry<string> RotationConfig { get; private set; }

		internal ConfigEntry<bool> LockedConfig { get; private set; }

		internal ConfigEntry<bool> StoredConfig { get; private set; }

		public UnlockableConfig(UnlockableItem unlockable, int unlockableID)
		{
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			Unlockable = unlockable;
			UnlockableID = unlockableID;
			FurnitureLock.Log.LogInfo((object)("Registering " + unlockable.unlockableName));
			string unlockableName = unlockable.unlockableName;
			string text = Regex.Replace(unlockableName, "[\\n\\t\\\\\\'\\[\\]]", "").Trim();
			ConfigFile config = ((BaseUnityPlugin)FurnitureLock.INSTANCE).Config;
			PositionConfig = config.Bind<string>(text, "position", "default", "default position of the Furniture piece.");
			RotationConfig = config.Bind<string>(text, "rotation", "default", "default rotation of the Furniture piece.");
			LockedConfig = config.Bind<bool>(text, "locked", false, "if true the furniture piece will not be movable");
			if (unlockable.canBeStored)
			{
				StoredConfig = config.Bind<bool>(text, "spawn_stored", false, "if true the furniture piece will be stored immediately upon spawn");
			}
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.AddConfig(PositionConfig);
				LethalConfigProxy.AddConfig(RotationConfig);
				LethalConfigProxy.AddConfig(LockedConfig);
				if (unlockable.canBeStored)
				{
					LethalConfigProxy.AddConfig(StoredConfig);
				}
				LethalConfigProxy.AddButton(text, "Set Values", "copy current position and rotation to config", "Copy", CopyValues);
				LethalConfigProxy.AddButton(text, "Apply values", "apply current config values", "Apply", delegate
				{
					ApplyValues();
				});
			}
			OnPositionConfigOnSettingChanged();
			PositionConfig.SettingChanged += delegate
			{
				OnPositionConfigOnSettingChanged();
			};
			OnRotationConfigOnSettingChanged();
			RotationConfig.SettingChanged += delegate
			{
				OnRotationConfigOnSettingChanged();
			};
			OnLockedConfigOnSettingChanged();
			LockedConfig.SettingChanged += delegate
			{
				OnLockedConfigOnSettingChanged();
			};
			if (unlockable.canBeStored)
			{
				OnStoredConfigOnSettingChanged();
				StoredConfig.SettingChanged += delegate
				{
					OnStoredConfigOnSettingChanged();
				};
			}
			FurnitureLock.Log.LogDebug((object)$"{unlockable.unlockableName} pos: {Position} rot: {Rotation} lock:{Locked} stored:{Stored}");
		}

		internal void CopyValues()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (((Vector3)(ref Unlockable.placedPosition)).Equals(default(Vector3)) || ((Vector3)(ref Unlockable.placedRotation)).Equals(default(Vector3)))
			{
				FurnitureLock.Log.LogError((object)(Unlockable.unlockableName + " Cannot copy values from default or missing furniture"));
				return;
			}
			Vector3 placedPosition = Unlockable.placedPosition;
			PositionConfig.Value = placedPosition.x.ToString(CultureInfo.InvariantCulture) + ", " + placedPosition.y.ToString(CultureInfo.InvariantCulture) + ", " + placedPosition.z.ToString(CultureInfo.InvariantCulture);
			Vector3 placedRotation = Unlockable.placedRotation;
			RotationConfig.Value = placedRotation.x.ToString(CultureInfo.InvariantCulture) + ", " + placedRotation.y.ToString(CultureInfo.InvariantCulture) + ", " + placedRotation.z.ToString(CultureInfo.InvariantCulture);
			FurnitureLock.PluginConfig.CleanAndSave();
		}

		internal void ApplyValues(GameObject gameObject = null, bool placementSound = true)
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				StartOfRound instance = StartOfRound.Instance;
				if ((Object)(object)instance == (Object)null)
				{
					return;
				}
				if (!((NetworkBehaviour)instance).IsServer)
				{
					FurnitureLock.Log.LogError((object)(Unlockable.unlockableName + " Only the Host can apply values!"));
					return;
				}
				if (!Object.op_Implicit((Object)(object)gameObject) && !StartOfRound.Instance.SpawnedShipUnlockables.TryGetValue(UnlockableID, out gameObject))
				{
					PlaceableShipObject[] array = Object.FindObjectsOfType<PlaceableShipObject>();
					PlaceableShipObject[] array2 = array;
					foreach (PlaceableShipObject val in array2)
					{
						if (val.unlockableID == UnlockableID)
						{
							gameObject = ((Component)val.parentObject).gameObject;
						}
					}
					if ((Object)(object)gameObject == (Object)null)
					{
						return;
					}
				}
				if (!Stored && Unlockable.inStorage)
				{
					instance.ReturnUnlockableFromStorageServerRpc(UnlockableID);
					FurnitureLock.Log.LogDebug((object)(Unlockable.unlockableName + " Forced out of storage"));
				}
				PlaceableShipObject componentInChildren = gameObject.GetComponentInChildren<PlaceableShipObject>();
				if (IsValid)
				{
					ShipBuildModeManager.Instance.PlaceShipObject(Position, Rotation, componentInChildren, placementSound);
					if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
					{
						ShipBuildModeManager.Instance.PlaceShipObjectServerRpc(Position, Rotation, NetworkObjectReference.op_Implicit(gameObject), (int)GameNetworkManager.Instance.localPlayerController.playerClientId);
					}
					FurnitureLock.Log.LogDebug((object)$"{Unlockable.unlockableName} moved to pos:{Position} rot:{Rotation}");
				}
				if (Stored && !Unlockable.inStorage)
				{
					ShipBuildModeManager.Instance.StoreObjectServerRpc(NetworkObjectReference.op_Implicit(gameObject), -1);
					FurnitureLock.Log.LogDebug((object)(Unlockable.unlockableName + " Forced in storage"));
				}
			}
			catch (Exception arg)
			{
				FurnitureLock.Log.LogError((object)$"{Unlockable.unlockableName} crashed while moving:\n{arg}");
			}
		}

		private void OnPositionConfigOnSettingChanged()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string[] source = PositionConfig.Value.Split(',');
				float[] array = source.Select((string s) => float.Parse(s, CultureInfo.InvariantCulture)).ToArray();
				Vector3 value = default(Vector3);
				((Vector3)(ref value))..ctor(array[0], array[1], array[2]);
				_position = value;
			}
			catch (Exception)
			{
				_position = null;
			}
		}

		private void OnRotationConfigOnSettingChanged()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string[] source = RotationConfig.Value.Split(',');
				float[] array = source.Select((string s) => float.Parse(s, CultureInfo.InvariantCulture)).ToArray();
				Vector3 value = default(Vector3);
				((Vector3)(ref value))..ctor(array[0], array[1], array[2]);
				_rotation = value;
			}
			catch (Exception)
			{
				_rotation = null;
			}
		}

		private void OnLockedConfigOnSettingChanged()
		{
			Locked = LockedConfig.Value;
		}

		private void OnStoredConfigOnSettingChanged()
		{
			Stored = StoredConfig.Value;
		}

		public override string ToString()
		{
			return $"{Unlockable.unlockableName}({UnlockableID})";
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}