Decompiled source of EmeraudeDeconstruction v1.0.0

plugins/EmeraudeDeconstruction.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("EmeraudeDeconstruction")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmeraudeDeconstruction")]
[assembly: AssemblyTitle("EmeraudeDeconstruction")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 EmeraudeDeconstruction
{
	[HarmonyPatch(typeof(Ship), "Awake")]
	internal static class ShipAwakePatch
	{
		private static void Postfix(Ship __instance)
		{
			Removal.Allow((Component)(object)__instance);
		}
	}
	[HarmonyPatch(typeof(Vagon), "Awake")]
	internal static class VagonAwakePatch
	{
		private static void Postfix(Vagon __instance)
		{
			Removal.Allow((Component)(object)__instance);
		}
	}
	[HarmonyPatch(typeof(Player), "RemovePiece")]
	internal static class RemovePiecePatch
	{
		private static void Prefix()
		{
			Removal.InProgress = true;
		}

		private static void Finalizer()
		{
			Removal.InProgress = false;
		}
	}
	[HarmonyPatch(typeof(Piece), "CanBeRemoved")]
	internal static class CanBeRemovedPatch
	{
		private static void Postfix(Piece __instance, ref bool __result)
		{
			if (__result && Removal.InProgress)
			{
				__result = Removal.IsFree(__instance);
			}
		}
	}
	internal static class Removal
	{
		internal static bool InProgress;

		internal static void Allow(Component vehicle)
		{
			Piece componentInParent = vehicle.GetComponentInParent<Piece>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				componentInParent.m_canBeRemoved = true;
			}
		}

		internal static bool IsFree(Piece piece)
		{
			Ship componentInChildren = ((Component)piece).GetComponentInChildren<Ship>();
			Vagon componentInChildren2 = ((Component)piece).GetComponentInChildren<Vagon>();
			if ((Object)(object)componentInChildren == (Object)null && (Object)(object)componentInChildren2 == (Object)null)
			{
				return true;
			}
			if ((Object)(object)componentInChildren != (Object)null && componentInChildren.HasPlayerOnboard())
			{
				return false;
			}
			if ((Object)(object)componentInChildren2 != (Object)null && componentInChildren2.InUse())
			{
				return false;
			}
			Container componentInChildren3 = ((Component)piece).GetComponentInChildren<Container>();
			if ((Object)(object)componentInChildren3 == (Object)null)
			{
				return true;
			}
			if (!componentInChildren3.IsInUse())
			{
				return componentInChildren3.GetInventory().NrOfItems() == 0;
			}
			return false;
		}
	}
	[BepInPlugin("emeraude.deconstruction", "Emeraude Deconstruction", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "emeraude.deconstruction";

		public const string Name = "Emeraude Deconstruction";

		public const string Version = "1.0.0";

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("emeraude.deconstruction").PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Emeraude Deconstruction 1.0.0 loaded");
		}
	}
}