Decompiled source of Moved Magnet Switch v1.5.0

BepInEx/Plugins/MagnetLever.dll

Decompiled 4 months 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 BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MagnetLever")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MagnetLever")]
[assembly: AssemblyTitle("MagnetLever")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
[BepInPlugin("com.atomic.magnetmoved", "Magnet Moved", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(NetworkManager))]
	internal static class NetworkPrefabPatch_MAGNET
	{
		private static readonly string MOD_GUID = "com.atomic.magnetmoved";

		[HarmonyPostfix]
		[HarmonyPatch("SetSingleton")]
		private static void RegisterPrefab()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(MOD_GUID + " Prefab");
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
			Object.DontDestroyOnLoad((Object)(object)val);
			NetworkObject obj = val.AddComponent<NetworkObject>();
			FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
			field.SetValue(obj, MOD_GUID.GetHashCode());
			NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		}
	}

	private class TransformData
	{
		public Vector3 Position { get; }

		public Quaternion Rotation { get; }

		public Vector3 Scale { get; }

		public TransformData(Vector3 position, Quaternion rotation, Vector3 scale)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Position = position;
			Rotation = rotation;
			Scale = scale;
		}
	}

	private bool isWiderShipModInstalled = false;

	private bool isRightSideOn = false;

	private readonly Dictionary<string, TransformData> positionMappings = new Dictionary<string, TransformData>();

	private void Positions()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: 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_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
		positionMappings["default"] = new TransformData(new Vector3(-6.579f, 1.778f, -9.633f), Quaternion.Euler(90f, 0f, -87.878f), new Vector3(1.414123f, 1.414122f, 1.414122f));
		positionMappings["wider_left"] = new TransformData(new Vector3(-7.513f, 1.61f, -9.553f), Quaternion.Euler(90f, 0f, 180f), new Vector3(1.414123f, 1.414122f, 1.414122f));
		positionMappings["wider_right"] = new TransformData(new Vector3(-7.513f, 1.61f, -3.853f), Quaternion.Euler(90f, 0f, 180f), new Vector3(1.414123f, 1.414122f, 1.414122f));
	}

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Magnet Moved loaded");
		isWiderShipModInstalled = CheckIfModInstalled("mborsh.WiderShipMod");
		Positions();
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if (((Scene)(ref scene)).name == "SampleSceneRelay")
		{
			isRightSideOn = (Object)(object)GameObject.Find("ShipInsideRight") != (Object)null;
			MoveMagnetSwitch();
		}
	}

	private void MoveMagnetSwitch()
	{
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: 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)
		//IL_00c3: 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)
		//IL_003b: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("MagnetLever");
		if (isWiderShipModInstalled)
		{
			if (isRightSideOn)
			{
				val.transform.localPosition = positionMappings["wider_right"].Position;
				val.transform.localRotation = positionMappings["wider_right"].Rotation;
				val.transform.localScale = positionMappings["wider_right"].Scale;
			}
			else
			{
				val.transform.localPosition = positionMappings["wider_left"].Position;
				val.transform.localRotation = positionMappings["wider_left"].Rotation;
				val.transform.localScale = positionMappings["wider_left"].Scale;
			}
		}
		else
		{
			val.transform.localPosition = positionMappings["default"].Position;
			val.transform.localRotation = positionMappings["default"].Rotation;
			val.transform.localScale = positionMappings["default"].Scale;
		}
	}

	private bool CheckIfModInstalled(string modGUID)
	{
		string modGUID2 = modGUID;
		return Chainloader.PluginInfos.Values.Any((PluginInfo info) => info.Metadata.GUID == modGUID2);
	}
}