Decompiled source of MirroredParts v1.0.3

MirroredParts.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WildSkies.Gameplay.Building;
using WildSkies.Gameplay.ShipBuilding;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MirroredParts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Nines (Natives)")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("MirroredParts")]
[assembly: AssemblyTitle("MirroredParts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 MirroredParts
{
	[BepInPlugin("MirroredParts", "MirroredParts", "1.0.3")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Log;

		internal static Harmony harmonyInstance;

		private static readonly string[] ExcludedParts = new string[10] { "ship.part.core.", "ship.part.helm.", "ship.part.cannon.", "ship.part.table.map.", "ship.part.decoration.wood.bench.", "ship.part.decoration.wood.stool.", "ship.part.decoration.saborian.stool.", "ship.part.chair.", "ship.part.decoration.bed.", "ship.part.instrument." };

		public override void Load()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("MirroredParts");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			harmonyInstance = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		public override bool Unload()
		{
			Harmony obj = harmonyInstance;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			return true;
		}

		private static float getSign(Vector3 localScale, float x)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			x += 1.6f;
			if (localScale.x > 0f && x < -0.02f)
			{
				return -1f;
			}
			if (localScale.x < 0f && x > 0.02f)
			{
				return 1f;
			}
			return 0f;
		}

		[HarmonyPatch(typeof(ShipFrameBuilder), "UpdateHullObjectDetails")]
		[HarmonyPostfix]
		public static void ShipFrameBuilder_UpdateHullObjectDetails(ShipFrameBuilder __instance, GameObject shipPartGameObject)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			string itemId = shipPartGameObject.GetComponent<BuildableAsset>().Id;
			if (ExcludedParts.Any((string x) => itemId.StartsWith(x)) || Object.op_Implicit((Object)(object)shipPartGameObject.GetComponentInChildren<MeshCollider>()))
			{
				return;
			}
			float sign = getSign(shipPartGameObject.transform.localScale, shipPartGameObject.transform.localPosition.x);
			if (sign == 0f)
			{
				return;
			}
			Il2CppArrayBase<BoxCollider> componentsInChildren = shipPartGameObject.GetComponentsInChildren<BoxCollider>(true);
			List<BoxCollider> list = ((IEnumerable<BoxCollider>)componentsInChildren).Where((BoxCollider x) => ((Collider)x).enabled).ToList();
			foreach (BoxCollider item in list)
			{
				((Collider)item).enabled = false;
			}
			Vector3 localScale = shipPartGameObject.transform.localScale;
			localScale.x = Mathf.Abs(localScale.x) * sign;
			shipPartGameObject.transform.localScale = localScale;
			foreach (BoxCollider item2 in componentsInChildren)
			{
				Vector3 size = item2.size;
				size.x = Mathf.Abs(size.x) * sign;
				item2.size = size;
			}
			foreach (BoxCollider item3 in list)
			{
				((Collider)item3).enabled = true;
			}
		}

		[HarmonyPatch(typeof(ShipFrameBuilder), "ApplyVisualShipHull")]
		[HarmonyPostfix]
		public static void ShipFrameBuilder_ApplyVisualShipHull(ShipFrameBuilder __instance)
		{
			//IL_0057: 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_0067: 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)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in ((IEnumerable<Transform>)((Component)__instance._visualHullParent).GetComponentsInChildren<Transform>()).Where((Transform x) => x.localScale.x < 0f || x.localScale.y < 0f || x.localScale.z < 0f))
			{
				foreach (BoxCollider componentsInChild in ((Component)item).GetComponentsInChildren<BoxCollider>(true))
				{
					Vector3 size = componentsInChild.size;
					size.x *= ((!(item.localScale.x < 0f)) ? 1 : (-1));
					size.y *= ((!(item.localScale.y < 0f)) ? 1 : (-1));
					size.z *= ((!(item.localScale.z < 0f)) ? 1 : (-1));
					componentsInChild.size = size;
				}
			}
		}

		[HarmonyPatch(typeof(CraftingToolController), "UpdatePlacementStamp")]
		[HarmonyPrefix]
		public static void CraftingToolController_UpdatePlacementStamp(CraftingToolController __instance)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance._placementData.IsLookingAtShip())
			{
				return;
			}
			string itemId = __instance._placementData.SelectedAssetDefinition.ItemId;
			if (ExcludedParts.Any((string x) => itemId.StartsWith(x)))
			{
				return;
			}
			float sign = getSign(((Component)__instance._placementData.SelectedAssetController).transform.localScale, __instance._placementData.LookAtPoint.Position.x);
			if (sign == 0f)
			{
				return;
			}
			Il2CppArrayBase<BoxCollider> componentsInChildren = ((Component)__instance._placementData.SelectedAssetController).GetComponentsInChildren<BoxCollider>();
			foreach (BoxCollider item in componentsInChildren)
			{
				((Collider)item).enabled = false;
			}
			Vector3 localScale = ((Component)__instance._placementData.SelectedAssetController).transform.localScale;
			localScale.x = Mathf.Abs(localScale.x) * sign;
			((Component)__instance._placementData.SelectedAssetController).transform.localScale = localScale;
			foreach (BoxCollider item2 in componentsInChildren)
			{
				Vector3 size = item2.size;
				size.x = Mathf.Abs(size.x) * sign;
				item2.size = size;
				((Collider)item2).enabled = true;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MirroredParts";

		public const string PLUGIN_NAME = "MirroredParts";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}